Browse Source

pretty print sig key types

pull/1/head
Jeff Becker 8 years ago
parent
commit
bb9dda6ba9
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 72
      common/key.hpp
  2. 8
      keygen.cpp
  3. 4
      keyinfo.cpp

72
common/key.hpp

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
#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("RSA2048") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048;
if(name.find("RSA-2048") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048;
if(name.find("RSA3072") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072;
if(name.find("RSA-3072") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072;
if(name.find("RSA4096") != npos) return i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096;
if(name.find("RSA-4096") != 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

8
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 < 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)

4
keyinfo.cpp

@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
#include <string>
#include <vector>
#include <unistd.h>
#include "common/key.hpp"
int main(int argc, char * argv[])
{
@ -58,7 +60,7 @@ int main(int argc, char * argv[]) @@ -58,7 +60,7 @@ int main(int argc, char * argv[])
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 << "Signature Type: " << SigTypeToName(dest->GetSigningKeyType()) << std::endl;
std::cout << "Encryption Type: " << (int) dest->GetCryptoKeyType() << std::endl;
} else {
if(print_full) {

Loading…
Cancel
Save