| 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 "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 *type = kPublicKeyTypeECDSA; | 370 *type = kPublicKeyTypeECDSA; |
| 371 *size_bits = EVP_PKEY_bits(key); | 371 *size_bits = EVP_PKEY_bits(key); |
| 372 break; | 372 break; |
| 373 case EVP_PKEY_DH: | 373 case EVP_PKEY_DH: |
| 374 *type = kPublicKeyTypeDH; | 374 *type = kPublicKeyTypeDH; |
| 375 *size_bits = EVP_PKEY_size(key) * 8; | 375 *size_bits = EVP_PKEY_size(key) * 8; |
| 376 break; | 376 break; |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 // static | |
| 381 X509Certificate::SignatureHashAlgorithm | |
| 382 X509Certificate::GetSignatureHashAlgorithm(OSCertHandle cert_handle) { | |
| 383 int sig_alg = OBJ_obj2nid(cert_handle->sig_alg->algorithm); | |
| 384 if (sig_alg == NID_md2WithRSAEncryption) | |
| 385 return kSignatureHashAlgorithmMd2; | |
| 386 if (sig_alg == NID_md4WithRSAEncryption) | |
| 387 return kSignatureHashAlgorithmMd4; | |
| 388 if (sig_alg == NID_md5WithRSAEncryption || sig_alg == NID_md5WithRSA) | |
| 389 return kSignatureHashAlgorithmMd5; | |
| 390 if (sig_alg == NID_sha1WithRSAEncryption || sig_alg == NID_dsaWithSHA || | |
| 391 sig_alg == NID_dsaWithSHA1 || sig_alg == NID_dsaWithSHA1_2 || | |
| 392 sig_alg == NID_sha1WithRSA || sig_alg == NID_ecdsa_with_SHA1) { | |
| 393 return kSignatureHashAlgorithmSha1; | |
| 394 } | |
| 395 return kSignatureHashAlgorithmOther; | |
| 396 } | |
| 397 | |
| 398 bool X509Certificate::IsIssuedByEncoded( | 380 bool X509Certificate::IsIssuedByEncoded( |
| 399 const std::vector<std::string>& valid_issuers) { | 381 const std::vector<std::string>& valid_issuers) { |
| 400 if (valid_issuers.empty()) | 382 if (valid_issuers.empty()) |
| 401 return false; | 383 return false; |
| 402 | 384 |
| 403 // Convert to a temporary list of X509_NAME objects. | 385 // Convert to a temporary list of X509_NAME objects. |
| 404 // It will own the objects it points to. | 386 // It will own the objects it points to. |
| 405 bssl::UniquePtr<STACK_OF(X509_NAME)> issuer_names(sk_X509_NAME_new_null()); | 387 bssl::UniquePtr<STACK_OF(X509_NAME)> issuer_names(sk_X509_NAME_new_null()); |
| 406 if (!issuer_names.get()) | 388 if (!issuer_names.get()) |
| 407 return false; | 389 return false; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { | 432 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { |
| 451 bssl::UniquePtr<EVP_PKEY> scoped_key(X509_get_pubkey(cert_handle)); | 433 bssl::UniquePtr<EVP_PKEY> scoped_key(X509_get_pubkey(cert_handle)); |
| 452 if (!scoped_key) | 434 if (!scoped_key) |
| 453 return false; | 435 return false; |
| 454 if (!X509_verify(cert_handle, scoped_key.get())) | 436 if (!X509_verify(cert_handle, scoped_key.get())) |
| 455 return false; | 437 return false; |
| 456 return X509_check_issued(cert_handle, cert_handle) == X509_V_OK; | 438 return X509_check_issued(cert_handle, cert_handle) == X509_V_OK; |
| 457 } | 439 } |
| 458 | 440 |
| 459 } // namespace net | 441 } // namespace net |
| OLD | NEW |