OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/net/x509_certificate_model.h" | 5 #include "chrome/common/net/x509_certificate_model.h" |
6 | 6 |
| 7 #include <openssl/bio.h> |
7 #include <openssl/obj_mac.h> | 8 #include <openssl/obj_mac.h> |
8 #include <openssl/sha.h> | 9 #include <openssl/sha.h> |
9 #include <openssl/x509v3.h> | 10 #include <openssl/x509v3.h> |
10 | 11 |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "crypto/openssl_bio_string.h" |
| 15 #include "crypto/openssl_util.h" |
13 #include "net/cert/x509_util_openssl.h" | 16 #include "net/cert/x509_util_openssl.h" |
14 | 17 |
15 namespace x509_util = net::x509_util; | 18 namespace x509_util = net::x509_util; |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 std::string AlternativeWhenEmpty(const std::string& text, | 22 std::string AlternativeWhenEmpty(const std::string& text, |
20 const std::string& alternative) { | 23 const std::string& alternative) { |
21 return text.empty() ? alternative : text; | 24 return text.empty() ? alternative : text; |
22 } | 25 } |
(...skipping 14 matching lines...) Expand all Loading... |
37 return ret; | 40 return ret; |
38 } | 41 } |
39 | 42 |
40 } // namespace | 43 } // namespace |
41 | 44 |
42 namespace x509_certificate_model { | 45 namespace x509_certificate_model { |
43 | 46 |
44 using net::X509Certificate; | 47 using net::X509Certificate; |
45 | 48 |
46 std::string GetCertNameOrNickname(X509Certificate::OSCertHandle cert_handle) { | 49 std::string GetCertNameOrNickname(X509Certificate::OSCertHandle cert_handle) { |
47 // TODO(bulach): implement me. | 50 std::string name = |
48 return ""; | 51 ProcessIDN(GetSubjectCommonName(cert_handle, std::string())); |
| 52 if (!name.empty()) |
| 53 return name; |
| 54 |
| 55 crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&name)); |
| 56 if (!bio.get()) |
| 57 return name; |
| 58 X509_NAME_print_ex(bio.get(), |
| 59 X509_get_subject_name(cert_handle), |
| 60 0 /* indent */, |
| 61 XN_FLAG_RFC2253 & ~ASN1_STRFLGS_ESC_MSB); |
| 62 return name; |
49 } | 63 } |
50 | 64 |
51 std::string GetTokenName(X509Certificate::OSCertHandle cert_handle) { | 65 std::string GetTokenName(X509Certificate::OSCertHandle cert_handle) { |
52 // TODO(bulach): implement me. | 66 // TODO(bulach): implement me. |
53 return ""; | 67 return ""; |
54 } | 68 } |
55 | 69 |
56 std::string GetVersion(net::X509Certificate::OSCertHandle cert_handle) { | 70 std::string GetVersion(net::X509Certificate::OSCertHandle cert_handle) { |
57 unsigned long version = X509_get_version(cert_handle); | 71 unsigned long version = X509_get_version(cert_handle); |
58 if (version != ULONG_MAX) | 72 if (version != ULONG_MAX) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 return AlternativeWhenEmpty(ret, alternative_text); | 147 return AlternativeWhenEmpty(ret, alternative_text); |
134 } | 148 } |
135 | 149 |
136 bool GetTimes(X509Certificate::OSCertHandle cert_handle, | 150 bool GetTimes(X509Certificate::OSCertHandle cert_handle, |
137 base::Time* issued, base::Time* expires) { | 151 base::Time* issued, base::Time* expires) { |
138 return x509_util::ParseDate(X509_get_notBefore(cert_handle), issued) && | 152 return x509_util::ParseDate(X509_get_notBefore(cert_handle), issued) && |
139 x509_util::ParseDate(X509_get_notAfter(cert_handle), expires); | 153 x509_util::ParseDate(X509_get_notAfter(cert_handle), expires); |
140 } | 154 } |
141 | 155 |
142 std::string GetTitle(net::X509Certificate::OSCertHandle cert_handle) { | 156 std::string GetTitle(net::X509Certificate::OSCertHandle cert_handle) { |
143 // TODO(bulach): implement me. | 157 // TODO(mattm): merge GetTitle and GetCertNameOrNickname? |
144 return ""; | 158 // Is there any reason GetCertNameOrNickname calls ProcessIDN and this |
| 159 // doesn't? |
| 160 std::string title = |
| 161 GetSubjectCommonName(cert_handle, std::string()); |
| 162 if (!title.empty()) |
| 163 return title; |
| 164 |
| 165 crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&title)); |
| 166 if (!bio.get()) |
| 167 return title; |
| 168 X509_NAME_print_ex(bio.get(), |
| 169 X509_get_subject_name(cert_handle), |
| 170 0 /* indent */, |
| 171 XN_FLAG_RFC2253 & ~ASN1_STRFLGS_ESC_MSB); |
| 172 return title; |
145 } | 173 } |
146 | 174 |
147 std::string GetIssuerName(net::X509Certificate::OSCertHandle cert_handle) { | 175 std::string GetIssuerName(net::X509Certificate::OSCertHandle cert_handle) { |
148 return GetKeyValuesFromName(X509_get_issuer_name(cert_handle)); | 176 return GetKeyValuesFromName(X509_get_issuer_name(cert_handle)); |
149 } | 177 } |
150 | 178 |
151 std::string GetSubjectName(net::X509Certificate::OSCertHandle cert_handle) { | 179 std::string GetSubjectName(net::X509Certificate::OSCertHandle cert_handle) { |
152 return GetKeyValuesFromName(X509_get_subject_name(cert_handle)); | 180 return GetKeyValuesFromName(X509_get_subject_name(cert_handle)); |
153 } | 181 } |
154 | 182 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return ""; | 254 return ""; |
227 } | 255 } |
228 | 256 |
229 std::string ProcessRawBitsSignatureWrap( | 257 std::string ProcessRawBitsSignatureWrap( |
230 net::X509Certificate::OSCertHandle cert_handle) { | 258 net::X509Certificate::OSCertHandle cert_handle) { |
231 // TODO(bulach): implement me. | 259 // TODO(bulach): implement me. |
232 return ""; | 260 return ""; |
233 } | 261 } |
234 | 262 |
235 } // namespace x509_certificate_model | 263 } // namespace x509_certificate_model |
OLD | NEW |