From c79e33896eb4f02830c47603dd0ccaaabe961214 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sat, 23 Aug 2014 13:48:13 +0000
Subject: [PATCH] SSU intro key checks

---
 .../i2p/router/transport/udp/IntroductionManager.java  |  5 ++++-
 .../src/net/i2p/router/transport/udp/UDPAddress.java   | 10 +++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java b/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java
index 4117edb14f..37db458801 100644
--- a/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java
+++ b/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java
@@ -218,9 +218,12 @@ class IntroductionManager {
                 _log.info("Picking introducer: " + cur);
             cur.setIntroducerTime();
             UDPAddress ura = new UDPAddress(ra);
+            byte[] ikey = ura.getIntroKey();
+            if (ikey == null)
+                continue;
             ssuOptions.setProperty(UDPAddress.PROP_INTRO_HOST_PREFIX + found, Addresses.toString(ip));
             ssuOptions.setProperty(UDPAddress.PROP_INTRO_PORT_PREFIX + found, String.valueOf(port));
-            ssuOptions.setProperty(UDPAddress.PROP_INTRO_KEY_PREFIX + found, Base64.encode(ura.getIntroKey()));
+            ssuOptions.setProperty(UDPAddress.PROP_INTRO_KEY_PREFIX + found, Base64.encode(ikey));
             ssuOptions.setProperty(UDPAddress.PROP_INTRO_TAG_PREFIX + found, String.valueOf(cur.getTheyRelayToUsAs()));
             found++;
         }
diff --git a/router/java/src/net/i2p/router/transport/udp/UDPAddress.java b/router/java/src/net/i2p/router/transport/udp/UDPAddress.java
index 8cc279fec7..f05205582d 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPAddress.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPAddress.java
@@ -17,7 +17,7 @@ class UDPAddress {
     private final String _host;
     private InetAddress _hostAddress;
     private final int _port;
-    private byte[] _introKey;
+    private final byte[] _introKey;
     private String _introHosts[];
     private InetAddress _introAddresses[];
     private int _introPorts[];
@@ -62,6 +62,7 @@ class UDPAddress {
         if (addr == null) {
             _host = null;
             _port = 0;
+            _introKey = null;
             return;
         }
         _host = addr.getOption(PROP_HOST);
@@ -78,6 +79,10 @@ class UDPAddress {
             byte[] ik = Base64.decode(key.trim());
             if (ik != null && ik.length == SessionKey.KEYSIZE_BYTES)
                 _introKey = ik;
+            else
+                _introKey = null;
+        } else {
+            _introKey = null;
         }
         
         for (int i = MAX_INTRODUCERS - 1; i >= 0; i--) {
@@ -167,6 +172,9 @@ class UDPAddress {
      */
     public int getPort() { return _port; }
 
+    /**
+     *  @return shouldn't be null but will be if invalid
+     */
     byte[] getIntroKey() { return _introKey; }
     
     int getIntroducerCount() { return (_introAddresses == null ? 0 : _introAddresses.length); }
-- 
GitLab