diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e93fe2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# emacs files +*~ +*\#* + +# object files +*.o + +# built binaries +keygen +keyinfo + +# private key files +*.dat \ No newline at end of file diff --git a/Makefile b/Makefile index 4837284..d638628 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,48 @@ +I2PD_PATH = i2pd CXX = g++ -CXXFLAGS = -g -Wall -std=c++11 -OBJECTS = keygen.o -INCFLAGS = -I"i2pd" +FLAGS = -g -Wall -std=c++11 +INCFLAGS = -I$(I2PD_PATH) +CXXFLAGS = $(FLAGS) $(INCFLAGS) LDFLAGS = -Wl,-rpath,/usr/local/lib -LIBS = i2pd/libi2pd.a -lboost_system -lboost_date_time -lboost_filesystem -lboost_program_options -lssl -lcrypto -lpthread -lrt -lz +LIBS = $(I2PD_PATH)/libi2pd.a -lboost_system -lboost_date_time -lboost_filesystem -lboost_program_options -lssl -lcrypto -lpthread -lrt -lz -all: keygen +SOURCES = $(wildcard *.cpp) +OBJECTS = $(SOURCES:.cpp=.o) +I2PD_LIB = libi2pd.a + + +all: keygen keyinfo keygen: $(OBJECTS) - $(CXX) -o keygen $(OBJECTS) $(LDFLAGS) $(LIBS) + $(CXX) -o keygen keygen.o $(LDFLAGS) $(LIBS) + +keyinfo: $(OBJECTS) + $(CXX) -o keyinfo keyinfo.o $(LDFLAGS) $(LIBS) + +$(OBJECTS): libi2pd.a .SUFFIXES: .SUFFIXES: .c .cc .C .cpp .o -.cpp.o : +$(I2PD_LIB): + $(MAKE) -C $(I2PD_PATH) mk_obj_dir $(I2PD_LIB) + +%.o: %.cpp libi2pd.a $(CXX) -o $@ -c $(CXXFLAGS) $< $(INCFLAGS) count: wc *.c *.cc *.C *.cpp *.h *.hpp -clean: - rm -f *.o keygen +clean-i2pd: + $(MAKE) -C $(I2PD_PATH) clean + +clean-obj: + rm -f $(OBJECTS) + +clean-bin: + rm -f keyinfo keygen + +clean: clean-i2pd clean-obj clean-bin .PHONY: all .PHONY: count diff --git a/README.md b/README.md new file mode 100644 index 0000000..eed44f5 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# i2pd-tools + +This repository contains tools that supplement i2pd. + +Notice: git submodules are used so make sure to clone this repository recursively + + git clone --recursive https://github.com/purplei2pd/i2pd-tools + +## Tools included + +### keygen + +Generate an i2p private key + + +### keyinfo + +Prints information about an i2p private key diff --git a/keyinfo.cpp b/keyinfo.cpp new file mode 100644 index 0000000..6b6689c --- /dev/null +++ b/keyinfo.cpp @@ -0,0 +1,70 @@ +#include "Identity.h" +#include +#include +#include +#include +#include + +int main(int argc, char * argv[]) +{ + if(argc == 1) { + std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; + return -1; + } + int opt; + bool print_full = false; + bool verbose = false; + while((opt = getopt(argc, argv, "vd"))!=-1) { + switch(opt){ + case 'v': + verbose = true; + break; + case 'd': + print_full = true; + break; + default: + std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; + return -1; + } + } + std::string fname(argv[optind]); + i2p::data::PrivateKeys keys; + { + std::vector buff; + std::ifstream inf; + inf.open(fname); + if (!inf.is_open()) { + std::cout << "cannot open private key file " << fname << std::endl; + return 2; + } + inf.seekg(0, std::ios::end); + const std::size_t len = inf.tellg(); + inf.seekg(0, std::ios::beg); + buff.resize(len); + inf.read((char*)buff.data(), buff.size()); + if (!keys.FromBuffer(buff.data(), buff.size())) { + std::cout << "bad key file format" << std::endl; + return 3; + } + } + auto dest = keys.GetPublic(); + if(!dest) { + std::cout << "failed to extract public key" << std::endl; + return 3; + } + + const auto & ident = dest->GetIdentHash(); + if (verbose) { + std::cout << "Destination: " << dest->ToBase64() << std::endl; + std::cout << "Destination Hash: " << ident.ToBase64() << std::endl; + std::cout << "B32 Address: " << ident.ToBase32() << ".b32.i2p" << std::endl; + std::cout << "Signature Type: " << (int) dest->GetSigningKeyType() << std::endl; + std::cout << "Encryption Type: " << (int) dest->GetCryptoKeyType() << std::endl; + } else { + if(print_full) { + std::cout << dest->ToBase64() << std::endl; + } else { + std::cout << ident.ToBase32() << ".b32.i2p" << std::endl; + } + } +}