Home | History | Annotate | Download | only in host
      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.
      4 
      5 #include "remoting/host/pin_hash.h"
      6 
      7 #include "base/base64.h"
      8 #include "base/logging.h"
      9 #include "remoting/protocol/authentication_method.h"
     10 #include "remoting/protocol/me2me_host_authenticator_factory.h"
     11 
     12 namespace remoting {
     13 
     14 std::string MakeHostPinHash(const std::string& host_id,
     15                             const std::string& pin) {
     16   std::string hash = protocol::AuthenticationMethod::ApplyHashFunction(
     17       protocol::AuthenticationMethod::HMAC_SHA256, host_id, pin);
     18   std::string hash_base64;
     19   base::Base64Encode(hash, &hash_base64);
     20   return "hmac:" + hash_base64;
     21 }
     22 
     23 bool VerifyHostPinHash(const std::string& hash,
     24                        const std::string& host_id,
     25                        const std::string& pin) {
     26   remoting::protocol::SharedSecretHash hash_parsed;
     27   if (!hash_parsed.Parse(hash)) {
     28     LOG(FATAL) << "Invalid hash.";
     29     return false;
     30   }
     31   std::string hash_calculated =
     32       remoting::protocol::AuthenticationMethod::ApplyHashFunction(
     33           hash_parsed.hash_function, host_id, pin);
     34   return hash_calculated == hash_parsed.value;
     35 }
     36 
     37 }  // namespace remoting
     38