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
3 // found in the LICENSE file.
5 // AuthenticationMethod represents an authentication algorithm and its
6 // configuration. It knows how to parse and format authentication
8 // Currently the following methods are supported:
9 // spake2_plain - SPAKE2 without hashing applied to the password.
10 // spake2_hmac - SPAKE2 with HMAC hashing of the password.
12 #ifndef REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_
13 #define REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_
22 class AuthenticationMethod
{
36 // Constructors for various authentication methods.
37 static AuthenticationMethod
Invalid();
38 static AuthenticationMethod
Spake2(HashFunction hash_function
);
39 static AuthenticationMethod
Spake2Pair();
40 static AuthenticationMethod
ThirdParty();
42 // Parses a string that defines an authentication method. Returns an
43 // invalid value if the string is invalid.
44 static AuthenticationMethod
FromString(const std::string
& value
);
46 // Applies the specified hash function to |shared_secret| with the
47 // specified |tag| as a key.
48 static std::string
ApplyHashFunction(HashFunction hash_function
,
49 const std::string
& tag
,
50 const std::string
& shared_secret
);
52 bool is_valid() const { return type_
!= INVALID
; }
54 MethodType
type() const { return type_
; }
56 // Following methods are valid only when is_valid() returns true.
58 // Hash function applied to the shared secret on both ends.
59 HashFunction
hash_function() const;
61 // Returns string representation of the value stored in this object.
62 const std::string
ToString() const;
64 // Comparison operators so that std::find() can be used with
65 // collections of this class.
66 bool operator ==(const AuthenticationMethod
& other
) const;
67 bool operator !=(const AuthenticationMethod
& other
) const {
68 return !(*this == other
);
72 AuthenticationMethod();
73 AuthenticationMethod(MethodType type
, HashFunction hash_function
);
76 HashFunction hash_function_
;
79 // SharedSecretHash stores hash of a host secret paired with the type
80 // of the hashing function.
81 struct SharedSecretHash
{
82 AuthenticationMethod::HashFunction hash_function
;
85 // Parse string representation of a shared secret hash. The |as_string|
86 // must be in form "<hash_function>:<hash_value_base64>".
87 bool Parse(const std::string
& as_string
);
90 } // namespace protocol
91 } // namespace remoting
93 #endif // REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_