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. |
(...skipping 11 matching lines...) Expand all Loading... | |
22 class AuthenticationMethod { | 22 class AuthenticationMethod { |
23 public: | 23 public: |
24 enum HashFunction { | 24 enum HashFunction { |
25 NONE, | 25 NONE, |
26 HMAC_SHA256, | 26 HMAC_SHA256, |
27 }; | 27 }; |
28 | 28 |
29 // Constructors for various authentication methods. | 29 // Constructors for various authentication methods. |
30 static AuthenticationMethod Invalid(); | 30 static AuthenticationMethod Invalid(); |
31 static AuthenticationMethod Spake2(HashFunction hash_function); | 31 static AuthenticationMethod Spake2(HashFunction hash_function); |
32 static AuthenticationMethod ThirdParty(); | |
32 | 33 |
33 // Parses a string that defines an authentication method. Returns an | 34 // Parses a string that defines an authentication method. Returns an |
34 // invalid value if the string is invalid. | 35 // invalid value if the string is invalid. |
35 static AuthenticationMethod FromString(const std::string& value); | 36 static AuthenticationMethod FromString(const std::string& value); |
36 | 37 |
37 // Applies the specified hash function to |shared_secret| with the | 38 // Applies the specified hash function to |shared_secret| with the |
38 // specified |tag| as a key. | 39 // specified |tag| as a key. |
39 static std::string ApplyHashFunction(HashFunction hash_function, | 40 static std::string ApplyHashFunction(HashFunction hash_function, |
40 const std::string& tag, | 41 const std::string& tag, |
41 const std::string& shared_secret); | 42 const std::string& shared_secret); |
42 | 43 |
43 // Returns true | 44 // Returns true |
44 bool is_valid() const { return !invalid_; } | 45 bool is_valid() const { return !invalid_; } |
45 | 46 |
47 // Returns true | |
48 bool requires_token() const { return requires_token_; } | |
49 | |
46 // Following methods are valid only when is_valid() returns true. | 50 // Following methods are valid only when is_valid() returns true. |
47 | 51 |
48 // Hash function applied to the shared secret on both ends. | 52 // Hash function applied to the shared secret on both ends. |
49 HashFunction hash_function() const; | 53 HashFunction hash_function() const; |
50 | 54 |
51 // Returns string representation of the value stored in this object. | 55 // Returns string representation of the value stored in this object. |
52 const std::string ToString() const; | 56 const std::string ToString() const; |
53 | 57 |
54 // Comparison operators so that std::find() can be used with | 58 // Comparison operators so that std::find() can be used with |
55 // collections of this class. | 59 // collections of this class. |
56 bool operator ==(const AuthenticationMethod& other) const; | 60 bool operator ==(const AuthenticationMethod& other) const; |
57 bool operator !=(const AuthenticationMethod& other) const { | 61 bool operator !=(const AuthenticationMethod& other) const { |
58 return !(*this == other); | 62 return !(*this == other); |
59 } | 63 } |
60 | 64 |
61 private: | 65 protected: |
Sergey Ulanov
2013/03/20 07:24:12
why?
rmsousa
2013/03/21 01:23:25
Likely some early design leftover.
| |
62 AuthenticationMethod(); | 66 AuthenticationMethod(); |
63 explicit AuthenticationMethod(HashFunction hash_function); | 67 explicit AuthenticationMethod(HashFunction hash_function, |
68 bool requires_token); | |
64 | 69 |
65 bool invalid_; | 70 bool invalid_; |
71 bool requires_token_; | |
Sergey Ulanov
2013/03/20 07:24:12
Doesn't look like a good name. I suggest that inst
rmsousa
2013/03/21 01:23:25
Done.
| |
66 HashFunction hash_function_; | 72 HashFunction hash_function_; |
67 }; | 73 }; |
68 | 74 |
69 // SharedSecretHash stores hash of a host secret paired with the type | 75 // SharedSecretHash stores hash of a host secret paired with the type |
70 // of the hashing function. | 76 // of the hashing function. |
71 struct SharedSecretHash { | 77 struct SharedSecretHash { |
72 AuthenticationMethod::HashFunction hash_function; | 78 AuthenticationMethod::HashFunction hash_function; |
73 std::string value; | 79 std::string value; |
74 | 80 |
75 // Parse string representation of a shared secret hash. The |as_string| | 81 // Parse string representation of a shared secret hash. The |as_string| |
76 // must be in form "<hash_function>:<hash_value_base64>". | 82 // must be in form "<hash_function>:<hash_value_base64>". |
77 bool Parse(const std::string& as_string); | 83 bool Parse(const std::string& as_string); |
78 }; | 84 }; |
79 | 85 |
80 } // namespace protocol | 86 } // namespace protocol |
81 } // namespace remoting | 87 } // namespace remoting |
82 | 88 |
83 #endif // REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ | 89 #endif // REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_ |
OLD | NEW |