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

Side by Side Diff: extensions/common/cast/cast_cert_validator.h

Issue 1888913005: Add a hook to inject trusted Cast roots for testing purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | extensions/common/cast/cast_cert_validator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_ 5 #ifndef EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
6 #define EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_ 6 #define EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "net/cert/internal/verify_certificate_chain.h"
16 17
17 namespace extensions { 18 namespace extensions {
18 namespace api { 19 namespace api {
19 namespace cast_crypto { 20 namespace cast_crypto {
20 21
21 // Describes the policy for a Device certificate. 22 // Describes the policy for a Device certificate.
22 enum class CastDeviceCertPolicy { 23 enum class CastDeviceCertPolicy {
23 // The device certificate is unrestricted. 24 // The device certificate is unrestricted.
24 NONE, 25 NONE,
25 26
(...skipping 18 matching lines...) Expand all
44 45
45 // Retrieve the Common Name attribute of the subject's distinguished name from 46 // Retrieve the Common Name attribute of the subject's distinguished name from
46 // the verified certificate, if present. Returns an empty string if no Common 47 // the verified certificate, if present. Returns an empty string if no Common
47 // Name is found. 48 // Name is found.
48 virtual std::string GetCommonName() const = 0; 49 virtual std::string GetCommonName() const = 0;
49 50
50 private: 51 private:
51 DISALLOW_COPY_AND_ASSIGN(CertVerificationContext); 52 DISALLOW_COPY_AND_ASSIGN(CertVerificationContext);
52 }; 53 };
53 54
55 // Helper function that creates and initializes a TrustAnchor struct given
56 // arrays for the subject's DER and the SPKI's DER.
57 template <size_t SubjectSize, size_t SpkiSize>
58 net::TrustAnchor CreateTrustAnchor(const uint8_t (&subject)[SubjectSize],
eroman 2016/04/18 18:28:40 A more useful API is probably: void AddTrustAncho
ryanchung 2016/04/19 17:19:34 I'm thinking of undoing this API change and waitin
59 const uint8_t (&spki)[SpkiSize]) {
60 net::TrustAnchor anchor;
61 anchor.name = std::string(subject, subject + SubjectSize);
62 anchor.spki = std::string(spki, spki + SpkiSize);
63 return anchor;
64 }
65
66 // Creates a trust store with the two Cast roots.
67 net::TrustStore CreateCastTrustStore();
68
54 // Verifies a cast device certficate given a chain of DER-encoded certificates. 69 // Verifies a cast device certficate given a chain of DER-encoded certificates.
55 // 70 //
56 // Inputs: 71 // Inputs:
57 // 72 //
58 // * |certs| is a chain of DER-encoded certificates: 73 // * |certs| is a chain of DER-encoded certificates:
59 // * |certs[0]| is the target certificate (i.e. the device certificate) 74 // * |certs[0]| is the target certificate (i.e. the device certificate)
60 // * |certs[i]| is the certificate that issued certs[i-1] 75 // * |certs[i]| is the certificate that issued certs[i-1]
61 // * |certs.back()| must be signed by a trust anchor 76 // * |certs.back()| must be signed by a trust anchor
62 // 77 //
63 // * |time| is the UTC time to use for determining if the certificate 78 // * |time| is the UTC time to use for determining if the certificate
64 // is expired. 79 // is expired.
65 // 80 //
66 // Outputs: 81 // Outputs:
67 // 82 //
68 // Returns true on success, false on failure. On success the output 83 // Returns true on success, false on failure. On success the output
69 // parameters are filled with more details: 84 // parameters are filled with more details:
70 // 85 //
71 // * |context| is filled with an object that can be used to verify signatures 86 // * |context| is filled with an object that can be used to verify signatures
72 // using the device certificate's public key, as well as to extract other 87 // using the device certificate's public key, as well as to extract other
73 // properties from the device certificate (Common Name). 88 // properties from the device certificate (Common Name).
74 // * |policy| is filled with an indication of the device certificate's policy 89 // * |policy| is filled with an indication of the device certificate's policy
75 // (i.e. is it for audio-only devices or is it unrestricted?) 90 // (i.e. is it for audio-only devices or is it unrestricted?)
91 // * |trust_store| is filled with the trusted CA certificate information
76 bool VerifyDeviceCert(const std::vector<std::string>& certs, 92 bool VerifyDeviceCert(const std::vector<std::string>& certs,
77 const base::Time::Exploded& time, 93 const base::Time::Exploded& time,
78 scoped_ptr<CertVerificationContext>* context, 94 scoped_ptr<CertVerificationContext>* context,
95 CastDeviceCertPolicy* policy,
96 net::TrustStore trust_store) WARN_UNUSED_RESULT;
eroman 2016/04/18 18:28:40 const net::TrustStore&
ryanchung 2016/04/19 17:19:34 Done.
97
98 // Overloads VerifyDeviceCert(const std::vector<std::string>& certs,
eroman 2016/04/18 18:28:40 This comment could be simplified. // This is an o
ryanchung 2016/04/19 17:19:34 Done.
99 // const base::Time::Exploded& time,
100 // scoped_ptr<CertVerificationContext>* context,
101 // CastDeviceCertPolicy* policy,
102 // net::TrustStore trust_store)
103 // Uses the default TrustStore from CreateCastTrustStore()
104 bool VerifyDeviceCert(const std::vector<std::string>& certs,
105 const base::Time::Exploded& time,
106 scoped_ptr<CertVerificationContext>* context,
79 CastDeviceCertPolicy* policy) WARN_UNUSED_RESULT; 107 CastDeviceCertPolicy* policy) WARN_UNUSED_RESULT;
80 108
81 // Exposed only for unit-tests, not for use in production code. 109 // Exposed only for unit-tests, not for use in production code.
82 // Production code would get a context from VerifyDeviceCert(). 110 // Production code would get a context from VerifyDeviceCert().
83 // 111 //
84 // Constructs a VerificationContext that uses the provided public key. 112 // Constructs a VerificationContext that uses the provided public key.
85 // The common name will be hardcoded to some test value. 113 // The common name will be hardcoded to some test value.
86 scoped_ptr<CertVerificationContext> CertVerificationContextImplForTest( 114 scoped_ptr<CertVerificationContext> CertVerificationContextImplForTest(
87 const base::StringPiece& spki); 115 const base::StringPiece& spki);
88 116
89 117
90 } // namespace cast_crypto 118 } // namespace cast_crypto
91 } // namespace api 119 } // namespace api
92 } // namespace extensions 120 } // namespace extensions
93 121
94 #endif // EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_ 122 #endif // EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/common/cast/cast_cert_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698