2 * Copyright (c) 2003,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <Security/SecCmsBase.h>
29 #include <Security/nameTemplates.h>
30 #include <Security/SecCertificate.h>
31 #include <CoreFoundation/CFDate.h>
32 #include <Security/SecTrust.h>
35 /************************************************************************/
38 typedef void CERTVerifyLog
;
40 void CERT_NormalizeX509NameNSS(NSS_Name
*nssName
);
42 SecIdentityRef
CERT_FindIdentityByUsage(SecKeychainRef keychainOrArray
,
43 char *nickname
, SECCertUsage usage
, Boolean validOnly
, void *proto_win
);
45 SecCertificateRef
CERT_FindUserCertByUsage(SecKeychainRef dbhandle
,
46 char *nickname
,SECCertUsage usage
,Boolean validOnly
,void *proto_win
);
48 // Find a certificate in the database by a email address or nickname
49 // "name" is the email address or nickname to look up
50 SecCertificateRef
CERT_FindCertByNicknameOrEmailAddr(SecKeychainRef dbhandle
, char *name
);
52 SecPublicKeyRef
SECKEY_CopyPublicKey(SecPublicKeyRef pubKey
);
53 void SECKEY_DestroyPublicKey(SecPublicKeyRef CF_CONSUMED pubKey
);
54 SecPublicKeyRef
SECKEY_CopyPrivateKey(SecPublicKeyRef privKey
);
55 void SECKEY_DestroyPrivateKey(SecPublicKeyRef privKey
);
56 void CERT_DestroyCertificate(SecCertificateRef cert
);
57 SecCertificateRef
CERT_DupCertificate(SecCertificateRef cert
);
59 // from security/nss/lib/certdb/cert.h
63 CERTCertificate * -> SecCertificateRef
64 SECKEYPublicKey * -> SecPublicKeyRef
65 CERTCertDBHandle * -> SecKeychainRef
66 CERT_GetDefaultCertDB -> OSStatus SecKeychainCopyDefault(SecKeychainRef *keychain);
67 CERTCertificateList * -> CFArrayRef
70 // Generate a certificate chain from a certificate.
72 CF_RETURNS_RETAINED CFArrayRef
CERT_CertChainFromCert(SecCertificateRef cert
, SECCertUsage usage
,Boolean includeRoot
, Boolean mustIncludeRoot
);
74 CF_RETURNS_RETAINED CFArrayRef
CERT_CertListFromCert(SecCertificateRef cert
);
76 CF_RETURNS_RETAINED CFArrayRef
CERT_DupCertList(CFArrayRef oldList
);
78 // Extract a public key object from a SubjectPublicKeyInfo
79 CF_RETURNS_RETAINED SecPublicKeyRef
CERT_ExtractPublicKey(SecCertificateRef cert
);
81 SECStatus
CERT_CheckCertUsage (SecCertificateRef cert
,unsigned char usage
);
83 // Find a certificate in the database by a email address
84 // "emailAddr" is the email address to look up
85 SecCertificateRef
CERT_FindCertByEmailAddr(SecKeychainRef keychainOrArray
, char *emailAddr
);
87 // Find a certificate in the database by a DER encoded certificate
88 // "derCert" is the DER encoded certificate
89 SecCertificateRef
CERT_FindCertByDERCert(SecKeychainRef keychainOrArray
, const SECItem
*derCert
);
91 // Generate a certificate key from the issuer and serialnumber, then look it up in the database.
92 // Return the cert if found. "issuerAndSN" is the issuer and serial number to look for
93 SecCertificateRef
CERT_FindCertByIssuerAndSN (CFTypeRef keychainOrArray
,
94 CSSM_DATA_PTR
*rawCerts
, CFArrayRef certList
,
95 PRArenaPool
*pl
, const SecCmsIssuerAndSN
*issuerAndSN
);
97 SecCertificateRef
CERT_FindCertBySubjectKeyID (CFTypeRef keychainOrArray
,
98 CSSM_DATA_PTR
*rawCerts
, CFArrayRef certList
, const SECItem
*subjKeyID
);
100 SecIdentityRef
CERT_FindIdentityByIssuerAndSN (CFTypeRef keychainOrArray
, const SecCmsIssuerAndSN
*issuerAndSN
);
102 SecIdentityRef
CERT_FindIdentityBySubjectKeyID (CFTypeRef keychainOrArray
, const SECItem
*subjKeyID
);
104 // find the smime symmetric capabilities profile for a given cert
105 SECItem
*CERT_FindSMimeProfile(SecCertificateRef cert
);
107 // Return the decoded value of the subjectKeyID extension. The caller should
108 // free up the storage allocated in retItem->data.
109 SECStatus
CERT_FindSubjectKeyIDExtension (SecCertificateRef cert
, SECItem
*retItem
);
111 // Extract the issuer and serial number from a certificate
112 SecCmsIssuerAndSN
*CERT_GetCertIssuerAndSN(PRArenaPool
*pl
, SecCertificateRef cert
);
114 // import a collection of certs into the temporary or permanent cert database
115 SECStatus
CERT_ImportCerts(SecKeychainRef keychain
, SECCertUsage usage
,unsigned int ncerts
,
116 SECItem
**derCerts
,SecCertificateRef
**retCerts
, Boolean keepCerts
,Boolean caOnly
, char *nickname
);
118 SECStatus
CERT_SaveSMimeProfile(SecCertificateRef cert
, SECItem
*emailProfile
,SECItem
*profileTime
);
120 // Check the hostname to make sure that it matches the shexp that
121 // is given in the common name of the certificate.
122 SECStatus
CERT_VerifyCertName(SecCertificateRef cert
, const char *hostname
);
124 SECStatus
CERT_VerifyCert(SecKeychainRef keychainOrArray
, SecCertificateRef cert
,
125 const CSSM_DATA_PTR
*otherCerts
, /* intermediates */
126 CFTypeRef policies
, CFAbsoluteTime stime
, SecTrustRef
*trustRef
);
128 CF_RETURNS_RETAINED CFTypeRef
CERT_PolicyForCertUsage(SECCertUsage certUsage
);
130 int CERT_CompareCssmData(const CSSM_DATA
*d1
, const CSSM_DATA
*d2
);
132 /************************************************************************/
135 #endif /* _CERT_H_ */