Debian Codegraph @

src/dpp/dave/persisted_key_pair.h

raw symbols SCIP
1 /************************************************************************************
2 *
3 * D++, A Lightweight C++ library for Discord
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 * Copyright 2021 Craig Edwards and D++ contributors
7 * (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 * This folder is a modified fork of libdave, https://github.com/discord/libdave
22 * Copyright (c) 2024 Discord, Licensed under MIT
23 *
24 ************************************************************************************/
25 #pragma once
26
27 #include <filesystem>
28 #include <fstream>
29 #include <sstream>
30 #include <mutex>
31 #include <functional>
32 #include <string>
33 #include <memory>
34 #include <vector>
35 #include <bytes/bytes.h>
36 #include <mls/crypto.h>
37 #include "parameters.h"
38 #include "version.h"
39
40 namespace dpp {
41 class cluster;
42 }
43
44 namespace mlspp {
45 struct SignaturePrivateKey;
46 };
47
48 namespace dpp::dave::mls {
49
50 /**
51 * @brief Key pair context type
52 */
53 using key_pair_context_type = const char *;
54
55 /**
56 * @brief Get persisted key pair
57 * @param ctx context (pass nullptr to generate transient key)
58 * @param session_id session id (pass empty string to generate transient key)
59 * @param version Protocol version
60 * @return MLS signature private key
61 */
62 std::shared_ptr<::mlspp::SignaturePrivateKey> get_persisted_key_pair(dpp::cluster& creator, key_pair_context_type ctx, const std::string& session_id, protocol_version version);
63
64 /**
65 * @brief self signed signature and key
66 */
67 struct KeyAndSelfSignature {
68 /**
69 * @brief key
70 */
71 std::vector<uint8_t> key;
72 /**
73 * @brief signature
74 */
75 std::vector<uint8_t> signature;
76 };
77
78 /**
79 * @brief Get persisted public key
80 * @param ctx context (set to nullptr to get transient key)
81 * @param session_id session id (set to empty string to get transient key)
82 * @param version protocol version
83 * @return Key and self signature
84 */
85 KeyAndSelfSignature get_persisted_public_key(dpp::cluster& creator, key_pair_context_type ctx, const std::string& session_id, signature_version version);
86
87 /**
88 * @brief Delete persisted key pair
89 * @param ctx context
90 * @param session_id session ID
91 * @param version protocol version
92 * @return true if deleted
93 */
94 bool delete_persisted_key_pair(dpp::cluster& creator, key_pair_context_type ctx, const std::string& session_id, signature_version version);
95
96 /**
97 * @brief Key version for DAVE
98 */
99 constexpr unsigned KeyVersion = 1;
100
101 namespace detail {
102 /**
103 * Get generic persisted key pair
104 * @param ctx context
105 * @param id key ID
106 * @param suite ciphersuite
107 * @return signature and private key
108 */
109 std::shared_ptr<::mlspp::SignaturePrivateKey> get_generic_persisted_key_pair(dpp::cluster& creator, key_pair_context_type ctx, const std::string& id, ::mlspp::CipherSuite suite);
110
111 /**
112 * Delete generic persisted key pair
113 * @param ctx context
114 * @param id id
115 * @return true if deleted
116 */
117 bool delete_generic_persisted_key_pair(dpp::cluster& creator, key_pair_context_type ctx, const std::string& id);
118 }
119
120 }