blob: 1d28ba310930345cca22035d065b4fe008d7c50e [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Vitaly Buka7ce499f2015-06-09 08:04:11 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Vitaly Buka912b6982015-07-06 11:13:03 -07005#ifndef LIBWEAVE_SRC_PRIVET_SECURITY_DELEGATE_H_
6#define LIBWEAVE_SRC_PRIVET_SECURITY_DELEGATE_H_
Vitaly Buka7ce499f2015-06-09 08:04:11 -07007
8#include <memory>
9#include <set>
10#include <string>
11
12#include <base/time/time.h>
Vitaly Buka7ce499f2015-06-09 08:04:11 -070013
Stefan Sauer2d16dfa2015-09-25 17:08:35 +020014#include "src/privet/privet_types.h"
Vitaly Buka7ce499f2015-06-09 08:04:11 -070015
Vitaly Bukab6f015a2015-07-09 14:59:23 -070016namespace weave {
17namespace privet {
Vitaly Buka7ce499f2015-06-09 08:04:11 -070018
Vitaly Buka7ce499f2015-06-09 08:04:11 -070019// Interface to provide Security related logic for |PrivetHandler|.
20class 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 Buka0801a1f2015-08-14 10:03:46 -070046 ErrorPtr* error) = 0;
Vitaly Buka7ce499f2015-06-09 08:04:11 -070047
48 virtual bool ConfirmPairing(const std::string& session_id,
49 const std::string& client_commitment,
50 std::string* fingerprint,
51 std::string* signature,
Vitaly Buka0801a1f2015-08-14 10:03:46 -070052 ErrorPtr* error) = 0;
Vitaly Buka7ce499f2015-06-09 08:04:11 -070053
54 virtual bool CancelPairing(const std::string& session_id,
Vitaly Buka0801a1f2015-08-14 10:03:46 -070055 ErrorPtr* error) = 0;
Vitaly Buka7ce499f2015-06-09 08:04:11 -070056};
57
Vitaly Bukab6f015a2015-07-09 14:59:23 -070058} // namespace privet
59} // namespace weave
Vitaly Buka7ce499f2015-06-09 08:04:11 -070060
Vitaly Buka912b6982015-07-06 11:13:03 -070061#endif // LIBWEAVE_SRC_PRIVET_SECURITY_DELEGATE_H_