Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / go_attest_keyfile.go
Created September 7, 2026 07:10
convert go-attestation key public/private output format PEM keyfile format
/*
*/
package main
import (
"bytes"
"crypto"
"crypto/ecdsa"
@salrashid123
salrashid123 / openbao-plugin.md
Last active August 26, 2026 15:47
openbao-tpm-plugin

TPM Key Wrapping

Plugin provides the ability to use a Trusted Platform Module (TPM) to seal and unseal keys

The sealed data can only get recovered on the same TPM it was sealed against.

This library also supports sealing data and binding it to a certain passphrase or TPM PCRs values

For an example of standalone usage, see the example below.

@salrashid123
salrashid123 / cloud_build_drive.md
Last active April 22, 2026 19:59
cloudbuild with drive access_token
@salrashid123
salrashid123 / cosign_mldsa.md
Last active March 16, 2026 11:27
Cosign MLDSA signatures (experimental)

Cosign local sign-blob with MLDSA

Simple demo of using MLDSA signatures with cosign.

Before you do anything, please note this is just a POC, nothing more, nothing less. Do not use other than just to test.

plase note

go does not support MLDSA but it will in crypto/mldsa after golang/go#77626

@salrashid123
salrashid123 / cosign_id_token.md
Created March 1, 2026 16:01
Cosign SignBlob with GCP Identity Token from TPM

Cosign SignBlob with GCP Identity Token from TPM

Snippet which uses a TPM based service account key to acquire an identity_token used to sign-blob using cosin

Normally, if you want to use cosign and a TPM, you would use the built in pkcs11 capability as described here:

However, this snippet encodes the service account private key into a TPM and then making it issue an id_token directly using:

@salrashid123
salrashid123 / decode_sigstore.md
Last active March 12, 2026 11:02
Decoding ENCRYPTED SIGSTORE PRIVATE KEY cosign key format

Decoding ENCRYPTED SIGSTORE PRIVATE KEY cosign key format

basically, -----BEGIN ENCRYPTED SIGSTORE PRIVATE KEY----- is not ans1 encoded but a JSON struct which looks like the follwoing

You need to decode/decrypt the EC key thats embedded inside it. The following keypair in the code does not have passphrase

also see cosign signature-specification

@salrashid123
salrashid123 / sign_verify_tpm.md
Created February 28, 2026 16:05
Sign and Verify TPM based JWT using `github.com/lestrrat-go/jwx`

Sign and Verify TPM based JWT using github.com/lestrrat-go/jwx

Using a crypto.Signer from github.com/salrashid123/tpmsigner

Following using a swtpm

rm -rf /tmp/myvtpm && mkdir /tmp/myvtpm
swtpm_setup --tpmstate /tmp/myvtpm --tpm2 --create-ek-cert
@salrashid123
salrashid123 / gcp_python_mtls.md
Created February 22, 2026 11:49
GCP Python Workload Federation TPM based mTLS
@salrashid123
salrashid123 / publickey_tpm.go
Created February 3, 2026 15:47
Create Public PEM key from TPM templates (rsa_ek, ecc_ek, h2, rsa_srk, ecc_srk)
package main
/*
rm -rf /tmp/myvtpm && mkdir /tmp/myvtpm && swtpm_setup --tpmstate /tmp/myvtpm --tpm2 --create-ek-cert && swtpm socket --tpmstate dir=/tmp/myvtpm --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --flags not-need-init,startup-clear --log level=2
export TPM2TOOLS_TCTI="swtpm:port=2321"
export TPMB="127.0.0.1:2321"
go run main.go --parentKeyType=ecc_srk --tpm-path=127.0.0.1:2321
@salrashid123
salrashid123 / jwtTPM.md
Last active January 22, 2026 11:10
Issue a TPM based JWT using `github.com/lestrrat-go/jwx/v3/jwt`

Issue a JWT using github.com/lestrrat-go/jwx/v3/jwt

basically, you just have to pass in a crypto.Signer that represents the TPM-based key

there are several crypto.Signers around, i'm just using my own from

https://github.com/salrashid123/tpmsigner

also see