Changeset f1df496


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

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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/Certificate.java

    rc0be83f rf1df496  
    9090     */
    9191    public static Certificate create(InputStream in) throws DataFormatException, IOException {
    92         int type = (int) DataHelper.readLong(in, 1);
     92        // EOF will be thrown in next read
     93        int type = in.read();
    9394        int length = (int) DataHelper.readLong(in, 2);
    9495        if (type == 0 && length == 0)
     
    162163        if (_type != 0 || _payload != null)
    163164            throw new IllegalStateException("already set");
    164         _type = (int) DataHelper.readLong(in, 1);
     165        // EOF will be thrown in next read
     166        _type = in.read();
    165167        int length = (int) DataHelper.readLong(in, 2);
    166168        if (length > 0) {
  • core/java/src/net/i2p/data/LeaseSet.java

    rc0be83f rf1df496  
    2020import net.i2p.I2PAppContext;
    2121import net.i2p.crypto.DSAEngine;
     22import net.i2p.crypto.SigType;
    2223import net.i2p.util.Clock;
    2324import net.i2p.util.Log;
     
    328329        _encryptionKey = PublicKey.create(in);
    329330        // revocation signing key must be same type as the destination signing key
    330         _signingKey = new SigningPublicKey(_destination.getSigningPublicKey().getType());
     331        SigType type = _destination.getSigningPublicKey().getType();
     332        // Even if not verifying, we have to construct a Signature object
     333        // below, which will fail for null type.
     334        if (type == null)
     335            throw new DataFormatException("unknown sig type");
     336        _signingKey = new SigningPublicKey(type);
     337        // EOF will be thrown in signature read below
    331338        _signingKey.readBytes(in);
    332         int numLeases = (int) DataHelper.readLong(in, 1);
     339        int numLeases = in.read();
    333340        if (numLeases > MAX_LEASES)
    334341            throw new DataFormatException("Too many leases - max is " + MAX_LEASES);
     
    340347        }
    341348        // signature must be same type as the destination signing key
    342         _signature = new Signature(_destination.getSigningPublicKey().getType());
     349        _signature = new Signature(type);
    343350        _signature.readBytes(in);
    344351    }
  • 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.