1*5c591343SA. Cody Schuffelen /* Microsoft Reference Implementation for TPM 2.0 2*5c591343SA. Cody Schuffelen * 3*5c591343SA. Cody Schuffelen * The copyright in this software is being made available under the BSD License, 4*5c591343SA. Cody Schuffelen * included below. This software may be subject to other third party and 5*5c591343SA. Cody Schuffelen * contributor rights, including patent rights, and no such rights are granted 6*5c591343SA. Cody Schuffelen * under this license. 7*5c591343SA. Cody Schuffelen * 8*5c591343SA. Cody Schuffelen * Copyright (c) Microsoft Corporation 9*5c591343SA. Cody Schuffelen * 10*5c591343SA. Cody Schuffelen * All rights reserved. 11*5c591343SA. Cody Schuffelen * 12*5c591343SA. Cody Schuffelen * BSD License 13*5c591343SA. Cody Schuffelen * 14*5c591343SA. Cody Schuffelen * Redistribution and use in source and binary forms, with or without modification, 15*5c591343SA. Cody Schuffelen * are permitted provided that the following conditions are met: 16*5c591343SA. Cody Schuffelen * 17*5c591343SA. Cody Schuffelen * Redistributions of source code must retain the above copyright notice, this list 18*5c591343SA. Cody Schuffelen * of conditions and the following disclaimer. 19*5c591343SA. Cody Schuffelen * 20*5c591343SA. Cody Schuffelen * Redistributions in binary form must reproduce the above copyright notice, this 21*5c591343SA. Cody Schuffelen * list of conditions and the following disclaimer in the documentation and/or 22*5c591343SA. Cody Schuffelen * other materials provided with the distribution. 23*5c591343SA. Cody Schuffelen * 24*5c591343SA. Cody Schuffelen * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" 25*5c591343SA. Cody Schuffelen * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26*5c591343SA. Cody Schuffelen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27*5c591343SA. Cody Schuffelen * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28*5c591343SA. Cody Schuffelen * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29*5c591343SA. Cody Schuffelen * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30*5c591343SA. Cody Schuffelen * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31*5c591343SA. Cody Schuffelen * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32*5c591343SA. Cody Schuffelen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33*5c591343SA. Cody Schuffelen * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34*5c591343SA. Cody Schuffelen */ 35*5c591343SA. Cody Schuffelen //** Introduction 36*5c591343SA. Cody Schuffelen // This file contains the macro and structure definitions for the X509 commands and 37*5c591343SA. Cody Schuffelen // functions. 38*5c591343SA. Cody Schuffelen 39*5c591343SA. Cody Schuffelen #ifndef _X509_H_ 40*5c591343SA. Cody Schuffelen #define _X509_H_ 41*5c591343SA. Cody Schuffelen 42*5c591343SA. Cody Schuffelen //** Includes 43*5c591343SA. Cody Schuffelen 44*5c591343SA. Cody Schuffelen #include "Tpm.h" 45*5c591343SA. Cody Schuffelen #include "TpmASN1.h" 46*5c591343SA. Cody Schuffelen 47*5c591343SA. Cody Schuffelen //** Defined Constants 48*5c591343SA. Cody Schuffelen 49*5c591343SA. Cody Schuffelen //*** X509 Application-specific types 50*5c591343SA. Cody Schuffelen #define X509_SELECTION 0xA0 51*5c591343SA. Cody Schuffelen #define X509_ISSUER_UNIQUE_ID 0xA1 52*5c591343SA. Cody Schuffelen #define X509_SUBJECT_UNIQUE_ID 0xA2 53*5c591343SA. Cody Schuffelen #define X509_EXTENSIONS 0xA3 54*5c591343SA. Cody Schuffelen 55*5c591343SA. Cody Schuffelen // These defines give the order in which values appear in the TBScertificate 56*5c591343SA. Cody Schuffelen // of an x.509 certificate. These values are used to index into an array of 57*5c591343SA. Cody Schuffelen // 58*5c591343SA. Cody Schuffelen #define ENCODED_SIZE_REF 0 59*5c591343SA. Cody Schuffelen #define VERSION_REF (ENCODED_SIZE_REF + 1) 60*5c591343SA. Cody Schuffelen #define SERIAL_NUMBER_REF (VERSION_REF + 1) 61*5c591343SA. Cody Schuffelen #define SIGNATURE_REF (SERIAL_NUMBER_REF + 1) 62*5c591343SA. Cody Schuffelen #define ISSUER_REF (SIGNATURE_REF + 1) 63*5c591343SA. Cody Schuffelen #define VALIDITY_REF (ISSUER_REF + 1) 64*5c591343SA. Cody Schuffelen #define SUBJECT_KEY_REF (VALIDITY_REF + 1) 65*5c591343SA. Cody Schuffelen #define SUBJECT_PUBLIC_KEY_REF (SUBJECT_KEY_REF + 1) 66*5c591343SA. Cody Schuffelen #define EXTENSIONS_REF (SUBJECT_PUBLIC_KEY_REF + 1) 67*5c591343SA. Cody Schuffelen #define REF_COUNT (EXTENSIONS_REF + 1) 68*5c591343SA. Cody Schuffelen 69*5c591343SA. Cody Schuffelen //** Structures 70*5c591343SA. Cody Schuffelen 71*5c591343SA. Cody Schuffelen // Used to access the fields of a TBSsignature some of which are in the in_CertifyX509 72*5c591343SA. Cody Schuffelen // structure and some of which are in the out_CertifyX509 structure. 73*5c591343SA. Cody Schuffelen typedef struct stringRef 74*5c591343SA. Cody Schuffelen { 75*5c591343SA. Cody Schuffelen BYTE *buf; 76*5c591343SA. Cody Schuffelen INT16 len; 77*5c591343SA. Cody Schuffelen } stringRef; 78*5c591343SA. Cody Schuffelen 79*5c591343SA. Cody Schuffelen // This is defined to avoid bit by bit comparisons within a UINT32 80*5c591343SA. Cody Schuffelen typedef union x509KeyUsageUnion { 81*5c591343SA. Cody Schuffelen TPMA_X509_KEY_USAGE x509; 82*5c591343SA. Cody Schuffelen UINT32 integer; 83*5c591343SA. Cody Schuffelen } x509KeyUsageUnion; 84*5c591343SA. Cody Schuffelen 85*5c591343SA. Cody Schuffelen //** Global X509 Constants 86*5c591343SA. Cody Schuffelen // These values are instanced by X509_spt.c and referenced by other X509-related 87*5c591343SA. Cody Schuffelen // files. 88*5c591343SA. Cody Schuffelen 89*5c591343SA. Cody Schuffelen // This is the DER-encoded value for the Key Usage OID (2.5.29.15). This is the 90*5c591343SA. Cody Schuffelen // full OID, not just the numeric value 91*5c591343SA. Cody Schuffelen #define OID_KEY_USAGE_EXTENSION_VALUE 0x06, 0x03, 0x55, 0x1D, 0x0F 92*5c591343SA. Cody Schuffelen MAKE_OID(_KEY_USAGE_EXTENSION); 93*5c591343SA. Cody Schuffelen 94*5c591343SA. Cody Schuffelen // This is the DER-encoded value for the TCG-defined TPMA_OBJECT OID 95*5c591343SA. Cody Schuffelen // (2.23.133.10.1.1.1) 96*5c591343SA. Cody Schuffelen #define OID_TCG_TPMA_OBJECT_VALUE 0x06, 0x07, 0x67, 0x81, 0x05, 0x0a, 0x01, \ 97*5c591343SA. Cody Schuffelen 0x01, 0x01 98*5c591343SA. Cody Schuffelen MAKE_OID(_TCG_TPMA_OBJECT); 99*5c591343SA. Cody Schuffelen 100*5c591343SA. Cody Schuffelen #ifdef _X509_SPT_ 101*5c591343SA. Cody Schuffelen // If a bit is SET in KEY_USAGE_SIGN is also SET in keyUsage then 102*5c591343SA. Cody Schuffelen // the associated key has to have 'sign' SET. 103*5c591343SA. Cody Schuffelen const x509KeyUsageUnion KEY_USAGE_SIGN = 104*5c591343SA. Cody Schuffelen { TPMA_X509_KEY_USAGE_INITIALIZER( 105*5c591343SA. Cody Schuffelen /* bits_at_0 */ 0, /* decipheronly */ 0, /* encipheronly */ 0, 106*5c591343SA. Cody Schuffelen /* crlsign */ 1, /* keycertsign */ 1, /* keyagreement */ 0, 107*5c591343SA. Cody Schuffelen /* dataencipherment */ 0, /* keyencipherment */ 0, /* nonrepudiation */ 0, 108*5c591343SA. Cody Schuffelen /* digitalsignature */ 1) }; 109*5c591343SA. Cody Schuffelen // If a bit is SET in KEY_USAGE_DECRYPT is also SET in keyUsage then 110*5c591343SA. Cody Schuffelen // the associated key has to have 'decrypt' SET. 111*5c591343SA. Cody Schuffelen const x509KeyUsageUnion KEY_USAGE_DECRYPT = 112*5c591343SA. Cody Schuffelen { TPMA_X509_KEY_USAGE_INITIALIZER( 113*5c591343SA. Cody Schuffelen /* bits_at_0 */ 0, /* decipheronly */ 1, /* encipheronly */ 1, 114*5c591343SA. Cody Schuffelen /* crlsign */ 0, /* keycertsign */ 0, /* keyagreement */ 1, 115*5c591343SA. Cody Schuffelen /* dataencipherment */ 1, /* keyencipherment */ 1, /* nonrepudiation */ 0, 116*5c591343SA. Cody Schuffelen /* digitalsignature */ 0) }; 117*5c591343SA. Cody Schuffelen #else 118*5c591343SA. Cody Schuffelen extern x509KeyUsageUnion KEY_USAGE_SIGN; 119*5c591343SA. Cody Schuffelen extern x509KeyUsageUnion KEY_USAGE_DECRYPT; 120*5c591343SA. Cody Schuffelen #endif 121*5c591343SA. Cody Schuffelen 122*5c591343SA. Cody Schuffelen #endif // _X509_H_ 123