@Override public boolean equals(Object o) { if(!(o instanceof SSKBlock)) return false; SSKBlock block = (SSKBlock)o; if(!block.pubKey.equals(pubKey)) return false; if(!block.nodeKey.equals(nodeKey)) return false; if(block.headersOffset != headersOffset) return false; if(block.hashIdentifier != hashIdentifier) return false; if(block.symCipherIdentifier != symCipherIdentifier) return false; // only compare some of the headers (see top) for (int i = 0; i < HEADER_COMPARE_TO; i++) { if (block.headers[i] != headers[i]) return false; } //if(!Arrays.equals(block.headers, headers)) return false; if(!Arrays.equals(block.data, data)) return false; return true; }
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; }
public void setPubKey(DSAPublicKey pubKey2) throws SSKVerifyException { if(pubKey == pubKey2) return; if(pubKey2 == null) return; if((pubKey == null) || !pubKey2.equals(pubKey)) { if(pubKey2 != null) { byte[] newPubKeyHash = SHA256.digest(pubKey2.asBytes()); if(Arrays.equals(pubKeyHash, newPubKeyHash)) { if(pubKey != null) { // same hash, yet different keys! Logger.error(this, "Found SHA-256 collision or something... WTF?"); throw new SSKVerifyException("Invalid new pubkey: "+pubKey2+" old pubkey: "+pubKey); } // Valid key, assign. } else { throw new SSKVerifyException("New pubkey has invalid hash"); } } pubKey = pubKey2; } }
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); }
synchronized (cachedPubKeys) { DSAPublicKey key2 = cachedPubKeys.get(w); if ((key2 != null) && !key2.equals(key)) throw new IllegalArgumentException("Wrong hash?? Already have different key with same hash!"); cachedPubKeys.push(w, key);