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