summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/authentication_method.h
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/protocol/authentication_method.h')
-rw-r--r--remoting/protocol/authentication_method.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/remoting/protocol/authentication_method.h b/remoting/protocol/authentication_method.h
new file mode 100644
index 0000000..402e3bc
--- /dev/null
+++ b/remoting/protocol/authentication_method.h
@@ -0,0 +1,90 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// AuthenticationMethod represents an authentication algorithm and its
+// configuration. It knows how to parse and format authentication
+// method names.
+// Currently the following methods are supported:
+// v1_token - deprecated V1 authentication mechanism,
+// spake2_plain - SPAKE2 without hashing applied to the password.
+// spake2_hmac - SPAKE2 with HMAC hashing of the password.
+
+#ifndef REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_
+#define REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+
+namespace remoting {
+namespace protocol {
+
+class Authenticator;
+
+class AuthenticationMethod {
+ public:
+ enum Version {
+ // Legacy authentication mechanism.
+ // TODO(sergeyu): Should be removed when we finished switching to
+ // the new version (at which point this enum may be removed).
+ // crbug.com/110483
+ VERSION_1,
+
+ // The new SPAKE2-based authentication.
+ VERSION_2,
+ };
+
+ enum HashFunction {
+ NONE,
+ HMAC_SHA256,
+ };
+
+ // Constructors for various authentication methods.
+ static AuthenticationMethod Invalid();
+ static AuthenticationMethod V1Token();
+ static AuthenticationMethod Spake2(HashFunction hash_function);
+
+ // Parses a string that defines an authentication method. Returns an
+ // invalid value if the string is invalid.
+ static AuthenticationMethod FromString(const std::string& value);
+
+ // Returns true
+ bool is_valid() const { return !invalid_; }
+
+ // Following methods are valid only when is_valid() returns true.
+
+ // Version of the authentication protocol.
+ Version version() const ;
+
+ // Hash function applied to the shared secret on both ends.
+ HashFunction hash_function() const;
+
+ // Returns string representation of the value stored in this object.
+ const std::string ToString() const;
+
+ // Applies the current hash function to |shared_secret| with the
+ // specified |tag| as a key.
+ std::string ApplyHashFunction(const std::string& tag,
+ const std::string& shared_secret);
+
+ // Creates client authenticator using the specified parameters.
+ scoped_ptr<Authenticator> CreateAuthenticator(
+ const std::string& local_jid,
+ const std::string& tag,
+ const std::string& shared_secret);
+
+ private:
+ AuthenticationMethod();
+ AuthenticationMethod(Version version,
+ HashFunction hash_function);
+
+ bool invalid_;
+ Version version_;
+ HashFunction hash_function_;
+};
+
+} // namespace protocol
+} // namespace remoting
+
+#endif // REMOTING_PROTOCOL_AUTHENTICATION_METHOD_H_