Author: toad
Date: 2006-01-14 22:07:51 +0000 (Sat, 14 Jan 2006)
New Revision: 7860
Modified:
trunk/freenet/src/freenet/keys/ClientCHK.java
trunk/freenet/src/freenet/keys/ClientCHKBlock.java
trunk/freenet/src/freenet/keys/ClientKSK.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/keys/NodeSSK.java
trunk/freenet/src/freenet/node/Version.java
Log:
356:
Sorry, folks. Incompatible SSK change.
URLs are now
freenet:SSK at
8O9-HLDWY0wMyyy-y5Mg3RYX1aOZX~kryl-EA-fJH1U,fty04AnCd88dO9DbCAhRcc-5hXczyYFv83N2~K2qwOg,AQABAAE/test
instead of
freenet:SSK at
8O9-HLDWY0wMyyy-y5Mg3RYX1aOZX~kryl-EA-fJH1U,fty04AnCd88dO9DbCAhRcc-5hXczyYFv83N2~K2qwOg/test
I am not sure why old links don't work when doctored as the above...
Modified: trunk/freenet/src/freenet/keys/ClientCHK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHK.java 2006-01-14 21:33:25 UTC
(rev 7859)
+++ trunk/freenet/src/freenet/keys/ClientCHK.java 2006-01-14 22:07:51 UTC
(rev 7860)
@@ -66,7 +66,7 @@
if(extra == null || extra.length < 5)
throw new MalformedURLException();
cryptoAlgorithm = (short)(((extra[0] & 0xff) << 8) + (extra[1] &
0xff));
- if(cryptoAlgorithm != Key.ALGO_AES_PCFB_256)
+ if(cryptoAlgorithm != Key.ALGO_AES_PCFB_256_SHA256)
throw new MalformedURLException("Invalid crypto
algorithm");
controlDocument = (extra[2] & 0x02) != 0;
compressionAlgorithm = (short)(((extra[3] & 0xff) << 8) + (extra[4] &
0xff));
@@ -81,7 +81,7 @@
byte[] extra = new byte[EXTRA_LENGTH];
dis.readFully(extra);
cryptoAlgorithm = (short)(((extra[0] & 0xff) << 8) + (extra[1] &
0xff));
- if(cryptoAlgorithm != Key.ALGO_AES_PCFB_256)
+ if(cryptoAlgorithm != Key.ALGO_AES_PCFB_256_SHA256)
throw new MalformedURLException("Invalid crypto
algorithm");
compressionAlgorithm = (short)(((extra[3] & 0xff) << 8) + (extra[4] &
0xff));
controlDocument = (extra[2] & 0x02) != 0;
Modified: trunk/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHKBlock.java 2006-01-14 21:33:25 UTC
(rev 7859)
+++ trunk/freenet/src/freenet/keys/ClientCHKBlock.java 2006-01-14 22:07:51 UTC
(rev 7860)
@@ -85,7 +85,7 @@
*/
public Bucket decode(BucketFactory bf, int maxLength) throws
CHKDecodeException, IOException {
// Overall hash already verified, so first job is to decrypt.
- if(key.cryptoAlgorithm != Key.ALGO_AES_PCFB_256)
+ if(key.cryptoAlgorithm != Key.ALGO_AES_PCFB_256_SHA256)
throw new UnsupportedOperationException();
BlockCipher cipher;
try {
@@ -215,7 +215,7 @@
byte[] finalHash = md256.digest(data);
// Now convert it into a ClientCHK
- key = new ClientCHK(finalHash, encKey, asMetadata,
Key.ALGO_AES_PCFB_256, compressionAlgorithm);
+ key = new ClientCHK(finalHash, encKey, asMetadata,
Key.ALGO_AES_PCFB_256_SHA256, compressionAlgorithm);
try {
return new ClientCHKBlock(data, header, key, false);
Modified: trunk/freenet/src/freenet/keys/ClientKSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientKSK.java 2006-01-14 21:33:25 UTC
(rev 7859)
+++ trunk/freenet/src/freenet/keys/ClientKSK.java 2006-01-14 22:07:51 UTC
(rev 7860)
@@ -1,6 +1,7 @@
package freenet.keys;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -14,7 +15,7 @@
final String keyword;
- public ClientKSK(String keyword, byte[] pubKeyHash, DSAPublicKey
pubKey, DSAPrivateKey privKey, byte[] keywordHash) {
+ private ClientKSK(String keyword, byte[] pubKeyHash, DSAPublicKey
pubKey, DSAPrivateKey privKey, byte[] keywordHash) throws MalformedURLException
{
super(keyword, pubKeyHash, pubKey, privKey, keywordHash);
this.keyword = keyword;
}
@@ -46,7 +47,11 @@
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);
+ try {
+ return new ClientKSK(keyword, pubKeyHash, pubKey,
privKey, keywordHash);
+ } catch (MalformedURLException e) {
+ throw new Error(e);
+ }
}
}
Modified: trunk/freenet/src/freenet/keys/ClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientSSK.java 2006-01-14 21:33:25 UTC
(rev 7859)
+++ trunk/freenet/src/freenet/keys/ClientSSK.java 2006-01-14 22:07:51 UTC
(rev 7860)
@@ -25,10 +25,16 @@
static final int CRYPTO_KEY_LENGTH = 32;
- public ClientSSK(String docName, byte[] pubKeyHash, DSAPublicKey
pubKey, byte[] cryptoKey) {
+ public ClientSSK(String docName, byte[] pubKeyHash, byte[] extras,
DSAPublicKey pubKey, byte[] cryptoKey) throws MalformedURLException {
this.docName = docName;
this.pubKey = pubKey;
this.pubKeyHash = pubKeyHash;
+ if(!Arrays.equals(extras, getExtraBytes()))
+ throw new MalformedURLException("Wrong extra bytes");
+ if(pubKeyHash.length != NodeSSK.PUBKEY_HASH_SIZE)
+ throw new MalformedURLException("Pubkey hash wrong
length: "+pubKeyHash.length+" should be "+NodeSSK.PUBKEY_HASH_SIZE);
+ if(cryptoKey.length != CRYPTO_KEY_LENGTH)
+ throw new MalformedURLException("Decryption key wrong
length: "+cryptoKey.length+" should be "+CRYPTO_KEY_LENGTH);
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
@@ -60,7 +66,7 @@
}
public ClientSSK(FreenetURI origURI) throws MalformedURLException {
- this(origURI.getDocName(), origURI.getRoutingKey(), null,
origURI.getCryptoKey());
+ this(origURI.getDocName(), origURI.getRoutingKey(),
origURI.getExtra(), null, origURI.getCryptoKey());
if(!origURI.getKeyType().equalsIgnoreCase("SSK"))
throw new MalformedURLException();
}
@@ -72,9 +78,23 @@
}
public FreenetURI getURI() {
- return new FreenetURI("SSK", docName, pubKeyHash, cryptoKey,
null);
+ return new FreenetURI("SSK", docName, pubKeyHash, cryptoKey,
getExtraBytes());
}
+
+ protected static final byte[] getExtraBytes() {
+ // 3 bytes.
+ byte[] extra = new byte[5];
+ short cryptoAlgorithm = NodeSSK.ALGO_AES_PCFB_256_SHA256;
+
+ extra[0] = NodeSSK.SSK_VERSION;
+ extra[1] = (byte) (cryptoAlgorithm >> 8);
+ extra[2] = (byte) cryptoAlgorithm;
+ extra[3] = (byte) (KeyBlock.HASH_SHA256 >> 8);
+ extra[4] = (byte) KeyBlock.HASH_SHA256;
+ return extra;
+ }
+
public Key getNodeKey() {
return new NodeSSK(pubKeyHash, ehDocname, pubKey);
}
Modified: trunk/freenet/src/freenet/keys/InsertableClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/InsertableClientSSK.java 2006-01-14
21:33:25 UTC (rev 7859)
+++ trunk/freenet/src/freenet/keys/InsertableClientSSK.java 2006-01-14
22:07:51 UTC (rev 7860)
@@ -26,8 +26,8 @@
public final DSAPrivateKey privKey;
- public InsertableClientSSK(String docName, byte[] pubKeyHash,
DSAPublicKey pubKey, DSAPrivateKey privKey, byte[] cryptoKey) {
- super(docName, pubKeyHash, pubKey, cryptoKey);
+ public InsertableClientSSK(String docName, byte[] pubKeyHash,
DSAPublicKey pubKey, DSAPrivateKey privKey, byte[] cryptoKey) throws
MalformedURLException {
+ super(docName, pubKeyHash, getExtraBytes(), pubKey, cryptoKey);
if(pubKey == null) throw new NullPointerException();
this.privKey = privKey;
}
@@ -113,8 +113,8 @@
headers[x++] = (byte) (ClientSSKBlock.HASH_SHA256 >> 8);
headers[x++] = (byte) (ClientSSKBlock.HASH_SHA256);
// Then crypto ID
- headers[x++] = (byte) (Key.ALGO_AES_PCFB_256 >> 8);
- headers[x++] = (byte) (Key.ALGO_AES_PCFB_256);
+ headers[x++] = (byte) (Key.ALGO_AES_PCFB_256_SHA256 >> 8);
+ headers[x++] = (byte) (Key.ALGO_AES_PCFB_256_SHA256);
// Then E(H(docname))
// Copy to headers
System.arraycopy(ehDocname, 0, headers, x, ehDocname.length);
@@ -193,7 +193,11 @@
} catch (NoSuchAlgorithmException e) {
throw new Error(e);
}
- return new InsertableClientSSK("", md.digest(pubKey.asBytes()),
pubKey, privKey, ckey);
+ try {
+ return new InsertableClientSSK("",
md.digest(pubKey.asBytes()), pubKey, privKey, ckey);
+ } catch (MalformedURLException e) {
+ throw new Error(e);
+ }
}
public FreenetURI getInsertURI() {
Modified: trunk/freenet/src/freenet/keys/Key.java
===================================================================
--- trunk/freenet/src/freenet/keys/Key.java 2006-01-14 21:33:25 UTC (rev
7859)
+++ trunk/freenet/src/freenet/keys/Key.java 2006-01-14 22:07:51 UTC (rev
7860)
@@ -30,8 +30,8 @@
/** Whatever its type, it will need a routingKey ! */
final byte[] routingKey;
- /** Code for 256-bit AES with PCFB */
- static final short ALGO_AES_PCFB_256 = 1;
+ /** Code for 256-bit AES with PCFB and SHA-256 */
+ static final short ALGO_AES_PCFB_256_SHA256 = 1;
protected Key(byte[] routingKey) {
this.routingKey = routingKey;
Modified: trunk/freenet/src/freenet/keys/NodeSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/NodeSSK.java 2006-01-14 21:33:25 UTC (rev
7859)
+++ trunk/freenet/src/freenet/keys/NodeSSK.java 2006-01-14 22:07:51 UTC (rev
7860)
@@ -28,6 +28,8 @@
/** The signature key, if we know it */
DSAPublicKey pubKey;
+ static final int SSK_VERSION = 1;
+
static final int PUBKEY_HASH_SIZE = 32;
static final int E_H_DOCNAME_SIZE = 32;
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-01-14 21:33:25 UTC (rev
7859)
+++ trunk/freenet/src/freenet/node/Version.java 2006-01-14 22:07:51 UTC (rev
7860)
@@ -20,10 +20,10 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 355;
+ public static final int buildNumber = 356;
/** Oldest build of Fred we will talk to */
- public static final int lastGoodBuild = 348;
+ public static final int lastGoodBuild = 356;
/** The highest reported build of fred */
public static int highestSeenBuild = buildNumber;