Author: dbkr
Date: 2006-06-14 17:26:40 +0000 (Wed, 14 Jun 2006)
New Revision: 9198

Added:
   trunk/apps/Freemail/src/freemail/MailSite.java
Modified:
   trunk/apps/Freemail/src/freemail/AccountManager.java
   trunk/apps/Freemail/src/freemail/MailFetcher.java
   trunk/apps/Freemail/src/freemail/MessageSender.java
   trunk/apps/Freemail/src/freemail/SingleAccountWatcher.java
   trunk/apps/Freemail/src/freemail/fcp/HighLevelFCPClient.java
Log:
Upload a mailsite


Modified: trunk/apps/Freemail/src/freemail/AccountManager.java
===================================================================
--- trunk/apps/Freemail/src/freemail/AccountManager.java        2006-06-14 
16:50:41 UTC (rev 9197)
+++ trunk/apps/Freemail/src/freemail/AccountManager.java        2006-06-14 
17:26:40 UTC (rev 9198)
@@ -86,52 +86,30 @@
                accfile.put("md5passwd", strmd5);
        }

-       public static String getMailsitePubkey(File accdir) {
-               PropsFile accfile = getAccountFile(accdir);
+       public static PropsFile getAccountFile(File accdir) {
+               PropsFile accfile = new PropsFile(new File(accdir, 
ACCOUNT_FILE));

-               String retval = accfile.get("mailsite.pubkey");
-               
-               if (retval == null) {
+               if (!accfile.exists()) {
                        initAccFile(accfile);
-                       retval = accfile.get("mailsite.pubkey");
                }

-               return retval;
-       }
-       
-       public static String getMailsitePrivkey(File accdir) {
-               PropsFile accfile = getAccountFile(accdir);
-               
-               String retval = accfile.get("mailsite.pubkey");
-               
-               if (retval == null) {
-                       initAccFile(accfile);
-                       retval = accfile.get("mailsite.privkey");
-               }
-               
-               return retval;
-       }
-       
-       private static PropsFile getAccountFile(File accdir) {
-               PropsFile accfile = new PropsFile(new File(accdir, 
ACCOUNT_FILE));
-               
                return accfile;
        }

        private static void initAccFile(PropsFile accfile) {
                try {
                        System.out.println("Generating mailsite keys...");
-                       HighLevelFCPClient fcpcli = new 
HighLevelFCPClient(Freemail.getFCPConnection());
+                       HighLevelFCPClient fcpcli = new HighLevelFCPClient();

                        SSKKeyPair keypair = fcpcli.makeSSK();

                        // write private key
-                       if (!accfile.put("mailsite.privkey", keypair.privkey)) {
+                       if (!accfile.put("mailsite.privkey", 
keypair.privkey+"mailsite")) {
                                throw new IOException("Unable to write account 
file");
                        }

                        // write public key
-                       if (!accfile.put("mailsite.pubkey", keypair.pubkey)) {
+                       if (!accfile.put("mailsite.pubkey", 
keypair.pubkey+"mailsite")) {
                                throw new IOException("Unable to write account 
file");
                        }

@@ -167,9 +145,9 @@
                RSAKeyParameters pub = (RSAKeyParameters) keypair.getPublic();
                RSAKeyParameters priv = (RSAKeyParameters) keypair.getPrivate();

-               accfile.put("asymkey.modulus=", pub.getModulus().toString());
-               accfile.put("asymkey.pubexponent=", 
pub.getExponent().toString());
-               accfile.put("asymkey.privexponent=", 
priv.getExponent().toString());
+               accfile.put("asymkey.modulus", pub.getModulus().toString());
+               accfile.put("asymkey.pubexponent", 
pub.getExponent().toString());
+               accfile.put("asymkey.privexponent", 
priv.getExponent().toString());

                System.out.println("Account creation completed.");
        }

Modified: trunk/apps/Freemail/src/freemail/MailFetcher.java
===================================================================
--- trunk/apps/Freemail/src/freemail/MailFetcher.java   2006-06-14 16:50:41 UTC 
(rev 9197)
+++ trunk/apps/Freemail/src/freemail/MailFetcher.java   2006-06-14 17:26:40 UTC 
(rev 9198)
@@ -65,7 +65,7 @@

        public void fetch_day(Contact contact, MailLog log, String date) {
                HighLevelFCPClient fcpcli;
-               fcpcli = new HighLevelFCPClient(this.fcpconn);
+               fcpcli = new HighLevelFCPClient();

                String keybase;
                try {

Added: trunk/apps/Freemail/src/freemail/MailSite.java
===================================================================
--- trunk/apps/Freemail/src/freemail/MailSite.java      2006-06-14 16:50:41 UTC 
(rev 9197)
+++ trunk/apps/Freemail/src/freemail/MailSite.java      2006-06-14 17:26:40 UTC 
(rev 9198)
@@ -0,0 +1,76 @@
+package freemail;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+
+import freemail.util.PropsFile;
+import freemail.fcp.HighLevelFCPClient;
+
+public class MailSite {
+       private final PropsFile accprops;
+
+       MailSite(PropsFile a) {
+               this.accprops = a;
+       }
+       
+       private String getMailPage() {
+               StringBuffer buf = new StringBuffer();
+               
+               String rtsksk = this.accprops.get("rtskey");
+               if (rtsksk == null) {
+                       System.out.println("Can't insert mailsite - missing RTS 
KSK");
+                       return null;
+               }
+               buf.append("rtsksk=").append(rtsksk).append("\r\n");
+               
+               String keymodulus = this.accprops.get("asymkey.modulus");
+               if (keymodulus == null) {
+                       System.out.println("Can't insert mailsite - missing 
asymmetic crypto key modulus");
+                       return null;
+               }
+               
buf.append("asymkey.modulus=").append(keymodulus).append("\r\n");
+               
+               String key_pubexponent = 
this.accprops.get("asymkey.pubexponent");
+               if (key_pubexponent == null) {
+                       System.out.println("Can't insert mailsite - missing 
asymmetic crypto key public exponent");
+                       return null;
+               }
+               
buf.append("asymkey.pubexponent=").append(key_pubexponent).append("\r\n");
+               
+               return buf.toString();
+       }
+       
+       public int Publish() {
+               byte[] mailpage;
+               String mailsite_s = this.getMailPage();
+               if (mailsite_s == null) {
+                       return -1;
+               }
+               try {
+                       mailpage = mailsite_s.getBytes("UTF-8");
+               } catch (UnsupportedEncodingException use) {
+                       mailpage = mailsite_s.getBytes();
+               }
+               
+               ByteArrayInputStream bis = new ByteArrayInputStream(mailpage);
+               
+               String key = this.accprops.get("mailsite.privkey");
+               if (key == null) return -1;
+               
+               HighLevelFCPClient cli = new HighLevelFCPClient();
+               
+               String minslot_s = this.accprops.get("mailsite.slot");
+               int minslot;
+               if (minslot_s != null) {
+                       minslot = Integer.parseInt(minslot_s);
+               } else {
+                       minslot = 1;
+               }
+               
+               int actualslot = cli.SlotInsert(bis, key, 1, "/mailpage");
+               
+               this.accprops.put("mailsite.slot", new 
Integer(actualslot).toString());
+               
+               return actualslot;
+       }
+}

Modified: trunk/apps/Freemail/src/freemail/MessageSender.java
===================================================================
--- trunk/apps/Freemail/src/freemail/MessageSender.java 2006-06-14 16:50:41 UTC 
(rev 9197)
+++ trunk/apps/Freemail/src/freemail/MessageSender.java 2006-06-14 17:26:40 UTC 
(rev 9198)
@@ -117,44 +117,18 @@
                }

                if (addr.domain.equalsIgnoreCase("nim.freemail")) {
-                       if (this.slotinsert(msg, 
NIM_KEY_PREFIX+addr.user+"-"+DateStringFactory.getKeyString())) {
-                               msg.delete();
-                       }
-               }
-       }
-       
-       private boolean slotinsert(File data, String basekey) {
-               HighLevelFCPClient cli = new 
HighLevelFCPClient(Freemail.getFCPConnection());
-               
-               int slot = 1;
-               boolean carryon = true;
-               while (carryon) {
-                       System.out.println("trying slotinsert to 
"+basekey+"-"+slot);
+                       HighLevelFCPClient cli = new HighLevelFCPClient();
+                       
                        FileInputStream fis;
                        try {
-                               fis = new FileInputStream(data);
+                               fis = new FileInputStream(msg);
                        } catch (FileNotFoundException fnfe) {
-                               // riiiiiight...
-                               return false;
+                               return;
                        }
-                       FCPInsertErrorMessage emsg;
-                       try {
-                               emsg = cli.put(fis, basekey+"-"+slot);
-                       } catch (FCPBadFileException bfe) {
-                               return false;
+                       
+                       if (cli.SlotInsert(fis, 
NIM_KEY_PREFIX+addr.user+"-"+DateStringFactory.getKeyString(), 1, "") > -1) {
+                               msg.delete();
                        }
-                       if (emsg == null) {
-                               System.out.println("insert successful");
-                               return true;
-                       } else if (emsg.errorcode == 
FCPInsertErrorMessage.COLLISION) {
-                               slot++;
-                               System.out.println("collision");
-                       } else {
-                               System.out.println("nope - error code is 
"+emsg.errorcode);
-                               // try again later
-                               return false;
-                       }
                }
-               return false;
        }
 }

Modified: trunk/apps/Freemail/src/freemail/SingleAccountWatcher.java
===================================================================
--- trunk/apps/Freemail/src/freemail/SingleAccountWatcher.java  2006-06-14 
16:50:41 UTC (rev 9197)
+++ trunk/apps/Freemail/src/freemail/SingleAccountWatcher.java  2006-06-14 
17:26:40 UTC (rev 9198)
@@ -3,6 +3,8 @@
 import java.io.File;
 import java.lang.InterruptedException;

+import freemail.util.PropsFile;
+
 public class SingleAccountWatcher implements Runnable {
        public static final String CONTACTS_DIR = "contacts";
        private static final int MIN_POLL_DURATION = 60000; // in milliseconds
@@ -13,8 +15,9 @@
        SingleAccountWatcher(File accdir) {
                File contacts_dir = new File(accdir, CONTACTS_DIR);

-               /////////////////
-               AccountManager.getMailsitePrivkey(accdir);
+               PropsFile accprops = AccountManager.getAccountFile(accdir);
+               MailSite ms = new MailSite(accprops);
+               ms.Publish();

                this.mb = new MessageBank(accdir.getName());
                this.mf = new MailFetcher(this.mb, contacts_dir, 
Freemail.getFCPConnection());

Modified: trunk/apps/Freemail/src/freemail/fcp/HighLevelFCPClient.java
===================================================================
--- trunk/apps/Freemail/src/freemail/fcp/HighLevelFCPClient.java        
2006-06-14 16:50:41 UTC (rev 9197)
+++ trunk/apps/Freemail/src/freemail/fcp/HighLevelFCPClient.java        
2006-06-14 17:26:40 UTC (rev 9198)
@@ -3,12 +3,14 @@
 import java.io.File;
 import java.io.InputStream;

+import freemail.Freemail;
+
 public class HighLevelFCPClient implements FCPClient {
        private FCPConnection conn;
        private FCPMessage donemsg;

-       public HighLevelFCPClient(FCPConnection c) {
-               this.conn = c;
+       public HighLevelFCPClient() {
+               this.conn = Freemail.getFCPConnection();
        }

        // It's up to the client to delete this File once they're
@@ -120,6 +122,33 @@
                }
        }

+       public int SlotInsert(InputStream data, String basekey, int minslot, 
String suffix) {
+               int slot = minslot;
+               boolean carryon = true;
+               while (carryon) {
+                       System.out.println("trying slotinsert to 
"+basekey+"-"+slot+suffix);
+                       
+                       FCPInsertErrorMessage emsg;
+                       try {
+                               emsg = this.put(data, basekey+"-"+slot+suffix);
+                       } catch (FCPBadFileException bfe) {
+                               return -1;
+                       }
+                       if (emsg == null) {
+                               System.out.println("insert successful");
+                               return slot;
+                       } else if (emsg.errorcode == 
FCPInsertErrorMessage.COLLISION) {
+                               slot++;
+                               System.out.println("collision");
+                       } else {
+                               System.out.println("nope - error code is 
"+emsg.errorcode);
+                               // try again later
+                               return -1;
+                       }
+               }
+               return -1;
+       }
+       
        public void requestStatus(FCPMessage msg) {

        }


Reply via email to