@ -253,6 +253,16 @@ namespace data
@@ -253,6 +253,16 @@ namespace data
memcpy ( m_Buffer , buf , len ) ;
}
BlindedPublicKey : : BlindedPublicKey ( std : : shared_ptr < const IdentityEx > identity , SigningKeyType blindedKeyType ) :
m_BlindedSigType ( blindedKeyType )
{
if ( ! identity ) return ;
auto len = identity - > GetSigningPublicKeyLen ( ) ;
m_PublicKey . resize ( len ) ;
memcpy ( m_PublicKey . data ( ) , identity - > GetSigningPublicKeyBuffer ( ) , len ) ;
m_SigType = identity - > GetSigningKeyType ( ) ;
}
LeaseSet2 : : LeaseSet2 ( uint8_t storeType , const uint8_t * buf , size_t len , bool storeLeases ) :
LeaseSet ( storeLeases ) , m_StoreType ( storeType )
{
@ -263,10 +273,10 @@ namespace data
@@ -263,10 +273,10 @@ namespace data
ReadFromBuffer ( buf , len ) ;
}
LeaseSet2 : : LeaseSet2 ( const uint8_t * buf , size_t len , std : : shared_ptr < const IdentityEx > identit y) :
LeaseSet2 : : LeaseSet2 ( const uint8_t * buf , size_t len , std : : shared_ptr < const BlindedPublicKey > ke y) :
LeaseSet ( true ) , m_StoreType ( NETDB_STORE_TYPE_ENCRYPTED_LEASESET2 )
{
ReadFromBufferEncrypted ( buf , len , identit y) ;
ReadFromBufferEncrypted ( buf , len , ke y) ;
}
void LeaseSet2 : : Update ( const uint8_t * buf , size_t len , bool verifySignature )
@ -423,7 +433,7 @@ namespace data
@@ -423,7 +433,7 @@ namespace data
return offset ;
}
void LeaseSet2 : : ReadFromBufferEncrypted ( const uint8_t * buf , size_t len , std : : shared_ptr < const IdentityEx > identit y)
void LeaseSet2 : : ReadFromBufferEncrypted ( const uint8_t * buf , size_t len , std : : shared_ptr < const BlindedPublicKey > ke y)
{
size_t offset = 0 ;
// blinded key
@ -463,7 +473,7 @@ namespace data
@@ -463,7 +473,7 @@ namespace data
VerifySignature ( blindedVerifier , buf , len , offset ) ;
SetIsValid ( verified ) ;
// handle ciphertext
if ( verified & & identit y & & lenOuterCiphertext > = 32 )
if ( verified & & ke y & & lenOuterCiphertext > = 32 )
{
SetIsValid ( false ) ; // we must verify it again in Layer 2
if ( blindedKeyType = = i2p : : data : : SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519 )
@ -472,7 +482,7 @@ namespace data
@@ -472,7 +482,7 @@ namespace data
char date [ 9 ] ;
i2p : : util : : GetCurrentDate ( date ) ;
uint8_t blinded [ 32 ] ;
BlindPublicKey ( identit y, date , blindedKeyTyp e , blinded ) ;
BlindPublicKey ( ke y, date , blinded ) ;
if ( memcmp ( blindedPublicKey , blinded , 32 ) )
{
LogPrint ( eLogError , " LeaseSet2: blinded public key doesn't match " ) ;
@ -483,9 +493,9 @@ namespace data
@@ -483,9 +493,9 @@ namespace data
uint8_t credential [ 32 ] , subcredential [ 36 ] ;
// A = destination's signing public key
// stA = signature type of A, 2 bytes big endian
uint16_t stA = htobe16 ( identit y- > GetSigningKey Type ( ) ) ;
uint16_t stA = htobe16 ( ke y- > GetSigType ( ) ) ;
// credential = H("credential", A || stA || stA1)
H ( " credential " , { { identit y- > GetSigning PublicKeyBuffer ( ) , identit y- > GetSigning PublicKeyLen ( ) } , { ( const uint8_t * ) & stA , 2 } , { stA1 , 2 } } , credential ) ;
H ( " credential " , { { ke y- > GetPublicKey ( ) , ke y- > GetPublicKeyLen ( ) } , { ( const uint8_t * ) & stA , 2 } , { stA1 , 2 } } , credential ) ;
// subcredential = H("subcredential", credential || blindedPublicKey)
H ( " subcredential " , { { credential , 32 } , { blindedPublicKey , blindedKeyLen } } , subcredential ) ;
// outer key
@ -535,18 +545,19 @@ namespace data
@@ -535,18 +545,19 @@ namespace data
SHA256_Final ( hash , & ctx ) ;
}
void LeaseSet2 : : BlindPublicKey ( std : : shared_ptr < const IdentityEx > identit y, const char * date , SigningKeyType blindedKeyTyp e , uint8_t * blindedKey )
void LeaseSet2 : : BlindPublicKey ( std : : shared_ptr < const BlindedPublicKey > ke y, const char * date , uint8_t * blindedKey )
{
uint16_t stA = htobe16 ( identit y- > GetSigningKey Type ( ) ) , stA1 = htobe16 ( blindedKeyType ) ;
uint16_t stA = htobe16 ( ke y- > GetSigType ( ) ) , stA1 = htobe16 ( key - > GetBlindedSigType ( ) ) ;
uint8_t salt [ 32 ] , seed [ 64 ] ;
//seed = HKDF(H("I2PGenerateAlpha", keydata), datestring || secret, "i2pblinding1", 64)
H ( " I2PGenerateAlpha " , { { identit y- > GetSigning PublicKeyBuffer ( ) , identit y- > GetSigning PublicKeyLen ( ) } , { ( const uint8_t * ) & stA , 2 } , { ( const uint8_t * ) & stA1 , 2 } } , salt ) ;
H ( " I2PGenerateAlpha " , { { ke y- > GetPublicKey ( ) , ke y- > GetPublicKeyLen ( ) } , { ( const uint8_t * ) & stA , 2 } , { ( const uint8_t * ) & stA1 , 2 } } , salt ) ;
i2p : : crypto : : HKDF ( salt , ( const uint8_t * ) date , 8 , " i2pblinding1 " , seed ) ;
i2p : : crypto : : GetEd25519 ( ) - > BlindPublicKey ( identit y- > GetSigning PublicKeyBuffer ( ) , seed , blindedKey ) ;
i2p : : crypto : : GetEd25519 ( ) - > BlindPublicKey ( ke y- > GetPublicKey ( ) , seed , blindedKey ) ;
}
void LeaseSet2 : : CalculateStoreHash ( std : : shared_ptr < const IdentityEx > identity , SigningKeyType blindedKeyType , i2p : : data : : IdentHash & hash )
void LeaseSet2 : : CalculateStoreHash ( std : : shared_ptr < const BlindedPublicKey > key , i2p : : data : : IdentHash & hash )
{
auto blindedKeyType = key - > GetBlindedSigType ( ) ;
if ( blindedKeyType ! = i2p : : data : : SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519 & &
blindedKeyType ! = SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519 )
{
@ -556,7 +567,7 @@ namespace data
@@ -556,7 +567,7 @@ namespace data
char date [ 9 ] ;
i2p : : util : : GetCurrentDate ( date ) ;
uint8_t blinded [ 32 ] ;
BlindPublicKey ( identit y, date , blindedKeyTyp e , blinded ) ;
BlindPublicKey ( ke y, date , blinded ) ;
auto stA1 = htobe16 ( blindedKeyType ) ;
SHA256_CTX ctx ;
SHA256_Init ( & ctx ) ;