2 * Copyright (c) 2002 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.
19 // Certificate.h - Certificate objects
21 #ifndef _SECURITY_CERTIFICATE_H_
22 #define _SECURITY_CERTIFICATE_H_
24 #include <Security/Item.h>
26 #include <Security/StorageManager.h>
27 // @@@ This should not be here.
28 #include <Security/SecBase.h>
29 #include <Security/clclient.h>
34 namespace KeychainCore
39 class Certificate
: public ItemImpl
43 SECCFFUNCTIONS(Certificate
, SecCertificateRef
, errSecInvalidItemRef
)
45 static CL
clForType(CSSM_CERT_TYPE type
);
47 // new item constructor
48 Certificate(const CSSM_DATA
&data
, CSSM_CERT_TYPE type
, CSSM_CERT_ENCODING encoding
);
50 // db item contstructor
51 Certificate(const Keychain
&keychain
, const PrimaryKey
&primaryKey
, const CssmClient::DbUniqueRecord
&uniqueId
);
53 // PrimaryKey item contstructor
54 Certificate(const Keychain
&keychain
, const PrimaryKey
&primaryKey
);
56 Certificate(Certificate
&certificate
);
57 virtual ~Certificate() throw();
59 virtual void update();
60 virtual Item
copyTo(const Keychain
&keychain
, Access
*newAccess
= NULL
);
61 virtual void didModify(); // Forget any attributes and data we just wrote to the db
63 const CssmData
&data();
64 CSSM_CERT_TYPE
type();
65 CSSM_CERT_ENCODING
encoding();
66 CFStringRef
commonName();
67 CFStringRef
copyFirstEmailAddress();
68 CFArrayRef
copyEmailAddresses();
69 void getSubject(CSSM_X509_NAME
&outSubject
);
70 void getIssuer(CSSM_X509_NAME
&outName
);
71 const CSSM_X509_ALGORITHM_IDENTIFIER
*algorithmID();
72 CSSM_CL_HANDLE
clHandle();
73 void inferLabel(bool addLabel
, CFStringRef
*rtnString
= NULL
);
74 SecPointer
<KeyItem
> publicKey();
75 const CssmData
&publicKeyHash();
77 static KCCursor
cursorForIssuerAndSN(const StorageManager::KeychainList
&keychains
, const CssmData
&issuer
, const CssmData
&serialNumber
);
78 static KCCursor
cursorForSubjectKeyID(const StorageManager::KeychainList
&keychains
, const CssmData
&subjectKeyID
);
79 static KCCursor
cursorForEmail(const StorageManager::KeychainList
&keychains
, const char *emailAddress
);
81 static SecPointer
<Certificate
> findByIssuerAndSN(const StorageManager::KeychainList
&keychains
, const CssmData
&issuer
, const CssmData
&serialNumber
);
82 static SecPointer
<Certificate
> findBySubjectKeyID(const StorageManager::KeychainList
&keychains
, const CssmData
&subjectKeyID
);
83 static SecPointer
<Certificate
> findByEmail(const StorageManager::KeychainList
&keychains
, const char *emailAddress
);
85 static void normalizeEmailAddress(CSSM_DATA
&emailAddress
);
86 static void getEmailAddresses(CSSM_DATA_PTR
*sanValues
, CSSM_DATA_PTR snValue
, std::vector
<CssmData
> &emailAddresses
);
88 bool operator < (Certificate
&other
);
89 bool operator == (Certificate
&other
);
92 CSSM_DATA_PTR
copyFirstFieldValue(const CSSM_OID
&field
);
93 void releaseFieldValue(const CSSM_OID
&field
, CSSM_DATA_PTR fieldValue
);
95 CSSM_DATA_PTR
*copyFieldValues(const CSSM_OID
&field
);
96 void releaseFieldValues(const CSSM_OID
&field
, CSSM_DATA_PTR
*fieldValues
);
99 virtual PrimaryKey
add(Keychain
&keychain
);
100 CSSM_HANDLE
certHandle();
102 void addParsedAttribute(const CSSM_DB_ATTRIBUTE_INFO
&info
, const CSSM_OID
&field
);
104 void populateAttributes();
107 bool mHaveTypeAndEncoding
;
108 CSSM_CERT_TYPE mType
;
109 CSSM_CERT_ENCODING mEncoding
;
111 CSSM_HANDLE mCertHandle
;
112 CssmData mPublicKeyHash
;
113 uint8 mPublicKeyHashBytes
[20];
114 CSSM_DATA_PTR mV1SubjectPublicKeyCStructValue
; // Hack to prevent algorithmID() from leaking.
117 } // end namespace KeychainCore
119 } // end namespace Security
121 #endif // !_SECURITY_CERTIFICATE_H_