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 EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ | 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
9 | 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_piece.h" |
| 13 #include "net/base/hash_value.h" |
| 14 |
10 namespace extensions { | 15 namespace extensions { |
11 namespace core_api { | 16 namespace core_api { |
12 namespace cast_channel { | 17 namespace cast_channel { |
13 | 18 |
14 class CastMessage; | 19 class CastMessage; |
15 | 20 |
16 struct AuthResult { | 21 struct AuthResult { |
17 public: | 22 public: |
18 enum ErrorType { | 23 enum ErrorType { |
19 ERROR_NONE, | 24 ERROR_NONE, |
(...skipping 25 matching lines...) Expand all Loading... |
45 std::string error_message; | 50 std::string error_message; |
46 ErrorType error_type; | 51 ErrorType error_type; |
47 int nss_error_code; | 52 int nss_error_code; |
48 | 53 |
49 private: | 54 private: |
50 AuthResult(const std::string& error_message, | 55 AuthResult(const std::string& error_message, |
51 ErrorType error_type, | 56 ErrorType error_type, |
52 int nss_error_code); | 57 int nss_error_code); |
53 }; | 58 }; |
54 | 59 |
| 60 typedef std::map<net::SHA256HashValue, |
| 61 base::StringPiece, |
| 62 net::SHA256HashValueLessThan> AuthorityKeysMap; |
| 63 |
| 64 namespace proto { |
| 65 |
| 66 // Forward declaration to avoid including generated protobuf header. |
| 67 class AuthorityKeys; |
| 68 |
| 69 } // namespace proto |
| 70 |
| 71 // AuthorityKeyStore is a helper class that is used to store and manipulate |
| 72 // intermediate CAs (ICAs) information used to authenticate cast devices. |
| 73 // A static list of ICAs is hardcoded and may optionally be replaced during |
| 74 // runtime by an extension supplying a protobuf of ICAs information signed with |
| 75 // known key. |
| 76 class AuthorityKeyStore { |
| 77 public: |
| 78 AuthorityKeyStore(); |
| 79 ~AuthorityKeyStore(); |
| 80 |
| 81 // Returns the public key of the ICA whose fingerprint matches |fingerprint|. |
| 82 // Returns an empty StringPiece if no such ICA is found. |
| 83 // Note: the returned StringPiece is invalidated if Load() is called. |
| 84 base::StringPiece GetICAPublicKeyFromFingerprint( |
| 85 const net::SHA256HashValue& fingerprint); |
| 86 |
| 87 // Returns the public key of the default / original cast ICA. |
| 88 // Returns an empty StringPiece if the default cast ICA is not found. |
| 89 // Note: the returned StringPiece is invalidated if Load() is called. |
| 90 base::StringPiece GetDefaultICAPublicKey(); |
| 91 |
| 92 // Replaces stored authority keys with the keys loaded from a serialized |
| 93 // protobuf. |
| 94 bool Load(const std::string& keys); |
| 95 |
| 96 private: |
| 97 // The map of trusted certificate authorities - fingerprints to public keys. |
| 98 AuthorityKeysMap certificate_authorities_; |
| 99 |
| 100 // Trusted certificate authorities data passed from the extension. |
| 101 scoped_ptr<proto::AuthorityKeys> authority_keys_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(AuthorityKeyStore); |
| 104 }; |
| 105 |
55 // Authenticates the given |challenge_reply|: | 106 // Authenticates the given |challenge_reply|: |
56 // 1. Signature contained in the reply is valid. | 107 // 1. Signature contained in the reply is valid. |
57 // 2. Certficate used to sign is rooted to a trusted CA. | 108 // 2. Certficate used to sign is rooted to a trusted CA. |
58 AuthResult AuthenticateChallengeReply(const CastMessage& challenge_reply, | 109 AuthResult AuthenticateChallengeReply(const CastMessage& challenge_reply, |
59 const std::string& peer_cert); | 110 const std::string& peer_cert); |
60 | 111 |
| 112 // Sets trusted certificate authorities. |
| 113 bool SetTrustedCertificateAuthorities(const std::string& keys, |
| 114 const std::string& signature); |
| 115 |
61 } // namespace cast_channel | 116 } // namespace cast_channel |
62 } // namespace core_api | 117 } // namespace core_api |
63 } // namespace extensions | 118 } // namespace extensions |
64 | 119 |
65 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ | 120 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
OLD | NEW |