Changeset f1df496 for router


Ignore:
Timestamp:
Aug 4, 2018 1:41:01 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2cc362c
Parents:
c0be83f
Message:

Data: Check sooner for unknown sig type;
minor efficiency improvements in parsing

Location:
router/java/src/net/i2p/data/router
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/data/router/RouterAddress.java

    rc0be83f rf1df496  
    280280        if (_transportStyle != null)
    281281            throw new IllegalStateException();
    282         _cost = (short) DataHelper.readLong(in, 1);
     282        // EOF will be thrown in next read
     283        _cost = (short) in.read();
    283284        _expiration = DataHelper.readLong(in, 8);
    284285        _transportStyle = DataHelper.readString(in);
  • router/java/src/net/i2p/data/router/RouterInfo.java

    rc0be83f rf1df496  
    550550        InputStream din;
    551551        MessageDigest digest;
     552        SigType type = _identity.getSigningPublicKey().getType();
     553        // Even if not verifying, we have to construct a Signature object
     554        // below, which will fail for null type.
     555        if (type == null)
     556            throw new DataFormatException("unknown sig type");
    552557        if (verifySig) {
    553             SigType type = _identity.getSigningPublicKey().getType();
    554558            if (type != SigType.EdDSA_SHA512_Ed25519) {
    555559                // This won't work for EdDSA
    556                 digest = _identity.getSigningPublicKey().getType().getDigestInstance();
     560                digest = type.getDigestInstance();
    557561                // TODO any better way?
    558562                digest.update(_identity.toByteArray());
     
    573577        //    _published = when.getTime();
    574578        _published = DataHelper.readLong(din, 8);
    575         int numAddresses = (int) DataHelper.readLong(din, 1);
     579        // EOF will be thrown in properties read below
     580        int numAddresses = din.read();
    576581        for (int i = 0; i < numAddresses; i++) {
    577582            RouterAddress address = new RouterAddress();
     
    579584            _addresses.add(address);
    580585        }
    581         int numPeers = (int) DataHelper.readLong(din, 1);
    582         if (numPeers == 0) {
     586        // EOF will be thrown in properties read below
     587        int numPeers = din.read();
     588        if (numPeers <= 0) {
    583589            _peers = null;
    584590        } else {
     
    591597        }
    592598        DataHelper.readProperties(din, _options);
    593         _signature = new Signature(_identity.getSigningPublicKey().getType());
     599        _signature = new Signature(type);
    594600        _signature.readBytes(in);
    595601
    596602        if (verifySig) {
    597             SigType type = _identity.getSigningPublicKey().getType();
    598603            if (type != SigType.EdDSA_SHA512_Ed25519) {
    599604                // This won't work for EdDSA
    600                 SimpleDataStructure hash = _identity.getSigningPublicKey().getType().getHashInstance();
     605                SimpleDataStructure hash = type.getHashInstance();
    601606                hash.setData(digest.digest());
    602607                _isValid = DSAEngine.getInstance().verifySignature(_signature, hash, _identity.getSigningPublicKey());
Note: See TracChangeset for help on using the changeset viewer.