Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: net/cert/x509_certificate_win.cc

Issue 1882433002: Removing NSS files and USE_OPENSSL flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing header ordering. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <openssl/sha.h>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/memory/free_deleter.h" 10 #include "base/memory/free_deleter.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/numerics/safe_conversions.h" 12 #include "base/numerics/safe_conversions.h"
11 #include "base/pickle.h" 13 #include "base/pickle.h"
12 #include "base/sha1.h" 14 #include "base/sha1.h"
13 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "crypto/capi_util.h" 17 #include "crypto/capi_util.h"
16 #include "crypto/scoped_capi_types.h" 18 #include "crypto/scoped_capi_types.h"
17 #include "crypto/sha2.h" 19 #include "crypto/sha2.h"
18 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
19 21
20 // Implement CalculateChainFingerprint() with our native crypto library.
21 #if defined(USE_OPENSSL)
22 #include <openssl/sha.h>
23 #else
24 #include <blapi.h>
25 #endif
26
27 using base::Time; 22 using base::Time;
28 23
29 namespace net { 24 namespace net {
30 25
31 namespace { 26 namespace {
32 27
33 typedef crypto::ScopedCAPIHandle< 28 typedef crypto::ScopedCAPIHandle<
34 HCERTSTORE, 29 HCERTSTORE,
35 crypto::CAPIDestroyerWithFlags<HCERTSTORE, 30 crypto::CAPIDestroyerWithFlags<HCERTSTORE,
36 CertCloseStore, 0> > ScopedHCERTSTORE; 31 CertCloseStore, 0> > ScopedHCERTSTORE;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 cert->cbCertEncoded); 327 cert->cbCertEncoded);
333 crypto::SHA256HashString(der_cert, sha256.data, sha256_size); 328 crypto::SHA256HashString(der_cert, sha256.data, sha256_size);
334 return sha256; 329 return sha256;
335 } 330 }
336 331
337 SHA1HashValue X509Certificate::CalculateCAFingerprint( 332 SHA1HashValue X509Certificate::CalculateCAFingerprint(
338 const OSCertHandles& intermediates) { 333 const OSCertHandles& intermediates) {
339 SHA1HashValue sha1; 334 SHA1HashValue sha1;
340 memset(sha1.data, 0, sizeof(sha1.data)); 335 memset(sha1.data, 0, sizeof(sha1.data));
341 336
342 #if defined(USE_OPENSSL)
343 SHA_CTX ctx; 337 SHA_CTX ctx;
344 if (!SHA1_Init(&ctx)) 338 if (!SHA1_Init(&ctx))
345 return sha1; 339 return sha1;
346 for (size_t i = 0; i < intermediates.size(); ++i) { 340 for (size_t i = 0; i < intermediates.size(); ++i) {
347 PCCERT_CONTEXT ca_cert = intermediates[i]; 341 PCCERT_CONTEXT ca_cert = intermediates[i];
348 if (!SHA1_Update(&ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded)) 342 if (!SHA1_Update(&ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded))
349 return sha1; 343 return sha1;
350 } 344 }
351 SHA1_Final(sha1.data, &ctx); 345 SHA1_Final(sha1.data, &ctx);
352 #else // !USE_OPENSSL
353 SHA1Context* sha1_ctx = SHA1_NewContext();
354 if (!sha1_ctx)
355 return sha1;
356 SHA1_Begin(sha1_ctx);
357 for (size_t i = 0; i < intermediates.size(); ++i) {
358 PCCERT_CONTEXT ca_cert = intermediates[i];
359 SHA1_Update(sha1_ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded);
360 }
361 unsigned int result_len;
362 SHA1_End(sha1_ctx, sha1.data, &result_len, SHA1_LENGTH);
363 SHA1_DestroyContext(sha1_ctx, PR_TRUE);
364 #endif // USE_OPENSSL
365 346
366 return sha1; 347 return sha1;
367 } 348 }
368 349
369 // static 350 // static
370 X509Certificate::OSCertHandle X509Certificate::ReadOSCertHandleFromPickle( 351 X509Certificate::OSCertHandle X509Certificate::ReadOSCertHandleFromPickle(
371 base::PickleIterator* pickle_iter) { 352 base::PickleIterator* pickle_iter) {
372 const char* data; 353 const char* data;
373 int length; 354 int length;
374 if (!pickle_iter->ReadData(&data, &length)) 355 if (!pickle_iter->ReadData(&data, &length))
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 X509_ASN_ENCODING, 468 X509_ASN_ENCODING,
488 CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT, 469 CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT,
489 reinterpret_cast<void*>(const_cast<PCERT_CONTEXT>(cert_handle)), 470 reinterpret_cast<void*>(const_cast<PCERT_CONTEXT>(cert_handle)),
490 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, 471 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT,
491 reinterpret_cast<void*>(const_cast<PCERT_CONTEXT>(cert_handle)), 472 reinterpret_cast<void*>(const_cast<PCERT_CONTEXT>(cert_handle)),
492 0, 473 0,
493 NULL); 474 NULL);
494 } 475 }
495 476
496 } // namespace net 477 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698