public ClientSSK(FreenetURI origURI) throws MalformedURLException { this(origURI.getDocName(), origURI.getRoutingKey(), origURI.getExtra(), null, origURI.getCryptoKey()); if(!origURI.getKeyType().equalsIgnoreCase("SSK")) throw new MalformedURLException(); }
/** * Create from a URI. */ public ClientCHK(FreenetURI uri) throws MalformedURLException { if(!uri.getKeyType().equals("CHK")) throw new MalformedURLException("Not CHK"); routingKey = uri.getRoutingKey(); cryptoKey = uri.getCryptoKey(); byte[] extra = uri.getExtra(); if((extra == null) || (extra.length < 5)) throw new MalformedURLException("No extra bytes in CHK - maybe a 0.5 key?"); // byte 0 is reserved, for now cryptoAlgorithm = extra[1]; if(!(cryptoAlgorithm == Key.ALGO_AES_PCFB_256_SHA256 || cryptoAlgorithm == Key.ALGO_AES_CTR_256_SHA256)) throw new MalformedURLException("Invalid crypto algorithm"); controlDocument = (extra[2] & 0x02) != 0; compressionAlgorithm = (short)(((extra[3] & 0xff) << 8) + (extra[4] & 0xff)); hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(cryptoKey) ^ compressionAlgorithm; }
public FreenetURI turnMySSKIntoUSK(FreenetURI uri) { if(uri.getKeyType().equals("SSK") && Arrays.equals(uri.getRoutingKey(), pubKeyHash) && Arrays.equals(uri.getCryptoKey(), cryptoKey) && Arrays.equals(uri.getExtra(), ClientSSK.getExtraBytes(cryptoAlgorithm)) && uri.getDocName() != null && uri.getDocName().startsWith(siteName)) { String doc = uri.getDocName(); doc = doc.substring(siteName.length()); if(doc.length() < 2 || doc.charAt(0) != '-') return uri; doc = doc.substring(1); long edition; try { edition = Long.parseLong(doc); } catch (NumberFormatException e) { Logger.normal(this, "Trying to turn SSK back into USK: "+uri+" doc="+doc+" caught "+e, e); return uri; } if(!doc.equals(Long.toString(edition))) return uri; return new FreenetURI("USK", siteName, uri.getAllMetaStrings(), pubKeyHash, cryptoKey, ClientSSK.getExtraBytes(cryptoAlgorithm), edition); } return uri; }
public static Key from(FreenetURI freenetURI) { return new Key(freenetURI.getRoutingKey(), freenetURI.getCryptoKey(), freenetURI.getExtra()); }
public static USK create(FreenetURI uri) throws MalformedURLException { if(!uri.isUSK()) throw new MalformedURLException("Not a USK"); return new USK(uri.getRoutingKey(), uri.getCryptoKey(), uri.getExtra(), uri.getDocName(), uri.getSuggestedEdition()); }
byte[] extra = uri.getExtra(); if(uri.getKeyType().equals("SSK")) { if(extra == null)
simpleRedirectKey = readKey(dis); if(simpleRedirectKey.isCHK()) { byte algo = ClientCHK.getCryptoAlgorithmFromExtra(simpleRedirectKey.getExtra()); if(algo == Key.ALGO_AES_CTR_256_SHA256) { minCompatMode = CompatibilityMode.COMPAT_1416;