/** * Does the base64 information look OK * * @param data * @return OK */ private static boolean is64ok(String data) { try { new Destination(data); return true; } catch (Exception e) { return false; } }
/** Base64 only - static (no naming service) */ static Destination getDestinationFromBase64(String ip) { if (ip == null) return null; if (ip.endsWith(".i2p")) { if (ip.length() < 520) return null; try { return new Destination(ip.substring(0, ip.length()-4)); // sans .i2p } catch (DataFormatException dfe) { return null; } } else { try { return new Destination(ip); } catch (DataFormatException dfe) { return null; } } }
public DataStructure createStructureToRead() { return new Destination(); } }
@Test(expected=IllegalArgumentException.class) public void testConstruct_Dest_negPort_throwsIAE() { new I2PSocketAddress(new Destination(), -1); }
@Test(expected=IllegalArgumentException.class) public void testConstruct_Dest_highPort_throwsIAE() { new I2PSocketAddress(new Destination(), 90000); }
/** * If the host name is a valid Base64 encoded destination, return the * decoded Destination. Useful as a "fallback" in custom naming * implementations. * This is misnamed as it isn't a "lookup" at all, but * a simple conversion from a Base64 string to a Destination. * * @param hostname 516+ character Base 64 * @return Destination or null on error */ protected Destination lookupBase64(String hostname) { try { Destination result = new Destination(); result.fromBase64(hostname); return result; } catch (DataFormatException dfe) { if (_log.shouldLog(Log.WARN)) _log.warn("Bad B64 dest [" + hostname + "]", dfe); return null; } }
/** * Read in the given destination, display it, and write it to the given location * Deprecated - only used by CLI * * @param readFrom stream to read the destination from * @param pubDest stream to write the destination to * @param l logger to send messages to */ private static void showKey(InputStream readFrom, OutputStream pubDest, Logging l) { try { Destination d = new Destination(); d.readBytes(readFrom); l.log("Destination: " + d.toBase32()); readFrom.close(); writePubKey(d, pubDest, l); } catch (I2PException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }
_producer = producer; _availableMessages = new ConcurrentHashMap<Long, MessagePayloadMessage>(); _myDestination = new Destination(); _privateKey = new PrivateKey(); _signingPrivateKey = new SigningPrivateKey();
/** * @param padding null OK, must be non-null if spubkey length < 128 * @throws IllegalArgumentException on mismatch of spubkey and spk types * @since 0.9.16 */ public PrivateKeyFile(File file, PublicKey pubkey, SigningPublicKey spubkey, Certificate cert, PrivateKey pk, SigningPrivateKey spk, byte[] padding) { if (spubkey.getType() != spk.getType()) throw new IllegalArgumentException("Signing key type mismatch"); this.file = file; this.client = null; this.dest = new Destination(); this.dest.setPublicKey(pubkey); this.dest.setSigningPublicKey(spubkey); this.dest.setCertificate(cert); if (padding != null) this.dest.setPadding(padding); this.privKey = pk; this.signingPrivKey = spk; }
Destination d; try { d = new Destination(dest); } catch (DataFormatException dfe) { return false;
/** * Change cert type - caller must also call write(). * Side effect - creates new Destination object. */ public Certificate setCertType(int t) { if (this.dest == null) throw new IllegalArgumentException("Dest is null"); Certificate c = new Certificate(); c.setCertificateType(t); // dests now immutable, must create new Destination newdest = new Destination(); newdest.setPublicKey(dest.getPublicKey()); newdest.setSigningPublicKey(dest.getSigningPublicKey()); newdest.setCertificate(c); dest = newdest; return c; }
/** * Create from persistent storage string. * Format: NID:Hash:Destination:port * First 3 in base 64; Destination may be empty string * @throws IllegalArgumentException */ public NodeInfo(String s) throws DataFormatException { super(); String[] parts = DataHelper.split(s, ":", 4); if (parts.length != 4) throw new DataFormatException("Bad format"); byte[] nid = Base64.decode(parts[0]); if (nid == null || nid.length != NID.HASH_LENGTH) throw new DataFormatException("Bad NID"); nID = new NID(nid); byte[] h = Base64.decode(parts[1]); if (h == null || h.length != Hash.HASH_LENGTH) throw new DataFormatException("Bad hash"); //hash = new Hash(h); hash = Hash.create(h); if (parts[2].length() > 0) dest = new Destination(parts[2]); try { port = Integer.parseInt(parts[3]); } catch (NumberFormatException nfe) { throw new DataFormatException("Bad port", nfe); } initialize(); }
@Test public void testConstruct_Dest() { Destination dest = new Destination(); I2PSocketAddress addr = new I2PSocketAddress(dest, 1234); assertThat(addr.getPort(), is(1234)); assertThat(addr.getAddress(), is(dest)); assertThat(addr.getHostName(), is(nullValue())); assertFalse(addr.isUnresolved()); }
Destination d; try { d = new Destination(olddest); } catch (DataFormatException dfe) { return false;
dest = new Destination(); dest.setPublicKey(ri.getPublicKey()); dest.setSigningPublicKey(ri.getSigningPublicKey());
rv = new Destination(pk, sk, c, padding); _cache.put(sk, rv);
signingPrivKey = (SigningPrivateKey) signingKeys[1]; Destination newdest = new Destination(); newdest.setPublicKey(dest.getPublicKey()); newdest.setSigningPublicKey(signingPubKey);
public void testAddRemoveLookup() throws Exception{ String testB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA"; Destination testDest = new Destination(); testDest.fromBase64(testB64); String testB642 = "24SmhWiRDm-GzpV5Gq2sXhuvPpa1OihY7rkxQO4aHy5qKjr6zmEnZ3xQXdkFJJ0Z1lKy73XRmgCyys02G25Hl3cuxlZ2fNbp6KhOzlRKpOIAWFdSWZNF4Fp7sos0x-a-9fxOWnwwQ9MFcRYwixE~iCZf4JG~-Pd-MHgAuDhIX0P3~GmfUvo~9xPjof1ZsnaOV1zC0XUkHxZA5D6V0Bse~Ptfb66lPNcgBxIEntCStBAy~rTjaA3SdAufG29IRWDscpFq1-D4XPaXHnlXu7n7WdpFEM8WWd3ebUMqnq8XvLL1eqoWYzKCe3aaavC3W6~pJp8cxKl2IKrhvSFatHZ0chRg3B4~ja1Cxmw1psisplSkJqMnF921E6pury0i6GH52XAVoj4iiDY~EAvqDhzG-ThwlzTs~2JKzslwxOrD2ejd-dcKdi4i9xvi2JQ4Ib2Mw2ktaQhuAw3Y9EkqAs7oriQQN8N8dwIoYkJLfvh7ousm0iKJJvMt3s55PccM46SoAAAA"; Destination testDest2 = new Destination(); testDest2.fromBase64(testB642);
public DataStructure createDataStructure() throws DataFormatException { Destination dest = new Destination(); StructureTest tst = new CertificateTest(); dest.setCertificate((Certificate)tst.createDataStructure()); tst = new PublicKeyTest(); dest.setPublicKey((PublicKey)tst.createDataStructure()); tst = new SigningPublicKeyTest(); dest.setSigningPublicKey((SigningPublicKey)tst.createDataStructure()); return dest; } public DataStructure createStructureToRead() { return new Destination(); }
@Test public void testEquals() { I2PSocketAddress addr = I2PSocketAddress.createUnresolved("example.i2p", 1234); assertTrue(addr.equals(I2PSocketAddress.createUnresolved("example.i2p", 1234))); assertFalse(addr.equals(I2PSocketAddress.createUnresolved("example2.i2p", 1234))); assertFalse(addr.equals(I2PSocketAddress.createUnresolved("example.i2p", 1235))); assertFalse(addr.equals(I2PSocketAddress.createUnresolved("example.i2p", 1235))); Destination dest = new Destination(); I2PSocketAddress addr2 = new I2PSocketAddress(dest, 1234); assertFalse(addr.equals(null)); assertFalse(addr.equals(dest)); assertFalse(addr.equals(addr2)); assertFalse(addr2.equals(addr)); } }