ClientCHKBlock encodeBlock(byte[] buf) { assert (buf.length == CHKBlock.DATA_LENGTH); ClientCHKBlock block; try { block = ClientCHKBlock.encodeSplitfileBlock(buf, splitfileCryptoKey, splitfileCryptoAlgorithm); } catch (CHKEncodeException e) { throw new Error(e); // Impossible! } return block; }
private ClientCHKBlock encodeBlock(ClientCHK key, byte[] data) { try { return ClientCHKBlock.encodeSplitfileBlock(data, key.getCryptoKey(), key.getCryptoAlgorithm()); } catch (CHKEncodeException e) { return null; } }
public static ClientCHK[] makeKeys(byte[][] blocks, byte[] cryptoKey, byte cryptoAlgorithm) throws CHKEncodeException { ClientCHK[] keys = new ClientCHK[blocks.length]; for(int i=0;i<blocks.length;i++) keys[i] = ClientCHKBlock.encodeSplitfileBlock(blocks[i], cryptoKey, cryptoAlgorithm).getClientKey(); return keys; }
public CHKBlock encodeCheckBlock(int i) throws CHKEncodeException { return ClientCHKBlock.encodeSplitfileBlock(checkBlocks[i], cryptoKey, cryptoAlgorithm).getBlock(); }
public CHKBlock encodeDataBlock(int i) throws CHKEncodeException { return ClientCHKBlock.encodeSplitfileBlock(dataBlocks[i], cryptoKey, cryptoAlgorithm).getBlock(); }
private boolean checkEncodedDataBlocks(byte[][] checkBlocks, boolean[] checkBlocksPresent, SplitFileSegmentKeys keys, boolean capturingBinaryBlob) { for(int i=0;i<checkBlocks.length;i++) { if(checkBlocksPresent[i]) continue; ClientCHK decodeKey = keys.getKey(i+blocksForDecode(), null, false); // Encode it to check whether the key is the same. ClientCHKBlock block; try { block = ClientCHKBlock.encodeSplitfileBlock(checkBlocks[i], decodeKey.getCryptoKey(), decodeKey.getCryptoAlgorithm()); ClientCHK actualKey = block.getClientKey(); if(!actualKey.equals(decodeKey)) { Logger.error(this, "Splitfile check block "+i+" does not encode to expected key for "+this+" for "+parent); return false; } if(capturingBinaryBlob) parent.fetcher.maybeAddToBinaryBlob(block); } catch (CHKEncodeException e) { // Impossible! parent.fail(new FetchException(FetchExceptionMode.INTERNAL_ERROR, "Decoded block could not be encoded")); Logger.error(this, "Impossible: Decoded block could not be encoded"); return false; } } return true; }
public synchronized byte[] checkAndGetBlockData(int blockNum) throws IOException { if(!blockChooser.hasSucceeded(blockNum)) return null; ClientCHK key = getKey(blockNum); if(key == null) return null; for(int i=0;i<blocksFetched.length;i++) { if(blocksFetched[i] == blockNum) { byte[] buf = readBlock(i); try { ClientCHKBlock block = ClientCHKBlock.encodeSplitfileBlock(buf, key.getCryptoKey(), key.getCryptoAlgorithm()); if(!(block.getClientKey().equals(key))) { Logger.error(this, "Block "+blockNum+" in blocksFound["+i+"] is not valid!"); blockChooser.onUnSuccess(blockNum); succeeded = false; finished = false; } else { return buf; } } catch (CHKEncodeException e) { // Should not be possible. Logger.error(this, "Impossible: "+e); return null; } } } Logger.error(this, "Block "+blockNum+" in blocksFound but not in blocksFetched on "+this); return null; }
block = ClientCHKBlock.encodeSplitfileBlock(dataBlocks[i], decodeKey.getCryptoKey(), decodeKey.getCryptoAlgorithm()); ClientCHK actualKey = block.getClientKey(); if(!actualKey.equals(decodeKey)) {
ClientCHKBlock.encodeSplitfileBlock(buf, decodeKey.getCryptoKey(), decodeKey.getCryptoAlgorithm()); ClientCHK actualKey = block.getClientKey(); if(decodeKey == null || !decodeKey.equals(actualKey)) {