Skip to content

Instantly share code, notes, and snippets.

View williamcroberts's full-sized avatar

William Roberts williamcroberts

View GitHub Profile
@williamcroberts
williamcroberts / tpm2_nvwrite_example.c
Created April 16, 2020 17:02
An Example of creating, writing, reading and deleting a TPM2.0 NV Index using the ESAPI.
#include <stdio.h>
#include <string.h>
#include <tss2/tss2_esys.h>
#include <tss2/tss2_rc.h>
#define DATA "hello world"
int main(int argc, char *argv[]) {
@williamcroberts
williamcroberts / gist:a3966e2131ba7e0adbf3ea757d36f15d
Created April 16, 2020 21:27
poor example of safe multithreaded sharing of ESYS_CONTEXT and ESYS_TR's
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <tss2/tss2_esys.h>
static ESYS_CONTEXT *ectx;
static ESYS_TR objectHandle;
@williamcroberts
williamcroberts / tpm2_aes_example.c
Created April 21, 2020 17:35
poor example of creating a TPM2 AES Key and using it
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <tss2/tss2_esys.h>
void create_primary(ESYS_CONTEXT *ectx, ESYS_TR *parent) {
@williamcroberts
williamcroberts / properties_fixed_dump.py
Created April 22, 2020 18:39
Given a properties output yaml file, will dump it into a C array
import yaml
y=yaml.load(open("props.yaml"))
for x in y:
print("{.property=%s, .value=0x%X}," % (x, y[x]['raw']))
@williamcroberts
williamcroberts / fedora32.ks
Last active May 13, 2020 22:41
Install kickstart file
logging --level=info
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext password
# user is needed for fedora? --disabled isn't an option
user --name="test" --password="password"
hostname fedoratest
wcrobert@wcrobert-MOBL1:~/workspace/tpm2-tools/tools$ find -name \*\.c | grep nv | xargs grep -lv on_arg_nv_index | wc -l
21
wcrobert@wcrobert-MOBL1:~/workspace/tpm2-tools/tools$ find -name \*\.c | grep nv | wc -l
21
@williamcroberts
williamcroberts / pkcs11-example.py
Created July 30, 2020 15:45
Example code to use pkcs11 from python to create a token, store a CKO_DATA object, and retrieve it.
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-2-Clause
'''
EXAMPLE CODE NOT INTENDED FOR PRODUCTION USE
Some Python code using ctypes to:
- enumerate the slot list
- find an empty slot
- Initialize a token
- Set the user pin
@williamcroberts
williamcroberts / mssim_command.sh
Created January 20, 2021 21:22
Send Control Commands to TPM Simulator
mssim_command() {
local raw="no"
local port="2322"
local ip="127.0.0.1"
while getopts "a:p:rh" opt; do
case ${opt} in
h)
echo "Send a command to the simulator"
@williamcroberts
williamcroberts / tss2-docker.sh
Created February 10, 2021 16:20
tss2-docker: examples and functions for running tpm2-software docker containers
#
# Source this file to get commands for launching containers like the tpm2-software CI system
# Example Usage:
# git clone https://github.com/tpm2-software/tpm2-tss.git
# cd tpm2-tss
# docker_run ubuntu-20.04
# Uses whatever arg1 is passed to it as container name. Useful for passing hashes from docker build results.
_docker_run() {
local b=$(basename $(pwd))
@williamcroberts
williamcroberts / build-tpm2-abrmd.sh
Created March 9, 2021 23:21
Building tpm2-abrmd from source on ubuntu-16.04
# On a docker ubuntu:16.04 base image, to build tpm2-abrmd I perform the following commands
sudo apt-get update
# The dependency list is fat here, because its deps for all the various projects, I trimmed it a little bit.
# but know you're getting more than you need.
sudo apt-get install -y \
autoconf-archive \
curl \
libcmocka0 \
libcmocka-dev \