| OLD | NEW |
| (Empty) |
| 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/protocol/authentication_method.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "crypto/hmac.h" | |
| 9 #include "remoting/protocol/auth_util.h" | |
| 10 #include "remoting/protocol/name_value_map.h" | |
| 11 | |
| 12 namespace remoting { | |
| 13 namespace protocol { | |
| 14 | |
| 15 const NameMapElement<AuthenticationMethod> kAuthenticationMethodStrings[] = { | |
| 16 {AuthenticationMethod::SPAKE2_SHARED_SECRET_PLAIN, "spake2_plain"}, | |
| 17 {AuthenticationMethod::SPAKE2_SHARED_SECRET_HMAC, "spake2_hmac"}, | |
| 18 {AuthenticationMethod::SPAKE2_PAIR, "spake2_pair"}, | |
| 19 {AuthenticationMethod::THIRD_PARTY, "third_party"}}; | |
| 20 | |
| 21 AuthenticationMethod ParseAuthenticationMethodString(const std::string& value) { | |
| 22 AuthenticationMethod result; | |
| 23 if (!NameToValue(kAuthenticationMethodStrings, value, &result)) | |
| 24 return AuthenticationMethod::INVALID; | |
| 25 return result; | |
| 26 } | |
| 27 | |
| 28 const std::string AuthenticationMethodToString( | |
| 29 AuthenticationMethod method) { | |
| 30 return ValueToName(kAuthenticationMethodStrings, method); | |
| 31 } | |
| 32 | |
| 33 HashFunction GetHashFunctionForAuthenticationMethod( | |
| 34 AuthenticationMethod method) { | |
| 35 switch (method) { | |
| 36 case AuthenticationMethod::INVALID: | |
| 37 NOTREACHED(); | |
| 38 return HashFunction::NONE; | |
| 39 | |
| 40 case AuthenticationMethod::SPAKE2_SHARED_SECRET_PLAIN: | |
| 41 case AuthenticationMethod::THIRD_PARTY: | |
| 42 return HashFunction::NONE; | |
| 43 | |
| 44 case AuthenticationMethod::SPAKE2_SHARED_SECRET_HMAC: | |
| 45 case AuthenticationMethod::SPAKE2_PAIR: | |
| 46 return HashFunction::HMAC_SHA256; | |
| 47 } | |
| 48 | |
| 49 NOTREACHED(); | |
| 50 return HashFunction::NONE; | |
| 51 } | |
| 52 | |
| 53 std::string ApplySharedSecretHashFunction(HashFunction hash_function, | |
| 54 const std::string& tag, | |
| 55 const std::string& shared_secret) { | |
| 56 switch (hash_function) { | |
| 57 case HashFunction::NONE: | |
| 58 return shared_secret; | |
| 59 | |
| 60 case HashFunction::HMAC_SHA256: { | |
| 61 crypto::HMAC response(crypto::HMAC::SHA256); | |
| 62 if (!response.Init(tag)) { | |
| 63 LOG(FATAL) << "HMAC::Init failed"; | |
| 64 } | |
| 65 | |
| 66 unsigned char out_bytes[kSharedSecretHashLength]; | |
| 67 if (!response.Sign(shared_secret, out_bytes, sizeof(out_bytes))) { | |
| 68 LOG(FATAL) << "HMAC::Sign failed"; | |
| 69 } | |
| 70 | |
| 71 return std::string(out_bytes, out_bytes + sizeof(out_bytes)); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 NOTREACHED(); | |
| 76 return shared_secret; | |
| 77 } | |
| 78 | |
| 79 } // namespace protocol | |
| 80 } // namespace remoting | |
| OLD | NEW |