Changeset 3cd12ec


Ignore:
Timestamp:
Jan 27, 2019 3:59:34 PM (20 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3fca0f6
Parents:
0889a75
Message:

LS2: Select first supported encryption key from leaseset
OCMOSJ: Fail if unsupported crypto or bad ls type

Files:
2 edited

Legend:

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

    r0889a75 r3cd12ec  
    6565            return null;
    6666        return _options.getProperty(opt);
     67    }
     68
     69    /**
     70     *  If more than one key, return the first supported one.
     71     *  If none supported, return the first one.
     72     *
     73     *  @since 0.9.39 overridden
     74     */
     75    @Override
     76    public PublicKey getEncryptionKey() {
     77        if (_encryptionKeys != null) {
     78            for (PublicKey pk : _encryptionKeys) {
     79                EncType type = pk.getType();
     80                if (type != null && type.isAvailable())
     81                    return pk;
     82            }
     83        }
     84        return _encryptionKey;
    6785    }
    6886
  • router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java

    r0889a75 r3cd12ec  
    99
    1010import net.i2p.client.SendMessageOptions;
     11import net.i2p.crypto.EncType;
    1112import net.i2p.crypto.SessionKeyManager;
    1213import net.i2p.crypto.TagSetHandle;
     
    312313        }
    313314    }
    314    
     315
    315316    /**
    316317     *  @param force to force including a reply lease set
     
    375376     *  Choose a lease from his leaseset to send the message to. Sets _lease.
    376377     *  Sets _wantACK if it's new or changed.
     378     *  Does several checks to see if we can actually send to this leaseset,
     379     *  and returns nonzero failure code if unable to.
     380     *
    377381     *  @return 0 on success, or a MessageStatusMessage failure code
    378382     */
     
    388392            }
    389393        }
    390         if (_leaseSet.getType() == DatabaseEntry.KEY_TYPE_META_LS2) {
    391             // can't send to a meta LS
     394
     395        int lsType = _leaseSet.getType();
     396        // Can't send to a meta LS.
     397        // TODO Encrypted LS2 must have been previously decrypted.
     398        if (lsType != DatabaseEntry.KEY_TYPE_LEASESET &&
     399            lsType != DatabaseEntry.KEY_TYPE_LS2) {
    392400            return MessageStatusMessage.STATUS_SEND_FAILURE_BAD_LEASESET;
    393401        }
     402        PublicKey pk = _leaseSet.getEncryptionKey();
     403        if (pk == null)
     404            return MessageStatusMessage.STATUS_SEND_FAILURE_BAD_LEASESET;
     405        EncType encType = pk.getType();
     406        if (encType == null || !encType.isAvailable())
     407            return MessageStatusMessage.STATUS_SEND_FAILURE_UNSUPPORTED_ENCRYPTION;
    394408
    395409        // Use the same lease if it's still good
Note: See TracChangeset for help on using the changeset viewer.