@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); } }
FailureTableEntry(Key key) { this.key = key.archivalCopy(); long now = System.currentTimeMillis(); creationTime = now; receivedTime = -1; sentTime = -1; requestorNodes = EMPTY_WEAK_REFERENCE; requestorTimes = EMPTY_LONG_ARRAY; requestorBootIDs = EMPTY_LONG_ARRAY; requestorHTLs = EMPTY_SHORT_ARRAY; requestedNodes = EMPTY_WEAK_REFERENCE; requestedLocs = EMPTY_DOUBLE_ARRAY; requestedBootIDs = EMPTY_LONG_ARRAY; requestedTimes = EMPTY_LONG_ARRAY; requestedTimeoutsRF = EMPTY_LONG_ARRAY; requestedTimeoutsFT = EMPTY_LONG_ARRAY; requestedTimeoutHTLs = EMPTY_SHORT_ARRAY; }
public void onSuccess(KeyBlock lowLevelBlock, boolean fromStore, SendableRequestItem token, ClientContext context) { ClientKeyBlock block; try { block = Key.createKeyBlock(this.key, lowLevelBlock); onSuccess(block, fromStore, token, context); } catch (KeyVerifyException e) { onBlockDecodeError(token, context); } }
BaseSender(Key key, boolean realTimeFlag, PeerNode source, Node node, short htl, long uid) { if(key.getRoutingKey() == null) throw new NullPointerException(); startTime = System.currentTimeMillis(); this.uid = uid; this.key = key; this.realTimeFlag = realTimeFlag; this.node = node; this.source = source; target = key.toNormalizedDouble(); this.isSSK = key instanceof NodeSSK; assert(isSSK || key instanceof NodeCHK); this.htl = htl; this.origHTL = htl; newLoadManagement = node.enableNewLoadManagement(realTimeFlag); incomingSearchTimeout = calculateTimeout(realTimeFlag, htl, node); }
public static void writeKey(DataOutputStream binaryBlobStream, KeyBlock block, Key key) throws IOException { byte[] keyData = key.getKeyBytes(); byte[] headers = block.getRawHeaders(); byte[] data = block.getRawData(); byte[] pubkey = block.getPubkeyBytes(); writeBlobHeader(binaryBlobStream, BLOB_BLOCK, BLOB_BLOCK_VERSION, 9+keyData.length+headers.length+data.length+(pubkey==null?0:pubkey.length)); binaryBlobStream.writeShort(block.getKey().getType()); binaryBlobStream.writeByte(keyData.length); binaryBlobStream.writeShort(headers.length); binaryBlobStream.writeShort(data.length); binaryBlobStream.writeShort(pubkey == null ? 0 : pubkey.length); binaryBlobStream.write(keyData); binaryBlobStream.write(headers); binaryBlobStream.write(data); if(pubkey != null) binaryBlobStream.write(pubkey); } static final short BLOB_BLOCK = 1;
store.put(block.getBlock(), false); assertEquals(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null), null); tests.add(test); chkBlocks.add(block); assertEquals(test, data); assertNotNull(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null));
@Override public byte[] saltKey(Key key) { return key.getRoutingKey(); }
/** Offer a key to this node */ public void offer(Key key) { byte[] keyBytes = key.getFullKey(); // FIXME maybe the authenticator should be shorter than 32 bytes to save memory? byte[] authenticator = HMAC.macWithSHA256(node.failureTable.offerAuthenticatorKey, keyBytes); Message msg = DMT.createFNPOfferKey(key, authenticator); try { sendAsync(msg, null, node.nodeStats.sendOffersCtr); } catch(NotConnectedException e) { // Ignore } }
@Override public short definitelyWantKey(Key key, byte[] saltedKey, ClientContext context) { if(!key.equals(this.key)) return -1; else return prio; }
throw new CHKDecodeException("HMAC is wrong, wrong decryption key?"); return Key.decompress(dontCompress ? false : key.isCompressed(), plaintext, size, bf, Math.min(maxLength, CHKBlock.MAX_LENGTH_BEFORE_COMPRESSION), key.compressionAlgorithm, false); } catch(GeneralSecurityException e) {
short compressionAlgorithm = -1; try { Compressed comp = Key.compress(sourceData, dontCompress, alreadyCompressedCodec, sourceLength, CHKBlock.MAX_LENGTH_BEFORE_COMPRESSION, CHKBlock.DATA_LENGTH, false, compressorDescriptor, pre1254); finalData = comp.compressedData; compressionAlgorithm = comp.compressionAlgorithm;
KeyBlock block; try { block = Key.createBlock(keyType, keyBytes, headersBytes, dataBytes, pubkeyBytes); } catch (KeyVerifyException e) { throw new BinaryBlobFormatException("Invalid key: "+e.getMessage(), e);
ClientCHKBlock block = encodeBlockCHK(test); assertEquals(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null), null); store.put(block.getBlock(), false); tests.add(test);
@Override public byte[] saltKey(Key key) { return key.getRoutingKey(); }
byte[] authenticator = ((ShortBuffer) m.getObject(DMT.OFFER_AUTHENTICATOR)).getData(); long uid = m.getLong(DMT.UID); if(!HMAC.verifyWithSHA256(node.failureTable.offerAuthenticatorKey, key.getFullKey(), authenticator)) { Logger.error(this, "Invalid offer request from "+source+" : authenticator did not verify"); try {
@Override public SendableGet[] getRequestsForKey(Key key, byte[] saltedKey, ClientContext context) { if(!key.equals(this.key)) return null; return new SendableGet[] { fetcher }; }
throw new CHKDecodeException("Problem with JCA, should be impossible!", e); return Key.decompress(dontCompress ? false : key.isCompressed(), plaintext, size, bf, Math.min(maxLength, CHKBlock.MAX_LENGTH_BEFORE_COMPRESSION), key.compressionAlgorithm, false);
short compressionAlgo; try { Compressed comp = Key.compress(sourceData, dontCompress, alreadyCompressedCodec, sourceLength, ClientSSKBlock.MAX_DECOMPRESSED_DATA_LENGTH, SSKBlock.DATA_LENGTH, true, compressordescriptor, pre1254); compressedData = comp.compressedData; compressionAlgo = comp.compressionAlgorithm;
assertEquals(test, data); assertNotNull(saltStore.fetch(block.getKey().getRoutingKey(), block.getKey().getFullKey(), false, false, false, false, null));
@Override public byte[] saltKey(Key key) { return key.getRoutingKey(); }