SSU2 more fixes

Fix OES2 MTU
Fix Token Request header encryption
This commit is contained in:
zzz
2022-02-28 12:32:36 -05:00
parent 44c30e78fc
commit a13f2b9768
3 changed files with 36 additions and 4 deletions

View File

@@ -72,7 +72,30 @@ class OutboundEstablishState2 extends OutboundEstablishState implements SSU2Payl
throw new IllegalArgumentException("bad IP", uhe);
}
}
_mtu = addr.getMTU();
// We need the MTU so the Session Confirmed can fit the RI in
int mtu = addr.getMTU();
if (mtu == 0) {
if (ra.getTransportStyle().equals("SSU2")) {
mtu = PeerState2.DEFAULT_MTU;
} else {
if (_bobIP.length == 16)
mtu = PeerState2.DEFAULT_SSU_IPV6_MTU;
else
mtu = PeerState2.DEFAULT_SSU_IPV4_MTU;
}
} else {
// TODO if too small, give up now
if (ra.getTransportStyle().equals("SSU2")) {
mtu = Math.min(Math.max(mtu, PeerState2.MIN_MTU), PeerState2.MAX_MTU);
} else {
if (_bobIP.length == 16)
mtu = Math.min(Math.max(mtu, PeerState2.MIN_SSU_IPV6_MTU), PeerState2.MAX_SSU_IPV6_MTU);
else
mtu = Math.min(Math.max(mtu, PeerState2.MIN_SSU_IPV4_MTU), PeerState2.MAX_SSU_IPV4_MTU);
}
}
_mtu = mtu;
// TODO if RI too big, give up now
if (addr.getIntroducerCount() > 0) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("new outbound establish to " + remotePeer.calculateHash() + ", with address: " + addr);
@@ -87,13 +110,13 @@ class OutboundEstablishState2 extends OutboundEstablishState implements SSU2Payl
do {
rcid = ctx.random().nextLong();
} while (_sendConnID == rcid);
_rcvConnID = rcid;
_token = _transport.getEstablisher().getOutboundToken(_remotePeer.calculateHash());
_routerAddress = ra;
if (_token != 0)
createNewState(ra);
_rcvConnID = rcid;
byte[] ik = introKey.getData();
_sendHeaderEncryptKey1 = ik;
_rcvHeaderEncryptKey1 = ik;

View File

@@ -453,7 +453,6 @@ class PacketBuilder2 {
len = info.length;
}
UDPPacket packets[] = new UDPPacket[numFragments];
packets[0] = buildSessionConfirmedPacket(state, numFragments, info, len, gzip);
if (numFragments > 1) {
@@ -909,7 +908,7 @@ class PacketBuilder2 {
_log.error("Bad token req msg out", gse);
throw new RuntimeException("Bad token req msg out", gse);
}
SSU2Header.encryptHandshakeHeader(packet, hdrKey1, hdrKey2);
SSU2Header.encryptLongHeader(packet, hdrKey1, hdrKey2);
}
/**

View File

@@ -48,7 +48,17 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
private final SSU2Bitfield _ackedMessages;
private byte[] _sessConfForReTX;
// As SSU
public static final int MIN_SSU_IPV4_MTU = 1292;
public static final int MAX_SSU_IPV4_MTU = 1484;
public static final int DEFAULT_SSU_IPV4_MTU = MAX_SSU_IPV4_MTU;
public static final int MIN_SSU_IPV6_MTU = 1280;
public static final int MAX_SSU_IPV6_MTU = 1488;
public static final int DEFAULT_SSU_IPV6_MTU = MIN_SSU_IPV6_MTU; // should always be published
// As SSU2
public static final int MIN_MTU = 1280;
public static final int MAX_MTU = 1500;
public static final int DEFAULT_MTU = MAX_MTU;
/**
* @param rtt from the EstablishState, or 0 if not available