Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / exponent.go
Created August 24, 2025 19:05
create ek rsa key with exponent
package main
import (
"crypto/x509"
"encoding/hex"
"encoding/pem"
"flag"
"io"
"log"
"net"
@salrashid123
salrashid123 / getName.md
Last active August 22, 2025 12:53
TPM "getName" from RSA|ECC PEM publickey

get the TPM "name" from the RSA or ECC PEM public key


RSA EK

tpm2_createek -c /tmp/ek.ctx -G rsa -u /tmp/ek.pub 
tpm2_readpublic -c /tmp/ek.ctx -o /tmp/ek.pem -f PEM -n /tmp/ek.name
@salrashid123
salrashid123 / main.py
Last active August 1, 2025 04:00
Adding x-request-reason to python google cloud clients
import google.auth
from google.oauth2 import service_account
from google.cloud import storage
from google.cloud import pubsub_v1
## requirements.txt
# google-cloud-storage
# google-cloud-pubsub
# requests
# google-api-python-client
@salrashid123
salrashid123 / tpm2_duplicateselct_policyAuthValue_policy_or.md
Last active July 31, 2025 23:27
PolicyDuplicateSelect and PolicyAuthValue bound PolicyDuplicate

PolicyDuplicateSelect and PolicyAuthValue bound PolicyDuplicate

The following transfer a key from TPM-A to TPM-B and demonstrates policies that prevent further duplication to TPM-C

ref:

@salrashid123
salrashid123 / envoy_ekm.md
Last active April 4, 2025 23:08
Envoy EKM : extract the EKM value for a TLS connection with envoy

The following diff extracts the EKM value for a given TLS connection and then surfaces that to LUA (which emits the EKM as a header to the backend)

the LUA config will log the EKM in trace logs

# envoy -c envoy_server.yaml -l trace
[2025-04-04 08:36:29.396][3334775][info][lua] [source/extensions/filters/common/lua/lua.cc:26] script log: >>>>>>>>>>>> EKM: XGurfnlqXyjXphhJrrCmHRoKXAwC7CjrD7vixHdqOIo=

which has the same derived EKM value as a sample client app (eg, golang)

@salrashid123
salrashid123 / openssl_ekm.md
Last active April 3, 2025 11:31
Openssl server and client which prints the EKM
@salrashid123
salrashid123 / openssl_server_tpm.md
Last active March 18, 2025 11:23
openssl server with TPM based private key

TLS with TPM based private key

Requires openssl-tpm2 provider

# export OPENSSL_MODULES=/usr/lib/x86_64-linux-gnu/ossl-modules/
# 
# cat /etc/ssl/openssl.cnf
# [openssl_init]
@salrashid123
salrashid123 / istio_gcp.md
Last active March 8, 2025 13:34
Istio with GCP OIDC Authorization

Simple demo of istio authorization rules using GCP OIDC tokens

Basically, this will allow inbound OIDC authentication and authorization for a service using a google issued id_token

Setup

First install minikube (i'm using kvm2 but you can use anything)

@salrashid123
salrashid123 / attestationkeyauth.go
Last active March 5, 2025 15:18
GCE Attestation Key based authentication
package main
/*
Authenticate to GCP using the GCP embedded vTPM AttestationKey
this specific implementation acquires a JWTAccessToken with scopes
https://github.com/salrashid123/gcp-vtpm-ek-ak/tree/main?tab=readme-ov-file#sign-jwt-with-tpm
1. first create a gce instance with confidentialcompute and vtpm enabled
@salrashid123
salrashid123 / hmacsha256.c
Created February 20, 2025 13:47
hmacsha256 with openssl
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/hmac.h>