Coder Social home page Coder Social logo

Comments (2)

bonedaddy avatar bonedaddy commented on April 30, 2024

Did a bit more reading and it looks like the b33_address function i wrote is wrong, as the address needs to be derived from the public key, which isn't returned directly by DEST GENERATE with the SAM API.

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)))
}

from i2p.i2p.

zzzi2p avatar zzzi2p commented on April 30, 2024

base64 decode the full 'secret' string and save binary in privkeys.dat
run: java -jar /path/to/i2p.jar privatekeyfile privkeys.dat
compare what it gives you with your output
if it's different, check format at top of PrivateKeyFile.java to see where you went wrong.

from i2p.i2p.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.