Author: toad
Date: 2006-01-14 21:33:25 +0000 (Sat, 14 Jan 2006)
New Revision: 7859
Added:
trunk/freenet/src/freenet/keys/ClientKSK.java
Modified:
trunk/freenet/src/freenet/client/FileInserter.java
trunk/freenet/src/freenet/keys/ClientKey.java
trunk/freenet/src/freenet/keys/ClientSSK.java
trunk/freenet/src/freenet/keys/InsertableClientSSK.java
trunk/freenet/src/freenet/keys/Key.java
trunk/freenet/src/freenet/node/TextModeClientInterface.java
trunk/freenet/src/freenet/node/Version.java
Log:
355:
Working KSKs.
Modified: trunk/freenet/src/freenet/client/FileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/FileInserter.java 2006-01-14 20:51:07 UTC
(rev 7858)
+++ trunk/freenet/src/freenet/client/FileInserter.java 2006-01-14 21:33:25 UTC
(rev 7859)
@@ -46,10 +46,11 @@
public FreenetURI run(InsertBlock block, boolean metadata, boolean
getCHKOnly, boolean noRetries, Bucket returnMetadata) throws InserterException {
if(block.data == null)
throw new NullPointerException();
- if(block.desiredURI.getKeyType().equalsIgnoreCase("CHK")) {
+ String type = block.desiredURI.getKeyType();
+ if(type.equalsIgnoreCase("CHK")) {
if(!block.desiredURI.toString(false).equalsIgnoreCase("CHK@"))
throw new
InserterException(InserterException.INVALID_URI, null);
- } else
if(!block.desiredURI.getKeyType().equalsIgnoreCase("SSK")) {
+ } else if(!(type.equalsIgnoreCase("SSK") ||
type.equalsIgnoreCase("KSK"))) {
throw new
InserterException(InserterException.INVALID_URI, null);
}
@@ -67,7 +68,7 @@
boolean dontCompress = false;
long origSize = data.size();
- if(block.desiredURI.getKeyType().equals("SSK")) {
+ if(type.equals("SSK") || type.equals("KSK")) {
blockSize = SSKBlock.DATA_LENGTH;
isSSK = true;
maxSourceDataSize =
ClientSSKBlock.MAX_DECOMPRESSED_DATA_LENGTH;
Added: trunk/freenet/src/freenet/keys/ClientKSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientKSK.java 2006-01-14 20:51:07 UTC
(rev 7858)
+++ trunk/freenet/src/freenet/keys/ClientKSK.java 2006-01-14 21:33:25 UTC
(rev 7859)
@@ -0,0 +1,52 @@
+package freenet.keys;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import org.spaceroots.mantissa.random.MersenneTwister;
+
+import freenet.crypt.DSAPrivateKey;
+import freenet.crypt.DSAPublicKey;
+import freenet.crypt.Global;
+
+public class ClientKSK extends InsertableClientSSK {
+
+ final String keyword;
+
+ public ClientKSK(String keyword, byte[] pubKeyHash, DSAPublicKey
pubKey, DSAPrivateKey privKey, byte[] keywordHash) {
+ super(keyword, pubKeyHash, pubKey, privKey, keywordHash);
+ this.keyword = keyword;
+ }
+
+ public FreenetURI getURI() {
+ return new FreenetURI("KSK", keyword);
+ }
+
+ public static InsertableClientSSK create(FreenetURI uri) {
+ if(!uri.getKeyType().equals("KSK"))
+ throw new IllegalArgumentException();
+ return create(uri.getDocName());
+ }
+
+ public static ClientKSK create(String keyword) {
+ MessageDigest md256;
+ try {
+ md256 = MessageDigest.getInstance("SHA-256");
+ } catch (NoSuchAlgorithmException e) {
+ throw new Error(e);
+ }
+ byte[] keywordHash;
+ try {
+ keywordHash = md256.digest(keyword.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new Error(e);
+ }
+ MersenneTwister mt = new MersenneTwister(keywordHash);
+ DSAPrivateKey privKey = new DSAPrivateKey(Global.DSAgroupBigA,
mt);
+ DSAPublicKey pubKey = new DSAPublicKey(Global.DSAgroupBigA,
privKey);
+ byte[] pubKeyHash = md256.digest(pubKey.asBytes());
+ return new ClientKSK(keyword, pubKeyHash, pubKey, privKey,
keywordHash);
+ }
+
+}
Modified: trunk/freenet/src/freenet/keys/ClientKey.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientKey.java 2006-01-14 20:51:07 UTC
(rev 7858)
+++ trunk/freenet/src/freenet/keys/ClientKey.java 2006-01-14 21:33:25 UTC
(rev 7859)
@@ -13,6 +13,8 @@
return new ClientCHK(origURI);
if(origURI.getKeyType().equals("SSK"))
return new ClientSSK(origURI);
+ if(origURI.getKeyType().equals("KSK"))
+ return ClientKSK.create(origURI.getDocName());
throw new UnsupportedOperationException("Unknown keytype from
"+origURI);
}
Modified: trunk/freenet/src/freenet/keys/ClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientSSK.java 2006-01-14 20:51:07 UTC
(rev 7858)
+++ trunk/freenet/src/freenet/keys/ClientSSK.java 2006-01-14 21:33:25 UTC
(rev 7859)
@@ -66,7 +66,7 @@
}
public void setPublicKey(DSAPublicKey pubKey) {
- if(this.pubKey != null && this.pubKey != pubKey)
+ if(this.pubKey != null && this.pubKey != pubKey &&
!this.pubKey.equals(pubKey))
throw new IllegalArgumentException("Cannot reassign:
was "+this.pubKey+" now "+pubKey);
this.pubKey = pubKey;
}
Modified: trunk/freenet/src/freenet/keys/InsertableClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/InsertableClientSSK.java 2006-01-14
20:51:07 UTC (rev 7858)
+++ trunk/freenet/src/freenet/keys/InsertableClientSSK.java 2006-01-14
21:33:25 UTC (rev 7859)
@@ -33,6 +33,8 @@
}
public static InsertableClientSSK create(FreenetURI uri) throws
MalformedURLException {
+ if(uri.getKeyType().equalsIgnoreCase("KSK"))
+ return ClientKSK.create(uri);
if(!uri.getKeyType().equalsIgnoreCase("SSK"))
throw new MalformedURLException();
DSAGroup g = Global.DSAgroupBigA;
Modified: trunk/freenet/src/freenet/keys/Key.java
===================================================================
--- trunk/freenet/src/freenet/keys/Key.java 2006-01-14 20:51:07 UTC (rev
7858)
+++ trunk/freenet/src/freenet/keys/Key.java 2006-01-14 21:33:25 UTC (rev
7859)
@@ -57,6 +57,7 @@
return NodeCHK.readCHK(raf);
} else if(type == NodeSSK.TYPE)
return NodeSSK.readSSK(raf);
+
throw new IOException("Unrecognized format: "+type);
}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-01-14
20:51:07 UTC (rev 7858)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-01-14
21:33:25 UTC (rev 7859)
@@ -2,7 +2,6 @@
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
@@ -20,7 +19,6 @@
import freenet.client.FetchException;
import freenet.client.FetchResult;
import freenet.client.HighLevelSimpleClient;
-import freenet.client.HighLevelSimpleClientImpl;
import freenet.client.InsertBlock;
import freenet.client.InserterException;
import freenet.client.Metadata;
@@ -417,6 +415,7 @@
System.out.println("Successfully inserted to
fetch URI: "+key.getURI());
} catch (InserterException e) {
System.out.println("Finished insert but: "+e.getMessage());
+ Logger.normal(this, "Error: "+e, e);
if(e.uri != null) {
System.out.println("URI would have been: "+e.uri);
}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-01-14 20:51:07 UTC (rev
7858)
+++ trunk/freenet/src/freenet/node/Version.java 2006-01-14 21:33:25 UTC (rev
7859)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 354;
+ public static final int buildNumber = 355;
/** Oldest build of Fred we will talk to */
public static final int lastGoodBuild = 348;