OLD | NEW |
1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
3 * | 3 * |
4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
8 * | 8 * |
9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // Mozilla just returns here, but we continue in case there are other certs | 73 // Mozilla just returns here, but we continue in case there are other certs |
74 // in the list which aren't already imported. | 74 // in the list which aren't already imported. |
75 // TODO(mattm): should we set/add trust if it differs from the present | 75 // TODO(mattm): should we set/add trust if it differs from the present |
76 // settings? | 76 // settings? |
77 not_imported->push_back(net::CertDatabase::ImportCertFailure( | 77 not_imported->push_back(net::CertDatabase::ImportCertFailure( |
78 root, net::ERR_IMPORT_CERT_ALREADY_EXISTS)); | 78 root, net::ERR_IMPORT_CERT_ALREADY_EXISTS)); |
79 } else { | 79 } else { |
80 // Mozilla uses CERT_AddTempCertToPerm, however it is privately exported, | 80 // Mozilla uses CERT_AddTempCertToPerm, however it is privately exported, |
81 // and it doesn't take the slot as an argument either. Instead, we use | 81 // and it doesn't take the slot as an argument either. Instead, we use |
82 // PK11_ImportCert and CERT_ChangeCertTrust. | 82 // PK11_ImportCert and CERT_ChangeCertTrust. |
83 char* nickname = CERT_MakeCANickname(root->os_cert_handle()); | 83 SECStatus srv = PK11_ImportCert( |
84 if (!nickname) | 84 slot.get(), |
85 return false; | 85 root->os_cert_handle(), |
86 SECStatus srv = PK11_ImportCert(slot.get(), root->os_cert_handle(), | 86 CK_INVALID_HANDLE, |
87 CK_INVALID_HANDLE, | 87 root->GetDefaultNickname(net::CA_CERT).c_str(), |
88 nickname, | 88 PR_FALSE /* includeTrust (unused) */); |
89 PR_FALSE /* includeTrust (unused) */); | |
90 PORT_Free(nickname); | |
91 if (srv != SECSuccess) { | 89 if (srv != SECSuccess) { |
92 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); | 90 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); |
93 return false; | 91 return false; |
94 } | 92 } |
95 if (!SetCertTrust(root, net::CA_CERT, trustBits)) | 93 if (!SetCertTrust(root, net::CA_CERT, trustBits)) |
96 return false; | 94 return false; |
97 } | 95 } |
98 | 96 |
99 PRTime now = PR_Now(); | 97 PRTime now = PR_Now(); |
100 // Import additional delivered certificates that can be verified. | 98 // Import additional delivered certificates that can be verified. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // error value). (maybe make MapSecurityError or MapCertErrorToCertStatus | 130 // error value). (maybe make MapSecurityError or MapCertErrorToCertStatus |
133 // public.) | 131 // public.) |
134 not_imported->push_back(net::CertDatabase::ImportCertFailure( | 132 not_imported->push_back(net::CertDatabase::ImportCertFailure( |
135 cert, net::ERR_FAILED)); | 133 cert, net::ERR_FAILED)); |
136 VLOG(1) << "skipping cert (verify) " << PORT_GetError(); | 134 VLOG(1) << "skipping cert (verify) " << PORT_GetError(); |
137 continue; | 135 continue; |
138 } | 136 } |
139 | 137 |
140 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use | 138 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use |
141 // PK11_ImportCert instead. | 139 // PK11_ImportCert instead. |
142 char* nickname = CERT_MakeCANickname(cert->os_cert_handle()); | 140 SECStatus srv = PK11_ImportCert( |
143 if (!nickname) | 141 slot.get(), |
144 return false; | 142 cert->os_cert_handle(), |
145 SECStatus srv = PK11_ImportCert(slot.get(), cert->os_cert_handle(), | 143 CK_INVALID_HANDLE, |
146 CK_INVALID_HANDLE, | 144 cert->GetDefaultNickname(net::CA_CERT).c_str(), |
147 nickname, | 145 PR_FALSE /* includeTrust (unused) */); |
148 PR_FALSE /* includeTrust (unused) */); | |
149 PORT_Free(nickname); | |
150 if (srv != SECSuccess) { | 146 if (srv != SECSuccess) { |
151 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); | 147 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); |
152 // TODO(mattm): Should we bail or continue on error here? Mozilla doesn't | 148 // TODO(mattm): Should we bail or continue on error here? Mozilla doesn't |
153 // check error code at all. | 149 // check error code at all. |
154 not_imported->push_back(net::CertDatabase::ImportCertFailure( | 150 not_imported->push_back(net::CertDatabase::ImportCertFailure( |
155 cert, net::ERR_IMPORT_CA_CERT_FAILED)); | 151 cert, net::ERR_IMPORT_CA_CERT_FAILED)); |
156 } | 152 } |
157 } | 153 } |
158 | 154 |
159 // Any errors importing individual certs will be in listed in |not_imported|. | 155 // Any errors importing individual certs will be in listed in |not_imported|. |
160 return true; | 156 return true; |
161 } | 157 } |
162 | 158 |
163 // Based on nsNSSCertificateDB::ImportServerCertificate. | 159 // Based on nsNSSCertificateDB::ImportServerCertificate. |
164 bool ImportServerCert(const net::CertificateList& certificates, | 160 bool ImportServerCert(const net::CertificateList& certificates, |
165 net::CertDatabase::ImportCertFailureList* not_imported) { | 161 net::CertDatabase::ImportCertFailureList* not_imported) { |
166 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot()); | 162 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot()); |
167 if (!slot.get()) { | 163 if (!slot.get()) { |
168 LOG(ERROR) << "Couldn't get internal key slot!"; | 164 LOG(ERROR) << "Couldn't get internal key slot!"; |
169 return false; | 165 return false; |
170 } | 166 } |
171 | 167 |
172 for (size_t i = 0; i < certificates.size(); ++i) { | 168 for (size_t i = 0; i < certificates.size(); ++i) { |
173 const scoped_refptr<net::X509Certificate>& cert = certificates[i]; | 169 const scoped_refptr<net::X509Certificate>& cert = certificates[i]; |
174 | 170 |
175 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use | 171 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use |
176 // PK11_ImportCert instead. | 172 // PK11_ImportCert instead. |
177 SECStatus srv = PK11_ImportCert(slot.get(), cert->os_cert_handle(), | 173 SECStatus srv = PK11_ImportCert( |
178 CK_INVALID_HANDLE, | 174 slot.get(), |
179 cert->subject().GetDisplayName().c_str(), | 175 cert->os_cert_handle(), |
180 PR_FALSE /* includeTrust (unused) */); | 176 CK_INVALID_HANDLE, |
| 177 cert->GetDefaultNickname(net::SERVER_CERT).c_str(), |
| 178 PR_FALSE /* includeTrust (unused) */); |
181 if (srv != SECSuccess) { | 179 if (srv != SECSuccess) { |
182 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); | 180 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); |
183 not_imported->push_back(net::CertDatabase::ImportCertFailure( | 181 not_imported->push_back(net::CertDatabase::ImportCertFailure( |
184 cert, net::ERR_IMPORT_SERVER_CERT_FAILED)); | 182 cert, net::ERR_IMPORT_SERVER_CERT_FAILED)); |
185 continue; | 183 continue; |
186 } | 184 } |
187 } | 185 } |
188 | 186 |
189 // Set as valid peer, but without any extra trust. | 187 // Set as valid peer, but without any extra trust. |
190 SetCertTrust(certificates[0].get(), net::SERVER_CERT, | 188 SetCertTrust(certificates[0].get(), net::SERVER_CERT, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } else { | 222 } else { |
225 // ignore user and email/unknown certs | 223 // ignore user and email/unknown certs |
226 return true; | 224 return true; |
227 } | 225 } |
228 if (srv != SECSuccess) | 226 if (srv != SECSuccess) |
229 LOG(ERROR) << "SetCertTrust failed with error " << PORT_GetError(); | 227 LOG(ERROR) << "SetCertTrust failed with error " << PORT_GetError(); |
230 return srv == SECSuccess; | 228 return srv == SECSuccess; |
231 } | 229 } |
232 | 230 |
233 } // namespace mozilla_security_manager | 231 } // namespace mozilla_security_manager |
OLD | NEW |