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 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 CFArrayRef
CERT_CertChainFromCert(SecCertificateRef cert
, SECCertUsage usage
,Boolean includeRoot
);
74 CFArrayRef
CERT_CertListFromCert(SecCertificateRef cert
);
76 CFArrayRef
CERT_DupCertList(CFArrayRef oldList
);
78 // Extract a public key object from a SubjectPublicKeyInfo
79 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
, PRArenaPool
*pl
, const SecCmsIssuerAndSN
*issuerAndSN
);
96 SecCertificateRef
CERT_FindCertBySubjectKeyID (CFTypeRef keychainOrArray
,
97 CSSM_DATA_PTR
*rawCerts
, const SECItem
*subjKeyID
);
99 SecIdentityRef
CERT_FindIdentityByIssuerAndSN (CFTypeRef keychainOrArray
, const SecCmsIssuerAndSN
*issuerAndSN
);
101 SecIdentityRef
CERT_FindIdentityBySubjectKeyID (CFTypeRef keychainOrArray
, const SECItem
*subjKeyID
);
103 // find the smime symmetric capabilities profile for a given cert
104 SECItem
*CERT_FindSMimeProfile(SecCertificateRef cert
);
106 // Return the decoded value of the subjectKeyID extension. The caller should
107 // free up the storage allocated in retItem->data.
108 SECStatus
CERT_FindSubjectKeyIDExtension (SecCertificateRef cert
, SECItem
*retItem
);
110 // Extract the issuer and serial number from a certificate
111 SecCmsIssuerAndSN
*CERT_GetCertIssuerAndSN(PRArenaPool
*pl
, SecCertificateRef cert
);
113 // import a collection of certs into the temporary or permanent cert database
114 SECStatus
CERT_ImportCerts(SecKeychainRef keychain
, SECCertUsage usage
,unsigned int ncerts
,
115 SECItem
**derCerts
,SecCertificateRef
**retCerts
, Boolean keepCerts
,Boolean caOnly
, char *nickname
);
117 SECStatus
CERT_SaveSMimeProfile(SecCertificateRef cert
, SECItem
*emailProfile
,SECItem
*profileTime
);
119 // Check the hostname to make sure that it matches the shexp that
120 // is given in the common name of the certificate.
121 SECStatus
CERT_VerifyCertName(SecCertificateRef cert
, const char *hostname
);
123 SECStatus
CERT_VerifyCert(SecKeychainRef keychainOrArray
, SecCertificateRef cert
,
124 const CSSM_DATA_PTR
*otherCerts
, /* intermediates */
125 CFTypeRef policies
, CFAbsoluteTime stime
, SecTrustRef
*trustRef
);
127 CFTypeRef
CERT_PolicyForCertUsage(SECCertUsage certUsage
);
129 /************************************************************************/
132 #endif /* _CERT_H_ */