Author: jflesch
Date: 2007-12-16 15:03:38 +0000 (Sun, 16 Dec 2007)
New Revision: 16597
Modified:
trunk/apps/Thaw/src/thaw/core/Core.java
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Draft.java
trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
Log:
MiniFrost : add support for crypted messages
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2007-12-16 13:22:37 UTC (rev
16596)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2007-12-16 15:03:38 UTC (rev
16597)
@@ -717,14 +717,15 @@
if ("ProtocolError".equals(m.getMessageName())) {
int code = Integer.parseInt(m.getValue("Code"));
- if (code == 8 /* Invalid field (?!) */
- || code == 9 /* File not found */
- || code == 10 /* Disk target exists */
- || code == 12 /* Couldn't create file */
- || code == 13 /* Couldn't write file */
- || code == 14 /* Couldn't rename file */
- || code == 22 /* File parse error */
- || code == 26 /* Could not read file */) {
+ if (connection.isLocalSocket()
+ && (code == 8 /* Invalid
field (?!) */
+ || code == 9 /* File
not found */
+ || code == 10 /* Disk
target exists */
+ || code == 12 /*
Couldn't create file */
+ || code == 13 /*
Couldn't write file */
+ || code == 14 /*
Couldn't rename file */
+ || code == 22 /* File
parse error */
+ || code == 26 /* Could
not read file */)) {
askToDisableDDA();
}
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-12-16
13:22:37 UTC (rev 16596)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-12-16
15:03:38 UTC (rev 16597)
@@ -2,7 +2,7 @@
# 2006-2007(c)
## Commons
-# Note for devs and translators: These words must be/are always used alone.
+
thaw.common.queueWatcher=Transferts
thaw.common.node=Node
thaw.common.plugins=Plugins
@@ -596,6 +596,8 @@
thaw.plugin.miniFrost.subject=Sujet
thaw.plugin.miniFrost.author=De
+thaw.plugin.miniFrost.recipient=?
+thaw.plugin.miniFrost.recipient.all=[n'importe-qui]
thaw.plugin.miniFrost.status=Status
thaw.plugin.miniFrost.date=Date
thaw.plugin.miniFrost.read=Lire
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-12-16 13:22:37 UTC
(rev 16596)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-12-16 15:03:38 UTC
(rev 16597)
@@ -6,7 +6,6 @@
## Commons
-# Note for devs and translators: These words must be/are always used alone.
thaw.common.node=Node
thaw.common.plugins=Plugins
@@ -600,6 +599,8 @@
thaw.plugin.miniFrost.subject=Subject
thaw.plugin.miniFrost.author=From
+thaw.plugin.miniFrost.recipient=To
+thaw.plugin.miniFrost.recipient.all=[anybody]
thaw.plugin.miniFrost.status=Status
thaw.plugin.miniFrost.date=Date
thaw.plugin.miniFrost.read=Read
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-12-16 13:22:37 UTC
(rev 16596)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-12-16 15:03:38 UTC
(rev 16597)
@@ -2,7 +2,7 @@
# 2006-2007(c)
## Commons
-# Note for devs and translators: These words must be/are always used alone.
+
thaw.common.queueWatcher=Transferts
thaw.common.node=Node
thaw.common.plugins=Plugins
@@ -596,6 +596,8 @@
thaw.plugin.miniFrost.subject=Sujet
thaw.plugin.miniFrost.author=De
+thaw.plugin.miniFrost.recipient=\u00c0
+thaw.plugin.miniFrost.recipient.all=[n'importe-qui]
thaw.plugin.miniFrost.status=Status
thaw.plugin.miniFrost.date=Date
thaw.plugin.miniFrost.read=Lire
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java 2007-12-16
13:22:37 UTC (rev 16596)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java 2007-12-16
15:03:38 UTC (rev 16597)
@@ -57,6 +57,8 @@
private JComboBox authorBox;
private JTextField subjectField;
private JTextArea textArea;
+ private JComboBox recipientBox;
+
private JButton cancelButton;
private JButton sendButton;
@@ -84,12 +86,22 @@
messageDateFormat = new SimpleDateFormat("yyyy.MM.dd -
HH:mm:ss");
panel = new JPanel(new BorderLayout(5, 5));
+
+ /* author box */
authorBox = new JComboBox();
authorBox.setEditable(true);
-
+
subjectField = new JTextField("");
subjectField.setEditable(true);
+
+ /* recipient box */
+
+ recipientBox = new JComboBox();
+
+ /* content will be updated when setDraft() will be called
+ * to take into consideration people marked as GOOD recently
+ */
textArea = new JTextArea("");
textArea.setEditable(true);
@@ -104,12 +116,13 @@
JPanel northPanel = new JPanel(new BorderLayout(5, 5));
- JPanel headersPanel = new JPanel(new GridLayout(3, 1));
+ JPanel headersPanel = new JPanel(new GridLayout(4, 1));
headersPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.board")+": "));
headersPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.author")+": "));
- headersPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.subject")+": "));
+ headersPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.recipient")+": "));
+ headersPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.subject")+": "));
- JPanel valuesPanel = new JPanel(new GridLayout(3, 1));
+ JPanel valuesPanel = new JPanel(new GridLayout(4, 1));
JPanel topPanel = new JPanel(new BorderLayout(5, 5));
topPanel.add(boardLabel, BorderLayout.CENTER);
@@ -117,6 +130,7 @@
valuesPanel.add(topPanel);
valuesPanel.add(authorBox);
+ valuesPanel.add(recipientBox);
valuesPanel.add(subjectField);
northPanel.add(headersPanel, BorderLayout.WEST);
@@ -210,16 +224,43 @@
Vector ids = new Vector();
ids.add(I18n.getMessage("thaw.plugin.miniFrost.anonymous"));
ids.addAll(Identity.getYourIdentities(mainPanel.getDb()));
-
+
authorBox.removeAllItems();
for (Iterator it = ids.iterator(); it.hasNext();)
authorBox.addItem(it.next());
-
+
if (draft.getAuthorIdentity() != null)
authorBox.setSelectedItem(draft.getAuthorIdentity());
else if (draft.getAuthorNick() != null)
authorBox.setSelectedItem(draft.getAuthorNick());
+ else
+ authorBox.setSelectedIndex(0);
+
+ /* recipient */
+ Vector nicePeople = new Vector();
+
nicePeople.add(I18n.getMessage("thaw.plugin.miniFrost.recipient.all"));
+ nicePeople.addAll(Identity.getIdentities(mainPanel.getDb(),
+
"trustLevel >= "+Integer.toString(Identity.trustLevelInt[1])));
+
+ recipientBox.removeAllItems();
+
+ for (Iterator it = nicePeople.iterator(); it.hasNext(); ) {
+ recipientBox.addItem(it.next());
+ }
+
+ recipientBox.setSelectedIndex(0);
+
+ if (draft.getRecipient() != null) {
+ recipientBox.setSelectedItem(draft.getRecipient());
+
+ if
(!recipientBox.getSelectedItem().equals(draft.getRecipient())) {
+ /* then it means that the recipient wasn't in
the list */
+ recipientBox.addItem(draft.getRecipient());
+
recipientBox.setSelectedItem(draft.getRecipient());
+ }
+ }
+
/* subject */
subjectField.setText(draft.getSubject());
@@ -296,6 +337,13 @@
draft.setAuthor(nick, null);
}
+
+ /* recipient */
+
+ if (recipientBox.getSelectedItem() instanceof Identity)
+
draft.setRecipient((Identity)recipientBox.getSelectedItem());
+ else
+ draft.setRecipient(null);
/* subject */
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
2007-12-16 13:22:37 UTC (rev 16596)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
2007-12-16 15:03:38 UTC (rev 16597)
@@ -21,14 +21,15 @@
public class KSKDraft
implements thaw.plugins.miniFrost.interfaces.Draft, Observer {
- private KSKMessage inReplyTo;
- private KSKBoard board;
+ private KSKMessage inReplyTo = null;
+ private KSKBoard board = null;
- private String subject;
- private String txt;
- private String nick;
- private Identity identity;
- private Date date;
+ private String subject = null;
+ private String txt = null;
+ private String nick = null;
+ private Identity identity = null;
+ private Identity recipient = null;
+ private Date date = null;
private int idLinePos = 0;
private int idLineLen = 0;
@@ -40,6 +41,13 @@
this.board = board;
this.inReplyTo = inReplyTo;
attachments = null;
+
+ if (inReplyTo != null
+ && inReplyTo.encryptedFor() != null
+ && inReplyTo.getSender() != null
+ && inReplyTo.getSender().getIdentity() != null)
{
+ recipient = inReplyTo.getSender().getIdentity();
+ }
}
public String getSubject() {
@@ -100,7 +108,15 @@
public String getAuthorNick() {
return nick;
}
+
+ public void setRecipient(Identity id) {
+ this.recipient = id;
+ }
+ public Identity getRecipient() {
+ return recipient;
+ }
+
public void setDate(Date date) {
this.date = date;
}
@@ -201,18 +217,14 @@
private void startInsertion() {
/* we generate first the XML message */
- KSKMessageParser generator = new KSKMessageParser( ((inReplyTo
!= null) ?
-
inReplyTo.getMsgId() :
-
null),
+ KSKMessageParser generator = new KSKMessageParser( ((inReplyTo
!= null) ? inReplyTo.getMsgId() : null),
nick,
subject,
date,
- null,
/* recipient */
+
recipient, /* recipient */
board.getName(),
txt,
-
((identity != null) ?
-
identity.getPublicKey() :
-
null),
+
((identity != null) ? identity.getPublicKey() : null),
attachments,
identity,
idLinePos,
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2007-12-16 13:22:37 UTC (rev 16596)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2007-12-16 15:03:38 UTC (rev 16597)
@@ -4,7 +4,10 @@
import org.w3c.dom.*;
import java.text.SimpleDateFormat;
+import java.io.DataInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
import java.util.Iterator;
@@ -65,11 +68,11 @@
private static FrostCrypt frostCrypt;
- public KSKMessageParser(String inReplyTo,
+ public KSKMessageParser(String inReplyTo, /* msg id */
String from,
String subject,
java.util.Date dateUtil,
- String recipient,
+ Identity encryptedFor,
String board,
String body,
String publicKey,
@@ -88,7 +91,8 @@
this.date = date[0];
this.time = date[1];
- this.recipient = null;
+ this.encryptedFor = encryptedFor;
+ this.recipient = (encryptedFor != null ?
encryptedFor.toString() : null);
this.board = board;
this.body = body;
@@ -429,16 +433,12 @@
protected boolean decrypt(Hsqldb db, Element rootNode) {
Vector identities = Identity.getYourIdentities(db);
- /**
- * I prefer to not trust the recipient field ...
- */
-
byte[] content;
String recipient =
XMLTools.getChildElementsCDATAValue(rootNode, "recipient");
try {
content =
Base64.decode(XMLTools.getChildElementsCDATAValue(rootNode,
-
"content").getBytes("UTF-8"));
+
"content").getBytes("UTF-8")); /* ISO-8859-1 in Frost */
} catch(Exception e) {
Logger.notice(this, "Unable to decode encrypted message
because : "+e.toString());
return false;
@@ -681,8 +681,61 @@
return root;
}
+
+ private byte[] readByteArray(File file) {
+ try {
+ byte[] data = new byte[(int)file.length()];
+ FileInputStream fileIn = new FileInputStream(file);
+ DataInputStream din = new DataInputStream(fileIn);
+ din.readFully(data);
+ fileIn.close();
+ return data;
+ } catch(java.io.IOException e) {
+ Logger.error(this, "Exception thrown in readByteArray(File file):
'"+e.toString()+"'");
+ }
+ return null;
+ }
+ public File crypt(Identity receiver, File msgFile) {
+ File tmpFile;
+ try {
+ tmpFile = File.createTempFile("thaw-", "-message.xml");
+ tmpFile.deleteOnExit();
+ } catch(java.io.IOException e) {
+ Logger.error(this, "Can't create temporary file because
: "+e.toString());
+ return null;
+ }
+
+ Document doc = XMLTools.createDomDocument();
+
+ Element el;
+ Element root = doc.createElement("EncryptedFrostMessage");
+
+ /* first tag : recipient */
+ if ((el = makeCDATA(doc, "recipient", receiver.toString())) !=
null) root.appendChild(el);
+
+ /* second tag : crypted content */
+ byte[] xmlContent = readByteArray(msgFile);
+ byte[] encContent = receiver.encode(xmlContent);
+
+ String base64enc;
+ try {
+ base64enc = new String(Base64.encode(encContent), "UTF-8"); /*
ISO-8859-1 in Frost */
+ } catch (UnsupportedEncodingException ex) {
+ Logger.error(this, "UTF-8 encoding is not supported ?! :
'"+ex.toString()+"'");
+ return null;
+ }
+ if ((el = makeCDATA(doc, "content", base64enc)) != null)
root.appendChild(el);
+
+ doc.appendChild(root);
+
+ File cryptedFile = (XMLTools.writeXmlFile(doc,
tmpFile.getPath()) ? tmpFile : null);
+
+ return cryptedFile;
+ }
+
+
public File generateXML() {
File tmpFile;
@@ -698,7 +751,16 @@
doc.appendChild(getXMLTree(doc));
- return (XMLTools.writeXmlFile(doc, tmpFile.getPath()) ? tmpFile
: null);
+ File clearMsg = (XMLTools.writeXmlFile(doc, tmpFile.getPath())
? tmpFile : null);
+
+ if (encryptedFor == null)
+ return clearMsg;
+
+ File cryptedFile = crypt(encryptedFor, clearMsg);
+
+ tmpFile.delete();
+
+ return cryptedFile;
}
protected boolean mustBeDisplayedAsRead() {
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Draft.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Draft.java
2007-12-16 13:22:37 UTC (rev 16596)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Draft.java
2007-12-16 15:03:38 UTC (rev 16597)
@@ -25,6 +25,12 @@
* @return can return null if unknown
*/
public Identity getAuthorIdentity();
+
+ /**
+ * @param id null for anybody
+ */
+ public void setRecipient(Identity id);
+ public Identity getRecipient();
public boolean allowUnsignedPost();
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-12-16
13:22:37 UTC (rev 16596)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-12-16
15:03:38 UTC (rev 16597)
@@ -61,7 +61,7 @@
private Hsqldb db;
- private int id;
+ private int id = -1;
private String nick;
@@ -634,6 +634,19 @@
return null;
}
+
+ public byte[] encode(byte[] input) {
+ initFrostCrypt();
+
+ try {
+ return frostCrypt.encrypt(input, publicKey);
+ } catch(Exception e) {
+ Logger.error(this, "Can't crypt message because :
'"+e.toString()+"'");
+ e.printStackTrace();
+ }
+
+ return null;
+ }
public static Identity importIdentity(Hsqldb db, File file) {
@@ -687,5 +700,15 @@
return null;
}
+
+ public boolean equals(Object o) {
+ if (!(o instanceof Identity))
+ return false;
+
+ if (getId() < 0)
+ return false;
+
+ return (getId() == ((Identity)o).getId());
+ }
}