diff --git a/Makefile b/Makefile index 84743bf..57e36cf 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ OBJECTS = $(SOURCES:.cpp=.o) I2PD_LIB = libi2pd.a -all: keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys b33address +all: keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys b33address regaddralias routerinfo: $(OBJECTS) $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) @@ -76,6 +76,9 @@ offlinekeys: $(OBJECTS) b33address: $(OBJECTS) $(CXX) -o b33address b33address.o $(LDFLAGS) $(LIBS) +regaddralias: $(OBJECTS) + $(CXX) -o regaddralias regaddralias.o $(LDFLAGS) $(LIBS) + $(OBJECTS): libi2pd.a .SUFFIXES: @@ -97,7 +100,7 @@ clean-obj: rm -f $(OBJECTS) clean-bin: - rm -f keyinfo keygen famtool regaddr regaddr_3ld routerinfo i2pbase64 vain offlinekeys b33address + rm -f keyinfo keygen famtool regaddr regaddr_3ld routerinfo i2pbase64 vain offlinekeys b33address changeaddr clean: clean-i2pd clean-obj clean-bin diff --git a/regaddralias.cpp b/regaddralias.cpp new file mode 100644 index 0000000..40d2cbb --- /dev/null +++ b/regaddralias.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include "Identity.h" +#include "Base.h" + +int main (int argc, char * argv[]) +{ + if (argc < 3) + { + std::cout << "Usage: regaddralias oldfilename newfilename address" << std::endl; + return -1; + } + + i2p::crypto::InitCrypto (false, true, true, false); + + i2p::data::PrivateKeys oldkeys, newkeys; + { + std::ifstream s(argv[1], 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(!oldkeys.FromBuffer (buf, len)) + { + std::cout << "Failed to load keyfile " << argv[1] << std::endl; + return -1; + } + delete[] buf; + } + else + { + std::cout << "Cab't open keyfile " << argv[1] << std::endl; + return -1; + } + } + + { + 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(!newkeys.FromBuffer (buf, len)) + { + std::cout << "Failed to load keyfile " << argv[2] << std::endl; + return -1; + } + delete[] buf; + } + else + { + std::cout << "Cab't open keyfile " << argv[2] << std::endl; + return -1; + } + } + + std::stringstream out; + out << argv[3] << "="; // address + out << newkeys.GetPublic ()->ToBase64 (); + out << "#!action=adddest#olddest="; + out << oldkeys.GetPublic ()->ToBase64 (); + + auto oldSignatureLen = oldkeys.GetPublic ()->GetSignatureLen (); + uint8_t * oldSignature = new uint8_t[oldSignatureLen]; + 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; + out << "#oldsig=" << oldSig; + delete[] oldSignature; + delete[] oldSig; + + auto signatureLen = newkeys.GetPublic ()->GetSignatureLen (); + uint8_t * signature = new uint8_t[signatureLen]; + 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; + out << "#sig=" << sig; + delete[] signature; + delete[] sig; + + std::cout << out.str () << std::endl; + + i2p::crypto::TerminateCrypto (); + + return 0; +}