From 44c30e78fc7d875e1f81bf14792640befa07d591 Mon Sep 17 00:00:00 2001
From: zzz <zzz@i2pmail.org>
Date: Mon, 28 Feb 2022 10:01:05 -0500
Subject: [PATCH] SSU2 fixes

Fix NPE in PS2
Fix Token Request message type
---
 .../i2p/router/transport/udp/OutboundEstablishState2.java | 8 ++++----
 .../src/net/i2p/router/transport/udp/PacketBuilder2.java  | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java
index ffe283a75e..d8a2e3a1f3 100644
--- a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java
+++ b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java
@@ -124,11 +124,11 @@ class OutboundEstablishState2 extends OutboundEstablishState implements SSU2Payl
     public synchronized void restart(long token) {
         _token = token;
         HandshakeState old = _handshakeState;
-        byte[] pub = new byte[32];
-        old.getRemotePublicKey().getPublicKey(pub, 0);
-        createNewState(_routerAddress);
-        if (old != null)
+        if (old != null) {
+            // TODO pass the old keys over to createNewState()
             old.destroy();
+        }
+        createNewState(_routerAddress);
         //_rcvHeaderEncryptKey2 will be set after the Session Request message is created
         _rcvHeaderEncryptKey2 = null;
     }
diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java
index 03c7036db5..91cf5c8e0f 100644
--- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java
+++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java
@@ -283,7 +283,7 @@ class PacketBuilder2 {
      */
     public UDPPacket buildTokenRequestPacket(OutboundEstablishState2 state) {
         long n = _context.random().signedNextInt() & 0xFFFFFFFFL;
-        UDPPacket packet = buildLongPacketHeader(state.getSendConnID(), n, SESSION_REQUEST_FLAG_BYTE,
+        UDPPacket packet = buildLongPacketHeader(state.getSendConnID(), n, TOKEN_REQUEST_FLAG_BYTE,
                                                  state.getRcvConnID(), 0);
         DatagramPacket pkt = packet.getPacket();
 
-- 
GitLab