forked from I2P_Developers/i2p.i2p
Ratchet: ECIESAEADEngine main() quick test IK/N NSR
This commit is contained in:
@ -1336,33 +1336,74 @@ public final class ECIESAEADEngine {
|
|||||||
|
|
||||||
|
|
||||||
/****
|
/****
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) throws Exception {
|
||||||
I2PAppContext ctx = new I2PAppContext();
|
java.util.Properties props = new java.util.Properties();
|
||||||
|
props.setProperty("i2p.dummyClientFacade", "true");
|
||||||
|
props.setProperty("i2p.dummyNetDb", "true");
|
||||||
|
props.setProperty("i2p.vmCommSystem", "true");
|
||||||
|
props.setProperty("i2p.dummyPeerManager", "true");
|
||||||
|
props.setProperty("i2p.dummyTunnelManager", "true");
|
||||||
|
RouterContext ctx = new RouterContext(null, props);
|
||||||
|
ctx.initAll();
|
||||||
ECIESAEADEngine e = new ECIESAEADEngine(ctx);
|
ECIESAEADEngine e = new ECIESAEADEngine(ctx);
|
||||||
Object kp[] = ctx.keyGenerator().generatePKIKeypair();
|
RatchetSKM rskm = new RatchetSKM(ctx);
|
||||||
PublicKey pubKey = (PublicKey)kp[0];
|
net.i2p.crypto.KeyPair kp = ctx.keyGenerator().generatePKIKeys(EncType.ECIES_X25519);
|
||||||
PrivateKey privKey = (PrivateKey)kp[1];
|
PublicKey pubKey = kp.getPublic();
|
||||||
SessionKey sessionKey = ctx.keyGenerator().generateSessionKey();
|
PrivateKey privKey = kp.getPrivate();
|
||||||
for (int i = 0; i < 10; i++) {
|
kp = ctx.keyGenerator().generatePKIKeys(EncType.ECIES_X25519);
|
||||||
try {
|
PublicKey pubKey2 = kp.getPublic();
|
||||||
Set tags = new HashSet(5);
|
PrivateKey privKey2 = kp.getPrivate();
|
||||||
if (i == 0) {
|
|
||||||
for (int j = 0; j < 5; j++)
|
Destination dest = new Destination();
|
||||||
tags.add(new SessionTag(true));
|
GarlicClove clove = new GarlicClove(ctx);
|
||||||
|
net.i2p.data.i2np.DataMessage msg = new net.i2p.data.i2np.DataMessage(ctx);
|
||||||
|
byte[] orig = DataHelper.getUTF8("blahblahblah");
|
||||||
|
msg.setData(orig);
|
||||||
|
clove.setData(msg);
|
||||||
|
clove.setCertificate(Certificate.NULL_CERT);
|
||||||
|
clove.setCloveId(0);
|
||||||
|
clove.setExpiration(new java.util.Date(System.currentTimeMillis() + 10000));
|
||||||
|
clove.setInstructions(net.i2p.data.i2np.DeliveryInstructions.LOCAL);
|
||||||
|
GarlicClove[] arr = new GarlicClove[1];
|
||||||
|
arr[0] = clove;
|
||||||
|
CloveSet cs = new CloveSet(arr, Certificate.NULL_CERT, clove.getCloveId(), clove.getExpiration().getTime());
|
||||||
|
|
||||||
|
// IK test
|
||||||
|
byte[] encrypted = e.encrypt(cs, pubKey, dest, privKey2, rskm, null);
|
||||||
|
System.out.println("IK Encrypted:\n" + net.i2p.util.HexDump.dump(encrypted));
|
||||||
|
|
||||||
|
CloveSet cs2 = e.decrypt(encrypted, privKey, rskm);
|
||||||
|
if (cs2 == null) {
|
||||||
|
System.out.println("IK DECRYPT FAIL");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
byte encrypted[] = e.encrypt("blah".getBytes(), pubKey, sessionKey, tags, 1024);
|
System.out.println("IK Decrypted: " + cs);
|
||||||
byte decrypted[] = e.decrypt(encrypted, privKey);
|
GarlicClove clove2 = cs2.getClove(0);
|
||||||
if ("blah".equals(new String(decrypted))) {
|
net.i2p.data.i2np.DataMessage msg2 = (net.i2p.data.i2np.DataMessage) clove2.getData();
|
||||||
System.out.println("equal on " + i);
|
byte[] decrypted = msg2.getData();
|
||||||
|
if (Arrays.equals(orig, decrypted)) {
|
||||||
|
System.out.println("IK Test passed");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("NOT equal on " + i + ": " + new String(decrypted));
|
System.out.println("IK Test FAILED: " + new String(decrypted));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ctx.sessionKeyManager().tagsDelivered(pubKey, sessionKey, tags);
|
|
||||||
} catch (Exception ee) {
|
// N test
|
||||||
ee.printStackTrace();
|
encrypted = e.encrypt(cs, pubKey);
|
||||||
break;
|
System.out.println("N Encrypted:\n" + net.i2p.util.HexDump.dump(encrypted));
|
||||||
|
|
||||||
|
cs2 = e.decrypt(encrypted, privKey, rskm);
|
||||||
|
if (cs2 == null) {
|
||||||
|
System.out.println("N DECRYPT FAIL");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
System.out.println("N Decrypted: " + cs);
|
||||||
|
clove2 = cs2.getClove(0);
|
||||||
|
msg2 = (net.i2p.data.i2np.DataMessage) clove2.getData();
|
||||||
|
decrypted = msg2.getData();
|
||||||
|
if (Arrays.equals(orig, decrypted)) {
|
||||||
|
System.out.println("N Test passed");
|
||||||
|
} else {
|
||||||
|
System.out.println("N Test FAILED: " + new String(decrypted));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
****/
|
****/
|
||||||
|
Reference in New Issue
Block a user