public static ClientSSKBlock construct(SSKBlock block, ClientSSK key) throws SSKVerifyException { // Constructor expects clientkey to have the pubkey. // In the case of binary blobs, the block may have it instead. if(key.getPubKey() == null) key.setPublicKey(block.getPubKey()); return new ClientSSKBlock(block.data, block.headers, key, false); }
public static ClientKeyBlock createKeyBlock(ClientKey key, KeyBlock block) throws KeyVerifyException { if(key instanceof ClientSSK) return ClientSSKBlock.construct((SSKBlock)block, (ClientSSK)key); else //if(key instanceof ClientCHK return new ClientCHKBlock((CHKBlock)block, (ClientCHK)key); }
private ClientCHKBlock encodeBlock(ClientCHK key, byte[] data) { try { return ClientCHKBlock.encodeSplitfileBlock(data, key.getCryptoKey(), key.getCryptoAlgorithm()); } catch (CHKEncodeException e) { return null; } }
public static BaseClientKey getBaseKey(FreenetURI origURI) throws MalformedURLException { String keyType = origURI.getKeyType(); if("CHK".equals(keyType)) return new ClientCHK(origURI); if("SSK".equals(keyType)) return new ClientSSK(origURI); if("KSK".equals(keyType)) return ClientKSK.create(origURI.getDocName()); if("USK".equals(keyType)) return USK.create(origURI); throw new MalformedURLException("Unknown keytype from "+origURI); }
public ClientSSKBlock decode(SSKBlock block, long edition) throws SSKVerifyException { ClientSSK csk = origUSK.getSSK(edition); assert(Arrays.equals(csk.ehDocname, block.getKey().getKeyBytes())); return ClientSSKBlock.construct(block, csk); }
@Override public FreenetURI getURI() { return new FreenetURI(pubKeyHash, cryptoKey, ClientSSK.getExtraBytes(cryptoAlgorithm), siteName, suggestedEdition); }
/** * @return URI form of this key. */ @Override public FreenetURI getURI() { byte[] extra = getExtra(); return new FreenetURI("CHK", null, routingKey, cryptoKey, extra); }
@Override public CHKBlock construct(byte[] data, byte[] headers, byte[] routingKey, byte[] fullKey, boolean canReadClientCache, boolean canReadSlashdotCache, BlockMetadata meta, DSAPublicKey ignored) throws KeyVerifyException { if(data == null || headers == null) throw new CHKVerifyException("Need either data and headers"); return CHKBlock.construct(data, headers, NodeCHK.cryptoAlgorithmFromFullKey(fullKey)); }
@Override public byte[] getRoutingKey() { return getKey().getRoutingKey(); }
/** * Construct from data retrieved, and a key. * Do not do full decode. Verify what can be verified without doing * a full decode. * @param key2 The client key. * @param header The header. * @param data The data. */ public ClientCHKBlock(byte[] data, byte[] header, ClientCHK key2, boolean verify) throws CHKVerifyException { block = new CHKBlock(data, header, key2.getNodeCHK(), verify, key2.cryptoAlgorithm); this.key = key2; }
/** Return true if this is the same block as the other ClientSSKBlock, *and* it is the same key */ @Override public boolean equals(Object o) { if(!(o instanceof ClientSSKBlock)) return false; ClientSSKBlock block = (ClientSSKBlock) o; if(!key.equals(block.key)) return false; return this.block.equals(block.block); }
private boolean keysValid(ClientCHK[] keys) { for(ClientCHK key: keys) if(key.getNodeCHK().getRoutingKey() == null) return false; return true; }
public ClientSSKBlock(byte[] data, byte[] headers, ClientSSK key, boolean dontVerify) throws SSKVerifyException { block = new SSKBlock(data, headers, (NodeSSK) key.getNodeKey(true), dontVerify); this.key = key; }
@Override public byte[] getFullKey() { return getKey().getFullKey(); }
@Override public Key getNodeKey(boolean cloneKey) { return cloneKey ? getNodeCHK().cloneKey() : getNodeCHK(); }
@Override public byte[] getRoutingKey() { return getKey().getRoutingKey(); }
@Override public FreenetURI getURI() { return new FreenetURI("SSK", docName, pubKeyHash, cryptoKey, getExtraBytes()); }