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

Unified Diff: net/android/keystore_unittest.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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/android/network_library.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/android/keystore_unittest.cc
diff --git a/net/android/keystore_unittest.cc b/net/android/keystore_unittest.cc
index 4faa2458cec9d12bdc39f5a7b0d0a7e0c62dff9b..26d49c28afa388dcf956f3b8565a81c755f166f7 100644
--- a/net/android/keystore_unittest.cc
+++ b/net/android/keystore_unittest.cc
@@ -9,7 +9,6 @@
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
-#include <openssl/x509.h>
#include "base/android/build_info.h"
#include "base/android/jni_android.h"
@@ -23,6 +22,7 @@
#include "base/files/scoped_file.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
+#include "crypto/auto_cbb.h"
#include "crypto/openssl_util.h"
#include "net/android/keystore.h"
#include "net/android/keystore_openssl.h"
@@ -128,18 +128,16 @@ EVP_PKEY* ImportPrivateKeyFile(const char* filename) {
// Returns true on success, false otherwise.
bool GetPrivateKeyPkcs8Bytes(const crypto::ScopedEVP_PKEY& pkey,
std::string* pkcs8) {
- // Convert to PKCS#8 object.
- ScopedPKCS8_PRIV_KEY_INFO p8_info(EVP_PKEY2PKCS8(pkey.get()));
- if (!p8_info.get()) {
- LOG(ERROR) << "Can't get PKCS#8 private key from EVP_PKEY: "
- << GetOpenSSLErrorString();
+ uint8_t* der;
+ size_t der_len;
+ crypto::AutoCBB cbb;
+ if (!CBB_init(cbb.get(), 0) ||
+ !EVP_marshal_private_key(cbb.get(), pkey.get()) ||
+ !CBB_finish(cbb.get(), &der, &der_len)) {
return false;
}
-
- // Then convert it
- int len = i2d_PKCS8_PRIV_KEY_INFO(p8_info.get(), NULL);
- unsigned char* p = OpenSSLWriteInto(pkcs8, static_cast<size_t>(len));
- i2d_PKCS8_PRIV_KEY_INFO(p8_info.get(), &p);
+ pkcs8->assign(reinterpret_cast<const char*>(der), der_len);
+ OPENSSL_free(der);
return true;
}
« no previous file with comments | « no previous file | net/android/network_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698