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 // AuthenticationMethod represents an authentication algorithm and its | 5 // AuthenticationMethod represents an authentication algorithm and its |
6 // configuration. It knows how to parse and format authentication | 6 // configuration. It knows how to parse and format authentication |
7 // method names. | 7 // method names. |
8 // Currently the following methods are supported: | 8 // Currently the following methods are supported: |
9 // spake2_plain - SPAKE2 without hashing applied to the password. | 9 // spake2_plain - SPAKE2 without hashing applied to the password. |
10 // spake2_hmac - SPAKE2 with HMAC hashing of the password. | 10 // spake2_hmac - SPAKE2 with HMAC hashing of the password. |
11 | 11 |
12 #ifndef REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ | 12 #ifndef REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ |
13 #define REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ | 13 #define REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 namespace protocol { | 18 namespace protocol { |
19 | 19 |
20 class Authenticator; | 20 class Authenticator; |
21 | 21 |
22 class AuthenticationMethod { | 22 class AuthenticationMethod { |
23 public: | 23 public: |
24 enum MethodType { | |
25 INVALID, | |
26 SPAKE2, | |
27 THIRD_PARTY | |
28 }; | |
29 | |
24 enum HashFunction { | 30 enum HashFunction { |
Wez
2013/03/22 06:17:01
Given that HashFunction only applies to SPAKE2, wh
rmsousa
2013/03/22 21:19:05
There are some explicit uses of the hashfunction e
| |
25 NONE, | 31 NONE, |
26 HMAC_SHA256, | 32 HMAC_SHA256, |
27 }; | 33 }; |
28 | 34 |
29 // Constructors for various authentication methods. | 35 // Constructors for various authentication methods. |
30 static AuthenticationMethod Invalid(); | 36 static AuthenticationMethod Invalid(); |
31 static AuthenticationMethod Spake2(HashFunction hash_function); | 37 static AuthenticationMethod Spake2(HashFunction hash_function); |
38 static AuthenticationMethod ThirdParty(); | |
32 | 39 |
33 // Parses a string that defines an authentication method. Returns an | 40 // Parses a string that defines an authentication method. Returns an |
34 // invalid value if the string is invalid. | 41 // invalid value if the string is invalid. |
35 static AuthenticationMethod FromString(const std::string& value); | 42 static AuthenticationMethod FromString(const std::string& value); |
36 | 43 |
37 // Applies the specified hash function to |shared_secret| with the | 44 // Applies the specified hash function to |shared_secret| with the |
38 // specified |tag| as a key. | 45 // specified |tag| as a key. |
39 static std::string ApplyHashFunction(HashFunction hash_function, | 46 static std::string ApplyHashFunction(HashFunction hash_function, |
40 const std::string& tag, | 47 const std::string& tag, |
41 const std::string& shared_secret); | 48 const std::string& shared_secret); |
42 | 49 |
43 // Returns true | 50 bool is_valid() const { return method_type_ != INVALID; } |
44 bool is_valid() const { return !invalid_; } | 51 |
52 MethodType method_type() const { return method_type_; } | |
45 | 53 |
46 // Following methods are valid only when is_valid() returns true. | 54 // Following methods are valid only when is_valid() returns true. |
47 | 55 |
48 // Hash function applied to the shared secret on both ends. | 56 // Hash function applied to the shared secret on both ends. |
49 HashFunction hash_function() const; | 57 HashFunction hash_function() const; |
50 | 58 |
51 // Returns string representation of the value stored in this object. | 59 // Returns string representation of the value stored in this object. |
52 const std::string ToString() const; | 60 const std::string ToString() const; |
53 | 61 |
54 // Comparison operators so that std::find() can be used with | 62 // Comparison operators so that std::find() can be used with |
55 // collections of this class. | 63 // collections of this class. |
56 bool operator ==(const AuthenticationMethod& other) const; | 64 bool operator ==(const AuthenticationMethod& other) const; |
57 bool operator !=(const AuthenticationMethod& other) const { | 65 bool operator !=(const AuthenticationMethod& other) const { |
58 return !(*this == other); | 66 return !(*this == other); |
59 } | 67 } |
60 | 68 |
61 private: | 69 protected: |
62 AuthenticationMethod(); | 70 AuthenticationMethod(); |
63 explicit AuthenticationMethod(HashFunction hash_function); | 71 AuthenticationMethod(MethodType method_type, HashFunction hash_function); |
64 | 72 |
65 bool invalid_; | 73 MethodType method_type_; |
Sergey Ulanov
2013/03/22 05:58:43
nit: type_
rmsousa
2013/03/22 21:19:05
Done.
| |
66 HashFunction hash_function_; | 74 HashFunction hash_function_; |
67 }; | 75 }; |
68 | 76 |
69 // SharedSecretHash stores hash of a host secret paired with the type | 77 // SharedSecretHash stores hash of a host secret paired with the type |
70 // of the hashing function. | 78 // of the hashing function. |
71 struct SharedSecretHash { | 79 struct SharedSecretHash { |
72 AuthenticationMethod::HashFunction hash_function; | 80 AuthenticationMethod::HashFunction hash_function; |
73 std::string value; | 81 std::string value; |
74 | 82 |
75 // Parse string representation of a shared secret hash. The |as_string| | 83 // Parse string representation of a shared secret hash. The |as_string| |
76 // must be in form "<hash_function>:<hash_value_base64>". | 84 // must be in form "<hash_function>:<hash_value_base64>". |
77 bool Parse(const std::string& as_string); | 85 bool Parse(const std::string& as_string); |
78 }; | 86 }; |
79 | 87 |
80 } // namespace protocol | 88 } // namespace protocol |
81 } // namespace remoting | 89 } // namespace remoting |
82 | 90 |
83 #endif // REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ | 91 #endif // REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ |
OLD | NEW |