forked from I2P_Developers/i2p.i2p
I2CP: Basic router-side handling of meta LS2
Improve error handling of LS2 params client-side Methods to remember blinded key in LS2
This commit is contained in:
@@ -103,6 +103,7 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
|
|||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
session.propogateError("Bad LS2 type", nfe);
|
session.propogateError("Bad LS2 type", nfe);
|
||||||
|
session.destroySession();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,6 +125,7 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
|
|||||||
leaseSet = new MetaLeaseSet();
|
leaseSet = new MetaLeaseSet();
|
||||||
} else {
|
} else {
|
||||||
session.propogateError("Unsupported LS2 type", new Exception());
|
session.propogateError("Unsupported LS2 type", new Exception());
|
||||||
|
session.destroySession();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -284,7 +286,7 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
|
|||||||
session.getOfflineSignature());
|
session.getOfflineSignature());
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
session.propogateError("Bad offline signature", new Exception());
|
session.propogateError("Bad offline signature", new Exception());
|
||||||
// TODO just let the router handle it for now
|
session.destroySession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -306,6 +308,7 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
|
|||||||
_log.debug("Created and signed LeaseSet: " + leaseSet);
|
_log.debug("Created and signed LeaseSet: " + leaseSet);
|
||||||
} catch (DataFormatException dfe) {
|
} catch (DataFormatException dfe) {
|
||||||
session.propogateError("Error signing the leaseSet", dfe);
|
session.propogateError("Error signing the leaseSet", dfe);
|
||||||
|
session.destroySession();
|
||||||
} catch (I2PSessionException ise) {
|
} catch (I2PSessionException ise) {
|
||||||
if (session.isClosed()) {
|
if (session.isClosed()) {
|
||||||
// race, closed while signing leaseset
|
// race, closed while signing leaseset
|
||||||
|
@@ -50,6 +50,7 @@ class RequestVariableLeaseSetMessageHandler extends RequestLeaseSetMessageHandle
|
|||||||
leaseSet = new MetaLeaseSet();
|
leaseSet = new MetaLeaseSet();
|
||||||
} else {
|
} else {
|
||||||
session.propogateError("Unsupported LS2 type", new Exception());
|
session.propogateError("Unsupported LS2 type", new Exception());
|
||||||
|
session.destroySession();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -39,6 +39,8 @@ public class LeaseSet2 extends LeaseSet {
|
|||||||
protected Properties _options;
|
protected Properties _options;
|
||||||
// only used if more than one key, otherwise null
|
// only used if more than one key, otherwise null
|
||||||
private List<PublicKey> _encryptionKeys;
|
private List<PublicKey> _encryptionKeys;
|
||||||
|
// If this leaseset was formerly blinded, the blinded hash, so we can find it again
|
||||||
|
private Hash _blindedHash;
|
||||||
|
|
||||||
private static final int FLAG_OFFLINE_KEYS = 1;
|
private static final int FLAG_OFFLINE_KEYS = 1;
|
||||||
private static final int FLAG_UNPUBLISHED = 2;
|
private static final int FLAG_UNPUBLISHED = 2;
|
||||||
@@ -182,6 +184,21 @@ public class LeaseSet2 extends LeaseSet {
|
|||||||
return ctx.dsa().verifySignature(_offlineSignature, data, 0, data.length, getSigningPublicKey());
|
return ctx.dsa().verifySignature(_offlineSignature, data, 0, data.length, getSigningPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this on creation if known
|
||||||
|
*/
|
||||||
|
public void setBlindedHash(Hash bh) {
|
||||||
|
_blindedHash = bh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The orignal blinded hash, where this came from.
|
||||||
|
* @return null if unknown or not previously blinded
|
||||||
|
*/
|
||||||
|
public Hash getBlindedHash() {
|
||||||
|
return _blindedHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///// overrides below here
|
///// overrides below here
|
||||||
|
|
||||||
|
@@ -13,9 +13,11 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import net.i2p.CoreVersion;
|
import net.i2p.CoreVersion;
|
||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
|
import net.i2p.data.DatabaseEntry;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
|
import net.i2p.data.LeaseSet;
|
||||||
import net.i2p.data.Payload;
|
import net.i2p.data.Payload;
|
||||||
import net.i2p.data.PublicKey;
|
import net.i2p.data.PublicKey;
|
||||||
import net.i2p.data.i2cp.BandwidthLimitsMessage;
|
import net.i2p.data.i2cp.BandwidthLimitsMessage;
|
||||||
@@ -266,6 +268,14 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
props.putAll(inProps);
|
props.putAll(inProps);
|
||||||
|
if ("7".equals(props.getProperty("i2cp.leaseSetType"))) {
|
||||||
|
// Prevent tunnel builds for Meta LS
|
||||||
|
// more TODO
|
||||||
|
props.setProperty("inbound.length", "0");
|
||||||
|
props.setProperty("outbound.length", "0");
|
||||||
|
props.setProperty("inbound.lengthVariance", "0");
|
||||||
|
props.setProperty("outbound.lengthVariance", "0");
|
||||||
|
}
|
||||||
cfg.setOptions(props);
|
cfg.setOptions(props);
|
||||||
// this sets the session id
|
// this sets the session id
|
||||||
int status = _runner.sessionEstablished(cfg);
|
int status = _runner.sessionEstablished(cfg);
|
||||||
@@ -469,10 +479,19 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
|
|
||||||
/** override for testing */
|
/** override for testing */
|
||||||
protected void handleCreateLeaseSet(CreateLeaseSetMessage message) {
|
protected void handleCreateLeaseSet(CreateLeaseSetMessage message) {
|
||||||
if ( (message.getLeaseSet() == null) || (message.getPrivateKey() == null) || (message.getSigningPrivateKey() == null) ) {
|
LeaseSet ls = message.getLeaseSet();
|
||||||
|
if (ls == null) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
_log.error("Null lease set granted: " + message);
|
_log.error("Null lease set granted: " + message);
|
||||||
_runner.disconnectClient("Invalid CreateLeaseSetMessage");
|
_runner.disconnectClient("Invalid CreateLeaseSetMessage - null LS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int type = ls.getType();
|
||||||
|
if (type != DatabaseEntry.KEY_TYPE_META_LS2 &&
|
||||||
|
(message.getPrivateKey() == null || message.getSigningPrivateKey() == null)) {
|
||||||
|
if (_log.shouldLog(Log.ERROR))
|
||||||
|
_log.error("Null private keys: " + message);
|
||||||
|
_runner.disconnectClient("Invalid CreateLeaseSetMessage - null private keys");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SessionId id = message.getSessionId();
|
SessionId id = message.getSessionId();
|
||||||
@@ -486,13 +505,14 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Destination dest = cfg.getDestination();
|
Destination dest = cfg.getDestination();
|
||||||
Destination ndest = message.getLeaseSet().getDestination();
|
Destination ndest = ls.getDestination();
|
||||||
if (!dest.equals(ndest)) {
|
if (!dest.equals(ndest)) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
_log.error("Different destination in LS");
|
_log.error("Different destination in LS");
|
||||||
_runner.disconnectClient("Different destination in LS");
|
_runner.disconnectClient("Different destination in LS");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (type != DatabaseEntry.KEY_TYPE_META_LS2) {
|
||||||
LeaseSetKeys keys = _context.keyManager().getKeys(dest);
|
LeaseSetKeys keys = _context.keyManager().getKeys(dest);
|
||||||
if (keys == null ||
|
if (keys == null ||
|
||||||
!message.getPrivateKey().equals(keys.getDecryptionKey())) {
|
!message.getPrivateKey().equals(keys.getDecryptionKey())) {
|
||||||
@@ -508,7 +528,7 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
_runner.disconnectClient("Bad private key in LS");
|
_runner.disconnectClient("Bad private key in LS");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pk.equals(message.getLeaseSet().getEncryptionKey())) {
|
if (!pk.equals(ls.getEncryptionKey())) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
_log.error("Private/public crypto key mismatch in LS");
|
_log.error("Private/public crypto key mismatch in LS");
|
||||||
_runner.disconnectClient("Private/public crypto key mismatch in LS");
|
_runner.disconnectClient("Private/public crypto key mismatch in LS");
|
||||||
@@ -520,8 +540,9 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
// just register new SPK, don't verify, unused
|
// just register new SPK, don't verify, unused
|
||||||
_context.keyManager().registerKeys(dest, message.getSigningPrivateKey(), message.getPrivateKey());
|
_context.keyManager().registerKeys(dest, message.getSigningPrivateKey(), message.getPrivateKey());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
_context.netDb().publish(message.getLeaseSet());
|
_context.netDb().publish(ls);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
_log.error("Invalid leaseset from client", iae);
|
_log.error("Invalid leaseset from client", iae);
|
||||||
@@ -532,7 +553,7 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
_log.info("New lease set granted for destination " + dest);
|
_log.info("New lease set granted for destination " + dest);
|
||||||
|
|
||||||
// leaseSetCreated takes care of all the LeaseRequestState stuff (including firing any jobs)
|
// leaseSetCreated takes care of all the LeaseRequestState stuff (including firing any jobs)
|
||||||
_runner.leaseSetCreated(message.getLeaseSet());
|
_runner.leaseSetCreated(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** override for testing */
|
/** override for testing */
|
||||||
|
Reference in New Issue
Block a user