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

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

Issue 687833002: Get net_unittests working on Windows BoringSSL port. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wincrypt
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/cert/sha256_legacy_support_win.cc ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <blapi.h> // Implement CalculateChainFingerprint() with NSS.
8
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
11 #include "base/pickle.h" 9 #include "base/pickle.h"
12 #include "base/sha1.h" 10 #include "base/sha1.h"
13 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
15 #include "crypto/capi_util.h" 13 #include "crypto/capi_util.h"
16 #include "crypto/scoped_capi_types.h" 14 #include "crypto/scoped_capi_types.h"
17 #include "crypto/sha2.h" 15 #include "crypto/sha2.h"
18 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
19 17
18 // Implement CalculateChainFingerprint() with our native crypto library.
19 #if defined(USE_OPENSSL)
20 #include <openssl/sha.h>
21 #else
22 #include <blapi.h>
23 #endif
24
20 #pragma comment(lib, "crypt32.lib") 25 #pragma comment(lib, "crypt32.lib")
21 26
22 using base::Time; 27 using base::Time;
23 28
24 namespace net { 29 namespace net {
25 30
26 namespace { 31 namespace {
27 32
28 typedef crypto::ScopedCAPIHandle< 33 typedef crypto::ScopedCAPIHandle<
29 HCERTSTORE, 34 HCERTSTORE,
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // Use crypto::SHA256HashString for two reasons: 332 // Use crypto::SHA256HashString for two reasons:
328 // * < Windows Vista does not have universal SHA-256 support. 333 // * < Windows Vista does not have universal SHA-256 support.
329 // * More efficient on Windows > Vista (less overhead since non-default CSP 334 // * More efficient on Windows > Vista (less overhead since non-default CSP
330 // is not needed). 335 // is not needed).
331 base::StringPiece der_cert(reinterpret_cast<const char*>(cert->pbCertEncoded), 336 base::StringPiece der_cert(reinterpret_cast<const char*>(cert->pbCertEncoded),
332 cert->cbCertEncoded); 337 cert->cbCertEncoded);
333 crypto::SHA256HashString(der_cert, sha256.data, sha256_size); 338 crypto::SHA256HashString(der_cert, sha256.data, sha256_size);
334 return sha256; 339 return sha256;
335 } 340 }
336 341
337 // TODO(wtc): This function is implemented with NSS low-level hash 342 // TODO(wtc): This function is implemented with low-level NSS and BoringSSL
338 // functions to ensure it is fast. Reimplement this function with 343 // hash functions to ensure it is fast. Reimplement this function with
339 // CryptoAPI. May need to cache the HCRYPTPROV to reduce the overhead. 344 // CryptoAPI. May need to cache the HCRYPTPROV to reduce the overhead.
340 // static 345 // static
Ryan Sleevi 2014/10/29 20:47:59 Remove this comment entirely. Not gonna happen.
davidben 2014/10/29 23:04:58 Done.
341 SHA1HashValue X509Certificate::CalculateCAFingerprint( 346 SHA1HashValue X509Certificate::CalculateCAFingerprint(
342 const OSCertHandles& intermediates) { 347 const OSCertHandles& intermediates) {
343 SHA1HashValue sha1; 348 SHA1HashValue sha1;
344 memset(sha1.data, 0, sizeof(sha1.data)); 349 memset(sha1.data, 0, sizeof(sha1.data));
345 350
351 #if defined(USE_OPENSSL)
352 SHA_CTX ctx;
353 if (!SHA1_Init(&ctx))
354 return sha1;
355 for (size_t i = 0; i < intermediates.size(); ++i) {
356 PCCERT_CONTEXT ca_cert = intermediates[i];
357 if (!SHA1_Update(&ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded))
358 return sha1;
359 }
360 SHA1_Final(sha1.data, &ctx);
361 #else // !USE_OPENSSL
346 SHA1Context* sha1_ctx = SHA1_NewContext(); 362 SHA1Context* sha1_ctx = SHA1_NewContext();
347 if (!sha1_ctx) 363 if (!sha1_ctx)
348 return sha1; 364 return sha1;
349 SHA1_Begin(sha1_ctx); 365 SHA1_Begin(sha1_ctx);
350 for (size_t i = 0; i < intermediates.size(); ++i) { 366 for (size_t i = 0; i < intermediates.size(); ++i) {
351 PCCERT_CONTEXT ca_cert = intermediates[i]; 367 PCCERT_CONTEXT ca_cert = intermediates[i];
352 SHA1_Update(sha1_ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded); 368 SHA1_Update(sha1_ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded);
353 } 369 }
354 unsigned int result_len; 370 unsigned int result_len;
355 SHA1_End(sha1_ctx, sha1.data, &result_len, SHA1_LENGTH); 371 SHA1_End(sha1_ctx, sha1.data, &result_len, SHA1_LENGTH);
356 SHA1_DestroyContext(sha1_ctx, PR_TRUE); 372 SHA1_DestroyContext(sha1_ctx, PR_TRUE);
373 #endif // USE_OPENSSL
357 374
358 return sha1; 375 return sha1;
359 } 376 }
360 377
361 // static 378 // static
362 X509Certificate::OSCertHandle 379 X509Certificate::OSCertHandle
363 X509Certificate::ReadOSCertHandleFromPickle(PickleIterator* pickle_iter) { 380 X509Certificate::ReadOSCertHandleFromPickle(PickleIterator* pickle_iter) {
364 const char* data; 381 const char* data;
365 int length; 382 int length;
366 if (!pickle_iter->ReadData(&data, &length)) 383 if (!pickle_iter->ReadData(&data, &length))
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (IsCertNameBlobInIssuerList(&(*it)->pCertInfo->Issuer, 483 if (IsCertNameBlobInIssuerList(&(*it)->pCertInfo->Issuer,
467 valid_issuers)) { 484 valid_issuers)) {
468 return true; 485 return true;
469 } 486 }
470 } 487 }
471 488
472 return false; 489 return false;
473 } 490 }
474 491
475 } // namespace net 492 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/sha256_legacy_support_win.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698