OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cert/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
9 | 9 |
10 #include <cert.h> | 10 #include <cert.h> |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return sha1; | 218 return sha1; |
219 CC_SHA1_Update(&sha1_ctx, | 219 CC_SHA1_Update(&sha1_ctx, |
220 CFDataGetBytePtr(cert_data), | 220 CFDataGetBytePtr(cert_data), |
221 CFDataGetLength(cert_data)); | 221 CFDataGetLength(cert_data)); |
222 } | 222 } |
223 CC_SHA1_Final(sha1.data, &sha1_ctx); | 223 CC_SHA1_Final(sha1.data, &sha1_ctx); |
224 return sha1; | 224 return sha1; |
225 } | 225 } |
226 | 226 |
227 // static | 227 // static |
228 X509Certificate::OSCertHandle | 228 X509Certificate::OSCertHandle X509Certificate::ReadOSCertHandleFromPickle( |
229 X509Certificate::ReadOSCertHandleFromPickle(PickleIterator* pickle_iter) { | 229 base::PickleIterator* pickle_iter) { |
230 return x509_util::ReadOSCertHandleFromPickle(pickle_iter); | 230 return x509_util::ReadOSCertHandleFromPickle(pickle_iter); |
231 } | 231 } |
232 | 232 |
233 // static | 233 // static |
234 bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, | 234 bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, |
235 Pickle* pickle) { | 235 base::Pickle* pickle) { |
236 ScopedCFTypeRef<CFDataRef> cert_data(SecCertificateCopyData(cert_handle)); | 236 ScopedCFTypeRef<CFDataRef> cert_data(SecCertificateCopyData(cert_handle)); |
237 if (!cert_data) | 237 if (!cert_data) |
238 return false; | 238 return false; |
239 | 239 |
240 return pickle->WriteData( | 240 return pickle->WriteData( |
241 reinterpret_cast<const char*>(CFDataGetBytePtr(cert_data)), | 241 reinterpret_cast<const char*>(CFDataGetBytePtr(cert_data)), |
242 CFDataGetLength(cert_data)); | 242 CFDataGetLength(cert_data)); |
243 } | 243 } |
244 | 244 |
245 // static | 245 // static |
246 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, | 246 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, |
247 size_t* size_bits, | 247 size_t* size_bits, |
248 PublicKeyType* type) { | 248 PublicKeyType* type) { |
249 x509_util_ios::NSSCertificate nss_cert(cert_handle); | 249 x509_util_ios::NSSCertificate nss_cert(cert_handle); |
250 x509_util::GetPublicKeyInfo(nss_cert.cert_handle(), size_bits, type); | 250 x509_util::GetPublicKeyInfo(nss_cert.cert_handle(), size_bits, type); |
251 } | 251 } |
252 | 252 |
253 // static | 253 // static |
254 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { | 254 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { |
255 x509_util_ios::NSSCertificate nss_cert(cert_handle); | 255 x509_util_ios::NSSCertificate nss_cert(cert_handle); |
256 crypto::ScopedSECKEYPublicKey public_key( | 256 crypto::ScopedSECKEYPublicKey public_key( |
257 CERT_ExtractPublicKey(nss_cert.cert_handle())); | 257 CERT_ExtractPublicKey(nss_cert.cert_handle())); |
258 if (!public_key.get()) | 258 if (!public_key.get()) |
259 return false; | 259 return false; |
260 return SECSuccess == CERT_VerifySignedDataWithPublicKey( | 260 return SECSuccess == CERT_VerifySignedDataWithPublicKey( |
261 &nss_cert.cert_handle()->signatureWrap, public_key.get(), NULL); | 261 &nss_cert.cert_handle()->signatureWrap, public_key.get(), NULL); |
262 } | 262 } |
263 | 263 |
264 } // namespace net | 264 } // namespace net |
OLD | NEW |