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 "content/child/webcrypto/openssl/rsa_key_openssl.h" | 5 #include "content/child/webcrypto/openssl/rsa_key_openssl.h" |
6 | 6 |
7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
8 #include <openssl/pkcs12.h> | 8 #include <openssl/pkcs12.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 rsa->dmq1 = CreateBIGNUM(params.dq); | 176 rsa->dmq1 = CreateBIGNUM(params.dq); |
177 rsa->iqmp = CreateBIGNUM(params.qi); | 177 rsa->iqmp = CreateBIGNUM(params.qi); |
178 | 178 |
179 if (!rsa->n || !rsa->e || !rsa->d || !rsa->p || !rsa->q || !rsa->dmp1 || | 179 if (!rsa->n || !rsa->e || !rsa->d || !rsa->p || !rsa->q || !rsa->dmp1 || |
180 !rsa->dmq1 || !rsa->iqmp) { | 180 !rsa->dmq1 || !rsa->iqmp) { |
181 return Status::OperationError(); | 181 return Status::OperationError(); |
182 } | 182 } |
183 | 183 |
184 // TODO(eroman): This should really be a DataError, however for compatibility | 184 // TODO(eroman): This should really be a DataError, however for compatibility |
185 // with NSS it is an OperationError. | 185 // with NSS it is an OperationError. |
186 if (1 != RSA_check_key(rsa.get())) | 186 if (!RSA_check_key(rsa.get())) |
187 return Status::OperationError(); | 187 return Status::OperationError(); |
188 | 188 |
189 // Create a corresponding EVP_PKEY. | 189 // Create a corresponding EVP_PKEY. |
190 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); | 190 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); |
191 if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) | 191 if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) |
192 return Status::OperationError(); | 192 return Status::OperationError(); |
193 | 193 |
194 return CreateWebCryptoPrivateKey(pkey.Pass(), | 194 return CreateWebCryptoPrivateKey(pkey.Pass(), |
195 algorithm.id(), | 195 algorithm.id(), |
196 algorithm.rsaHashedImportParams()->hash(), | 196 algorithm.rsaHashedImportParams()->hash(), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 return Status::DataError(); | 352 return Status::DataError(); |
353 | 353 |
354 if (EVP_PKEY_id(private_key.get()) != EVP_PKEY_RSA) | 354 if (EVP_PKEY_id(private_key.get()) != EVP_PKEY_RSA) |
355 return Status::DataError(); // Data did not define an RSA key. | 355 return Status::DataError(); // Data did not define an RSA key. |
356 | 356 |
357 // Verify the parameters of the key (because EVP_PKCS82PKEY() happily imports | 357 // Verify the parameters of the key (because EVP_PKCS82PKEY() happily imports |
358 // invalid keys). | 358 // invalid keys). |
359 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(private_key.get())); | 359 crypto::ScopedRSA rsa(EVP_PKEY_get1_RSA(private_key.get())); |
360 if (!rsa.get()) | 360 if (!rsa.get()) |
361 return Status::ErrorUnexpected(); | 361 return Status::ErrorUnexpected(); |
362 if (1 != RSA_check_key(rsa.get())) | 362 if (!RSA_check_key(rsa.get())) |
363 return Status::DataError(); | 363 return Status::DataError(); |
364 | 364 |
365 // TODO(eroman): Validate the algorithm OID against the webcrypto provided | 365 // TODO(eroman): Validate the algorithm OID against the webcrypto provided |
366 // hash. http://crbug.com/389400 | 366 // hash. http://crbug.com/389400 |
367 | 367 |
368 return CreateWebCryptoPrivateKey(private_key.Pass(), | 368 return CreateWebCryptoPrivateKey(private_key.Pass(), |
369 algorithm.id(), | 369 algorithm.id(), |
370 algorithm.rsaHashedImportParams()->hash(), | 370 algorithm.rsaHashedImportParams()->hash(), |
371 extractable, | 371 extractable, |
372 usage_mask, | 372 usage_mask, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 return Status::Success(); | 495 return Status::Success(); |
496 | 496 |
497 default: | 497 default: |
498 return Status::ErrorUnexpected(); | 498 return Status::ErrorUnexpected(); |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 } // namespace webcrypto | 502 } // namespace webcrypto |
503 | 503 |
504 } // namespace content | 504 } // namespace content |
OLD | NEW |