| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
| 6 | 6 |
| 7 #include <openssl/asn1.h> | 7 #include <openssl/asn1.h> |
| 8 #include <openssl/crypto.h> | 8 #include <openssl/crypto.h> |
| 9 #include <openssl/obj_mac.h> | 9 #include <openssl/obj_mac.h> |
| 10 #include <openssl/pem.h> | 10 #include <openssl/pem.h> |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 x509_time->length); | 121 x509_time->length); |
| 122 // UTCTime: YYMMDDHHMMSSZ | 122 // UTCTime: YYMMDDHHMMSSZ |
| 123 // GeneralizedTime: YYYYMMDDHHMMSSZ | 123 // GeneralizedTime: YYYYMMDDHHMMSSZ |
| 124 size_t year_length = x509_time->type == V_ASN1_UTCTIME ? 2 : 4; | 124 size_t year_length = x509_time->type == V_ASN1_UTCTIME ? 2 : 4; |
| 125 size_t fields_offset = x509_time->type == V_ASN1_UTCTIME ? 0 : 2; | 125 size_t fields_offset = x509_time->type == V_ASN1_UTCTIME ? 0 : 2; |
| 126 | 126 |
| 127 if (str_date.length() < 11 + year_length) | 127 if (str_date.length() < 11 + year_length) |
| 128 return; | 128 return; |
| 129 | 129 |
| 130 base::Time::Exploded exploded = {0}; | 130 base::Time::Exploded exploded = {0}; |
| 131 bool valid = base::StringToInt(str_date.substr(0, year_length), | 131 bool valid = base::StringToInt(str_date.begin(), |
| 132 str_date.begin() + year_length, |
| 132 &exploded.year); | 133 &exploded.year); |
| 133 if (valid && year_length == 2) | 134 if (valid && year_length == 2) |
| 134 exploded.year += exploded.year < 50 ? 2000 : 1900; | 135 exploded.year += exploded.year < 50 ? 2000 : 1900; |
| 135 | 136 |
| 136 valid &= base::StringToInt(str_date.substr(2 + fields_offset, 2), | 137 valid &= base::StringToInt(str_date.begin() + fields_offset + 2, |
| 138 str_date.begin() + fields_offset + 4, |
| 137 &exploded.month); | 139 &exploded.month); |
| 138 valid &= base::StringToInt(str_date.substr(4 + fields_offset, 2), | 140 valid &= base::StringToInt(str_date.begin() + fields_offset + 4, |
| 141 str_date.begin() + fields_offset + 6), |
| 139 &exploded.day_of_month); | 142 &exploded.day_of_month); |
| 140 valid &= base::StringToInt(str_date.substr(6 + fields_offset, 2), | 143 valid &= base::StringToInt(str_date.begin() + fields_offset + 6, |
| 144 str_date.begin() + fields_offset + 8), |
| 141 &exploded.hour); | 145 &exploded.hour); |
| 142 valid &= base::StringToInt(str_date.substr(8 + fields_offset, 2), | 146 valid &= base::StringToInt(str_date.begin() + fields_offset + 8, |
| 147 str_date.begin() + fields_offset + 10), |
| 143 &exploded.minute); | 148 &exploded.minute); |
| 144 valid &= base::StringToInt(str_date.substr(10 + fields_offset, 2), | 149 valid &= base::StringToInt(str_date.begin() + fields_offset + 10, |
| 150 str_date.begin() + fields_offset + 12, |
| 145 &exploded.second); | 151 &exploded.second); |
| 146 | 152 |
| 147 DCHECK(valid); | 153 DCHECK(valid); |
| 148 | 154 |
| 149 *time = base::Time::FromUTCExploded(exploded); | 155 *time = base::Time::FromUTCExploded(exploded); |
| 150 } | 156 } |
| 151 | 157 |
| 152 void ParseSubjectAltNames(X509Certificate::OSCertHandle cert, | 158 void ParseSubjectAltNames(X509Certificate::OSCertHandle cert, |
| 153 std::vector<std::string>* dns_names) { | 159 std::vector<std::string>* dns_names) { |
| 154 int index = X509_get_ext_by_NID(cert, NID_subject_alt_name, -1); | 160 int index = X509_get_ext_by_NID(cert, NID_subject_alt_name, -1); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // cache the DER (if not already cached via X509_set_ex_data). | 486 // cache the DER (if not already cached via X509_set_ex_data). |
| 481 DERCache der_cache_a, der_cache_b; | 487 DERCache der_cache_a, der_cache_b; |
| 482 | 488 |
| 483 return GetDERAndCacheIfNeeded(a, &der_cache_a) && | 489 return GetDERAndCacheIfNeeded(a, &der_cache_a) && |
| 484 GetDERAndCacheIfNeeded(b, &der_cache_b) && | 490 GetDERAndCacheIfNeeded(b, &der_cache_b) && |
| 485 der_cache_a.data_length == der_cache_b.data_length && | 491 der_cache_a.data_length == der_cache_b.data_length && |
| 486 memcmp(der_cache_a.data, der_cache_b.data, der_cache_a.data_length) == 0; | 492 memcmp(der_cache_a.data, der_cache_b.data, der_cache_a.data_length) == 0; |
| 487 } | 493 } |
| 488 | 494 |
| 489 } // namespace net | 495 } // namespace net |
| OLD | NEW |