From c8c8c462b9e6b940e1545695b82631cc684930e6 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Thu, 21 Aug 2025 04:30:28 +0700 Subject: [PATCH 1/5] fix: pre init fixes, not tested --- famtool.cpp | 19 ++++++++++-------- i2pbase64.cpp | 53 +++++++++++++++++++++++++++++-------------------- i2pd | 2 +- regaddr.cpp | 8 ++++---- regaddr_3ld.cpp | 16 +++++++-------- verifyhost.cpp | 5 +++-- x25519.cpp | 10 +++++----- 7 files changed, 63 insertions(+), 50 deletions(-) diff --git a/famtool.cpp b/famtool.cpp index 0a40689..30d6d17 100644 --- a/famtool.cpp +++ b/famtool.cpp @@ -74,7 +74,7 @@ static std::shared_ptr LoadCertificate (const std::string& filename) bn2buf (y, signingKey + 32, 32); BN_free (x); BN_free (y); verifier = std::make_shared(); - verifier->SetPublicKey (signingKey); + verifier->SetPublicKey (signingKey); } } EC_KEY_free (ecKey); @@ -113,11 +113,11 @@ static bool CreateFamilySignature (const std::string& family, const IdentHash& i len += 32; signer.Sign (buf, len, signature); len = Base64EncodingBufferSize (64); - char * b64 = new char[len+1]; - len = ByteStreamToBase64 (signature, 64, b64, len); - b64[len] = 0; + //char * b64 = new char[len+1]; + auto b64 = ByteStreamToBase64 (signature, len); + //b64[len] = 0; sig = b64; - delete[] b64; + //delete[] b64; } else return false; @@ -383,9 +383,12 @@ int main(int argc, char * argv[]) memcpy(buf, fam.c_str(), len); memcpy(buf + len, (const uint8_t *) ident, 32); len += 32; - uint8_t sigbuf[64]; - Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64); - if(!v->Verify(buf, len, sigbuf)) { + //uint8_t sigbuf[64]; + auto b64 = ByteStreamToBase64(reinterpret_cast(sig.c_str()), sig.length()); + + //Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64); + if (!v->Verify(buf, len, + reinterpret_cast(b64.data()))) { std::cout << "invalid signature" << std::endl; return 1; } diff --git a/i2pbase64.cpp b/i2pbase64.cpp index 1734365..ad3c4ba 100644 --- a/i2pbase64.cpp +++ b/i2pbase64.cpp @@ -14,26 +14,35 @@ static int printHelp(const char * exe, int exitcode) return exitcode; } -template -static int operate(std::function f, int infile, int outfile) -{ - InCh inbuf[isz]; - OutCh outbuf[osz]; - ssize_t sz; - size_t outsz; - while((sz = read(infile, inbuf, sizeof(inbuf))) > 0) - { - outsz = f(inbuf, sz, outbuf, sizeof(outbuf)); - if(outsz && outsz <= sizeof(outbuf)) - { - write(outfile, outbuf, outsz); - } - else - { - return -1; - } - } - return errno; +int operate_b64_decode(int infile, int outfile) { + constexpr size_t BUFFSZ = 4096; + char inbuf[BUFFSZ*4]; + uint8_t outbuf[BUFFSZ*3]; + ssize_t sz; + while ((sz = read(infile, inbuf, sizeof(inbuf))) > 0) { + std::string_view chunk(inbuf, sz); + + size_t outsz = i2p::data::Base64ToByteStream(chunk, outbuf, sizeof(outbuf)); + if (outsz > 0) { + write(outfile, outbuf, outsz); + } else { + return -1; + } + } + return errno; +} + + +int operate_b64_encode(int infile, int outfile) { + constexpr size_t BUFFSZ = 4096; + uint8_t inbuf[BUFFSZ*3]; + //char outbuf[BUFFSZ*4]; + ssize_t sz; + while((sz = read(infile, inbuf, sizeof(inbuf))) > 0) { + std::string out = i2p::data::ByteStreamToBase64(inbuf, sz); + write(outfile, out.data(), out.size()); + } + return errno; } int main(int argc, char * argv[]) @@ -71,11 +80,11 @@ int main(int argc, char * argv[]) int retcode = 0; if(decode) { - retcode = operate(i2p::data::Base64ToByteStream, infile, 1); + retcode = operate_b64_decode(infile, 1); } else { - retcode = operate(&i2p::data::ByteStreamToBase64, infile, 1); + retcode = operate_b64_encode(infile, 1); } close(infile); return retcode; diff --git a/i2pd b/i2pd index dcd15cc..de14e81 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit dcd15cc2449d6320de6351054e61ef2ee7ebee40 +Subproject commit de14e81f50e24b78eb3b190cd4f1ca8514bc4e64 diff --git a/regaddr.cpp b/regaddr.cpp index 6dbf1fd..84f14af 100644 --- a/regaddr.cpp +++ b/regaddr.cpp @@ -29,16 +29,16 @@ int main (int argc, char * argv[]) { auto signatureLen = keys.GetPublic ()->GetSignatureLen (); uint8_t * signature = new uint8_t[signatureLen]; - char * sig = new char[signatureLen*2]; + //char * sig = new char[signatureLen*2]; std::stringstream out; out << argv[2] << "="; // address out << keys.GetPublic ()->ToBase64 (); keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature); - auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2); - sig[len] = 0; + auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2); + //sig[len] = 0; out << "#!sig=" << sig; delete[] signature; - delete[] sig; + //delete[] sig; std::cout << out.str () << std::endl; } else diff --git a/regaddr_3ld.cpp b/regaddr_3ld.cpp index 4c94b09..918c8a3 100644 --- a/regaddr_3ld.cpp +++ b/regaddr_3ld.cpp @@ -66,16 +66,16 @@ int main (int argc, char * argv[]) if(keys.FromBuffer (buf, len)) { auto signatureLen = keys.GetPublic ()->GetSignatureLen (); uint8_t * signature = new uint8_t[signatureLen]; - char * sig = new char[signatureLen*2]; + //char * sig = new char[signatureLen*2]; out << "#date=" << std::time(nullptr); out << "#olddest=" << keys.GetPublic ()->ToBase64 (); out << "#oldname=" << argv[4]; keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature); - auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2); - sig[len] = 0; + auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2); + //sig[len] = 0; out << "#oldsig=" << sig; delete[] signature; - delete[] sig; + //delete[] sig; std::cout << out.str () << std::endl; } else std::cout << "Failed to load keyfile " << argv[1] << std::endl; @@ -108,13 +108,13 @@ int main (int argc, char * argv[]) if(keys.FromBuffer (buf, len)) { auto signatureLen = keys.GetPublic ()->GetSignatureLen (); uint8_t * signature = new uint8_t[signatureLen]; - char * sig = new char[signatureLen*2]; + //char * sig = new char[signatureLen*2]; keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature); - auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2); - sig[len] = 0; + auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2); + //sig[len] = 0; out << "#sig=" << sig; delete[] signature; - delete[] sig; + //delete[] sig; std::cout << out.str () << std::endl; } else std::cout << "Failed to load keyfile " << argv[1] << std::endl; diff --git a/verifyhost.cpp b/verifyhost.cpp index 52c4cff..4e843b4 100644 --- a/verifyhost.cpp +++ b/verifyhost.cpp @@ -51,7 +51,8 @@ int main (int argc, char * argv[]) uint8_t * signature = new uint8_t[signatureLen]; // validate signature - i2p::data::Base64ToByteStream(sig.c_str (), sig.length(), signature, signatureLen); + // size_t Base64ToByteStream (std::string_view base64Str, uint8_t * OutBuffer, size_t len); + i2p::data::Base64ToByteStream(sig, signature, signatureLen); if (!Identity.Verify ((uint8_t *)hostNoSig.c_str (), hostNoSig.length (), signature)) { std::cout << "Invalid destination signature." << std::endl; @@ -85,7 +86,7 @@ int main (int argc, char * argv[]) std::string oldSig = oldSigCut.substr (0, pos); // validate signature - i2p::data::Base64ToByteStream(oldSig.c_str (), oldSig.length(), signature, signatureLen); + i2p::data::Base64ToByteStream(oldSig, signature, signatureLen); bool oldSignValid = OldIdentity.Verify ((uint8_t *)hostNoOldSig.c_str (), hostNoOldSig.length (), signature); if(!oldSignValid) diff --git a/x25519.cpp b/x25519.cpp index 4a93b1e..44ea748 100644 --- a/x25519.cpp +++ b/x25519.cpp @@ -57,17 +57,17 @@ int main(int argc, char * argv[]) BoxKeys newKeys = getKeyPair(); - const size_t len_out = 50; - char b64Public[len_out] = {0}; - char b64Private[len_out] = {0}; + //const size_t len_out = 50; + //char b64Public[len_out] = {0}; + //char b64Private[len_out] = {0}; - i2p::data::ByteStreamToBase64 (newKeys.PublicKey, len, b64Public, len_out); + auto b64Public = i2p::data::ByteStreamToBase64 (newKeys.PublicKey, len);//, b64Public, len_out); std::cout << "PublicKey: "; for (int i = 0; b64Public[i] != 0; ++i) std::cout << b64Public[i]; - i2p::data::ByteStreamToBase64 (newKeys.PrivateKey, len, b64Private, len_out); + auto b64Private = i2p::data::ByteStreamToBase64 (newKeys.PrivateKey, len);//, b64Private, len_out); std::cout << "\nPrivateKey: "; for (int i = 0; b64Private[i] != 0; ++i) From 570bad5af4b3911c36d59bc568bb446e257c7799 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Thu, 21 Aug 2025 04:33:18 +0700 Subject: [PATCH 2/5] fix: pre init fix not tested --- regaddralias.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/regaddralias.cpp b/regaddralias.cpp index cc56bc0..1f22cdf 100644 --- a/regaddralias.cpp +++ b/regaddralias.cpp @@ -69,23 +69,23 @@ int main (int argc, char * argv[]) auto oldSignatureLen = oldkeys.GetPublic ()->GetSignatureLen (); uint8_t * oldSignature = new uint8_t[oldSignatureLen]; - char * oldSig = new char[oldSignatureLen*2]; + //char * oldSig = new char[oldSignatureLen*2]; oldkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), oldSignature); - auto len = i2p::data::ByteStreamToBase64 (oldSignature, oldSignatureLen, oldSig, oldSignatureLen*2); - oldSig[len] = 0; + auto oldSig = i2p::data::ByteStreamToBase64 (oldSignature, oldSignatureLen);//, oldSig, oldSignatureLen*2); + //oldSig[len] = 0; out << "#oldsig=" << oldSig; delete[] oldSignature; - delete[] oldSig; + //delete[] oldSig; auto signatureLen = newkeys.GetPublic ()->GetSignatureLen (); uint8_t * signature = new uint8_t[signatureLen]; - char * sig = new char[signatureLen*2]; + //char * sig = new char[signatureLen*2]; newkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature); - len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2); - sig[len] = 0; + auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2); + //sig[len] = 0; out << "#sig=" << sig; delete[] signature; - delete[] sig; + //delete[] sig; std::cout << out.str () << std::endl; From a73b83bd2adb8f1dd2b1dabb09b6343c22c3bf8e Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Thu, 21 Aug 2025 04:42:03 +0700 Subject: [PATCH 3/5] fix: i2pbase64.cpp fix --- i2pbase64.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/i2pbase64.cpp b/i2pbase64.cpp index ad3c4ba..0c402ec 100644 --- a/i2pbase64.cpp +++ b/i2pbase64.cpp @@ -21,8 +21,10 @@ int operate_b64_decode(int infile, int outfile) { ssize_t sz; while ((sz = read(infile, inbuf, sizeof(inbuf))) > 0) { std::string_view chunk(inbuf, sz); + std::string s(chunk); + s.erase(std::remove(s.begin(), s.end(), '\n'), s.end()); - size_t outsz = i2p::data::Base64ToByteStream(chunk, outbuf, sizeof(outbuf)); + size_t outsz = i2p::data::Base64ToByteStream(s, outbuf, sizeof(outbuf)); if (outsz > 0) { write(outfile, outbuf, outsz); } else { From fcf00638baddcdbc6715b277c1abd8f48b6a7901 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Thu, 21 Aug 2025 04:43:45 +0700 Subject: [PATCH 4/5] i2pbase64 documentation --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 8fcaa27..208ee47 100755 --- a/README.md +++ b/README.md @@ -35,6 +35,20 @@ make ## Tools included +### i2pbase64 + +encode/decode b64 string +example usage: +``` +user@computer:~/i2pd-tools$ ./i2pbase64 +encode +ZW5jb2RlCg==^C +user@computer:~/i2pd-tools$ ./i2pbase64 -d +ZW5jb2RlCg== +encode +``` +U also can use file + ### routerinfo print information about a router info file From 50f1df57bb5732d12504ecc9d156ddfe643d93f8 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Thu, 21 Aug 2025 04:57:30 +0700 Subject: [PATCH 5/5] feat: verifyhost to README.md --- README.md | 16 ++++++++++++++++ verifyhost.cpp | 2 ++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 208ee47..038b35e 100755 --- a/README.md +++ b/README.md @@ -35,6 +35,22 @@ make ## Tools included +### verifyhost +#### Example usage +```bash +# Valid destination with old destination signature +./verifyhost 'test12356.i2p=7qYyu4ZkY5ixxLTUn6RF-LvX7YlFZGcpGQPJITq7NieLKW-pwJuyxz7Ga06HzNwieLackwmBVsbizzPHffFXiwqwTcsTbjZvYdRs4oEyCg1V1qoEMaQXHZkwhcIZ0DVFEkscytDy327C9-x5gH0d2lNdrVf2k2dmWKU3hUMSqYRHHOHgJyGIHF8bv4nPCaUjVu9gL6g1Nzfxf5mEwx1-vIsV3NW83Pe9fpXaoqQ~zOXKZ-rOz8h4yfHJ7WKARxEFaUNALa6Kkm4~FOctB6aV05Meh~OW7GzM~ZUalguaDpGkqbOr~mK8b6o8gzOJTWUOku4jHmVeD9doePudAxygPhahZt5j5bCNPSezCCa6DVbLCqJLQr6uK0izlJnrsYnYFqFm3mPlsI09J7MIJroNVssKoktCvq4rSLOUmeuxidhCkv18Y-WwjT0nswgmug1WywqiS0K-ritIs5SZ67GJ2Oshc-W7rUv86yoFksGfsXaeBzGiKX9i0R~UqcxTsjRjBQAEAAcAAA==#!action=adddest#olddest=GcxIh28qJRLIBfZ3AO~-hQdZhJhYM93zeODGYXyzPBE~gQmIYTbw84d~kwQXzzWDvqgpTmwYlqejUiGWOGXTrfPlByoWpKwUf-1Oe~kARvSwWLCpyuAPDNAMm~xTxexsjZ4Ry7Ad7IlxCrlQgBVus6l2t7ZznHa1OPIJh-zMzXoX9DNQpvSVdVYMXXKguQr4HFSa2LVQkPXrVrqXLMj1QDmFrXEwZAhWujntVstCoC8u00B6xhQSqTsvHhca63ZYkge78SNILbpWQQKb7XbjJKkQS99tLFbG-KSERm5YrP61PdF25TIUsiFN7i07HkseUTGMbuwHsfFp6-uXYMK2gz9Vyv0kXYu0ahoTEUJmC0DbYsLGpkF7UI1hWp43eWmWP1XK~SRdi7RqGhMRQmYLQNtiwsamQXtQjWFanjd5aZYwl8r9JF2LtGoaExFCZgtA22LCxqZBe1CNYVqeN3lplr8ep7m~ZwjgWrnjuxEVY52zLnp8oiVo1Hstf~F8w22KBQAEAAcAAA==' +Valid destination + +# Destination with missing old signature +./verifyhost 'test123456.i2p=GcxIh28qJRLIBfZ3AO~-hQdZhJhYM93zeODGYXyzPBE~gQmIYTbw84d~kwQXzzWDvqgpTmwYlqejUiGWOGXTrfPlByoWpKwUf-1Oe~kARvSwWLCpyuAPDNAMm~xTxexsjZ4Ry7Ad7IlxCrlQgBVus6l2t7ZznHa1OPIJh-zMzXoX9DNQpvSVdVYMXXKguQr4HFSa2LVQkPXrVrqXLMj1QDmFrXEwZAhWujntVstCoC8u00B6xhQSqTsvHhca63ZYkge78SNILbpWQQKb7XbjJKkQS99tLFbG-KSERm5YrP61PdF25TIUsiFN7i07HkseUTGMbuwHsfFp6-uXYMK2gz9Vyv0kXYu0ahoTEUJmC0DbYsLGpkF7UI1hWp43eWmWP1XK~SRdi7RqGhMRQmYLQNtiwsamQXtQjWFanjd5aZYwl8r9JF2LtGoaExFCZgtA22LCxqZBe1CNYVqeN3lplr8ep7m~ZwjgWrnjuxEVY52zLnp8oiVo1Hstf~F8w22KBQAEAAcAAA==#!action=addsubdomain' +Destination signature not found. + +# Invalid signature +./verifyhost 'test.i2p=GcxIh28qJRLIBfZ3AO~-hQdZhJhYM93zeODGYXyzPBE~gQmIYTbw84d~kwQXzzWDvqgpTmwYlqejUiGWOGXTrfPlByoWpKwUf-1Oe~kARvSwWLCpyuAPDNAMm~xTxexsjZ4Ry7Ad7IlxCrlQgBVus6l2t7ZznHa1OPIJh-zMzXoX9DNQpvSVdVYMXXKguQr4HFSa2LVQkPXrVrqXLMj1QDmFrXEwZAhWujntVstCoC8u00B6xhQSqTsvHhca63ZYkge78SNILbpWQQKb7XbjJKkQS99tLFbG-KSERm5YrP61PdF25TIUsiFN7i07HkseUTGMbuwHsfFp6-uXYMK2gz9Vyv0kXYu0ahoTEUJmC0DbYsLGpkF7UI1hWp43eWmWP1XK~SRdi7RqGhMRQmYLQNtiwsamQXtQjWFanjd5aZYwl8r9JF2LtGoaExFCZgtA22LCxqZBe1CNYVqeN3lplr8ep7m~ZwjgWrnjuxEVY52zLnp8oiVo1Hstf~F8w22KBQAEAAcAAA==#!sig=0CiP4rB3x2EVmTMzlXBseUUnjENO900OLaw5Db5ylQwXYcnbmSbVoiR2nxNrjBqrdMOTDF8G-Ps2Wuv-TZ5yDA2=' +Invalid destination signature +``` + ### i2pbase64 encode/decode b64 string diff --git a/verifyhost.cpp b/verifyhost.cpp index 4e843b4..acb63cc 100644 --- a/verifyhost.cpp +++ b/verifyhost.cpp @@ -93,6 +93,8 @@ int main (int argc, char * argv[]) { std::cout << "Invalid old destination signature." << std::endl; return 1; + } else { + std::cout << "Valid destination" << std::endl; } } }