1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_ASH_COMPONENTS_DBUS_CHAPS_CHAPS_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_CHAPS_CHAPS_CLIENT_H_
#include <stdint.h>
#include <vector>
#include "base/component_export.h"
#include "base/functional/callback.h"
namespace dbus {
class Bus;
} // namespace dbus
namespace ash {
// Interface for communicating with the Chaps daemon over D-Bus. It should be
// kept in sync with platform2/chaps/dbus_bindings/org.chromium.Chaps.xml .
// The class is exported for unit tests, use SimpleChapsClient for communicating
// with Chaps.
class COMPONENT_EXPORT(ASH_DBUS_CHAPS) ChapsClient {
public:
// Callback types.
using ResultCodeCallback = base::OnceCallback<void(uint32_t result_code)>;
using Uint64Callback =
base::OnceCallback<void(uint64_t value, uint32_t result_code)>;
using ArrayOfUint64Callback =
base::OnceCallback<void(const std::vector<uint64_t>& list,
uint32_t result_code)>;
using DataCallback = base::OnceCallback<void(uint64_t actual_out_length,
const std::vector<uint8_t>& data,
uint32_t result_code)>;
// `attributes` are a serialized chaps::AttributeList.
using GetAttributeValueCallback =
base::OnceCallback<void(const std::vector<uint8_t>& attributes,
uint32_t result_code)>;
using GenerateKeyPairCallback =
base::OnceCallback<void(uint64_t public_key_handle,
uint64_t private_key_handle,
uint32_t result_code)>;
ChapsClient(const ChapsClient&) = delete;
ChapsClient& operator=(const ChapsClient&) = delete;
ChapsClient(ChapsClient&&) = delete;
ChapsClient& operator=(ChapsClient&&) = delete;
// Returns the global instance which may be null if not initialized.
static ChapsClient* Get();
// Creates and initializes the global instance. |bus| must not be null.
static void Initialize(dbus::Bus* bus);
// Creates and initializes a fake global instance if not already created.
static void InitializeFake();
// Destroys the global instance.
static void Shutdown();
// PKCS #11 v2.20 section 11.5 page 106.
virtual void GetSlotList(bool token_present,
ArrayOfUint64Callback callback) = 0;
// PKCS #11 v2.20 section 11.5 page 111.
virtual void GetMechanismList(uint64_t slot_id,
ArrayOfUint64Callback callback) = 0;
// PKCS #11 v2.20 section 11.6 page 117.
virtual void OpenSession(uint64_t slot_id,
uint64_t flags,
Uint64Callback callback) = 0;
// PKCS #11 v2.20 section 11.6 page 118.
virtual void CloseSession(uint64_t session_id,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 128.
virtual void CreateObject(uint64_t session_id,
const std::vector<uint8_t>& attributes,
Uint64Callback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 131.
virtual void DestroyObject(uint64_t session_id,
uint64_t object_handle,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 133.
virtual void GetAttributeValue(uint64_t session_id,
uint64_t object_handle,
const std::vector<uint8_t>& attributes_query,
GetAttributeValueCallback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 135.
virtual void SetAttributeValue(uint64_t session_id,
uint64_t object_handle,
const std::vector<uint8_t>& attributes,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 136.
virtual void FindObjectsInit(uint64_t session_id,
const std::vector<uint8_t>& attributes,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 137.
virtual void FindObjects(uint64_t session_id,
uint64_t max_object_count,
ArrayOfUint64Callback callback) = 0;
// PKCS #11 v2.20 section 11.7 page 138.
virtual void FindObjectsFinal(uint64_t session_id,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.8 page 139.
virtual void EncryptInit(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
uint64_t key_handle,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.8 page 140.
virtual void Encrypt(uint64_t session_id,
const std::vector<uint8_t>& data,
uint64_t max_out_length,
DataCallback callback) = 0;
// PKCS #11 v2.20 section 11.9 page 144.
virtual void DecryptInit(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
uint64_t key_handle,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.9 page 145.
virtual void Decrypt(uint64_t session_id,
const std::vector<uint8_t>& data,
uint64_t max_out_length,
DataCallback callback) = 0;
// PKCS #11 v2.20 section 11.11 page 152.
virtual void SignInit(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
uint64_t key_handle,
ResultCodeCallback callback) = 0;
// PKCS #11 v2.20 section 11.11 page 153.
virtual void Sign(uint64_t session_id,
const std::vector<uint8_t>& data,
uint64_t max_out_length,
DataCallback callback) = 0;
// PKCS #11 v2.20 section 11.14 page 176.
virtual void GenerateKeyPair(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
const std::vector<uint8_t>& public_attributes,
const std::vector<uint8_t>& private_attributes,
GenerateKeyPairCallback callback) = 0;
// PKCS #11 v2.20 section 11.14 page 178.
virtual void WrapKey(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
uint64_t wrapping_key_handle,
uint64_t key_handle,
uint64_t max_out_length,
DataCallback callback) = 0;
// PKCS #11 v2.20 section 11.14 page 180.
virtual void UnwrapKey(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
uint64_t wrapping_key_handle,
const std::vector<uint8_t>& wrapped_key,
const std::vector<uint8_t>& attributes,
Uint64Callback callback) = 0;
// PKCS #11 v2.20 section 11.14 page 182.
virtual void DeriveKey(uint64_t session_id,
uint64_t mechanism_type,
const std::vector<uint8_t>& mechanism_parameter,
uint64_t base_key_handle,
const std::vector<uint8_t>& attributes,
Uint64Callback callback) = 0;
protected:
// Initialize/Shutdown should be used instead.
ChapsClient();
virtual ~ChapsClient();
};
} // namespace ash
#endif // CHROMEOS_ASH_COMPONENTS_DBUS_CHAPS_CHAPS_CLIENT_H_
|