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

Side by Side Diff: crypto/rsa_private_key_openssl.cc

Issue 805193004: Don't allow importing non-RSA keys from crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: aaand remove space Created 5 years, 11 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 | « no previous file | crypto/rsa_private_key_unittest.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "crypto/rsa_private_key.h" 5 #include "crypto/rsa_private_key.h"
6 6
7 #include <openssl/bio.h> 7 #include <openssl/bio.h>
8 #include <openssl/bn.h> 8 #include <openssl/bn.h>
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 #include <openssl/pkcs12.h> 10 #include <openssl/pkcs12.h>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // PKCS#8 decode the input, and then import the EVP_PKEY from Private Key 84 // PKCS#8 decode the input, and then import the EVP_PKEY from Private Key
85 // Info structure returned. 85 // Info structure returned.
86 const uint8_t* ptr = &input[0]; 86 const uint8_t* ptr = &input[0];
87 ScopedPKCS8_PRIV_KEY_INFO p8inf( 87 ScopedPKCS8_PRIV_KEY_INFO p8inf(
88 d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, input.size())); 88 d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, input.size()));
89 if (!p8inf.get() || ptr != &input[0] + input.size()) 89 if (!p8inf.get() || ptr != &input[0] + input.size())
90 return NULL; 90 return NULL;
91 91
92 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); 92 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
93 result->key_ = EVP_PKCS82PKEY(p8inf.get()); 93 result->key_ = EVP_PKCS82PKEY(p8inf.get());
94 if (!result->key_) 94 if (!result->key_ || EVP_PKEY_id(result->key_) != EVP_PKEY_RSA)
95 return NULL; 95 return NULL;
96 96
97 return result.release(); 97 return result.release();
98 } 98 }
99 99
100 // static 100 // static
101 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { 101 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) {
102 DCHECK(key); 102 DCHECK(key);
103 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) 103 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA)
104 return NULL; 104 return NULL;
(...skipping 24 matching lines...) Expand all
129 129
130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { 130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const {
131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); 131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output);
132 } 132 }
133 133
134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { 134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const {
135 return ExportKey(key_, i2d_PUBKEY_bio, output); 135 return ExportKey(key_, i2d_PUBKEY_bio, output);
136 } 136 }
137 137
138 } // namespace crypto 138 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | crypto/rsa_private_key_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698