1
0
mirror of https://github.com/PurpleI2P/i2pd-tools synced 2025-08-26 04:41:48 +00:00

fix: pre init fixes, not tested

This commit is contained in:
wipedlifepotato 2025-08-21 04:30:28 +07:00
parent 2700a2a40e
commit c8c8c462b9
7 changed files with 63 additions and 50 deletions

View File

@ -113,11 +113,11 @@ static bool CreateFamilySignature (const std::string& family, const IdentHash& i
len += 32;
signer.Sign (buf, len, signature);
len = Base64EncodingBufferSize (64);
char * b64 = new char[len+1];
len = ByteStreamToBase64 (signature, 64, b64, len);
b64[len] = 0;
//char * b64 = new char[len+1];
auto b64 = ByteStreamToBase64 (signature, len);
//b64[len] = 0;
sig = b64;
delete[] b64;
//delete[] b64;
}
else
return false;
@ -383,9 +383,12 @@ int main(int argc, char * argv[])
memcpy(buf, fam.c_str(), len);
memcpy(buf + len, (const uint8_t *) ident, 32);
len += 32;
uint8_t sigbuf[64];
Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64);
if(!v->Verify(buf, len, sigbuf)) {
//uint8_t sigbuf[64];
auto b64 = ByteStreamToBase64(reinterpret_cast<const uint8_t*>(sig.c_str()), sig.length());
//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;
return 1;
}

View File

@ -14,28 +14,37 @@ static int printHelp(const char * exe, int exitcode)
return exitcode;
}
template <typename InCh, typename OutCh, size_t isz, size_t osz>
static int operate(std::function<std::size_t(const InCh *, size_t, OutCh *, size_t)> f, int infile, int outfile)
{
InCh inbuf[isz];
OutCh outbuf[osz];
int operate_b64_decode(int infile, int outfile) {
constexpr size_t BUFFSZ = 4096;
char inbuf[BUFFSZ*4];
uint8_t outbuf[BUFFSZ*3];
ssize_t sz;
size_t outsz;
while((sz = read(infile, inbuf, sizeof(inbuf))) > 0)
{
outsz = f(inbuf, sz, outbuf, sizeof(outbuf));
if(outsz && outsz <= sizeof(outbuf))
{
while ((sz = read(infile, inbuf, sizeof(inbuf))) > 0) {
std::string_view chunk(inbuf, sz);
size_t outsz = i2p::data::Base64ToByteStream(chunk, outbuf, sizeof(outbuf));
if (outsz > 0) {
write(outfile, outbuf, outsz);
}
else
{
} else {
return -1;
}
}
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 opt;
@ -71,11 +80,11 @@ int main(int argc, char * argv[])
int retcode = 0;
if(decode)
{
retcode = operate<char, uint8_t, BUFFSZ*4, BUFFSZ*3>(i2p::data::Base64ToByteStream, infile, 1);
retcode = operate_b64_decode(infile, 1);
}
else
{
retcode = operate<uint8_t, char, BUFFSZ*3, BUFFSZ*4>(&i2p::data::ByteStreamToBase64, infile, 1);
retcode = operate_b64_encode(infile, 1);
}
close(infile);
return retcode;

2
i2pd

@ -1 +1 @@
Subproject commit dcd15cc2449d6320de6351054e61ef2ee7ebee40
Subproject commit de14e81f50e24b78eb3b190cd4f1ca8514bc4e64

View File

@ -29,16 +29,16 @@ int main (int argc, char * argv[])
{
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
uint8_t * signature = new uint8_t[signatureLen];
char * sig = new char[signatureLen*2];
//char * sig = new char[signatureLen*2];
std::stringstream out;
out << argv[2] << "="; // address
out << keys.GetPublic ()->ToBase64 ();
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
sig[len] = 0;
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2);
//sig[len] = 0;
out << "#!sig=" << sig;
delete[] signature;
delete[] sig;
//delete[] sig;
std::cout << out.str () << std::endl;
}
else

View File

@ -66,16 +66,16 @@ int main (int argc, char * argv[])
if(keys.FromBuffer (buf, len)) {
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
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 << "#olddest=" << keys.GetPublic ()->ToBase64 ();
out << "#oldname=" << argv[4];
keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
sig[len] = 0;
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2);
//sig[len] = 0;
out << "#oldsig=" << sig;
delete[] signature;
delete[] sig;
//delete[] sig;
std::cout << out.str () << std::endl;
} else
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)) {
auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
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);
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
sig[len] = 0;
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);//, sig, signatureLen*2);
//sig[len] = 0;
out << "#sig=" << sig;
delete[] signature;
delete[] sig;
//delete[] sig;
std::cout << out.str () << std::endl;
} else
std::cout << "Failed to load keyfile " << argv[1] << std::endl;

View File

@ -51,7 +51,8 @@ int main (int argc, char * argv[])
uint8_t * signature = new uint8_t[signatureLen];
// 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))
{
std::cout << "Invalid destination signature." << std::endl;
@ -85,7 +86,7 @@ int main (int argc, char * argv[])
std::string oldSig = oldSigCut.substr (0, pos);
// 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);
if(!oldSignValid)

View File

@ -57,17 +57,17 @@ int main(int argc, char * argv[])
BoxKeys newKeys = getKeyPair();
const size_t len_out = 50;
char b64Public[len_out] = {0};
char b64Private[len_out] = {0};
//const size_t len_out = 50;
//char b64Public[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: ";
for (int i = 0; b64Public[i] != 0; ++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: ";
for (int i = 0; b64Private[i] != 0; ++i)