Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Unified Diff: remoting/host/pin_hash.cc

Issue 10243011: [Chromoting] Factor out common code for pin hashing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/pin_hash.cc
diff --git a/remoting/host/pin_hash.cc b/remoting/host/pin_hash.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe17f38caff4d46e4fd812462bb7b9788c94e317
--- /dev/null
+++ b/remoting/host/pin_hash.cc
@@ -0,0 +1,39 @@
+// 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.
+
+#include "remoting/host/pin_hash.h"
+
+#include "base/base64.h"
+#include "base/logging.h"
+#include "remoting/protocol/authentication_method.h"
+#include "remoting/protocol/me2me_host_authenticator_factory.h"
+
+namespace remoting {
+
+std::string MakeHostPinHash(const std::string& host_id,
+ const std::string& pin) {
+ std::string hash = protocol::AuthenticationMethod::ApplyHashFunction(
+ protocol::AuthenticationMethod::HMAC_SHA256, host_id, pin);
+ std::string hash_base64;
+ if (!base::Base64Encode(hash, &hash_base64)) {
+ LOG(FATAL) << "Base64Encode failed";
+ }
+ return "hmac:" + hash_base64;
+}
+
+bool VerifyHostPinHash(const std::string& hash,
+ const std::string& host_id,
+ const std::string& pin) {
+ remoting::protocol::SharedSecretHash hash_parsed;
+ if (!hash_parsed.Parse(hash)) {
+ LOG(FATAL) << "Invalid hash.";
+ return false;
+ }
+ std::string hash_calculated =
+ remoting::protocol::AuthenticationMethod::ApplyHashFunction(
+ hash_parsed.hash_function, host_id, pin);
+ return hash_calculated == hash_parsed.value;
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698