1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/********************************************************************************/
/* */
/* IWG EK Index Parsing Utilities */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: ekutils.h 1015 2017-06-07 13:16:34Z kgoldman $ */
/* */
/* (c) Copyright IBM Corporation 2016, 2017. */
/* */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* */
/* Redistributions of source code must retain the above copyright notice, */
/* this list of conditions and the following disclaimer. */
/* */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* Neither the names of the IBM Corporation nor the names of its */
/* contributors may be used to endorse or promote products derived from */
/* this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/********************************************************************************/
#ifndef EKUTILS_H
#define EKUTILS_H
#include <openssl/x509.h>
#include <openssl/bn.h>
#include <tss2/tss.h>
/* legacy TCG IWG NV indexes */
#define EK_CERT_RSA_INDEX 0x01c00002
#define EK_NONCE_RSA_INDEX 0x01c00003
#define EK_TEMPLATE_RSA_INDEX 0x01c00004
#define EK_CERT_EC_INDEX 0x01c0000a
#define EK_NONCE_EC_INDEX 0x01c0000b
#define EK_TEMPLATE_EC_INDEX 0x01c0000c
#define MAX_ROOTS 100 /* 100 should be more than enough */
#ifdef __cplusplus
extern "C" {
#endif
TPM_RC readNvBufferMax(TSS_CONTEXT *tssContext,
uint32_t *nvBufferMax);
TPM_RC getIndexSize(TSS_CONTEXT *tssContext,
uint16_t *dataSize,
TPMI_RH_NV_INDEX nvIndex);
TPM_RC getIndexData(TSS_CONTEXT *tssContext,
unsigned char **buffer,
TPMI_RH_NV_INDEX nvIndex,
uint16_t dataSize);
TPM_RC getIndexContents(TSS_CONTEXT *tssContext,
unsigned char **buffer,
uint16_t *bufferSize,
TPMI_RH_NV_INDEX nvIndex);
void getRsaTemplate(TPMT_PUBLIC *tpmtPublic);
void getEccTemplate(TPMT_PUBLIC *tpmtPublic);
TPM_RC getIndexX509Certificate(TSS_CONTEXT *tssContext,
X509 **certificate,
TPMI_RH_NV_INDEX nvIndex);
uint32_t getPubkeyFromDerCertFile(RSA **rsaPkey,
X509 **x509,
const char *derCertificateFileName);
uint32_t getPubKeyFromX509Cert(RSA **rsaPkey,
X509 *x509);
TPM_RC getRootCertificateFilenames(char *rootFilename[],
unsigned int *rootFileCount,
const char *listFilename,
int print);
TPM_RC getCaStore(X509_STORE **caStore,
X509 *caCert[],
const char *rootFilename[],
unsigned int rootFileCount);
TPM_RC verifyCertificate(X509 *x509Certificate,
const char *rootFilename[],
unsigned int rootFileCount,
int print);
TPM_RC processEKNonce(TSS_CONTEXT *tssContext,
unsigned char **nonce,
uint16_t *nonceSize,
TPMI_RH_NV_INDEX ekNonceIndex,
int print);
TPM_RC processEKTemplate(TSS_CONTEXT *tssContext,
TPMT_PUBLIC *tpmtPublic,
TPMI_RH_NV_INDEX ekTemplateIndex,
int print);
TPM_RC processEKCertificate(TSS_CONTEXT *tssContext,
X509 **ekCertificate,
uint8_t **modulusBin,
int *modulusBytes,
TPMI_RH_NV_INDEX ekCertIndex,
int print);
TPM_RC convertX509ToDer(uint32_t *certLength,
unsigned char **certificate,
X509 *x509Certificate);
TPM_RC convertX509ToRsa(RSA **rsaPkey,
X509 *x509);
TPM_RC convertX509ToEc(EC_KEY **ecKey,
X509 *x509);
TPM_RC convertPemToX509(X509 **x509,
const char *pemCertificate);
TPM_RC convertCertificatePubKey(uint8_t **modulusBin,
int *modulusBytes,
X509 *ekCertificate,
TPMI_RH_NV_INDEX ekCertIndex,
int print);
TPM_RC processRoot(TSS_CONTEXT *tssContext,
TPMI_RH_NV_INDEX ekCertIndex,
const char *rootFilename[],
unsigned int rootFileCount,
int print);
TPM_RC processCreatePrimary(TSS_CONTEXT *tssContext,
TPM_HANDLE *keyHandle,
TPMI_RH_NV_INDEX ekCertIndex,
unsigned char *nonce,
uint16_t nonceSize,
TPMT_PUBLIC *tpmtPublicIn,
TPMT_PUBLIC *tpmtPublicOut,
unsigned int noFlush,
int print);
TPM_RC processValidatePrimary(uint8_t *publicKeyBin,
int publicKeyBytes,
TPMT_PUBLIC *tpmtPublic,
TPMI_RH_NV_INDEX ekCertIndex,
int print);
TPM_RC processPrimary(TSS_CONTEXT *tssContext,
TPM_HANDLE *keyHandle,
TPMI_RH_NV_INDEX ekCertIndex,
TPMI_RH_NV_INDEX ekNonceIndex,
TPMI_RH_NV_INDEX ekTemplateIndex,
unsigned int noFlush,
int print);
TPM_RC TSS_RSAGetKey(const BIGNUM **n,
const BIGNUM **e,
const BIGNUM **d,
const BIGNUM **p,
const BIGNUM **q,
const RSA *rsaKey);
int TSS_Pubkey_GetAlgorithm(EVP_PKEY *pkey);
#ifdef __cplusplus
}
#endif
#endif
|