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

Side by Side Diff: net/third_party/mozilla_security_manager/nsKeygenHandler.cpp

Issue 2806045: Give keys friendly names in NSS and OS X (Closed)
Patch Set: Address Wan-Teh's comments Created 10 years, 4 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 | « net/third_party/mozilla_security_manager/nsKeygenHandler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * 2 *
3 * ***** BEGIN LICENSE BLOCK ***** 3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * 5 *
6 * The contents of this file are subject to the Mozilla Public License Version 6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with 7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at 8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/ 9 * http://www.mozilla.org/MPL/
10 * 10 *
(...skipping 30 matching lines...) Expand all
41 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h" 41 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h"
42 42
43 #include <pk11pub.h> 43 #include <pk11pub.h>
44 #include <prerror.h> // PR_GetError() 44 #include <prerror.h> // PR_GetError()
45 #include <secmod.h> 45 #include <secmod.h>
46 #include <secder.h> // DER_Encode() 46 #include <secder.h> // DER_Encode()
47 #include <cryptohi.h> // SEC_DerSignData() 47 #include <cryptohi.h> // SEC_DerSignData()
48 #include <keyhi.h> // SECKEY_CreateSubjectPublicKeyInfo() 48 #include <keyhi.h> // SECKEY_CreateSubjectPublicKeyInfo()
49 49
50 #include "base/base64.h" 50 #include "base/base64.h"
51 #include "base/logging.h"
51 #include "base/nss_util_internal.h" 52 #include "base/nss_util_internal.h"
52 #include "base/nss_util.h" 53 #include "base/nss_util.h"
53 #include "base/logging.h" 54 #include "base/string_util.h"
55 #include "googleurl/src/gurl.h"
54 56
55 namespace { 57 namespace {
56 58
57 // Template for creating the signed public key structure to be sent to the CA. 59 // Template for creating the signed public key structure to be sent to the CA.
58 DERTemplate SECAlgorithmIDTemplate[] = { 60 DERTemplate SECAlgorithmIDTemplate[] = {
59 { DER_SEQUENCE, 61 { DER_SEQUENCE,
60 0, NULL, sizeof(SECAlgorithmID) }, 62 0, NULL, sizeof(SECAlgorithmID) },
61 { DER_OBJECT_ID, 63 { DER_OBJECT_ID,
62 offsetof(SECAlgorithmID, algorithm), }, 64 offsetof(SECAlgorithmID, algorithm), },
63 { DER_OPTIONAL | DER_ANY, 65 { DER_OPTIONAL | DER_ANY,
(...skipping 23 matching lines...) Expand all
87 }; 89 };
88 90
89 } // namespace 91 } // namespace
90 92
91 namespace mozilla_security_manager { 93 namespace mozilla_security_manager {
92 94
93 // This function is based on the nsKeygenFormProcessor::GetPublicKey function 95 // This function is based on the nsKeygenFormProcessor::GetPublicKey function
94 // in mozilla/security/manager/ssl/src/nsKeygenHandler.cpp. 96 // in mozilla/security/manager/ssl/src/nsKeygenHandler.cpp.
95 std::string GenKeyAndSignChallenge(int key_size_in_bits, 97 std::string GenKeyAndSignChallenge(int key_size_in_bits,
96 const std::string& challenge, 98 const std::string& challenge,
99 const GURL& url,
97 bool stores_key) { 100 bool stores_key) {
98 // Key pair generation mechanism - only RSA is supported at present. 101 // Key pair generation mechanism - only RSA is supported at present.
99 PRUint32 keyGenMechanism = CKM_RSA_PKCS_KEY_PAIR_GEN; // from nss/pkcs11t.h 102 PRUint32 keyGenMechanism = CKM_RSA_PKCS_KEY_PAIR_GEN; // from nss/pkcs11t.h
100 103
101 // Temporary structures used for generating the result 104 // Temporary structures used for generating the result
102 // in the right format. 105 // in the right format.
103 PK11SlotInfo *slot = NULL; 106 PK11SlotInfo *slot = NULL;
104 PK11RSAGenParams rsaKeyGenParams; // Keygen parameters. 107 PK11RSAGenParams rsaKeyGenParams; // Keygen parameters.
105 SECOidTag algTag; // used by SEC_DerSignData(). 108 SECOidTag algTag; // used by SEC_DerSignData().
106 SECKEYPrivateKey *privateKey = NULL; 109 SECKEYPrivateKey *privateKey = NULL;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 NULL); 167 NULL);
165 } 168 }
166 LOG(INFO) << "done."; 169 LOG(INFO) << "done.";
167 170
168 if (!privateKey) { 171 if (!privateKey) {
169 LOG(INFO) << "Generation of Keypair failed!"; 172 LOG(INFO) << "Generation of Keypair failed!";
170 isSuccess = false; 173 isSuccess = false;
171 goto failure; 174 goto failure;
172 } 175 }
173 176
177 // Set friendly names for the keys.
178 if (url.has_host()) {
179 // TODO(davidben): Use something like "Key generated for
180 // example.com", but localize it.
181 const std::string& label = url.host();
182 {
183 base::AutoNSSWriteLock lock;
184 PK11_SetPublicKeyNickname(publicKey, label.c_str());
185 PK11_SetPrivateKeyNickname(privateKey, label.c_str());
186 }
187 }
188
174 // The CA expects the signed public key in a specific format 189 // The CA expects the signed public key in a specific format
175 // Let's create that now. 190 // Let's create that now.
176 191
177 // Create a subject public key info from the public key. 192 // Create a subject public key info from the public key.
178 spkInfo = SECKEY_CreateSubjectPublicKeyInfo(publicKey); 193 spkInfo = SECKEY_CreateSubjectPublicKeyInfo(publicKey);
179 if (!spkInfo) { 194 if (!spkInfo) {
180 LOG(ERROR) << "Couldn't create SubjectPublicKeyInfo from public key"; 195 LOG(ERROR) << "Couldn't create SubjectPublicKeyInfo from public key";
181 isSuccess = false; 196 isSuccess = false;
182 goto failure; 197 goto failure;
183 } 198 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 PORT_FreeArena(arena, PR_TRUE); 276 PORT_FreeArena(arena, PR_TRUE);
262 } 277 }
263 if (slot != NULL) { 278 if (slot != NULL) {
264 PK11_FreeSlot(slot); 279 PK11_FreeSlot(slot);
265 } 280 }
266 281
267 return (isSuccess ? result_blob : std::string()); 282 return (isSuccess ? result_blob : std::string());
268 } 283 }
269 284
270 } // namespace mozilla_security_manager 285 } // namespace mozilla_security_manager
OLDNEW
« no previous file with comments | « net/third_party/mozilla_security_manager/nsKeygenHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698