Search in sources :

Example 6 with Certificate

use of net.i2p.data.Certificate in project i2p.i2p by i2p.

the class RouterGenerator method createRouterInfo.

static RouterInfo createRouterInfo(int num) {
    RouterInfo info = new RouterInfo();
    try {
        info.setAddresses(createAddresses(num));
        // not necessary, in constructor
        // info.setOptions(new Properties());
        // info.setPeers(new HashSet());
        info.setPublished(Clock.getInstance().now());
        RouterIdentity ident = new RouterIdentity();
        BigInteger bv = new BigInteger("" + num);
        Certificate cert = new Certificate(Certificate.CERTIFICATE_TYPE_NULL, bv.toByteArray());
        ident.setCertificate(cert);
        ident.setPublicKey(pubkey);
        ident.setSigningPublicKey(signingPubKey);
        info.setIdentity(ident);
        info.sign(signingPrivKey);
    } catch (Exception e) {
        System.err.println("Error building router " + num + ": " + e.getMessage());
        e.printStackTrace();
    }
    return info;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) RouterIdentity(net.i2p.data.router.RouterIdentity) BigInteger(java.math.BigInteger) Certificate(net.i2p.data.Certificate)

Example 7 with Certificate

use of net.i2p.data.Certificate in project i2p.i2p by i2p.

the class RouterInfoTest method createDataStructure.

@SuppressWarnings("deprecation")
public DataStructure createDataStructure() throws DataFormatException {
    RouterInfo info = new RouterInfo();
    HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();
    DataStructure structure = (new RouterAddressTest()).createDataStructure();
    addresses.add((RouterAddress) structure);
    info.setAddresses(addresses);
    PublicKey pubKey = null;
    SigningPublicKey signingPubKey = null;
    PrivateKey privKey = null;
    SigningPrivateKey signingPrivKey = null;
    Object[] obj = KeyGenerator.getInstance().generatePKIKeypair();
    pubKey = (PublicKey) obj[0];
    privKey = (PrivateKey) obj[1];
    obj = KeyGenerator.getInstance().generateSigningKeypair();
    signingPubKey = (SigningPublicKey) obj[0];
    signingPrivKey = (SigningPrivateKey) obj[1];
    _log.debug("SigningPublicKey: " + signingPubKey);
    _log.debug("SigningPrivateKey: " + signingPrivKey);
    RouterIdentity ident = new RouterIdentity();
    ident.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
    ident.setPublicKey(pubKey);
    ident.setSigningPublicKey(signingPubKey);
    info.setIdentity(ident);
    Properties options = new Properties();
    for (int i = 0; i < 16; i++) {
        options.setProperty("option." + i, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890$:." + i);
    }
    options.setProperty("netConnectionSpeed", "OC12");
    info.setOptions(options);
    HashSet<Hash> peers = new HashSet<Hash>();
    structure = (new HashTest()).createDataStructure();
    peers.add((Hash) structure);
    info.setPeers(peers);
    info.setPublished(System.currentTimeMillis());
    // info.setVersion(69);
    info.sign(signingPrivKey);
    return info;
}
Also used : SigningPublicKey(net.i2p.data.SigningPublicKey) PrivateKey(net.i2p.data.PrivateKey) SigningPrivateKey(net.i2p.data.SigningPrivateKey) SigningPublicKey(net.i2p.data.SigningPublicKey) PublicKey(net.i2p.data.PublicKey) DataStructure(net.i2p.data.DataStructure) Properties(java.util.Properties) Hash(net.i2p.data.Hash) HashTest(net.i2p.data.HashTest) SigningPrivateKey(net.i2p.data.SigningPrivateKey) HashSet(java.util.HashSet) Certificate(net.i2p.data.Certificate)

Example 8 with Certificate

use of net.i2p.data.Certificate in project i2p.i2p by i2p.

the class BuildTestMessageJob method buildGarlicCloveConfig.

private GarlicConfig buildGarlicCloveConfig() {
    _testMessageKey = getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE);
    if (_log.shouldLog(Log.INFO))
        _log.info("Test message key: " + _testMessageKey);
    GarlicConfig config = new GarlicConfig();
    PayloadGarlicConfig ackClove = buildAckClove();
    config.addClove(ackClove);
    DeliveryInstructions instructions = new DeliveryInstructions();
    instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
    instructions.setRouter(_target.getIdentity().getHash());
    instructions.setTunnelId(null);
    config.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
    config.setDeliveryInstructions(instructions);
    config.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
    config.setExpiration(_timeoutMs + getContext().clock().now() + 2 * Router.CLOCK_FUDGE_FACTOR);
    config.setRecipient(_target);
    return config;
}
Also used : DeliveryInstructions(net.i2p.data.i2np.DeliveryInstructions) Certificate(net.i2p.data.Certificate)

Example 9 with Certificate

use of net.i2p.data.Certificate in project i2p.i2p by i2p.

the class RouterIdentityTest method testNullPublicKey.

@Test
public void testNullPublicKey() throws Exception {
    RouterIdentity ident = new RouterIdentity();
    Certificate cert = (Certificate) (new CertificateTest()).createDataStructure();
    ident.setCertificate(cert);
    ident.setPublicKey(null);
    SigningPublicKey k = (SigningPublicKey) (new SigningPublicKeyTest()).createDataStructure();
    ident.setSigningPublicKey(k);
    exception.expect(DataFormatException.class);
    exception.expectMessage("Not enough data to format the router identity");
    ident.writeBytes(new ByteArrayOutputStream());
}
Also used : SigningPublicKey(net.i2p.data.SigningPublicKey) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest) CertificateTest(net.i2p.data.CertificateTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Certificate(net.i2p.data.Certificate) StructureTest(net.i2p.data.StructureTest) CertificateTest(net.i2p.data.CertificateTest) Test(org.junit.Test) PublicKeyTest(net.i2p.data.PublicKeyTest) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest)

Example 10 with Certificate

use of net.i2p.data.Certificate in project i2p.i2p by i2p.

the class RouterIdentityTest method createDataStructure.

public DataStructure createDataStructure() throws DataFormatException {
    RouterIdentity ident = new RouterIdentity();
    Certificate cert = (Certificate) (new CertificateTest()).createDataStructure();
    ident.setCertificate(cert);
    PublicKey pk = (PublicKey) (new PublicKeyTest()).createDataStructure();
    ident.setPublicKey(pk);
    SigningPublicKey k = (SigningPublicKey) (new SigningPublicKeyTest()).createDataStructure();
    ident.setSigningPublicKey(k);
    return ident;
}
Also used : SigningPublicKey(net.i2p.data.SigningPublicKey) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest) SigningPublicKey(net.i2p.data.SigningPublicKey) PublicKey(net.i2p.data.PublicKey) PublicKeyTest(net.i2p.data.PublicKeyTest) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest) CertificateTest(net.i2p.data.CertificateTest) Certificate(net.i2p.data.Certificate)

Aggregations

Certificate (net.i2p.data.Certificate)13 SigningPublicKey (net.i2p.data.SigningPublicKey)6 PublicKey (net.i2p.data.PublicKey)5 CertificateTest (net.i2p.data.CertificateTest)4 PublicKeyTest (net.i2p.data.PublicKeyTest)4 SigningPublicKeyTest (net.i2p.data.SigningPublicKeyTest)4 RouterInfo (net.i2p.data.router.RouterInfo)4 Properties (java.util.Properties)3 DataFormatException (net.i2p.data.DataFormatException)3 Destination (net.i2p.data.Destination)3 StructureTest (net.i2p.data.StructureTest)3 RouterIdentity (net.i2p.data.router.RouterIdentity)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 SigType (net.i2p.crypto.SigType)2 Hash (net.i2p.data.Hash)2 KeyCertificate (net.i2p.data.KeyCertificate)2 PrivateKey (net.i2p.data.PrivateKey)2