2 * tpUtils.h - TP and cert group test support
8 #include <Security/cssmtype.h>
9 #include <Security/x509defs.h>
10 #include <Security/cssmapple.h>
13 #include <CoreFoundation/CoreFoundation.h>
14 #include <Security/Security.h>
20 #define TP_DB_ENABLE 1
23 * Given an array of certs and an uninitialized CSSM_CERTGROUP, place the
24 * certs into the certgroup and optionally into one of a list of DBs in
25 * random order. Optionaly the first cert in the array is placed in the
26 * first element of certgroup. Only error is memory error. It's legal to
27 * pass in an empty cert array.
29 CSSM_RETURN
tpMakeRandCertGroup(
30 CSSM_CL_HANDLE clHand
,
31 CSSM_DL_DB_LIST_PTR dbList
,
32 const CSSM_DATA_PTR certs
,
34 CSSM_CERTGROUP_PTR certGroup
,
35 CSSM_BOOL firstCertIsSubject
, // true: certs[0] goes to head
38 CSSM_BOOL allInDbs
, // all certs go to DBs
39 CSSM_BOOL skipFirstDb
); // no certs go to db[0]
41 CSSM_RETURN
tpStoreCert(
42 CSSM_DL_DB_HANDLE dlDb
,
43 const CSSM_DATA_PTR cert
,
45 CSSM_CERT_TYPE certType
, // e.g. CSSM_CERT_X_509v3
47 const CSSM_DATA
*issuer
, // (shouldn't this be subject?)
48 // normalized & encoded
50 CSSM_CERT_ENCODING certEncoding
, // e.g. CSSM_CERT_ENCODING_DER
51 const CSSM_DATA
*printName
,
52 const CSSM_DATA
*subject
); // normalized & encoded
55 * Store a cert when we don't already know the required fields. We'll
58 CSSM_RETURN
tpStoreRawCert(
59 CSSM_DL_DB_HANDLE dlDb
,
60 CSSM_CL_HANDLE clHand
,
61 const CSSM_DATA_PTR cert
);
64 * Generate numKeyPairs key pairs of specified algorithm and size.
65 * Key labels will be 'keyLabelBase' concatenated with a 4-digit
68 CSSM_RETURN
tpGenKeys(
69 CSSM_CSP_HANDLE cspHand
,
70 CSSM_DL_DB_HANDLE dbHand
, /* keys go here */
72 uint32 keyGenAlg
, /* CSSM_ALGID_RSA, etc. */
74 const char *keyLabelBase
, /* C string */
75 CSSM_KEY_PTR pubKeys
, /* array of keys RETURNED here */
76 CSSM_KEY_PTR privKeys
, /* array of keys RETURNED here */
77 CSSM_DATA_PTR paramData
= NULL
); // optional DSA params
80 * Generate a cert chain using specified key pairs. The last cert in the
81 * chain (certs[numCerts-1]) is a root cert, self-signed.
83 CSSM_RETURN
tpGenCerts(
84 CSSM_CSP_HANDLE cspHand
,
85 CSSM_CL_HANDLE clHand
,
87 uint32 sigAlg
, /* CSSM_ALGID_SHA1WithRSA, etc. */
88 const char *nameBase
, /* C string */
89 CSSM_KEY_PTR pubKeys
, /* array of public keys */
90 CSSM_KEY_PTR privKeys
, /* array of private keys */
91 CSSM_DATA_PTR certs
, /* array of certs RETURNED here */
92 const char *notBeforeStr
, /* from genTimeAtNowPlus() */
93 const char *notAfterStr
); /* from genTimeAtNowPlus() */
96 * Generate a cert chain using specified key pairs. The last cert in the
97 * chain (certs[numCerts-1]) is a root cert, self-signed. Store
98 * the certs indicated by corresponding element on storeArray. If
99 * storeArray[n].DLHandle == 0, the cert is not stored.
101 CSSM_RETURN
tpGenCertsStore(
102 CSSM_CSP_HANDLE cspHand
,
103 CSSM_CL_HANDLE clHand
,
105 uint32 sigAlg
, /* CSSM_ALGID_SHA1WithRSA, etc. */
106 const char *nameBase
, /* C string */
107 CSSM_KEY_PTR pubKeys
, /* array of public keys */
108 CSSM_KEY_PTR privKeys
, /* array of private keys */
109 CSSM_DL_DB_HANDLE
*storeArray
, /* array of certs stored here */
110 CSSM_DATA_PTR certs
, /* array of certs RETURNED here */
111 const char *notBeforeStr
, /* from genTimeAtNowPlus() */
112 const char *notAfterStr
); /* from genTimeAtNowPlus() */
114 /* free a CSSM_CERT_GROUP */
115 void tpFreeCertGroup(
116 CSSM_CERTGROUP_PTR certGroup
,
117 CSSM_BOOL freeCertData
, // free individual CertList.Data
118 CSSM_BOOL freeStruct
); // free the overall CSSM_CERTGROUP
120 CSSM_BOOL
tpCompareCertGroups(
121 const CSSM_CERTGROUP
*grp1
,
122 const CSSM_CERTGROUP
*grp2
);
124 CSSM_RETURN
clDeleteAllCerts(CSSM_DL_DB_HANDLE dlDb
);
127 * Wrapper for CSSM_TP_CertGroupVerify.
129 CSSM_RETURN
tpCertGroupVerify(
130 CSSM_TP_HANDLE tpHand
,
131 CSSM_CL_HANDLE clHand
,
132 CSSM_CSP_HANDLE cspHand
,
133 CSSM_DL_DB_LIST_PTR dbListPtr
,
134 const CSSM_OID
*policy
, // optional
135 const CSSM_DATA
*fieldOpts
, // optional
136 const CSSM_DATA
*actionData
, // optional
138 const CSSM_CERTGROUP
*certGroup
,
139 CSSM_DATA_PTR anchorCerts
,
140 unsigned numAnchorCerts
,
141 CSSM_TP_STOP_ON stopOn
, // CSSM_TP_STOP_ON_POLICY, etc.
142 CSSM_TIMESTRING cssmTimeStr
,// optional
143 CSSM_TP_VERIFY_CONTEXT_RESULT_PTR result
); // RETURNED
145 CSSM_RETURN
tpKcOpen(
146 CSSM_DL_HANDLE dlHand
,
148 const char *pwd
, // optional to avoid UI
150 CSSM_DB_HANDLE
*dbHand
); // RETURNED
152 CSSM_RETURN
freeVfyResult(
153 CSSM_TP_VERIFY_CONTEXT_RESULT
*ctx
);
156 unsigned numCerts
, // from CertGroup
157 const CSSM_TP_APPLE_EVIDENCE_INFO
*info
);
160 const CSSM_TP_VERIFY_CONTEXT_RESULT
*vfyResult
);
163 * Obtain system anchors in CF and in CSSM_DATA form.
164 * Caller must CFRelease the returned rootArray and
165 * free() the returned CSSM_DATA array, but not its
166 * contents - SecCertificates themselves own that.
168 OSStatus
getSystemAnchors(
169 CFArrayRef
*rootArray
, /* RETURNED */
170 CSSM_DATA
**anchors
, /* RETURNED */
171 unsigned *numAnchors
); /* RETURNED */
173 /* get a SecCertificateRef from a file */
174 SecCertificateRef
certFromFile(
175 const char *fileName
);
180 #endif /* _TP_UTILS_H_ */