Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 5 | #ifndef LIBWEAVE_SRC_PRIVET_SECURITY_DELEGATE_H_ |
| 6 | #define LIBWEAVE_SRC_PRIVET_SECURITY_DELEGATE_H_ |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <set> |
| 10 | #include <string> |
| 11 | |
| 12 | #include <base/time/time.h> |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 13 | |
Stefan Sauer | 2d16dfa | 2015-09-25 17:08:35 +0200 | [diff] [blame] | 14 | #include "src/privet/privet_types.h" |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 15 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 16 | namespace weave { |
| 17 | namespace privet { |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 18 | |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 19 | // Interface to provide Security related logic for |PrivetHandler|. |
| 20 | class SecurityDelegate { |
| 21 | public: |
| 22 | virtual ~SecurityDelegate() = default; |
| 23 | |
| 24 | // Creates access token for the given scope, user id and |time|. |
| 25 | virtual std::string CreateAccessToken(const UserInfo& user_info, |
| 26 | const base::Time& time) = 0; |
| 27 | |
| 28 | // Validates |token| and returns scope and user id parsed from that. |
| 29 | virtual UserInfo ParseAccessToken(const std::string& token, |
| 30 | base::Time* time) const = 0; |
| 31 | |
| 32 | // Returns list of pairing methods by device. |
| 33 | virtual std::set<PairingType> GetPairingTypes() const = 0; |
| 34 | |
| 35 | // Returns list of crypto methods supported by devices. |
| 36 | virtual std::set<CryptoType> GetCryptoTypes() const = 0; |
| 37 | |
| 38 | // Returns true if |auth_code| provided by client is valid. Client should |
| 39 | // obtain |auth_code| during pairing process. |
| 40 | virtual bool IsValidPairingCode(const std::string& auth_code) const = 0; |
| 41 | |
| 42 | virtual bool StartPairing(PairingType mode, |
| 43 | CryptoType crypto, |
| 44 | std::string* session_id, |
| 45 | std::string* device_commitment, |
Vitaly Buka | 0801a1f | 2015-08-14 10:03:46 -0700 | [diff] [blame] | 46 | ErrorPtr* error) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 47 | |
| 48 | virtual bool ConfirmPairing(const std::string& session_id, |
| 49 | const std::string& client_commitment, |
| 50 | std::string* fingerprint, |
| 51 | std::string* signature, |
Vitaly Buka | 0801a1f | 2015-08-14 10:03:46 -0700 | [diff] [blame] | 52 | ErrorPtr* error) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 53 | |
| 54 | virtual bool CancelPairing(const std::string& session_id, |
Vitaly Buka | 0801a1f | 2015-08-14 10:03:46 -0700 | [diff] [blame] | 55 | ErrorPtr* error) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 58 | } // namespace privet |
| 59 | } // namespace weave |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 60 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 61 | #endif // LIBWEAVE_SRC_PRIVET_SECURITY_DELEGATE_H_ |