Browse Source

Merge pull request #1 from majestrate/master

merge recent changes
pull/2/head
Jeff 8 years ago committed by GitHub
parent
commit
c48948d6d6
  1. 13
      .gitignore
  2. 40
      Makefile
  3. 59
      README.md
  4. 69
      common/key.hpp
  5. 10
      keygen.cpp
  6. 72
      keyinfo.cpp

13
.gitignore vendored

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
# emacs files
*~
*\#*
# object files
*.o
# built binaries
keygen
keyinfo
# private key files
*.dat

40
Makefile

@ -1,26 +1,48 @@ @@ -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

59
README.md

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
# 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
#### Usage
Make a DSA-SHA1 destination key
./keygen privkey.dat
Make an destination key with a certain key type
./keygen privkey.dat <number>
or
./keygen privkey.dat <key name>
| key name | number |
| -------------------- | ------ |
| DSA-SHA1 | 0 |
| ECDSA-SHA256-P256 | 1 |
| ECDSA-SHA384-P384 | 2 |
| ECDSA-SHA512-P521 | 3 |
| RSA-SHA256-2048 | 4 |
| RSA-SHA384-3072 | 5 |
| RSA-SHA512-4096 | 6 |
| EDDSA-SHA512-ED25519 | 7 |
### keyinfo
Prints information about an i2p private key
#### Usage
Print just the b32 address for this key
./keyinfo privatekey.dat
... just the base64 address
./keyinfo -d privatekey.dat
Print all info about the public key
./keyinfo -v privatekey.dat

69
common/key.hpp

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
#ifndef I2PD_TOOLS_COMMON_KEY_HPP
#define I2PD_TOOLS_COMMON_KEY_HPP
#include "Identity.h"
#include <algorithm>
#include <cctype>
#include <sstream>
#include <string>
/** @brief returns string representation of a signing key type */
std::string SigTypeToName(uint16_t keytype)
{
switch(keytype) {
case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1:
return "DSA-SHA1";
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256:
return "ECDSA-P256";
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384:
return "ECDSA-P384";
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521:
return "ECDSA-P521";
case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048:
return "RSA-2048-SHA256";
case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072:
return "RSA-3072-SHA384";
case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096:
return "RSA-4096-SHA512";
case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
return "ED25519-SHA512";
default:
std::stringstream ss;
ss << "unknown: " << keytype;
return ss.str();
}
}
/** @brief make string uppercase */
static void ToUpper(std::string & str)
{
std::transform(str.begin(), str.end(), str.begin(), [] (uint8_t ch) {
return std::toupper(ch);
});
}
/** @brief returns the signing key number given its name or -1 if there is no key of that type */
uint16_t NameToSigType(const std::string & keyname)
{
if(keyname.size() == 1) return atoi(keyname.c_str());
std::string name = keyname;
ToUpper(name);
auto npos = std::string::npos;
if(name.find("DSA") == 0) return i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
if(name.find("P256") != npos) return i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256;
if(name.find("P384") != npos) return i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384;
if(name.find("RSA-SHA265") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048;
if(name.find("RSA-SHA384") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072;
if(name.find("RSA-SHA512") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096;
if(name.find("ED25519") != npos) return i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519;
return -1;
}
#endif

10
keygen.cpp

@ -3,17 +3,21 @@ @@ -3,17 +3,21 @@
#include <stdlib.h>
#include "Crypto.h"
#include "Identity.h"
#include "common/key.hpp"
int main (int argc, char * argv[])
{
if (argc < 3)
if (argc < 2)
{
std::cout << "Usage: keygen filename <signuture type>" << std::endl;
std::cout << "Usage: keygen filename <signature type>" << std::endl;
return -1;
}
i2p::crypto::InitCrypto (false);
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
if (argc >= 3) type = atoi (argv[2]);
if (argc > 2) {
std::string str(argv[2]);
type = NameToSigType(str);
}
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (type);
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);
if (f)

72
keyinfo.cpp

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
#include "Identity.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <unistd.h>
#include "common/key.hpp"
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<uint8_t> 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: " << SigTypeToName(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;
}
}
}
Loading…
Cancel
Save