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

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

Issue 1742873002: Switch //net to the new SPKI and PKCS#8 APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@spki-crypto
Patch Set: tweak keygen_handler_openssl.cc Created 4 years, 9 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
« no previous file with comments | « net/cert/internal/verify_signed_data_unittest.cc ('k') | net/ssl/scoped_openssl_types.h » ('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 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
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
OLDNEW
« no previous file with comments | « net/cert/internal/verify_signed_data_unittest.cc ('k') | net/ssl/scoped_openssl_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698