Browse Source

offline keys added

pull/61/head
orignal 5 years ago
parent
commit
7dc04d52f7
  1. 7
      Makefile
  2. 1
      keyinfo.cpp
  3. 70
      offlinekeys.cpp

7
Makefile

@ -44,7 +44,7 @@ OBJECTS = $(SOURCES:.cpp=.o) @@ -44,7 +44,7 @@ OBJECTS = $(SOURCES:.cpp=.o)
I2PD_LIB = libi2pd.a
all: keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64
all: keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys
routerinfo: $(OBJECTS)
$(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS)
@ -70,6 +70,9 @@ vain: $(OBJECTS) @@ -70,6 +70,9 @@ vain: $(OBJECTS)
i2pbase64: $(OBJECTS)
$(CXX) -o i2pbase64 i2pbase64.o $(LDFLAGS) $(LIBS)
offlinekeys: $(OBJECTS)
$(CXX) -o offlinekeys offlinekeys.o $(LDFLAGS) $(LIBS)
$(OBJECTS): libi2pd.a
.SUFFIXES:
@ -91,7 +94,7 @@ clean-obj: @@ -91,7 +94,7 @@ clean-obj:
rm -f $(OBJECTS)
clean-bin:
rm -f keyinfo keygen famtool regaddr regaddr_3ld routerinfo i2pbase64 vain
rm -f keyinfo keygen famtool regaddr regaddr_3ld routerinfo i2pbase64 vain offlinekeys
clean: clean-i2pd clean-obj clean-bin

1
keyinfo.cpp

@ -62,6 +62,7 @@ int main(int argc, char * argv[]) @@ -62,6 +62,7 @@ int main(int argc, char * argv[])
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;
if (keys.IsOfflineSignature ()) std::cout << "Offline signature" << std::endl;
} else {
if(print_full) {
std::cout << dest->ToBase64() << std::endl;

70
offlinekeys.cpp

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
#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);
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);
}
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;
}
else
std::cout << "Can't create file " << argv[1] << std::endl;
i2p::crypto::TerminateCrypto ();
return 0;
}
Loading…
Cancel
Save