OLD | NEW |
(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_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
| 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/time/time.h" |
| 12 |
| 13 namespace cast_certificate { |
| 14 enum class CRLPolicy; |
| 15 } |
| 16 |
| 17 namespace net { |
| 18 class X509Certificate; |
| 19 class TrustStore; |
| 20 } // namespace net |
| 21 |
| 22 namespace extensions { |
| 23 namespace api { |
| 24 namespace cast_channel { |
| 25 |
| 26 class AuthResponse; |
| 27 class CastMessage; |
| 28 |
| 29 struct AuthResult { |
| 30 public: |
| 31 enum ErrorType { |
| 32 ERROR_NONE, |
| 33 ERROR_PEER_CERT_EMPTY, |
| 34 ERROR_WRONG_PAYLOAD_TYPE, |
| 35 ERROR_NO_PAYLOAD, |
| 36 ERROR_PAYLOAD_PARSING_FAILED, |
| 37 ERROR_MESSAGE_ERROR, |
| 38 ERROR_NO_RESPONSE, |
| 39 ERROR_FINGERPRINT_NOT_FOUND, |
| 40 ERROR_CERT_PARSING_FAILED, |
| 41 ERROR_CERT_NOT_SIGNED_BY_TRUSTED_CA, |
| 42 ERROR_CANNOT_EXTRACT_PUBLIC_KEY, |
| 43 ERROR_SIGNED_BLOBS_MISMATCH, |
| 44 ERROR_TLS_CERT_VALIDITY_PERIOD_TOO_LONG, |
| 45 ERROR_TLS_CERT_VALID_START_DATE_IN_FUTURE, |
| 46 ERROR_TLS_CERT_EXPIRED, |
| 47 ERROR_CRL_INVALID, |
| 48 ERROR_CERT_REVOKED, |
| 49 ERROR_SENDER_NONCE_MISMATCH, |
| 50 }; |
| 51 |
| 52 enum PolicyType { POLICY_NONE = 0, POLICY_AUDIO_ONLY = 1 << 0 }; |
| 53 |
| 54 // Constructs a AuthResult that corresponds to success. |
| 55 AuthResult(); |
| 56 |
| 57 AuthResult(const std::string& error_message, ErrorType error_type); |
| 58 |
| 59 ~AuthResult(); |
| 60 |
| 61 static AuthResult CreateWithParseError(const std::string& error_message, |
| 62 ErrorType error_type); |
| 63 |
| 64 bool success() const { return error_type == ERROR_NONE; } |
| 65 |
| 66 std::string error_message; |
| 67 ErrorType error_type; |
| 68 unsigned int channel_policies; |
| 69 }; |
| 70 |
| 71 class AuthContext { |
| 72 public: |
| 73 ~AuthContext(); |
| 74 |
| 75 // Get an auth challenge context. |
| 76 // The same context must be used in the challenge and reply. |
| 77 static AuthContext Create(); |
| 78 |
| 79 // Verifies the nonce received in the response is equivalent to the one sent. |
| 80 // Returns success if |nonce_response| matches nonce_ |
| 81 AuthResult VerifySenderNonce(const std::string& nonce_response) const; |
| 82 |
| 83 // The nonce challenge. |
| 84 const std::string& nonce() const { return nonce_; } |
| 85 |
| 86 private: |
| 87 explicit AuthContext(const std::string& nonce); |
| 88 |
| 89 const std::string nonce_; |
| 90 }; |
| 91 |
| 92 // Authenticates the given |challenge_reply|: |
| 93 // 1. Signature contained in the reply is valid. |
| 94 // 2. Certficate used to sign is rooted to a trusted CA. |
| 95 AuthResult AuthenticateChallengeReply(const CastMessage& challenge_reply, |
| 96 const net::X509Certificate& peer_cert, |
| 97 const AuthContext& auth_context); |
| 98 |
| 99 // Performs a quick check of the TLS certificate for time validity requirements. |
| 100 AuthResult VerifyTLSCertificate(const net::X509Certificate& peer_cert, |
| 101 std::string* peer_cert_der, |
| 102 const base::Time& verification_time); |
| 103 |
| 104 // Auth-library specific implementation of cryptographic signature |
| 105 // verification routines. Verifies that |response| contains a |
| 106 // valid signature of |signature_input|. |
| 107 AuthResult VerifyCredentials(const AuthResponse& response, |
| 108 const std::string& signature_input); |
| 109 |
| 110 // Exposed for testing only. |
| 111 // |
| 112 // Overloaded version of VerifyCredentials that allows modifying |
| 113 // the crl policy, trust stores, and verification times. |
| 114 AuthResult VerifyCredentialsForTest( |
| 115 const AuthResponse& response, |
| 116 const std::string& signature_input, |
| 117 const cast_certificate::CRLPolicy& crl_policy, |
| 118 net::TrustStore* cast_trust_store, |
| 119 net::TrustStore* crl_trust_store, |
| 120 const base::Time& verification_time); |
| 121 |
| 122 } // namespace cast_channel |
| 123 } // namespace api |
| 124 } // namespace extensions |
| 125 |
| 126 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
OLD | NEW |