/** * Generate a random destination key. * Caller must close streams. Fails silently. * * @param priv Stream used to write the destination and private keys * @param pub Stream used to write the destination (may be null) * @param sigType what signature type * @since 0.9.14 */ public static void genRandomKey(OutputStream priv, OutputStream pub, SigType sigType) { //_log.debug("Generating random keys..."); try { I2PClient c = I2PClientFactory.createClient(); Destination d = c.createDestination(priv, sigType); priv.flush(); if (pub != null) { d.writeBytes(pub); pub.flush(); } } catch (I2PException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public void testI2PClient() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); _client.createDestination(out); _client.createSession(new ByteArrayInputStream(out.toByteArray()), null); } }
/** * Create with the specified signature type if nonexistent. * * Also reads in the file to get the privKey and signingPrivKey, * which aren't available from I2PClient. * * @since 0.9.26 */ public Destination createIfAbsent(SigType type) throws I2PException, IOException, DataFormatException { if(!this.file.exists()) { OutputStream out = null; try { out = new SecureFileOutputStream(this.file); if (this.client != null) this.client.createDestination(out, type); else write(); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) {} } } } return getDestination(); }
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try { client.createDestination(keyStream, getSigType(opts)); } catch (I2PException e) { throw new I2PSessionException("Error creating keys", e);
/** * Create a new destination, storing the destination and its private keys where * instructed. * Does NOT support non-default sig types. * Deprecated - only used by CLI * * @param writeTo location to store the destination and private keys * @param pubDest location to store the destination * @param l logger to send messages to */ private static void makeKey(OutputStream writeTo, OutputStream pubDest, Logging l) { try { l.log("Generating new keys..."); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(writeTo); l.log("New destination: " + d.toBase32()); writeTo.flush(); writeTo.close(); writePubKey(d, pubDest, l); } catch (I2PException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }
protected I2PSession createSession() throws Exception { I2PClient client = I2PClientFactory.createClient(); ByteArrayOutputStream baos = new ByteArrayOutputStream(512); client.createDestination(baos); Properties p = getProperties(); I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p); sess.connect(); return sess; }
/** * Create a socket manager using a brand new destination connected to the * I2CP router on the given machine reachable through the given port. * * Blocks for a long time while the router builds tunnels. * The nonblocking createDisconnectedManager() is preferred. * * @param i2cpHost I2CP host null to use default, ignored if in router context * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context * @param opts Streaming and I2CP options, may be null * @return the newly created socket manager, or null if there were errors */ public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts) { I2PClient client = I2PClientFactory.createClient(); ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try { client.createDestination(keyStream, getSigType(opts)); ByteArrayInputStream in = new ByteArrayInputStream(keyStream.toByteArray()); return createManager(in, i2cpHost, i2cpPort, opts); } catch (IOException ioe) { getLog().error("Error creating the destination for socket manager", ioe); return null; } catch (I2PException ie) { getLog().error("Error creating the destination for socket manager", ie); return null; } }
@Test public void testCreateDiscMgr_customDest() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Destination dest = I2PClientFactory.createClient().createDestination(baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); I2PSocketManagerFull mgr = (I2PSocketManagerFull) I2PSocketManagerFactory.createDisconnectedManager(bais, null, 0, null); assertThat(mgr, is(not(nullValue()))); assertThat(mgr.getName(), is("manager")); assertThat(mgr.getSession().getMyDestination(), is(equalTo(dest))); }
l.log("Unsupported sig type " + st); client.createDestination(out, stype); key = out.toByteArray(); } catch(Exception exc) {
@Test public void testToString() throws Exception { Destination dest = I2PClientFactory.createClient().createDestination(new ByteArrayOutputStream()); I2PSocketAddress addr = new I2PSocketAddress(dest, 1234); assertThat(addr.toString(), is(equalTo(dest.calculateHash().toString() + ":1234"))); }
log("Unsupported sig type " + st + ", reverting to " + stype); Destination dest = client.createDestination(fos, stype); String destStr = dest.toBase64(); log("Private key created and saved in " + keyFile.getAbsolutePath());
d = I2PClientFactory.createClient().createDestination(prikey); wlock(); try {
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();
public void testDatagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); I2PDatagramMaker dm = new I2PDatagramMaker(session); byte[] dg = dm.makeI2PDatagram(DataHelper.getASCII("What's the deal with 42?")); I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(dg); byte[] x = dd.getPayload(); assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); x = dd.extractPayload(); assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); assertEquals(d, dd.getSender()); assertEquals(d, dd.extractSender()); }
private I2PSession createI2PSession() throws KeyException { try { I2PClient i2pClient = I2PClientFactory.createClient(); ByteArrayOutputStream arrayStream = new ByteArrayOutputStream(); i2pClient.createDestination(arrayStream); byte[] destinationArray = arrayStream.toByteArray(); I2PSession i2pSession = i2pClient.createSession(new ByteArrayInputStream(destinationArray), null); return i2pSession; } catch (Exception e) { throw new KeyException("Can't generate I2P destination.", e); } }
private Ping() throws Exception { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { i2pSession.destroySession(); System.out.println("Finished"); } catch (I2PSessionException e) { e.printStackTrace(); } } }); // initialize i2pSession I2PClient i2pClient = I2PClientFactory.createClient(); ByteArrayOutputStream arrayStream = new ByteArrayOutputStream(); i2pClient.createDestination(arrayStream); byte[] destinationArray = arrayStream.toByteArray(); i2pSession = i2pClient.createSession(new ByteArrayInputStream(destinationArray), null); i2pSession.connect(); }
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try { client.createDestination(keyStream, getSigType(opts)); } catch (I2PException e) { throw new I2PSessionException("Error creating keys", e);
/** * Create a socket manager using a brand new destination connected to the * I2CP router on the given machine reachable through the given port. * * Blocks for a long time while the router builds tunnels. * The nonblocking createDisconnectedManager() is preferred. * * @param i2cpHost I2CP host null to use default, ignored if in router context * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context * @param opts Streaming and I2CP options, may be null * @return the newly created socket manager, or null if there were errors */ public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts) { I2PClient client = I2PClientFactory.createClient(); ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try { client.createDestination(keyStream, getSigType(opts)); ByteArrayInputStream in = new ByteArrayInputStream(keyStream.toByteArray()); return createManager(in, i2cpHost, i2cpPort, opts); } catch (IOException ioe) { getLog().error("Error creating the destination for socket manager", ioe); return null; } catch (I2PException ie) { getLog().error("Error creating the destination for socket manager", ie); return null; } }
try { ByteArrayOutputStream arrayStream = new ByteArrayOutputStream(); i2pClient.createDestination(arrayStream); byte[] localDestinationKey = arrayStream.toByteArray();