@Override public FreenetURI[] generateKeyPair(String docName) { InsertableClientSSK key = InsertableClientSSK.createRandom(random, docName); return new FreenetURI[] { key.getInsertURI(), key.getURI() }; }
public InsertableClientSSK getInsertableSSK(String string) { try { return new InsertableClientSSK(string, pubKeyHash, new DSAPublicKey(getCryptoGroup(), privKey), privKey, cryptoKey, cryptoAlgorithm); } catch (MalformedURLException e) { Logger.error(this, "Caught "+e+" should not be possible in USK.getSSK", e); throw new Error(e); } }
private ClientSSKBlock encodeBlockSSK(String test, RandomSource random) throws IOException, SSKEncodeException, InvalidCompressionCodecException { byte[] data = test.getBytes("UTF-8"); SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(data); InsertableClientSSK ik = InsertableClientSSK.createRandom(random, test); return ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); } }
protected static ClientKeyBlock innerEncode(RandomSource random, FreenetURI uri, Bucket sourceData, boolean isMetadata, short compressionCodec, int sourceLength, String compressorDescriptor, boolean pre1254, byte cryptoAlgorithm, byte[] cryptoKey) throws InsertException, CHKEncodeException, IOException, SSKEncodeException, MalformedURLException, InvalidCompressionCodecException { String uriType = uri.getKeyType(); if(uriType.equals("CHK")) { return ClientCHKBlock.encode(sourceData, isMetadata, compressionCodec == -1, compressionCodec, sourceLength, compressorDescriptor, pre1254, cryptoKey, cryptoAlgorithm); } else if(uriType.equals("SSK") || uriType.equals("KSK")) { InsertableClientSSK ik = InsertableClientSSK.create(uri); return ik.encode(sourceData, isMetadata, compressionCodec == -1, compressionCodec, sourceLength, random, compressorDescriptor, pre1254); } else { throw new InsertException(InsertExceptionMode.INVALID_URI, "Unknown keytype "+uriType, null); } }
static FreenetURI checkEmptySSK(FreenetURI uri, String filename, ClientContext context) { if("SSK".equals(uri.getKeyType()) && uri.getDocName() == null && uri.getRoutingKey() == null) { if(filename == null || filename.equals("")) filename = "key"; // SSK@ = use a random SSK. InsertableClientSSK key = InsertableClientSSK.createRandom(context.random, ""); return key.getInsertURI().setDocName(filename); } else { return uri; } }
@Test public void registeringAnActiveUskWillSubscribeToItCorrectly() { FreenetURI freenetUri = createRandom(randomSource, "test-0").getURI().uskForSSK(); final USKCallback uskCallback = mock(USKCallback.class); freenetInterface.registerActiveUsk(freenetUri, uskCallback); verify(uskManager).subscribe(any(USK.class), eq(uskCallback), eq(true), any(RequestClient.class)); }
byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256); ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock = (SSKBlock) block.getBlock(); pubkeyCache.cacheKey(sskBlock.getKey().getPubKeyHash(), sskBlock.getPubKey(), false, false, false, false, false); block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock2 = (SSKBlock) block.getBlock(); try {
/** Return the URL's to insert hint data to */ public FreenetURI[] getInsertURIs(InsertableUSK key) { FreenetURI[] uris = new FreenetURI[Type.values.length]; int x = 0; for(Type t : Type.values) uris[x++] = key.getInsertableSSK(key.siteName+PREFIX+get(t)).getInsertURI(); return uris; }
if(privARK != null) { FreenetURI uri = new FreenetURI(privARK); ark = InsertableClientSSK.create(uri); if(s == null) { ark = null; ark = InsertableClientSSK.createRandom(random, "ark"); myARKNumber = 0;
/** * Create the cryptographic keys etc from scratch */ public void initCrypto() { ecdsaP256 = new ECDSA(ECDSA.Curves.P256); ecdsaPubKeyHash = SHA256.digest(ecdsaP256.getPublicKey().getEncoded()); myARK = InsertableClientSSK.createRandom(random, "ark"); myARKNumber = 0; clientNonce = new byte[32]; node.random.nextBytes(clientNonce); myIdentity = new byte[IDENTITY_LENGTH]; node.random.nextBytes(myIdentity); identityHash = SHA256.digest(myIdentity); identityHashHash = SHA256.digest(identityHash); anonSetupCipher.initialize(identityHash); }
SimpleFieldSet exportPublicCryptoFieldSet(boolean forSetup, boolean forAnonInitiator) { SimpleFieldSet fs = new SimpleFieldSet(true); int[] negTypes = packetMangler.supportedNegTypes(true); if(!forSetup) { // These are invariant. They cannot change on connection setup. They can safely be excluded. fs.put("ecdsa", ecdsaP256.asFieldSet(false)); fs.putSingle("identity", Base64.encode(myIdentity)); } if(!forAnonInitiator) { // Short-lived connections don't need ARK and don't need negTypes either. fs.put("auth.negTypes", negTypes); if(!forSetup) { fs.put("ark.number", myARKNumber); // Can be changed on setup fs.putSingle("ark.pubURI", myARK.getURI().toString(false, false)); // Can be changed on setup } } return fs; }
private byte[] getInsertExtraBytes() { byte[] extra = getExtraBytes(); extra[1] = 1; // insert return extra; }
public static InsertableUSK createInsertable(FreenetURI uri, boolean persistent) throws MalformedURLException { if(!uri.getKeyType().equalsIgnoreCase("USK")) throw new MalformedURLException(); InsertableClientSSK ssk = InsertableClientSSK.create(uri.setKeyType("SSK")); return new InsertableUSK(ssk.docName, ssk.pubKeyHash, ssk.cryptoKey, ssk.privKey, uri.getSuggestedEdition(), ssk.cryptoAlgorithm); }
@Test public void registeringAnInactiveUskWillSubscribeToItCorrectly() { FreenetURI freenetUri = createRandom(randomSource, "test-0").getURI().uskForSSK(); final USKCallback uskCallback = mock(USKCallback.class); freenetInterface.registerPassiveUsk(freenetUri, uskCallback); verify(uskManager).subscribe(any(USK.class), eq(uskCallback), eq(false), any(RequestClient.class)); }
protected InsertBlock generateBlock(DummyRandomSource random) throws MalformedURLException { byte[] data = new byte[FILE_SIZE]; random.nextBytes(data); RandomAccessBucket bucket = new SimpleReadOnlyArrayBucket(data); FreenetURI uri = InsertableClientSSK.createRandom(random, "test").getInsertURI(); return new InsertBlock(bucket, new ClientMetadata(null), uri); }
byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256); ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock = (SSKBlock) block.getBlock(); store.put(sskBlock, false, false); ClientSSKBlock block1 = ik.encode(bucket1, false, false, (short)-1, bucket1.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false); SSKBlock sskBlock1 = (SSKBlock) block1.getBlock();
void addPrivateFields(SimpleFieldSet fs) { // Let's not add it twice fs.removeSubset("ecdsa"); fs.put("ecdsa", ecdsaP256.asFieldSet(true)); fs.putSingle("ark.privURI", myARK.getInsertURI().toString(false, false)); fs.putSingle("clientNonce", Base64.encode(clientNonce)); }
testKey = new FreenetURI("KSK", dataString); insertKey = InsertableClientSSK.create(testKey); fetchKey = ClientKSK.create(testKey); block = ((InsertableClientSSK)insertKey).encode(new ArrayBucket(buf), false, false, (short)-1, buf.length, random, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false); } else { block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
public InsertableClientSSK(String docName, byte[] pubKeyHash, DSAPublicKey pubKey, DSAPrivateKey privKey, byte[] cryptoKey, byte cryptoAlgorithm) throws MalformedURLException { super(docName, pubKeyHash, getExtraBytes(cryptoAlgorithm), pubKey, cryptoKey); if(pubKey == null) throw new NullPointerException(); this.privKey = privKey; }