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 <string> | 8 #include <string> |
| 9 #include "crypto/scoped_nss_types.h" |
| 10 #include "extensions/common/api/cast_channel/authority_keys.pb.h" |
| 11 #include "net/base/hash_value.h" |
9 | 12 |
10 namespace extensions { | 13 namespace extensions { |
11 namespace core_api { | 14 namespace core_api { |
12 namespace cast_channel { | 15 namespace cast_channel { |
13 | 16 |
14 class CastMessage; | 17 class CastMessage; |
15 | 18 |
16 struct AuthResult { | 19 struct AuthResult { |
17 public: | 20 public: |
18 enum ErrorType { | 21 enum ErrorType { |
(...skipping 26 matching lines...) Expand all Loading... |
45 std::string error_message; | 48 std::string error_message; |
46 ErrorType error_type; | 49 ErrorType error_type; |
47 int nss_error_code; | 50 int nss_error_code; |
48 | 51 |
49 private: | 52 private: |
50 AuthResult(const std::string& error_message, | 53 AuthResult(const std::string& error_message, |
51 ErrorType error_type, | 54 ErrorType error_type, |
52 int nss_error_code); | 55 int nss_error_code); |
53 }; | 56 }; |
54 | 57 |
| 58 // Helper class for intermediate certificate authority validation. |
| 59 class AuthorityKeysStore { |
| 60 public: |
| 61 AuthorityKeysStore(); |
| 62 ~AuthorityKeysStore(); |
| 63 |
| 64 // Returns the public key of the ICA whose fingerprint matches |fingerprint|. |
| 65 // Returns NULL, if no such ICA is found. |
| 66 const SECItem* GetICAPublicKeyFromFingerprint( |
| 67 const net::SHA256HashValue& fingerprint); |
| 68 |
| 69 // Returns the public key of the first ICA in the list. |
| 70 // Returns NULL if the authority keys store is empty. |
| 71 const SECItem* GetDefaultICAPublicKey(); |
| 72 |
| 73 // Loads authority keys from a serialized protobuf. |
| 74 bool Load(std::string& keys); |
| 75 |
| 76 private: |
| 77 // Info for trusted ICA certs. |
| 78 struct ICACertInfo { |
| 79 const net::SHA256HashValue* fingerprint; |
| 80 SECItem public_key; |
| 81 }; |
| 82 |
| 83 // The list of trusted certificate authorities, this points to either |
| 84 // hard-coded constant data or to the data in the de-serialized protobuf. |
| 85 std::vector<ICACertInfo> certificate_authorities_; |
| 86 |
| 87 // Holds hard-coded constant ICA data. |
| 88 static const ICACertInfo kAllowedICAs[]; |
| 89 |
| 90 // Trusted certificate authorities data passed from the extension. |
| 91 proto::AuthorityKeys authority_keys_; |
| 92 }; |
| 93 |
55 // Authenticates the given |challenge_reply|: | 94 // Authenticates the given |challenge_reply|: |
56 // 1. Signature contained in the reply is valid. | 95 // 1. Signature contained in the reply is valid. |
57 // 2. Certficate used to sign is rooted to a trusted CA. | 96 // 2. Certficate used to sign is rooted to a trusted CA. |
58 AuthResult AuthenticateChallengeReply(const CastMessage& challenge_reply, | 97 AuthResult AuthenticateChallengeReply(const CastMessage& challenge_reply, |
59 const std::string& peer_cert); | 98 const std::string& peer_cert); |
60 | 99 |
| 100 // Sets trusted certificate authorities. |
| 101 bool SetTrustedCertificateAuthorities(const std::string& keys, |
| 102 const std::string& signature); |
| 103 |
61 } // namespace cast_channel | 104 } // namespace cast_channel |
62 } // namespace core_api | 105 } // namespace core_api |
63 } // namespace extensions | 106 } // namespace extensions |
64 | 107 |
65 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ | 108 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
OLD | NEW |