@Override public Key cloneKey() { return new NodeSSK(this); }
public static Key readSSK(DataInput raf, byte cryptoAlgorithm) throws IOException { byte[] buf = new byte[E_H_DOCNAME_SIZE]; raf.readFully(buf); byte[] buf2 = new byte[PUBKEY_HASH_SIZE]; raf.readFully(buf2); try { return new NodeSSK(buf2, buf, null, cryptoAlgorithm); } catch (SSKVerifyException e) { throw (AssertionError)new AssertionError("Impossible").initCause(e); } }
public static NodeSSK construct(byte[] buf) throws SSKVerifyException { if(buf[0] != 2) throw new SSKVerifyException("Unknown type byte "+buf[0]); byte cryptoAlgorithm = buf[1]; if(cryptoAlgorithm != Key.ALGO_AES_PCFB_256_SHA256) throw new SSKVerifyException("Unknown crypto algorithm "+buf[1]); byte[] encryptedHashedDocname = Arrays.copyOfRange(buf, 2, 2+E_H_DOCNAME_SIZE); byte[] pubkeyHash = Arrays.copyOfRange(buf, 2+E_H_DOCNAME_SIZE, 2+E_H_DOCNAME_SIZE+PUBKEY_HASH_SIZE); return new NodeSSK(pubkeyHash, encryptedHashedDocname, null, cryptoAlgorithm); }
@Override public Key getNodeKey(boolean cloneKey) { try { Key nodeKey; synchronized(this) { if(ehDocname == null) throw new NullPointerException(); if(pubKeyHash == null) throw new NullPointerException(); if (cachedNodeKey == null || cachedNodeKey.getKeyBytes() == null || cachedNodeKey.getRoutingKey() == null) cachedNodeKey = new NodeSSK(pubKeyHash, ehDocname, pubKey, cryptoAlgorithm); nodeKey = cachedNodeKey; } return cloneKey ? nodeKey.cloneKey() : nodeKey; } catch (SSKVerifyException e) { Logger.error(this, "Have already verified and yet it fails!: "+e); throw (AssertionError)new AssertionError("Have already verified and yet it fails!").initCause(e); } }
/** * Check for WATCH_KEYS from lastSlot, but do not check any slots earlier than checkedDatastoreUpTo. * Re-use the cache if possible, and extend it if necessary; all we need to construct a NodeSSK is the base data and the E(H(docname)), and we have that. */ public synchronized StoreSubChecker checkStore(long lastSlot) { if(logDEBUG) Logger.minor(this, "check store from "+lastSlot+" current first slot "+firstSlot); long checkFrom = lastSlot; long checkTo = lastSlot + WATCH_KEYS; if(checkedDatastoreTo >= checkFrom) { checkFrom = checkedDatastoreTo; } if(checkFrom >= checkTo) return null; // Nothing to check. // Update the cache. RemoveRangeArrayList<byte[]> ehDocnames = updateCache(lastSlot); // Now create NodeSSK[] from the part of the cache that // ehDocnames[0] is firstSlot // ehDocnames[checkFrom-firstSlot] is checkFrom int offset = (int)(checkFrom - firstSlot); NodeSSK[] keysToCheck = new NodeSSK[WATCH_KEYS - offset]; for(int x=0, i=offset; i<WATCH_KEYS; i++, x++) { keysToCheck[x] = new NodeSSK(pubKeyHash, ehDocnames.get(i), cryptoAlgorithm); } return new StoreSubChecker(keysToCheck, checkFrom, checkTo); }
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)); } }