| 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 <cert.h> | 5 #include <cert.h> |
| 6 #include <cryptohi.h> | 6 #include <cryptohi.h> |
| 7 #include <keyhi.h> | 7 #include <keyhi.h> |
| 8 #include <nss.h> | 8 #include <nss.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 #include <prtime.h> | 10 #include <prtime.h> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 211 } |
| 212 unsigned int result_len; | 212 unsigned int result_len; |
| 213 HASH_End(sha256_ctx, sha256.data, &result_len, | 213 HASH_End(sha256_ctx, sha256.data, &result_len, |
| 214 HASH_ResultLenContext(sha256_ctx)); | 214 HASH_ResultLenContext(sha256_ctx)); |
| 215 HASH_Destroy(sha256_ctx); | 215 HASH_Destroy(sha256_ctx); |
| 216 | 216 |
| 217 return sha256; | 217 return sha256; |
| 218 } | 218 } |
| 219 | 219 |
| 220 // static | 220 // static |
| 221 SHA256HashValue X509Certificate::CalculatePublicKeyHashSHA256( |
| 222 OSCertHandle cert) { |
| 223 SHA256HashValue sha256; |
| 224 memset(sha256.data, 0, sizeof(sha256.data)); |
| 225 |
| 226 DCHECK(NULL != cert->derPublicKey.data); |
| 227 DCHECK_NE(0U, cert->derPublicKey.len); |
| 228 SECStatus rv = HASH_HashBuf(HASH_AlgSHA256, sha256.data, |
| 229 cert->derPublicKey.data, cert->derPublicKey.len); |
| 230 DCHECK_EQ(rv, SECSuccess); |
| 231 |
| 232 return sha256; |
| 233 } |
| 234 |
| 235 // static |
| 221 X509Certificate::OSCertHandle X509Certificate::ReadOSCertHandleFromPickle( | 236 X509Certificate::OSCertHandle X509Certificate::ReadOSCertHandleFromPickle( |
| 222 base::PickleIterator* pickle_iter) { | 237 base::PickleIterator* pickle_iter) { |
| 223 return x509_util::ReadOSCertHandleFromPickle(pickle_iter); | 238 return x509_util::ReadOSCertHandleFromPickle(pickle_iter); |
| 224 } | 239 } |
| 225 | 240 |
| 226 // static | 241 // static |
| 227 bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, | 242 bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, |
| 228 base::Pickle* pickle) { | 243 base::Pickle* pickle) { |
| 229 return pickle->WriteData( | 244 return pickle->WriteData( |
| 230 reinterpret_cast<const char*>(cert_handle->derCert.data), | 245 reinterpret_cast<const char*>(cert_handle->derCert.data), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 245 return false; | 260 return false; |
| 246 if (SECSuccess != CERT_VerifySignedDataWithPublicKey( | 261 if (SECSuccess != CERT_VerifySignedDataWithPublicKey( |
| 247 &cert_handle->signatureWrap, public_key.get(), NULL)) { | 262 &cert_handle->signatureWrap, public_key.get(), NULL)) { |
| 248 return false; | 263 return false; |
| 249 } | 264 } |
| 250 return CERT_CompareName(&cert_handle->subject, &cert_handle->issuer) == | 265 return CERT_CompareName(&cert_handle->subject, &cert_handle->issuer) == |
| 251 SECEqual; | 266 SECEqual; |
| 252 } | 267 } |
| 253 | 268 |
| 254 } // namespace net | 269 } // namespace net |
| OLD | NEW |