OLD | NEW |
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_util.h" | 5 #include "net/cert/x509_util.h" |
6 #include "net/cert/x509_util_nss.h" | 6 #include "net/cert/x509_util_nss.h" |
7 | 7 |
8 #include <cert.h> | 8 #include <cert.h> // Must be included before certdb.h |
| 9 #include <certdb.h> |
9 #include <cryptohi.h> | 10 #include <cryptohi.h> |
10 #include <nss.h> | 11 #include <nss.h> |
11 #include <pk11pub.h> | 12 #include <pk11pub.h> |
12 #include <prerror.h> | 13 #include <prerror.h> |
13 #include <secder.h> | 14 #include <secder.h> |
14 #include <secmod.h> | 15 #include <secmod.h> |
15 #include <secport.h> | 16 #include <secport.h> |
16 | 17 |
17 #include "base/debug/leak_annotations.h" | 18 #include "base/debug/leak_annotations.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/singleton.h" | 21 #include "base/memory/singleton.h" |
21 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 23 #include "base/stringprintf.h" |
22 #include "crypto/ec_private_key.h" | 24 #include "crypto/ec_private_key.h" |
23 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
24 #include "crypto/nss_util_internal.h" | 26 #include "crypto/nss_util_internal.h" |
25 #include "crypto/scoped_nss_types.h" | 27 #include "crypto/scoped_nss_types.h" |
26 #include "crypto/third_party/nss/chromium-nss.h" | 28 #include "crypto/third_party/nss/chromium-nss.h" |
27 #include "net/cert/x509_certificate.h" | 29 #include "net/cert/x509_certificate.h" |
28 | 30 |
29 namespace net { | 31 namespace net { |
30 | 32 |
31 namespace { | 33 namespace { |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 for (size_t n = 0; n < cert_chain.size(); ++n) { | 593 for (size_t n = 0; n < cert_chain.size(); ++n) { |
592 CERTName* cert_issuer = &cert_chain[n]->issuer; | 594 CERTName* cert_issuer = &cert_chain[n]->issuer; |
593 for (size_t i = 0; i < valid_issuers.size(); ++i) { | 595 for (size_t i = 0; i < valid_issuers.size(); ++i) { |
594 if (CERT_CompareName(valid_issuers[i], cert_issuer) == SECEqual) | 596 if (CERT_CompareName(valid_issuers[i], cert_issuer) == SECEqual) |
595 return true; | 597 return true; |
596 } | 598 } |
597 } | 599 } |
598 return false; | 600 return false; |
599 } | 601 } |
600 | 602 |
| 603 std::string GetUniqueNicknameForSlot(const std::string& nickname, |
| 604 const SECItem* subject, |
| 605 PK11SlotInfo* slot) { |
| 606 int index = 2; |
| 607 std::string new_name = nickname; |
| 608 std::string temp_nickname = new_name; |
| 609 std::string token_name; |
| 610 |
| 611 if (!slot) |
| 612 return new_name; |
| 613 |
| 614 if (!PK11_IsInternalKeySlot(slot)) { |
| 615 token_name.assign(PK11_GetTokenName(slot)); |
| 616 token_name.append(":"); |
| 617 |
| 618 temp_nickname = token_name + new_name; |
| 619 } |
| 620 |
| 621 while (SEC_CertNicknameConflict(temp_nickname.c_str(), |
| 622 const_cast<SECItem*>(subject), |
| 623 CERT_GetDefaultCertDB())) { |
| 624 base::SStringPrintf(&new_name, "%s #%d", nickname.c_str(), index++); |
| 625 temp_nickname = token_name + new_name; |
| 626 } |
| 627 |
| 628 return new_name; |
| 629 } |
| 630 |
601 #endif // defined(USE_NSS) || defined(OS_IOS) | 631 #endif // defined(USE_NSS) || defined(OS_IOS) |
602 | 632 |
603 } // namespace x509_util | 633 } // namespace x509_util |
604 | 634 |
605 } // namespace net | 635 } // namespace net |
OLD | NEW |