Changeset 54d9a29


Ignore:
Timestamp:
Mar 2, 2019 9:52:12 PM (21 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cd97718
Parents:
7cbb43a
Message:

I2CP, NetDB, Console: Encrypted LS2 handling fixes (WIP)
log tweaks

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbRenderer.java

    r7cbb43a r54d9a29  
    449449          for (LeaseSet ls : leases) {
    450450            Destination dest = ls.getDestination();
    451             Hash key = dest.calculateHash();
     451            Hash key = ls.getHash();
    452452            buf.append("<table class=\"leaseset\">\n")
    453453               .append("<tr><th><b>").append(_t("LeaseSet")).append(":</b>&nbsp;<code>").append(key.toBase64()).append("</code>");
    454             if (_context.keyRing().get(key) != null)
    455                 buf.append(" (").append(_t("Encrypted")).append(')');
     454            int type = ls.getType();
     455            if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2 || _context.keyRing().get(key) != null)
     456                buf.append(" <b>(").append(_t("Encrypted")).append(")</b>");
    456457            buf.append("</th>");
    457458            if (_context.clientManager().isLocal(dest)) {
     
    478479                }
    479480                buf.append(">");
    480                 String b32 = dest.toBase32();
     481                String b32 = key.toBase32();
    481482                buf.append("<a href=\"http://").append(b32).append("\">").append(b32).append("</a></td>");
    482483                if (linkSusi && !unpublished) {
     
    506507                }
    507508            }
    508             buf.append("</tr>\n<tr><td colspan=\"2\">\n");
    509             long exp = ls.getLatestLeaseDate()-now;
     509            long exp;
     510            if (type == DatabaseEntry.KEY_TYPE_LEASESET) {
     511                exp = ls.getLatestLeaseDate() - now;
     512            } else {
     513                LeaseSet2 ls2 = (LeaseSet2) ls;
     514                long pub = now - ls2.getPublished();
     515                buf.append("</tr>\n<tr><td colspan=\"2\">\n<b>")
     516                   .append(_t("Published {0} ago", DataHelper.formatDuration2(pub)))
     517                   .append("</b>");
     518                exp = ((LeaseSet2)ls).getExpires()-now;
     519            }
     520            buf.append("</tr>\n<tr><td colspan=\"2\">\n<b>");
    510521            if (exp > 0)
    511                 buf.append("<b>").append(_t("Expires in {0}", DataHelper.formatDuration2(exp))).append("</b>");
     522                buf.append(_t("Expires in {0}", DataHelper.formatDuration2(exp)));
    512523            else
    513                 buf.append("<b>").append(_t("Expired {0} ago", DataHelper.formatDuration2(0-exp))).append("</b>");
    514             buf.append("</td></tr>\n");
     524                buf.append(_t("Expired {0} ago", DataHelper.formatDuration2(0-exp)));
     525            buf.append("</b></td></tr>\n");
    515526            if (debug) {
    516527                buf.append("<tr><td colspan=\"2\">");
     
    523534                }
    524535                buf.append("&nbsp;&nbsp;<b>Distance: </b>").append(fmt.format(biLog2(dist)));
    525                 int type = ls.getType();
    526536                buf.append("&nbsp;&nbsp;<b>Type: </b>").append(type);
    527537                if (type != DatabaseEntry.KEY_TYPE_LEASESET) {
  • core/java/src/net/i2p/data/EncryptedLeaseSet.java

    r7cbb43a r54d9a29  
    287287
    288288    /**
     289     *  This must be used instead of getDestination().getHash().
     290     *
    289291     *  Overridden because we have a blinded key, not a dest.
    290292     *  This is the hash of the signing public key type and the signing public key.
     
    538540    @Override
    539541    public boolean verifySignature() {
     542        // TODO use fields in super
     543        if (_decryptedLS2 != null)
     544            return _decryptedLS2.verifySignature();
    540545        if (_log.shouldDebug()) {
    541546            _log.debug("Sig verify outer with key: " + _signingKey.getType() + ' ' + _signingKey.toBase64());
     
    597602        buf.append("[EncryptedLeaseSet: ");
    598603        buf.append("\n\tBlinded Key: ").append(_signingKey);
     604        buf.append("\n\tHash: ").append(getHash());
     605        buf.append("\n\tB32: ").append(getHash().toBase32());
    599606        if (isOffline()) {
    600607            buf.append("\n\tTransient Key: ").append(_transientSigningPublicKey);
  • core/java/src/net/i2p/data/LeaseSet.java

    r7cbb43a r54d9a29  
    403403        buf.append("[LeaseSet: ");
    404404        buf.append("\n\tDestination: ").append(_destination);
     405        buf.append("\n\tB32: ").append(_destination.toBase32());
    405406        buf.append("\n\tEncryptionKey: ").append(_encryptionKey);
    406407        buf.append("\n\tSigningKey: ").append(_signingKey);
    407         //buf.append("\n\tVersion: ").append(getVersion());
    408408        buf.append("\n\tSignature: ").append(_signature);
    409409        buf.append("\n\tLeases: #").append(getLeaseCount());
  • core/java/src/net/i2p/data/LeaseSet2.java

    r7cbb43a r54d9a29  
    5656    /**
    5757     * Published timestamp, as received.
    58      * Different than getDate(), which is the earliest lease expiration.
     58     * Different than getDate() or getEarliestLeaseDate(), which are the earliest lease expiration.
    5959     *
    6060     * @return in ms, with 1 second resolution
     
    6363    public long getPublished() {
    6464        return _published;
     65    }
     66
     67    /**
     68     * Published expiration, as received.
     69     * May be different than getLatestLeaseDate(), which is the latest lease expiration.
     70     *
     71     * @return in ms, with 1 second resolution
     72     * @since 0.9.39
     73     */
     74    public long getExpires() {
     75        return _expires;
    6576    }
    6677
     
    579590        buf.append("[LeaseSet2: ");
    580591        buf.append("\n\tDestination: ").append(_destination);
     592        buf.append("\n\tB32: ").append(_destination.toBase32());
    581593        List<PublicKey> keys = getEncryptionKeys();
    582594        int sz = keys.size();
  • router/java/src/net/i2p/router/client/ClientMessageEventListener.java

    r7cbb43a r54d9a29  
    1818import net.i2p.data.DataHelper;
    1919import net.i2p.data.Destination;
     20import net.i2p.data.EncryptedLeaseSet;
    2021import net.i2p.data.Hash;
    2122import net.i2p.data.LeaseSet;
     
    632633        }
    633634        try {
     635            if (_log.shouldDebug())
     636                _log.debug("Publishing: " + ls);
    634637            _context.netDb().publish(ls);
     638            if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
     639                // store the decrypted ls also
     640                EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
     641                if (_log.shouldDebug())
     642                    _log.debug("Storing decrypted: " + encls.getDecryptedLeaseSet());
     643                _context.netDb().store(dest.getHash(), encls.getDecryptedLeaseSet());
     644            }
    635645        } catch (IllegalArgumentException iae) {
    636646            if (_log.shouldLog(Log.ERROR))
     
    643653
    644654        // leaseSetCreated takes care of all the LeaseRequestState stuff (including firing any jobs)
    645         _runner.leaseSetCreated(ls);
     655        if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
     656            EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
     657            _runner.leaseSetCreated(encls.getDecryptedLeaseSet());
     658        } else {
     659            _runner.leaseSetCreated(ls);
     660        }
    646661    }
    647662
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    r7cbb43a r54d9a29  
    3030import net.i2p.data.KeyCertificate;
    3131import net.i2p.data.LeaseSet;
     32import net.i2p.data.LeaseSet2;
    3233import net.i2p.data.i2np.DatabaseLookupMessage;
    3334import net.i2p.data.i2np.DatabaseStoreMessage;
     
    684685            return;
    685686        }
    686         Hash h = localLeaseSet.getDestination().calculateHash();
     687        Hash h = localLeaseSet.getHash();
    687688        try {
    688689            store(h, localLeaseSet);
     
    799800     */
    800801    private String validate(Hash key, LeaseSet leaseSet) throws UnsupportedCryptoException {
    801         if (!key.equals(leaseSet.getDestination().calculateHash())) {
     802        if (!key.equals(leaseSet.getHash())) {
    802803            if (_log.shouldLog(Log.WARN))
    803804                _log.warn("Invalid store attempt! key does not match leaseSet.destination!  key = "
    804                           + key + ", leaseSet = " + leaseSet);
     805                          + key.toBase32() + ", leaseSet = " + leaseSet);
    805806            return "Key does not match leaseSet.destination - " + key.toBase64();
    806807        }
     
    813814            return "Invalid leaseSet signature on " + key;
    814815        }
    815         long earliest = leaseSet.getEarliestLeaseDate();
    816         long latest = leaseSet.getLatestLeaseDate();
     816        long earliest;
     817        long latest;
     818        int type = leaseSet.getType();
     819        if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
     820            LeaseSet2 ls2 = (LeaseSet2) leaseSet;
     821            // we'll assume it's not an encrypted meta, for now
     822            earliest = ls2.getPublished();
     823            latest = ls2.getExpires();
     824        } else if (type == DatabaseEntry.KEY_TYPE_META_LS2) {
     825            LeaseSet2 ls2 = (LeaseSet2) leaseSet;
     826            // TODO this isn't right, and must adjust limits below also
     827            earliest = Math.min(ls2.getEarliestLeaseDate(), ls2.getPublished());
     828            latest = Math.min(ls2.getLatestLeaseDate(), ls2.getExpires());
     829        } else {
     830            earliest = leaseSet.getEarliestLeaseDate();
     831            latest = leaseSet.getLatestLeaseDate();
     832        }
    817833        long now = _context.clock().now();
    818834        if (earliest <= now - 10*60*1000L ||
Note: See TracChangeset for help on using the changeset viewer.