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 #ifndef CRYPTO_MUTUAL_AUTH_H_ | |
6 #define CRYPTO_MUTUAL_AUTH_H_ | |
Wez
2011/11/09 22:43:46
"mutual auth" seems a very generic name for this,
agl
2011/11/11 16:05:17
Done: p224_spake.cc
Wez
2011/11/12 00:50:23
Technically SPAKE2...? ;)
| |
7 #pragma once | |
8 | |
9 #include <base/string_piece.h> | |
10 #include <crypto/p224.h> | |
11 #include <crypto/sha2.h> | |
12 | |
13 namespace crypto { | |
14 | |
15 // SharedSecretMutualAuthentication provides a means to authenticate an | |
16 // encrypted transport using a low-entropy, shared secret. | |
17 // | |
18 // You need a value derived from the master secret of the connection in order | |
19 // to bind the authentication to the encrypted channel. It's the |session| | |
20 // argument to the constructor and can be of any length. | |
21 // | |
22 // The password can be low entropy as authenticating with an attacker only | |
23 // gives the attacker a one-shot password oracle. No other information about | |
24 // the password is leaked. (However, you must be sure to limit the number of | |
25 // permitted authentication attempts otherwise they get many one-shot oracles.) | |
26 // | |
27 // The protocol requires several RTTs (actually two, but you shouldn't assume | |
28 // that.) To use the object, call GetMessage() and pass that message to the | |
29 // peer. Get a message from the peer and feed it into ProcessMessage. Then | |
30 // examine the return value of ProcessMessage: | |
31 // kResultPending: another round is required. Call GetMessage and repeat. | |
Wez
2011/11/09 22:43:46
nit: Capitalize "another", and similarly for Faile
agl
2011/11/11 16:05:17
I don't think my English teacher would agree, but
| |
32 // kResultFailed: the authentication has failed. You can get a human readable | |
33 // error message by calling error(). | |
34 // kResultSuccess: the authentication was successful. | |
35 // | |
36 // In each exchange, each peer always sends a message. | |
37 class CRYPTO_EXPORT SharedSecretMutualAuthentication { | |
Wez
2011/11/09 22:43:46
Would EncryptedKeyExchange or something of that il
agl
2011/11/11 16:05:17
Well, if the filename is algorithm specific then s
| |
38 public: | |
39 enum Result { | |
40 kResultPending, | |
41 kResultFailed, | |
42 kResultSuccess, | |
43 }; | |
44 | |
45 // PeerType's values are named client and server due to convention. But | |
46 // they could be called "A" and "B" as far as the protocol is concerned so | |
47 // long as the two parties don't both get the same label. | |
48 enum PeerType { | |
49 kClient, | |
50 kServer, | |
51 }; | |
Wez
2011/11/09 22:43:46
nit: Should these be kPeerTypeClient and kPeerType
agl
2011/11/11 16:05:17
Done.
| |
52 | |
53 // peer_type: the type of the local authentication party. | |
54 // password: a, possibly low-entropy, mutually known password. | |
55 // session: a value securely derived from the connection's master secret. | |
56 // Both parties to the authentication must pass the same value. For the | |
57 // case of a TLS connection, see RFC 5705. | |
58 SharedSecretMutualAuthentication(PeerType peer_type, | |
59 const base::StringPiece& password, | |
60 const base::StringPiece& session); | |
Wez
2011/11/09 22:43:46
Are there any size limits that we should enforce o
agl
2011/11/11 16:05:17
Nope
| |
61 | |
62 // GetMessage returns a byte string which must be passed to the other party | |
63 // in the authentication. | |
64 const std::string& GetMessage(); | |
Wez
2011/11/09 22:43:46
What happens if the caller calls this twice betwee
agl
2011/11/11 16:05:17
It LOG(FATAL)s.
| |
65 | |
66 // ProcessMessage processes a message which must have been generated by a | |
67 // call to GetMessage() by the other party. | |
68 Result ProcessMessage(const base::StringPiece& message); | |
69 | |
70 // In the event that ProcessMessage() returns kResultFailed, error will | |
71 // return a human readable error message. | |
72 const std::string& error() const; | |
Wez
2011/11/09 22:43:46
Wot no numeric error code that calling code can sw
agl
2011/11/11 16:05:17
Nope, because the higher level code should't act d
Wez
2011/11/12 00:50:23
nit: Add the ", to aid debugging" to the comment,
| |
73 | |
74 private: | |
75 // The authentication state machine is very simple and each party proceeds | |
76 // through each of these states, in order. | |
77 enum State { | |
78 kStateInitial, | |
79 kStateRecvDH, | |
80 kStateSendHash, | |
81 kStateRecvHash, | |
82 kStateDone, | |
83 }; | |
84 | |
85 const bool is_server_; | |
86 | |
87 State state_; | |
Wez
2011/11/09 22:43:46
nit: Blank line after |state_|, please.
agl
2011/11/11 16:05:17
moot after moving.
| |
88 // x_ is the secret Diffie-Hellman exponent. | |
89 uint8 x_[p224::kScalarBytes]; | |
90 // pw_ is SHA256(P(password), P(session))[:28] where P() prepends a uint32, | |
91 // big-endian length prefix. | |
Wez
2011/11/09 22:43:46
nit: Are "x" and "pw" the EKE terminology? If so
agl
2011/11/11 16:05:17
Done.
| |
92 uint8 pw_[p224::kScalarBytes]; | |
93 // expected_authenticator_ is used to store the hash value expected from the | |
94 // other party. | |
Wez
2011/11/09 22:43:46
nit: If it's the expected hash value, why not |exp
agl
2011/11/11 16:05:17
Because it's less specific.
| |
95 uint8 expected_authenticator_[kSHA256Length]; | |
96 // next_message_ contains a value for GetMessage() to return. | |
97 std::string next_message_; | |
98 std::string error_; | |
Wez
2011/11/09 22:43:46
nit: Consider moving these implementation-detail f
agl
2011/11/11 16:05:17
Done.
| |
99 }; | |
100 | |
101 } // namespace crypto | |
102 | |
103 #endif // MUTUAL_AUTH_H_ | |
OLD | NEW |