Author: nextgens
Date: 2007-09-30 08:50:54 +0000 (Sun, 30 Sep 2007)
New Revision: 15415
Modified:
trunk/freenet/src/freenet/node/FNPPacketMangler.java
trunk/freenet/src/freenet/node/PeerNode.java
Log:
Refactoring:
* getLightDiffieHellmanContext(PeerNode) => getLightDiffieHellmanContext()
hardcoding the DSA group...
* Use a HashMap in PeerNode to store nonces with a Peer as key
Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java 2007-09-30
08:43:26 UTC (rev 15414)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java 2007-09-30
08:50:54 UTC (rev 15415)
@@ -508,7 +508,7 @@
*/
private void sendJFKMessage1(PeerNode pn, Peer replyTo) {
if(logMINOR) Logger.minor(this, "Sending a JFK(1) message to
"+pn);
- DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext(pn);
+ DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext();
int offset = 0;
byte[] myExponential =
stripBigIntegerToNetworkFormat(dhContext.myExponential);
byte[] nonce = new byte[NONCE_SIZE];
@@ -535,7 +535,7 @@
*/
private void sendJFKMessage2(byte[] nonceInitator, PeerNode pn, Peer
replyTo) {
if(logMINOR) Logger.minor(this, "Sending a JFK(2) message to
"+pn);
- DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext(pn);
+ DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext();
// g^r
byte[] myExponential =
stripBigIntegerToNetworkFormat(dhContext.myExponential);
// Nr
@@ -777,7 +777,7 @@
System.arraycopy(payload, inputOffset, hmac, 0, HASH_LENGTH);
inputOffset += HASH_LENGTH;
- DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext(pn);
+ DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext();
BigInteger computedExponential =
dhContext.getHMACKey(_hisExponential, Global.DHgroupA);
byte[] Ks = computeJFKSharedKey(computedExponential,
nonceInitiator, nonceResponder, "0");
byte[] Ke = computeJFKSharedKey(computedExponential,
nonceInitiator, nonceResponder, "1");
@@ -1002,7 +1002,7 @@
if(logMINOR) Logger.minor(this, "Sending a JFK(3) message to
"+pn);
BlockCipher c = null;
try { c = new Rijndael(256, 256); } catch
(UnsupportedCipherException e) {}
- DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext(pn);
+ DiffieHellmanLightContext dhContext =
getLightDiffieHellmanContext();
byte[] ourExponential =
stripBigIntegerToNetworkFormat(dhContext.myExponential);
pn.jfkMyRef = crypto.myCompressedSetupRef();
byte[] data = new byte[8 + pn.jfkMyRef.length];
@@ -2429,14 +2429,14 @@
return crypto.config.alwaysAllowLocalAddresses();
}
- private DiffieHellmanLightContext getLightDiffieHellmanContext(PeerNode
pn) {
+ private DiffieHellmanLightContext getLightDiffieHellmanContext() {
final long now = System.currentTimeMillis();
synchronized (this) {
if((currentDHContext == null) ||
(currentDHContextLifetime + 1800000 /*30mins*/) < now) {
currentDHContextLifetime = now;
currentDHContext =
DiffieHellman.generateLightContext();
-
currentDHContext.setSignature(signDHParams(currentDHContext.myExponential,
pn.peerCryptoGroup));
+
currentDHContext.setSignature(signDHParams(currentDHContext.myExponential,
Global.DSAgroupBigA));
}
}
return currentDHContext;
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2007-09-30 08:43:26 UTC
(rev 15414)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2007-09-30 08:50:54 UTC
(rev 15415)
@@ -11,6 +11,7 @@
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
@@ -94,6 +95,8 @@
protected byte[] jfkKa;
protected byte[] jfkKe;
protected byte[] jfkKs;
+ protected final HashMap jfkNonceInitiator = new HashMap();
+ protected byte[] jfkMyRef;
/** My low-level address for SocketManager purposes */
private Peer detectedPeer;