VirtualBox

source: vbox/trunk/include/iprt/crypto/x509.h@ 53402

Last change on this file since 53402 was 52600, checked in by vboxsync, 10 years ago

IPRT: Added support for microsoft timestamp counter signatures. This required making the PKCS #7 code accept some of the CMS (RFC-5652) stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.4 KB
Line 
1/** @file
2 * IPRT - Crypto - X.509, Public Key and Privilege Management Infrastructure.
3 */
4
5/*
6 * Copyright (C) 2014 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_crypto_x509_h
27#define ___iprt_crypto_x509_h
28
29#include <iprt/asn1.h>
30
31
32RT_C_DECLS_BEGIN
33
34
35/** @defgroup grp_rt_crypto Crypto
36 * @ingroup grp_rt
37 * @{
38 */
39
40/** @defgroup grp_rt_crx509 RTCrX509 - Public Key and Privilege Management Infrastructure.
41 * @{
42 */
43
44/**
45 * X.509 algorithm identifier (IPRT representation).
46 */
47typedef struct RTCRX509ALGORITHMIDENTIFIER
48{
49 /** The sequence making up this algorithm identifier. */
50 RTASN1SEQUENCECORE SeqCore;
51 /** The algorithm object ID. */
52 RTASN1OBJID Algorithm;
53 /** Optional parameters specified by the algorithm. */
54 RTASN1DYNTYPE Parameters;
55} RTCRX509ALGORITHMIDENTIFIER;
56/** Poitner to the IPRT representation of a X.509 algorithm identifier. */
57typedef RTCRX509ALGORITHMIDENTIFIER *PRTCRX509ALGORITHMIDENTIFIER;
58/** Poitner to the const IPRT representation of a X.509 algorithm identifier. */
59typedef RTCRX509ALGORITHMIDENTIFIER const *PCRTCRX509ALGORITHMIDENTIFIER;
60RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509ALGORITHMIDENTIFIER, RTDECL, RTCrX509AlgorithmIdentifier, SeqCore.Asn1Core);
61RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRX509ALGORITHMIDENTIFIERS, RTCRX509ALGORITHMIDENTIFIER, RTDECL, RTCrX509AlgorithmIdentifiers);
62
63/**
64 * Tries to convert an X.509 digest algorithm ID into a RTDIGESTTYPE value.
65 *
66 * @returns Valid RTDIGESTTYPE on success, RTDIGESTTYPE_INVALID on failure.
67 * @param pThis The IPRT representation of a X.509 algorithm
68 * identifier object.
69 */
70RTDECL(RTDIGESTTYPE) RTCrX509AlgorithmIdentifier_QueryDigestType(PCRTCRX509ALGORITHMIDENTIFIER pThis);
71
72/**
73 * Tries to figure the digest size of an X.509 digest algorithm ID.
74 *
75 * @returns The digest size in bytes, UINT32_MAX if unknown digest.
76 * @param pThis The IPRT representation of a X.509 algorithm
77 * identifier object.
78 */
79RTDECL(uint32_t) RTCrX509AlgorithmIdentifier_QueryDigestSize(PCRTCRX509ALGORITHMIDENTIFIER pThis);
80
81RTDECL(int) RTCrX509AlgorithmIdentifier_CompareWithString(PCRTCRX509ALGORITHMIDENTIFIER pThis, const char *pszObjId);
82
83/**
84 * Compares a digest with an encrypted digest algorithm, checking if they
85 * specify the same digest.
86 *
87 * @returns 0 if same digest, -1 if the digest is unknown, 1 if the encrypted
88 * digest does not match.
89 * @param pDigest The digest algorithm.
90 * @param pEncryptedDigest The encrypted digest algorithm.
91 */
92RTDECL(int) RTCrX509AlgorithmIdentifier_CompareDigestAndEncryptedDigest(PCRTCRX509ALGORITHMIDENTIFIER pDigest,
93 PCRTCRX509ALGORITHMIDENTIFIER pEncryptedDigest);
94
95/** @name Typical Digest Algorithm OIDs.
96 * @{ */
97#define RTCRX509ALGORITHMIDENTIFIERID_MD2 "1.2.840.113549.2.2"
98#define RTCRX509ALGORITHMIDENTIFIERID_MD4 "1.2.840.113549.2.4"
99#define RTCRX509ALGORITHMIDENTIFIERID_MD5 "1.2.840.113549.2.5"
100#define RTCRX509ALGORITHMIDENTIFIERID_SHA1 "1.3.14.3.2.26"
101#define RTCRX509ALGORITHMIDENTIFIERID_SHA256 "2.16.840.1.101.3.4.2.1"
102#define RTCRX509ALGORITHMIDENTIFIERID_SHA384 "2.16.840.1.101.3.4.2.2"
103#define RTCRX509ALGORITHMIDENTIFIERID_SHA512 "2.16.840.1.101.3.4.2.3"
104#define RTCRX509ALGORITHMIDENTIFIERID_SHA224 "2.16.840.1.101.3.4.2.4"
105#define RTCRX509ALGORITHMIDENTIFIERID_SHA512T224 "2.16.840.1.101.3.4.2.5"
106#define RTCRX509ALGORITHMIDENTIFIERID_SHA512T256 "2.16.840.1.101.3.4.2.6"
107#define RTCRX509ALGORITHMIDENTIFIERID_WHIRLPOOL "1.0.10118.3.0.55"
108/** @} */
109
110/** @name Encrypted Digest Algorithm OIDs.
111 * @remarks The PKCS variants are the default ones, alternative OID are marked
112 * as such.
113 * @{ */
114#define RTCRX509ALGORITHMIDENTIFIERID_RSA "1.2.840.113549.1.1.1"
115#define RTCRX509ALGORITHMIDENTIFIERID_MD2_WITH_RSA "1.2.840.113549.1.1.2"
116#define RTCRX509ALGORITHMIDENTIFIERID_MD4_WITH_RSA "1.2.840.113549.1.1.3"
117#define RTCRX509ALGORITHMIDENTIFIERID_MD5_WITH_RSA "1.2.840.113549.1.1.4"
118#define RTCRX509ALGORITHMIDENTIFIERID_SHA1_WITH_RSA "1.2.840.113549.1.1.5"
119#define RTCRX509ALGORITHMIDENTIFIERID_SHA256_WITH_RSA "1.2.840.113549.1.1.11"
120#define RTCRX509ALGORITHMIDENTIFIERID_SHA384_WITH_RSA "1.2.840.113549.1.1.12"
121#define RTCRX509ALGORITHMIDENTIFIERID_SHA512_WITH_RSA "1.2.840.113549.1.1.13"
122#define RTCRX509ALGORITHMIDENTIFIERID_SHA224_WITH_RSA "1.2.840.113549.1.1.14"
123/** @} */
124
125
126
127
128/**
129 * One X.509 AttributeTypeAndValue (IPRT representation).
130 */
131typedef struct RTCRX509ATTRIBUTETYPEANDVALUE
132{
133 /** Sequence core. */
134 RTASN1SEQUENCECORE SeqCore;
135 /** The attribute type (object ID). */
136 RTASN1OBJID Type;
137 /** The attribute value (what it is is defined by Type). */
138 RTASN1DYNTYPE Value;
139} RTCRX509ATTRIBUTETYPEANDVALUE;
140/** Pointer to a X.509 AttributeTypeAndValue (IPRT representation). */
141typedef RTCRX509ATTRIBUTETYPEANDVALUE *PRTCRX509ATTRIBUTETYPEANDVALUE;
142/** Pointer to a const X.509 AttributeTypeAndValue (IPRT representation). */
143typedef RTCRX509ATTRIBUTETYPEANDVALUE const *PCRTCRX509ATTRIBUTETYPEANDVALUE;
144RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509ATTRIBUTETYPEANDVALUE, RTDECL, RTCrX509AttributeTypeAndValue, SeqCore.Asn1Core);
145RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRX509ATTRIBUTETYPEANDVALUES, RTCRX509ATTRIBUTETYPEANDVALUE, RTDECL, RTCrX509AttributeTypeAndValues);
146
147RTASN1TYPE_ALIAS(RTCRX509RELATIVEDISTINGUISHEDNAME, RTCRX509ATTRIBUTETYPEANDVALUES, RTCrX509RelativeDistinguishedName, RTCrX509AttributeTypeAndValues);
148
149
150RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509NAME, RTCRX509RELATIVEDISTINGUISHEDNAME, RTDECL, RTCrX509Name);
151RTDECL(int) RTCrX509Name_CheckSanity(PCRTCRX509NAME pName, uint32_t fFlags, PRTERRINFO pErrInfo, const char *pszErrorTag);
152RTDECL(bool) RTCrX509Name_MatchByRfc5280(PCRTCRX509NAME pLeft, PCRTCRX509NAME pRight);
153
154/**
155 * Name constraint matching (RFC-5280).
156 *
157 * @returns true on match, false on mismatch.
158 * @param pConstraint The constraint name.
159 * @param pName The name to match against the constraint.
160 * @sa RTCrX509GeneralName_ConstraintMatch,
161 * RTCrX509RelativeDistinguishedName_ConstraintMatch
162 */
163RTDECL(bool) RTCrX509Name_ConstraintMatch(PCRTCRX509NAME pConstraint, PCRTCRX509NAME pName);
164RTDECL(int) RTCrX509Name_RecodeAsUtf8(PRTCRX509NAME pThis, PCRTASN1ALLOCATORVTABLE pAllocator);
165
166/**
167 * Matches the directory name against a comma separated list of the comonent
168 * strings (case sensitive).
169 *
170 * @returns true if match, false if mismatch.
171 * @param pThis The name object.
172 * @param pszString The string to match against. For example:
173 * "C=US, ST=California, L=Redwood Shores, O=Oracle Corporation"
174 *
175 * @remarks This is doing a straight compare, no extra effort is expended in
176 * dealing with different component order. If the component order
177 * differs, there won't be any match.
178 */
179RTDECL(bool) RTCrX509Name_MatchWithString(PCRTCRX509NAME pThis, const char *pszString);
180
181/**
182 * Formats the name as a command separated list of components with type
183 * prefixes.
184 *
185 * The output of this function is suitable for use with
186 * RTCrX509Name_MatchWithString.
187 *
188 * @returns IPRT status code.
189 * @param pThis The name object.
190 * @param pszBuf The output buffer.
191 * @param cbBuf The size of the output buffer.
192 * @param pcbActual Where to return the number of bytes required for the
193 * output, including the null terminator character.
194 * Optional.
195 */
196RTDECL(int) RTCrX509Name_FormatAsString(PCRTCRX509NAME pThis, char *pszBuf, size_t cbBuf, size_t *pcbActual);
197
198
199
200typedef enum RTCRX509GENERALNAMECHOICE
201{
202 RTCRX509GENERALNAMECHOICE_INVALID = 0,
203 RTCRX509GENERALNAMECHOICE_OTHER_NAME,
204 RTCRX509GENERALNAMECHOICE_RFC822_NAME,
205 RTCRX509GENERALNAMECHOICE_DNS_NAME,
206 RTCRX509GENERALNAMECHOICE_X400_ADDRESS,
207 RTCRX509GENERALNAMECHOICE_DIRECTORY_NAME,
208 RTCRX509GENERALNAMECHOICE_EDI_PARTY_NAME,
209 RTCRX509GENERALNAMECHOICE_URI,
210 RTCRX509GENERALNAMECHOICE_IP_ADDRESS,
211 RTCRX509GENERALNAMECHOICE_REGISTERED_ID,
212 RTCRX509GENERALNAMECHOICE_END,
213 RTCRX509GENERALNAMECHOICE_32BIT_HACK = 0x7fffffff
214} RTCRX509GENERALNAMECHOICE;
215
216/**
217 * One X.509 GeneralName (IPRT representation).
218 *
219 * This is represented as a union. Use the RTCRX509GENERALNAME_IS_XXX predicate
220 * macros to figure out which member is valid (Asn1Core is always valid).
221 */
222typedef struct RTCRX509GENERALNAME
223{
224 /** Dummy ASN.1 record, not encoded. */
225 RTASN1DUMMY Dummy;
226 /** The value allocation. */
227 RTASN1ALLOCATION Allocation;
228 /** The choice of value. */
229 RTCRX509GENERALNAMECHOICE enmChoice;
230 /** The value union. */
231 union
232 {
233 /** Tag 0: Other. */
234 struct
235 {
236 /** Context tag 0. */
237 RTASN1CONTEXTTAG0 CtxTag0;
238 /** User defined. */
239 RTASN1DYNTYPE Other;
240 } *pT0;
241 /** Tag 1: RFC-822 Name. */
242 PRTASN1STRING pT1_Rfc822;
243 /** Tag 2: DNS name. */
244 PRTASN1STRING pT2_DnsName;
245 /** Tag 3: X.400 Address. */
246 struct
247 {
248 /** Context tag 3. */
249 RTASN1CONTEXTTAG3 CtxTag3;
250 /** Later. */
251 RTASN1DYNTYPE X400Address;
252 } *pT3;
253 /** Tag 4: Directory Name. */
254 struct
255 {
256 /** Context tag 4. */
257 RTASN1CONTEXTTAG4 CtxTag4;
258 /** Directory name. */
259 RTCRX509NAME DirectoryName;
260 } *pT4;
261 /** Tag 5: EDI Party Name. */
262 struct
263 {
264 /** Context tag 5. */
265 RTASN1CONTEXTTAG5 CtxTag5;
266 /** Later. */
267 RTASN1DYNTYPE EdiPartyName;
268 } *pT5;
269 /** Tag 6: URI. */
270 PRTASN1STRING pT6_Uri;
271 /** Tag 7: IP address. Either 4/8 (IPv4) or 16/32 (IPv16) octets long. */
272 PRTASN1OCTETSTRING pT7_IpAddress;
273 /** Tag 8: Registered ID. */
274 PRTASN1OBJID pT8_RegisteredId;
275 } u;
276} RTCRX509GENERALNAME;
277/** Pointer to the IPRT representation of an X.509 general name. */
278typedef RTCRX509GENERALNAME *PRTCRX509GENERALNAME;
279/** Pointer to the const IPRT representation of an X.509 general name. */
280typedef RTCRX509GENERALNAME const *PCRTCRX509GENERALNAME;
281RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509GENERALNAME, RTDECL, RTCrX509GeneralName, Dummy.Asn1Core);
282
283/** @name RTCRX509GENERALNAME tag predicates.
284 * @{ */
285#define RTCRX509GENERALNAME_IS_OTHER_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_OTHER_NAME)
286#define RTCRX509GENERALNAME_IS_RFC822_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_RFC822_NAME)
287#define RTCRX509GENERALNAME_IS_DNS_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_DNS_NAME)
288#define RTCRX509GENERALNAME_IS_X400_ADDRESS(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_X400_ADDRESS)
289#define RTCRX509GENERALNAME_IS_DIRECTORY_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_DIRECTORY_NAME)
290#define RTCRX509GENERALNAME_IS_EDI_PARTY_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_EDI_PARTY_NAME)
291#define RTCRX509GENERALNAME_IS_URI(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_URI)
292#define RTCRX509GENERALNAME_IS_IP_ADDRESS(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_IP_ADDRESS)
293#define RTCRX509GENERALNAME_IS_REGISTERED_ID(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_REGISTERED_ID)
294/** @} */
295
296
297RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509GENERALNAMES, RTCRX509GENERALNAME, RTDECL, RTCrX509GeneralNames);
298RTDECL(bool) RTCrX509GeneralName_ConstraintMatch(PCRTCRX509GENERALNAME pConstraint, PCRTCRX509GENERALNAME pName);
299
300
301/**
302 * X.509 Validity (IPRT representation).
303 */
304typedef struct RTCRX509VALIDITY
305{
306 /** Core sequence bits. */
307 RTASN1SEQUENCECORE SeqCore;
308 /** Effective starting. */
309 RTASN1TIME NotBefore;
310 /** Expires after. */
311 RTASN1TIME NotAfter;
312} RTCRX509VALIDITY;
313/** Pointer to the IPRT representation of an X.509 validity sequence. */
314typedef RTCRX509VALIDITY *PRTCRX509VALIDITY;
315/** Pointer ot the const IPRT representation of an X.509 validity sequence. */
316typedef RTCRX509VALIDITY const *PCRTCRX509VALIDITY;
317RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509VALIDITY, RTDECL, RTCrX509Validity, SeqCore.Asn1Core);
318
319RTDECL(bool) RTCrX509Validity_IsValidAtTimeSpec(PCRTCRX509VALIDITY pThis, PCRTTIMESPEC pTimeSpec);
320
321
322#if 0
323/**
324 * X.509 UniqueIdentifier (IPRT representation).
325 */
326typedef struct RTCRX509UNIQUEIDENTIFIER
327{
328 /** Representation is a bit string. */
329 RTASN1BITSTRING BitString;
330} RTCRX509UNIQUEIDENTIFIER;
331/** Pointer to the IPRT representation of an X.509 unique identifier. */
332typedef RTCRX509UNIQUEIDENTIFIER *PRTCRX509UNIQUEIDENTIFIER;
333/** Pointer to the const IPRT representation of an X.509 unique identifier. */
334typedef RTCRX509UNIQUEIDENTIFIER const *PCRTCRX509UNIQUEIDENTIFIER;
335RTASN1TYPE_STANDARD_PROTOTYPES_NO_GET_CORE(RTCRX509UNIQUEIDENTIFIER, RTDECL, RTCrX509UniqueIdentifier);
336#endif
337RTASN1TYPE_ALIAS(RTCRX509UNIQUEIDENTIFIER, RTASN1BITSTRING, RTCrX509UniqueIdentifier, RTAsn1BitString);
338
339
340/**
341 * X.509 SubjectPublicKeyInfo (IPRT representation).
342 */
343typedef struct RTCRX509SUBJECTPUBLICKEYINFO
344{
345 /** Core sequence bits. */
346 RTASN1SEQUENCECORE SeqCore;
347 /** The algorithm used with the public key. */
348 RTCRX509ALGORITHMIDENTIFIER Algorithm;
349 /** A bit string containing the public key.
350 *
351 * For algorithms like rsaEncryption this is generally a sequence of two
352 * integers, where the first one has lots of bits, and the second one being a
353 * modulous value. These are details specific to the algorithm and not relevant
354 * when validating the certificate chain. */
355 RTASN1BITSTRING SubjectPublicKey;
356} RTCRX509SUBJECTPUBLICKEYINFO;
357/** Pointer to the IPRT representation of an X.509 subject public key info
358 * sequence. */
359typedef RTCRX509SUBJECTPUBLICKEYINFO *PRTCRX509SUBJECTPUBLICKEYINFO;
360/** Pointer to the const IPRT representation of an X.509 subject public key info
361 * sequence. */
362typedef RTCRX509SUBJECTPUBLICKEYINFO const *PCRTCRX509SUBJECTPUBLICKEYINFO;
363RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509SUBJECTPUBLICKEYINFO, RTDECL, RTCrX509SubjectPublicKeyInfo, SeqCore.Asn1Core);
364
365
366/**
367 * One X.509 AuthorityKeyIdentifier (IPRT representation).
368 */
369typedef struct RTCRX509AUTHORITYKEYIDENTIFIER
370{
371 /** Sequence core. */
372 RTASN1SEQUENCECORE SeqCore;
373 /** Tag 0, optional, implicit: Key identifier. */
374 RTASN1OCTETSTRING KeyIdentifier;
375 /** Tag 1, optional, implicit: Issuer name. */
376 RTCRX509GENERALNAMES AuthorityCertIssuer;
377 /** Tag 2, optional, implicit: Serial number of issuer. */
378 RTASN1INTEGER AuthorityCertSerialNumber;
379} RTCRX509AUTHORITYKEYIDENTIFIER;
380/** Pointer to the IPRT representation of an X.509 AuthorityKeyIdentifier
381 * sequence. */
382typedef RTCRX509AUTHORITYKEYIDENTIFIER *PRTCRX509AUTHORITYKEYIDENTIFIER;
383/** Pointer to the const IPRT representation of an X.509 AuthorityKeyIdentifier
384 * sequence. */
385typedef RTCRX509AUTHORITYKEYIDENTIFIER const *PCRTCRX509AUTHORITYKEYIDENTIFIER;
386RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509AUTHORITYKEYIDENTIFIER, RTDECL, RTCrX509AuthorityKeyIdentifier, SeqCore.Asn1Core);
387
388
389/**
390 * One X.509 OldAuthorityKeyIdentifier (IPRT representation).
391 */
392typedef struct RTCRX509OLDAUTHORITYKEYIDENTIFIER
393{
394 /** Sequence core. */
395 RTASN1SEQUENCECORE SeqCore;
396 /** Tag 0, optional, implicit: Key identifier. */
397 RTASN1OCTETSTRING KeyIdentifier;
398 struct
399 {
400 RTASN1CONTEXTTAG1 CtxTag1;
401 /** Tag 1, optional, implicit: Issuer name. */
402 RTCRX509NAME AuthorityCertIssuer;
403 } T1;
404 /** Tag 2, optional, implicit: Serial number of issuer. */
405 RTASN1INTEGER AuthorityCertSerialNumber;
406} RTCRX509OLDAUTHORITYKEYIDENTIFIER;
407/** Pointer to the IPRT representation of an X.509 AuthorityKeyIdentifier
408 * sequence. */
409typedef RTCRX509OLDAUTHORITYKEYIDENTIFIER *PRTCRX509OLDAUTHORITYKEYIDENTIFIER;
410/** Pointer to the const IPRT representation of an X.509 AuthorityKeyIdentifier
411 * sequence. */
412typedef RTCRX509OLDAUTHORITYKEYIDENTIFIER const *PCRTCRX509OLDAUTHORITYKEYIDENTIFIER;
413RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509OLDAUTHORITYKEYIDENTIFIER, RTDECL, RTCrX509OldAuthorityKeyIdentifier, SeqCore.Asn1Core);
414
415
416/**
417 * One X.509 PolicyQualifierInfo (IPRT representation).
418 */
419typedef struct RTCRX509POLICYQUALIFIERINFO
420{
421 /** Core sequence bits. */
422 RTASN1SEQUENCECORE SeqCore;
423 /** The policy object ID. */
424 RTASN1OBJID PolicyQualifierId;
425 /** Anything defined by the policy qualifier id. */
426 RTASN1DYNTYPE Qualifier;
427} RTCRX509POLICYQUALIFIERINFO;
428/** Pointer to the IPRT representation of an X.509 PolicyQualifierInfo
429 * sequence. */
430typedef RTCRX509POLICYQUALIFIERINFO *PRTCRX509POLICYQUALIFIERINFO;
431/** Pointer to the const IPRT representation of an X.509 PolicyQualifierInfo
432 * sequence. */
433typedef RTCRX509POLICYQUALIFIERINFO const *PCRTCRX509POLICYQUALIFIERINFO;
434RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYQUALIFIERINFO, RTDECL, RTCrX509PolicyQualifierInfo, SeqCore.Asn1Core);
435RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509POLICYQUALIFIERINFOS, RTCRX509POLICYQUALIFIERINFO, RTDECL, RTCrX509PolicyQualifierInfos);
436
437
438/**
439 * One X.509 PolicyInformation (IPRT representation).
440 */
441typedef struct RTCRX509POLICYINFORMATION
442{
443 /** Core sequence bits. */
444 RTASN1SEQUENCECORE SeqCore;
445 /** The policy object ID. */
446 RTASN1OBJID PolicyIdentifier;
447 /** Optional sequence of policy qualifiers. */
448 RTCRX509POLICYQUALIFIERINFOS PolicyQualifiers;
449} RTCRX509POLICYINFORMATION;
450/** Pointer to the IPRT representation of an X.509 PolicyInformation
451 * sequence. */
452typedef RTCRX509POLICYINFORMATION *PRTCRX509POLICYINFORMATION;
453/** Pointer to the const IPRT representation of an X.509 PolicyInformation
454 * sequence. */
455typedef RTCRX509POLICYINFORMATION const *PCRTCRX509POLICYINFORMATION;
456RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYINFORMATION, RTDECL, RTCrX509PolicyInformation, SeqCore.Asn1Core);
457RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509CERTIFICATEPOLICIES, RTCRX509POLICYINFORMATION, RTDECL, RTCrX509CertificatePolicies);
458
459/** Sepcial policy object ID that matches any policy. */
460#define RTCRX509_ID_CE_CP_ANY_POLICY_OID "2.5.29.32.0"
461
462
463/**
464 * One X.509 PolicyMapping (IPRT representation).
465 */
466typedef struct RTCRX509POLICYMAPPING
467{
468 /** Core sequence bits. */
469 RTASN1SEQUENCECORE SeqCore;
470 /** Issuer policy ID. */
471 RTASN1OBJID IssuerDomainPolicy;
472 /** Subject policy ID. */
473 RTASN1OBJID SubjectDomainPolicy;
474} RTCRX509POLICYMAPPING;
475/** Pointer to the IPRT representation of a sequence of X.509 PolicyMapping. */
476typedef RTCRX509POLICYMAPPING *PRTCRX509POLICYMAPPING;
477/** Pointer to the const IPRT representation of a sequence of X.509
478 * PolicyMapping. */
479typedef RTCRX509POLICYMAPPING const *PCRTCRX509POLICYMAPPING;
480RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYMAPPING, RTDECL, RTCrX509PolicyMapping, SeqCore.Asn1Core);
481RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509POLICYMAPPINGS, RTCRX509POLICYMAPPING, RTDECL, RTCrX509PolicyMappings);
482
483
484/**
485 * X.509 BasicConstraints (IPRT representation).
486 */
487typedef struct RTCRX509BASICCONSTRAINTS
488{
489 /** Core sequence bits. */
490 RTASN1SEQUENCECORE SeqCore;
491 /** Is this ia certficiate authority? Default to false. */
492 RTASN1BOOLEAN CA;
493 /** Path length constraint. */
494 RTASN1INTEGER PathLenConstraint;
495} RTCRX509BASICCONSTRAINTS;
496/** Pointer to the IPRT representation of a sequence of X.509
497 * BasicConstraints. */
498typedef RTCRX509BASICCONSTRAINTS *PRTCRX509BASICCONSTRAINTS;
499/** Pointer to the const IPRT representation of a sequence of X.509
500 * BasicConstraints. */
501typedef RTCRX509BASICCONSTRAINTS const *PCRTCRX509BASICCONSTRAINTS;
502RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509BASICCONSTRAINTS, RTDECL, RTCrX509BasicConstraints, SeqCore.Asn1Core);
503
504
505/**
506 * X.509 GeneralSubtree (IPRT representation).
507 */
508typedef struct RTCRX509GENERALSUBTREE
509{
510 /** Core sequence bits. */
511 RTASN1SEQUENCECORE SeqCore;
512 /** Base name. */
513 RTCRX509GENERALNAME Base;
514 /** Tag 0, optional: Minimum, default 0. Fixed at 0 by RFC-5280. */
515 RTASN1INTEGER Minimum;
516 /** Tag 1, optional: Maximum. Fixed as not-present by RFC-5280. */
517 RTASN1INTEGER Maximum;
518} RTCRX509GENERALSUBTREE;
519/** Pointer to the IPRT representation of a sequence of X.509 GeneralSubtree. */
520typedef RTCRX509GENERALSUBTREE *PRTCRX509GENERALSUBTREE;
521/** Pointer to the const IPRT representation of a sequence of X.509
522 * GeneralSubtree. */
523typedef RTCRX509GENERALSUBTREE const *PCRTCRX509GENERALSUBTREE;
524RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509GENERALSUBTREE, RTDECL, RTCrX509GeneralSubtree, SeqCore.Asn1Core);
525
526RTDECL(bool) RTCrX509GeneralSubtree_ConstraintMatch(PCRTCRX509GENERALSUBTREE pConstraint, PCRTCRX509GENERALSUBTREE pName);
527
528RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509GENERALSUBTREES, RTCRX509GENERALSUBTREE, RTDECL, RTCrX509GeneralSubtrees);
529
530
531/**
532 * X.509 NameConstraints (IPRT representation).
533 */
534typedef struct RTCRX509NAMECONSTRAINTS
535{
536 /** Core sequence bits. */
537 RTASN1SEQUENCECORE SeqCore;
538 /** Tag 0, optional: Permitted subtrees. */
539 struct
540 {
541 /** Context tag. */
542 RTASN1CONTEXTTAG0 CtxTag0;
543 /** The permitted subtrees. */
544 RTCRX509GENERALSUBTREES PermittedSubtrees;
545 } T0;
546 /** Tag 1, optional: Excluded subtrees. */
547 struct
548 {
549 /** Context tag. */
550 RTASN1CONTEXTTAG1 CtxTag1;
551 /** The excluded subtrees. */
552 RTCRX509GENERALSUBTREES ExcludedSubtrees;
553 } T1;
554} RTCRX509NAMECONSTRAINTS;
555/** Pointer to the IPRT representation of a sequence of X.509
556 * NameConstraints. */
557typedef RTCRX509NAMECONSTRAINTS *PRTCRX509NAMECONSTRAINTS;
558/** Pointer to the const IPRT representation of a sequence of X.509
559 * NameConstraints. */
560typedef RTCRX509NAMECONSTRAINTS const *PCRTCRX509NAMECONSTRAINTS;
561RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509NAMECONSTRAINTS, RTDECL, RTCrX509NameConstraints, SeqCore.Asn1Core);
562
563
564/**
565 * X.509 PolicyConstraints (IPRT representation).
566 */
567typedef struct RTCRX509POLICYCONSTRAINTS
568{
569 /** Core sequence bits. */
570 RTASN1SEQUENCECORE SeqCore;
571 /** Tag 0, optional: Certificates before an explicit policy is required. */
572 RTASN1INTEGER RequireExplicitPolicy;
573 /** Tag 1, optional: Certificates before policy mapping is inhibited. */
574 RTASN1INTEGER InhibitPolicyMapping;
575} RTCRX509POLICYCONSTRAINTS;
576/** Pointer to the IPRT representation of a sequence of X.509
577 * PolicyConstraints. */
578typedef RTCRX509POLICYCONSTRAINTS *PRTCRX509POLICYCONSTRAINTS;
579/** Pointer to the const IPRT representation of a sequence of X.509
580 * PolicyConstraints. */
581typedef RTCRX509POLICYCONSTRAINTS const *PCRTCRX509POLICYCONSTRAINTS;
582RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYCONSTRAINTS, RTDECL, RTCrX509PolicyConstraints, SeqCore.Asn1Core);
583
584
585/**
586 * Indicates what an X.509 extension value encapsulates.
587 */
588typedef enum RTCRX509EXTENSIONVALUE
589{
590 RTCRX509EXTENSIONVALUE_INVALID = 0,
591 /** Unknown, no decoding available just the octet string. */
592 RTCRX509EXTENSIONVALUE_UNKNOWN,
593 /** Unencapsulated (i.e. octet string). */
594 RTCRX509EXTENSIONVALUE_NOT_ENCAPSULATED,
595
596 /** Bit string (RTASN1BITSTRING). */
597 RTCRX509EXTENSIONVALUE_BIT_STRING,
598 /** Octet string (RTASN1OCTETSTRING). */
599 RTCRX509EXTENSIONVALUE_OCTET_STRING,
600 /** Integer string (RTASN1INTEGER). */
601 RTCRX509EXTENSIONVALUE_INTEGER,
602 /** Sequence of object identifiers (RTASN1SEQOFOBJIDS). */
603 RTCRX509EXTENSIONVALUE_SEQ_OF_OBJ_IDS,
604
605 /** Authority key identifier (RTCRX509AUTHORITYKEYIDENTIFIER). */
606 RTCRX509EXTENSIONVALUE_AUTHORITY_KEY_IDENTIFIER,
607 /** Old Authority key identifier (RTCRX509OLDAUTHORITYKEYIDENTIFIER). */
608 RTCRX509EXTENSIONVALUE_OLD_AUTHORITY_KEY_IDENTIFIER,
609 /** Certificate policies (RTCRX509CERTIFICATEPOLICIES). */
610 RTCRX509EXTENSIONVALUE_CERTIFICATE_POLICIES,
611 /** Sequence of policy mappings (RTCRX509POLICYMAPPINGS). */
612 RTCRX509EXTENSIONVALUE_POLICY_MAPPINGS,
613 /** Basic constraints (RTCRX509BASICCONSTRAINTS). */
614 RTCRX509EXTENSIONVALUE_BASIC_CONSTRAINTS,
615 /** Name constraints (RTCRX509NAMECONSTRAINTS). */
616 RTCRX509EXTENSIONVALUE_NAME_CONSTRAINTS,
617 /** Policy constraints (RTCRX509POLICYCONSTRAINTS). */
618 RTCRX509EXTENSIONVALUE_POLICY_CONSTRAINTS,
619 /** Sequence of general names (RTCRX509GENERALNAMES). */
620 RTCRX509EXTENSIONVALUE_GENERAL_NAMES,
621
622 /** Blow the type up to 32-bits. */
623 RTCRX509EXTENSIONVALUE_32BIT_HACK = 0x7fffffff
624} RTCRX509EXTENSIONVALUE;
625
626/**
627 * One X.509 Extension (IPRT representation).
628 */
629typedef struct RTCRX509EXTENSION
630{
631 /** Core sequence bits. */
632 RTASN1SEQUENCECORE SeqCore;
633 /** Extension ID. */
634 RTASN1OBJID ExtnId;
635 /** Whether this is critical (default @c false). */
636 RTASN1BOOLEAN Critical;
637 /** Indicates what ExtnValue.pEncapsulated points at. */
638 RTCRX509EXTENSIONVALUE enmValue;
639 /** The value.
640 * Contains extension specific data that we don't yet parse. */
641 RTASN1OCTETSTRING ExtnValue;
642} RTCRX509EXTENSION;
643/** Pointer to the IPRT representation of one X.509 extensions. */
644typedef RTCRX509EXTENSION *PRTCRX509EXTENSION;
645/** Pointer to the const IPRT representation of one X.509 extension. */
646typedef RTCRX509EXTENSION const *PCRTCRX509EXTENSION;
647RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509EXTENSION, RTDECL, RTCrX509Extension, SeqCore.Asn1Core);
648RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509EXTENSIONS, RTCRX509EXTENSION, RTDECL, RTCrX509Extensions);
649
650RTDECL(int) RTCrX509Extension_ExtnValue_DecodeAsn1(PRTASN1CURSOR pCursor, uint32_t fFlags,
651 PRTCRX509EXTENSION pThis, const char *pszErrorTag);
652
653
654/**
655 * X.509 To-be-signed certificate information (IPRT representation).
656 */
657typedef struct RTCRX509TBSCERTIFICATE
658{
659 /** Sequence core. */
660 RTASN1SEQUENCECORE SeqCore;
661 /** Structure version. */
662 struct
663 {
664 /** Context tag with value 0. */
665 RTASN1CONTEXTTAG0 CtxTag0;
666 /** The actual value (RTCRX509TBSCERTIFICATE_V1, ...). */
667 RTASN1INTEGER Version;
668 } T0;
669 /** The serial number of the certificate. */
670 RTASN1INTEGER SerialNumber;
671 /** The signature algorithm. */
672 RTCRX509ALGORITHMIDENTIFIER Signature;
673 /** The issuer name. */
674 RTCRX509NAME Issuer;
675 /** The certificate validity period. */
676 RTCRX509VALIDITY Validity;
677 /** The subject name. */
678 RTCRX509NAME Subject;
679 /** The public key for this certificate. */
680 RTCRX509SUBJECTPUBLICKEYINFO SubjectPublicKeyInfo;
681 /** Issuer unique identifier (optional, version >= v2). */
682 struct
683 {
684 /** Context tag with value 1. */
685 RTASN1CONTEXTTAG1 CtxTag1;
686 /** The unique identifier value. */
687 RTCRX509UNIQUEIDENTIFIER IssuerUniqueId;
688 } T1;
689 /** Subject unique identifier (optional, version >= v2). */
690 struct
691 {
692 /** Context tag with value 2. */
693 RTASN1CONTEXTTAG2 CtxTag2;
694 /** The unique identifier value. */
695 RTCRX509UNIQUEIDENTIFIER SubjectUniqueId;
696 } T2;
697 /** Extensions (optional, version >= v3). */
698 struct
699 {
700 /** Context tag with value 3. */
701 RTASN1CONTEXTTAG3 CtxTag3;
702 /** The unique identifier value. */
703 RTCRX509EXTENSIONS Extensions;
704 /** Extensions summary flags. */
705 uint32_t fFlags;
706 /** Key usage flags. */
707 uint32_t fKeyUsage;
708 /** Extended key usage flags. */
709 uint32_t fExtKeyUsage;
710
711 /** Pointer to the authority key ID extension if present. */
712 PCRTCRX509AUTHORITYKEYIDENTIFIER pAuthorityKeyIdentifier;
713 /** Pointer to the OLD authority key ID extension if present. */
714 PCRTCRX509OLDAUTHORITYKEYIDENTIFIER pOldAuthorityKeyIdentifier;
715 /** Pointer to the subject key ID extension if present. */
716 PCRTASN1OCTETSTRING pSubjectKeyIdentifier;
717 /** Pointer to the alternative subject name extension if present. */
718 PCRTCRX509GENERALNAMES pAltSubjectName;
719 /** Pointer to the alternative issuer name extension if present. */
720 PCRTCRX509GENERALNAMES pAltIssuerName;
721 /** Pointer to the certificate policies extension if present. */
722 PCRTCRX509CERTIFICATEPOLICIES pCertificatePolicies;
723 /** Pointer to the policy mappings extension if present. */
724 PCRTCRX509POLICYMAPPINGS pPolicyMappings;
725 /** Pointer to the basic constraints extension if present. */
726 PCRTCRX509BASICCONSTRAINTS pBasicConstraints;
727 /** Pointer to the name constraints extension if present. */
728 PCRTCRX509NAMECONSTRAINTS pNameConstraints;
729 /** Pointer to the policy constraints extension if present. */
730 PCRTCRX509POLICYCONSTRAINTS pPolicyConstraints;
731 /** Pointer to the inhibit anyPolicy extension if present. */
732 PCRTASN1INTEGER pInhibitAnyPolicy;
733 } T3;
734} RTCRX509TBSCERTIFICATE;
735/** Pointer to the IPRT representation of a X.509 TBSCertificate. */
736typedef RTCRX509TBSCERTIFICATE *PRTCRX509TBSCERTIFICATE;
737/** Pointer to the const IPRT representation of a X.509 TBSCertificate. */
738typedef RTCRX509TBSCERTIFICATE const *PCRTCRX509TBSCERTIFICATE;
739RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509TBSCERTIFICATE, RTDECL, RTCrX509TbsCertificate, SeqCore.Asn1Core);
740
741/** @name RTCRX509TBSCERTIFICATE::T0.Version values.
742 * @{ */
743#define RTCRX509TBSCERTIFICATE_V1 0
744#define RTCRX509TBSCERTIFICATE_V2 1
745#define RTCRX509TBSCERTIFICATE_V3 2
746/** @} */
747
748/** @name RTCRX509TBSCERTIFICATE::T3.fFlags values.
749 * @{ */
750#define RTCRX509TBSCERTIFICATE_F_PRESENT_KEY_USAGE RT_BIT_32(0)
751#define RTCRX509TBSCERTIFICATE_F_PRESENT_EXT_KEY_USAGE RT_BIT_32(1)
752#define RTCRX509TBSCERTIFICATE_F_PRESENT_SUBJECT_KEY_IDENTIFIER RT_BIT_32(2)
753#define RTCRX509TBSCERTIFICATE_F_PRESENT_SUBJECT_ALT_NAME RT_BIT_32(3)
754#define RTCRX509TBSCERTIFICATE_F_PRESENT_ISSUER_ALT_NAME RT_BIT_32(4)
755#define RTCRX509TBSCERTIFICATE_F_PRESENT_CERTIFICATE_POLICIES RT_BIT_32(5)
756#define RTCRX509TBSCERTIFICATE_F_PRESENT_POLICY_MAPPINGS RT_BIT_32(6)
757#define RTCRX509TBSCERTIFICATE_F_PRESENT_BASIC_CONSTRAINTS RT_BIT_32(7)
758#define RTCRX509TBSCERTIFICATE_F_PRESENT_NAME_CONSTRAINTS RT_BIT_32(8)
759#define RTCRX509TBSCERTIFICATE_F_PRESENT_POLICY_CONSTRAINTS RT_BIT_32(9)
760#define RTCRX509TBSCERTIFICATE_F_PRESENT_AUTHORITY_KEY_IDENTIFIER RT_BIT_32(10)
761#define RTCRX509TBSCERTIFICATE_F_PRESENT_OLD_AUTHORITY_KEY_IDENTIFIER RT_BIT_32(11)
762#define RTCRX509TBSCERTIFICATE_F_PRESENT_ACCEPTABLE_CERT_POLICIES RT_BIT_32(12)
763#define RTCRX509TBSCERTIFICATE_F_PRESENT_INHIBIT_ANY_POLICY RT_BIT_32(13)
764#define RTCRX509TBSCERTIFICATE_F_PRESENT_OTHER RT_BIT_32(22) /**< Other unknown extension present. */
765#define RTCRX509TBSCERTIFICATE_F_PRESENT_NONE RT_BIT_32(23) /**< No extensions present. */
766/** @} */
767
768/** @name X.509 Key Usage flags. (RFC-5280 section 4.2.1.3.)
769 * @{ */
770#define RTCRX509CERT_KEY_USAGE_F_DIGITAL_SIGNATURE_BIT 0
771#define RTCRX509CERT_KEY_USAGE_F_DIGITAL_SIGNATURE RT_BIT_32(0)
772#define RTCRX509CERT_KEY_USAGE_F_CONTENT_COMMITTMENT_BIT 1
773#define RTCRX509CERT_KEY_USAGE_F_CONTENT_COMMITTMENT RT_BIT_32(1)
774#define RTCRX509CERT_KEY_USAGE_F_KEY_ENCIPHERMENT_BIT 2
775#define RTCRX509CERT_KEY_USAGE_F_KEY_ENCIPHERMENT RT_BIT_32(2)
776#define RTCRX509CERT_KEY_USAGE_F_DATA_ENCIPHERMENT_BIT 3
777#define RTCRX509CERT_KEY_USAGE_F_DATA_ENCIPHERMENT RT_BIT_32(3)
778#define RTCRX509CERT_KEY_USAGE_F_KEY_AGREEMENT_BIT 4
779#define RTCRX509CERT_KEY_USAGE_F_KEY_AGREEMENT RT_BIT_32(4)
780#define RTCRX509CERT_KEY_USAGE_F_KEY_CERT_SIGN_BIT 5
781#define RTCRX509CERT_KEY_USAGE_F_KEY_CERT_SIGN RT_BIT_32(5)
782#define RTCRX509CERT_KEY_USAGE_F_CRL_SIGN_BIT 6
783#define RTCRX509CERT_KEY_USAGE_F_CRL_SIGN RT_BIT_32(6)
784#define RTCRX509CERT_KEY_USAGE_F_ENCIPHERMENT_ONLY_BIT 7
785#define RTCRX509CERT_KEY_USAGE_F_ENCIPHERMENT_ONLY RT_BIT_32(7)
786#define RTCRX509CERT_KEY_USAGE_F_DECIPHERMENT_ONLY_BIT 8
787#define RTCRX509CERT_KEY_USAGE_F_DECIPHERMENT_ONLY RT_BIT_32(8)
788/** @} */
789
790/** @name X.509 Extended Key Usage flags. (RFC-5280 section 4.2.1.12, ++.)
791 * @remarks Needless to say, these flags doesn't cover all possible extended key
792 * usages, because there is a potential unlimited number of them. Only
793 * ones relevant to IPRT and it's users are covered.
794 * @{ */
795#define RTCRX509CERT_EKU_F_ANY RT_BIT_64(0)
796#define RTCRX509CERT_EKU_F_SERVER_AUTH RT_BIT_64(1)
797#define RTCRX509CERT_EKU_F_CLIENT_AUTH RT_BIT_64(2)
798#define RTCRX509CERT_EKU_F_CODE_SIGNING RT_BIT_64(3)
799#define RTCRX509CERT_EKU_F_EMAIL_PROTECTION RT_BIT_64(4)
800#define RTCRX509CERT_EKU_F_IPSEC_END_SYSTEM RT_BIT_64(5)
801#define RTCRX509CERT_EKU_F_IPSEC_TUNNEL RT_BIT_64(6)
802#define RTCRX509CERT_EKU_F_IPSEC_USER RT_BIT_64(7)
803#define RTCRX509CERT_EKU_F_TIMESTAMPING RT_BIT_64(8)
804#define RTCRX509CERT_EKU_F_OCSP_SIGNING RT_BIT_64(9)
805#define RTCRX509CERT_EKU_F_DVCS RT_BIT_64(10)
806#define RTCRX509CERT_EKU_F_SBGP_CERT_AA_SERVICE_AUTH RT_BIT_64(11)
807#define RTCRX509CERT_EKU_F_EAP_OVER_PPP RT_BIT_64(12)
808#define RTCRX509CERT_EKU_F_EAP_OVER_LAN RT_BIT_64(13)
809#define RTCRX509CERT_EKU_F_OTHER RT_BIT_64(16) /**< Other unknown extended key usage present. */
810#define RTCRX509CERT_EKU_F_APPLE_CODE_SIGNING RT_BIT_64(24)
811#define RTCRX509CERT_EKU_F_APPLE_CODE_SIGNING_DEVELOPMENT RT_BIT_64(25)
812#define RTCRX509CERT_EKU_F_APPLE_SOFTWARE_UPDATE_SIGNING RT_BIT_64(26)
813#define RTCRX509CERT_EKU_F_APPLE_CODE_SIGNING_THIRD_PARTY RT_BIT_64(27)
814#define RTCRX509CERT_EKU_F_APPLE_RESOURCE_SIGNING RT_BIT_64(28)
815#define RTCRX509CERT_EKU_F_APPLE_SYSTEM_IDENTITY RT_BIT_64(29)
816#define RTCRX509CERT_EKU_F_MS_TIMESTAMP_SIGNING RT_BIT_64(32)
817#define RTCRX509CERT_EKU_F_MS_NT5_CRYPTO RT_BIT_64(33)
818#define RTCRX509CERT_EKU_F_MS_OEM_WHQL_CRYPTO RT_BIT_64(34)
819#define RTCRX509CERT_EKU_F_MS_EMBEDDED_NT_CRYPTO RT_BIT_64(35)
820#define RTCRX509CERT_EKU_F_MS_KERNEL_MODE_CODE_SIGNING RT_BIT_64(36)
821#define RTCRX509CERT_EKU_F_MS_LIFETIME_SIGNING RT_BIT_64(37)
822#define RTCRX509CERT_EKU_F_MS_DRM RT_BIT_64(38)
823#define RTCRX509CERT_EKU_F_MS_DRM_INDIVIDUALIZATION RT_BIT_64(39)
824/** @} */
825
826/** @name Key purpose OIDs (extKeyUsage)
827 * @{ */
828#define RTCRX509_ANY_EXTENDED_KEY_USAGE_OID "2.5.29.37.0"
829#define RTCRX509_ID_KP_OID "1.3.6.1.5.5.7.3"
830#define RTCRX509_ID_KP_SERVER_AUTH_OID "1.3.6.1.5.5.7.3.1"
831#define RTCRX509_ID_KP_CLIENT_AUTH_OID "1.3.6.1.5.5.7.3.2"
832#define RTCRX509_ID_KP_CODE_SIGNING_OID "1.3.6.1.5.5.7.3.3"
833#define RTCRX509_ID_KP_EMAIL_PROTECTION_OID "1.3.6.1.5.5.7.3.4"
834#define RTCRX509_ID_KP_IPSEC_END_SYSTEM_OID "1.3.6.1.5.5.7.3.5"
835#define RTCRX509_ID_KP_IPSEC_TUNNEL_OID "1.3.6.1.5.5.7.3.6"
836#define RTCRX509_ID_KP_IPSEC_USER_OID "1.3.6.1.5.5.7.3.7"
837#define RTCRX509_ID_KP_TIMESTAMPING_OID "1.3.6.1.5.5.7.3.8"
838#define RTCRX509_ID_KP_OCSP_SIGNING_OID "1.3.6.1.5.5.7.3.9"
839#define RTCRX509_ID_KP_DVCS_OID "1.3.6.1.5.5.7.3.10"
840#define RTCRX509_ID_KP_SBGP_CERT_AA_SERVICE_AUTH_OID "1.3.6.1.5.5.7.3.11"
841#define RTCRX509_ID_KP_EAP_OVER_PPP_OID "1.3.6.1.5.5.7.3.13"
842#define RTCRX509_ID_KP_EAP_OVER_LAN_OID "1.3.6.1.5.5.7.3.14"
843/** @} */
844
845/** @name Microsoft extended key usage OIDs
846 * @{ */
847#define RTCRX509_MS_EKU_CERT_TRUST_LIST_SIGNING_OID "1.3.6.1.4.1.311.10.3.1"
848#define RTCRX509_MS_EKU_TIMESTAMP_SIGNING_OID "1.3.6.1.4.1.311.10.3.2"
849#define RTCRX509_MS_EKU_SERVER_GATED_CRYPTO_OID "1.3.6.1.4.1.311.10.3.3"
850#define RTCRX509_MS_EKU_SGC_SERIALIZED_OID "1.3.6.1.4.1.311.10.3.3.1"
851#define RTCRX509_MS_EKU_ENCRYPTED_FILE_SYSTEM_OID "1.3.6.1.4.1.311.10.3.4"
852#define RTCRX509_MS_EKU_WHQL_CRYPTO_OID "1.3.6.1.4.1.311.10.3.5"
853#define RTCRX509_MS_EKU_NT5_CRYPTO_OID "1.3.6.1.4.1.311.10.3.6"
854#define RTCRX509_MS_EKU_OEM_WHQL_CRYPTO_OID "1.3.6.1.4.1.311.10.3.7"
855#define RTCRX509_MS_EKU_EMBEDDED_NT_CRYPTO_OID "1.3.6.1.4.1.311.10.3.8"
856#define RTCRX509_MS_EKU_ROOT_LIST_SIGNER_OID "1.3.6.1.4.1.311.10.3.9"
857#define RTCRX509_MS_EKU_QUALIFIED_SUBORDINATE_OID "1.3.6.1.4.1.311.10.3.10"
858#define RTCRX509_MS_EKU_KEY_RECOVERY_3_OID "1.3.6.1.4.1.311.10.3.11"
859#define RTCRX509_MS_EKU_DOCUMENT_SIGNING_OID "1.3.6.1.4.1.311.10.3.12"
860#define RTCRX509_MS_EKU_LIFETIME_SIGNING_OID "1.3.6.1.4.1.311.10.3.13"
861#define RTCRX509_MS_EKU_MOBILE_DEVICE_SOFTWARE_OID "1.3.6.1.4.1.311.10.3.14"
862#define RTCRX509_MS_EKU_SMART_DISPLAY_OID "1.3.6.1.4.1.311.10.3.15"
863#define RTCRX509_MS_EKU_CSP_SIGNATURE_OID "1.3.6.1.4.1.311.10.3.16"
864#define RTCRX509_MS_EKU_EFS_RECOVERY_OID "1.3.6.1.4.1.311.10.3.4.1"
865#define RTCRX509_MS_EKU_DRM_OID "1.3.6.1.4.1.311.10.5.1"
866#define RTCRX509_MS_EKU_DRM_INDIVIDUALIZATION_OID "1.3.6.1.4.1.311.10.5.2"
867#define RTCRX509_MS_EKU_LICENSES_OID "1.3.6.1.4.1.311.10.5.3"
868#define RTCRX509_MS_EKU_LICENSE_SERVER_OID "1.3.6.1.4.1.311.10.5.4"
869#define RTCRX509_MS_EKU_ENROLLMENT_AGENT_OID "1.3.6.1.4.1.311.20.2.1"
870#define RTCRX509_MS_EKU_SMARTCARD_LOGON_OID "1.3.6.1.4.1.311.20.2.2"
871#define RTCRX509_MS_EKU_CA_EXCHANGE_OID "1.3.6.1.4.1.311.21.5"
872#define RTCRX509_MS_EKU_KEY_RECOVERY_21_OID "1.3.6.1.4.1.311.21.6"
873#define RTCRX509_MS_EKU_SYSTEM_HEALTH_OID "1.3.6.1.4.1.311.47.1.1"
874#define RTCRX509_MS_EKU_SYSTEM_HEALTH_LOOPHOLE_OID "1.3.6.1.4.1.311.47.1.3"
875#define RTCRX509_MS_EKU_KERNEL_MODE_CODE_SIGNING_OID "1.3.6.1.4.1.311.61.1.1"
876/** @} */
877
878/** @name Apple extended key usage OIDs
879 * @{ */
880#define RTCRX509_APPLE_EKU_APPLE_EXTENDED_KEY_USAGE_OID "1.2.840.113635.100.4"
881#define RTCRX509_APPLE_EKU_CODE_SIGNING_OID "1.2.840.113635.100.4.1"
882#define RTCRX509_APPLE_EKU_CODE_SIGNING_DEVELOPMENT_OID "1.2.840.113635.100.4.1.1"
883#define RTCRX509_APPLE_EKU_SOFTWARE_UPDATE_SIGNING_OID "1.2.840.113635.100.4.1.2"
884#define RTCRX509_APPLE_EKU_CODE_SIGNING_THRID_PARTY_OID "1.2.840.113635.100.4.1.3"
885#define RTCRX509_APPLE_EKU_RESOURCE_SIGNING_OID "1.2.840.113635.100.4.1.4"
886#define RTCRX509_APPLE_EKU_ICHAT_SIGNING_OID "1.2.840.113635.100.4.2"
887#define RTCRX509_APPLE_EKU_ICHAT_ENCRYPTION_OID "1.2.840.113635.100.4.3"
888#define RTCRX509_APPLE_EKU_SYSTEM_IDENTITY_OID "1.2.840.113635.100.4.4"
889#define RTCRX509_APPLE_EKU_CRYPTO_ENV_OID "1.2.840.113635.100.4.5"
890#define RTCRX509_APPLE_EKU_CRYPTO_PRODUCTION_ENV_OID "1.2.840.113635.100.4.5.1"
891#define RTCRX509_APPLE_EKU_CRYPTO_MAINTENANCE_ENV_OID "1.2.840.113635.100.4.5.2"
892#define RTCRX509_APPLE_EKU_CRYPTO_TEST_ENV_OID "1.2.840.113635.100.4.5.3"
893#define RTCRX509_APPLE_EKU_CRYPTO_DEVELOPMENT_ENV_OID "1.2.840.113635.100.4.5.4"
894#define RTCRX509_APPLE_EKU_CRYPTO_QOS_OID "1.2.840.113635.100.4.6"
895#define RTCRX509_APPLE_EKU_CRYPTO_TIER0_QOS_OID "1.2.840.113635.100.4.6.1"
896#define RTCRX509_APPLE_EKU_CRYPTO_TIER1_QOS_OID "1.2.840.113635.100.4.6.2"
897#define RTCRX509_APPLE_EKU_CRYPTO_TIER2_QOS_OID "1.2.840.113635.100.4.6.3"
898#define RTCRX509_APPLE_EKU_CRYPTO_TIER3_QOS_OID "1.2.840.113635.100.4.6.4"
899/** @} */
900
901/**
902 * Use this to update derived values after changing the certificate
903 * extensions.
904 *
905 * @returns IPRT status code
906 * @param pThis The certificate.
907 * @param pErrInfo Where to return additional error information. Optional.
908 */
909RTDECL(int) RTCrX509TbsCertificate_ReprocessExtensions(PRTCRX509TBSCERTIFICATE pThis, PRTERRINFO pErrInfo);
910
911
912/**
913 * One X.509 Certificate (IPRT representation).
914 */
915typedef struct RTCRX509CERTIFICATE
916{
917 /** Sequence core. */
918 RTASN1SEQUENCECORE SeqCore;
919 /** The to-be-signed certificate information. */
920 RTCRX509TBSCERTIFICATE TbsCertificate;
921 /** The signature algorithm (must match TbsCertificate.Signature). */
922 RTCRX509ALGORITHMIDENTIFIER SignatureAlgorithm;
923 /** The signature value. */
924 RTASN1BITSTRING SignatureValue;
925} RTCRX509CERTIFICATE;
926/** Pointer to the IPRT representation of one X.509 certificate. */
927typedef RTCRX509CERTIFICATE *PRTCRX509CERTIFICATE;
928/** Pointer to the const IPRT representation of one X.509 certificate. */
929typedef RTCRX509CERTIFICATE const *PCRTCRX509CERTIFICATE;
930RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509CERTIFICATE, RTDECL, RTCrX509Certificate, SeqCore.Asn1Core);
931
932/**
933 * Checks if a certificate matches a given issuer name and serial number.
934 *
935 * @returns True / false.
936 * @param pCertificates The X.509 certificat.
937 * @param pIssuer The issuer name to match against.
938 * @param pSerialNumber The serial number to match against.
939 */
940RTDECL(bool) RTCrX509Certificate_MatchIssuerAndSerialNumber(PCRTCRX509CERTIFICATE pCertificate,
941 PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNumber);
942
943RTDECL(bool) RTCrX509Certificate_MatchSubjectOrAltSubjectByRfc5280(PCRTCRX509CERTIFICATE pThis, PCRTCRX509NAME pName);
944RTDECL(bool) RTCrX509Certificate_IsSelfSigned(PCRTCRX509CERTIFICATE pCertificate);
945
946RTDECL(int) RTCrX509Certificate_VerifySignature(PCRTCRX509CERTIFICATE pThis, PCRTASN1OBJID pAlgorithm,
947 PCRTASN1DYNTYPE pParameters, PCRTASN1BITSTRING pPublicKey,
948 PRTERRINFO pErrInfo);
949RTDECL(int) RTCrX509Certificate_ReadFromFile(PRTCRX509CERTIFICATE pCertificate, const char *pszFilename, uint32_t fFlags,
950 PCRTASN1ALLOCATORVTABLE pAllocator, PRTERRINFO pErrInfo);
951
952
953/** @name X.509 Certificate Extensions
954 * @{ */
955/** Old AuthorityKeyIdentifier OID. */
956#define RTCRX509_ID_CE_OLD_AUTHORITY_KEY_IDENTIFIER_OID "2.5.29.1"
957/** Old CertificatePolicies extension OID. */
958#define RTCRX509_ID_CE_OLD_CERTIFICATE_POLICIES_OID "2.5.29.3"
959/** Old SubjectAltName extension OID. */
960#define RTCRX509_ID_CE_OLD_SUBJECT_ALT_NAME_OID "2.5.29.7"
961/** Old IssuerAltName extension OID. */
962#define RTCRX509_ID_CE_OLD_ISSUER_ALT_NAME_OID "2.5.29.8"
963/** Old BasicContraints extension OID. */
964#define RTCRX509_ID_CE_OLD_BASIC_CONSTRAINTS_OID "2.5.29.10"
965/** SubjectKeyIdentifier OID. */
966#define RTCRX509_ID_CE_SUBJECT_KEY_IDENTIFIER_OID "2.5.29.14"
967/** KeyUsage OID. */
968#define RTCRX509_ID_CE_KEY_USAGE_OID "2.5.29.15"
969/** PrivateKeyUsagePeriod OID. */
970#define RTCRX509_ID_CE_PRIVATE_KEY_USAGE_PERIOD_OID "2.5.29.16"
971/** SubjectAltName extension OID. */
972#define RTCRX509_ID_CE_SUBJECT_ALT_NAME_OID "2.5.29.17"
973/** IssuerAltName extension OID. */
974#define RTCRX509_ID_CE_ISSUER_ALT_NAME_OID "2.5.29.18"
975/** BasicContraints extension OID. */
976#define RTCRX509_ID_CE_BASIC_CONSTRAINTS_OID "2.5.29.19"
977/** NameContraints extension OID. */
978#define RTCRX509_ID_CE_NAME_CONSTRAINTS_OID "2.5.29.30"
979/** CertificatePolicies extension OID. */
980#define RTCRX509_ID_CE_CERTIFICATE_POLICIES_OID "2.5.29.32"
981/** PolicyMappings extension OID. */
982#define RTCRX509_ID_CE_POLICY_MAPPINGS_OID "2.5.29.33"
983/** AuthorityKeyIdentifier OID. */
984#define RTCRX509_ID_CE_AUTHORITY_KEY_IDENTIFIER_OID "2.5.29.35"
985/** PolicyContraints extension OID. */
986#define RTCRX509_ID_CE_POLICY_CONSTRAINTS_OID "2.5.29.36"
987/** ExtKeyUsage (extended key usage) extension OID. */
988#define RTCRX509_ID_CE_EXT_KEY_USAGE_OID "2.5.29.37"
989/** ExtKeyUsage: OID for permitting any unspecified key usage. */
990#define RTCRX509_ID_CE_ANY_EXTENDED_KEY_USAGE_OID "2.5.29.37.0"
991/** AuthorityAttributeIdentifier OID. */
992#define RTCRX509_ID_CE_AUTHORITY_ATTRIBUTE_IDENTIFIER_OID "2.5.29.38"
993/** AcceptableCertPolicies OID. */
994#define RTCRX509_ID_CE_ACCEPTABLE_CERT_POLICIES_OID "2.5.29.52"
995/** InhibitAnyPolicy OID. */
996#define RTCRX509_ID_CE_INHIBIT_ANY_POLICY_OID "2.5.29.54"
997/** @} */
998
999
1000/*
1001 * Sequence of X.509 Certifcates (IPRT representation).
1002 */
1003RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRX509CERTIFICATES, RTCRX509CERTIFICATE, RTDECL, RTCrX509Certificates);
1004
1005/**
1006 * Looks up a certificate by issuer name and serial number.
1007 *
1008 * @returns Pointer to the given certificate if found, NULL if not.
1009 * @param pCertificates The X.509 certificate set to search.
1010 * @param pIssuer The issuer name of the wanted certificate.
1011 * @param pSerialNumber The serial number of the wanted certificate.
1012 */
1013RTDECL(PCRTCRX509CERTIFICATE) RTCrX509Certificates_FindByIssuerAndSerialNumber(PCRTCRX509CERTIFICATES pCertificates,
1014 PCRTCRX509NAME pIssuer,
1015 PCRTASN1INTEGER pSerialNumber);
1016
1017
1018
1019RTDECL(int) RTCrX509CertPathsCreate(PRTCRX509CERTPATHS phCertPaths, PCRTCRX509CERTIFICATE pTarget);
1020RTDECL(uint32_t) RTCrX509CertPathsRetain(RTCRX509CERTPATHS hCertPaths);
1021RTDECL(uint32_t) RTCrX509CertPathsRelease(RTCRX509CERTPATHS hCertPaths);
1022RTDECL(int) RTCrX509CertPathsSetTrustedStore(RTCRX509CERTPATHS hCertPaths, RTCRSTORE hTrustedStore);
1023RTDECL(int) RTCrX509CertPathsSetUntrustedStore(RTCRX509CERTPATHS hCertPaths, RTCRSTORE hUntrustedStore);
1024RTDECL(int) RTCrX509CertPathsSetUntrustedArray(RTCRX509CERTPATHS hCertPaths, PCRTCRX509CERTIFICATE paCerts, uint32_t cCerts);
1025RTDECL(int) RTCrX509CertPathsSetUntrustedSet(RTCRX509CERTPATHS hCertPaths, struct RTCRPKCS7SETOFCERTS const *pSetOfCerts);
1026RTDECL(int) RTCrX509CertPathsSetValidTime(RTCRX509CERTPATHS hCertPaths, PCRTTIME pTime);
1027RTDECL(int) RTCrX509CertPathsSetValidTimeSpec(RTCRX509CERTPATHS hCertPaths, PCRTTIMESPEC pTimeSpec);
1028RTDECL(int) RTCrX509CertPathsCreateEx(PRTCRX509CERTPATHS phCertPaths, PCRTCRX509CERTIFICATE pTarget, RTCRSTORE hTrustedStore,
1029 RTCRSTORE hUntrustedStore, PCRTCRX509CERTIFICATE paUntrustedCerts, uint32_t cUntrustedCerts,
1030 PCRTTIMESPEC pValidTime);
1031RTDECL(int) RTCrX509CertPathsBuild(RTCRX509CERTPATHS hCertPaths, PRTERRINFO pErrInfo);
1032RTDECL(int) RTCrX509CertPathsDumpOne(RTCRX509CERTPATHS hCertPaths, uint32_t iPath, uint32_t uVerbosity,
1033 PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser);
1034RTDECL(int) RTCrX509CertPathsDumpAll(RTCRX509CERTPATHS hCertPaths, uint32_t uVerbosity,
1035 PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser);
1036
1037RTDECL(int) RTCrX509CertPathsValidateOne(RTCRX509CERTPATHS hCertPaths, uint32_t iPath, PRTERRINFO pErrInfo);
1038RTDECL(int) RTCrX509CertPathsValidateAll(RTCRX509CERTPATHS hCertPaths, uint32_t *pcValidPaths, PRTERRINFO pErrInfo);
1039
1040RTDECL(uint32_t) RTCrX509CertPathsGetPathCount(RTCRX509CERTPATHS hCertPaths);
1041RTDECL(int) RTCrX509CertPathsQueryPathInfo(RTCRX509CERTPATHS hCertPaths, uint32_t iPath,
1042 bool *pfTrusted, uint32_t *pcNodes, PCRTCRX509NAME *ppSubject,
1043 PCRTCRX509SUBJECTPUBLICKEYINFO *ppPublicKeyInfo,
1044 PCRTCRX509CERTIFICATE *ppCert, PCRTCRCERTCTX *ppCertCtx, int *prcVerify);
1045RTDECL(uint32_t) RTCrX509CertPathsGetPathLength(RTCRX509CERTPATHS hCertPaths, uint32_t iPath);
1046RTDECL(int) RTCrX509CertPathsGetPathVerifyResult(RTCRX509CERTPATHS hCertPaths, uint32_t iPath);
1047RTDECL(PCRTCRX509CERTIFICATE) RTCrX509CertPathsGetPathNodeCert(RTCRX509CERTPATHS hCertPaths, uint32_t iPath, uint32_t iNode);
1048
1049
1050RT_C_DECLS_END
1051
1052/** @} */
1053
1054/** @} */
1055
1056#endif
1057
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette