Author: jflesch
Date: 2007-07-27 20:48:53 +0000 (Fri, 27 Jul 2007)
New Revision: 14399
Modified:
trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAuthor.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
Log:
miniFrost checks the signatures now
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2007-07-27 18:42:32 UTC
(rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2007-07-27 20:48:53 UTC
(rev 14399)
@@ -169,7 +169,7 @@
new
java.awt.Font("Dialog", java.awt.Font.BOLD, 14) ));
JLabel sigLabel = new
JLabel(I18n.getMessage("thaw.plugin.signature.trustLevel.trustLevel")+ " : ");
- JTextField sigLevel = new
JTextField(I18n.getMessage(author.getTrustLevelStr())
+ JTextField sigLevel = new JTextField(author.getTrustLevelStr()
+ (author.isDup() ? " - "
+ I18n.getMessage("thaw.plugin.signature.duplicata") : ""));
@@ -187,12 +187,12 @@
for (int i = 0 ; i < Identity.trustLevelInt.length ; i++) {
if (Identity.trustLevelInt[i] < 100)
-
trustLevels.add(I18n.getMessage(Identity.trustLevelStr[i]));
+ trustLevels.add(Identity.trustLevelStr[i]);
}
trust = new JComboBox(trustLevels);
-
trust.setSelectedItem(I18n.getMessage(author.getTrustLevelStr()));
+ trust.setSelectedItem(author.getTrustLevelStr());
changeTrust = new JButton(I18n.getMessage("thaw.common.apply"));
changeTrust.addActionListener(this);
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -27,6 +27,8 @@
import thaw.gui.IconBox;
import thaw.core.I18n;
import thaw.core.Logger;
+import thaw.plugins.signatures.Identity;
+import thaw.plugins.miniFrost.interfaces.Author;
import thaw.plugins.miniFrost.interfaces.Message;
import thaw.plugins.miniFrost.interfaces.SubMessage;
import thaw.plugins.miniFrost.interfaces.Attachment;
@@ -135,7 +137,46 @@
}
+ protected class AuthorPanel extends JPanel implements ActionListener {
+ private JComboBox box = null;
+ private JLabel nick;
+ private Author author;
+ public AuthorPanel(Author author) {
+ super(new BorderLayout(5, 5));
+
+ this.author = author;
+
+ nick = new JLabel(author.toString());
+
+ add(nick, BorderLayout.CENTER);
+
+ if (author.getIdentity() != null) {
+ if (author.getIdentity().getTrustLevel()
+ == Identity.trustLevelInt[0]) /* if dev */
+ box = new
JComboBox(Identity.trustLevelStr);
+ else
+ box = new
JComboBox(Identity.trustLevelUserStr);
+
+
nick.setForeground(author.getIdentity().getTrustLevelColor());
+
+
box.setSelectedItem(author.getIdentity().getTrustLevelStr());
+ box.addActionListener(this);
+
+ add(box, BorderLayout.EAST);
+ }
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
author.getIdentity().setTrustLevel((String)box.getSelectedItem());
+
nick.setForeground(author.getIdentity().getTrustLevelColor());
+
+ /* we just refresh, because if now the trust level is
below what must be
+ * displayed ... */
+ mainPanel.getMessageTreeTable().refresh();
+ }
+ }
+
protected class SubMessagePanel extends JPanel implements
ActionListener {
private JButton upDownButton;
private boolean retracted;
@@ -158,8 +199,8 @@
JPanel headPanel = new JPanel(new BorderLayout(10, 0));
JLabel dateLabel = new JLabel(msg.getDate().toString());
- JLabel authorLabel = new
JLabel(msg.getAuthor().toString());
- authorLabel.setPreferredSize(new
java.awt.Dimension(300, 15));
+ AuthorPanel authorLabel = new
AuthorPanel(msg.getAuthor());
+ authorLabel.setPreferredSize(new
java.awt.Dimension(350, 15));
upDownButton = new JButton("", (retracted ?
IconBox.minDown : IconBox.minUp));
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -15,6 +15,8 @@
import javax.swing.JPopupMenu;
import javax.swing.JMenuItem;
+import java.awt.Color;
+
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.DefaultCellEditor;
import javax.swing.event.TableModelEvent;
@@ -49,6 +51,7 @@
import thaw.core.I18n;
import thaw.core.Logger;
+import thaw.plugins.miniFrost.interfaces.Author;
import thaw.plugins.miniFrost.interfaces.Board;
import thaw.plugins.miniFrost.interfaces.BoardFactory;
import thaw.plugins.miniFrost.interfaces.Message;
@@ -227,6 +230,8 @@
final int row,
final int column) {
Component c;
+ Author author = model.getMsg(row).getSender();
+
if (value instanceof Boolean) {
JCheckBox box = new JCheckBox();
@@ -235,13 +240,26 @@
return box;
}
- if (column == 3) {
- value = "NOT CHECKED";
+ Color color = Color.BLACK;
+
+
+ if (column == 3)
+ value = author.toString();
+ else if (column == 4) {
+ if (author.getIdentity() != null)
+ value =
author.getIdentity().getTrustLevelStr();
+ else
+ value =
I18n.getMessage("thaw.plugin.signature.trustLevel.none");
}
+ if (author.getIdentity() != null)
+ color =
author.getIdentity().getTrustLevelColor();
+
c = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus,
row, column);
+ c.setForeground(color);
+
Message msg = model.getMsg(row);
int mod = Font.PLAIN;
@@ -305,7 +323,7 @@
}
if (column == 2) {
- return
((Message)msgs.get(row)).getSender().toString();
+ return ((Message)msgs.get(row)).getSender();
}
if (column == 3) {
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -9,4 +9,6 @@
extends thaw.plugins.miniFrost.interfaces.Attachment {
public void insert(Hsqldb db, int messageId);
+
+ public StringBuffer getSignedStr();
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAuthor.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAuthor.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAuthor.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -21,6 +21,9 @@
}
public String toString() {
+ if (identity != null)
+ return identity.toString();
+
return nick;
}
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -565,4 +565,5 @@
public KSKBoardFactory getFactory() {
return factory;
}
+
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -231,4 +231,18 @@
return (v.size() > 0 ? v : null);
}
+
+
+ public StringBuffer getSignedStr() {
+ StringBuffer buf = new StringBuffer();
+
+
buf.append(boardName).append(KSKMessageParser.SIGNATURE_ELEMENTS_SEPARATOR);
+
+ if (publicKey != null)
+
buf.append(publicKey).append(KSKMessageParser.SIGNATURE_ELEMENTS_SEPARATOR);
+ if (privateKey != null)
+
buf.append(privateKey).append(KSKMessageParser.SIGNATURE_ELEMENTS_SEPARATOR);
+
+ return buf;
+ }
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -256,4 +256,13 @@
return (v.size() > 0 ? v : null);
}
+
+ public StringBuffer getSignedStr() {
+ StringBuffer buf = new StringBuffer();
+
+
buf.append(filename).append(KSKMessageParser.SIGNATURE_ELEMENTS_SEPARATOR);
+
buf.append(key).append(KSKMessageParser.SIGNATURE_ELEMENTS_SEPARATOR);
+
+ return buf;
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -17,7 +17,9 @@
import thaw.core.I18n;
import thaw.plugins.Hsqldb;
+import thaw.plugins.signatures.Identity;
+
/**
* only notify when the message has been fully parsed
*/
@@ -122,6 +124,7 @@
KSKMessageParser parser = new KSKMessageParser();
if (parser.loadFile(new File(get.getPath()))
+ && parser.checkSignature(db)
&& parser.insert(db, board.getId(), rev,
board.getName())) {
new File(get.getPath()).delete();
@@ -173,7 +176,16 @@
KSKBoard board) {
this.id = id;
this.subject = subject;
- this.author = new KSKAuthor(nick, null);
+
+ Identity identity = null;
+
+ if (sigId >= 0)
+ identity =
Identity.getIdentity(board.getFactory().getDb(),
+ sigId);
+
+ this.author = new KSKAuthor(nick, identity);
+
+
this.sigId = sigId;
this.date = date;
this.rev = rev;
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2007-07-27 18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2007-07-27 20:48:53 UTC (rev 14399)
@@ -14,6 +14,8 @@
import frost.util.XMLTools;
+import thaw.plugins.signatures.Identity;
+
import thaw.plugins.Hsqldb;
import thaw.core.Logger;
@@ -33,15 +35,17 @@
private String subject;
private String date;
private String time;
- private String pubKey;
private String recipient;
private String board;
private String body;
-
+ private String publicKey;
private String signature;
+ private String idLinePos;
+ private String idLineLen;
private Vector attachments;
+ private Identity identity;
private boolean alreadyInTheDb(Hsqldb db, String msgId) {
try {
@@ -129,27 +133,31 @@
"subject, nick, sigId, content, "+
"date,
msgId, inReplyTo, inReplyToId, "+
"rev,
read, archived, boardId) VALUES ("+
- "?, ?,
NULL, ?, "+
"?, ?,
?, ?, "+
+ "?, ?,
?, ?, "+
"?,
FALSE, FALSE, ?)");
st.setString(1, subject);
st.setString(2, from); /* nick */
- st.setString(3, body); /* content */
- st.setTimestamp(4, dateSql);
- st.setString(5, messageId);
+ if (identity != null)
+ st.setInt(3, identity.getId());
+ else
+ st.setNull(3, Types.INTEGER);
+ st.setString(4, body); /* content */
+ st.setTimestamp(5, dateSql);
+ st.setString(6, messageId);
if (replyToId >= 0)
- st.setInt(6, replyToId);
+ st.setInt(7, replyToId);
else
- st.setNull(6, Types.INTEGER);
+ st.setNull(7, Types.INTEGER);
if (inReplyTo != null)
- st.setString(7, inReplyTo);
+ st.setString(8, inReplyTo);
else
- st.setNull(7, Types.VARCHAR);
+ st.setNull(8, Types.VARCHAR);
- st.setInt(8, rev);
- st.setInt(9, boardId);
+ st.setInt(9, rev);
+ st.setInt(10, boardId);
st.execute();
@@ -185,14 +193,55 @@
}
- public String getSignedContent() {
- return null;
+ public final static char SIGNATURE_ELEMENTS_SEPARATOR = '|';
+
+ private String getSignedContent() {
+ final StringBuilder allContent = new StringBuilder();
+
+ allContent.append(date).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ allContent.append(time).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ allContent.append(board).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ allContent.append(from).append(SIGNATURE_ELEMENTS_SEPARATOR);
+
allContent.append(messageId).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ if( inReplyTo != null && inReplyTo.length() > 0 ) {
+
allContent.append(inReplyTo).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ }
+ if( recipient != null && recipient.length() > 0 ) {
+
allContent.append(recipient).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ }
+
allContent.append(idLinePos).append(SIGNATURE_ELEMENTS_SEPARATOR);
+
allContent.append(idLineLen).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ allContent.append(subject).append(SIGNATURE_ELEMENTS_SEPARATOR);
+ allContent.append(body).append(SIGNATURE_ELEMENTS_SEPARATOR);
+
+ if (attachments != null) {
+ for (Iterator it = attachments.iterator();
+ it.hasNext();) {
+ KSKAttachment a = (KSKAttachment)it.next();
+ allContent.append(a.getSignedStr());
+ }
+ }
+
+ return allContent.toString();
+
}
public boolean checkSignature(Hsqldb db) {
+ if (publicKey == null || signature == null) {
+ from = from.replaceAll("@", "_");
+ return true;
+ }
- return true;
+ String[] split = from.split("@");
+ if (split.length < 2 || "".equals(split[0].trim()))
+ return false;
+
+ String nick = split[0].trim();
+
+ identity = Identity.getIdentity(db, nick, publicKey);
+
+ return identity.check(getSignedContent(), signature);
}
@@ -203,10 +252,13 @@
subject = XMLTools.getChildElementsCDATAValue(root,
"Subject");
date = XMLTools.getChildElementsCDATAValue(root,
"Date");
time = XMLTools.getChildElementsCDATAValue(root,
"Time");
- pubKey = XMLTools.getChildElementsCDATAValue(root,
"pubKey");
recipient = XMLTools.getChildElementsCDATAValue(root,
"recipient");
board = XMLTools.getChildElementsCDATAValue(root,
"Board");
body = XMLTools.getChildElementsCDATAValue(root,
"Body");
+ signature = XMLTools.getChildElementsCDATAValue(root,
"SignatureV2");
+ publicKey = XMLTools.getChildElementsCDATAValue(root,
"pubKey");
+ idLinePos = XMLTools.getChildElementsTextValue(root,
"IdLinePos");
+ idLineLen = XMLTools.getChildElementsTextValue(root,
"IdLineLen");
List l = XMLTools.getChildElementsByTagName(root,
"AttachmentList");
if (l.size() == 1) {
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-07-27
18:42:32 UTC (rev 14398)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-07-27
20:48:53 UTC (rev 14399)
@@ -43,14 +43,22 @@
};
public final static String[] trustLevelStr = {
- "thaw.plugin.signature.trustLevel.dev",
- "thaw.plugin.signature.trustLevel.good",
- "thaw.plugin.signature.trustLevel.observe",
- "thaw.plugin.signature.trustLevel.check",
- "thaw.plugin.signature.trustLevel.bad",
- "thaw.plugin.signature.trustLevel.evil"
+ I18n.getMessage("thaw.plugin.signature.trustLevel.dev"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.good"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.observe"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.check"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.bad"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.evil")
};
+ public final static String[] trustLevelUserStr= {
+ I18n.getMessage("thaw.plugin.signature.trustLevel.good"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.observe"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.check"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.bad"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel.evil")
+ };
+
public final static Color[] trustLevelColor = {
Color.BLUE,
new java.awt.Color(0, 175, 0), /* green */
@@ -86,6 +94,7 @@
private Identity() {
}
+
/**
* If you don't have a value, let it to null and pray it won't be used
:P
* @param nick part *before* the @
@@ -129,6 +138,10 @@
return privateKey;
}
+ public int getTrustLevel() {
+ return trustLevel;
+ }
+
public String getTrustLevelStr() {
int i;
@@ -176,7 +189,7 @@
int i;
for (i = 0 ; i < Identity.trustLevelStr.length ; i++) {
- if
(I18n.getMessage(Identity.trustLevelStr[i]).equals(str))
+ if (Identity.trustLevelStr[i].equals(str))
break;
}
@@ -200,6 +213,9 @@
st.execute();
}
+
+ trustLevel = i;
+
} catch(SQLException e) {
Logger.error(this, "Unable to change trust level
because: "+e.toString());
}
@@ -258,7 +274,7 @@
st =
db.getConnection().prepareStatement("SELECT id, nickName, publicKey, "+
"privateKey, isDup, trustLevel "+
"FROM
signatures "+
- "WHERE
y = ? LIMIT 1");
+ "WHERE
publicKey = ? LIMIT 1");
st.setString(1, publicKey);
ResultSet set = st.executeQuery();
@@ -267,7 +283,7 @@
Identity i = new Identity(db,
set.getInt("id"), set.getString("nickName"),
set.getString("publicKey"), set.getString("privateKey"),
set.getBoolean("isDup"), set.getInt("trustLevel"));
- Logger.info(i, "Identity found");
+ Logger.debug(i, "Identity found");
return i;
}
@@ -294,7 +310,21 @@
st.execute();
- Identity i = new Identity(db, -1, nick,
publicKey, null, isDup, 0);
+
+ /* and next we find back the id */
+
+ st =
db.getConnection().prepareStatement("SELECT id "+
+ "FROM
signatures "+
+ "WHERE
publicKey = ? LIMIT 1");
+ st.setString(1, publicKey);
+
+ set = st.executeQuery();
+
+ set.next();
+
+ int id = set.getInt("id");
+
+ Identity i = new Identity(db, id, nick,
publicKey, null, isDup, 0);
Logger.info(i, "New identity found");
return i;