forked from I2P_Developers/i2p.i2p
Data: Add LeaseSet methods to get encryption key by type
This commit is contained in:
@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.crypto.Blinding;
|
||||
@ -132,6 +133,20 @@ public class EncryptedLeaseSet extends LeaseSet2 {
|
||||
return super.getEncryptionKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* If more than one key, return the first supported one.
|
||||
* If none supported, return null.
|
||||
*
|
||||
* @return first supported key or null
|
||||
* @since 0.9.44
|
||||
*/
|
||||
@Override
|
||||
public PublicKey getEncryptionKey(Set<EncType> supported) {
|
||||
if (_decryptedLS2 != null)
|
||||
return _decryptedLS2.getEncryptionKey(supported);
|
||||
return super.getEncryptionKey(supported);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to set the blinded key.
|
||||
* setSecret() MUST be called before this for non-null secret, or alpha will be wrong.
|
||||
|
@ -16,9 +16,11 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.crypto.DSAEngine;
|
||||
import net.i2p.crypto.EncType;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.util.Clock;
|
||||
import net.i2p.util.Log;
|
||||
@ -131,12 +133,29 @@ public class LeaseSet extends DatabaseEntry {
|
||||
return _encryptionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* If more than one key, return the first supported one.
|
||||
* If none supported, return null.
|
||||
*
|
||||
* @param supported what return types are allowed
|
||||
* @return ElGamal key or null if ElGamal not in supported
|
||||
* @since 0.9.44
|
||||
*/
|
||||
public PublicKey getEncryptionKey(Set<EncType> supported) {
|
||||
if (supported.contains(EncType.ELGAMAL_2048))
|
||||
return _encryptionKey;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if already signed
|
||||
*/
|
||||
public void setEncryptionKey(PublicKey encryptionKey) {
|
||||
if (_signature != null)
|
||||
throw new IllegalStateException();
|
||||
// subclasses may set an ECIES key
|
||||
//if (encryptionKey.getType() != EncType.ELGAMAL_2048)
|
||||
// throw new IllegalArgumentException();
|
||||
_encryptionKey = encryptionKey;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.crypto.DSAEngine;
|
||||
@ -140,8 +141,26 @@ public class LeaseSet2 extends LeaseSet {
|
||||
return _encryptionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* If more than one key, return the first supported one.
|
||||
* If none supported, return null.
|
||||
*
|
||||
* @return first supported key or null
|
||||
* @since 0.9.44
|
||||
*/
|
||||
@Override
|
||||
public PublicKey getEncryptionKey(Set<EncType> supported) {
|
||||
for (PublicKey pk : getEncryptionKeys()) {
|
||||
if (supported.contains(pk.getType()))
|
||||
return pk;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an encryption key.
|
||||
*
|
||||
* Encryption keys should be added in order of server preference, most-preferred first.
|
||||
*/
|
||||
public void addEncryptionKey(PublicKey key) {
|
||||
if (_encryptionKey == null) {
|
||||
@ -160,6 +179,11 @@ public class LeaseSet2 extends LeaseSet {
|
||||
|
||||
/**
|
||||
* This returns all the keys. getEncryptionKey() returns the first one.
|
||||
*
|
||||
* Encryption keys should be in order of server preference, most-preferred first.
|
||||
* Client behavior should be to select the first key with a supported encryption type.
|
||||
* Clients may use other selection algorithms based on encryption support, relative performance, and other factors.
|
||||
*
|
||||
* @return not a copy, do not modify, null if none
|
||||
*/
|
||||
public List<PublicKey> getEncryptionKeys() {
|
||||
|
Reference in New Issue
Block a user