Author: dbkr
Date: 2006-06-23 14:01:35 +0000 (Fri, 23 Jun 2006)
New Revision: 9366
Added:
trunk/apps/Freemail/src/freemail/utils/ChainedAsymmetricBlockCipher.java
Modified:
trunk/apps/Freemail/src/freemail/OutboundContact.java
Log:
Chain the RSA blocks together in RTS messages
Modified: trunk/apps/Freemail/src/freemail/OutboundContact.java
===================================================================
--- trunk/apps/Freemail/src/freemail/OutboundContact.java 2006-06-23
13:12:48 UTC (rev 9365)
+++ trunk/apps/Freemail/src/freemail/OutboundContact.java 2006-06-23
14:01:35 UTC (rev 9366)
@@ -11,6 +11,7 @@
import freemail.utils.EmailAddress;
import freemail.utils.PropsFile;
import freemail.utils.DateStringFactory;
+import freemail.utils.ChainedAsymmetricBlockCipher;
import freemail.fcp.HighLevelFCPClient;
import freemail.fcp.SSKKeyPair;
@@ -131,6 +132,10 @@
StringBuffer rtsmessage = new StringBuffer();
+ // 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("messagetype=rts\r\n");
// must include who this RTS is to, otherwise we're vulnerable
to surruptitious forwarding
@@ -141,9 +146,6 @@
rtsmessage.append("mailsite="+our_mailsite_uri+"\r\n");
- // the public part of the SSK keypair we generated
- rtsmessage.append("commssk="+ssk.pubkey+"\r\n");
-
rtsmessage.append("\r\n");
// sign the message
@@ -185,7 +187,7 @@
enccipher.init(true, their_pub_key);
byte[] encmsg = null;
try {
- encmsg = sigcipher.processBlock(bos.toByteArray(), 0,
bos.toByteArray().length);
+ encmsg =
ChainedAsymmetricBlockCipher.encrypt(sigcipher, bos.toByteArray());
} catch (InvalidCipherTextException e) {
e.printStackTrace();
return false;
Added: trunk/apps/Freemail/src/freemail/utils/ChainedAsymmetricBlockCipher.java
===================================================================
--- trunk/apps/Freemail/src/freemail/utils/ChainedAsymmetricBlockCipher.java
2006-06-23 13:12:48 UTC (rev 9365)
+++ trunk/apps/Freemail/src/freemail/utils/ChainedAsymmetricBlockCipher.java
2006-06-23 14:01:35 UTC (rev 9366)
@@ -0,0 +1,35 @@
+package freemail.utils;
+
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+import org.bouncycastle.crypto.AsymmetricBlockCipher;
+import org.bouncycastle.crypto.InvalidCipherTextException;
+
+/*
+ * A wrapper around AsymmetricBlockCipher to chain several blocks together.
+ * This class just concatentates them, ie. without CBC or suchlike.
+ *
+ * Clearly this is intended for use with small amounts of data, where it's not
worthwhile encrypting a symmetric key and using that
+ */
+public class ChainedAsymmetricBlockCipher {
+ public static byte[] encrypt(AsymmetricBlockCipher cipher, byte[] in)
throws InvalidCipherTextException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ByteArrayInputStream bis = new ByteArrayInputStream(in);
+
+ int read;
+ byte[] buf = new byte[cipher.getInputBlockSize()];
+
+ while ( (read = bis.read(buf, 0, cipher.getInputBlockSize())) >
0) {
+ byte[] obuf = cipher.processBlock(buf, 0, read);
+ try {
+ bos.write(obuf);
+ } catch (IOException ioe) {
+ throw new InvalidCipherTextException();
+ }
+ }
+
+ return bos.toByteArray();
+ }
+}