Author: dbkr
Date: 2006-06-13 18:58:30 +0000 (Tue, 13 Jun 2006)
New Revision: 9185

Modified:
   trunk/apps/Freemail/README
   trunk/apps/Freemail/build.xml
   trunk/apps/Freemail/src/freemail/AccountManager.java
   trunk/apps/Freemail/src/freemail/utils/PropsFile.java
Log:
Import the bouncycastle code (fetch and compile it in the any buildfile) and 
generate a keypair. Also nomenclature corrections to the README.


Modified: trunk/apps/Freemail/README
===================================================================
--- trunk/apps/Freemail/README  2006-06-13 18:57:44 UTC (rev 9184)
+++ trunk/apps/Freemail/README  2006-06-13 18:58:30 UTC (rev 9185)
@@ -11,7 +11,7 @@
 Proper, secure implemenations of the Freemail protocol will come later.

 All the data, including your passwd file, will most likley end up world
-readable. Under unix, you could try running fnmail with a modified umask
+readable. Under unix, you could try running Freemail with a modified umask
 if this bothers you, but I don't believe there is a portable way of doing
 this in Java (or I haven't found it).

@@ -23,28 +23,28 @@
 compile: (however you compile Java, an ant buildfile is supplied)
 run with --newaccount <account name> to create an account, eg:

-java -cp build/ fnmail.FNMail --newaccount fred
+java -cp build/ freemail.Freemail --newaccount fred

 Use --passwd <account> <passwd> to set your password

-java -cp build/ fnmail.FNMail --passwd fred fredspassword
+java -cp build/ freemail.Freemail --passwd fred fredspassword

 Run:

-java -cp build/ fnmail.FNMail
+java -cp build/ Freemail.FNMail

 Set up your email client to point at IMAP port 3143 and SMTP port 3025.

-Your address is <accountname>@nim.fnmail
+Your address is <accountname>@nim.Freemail

 And yes, in case you were wondering, no - there's nothing to stop someone
 else using the same address. I did say it was insecure ;)

 Send me a message if you like, I promise to reply if it works :)

-dbkr at nim.fnmail
+dbkr at nim.Freemail

-(and since anyone can read fnmail message right now, my fnmail public key
+(and since anyone can read Freemail messages right now, my Freemail public key
 can be found at USK at 
vjETpEgDH-6EzlngZoO8KgOZm-B8AAlvZ-6oP6aQmow,DZYYfhpOxIrtdCNJiflIPjd0Qy8nA1d3Dwy86dcdhu0,AQABAAE/dbkr/10/contact/pubkey.fnmail.asc,
 or failing that, http://accidentalegg.co.uk/contact/pubkey.fnmail)

 If it doesn't, dbkr at freenetproject.org!

Modified: trunk/apps/Freemail/build.xml
===================================================================
--- trunk/apps/Freemail/build.xml       2006-06-13 18:57:44 UTC (rev 9184)
+++ trunk/apps/Freemail/build.xml       2006-06-13 18:58:30 UTC (rev 9185)
@@ -1,49 +1,67 @@
 <?xml version="1.0"?>
-<project name="fnmail" default="compile" basedir=".">
-<!-- set global properties for this build -->
-       <property name="src" location="src"/>
+<project name="Freemail" default="compile" basedir=".">
+       <!-- set global properties for this build -->
+       <property name="src" location="src"/>
        <property name="build" location="build"/>
-       <property name="lib"    location="lib"/>
+       <property name="lib" location="lib"/>
+       <property name="deps" location="deps"/>
+       
+       <property name="bcdist" value="lcrypto-jdk14-133"/>

-       <target name="mkdir">
-               <mkdir dir="${build}"/>
-               <mkdir dir="${lib}"/>
+       <available file="${deps}/${bcdist}" 
property="bouncycastle-dist.present" />
+       <available file="${build}/org/bouncycastle" 
property="bouncycastle-bin.present" />
+
+       <target name="bouncycastle-fetch" unless="bouncycastle-dist.present">
+               <mkdir dir="${deps}" />
+               <get src="http://www.bouncycastle.org/download/${bcdist}.zip"; 
+               dest="${deps}/${bcdist}.zip" 
+               verbose="true"
+               usetimestamp="true" />
+
+               <unzip src="${deps}/${bcdist}.zip" dest="${deps}" />
        </target>

-       <target name="compile" depends="mkdir">
-               <!-- Create the time stamp -->
+       <target name="bouncycastle-compile" depends="bouncycastle-fetch" 
unless="bouncycastle-bin.present">
+               <mkdir dir="build" />
+               <javac srcdir="${deps}/${bcdist}/src" destdir="${build}" 
debug="off" optimize="on" source="1.4" nowarn="true">
+                       <exclude name="**/test/*" />
+               </javac>
+       </target>
+
+       <target name="compile" depends="bouncycastle-compile">
+               <mkdir dir="${build}"/>
+
                <tstamp/>
-               <!-- Create the build directory structure used by compile -->

-               <javac srcdir="${src}" destdir="${build}" debug="on" 
optimize="on" source="1.4" compiler="jikes">
-               <include name="fnmail/*.java"/>
-               <include name="fnmail/*/*.java"/>
-               <include name="thirdparty/*.java"/>
-               <include name="freenet/support/io/*.java"/>
-               </javac>
+               <!-- Bundle the whole lot together, unless anyone whinges.
+                    It makes it much easier to run -->
+               <javac srcdir="${src}" destdir="${build}" debug="on" 
optimize="on" source="1.4" compiler="jikes" />
        </target>


        <target name="dist" depends="compile">
-       <jar jarfile="${lib}/fnmail.jar" basedir="${build}">
-       <manifest>
-       <attribute name="Main-Class" value="fnmail.FNMail"/>
-               <attribute name="Built-By" value="${user.name}"/>
-               <section name="common">
-                       <attribute name="Implementation-Title" value="fnmail"/>
-                       <attribute name="Implementation-Version" value="0.0"/> 
-                       <attribute name="Implementation-Vendor" value="Dave 
Baker"/>
-               </section>
-       </manifest>
-       </jar>    
+               <mkdir dir="${lib}"/>
+               <jar jarfile="${lib}/Freemail.jar" basedir="${build}">
+                       <manifest>
+                               <attribute name="Main-Class" 
value="freemail.Freemail"/>
+                               <attribute name="Built-By" 
value="${user.name}"/>
+                               <section name="common">
+                                       <attribute name="Implementation-Title" 
value="Freemail"/>
+                                       <attribute 
name="Implementation-Version" value="0.0"/> 
+                                       <attribute name="Implementation-Vendor" 
value="Dave Baker"/>
+                               </section>
+                       </manifest>
+               </jar>    
        </target>

        <target name="clean">
                <delete dir="${build}"/>
                <delete dir="${lib}"/>
        </target>
-       <target name="distclean" description="Delete class files, lib dir and 
docs dir.">
+
+       <target name="distclean" description="Delete everything and restore to 
the original state.">
                <delete dir="${build}"/>
                <delete dir="${lib}"/>
+               <delete dir="${deps}"/>
        </target>
 </project>

Modified: trunk/apps/Freemail/src/freemail/AccountManager.java
===================================================================
--- trunk/apps/Freemail/src/freemail/AccountManager.java        2006-06-13 
18:57:44 UTC (rev 9184)
+++ trunk/apps/Freemail/src/freemail/AccountManager.java        2006-06-13 
18:58:30 UTC (rev 9185)
@@ -9,7 +9,14 @@
 import java.util.Random;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.math.BigInteger;

+import org.bouncycastle.crypto.generators.RSAKeyPairGenerator;
+import org.bouncycastle.crypto.params.RSAKeyGenerationParameters;
+import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
+import org.bouncycastle.crypto.params.RSAKeyParameters;
+import java.security.SecureRandom;
+
 import freemail.fcp.HighLevelFCPClient;
 import freemail.fcp.SSKKeyPair;
 import freemail.util.PropsFile;
@@ -22,6 +29,10 @@
        private static final String ACCOUNT_FILE = "accprops";
        private static final int RTS_KEY_LENGTH = 32;

+       private static final int ASYM_KEY_MODULUS_LENGTH = 4096;
+       private static final BigInteger ASYM_KEY_EXPONENT = new 
BigInteger("17", 10);
+       private static final int ASYM_KEY_CERTAINTY = 80;
+       

        public static void Create(String username) throws IOException {
                File datadir = new File(DATADIR);
@@ -141,6 +152,26 @@
                } catch (IOException ioe) {
                        System.out.println("Couldn't create mailsite key file! 
"+ioe.getMessage());
                }
+               
+               // generate an RSA keypair
+               System.out.println("Generating cryptographic keypair (this 
could take a few minutes)...");
+               
+               SecureRandom rand = new SecureRandom();
+
+               RSAKeyGenerationParameters kparams = new 
RSAKeyGenerationParameters(ASYM_KEY_EXPONENT, rand, ASYM_KEY_MODULUS_LENGTH, 
ASYM_KEY_CERTAINTY);
+
+               RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
+               kpg.init(kparams);
+               
+               AsymmetricCipherKeyPair keypair = kpg.generateKeyPair();
+               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());
+               
+               System.out.println("Account creation completed.");
        }

        public static boolean authenticate(String username, String password) {

Modified: trunk/apps/Freemail/src/freemail/utils/PropsFile.java
===================================================================
--- trunk/apps/Freemail/src/freemail/utils/PropsFile.java       2006-06-13 
18:57:44 UTC (rev 9184)
+++ trunk/apps/Freemail/src/freemail/utils/PropsFile.java       2006-06-13 
18:58:30 UTC (rev 9185)
@@ -57,6 +57,8 @@
        }

        public String get(String key) {
+               if (this.data == null) return null;
+               
                return (String)this.data.get(key);
        }



Reply via email to