Chromium Code Reviews| 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 <vector> | |
| 9 | 10 |
| 10 namespace extensions { | 11 namespace extensions { |
| 11 namespace core_api { | 12 namespace core_api { |
| 12 namespace cast_channel { | 13 namespace cast_channel { |
| 13 | 14 |
| 15 class AuthResponse; | |
| 14 class CastMessage; | 16 class CastMessage; |
| 15 class DeviceAuthMessage; | 17 class DeviceAuthMessage; |
| 16 | 18 |
| 17 struct AuthResult { | 19 struct AuthResult { |
| 18 public: | 20 public: |
| 19 enum ErrorType { | 21 enum ErrorType { |
| 20 ERROR_NONE, | 22 ERROR_NONE, |
| 21 ERROR_PEER_CERT_EMPTY, | 23 ERROR_PEER_CERT_EMPTY, |
| 22 ERROR_WRONG_PAYLOAD_TYPE, | 24 ERROR_WRONG_PAYLOAD_TYPE, |
| 23 ERROR_NO_PAYLOAD, | 25 ERROR_NO_PAYLOAD, |
| 24 ERROR_PAYLOAD_PARSING_FAILED, | 26 ERROR_PAYLOAD_PARSING_FAILED, |
| 25 ERROR_MESSAGE_ERROR, | 27 ERROR_MESSAGE_ERROR, |
| 26 ERROR_NO_RESPONSE, | 28 ERROR_NO_RESPONSE, |
| 27 ERROR_FINGERPRINT_NOT_FOUND, | 29 ERROR_FINGERPRINT_NOT_FOUND, |
| 28 ERROR_NSS_CERT_PARSING_FAILED, | 30 ERROR_CERT_PARSING_FAILED, |
| 29 ERROR_NSS_CERT_NOT_SIGNED_BY_TRUSTED_CA, | 31 ERROR_CERT_NOT_SIGNED_BY_TRUSTED_CA, |
| 30 ERROR_NSS_CANNOT_EXTRACT_PUBLIC_KEY, | 32 ERROR_CANNOT_EXTRACT_PUBLIC_KEY, |
| 31 ERROR_NSS_SIGNED_BLOBS_MISMATCH | 33 ERROR_SIGNED_BLOBS_MISMATCH, |
| 34 ERROR_UNEXPECTED_AUTH_LIBRARY_RESULT, | |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 // Constructs a AuthResult that corresponds to success. | 37 // Constructs a AuthResult that corresponds to success. |
| 35 AuthResult(); | 38 AuthResult(); |
| 36 ~AuthResult(); | 39 ~AuthResult(); |
| 37 | 40 |
| 41 AuthResult(const AuthResult& rvalue); | |
| 42 | |
| 38 static AuthResult CreateWithParseError(const std::string& error_message, | 43 static AuthResult CreateWithParseError(const std::string& error_message, |
| 39 ErrorType error_type); | 44 ErrorType error_type); |
| 45 static AuthResult CreateWithOpenSSLErrors( | |
| 46 const std::string& error_message, | |
| 47 ErrorType error_type, | |
| 48 const std::vector<std::pair<std::string, int>>& openssl_errors); | |
| 40 static AuthResult CreateWithNSSError(const std::string& error_message, | 49 static AuthResult CreateWithNSSError(const std::string& error_message, |
| 41 ErrorType error_type, | 50 ErrorType error_type, |
| 42 int nss_error_code); | 51 int nss_error_code); |
| 43 | 52 |
| 44 bool success() const { return error_type == ERROR_NONE; } | 53 bool success() const { return error_type == ERROR_NONE; } |
| 45 | 54 |
| 46 std::string error_message; | 55 std::string error_message; |
| 47 ErrorType error_type; | 56 ErrorType error_type; |
| 48 int nss_error_code; | 57 int nss_error_code; |
| 49 | 58 |
| 59 // Vector of filename, line number pairs that comprise the stack | |
| 60 // of OpenSSL errors. | |
|
mark a. foltz
2014/10/31 22:29:25
So each entry is just part of a stack trace for a
Kevin M
2014/11/01 00:03:05
It's a stack of errors.
https://code.google.com/p/
davidben
2014/11/01 00:19:34
Including the error values is fine as long as it's
Kevin M
2014/11/03 18:31:46
Done in a separate Git branch.
| |
| 61 std::vector<std::pair<std::string, int>> openssl_errors; | |
|
mark a. foltz
2014/10/31 22:29:25
Slight preference for declaring a struct to hold t
Kevin M
2014/11/01 00:03:05
How's this?
| |
| 62 | |
| 50 private: | 63 private: |
| 51 AuthResult(const std::string& error_message, | 64 AuthResult(const std::string& error_message, |
| 52 ErrorType error_type, | 65 ErrorType error_type, |
| 53 int nss_error_code); | 66 int nss_error_code, |
| 67 const std::vector<std::pair<std::string, int>>& openssl_errors); | |
|
mark a. foltz
2014/10/31 22:29:25
Maybe this should be openssl_error_stack?
Kevin M
2014/11/01 00:03:05
Done.
| |
| 54 }; | 68 }; |
| 55 | 69 |
| 56 // Authenticates the given |challenge_reply|: | 70 // Authenticates the given |challenge_reply|: |
| 57 // 1. Signature contained in the reply is valid. | 71 // 1. Signature contained in the reply is valid. |
| 58 // 2. Certficate used to sign is rooted to a trusted CA. | 72 // 2. Certficate used to sign is rooted to a trusted CA. |
| 59 AuthResult AuthenticateChallengeReply(const CastMessage& challenge_reply, | 73 AuthResult AuthenticateChallengeReply( |
| 60 const std::string& peer_cert); | 74 const CastMessage& challenge_reply, |
| 75 const std::string& peer_cert); | |
| 61 | 76 |
| 62 // Parses a DeviceAuthMessage payload from a challenge reply. | 77 // Auth-library specific implementation of cryptographic signature |
| 63 // Returns an AuthResult to indicate success or failure. | 78 // verification routines. Verifies that |response| contains a |
| 64 AuthResult ParseAuthMessage(const CastMessage& challenge_reply, | 79 // valid signed form of |peer_cert|. |
| 65 DeviceAuthMessage* auth_message); | 80 AuthResult VerifyCredentials(const AuthResponse& response, |
| 81 const std::string& peer_cert); | |
| 66 | 82 |
| 67 } // namespace cast_channel | 83 } // namespace cast_channel |
| 68 } // namespace core_api | 84 } // namespace core_api |
| 69 } // namespace extensions | 85 } // namespace extensions |
| 70 | 86 |
| 71 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ | 87 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_AUTH_UTIL_H_ |
| OLD | NEW |