Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / AWS_v4_Signing_noSDK_TPM.md
Last active September 10, 2024 12:20
AWS SigV4 Signing without SDK using Trusted Platform Module (TPM)

AWS v4 signed request using Trusted Platform Module

similar to https://github.com/aws-samples/sigv4-signing-examples but the varaint below invokes sts.GetCallerIdentity where the AWS_SECRET_ACCESS_KEY is embedded in a TPM

In other words, this sample will seal the AWS_SECRET_ACCESS_KEY inside a TPM and then use the TPM to create an AWS v4 signature at no time does the secret leave the TPM but it can be made to issue an hmac

for more info, see

@salrashid123
salrashid123 / AWS_v4_Signing_noSDK.md
Last active September 10, 2024 12:21
AWS SigV4 Signing without SDK
@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