Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | |
|
wtc
2010/03/24 23:52:05
Nit: the copyright notice should just say 2010. I
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_X509_TYPES_H_ | |
| 6 #define NET_BASE_X509_TYPES_H_ | |
| 7 | |
| 8 #include <string.h> | |
| 9 | |
| 10 #include <iostream> | |
| 11 #include <map> | |
| 12 #include <set> | |
| 13 #include <string> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "base/ref_counted.h" | |
| 17 #include "base/singleton.h" | |
| 18 #include "base/time.h" | |
| 19 #include "testing/gtest/include/gtest/gtest_prod.h" | |
| 20 | |
| 21 #if defined(OS_WIN) | |
| 22 #include <windows.h> | |
| 23 #include <wincrypt.h> | |
| 24 #elif defined(OS_MACOSX) | |
| 25 #include <Security/x509defs.h> | |
| 26 #elif defined(USE_NSS) | |
| 27 // Forward declaration; real one in <cert.h> | |
| 28 struct CERTCertificateStr; | |
| 29 #endif | |
| 30 | |
| 31 namespace net { | |
| 32 | |
| 33 class X509Certificate; | |
|
wtc
2010/03/24 23:52:05
Nit: don't indent the contents of a namespace.
ht
| |
| 34 | |
| 35 // SHA-1 fingerprint (160 bits) of a certificate. | |
| 36 struct SHA1Fingerprint { | |
| 37 bool Equals(const SHA1Fingerprint& other) const { | |
| 38 return memcmp(data, other.data, sizeof(data)) == 0; | |
| 39 } | |
| 40 | |
| 41 unsigned char data[20]; | |
| 42 }; | |
| 43 | |
| 44 class SHA1FingerprintLessThan | |
| 45 : public std::binary_function<SHA1Fingerprint, SHA1Fingerprint, bool> { | |
| 46 public: | |
| 47 bool operator() (const SHA1Fingerprint& lhs, const SHA1Fingerprint& rhs) con st; | |
| 48 }; | |
| 49 | |
| 50 // Principal represent an X.509 principal. | |
|
wtc
2010/03/24 23:52:05
Nit: let's change this comment to:
// CertPrinc
| |
| 51 struct CertPrincipal { | |
| 52 CertPrincipal() { } | |
| 53 explicit CertPrincipal(const std::string& name) : common_name(name) { } | |
| 54 | |
| 55 // Parses a BER-format X.509 DistinguishedName. | |
|
wtc
2010/03/24 23:52:05
Nit: remove "X.509" because DistinguishedName come
| |
| 56 bool ParseDistinguishedName(const void* x509_name_data, size_t length); | |
| 57 | |
| 58 #if defined(OS_MACOSX) | |
| 59 // Parses a CSSM_X509_NAME struct. | |
| 60 void Parse(const CSSM_X509_NAME* name); | |
| 61 #endif | |
| 62 | |
| 63 // Returns true if all non-empty components of |against| match the | |
| 64 // corresponding components of the receiver, where "match" is defined | |
|
wtc
2010/03/24 23:52:05
Nit: receiver => object?
I still think we should
| |
| 65 // in RFC 5280 sec. 7.1. | |
| 66 bool Matches(const CertPrincipal& against) const; | |
| 67 | |
| 68 // The different attributes for a principal. They may be "". | |
| 69 // Note that some of them can have several values. | |
| 70 | |
| 71 std::string common_name; | |
| 72 std::string locality_name; | |
| 73 std::string state_or_province_name; | |
| 74 std::string country_name; | |
| 75 | |
| 76 std::vector<std::string> street_addresses; | |
| 77 std::vector<std::string> organization_names; | |
| 78 std::vector<std::string> organization_unit_names; | |
| 79 std::vector<std::string> domain_components; | |
| 80 }; | |
| 81 | |
| 82 // Writes a human-readable description of a Principal, for debugging. | |
|
wtc
2010/03/24 23:52:05
Nit: Principal => CertPrincipal
| |
| 83 std::ostream& operator<<(std::ostream& s, const CertPrincipal& p); | |
| 84 | |
| 85 // This class is useful for maintaining policies about which certificates are | |
| 86 // permitted or forbidden for a particular purpose. | |
| 87 class CertPolicy { | |
| 88 public: | |
| 89 // The judgments this policy can reach. | |
| 90 enum Judgment { | |
| 91 // We don't have policy information for this certificate. | |
| 92 UNKNOWN, | |
| 93 | |
| 94 // This certificate is allowed. | |
| 95 ALLOWED, | |
| 96 | |
| 97 // This certificate is denied. | |
| 98 DENIED, | |
| 99 }; | |
| 100 | |
| 101 // Returns the judgment this policy makes about this certificate. | |
| 102 Judgment Check(X509Certificate* cert) const; | |
| 103 | |
| 104 // Causes the policy to allow this certificate. | |
| 105 void Allow(X509Certificate* cert); | |
| 106 | |
| 107 // Causes the policy to deny this certificate. | |
| 108 void Deny(X509Certificate* cert); | |
| 109 | |
| 110 // Returns true if this policy has allowed at least one certificate. | |
| 111 bool HasAllowedCert() const; | |
| 112 | |
| 113 // Returns true if this policy has denied at least one certificate. | |
| 114 bool HasDeniedCert() const; | |
| 115 | |
| 116 private: | |
| 117 // The set of fingerprints of allowed certificates. | |
| 118 std::set<SHA1Fingerprint, SHA1FingerprintLessThan> allowed_; | |
| 119 | |
| 120 // The set of fingerprints of denied certificates. | |
| 121 std::set<SHA1Fingerprint, SHA1FingerprintLessThan> denied_; | |
| 122 }; | |
| 123 | |
| 124 #if defined(OS_MACOSX) | |
| 125 // Compares two OIDs by value. | |
| 126 inline bool CSSMOIDEqual(const CSSM_OID* oid1, const CSSM_OID* oid2) { | |
| 127 return oid1->Length == oid2->Length && | |
| 128 (memcmp(oid1->Data, oid2->Data, oid1->Length) == 0); | |
| 129 } | |
| 130 #endif | |
| 131 | |
| 132 } // namespace net | |
| 133 | |
| 134 #endif // NET_BASE_X509_TYPES_H_ | |
| OLD | NEW |