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 ClientSSK getSSK(String string) { try { return new ClientSSK(string, pubKeyHash, ClientSSK.getExtraBytes(cryptoAlgorithm), null, cryptoKey); } catch (MalformedURLException e) { Logger.error(this, "Caught "+e+" should not be possible in USK.getSSK", e); throw new Error(e); } }
/** 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); }
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 ClientKeyBlock fetch(ClientSSK clientSSK, boolean canReadClientCache, boolean canWriteClientCache, boolean canWriteDatastore) throws SSKVerifyException { DSAPublicKey key = clientSSK.getPubKey(); if(key == null) { key = getPubKey.getKey(clientSSK.pubKeyHash, canReadClientCache, false, null); } if(key == null) return null; clientSSK.setPublicKey(key); SSKBlock block = fetch((NodeSSK)clientSSK.getNodeKey(true), false, canReadClientCache, canWriteClientCache, canWriteDatastore, false, null); if(block == null) { if(logMINOR) Logger.minor(this, "Could not find key for "+clientSSK); return null; } // Move the pubkey to the top of the LRU, and fix it if it // was corrupt. getPubKey.cacheKey(clientSSK.pubKeyHash, key, false, canWriteClientCache, canWriteDatastore, false, writeLocalToDatastore); return ClientSSKBlock.construct(block, clientSSK); }
RequestSender rs = null; try { Object o = node.makeRequestSender(key.getNodeKey(true), node.maxHTL(), uid, tag, null, localOnly, ignoreStore, false, true, canWriteClientCache, realTimeFlag); if(o instanceof SSKBlock) try { tag.setServedFromDatastore(); SSKBlock block = (SSKBlock) o; key.setPublicKey(block.getPubKey()); return ClientSSKBlock.construct(block, key); } catch(SSKVerifyException e) { requestStarters.requestCompleted(true, false, key.getNodeKey(true), realTimeFlag); try { SSKBlock block = rs.getSSKBlock(); key.setPublicKey(block.getPubKey()); return ClientSSKBlock.construct(block, key); } catch(SSKVerifyException e) {
protected final byte[] getExtraBytes() { return getExtraBytes(cryptoAlgorithm); }
@Override public String toString() { return "ClientSSK:"+getURI().toString(); }
@Override public ClientKey cloneKey() { return new ClientSSK(this); }
@Override public int hashCode() { return block.hashCode() ^ key.hashCode(); }
/** Optimize for memory. */ public FreenetURI intern() { boolean changedAnything = false; byte[] x = extra; if(keyType.equals("CHK")) x = ClientCHK.internExtra(x); else x = ClientSSK.internExtra(x); if(x != extra) changedAnything = true; String[] newMetaStr = null; if(metaStr != null) { newMetaStr = new String[metaStr.length]; for(int i=0;i<metaStr.length;i++) { newMetaStr[i] = metaStr[i].intern(); if(metaStr[i] != newMetaStr[i]) changedAnything = true; } } String dn = docName == null ? null : docName.intern(); if(dn != docName) changedAnything = true; if(!changedAnything) { noCacheURI = true; return this; } FreenetURI u = new FreenetURI(keyType, dn, newMetaStr, routingKey, cryptoKey, extra); u.noCacheURI = true; return u; }
@Override public FreenetURI getURI() { return new FreenetURI("SSK", docName, pubKeyHash, cryptoKey, getExtraBytes()); }
Rijndael aes; try { Logger.minor(this, "cryptoAlgorithm="+key.cryptoAlgorithm+" for "+getClientKey().getURI()); aes = new Rijndael(256,256); } catch (UnsupportedCipherException e) {
public USK(byte[] pubKeyHash, byte[] cryptoKey, byte[] extra, String siteName, long suggestedEdition) throws MalformedURLException { this.pubKeyHash = pubKeyHash; this.cryptoKey = cryptoKey; this.siteName = siteName; this.suggestedEdition = suggestedEdition; if(extra == null) throw new MalformedURLException("No extra bytes (third bit) in USK"); if(pubKeyHash == null) throw new MalformedURLException("No pubkey hash (first bit) in USK"); if(cryptoKey == null) throw new MalformedURLException("No crypto key (second bit) in USK"); // Verify extra bytes, get cryptoAlgorithm - FIXME this should be a static method or something? ClientSSK tmp = new ClientSSK(siteName, pubKeyHash, extra, null, cryptoKey); cryptoAlgorithm = tmp.cryptoAlgorithm; if(pubKeyHash.length != NodeSSK.PUBKEY_HASH_SIZE) throw new MalformedURLException("Pubkey hash wrong length: "+pubKeyHash.length+" should be "+NodeSSK.PUBKEY_HASH_SIZE); if(cryptoKey.length != ClientSSK.CRYPTO_KEY_LENGTH) throw new MalformedURLException("Decryption key wrong length: "+cryptoKey.length+" should be "+ClientSSK.CRYPTO_KEY_LENGTH); hashCode = Fields.hashCode(pubKeyHash) ^ Fields.hashCode(cryptoKey) ^ siteName.hashCode() ^ (int)suggestedEdition ^ (int)(suggestedEdition >> 32); }
ClientSSKBlock block = sskBlocks.remove(0); //get the first element ClientSSK key = block.getClientKey(); NodeSSK ssk = (NodeSSK) key.getNodeKey(); SSKBlock verify = store.fetch(ssk, false, false, false, false, null); String data = decodeBlockSSK(verify, key);
@Override public FreenetURI getURI() { return new FreenetURI(pubKeyHash, cryptoKey, ClientSSK.getExtraBytes(cryptoAlgorithm), siteName, suggestedEdition); }
@Override public void onFoundEdition(long l, USK newUSK, ClientContext context, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { if(l < usk.suggestedEdition && datastoreOnly) l = usk.suggestedEdition; ClientSSK key = usk.getSSK(l); try { if(l == usk.suggestedEdition) { SingleFileFetcher sf = new SingleFileFetcher(parent, cb, null, key, metaStrings, key.getURI().addMetaStrings(metaStrings), 0, ctx, false, realTimeFlag, actx, null, null, maxRetries, recursionLevel+1, dontTellClientGet, token, false, true, false, (short)0, context, false); if(tag != null) { cb.onTransition(tag, sf, context); } sf.schedule(context); } else { cb.onFailure(new FetchException(FetchExceptionMode.PERMANENT_REDIRECT, newUSK.getURI().addMetaStrings(metaStrings)), null, context); } } catch (FetchException e) { cb.onFailure(e, null, context); } }
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); }
ClientSSKBlock block = sskBlocks.remove(0); //get the first element ClientSSK key = block.getClientKey(); NodeSSK ssk = (NodeSSK) key.getNodeKey(); SSKBlock verify = store.fetch(ssk, false, false, false, false, null); String data = decodeBlockSSK(verify, key);
public FreenetURI getBaseSSK() { return new FreenetURI("SSK", siteName, pubKeyHash, cryptoKey, ClientSSK.getExtraBytes(cryptoAlgorithm)); }