mirror of
https://github.com/PurpleI2P/i2pd-tools
synced 2025-08-26 12:51:50 +00:00
fix: pre init fixes, not tested
This commit is contained in:
parent
2700a2a40e
commit
c8c8c462b9
17
famtool.cpp
17
famtool.cpp
@ -113,11 +113,11 @@ static bool CreateFamilySignature (const std::string& family, const IdentHash& i
|
|||||||
len += 32;
|
len += 32;
|
||||||
signer.Sign (buf, len, signature);
|
signer.Sign (buf, len, signature);
|
||||||
len = Base64EncodingBufferSize (64);
|
len = Base64EncodingBufferSize (64);
|
||||||
char * b64 = new char[len+1];
|
//char * b64 = new char[len+1];
|
||||||
len = ByteStreamToBase64 (signature, 64, b64, len);
|
auto b64 = ByteStreamToBase64 (signature, len);
|
||||||
b64[len] = 0;
|
//b64[len] = 0;
|
||||||
sig = b64;
|
sig = b64;
|
||||||
delete[] b64;
|
//delete[] b64;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -383,9 +383,12 @@ int main(int argc, char * argv[])
|
|||||||
memcpy(buf, fam.c_str(), len);
|
memcpy(buf, fam.c_str(), len);
|
||||||
memcpy(buf + len, (const uint8_t *) ident, 32);
|
memcpy(buf + len, (const uint8_t *) ident, 32);
|
||||||
len += 32;
|
len += 32;
|
||||||
uint8_t sigbuf[64];
|
//uint8_t sigbuf[64];
|
||||||
Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64);
|
auto b64 = ByteStreamToBase64(reinterpret_cast<const uint8_t*>(sig.c_str()), sig.length());
|
||||||
if(!v->Verify(buf, len, sigbuf)) {
|
|
||||||
|
//Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64);
|
||||||
|
if (!v->Verify(buf, len,
|
||||||
|
reinterpret_cast<const uint8_t*>(b64.data()))) {
|
||||||
std::cout << "invalid signature" << std::endl;
|
std::cout << "invalid signature" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -14,28 +14,37 @@ static int printHelp(const char * exe, int exitcode)
|
|||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename InCh, typename OutCh, size_t isz, size_t osz>
|
int operate_b64_decode(int infile, int outfile) {
|
||||||
static int operate(std::function<std::size_t(const InCh *, size_t, OutCh *, size_t)> f, int infile, int outfile)
|
constexpr size_t BUFFSZ = 4096;
|
||||||
{
|
char inbuf[BUFFSZ*4];
|
||||||
InCh inbuf[isz];
|
uint8_t outbuf[BUFFSZ*3];
|
||||||
OutCh outbuf[osz];
|
|
||||||
ssize_t sz;
|
ssize_t sz;
|
||||||
size_t outsz;
|
while ((sz = read(infile, inbuf, sizeof(inbuf))) > 0) {
|
||||||
while((sz = read(infile, inbuf, sizeof(inbuf))) > 0)
|
std::string_view chunk(inbuf, sz);
|
||||||
{
|
|
||||||
outsz = f(inbuf, sz, outbuf, sizeof(outbuf));
|
size_t outsz = i2p::data::Base64ToByteStream(chunk, outbuf, sizeof(outbuf));
|
||||||
if(outsz && outsz <= sizeof(outbuf))
|
if (outsz > 0) {
|
||||||
{
|
|
||||||
write(outfile, outbuf, outsz);
|
write(outfile, outbuf, outsz);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int operate_b64_encode(int infile, int outfile) {
|
||||||
|
constexpr size_t BUFFSZ = 4096;
|
||||||
|
uint8_t inbuf[BUFFSZ*3];
|
||||||
|
//char outbuf[BUFFSZ*4];
|
||||||
|
ssize_t sz;
|
||||||
|
while((sz = read(infile, inbuf, sizeof(inbuf))) > 0) {
|
||||||
|
std::string out = i2p::data::ByteStreamToBase64(inbuf, sz);
|
||||||
|
write(outfile, out.data(), out.size());
|
||||||
|
}
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
@ -71,11 +80,11 @@ int main(int argc, char * argv[])
|
|||||||
int retcode = 0;
|
int retcode = 0;
|
||||||
if(decode)
|
if(decode)
|
||||||
{
|
{
|
||||||
retcode = operate<char, uint8_t, BUFFSZ*4, BUFFSZ*3>(i2p::data::Base64ToByteStream, infile, 1);
|
retcode = operate_b64_decode(infile, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retcode = operate<uint8_t, char, BUFFSZ*3, BUFFSZ*4>(&i2p::data::ByteStreamToBase64, infile, 1);
|
retcode = operate_b64_encode(infile, 1);
|
||||||
}
|
}
|
||||||
close(infile);
|
close(infile);
|
||||||
return retcode;
|
return retcode;
|
||||||
|
2
i2pd
2
i2pd
@ -1 +1 @@
|
|||||||
Subproject commit dcd15cc2449d6320de6351054e61ef2ee7ebee40
|
Subproject commit de14e81f50e24b78eb3b190cd4f1ca8514bc4e64
|
@ -29,16 +29,16 @@ int main (int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
|
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
|
||||||
uint8_t * signature = new uint8_t[signatureLen];
|
uint8_t * signature = new uint8_t[signatureLen];
|
||||||
char * sig = new char[signatureLen*2];
|
//char * sig = new char[signatureLen*2];
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << argv[2] << "="; // address
|
out << argv[2] << "="; // address
|
||||||
out << keys.GetPublic ()->ToBase64 ();
|
out << keys.GetPublic ()->ToBase64 ();
|
||||||
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
||||||
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
|
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2);
|
||||||
sig[len] = 0;
|
//sig[len] = 0;
|
||||||
out << "#!sig=" << sig;
|
out << "#!sig=" << sig;
|
||||||
delete[] signature;
|
delete[] signature;
|
||||||
delete[] sig;
|
//delete[] sig;
|
||||||
std::cout << out.str () << std::endl;
|
std::cout << out.str () << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -66,16 +66,16 @@ int main (int argc, char * argv[])
|
|||||||
if(keys.FromBuffer (buf, len)) {
|
if(keys.FromBuffer (buf, len)) {
|
||||||
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
|
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
|
||||||
uint8_t * signature = new uint8_t[signatureLen];
|
uint8_t * signature = new uint8_t[signatureLen];
|
||||||
char * sig = new char[signatureLen*2];
|
//char * sig = new char[signatureLen*2];
|
||||||
out << "#date=" << std::time(nullptr);
|
out << "#date=" << std::time(nullptr);
|
||||||
out << "#olddest=" << keys.GetPublic ()->ToBase64 ();
|
out << "#olddest=" << keys.GetPublic ()->ToBase64 ();
|
||||||
out << "#oldname=" << argv[4];
|
out << "#oldname=" << argv[4];
|
||||||
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
||||||
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
|
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2);
|
||||||
sig[len] = 0;
|
//sig[len] = 0;
|
||||||
out << "#oldsig=" << sig;
|
out << "#oldsig=" << sig;
|
||||||
delete[] signature;
|
delete[] signature;
|
||||||
delete[] sig;
|
//delete[] sig;
|
||||||
std::cout << out.str () << std::endl;
|
std::cout << out.str () << std::endl;
|
||||||
} else
|
} else
|
||||||
std::cout << "Failed to load keyfile " << argv[1] << std::endl;
|
std::cout << "Failed to load keyfile " << argv[1] << std::endl;
|
||||||
@ -108,13 +108,13 @@ int main (int argc, char * argv[])
|
|||||||
if(keys.FromBuffer (buf, len)) {
|
if(keys.FromBuffer (buf, len)) {
|
||||||
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
|
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
|
||||||
uint8_t * signature = new uint8_t[signatureLen];
|
uint8_t * signature = new uint8_t[signatureLen];
|
||||||
char * sig = new char[signatureLen*2];
|
//char * sig = new char[signatureLen*2];
|
||||||
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
||||||
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
|
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2);
|
||||||
sig[len] = 0;
|
//sig[len] = 0;
|
||||||
out << "#sig=" << sig;
|
out << "#sig=" << sig;
|
||||||
delete[] signature;
|
delete[] signature;
|
||||||
delete[] sig;
|
//delete[] sig;
|
||||||
std::cout << out.str () << std::endl;
|
std::cout << out.str () << std::endl;
|
||||||
} else
|
} else
|
||||||
std::cout << "Failed to load keyfile " << argv[1] << std::endl;
|
std::cout << "Failed to load keyfile " << argv[1] << std::endl;
|
||||||
|
@ -51,7 +51,8 @@ int main (int argc, char * argv[])
|
|||||||
uint8_t * signature = new uint8_t[signatureLen];
|
uint8_t * signature = new uint8_t[signatureLen];
|
||||||
|
|
||||||
// validate signature
|
// validate signature
|
||||||
i2p::data::Base64ToByteStream(sig.c_str (), sig.length(), signature, signatureLen);
|
// size_t Base64ToByteStream (std::string_view base64Str, uint8_t * OutBuffer, size_t len);
|
||||||
|
i2p::data::Base64ToByteStream(sig, signature, signatureLen);
|
||||||
if (!Identity.Verify ((uint8_t *)hostNoSig.c_str (), hostNoSig.length (), signature))
|
if (!Identity.Verify ((uint8_t *)hostNoSig.c_str (), hostNoSig.length (), signature))
|
||||||
{
|
{
|
||||||
std::cout << "Invalid destination signature." << std::endl;
|
std::cout << "Invalid destination signature." << std::endl;
|
||||||
@ -85,7 +86,7 @@ int main (int argc, char * argv[])
|
|||||||
std::string oldSig = oldSigCut.substr (0, pos);
|
std::string oldSig = oldSigCut.substr (0, pos);
|
||||||
|
|
||||||
// validate signature
|
// validate signature
|
||||||
i2p::data::Base64ToByteStream(oldSig.c_str (), oldSig.length(), signature, signatureLen);
|
i2p::data::Base64ToByteStream(oldSig, signature, signatureLen);
|
||||||
bool oldSignValid = OldIdentity.Verify ((uint8_t *)hostNoOldSig.c_str (), hostNoOldSig.length (), signature);
|
bool oldSignValid = OldIdentity.Verify ((uint8_t *)hostNoOldSig.c_str (), hostNoOldSig.length (), signature);
|
||||||
|
|
||||||
if(!oldSignValid)
|
if(!oldSignValid)
|
||||||
|
10
x25519.cpp
10
x25519.cpp
@ -57,17 +57,17 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
BoxKeys newKeys = getKeyPair();
|
BoxKeys newKeys = getKeyPair();
|
||||||
|
|
||||||
const size_t len_out = 50;
|
//const size_t len_out = 50;
|
||||||
char b64Public[len_out] = {0};
|
//char b64Public[len_out] = {0};
|
||||||
char b64Private[len_out] = {0};
|
//char b64Private[len_out] = {0};
|
||||||
|
|
||||||
i2p::data::ByteStreamToBase64 (newKeys.PublicKey, len, b64Public, len_out);
|
auto b64Public = i2p::data::ByteStreamToBase64 (newKeys.PublicKey, len);//, b64Public, len_out);
|
||||||
|
|
||||||
std::cout << "PublicKey: ";
|
std::cout << "PublicKey: ";
|
||||||
for (int i = 0; b64Public[i] != 0; ++i)
|
for (int i = 0; b64Public[i] != 0; ++i)
|
||||||
std::cout << b64Public[i];
|
std::cout << b64Public[i];
|
||||||
|
|
||||||
i2p::data::ByteStreamToBase64 (newKeys.PrivateKey, len, b64Private, len_out);
|
auto b64Private = i2p::data::ByteStreamToBase64 (newKeys.PrivateKey, len);//, b64Private, len_out);
|
||||||
|
|
||||||
std::cout << "\nPrivateKey: ";
|
std::cout << "\nPrivateKey: ";
|
||||||
for (int i = 0; b64Private[i] != 0; ++i)
|
for (int i = 0; b64Private[i] != 0; ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user