Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112527
D157.1732329124.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D157.1732329124.diff
View Options
diff --git a/src/tests/resources/libolm-crypto-dump b/src/tests/resources/libolm-crypto-dump
new file mode 100644
--- /dev/null
+++ b/src/tests/resources/libolm-crypto-dump
@@ -0,0 +1,123 @@
+{
+ "a": {
+ "account": "InbHVpDA1VYNczyPzia2Z2561pe0akDPpBPURkMyWexGY5KXGzsOeU35Cg9NS2+yafv0IrkctQPowY94KljW2il4mY8+pyD4pPfWL1rcQfd1DYmuPQ1eVKE8xoe5FuGpm7+GUgiZNTW1aJIYm/bmvrrv7yhBB6M6IHW/nI7kyJQyv8bRXe8Di0tTLE0EnsQXFK48YF7cFb4p40piDbYfO2qd28V3MizokVL3LBNpvvUT48Gi2calCQJ6HL6iddNFjdhDHfZX70iCN1HM1kIA7/NBiE2DBr6YbpD/zbtaJ0715RNfmSlmi4R0Q9aASn2AL7KMjj9A2p1GRYUAc92F68/1KhrCznm7",
+ "inboundGroupSessions": [
+ [
+ {
+ "roomId": "!foo:example.com",
+ "sessionId": "ugpq3d+cOOyAC4IbxiPnk9eMrRkS3L8LXHd5pIZXT2M"
+ },
+ {
+ "decryptedEvents": [
+ 0,
+ {
+ "eventId": "$1",
+ "originServerTs": 1234
+ }
+ ],
+ "ed25519Key": "wgp5eyDKd4isViNiPpJIeImNu9pGA2Efs/Fnz0YKipk",
+ "session": "32jHxAe1JN1euTkPoVEnMm9pQrK1lsX6lkYdt0ffI+03c2TYFoCjEeUWlajB3AZtoGmtymaBCbaqERHIocypQ4DdxMpFct0iV/OJMldmr+++RWYSdiaHUQtfQJnJNt3ggein5DUNeBlXefU8yRaIBEGh/QZZYRqfCbC/ps/QbNsscXKy3Z3tY9tv3FVOKKv7VT5ObwsK51UpRurenIEi/Nda3RSaqE4HgZWuDDFP9cIwyXOhizIiOkJieNrvuvgSvgMHqNEqWf7yl8lGOq5J1yFKaFZeJGRiy6moTT4lhQwIvsTerdumd8+EuDiQewbyqvi2N51/Z1lnv36ckgHhIKsY17xoh5Ks4ExND7rxJ7p2/v/P+bs/vMsNQA4lXmlTKdmaShxcAftXtiBcdA8ASu83GH6eAMHu",
+ "valid": true
+ }
+ ]
+ ],
+ "knownSessions": {
+ "wklSkg9T1gz0pnYDZUmKrVqQXEDGW8HnQV0JDWqzYVs": {
+ "data": "9F6JOJCSDnejHEAbOlcRQE0nnzSXdkJ4qLl9AjtZq+LDnaX3KISsAd3sqRaI2jVS+d4uL2MbaH7RYlNvrPoKuf3tDdVnSoLa2bKGtE889ENP3lUCzsV9+k+YwOYrwiFu/umc39/GutHFuOR6kHQ8YwGznmGFYTF2uI45GeieST6AFSnyWMx9WBmYgvjtlnplIZiEXRh9aAl2uBkF2/i8wnyLG4t8o9jWdzjRA7SOkXauaY2w1oGHJn6UhKAaKgt3Vl6IRpbxeQ20//FNvS3HIp4sgyBfhoLhJnAg6tf6WBcgFx91gRbs/qQfNmPzzb0dbv5fs21MPFRDvEA+3HV3D+5uB2DoRGaXNiykJl3pt+v7sDt9fcdEzhfFVMN2CA5uZBsWMGUOfG/rtqj/1EeTnfuGFKQOYDIT5eK7qpZHJ2fNuLPuu31+zg",
+ "valid": true
+ }
+ },
+ "numUnpublishedKeys": 1,
+ "outboundGroupSessions": {
+ "!foo:example.com": {
+ "creationTime": 0,
+ "initialSessionKey": "AgAAAABwAZnJFcXBZlo2IeX/8TMVJLYGqTP8GlHPc5AClXecXCMi/1lCnjdke46VN0SGlGJ+iop5GcOEaLBFNUnteHNhaRR/elxA6EilV3V5LFC78bEZsmcGI49RcHIMnArez5Qx2bJOvzDxOLu0M+4/Ck/4VwV9U3wj35WczvpWqjADlLoKat3fnDjsgAuCG8Yj55PXjK0ZEty/C1x3eaSGV09jkciQW9mcrQt6R+Rr7Ci8GulZaHRaIeq9T86dyXT7JaLWbjnH1wearEE77aanBWS83OXjLynatPUg2VE1KZ4DDA",
+ "session": "1TfNuq1pP70TliOdAWVKztCiXpL4eX5wClJur0MHzkzH0KYHLi8NvLrQWk+LbwDy1VU4Kp6Ql1v3iNIgtGOSkS+nMwq3chWdc6WARj5kNkF1vPDACqg2z32J8Zia47OayiCoyuDKxeBIIjuB1Hp1UBomT7Oecad0P8zlf+OarOIPFB38v+YwRu/GHLqvioTLD4lZmHWj2MsoRJ2e3GpHz8rfNqUku6mB5QPijAiuPBHgttCb/jDjSRq3RQlKNZZ/cE7S7bufRfLtzcar0dTYuyRY2lGVbpUGEljx85e99VFsZD3hs8aKVbkB+KdLF4V88F6QQiSkLv4",
+ "valid": true
+ }
+ },
+ "uploadedOneTimeKeysCount": {},
+ "valid": true
+ },
+ "aIdKey": "L75F3cTDIM/bw/n11zm73o0+LpNZ5ll+FCbCH8+OETQ",
+ "b": {
+ "account": "z6sIAP5uTDNqUY8TrUHo+x8WSZieoWuoUN66oYBbk7Jz+UWJ1gQA2nXDZRHOSqS+NQNIMX13IKhXr3916JCDYsQOd1BknfJf8xyYIbYifgb9DKovNBOQm7jOxqRXF+IOkklDy/r3lWvd58fN83LvP7g8kjtDi4XSq1KULfuMiAeF3FnLuMGQWkY9Qc9nNHFjbWkoulv8Xf7uT5sc95VjlpMLk2Oe2mOxuUuSze5KuzNQvGOz2vefVw",
+ "inboundGroupSessions": [],
+ "knownSessions": {
+ "L75F3cTDIM/bw/n11zm73o0+LpNZ5ll+FCbCH8+OETQ": {
+ "data": "9F6JOJCSDnejHEAbOlcRQE0nnzSXdkJ4qLl9AjtZq+LDnaX3KISsAd3sqRaI2jVS+d4uL2MbaH7RYlNvrPoKuf3tDdVnSoLa2bKGtE889ENP3lUCzsV9+k+YwOYrwiFu/umc39/GutHFuOR6kHQ8YwGznmGFYTF2uI45GeieST4CQWW2fUQsb5KdTkeRgJEP6slQGr249D7Cbqs7UYuFKmKu3fDZSoAbJX9IX+s1JJXQNqR22R58ZTI88dLl/hGPZgXgp+M1+8WLrl1/hW4w5aUdNtuF6ezKpGWfWiEYX3p0QgQgwaBqew",
+ "valid": true
+ }
+ },
+ "numUnpublishedKeys": 0,
+ "outboundGroupSessions": {},
+ "uploadedOneTimeKeysCount": {},
+ "valid": true
+ },
+ "bIdKey": "wklSkg9T1gz0pnYDZUmKrVqQXEDGW8HnQV0JDWqzYVs",
+ "megolmEncrypted": {
+ "content": {
+ "algorithm": "m.megolm.v1.aes-sha2",
+ "ciphertext": "AwgAElCaGCczDxlcpqmVOxHO0PD0E0WEUA89CRi0G6R8i/AnyPGVSopCZVK5D/Usv/69FcFa17Ds4Kght74UnaQbrUQIuU5s/DaAz7VxSAxFaFs2E0tUHFpXh1CJuTQKaceLiTmQxQWTHYGZXNb2kZ/oOM6Yygpxu9Iaz/N4Zr+nYnrAHWidcaH+TElgimnk4FXjiTDvWNpWMzmJAw",
+ "sender_key": "L75F3cTDIM/bw/n11zm73o0+LpNZ5ll+FCbCH8+OETQ",
+ "session_id": "ugpq3d+cOOyAC4IbxiPnk9eMrRkS3L8LXHd5pIZXT2M"
+ },
+ "event_id": "$1",
+ "origin_server_ts": 1234,
+ "room_id": "!foo:example.com"
+ },
+ "megolmPlainText": {
+ "content": {
+ "mew": "mew"
+ },
+ "room_id": "!foo:example.com",
+ "type": "m.room.message"
+ },
+ "olmEncrypted1": {
+ "content": {
+ "algorithm": "m.olm.v1.curve25519-aes-sha2",
+ "ciphertext": {
+ "L75F3cTDIM/bw/n11zm73o0+LpNZ5ll+FCbCH8+OETQ": {
+ "body": "AwogvGHanO3AZ+EgRYBzXxff45/jmpNX5CIkFBo+SrjUamESICu+11zE1eNPsOboLGVjj1adIbWzS1r3NmZ+nneUS2I8GiDCSVKSD1PWDPSmdgNlSYqtWpBcQMZbwedBXQkNarNhWyI/AwogyNnUBXJ2CHMAsEDDPSwQ2QPgn6+/D5L+3fidyqMwGC8QACIQSlvPI16rEXr1qhqmsvuDbUyoDQAbGANK",
+ "type": 0
+ }
+ },
+ "sender_key": "wklSkg9T1gz0pnYDZUmKrVqQXEDGW8HnQV0JDWqzYVs"
+ }
+ },
+ "olmEncrypted2": {
+ "content": {
+ "algorithm": "m.olm.v1.curve25519-aes-sha2",
+ "ciphertext": {
+ "wklSkg9T1gz0pnYDZUmKrVqQXEDGW8HnQV0JDWqzYVs": {
+ "body": "AwogHp+8jwr0qOHA/olaTGwc0aCj+hLb5LjkrRiSjA2+GRsQACIQrbIEczIcTnraT17CWsNJMrxyeTgLPXqT",
+ "type": 1
+ }
+ },
+ "sender_key": "L75F3cTDIM/bw/n11zm73o0+LpNZ5ll+FCbCH8+OETQ"
+ }
+ },
+ "olmPlainText": {
+ "test": "mew"
+ },
+ "oneTimeKeys1": {
+ "curve25519": {
+ "AAAAAQ": "vGHanO3AZ+EgRYBzXxff45/jmpNX5CIkFBo+SrjUamE"
+ }
+ },
+ "oneTimeKeys2": {
+ "curve25519": {
+ "AAAAAg": "XlP9NyP2FSyhuY/WYpEH9PdGOHdrpD6RjtbStyxSFlU"
+ }
+ },
+ "seeds": {
+ "construct1": "x22PyHo0qa65Ur8sxESNGkmh0bOPm2sa6ijiVM3EmYawEgUVaW8snFpGBACPqRFOkQmj8OA9sN2VU72uGseWfg",
+ "construct2": "F4RXaQfaGZsPGyELCknCEEtEza8ij8PUNCtmQAnBxxYj6JpR63gTUOe/bpxWpW+o3T1sIvwwRJR4SLwQDpPkDg",
+ "createOutbound": "bEYzNPryucXP0c1dTWL05eqXRgMboc8MmgRTrBp88OfVwnVj+ALz7i9XdelCbrs2Efn1Gc4MXnzq5I1ehmTzQQ",
+ "encryptOlm1": "lqkzYypWvu0PhZr+xk8UwU/u6ghsUsGwIY5ixQ6OrvI",
+ "encryptOlm2": "YXcyZmFFNwTPPt/PTg9TzVWbV2dPR3m11AbQFXatcNQ",
+ "oneTimeKeys1": "QvvCrMSXI9DkSW0jTX2hseTuIsCcQgkzdx5lUNpf2Fs",
+ "oneTimeKeys2": "pOM8FDXy3bnYM6Rdo3lyt5APefIWdg+S5nmACuTqK3E",
+ "rotateMegOlm1": "cAGZyRXFwWZaNiHl//EzFSS2Bqkz/BpRz3OQApV3nFwjIv9ZQp43ZHuOlTdEhpRifoqKeRnDhGiwRTVJ7XhzYWkUf3pcQOhIpVd1eSxQu/GxGbJnBiOPUXByDJwK3s+UMdmyTr8w8Ti7tDPuPwpP+FcFfVN8I9+VnM76VqowA5Q+vOR01rXPWVpEx0ZJFjn3GAX1R4tXnRVCUDzxsglqjg"
+ }
+}
diff --git a/tools/generate-libolm-crypto-dump.cpp b/tools/generate-libolm-crypto-dump.cpp
new file mode 100644
--- /dev/null
+++ b/tools/generate-libolm-crypto-dump.cpp
@@ -0,0 +1,127 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include <iostream>
+#include <crypto.hpp>
+#include <crypto-util.hpp>
+#include <base64.hpp>
+#include <types.hpp>
+
+using namespace Kazv;
+using namespace Kazv::CryptoConstants;
+
+// This program generates a dump of olm accounts, sessions,
+// and megolm sessions. It is intended to be linked against
+// the libolm implementation of libkazvcrypto.
+//
+// The generated file is at src/tests/resources/libolm-crypto-dump .
+// It is used to test the conversion from a libolm Crypto
+// to a future vodozemac Crypto.
+
+static json convert(std::unordered_map<std::string, RandomData> seeds)
+{
+ auto res = json::object();
+ for (auto [k, v] : seeds) {
+ res[k] = encodeBase64(v);
+ }
+ return res;
+}
+
+static void verify(MaybeString s)
+{
+ if (!s.has_value()) {
+ throw std::runtime_error{s.reason()};
+ }
+}
+
+int main()
+{
+ auto seeds = std::unordered_map<std::string, RandomData>{};
+ seeds["construct1"] = genRandomData(Crypto::constructRandomSize());
+ auto a = Crypto(RandomTag{}, seeds["construct1"]);
+
+ seeds["construct2"] = genRandomData(Crypto::constructRandomSize());
+ auto b = Crypto(RandomTag{}, seeds["construct2"]);
+
+ seeds["oneTimeKeys1"] = genRandomData(Crypto::genOneTimeKeysRandomSize(1));
+ a.genOneTimeKeysWithRandom(seeds["oneTimeKeys1"], 1);
+
+ auto k = a.unpublishedOneTimeKeys();
+ a.markOneTimeKeysAsPublished();
+
+ seeds["oneTimeKeys2"] = genRandomData(Crypto::genOneTimeKeysRandomSize(1));
+ a.genOneTimeKeysWithRandom(seeds["oneTimeKeys2"], 1);
+ auto k2 = a.unpublishedOneTimeKeys();
+
+ auto oneTimeKey = k[curve25519].begin().value();
+ auto aIdKey = a.curve25519IdentityKey();
+ auto bIdKey = b.curve25519IdentityKey();
+
+ seeds["createOutbound"] = genRandomData(Crypto::createOutboundSessionRandomSize());
+ b.createOutboundSessionWithRandom(seeds["createOutbound"], aIdKey, oneTimeKey);
+
+ auto origJson = json{{"test", "mew"}};
+ seeds["encryptOlm1"] = genRandomData(Crypto::encryptOlmMaxRandomSize());
+ auto encryptedMsg = b.encryptOlmWithRandom(seeds["encryptOlm1"], origJson, aIdKey);
+ auto encJson = json{{"content", {
+ {"algorithm", olmAlgo},
+ {"ciphertext", encryptedMsg},
+ {"sender_key", b.curve25519IdentityKey()}
+ }}};
+
+ auto decryptedOpt = a.decrypt(encJson);
+ verify(decryptedOpt);
+
+ seeds["encryptOlm2"] = genRandomData(Crypto::encryptOlmMaxRandomSize());
+ auto encryptedMsg2 = a.encryptOlmWithRandom(seeds["encryptOlm2"], origJson, bIdKey);
+ auto encJson2 = json{{"content", {
+ {"algorithm", olmAlgo},
+ {"ciphertext", encryptedMsg2},
+ {"sender_key", a.curve25519IdentityKey()}
+ }}};
+
+ decryptedOpt = b.decrypt(encJson2);
+ verify(decryptedOpt);
+
+ seeds["rotateMegOlm1"] = genRandomData(Crypto::rotateMegOlmSessionRandomSize());
+
+ a.rotateMegOlmSessionWithRandom(seeds["rotateMegOlm1"], 0, "!foo:example.com");
+
+ auto megolmPlainText = json{
+ {"type", "m.room.message"},
+ {"room_id", "!foo:example.com"},
+ {"content", {
+ {"mew", "mew"}
+ }}
+ };
+ auto encryptedContent = a.encryptMegOlm(megolmPlainText);
+
+ auto encrypted = json{
+ {"event_id", "$1"},
+ {"origin_server_ts", 1234},
+ {"room_id", "!foo:example.com"},
+ {"content", encryptedContent},
+ };
+
+ decryptedOpt = a.decrypt(encrypted);
+ verify(decryptedOpt);
+
+ std::cout << json{
+ {"seeds", convert(seeds)},
+ {"oneTimeKeys1", k},
+ {"oneTimeKeys2", k2},
+ {"olmPlainText", origJson},
+ {"olmEncrypted1", encJson},
+ {"olmEncrypted2", encJson2},
+ {"megolmPlainText", megolmPlainText},
+ {"megolmEncrypted", encrypted},
+ {"aIdKey", aIdKey},
+ {"a", a.toJson()},
+ {"bIdKey", bIdKey},
+ {"b", b.toJson()},
+ }.dump();
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 6:32 PM (10 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39049
Default Alt Text
D157.1732329124.diff (10 KB)
Attached To
Mode
D157: Add generate-libolm-crypto-dump tool
Attached
Detach File
Event Timeline
Log In to Comment