]>
git.saurik.com Git - apple/security.git/blob - Keychain/Certificates.cpp
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.
20 File: Certificates.cpp
22 Contains: Working with Certificates
24 Copyright: 2002 by Apple Computer, Inc., all rights reserved.
29 #include <Security/Certificates.h>
30 #include <Security/CertLibRef.h>//%%%should be included in Certificates.h
32 using namespace KeychainCore
;
34 void CertificateImpl::CertificateImplCommonInit(CSSM_CERT_TYPE type
)
39 // Create a CL reference for this certificate type.
40 // %%%find us the 1st CL reference we can find for this cert type (this can change)
42 CertLibCursorImpl
* cursor
= NULL
;
43 cursor
= new CertLibCursorImpl(type
);
45 MacOSError::throwMe(errSecItemNotFound
/*%%%*/);
47 CertLib certLib
;//%%%allocated on the stack?!
48 if (!cursor
->next(certLib
))
51 MacOSError::throwMe(errSecItemNotFound
/*%%%*/);
55 mCLReference
= CertLibRef::handle(certLib
); // 'tis a SecCertificateLibraryRef
58 CertificateImpl::CertificateImpl(const CSSM_DATA
* data
, CSSM_CERT_TYPE type
):
61 CertificateImplCommonInit(type
);
62 (void*)mData
.Data
= malloc(data
->Length
);
63 memcpy(mData
.Data
, data
->Data
, data
->Length
);
64 mData
.Length
= data
->Length
;
67 CertificateImpl::CertificateImpl(SecKeychainItemRef item
, CSSM_CERT_TYPE type
)
69 CertificateImplCommonInit(type
);
76 CertificateImpl::~CertificateImpl()
81 SecKeychainItemFreeContent(NULL
, mData
.Data
); // free if copied via SecKeychainItemCopyContent.
83 free(mData
.Data
); // free if copied from the caller when cert ref was created.
89 SecRelease(mCLReference
);
92 CSSM_DATA
* CertificateImpl::getData()
97 SecKeychainItemFreeContent(NULL
, mData
.Data
);
99 OSStatus result
= SecKeychainItemCopyContent(mItem
, NULL
, NULL
, &mData
.Length
, (void**)&(mData
.Data
));
101 MacOSError::throwMe(result
);
102 } // otherwise, return the data originally specified when the cert ref was created.
106 CSSM_X509_NAME
* CertificateImpl::getSubject()
108 return NULL
;//%%%use mCLReference to get subject
111 CSSM_X509_NAME
* CertificateImpl::getIssuer()
113 return NULL
;//%%%use mCLReference to get issuer