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