public ClientSSK(FreenetURI origURI) throws MalformedURLException { this(origURI.getDocName(), origURI.getRoutingKey(), origURI.getExtra(), null, origURI.getCryptoKey()); if(!origURI.getKeyType().equalsIgnoreCase("SSK")) throw new MalformedURLException(); }
static FreenetURI checkEmptySSK(FreenetURI uri, String filename, ClientContext context) { if("SSK".equals(uri.getKeyType()) && uri.getDocName() == null && uri.getRoutingKey() == null) { if(filename == null || filename.equals("")) filename = "key"; // SSK@ = use a random SSK. InsertableClientSSK key = InsertableClientSSK.createRandom(context.random, ""); return key.getInsertURI().setDocName(filename); } else { return uri; } }
/** * 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()); }
return ClientKSK.create(uri); if(uri.getRoutingKey() == null) throw new MalformedURLException("Insertable SSK URIs must have a private key!: "+uri); if(uri.getCryptoKey() == null) DSAPrivateKey privKey; try { privKey = new DSAPrivateKey(new BigInteger(1, uri.getRoutingKey()), g); } catch(IllegalArgumentException e) {
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()); }
@Before public void setupSone() { InsertableClientSSK insertSsk = createRandom(randomSource, "test-0"); when(sone.getId()).thenReturn(Base64.encode(insertSsk.getURI().getRoutingKey())); when(sone.getRequestUri()).thenReturn(insertSsk.getURI().uskForSSK()); }
if(uri.getRoutingKey() == null && !uri.isKSK()) targetFilename = fnam; else