mirror of
https://github.com/PurpleI2P/i2pd-tools.git
synced 2025-09-02 19:30:24 +01:00
commit
99435f3c48
9 changed files with 105 additions and 58 deletions
30
README.md
30
README.md
|
@ -35,6 +35,36 @@ make
|
|||
|
||||
## Tools included
|
||||
|
||||
### verifyhost
|
||||
#### Example usage
|
||||
```bash
|
||||
# Valid destination with old destination signature
|
||||
./verifyhost 'test12356.i2p=7qYyu4ZkY5ixxLTUn6RF-LvX7YlFZGcpGQPJITq7NieLKW-pwJuyxz7Ga06HzNwieLackwmBVsbizzPHffFXiwqwTcsTbjZvYdRs4oEyCg1V1qoEMaQXHZkwhcIZ0DVFEkscytDy327C9-x5gH0d2lNdrVf2k2dmWKU3hUMSqYRHHOHgJyGIHF8bv4nPCaUjVu9gL6g1Nzfxf5mEwx1-vIsV3NW83Pe9fpXaoqQ~zOXKZ-rOz8h4yfHJ7WKARxEFaUNALa6Kkm4~FOctB6aV05Meh~OW7GzM~ZUalguaDpGkqbOr~mK8b6o8gzOJTWUOku4jHmVeD9doePudAxygPhahZt5j5bCNPSezCCa6DVbLCqJLQr6uK0izlJnrsYnYFqFm3mPlsI09J7MIJroNVssKoktCvq4rSLOUmeuxidhCkv18Y-WwjT0nswgmug1WywqiS0K-ritIs5SZ67GJ2Oshc-W7rUv86yoFksGfsXaeBzGiKX9i0R~UqcxTsjRjBQAEAAcAAA==#!action=adddest#olddest=GcxIh28qJRLIBfZ3AO~-hQdZhJhYM93zeODGYXyzPBE~gQmIYTbw84d~kwQXzzWDvqgpTmwYlqejUiGWOGXTrfPlByoWpKwUf-1Oe~kARvSwWLCpyuAPDNAMm~xTxexsjZ4Ry7Ad7IlxCrlQgBVus6l2t7ZznHa1OPIJh-zMzXoX9DNQpvSVdVYMXXKguQr4HFSa2LVQkPXrVrqXLMj1QDmFrXEwZAhWujntVstCoC8u00B6xhQSqTsvHhca63ZYkge78SNILbpWQQKb7XbjJKkQS99tLFbG-KSERm5YrP61PdF25TIUsiFN7i07HkseUTGMbuwHsfFp6-uXYMK2gz9Vyv0kXYu0ahoTEUJmC0DbYsLGpkF7UI1hWp43eWmWP1XK~SRdi7RqGhMRQmYLQNtiwsamQXtQjWFanjd5aZYwl8r9JF2LtGoaExFCZgtA22LCxqZBe1CNYVqeN3lplr8ep7m~ZwjgWrnjuxEVY52zLnp8oiVo1Hstf~F8w22KBQAEAAcAAA=='
|
||||
Valid destination
|
||||
|
||||
# Destination with missing old signature
|
||||
./verifyhost 'test123456.i2p=GcxIh28qJRLIBfZ3AO~-hQdZhJhYM93zeODGYXyzPBE~gQmIYTbw84d~kwQXzzWDvqgpTmwYlqejUiGWOGXTrfPlByoWpKwUf-1Oe~kARvSwWLCpyuAPDNAMm~xTxexsjZ4Ry7Ad7IlxCrlQgBVus6l2t7ZznHa1OPIJh-zMzXoX9DNQpvSVdVYMXXKguQr4HFSa2LVQkPXrVrqXLMj1QDmFrXEwZAhWujntVstCoC8u00B6xhQSqTsvHhca63ZYkge78SNILbpWQQKb7XbjJKkQS99tLFbG-KSERm5YrP61PdF25TIUsiFN7i07HkseUTGMbuwHsfFp6-uXYMK2gz9Vyv0kXYu0ahoTEUJmC0DbYsLGpkF7UI1hWp43eWmWP1XK~SRdi7RqGhMRQmYLQNtiwsamQXtQjWFanjd5aZYwl8r9JF2LtGoaExFCZgtA22LCxqZBe1CNYVqeN3lplr8ep7m~ZwjgWrnjuxEVY52zLnp8oiVo1Hstf~F8w22KBQAEAAcAAA==#!action=addsubdomain'
|
||||
Destination signature not found.
|
||||
|
||||
# Invalid signature
|
||||
./verifyhost 'test.i2p=GcxIh28qJRLIBfZ3AO~-hQdZhJhYM93zeODGYXyzPBE~gQmIYTbw84d~kwQXzzWDvqgpTmwYlqejUiGWOGXTrfPlByoWpKwUf-1Oe~kARvSwWLCpyuAPDNAMm~xTxexsjZ4Ry7Ad7IlxCrlQgBVus6l2t7ZznHa1OPIJh-zMzXoX9DNQpvSVdVYMXXKguQr4HFSa2LVQkPXrVrqXLMj1QDmFrXEwZAhWujntVstCoC8u00B6xhQSqTsvHhca63ZYkge78SNILbpWQQKb7XbjJKkQS99tLFbG-KSERm5YrP61PdF25TIUsiFN7i07HkseUTGMbuwHsfFp6-uXYMK2gz9Vyv0kXYu0ahoTEUJmC0DbYsLGpkF7UI1hWp43eWmWP1XK~SRdi7RqGhMRQmYLQNtiwsamQXtQjWFanjd5aZYwl8r9JF2LtGoaExFCZgtA22LCxqZBe1CNYVqeN3lplr8ep7m~ZwjgWrnjuxEVY52zLnp8oiVo1Hstf~F8w22KBQAEAAcAAA==#!sig=0CiP4rB3x2EVmTMzlXBseUUnjENO900OLaw5Db5ylQwXYcnbmSbVoiR2nxNrjBqrdMOTDF8G-Ps2Wuv-TZ5yDA2='
|
||||
Invalid destination signature
|
||||
```
|
||||
|
||||
### i2pbase64
|
||||
|
||||
encode/decode b64 string
|
||||
example usage:
|
||||
```
|
||||
user@computer:~/i2pd-tools$ ./i2pbase64
|
||||
encode
|
||||
ZW5jb2RlCg==^C
|
||||
user@computer:~/i2pd-tools$ ./i2pbase64 -d
|
||||
ZW5jb2RlCg==
|
||||
encode
|
||||
```
|
||||
U also can use file
|
||||
|
||||
### routerinfo
|
||||
|
||||
print information about a router info file
|
||||
|
|
19
famtool.cpp
19
famtool.cpp
|
@ -74,7 +74,7 @@ static std::shared_ptr<Verifier> LoadCertificate (const std::string& filename)
|
|||
bn2buf (y, signingKey + 32, 32);
|
||||
BN_free (x); BN_free (y);
|
||||
verifier = std::make_shared<i2p::crypto::ECDSAP256Verifier>();
|
||||
verifier->SetPublicKey (signingKey);
|
||||
verifier->SetPublicKey (signingKey);
|
||||
}
|
||||
}
|
||||
EC_KEY_free (ecKey);
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -14,26 +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];
|
||||
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))
|
||||
{
|
||||
write(outfile, outbuf, outsz);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return errno;
|
||||
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;
|
||||
while ((sz = read(infile, inbuf, sizeof(inbuf))) > 0) {
|
||||
std::string_view chunk(inbuf, sz);
|
||||
std::string s(chunk);
|
||||
s.erase(std::remove(s.begin(), s.end(), '\n'), s.end());
|
||||
|
||||
size_t outsz = i2p::data::Base64ToByteStream(s, outbuf, sizeof(outbuf));
|
||||
if (outsz > 0) {
|
||||
write(outfile, outbuf, outsz);
|
||||
} 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[])
|
||||
|
@ -71,11 +82,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
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 ();
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -69,23 +69,23 @@ int main (int argc, char * argv[])
|
|||
|
||||
auto oldSignatureLen = oldkeys.GetPublic ()->GetSignatureLen ();
|
||||
uint8_t * oldSignature = new uint8_t[oldSignatureLen];
|
||||
char * oldSig = new char[oldSignatureLen*2];
|
||||
//char * oldSig = new char[oldSignatureLen*2];
|
||||
oldkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), oldSignature);
|
||||
auto len = i2p::data::ByteStreamToBase64 (oldSignature, oldSignatureLen, oldSig, oldSignatureLen*2);
|
||||
oldSig[len] = 0;
|
||||
auto oldSig = i2p::data::ByteStreamToBase64 (oldSignature, oldSignatureLen);//, oldSig, oldSignatureLen*2);
|
||||
//oldSig[len] = 0;
|
||||
out << "#oldsig=" << oldSig;
|
||||
delete[] oldSignature;
|
||||
delete[] oldSig;
|
||||
//delete[] oldSig;
|
||||
|
||||
auto signatureLen = newkeys.GetPublic ()->GetSignatureLen ();
|
||||
uint8_t * signature = new uint8_t[signatureLen];
|
||||
char * sig = new char[signatureLen*2];
|
||||
//char * sig = new char[signatureLen*2];
|
||||
newkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
||||
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;
|
||||
|
||||
|
|
|
@ -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,13 +86,15 @@ 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)
|
||||
{
|
||||
std::cout << "Invalid old destination signature." << std::endl;
|
||||
return 1;
|
||||
} else {
|
||||
std::cout << "Valid destination" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
x25519.cpp
10
x25519.cpp
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue