use of net.i2p.data.Certificate in project i2p.i2p by i2p.
the class RouterIdentityTest method testCalculatedHash.
@Test
public void testCalculatedHash() throws Exception {
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);
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
}
use of net.i2p.data.Certificate in project i2p.i2p by i2p.
the class FloodfillVerifyStoreJob method pickTarget.
/**
* Pick a responsive floodfill close to the key, but not the one we sent to
*/
private Hash pickTarget() {
Hash rkey = getContext().routingKeyGenerator().getRoutingKey(_key);
FloodfillPeerSelector sel = (FloodfillPeerSelector) _facade.getPeerSelector();
Certificate keyCert = null;
if (!_isRouterInfo) {
Destination dest = _facade.lookupDestinationLocally(_key);
if (dest != null) {
Certificate cert = dest.getCertificate();
if (cert.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY)
keyCert = cert;
}
}
if (keyCert != null) {
while (true) {
List<Hash> peers = sel.selectFloodfillParticipants(rkey, 1, _ignore, _facade.getKBuckets());
if (peers.isEmpty())
break;
Hash peer = peers.get(0);
RouterInfo ri = _facade.lookupRouterInfoLocally(peer);
// if (ri != null && StoreJob.supportsCert(ri, keyCert)) {
if (ri != null && StoreJob.shouldStoreTo(ri)) {
Set<String> peerIPs = new MaskedIPSet(getContext(), ri, IP_CLOSE_BYTES);
if (!_ipSet.containsAny(peerIPs)) {
_ipSet.addAll(peerIPs);
return peer;
} else {
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": Skipping verify w/ router too close to the store " + peer);
}
} else {
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": Skipping verify w/ router that is too old " + peer);
}
_ignore.add(peer);
}
} else {
List<Hash> peers = sel.selectFloodfillParticipants(rkey, 1, _ignore, _facade.getKBuckets());
if (!peers.isEmpty())
return peers.get(0);
}
if (_log.shouldLog(Log.WARN))
_log.warn("No other peers to verify floodfill with, using the one we sent to");
return _sentTo;
}
use of net.i2p.data.Certificate in project i2p.i2p by i2p.
the class GarlicMessageParser method readCloveSet.
private CloveSet readCloveSet(byte[] data) throws DataFormatException {
int offset = 0;
int numCloves = data[offset] & 0xff;
offset++;
if (_log.shouldLog(Log.DEBUG))
_log.debug("# cloves to read: " + numCloves);
if (numCloves <= 0 || numCloves > MAX_CLOVES)
throw new DataFormatException("bad clove count " + numCloves);
GarlicClove[] cloves = new GarlicClove[numCloves];
for (int i = 0; i < numCloves; i++) {
// if (_log.shouldLog(Log.DEBUG))
// _log.debug("Reading clove " + i);
GarlicClove clove = new GarlicClove(_context);
offset += clove.readBytes(data, offset);
cloves[i] = clove;
// if (_log.shouldLog(Log.DEBUG))
// _log.debug("After reading clove " + i);
}
// Certificate cert = new Certificate();
// offset += cert.readBytes(data, offset);
Certificate cert = Certificate.create(data, offset);
offset += cert.size();
long msgId = DataHelper.fromLong(data, offset, 4);
offset += 4;
// Date expiration = DataHelper.fromDate(data, offset);
long expiration = DataHelper.fromLong(data, offset, 8);
CloveSet set = new CloveSet(cloves, cert, msgId, expiration);
return set;
}
Aggregations