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; }
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)); } }
@Override public SSKBlock construct(byte[] data, byte[] headers, byte[] routingKey, byte[] fullKey, boolean canReadClientCache, boolean canReadSlashdotCache, BlockMetadata meta, DSAPublicKey knownPublicKey) throws SSKVerifyException { if(data == null || headers == null) throw new SSKVerifyException("Need data and headers"); if(fullKey == null) throw new SSKVerifyException("Need full key to reconstruct an SSK"); NodeSSK key; key = NodeSSK.construct(fullKey); if(knownPublicKey != null) key.setPubKey(knownPublicKey); else if(!key.grabPubkey(pubkeyCache, canReadClientCache, canReadSlashdotCache, meta)) throw new SSKVerifyException("No pubkey found"); SSKBlock block = new SSKBlock(data, headers, key, false); return block; }
/** * Finish fetching an SSK. We must have received the data, the headers and the pubkey by this point. * @param next The node we received the data from. * @return True if the request has completed. False if we need to look elsewhere. */ private boolean finishSSKFromGetOffer(PeerNode next, byte[] headers, byte[] sskData) { try { block = new SSKBlock(sskData, headers, (NodeSSK)key, false); synchronized(this) { finalHeaders = headers; finalSskData = sskData; } node.storeShallow(block, canWriteClientCache, canWriteDatastore, tryOffersOnly); if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0) node.queueRandomReinsert(block); finish(SUCCESS, next, true); return true; } catch (SSKVerifyException e) { Logger.error(this, "Failed to verify (from get offer): "+e+" from "+next, e); return false; } catch (KeyCollisionException e) { Logger.normal(this, "Collision (from get offer) on "+this); finish(SUCCESS, next, true); return false; } }
private void verifyAndCommit(byte[] headers, byte[] data) throws KeyVerifyException { if(!isSSK) { CHKBlock block = new CHKBlock(data, headers, (NodeCHK)key); synchronized(this) { finalHeaders = headers; } if(logMINOR) Logger.minor(this, "Verified"); // Cache only in the cache, not the store. The reason for this is that // requests don't go to the full distance, and therefore pollute the // store; simulations it is best to only include data from requests // which go all the way i.e. inserts. node.storeShallow(block, canWriteClientCache, canWriteDatastore, tryOffersOnly); if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0) node.queueRandomReinsert(block); } else /*if (key instanceof NodeSSK)*/ { synchronized(this) { finalHeaders = headers; finalSskData = data; } try { SSKBlock block = new SSKBlock(data, headers, (NodeSSK)key, false); if(logMINOR) Logger.minor(this, "Verified SSK"); node.storeShallow(block, canWriteClientCache, canWriteDatastore, tryOffersOnly); } catch (KeyCollisionException e) { Logger.normal(this, "Collision on "+this); } } }
block = new SSKBlock(sskData, headers, (NodeSSK)key, false); node.storeShallow(block, canWriteClientCache, canWriteDatastore, false); if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0)
block = new SSKBlock(data, headers, block.getKey(), false);