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

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

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
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 #include "extensions/common/cast/cast_cert_validator.h" 5 #include "extensions/common/cast/cast_cert_validator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 0x07, 0x7F, 0xD7, 0xE9, 0x69, 0x1F, 0xAE, 0x3F, 0x4F, 0x63, 0x8A, 0x8F, 112 0x07, 0x7F, 0xD7, 0xE9, 0x69, 0x1F, 0xAE, 0x3F, 0x4F, 0x63, 0x8A, 0x8F,
113 0x89, 0xD6, 0xF2, 0x19, 0x78, 0x5C, 0x21, 0x8E, 0xB1, 0xB6, 0x57, 0xD8, 113 0x89, 0xD6, 0xF2, 0x19, 0x78, 0x5C, 0x21, 0x8E, 0xB1, 0xB6, 0x57, 0xD8,
114 0xC0, 0xE1, 0xEE, 0x7D, 0x6E, 0xDD, 0xF1, 0x3A, 0x0A, 0x6A, 0xF1, 0xBA, 114 0xC0, 0xE1, 0xEE, 0x7D, 0x6E, 0xDD, 0xF1, 0x3A, 0x0A, 0x6A, 0xF1, 0xBA,
115 0xFF, 0xF9, 0x83, 0x2F, 0xDC, 0xB5, 0xA4, 0x20, 0x17, 0x63, 0x36, 0xEF, 115 0xFF, 0xF9, 0x83, 0x2F, 0xDC, 0xB5, 0xA4, 0x20, 0x17, 0x63, 0x36, 0xEF,
116 0xC8, 0x62, 0x19, 0xCC, 0x56, 0xCE, 0xB2, 0xEA, 0x31, 0x89, 0x4B, 0x78, 116 0xC8, 0x62, 0x19, 0xCC, 0x56, 0xCE, 0xB2, 0xEA, 0x31, 0x89, 0x4B, 0x78,
117 0x58, 0xC1, 0xBF, 0x03, 0x13, 0x99, 0xE0, 0x12, 0xF2, 0x88, 0xAA, 0x9B, 117 0x58, 0xC1, 0xBF, 0x03, 0x13, 0x99, 0xE0, 0x12, 0xF2, 0x88, 0xAA, 0x9B,
118 0x94, 0xDA, 0xDD, 0x76, 0x79, 0x17, 0x1E, 0x34, 0xD1, 0x0A, 0xC4, 0x07, 118 0x94, 0xDA, 0xDD, 0x76, 0x79, 0x17, 0x1E, 0x34, 0xD1, 0x0A, 0xC4, 0x07,
119 0x45, 0x02, 0x03, 0x01, 0x00, 0x01, 119 0x45, 0x02, 0x03, 0x01, 0x00, 0x01,
120 }; 120 };
121 121
122 // Helper function that creates and initializes a TrustAnchor struct given
123 // arrays for the subject's DER and the SPKI's DER.
124 template <size_t SubjectSize, size_t SpkiSize>
125 net::TrustAnchor CreateTrustAnchor(const uint8_t (&subject)[SubjectSize],
126 const uint8_t (&spki)[SpkiSize]) {
127 net::TrustAnchor anchor;
128 anchor.name = std::string(subject, subject + SubjectSize);
129 anchor.spki = std::string(spki, spki + SpkiSize);
130 return anchor;
131 }
132
133 // Creates a trust store with the two Cast roots.
134 //
135 // TODO(eroman): The root certificates themselves are not included in the trust
136 // store (just their subject/SPKI). The problem with this approach is any
137 // restrictions encoded in their (like path length, or policy) are not known
138 // when verifying, and hence not enforced.
139 net::TrustStore CreateCastTrustStore() {
140 net::TrustStore store;
141 store.anchors.push_back(
142 CreateTrustAnchor(kEurekaRootCaSubjectDer, kEurekaRootCaSpkiDer));
143 store.anchors.push_back(
144 CreateTrustAnchor(kCastRootCaSubjectDer, kCastRootCaSpkiDer));
145 return store;
146 }
147
148 using ExtensionsMap = std::map<net::der::Input, net::ParsedExtension>; 122 using ExtensionsMap = std::map<net::der::Input, net::ParsedExtension>;
149 123
150 // Helper that looks up an extension by OID given a map of extensions. 124 // Helper that looks up an extension by OID given a map of extensions.
151 bool GetExtensionValue(const ExtensionsMap& extensions, 125 bool GetExtensionValue(const ExtensionsMap& extensions,
152 const net::der::Input& oid, 126 const net::der::Input& oid,
153 net::der::Input* value) { 127 net::der::Input* value) {
154 auto it = extensions.find(oid); 128 auto it = extensions.find(oid);
155 if (it == extensions.end()) 129 if (it == extensions.end())
156 return false; 130 return false;
157 *value = it->second.value; 131 *value = it->second.value;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 result.month = exploded.month; 303 result.month = exploded.month;
330 result.day = exploded.day_of_month; 304 result.day = exploded.day_of_month;
331 result.hours = exploded.hour; 305 result.hours = exploded.hour;
332 result.minutes = exploded.minute; 306 result.minutes = exploded.minute;
333 result.seconds = exploded.second; 307 result.seconds = exploded.second;
334 return result; 308 return result;
335 } 309 }
336 310
337 } // namespace 311 } // namespace
338 312
313 // TODO(eroman): The root certificates themselves are not included in the trust
314 // store (just their subject/SPKI). The problem with this approach is any
315 // restrictions encoded in their (like path length, or policy) are not known
316 // when verifying, and hence not enforced.
317 net::TrustStore CreateCastTrustStore() {
318 net::TrustStore store;
319 store.anchors.push_back(
320 CreateTrustAnchor(kEurekaRootCaSubjectDer, kEurekaRootCaSpkiDer));
321 store.anchors.push_back(
322 CreateTrustAnchor(kCastRootCaSubjectDer, kCastRootCaSpkiDer));
323 return store;
324 }
325
339 bool VerifyDeviceCert(const std::vector<std::string>& certs, 326 bool VerifyDeviceCert(const std::vector<std::string>& certs,
340 const base::Time::Exploded& time, 327 const base::Time::Exploded& time,
341 scoped_ptr<CertVerificationContext>* context, 328 scoped_ptr<CertVerificationContext>* context,
342 CastDeviceCertPolicy* policy) { 329 CastDeviceCertPolicy* policy) {
343 // Initialize the trust store used for verifying Cast 330 // Initialize the trust store used for verifying Cast
344 // device certificates. 331 // device certificates.
345 // 332 //
346 // Performance: This code is re-building a TrustStore object each 333 // Performance: This code is re-building a TrustStore object each
347 // time a chain needs to be verified rather than caching it, to 334 // time a chain needs to be verified rather than caching it, to
348 // avoid memory bloat. 335 // avoid memory bloat.
349 auto trust_store = CreateCastTrustStore(); 336 auto trust_store = CreateCastTrustStore();
337 return VerifyDeviceCert(certs, time, context, policy, trust_store);
338 }
350 339
340 bool VerifyDeviceCert(const std::vector<std::string>& certs,
341 const base::Time::Exploded& time,
342 scoped_ptr<CertVerificationContext>* context,
343 CastDeviceCertPolicy* policy,
344 net::TrustStore trust_store) {
351 // The underlying verification function expects a sequence of 345 // The underlying verification function expects a sequence of
352 // der::Input, so wrap the data in it (cheap). 346 // der::Input, so wrap the data in it (cheap).
353 std::vector<net::der::Input> input_chain; 347 std::vector<net::der::Input> input_chain;
354 for (const auto& cert : certs) 348 for (const auto& cert : certs)
355 input_chain.push_back(net::der::Input(&cert)); 349 input_chain.push_back(net::der::Input(&cert));
356 350
357 // Use a signature policy compatible with Cast's PKI. 351 // Use a signature policy compatible with Cast's PKI.
358 auto signature_policy = CreateCastSignaturePolicy(); 352 auto signature_policy = CreateCastSignaturePolicy();
359 353
360 // Do RFC 5280 compatible certificate verification using the two Cast 354 // Do RFC 5280 compatible certificate verification using the two Cast
(...skipping 13 matching lines...) Expand all
374 const base::StringPiece& spki) { 368 const base::StringPiece& spki) {
375 // Use a bogus CommonName, since this is just exposed for testing signature 369 // Use a bogus CommonName, since this is just exposed for testing signature
376 // verification by unittests. 370 // verification by unittests.
377 return make_scoped_ptr( 371 return make_scoped_ptr(
378 new CertVerificationContextImpl(net::der::Input(spki), "CommonName")); 372 new CertVerificationContextImpl(net::der::Input(spki), "CommonName"));
379 } 373 }
380 374
381 } // namespace cast_crypto 375 } // namespace cast_crypto
382 } // namespace api 376 } // namespace api
383 } // namespace extensions 377 } // namespace extensions
OLDNEW
« extensions/common/cast/cast_cert_validator.h ('K') | « extensions/common/cast/cast_cert_validator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698