| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/jwk_serializer.h" | 5 #include "net/cert/jwk_serializer.h" |
| 6 | 6 |
| 7 #include <openssl/bn.h> | 7 #include <openssl/bn.h> |
| 8 #include <openssl/bytestring.h> |
| 8 #include <openssl/ec.h> | 9 #include <openssl/ec.h> |
| 9 #include <openssl/ec_key.h> | 10 #include <openssl/ec_key.h> |
| 10 #include <openssl/evp.h> | 11 #include <openssl/evp.h> |
| 11 #include <openssl/x509.h> | |
| 12 | 12 |
| 13 #include "base/base64url.h" | 13 #include "base/base64url.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "crypto/openssl_util.h" | 17 #include "crypto/openssl_util.h" |
| 18 #include "crypto/scoped_openssl_types.h" | 18 #include "crypto/scoped_openssl_types.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 bool ConvertSpkiFromDerToJwk( | 91 bool ConvertSpkiFromDerToJwk( |
| 92 const base::StringPiece& spki_der, | 92 const base::StringPiece& spki_der, |
| 93 base::DictionaryValue* public_key_jwk) { | 93 base::DictionaryValue* public_key_jwk) { |
| 94 public_key_jwk->Clear(); | 94 public_key_jwk->Clear(); |
| 95 | 95 |
| 96 crypto::EnsureOpenSSLInit(); | 96 crypto::EnsureOpenSSLInit(); |
| 97 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 97 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 98 | 98 |
| 99 const uint8_t *data = reinterpret_cast<const uint8_t*>(spki_der.data()); | 99 CBS cbs; |
| 100 const uint8_t *ptr = data; | 100 CBS_init(&cbs, reinterpret_cast<const uint8_t*>(spki_der.data()), |
| 101 crypto::ScopedEVP_PKEY pubkey(d2i_PUBKEY(NULL, &ptr, spki_der.size())); | 101 spki_der.size()); |
| 102 if (!pubkey || ptr != data + spki_der.size()) | 102 crypto::ScopedEVP_PKEY pubkey(EVP_parse_public_key(&cbs)); |
| 103 if (!pubkey || CBS_len(&cbs) != 0) |
| 103 return false; | 104 return false; |
| 104 | 105 |
| 105 if (pubkey->type == EVP_PKEY_EC) { | 106 if (pubkey->type == EVP_PKEY_EC) { |
| 106 return ConvertEcKeyToJwk(pubkey.get(), public_key_jwk, err_tracer); | 107 return ConvertEcKeyToJwk(pubkey.get(), public_key_jwk, err_tracer); |
| 107 } else { | 108 } else { |
| 108 // TODO(juanlang): other algorithms | 109 // TODO(juanlang): other algorithms |
| 109 return false; | 110 return false; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace JwkSerializer | 114 } // namespace JwkSerializer |
| 114 | 115 |
| 115 } // namespace net | 116 } // namespace net |
| OLD | NEW |