From 166ccc7a367877a87eb7bb76ee96ec4f560561a6 Mon Sep 17 00:00:00 2001 From: r4sas Date: Wed, 29 Aug 2018 21:52:56 +0000 Subject: [PATCH] implement 3LD authentification string generator for stats.i2p --- Makefile | 7 ++- README.md | 13 +++++ regaddr_3ld.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 regaddr_3ld.cpp diff --git a/Makefile b/Makefile index 7ca8bda..c41be85 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ OBJECTS = $(SOURCES:.cpp=.o) I2PD_LIB = libi2pd.a -all: keygen keyinfo famtool routerinfo regaddr vain i2pbase64 +all: keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 routerinfo: $(OBJECTS) $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) @@ -55,6 +55,9 @@ famtool: $(OBJECTS) regaddr: $(OBJECTS) $(CXX) -o regaddr regaddr.o $(LDFLAGS) $(LIBS) +regaddr_3ld: $(OBJECTS) + $(CXX) -o regaddr_3ld regaddr_3ld.o $(LDFLAGS) $(LIBS) + vain: $(OBJECTS) $(CXX) -o vain vanitygen.o $(LDFLAGS) $(LIBS) @@ -82,7 +85,7 @@ clean-obj: rm -f $(OBJECTS) clean-bin: - rm -f keyinfo keygen famtool regaddr routerinfo i2pbase64 vain + rm -f keyinfo keygen famtool regaddr regaddr_3ld routerinfo i2pbase64 vain clean: clean-i2pd clean-obj clean-bin diff --git a/README.md b/README.md index 2e98330..778084b 100644 --- a/README.md +++ b/README.md @@ -127,3 +127,16 @@ Print just the b32 address for this key Print all info about the public key ./keyinfo -v privatekey.dat + +### regaddr_3ld + +Generate authentication string for stats.i2p in 3 steps + +#### + + ./regaddr_3ld step1 sub_domain.dat sub.domain.i2p > step1.txt + ./regaddr_3ld step2 step1.txt domain.dat domain.i2p > step2.txt + ./regaddr_3ld step3 step2.txt sub_domain.dat > step3.txt + cat step3.txt + +Send output from step3 to http://stats.i2p/i2p/addkey.html to register subdomain on stats.i2p diff --git a/regaddr_3ld.cpp b/regaddr_3ld.cpp new file mode 100644 index 0000000..4c94b09 --- /dev/null +++ b/regaddr_3ld.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include "Identity.h" +#include "Base.h" + +static void help () +{ + std::cout << "Usage:" << std::endl; + std::cout << "\treg3ldaddr step1 privkey address" << std::endl; + std::cout << "\treg3ldaddr step2 step1file oldprivkey oldaddress" << std::endl; + std::cout << "\treg3ldaddr step3 step2file privkey" << std::endl; +} + +int main (int argc, char * argv[]) +{ + if (argc < 3) { help(); return -1;} + std::string arg = argv[1]; + + i2p::crypto::InitCrypto (false); + i2p::data::PrivateKeys keys; + + if (arg == "step1") { + std::ifstream s(argv[2], std::ifstream::binary); + if (s.is_open ()) { + s.seekg (0, std::ios::end); + size_t len = s.tellg(); + s.seekg (0, std::ios::beg); + uint8_t * buf = new uint8_t[len]; + s.read ((char *)buf, len); + if(keys.FromBuffer (buf, len)) { + std::stringstream out; + out << argv[3] << "="; // address + out << keys.GetPublic ()->ToBase64 (); + out << "#!action=addsubdomain"; + std::cout << out.str () << std::endl; + } else + std::cout << "Failed to load keyfile " << argv[1] << std::endl; + delete[] buf; + } + } + else if (arg == "step2") { + std::ifstream t(argv[2]); + std::ifstream s(argv[3], std::ifstream::binary); + std::string regtxt; + std::stringstream out; + + if (t.is_open ()) { + while (t.good()) { + getline (t, regtxt); + out << regtxt; + } + t.close(); + } else { + std::cout << "Failed to read file with STEP1 output"; + exit(1); + } + + if (s.is_open ()) { + s.seekg (0, std::ios::end); + size_t len = s.tellg(); + s.seekg (0, std::ios::beg); + uint8_t * buf = new uint8_t[len]; + s.read ((char *)buf, len); + if(keys.FromBuffer (buf, len)) { + auto signatureLen = keys.GetPublic ()->GetSignatureLen (); + uint8_t * signature = new uint8_t[signatureLen]; + 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; + out << "#oldsig=" << sig; + delete[] signature; + delete[] sig; + std::cout << out.str () << std::endl; + } else + std::cout << "Failed to load keyfile " << argv[1] << std::endl; + delete[] buf; + } + } + else if (arg == "step3") { + std::ifstream t(argv[2]); + std::ifstream s(argv[3], std::ifstream::binary); + std::string regtxt; + std::stringstream out; + + if (t.is_open ()) { + while (t.good()) { + getline (t, regtxt); + out << regtxt; + } + t.close(); + } else { + std::cout << "Failed to read file with STEP2 output"; + exit(1); + } + + if (s.is_open ()) { + s.seekg (0, std::ios::end); + size_t len = s.tellg(); + s.seekg (0, std::ios::beg); + uint8_t * buf = new uint8_t[len]; + s.read ((char *)buf, len); + if(keys.FromBuffer (buf, len)) { + auto signatureLen = keys.GetPublic ()->GetSignatureLen (); + uint8_t * signature = new uint8_t[signatureLen]; + 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; + out << "#sig=" << sig; + delete[] signature; + delete[] sig; + std::cout << out.str () << std::endl; + } else + std::cout << "Failed to load keyfile " << argv[1] << std::endl; + delete[] buf; + } + } + else { + help(); exit(1); + } + + i2p::crypto::TerminateCrypto (); + return 0; +}