-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I2P "B33" / Encrypted Base32 Address Encoding In Rust #36
Comments
Did a bit more reading and it looks like the I've rewritten the function to what I believe is now the correct implementation, however I'm still unable to derive the address associated with the published encrypted leaseset 🤔 pub fn b33_address(tun_conf: TunnelConfig, require_secret: bool, client_auth: bool) -> Option<String> {
use crc::Crc;
let public_key_type = match tun_conf.sam_options.signature_type {
SignatureType::EdDsaSha512Ed25519 => 7,
SignatureType::RedDsaSha512Ed25519 => 11,
_ => return None,
};
// the private key returned from `DEST GENERATE`
let decoded_private_key = BASE64_I2P.decode(tun_conf.secret_key.as_bytes()).ok()?;
// the public key returned from `DEST GENERATE`
let decoded_destination = BASE64_I2P.decode(tun_conf.public_key.as_bytes()).ok()?;
let stripped_private_key = &decoded_private_key[decoded_destination.len()..];
let private_key = &stripped_private_key[0..32];
let public_key = if public_key_type == 7 {
let sk = ed25519_dalek::SecretKey::from_bytes(private_key).ok()?;
let pk: ed25519_dalek::PublicKey = (&sk).into();
pk.as_bytes().to_vec()
} else if public_key_type == 11 {
let mut pk: [u8; 32] = [0_u8; 32];
pk.copy_from_slice(private_key);
let sk = x25519_dalek::StaticSecret::from(pk);
let pk = x25519_dalek::PublicKey::from(&sk);
pk.as_bytes().to_vec()
} else {
unreachable!()
};
let mut data_vec = Vec::with_capacity(public_key.len() + 3);
data_vec.extend_from_slice(&[0, 0, 0]);
data_vec.extend_from_slice(&public_key[..]);
let summer: Crc<u32> = Crc::<u32>::new(&crc::CRC_32_CKSUM);
let chk_sum = summer.checksum(&data_vec[3..]);
if require_secret {
data_vec[0] = 0x02;
}
if client_auth {
data_vec[0] |= 0x04;
}
data_vec[1] = (public_key_type & 0xff) as u8;
data_vec[2] = (11 & 0xff) as u8;
data_vec[0] ^= chk_sum as u8;
data_vec[1] ^= (chk_sum >> 8) as u8;
data_vec[2] ^= (chk_sum >> 16) as u8;
Some(format!("{}.b32.i2p", BASE32_I2P.encode(&data_vec)))
} |
base64 decode the full 'secret' string and save binary in privkeys.dat |
Overview
Hello, I'm attempting to work with encrypted leasesets using rust, and am having difficulties calculating the encrypted/blinded destination address. Any attempt at using the derived b33 addresses results in a lookup error being returned:
Implementation
So far this is the function I have written modified from the java implementation
And here is how I'm testing:
Note that to generate the base64 string stored in the variable
pub_key
, I'm using the i2p-rs library, and running the following fromThe result of the test is the following "b33" address
m7nz7xpbohymusevu4lic3jmukc62ykf5r322vvfxgtwnrzirazadfnu.b32.i2p
however when attempting to navigate to that address using my web browser, I receive the following error messageCorrupt b32 address (or unsupported options)
Key Material
I've included the following keys generated via the SAM api, using sig type 7 (EdDSA_SHA512_Ed25519)
Public Key:
Secret Key:
The text was updated successfully, but these errors were encountered: