OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_CRYPTO_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_CRYPTO_PROVIDER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 |
| 13 namespace local_discovery { |
| 14 |
| 15 class PrivetV3CryptoProvider { |
| 16 public: |
| 17 enum HandshakeState { |
| 18 // Handshake still in progress. Call |GetNextStep| to send next handshake |
| 19 // step. |
| 20 IN_PROGRESS, |
| 21 // Handshake in progress, waiting for response. Call |SetStepResponse| to |
| 22 // set the step response. |
| 23 AWAITING_RESPONSE, |
| 24 // Handshake in progress, need to wait for user verification to |
| 25 // continue. Call |GetVerificationCode| to get the verification code and |
| 26 // |AcceptVerificationCode| to signify the code is accepted. |
| 27 AWAITING_USER_VERIFICATION, |
| 28 // Handshake complete. Call |EncryptData| to encrypt the data. |
| 29 HANDSHAKE_COMPLETE, |
| 30 // Handshake error. |
| 31 HANDSHAKE_ERROR |
| 32 }; |
| 33 |
| 34 virtual ~PrivetV3CryptoProvider() {} |
| 35 |
| 36 static scoped_ptr<PrivetV3CryptoProvider> Create( |
| 37 const std::vector<std::string>& available_auth_methods); |
| 38 |
| 39 // Return the current state of the crypto provider. |
| 40 virtual HandshakeState GetState() = 0; |
| 41 |
| 42 // Return the authentication method used. |
| 43 virtual std::string GetAuthMethod() = 0; |
| 44 |
| 45 // Get the next handshake command. |step| is the step number to send, |
| 46 // |package| is a base64-encoded package to send with the step. Return |
| 47 // |true| if a package is generated or |false| in case of an error. |
| 48 virtual HandshakeState GetNextStep(int* step, std::string* package) = 0; |
| 49 |
| 50 // Input the response to the handshake command. |step| is the received step |
| 51 // number, |state| is the received state string, |package| is the received |
| 52 // base64-encoded package. Return the current handshake state. |
| 53 virtual HandshakeState SetStepResponse(int step, |
| 54 const std::string& state, |
| 55 const std::string& package) = 0; |
| 56 |
| 57 // Get the verification code to be displayed on the screen. |
| 58 virtual std::string GetVerificationCode() = 0; |
| 59 |
| 60 // Signal that the verification code is accepted. Returns the current |
| 61 // handshake state. |
| 62 virtual HandshakeState AcceptVerificationCode() = 0; |
| 63 |
| 64 // Encrypt a string using the session key. |
| 65 virtual bool EncryptData(const std::string& input, std::string* output) = 0; |
| 66 }; |
| 67 |
| 68 } // namespace local_discovery |
| 69 |
| 70 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_CRYPTO_PROVIDER_H_ |
OLD | NEW |