diff --git a/libi2pd/LeaseSet.cpp b/libi2pd/LeaseSet.cpp index d418ca50..c748d3ce 100644 --- a/libi2pd/LeaseSet.cpp +++ b/libi2pd/LeaseSet.cpp @@ -299,6 +299,21 @@ namespace data LogPrint (eLogError, "LeaseSet2: unknown signature type ", (int)m_SigType, " in b33"); } + std::string BlindedPublicKey::ToB33 () const + { + if (m_PublicKey.size () > 32) return ""; // assume 25519 + uint8_t addr[35]; char str[60]; // TODO: define actual length + addr[0] = 0; // flags + addr[1] = m_SigType; // sig type + addr[2] = m_BlindedSigType; // blinded sig type + memcpy (addr + 3, m_PublicKey.data (), m_PublicKey.size ()); + uint32_t checksum = crc32 (0, addr + 3, m_PublicKey.size ()); + // checksum is Little Endian + addr[0] ^= checksum; addr[1] ^= (checksum >> 8); addr[2] ^= (checksum >> 16); + auto l = ByteStreamToBase32 (addr, m_PublicKey.size () + 3, str, 60); + return std::string (str, str + l); + } + LeaseSet2::LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len, bool storeLeases): LeaseSet (storeLeases), m_StoreType (storeType) { diff --git a/libi2pd/LeaseSet.h b/libi2pd/LeaseSet.h index ecf2dc96..9b3fc2b2 100644 --- a/libi2pd/LeaseSet.h +++ b/libi2pd/LeaseSet.h @@ -134,6 +134,7 @@ namespace data BlindedPublicKey (std::shared_ptr identity, SigningKeyType blindedKeyType = i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519); BlindedPublicKey (const std::string& b33); // from b33 without .b32.i2p + std::string ToB33 () const; const uint8_t * GetPublicKey () const { return m_PublicKey.data (); }; size_t GetPublicKeyLen () const { return m_PublicKey.size (); }; diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index 9af66786..bf22c279 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -189,13 +189,14 @@ namespace client } for (const auto& it: addresses) - { + { + f << it.first << ","; if (it.second->IsIdentHash ()) - { - f << it.first << "," << it.second->identHash.ToBase32 () << std::endl; - num++; - } - // TODO: save blinded public key + f << it.second->identHash.ToBase32 (); + else + f << it.second->blindedPublicKey->ToB33 (); + f << std::endl; + num++; } LogPrint (eLogInfo, "Addressbook: ", num, " addresses saved"); return num;