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

Side by Side Diff: net/cert/x509_certificate_nss.cc

Issue 15315003: Generate unique certificate nicknames on Linux/CrOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update README Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/cert/x509_certificate.h" 5 #include "net/cert/x509_certificate.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <cryptohi.h> 8 #include <cryptohi.h>
9 #include <keyhi.h> 9 #include <keyhi.h>
10 #include <nss.h> 10 #include <nss.h>
11 #include <pk11pub.h> 11 #include <pk11pub.h>
12 #include <prtime.h> 12 #include <prtime.h>
13 #include <seccomon.h> 13 #include <seccomon.h>
14 #include <secder.h> 14 #include <secder.h>
15 #include <sechash.h> 15 #include <sechash.h>
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/pickle.h" 19 #include "base/pickle.h"
20 #include "base/stringprintf.h"
20 #include "base/time.h" 21 #include "base/time.h"
21 #include "crypto/nss_util.h" 22 #include "crypto/nss_util.h"
22 #include "crypto/rsa_private_key.h" 23 #include "crypto/rsa_private_key.h"
23 #include "crypto/scoped_nss_types.h" 24 #include "crypto/scoped_nss_types.h"
24 #include "net/cert/x509_util_nss.h" 25 #include "net/cert/x509_util_nss.h"
25 26
26 namespace net { 27 namespace net {
27 28
28 void X509Certificate::Initialize() { 29 void X509Certificate::Initialize() {
29 x509_util::ParsePrincipal(&cert_handle_->subject, &subject_); 30 x509_util::ParsePrincipal(&cert_handle_->subject, &subject_);
(...skipping 29 matching lines...) Expand all
59 } 60 }
60 61
61 std::string X509Certificate::GetDefaultNickname(CertType type) const { 62 std::string X509Certificate::GetDefaultNickname(CertType type) const {
62 if (!default_nickname_.empty()) 63 if (!default_nickname_.empty())
63 return default_nickname_; 64 return default_nickname_;
64 65
65 std::string result; 66 std::string result;
66 if (type == USER_CERT && cert_handle_->slot) { 67 if (type == USER_CERT && cert_handle_->slot) {
67 // Find the private key for this certificate and see if it has a 68 // Find the private key for this certificate and see if it has a
68 // nickname. If there is a private key, and it has a nickname, then 69 // nickname. If there is a private key, and it has a nickname, then
69 // we return that nickname. 70 // return that nickname.
70 SECKEYPrivateKey* private_key = PK11_FindPrivateKeyFromCert( 71 SECKEYPrivateKey* private_key = PK11_FindPrivateKeyFromCert(
71 cert_handle_->slot, 72 cert_handle_->slot,
72 cert_handle_, 73 cert_handle_,
73 NULL); // wincx 74 NULL); // wincx
74 if (private_key) { 75 if (private_key) {
75 char* private_key_nickname = PK11_GetPrivateKeyNickname(private_key); 76 char* private_key_nickname = PK11_GetPrivateKeyNickname(private_key);
76 if (private_key_nickname) { 77 if (private_key_nickname) {
77 result = private_key_nickname; 78 result = private_key_nickname;
78 PORT_Free(private_key_nickname); 79 PORT_Free(private_key_nickname);
79 SECKEY_DestroyPrivateKey(private_key); 80 SECKEY_DestroyPrivateKey(private_key);
80 return result; 81 return result;
81 } 82 }
82 SECKEY_DestroyPrivateKey(private_key); 83 SECKEY_DestroyPrivateKey(private_key);
83 } 84 }
84 } 85 }
85 86
86 switch (type) { 87 switch (type) {
87 case CA_CERT: { 88 case CA_CERT: {
88 char* nickname = CERT_MakeCANickname(cert_handle_); 89 char* nickname = CERT_MakeCANickname(cert_handle_);
89 result = nickname; 90 result = nickname;
90 PORT_Free(nickname); 91 PORT_Free(nickname);
91 break; 92 break;
92 } 93 }
93 case USER_CERT: { 94 case USER_CERT: {
wtc 2013/05/22 20:58:45 Nit: you can remove the curly braces for this case
Ryan Sleevi 2013/05/22 23:20:19 Done.
94 // Create a nickname for a user certificate. 95 // TODO(gspencer): Internationalize this. It's wrong to assume English
95 // We use the scheme used by Firefox: 96 // here.
96 // --> <subject's common name>'s <issuer's common name> ID. 97 result = base::StringPrintf("%s's %s ID",
97 // TODO(gspencer): internationalize this: it's wrong to 98 subject_.GetDisplayName().c_str(),
98 // hard code English. 99 issuer_.GetDisplayName().c_str());
wtc 2013/05/22 20:58:45 Is this change to fix the problem that the common
Ryan Sleevi 2013/05/22 23:20:19 Yes. Made the code simpler to fix while I was here
99
100 std::string username, ca_name;
101 char* temp_username = CERT_GetCommonName(
102 &cert_handle_->subject);
103 char* temp_ca_name = CERT_GetCommonName(&cert_handle_->issuer);
104 if (temp_username) {
105 username = temp_username;
106 PORT_Free(temp_username);
107 }
108 if (temp_ca_name) {
109 ca_name = temp_ca_name;
110 PORT_Free(temp_ca_name);
111 }
112 result = username + "'s " + ca_name + " ID";
113 break; 100 break;
114 } 101 }
115 case SERVER_CERT: 102 case SERVER_CERT:
116 result = subject_.GetDisplayName(); 103 result = subject_.GetDisplayName();
117 break; 104 break;
118 case UNKNOWN_CERT: 105 case UNKNOWN_CERT:
119 default: 106 default:
120 break; 107 break;
121 } 108 }
122 return result; 109 return result;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 280 }
294 281
295 // static 282 // static
296 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, 283 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle,
297 size_t* size_bits, 284 size_t* size_bits,
298 PublicKeyType* type) { 285 PublicKeyType* type) {
299 x509_util::GetPublicKeyInfo(cert_handle, size_bits, type); 286 x509_util::GetPublicKeyInfo(cert_handle, size_bits, type);
300 } 287 }
301 288
302 } // namespace net 289 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698