Skip to content

Instantly share code, notes, and snippets.

View williamcroberts's full-sized avatar

William Roberts williamcroberts

View GitHub Profile
@williamcroberts
williamcroberts / setup.sh
Last active May 4, 2021 23:36
Ubuntu 20.10 Installer and Demo of tpm2-tss
#!/usr/bin/env bash
# SPDX: BSD-3-Clause
# Usage:
# ./script.sh or bash script.sh
#
# Arguments:
# (optional) arg1: A aorking directory to use. Defaults to $HOME.
#
# Example: mkdir tmp
@williamcroberts
williamcroberts / example.c
Last active March 23, 2021 20:28
Example of Bounds Checking At Compile Time
typedef union TPM2B_FOO TPM2B_FOO;
union TPM2B_FOO {
struct {
uint16_t size;
uint8_t data[32];
}t;
TPM2B b;
};
int main(int argc, char *argv[]) {
@williamcroberts
williamcroberts / send.py
Last active March 24, 2021 00:59
Example (UNTESTED) Python script to read from stdin, write to /dev/tpm0 or argv[1], get the TPM response and write it to stdout
#!/usr/bin/env python3
import sys
TSS2_HEADER_SIZE=14
path = sys.argv[1] if len(sys.argv) > 1 else "/dev/tpm0"
with open(path, "r+b") as f:
@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 \
@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 / 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 / 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
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 / 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
@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']))