Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / certextract.go
Last active August 14, 2024 02:03
GCE mTLS Cert Extractor
package main
/*
script extracts the tpm encryptedblob (which is the client public/private key
curl -v -H 'Metadata-Flavor: Google' http://metadata/computeMetadata/v1/instance/credentials/certs
{
"encrypted_credentials": "qmiCsZSSGxU8w7MnZoKe0XriLAPYmNGh6t9BqwtI5MqEJS7sv3pGFaHWi+U0oT8zQpuVsVVaEHP2qLwjE11v7xGR8ZCGr2Y5XnvlyEao8rcD8th6hCswLdJiMUATSZviThwziGIGAAzuHOofzEHbp8vDMe4hFsinz1sPvmOrd1aN1HAYPcXH5qpMdo0kgklXhc3O8p+cgVKO2UA7uNqM+/mOHzgxdLZ9f+X8gxAA1WWgr+X2G4W1BUUTPxFTchnzImoandoUo/SMinSVSrvVSkBCEm6GttxBjjgjc0Y391bOsCcEZH2xUx/Ev7+TfI2zqz0nMYQgB8Vly4/07WAPwUX3D8mFAgoTnokAOgHz1mcenH6C7XhKQRKd84wst2e5L35WFAsXY2Dtj7NgAS08T1e1N81VzDIBS7L8B1y9Y9ACu4n2gcKr/uRo36zunKEOd9rBRvNOdpkzaU3RQC97FUJrAUu6At2q9RLE2brphkq5bn11/CXWskNuzApS3MwzG9jeHJ1AAmDYbKicr1jzgMXhSBB63FXMs87kNtqj3X8XiCFJ89Ckewv1r3G9kzHisOQP1JjSfzD/AFOabkg/eFI6WfnriADuNPwMJHCKMsjDik+f6w4rLuOuLjMFm5OCAQkqAIppiWiBIfoT+4P7Z8Eg31s35wBvd82bIuTx8jG5ODYR7DjXa2kKlnytSI6KKPzlu3Q4z2gzkn3vuP5H5qjpWgDripKr2uqGMsYCRTEC0q0AutLtEY4ayU/Xo07kPyC/fBfQgXJuK/4Eq4UGHmbUP3YWaz
@salrashid123
salrashid123 / duplicate_tpm.md
Last active August 8, 2024 14:01
Transfer TPM based key using PCR policy
@salrashid123
salrashid123 / keyfile.md
Last active June 11, 2024 13:40
go-tpm-files save/load from persistent handle
  • crate prmiary

  • create key

  • evict primary to persistent handle 0x81000000

  • save key with go-tpm-keyfiles

  • load key using go-tpm-keyfile

module main
@salrashid123
salrashid123 / tpm2_createprimary_h2.md
Created May 31, 2024 22:16
tpm2 primarykey for (eg TCG EK Credential Profile H-2 profile
@salrashid123
salrashid123 / tpm2_hmac_pcr_policy.md
Last active June 2, 2024 18:24
tpm2_hmac with pcr policy

seal an external hmac key to a tpm with a PCR policy

export secret="change this password to a secret"
export plain="foo"
echo -n $secret > hmac.key
hexkey=$(xxd -p -c 256 < hmac.key)
echo $hexkey
echo -n $plain > data.in
openssl dgst -sha256 -mac hmac -macopt hexkey:$hexkey data.in
@salrashid123
salrashid123 / go-tpm-gokeyfile.md
Created May 30, 2024 16:49
go-tpm-tools compatibility with go-tpm-keyfile and go-tpm

sample demonstrating cross-usage/compatiblity between

go-tpm go-tpm-keyfile go-tpm-tools

package main
@salrashid123
salrashid123 / keyfilepermanent.md
Created May 26, 2024 16:19
TPM Keyfile with permanent handle
@salrashid123
salrashid123 / iap_jwtaccesstoken.go
Last active May 21, 2024 17:57
self-signed jwt access to google cloud iap
/*
self-signed jwt access to google cloud iap
https://cloud.google.com/iap/docs/authentication-howto#authenticating_with_a_self-signed_jwt
using google auth library
and service account bound inside Trusted Platform Module
*/
package main
@salrashid123
salrashid123 / duplicate_policyduplicationselect.md
Created May 9, 2024 14:56
Prevent Chained duplication from TPM-A -> TPM-B -> TPM-C using tpm2_policyduplicationselect

Prevent Chained duplication from A -> B -> C using tpm2_policyduplicationselect

This procedure will transfer an HMAC key created inside TPM-A to TPM-B but prevent TPM-B to transfer it to TPM-C.

Basically, and extension of As an end-to-end example, the following will transfer an RSA key generated on TPM-A to TPM-B but using tpm2_policyduplicationselect tp prevent further duplication

Step 1 below will transfer a key from A->B, step 2 attempts B->C but is prevented duplication on B by policy

@salrashid123
salrashid123 / duplicate_policycommandcode.md
Created May 9, 2024 14:40
Duplicate and Transfer an encoded key from TPM-A -> TPM-B -> TPM-C using tpm2_policycommandcode