OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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/auth_util.h" | |
6 | |
7 #include "base/base64.h" | |
8 #include "base/logging.h" | |
9 #include "base/string_util.h" | |
10 #include "crypto/sha2.h" | |
Wez
2011/11/22 22:29:48
This should come after crypto/hmac.h
Sergey Ulanov
2011/11/23 01:23:42
Done.
| |
11 #include "crypto/hmac.h" | |
12 | |
13 namespace remoting { | |
14 namespace protocol { | |
15 | |
16 const char kClientAuthSslExporterLabel[] = | |
17 "EXPORTER-remoting-channel-auth-client"; | |
18 | |
19 const char kSslFakeHostName[] = "chromoting"; | |
20 | |
21 std::string GenerateSupportAuthToken(const std::string& jid, | |
22 const std::string& access_code) { | |
23 std::string sha256 = crypto::SHA256HashString(jid + " " + access_code); | |
24 std::string sha256_base64; | |
25 if (!base::Base64Encode(sha256, &sha256_base64)) { | |
26 LOG(FATAL) << "Failed to encode auth token"; | |
Wez
2011/11/22 22:29:48
Out of interest, how on earth can that ever fail??
Sergey Ulanov
2011/11/23 01:23:42
It should not, that's why we have LOG(FATAL) here,
| |
27 } | |
28 return sha256_base64; | |
29 } | |
30 | |
31 bool VerifySupportAuthToken(const std::string& jid, | |
32 const std::string& access_code, | |
33 const std::string& auth_token) { | |
34 std::string expected_token = | |
35 GenerateSupportAuthToken(jid, access_code); | |
36 return expected_token == auth_token; | |
37 } | |
38 | |
39 // static | |
40 bool GetAuthBytes(const std::string& shared_secret, | |
41 const std::string& key_material, | |
42 std::string* auth_bytes) { | |
43 // Generate auth digest based on the keying material and shared secret. | |
44 crypto::HMAC response(crypto::HMAC::SHA256); | |
45 if (!response.Init(key_material)) { | |
46 NOTREACHED() << "HMAC::Init failed"; | |
Wez
2011/11/22 22:29:48
Would it be cleaner to get rid of the return code
Sergey Ulanov
2011/11/23 01:23:42
This method may fail, for example, if key_material
| |
47 return false; | |
48 } | |
49 unsigned char out_bytes[kAuthDigestLength]; | |
50 if (!response.Sign(shared_secret, out_bytes, kAuthDigestLength)) { | |
51 NOTREACHED() << "HMAC::Sign failed"; | |
52 return false; | |
53 } | |
54 | |
55 auth_bytes->assign(out_bytes, out_bytes + kAuthDigestLength); | |
56 return true; | |
57 } | |
58 | |
59 } // namespace protocol | |
60 } // namespace remoting | |
OLD | NEW |