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

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

Issue 465133004: Remove DenyCertForHost from SSLHostStateDelegate API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sleevi comments Created 6 years, 3 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_cert_types.h" 5 #include "net/cert/x509_cert_types.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <cstring> 8 #include <cstring>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 if (!common_name.empty()) 42 if (!common_name.empty())
43 return common_name; 43 return common_name;
44 if (!organization_names.empty()) 44 if (!organization_names.empty())
45 return organization_names[0]; 45 return organization_names[0];
46 if (!organization_unit_names.empty()) 46 if (!organization_unit_names.empty())
47 return organization_unit_names[0]; 47 return organization_unit_names[0];
48 48
49 return std::string(); 49 return std::string();
50 } 50 }
51 51
52 CertPolicy::CertPolicy() {
53 }
54
55 CertPolicy::~CertPolicy() {
56 }
57
58 // For a denial, we consider a given |cert| to be a match to a saved denied
59 // cert if the |error| intersects with the saved error status. For an
60 // allowance, we consider a given |cert| to be a match to a saved allowed
61 // cert if the |error| is an exact match to or subset of the errors in the
62 // saved CertStatus.
63 CertPolicy::Judgment CertPolicy::Check(
64 X509Certificate* cert, CertStatus error) const {
65 // It shouldn't matter which set we check first, but we check denied first
66 // in case something strange has happened.
67 bool denied = false;
68 std::map<SHA1HashValue, CertStatus, SHA1HashValueLessThan>::const_iterator
69 denied_iter = denied_.find(cert->fingerprint());
70 if ((denied_iter != denied_.end()) && (denied_iter->second & error))
71 denied = true;
72
73 std::map<SHA1HashValue, CertStatus, SHA1HashValueLessThan>::const_iterator
74 allowed_iter = allowed_.find(cert->fingerprint());
75 if ((allowed_iter != allowed_.end()) &&
76 (allowed_iter->second & error) &&
77 !(~(allowed_iter->second & error) ^ ~error)) {
78 DCHECK(!denied);
79 return ALLOWED;
80 }
81
82 if (denied)
83 return DENIED;
84 return UNKNOWN; // We don't have a policy for this cert.
85 }
86
87 void CertPolicy::Allow(X509Certificate* cert, CertStatus error) {
88 // Put the cert in the allowed set and (maybe) remove it from the denied set.
89 denied_.erase(cert->fingerprint());
90 // If this same cert had already been saved with a different error status,
91 // this will replace it with the new error status.
92 allowed_[cert->fingerprint()] = error;
93 }
94
95 void CertPolicy::Deny(X509Certificate* cert, CertStatus error) {
96 // Put the cert in the denied set and (maybe) remove it from the allowed set.
97 std::map<SHA1HashValue, CertStatus, SHA1HashValueLessThan>::const_iterator
98 allowed_iter = allowed_.find(cert->fingerprint());
99 if ((allowed_iter != allowed_.end()) && (allowed_iter->second & error))
100 allowed_.erase(cert->fingerprint());
101 denied_[cert->fingerprint()] |= error;
102 }
103
104 bool CertPolicy::HasAllowedCert() const {
105 return !allowed_.empty();
106 }
107
108 bool CertPolicy::HasDeniedCert() const {
109 return !denied_.empty();
110 }
111
112 bool ParseCertificateDate(const base::StringPiece& raw_date, 52 bool ParseCertificateDate(const base::StringPiece& raw_date,
113 CertDateFormat format, 53 CertDateFormat format,
114 base::Time* time) { 54 base::Time* time) {
115 size_t year_length = format == CERT_DATE_FORMAT_UTC_TIME ? 2 : 4; 55 size_t year_length = format == CERT_DATE_FORMAT_UTC_TIME ? 2 : 4;
116 56
117 if (raw_date.length() < 11 + year_length) 57 if (raw_date.length() < 11 + year_length)
118 return false; 58 return false;
119 59
120 const char* field = raw_date.data(); 60 const char* field = raw_date.data();
121 bool valid = true; 61 bool valid = true;
(...skipping 11 matching lines...) Expand all
133 valid &= exploded.HasValidValues(); 73 valid &= exploded.HasValidValues();
134 74
135 if (!valid) 75 if (!valid)
136 return false; 76 return false;
137 77
138 *time = base::Time::FromUTCExploded(exploded); 78 *time = base::Time::FromUTCExploded(exploded);
139 return true; 79 return true;
140 } 80 }
141 81
142 } // namespace net 82 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698