OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ | 5 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ |
6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ | 6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
16 #include "net/cert/internal/parse_certificate.h" | |
17 #include "net/der/input.h" | |
16 | 18 |
17 namespace net { | 19 namespace net { |
18 | 20 |
19 namespace der { | 21 namespace der { |
20 class Input; | |
21 struct GeneralizedTime; | 22 struct GeneralizedTime; |
22 } | 23 } |
23 | 24 |
24 class SignaturePolicy; | 25 class SignaturePolicy; |
25 | 26 |
26 struct NET_EXPORT TrustAnchor { | 27 struct NET_EXPORT TrustAnchor { |
27 ~TrustAnchor(); | 28 ~TrustAnchor(); |
28 | 29 |
29 // DER-encoded SubjectPublicKeyInfo for the trusted key. | 30 // Initializes the TrustAnchor given a DER-encoded certificate. If |copy| |
30 std::string spki; | 31 // is true, a copy of the provided data is made. Otherwise no copy is |
32 // made but the caller must ensure the pointer remains valid for the | |
33 // lifetime of the TrustStore. | |
34 bool AssignCertData(const uint8_t* data, size_t length, bool copy); | |
31 | 35 |
32 // DER-encoded "Name" corresponding to the key. | 36 // The backing store for the certificate data in case it was copied. |
33 std::string name; | 37 std::string owned_cert_tlv; |
38 | |
39 // Points to the raw certificate DER (might be |owned_cert_tlv|, or might | |
40 // be something else). | |
41 der::Input cert_tlv; | |
42 | |
43 ParsedCertificate cert; | |
44 ParsedTbsCertificate tbs; | |
34 }; | 45 }; |
35 | 46 |
36 // A very simple implementation of a TrustStore, which contains mappings from | 47 // A very simple implementation of a TrustStore, which contains a set of |
37 // names to trusted public keys. | 48 // trusted certificates. |
mattm
2016/04/16 02:40:29
I thought we still wanted to allow having trust an
eroman
2016/04/18 20:43:03
I spoke with Ryan and he was of the opinion that r
| |
38 struct NET_EXPORT TrustStore { | 49 struct NET_EXPORT TrustStore { |
39 TrustStore(); | 50 TrustStore(); |
40 TrustStore(const TrustStore& other); | 51 TrustStore(const TrustStore& other); |
41 ~TrustStore(); | 52 ~TrustStore(); |
42 | 53 |
54 bool AddTrustedCertificate(const uint8_t* data, | |
55 size_t length) WARN_UNUSED_RESULT; | |
56 bool AddTrustedCertificate(const base::StringPiece& data) WARN_UNUSED_RESULT; | |
57 | |
58 // Same as AddTrustedCertificate(), but skips copying the certificate | |
59 // data. The caller MUST ensure that data pointer remains valid and is not | |
60 // mutated. This can be used to point to static data and avoid copying it, | |
61 // but shoudl otherwise be avoided. | |
mattm
2016/04/16 02:40:29
should
eroman
2016/04/18 20:43:03
Done.
| |
62 bool AddTrustedCertificateWithoutCopying(const uint8_t* data, | |
63 size_t length) WARN_UNUSED_RESULT; | |
64 | |
65 // Returns nullptr if no certificate matching |name| is in the TrustStore. | |
66 // Otherwise returns the DER data for the matching certificate. | |
67 const der::Input* FindTrustedCertificateByName(const der::Input& name) const | |
68 WARN_UNUSED_RESULT; | |
69 | |
70 // Returns true if |cert_der| matches a certificate in the TrustStore. | |
71 bool IsTrustedCertificate(const der::Input& cert_der) const | |
72 WARN_UNUSED_RESULT; | |
73 | |
43 std::vector<TrustAnchor> anchors; | 74 std::vector<TrustAnchor> anchors; |
44 }; | 75 }; |
45 | 76 |
46 // VerifyCertificateChain() verifies a certificate path (chain) based on the | 77 // VerifyCertificateChain() verifies a certificate path (chain) based on the |
47 // rules in RFC 5280. | 78 // rules in RFC 5280. |
48 // | 79 // |
49 // WARNING: This implementation is in progress, and is currently | 80 // WARNING: This implementation is in progress, and is currently |
50 // incomplete. DO NOT USE IT unless its limitations are acceptable for your use. | 81 // incomplete. DO NOT USE IT unless its limitations are acceptable for your use. |
51 // | 82 // |
52 // --------- | 83 // --------- |
(...skipping 25 matching lines...) Expand all Loading... | |
78 // Returns true if the target certificate can be verified. | 109 // Returns true if the target certificate can be verified. |
79 NET_EXPORT bool VerifyCertificateChain(const std::vector<der::Input>& certs_der, | 110 NET_EXPORT bool VerifyCertificateChain(const std::vector<der::Input>& certs_der, |
80 const TrustStore& trust_store, | 111 const TrustStore& trust_store, |
81 const SignaturePolicy* signature_policy, | 112 const SignaturePolicy* signature_policy, |
82 const der::GeneralizedTime& time) | 113 const der::GeneralizedTime& time) |
83 WARN_UNUSED_RESULT; | 114 WARN_UNUSED_RESULT; |
84 | 115 |
85 } // namespace net | 116 } // namespace net |
86 | 117 |
87 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ | 118 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ |
OLD | NEW |