Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113969
D157.1732499671.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D157.1732499671.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 @@
+{"a":{"account":"B1oFFRXEVZ4gOxukD6L3Qg+qcbLxs6PwGUnSA1nC7XCXFFUP+7ALzG+e1TMQs6PmXBgoQwHbIDaQzTBEMonMa7basPn9N+wG1yJ1loJ4V38+xFwowTMNoW836Rmd00WcYZzsqh4RA+NUclCJIhGB/bTKHLDXLea80j3pWbEVcJgX96RRAZVcVNkkLaxz9DkfsNQ7c1Z8RtLiHPiBL23guWS+riSjAvSL310J08fBLThVHw5u/oV2C2/5s22zHMK83/MCwqf4jzhEg0HbAG1Js6QuYMMIU3PEVPI06s9KLOx2dj8c/a/qazA/pP56wtpS2MOeyD+71EE6Fgu/4RMhOTAYRoXCDGxR","inboundGroupSessions":[[{"roomId":"!foo:example.com","sessionId":"c+I3OYLcgq6l/tPqK1zoUTlBoBuqx2R0t7XTMd8C8qM"},{"decryptedEvents":[0,{"eventId":"$1","originServerTs":1234}],"ed25519Key":"wKQXSqbPVhMrLoQIoKwy9Xx2BTrC40qxZjVynbu+404","session":"iuNeOLUojoNzx9yVAbzuJe+4Dm9DBR9834tvT37DTCJ2YwYQuKs/YT95/L2k/MLFi1bo+hLZVYB72Ccdu2VfrZmF2n7w1OEkv7VjAyiQcWAB882d66/uDtj6sGwUgGXrqpdzPMLJNlUL6wIChcow3G0PzIZNHRl4diEAditVnRjV81xp1/5eia7iZoB8/4NMvQQq+TKm+X2Knh907lWHWMz5RNhs0REtG66GCLqV9FLxvg2stAG/wArkAx5QNyBURiaJ+ZykcejFmUVL73uVTN88JR7vdqtPtnsxeEZekdhQJLIq6lQUEngp8sdGHNJMuVg11Kbd4nFVL63ty7TIY1ihGgPMaaxP+1JSPXuqagusmx/UutACe2YbnAmxQ1c2n+MX0J3e0ohh/hIC9JyOSICz2bAaZlRn","valid":true}]],"knownSessions":{"BwCDm5MhEXEBnmvJBybExex/WBA9qpxwRVVqiTzrSnM":{"data":"r1I8V4qsBmxI2XprDZwMKp9BdQ46OeWYLX2/PZTcgcAtKSTLmGfrf0KvEW3DyRci+mC8YpCJnADsBg9hmEMtOCIYaAA7V6iu/MG7KdnASOdcYqBisDz9P7/7Gv12+bCxmtOV3VrbberDRoiQuzqofYNKcIz51usLaecsfkALsL32qdg5+uSHbYYacNpYWcAbX9ccgvhTxmDf2S462clNM6IPuk2ysszEqtN4K5CFnEYI/a+QzF8t/TjtscXPpjRxgIooL6NA2O1z5FinOwlXNeEPi1ZDeFXFz9K1rS8KJAxLEs+StBC6jEizobBWql3hgXZ8M3tdo89La0CkKjMs7/zRUwwlTuvH7dxuvXSWp0TJ0JqDKe284IVixMzkaspQyZfQqZdQI/x6lKGsHLuUF8SJYIDbn2S1X++z7lqS+qG/YFBzYa/DgA","valid":true}},"numUnpublishedKeys":1,"outboundGroupSessions":{"!foo:example.com":{"creationTime":0,"initialSessionKey":"AgAAAABMSXg1LKCj9vjzTsBX4VnfwERzIKfh1YH3MYHNI+6eD328SrSnBOiN4rvCtH8yDVMSsUpfOj9DuJyx26G0EEmzbawYIbSXtCJ0qyIYMFhopsigemzuk0clZ6prp36piOSyWUzi8EKjt495uAwh3gNMl1MFFa9pEaMxhMhdjiMqF3PiNzmC3IKupf7T6itc6FE5QaAbqsdkdLe10zHfAvKjX6NcSCo07Ww1RwAqYE6UqKEMwb2xrTidoM15AXaS6RJ9R+r0uaQv2r4Zn30yEV4XcrtBTGRvwoVJHDExToSgCw","session":"uy5XSz5KAT1WO7HtNe8k/PxbwjLnR/OuMNM4R0WOn40j3hAChlXDyu3+SKLt8SilQgFM+xRFGDCSdsBbPh1CiCxtnZQpPxOs0EiTPp2mOWz58JYRmPnR9u6m1EVtTa5xNmMnIGNSSDjNmSe8iEcBRA5T48N1gvlPVece8RyA0tnj1vYEOaSlIKN4Gr8yw8PGH2cYnqLynN1L2Jl7xXbcvRSlnYWJaT/1MIde1FM2M7zeyqBO5DUjg7UK/O34SwNmdjTwxXMHeLOQSiyzYDX9n1u3VOnfGHvR/KHBbcedeZk6ybz9tQMS4uQWZseWmE0wDMftH0x7PeE","valid":true}},"uploadedOneTimeKeysCount":{},"valid":true},"aIdKey":"uZ4S7S9ctMyUYfqLA4WZD5BnitZFW4Df44SvC2uDPAs","b":{"account":"RYO5gwfVAjWsIKWI/3Lil3VgMnatK61K2xHYvUHn+po3LyXZXUC4O94AN/w/0pROg2T+DxDvAMGkvgnICBmh4KZmiXW4CZ/8ghLp2a59C8hqumx8TrQxHpUQOlGgRCaWw/Er4/hq6zpI144fwW4tv1MZVVH5mM6CRbMKm0HNRYgt03asgZjHcV8scu4iGjvalzdgy5hJZ+ltbTlynZOmfR5dQO8nX1x5QnCLX4UGoVzPPU7VygbQTw","inboundGroupSessions":[],"knownSessions":{"uZ4S7S9ctMyUYfqLA4WZD5BnitZFW4Df44SvC2uDPAs":{"data":"eVzVrQDp5Qqe+8RpOnUOQHBAp4iWOzOcdxGAzXj8nu085A/AmXc29JwaVA8FvLLtXsrYCJl57iQAKArwcMRm1t+mONm3NWwJ47xUi0vgTooMz2UwcIPM35bbQjIIoSxnzekL9fE1WfD9DvmzHHhRsuBa3ItlEFXoKU5PrBjym1aojeDTI7xmbGIubHgOdRBXgO1RNgi6QQduYMsHNOVwgbXt0Pt28HC1WS//fn54TiNsr/MzUROxho4GJM4i/VagjZtLvmGKy5mF9n7jz+7EW1nfp3Oq5bCAM+W2E3FngcEC7zEcQ4uw6mgmWoSkqHcYSrupPDlaSLhTnkPHsFaPOBfSEvPIev3b","valid":true}},"numUnpublishedKeys":0,"outboundGroupSessions":{},"uploadedOneTimeKeysCount":{},"valid":true},"bIdKey":"BwCDm5MhEXEBnmvJBybExex/WBA9qpxwRVVqiTzrSnM","seeds":{"construct1":"09+5R50uW6VrIXFT4xDxsZXsvPPSaRCEgqZCCffy4X8ee0ufD0z0y2wm8TFUEIclsCXN98BBBsdx32oUiyWRqA","construct2":"26TV5vqx7kgfBKUU42xIFZqDQ1V+IsRCzoMCSFC1yb3rG4rH2y/DhHJjad0oBLyoJOqn6AVhLlDrM26LwP1bsA","createOutbound":"Xm2Dc7QGroJsN8Lg9ISEHQQt1OTmQkxegw75/nh5KMWLRAfHGwVoAcciYVUGdjkXoG+beKNt2X5VaJ+EVZXD/Q","encryptOlm1":"k4cg5wT7K+Aw343n5s6JKKPvBzxhzh4PRi7ThOAa7eA","encryptOlm2":"VbPQeG/Dz0GC737thelfbtydOX4H3f8tqp2dDnpW9Eo","oneTimeKeys1":"VMDpOTs+KZvsA/M+BcDWhHyHp0wETQExavAseIELi5M","oneTimeKeys2":"XAdNFVxudQ6ojVHnVW365q6bEdoNGCjwzl+Wq82E1J4","rotateMegOlm1":"TEl4NSygo/b4807AV+FZ38BEcyCn4dWB9zGBzSPung99vEq0pwTojeK7wrR/Mg1TErFKXzo/Q7icsduhtBBJs22sGCG0l7QidKsiGDBYaKbIoHps7pNHJWeqa6d+qYjksllM4vBCo7ePebgMId4DTJdTBRWvaRGjMYTIXY4jKhenm69u/aTn2+rBXEYCF9IT2UMniHvMLV6h3TlYOLNbxA"}}
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,101 @@
+/*
+ * 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;
+}
+
+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 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);
+
+ seeds["encryptOlm2"] = genRandomData(Crypto::encryptOlmMaxRandomSize());
+ encryptedMsg = a.encryptOlmWithRandom(seeds["encryptOlm2"], origJson, bIdKey);
+
+ decryptedOpt = b.decrypt(encJson);
+
+ seeds["rotateMegOlm1"] = genRandomData(Crypto::rotateMegOlmSessionRandomSize());
+
+ a.rotateMegOlmSessionWithRandom(seeds["rotateMegOlm1"], 0, "!foo:example.com");
+
+ auto encrypted = a.encryptMegOlm(json{
+ {"type", "m.room.message"},
+ {"room_id", "!foo:example.com"},
+ {"content", {
+ {"mew", "mew"}
+ }}
+ });
+
+ decryptedOpt = a.decrypt(json{
+ {"event_id", "$1"},
+ {"origin_server_ts", 1234},
+ {"room_id", "!foo:example.com"},
+ {"content", encrypted},
+ });
+
+ std::cout << json{
+ {"seeds", convert(seeds)},
+ {"aIdKey", aIdKey},
+ {"a", a.toJson()},
+ {"bIdKey", bIdKey},
+ {"b", b.toJson()},
+ }.dump();
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 5:54 PM (10 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39983
Default Alt Text
D157.1732499671.diff (7 KB)
Attached To
Mode
D157: Add generate-libolm-crypto-dump tool
Attached
Detach File
Event Timeline
Log In to Comment