2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * SnaccUtils.h - snacc-related cert functions
22 * Created 9/1/2000 by Doug Mitchell.
23 * Copyright (c) 2000 by Apple Computer.
26 #ifndef _SNACC_UTILS_H_
27 #define _SNACC_UTILS_H_
29 #include <Security/cssmtype.h>
30 #include <Security/x509defs.h>
31 #include <Security/certextensions.h>
32 #include <Security/cssmdata.h>
33 #include "DecodedCert.h"
35 /* ghastly requirements of snacc-generated cert code */
36 #include <Security/asn-incl.h>
37 #include <Security/sm_vdatypes.h>
38 #include <Security/sm_x501if.h>
39 #include <Security/sm_x520sa.h>
40 #include <Security/sm_x411mtsas.h>
41 #include <Security/sm_x509cmn.h>
42 #include <Security/sm_x509af.h>
43 #include <Security/pkcs9oids.h>
44 #include <Security/sm_x509ce.h>
45 #include <Security/sm_cms.h>
46 #include <Security/sm_ess.h>
54 CL_certDecodeComponents(
55 const CssmData
&signedCert
, // DER-encoded
56 CssmOwnedData
&TBSCert
, // still DER-encoded
57 CssmOwnedData
&algId
, // ditto
58 CssmOwnedData
&sig
); // ditto
61 CL_certEncodeComponents(
62 const CssmData
&TBSCert
, // DER-encoded
63 const CssmData
&algId
, // ditto
64 const CssmData
&rawSig
, // the raw bits, not encoded
65 CssmOwnedData
&signedCert
); // DER-encoded
67 void CL_snaccOidToCssm(
70 CssmAllocator
&alloc
);
72 /* convert algorithm identifier between CSSM and snacc formats */
73 void CL_cssmAlgIdToSnacc (
74 const CSSM_X509_ALGORITHM_IDENTIFIER
&cssmAlgId
,
75 AlgorithmIdentifier
&snaccAlgId
);
77 void CL_snaccAlgIdToCssm (
78 const AlgorithmIdentifier
&snaccAlgId
,
79 CSSM_X509_ALGORITHM_IDENTIFIER
&cssmAlgId
,
80 CssmAllocator
&alloc
);
82 /* convert between uint32-style CSSM algorithm and snacc-style AsnOid */
83 CSSM_ALGORITHMS
CL_snaccOidToCssmAlg(
86 void CL_cssmAlgToSnaccOid(
87 CSSM_ALGORITHMS cssmAlg
,
90 /* set up a encoded NULL for AlgorithmIdentifier.parameters */
91 void CL_nullAlgParams(
92 AlgorithmIdentifier
&snaccAlgId
);
94 /* AsnOcts --> CSSM_DATA */
95 void CL_AsnOctsToCssmData(
98 CssmAllocator
&alloc
);
100 /* snacc-style GeneralNames --> CE_GeneralNames */
101 /* GeneralNames from sm_x509cmn.h */
102 void CL_snaccGeneralNamesToCdsa(
103 GeneralNames
&snaccObj
,
104 CE_GeneralNames
&cdsaObj
,
105 CssmAllocator
&alloc
);
107 /* CE_GeneralNames --> snacc-style GeneralNames */
108 GeneralNames
*CL_cdsaGeneralNamesToSnacc(
109 CE_GeneralNames
&cdsaObj
);
111 #define MAX_RDN_SIZE (4 * 1024)
113 void CL_normalizeString(
116 void CL_normalizeX509Name(
118 CssmAllocator
&alloc
);
121 * Obtain a CSSM_KEY from a SubjectPublicKeyInfo, inferring as much as we can
122 * from required fields (subjectPublicKeyInfo) and extensions (for
123 * KeyUse, obtained from the optional DecodedCert).
125 CSSM_KEY_PTR
CL_extractCSSMKey(
126 SubjectPublicKeyInfo
&snaccKeyInfo
,
127 CssmAllocator
&alloc
,
128 const DecodedCert
*decodedCert
); // optional
131 * Free key obtained in CL_extractCSSMKey().
134 CSSM_KEY_PTR cssmKey
,
135 CssmAllocator
&alloc
,
136 bool freeTop
= true); // delete the actual key
137 // as well as contents
143 #endif /* _SNACC_UTILS_H_ */