| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ssl/ssl_platform_key_util.h" | 5 #include "net/ssl/ssl_platform_key_util.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 CBS cbs; | 66 CBS cbs; |
| 67 CBS_init(&cbs, reinterpret_cast<const uint8_t*>(spki.data()), spki.size()); | 67 CBS_init(&cbs, reinterpret_cast<const uint8_t*>(spki.data()), spki.size()); |
| 68 bssl::UniquePtr<EVP_PKEY> key(EVP_parse_public_key(&cbs)); | 68 bssl::UniquePtr<EVP_PKEY> key(EVP_parse_public_key(&cbs)); |
| 69 if (!key || CBS_len(&cbs) != 0) { | 69 if (!key || CBS_len(&cbs) != 0) { |
| 70 LOG(ERROR) << "Could not parse public key."; | 70 LOG(ERROR) << "Could not parse public key."; |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 switch (EVP_PKEY_id(key.get())) { | 74 int key_type = EVP_PKEY_id(key.get()); |
| 75 switch (key_type) { |
| 75 case EVP_PKEY_RSA: | 76 case EVP_PKEY_RSA: |
| 76 *out_type = SSLPrivateKey::Type::RSA; | 77 *out_type = SSLPrivateKey::Type::RSA; |
| 77 break; | 78 break; |
| 78 | 79 |
| 79 case EVP_PKEY_EC: { | 80 case EVP_PKEY_EC: { |
| 80 EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(key.get()); | 81 EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(key.get()); |
| 81 int curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key)); | 82 int curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key)); |
| 82 switch (curve) { | 83 switch (curve) { |
| 83 case NID_X9_62_prime256v1: | 84 case NID_X9_62_prime256v1: |
| 84 *out_type = SSLPrivateKey::Type::ECDSA_P256; | 85 *out_type = SSLPrivateKey::Type::ECDSA_P256; |
| 85 break; | 86 break; |
| 86 case NID_secp384r1: | 87 case NID_secp384r1: |
| 87 *out_type = SSLPrivateKey::Type::ECDSA_P384; | 88 *out_type = SSLPrivateKey::Type::ECDSA_P384; |
| 88 break; | 89 break; |
| 89 case NID_secp521r1: | 90 case NID_secp521r1: |
| 90 *out_type = SSLPrivateKey::Type::ECDSA_P384; | 91 *out_type = SSLPrivateKey::Type::ECDSA_P384; |
| 91 break; | 92 break; |
| 92 default: | 93 default: |
| 94 LOG(ERROR) << "Unsupported curve type " << curve; |
| 93 return false; | 95 return false; |
| 94 } | 96 } |
| 95 break; | 97 break; |
| 96 } | 98 } |
| 97 | 99 |
| 98 default: | 100 default: |
| 101 LOG(ERROR) << "Unsupported key type " << key_type; |
| 99 return false; | 102 return false; |
| 100 } | 103 } |
| 101 | 104 |
| 102 *out_max_length = EVP_PKEY_size(key.get()); | 105 *out_max_length = EVP_PKEY_size(key.get()); |
| 103 return true; | 106 return true; |
| 104 } | 107 } |
| 105 | 108 |
| 106 } // namespace net | 109 } // namespace net |
| OLD | NEW |