| OLD | NEW |
| 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 COMPONENTS_CAST_CERTIFICATE_CAST_CERT_VALIDATOR_H_ | 5 #ifndef COMPONENTS_CAST_CERTIFICATE_CAST_CERT_VALIDATOR_H_ |
| 6 #define COMPONENTS_CAST_CERTIFICATE_CAST_CERT_VALIDATOR_H_ | 6 #define COMPONENTS_CAST_CERTIFICATE_CAST_CERT_VALIDATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.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 | 16 |
| 17 namespace cast_certificate { | 17 namespace cast_certificate { |
| 18 | 18 |
| 19 class CastCRL; | |
| 20 | |
| 21 // Describes the policy for a Device certificate. | 19 // Describes the policy for a Device certificate. |
| 22 enum class CastDeviceCertPolicy { | 20 enum class CastDeviceCertPolicy { |
| 23 // The device certificate is unrestricted. | 21 // The device certificate is unrestricted. |
| 24 NONE, | 22 NONE, |
| 25 | 23 |
| 26 // The device certificate is for an audio-only device. | 24 // The device certificate is for an audio-only device. |
| 27 AUDIO_ONLY, | 25 AUDIO_ONLY, |
| 28 }; | 26 }; |
| 29 | 27 |
| 30 enum class CRLPolicy { | |
| 31 // Revocation is only checked if a CRL is provided. | |
| 32 CRL_OPTIONAL, | |
| 33 | |
| 34 // Revocation is always checked. A missing CRL results in failure. | |
| 35 CRL_REQUIRED, | |
| 36 }; | |
| 37 | |
| 38 // An object of this type is returned by the VerifyDeviceCert function, and can | 28 // An object of this type is returned by the VerifyDeviceCert function, and can |
| 39 // be used for additional certificate-related operations, using the verified | 29 // be used for additional certificate-related operations, using the verified |
| 40 // certificate. | 30 // certificate. |
| 41 class CertVerificationContext { | 31 class CertVerificationContext { |
| 42 public: | 32 public: |
| 43 CertVerificationContext() {} | 33 CertVerificationContext() {} |
| 44 virtual ~CertVerificationContext() {} | 34 virtual ~CertVerificationContext() {} |
| 45 | 35 |
| 46 // Use the public key from the verified certificate to verify a | 36 // Use the public key from the verified certificate to verify a |
| 47 // sha1WithRSAEncryption |signature| over arbitrary |data|. Both |signature| | 37 // sha1WithRSAEncryption |signature| over arbitrary |data|. Both |signature| |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 | 51 |
| 62 // Verifies a cast device certficate given a chain of DER-encoded certificates. | 52 // Verifies a cast device certficate given a chain of DER-encoded certificates. |
| 63 // | 53 // |
| 64 // Inputs: | 54 // Inputs: |
| 65 // | 55 // |
| 66 // * |certs| is a chain of DER-encoded certificates: | 56 // * |certs| is a chain of DER-encoded certificates: |
| 67 // * |certs[0]| is the target certificate (i.e. the device certificate). | 57 // * |certs[0]| is the target certificate (i.e. the device certificate). |
| 68 // * |certs[1..n-1]| are intermediates certificates to use in path building. | 58 // * |certs[1..n-1]| are intermediates certificates to use in path building. |
| 69 // Their ordering does not matter. | 59 // Their ordering does not matter. |
| 70 // | 60 // |
| 71 // * |time| is the unix timestamp to use for determining if the certificate | 61 // * |time| is the UTC time to use for determining if the certificate |
| 72 // is expired. | 62 // is expired. |
| 73 // | 63 // |
| 74 // * |crl| is the CRL to check for certificate revocation status. | |
| 75 // If this is a nullptr, then revocation checking is currently disabled. | |
| 76 // | |
| 77 // * |crl_options| is for choosing how to handle the absence of a CRL. | |
| 78 // If crl_required is set to true, then an empty |crl| input would result | |
| 79 // in a failed verification. Otherwise, |crl| is ignored if it is absent. | |
| 80 // | |
| 81 // Outputs: | 64 // Outputs: |
| 82 // | 65 // |
| 83 // Returns true on success, false on failure. On success the output | 66 // Returns true on success, false on failure. On success the output |
| 84 // parameters are filled with more details: | 67 // parameters are filled with more details: |
| 85 // | 68 // |
| 86 // * |context| is filled with an object that can be used to verify signatures | 69 // * |context| is filled with an object that can be used to verify signatures |
| 87 // using the device certificate's public key, as well as to extract other | 70 // using the device certificate's public key, as well as to extract other |
| 88 // properties from the device certificate (Common Name). | 71 // properties from the device certificate (Common Name). |
| 89 // * |policy| is filled with an indication of the device certificate's policy | 72 // * |policy| is filled with an indication of the device certificate's policy |
| 90 // (i.e. is it for audio-only devices or is it unrestricted?) | 73 // (i.e. is it for audio-only devices or is it unrestricted?) |
| 91 bool VerifyDeviceCert(const std::vector<std::string>& certs, | 74 bool VerifyDeviceCert(const std::vector<std::string>& certs, |
| 92 const base::Time& time, | 75 const base::Time::Exploded& time, |
| 93 std::unique_ptr<CertVerificationContext>* context, | 76 std::unique_ptr<CertVerificationContext>* context, |
| 94 CastDeviceCertPolicy* policy, | 77 CastDeviceCertPolicy* policy) WARN_UNUSED_RESULT; |
| 95 const CastCRL* crl, | |
| 96 CRLPolicy crl_policy) WARN_UNUSED_RESULT; | |
| 97 | 78 |
| 98 // Exposed only for unit-tests, not for use in production code. | 79 // Exposed only for unit-tests, not for use in production code. |
| 99 // Production code would get a context from VerifyDeviceCert(). | 80 // Production code would get a context from VerifyDeviceCert(). |
| 100 // | 81 // |
| 101 // Constructs a VerificationContext that uses the provided public key. | 82 // Constructs a VerificationContext that uses the provided public key. |
| 102 // The common name will be hardcoded to some test value. | 83 // The common name will be hardcoded to some test value. |
| 103 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest( | 84 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest( |
| 104 const base::StringPiece& spki); | 85 const base::StringPiece& spki); |
| 105 | 86 |
| 106 // Exposed only for testing, not for use in production code. | 87 // Exposed only for testing, not for use in production code. |
| 107 // | 88 // |
| 108 // Replaces trusted root certificates in the CastTrustStore. | 89 // Injects trusted root certificates into the CastTrustStore. |
| 109 // Returns true if successful, false if nothing is changed. | 90 // |data| must remain valid and not be mutated throughout the lifetime of |
| 110 bool SetTrustAnchorForTest(const std::string& cert) WARN_UNUSED_RESULT; | 91 // the program. |
| 92 // Warning: Using this function concurrently with VerifyDeviceCert() |
| 93 // is not thread safe. |
| 94 bool AddTrustAnchorForTest(const uint8_t* data, |
| 95 size_t length) WARN_UNUSED_RESULT; |
| 111 | 96 |
| 112 } // namespace cast_certificate | 97 } // namespace cast_certificate |
| 113 | 98 |
| 114 #endif // COMPONENTS_CAST_CERTIFICATE_CAST_CERT_VALIDATOR_H_ | 99 #endif // COMPONENTS_CAST_CERTIFICATE_CAST_CERT_VALIDATOR_H_ |
| OLD | NEW |