Search in sources :

Example 26 with SigningPublicKey

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

the class KeyGeneratorTest method testKeyGen.

public void testKeyGen() {
    RandomSource.getInstance().nextBoolean();
    byte[] src = new byte[200];
    RandomSource.getInstance().nextBytes(src);
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    for (int i = 0; i < 10; i++) {
        Object[] keys = KeyGenerator.getInstance().generatePKIKeypair();
        byte[] ctext = ctx.elGamalEngine().encrypt(src, (PublicKey) keys[0]);
        byte[] ptext = ctx.elGamalEngine().decrypt(ctext, (PrivateKey) keys[1]);
        assertTrue(DataHelper.eq(ptext, src));
    }
    Object[] obj = KeyGenerator.getInstance().generateSigningKeypair();
    SigningPublicKey fake = (SigningPublicKey) obj[0];
    for (int i = 0; i < 10; i++) {
        Object[] keys = KeyGenerator.getInstance().generateSigningKeypair();
        Signature sig = DSAEngine.getInstance().sign(src, (SigningPrivateKey) keys[1]);
        assertTrue(DSAEngine.getInstance().verifySignature(sig, src, (SigningPublicKey) keys[0]));
        assertFalse(DSAEngine.getInstance().verifySignature(sig, src, fake));
    }
    for (int i = 0; i < 1000; i++) {
        KeyGenerator.getInstance().generateSessionKey();
    }
}
Also used : SigningPublicKey(net.i2p.data.SigningPublicKey) I2PAppContext(net.i2p.I2PAppContext) Signature(net.i2p.data.Signature)

Example 27 with SigningPublicKey

use of net.i2p.data.SigningPublicKey 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 28 with SigningPublicKey

use of net.i2p.data.SigningPublicKey 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 29 with SigningPublicKey

use of net.i2p.data.SigningPublicKey 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)

Example 30 with SigningPublicKey

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

the class RouterIdentityTest method testCalculatedHash.

@Test
public void testCalculatedHash() throws Exception {
    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);
    ident.calculateHash();
    ident.calculateHash();
    ident.calculateHash();
    ident.calculateHash();
    ident.calculateHash();
}
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) StructureTest(net.i2p.data.StructureTest) CertificateTest(net.i2p.data.CertificateTest) Test(org.junit.Test) PublicKeyTest(net.i2p.data.PublicKeyTest) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest)

Aggregations

SigningPublicKey (net.i2p.data.SigningPublicKey)36 SigningPrivateKey (net.i2p.data.SigningPrivateKey)13 IOException (java.io.IOException)12 DataFormatException (net.i2p.data.DataFormatException)11 SigType (net.i2p.crypto.SigType)10 Signature (net.i2p.data.Signature)10 PublicKey (net.i2p.data.PublicKey)9 File (java.io.File)8 GeneralSecurityException (java.security.GeneralSecurityException)8 PublicKey (java.security.PublicKey)7 PrivateKey (net.i2p.data.PrivateKey)6 SimpleDataStructure (net.i2p.data.SimpleDataStructure)6 BigInteger (java.math.BigInteger)5 ECPoint (java.security.spec.ECPoint)5 Certificate (net.i2p.data.Certificate)5 Destination (net.i2p.data.Destination)5 NativeBigInteger (net.i2p.util.NativeBigInteger)5 FileInputStream (java.io.FileInputStream)3 StringWriter (java.io.StringWriter)3 CertificateTest (net.i2p.data.CertificateTest)3