Chromium Code Reviews| Index: net/base/x509_cert_types.h |
| diff --git a/net/base/x509_cert_types.h b/net/base/x509_cert_types.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7bc66495668ccfd060733c14257337795e7246b2 |
| --- /dev/null |
| +++ b/net/base/x509_cert_types.h |
| @@ -0,0 +1,134 @@ |
| +// 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
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_BASE_X509_TYPES_H_ |
| +#define NET_BASE_X509_TYPES_H_ |
| + |
| +#include <string.h> |
| + |
| +#include <iostream> |
| +#include <map> |
| +#include <set> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/ref_counted.h" |
| +#include "base/singleton.h" |
| +#include "base/time.h" |
| +#include "testing/gtest/include/gtest/gtest_prod.h" |
| + |
| +#if defined(OS_WIN) |
| +#include <windows.h> |
| +#include <wincrypt.h> |
| +#elif defined(OS_MACOSX) |
| +#include <Security/x509defs.h> |
| +#elif defined(USE_NSS) |
| +// Forward declaration; real one in <cert.h> |
| +struct CERTCertificateStr; |
| +#endif |
| + |
| +namespace net { |
| + |
| + class X509Certificate; |
|
wtc
2010/03/24 23:52:05
Nit: don't indent the contents of a namespace.
ht
|
| + |
| + // SHA-1 fingerprint (160 bits) of a certificate. |
| + struct SHA1Fingerprint { |
| + bool Equals(const SHA1Fingerprint& other) const { |
| + return memcmp(data, other.data, sizeof(data)) == 0; |
| + } |
| + |
| + unsigned char data[20]; |
| + }; |
| + |
| + class SHA1FingerprintLessThan |
| + : public std::binary_function<SHA1Fingerprint, SHA1Fingerprint, bool> { |
| + public: |
| + bool operator() (const SHA1Fingerprint& lhs, const SHA1Fingerprint& rhs) const; |
| + }; |
| + |
| + // Principal represent an X.509 principal. |
|
wtc
2010/03/24 23:52:05
Nit: let's change this comment to:
// CertPrinc
|
| + struct CertPrincipal { |
| + CertPrincipal() { } |
| + explicit CertPrincipal(const std::string& name) : common_name(name) { } |
| + |
| + // Parses a BER-format X.509 DistinguishedName. |
|
wtc
2010/03/24 23:52:05
Nit: remove "X.509" because DistinguishedName come
|
| + bool ParseDistinguishedName(const void* x509_name_data, size_t length); |
| + |
| +#if defined(OS_MACOSX) |
| + // Parses a CSSM_X509_NAME struct. |
| + void Parse(const CSSM_X509_NAME* name); |
| +#endif |
| + |
| + // Returns true if all non-empty components of |against| match the |
| + // corresponding components of the receiver, where "match" is defined |
|
wtc
2010/03/24 23:52:05
Nit: receiver => object?
I still think we should
|
| + // in RFC 5280 sec. 7.1. |
| + bool Matches(const CertPrincipal& against) const; |
| + |
| + // The different attributes for a principal. They may be "". |
| + // Note that some of them can have several values. |
| + |
| + std::string common_name; |
| + std::string locality_name; |
| + std::string state_or_province_name; |
| + std::string country_name; |
| + |
| + std::vector<std::string> street_addresses; |
| + std::vector<std::string> organization_names; |
| + std::vector<std::string> organization_unit_names; |
| + std::vector<std::string> domain_components; |
| + }; |
| + |
| + // Writes a human-readable description of a Principal, for debugging. |
|
wtc
2010/03/24 23:52:05
Nit: Principal => CertPrincipal
|
| + std::ostream& operator<<(std::ostream& s, const CertPrincipal& p); |
| + |
| + // This class is useful for maintaining policies about which certificates are |
| + // permitted or forbidden for a particular purpose. |
| + class CertPolicy { |
| + public: |
| + // The judgments this policy can reach. |
| + enum Judgment { |
| + // We don't have policy information for this certificate. |
| + UNKNOWN, |
| + |
| + // This certificate is allowed. |
| + ALLOWED, |
| + |
| + // This certificate is denied. |
| + DENIED, |
| + }; |
| + |
| + // Returns the judgment this policy makes about this certificate. |
| + Judgment Check(X509Certificate* cert) const; |
| + |
| + // Causes the policy to allow this certificate. |
| + void Allow(X509Certificate* cert); |
| + |
| + // Causes the policy to deny this certificate. |
| + void Deny(X509Certificate* cert); |
| + |
| + // Returns true if this policy has allowed at least one certificate. |
| + bool HasAllowedCert() const; |
| + |
| + // Returns true if this policy has denied at least one certificate. |
| + bool HasDeniedCert() const; |
| + |
| + private: |
| + // The set of fingerprints of allowed certificates. |
| + std::set<SHA1Fingerprint, SHA1FingerprintLessThan> allowed_; |
| + |
| + // The set of fingerprints of denied certificates. |
| + std::set<SHA1Fingerprint, SHA1FingerprintLessThan> denied_; |
| + }; |
| + |
| +#if defined(OS_MACOSX) |
| + // Compares two OIDs by value. |
| + inline bool CSSMOIDEqual(const CSSM_OID* oid1, const CSSM_OID* oid2) { |
| + return oid1->Length == oid2->Length && |
| + (memcmp(oid1->Data, oid2->Data, oid1->Length) == 0); |
| + } |
| +#endif |
| + |
| +} // namespace net |
| + |
| +#endif // NET_BASE_X509_TYPES_H_ |