use of net.i2p.data.Certificate in project i2p.i2p by i2p.
the class RouterGenerator method createRouterInfo.
static RouterInfo createRouterInfo(int num) {
RouterInfo info = new RouterInfo();
try {
info.setAddresses(createAddresses(num));
// not necessary, in constructor
// info.setOptions(new Properties());
// info.setPeers(new HashSet());
info.setPublished(Clock.getInstance().now());
RouterIdentity ident = new RouterIdentity();
BigInteger bv = new BigInteger("" + num);
Certificate cert = new Certificate(Certificate.CERTIFICATE_TYPE_NULL, bv.toByteArray());
ident.setCertificate(cert);
ident.setPublicKey(pubkey);
ident.setSigningPublicKey(signingPubKey);
info.setIdentity(ident);
info.sign(signingPrivKey);
} catch (Exception e) {
System.err.println("Error building router " + num + ": " + e.getMessage());
e.printStackTrace();
}
return info;
}
use of net.i2p.data.Certificate 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;
}
use of net.i2p.data.Certificate in project i2p.i2p by i2p.
the class BuildTestMessageJob method buildGarlicCloveConfig.
private GarlicConfig buildGarlicCloveConfig() {
_testMessageKey = getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE);
if (_log.shouldLog(Log.INFO))
_log.info("Test message key: " + _testMessageKey);
GarlicConfig config = new GarlicConfig();
PayloadGarlicConfig ackClove = buildAckClove();
config.addClove(ackClove);
DeliveryInstructions instructions = new DeliveryInstructions();
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
instructions.setRouter(_target.getIdentity().getHash());
instructions.setTunnelId(null);
config.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
config.setDeliveryInstructions(instructions);
config.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
config.setExpiration(_timeoutMs + getContext().clock().now() + 2 * Router.CLOCK_FUDGE_FACTOR);
config.setRecipient(_target);
return config;
}
use of net.i2p.data.Certificate 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());
}
use of net.i2p.data.Certificate 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;
}
Aggregations