/********************************************************************************/ /* */ /* TPM 2.0 Attestation - Client EK and EK certificate */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ /* */ /* (c) Copyright IBM Corporation 2016 - 2019. */ /* */ /* 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. */ /********************************************************************************/ /* This program provisions an EK certificate. It is required only for a SW TPM, which does not, of course, come with a certificate. NOTE This is a one time operation unless the EPS is changed, typically through the TSS regression test. I suggest saving the NVChip file. Steps implemented: Create a primary key using the default IWG template Create a certificate using the CA key cakey.pem Create NV Index if not already provisioned. Write the certificate to NV. */ #include #include #include #include /* Windows 10 crypto API clashes with openssl */ #ifdef TPM_WINDOWS #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #endif #include #include #include #include #include "ekutils.h" /* local function prototypes */ static void printUsage(void); static TPM_RC defineEKCertIndex(TSS_CONTEXT *tssContext, uint32_t certLength, TPMI_RH_NV_INDEX nvIndex, const char *platformPassword); static TPM_RC storeEkCertificate(TSS_CONTEXT *tssContext, uint32_t certLength, unsigned char *certificate, TPMI_RH_NV_INDEX nvIndex, const char *platformPassword); int vverbose = 0; extern int tssUtilsVerbose; int main(int argc, char *argv[]) { int rc = 0; int i; /* argc iterator */ TSS_CONTEXT *tssContext = NULL; int noFlush = FALSE; const char *certificateFilename = NULL; TPMI_RH_NV_INDEX ekCertIndex = EK_CERT_RSA_INDEX; /* the CA for endorsement key certificates */ const char *caKeyFileName = NULL; const char *caKeyPassword = ""; const char *platformPassword = NULL; TPMT_PUBLIC tpmtPublicOut; /* primary key public part */ char *x509CertString = NULL; char *pemCertString = NULL; uint32_t certLength; unsigned char *certificate = NULL; /* FIXME may be better from command line or config file */ char *subjectEntries[] = { "US", /* 0 country */ "NY", /* 1 state */ "Yorktown", /* 2 locality*/ "IBM", /* 3 organization */ NULL, /* 4 organization unit */ "IBM's SW TPM", /* 5 common name */ NULL /* 6 email */ }; /* FIXME should come from root certificate, cacert.pem, cacertec.pem */ char *rootIssuerEntriesRsa[] = { "US" , "NY" , "Yorktown" , "IBM" , NULL , "EK CA" , NULL }; char *rootIssuerEntriesEc[] = { "US" , "NY" , "Yorktown" , "IBM" , NULL , "EK EC CA" , NULL }; /* default RSA */ char **issuerEntries = rootIssuerEntriesRsa; size_t issuerEntriesSize = sizeof(rootIssuerEntriesRsa)/sizeof(char *); setvbuf(stdout, 0, _IONBF, 0); /* output may be going through pipe to log file */ TSS_SetProperty(NULL, TPM_TRACE_LEVEL, "1"); tssUtilsVerbose = FALSE; /* command line argument defaults */ for (i=1 ; (i