Router: Use MuxedSKM for ECIES routers (proposal 156 WIP)

This commit is contained in:
zzz
2020-09-11 14:13:36 +00:00
parent 19d4a5ce26
commit 30244f9d9b
2 changed files with 29 additions and 7 deletions

View File

@ -9,7 +9,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.app.ClientAppManager; import net.i2p.app.ClientAppManager;
import net.i2p.crypto.EncType;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.PublicKey;
import net.i2p.data.RoutingKeyGenerator; import net.i2p.data.RoutingKeyGenerator;
import net.i2p.data.router.RouterInfo; import net.i2p.data.router.RouterInfo;
import net.i2p.data.router.RouterKeyGenerator; import net.i2p.data.router.RouterKeyGenerator;
@ -17,6 +19,8 @@ import net.i2p.internal.InternalClientManager;
import net.i2p.router.client.ClientManagerFacadeImpl; import net.i2p.router.client.ClientManagerFacadeImpl;
import net.i2p.router.crypto.ElGamalAESEngine; import net.i2p.router.crypto.ElGamalAESEngine;
import net.i2p.router.crypto.ratchet.ECIESAEADEngine; import net.i2p.router.crypto.ratchet.ECIESAEADEngine;
import net.i2p.router.crypto.ratchet.MuxedSKM;
import net.i2p.router.crypto.ratchet.RatchetSKM;
import net.i2p.router.crypto.TransientSessionKeyManager; import net.i2p.router.crypto.TransientSessionKeyManager;
import net.i2p.router.dummy.*; import net.i2p.router.dummy.*;
import net.i2p.router.message.GarlicMessageParser; import net.i2p.router.message.GarlicMessageParser;
@ -629,16 +633,25 @@ public class RouterContext extends I2PAppContext {
/** /**
* As of 0.9.15, this returns a dummy SessionKeyManager in I2PAppContext. * As of 0.9.15, this returns a dummy SessionKeyManager in I2PAppContext.
* Overridden in RouterContext to return the full TransientSessionKeyManager. * Overridden in RouterContext to return the full TransientSessionKeyManager
* or MuxedSKM, depending on configured router encryption type.
* *
* @since 0.9.15 * @since 0.9.15
*/ */
@Override @Override
protected void initializeSessionKeyManager() { protected void initializeSessionKeyManager() {
synchronized (_lock3) { synchronized (_lock3) {
if (_sessionKeyManager == null) if (_sessionKeyManager == null) {
//_sessionKeyManager = new PersistentSessionKeyManager(this); TransientSessionKeyManager tskm = new TransientSessionKeyManager(this);
_sessionKeyManager = new TransientSessionKeyManager(this); PublicKey pk = keyManager().getPublicKey();
if (pk != null && pk.getType() == EncType.ECIES_X25519) {
// TODO RatchetSKM only after updating MessageWrapper
RatchetSKM rskm = new RatchetSKM(this);
_sessionKeyManager = new MuxedSKM(tskm, rskm);
} else {
_sessionKeyManager = tskm;
}
}
_sessionKeyManagerInitialized = true; _sessionKeyManagerInitialized = true;
} }
} }

View File

@ -78,10 +78,19 @@ public class RatchetSKM extends SessionKeyManager implements SessionTagListener
/** /**
* The session key manager should only be constructed and accessed through the * For the router SKM only.
* application context. This constructor should only be used by the
* appropriate application context itself.
* *
* @since 0.9.48
*/
public RatchetSKM(RouterContext context) {
this(context, null);
}
/**
* The session key manager is constructed and accessed through the
* client manager.
*
* @param dest null for router's SKM only
*/ */
public RatchetSKM(RouterContext context, Destination dest) { public RatchetSKM(RouterContext context, Destination dest) {
super(context); super(context);