@Override public byte[] getFullKey() { return asBytesHash(); }
@Override public byte[] getRoutingKey() { return asBytesHash(); }
public synchronized void setPublicKey(DSAPublicKey pubKey) { if((this.pubKey != null) && (this.pubKey != pubKey) && !this.pubKey.equals(pubKey)) throw new IllegalArgumentException("Cannot reassign: was "+this.pubKey+" now "+pubKey); byte[] newKeyHash = pubKey.asBytesHash(); if(!Arrays.equals(newKeyHash, pubKeyHash)) throw new IllegalArgumentException("New pubKey hash does not match pubKeyHash: "+HexUtil.bytesToHex(newKeyHash)+" ( "+HexUtil.bytesToHex(pubKey.asBytesHash())+" != "+HexUtil.bytesToHex(pubKeyHash)+" for "+pubKey); this.pubKey = pubKey; this.cachedNodeKey = null; }
byte[] pkHash = pubKey.asBytesHash(); return new InsertableClientSSK(uri.getDocName(), pkHash, pubKey, privKey, uri.getCryptoKey(), keyType);
public static KeyBlock createBlock(short keyType, byte[] keyBytes, byte[] headersBytes, byte[] dataBytes, byte[] pubkeyBytes) throws KeyVerifyException { byte type = (byte)(keyType >> 8); byte subtype = (byte)(keyType & 0xFF); if(type == NodeCHK.BASE_TYPE) { // For CHKs, the subtype is the crypto algorithm. return CHKBlock.construct(dataBytes, headersBytes, subtype); } else if(type == NodeSSK.BASE_TYPE) { DSAPublicKey pubKey; try { pubKey = new DSAPublicKey(pubkeyBytes); } catch (IOException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } catch (CryptFormatException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } NodeSSK key = new NodeSSK(pubKey.asBytesHash(), keyBytes, pubKey, subtype); return new SSKBlock(dataBytes, headersBytes, key, false); } else { throw new KeyVerifyException("No such key type "+Integer.toHexString(type)); } }
public void testSimple() throws IOException { final int keys = 10; PubkeyStore pk = new PubkeyStore(); new RAMFreenetStore<DSAPublicKey>(pk, keys); DSAGroup group = Global.DSAgroupBigA; Random random = new MersenneTwister(1010101); HashMap<ByteArrayWrapper, DSAPublicKey> map = new HashMap<ByteArrayWrapper, DSAPublicKey>(); for(int i=0;i<keys;i++) { DSAPrivateKey privKey = new DSAPrivateKey(group, random); DSAPublicKey key = new DSAPublicKey(group, privKey); byte[] hash = key.asBytesHash(); ByteArrayWrapper w = new ByteArrayWrapper(hash); map.put(w, key.cloneKey()); pk.put(hash, key, false); assertTrue(pk.fetch(hash, false, false, null).equals(key)); } int x = 0; for(Map.Entry<ByteArrayWrapper, DSAPublicKey> entry : map.entrySet()) { x++; assertTrue(pk.fetch(entry.getKey().get(), false, false, null).equals(entry.getValue())); } assert(x == keys); }
public void testSimple() { final int keys = 10; PubkeyStore pk = new PubkeyStore(); new RAMFreenetStore<DSAPublicKey>(pk, keys); GetPubkey pubkeys = new SimpleGetPubkey(pk); DSAGroup group = Global.DSAgroupBigA; Random random = new MersenneTwister(1010101); HashMap<ByteArrayWrapper, DSAPublicKey> map = new HashMap<ByteArrayWrapper, DSAPublicKey>(); for(int i=0;i<keys;i++) { DSAPrivateKey privKey = new DSAPrivateKey(group, random); DSAPublicKey key = new DSAPublicKey(group, privKey); byte[] hash = key.asBytesHash(); ByteArrayWrapper w = new ByteArrayWrapper(hash); map.put(w, key.cloneKey()); pubkeys.cacheKey(hash, key, false, false, false, false, false); assertTrue(pubkeys.getKey(hash, false, false, null).equals(key)); } int x = 0; for(Map.Entry<ByteArrayWrapper, DSAPublicKey> entry : map.entrySet()) { x++; assertTrue(pubkeys.getKey(entry.getKey().get(), false, false, null).equals(entry.getValue())); } assert(x == keys); }