Author: bback
Date: 2006-02-12 13:36:40 +0000 (Sun, 12 Feb 2006)
New Revision: 8022
Removed:
trunk/apps/frost-0.7/source/frost/crypt/EncryptMetaData.java
trunk/apps/frost-0.7/source/frost/crypt/MetaData.java
trunk/apps/frost-0.7/source/frost/crypt/SignMetaData.java
Modified:
trunk/apps/frost-0.7/source/frost/crypt/Crypt.java
trunk/apps/frost-0.7/source/frost/crypt/FrostCrypt.java
trunk/apps/frost-0.7/source/frost/fcp/FcpConnection.java
trunk/apps/frost-0.7/source/frost/fcp/FcpInsert.java
trunk/apps/frost-0.7/source/frost/fcp/FcpRequest.java
trunk/apps/frost-0.7/source/frost/fcp/FcpResults.java
trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadThread.java
trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadThread.java
trunk/apps/frost-0.7/source/frost/messages/FrostIndex.java
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
trunk/apps/frost-0.7/source/frost/threads/UpdateIdThread.java
Log:
uploads/downloads repaired, rewrote msg handling to use no metadata any longer
Modified: trunk/apps/frost-0.7/source/frost/crypt/Crypt.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/crypt/Crypt.java 2006-02-11 21:43:18 UTC
(rev 8021)
+++ trunk/apps/frost-0.7/source/frost/crypt/Crypt.java 2006-02-12 13:36:40 UTC
(rev 8022)
@@ -57,7 +57,9 @@
public String digest(File which);
public byte[] encrypt(byte[] what, String publicKey);
- public byte [] decrypt(byte [] what, String privateKey);
+ public byte[] decrypt(byte [] what, String privateKey);
+ public String encrypt(String what, String publicKey);
+ public String decrypt(String what, String privateKey);
public String encode64(String what);
Deleted: trunk/apps/frost-0.7/source/frost/crypt/EncryptMetaData.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/crypt/EncryptMetaData.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/crypt/EncryptMetaData.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -1,124 +0,0 @@
-/*
- EncryptMetaData.java / Frost
- Copyright (C) 2003 Jan-Thomas Czornack <jantho at users.sourceforge.net>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-package frost.crypt;
-
-import java.util.logging.*;
-
-import org.w3c.dom.*;
-import org.xml.sax.*;
-
-import frost.*;
-import frost.identities.*;
-
-/**
- * @author zlatinb
- *
- * MetaData for encrypted messages
- * Format:
- * <FrostMetaData>
- * <MyIdentity>
- * <name> unique name of sender </name>
- * <key> public key of sender </key>
- * </MyIdentity>
- *
- * <sig> signature of file </sig>
- *
- * <Recipient> unique name of recipient </Recipient>
- * </FrostMetaData>
- */
-public class EncryptMetaData extends SignMetaData {
-
- private static Logger logger =
Logger.getLogger(EncryptMetaData.class.getName());
-
- String recipient; // unique name of recipient
-
- /**
- * Creates MetaData from received metadata.
- * Loads person, sig and receiver from XML.
- */
- public EncryptMetaData(Element el) throws SAXException {
- try {
- loadXMLElement(el);
- } catch (SAXException e) {
- logger.log(Level.SEVERE, "Exception thrown in constructor", e);
- throw e;
- }
- }
-
- /**
- * Creates metadata to be attached to encrypted message.
- * Computes signature for encrypted_data.
- *
- * @param recipient the recepient
- */
- public EncryptMetaData(byte[] encrypted_data, LocalIdentity myId, String
recipient) {
-
- super(encrypted_data, myId); // compute sig for encrypted_data
-
- assert recipient != null;
-
- this.recipient = recipient;
- }
-
- /**
- * Returns XML with person (sender), sig and recipient set.
- */
- public Element getXMLElement(Document container) {
-
- Element el = super.getXMLElement(container); // set sender and
sig
-
- if( recipient != null ) {
- Element rec = container.createElement("Recipient");
- CDATASection cdata = container.createCDATASection(recipient);
- rec.appendChild(cdata);
- el.appendChild(rec);
- } else {
- logger.log(Level.SEVERE, "getXMLElement: recipient is null, this
is not allowed!");
- return null;
- }
- return el;
- }
-
- /**
- * Loads person (sender), sig and recipient from XML data.
- */
- public void loadXMLElement(Element e) throws SAXException {
-
- super.loadXMLElement(e); // get sender and sig
-
- if( XMLTools.getChildElementsByTagName(e,"Recipient").size() > 0 ) {
- recipient = XMLTools.getChildElementsCDATAValue(e, "Recipient");
- }
- assert recipient != null && recipient.length() > 0;
- }
-
- /**
- * @return Returns the recipient.
- */
- public String getRecipient() {
- return recipient;
- }
-
- /* (non-Javadoc)
- * @see frost.crypt.MetaData#getType()
- */
- public int getType() {
- return MetaData.ENCRYPT;
- }
-}
Modified: trunk/apps/frost-0.7/source/frost/crypt/FrostCrypt.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/crypt/FrostCrypt.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/crypt/FrostCrypt.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -115,13 +115,18 @@
* Computes the SHA-1 checksum of given message.
*/
public synchronized String digest(String message) {
- SHA1Digest stomach = new SHA1Digest();
- stomach.reset();
- byte[] food = message.getBytes();
- stomach.update(food, 0, food.length);
- byte[] poop = new byte[64];
- stomach.doFinal(poop, 0);
- return (new String(Base64.encode(poop))).substring(0, 27);
+ try {
+ SHA1Digest stomach = new SHA1Digest();
+ stomach.reset();
+ byte[] food = message.getBytes("UTF-8");
+ stomach.update(food, 0, food.length);
+ byte[] poop = new byte[64];
+ stomach.doFinal(poop, 0);
+ return (new String(Base64.encode(poop))).substring(0, 27);
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 encoding is not supported.", ex);
+ }
+ return null;
}
/**
@@ -158,6 +163,18 @@
return (new String(Base64.encode(poop))).substring(0, 27);
}
+ public synchronized String encrypt(String what, String publicKey) {
+ try {
+ byte[] whatBytes = what.getBytes("UTF-8");
+ byte[] encryptedBytes = encrypt(whatBytes, publicKey);
+ String result = new String(Base64.encode(encryptedBytes),
"ISO-8859-1");
+ return result;
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 encoding is not supported.", ex);
+ }
+ return null;
+ }
+
/**
* Encryption of a byte array.
*
@@ -249,6 +266,17 @@
return plainOut.toByteArray();
}
+ public synchronized String decrypt(String what, String privateKey) {
+ try {
+ byte[] encBytes = Base64.decode(what.getBytes("ISO-8859-1"));
+ byte[] decBytes = decrypt(encBytes, privateKey);
+ return new String(decBytes, "UTF-8");
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 encoding is not supported.", ex);
+ }
+ return null;
+ }
+
/**
* Decrypts a byte array.
*
@@ -338,9 +366,14 @@
return plainOut.toByteArray();
}
-
- public synchronized String detachedSign(String message, String key){
- return detachedSign(message.getBytes(), key);
+ public synchronized String detachedSign(String message, String key) {
+ try {
+ byte[] msgBytes = message.getBytes("UTF-8");
+ return detachedSign(msgBytes, key);
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 encoding is not supported.", ex);
+ }
+ return null;
}
public synchronized String detachedSign(byte[] message, String key) {
@@ -366,26 +399,42 @@
logger.log(Level.SEVERE, "Exception thrown in
detachedSign(String message, String key)", e);
}
signer.reset();
- String result = new String(Base64.encode(signature));
- return result;
+ try {
+ String result = new String(Base64.encode(signature),
"ISO-8859-1");
+ return result;
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "ISO-8859-1 encoding is not supported.",
ex);
+ }
+ return null;
}
public synchronized boolean detachedVerify(String message, String key,
String sig){
- return detachedVerify(message.getBytes(),key,sig);
+ try {
+ byte[] msgBytes = message.getBytes("UTF-8");
+ return detachedVerify(msgBytes, key, sig);
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 encoding is not supported.", ex);
+ }
+ return false;
}
public synchronized boolean detachedVerify(byte[] message, String key,
String _sig) {
- byte[] sig = Base64.decode(_sig.getBytes());
-
- StringTokenizer keycutter = new StringTokenizer(key, ":");
- BigInteger Exponent = new
BigInteger(Base64.decode(keycutter.nextToken()));
- BigInteger Modulus = new
BigInteger(Base64.decode(keycutter.nextToken()));
-
- signer.init(false, new RSAKeyParameters(true, Modulus,
Exponent));
-
- signer.update(message, 0, message.length);
- boolean result = signer.verifySignature(sig);
- signer.reset();
- return result;
+ try {
+ byte[] sig = Base64.decode(_sig.getBytes("ISO-8859-1"));
+
+ StringTokenizer keycutter = new StringTokenizer(key, ":");
+ BigInteger Exponent = new
BigInteger(Base64.decode(keycutter.nextToken()));
+ BigInteger Modulus = new
BigInteger(Base64.decode(keycutter.nextToken()));
+
+ signer.init(false, new RSAKeyParameters(true, Modulus,
Exponent));
+
+ signer.update(message, 0, message.length);
+ boolean result = signer.verifySignature(sig);
+ signer.reset();
+ return result;
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "ISO-8859-1 encoding is not supported.",
ex);
+ }
+ return false;
}
private synchronized SecureRandom getSecureRandom() {
@@ -393,11 +442,23 @@
}
public String decode64(String what) {
- return new String(Base64.decode(what.getBytes()));
+ try {
+ byte[] whatBytes = what.getBytes("ISO-8859-1");
+ return new String(Base64.decode(whatBytes), "UTF-8");
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 or ISO-8859-1 encoding is not
supported.", ex);
+ }
+ return null;
}
public String encode64(String what) {
- return new String(Base64.encode(what.getBytes()));
+ try {
+ byte[] whatBytes = what.getBytes("UTF-8");
+ return new String(Base64.encode(whatBytes), "ISO-8859-1");
+ } catch(UnsupportedEncodingException ex) {
+ logger.log(Level.SEVERE, "UTF-8 or ISO-8859-1 encoding is not
supported.", ex);
+ }
+ return null;
}
/**
Deleted: trunk/apps/frost-0.7/source/frost/crypt/MetaData.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/crypt/MetaData.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/crypt/MetaData.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -1,77 +0,0 @@
-/*
- MetaData.java / Frost
- Copyright (C) 2003 Jan-Thomas Czornack <jantho at users.sourceforge.net>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-package frost.crypt;
-
-import java.util.logging.*;
-
-import org.w3c.dom.*;
-import org.xml.sax.SAXException;
-
-import frost.*;
-import frost.identities.Identity;
-
-public abstract class MetaData implements XMLizable {
-
- private static Logger logger =
Logger.getLogger(MetaData.class.getName());
-
- public static final int SIGN = 0;
- public static final int ENCRYPT = 1;
-
- public abstract int getType();
-
- Identity person; // sender
-
- /**
- * @return the person (sender) of the message
- */
- public Identity getPerson(){
- return person;
- }
-
- public Element getXMLElement(Document container){
- Element el = container.createElement("FrostMetaData");
- // use getSafeXMLElement to make sure we don't add sensitive fields in
the metadata
- Element _person = person.getSafeXMLElement(container);
- el.appendChild(_person);
- return el;
- }
-
- public static MetaData getInstance(Element e) {
-
- if( e == null ) {
- logger.log(Level.SEVERE, "MetaData.getInstance(): The provided XML
element is null.");
- return null;
- }
- if( e.getNodeName().equals("FrostMetaData") == false ) {
- logger.log(Level.SEVERE, "MetaData.getInstance(): This is no
FrostMetaData XML element.");
- return null;
- }
-
- try {
- if
(XMLTools.getChildElementsByTagName(e,"Recipient").size() == 0) {
- return new SignMetaData(e);
- } else {
- return new EncryptMetaData(e);
- }
- } catch(SAXException ex) {
- logger.log(Level.SEVERE, "Exception thrown in
getInstance(byte [] body, Element e)", ex);
- }
- return null;
- }
-}
Deleted: trunk/apps/frost-0.7/source/frost/crypt/SignMetaData.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/crypt/SignMetaData.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/crypt/SignMetaData.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -1,135 +0,0 @@
-/*
- SignMetaData.java / Frost
- Copyright (C) 2003 Jan-Thomas Czornack <jantho at users.sourceforge.net>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-package frost.crypt;
-
-import java.util.logging.*;
-
-import org.w3c.dom.*;
-import org.xml.sax.*;
-
-import frost.*;
-import frost.identities.*;
-
-/**
- * @author zlatinb
- *
- * This file represents MetaData that's of a file in Freenet.
- * It has the following format:
- * <FrostMetaData>
- * <MyIdentity>
- * <name> unique name of person</name>
- * <key> public key of person </key>
- * </MyIdentity>
- * <sig> signature of file </sig>
- * </FrostMetaData>
- */
-public class SignMetaData extends MetaData {
-
- private static Logger logger =
Logger.getLogger(SignMetaData.class.getName());
-
- String sig;
-
- public SignMetaData() {
- person = null;
- sig = null;
- }
-
- /**
- * Represents a metadata of something about to be sent.
- * Computes signature of plaintext.
- */
- public SignMetaData(byte[] plaintext, LocalIdentity myId) {
- this.person = myId;
- sig = Core.getCrypto().detachedSign(plaintext,
myId.getPrivKey());
- }
-
- /**
- * Metadata of something that was received.
- */
- public SignMetaData(byte [] metadata) throws Throwable {
-
- Document d = XMLTools.parseXmlContent(metadata, false);
- Element el = d.getDocumentElement();
- if( el.getTagName().equals("FrostMetaData") == false ) {
- throw new Exception("This is not FrostMetaData XML file.");
- }
- try {
- loadXMLElement(el);
- } catch (SAXException e) {
- logger.log(Level.SEVERE, "Exception thrown in
constructor", e);
- throw e;
- }
- }
-
- /**
- * Represents something that was received and needs to be verified.
- * Parses XML and sets person and sig.
- * @param plaintext the plaintext to be verified
- * @param el the xml element to populate from
- */
- public SignMetaData(Element el) throws SAXException {
- try {
- loadXMLElement(el);
- } catch (SAXException e) {
- logger.log(Level.SEVERE, "Exception thrown in
constructor", e);
- throw e;
- }
- }
-
- /* (non-Javadoc)
- * @see frost.XMLizable#getXMLElement(org.w3c.dom.Document)
- */
- public Element getXMLElement(Document container) {
-
- Element el = super.getXMLElement(container);
-
- Element _sig = container.createElement("sig");
- CDATASection cdata = container.createCDATASection(sig);
- _sig.appendChild(cdata);
-
- el.appendChild(_sig);
- return el;
- }
-
- /* (non-Javadoc)
- * @see frost.XMLizable#loadXMLElement(org.w3c.dom.Element)
- */
- public void loadXMLElement(Element e) throws SAXException {
-
- Element _person = (Element)
XMLTools.getChildElementsByTagName(e, "MyIdentity").iterator().next();
- person = new Identity(_person);
- sig = XMLTools.getChildElementsCDATAValue(e, "sig");
-
- assert person!=null && sig!=null;
- }
-
- /**
- * @return
- */
- public String getSig() {
- return sig;
- }
-
- /* (non-Javadoc)
- * @see frost.crypt.MetaData#getType()
- */
- public int getType() {
- return MetaData.SIGN;
- }
-}
Modified: trunk/apps/frost-0.7/source/frost/fcp/FcpConnection.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fcp/FcpConnection.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/fcp/FcpConnection.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -23,12 +23,9 @@
import java.io.*;
import java.net.*;
-import java.nio.*;
import java.util.*;
import java.util.logging.*;
-import frost.*;
-
/**
* This class is a wrapper to simplify access to the FCP library.
* @author <a href=mailto:landtuna at hotmail.com>Jim Hunziker</a>
@@ -147,8 +144,7 @@
*/
public FcpResults getKeyToFile(String keyString,
String filename,
- int htl,
- boolean fastDownload) throws IOException,
FcpToolsException, InterruptedIOException {
+ int htl) throws IOException,
FcpToolsException, InterruptedIOException {
keyString = FcpDisconnect(keyString);
keyString = StripSlashes(keyString);
@@ -196,7 +192,6 @@
FcpKeyword kw;
boolean receivedFinalByte = false;
long totalDataLength = 0;
- int metaDataLength = 0;
int dataChunkLength = 0;
boolean expectingData = false;
boolean flagRestarted = false;
@@ -222,7 +217,6 @@
fileOut = new FileOutputStream(filename);
totalDataLength = 0;
- metaDataLength = 0;
dataChunkLength = 0;
flagRestarted = false;
@@ -323,13 +317,11 @@
// would be , but after 25 minutes my 5 boards did not finish to update, 4
days backload
// thats really too slow ...
// now the fast mode is only used by MessageDownloadThread ...
- if( fastDownload ) receivedFinalByte = true;
+// if( fastDownload ) receivedFinalByte = true;
break;
}
} else { // handle data bytes
-
-
dataChunkLength = (int) totalDataLength;
logger.fine("Expecting " + dataChunkLength + " bytes, " +
totalDataLength + " total.");
System.out.println("Expecting " + dataChunkLength + " bytes, "
+ totalDataLength + " total.");
@@ -350,15 +342,7 @@
}
System.out.println("GOT DATA");
- //System.out.println(new String(b,
Charset.defaultCharset().name()));
- metaDataLength = getMetaDataLength(b);
- System.out.println("Metadata length=" + metaDataLength);
- b = removeMetaData(b);
- System.out.println("DATA WITHOUT first 4 bytes:");
- //System.out.println(new String(b,
Charset.defaultCharset().name()));
fileOut.write(b);
- System.out.println("wrote:");
- //System.out.println(new String(b,
Charset.defaultCharset().name()));
expectingData = false;
totalDataLength -= bytesRead;
if( totalDataLength <= 0 ) {
@@ -373,53 +357,12 @@
fileOut.flush();
fileOut.close();
File checkSize = new File(filename);
- if( metaDataLength > 0 && checkSize.length() > 0 ) {
- if( metaDataLength == checkSize.length() ) {
- // all data are metadata ...
- byte[] content = FileAccess.readByteArray(checkSize);
- result.setRawMetadata(content);
- // delete data file which contains no data
- checkSize.delete();
- } else {
- // remove metadata from file and put metadata into result
- byte[] content = FileAccess.readByteArray(checkSize);
- byte[] metadata = new byte[(int) metaDataLength];
- System.arraycopy(content, 0, metadata, 0, (int)
metaDataLength);
-
- result.setRawMetadata(metadata);
- // there is data behind metadata, write only this raw data to
file
- int datalen = (int) (checkSize.length() - metaDataLength);
- byte[] rawdata = new byte[datalen];
- System.arraycopy(content, (int) metaDataLength, rawdata, 0,
datalen);
- FileAccess.writeFile(rawdata, checkSize);
- }
- } else if( metaDataLength == 0 && checkSize.length() == 0 ) {
+ if( checkSize.length() == 0 ) {
checkSize.delete();
}
- System.out.println("result");
return result;
}
- //computes length from first 4 bytes of data
- private int getMetaDataLength(byte[] data){
- int length = 0;
-
- ByteBuffer bb = ByteBuffer.wrap(data,0,4);
- length = bb.getInt();
-
- return length;
- }
-
- //removes first 4 bytes from data, it is always metaData
- private byte[] removeMetaData(byte[] data){
- System.out.println("removing metadata");
- byte[] shortdata = new byte[data.length - 4];
- System.arraycopy(data,4,shortdata,0,shortdata.length);
-
- return shortdata;
-
- }
-
/**
* Inserts the specified key with the data from the file specified.
*
@@ -431,8 +374,7 @@
* the HTL to use for this insert
* @return the results filled with metadata and the CHK used to insert the
data
*/
- public String putKeyFromArray(String key, byte[] data, byte[] metadata,
int htl,
- boolean getchkonly)
+ public String putKeyFromArray(String key, byte[] data, int htl, boolean
getchkonly)
throws IOException, FcpToolsException {
key = FcpDisconnect(key);
@@ -455,17 +397,12 @@
System.out.println("URI="+key);
int dataLength = 0;
- int metadataLength = 0;
if (data != null) {
dataLength = data.length;
}
- if (metadata != null) {
- metadataLength = metadata.length;
- }
-
- fcpOut.println("DataLength=" + Integer.toString(dataLength +
metadataLength + 4));
- System.out.println("DataLength="+ Integer.toString(dataLength +
metadataLength + 4));
+ fcpOut.println("DataLength=" + Integer.toString(dataLength));
+ System.out.println("DataLength="+ Integer.toString(dataLength));
fcpOut.println("Identifier=put-" +
Thread.currentThread().getId() );
System.out.println("Identifier=put-" +
Thread.currentThread().getId());
@@ -482,18 +419,6 @@
System.out.println("Data");
fcpOut.flush();
- //putting first 4 bytes of data which tells us the length of
metadata
- ByteBuffer bb = ByteBuffer.allocate(4);
- bb.putInt(metadataLength);
- byte[] ba = bb.array();
- dOut.write(ba);
- //System.out.println(new String(ba,
Charset.defaultCharset().toString()));
-
- if (metadata != null) {
- dOut.write(metadata);
- //System.out.println( new
String(metadata,Charset.defaultCharset().toString()) );
- }
-
if (data != null) {
dOut.write(data);
//System.out.println( new
String(data,Charset.defaultCharset().toString()) );
@@ -526,12 +451,12 @@
/**
* Performs a handshake using this FcpConnection
*/
- public void doHandshake(Socket fcpSock) throws IOException,
FcpToolsException
+ public void doHandshake(Socket fcpSocket) throws IOException,
FcpToolsException
{
//fcpSock = new Socket(host, port);
- fcpIn = new BufferedInputStream(fcpSock.getInputStream());
- fcpOut = new PrintStream(fcpSock.getOutputStream());
- fcpSock.setSoTimeout(TIMEOUT);
+ fcpIn = new BufferedInputStream(fcpSocket.getInputStream());
+ fcpOut = new PrintStream(fcpSocket.getOutputStream());
+ fcpSocket.setSoTimeout(TIMEOUT);
fcpOut.println("ClientHello");
logger.fine("ClientHello");
@@ -569,10 +494,10 @@
/**
* generates chk for the data
*/
- public String getCHK(byte[] data) throws IOException, FcpToolsException
+ public String generateCHK(byte[] data) throws IOException,
FcpToolsException
{
String uri = "";
- String output = putKeyFromArray("CHK@", data, null, 3, true);
+ String output = putKeyFromArray("CHK@", data, 3, true);
System.out.println("GOT OUTPUT " + output + "\n STARTING CHK
GENERATION");
int URIstart = output.indexOf("CHK@");
String substr = output.substring(URIstart);
Modified: trunk/apps/frost-0.7/source/frost/fcp/FcpInsert.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fcp/FcpInsert.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/fcp/FcpInsert.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -40,15 +40,6 @@
{
private static Logger logger =
Logger.getLogger(FcpInsert.class.getName());
- //public final static int smallestChunk = 262144;
- // changed to freenets behaviour. also smaller values will produce errors
in RandomAccessFile2.segment()
- //however, Freenet fails very often to transfer large chuncks.
- //--zab
- //public final static int smallestChunk = 256 * 1024;
- //changed again because files smaller than 768KB in size caused an
IllegalArgumentException
- //in RandomAccessFileBucket2.segment(). Kevloral 20-02-2004
-
-
/*
* ClientPut
URI=KSK at fuckkkk
@@ -129,9 +120,7 @@
*/
public static String[] putFile(String uri,
File file,
- byte[] metadata,
int htl,
- boolean doRedirect,
FrostUploadItem ulItem)
{
if (file.length() == 0) {
@@ -151,101 +140,44 @@
}
byte[] data = FileAccess.readByteArray(file);
-// if ( doRedirect ){
-// System.out.println("REDIRECT requested!");
-// }
- String output = connection.putKeyFromArray(uri, data, metadata,
htl, false);
-// String output = workaroundPutKeyFromArray(connection, uri, data,
metadata, htl);
+ String output = connection.putKeyFromArray(uri, data, htl, false);
return result(output);
} catch( UnknownHostException e ) {
-
logger.log(Level.SEVERE, "UnknownHostException", e);
} catch( Throwable e ) {
-
logger.log(Level.SEVERE, "Throwable", e);
}
-
return ERROR;
-
}
-
-// public static String getCHK(File file){
-// String ERROR="CHK@";
-// if (file.length() == 0) {
-// logger.log(Level.SEVERE, "Error: Can't generate CHK empty file:
"+file.getPath());
-// System.out.println("Error: Can't generate CHK for empty file:
"+file.getPath());
-// JOptionPane.showMessageDialog(MainFrame.getInstance(),
-// "FcpInsert: File
"+file.getPath()+" is empty!", // message
-// "Warning",
-//
JOptionPane.WARNING_MESSAGE);
-// return ERROR;
-// }
-//
-// try {
-// FcpConnection connection = FcpFactory.getFcpConnectionInstance();
-// if( connection == null ) {
-// return ERROR;
-// }
-//
-// byte[] data = FileAccess.readByteArray(file);
-// String output = connection.getCHK(data);
-//
-// return output;
-//
-// } catch( UnknownHostException e ) {
-//
-// logger.log(Level.SEVERE, "UnknownHostException", e);
-// } catch( Throwable e ) {
-//
-// logger.log(Level.SEVERE, "Throwable", e);
-// }
-//
-// return ERROR;
-// }
-
- /**
- * Method calls FcpConnection.putKeyFromArray() and works around a freenet
bug:
- * sometimes freenet closes the socket without to provide an EndMessage.
- * The output is < 5 characters then. If this is received, the insert is
restarted.
- * TODO: please remove this workaround when the freenet devs fix the FCP
insert
- */
-// private static String workaroundPutKeyFromArray(
-// FcpConnection connection, String key, byte[] data, byte[]
metadata, int htl) throws IOException {
-//
-// int loop = 0;
-// final int maxLoops = 16; // high value for sure, should never happen
-//
-// while(true) {
-// String output = "";
-// try{
-// output = connection.putKeyFromArray(key, data,
metadata, htl, false);
-// }catch (FcpToolsException e){
-// System.out.println("no connection to node");
-// }
-// if( output.length() < 5 ) { // actually the length is 1, but
just in case...
-// if( loop < maxLoops ) {
-// logger.warning("Freenet insert failed, maybe a freenet
bug (output="+output+"). Loop "+loop+". Trying again...");
-// System.out.println("Freenet insert failed, maybe a
freenet bug (output="+output+"). Loop "+loop+". Trying again...");
-// loop++;
-// Mixed.wait(333);
-// continue;
-// } else {
-// logger.severe("Freenet insert failed due to freenet bug,
tried "+loop+" times (output="+output+").");
-// System.out.println("Freenet insert failed due to freenet
bug, tried "+loop+" times (output="+output+").");
-// return null;
-// }
-// } else {
-// logger.info("Freenet insert ended, loop="+loop+", output
from fcp insert : "+output);
-// System.out.println("Freenet insert ended, loop="+loop+",
output from fcp insert : "+output);
-// return output;
-// }
-// }
-// }
-
-}
+ public static String generateCHK(File file) {
-
-
+ if (file.length() == 0) {
+ logger.log(Level.SEVERE, "Error: Can't generate CHK empty file:
"+file.getPath());
+ System.out.println("Error: Can't generate CHK for empty file:
"+file.getPath());
+ JOptionPane.showMessageDialog(MainFrame.getInstance(),
+ "FcpInsert: File
"+file.getPath()+" is empty!", // message
+ "Warning",
+
JOptionPane.WARNING_MESSAGE);
+ return null;
+ }
+
+ try {
+ FcpConnection connection = FcpFactory.getFcpConnectionInstance();
+ if( connection == null ) {
+ return null;
+ }
+ byte[] data = FileAccess.readByteArray(file);
+ String generatedCHK = connection.generateCHK(data);
+ return generatedCHK;
+
+ } catch( UnknownHostException e ) {
+ logger.log(Level.SEVERE, "UnknownHostException", e);
+ } catch( Throwable e ) {
+ logger.log(Level.SEVERE, "Throwable", e);
+ }
+ return null;
+ }
+}
Modified: trunk/apps/frost-0.7/source/frost/fcp/FcpRequest.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fcp/FcpRequest.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/fcp/FcpRequest.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -50,8 +50,6 @@
Long size,
File target,
int htl,
- boolean doRedirect,
- boolean fastDownload,
boolean createTempFile,
FrostDownloadItem dlItem)
{
@@ -68,7 +66,7 @@
}
// First we just download the file, not knowing what lies ahead
- FcpResults results = getKey(key, tempFile, htl, fastDownload);
+ FcpResults results = getKey(key, tempFile, htl);
if( results != null ) {
@@ -98,7 +96,7 @@
}
// used by getFile
- private static FcpResults getKey(String key, File target, int htl, boolean
fastDownload) {
+ private static FcpResults getKey(String key, File target, int htl) {
if( key == null || key.length() == 0 || key.startsWith("null") ) {
return null;
@@ -112,7 +110,7 @@
int maxtries = 3;
while( tries < maxtries || results != null ) {
try {
- results = connection.getKeyToFile(key, target.getPath(),
htl, fastDownload);
+ results = connection.getKeyToFile(key, target.getPath(),
htl);
break;
}
catch( java.net.ConnectException e ) {
@@ -149,9 +147,7 @@
.append(keyUrl).toString();
}
- boolean metadataAvailable = results!=null &&
results.getRawMetadata()!=null &&
- results.getRawMetadata().length > 0;
- if( results != null && ( target.length() > 0 || metadataAvailable ) ) {
+ if( results != null && target.length() > 0 ) {
logger.info("getKey - Success: " + printableKey );
System.out.println("getKey - Success: " + printableKey );
return results;
Modified: trunk/apps/frost-0.7/source/frost/fcp/FcpResults.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fcp/FcpResults.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/fcp/FcpResults.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -23,17 +23,13 @@
* returned from an FCP operation.
* @author <a href=mailto:landtuna at hotmail.com>Jim Hunziker</a>
*/
-public class FcpResults
-{
- /** the metadata */
- byte [] rawMetadata = null;
+public class FcpResults {
/** the CHK URI */
String chkUri = null;
- public FcpResults(byte[] md, String cu)
+ public FcpResults(String cu)
{
- rawMetadata = md;
chkUri = cu;
}
@@ -42,21 +38,6 @@
}
/**
- * Retrieves the metadata.
- * Valid for downloading.
- *
- * @return the metadata
- */
- public String [] getMetadataAsLines()
- {
- if( rawMetadata == null )
- {
- return null;
- }
- return new String(rawMetadata).split("\n");
- }
-
- /**
* Retrieves the CHK URI.
* Valid for uploading.
*
@@ -77,22 +58,4 @@
{
this.chkUri = chkUri;
}
-
- /**
- * @return
- */
- public byte[] getRawMetadata() {
- return rawMetadata;
- }
-
- /**
- * Sets the metadata.
- * Valid for downloading.
- *
- * @param metadata the metadata
- */
- public void setRawMetadata(byte[] bs) {
- rawMetadata = bs;
- }
-
}
Modified:
trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadThread.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadThread.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -96,8 +96,6 @@
size,
newFile,
25, // HTL
- true, // doRedirect
- false, // fastDownload
false, // createTempFile
downloadItem);
} catch (Throwable t) {
Modified:
trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadThread.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadThread.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -128,9 +128,7 @@
result = FcpInsert.putFile(
"CHK@",
file,
- null, // metadata
htl,
- true, // doRedirect
uploadItem); // provide the uploadItem to indicate that this
upload is contained in table
if (result[0].equals("PutSuccessful") ||
result[0].equals("KeyCollision")) {
Modified: trunk/apps/frost-0.7/source/frost/messages/FrostIndex.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/messages/FrostIndex.java 2006-02-11
21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/messages/FrostIndex.java 2006-02-12
13:36:40 UTC (rev 8022)
@@ -49,6 +49,21 @@
if (Core.frostSettings.getBoolValue("signUploads") &&
sharer!=null) {
Element _sharer = sharer.getSafeXMLElement(container);
el.appendChild(_sharer);
+
+ // compute and append signature
+// String toSign = "";
+// for(Iterator i = getFilesMap().values().iterator(); i.hasNext();
) {
+// SharedFileObject current = (SharedFileObject)i.next();
+// toSign += current.getKey()+current.getBoard();
+// }
+// String sig = Core.getCrypto().detachedSign(toSign,
Core.getInstance().getIdentities().getMyId().getPrivKey());
+//
+// CDATASection cdata;
+// Element current;
+// current = container.createElement("Signature");
+// cdata = container.createCDATASection(Mixed.makeSafeXML(sig));
+// current.appendChild(cdata);
+// el.appendChild(current);
}
boolean signUploads =
Core.frostSettings.getBoolValue("signUploads");
@@ -91,9 +106,7 @@
while (it.hasNext()) {
Element el = (Element)it.next();
SharedFileObject file =
SharedFileObject.getInstance(el);
-// if (file.getSHA1()!=null) {
- filesMap.put(file.getKey(),file);
-// }
+ filesMap.put(file.getKey(),file);
}
}
Modified: trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -55,7 +55,8 @@
private String time = "";
private String index = "";
private String publicKey = "";
- private String recipient = ""; // set if msg was encrypted
+ private String recipient = ""; // set if msg was encrypted
+ private String signature = ""; // set if message is signed
private boolean deleted = false;
private int signatureStatus = SIGNATURESTATUS_UNSET;
@@ -194,6 +195,10 @@
public String getRecipient() {
return recipient;
}
+
+ public String getSignature() {
+ return signature;
+ }
/**
* Get a list of all attached files that are currently offline.
@@ -285,6 +290,14 @@
el.appendChild(current);
}
+ // signature
+ if (signature != null && signature.length() > 0) {
+ current = d.createElement("Signature");
+ cdata = d.createCDATASection(Mixed.makeSafeXML(getSignature()));
+ current.appendChild(cdata);
+ el.appendChild(current);
+ }
+
//is deleted?
if (deleted) {
current = d.createElement("Deleted");
@@ -394,6 +407,7 @@
recipient = XMLTools.getChildElementsCDATAValue(e, "recipient");
board = XMLTools.getChildElementsCDATAValue(e, "Board");
content = XMLTools.getChildElementsCDATAValue(e, "Body");
+ signature = XMLTools.getChildElementsCDATAValue(e, "Signature");
if (!XMLTools.getChildElementsByTagName(e,
"Deleted").isEmpty()) {
deleted = true;
@@ -502,6 +516,10 @@
public void setRecipient(String rec) {
recipient = rec;
}
+
+ public void setSignature(String sig) {
+ signature = sig;
+ }
/**
* This method adds a new Attachment to the attachments list.
Modified: trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/threads/MessageDownloadThread.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -23,11 +23,8 @@
import java.util.*;
import java.util.logging.*;
-import org.w3c.dom.*;
-
import frost.*;
import frost.boards.*;
-import frost.crypt.*;
import frost.fcp.*;
import frost.fileTransfer.*;
import frost.gui.objects.*;
@@ -57,13 +54,11 @@
* .xml files with this content are ignored by the gui (in fact all .xml
files with length smaller than 20)
*/
public static final String DUPLICATE_MSG = "DuplicateMsg"; // msg was
already received
- public static final String BROKEN_METADATA = "BrokenMetaData"; // could
not load metadata
public static final String BROKEN_MSG = "BrokenMsg"; // could not
load xml
public static final String MSG_NOT_FOR_ME = "NotForMe"; // encrypted for
someone other
public static final String DECRYPT_FAILED = "DecryptFailed"; // encrypted
for me, but decrypt failed
public static final String INVALID_MSG = "InvalidMsg"; // message
format validation failed
-
public int getThreadType() {
if (flagNew) {
return BoardUpdateThread.MSG_DNLOAD_TODAY;
@@ -138,13 +133,13 @@
notifyThreadFinished(this);
}
- protected void downloadDate(GregorianCalendar calDL)
- {
+ protected void downloadDate(GregorianCalendar calDL) {
+
VerifyableMessageObject currentMsg = null;
String dirdate = DateFun.getDateOfCalendar(calDL);
String fileSeparator = System.getProperty("file.separator");
- destination =
+ destination =
new StringBuffer()
.append(keypool)
.append(board.getBoardFilename())
@@ -158,28 +153,16 @@
makedir.mkdirs();
}
-// File checkLockfile = new File(destination + "locked.lck");
int index = 0;
int failures = 0;
- int maxFailures;
-
- // this works, but could lead into problems if you don't run frost 24h
a day
-// if (flagNew) {
-// maxFailures = 2; // skip a maximum of 2 empty slots for today
-// } else {
-// maxFailures = 1; // skip a maximum of 1 empty slots for backload
-// }
+ int maxFailures = 2; // skip a maximum of 2 empty slots
- maxFailures = 2; // skip a maximum of 2 empty slots
-
while (failures < maxFailures) {
-// while (failures < maxFailures && (flagNew ||
checkLockfile.exists() == false )) {
if (isInterrupted()) {
return;
}
File testMe = null, testMe2 = null;
- byte[] metadata = null;
try { // we don't want to die for any reason
String val = new StringBuffer()
@@ -231,24 +214,14 @@
.toString();
}
- // for backload use fast download, deep for today
- boolean fastDownload = !flagNew;
- FcpResults res = FcpRequest.getFile(
+ FcpRequest.getFile(
downKey,
null,
testMe,
downloadHtl,
- false,
- fastDownload,
true, // createTempFile
null); // no DownloadItem
- if (res == null) {
- metadata = null; // if metadata==null its NOT a signed
message
- } else {
- metadata = res.getRawMetadata(); // signed and maybe
encrypted message
- }
-
} catch(Throwable t) {
logger.log(Level.SEVERE, "TOFDN: Exception thrown in
downloadDate(GregorianCalendar calDL)", t);
// download failed, try next file
@@ -272,162 +245,69 @@
testMe.renameTo(testMe2);
testMe = testMe2;
- // compute the sha1 checksum of the original msg file
- // this digest is ONLY used to check for incoming exact
duplicate files, because
- // the locally stored message xml file could be changed later
by Frost
-// String messageId = Core.getCrypto().digest(testMe);
-
- // if no metadata, message wasn't signed
- if (metadata == null) {
-
-// byte[] unzippedXml =
FileAccess.readZipFileBinary(testMe);
-// if( unzippedXml == null ) {
-// logger.log(Level.SEVERE, "TOFDN: Unzip of unsigned
xml failed");
-// System.out.println("TOFDN: Unzip of unsigned xml
failed");
-// FileAccess.writeFile(BROKEN_MSG, testMe); // this
file is ignored by the gui
-// continue;
-// }
-// FileAccess.writeFile(unzippedXml, testMe);
-
- try {
- currentMsg = new VerifyableMessageObject(testMe);
- // check and maybe add msg to gui, set to unsigned
- addMessageToGui(currentMsg, testMe, true, calDL,
MessageObject.SIGNATURESTATUS_OLD);
-
- } catch (Exception ex) {
- logger.log(Level.SEVERE,
"TOFDN: Exception thrown in downloadDate(GregorianCalendar calDL)", ex);
- // file could not be read, mark it invalid not to
confuse gui
- FileAccess.writeFile(BROKEN_MSG, testMe); // this file
is ignored by the gui
- }
- continue;
- }
-
- // verify the zipped message
- MetaData _metaData = null;
try {
- Element el = XMLTools.parseXmlContent(metadata,
false).getDocumentElement();
- _metaData = MetaData.getInstance(el);
- } catch (Throwable t) {
- logger.log(Level.SEVERE, "TOFDN: Exeption in
MetaData.getInstance(): ", t);
- _metaData = null;
- }
- if( _metaData == null ) {
- // metadata failed, do something
- logger.log(Level.SEVERE, "TOFDN: Metadata couldn't be
read. " +
- "Offending file saved as badmetadata.xml -
send to a dev for analysis");
- File badmetadata = new File("badmetadata.xml");
- FileAccess.writeFile(metadata, badmetadata);
- // don't try this file again
- FileAccess.writeFile(BROKEN_METADATA, testMe); // this
file is ignored by the gui
+ currentMsg = new VerifyableMessageObject(testMe);
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, "TOFDN: Exception thrown in
downloadDate(GregorianCalendar calDL)", ex);
+ // file could not be read, mark it invalid not to confuse
gui
+ FileAccess.writeFile(BROKEN_MSG, testMe); // this file is
ignored by the gui
continue;
}
-
- assert _metaData.getType() == MetaData.SIGN ||
_metaData.getType() == MetaData.ENCRYPT :
- "TOFDN: unknown type of metadata";
- // now the msg could be signed OR signed and encrypted
- // first check sign, later decrypt if msg was for me
-
- SignMetaData metaData = (SignMetaData)_metaData;
-
- //check if we have the owner already on the lists
- String _owner = metaData.getPerson().getUniqueName();
- Identity owner = identities.getIdentity(_owner);
- // if not on any list, use the parsed id and add to our
identities list
- if (owner == null) {
- owner = metaData.getPerson();
- owner.setState(FrostIdentities.NEUTRAL);
- identities.addIdentity(owner);
+ if( currentMsg.getSignature() == null ||
currentMsg.getSignature().length() == 0 ) {
+ // unsigned msg
+ // check and maybe add msg to gui, set to unsigned
+ addMessageToGui(currentMsg, testMe, true, calDL,
MessageObject.SIGNATURESTATUS_OLD);
+ continue;
}
-
- // verify signature
- byte[] plaintext = FileAccess.readByteArray(testMe);
- boolean sigIsValid =
Core.getCrypto().detachedVerify(plaintext, owner.getKey(), metaData.getSig());
-
- // only for correct owner (no faking allowed here)
- if( sigIsValid ) {
- // check if we already have owners board
-// if( owner.getBoard() == null &&
metaData.getPerson().getBoard() != null ) {
-// owner.setBoard(metaData.getPerson().getBoard());
-// }
- // update lastSeen for this Identity
- owner.updateLastSeenTimestamp();
- }
- // now check if msg is encrypted and for me, if yes decrypt
the zipped data
- if (_metaData.getType() == MetaData.ENCRYPT) {
- EncryptMetaData encMetaData = (EncryptMetaData)metaData;
-
- // 1. check if the message is for me
- if
(!encMetaData.getRecipient().equals(identities.getMyId().getUniqueName())) {
+ // check if msg is encrypted for me
+ if (currentMsg.getRecipient() != null &&
currentMsg.getRecipient().length() > 0 )
+ {
+ if(
!currentMsg.getRecipient().equals(identities.getMyId().getUniqueName()) ) {
logger.fine("TOFDN: Encrypted message was not for
me.");
FileAccess.writeFile(MSG_NOT_FOR_ME, testMe); // this
file is ignored by the gui
continue;
+ } else {
+ // decrypt msg content encrypted for me
+ String encContent = currentMsg.getContent();
+ String decContent =
Core.getCrypto().decrypt(encContent, identities.getMyId().getPrivKey());
+ if( decContent == null ) {
+ logger.log(Level.SEVERE, "TOFDN: Encrypted message
from "+currentMsg.getFrom()+
+ " could not be decrypted!");
+ FileAccess.writeFile(DECRYPT_FAILED, testMe); //
this file is ignored by the gui
+ continue;
+ }
+ currentMsg.setContent(decContent);
+ logger.fine("TOFDN: Decrypted an encrypted message for
me, sender was "+currentMsg.getFrom());
}
-
- // 2. if yes, decrypt the content
- byte[] cipherText = FileAccess.readByteArray(testMe);
- byte[] msgContent =
Core.getCrypto().decrypt(cipherText,identities.getMyId().getPrivKey());
-
- if( msgContent == null ) {
- logger.log(Level.SEVERE, "TOFDN: Encrypted message
from "+encMetaData.getPerson().getUniqueName()+
- " could not be decrypted!");
- FileAccess.writeFile(DECRYPT_FAILED, testMe); // this
file is ignored by the gui
- continue;
- }
-
- testMe.delete();
- FileAccess.writeFile(msgContent, testMe);
-
- logger.fine("TOFDN: Decrypted an encrypted message for me,
sender was "+encMetaData.getPerson().getUniqueName());
-
- // now continue as for signed files
-
- } //endif encrypted message
+ }
- // unzip
-// byte[] unzippedXml = FileAccess.readZipFileBinary(testMe);
-// if( unzippedXml == null ) {
-// logger.log(Level.SEVERE, "TOFDN: Unzip of signed xml
failed");
-// FileAccess.writeFile(BROKEN_MSG, testMe); // this file
is ignored by the gui
-// continue;
-// }
-// FileAccess.writeFile(unzippedXml, testMe);
-
- // create object
- try {
- currentMsg = new VerifyableMessageObject(testMe);
- } catch (Exception ex) {
- logger.log(Level.SEVERE, "TOFDN:
Exception when creating message object", ex);
- // file could not be read, mark it invalid not to confuse
gui
- FileAccess.writeFile(BROKEN_MSG, testMe); // this file is
ignored by the gui
- continue;
+ // check if we have the owner (sender) already on the lists
+ String _owner = currentMsg.getFrom();
+ Identity owner = identities.getIdentity(_owner);
+ // if not on any list, use the parsed id and add to our
identities list
+ if (owner == null) {
+ owner = new Identity(currentMsg.getFrom(),
currentMsg.getPublicKey());
+ owner.setState(FrostIdentities.NEUTRAL);
+ identities.addIdentity(owner);
}
- //then check if the signature was ok
+ // now verify signed content
+ String toVerify =
currentMsg.getDate()+currentMsg.getTime()+currentMsg.getSubject()+currentMsg.getContent();
+ boolean sigIsValid = Core.getCrypto().detachedVerify(toVerify,
owner.getKey(), currentMsg.getSignature());
+
+ // then check if the signature was ok
if (!sigIsValid) {
// TODO: should'nt we drop this msg instead of adding it
to the gui?
logger.warning("TOFDN: message failed verification, status
set to TAMPERED.");
addMessageToGui(currentMsg, testMe, false, calDL,
MessageObject.SIGNATURESTATUS_TAMPERED);
continue;
}
+
+ // update lastSeen for this Identity
+ owner.updateLastSeenTimestamp();
- //make sure the pubkey and from fields in the xml file are the
same as those in the metadata
- String metaDataHash =
Mixed.makeFilename(Core.getCrypto().digest(metaData.getPerson().getKey()));
- String messageHash = Mixed.makeFilename(
- currentMsg.getFrom().substring(
- currentMsg.getFrom().indexOf("@") + 1,
- currentMsg.getFrom().length()));
-
- if (!metaDataHash.equals(messageHash)) {
- // TODO: should'nt we drop this msg instead of adding it
to the gui?
- logger.warning("TOFDN: Hash in metadata doesn't match hash
in message!\n" +
- "metadata : "+metaDataHash+" ,
message: " + messageHash+
- ". Message failed verification, status set
to TAMPERED.");
- addMessageToGui(currentMsg, testMe, false, calDL,
MessageObject.SIGNATURESTATUS_TAMPERED);
- continue;
- }
-
addMessageToGui(currentMsg, testMe, true, calDL,
MessageObject.SIGNATURESTATUS_VERIFIED);
} catch (Throwable t) {
Modified: trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -28,8 +28,6 @@
import org.w3c.dom.*;
import frost.*;
-
-import frost.crypt.*;
import frost.fcp.*;
import frost.fileTransfer.upload.*;
import frost.gui.*;
@@ -53,13 +51,12 @@
private String keypool;
private MessageObject message;
- private File messageFile;
+ private File unsentMessageFile;
private int messageUploadHtl;
private String privateKey;
- private String publicKey;
+// private String publicKey;
private boolean secure;
- private byte[] signMetadata;
private File uploadFile;
private Identity encryptForRecipient;
@@ -108,11 +105,13 @@
// after upload was successful, or keeps it for next try
String uploadMe = new StringBuffer()
.append(frostSettings.getValue("unsent.dir"))
- .append("unsent")
+ .append("unsent-")
+ .append(board.getBoardFilename())
+ .append("-")
.append(String.valueOf(System.currentTimeMillis()))
.append(".xml")
.toString();
- messageFile = new File(uploadMe);
+ unsentMessageFile = new File(uploadMe);
}
/**
@@ -306,7 +305,7 @@
// switch public / secure board
if (board.isWriteAccessBoard()) {
privateKey = board.getPrivateKey();
- publicKey = board.getPublicKey();
+// publicKey = board.getPublicKey();
secure = true;
} else {
secure = false;
@@ -315,57 +314,75 @@
logger.info("TOFUP: Uploading message to board '" +
board.getName() + "' with HTL " + messageUploadHtl);
// first save msg to be able to resend on crash
- if (!saveMessage(message, messageFile)) {
+ if (!saveMessage(message, unsentMessageFile)) {
logger.severe("This was a HARD error and the file to
upload is lost, please report to a dev!");
return false;
}
// BBACKFLAG: ask user if uploading of X files is allowed!
- if (!uploadAttachments(message, messageFile)) {
+ if (!uploadAttachments(message, unsentMessageFile)) {
return false;
}
+
+ // sign the message content if necessary
+ String sender = message.getFrom();
+ String myId = identities.getMyId().getUniqueName();
- // zip the xml file to a temp file
- uploadFile = new File(messageFile.getPath() + ".upltmp");
+ 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;
+// }
+// }
+
+ 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!");
+ return false;
+ }
+ }
+
+ // copy the xml file to a temp file that is uploaded
+ uploadFile = new File(unsentMessageFile.getPath() + ".upltmp");
uploadFile.delete(); // just in case it already exists
uploadFile.deleteOnExit(); // so that it is deleted when Frost exits
- FileAccess.copyFile(messageFile.getPath(), uploadFile.getPath());
- if( !uploadFile.isFile() || uploadFile.length() == 0 ) {
- logger.severe("Error: Copy of message xml file failed, result file
not existing or empty. Please report to a dev!");
- return false;
- }
-
- // encrypt and sign or just sign the message file if necessary
- String sender = message.getFrom();
- String myId = identities.getMyId().getUniqueName();
- if (sender.equals(myId) // nick same as my identity
- || sender.equals(Mixed.makeFilename(myId))) //
serialization may have changed it
- {
- byte[] msgFileContent = FileAccess.readByteArray(messageFile);
-
- if( encryptForRecipient != null ) {
- // encrypt + sign
- // first encrypt, then sign
-
- byte[] encData = Core.getCrypto().encrypt(msgFileContent,
encryptForRecipient.getKey());
- if( encData == null ) {
- logger.severe("Error: could not encrypt the message,
please report to a dev!");
- return false;
- }
- FileAccess.writeFile(encData, uploadFile); // write encrypted
file
-
- EncryptMetaData ed = new EncryptMetaData(encData,
identities.getMyId(), encryptForRecipient.getUniqueName());
- signMetadata = XMLTools.getRawXMLDocument(ed);
-
- } else {
- // sign only
- SignMetaData md = new SignMetaData(msgFileContent,
identities.getMyId());
- signMetadata = XMLTools.getRawXMLDocument(md);
+ if( message.getSignature() != null && message.getSignature().length()
> 0 && // we signed, so encrypt is possible
+ encryptForRecipient != null )
+ {
+ // encrypt signed content
+ String encContent = Core.getCrypto().encrypt(message.getContent(),
encryptForRecipient.getKey());
+ if( encContent == null ) {
+ return false;
}
- } else if( encryptForRecipient != null ) {
+ message.setContent(encContent);
+ // save changed msg again, but to tmp upload file
+ if (!saveMessage(message, uploadFile)) {
+ logger.severe("This was a HARD error and the file to upload is
lost, please report to a dev!");
+ return false;
+ }
+ } else if( encryptForRecipient != null ) {
logger.log(Level.SEVERE, "TOFUP: ALERT - can't encrypt message if
sender is Anonymous! Will not send message!");
- return false; // unable to encrypt
+ return false; // unable to encrypt
+ } else {
+ // leave msg as is
+ FileAccess.copyFile(unsentMessageFile.getPath(),
uploadFile.getPath());
+ if( !uploadFile.isFile() || uploadFile.length() == 0 ) {
+ logger.severe("Error: Copy of message xml file failed, result
file not existing or empty. Please report to a dev!");
+ return false;
+ }
}
return true;
}
@@ -419,8 +436,8 @@
logger.log(Level.SEVERE, "Exception thrown in
saveMessage()", ex);
}
if (success && tmpFile.length() > 0) {
- messageFile.delete();
- tmpFile.renameTo(messageFile);
+ file.delete();
+ tmpFile.renameTo(file);
return true;
} else {
tmpFile.delete();
@@ -455,11 +472,8 @@
FcpInsert.putFile(
"CHK@",
attachment.getFile(),
- null,
uploadHtl,
- true,
new FrostUploadItem(null,
null));
- // doRedirect
} catch (Exception ex) {
result = new String[1];
result[0] = "Error";
@@ -571,7 +585,6 @@
// check each existing message in board if this is the msg we
want to send
if (encryptForRecipient == null && checkLocalMessage(testMe)) {
return -1;
-// throw new MessageAlreadyUploadedException(); // bad idea
} else {
tryIndex++;
firstEmptyIndex = -1;
@@ -642,9 +655,7 @@
result = FcpInsert.putFile(
upKey,
uploadFile,
- signMetadata,
messageUploadHtl,
- false, // doRedirect
null); // UploadItem
} catch (Throwable t) {
logger.log(Level.SEVERE, "TOFUP: Error in
run()/FcpInsert.putFile", t);
@@ -655,7 +666,6 @@
result[0] = "Error";
result[1] = "Error";
}
-
if (result[0].equals("PutSuccessful")) {
success = true;
@@ -713,10 +723,10 @@
counter++;
}
- boolean wasOk = messageFile.renameTo(sentTarget);
+ boolean wasOk = unsentMessageFile.renameTo(sentTarget);
if( !wasOk ) {
- logger.severe("Error: rename of '"+messageFile.getPath()+"'
into '"+sentTarget.getPath()+"' failed!");
- messageFile.delete(); // we must delete the file from unsent
folder to prevent another upload
+ logger.severe("Error: rename of
'"+unsentMessageFile.getPath()+"' into '"+sentTarget.getPath()+"' failed!");
+ unsentMessageFile.delete(); // we must delete the file from
unsent folder to prevent another upload
}
uploadFile.delete();
@@ -739,7 +749,7 @@
tryAgain = false;
} else if (answer == MessageUploadFailedDialog.DISCARD_VALUE) {
uploadFile.delete();
- messageFile.delete();
+ unsentMessageFile.delete();
logger.warning("TOFUP: Will NOT try to upload message
again.");
tryAgain = false;
} else { // paranoia
Modified: trunk/apps/frost-0.7/source/frost/threads/UpdateIdThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/UpdateIdThread.java
2006-02-11 21:43:18 UTC (rev 8021)
+++ trunk/apps/frost-0.7/source/frost/threads/UpdateIdThread.java
2006-02-12 13:36:40 UTC (rev 8022)
@@ -23,7 +23,6 @@
import java.util.logging.*;
import frost.*;
-import frost.crypt.*;
import frost.fcp.*;
import frost.fileTransfer.*;
import frost.gui.objects.*;
@@ -32,11 +31,6 @@
public class UpdateIdThread extends Thread // extends BoardUpdateThreadObject
implements BoardUpdateThread
{
- //private static int keyCount = 0;
- //private static int minKeyCount = 50;
- //private static int maxKeysPerFile = 5000;
-// private int maxKeys;
-
private static Logger logger =
Logger.getLogger(UpdateIdThread.class.getName());
private String date;
@@ -56,10 +50,6 @@
private IndexSlots indexSlots;
private final static int MAX_SLOTS_PER_DAY = 100;
-// public int getThreadType() {
-// return BoardUpdateThread.BOARD_FILE_DNLOAD;
-// }
-
// TODO: if we fail to upload here, the file to upload should be uploaded
next time!
/**
* Returns true if no error occured.
@@ -77,7 +67,6 @@
Map files = null;
Index index = Index.getInstance();
synchronized(index) {
- // this method checks the final zip size (<=30000) !!!
files = index.getUploadKeys(board);
}
@@ -115,19 +104,17 @@
*/
private boolean uploadFile(File zippedIndexFile) {
- // TODO: generalize this and use it in MessageUploadThread too??
-
boolean success = false;
try {
// sign file if requested
- boolean signUpload =
MainFrame.frostSettings.getBoolValue("signUploads");
- byte[] metadata = null;
- if( signUpload ) {
- byte[] zipped = FileAccess.readByteArray(zippedIndexFile);
- SignMetaData md = new SignMetaData(zipped,
identities.getMyId());
- metadata = XMLTools.getRawXMLDocument(md);
- }
+// boolean signUpload =
MainFrame.frostSettings.getBoolValue("signUploads");
+// byte[] metadata = null;
+// if( signUpload ) {
+// byte[] zipped = FileAccess.readByteArray(zippedIndexFile);
+// SignMetaData md = new SignMetaData(zipped,
identities.getMyId());
+// metadata = XMLTools.getRawXMLDocument(md);
+// }
int tries = 0;
final int maxTries = 3;
@@ -141,9 +128,7 @@
String[] result = FcpInsert.putFile(
insertKey + index + ".idx.sha3.zip", // this format is
sha3 ;)
zippedIndexFile,
- metadata,
insertHtl,
- false, // doRedirect
null); // UploadItem
if( result[0].equals("PutSuccessful") ) {
@@ -174,27 +159,6 @@
return success;
}
- // If we're getting too much files on a board, we lower
- // the maxAge of keys. That way older keys get removed
- // sooner. With the new index system it should be possible
- // to work with large numbers of keys because they are
- // no longer kept in memory, but on disk.
-// private void adjustMaxAge(int count) {/* //this is not used
-// //if (DEBUG) Core.getOut().println("FILEDN: AdjustMaxAge: old value = "
+ frame1.frame1.frostSettings.getValue("maxAge"));
-//
-// int lowerLimit = 10 * maxKeys / 100;
-// int upperLimit = 90 * maxKeys / 100;
-// int maxAge = frame1.frame1.frame1.frostSettings.getIntValue("maxAge");
-//
-// if (count < lowerLimit && maxAge < 21)
-// maxAge++;
-// if (count > upperLimit && maxAge > 1)
-// maxAge--;
-//
-// frame1.frame1.frame1.frostSettings.setValue("maxAge", maxAge);
-// //if (DEBUG) Core.getOut().println("FILEDN: AdjustMaxAge: new value = "
+ maxAge);*/
-// }
-
public void run() {
// notifyThreadStarted(this);
@@ -228,8 +192,6 @@
null,
target,
requestHtl, // we need it faster, same as for messages
- false, // doRedirect, like in uploadIndexFile()
- false, // fastDownload
true, // createTempFile
null); // DownloadItem
@@ -286,115 +248,123 @@
Identity sharerInFile =
receivedIndex.getSharer();
// verify the file if it is
signed
- if (fcpresults.getRawMetadata()
!= null) {
- SignMetaData md;
- try {
- md = new
SignMetaData(fcpresults.getRawMetadata());
- } catch (Throwable t) {
- // reading of
xml metadata failed, handle
-
logger.log(Level.SEVERE, "Could not read the XML metadata, skipping file
index.", t);
- target.delete();
- continue;
- }
+// if (fcpresults.getRawMetadata()
!= null) {
+// SignMetaData md;
+// try {
+// md = new
SignMetaData(fcpresults.getRawMetadata());
+// } catch (Throwable t) {
+// // reading of
xml metadata failed, handle
+//
logger.log(Level.SEVERE, "Could not read the XML metadata, skipping file
index.", t);
+// target.delete();
+// continue;
+// }
+//
+// //metadata says we're
signed. Check if there is identity in the file
+// if (sharerInFile ==
null) {
+//
logger.warning("MetaData present, but file didn't contain an identity :(");
+//
unzippedTarget.delete();
+// target.delete();
+// continue;
+// }
+//
+// String _owner = null;
+// String _pubkey = null;
+// if (sharerInFile != null) {
+// _owner =
Mixed.makeFilename(sharerInFile.getUniqueName());
+// _pubkey = sharerInFile.getKey();
+// }
+// //check if metadata is
proper
+// if (_owner == null ||
_owner.length() == 0 || _pubkey == null || _pubkey.length() == 0) {
+//
logger.warning("XML metadata have missing fields, skipping file index.");
+//
unzippedTarget.delete();
+// target.delete();
+// continue;
+// }
+//
+// //check if fields match
those in the index file
+// if
(!_owner.equals(Mixed.makeFilename(sharerInFile.getUniqueName()))
+// ||
!_pubkey.equals(sharerInFile.getKey())) {
+//
+//
logger.warning("The identity in MetaData didn't match the identity in File!
:(\n" +
+//
"file owner : " + sharerInFile.getUniqueName() + "\n" +
+//
"file key : " + sharerInFile.getKey() + "\n" +
+//
"meta owner: " + _owner + "\n" +
+//
"meta key : " + _pubkey);
+//
unzippedTarget.delete();
+// target.delete();
+// continue;
+// }
- //metadata says we're
signed. Check if there is identity in the file
- if (sharerInFile ==
null) {
-
logger.warning("MetaData present, but file didn't contain an identity :(");
-
unzippedTarget.delete();
- target.delete();
- continue;
- }
-
- String _owner = null;
- String _pubkey = null;
- if (md.getPerson() !=
null) {
- _owner =
Mixed.makeFilename(md.getPerson().getUniqueName());
- _pubkey =
md.getPerson().getKey();
- }
-
- //check if metadata is
proper
- if (_owner == null ||
_owner.length() == 0 || _pubkey == null || _pubkey.length() == 0) {
-
logger.warning("XML metadata have missing fields, skipping file index.");
-
unzippedTarget.delete();
- target.delete();
- continue;
- }
-
- //check if fields match
those in the index file
- if
(!_owner.equals(Mixed.makeFilename(sharerInFile.getUniqueName()))
- ||
!_pubkey.equals(sharerInFile.getKey())) {
-
-
logger.warning("The identity in MetaData didn't match the identity in File!
:(\n" +
-
"file owner : " + sharerInFile.getUniqueName() + "\n" +
-
"file key : " + sharerInFile.getKey() + "\n" +
-
"meta owner: " + _owner + "\n" +
-
"meta key : " + _pubkey);
-
unzippedTarget.delete();
- target.delete();
- continue;
- }
-
//verify! :)
- byte[] zippedXml =
FileAccess.readByteArray(target);
- boolean valid =
Core.getCrypto().detachedVerify(zippedXml, _pubkey, md.getSig());
- zippedXml = null;
+// byte[] zippedXml =
FileAccess.readByteArray(target);
+// boolean valid =
Core.getCrypto().detachedVerify(zippedXml, _pubkey, md.getSig());
+// zippedXml = null;
+//
+// if (valid == false) {
+//
logger.warning("Invalid signature for index file from " + _owner);
+//
unzippedTarget.delete();
+// target.delete();
+// continue;
+// }
- if (valid == false) {
-
logger.warning("Invalid signature for index file from " + _owner);
-
unzippedTarget.delete();
- target.delete();
- continue;
- }
-
- //check if we have the
owner already on the lists
- if
(identities.isMySelf(_owner)) {
-
logger.info("Received index file from myself");
- sharer =
identities.getMyId();
- } else {
- logger.info("Received index file from " +
_owner);
- sharer = identities.getIdentity(_owner);
-
- if( sharer == null ) {
- // a new sharer, put to neutral list
- sharer = addNewSharer(_owner, _pubkey);
- if (sharer == null) { // digest did not
match, block file
- logger.info("sharer was null... :(");
- unzippedTarget.delete();
- target.delete();
- continue;
+ String _owner = null;
+ String _pubkey = null;
+ if (sharerInFile != null) {
+ _owner =
Mixed.makeFilename(sharerInFile.getUniqueName());
+ _pubkey = sharerInFile.getKey();
+ }
+ if( _owner != null ) {
+ //check if we have the
owner already on the lists
+ if
(identities.isMySelf(_owner)) {
+
logger.info("Received index file from myself");
+ sharer =
identities.getMyId();
+ } else {
+ logger.info("Received index file from " +
_owner);
+ sharer = identities.getIdentity(_owner);
+
+ if( sharer == null ) {
+ // a new sharer, put to neutral list
+ sharer = addNewSharer(_owner, _pubkey);
+ if (sharer == null) { // digest did
not match, block file
+ logger.info("sharer was null...
:(");
+ unzippedTarget.delete();
+ target.delete();
+ continue;
+ }
+ } else if (sharer.getState() ==
FrostIdentities.ENEMY ) {
+ if
(MainFrame.frostSettings.getBoolValue("hideBadFiles")) {
+ logger.info("Skipped index file
from BAD user " + _owner);
+ target.delete();
+ unzippedTarget.delete();
+ continue;
+ }
}
- } else if (sharer.getState() ==
FrostIdentities.ENEMY ) {
- if
(MainFrame.frostSettings.getBoolValue("hideBadFiles")) {
- logger.info("Skipped index file from
BAD user " + _owner);
- target.delete();
- unzippedTarget.delete();
- continue;
- }
- }
- // update lastSeen for sharer Identity
- sharer.updateLastSeenTimestamp();
- }
- } // end-of: if metadata != null
- else if
(MainFrame.frostSettings.getBoolValue("hideAnonFiles")) {
- unzippedTarget.delete();
- target.delete();
- continue; //do not show
index.
- }
+ // update lastSeen for sharer Identity
+ sharer.updateLastSeenTimestamp();
+ }
+ }
+// } // end-of: if metadata != null
+// else if
(MainFrame.frostSettings.getBoolValue("hideAnonFiles")) {
+// unzippedTarget.delete();
+// target.delete();
+// continue; //do not show
index.
+// }
// if the user is not on the
GOOD list..
- String sharerStr;
- if (sharer == null ||
sharer.getState() != FrostIdentities.FRIEND ) {
- // add only files from
that user (not files from his friends)
- sharerStr = (sharer ==
null) ? "Anonymous" : sharer.getUniqueName();
- logger.info("adding
only files from " + sharerStr);
- } else {
- // if user is GOOD, add
all files (user could have sent files from HIS friends in this index)
- logger.info("adding all
files from " + sharer.getUniqueName());
- sharerStr = null;
- }
+// String sharerStr;
+// if (sharer == null ||
sharer.getState() != FrostIdentities.FRIEND ) {
+// // add only files from
that user (not files from his friends)
+// sharerStr = (sharer ==
null) ? "Anonymous" : sharer.getUniqueName();
+// logger.info("adding
only files from " + sharerStr);
+// } else {
+// // if user is GOOD, add
all files (user could have sent files from HIS friends in this index)
+// logger.info("adding all
files from " + sharer.getUniqueName());
+// sharerStr = null;
+// }
Index idx = Index.getInstance();
synchronized(idx) {
- idx.add(receivedIndex, board, sharerStr);
+ // add all files
+ idx.add(receivedIndex, board, null);
}
target.delete();