Author: bback
Date: 2006-02-16 17:42:34 +0000 (Thu, 16 Feb 2006)
New Revision: 8050
Modified:
trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
Log:
msg upload fixes and some more :)
Modified: trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
2006-02-16 00:26:26 UTC (rev 8049)
+++ trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
2006-02-16 17:42:34 UTC (rev 8050)
@@ -199,6 +199,59 @@
public String getSignature() {
return signature;
}
+
+ /**
+ * Signs message and sets signature.
+ *
+ * @param privateKey
+ */
+ public void signMessage(String privateKey) {
+ String sig = Core.getCrypto().detachedSign(getSignableContent(),
privateKey);
+ setSignature(sig);
+ }
+
+ /**
+ * Returns true if the message signature is valid.
+ *
+ * @param pubKey
+ * @return
+ */
+ public boolean verifyMessageSignature(String pubKey) {
+ boolean sigIsValid =
Core.getCrypto().detachedVerify(getSignableContent(), pubKey, getSignature());
+ return sigIsValid;
+ }
+
+ /**
+ * Returns a String containing all content that is used to sign/verify the
message.
+ * @return
+ */
+ private String getSignableContent() {
+
+ StringBuffer allContent = new StringBuffer();
+ allContent.append(getDate());
+ allContent.append(getTime());
+ allContent.append(getSubject());
+ allContent.append(getContent());
+ // attachments
+ for(Iterator it = getAllAttachments().iterator(); it.hasNext(); ) {
+ Attachment a = (Attachment)it.next();
+ if( a.getType() == Attachment.BOARD ) {
+ BoardAttachment ba = (BoardAttachment)a;
+ allContent.append( ba.getBoardObj().getBoardFilename() );
+ if( ba.getBoardObj().getPublicKey() != null ) {
+ allContent.append( ba.getBoardObj().getPublicKey() );
+ }
+ if( ba.getBoardObj().getPrivateKey() != null ) {
+ allContent.append( ba.getBoardObj().getPrivateKey() );
+ }
+ } else if( a.getType() == Attachment.FILE ) {
+ FileAttachment fa = (FileAttachment)a;
+ allContent.append( fa.getFileObj().getFilename() );
+ allContent.append( fa.getFileObj().getKey() );
+ }
+ }
+ return allContent.toString();
+ }
/**
* Get a list of all attached files that are currently offline.
@@ -517,7 +570,7 @@
recipient = rec;
}
- public void setSignature(String sig) {
+ private void setSignature(String sig) {
signature = sig;
}
Modified: trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
2006-02-16 00:26:26 UTC (rev 8049)
+++ trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
2006-02-16 17:42:34 UTC (rev 8050)
@@ -292,8 +292,7 @@
}
// now verify signed content
- String toVerify =
currentMsg.getDate()+currentMsg.getTime()+currentMsg.getSubject()+currentMsg.getContent();
- boolean sigIsValid = Core.getCrypto().detachedVerify(toVerify,
owner.getKey(), currentMsg.getSignature());
+ boolean sigIsValid =
currentMsg.verifyMessageSignature(owner.getKey());
// then check if the signature was ok
if (!sigIsValid) {
Modified: trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
2006-02-16 00:26:26 UTC (rev 8049)
+++ trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
2006-02-16 17:42:34 UTC (rev 8050)
@@ -318,6 +318,7 @@
}
// BBACKFLAG: ask user if uploading of X files is allowed!
+ // if one attachment file does not longer exists (on retry), we delete
the message in uploadAttachments()!
if (!uploadAttachments(message, unsentMessageFile)) {
return false;
}
@@ -329,22 +330,9 @@
if (sender.equals(myId) // nick same as my identity
|| sender.equals(Mixed.makeFilename(myId))) // serialization may
have changed it
{
- // sign several parts of msg
- String toSign =
message.getDate()+message.getTime()+message.getSubject()+message.getContent();
- // TODO: sign all attachments. Order?
-// for(Iterator it = message.getAllAttachments().iterator();
it.hasNext(); ) {
-// Attachment a = (Attachment)it.next();
-// if( a.getType() == Attachment.BOARD ) {
-// BoardAttachment ba = (BoardAttachment)a;
-// toSign += ba.getBoardObj().getBoardFilename();
-// } else if( a.getType() == Attachment.FILE ) {
-// FileAttachment fa = (FileAttachment)a;
-// }
-// }
+ // sign msg
+ message.signMessage(identities.getMyId().getPrivKey());
- String sig = Core.getCrypto().detachedSign(toSign,
identities.getMyId().getPrivKey());
- message.setSignature(sig);
-
// save msg with signature
if (!saveMessage(message, unsentMessageFile)) {
logger.severe("This was a HARD error and the file to upload is
lost, please report to a dev!");
@@ -360,6 +348,9 @@
if( message.getSignature() != null && message.getSignature().length()
> 0 && // we signed, so encrypt is possible
encryptForRecipient != null )
{
+ // TODO: rewrite encryption. Write complete signed XML to disk,
encrypt it, encode64 it and
+ // save a new XML containing the receiver and the base64
content only.
+
// encrypt signed content
String encContent = Core.getCrypto().encrypt(message.getContent(),
encryptForRecipient.getKey());
if( encContent == null ) {
@@ -516,15 +507,38 @@
boolean success = true;
List fileAttachments = msg.getOfflineFiles();
Iterator i = fileAttachments.iterator();
- while (i.hasNext()) {
- SharedFileObject attachment = (SharedFileObject)
i.next();
- if(uploadAttachment(attachment)) {
- //If the attachment was successfully inserted,
we update the message on disk.
- saveMessage(msg, file);
- } else {
- success = false;
- }
- }
+ // check if upload files still exist
+ while (i.hasNext()) {
+ SharedFileObject attachment = (SharedFileObject) i.next();
+ if( attachment.getFile()== null ||
+ attachment.getFile().isFile() == false ||
+ attachment.getFile().length() == 0 )
+ {
+ JOptionPane.showMessageDialog(
+ parentFrame,
+ "The message that is currently send (maybe a send
retry on next startup of Frost)\n"+
+ "contains a file attachment that does not longer
exist!\n\n"+
+ "The send of the message was aborted and the message
file was deleted\n"+
+ "to prevent another upload try on next startup of
Frost.",
+ "Unrecoverable error",
+ JOptionPane.ERROR_MESSAGE);
+
+ unsentMessageFile.delete();
+ return false;
+ }
+ }
+
+ // upload each attachment
+ i = fileAttachments.iterator();
+ while (i.hasNext()) {
+ SharedFileObject attachment = (SharedFileObject) i.next();
+ if(uploadAttachment(attachment)) {
+ //If the attachment was successfully inserted, we update the
message on disk.
+ saveMessage(msg, file);
+ } else {
+ success = false;
+ }
+ }
if (!success) {
JOptionPane.showMessageDialog(