HP-UX Trusted Computing Services A.01.00 Administrator's Guide
B Sample TSS Application
This sample program creates and registers a new key in TSS. The new key is then used to encrypt
a secret. The results are displayed in the output.
Makefile.hpux and example.c are located in the /opt/tcs/src/example/ directory. The
make –f Makefile.hpux command compiles both 32-bit and 64-bit versions of example.c.
Example of Makefile.hpux:
CC=cc
INC=/opt/tcs/include
LIBS=-L/usr/lib -ltspi -lcrypto
CFLAGS=-Ae -I$(INC) -DHPUX -g
all: example example64
example: example.c
$(CC) $(CFLAGS) -o example example.c $(LIBS)
example64: example.c
$(CC) $(CFLAGS) +DD64 -o example64 example.c $(LIBS)
clean:
rm -f *.o *~ core example example64
Example of example.c:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <trousers/tss.h>
#include <trousers/trousers.h>
static TSS_UUID SRK_UUID = TSS_UUID_SRK; // SRK
int parseOptions(int argc, char **argv);
TSS_UUID * uuidGen(TSS_HTPM hTPM);
void usage();
void printHex(BYTE *blob, UINT32 blobLen);
char *host = NULL;
char *password = NULL;
char *secret = "secret";
int main(int argc, char **argv)
{
TSS_RESULT tResult;
TSS_HCONTEXT hContext;
TSS_HTPM hTpm;
int i, retcode = -1;
UINT32 uiSize;
TSS_FLAG keyInitFlags = TSS_KEY_TYPE_BIND | TSS_KEY_SIZE_2048 |
TSS_KEY_VOLATILE | TSS_KEY_MIGRATABLE;
TSS_FLAG dataInitFlags = TSS_ENCDATA_BIND;
TSS_HKEY hKey, hSRK;
TSS_HENCDATA hEncData;
TSS_HPOLICY hSRKp, hPolicy;
BYTE *blob = NULL;
UINT32 blobLen;
TSS_UUID *keyUUID;
if(parseOptions(argc, argv) != 0) {
goto out;
}
// Ensure that data to be 'binded' is no larger than our keysize
if(strlen(secret) > 256) {
fprintf(stderr, "Error: Secret to be bound to TPM is too large. Please limit the secret to 256 characters\n");
}
// Start a TSS session
tResult = Tspi_Context_Create(&hContext);
if (tResult != TSS_SUCCESS) {
fprintf(stderr, "Tspi_Context_Create failed. Error: %s\n", Trspi_Error_String(tResult));
goto out;
}
45