5 * Created by john on Wed Mar 12 2003.
6 * Copyright (c) 2003 __MyCompanyName__. All rights reserved.
13 #include "SecCmsBase.h"
14 #include <Security/nameTemplates.h>
15 #include <Security/SecCertificate.h>
16 #include <CoreFoundation/CFDate.h>
17 #include <Security/SecTrust.h>
19 #include <security_asn1/seccomon.h>
21 /************************************************************************/
24 bool CERT_CheckIssuerAndSerial(SecCertificateRef cert
, SecAsn1Item
*issuer
, SecAsn1Item
*serial
);
26 typedef void CERTVerifyLog
;
28 void CERT_NormalizeX509NameNSS(NSS_Name
*nssName
);
30 SecIdentityRef
CERT_FindIdentityByUsage(SecKeychainRef keychainOrArray
,
31 char *nickname
, SECCertUsage usage
, Boolean validOnly
, void *proto_win
);
33 SecCertificateRef
CERT_FindUserCertByUsage(SecKeychainRef dbhandle
,
34 char *nickname
,SECCertUsage usage
,Boolean validOnly
,void *proto_win
);
36 // Find a certificate in the database by a email address or nickname
37 // "name" is the email address or nickname to look up
38 SecCertificateRef
CERT_FindCertByNicknameOrEmailAddr(SecKeychainRef dbhandle
, char *name
);
40 SecPublicKeyRef
SECKEY_CopyPublicKey(SecPublicKeyRef pubKey
);
41 void SECKEY_DestroyPublicKey(SecPublicKeyRef pubKey
);
42 SecPublicKeyRef
SECKEY_CopyPrivateKey(SecPublicKeyRef privKey
);
43 void SECKEY_DestroyPrivateKey(SecPublicKeyRef privKey
);
44 void CERT_DestroyCertificate(SecCertificateRef cert
);
45 SecCertificateRef
CERT_DupCertificate(SecCertificateRef cert
);
47 // from security/nss/lib/certdb/cert.h
51 CERTCertificate * -> SecCertificateRef
52 SECKEYPublicKey * -> SecPublicKeyRef
53 CERTCertDBHandle * -> SecKeychainRef
54 CERT_GetDefaultCertDB -> OSStatus SecKeychainCopyDefault(SecKeychainRef *keychain);
55 CERTCertificateList * -> CFArrayRef
58 // Generate a certificate chain from a certificate.
60 CF_RETURNS_RETAINED CFArrayRef
CERT_CertChainFromCert(SecCertificateRef cert
, SECCertUsage usage
,Boolean includeRoot
);
62 CFArrayRef
CERT_CertListFromCert(SecCertificateRef cert
);
64 CFArrayRef
CERT_DupCertList(CFArrayRef oldList
);
66 // Extract a public key object from a SubjectPublicKeyInfo
67 SecPublicKeyRef
CERT_ExtractPublicKey(SecCertificateRef cert
);
69 SECStatus
CERT_CheckCertUsage (SecCertificateRef cert
,unsigned char usage
);
71 // Find a certificate in the database by a email address
72 // "emailAddr" is the email address to look up
73 SecCertificateRef
CERT_FindCertByEmailAddr(SecKeychainRef keychainOrArray
, char *emailAddr
);
75 // Find a certificate in the database by a DER encoded certificate
76 // "derCert" is the DER encoded certificate
77 SecCertificateRef
CERT_FindCertByDERCert(SecKeychainRef keychainOrArray
, const SecAsn1Item
*derCert
);
79 // Generate a certificate key from the issuer and serialnumber, then look it up in the database.
80 // Return the cert if found. "issuerAndSN" is the issuer and serial number to look for
81 SecCertificateRef
CERT_FindCertByIssuerAndSN (CFTypeRef keychainOrArray
, const SecCmsIssuerAndSN
*issuerAndSN
);
83 SecCertificateRef
CERT_FindCertBySubjectKeyID (CFTypeRef keychainOrArray
, const SecAsn1Item
*subjKeyID
);
85 SecIdentityRef
CERT_FindIdentityByIssuerAndSN (CFTypeRef keychainOrArray
, const SecCmsIssuerAndSN
*issuerAndSN
);
86 SecCertificateRef
CERT_FindCertificateByIssuerAndSN (CFTypeRef keychainOrArray
, const SecCmsIssuerAndSN
*issuerAndSN
);
88 SecIdentityRef
CERT_FindIdentityBySubjectKeyID (CFTypeRef keychainOrArray
, const SecAsn1Item
*subjKeyID
);
90 // find the smime symmetric capabilities profile for a given cert
91 SecAsn1Item
*CERT_FindSMimeProfile(SecCertificateRef cert
);
93 // Return the decoded value of the subjectKeyID extension. The caller should
94 // free up the storage allocated in retItem->data.
95 SECStatus
CERT_FindSubjectKeyIDExtension (SecCertificateRef cert
, SecAsn1Item
*retItem
);
97 // Extract the issuer and serial number from a certificate
98 SecCmsIssuerAndSN
*CERT_GetCertIssuerAndSN(PRArenaPool
*pl
, SecCertificateRef cert
);
100 // import a collection of certs into the temporary or permanent cert database
101 SECStatus
CERT_ImportCerts(SecKeychainRef keychain
, SECCertUsage usage
,unsigned int ncerts
,
102 SecAsn1Item
**derCerts
,SecCertificateRef
**retCerts
, Boolean keepCerts
,Boolean caOnly
, char *nickname
);
104 SECStatus
CERT_SaveSMimeProfile(SecCertificateRef cert
, SecAsn1Item
*emailProfile
,SecAsn1Item
*profileTime
);
106 // Check the hostname to make sure that it matches the shexp that
107 // is given in the common name of the certificate.
108 SECStatus
CERT_VerifyCertName(SecCertificateRef cert
, const char *hostname
);
110 SECStatus
CERT_VerifyCert(SecKeychainRef keychainOrArray
, CFArrayRef cert
,
111 CFTypeRef policies
, CFAbsoluteTime stime
, SecTrustRef
*trustRef
);
113 CFTypeRef
CERT_PolicyForCertUsage(SECCertUsage certUsage
);
115 /************************************************************************/
118 #endif /* _CERT_H_ */