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.
5 #ifndef EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
6 #define EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_piece.h"
14 namespace extensions
{
16 namespace cast_crypto
{
18 // Status of a certificate or certificate verification operation.
19 struct VerificationResult
{
20 // Mapped to extensions::api::cast_channel::AuthResult::ErrorType in
21 // cast_auto_util.cc. Update the mapping code when modifying this enum.
23 // Verification has succeeded.
25 // There was a problem with the certificate, such as invalid or corrupt
26 // certificate data or invalid issuing certificate signature.
28 // Certificate may be valid, but not trusted in this context.
30 // Signature verification failed
31 ERROR_SIGNATURE_INVALID
,
32 // Catch-all for internal errors that are not covered by the other error
37 // Constructs a VerificationResult that corresponds to success.
40 // Construct error-related objects
41 VerificationResult(const std::string
& error_message
, ErrorType error_type
);
42 VerificationResult(const std::string
& error_message
,
46 bool Success() const { return error_type
== ERROR_NONE
; }
47 bool Failure() const { return error_type
!= ERROR_NONE
; }
49 // Generates a string representation of this object for logging.
50 std::string
GetLogString() const;
53 // Human-readable description of the problem if error_type != ERROR_NONE
54 std::string error_message
;
55 // May contain the underlying crypto library error code.
56 int library_error_code
;
59 // An object of this type is returned by the VerifyCert function, and can be
60 // used for additional certificate-related operations, using the verified
62 class CertVerificationContext
{
64 CertVerificationContext() {}
65 virtual ~CertVerificationContext() {}
67 // Use the public key from the verified certificate to verify a
68 // sha1WithRSAEncryption |signature| over arbitrary |data|. Both |signature|
69 // and |data| hold raw binary data.
70 virtual VerificationResult
VerifySignatureOverData(
71 const base::StringPiece
& signature
,
72 const base::StringPiece
& data
) const = 0;
74 // Retrieve the Common Name attribute of the subject's distinguished name from
75 // the verified certificate, if present. Returns an empty string if no Common
77 virtual std::string
GetCommonName() const = 0;
80 DISALLOW_COPY_AND_ASSIGN(CertVerificationContext
);
83 // Verify a cast device certificate, using optional intermediate certificate
84 // authority certificates. |context| will be populated with an instance of
85 // CertVerificationContext, which allows to perform additional verification
87 VerificationResult
VerifyDeviceCert(
88 const base::StringPiece
& device_cert
,
89 const std::vector
<std::string
>& ica_certs
,
90 scoped_ptr
<CertVerificationContext
>* context
);
92 // Sets trusted certificate authorities. Only exposed for tests.
93 bool SetTrustedCertificateAuthoritiesForTest(const std::string
& keys
,
94 const std::string
& signature
);
96 } // namespace cast_crypto
98 } // namespace extensions
100 #endif // EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_