TrustCore SDK NanoCert API reference  version 7.0
pkcs10.h
Go to the documentation of this file.
1 /*
2  * pkcs10.h
3  *
4  * PKCS #10 Header
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
27 /*------------------------------------------------------------------*/
28 
29 #ifndef __PKCS10_HEADER__
30 #define __PKCS10_HEADER__
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 #ifdef __ENABLE_MOCANA_PKCS10__
38 
39 /* PKCS#10 certificate request attributes as defined in PKCS#9 */
40 typedef struct requestAttributes
41 {
42  sbyte* pChallengePwd; /* ChallengePassword */
43  ubyte4 challengePwdLength;
44 
45  certExtensions *pExtensions;
46 } requestAttributes;
47 
48 /* This holds a P10 cert request attribute.
49  * An attribute consists of an OID and data. It is encoded as follows:
50  * SEQ {
51  * OID,
52  * SET OF
53  * ANY }
54  * There can be many attribute values for each OID.
55  * At the moment, we don't support multiple values for an attribute.
56  * The actual data can be ANY. It might be a SEQUENCE of some group of elements,
57  * it could be an OCTET STRING.
58  * When you set the value field, you should set it to a buffer containing the DER
59  * encoding of the "ANY". For example, if you are adding the Microsoft
60  * EnrollmentNameValuePair, and the pair is "CertificateTemplate" and "User",
61  * then the value will be
62  * 30 32
63  * 1e 26 <Unicode String of CertificateTemplate>
64  * 1e 08 <Unicode String of User>
65  * and the valueLen will be 52.
66  * The OID can be one of the *_OID values defined in /mss/src/asn1/oiddefs.h, or
67  * it can be your own buffer if the attribute OID is not defined in Mocana's
68  * code. The format of the OID is <len || OID>. That is, build a buffer, set the
69  * first byte to be the length and then the next length bytes to be the actual
70  * OID. For example, the subjectAltName OID would be { 3, 0x55, 0x1D, 0x11 }, or
71  * the Microsoft EnrollmentNameValuePair would be
72  * { 10, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0D, 0x01, 0x01 }
73  * Because the first byte is the length, you don't need to specify the length
74  * searately, and that's why there is no oidLen field.
75  */
76 typedef struct MocRequestAttr
77 {
78  ubyte *oid;
79  ubyte *pValue;
80  ubyte4 valueLen;
81 } MocRequestAttr;
82 
83 /* This is the same as requestAttributes, except it is extended.
84  * It contains a field for other attributes, just as the certExtensions struct
85  * contains a field for other extensions.
86  * If there are no other attributes, set pOtherAttrs to NULL and set
87  * otherAttrCount to 0. Otherwise, create an array of MocRequestAttr, set the
88  * fields in each entry to that array, and set pOtherAttrs to that array and
89  * otherAttrCount to the number of entries in the array.
90  */
91 typedef struct requestAttributesEx
92 {
93  sbyte *pChallengePwd;
94  ubyte4 challengePwdLength;
95 
96  certExtensions *pExtensions;
97 
98  MocRequestAttr *pOtherAttrs;
99  ubyte4 otherAttrCount;
100 } requestAttributesEx;
101 
102 /* outbound CSR BER encoded use FREE to delete */
103 
155 MOC_EXTERN MSTATUS PKCS10_GenerateCertReqFromDN(AsymmetricKey* pKey,
156  ubyte signAlgo,
157  const certDistinguishedName *pCertInfo,
158  const requestAttributes *pReqAttrs, /* can be null */
159  ubyte** ppCertReq,
160  ubyte4* pCertReqLength);
161 
222 MOC_EXTERN MSTATUS PKCS10_GenerateCertReqFromASN1Name(AsymmetricKey* pKey,
223  ubyte signAlgo,
224  const ubyte* pASN1Name,
225  ubyte4 asn1NameLen,
226  const requestAttributes *pReqAttrs, /* can be null */
227  ubyte** ppCertReq,
228  ubyte4* pCertReqLength);
229 
268 MOC_EXTERN MSTATUS PKCS10_CertReqToCSR( const ubyte* pCertReq, ubyte4 pCertReqLength,
269  ubyte** ppCsr, ubyte4* pCsrLength);
270 
322 MOC_EXTERN MSTATUS PKCS10_GenerateCertReqFromDNEx (
323  AsymmetricKey* pKey,
324  ubyte signAlgo,
325  const certDistinguishedName *pCertInfo,
326  const requestAttributesEx *pReqAttrs, /* can be null */
327  ubyte** ppCertReq,
328  ubyte4* pCertReqLength
329  );
330 
331 #endif /* __ENABLE_MOCANA_PKCS10__ */
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* __PKCS10_HEADER__ */
MOC_EXTERN MSTATUS PKCS10_GenerateCertReqFromDN(AsymmetricKey *pKey, ubyte signAlgo, const certDistinguishedName *pCertInfo, const requestAttributes *pReqAttrs, ubyte **ppCertReq, ubyte4 *pCertReqLength)
Generate a DER-encoded PKCS&#160;#10 certificate request for a given distinguished name.
MOC_EXTERN MSTATUS PKCS10_CertReqToCSR(const ubyte *pCertReq, ubyte4 pCertReqLength, ubyte **ppCsr, ubyte4 *pCsrLength)
Generate a text representation of a DER-encoded certificate request.
Distinguished name data (names and start/end dates) to support certificate generation.
Definition: ca_mgmt.h:424
Container for a certificate&#39;s version 3 extensions.
Definition: ca_mgmt.h:560
MOC_EXTERN MSTATUS PKCS10_GenerateCertReqFromASN1Name(AsymmetricKey *pKey, ubyte signAlgo, const ubyte *pASN1Name, ubyte4 asn1NameLen, const requestAttributes *pReqAttrs, ubyte **ppCertReq, ubyte4 *pCertReqLength)
Generate a DER-encoded PKCS&#160;#10 certificate request for a given ASN.1 name.
MOC_EXTERN MSTATUS PKCS10_GenerateCertReqFromDNEx(AsymmetricKey *pKey, ubyte signAlgo, const certDistinguishedName *pCertInfo, const requestAttributesEx *pReqAttrs, ubyte **ppCertReq, ubyte4 *pCertReqLength)
This is the same as PKCS10_GenerateCertReqFromDN, except that it takes a requestAttributesEx.