| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/webcrypto/algorithms/rsa.h" | 5 #include "components/webcrypto/algorithms/rsa.h" |
| 6 | 6 |
| 7 #include <openssl/bn.h> |
| 7 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 9 #include <openssl/rsa.h> |
| 8 #include <utility> | 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "components/webcrypto/algorithms/asymmetric_key_util.h" | 13 #include "components/webcrypto/algorithms/asymmetric_key_util.h" |
| 12 #include "components/webcrypto/algorithms/util.h" | 14 #include "components/webcrypto/algorithms/util.h" |
| 13 #include "components/webcrypto/blink_key_handle.h" | 15 #include "components/webcrypto/blink_key_handle.h" |
| 14 #include "components/webcrypto/crypto_data.h" | 16 #include "components/webcrypto/crypto_data.h" |
| 15 #include "components/webcrypto/generate_key_result.h" | 17 #include "components/webcrypto/generate_key_result.h" |
| 16 #include "components/webcrypto/jwk.h" | 18 #include "components/webcrypto/jwk.h" |
| 17 #include "components/webcrypto/status.h" | 19 #include "components/webcrypto/status.h" |
| 18 #include "crypto/openssl_util.h" | 20 #include "crypto/openssl_util.h" |
| 19 #include "crypto/scoped_openssl_types.h" | |
| 20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 21 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 21 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 22 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 22 | 23 |
| 23 namespace webcrypto { | 24 namespace webcrypto { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Describes the RSA components for a parsed key. The names of the properties | 28 // Describes the RSA components for a parsed key. The names of the properties |
| 28 // correspond with those from the JWK spec. Note that Chromium's WebCrypto | 29 // correspond with those from the JWK spec. Note that Chromium's WebCrypto |
| 29 // implementation does not support multi-primes, so there is no parsed field | 30 // implementation does not support multi-primes, so there is no parsed field |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 107 |
| 107 // Creates a blink::WebCryptoAlgorithm having the modulus length and public | 108 // Creates a blink::WebCryptoAlgorithm having the modulus length and public |
| 108 // exponent of |key|. | 109 // exponent of |key|. |
| 109 Status CreateRsaHashedKeyAlgorithm( | 110 Status CreateRsaHashedKeyAlgorithm( |
| 110 blink::WebCryptoAlgorithmId rsa_algorithm, | 111 blink::WebCryptoAlgorithmId rsa_algorithm, |
| 111 blink::WebCryptoAlgorithmId hash_algorithm, | 112 blink::WebCryptoAlgorithmId hash_algorithm, |
| 112 EVP_PKEY* key, | 113 EVP_PKEY* key, |
| 113 blink::WebCryptoKeyAlgorithm* key_algorithm) { | 114 blink::WebCryptoKeyAlgorithm* key_algorithm) { |
| 114 DCHECK_EQ(EVP_PKEY_RSA, EVP_PKEY_id(key)); | 115 DCHECK_EQ(EVP_PKEY_RSA, EVP_PKEY_id(key)); |
| 115 | 116 |
| 116 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(key)); | 117 RSA* rsa = EVP_PKEY_get0_RSA(key); |
| 117 if (!rsa.get()) | 118 if (!rsa) |
| 118 return Status::ErrorUnexpected(); | 119 return Status::ErrorUnexpected(); |
| 119 | 120 |
| 120 unsigned int modulus_length_bits = BN_num_bits(rsa.get()->n); | 121 unsigned int modulus_length_bits = BN_num_bits(rsa->n); |
| 121 | 122 |
| 122 // Convert the public exponent to big-endian representation. | 123 // Convert the public exponent to big-endian representation. |
| 123 std::vector<uint8_t> e(BN_num_bytes(rsa.get()->e)); | 124 std::vector<uint8_t> e(BN_num_bytes(rsa->e)); |
| 124 if (e.size() == 0) | 125 if (e.size() == 0) |
| 125 return Status::ErrorUnexpected(); | 126 return Status::ErrorUnexpected(); |
| 126 if (e.size() != BN_bn2bin(rsa.get()->e, &e[0])) | 127 if (e.size() != BN_bn2bin(rsa->e, &e[0])) |
| 127 return Status::ErrorUnexpected(); | 128 return Status::ErrorUnexpected(); |
| 128 | 129 |
| 129 *key_algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed( | 130 *key_algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed( |
| 130 rsa_algorithm, modulus_length_bits, &e[0], | 131 rsa_algorithm, modulus_length_bits, &e[0], |
| 131 static_cast<unsigned int>(e.size()), hash_algorithm); | 132 static_cast<unsigned int>(e.size()), hash_algorithm); |
| 132 | 133 |
| 133 return Status::Success(); | 134 return Status::Success(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 // Creates a WebCryptoKey that wraps |private_key|. | 137 // Creates a WebCryptoKey that wraps |private_key|. |
| 137 Status CreateWebCryptoRsaPrivateKey( | 138 Status CreateWebCryptoRsaPrivateKey( |
| 138 crypto::ScopedEVP_PKEY private_key, | 139 bssl::UniquePtr<EVP_PKEY> private_key, |
| 139 const blink::WebCryptoAlgorithmId rsa_algorithm_id, | 140 const blink::WebCryptoAlgorithmId rsa_algorithm_id, |
| 140 const blink::WebCryptoAlgorithm& hash, | 141 const blink::WebCryptoAlgorithm& hash, |
| 141 bool extractable, | 142 bool extractable, |
| 142 blink::WebCryptoKeyUsageMask usages, | 143 blink::WebCryptoKeyUsageMask usages, |
| 143 blink::WebCryptoKey* key) { | 144 blink::WebCryptoKey* key) { |
| 144 blink::WebCryptoKeyAlgorithm key_algorithm; | 145 blink::WebCryptoKeyAlgorithm key_algorithm; |
| 145 Status status = CreateRsaHashedKeyAlgorithm( | 146 Status status = CreateRsaHashedKeyAlgorithm( |
| 146 rsa_algorithm_id, hash.id(), private_key.get(), &key_algorithm); | 147 rsa_algorithm_id, hash.id(), private_key.get(), &key_algorithm); |
| 147 if (status.IsError()) | 148 if (status.IsError()) |
| 148 return status; | 149 return status; |
| 149 | 150 |
| 150 return CreateWebCryptoPrivateKey(std::move(private_key), key_algorithm, | 151 return CreateWebCryptoPrivateKey(std::move(private_key), key_algorithm, |
| 151 extractable, usages, key); | 152 extractable, usages, key); |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Creates a WebCryptoKey that wraps |public_key|. | 155 // Creates a WebCryptoKey that wraps |public_key|. |
| 155 Status CreateWebCryptoRsaPublicKey( | 156 Status CreateWebCryptoRsaPublicKey( |
| 156 crypto::ScopedEVP_PKEY public_key, | 157 bssl::UniquePtr<EVP_PKEY> public_key, |
| 157 const blink::WebCryptoAlgorithmId rsa_algorithm_id, | 158 const blink::WebCryptoAlgorithmId rsa_algorithm_id, |
| 158 const blink::WebCryptoAlgorithm& hash, | 159 const blink::WebCryptoAlgorithm& hash, |
| 159 bool extractable, | 160 bool extractable, |
| 160 blink::WebCryptoKeyUsageMask usages, | 161 blink::WebCryptoKeyUsageMask usages, |
| 161 blink::WebCryptoKey* key) { | 162 blink::WebCryptoKey* key) { |
| 162 blink::WebCryptoKeyAlgorithm key_algorithm; | 163 blink::WebCryptoKeyAlgorithm key_algorithm; |
| 163 Status status = CreateRsaHashedKeyAlgorithm(rsa_algorithm_id, hash.id(), | 164 Status status = CreateRsaHashedKeyAlgorithm(rsa_algorithm_id, hash.id(), |
| 164 public_key.get(), &key_algorithm); | 165 public_key.get(), &key_algorithm); |
| 165 if (status.IsError()) | 166 if (status.IsError()) |
| 166 return status; | 167 return status; |
| 167 | 168 |
| 168 return CreateWebCryptoPublicKey(std::move(public_key), key_algorithm, | 169 return CreateWebCryptoPublicKey(std::move(public_key), key_algorithm, |
| 169 extractable, usages, key); | 170 extractable, usages, key); |
| 170 } | 171 } |
| 171 | 172 |
| 172 Status ImportRsaPrivateKey(const blink::WebCryptoAlgorithm& algorithm, | 173 Status ImportRsaPrivateKey(const blink::WebCryptoAlgorithm& algorithm, |
| 173 bool extractable, | 174 bool extractable, |
| 174 blink::WebCryptoKeyUsageMask usages, | 175 blink::WebCryptoKeyUsageMask usages, |
| 175 const JwkRsaInfo& params, | 176 const JwkRsaInfo& params, |
| 176 blink::WebCryptoKey* key) { | 177 blink::WebCryptoKey* key) { |
| 177 crypto::ScopedRSA rsa(RSA_new()); | 178 bssl::UniquePtr<RSA> rsa(RSA_new()); |
| 178 | 179 |
| 179 rsa->n = CreateBIGNUM(params.n); | 180 rsa->n = CreateBIGNUM(params.n); |
| 180 rsa->e = CreateBIGNUM(params.e); | 181 rsa->e = CreateBIGNUM(params.e); |
| 181 rsa->d = CreateBIGNUM(params.d); | 182 rsa->d = CreateBIGNUM(params.d); |
| 182 rsa->p = CreateBIGNUM(params.p); | 183 rsa->p = CreateBIGNUM(params.p); |
| 183 rsa->q = CreateBIGNUM(params.q); | 184 rsa->q = CreateBIGNUM(params.q); |
| 184 rsa->dmp1 = CreateBIGNUM(params.dp); | 185 rsa->dmp1 = CreateBIGNUM(params.dp); |
| 185 rsa->dmq1 = CreateBIGNUM(params.dq); | 186 rsa->dmq1 = CreateBIGNUM(params.dq); |
| 186 rsa->iqmp = CreateBIGNUM(params.qi); | 187 rsa->iqmp = CreateBIGNUM(params.qi); |
| 187 | 188 |
| 188 if (!rsa->n || !rsa->e || !rsa->d || !rsa->p || !rsa->q || !rsa->dmp1 || | 189 if (!rsa->n || !rsa->e || !rsa->d || !rsa->p || !rsa->q || !rsa->dmp1 || |
| 189 !rsa->dmq1 || !rsa->iqmp) { | 190 !rsa->dmq1 || !rsa->iqmp) { |
| 190 return Status::OperationError(); | 191 return Status::OperationError(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 // TODO(eroman): This should be a DataError. | 194 // TODO(eroman): This should be a DataError. |
| 194 if (!RSA_check_key(rsa.get())) | 195 if (!RSA_check_key(rsa.get())) |
| 195 return Status::OperationError(); | 196 return Status::OperationError(); |
| 196 | 197 |
| 197 // Create a corresponding EVP_PKEY. | 198 // Create a corresponding EVP_PKEY. |
| 198 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); | 199 bssl::UniquePtr<EVP_PKEY> pkey(EVP_PKEY_new()); |
| 199 if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) | 200 if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) |
| 200 return Status::OperationError(); | 201 return Status::OperationError(); |
| 201 | 202 |
| 202 return CreateWebCryptoRsaPrivateKey(std::move(pkey), algorithm.id(), | 203 return CreateWebCryptoRsaPrivateKey(std::move(pkey), algorithm.id(), |
| 203 algorithm.rsaHashedImportParams()->hash(), | 204 algorithm.rsaHashedImportParams()->hash(), |
| 204 extractable, usages, key); | 205 extractable, usages, key); |
| 205 } | 206 } |
| 206 | 207 |
| 207 Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm, | 208 Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm, |
| 208 bool extractable, | 209 bool extractable, |
| 209 blink::WebCryptoKeyUsageMask usages, | 210 blink::WebCryptoKeyUsageMask usages, |
| 210 const CryptoData& n, | 211 const CryptoData& n, |
| 211 const CryptoData& e, | 212 const CryptoData& e, |
| 212 blink::WebCryptoKey* key) { | 213 blink::WebCryptoKey* key) { |
| 213 crypto::ScopedRSA rsa(RSA_new()); | 214 bssl::UniquePtr<RSA> rsa(RSA_new()); |
| 214 | 215 |
| 215 rsa->n = BN_bin2bn(n.bytes(), n.byte_length(), NULL); | 216 rsa->n = BN_bin2bn(n.bytes(), n.byte_length(), NULL); |
| 216 rsa->e = BN_bin2bn(e.bytes(), e.byte_length(), NULL); | 217 rsa->e = BN_bin2bn(e.bytes(), e.byte_length(), NULL); |
| 217 | 218 |
| 218 if (!rsa->n || !rsa->e) | 219 if (!rsa->n || !rsa->e) |
| 219 return Status::OperationError(); | 220 return Status::OperationError(); |
| 220 | 221 |
| 221 // Create a corresponding EVP_PKEY. | 222 // Create a corresponding EVP_PKEY. |
| 222 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); | 223 bssl::UniquePtr<EVP_PKEY> pkey(EVP_PKEY_new()); |
| 223 if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) | 224 if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) |
| 224 return Status::OperationError(); | 225 return Status::OperationError(); |
| 225 | 226 |
| 226 return CreateWebCryptoRsaPublicKey(std::move(pkey), algorithm.id(), | 227 return CreateWebCryptoRsaPublicKey(std::move(pkey), algorithm.id(), |
| 227 algorithm.rsaHashedImportParams()->hash(), | 228 algorithm.rsaHashedImportParams()->hash(), |
| 228 extractable, usages, key); | 229 extractable, usages, key); |
| 229 } | 230 } |
| 230 | 231 |
| 231 // Converts a BIGNUM to a big endian byte array. | 232 // Converts a BIGNUM to a big endian byte array. |
| 232 std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n) { | 233 std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (!params->convertPublicExponentToUnsigned(public_exponent)) | 282 if (!params->convertPublicExponentToUnsigned(public_exponent)) |
| 282 return Status::ErrorGenerateKeyPublicExponent(); | 283 return Status::ErrorGenerateKeyPublicExponent(); |
| 283 | 284 |
| 284 // OpenSSL hangs when given bad public exponents. Use a whitelist. | 285 // OpenSSL hangs when given bad public exponents. Use a whitelist. |
| 285 if (public_exponent != 3 && public_exponent != 65537) | 286 if (public_exponent != 3 && public_exponent != 65537) |
| 286 return Status::ErrorGenerateKeyPublicExponent(); | 287 return Status::ErrorGenerateKeyPublicExponent(); |
| 287 | 288 |
| 288 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 289 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 289 | 290 |
| 290 // Generate an RSA key pair. | 291 // Generate an RSA key pair. |
| 291 crypto::ScopedRSA rsa_private_key(RSA_new()); | 292 bssl::UniquePtr<RSA> rsa_private_key(RSA_new()); |
| 292 crypto::ScopedBIGNUM bn(BN_new()); | 293 bssl::UniquePtr<BIGNUM> bn(BN_new()); |
| 293 if (!rsa_private_key.get() || !bn.get() || | 294 if (!rsa_private_key.get() || !bn.get() || |
| 294 !BN_set_word(bn.get(), public_exponent)) { | 295 !BN_set_word(bn.get(), public_exponent)) { |
| 295 return Status::OperationError(); | 296 return Status::OperationError(); |
| 296 } | 297 } |
| 297 | 298 |
| 298 if (!RSA_generate_key_ex(rsa_private_key.get(), modulus_length_bits, bn.get(), | 299 if (!RSA_generate_key_ex(rsa_private_key.get(), modulus_length_bits, bn.get(), |
| 299 NULL)) { | 300 NULL)) { |
| 300 return Status::OperationError(); | 301 return Status::OperationError(); |
| 301 } | 302 } |
| 302 | 303 |
| 303 // Construct an EVP_PKEY for the private key. | 304 // Construct an EVP_PKEY for the private key. |
| 304 crypto::ScopedEVP_PKEY private_pkey(EVP_PKEY_new()); | 305 bssl::UniquePtr<EVP_PKEY> private_pkey(EVP_PKEY_new()); |
| 305 if (!private_pkey || | 306 if (!private_pkey || |
| 306 !EVP_PKEY_set1_RSA(private_pkey.get(), rsa_private_key.get())) { | 307 !EVP_PKEY_set1_RSA(private_pkey.get(), rsa_private_key.get())) { |
| 307 return Status::OperationError(); | 308 return Status::OperationError(); |
| 308 } | 309 } |
| 309 | 310 |
| 310 // Construct an EVP_PKEY for the public key. | 311 // Construct an EVP_PKEY for the public key. |
| 311 crypto::ScopedRSA rsa_public_key(RSAPublicKey_dup(rsa_private_key.get())); | 312 bssl::UniquePtr<RSA> rsa_public_key(RSAPublicKey_dup(rsa_private_key.get())); |
| 312 crypto::ScopedEVP_PKEY public_pkey(EVP_PKEY_new()); | 313 bssl::UniquePtr<EVP_PKEY> public_pkey(EVP_PKEY_new()); |
| 313 if (!public_pkey || | 314 if (!public_pkey || |
| 314 !EVP_PKEY_set1_RSA(public_pkey.get(), rsa_public_key.get())) { | 315 !EVP_PKEY_set1_RSA(public_pkey.get(), rsa_public_key.get())) { |
| 315 return Status::OperationError(); | 316 return Status::OperationError(); |
| 316 } | 317 } |
| 317 | 318 |
| 318 blink::WebCryptoKey public_key; | 319 blink::WebCryptoKey public_key; |
| 319 blink::WebCryptoKey private_key; | 320 blink::WebCryptoKey private_key; |
| 320 | 321 |
| 321 // Note that extractable is unconditionally set to true. This is because per | 322 // Note that extractable is unconditionally set to true. This is because per |
| 322 // the WebCrypto spec generated public keys are always extractable. | 323 // the WebCrypto spec generated public keys are always extractable. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 Status RsaHashedAlgorithm::ImportKeyPkcs8( | 373 Status RsaHashedAlgorithm::ImportKeyPkcs8( |
| 373 const CryptoData& key_data, | 374 const CryptoData& key_data, |
| 374 const blink::WebCryptoAlgorithm& algorithm, | 375 const blink::WebCryptoAlgorithm& algorithm, |
| 375 bool extractable, | 376 bool extractable, |
| 376 blink::WebCryptoKeyUsageMask usages, | 377 blink::WebCryptoKeyUsageMask usages, |
| 377 blink::WebCryptoKey* key) const { | 378 blink::WebCryptoKey* key) const { |
| 378 Status status = CheckKeyCreationUsages(all_private_key_usages_, usages); | 379 Status status = CheckKeyCreationUsages(all_private_key_usages_, usages); |
| 379 if (status.IsError()) | 380 if (status.IsError()) |
| 380 return status; | 381 return status; |
| 381 | 382 |
| 382 crypto::ScopedEVP_PKEY private_key; | 383 bssl::UniquePtr<EVP_PKEY> private_key; |
| 383 status = ImportUnverifiedPkeyFromPkcs8(key_data, EVP_PKEY_RSA, &private_key); | 384 status = ImportUnverifiedPkeyFromPkcs8(key_data, EVP_PKEY_RSA, &private_key); |
| 384 if (status.IsError()) | 385 if (status.IsError()) |
| 385 return status; | 386 return status; |
| 386 | 387 |
| 387 // Verify the parameters of the key. | 388 // Verify the parameters of the key. |
| 388 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(private_key.get())); | 389 RSA* rsa = EVP_PKEY_get0_RSA(private_key.get()); |
| 389 if (!rsa.get()) | 390 if (!rsa) |
| 390 return Status::ErrorUnexpected(); | 391 return Status::ErrorUnexpected(); |
| 391 if (!RSA_check_key(rsa.get())) | 392 if (!RSA_check_key(rsa)) |
| 392 return Status::DataError(); | 393 return Status::DataError(); |
| 393 | 394 |
| 394 // TODO(eroman): Validate the algorithm OID against the webcrypto provided | 395 // TODO(eroman): Validate the algorithm OID against the webcrypto provided |
| 395 // hash. http://crbug.com/389400 | 396 // hash. http://crbug.com/389400 |
| 396 | 397 |
| 397 return CreateWebCryptoRsaPrivateKey(std::move(private_key), algorithm.id(), | 398 return CreateWebCryptoRsaPrivateKey(std::move(private_key), algorithm.id(), |
| 398 algorithm.rsaHashedImportParams()->hash(), | 399 algorithm.rsaHashedImportParams()->hash(), |
| 399 extractable, usages, key); | 400 extractable, usages, key); |
| 400 } | 401 } |
| 401 | 402 |
| 402 Status RsaHashedAlgorithm::ImportKeySpki( | 403 Status RsaHashedAlgorithm::ImportKeySpki( |
| 403 const CryptoData& key_data, | 404 const CryptoData& key_data, |
| 404 const blink::WebCryptoAlgorithm& algorithm, | 405 const blink::WebCryptoAlgorithm& algorithm, |
| 405 bool extractable, | 406 bool extractable, |
| 406 blink::WebCryptoKeyUsageMask usages, | 407 blink::WebCryptoKeyUsageMask usages, |
| 407 blink::WebCryptoKey* key) const { | 408 blink::WebCryptoKey* key) const { |
| 408 Status status = CheckKeyCreationUsages(all_public_key_usages_, usages); | 409 Status status = CheckKeyCreationUsages(all_public_key_usages_, usages); |
| 409 if (status.IsError()) | 410 if (status.IsError()) |
| 410 return status; | 411 return status; |
| 411 | 412 |
| 412 crypto::ScopedEVP_PKEY public_key; | 413 bssl::UniquePtr<EVP_PKEY> public_key; |
| 413 status = ImportUnverifiedPkeyFromSpki(key_data, EVP_PKEY_RSA, &public_key); | 414 status = ImportUnverifiedPkeyFromSpki(key_data, EVP_PKEY_RSA, &public_key); |
| 414 if (status.IsError()) | 415 if (status.IsError()) |
| 415 return status; | 416 return status; |
| 416 | 417 |
| 417 // TODO(eroman): Validate the algorithm OID against the webcrypto provided | 418 // TODO(eroman): Validate the algorithm OID against the webcrypto provided |
| 418 // hash. http://crbug.com/389400 | 419 // hash. http://crbug.com/389400 |
| 419 | 420 |
| 420 return CreateWebCryptoRsaPublicKey(std::move(public_key), algorithm.id(), | 421 return CreateWebCryptoRsaPublicKey(std::move(public_key), algorithm.id(), |
| 421 algorithm.rsaHashedImportParams()->hash(), | 422 algorithm.rsaHashedImportParams()->hash(), |
| 422 extractable, usages, key); | 423 extractable, usages, key); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 // structured clone). | 479 // structured clone). |
| 479 *buffer = GetSerializedKeyData(key); | 480 *buffer = GetSerializedKeyData(key); |
| 480 return Status::Success(); | 481 return Status::Success(); |
| 481 } | 482 } |
| 482 | 483 |
| 483 Status RsaHashedAlgorithm::ExportKeyJwk(const blink::WebCryptoKey& key, | 484 Status RsaHashedAlgorithm::ExportKeyJwk(const blink::WebCryptoKey& key, |
| 484 std::vector<uint8_t>* buffer) const { | 485 std::vector<uint8_t>* buffer) const { |
| 485 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 486 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 486 | 487 |
| 487 EVP_PKEY* pkey = GetEVP_PKEY(key); | 488 EVP_PKEY* pkey = GetEVP_PKEY(key); |
| 488 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(pkey)); | 489 RSA* rsa = EVP_PKEY_get0_RSA(pkey); |
| 489 if (!rsa.get()) | 490 if (!rsa) |
| 490 return Status::ErrorUnexpected(); | 491 return Status::ErrorUnexpected(); |
| 491 | 492 |
| 492 const char* jwk_algorithm = | 493 const char* jwk_algorithm = |
| 493 GetJwkAlgorithm(key.algorithm().rsaHashedParams()->hash().id()); | 494 GetJwkAlgorithm(key.algorithm().rsaHashedParams()->hash().id()); |
| 494 if (!jwk_algorithm) | 495 if (!jwk_algorithm) |
| 495 return Status::ErrorUnexpected(); | 496 return Status::ErrorUnexpected(); |
| 496 | 497 |
| 497 switch (key.type()) { | 498 switch (key.type()) { |
| 498 case blink::WebCryptoKeyTypePublic: { | 499 case blink::WebCryptoKeyTypePublic: { |
| 499 JwkWriter writer(jwk_algorithm, key.extractable(), key.usages(), "RSA"); | 500 JwkWriter writer(jwk_algorithm, key.extractable(), key.usages(), "RSA"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 memcmp(algorithm.rsaHashedParams()->publicExponent().data(), | 573 memcmp(algorithm.rsaHashedParams()->publicExponent().data(), |
| 573 key->algorithm().rsaHashedParams()->publicExponent().data(), | 574 key->algorithm().rsaHashedParams()->publicExponent().data(), |
| 574 key->algorithm().rsaHashedParams()->publicExponent().size())) { | 575 key->algorithm().rsaHashedParams()->publicExponent().size())) { |
| 575 return Status::ErrorUnexpected(); | 576 return Status::ErrorUnexpected(); |
| 576 } | 577 } |
| 577 | 578 |
| 578 return Status::Success(); | 579 return Status::Success(); |
| 579 } | 580 } |
| 580 | 581 |
| 581 } // namespace webcrypto | 582 } // namespace webcrypto |
| OLD | NEW |