libkazv
crypto-p.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of libkazv.
3  * SPDX-FileCopyrightText: 2021-2024 tusooa <tusooa@kazv.moe>
4  * SPDX-License-Identifier: AGPL-3.0-or-later
5  */
6 
7 #pragma once
8 #include <libkazv-config.hpp>
9 
10 #include <olm/olm.h>
11 
12 #include <unordered_map>
13 
14 #include "crypto.hpp"
15 #include "crypto-util.hpp"
16 #include "session.hpp"
19 
20 namespace Kazv
21 {
22  using SessionList = std::vector<Session>;
23 
25  {
26  CryptoPrivate();
28  CryptoPrivate(const CryptoPrivate &that);
30 
32  OlmAccount *account;
33  immer::map<std::string /* algorithm */, int> uploadedOneTimeKeysCount;
35  std::unordered_map<std::string /* theirCurve25519IdentityKey */, Session> knownSessions;
36  std::unordered_map<KeyOfGroupSession, InboundGroupSession> inboundGroupSessions;
37 
38  std::unordered_map<std::string /* roomId */, OutboundGroupSession> outboundGroupSessions;
39 
41  OlmUtility *utility;
42  bool valid{true};
43 
44  std::size_t checkUtilError(std::size_t code) const;
45 
46  std::string pickle() const;
47  void unpickle(std::string data);
48 
49  ByteArray identityKeys() const;
50  std::string ed25519IdentityKey() const;
51  std::string curve25519IdentityKey() const;
52 
53  std::size_t checkError(std::size_t code) const;
54 
56  // Here we need the full event for eventId and originServerTs
58 
60  bool createInboundSession(std::string theirCurve25519IdentityKey,
61  std::string message);
62 
63  bool createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key);
64 
66  std::string roomId, std::optional<MegOlmSessionRotateDesc> desc);
67  };
68 
69 }
session.hpp
Kazv::CryptoPrivate::checkUtilError
std::size_t checkUtilError(std::size_t code) const
Definition: crypto.cpp:95
Kazv::CryptoPrivate::accountData
ByteArray accountData
Definition: crypto-p.hpp:31
Kazv::Session
Definition: session.hpp:27
Kazv::RandomData
std::string RandomData
Definition: crypto-util.hpp:34
crypto-util.hpp
Kazv::CryptoPrivate::unpickle
void unpickle(std::string data)
Definition: crypto.cpp:80
Kazv::CryptoPrivate::knownSessions
std::unordered_map< std::string, Session > knownSessions
Definition: crypto-p.hpp:35
Kazv::Maybe
Definition: maybe.hpp:24
Kazv
Definition: location.hpp:10
Kazv::Timestamp
std::int_fast64_t Timestamp
Definition: event.hpp:18
Kazv::CryptoPrivate::identityKeys
ByteArray identityKeys() const
Definition: crypto.cpp:274
Kazv::CryptoPrivate::createInboundSession
bool createInboundSession(std::string theirCurve25519IdentityKey, std::string message)
returns whether the session is successfully established
Definition: crypto.cpp:167
Kazv::KeyOfGroupSession
Definition: crypto-util.hpp:23
Kazv::CryptoPrivate::numUnpublishedKeys
int numUnpublishedKeys
Definition: crypto-p.hpp:34
outbound-group-session.hpp
inbound-group-session.hpp
Kazv::CryptoPrivate::~CryptoPrivate
~CryptoPrivate()
Definition: crypto.cpp:52
Kazv::CryptoPrivate::account
OlmAccount * account
Definition: crypto-p.hpp:32
Kazv::json
nlohmann::json json
Definition: jsonwrap.hpp:20
Kazv::OutboundGroupSession
Definition: outbound-group-session.hpp:21
Kazv::CryptoPrivate
Definition: crypto-p.hpp:24
Kazv::CryptoPrivate::pickle
std::string pickle() const
Definition: crypto.cpp:71
Kazv::CryptoPrivate::outboundGroupSessions
std::unordered_map< std::string, OutboundGroupSession > outboundGroupSessions
Definition: crypto-p.hpp:38
Kazv::CryptoPrivate::createInboundGroupSession
bool createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key)
Definition: crypto.cpp:411
Kazv::CryptoPrivate::ed25519IdentityKey
std::string ed25519IdentityKey() const
Definition: crypto.cpp:281
Kazv::CryptoPrivate::reuseOrCreateOutboundGroupSession
bool reuseOrCreateOutboundGroupSession(RandomData random, Timestamp timeMs, std::string roomId, std::optional< MegOlmSessionRotateDesc > desc)
Definition: crypto.cpp:182
Kazv::CryptoPrivate::curve25519IdentityKey
std::string curve25519IdentityKey() const
Definition: crypto.cpp:289
Kazv::ByteArray
std::vector< unsigned char > ByteArray
Definition: crypto-util.hpp:21
Kazv::CryptoPrivate::inboundGroupSessions
std::unordered_map< KeyOfGroupSession, InboundGroupSession > inboundGroupSessions
Definition: crypto-p.hpp:36
Kazv::CryptoPrivate::CryptoPrivate
CryptoPrivate()
Definition: crypto.cpp:32
libkazv-config.hpp
Kazv::CryptoPrivate::utilityData
ByteArray utilityData
Definition: crypto-p.hpp:40
Kazv::CryptoPrivate::decryptMegOlm
MaybeString decryptMegOlm(nlohmann::json eventJson)
Definition: crypto.cpp:146
Kazv::CryptoPrivate::utility
OlmUtility * utility
Definition: crypto-p.hpp:41
crypto.hpp
Kazv::CryptoPrivate::valid
bool valid
Definition: crypto-p.hpp:42
Kazv::RandomTag
The tag to indicate that a constructor should use user-provided random data.
Definition: crypto-util.hpp:32
Kazv::CryptoPrivate::decryptOlm
MaybeString decryptOlm(nlohmann::json content)
Definition: crypto.cpp:104
Kazv::SessionList
std::vector< Session > SessionList
Definition: crypto-p.hpp:22
Kazv::CryptoPrivate::uploadedOneTimeKeysCount
immer::map< std::string, int > uploadedOneTimeKeysCount
Definition: crypto-p.hpp:33
Kazv::CryptoPrivate::checkError
std::size_t checkError(std::size_t code) const
Definition: crypto.cpp:87