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

Unified Diff: crypto/rsa_private_key_nss.cc

Issue 270663002: Implemented profile-aware owner key loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small fix: removed redundant check. Created 6 years, 7 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
Index: crypto/rsa_private_key_nss.cc
diff --git a/crypto/rsa_private_key_nss.cc b/crypto/rsa_private_key_nss.cc
index bd54c2e4037131b536a6134305e1027fdf804b73..5f7c48d8bb50555deb6272e945f35133dacbbb7a 100644
--- a/crypto/rsa_private_key_nss.cc
+++ b/crypto/rsa_private_key_nss.cc
@@ -38,6 +38,26 @@ static bool ReadAttribute(SECKEYPrivateKey* key,
return true;
}
+#if defined(USE_NSS)
+SECKEYPublicKey* GetRSAPublicKey(const std::vector<uint8>& input) {
+ // First, decode and save the public key.
+ SECItem key_der;
+ key_der.type = siBuffer;
+ key_der.data = const_cast<unsigned char*>(&input[0]);
+ key_der.len = input.size();
+
+ CERTSubjectPublicKeyInfo* spki =
+ SECKEY_DecodeDERSubjectPublicKeyInfo(&key_der);
+ if (!spki)
+ return NULL;
+ SECKEYPublicKey* result = SECKEY_ExtractPublicKey(spki);
+ SECKEY_DestroySubjectPublicKeyInfo(spki);
+ if (!result || result->keyType != rsaKey)
+ return NULL;
+ return result;
+}
+#endif // defined(USE_NSS)
+
} // namespace
namespace crypto {
@@ -114,34 +134,13 @@ RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo(
const std::vector<uint8>& input) {
EnsureNSSInit();
- scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
-
- // First, decode and save the public key.
- SECItem key_der;
- key_der.type = siBuffer;
- key_der.data = const_cast<unsigned char*>(&input[0]);
- key_der.len = input.size();
-
- CERTSubjectPublicKeyInfo* spki =
- SECKEY_DecodeDERSubjectPublicKeyInfo(&key_der);
- if (!spki) {
- NOTREACHED();
- return NULL;
- }
-
- result->public_key_ = SECKEY_ExtractPublicKey(spki);
- SECKEY_DestroySubjectPublicKeyInfo(spki);
+ scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey());
+ result->public_key_ = GetRSAPublicKey(input);
if (!result->public_key_) {
NOTREACHED();
return NULL;
}
- // Make sure the key is an RSA key. If not, that's an error
- if (result->public_key_->keyType != rsaKey) {
- NOTREACHED();
- return NULL;
- }
-
ScopedSECItem ck_id(
PK11_MakeIDFromPubKey(&(result->public_key_->u.rsa.modulus)));
if (!ck_id.get()) {
@@ -166,6 +165,35 @@ RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo(
// We didn't find the key.
return NULL;
}
+
+// static
+RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfoInSlot(
+ const std::vector<uint8>& input,
+ PK11SlotInfo* slot) {
+ EnsureNSSInit();
+
+ if (!slot)
+ return NULL;
+
+ scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey());
+ result->public_key_ = GetRSAPublicKey(input);
+ if (!result->public_key_) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ ScopedSECItem ck_id(
+ PK11_MakeIDFromPubKey(&(result->public_key_->u.rsa.modulus)));
+ if (!ck_id.get()) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ result->key_ = PK11_FindKeyByKeyID(slot, ck_id.get(), NULL);
+ if (!result->key_)
+ return NULL;
+ return result.release();
+}
#endif
RSAPrivateKey* RSAPrivateKey::Copy() const {
« chrome/browser/chromeos/settings/session_manager_operation.h ('K') | « crypto/rsa_private_key.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698