OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "remoting/protocol/authentication_method.h" | 5 #include "remoting/protocol/authentication_method.h" |
6 | 6 |
| 7 #include "base/base64.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "crypto/hmac.h" | 9 #include "crypto/hmac.h" |
9 #include "remoting/protocol/auth_util.h" | 10 #include "remoting/protocol/auth_util.h" |
10 #include "remoting/protocol/v1_authenticator.h" | 11 #include "remoting/protocol/v1_authenticator.h" |
11 #include "remoting/protocol/v2_authenticator.h" | 12 #include "remoting/protocol/v2_authenticator.h" |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 namespace protocol { | 15 namespace protocol { |
15 | 16 |
16 // static | 17 // static |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 bool AuthenticationMethod::operator ==( | 97 bool AuthenticationMethod::operator ==( |
97 const AuthenticationMethod& other) const { | 98 const AuthenticationMethod& other) const { |
98 if (!is_valid()) | 99 if (!is_valid()) |
99 return !other.is_valid(); | 100 return !other.is_valid(); |
100 if (!other.is_valid()) | 101 if (!other.is_valid()) |
101 return false; | 102 return false; |
102 return hash_function_ == other.hash_function_; | 103 return hash_function_ == other.hash_function_; |
103 } | 104 } |
104 | 105 |
| 106 bool SharedSecretHash::Parse(const std::string& as_string) { |
| 107 size_t separator = as_string.find(':'); |
| 108 if (separator == std::string::npos) |
| 109 return false; |
| 110 |
| 111 std::string function_name = as_string.substr(0, separator); |
| 112 if (function_name == "plain") { |
| 113 hash_function = AuthenticationMethod::NONE; |
| 114 } else if (function_name == "hmac") { |
| 115 hash_function = AuthenticationMethod::HMAC_SHA256; |
| 116 } else { |
| 117 return false; |
| 118 } |
| 119 |
| 120 if (!base::Base64Decode(as_string.substr(separator + 1), &value)) { |
| 121 return false; |
| 122 } |
| 123 |
| 124 return true; |
| 125 } |
| 126 |
105 } // namespace protocol | 127 } // namespace protocol |
106 } // namespace remoting | 128 } // namespace remoting |
OLD | NEW |