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

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

Issue 1924323002: Move Cast certificate verification code from extensions to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified OWNERS files Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
6 #define EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h"
16
17 namespace extensions {
18 namespace api {
19 namespace cast_crypto {
20
21 // Describes the policy for a Device certificate.
22 enum class CastDeviceCertPolicy {
23 // The device certificate is unrestricted.
24 NONE,
25
26 // The device certificate is for an audio-only device.
27 AUDIO_ONLY,
28 };
29
30 // An object of this type is returned by the VerifyDeviceCert function, and can
31 // be used for additional certificate-related operations, using the verified
32 // certificate.
33 class CertVerificationContext {
34 public:
35 CertVerificationContext() {}
36 virtual ~CertVerificationContext() {}
37
38 // Use the public key from the verified certificate to verify a
39 // sha1WithRSAEncryption |signature| over arbitrary |data|. Both |signature|
40 // and |data| hold raw binary data. Returns true if the signature was
41 // correct.
42 virtual bool VerifySignatureOverData(const base::StringPiece& signature,
43 const base::StringPiece& data) const = 0;
44
45 // 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 // Name is found.
48 virtual std::string GetCommonName() const = 0;
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(CertVerificationContext);
52 };
53
54 // Verifies a cast device certficate given a chain of DER-encoded certificates.
55 //
56 // Inputs:
57 //
58 // * |certs| is a chain of DER-encoded certificates:
59 // * |certs[0]| is the target certificate (i.e. the device certificate)
60 // * |certs[i]| is the certificate that issued certs[i-1]
61 // * |certs.back()| must be signed by a trust anchor
62 //
63 // * |time| is the UTC time to use for determining if the certificate
64 // is expired.
65 //
66 // Outputs:
67 //
68 // Returns true on success, false on failure. On success the output
69 // parameters are filled with more details:
70 //
71 // * |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
73 // properties from the device certificate (Common Name).
74 // * |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?)
76 bool VerifyDeviceCert(const std::vector<std::string>& certs,
77 const base::Time::Exploded& time,
78 std::unique_ptr<CertVerificationContext>* context,
79 CastDeviceCertPolicy* policy) WARN_UNUSED_RESULT;
80
81 // Exposed only for unit-tests, not for use in production code.
82 // Production code would get a context from VerifyDeviceCert().
83 //
84 // Constructs a VerificationContext that uses the provided public key.
85 // The common name will be hardcoded to some test value.
86 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest(
87 const base::StringPiece& spki);
88
89 // Exposed only for testing, not for use in production code.
90 //
91 // Injects trusted root certificates into the CastTrustStore.
92 // |data| must remain valid and not be mutated throughout the lifetime of
93 // the program.
94 // Warning: Using this function concurrently with VerifyDeviceCert()
95 // is not thread safe.
96 bool AddTrustAnchorForTest(const uint8_t* data,
97 size_t length) WARN_UNUSED_RESULT;
98
99 } // namespace cast_crypto
100 } // namespace api
101 } // namespace extensions
102
103 #endif // EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_auth_util_unittest.cc ('k') | extensions/common/cast/cast_cert_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698