Author: dbkr
Date: 2006-07-20 12:07:41 +0000 (Thu, 20 Jul 2006)
New Revision: 9670

Modified:
   trunk/apps/Freemail/src/freemail/AccountManager.java
   trunk/apps/Freemail/src/freemail/OutboundContact.java
   trunk/apps/Freemail/src/freemail/RTSFetcher.java
Log:
More on RTS messages (bugfixes and things added to the spec later)


Modified: trunk/apps/Freemail/src/freemail/AccountManager.java
===================================================================
--- trunk/apps/Freemail/src/freemail/AccountManager.java        2006-07-20 
01:52:32 UTC (rev 9669)
+++ trunk/apps/Freemail/src/freemail/AccountManager.java        2006-07-20 
12:07:41 UTC (rev 9670)
@@ -138,7 +138,7 @@
                                throw new IOException("Unable to write account 
file");
                        }

-                       // initialise RTS/CTS KSK
+                       // initialise RTS KSK
                        Random rnd = new Random();
                        String rtskey = new String();


Modified: trunk/apps/Freemail/src/freemail/OutboundContact.java
===================================================================
--- trunk/apps/Freemail/src/freemail/OutboundContact.java       2006-07-20 
01:52:32 UTC (rev 9669)
+++ trunk/apps/Freemail/src/freemail/OutboundContact.java       2006-07-20 
12:07:41 UTC (rev 9670)
@@ -7,6 +7,7 @@
 import java.math.BigInteger;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.Random;

 import freemail.utils.EmailAddress;
 import freemail.utils.PropsFile;
@@ -25,6 +26,7 @@
        private final File accdir;
        private final EmailAddress address;
        private static final String OUTBOUND_DIR = "outbound";
+       private static final int CTS_KSK_LENGTH = 32;

        public OutboundContact(File accdir, EmailAddress a) throws 
BadFreemailAddressException {
                this.address = a;
@@ -76,13 +78,29 @@
                        this.contactfile.put("commssk.pubkey", ssk.pubkey);
                        // we've just generated a new SSK, so the other party 
definately doesn't know about it
                        this.contactfile.put("status", "notsent");
-               } else {
-                       ssk = new SSKKeyPair();
                }

                return ssk;
        }

+       private SSKKeyPair getAckKeyPair() {
+               SSKKeyPair ssk = new SSKKeyPair();
+               
+               ssk.pubkey = this.contactfile.get("ackssk.privkey");
+               ssk.privkey = this.contactfile.get("ackssk.pubkey");
+               
+               
+               if (ssk.pubkey == null || ssk.privkey == null) {
+                       HighLevelFCPClient cli = new HighLevelFCPClient();
+                       ssk = cli.makeSSK();
+                       
+                       this.contactfile.put("ackssk.privkey", ssk.privkey);
+                       this.contactfile.put("ackssk.pubkey", ssk.pubkey);
+               }
+               
+               return ssk;
+       }
+       
        private RSAKeyParameters getPubKey() throws 
OutboundContactFatalException {
                String mod_str = this.contactfile.get("asymkey.modulus");
                String exp_str = this.contactfile.get("asymkey.pubexponent");
@@ -123,8 +141,9 @@
         */
        public boolean init() throws OutboundContactFatalException {
                // try to fetch get all necessary info. will fetch mailsite / 
generate new keys if necessary
-               SSKKeyPair ssk = this.getCommKeyPair();
-               if (ssk == null) return false;
+               SSKKeyPair commssk = this.getCommKeyPair();
+               if (commssk == null) return false;
+               SSKKeyPair ackssk = this.getAckKeyPair();
                RSAKeyParameters their_pub_key = this.getPubKey();
                if (their_pub_key == null) return false;
                String rtsksk = this.getRtsKsk();
@@ -134,8 +153,20 @@

                // the public part of the SSK keypair we generated
                // put this first to avoid messages with the same first block, 
since we don't (currently) use CBC
-               rtsmessage.append("commssk="+ssk.pubkey+"\r\n");
+               rtsmessage.append("commssk="+commssk.pubkey+"\r\n");

+               rtsmessage.append("ackssk="+ackssk.privkey+"\r\n");
+               
+               Random rnd = new Random();
+               String ctsksk = new String("KSK@");
+                       
+               int i;
+               for (i = 0; i < CTS_KSK_LENGTH; i++) {
+                       ctsksk += (char)(rnd.nextInt(25) + (int)'a');
+               }
+               
+               rtsmessage.append("ctsksk="+ctsksk+"\r\n");
+               
                rtsmessage.append("messagetype=rts\r\n");

                // must include who this RTS is to, otherwise we're vulnerable 
to surruptitious forwarding

Modified: trunk/apps/Freemail/src/freemail/RTSFetcher.java
===================================================================
--- trunk/apps/Freemail/src/freemail/RTSFetcher.java    2006-07-20 01:52:32 UTC 
(rev 9669)
+++ trunk/apps/Freemail/src/freemail/RTSFetcher.java    2006-07-20 12:07:41 UTC 
(rev 9670)
@@ -164,8 +164,6 @@
                        return true;
                }

-               System.out.println("RTS decrypted to: "+new String(plaintext));
-               
                File rtsfile = null;
                byte[] their_encrypted_sig;
                int messagebytes = 0;
@@ -182,6 +180,7 @@
                                messagebytes += lis.getLastBytesRead();

                                if (line == null || line.equals("")) break;
+                               System.out.println(line);

                                ps.println(line);
                        }
@@ -198,11 +197,15 @@

                        their_encrypted_sig = new byte[bis.available()];

-                       int read = 0;
+                       int totalread = 0;
                        while (true) {
-                               read = bis.read(their_encrypted_sig, 0, 
bis.available());
-                               if (read == 0) break;
+                               int read = bis.read(their_encrypted_sig, 
totalread, bis.available());
+                               if (read <= 0) break;
+                               totalread += read;
                        }
+                       
+                       System.out.println("read "+totalread+" bytes of 
signature");
+                       
                        bis.close();
                } catch (IOException ioe) {
                        System.out.println("IO error whilst handling RTS 
message. "+ioe.getMessage());
@@ -211,6 +214,8 @@
                        return false;
                }

+               
+               
                PropsFile rtsprops = new PropsFile(rtsfile);

                try {
@@ -358,25 +363,25 @@
                StringBuffer missing = new StringBuffer();

                if (rts.get("commssk") == null) {
-                       missing.append("commssk");
+                       missing.append("commssk, ");
                }
-               if (rts.get("ackksk") == null) {
-                       missing.append("ackssk");
+               if (rts.get("ackssk") == null) {
+                       missing.append("ackssk, ");
                }
                if (rts.get("messagetype") == null) {
-                       missing.append("messagetype");
+                       missing.append("messagetype, ");
                }
                if (rts.get("to") == null) {
-                       missing.append("to");
+                       missing.append("to, ");
                }
                if (rts.get("mailsite") == null) {
-                       missing.append("mailsite");
+                       missing.append("mailsite, ");
                }
                if (rts.get("ctsksk") == null) {
-                       missing.append("ctsssk");
+                       missing.append("ctsksk, ");
                }

                if (missing.length() == 0) return;
-               throw new Exception(missing.toString());
+               throw new Exception(missing.toString().substring(0, 
missing.length() - 2));
        }
 }


Reply via email to