Author: kryptos
Date: 2007-09-25 13:28:50 +0000 (Tue, 25 Sep 2007)
New Revision: 15290

Modified:
   branches/freenet-jfk/src/freenet/node/FNPPacketMangler.java
   branches/freenet-jfk/src/freenet/node/PeerNode.java
Log:
Updates to JFK(4)

Modified: branches/freenet-jfk/src/freenet/node/FNPPacketMangler.java
===================================================================
--- branches/freenet-jfk/src/freenet/node/FNPPacketMangler.java 2007-09-24 
16:51:11 UTC (rev 15289)
+++ branches/freenet-jfk/src/freenet/node/FNPPacketMangler.java 2007-09-25 
13:28:50 UTC (rev 15290)
@@ -814,7 +814,7 @@
                DiffieHellmanLightContext dhContext = 
getLightDiffieHellmanContext();
                byte[] ourExponential = dhContext.myExponential.toByteArray();
                byte[] unVerifiedData=new 
byte[NONCE_SIZE*2+DiffieHellman.modulusLengthInBytes()*2];
-               int offset = 
0;http://www.google.co.in/search?q=inline+gpg&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:official&client=firefox-a
+               int offset = 0;
                // Ni
                 System.arraycopy(nonceInitiator, 0, unVerifiedData, offset, 
NONCE_SIZE);
                offset += NONCE_SIZE;
@@ -855,7 +855,12 @@
                byte[] iv=new byte[pk.lengthIV()];
                 node.random.nextBytes(iv);
                byte[] idI = new byte[0];
-                
+                /*
+                 * Save state at this point for signature verification in 
JFK(4)
+                 * Ni,Nr,g^i,g^r,Idi
+                 */
+                
System.arraycopy(unVerifiedData,0,pn.bufferJFK,0,unVerifiedData.length);
+                
System.arraycopy(idI,0,pn.bufferJFK,unVerifiedData.length,idI.length);
                 int encryptedDataLength = iv.length + idI.length + r.length + 
s.length + 2;
                byte[] encryptedData = new byte[encryptedDataLength];
                System.arraycopy(iv, 0, encryptedData, 0, iv.length);
@@ -904,7 +909,7 @@
                
pk.blockDecipher(payload,inputOffset,payload.length-inputOffset);
                 inputOffset += ivLength;
                 // Now verify signature
-                // FIXME: How do we verify the signature?
+                
                 byte[] r = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
                System.arraycopy(payload, inputOffset, r, 0, 
Node.SIGNATURE_PARAMETER_LENGTH);
                inputOffset += Node.SIGNATURE_PARAMETER_LENGTH;
@@ -914,13 +919,15 @@
                DSASignature remoteSignature = new DSASignature(new 
NativeBigInteger(1,r), new NativeBigInteger(1,s));
                if(logMINOR)
                     Logger.minor(this, "Remote sent us the following sig 
:"+remoteSignature.toLongString());
-               // FIXME: How do we save state?
-                byte[] locallyExpectedExponentials = new 
byte[Node.SIGNATURE_PARAMETER_LENGTH*2];
+               
+                byte[] locallyExpectedExponentials = new 
byte[NONCE_SIZE*2+DiffieHellman.modulusLengthInBytes()*2];
+                
System.arraycopy(pn.bufferJFK,0,locallyExpectedExponentials,0,pn.bufferJFK.length);

                if(!DSA.verify(pn.peerPubKey, remoteSignature, new 
NativeBigInteger(1, locallyExpectedExponentials), false)) {
                        Logger.error(this, "The signature verification has 
failed!!");
                        return;
-               }          
+               }       
+                Logger.normal(this,"Reached end of JFK. Now send completed 
handshake");
                 // FIXME: When do we send the Handshake?
                 // FIXME: What about noderef?
         }

Modified: branches/freenet-jfk/src/freenet/node/PeerNode.java
===================================================================
--- branches/freenet-jfk/src/freenet/node/PeerNode.java 2007-09-24 16:51:11 UTC 
(rev 15289)
+++ branches/freenet-jfk/src/freenet/node/PeerNode.java 2007-09-25 13:28:50 UTC 
(rev 15290)
@@ -27,6 +27,7 @@
 import freenet.crypt.DSAGroup;
 import freenet.crypt.DSAPublicKey;
 import freenet.crypt.DSASignature;
+import freenet.crypt.DiffieHellman;
 import freenet.crypt.KeyAgreementSchemeContext;
 import freenet.crypt.SHA256;
 import freenet.crypt.UnsupportedCipherException;
@@ -85,6 +86,13 @@
      *  Set true if this peer has a incompatible newer build than we are
      */
     protected boolean verifiedIncompatibleNewerVersion;
+    
+    /*
+     * Buffer of Ni,Nr,g^i,g^r,Idi
+     * Currently Idi is not being used, but may find use in opennet
+     * Used to verify the signature in JFK(4)
+     */
+    protected byte[] bufferJFK = new 
byte[NONCE_SIZE*2+DiffieHellman.modulusLengthInBytes()*2];

     /** My low-level address for SocketManager purposes */
     private Peer detectedPeer;
@@ -295,6 +303,7 @@
     /** If the clock delta is more than this constant, we don't talk to the 
node. Reason: It may not be up to date,
      * it will have difficulty resolving date-based content etc. */
        private static final long MAX_CLOCK_DELTA = 24L*60L*60L*1000L;
+        private static final int NONCE_SIZE = 6;

        /** A WeakReference to this object. Can be taken whenever a node object 
needs to refer to this object for a 
         * long time, but without preventing it from being GC'ed. */


Reply via email to