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

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

Issue 792353002: Refactoring of Cast-related crypto code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes in response to comments by mfoltz Created 5 years, 11 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 <string>
9 #include <vector>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_piece.h"
13
14 namespace extensions {
15 namespace core_api {
16 namespace cast_crypto {
17
18 // Status of a certificate or certificate verification operation.
19 struct VerificationResult {
20
21 // Mapped to extensions::core_api::cast_channel::AuthResult::ErrorType in
22 // cast_auto_util.cc. Update the mapping code when modifying this enum.
23 enum ErrorType {
24 // Verification has succeeded.
25 ERROR_NONE = 0,
26 // There was a problem with the certificate, such as invalid or corrupt
27 // certificate data or invalid issuing certificate signature.
28 ERROR_CERT_INVALID,
29 // Certificate may be valid, but not trusted in this context.
30 ERROR_CERT_UNTRUSTED,
31 // Signature verification failed
32 ERROR_SIGNATURE_INVALID,
33 // Catch-all for internal errors that are not covered by the other error
34 // types.
35 ERROR_INTERNAL
36 };
37
38 // Constructs a VerificationResult that corresponds to success.
39 VerificationResult();
40
41 // Construct error-related objects
42 VerificationResult(const std::string& error_message, ErrorType error_type);
43 VerificationResult(const std::string& error_message,
44 ErrorType error_type,
45 int error_code);
46
47 bool Success() const { return error_type == ERROR_NONE; }
48 bool Failure() const { return error_type != ERROR_NONE; }
49
50 // Generates a string representation of this object for logging.
51 std::string GetLogString() const;
52
53 ErrorType error_type;
54 // Human-readable description of the problem if error_type != ERROR_NONE
55 std::string error_message;
56 // May contain the underlying crypto library error code.
57 int library_error_code;
58 };
59
60 // An object of this type is returned by the VerifyCert function, and can be
61 // used for additional certificate-related operations, using the verified
62 // certificate.
63 class CertVerificationContext {
64 public:
65 CertVerificationContext() {}
66 virtual ~CertVerificationContext() {}
67
68 // Use the public key from the verified certificate to verify a
69 // sha1WithRSAEncryption |signature| over arbitrary |data|. Both |signature|
70 // and |data| hold raw binary data.
71 virtual VerificationResult VerifySignatureOverData(
72 const base::StringPiece& signature,
73 const base::StringPiece& data) const = 0;
74
75 // Retrieve the Common Name attribute of the subject's distinguished name from
76 // the verified certificate, if present. Returns an empty string if no Common
77 // Name is found.
78 virtual std::string GetCommonName() const = 0;
79
80 private:
81 DISALLOW_COPY_AND_ASSIGN(CertVerificationContext);
82 };
83
84 // Verify a cast device certificate, using optional intermediate certificate
85 // authority certificates. |context| will be populated with an instance of
86 // CertVerificationContext, which allows to perform additional verification
87 // steps as required.
88 VerificationResult VerifyDeviceCert(
mef 2015/01/05 17:24:08 Is there a reason why VerifyDeviceCert shouldn't b
sheretov 2015/01/05 22:43:03 I experimented with that approach and ended up wit
89 const base::StringPiece& device_cert,
90 const std::vector<std::string>& ica_certs,
91 scoped_ptr<CertVerificationContext>* context);
92
93 } // namespace cast_crypto
94 } // namespace core_api
95 } // namespace extensions
96
97 #endif // EXTENSIONS_COMMON_CAST_CAST_CERT_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698