Search in sources :

Example 11 with Certificate

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();
}
Also used : SigningPublicKey(net.i2p.data.SigningPublicKey) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest) SigningPublicKey(net.i2p.data.SigningPublicKey) PublicKey(net.i2p.data.PublicKey) PublicKeyTest(net.i2p.data.PublicKeyTest) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest) CertificateTest(net.i2p.data.CertificateTest) Certificate(net.i2p.data.Certificate) StructureTest(net.i2p.data.StructureTest) CertificateTest(net.i2p.data.CertificateTest) Test(org.junit.Test) PublicKeyTest(net.i2p.data.PublicKeyTest) SigningPublicKeyTest(net.i2p.data.SigningPublicKeyTest)

Example 12 with Certificate

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;
}
Also used : Destination(net.i2p.data.Destination) RouterInfo(net.i2p.data.router.RouterInfo) Hash(net.i2p.data.Hash) MaskedIPSet(net.i2p.router.util.MaskedIPSet) Certificate(net.i2p.data.Certificate)

Example 13 with Certificate

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;
}
Also used : DataFormatException(net.i2p.data.DataFormatException) GarlicClove(net.i2p.data.i2np.GarlicClove) Certificate(net.i2p.data.Certificate)

Aggregations

Certificate (net.i2p.data.Certificate)13 SigningPublicKey (net.i2p.data.SigningPublicKey)6 PublicKey (net.i2p.data.PublicKey)5 CertificateTest (net.i2p.data.CertificateTest)4 PublicKeyTest (net.i2p.data.PublicKeyTest)4 SigningPublicKeyTest (net.i2p.data.SigningPublicKeyTest)4 RouterInfo (net.i2p.data.router.RouterInfo)4 Properties (java.util.Properties)3 DataFormatException (net.i2p.data.DataFormatException)3 Destination (net.i2p.data.Destination)3 StructureTest (net.i2p.data.StructureTest)3 RouterIdentity (net.i2p.data.router.RouterIdentity)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 SigType (net.i2p.crypto.SigType)2 Hash (net.i2p.data.Hash)2 KeyCertificate (net.i2p.data.KeyCertificate)2 PrivateKey (net.i2p.data.PrivateKey)2