Browse Source

PrivateKeys with extended identity

pull/93/head
orignal 10 years ago
parent
commit
a6c308f2f5
  1. 28
      Identity.cpp
  2. 30
      Identity.h
  3. 17
      Streaming.cpp
  4. 3
      Streaming.h
  5. 2
      version.h

28
Identity.cpp

@ -186,12 +186,34 @@ namespace data
PrivateKeys& PrivateKeys::operator=(const Keys& keys) PrivateKeys& PrivateKeys::operator=(const Keys& keys)
{ {
pub = keys; m_Public = Identity (keys);
memcpy (privateKey, keys.privateKey, 276); // 256 + 20 memcpy (m_PrivateKey, keys.privateKey, 256); // 256
memcpy (m_SigningPrivateKey, keys.signingPrivateKey, 20); // 20 - DSA
return *this; return *this;
} }
size_t PrivateKeys::FromBuffer (const uint8_t * buf, size_t len)
{
size_t ret = m_Public.FromBuffer (buf, len);
memcpy (m_PrivateKey, buf + ret, 256); // private key always 256
ret += 256;
size_t signingPrivateKeySize = m_Public.GetSignatureLen ()/2; // 20 for DSA
memcpy (m_SigningPrivateKey, buf + ret, signingPrivateKeySize);
ret += signingPrivateKeySize;
return ret;
}
size_t PrivateKeys::ToBuffer (uint8_t * buf, size_t len) const
{
size_t ret = m_Public.ToBuffer (buf, len);
memcpy (buf + ret, m_PrivateKey, 256); // private key always 256
ret += 256;
size_t signingPrivateKeySize = m_Public.GetSignatureLen ()/2; // 20 for DSA
memcpy (buf + ret, m_SigningPrivateKey, signingPrivateKeySize);
ret += signingPrivateKeySize;
return ret;
}
Keys CreateRandomKeys () Keys CreateRandomKeys ()
{ {
Keys keys; Keys keys;

30
Identity.h

@ -93,6 +93,8 @@ namespace data
uint16_t length; uint16_t length;
} certificate; } certificate;
Identity () = default;
Identity (const Keys& keys) { *this = keys; };
Identity& operator=(const Keys& keys); Identity& operator=(const Keys& keys);
bool FromBase64(const std::string& ); bool FromBase64(const std::string& );
size_t FromBuffer (const uint8_t * buf, size_t len); size_t FromBuffer (const uint8_t * buf, size_t len);
@ -133,17 +135,27 @@ namespace data
uint8_t * m_ExtendedBuffer; uint8_t * m_ExtendedBuffer;
}; };
struct PrivateKeys // for eepsites class PrivateKeys // for eepsites
{ {
Identity pub; public:
uint8_t privateKey[256];
uint8_t signingPrivateKey[20]; PrivateKeys () = default;
PrivateKeys (const PrivateKeys& ) = default;
PrivateKeys (const Keys& keys) { *this = keys; };
PrivateKeys& operator=(const Keys& keys);
PrivateKeys () = default; const IdentityEx& GetPublic () const { return m_Public; };
PrivateKeys (const PrivateKeys& ) = default; const uint8_t * GetPrivateKey () const { return m_PrivateKey; };
PrivateKeys (const Keys& keys) { *this = keys; }; const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; };
PrivateKeys& operator=(const Keys& keys); size_t FromBuffer (const uint8_t * buf, size_t len);
size_t ToBuffer (uint8_t * buf, size_t len) const;
private:
IdentityEx m_Public;
uint8_t m_PrivateKey[256];
uint8_t m_SigningPrivateKey[128]; // assume private key doesn't exceed 128 bytes
}; };
#pragma pack() #pragma pack()

17
Streaming.cpp

@ -506,10 +506,8 @@ namespace stream
m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false) m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false)
{ {
m_Keys = i2p::data::CreateRandomKeys (); m_Keys = i2p::data::CreateRandomKeys ();
m_Identity = m_Keys.pub;
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); CryptoPP::Integer (m_Keys.GetSigningPrivateKey (), 20));
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
@ -520,13 +518,20 @@ namespace stream
{ {
std::ifstream s(fullPath.c_str (), std::ifstream::binary); std::ifstream s(fullPath.c_str (), std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
s.read ((char *)&m_Keys, sizeof (m_Keys)); {
s.seekg (0, std::ios::end);
size_t len = s.tellg();
s.seekg (0, std::ios::beg);
uint8_t * buf = new uint8_t[len];
s.read ((char *)buf, len);
m_Keys.FromBuffer (buf, len);
delete[] buf;
}
else else
LogPrint ("Can't open file ", fullPath); LogPrint ("Can't open file ", fullPath);
m_Identity = m_Keys.pub;
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); CryptoPP::Integer (m_Keys.GetSigningPrivateKey (), 20));
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel

3
Streaming.h

@ -153,7 +153,7 @@ namespace stream
void HandleNextPacket (Packet * packet); void HandleNextPacket (Packet * packet);
// implements LocalDestination // implements LocalDestination
const i2p::data::IdentityEx& GetIdentity () const { return m_Identity; }; const i2p::data::IdentityEx& GetIdentity () const { return m_Keys.GetPublic (); };
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
void Sign (const uint8_t * buf, int len, uint8_t * signature) const; void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
@ -169,7 +169,6 @@ namespace stream
boost::asio::io_service& m_Service; boost::asio::io_service& m_Service;
std::map<uint32_t, Stream *> m_Streams; std::map<uint32_t, Stream *> m_Streams;
i2p::data::PrivateKeys m_Keys; i2p::data::PrivateKeys m_Keys;
i2p::data::IdentityEx m_Identity;
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
i2p::tunnel::TunnelPool * m_Pool; i2p::tunnel::TunnelPool * m_Pool;

2
version.h

@ -5,7 +5,7 @@
#define CODENAME "Purple" #define CODENAME "Purple"
#define I2P_VERSION "0.9.11" #define I2P_VERSION "0.9.14"
/* TEMPORARY STORE FOR IMAGE CODES */ /* TEMPORARY STORE FOR IMAGE CODES */

Loading…
Cancel
Save