Jeff
8 years ago
committed by
GitHub
6 changed files with 251 additions and 12 deletions
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
# emacs files |
||||
*~ |
||||
*\#* |
||||
|
||||
# object files |
||||
*.o |
||||
|
||||
# built binaries |
||||
keygen |
||||
keyinfo |
||||
|
||||
# private key files |
||||
*.dat |
@ -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 |
@ -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 |
@ -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…
Reference in new issue