Search in sources :

Example 1 with DSAEngine

use of net.i2p.crypto.DSAEngine in project i2p.i2p by i2p.

the class DatagramTest method testBadagram.

public void testBadagram() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    I2PClient client = I2PClientFactory.createClient();
    Destination d = client.createDestination(out);
    I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null);
    DSAEngine dsaEng = DSAEngine.getInstance();
    ByteArrayOutputStream dout = new ByteArrayOutputStream();
    d.writeBytes(dout);
    dsaEng.sign(Hash.FAKE_HASH.toByteArray(), session.getPrivateKey()).writeBytes(dout);
    dout.write(DataHelper.getASCII("blah"));
    byte[] data = dout.toByteArray();
    I2PDatagramDissector dd = new I2PDatagramDissector();
    dd.loadI2PDatagram(data);
    boolean error = false;
    try {
        dd.getPayload();
    } catch (I2PInvalidDatagramException i2pide) {
        error = true;
    }
    assertTrue(error);
    error = false;
    try {
        dd.getSender();
    } catch (I2PInvalidDatagramException i2pide) {
        error = true;
    }
    assertTrue(error);
    error = false;
    try {
        dd.getHash();
    } catch (I2PInvalidDatagramException i2pide) {
        error = true;
    }
    assertTrue(error);
}
Also used : Destination(net.i2p.data.Destination) DSAEngine(net.i2p.crypto.DSAEngine) ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PClient(net.i2p.client.I2PClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 I2PClient (net.i2p.client.I2PClient)1 I2PSession (net.i2p.client.I2PSession)1 DSAEngine (net.i2p.crypto.DSAEngine)1 Destination (net.i2p.data.Destination)1