You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
#include <iostream> |
|
#include <fstream> |
|
#include <stdlib.h> |
|
#include <inttypes.h> |
|
#include "Crypto.h" |
|
#include "Identity.h" |
|
#include "Timestamp.h" |
|
#include "common/key.hpp" |
|
|
|
int main (int argc, char * argv[]) |
|
{ |
|
if (argc < 3) |
|
{ |
|
std::cout << "Usage: offlinekeys <output file> <keys file> <signature type> <days>" << std::endl; |
|
return -1; |
|
} |
|
i2p::crypto::InitCrypto (false, true, false); |
|
|
|
std::string fname(argv[2]); |
|
i2p::data::PrivateKeys keys; |
|
{ |
|
std::vector<uint8_t> buff; |
|
std::ifstream inf; |
|
inf.open(fname); |
|
if (!inf.is_open()) { |
|
std::cout << "cannot open keys 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 keys file format" << std::endl; |
|
return 3; |
|
} |
|
} |
|
|
|
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; // EdDSA by default |
|
if (argc > 3) |
|
{ |
|
std::string str(argv[3]); |
|
type = NameToSigType(str); |
|
if (SigTypeToName(type).find("unknown") != std::string::npos) { std::cerr << "Incorrect signature type" << std::endl; return -2; } |
|
} |
|
|
|
int days = 365; // 1 year by default |
|
if (argc > 4) |
|
days = std::stoi (argv[4]); |
|
uint32_t expires = i2p::util::GetSecondsSinceEpoch () + days*24*60*60; |
|
|
|
auto offlineKeys = keys.CreateOfflineKeys (type, expires); |
|
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out); |
|
if (f) |
|
{ |
|
size_t len = offlineKeys.GetFullLen (); |
|
uint8_t * buf = new uint8_t[len]; |
|
len = offlineKeys.ToBuffer (buf, len); |
|
f.write ((char *)buf, len); |
|
delete[] buf; |
|
std::cout << "Offline keys for destination " << offlineKeys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl |
|
<< "Signature type: " << SigTypeToName(type) << " (" << type << ")" << std::endl |
|
<< "Days: " << days << std::endl; |
|
} |
|
else |
|
std::cout << "Can't create file " << argv[1] << std::endl; |
|
|
|
i2p::crypto::TerminateCrypto (); |
|
|
|
return 0; |
|
}
|
|
|