diff --git a/src/freenet/client/FetchContext.java b/src/freenet/client/FetchContext.java index 45b09b90de5..863084f2dcb 100644 --- a/src/freenet/client/FetchContext.java +++ b/src/freenet/client/FetchContext.java @@ -114,15 +114,17 @@ public class FetchContext implements Cloneable, Serializable { /** Number of attempts before we go into cooldown. Must be less than or equal to * RequestScheduler.COOLDOWN_RETRIES. */ private int cooldownRetries; - /** Time period for which we go into cooldown. Must be NO LESS THAN + /** Time period for which we go into cooldown. Must be NO LESS THAN * RequestScheduler.COOLDOWN_PERIOD, because ULPRs will ensure rapid success * with that interval or less. */ private long cooldownTime; /** Ignore USK DATEHINTs */ public boolean ignoreUSKDatehints; - - public FetchContext(long curMaxLength, + /** host and port (authority) */ + public String host; + + public FetchContext(long curMaxLength, long curMaxTempLength, int maxMetadataSize, int maxRecursionLevel, int maxArchiveRestarts, int maxArchiveLevels, boolean dontEnterImplicitArchives, int maxSplitfileBlockRetries, int maxNonSplitfileRetries, int maxUSKRetries, @@ -130,8 +132,9 @@ public FetchContext(long curMaxLength, boolean filterData, int maxDataBlocksPerSegment, int maxCheckBlocksPerSegment, BucketFactory bucketFactory, ClientEventProducer producer, - boolean ignoreTooManyPathComponents, boolean canWriteClientCache, String charset, String overrideMIME) { - this.blocks = null; + boolean ignoreTooManyPathComponents, boolean canWriteClientCache, String charset, String overrideMIME, + String host) { + this.blocks = null; this.maxOutputLength = curMaxLength; if(maxOutputLength < 0) throw new IllegalArgumentException("Bad max output length"); this.maxTempLength = curMaxTempLength; @@ -170,8 +173,9 @@ public FetchContext(long curMaxLength, this.cooldownTime = RequestScheduler.COOLDOWN_PERIOD; this.ignoreUSKDatehints = false; // FIXME hasOwnEventProducer = true; + this.host = host; } - + /** Copy a FetchContext, creating a new EventProducer and not changing the blocks list. * @param ctx The old FetchContext to copy. * @param maskID Mask mode for the copy operation e.g. SPLITFILE_DEFAULT_BLOCK_MASK. @@ -227,6 +231,7 @@ public FetchContext(FetchContext ctx, int maskID, boolean keepProducer, BlockSet this.cooldownRetries = ctx.cooldownRetries; this.cooldownTime = ctx.cooldownTime; this.ignoreUSKDatehints = ctx.ignoreUSKDatehints; + this.host = ctx.host; if(maskID == IDENTICAL_MASK || maskID == SPLITFILE_DEFAULT_MASK) { // DEFAULT @@ -333,8 +338,12 @@ public void writeTo(DataOutputStream dos) throws IOException { dos.writeInt(cooldownRetries); dos.writeLong(cooldownTime); dos.writeBoolean(ignoreUSKDatehints); + if (host != null) + dos.writeUTF(host); + else + dos.writeUTF(""); } - + /** Create from a saved form, e.g. for restarting a request from scratch. Will create its own * SimpleEventProducer. * @param dis @@ -404,6 +413,11 @@ public FetchContext(DataInputStream dis) throws StorageFormatException, IOExcept cooldownRetries = dis.readInt(); cooldownTime = dis.readLong(); ignoreUSKDatehints = dis.readBoolean(); + s = dis.readUTF(); + if(s.equals("")) + host = null; + else + host = s; hasOwnEventProducer = true; eventProducer = new SimpleEventProducer(); blocks = null; @@ -444,6 +458,7 @@ public int hashCode() { result = prime * result + ((prefetchHook == null) ? 0 : prefetchHook.hashCode()); result = prime * result + (returnZIPManifests ? 1231 : 1237); result = prime * result + ((tagReplacer == null) ? 0 : tagReplacer.hashCode()); + result = prime * result + ((host == null) ? 0 : host.hashCode()); return result; } @@ -539,6 +554,11 @@ public boolean equals(Object obj) { return false; } else if (!tagReplacer.equals(other.tagReplacer)) return false; + if (host == null) { + if (other.host != null) + return false; + } else if (!host.equals(other.host)) + return false; return true; } diff --git a/src/freenet/client/HighLevelSimpleClientImpl.java b/src/freenet/client/HighLevelSimpleClientImpl.java index 9f3d794d515..2d204b5a41d 100644 --- a/src/freenet/client/HighLevelSimpleClientImpl.java +++ b/src/freenet/client/HighLevelSimpleClientImpl.java @@ -352,21 +352,21 @@ public FetchContext getFetchContext(long overrideMaxSize) { MAX_RECURSION, MAX_ARCHIVE_RESTARTS, MAX_ARCHIVE_LEVELS, DONT_ENTER_IMPLICIT_ARCHIVES, SPLITFILE_BLOCK_RETRIES, NON_SPLITFILE_RETRIES, USK_RETRIES, FETCH_SPLITFILES, FOLLOW_REDIRECTS, LOCAL_REQUESTS_ONLY, - FILTER_DATA, MAX_SPLITFILE_BLOCKS_PER_SEGMENT, MAX_SPLITFILE_CHECK_BLOCKS_PER_SEGMENT, + FILTER_DATA, MAX_SPLITFILE_BLOCKS_PER_SEGMENT, MAX_SPLITFILE_CHECK_BLOCKS_PER_SEGMENT, bucketFactory, eventProducer, - false, CAN_WRITE_CLIENT_CACHE, null, null); + false, CAN_WRITE_CLIENT_CACHE, null, null, null); } - - public static FetchContext makeDefaultFetchContext(long maxLength, long maxTempLength, + + public static FetchContext makeDefaultFetchContext(long maxLength, long maxTempLength, BucketFactory bucketFactory, SimpleEventProducer eventProducer) { return new FetchContext(maxLength, maxTempLength, 1024*1024, MAX_RECURSION, MAX_ARCHIVE_RESTARTS, MAX_ARCHIVE_LEVELS, DONT_ENTER_IMPLICIT_ARCHIVES, SPLITFILE_BLOCK_RETRIES, NON_SPLITFILE_RETRIES, USK_RETRIES, FETCH_SPLITFILES, FOLLOW_REDIRECTS, LOCAL_REQUESTS_ONLY, - FILTER_DATA, MAX_SPLITFILE_BLOCKS_PER_SEGMENT, MAX_SPLITFILE_CHECK_BLOCKS_PER_SEGMENT, + FILTER_DATA, MAX_SPLITFILE_BLOCKS_PER_SEGMENT, MAX_SPLITFILE_CHECK_BLOCKS_PER_SEGMENT, bucketFactory, eventProducer, - false, CAN_WRITE_CLIENT_CACHE, null, null); + false, CAN_WRITE_CLIENT_CACHE, null, null, null); } @Override diff --git a/src/freenet/client/async/ClientGetWorkerThread.java b/src/freenet/client/async/ClientGetWorkerThread.java index f31f4bd5956..daa69103736 100644 --- a/src/freenet/client/async/ClientGetWorkerThread.java +++ b/src/freenet/client/async/ClientGetWorkerThread.java @@ -36,6 +36,7 @@ public class ClientGetWorkerThread extends Thread { private InputStream input; + private String host; final private URI uri; final private HashResult[] hashes; final private boolean filterData; @@ -76,10 +77,10 @@ private static synchronized int counter() { * @param prefetchHook Only needed if filterData is true. * @param tagReplacer Used for web-pushing. Only needed if filterData is true. * @param linkFilterExceptionProvider Provider for link filter exceptions - * @throws URISyntaxException + * @throws URISyntaxException */ public ClientGetWorkerThread(InputStream input, OutputStream output, FreenetURI uri, - String mimeType, HashResult[] hashes, boolean filterData, String charset, + String mimeType, String host, HashResult[] hashes, boolean filterData, String charset, FoundURICallback prefetchHook, TagReplacerCallback tagReplacer, LinkFilterExceptionProvider linkFilterExceptionProvider) throws URISyntaxException { super("ClientGetWorkerThread-"+counter()); this.input = input; @@ -87,6 +88,7 @@ public ClientGetWorkerThread(InputStream input, OutputStream output, FreenetURI else this.uri = null; if(mimeType != null && mimeType.compareTo("application/xhtml+xml") == 0) mimeType = "text/html"; this.mimeType = mimeType; + this.host = host; this.hashes = hashes; this.output = output; this.filterData = filterData; @@ -113,7 +115,7 @@ public void run() { if(logMINOR) Logger.minor(this, "Running content filter... Prefetch hook: "+prefetchHook+" tagReplacer: "+tagReplacer); if(mimeType == null || uri == null || input == null || output == null) throw new IOException("Insufficient arguements to worker thread"); // Send XHTML as HTML because we can't use web-pushing on XHTML. - FilterStatus filterStatus = ContentFilter.filter(input, output, mimeType, uri, prefetchHook, tagReplacer, charset, linkFilterExceptionProvider); + FilterStatus filterStatus = ContentFilter.filter(input, output, mimeType, uri, host, prefetchHook, tagReplacer, charset, linkFilterExceptionProvider); String detectedMIMEType = filterStatus.mimeType.concat(filterStatus.charset == null ? "" : "; charset="+filterStatus.charset); synchronized(this) { diff --git a/src/freenet/client/async/ClientGetter.java b/src/freenet/client/async/ClientGetter.java index 87d454dae06..5db4588794e 100644 --- a/src/freenet/client/async/ClientGetter.java +++ b/src/freenet/client/async/ClientGetter.java @@ -338,7 +338,7 @@ public void onSuccess(StreamGenerator streamGenerator, ClientMetadata clientMeta output = finalResult.getOutputStream(); if(ctx.overrideMIME != null) mimeType = ctx.overrideMIME; - worker = new ClientGetWorkerThread(new BufferedInputStream(dataInput), output, uri, mimeType, hashes, ctx.filterData, ctx.charset, ctx.prefetchHook, ctx.tagReplacer, context.linkFilterExceptionProvider); + worker = new ClientGetWorkerThread(new BufferedInputStream(dataInput), output, uri, mimeType, ctx.host, hashes, ctx.filterData, ctx.charset, ctx.prefetchHook, ctx.tagReplacer, context.linkFilterExceptionProvider); worker.start(); try { streamGenerator.writeTo(dataOutput, context); @@ -903,9 +903,9 @@ public void onExpectedTopSize(long size, long compressed, int blocksReq, int blo } @Override - public void onSplitfileCompatibilityMode(final CompatibilityMode min, - final CompatibilityMode max, final byte[] customSplitfileKey, - final boolean dontCompress, final boolean bottomLayer, final boolean definitiveAnyway, + public void onSplitfileCompatibilityMode(final CompatibilityMode min, + final CompatibilityMode max, final byte[] customSplitfileKey, + final boolean dontCompress, final boolean bottomLayer, final boolean definitiveAnyway, ClientContext context) { context.getJobRunner(persistent()).queueNormalOrDrop(new PersistentJob() { diff --git a/src/freenet/client/async/SingleFileFetcher.java b/src/freenet/client/async/SingleFileFetcher.java index 1df82535f1a..e194f51b1f1 100644 --- a/src/freenet/client/async/SingleFileFetcher.java +++ b/src/freenet/client/async/SingleFileFetcher.java @@ -916,7 +916,7 @@ public void onSuccess(StreamGenerator streamGenerator, ClientMetadata clientMeta pipeOut.connect(pipeIn); DecompressorThreadManager decompressorManager = new DecompressorThreadManager(pipeIn, decompressors, maxLen); pipeIn = decompressorManager.execute(); - ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, null, false, null, null, null, context.linkFilterExceptionProvider); + ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, ctx.host,null, false, null, null, null, context.linkFilterExceptionProvider); worker.start(); streamGenerator.writeTo(pipeOut, context); decompressorManager.waitFinished(); @@ -1066,7 +1066,7 @@ public void onSuccess(StreamGenerator streamGenerator, ClientMetadata clientMeta pipeIn.connect(pipeOut); DecompressorThreadManager decompressorManager = new DecompressorThreadManager(pipeIn, decompressors, maxLen); pipeIn = decompressorManager.execute(); - ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, null, false, null, null, null, context.linkFilterExceptionProvider); + ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, ctx.host,null, false, null, null, null, context.linkFilterExceptionProvider); worker.start(); streamGenerator.writeTo(pipeOut, context); decompressorManager.waitFinished(); diff --git a/src/freenet/client/async/USKFetcher.java b/src/freenet/client/async/USKFetcher.java index f51f0deeac3..05014f59c15 100644 --- a/src/freenet/client/async/USKFetcher.java +++ b/src/freenet/client/async/USKFetcher.java @@ -226,7 +226,7 @@ public void onSuccess(StreamGenerator streamGenerator, pipeOut.connect(pipeIn); DecompressorThreadManager decompressorManager = new DecompressorThreadManager(pipeIn, decompressors, maxLen); pipeIn = decompressorManager.execute(); - ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, null, false, null, null, null, context.linkFilterExceptionProvider); + ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, ctx.host,null, false, null, null, null, context.linkFilterExceptionProvider); worker.start(); streamGenerator.writeTo(pipeOut, context); decompressorManager.waitFinished(); diff --git a/src/freenet/client/async/USKRetriever.java b/src/freenet/client/async/USKRetriever.java index 016ccfdd9f8..a958737c972 100644 --- a/src/freenet/client/async/USKRetriever.java +++ b/src/freenet/client/async/USKRetriever.java @@ -133,7 +133,7 @@ public void onSuccess(StreamGenerator streamGenerator, ClientMetadata clientMeta pipeOut = new PipedOutputStream(pipeIn); decompressorManager = new DecompressorThreadManager(pipeIn, decompressors, maxLen); pipeIn = decompressorManager.execute(); - ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, null, false, null, null, null, context.linkFilterExceptionProvider); + ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, ctx.host,null, false, null, null, null, context.linkFilterExceptionProvider); worker.start(); streamGenerator.writeTo(pipeOut, context); worker.waitFinished(); diff --git a/src/freenet/client/filter/BMPFilter.java b/src/freenet/client/filter/BMPFilter.java index dc6ed896273..4f2247ae3ba 100644 --- a/src/freenet/client/filter/BMPFilter.java +++ b/src/freenet/client/filter/BMPFilter.java @@ -86,8 +86,9 @@ public int readShort(DataInputStream dis) throws IOException @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { DataInputStream dis = new DataInputStream(input); dis.mark(54); byte[] StartWord = new byte[2]; diff --git a/src/freenet/client/filter/CSSReadFilter.java b/src/freenet/client/filter/CSSReadFilter.java index efde1aeaea5..6436efea44b 100644 --- a/src/freenet/client/filter/CSSReadFilter.java +++ b/src/freenet/client/filter/CSSReadFilter.java @@ -38,8 +38,9 @@ public void shouldUpdate(){ } @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { if (logDEBUG) Logger.debug( this, diff --git a/src/freenet/client/filter/CSSTokenizerFilter.java b/src/freenet/client/filter/CSSTokenizerFilter.java index 256d6fb31ec..f20974bdf4f 100644 --- a/src/freenet/client/filter/CSSTokenizerFilter.java +++ b/src/freenet/client/filter/CSSTokenizerFilter.java @@ -4843,7 +4843,7 @@ public static void main(String arg[]) throws Throwable { Logger.setupStdoutLogging(Logger.LogLevel.DEBUG, ""); ContentFilter.filter(inputStream, outputStream, "text/css", - new URI("http://127.0.0.1:8888/freenet:USK@ZupQjDFZSc3I4orBpl1iTEAPZKo2733RxCUbZ2Q7iH0,EO8Tuf8SP3lnDjQdAPdCM2ve2RaUEN8m-hod3tQ5oQE,AQACAAE/jFreesite/19/Style/"), null, null, null); + new URI("http://127.0.0.1:8888/freenet:USK@ZupQjDFZSc3I4orBpl1iTEAPZKo2733RxCUbZ2Q7iH0,EO8Tuf8SP3lnDjQdAPdCM2ve2RaUEN8m-hod3tQ5oQE,AQACAAE/jFreesite/19/Style/"), null, null, null, null); } finally { Closer.close(inputStream); Closer.close(outputStream); diff --git a/src/freenet/client/filter/ContentDataFilter.java b/src/freenet/client/filter/ContentDataFilter.java index 2c6e7d89500..f4db0ef8e4f 100644 --- a/src/freenet/client/filter/ContentDataFilter.java +++ b/src/freenet/client/filter/ContentDataFilter.java @@ -12,19 +12,20 @@ * Data filter for a specific MIME type. */ public interface ContentDataFilter { - + /** Filter data for reading. Objective is to ensure the data is safe if * rendered by e.g. a web browser, and to guarantee that it is of the * correct type. Filters should usually be implemented as "white list", - * that is, they should parse everything, and when encountering + * that is, they should parse everything, and when encountering * anything they cannot parse, should delete it, or throw a DataFilterException. - * IMPORTANT Implementation note: The InputStream may be a PipedInputStream - * (or conceivably even a network stream). Implementations MUST NOT ASSUME + * IMPORTANT Implementation note: The InputStream may be a PipedInputStream + * (or conceivably even a network stream). Implementations MUST NOT ASSUME * that input.available() == 0 => EOF! * @param input Stream to read potentially unsafe data from. * @param output Stream to write safe (but possibly incomplete) data to. * @param charset Character set of the data if appropriate for this MIME type. * @param otherParams Other type parameters if appropriate. + * @param hostPort * @param cb Filter callback for modifying HTML tags. Irrelevant for most MIME types. In future we * might need this for other types. * @throws DataFilterException If the data cannot be filtered. Any data @@ -34,6 +35,7 @@ public interface ContentDataFilter { * if data is merely badly formatted - any such exceptions should be * caught and converted to a DataFilterException. */ - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException; + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException; } diff --git a/src/freenet/client/filter/ContentFilter.java b/src/freenet/client/filter/ContentFilter.java index 432613ad582..667275d4a31 100644 --- a/src/freenet/client/filter/ContentFilter.java +++ b/src/freenet/client/filter/ContentFilter.java @@ -189,9 +189,12 @@ public static FilterMIMEType getMIMEType(String mimeType) { * Stream to write filtered data to * @param typeName * MIME type for input data + * @param host + * HOST and PORT from the request * @param maybeCharset * MIME type of the referring document, as a hint, some types, * such as CSS, will inherit it if no other data is available. + * @param linkFilterExceptionProvider * @return * @throws IOException * If an internal error involving s occurred. @@ -200,8 +203,16 @@ public static FilterMIMEType getMIMEType(String mimeType) { * @throws IllegalStateException * If data is invalid (e.g. corrupted file) and the filter have no way to recover. */ - public static FilterStatus filter(InputStream input, OutputStream output, String typeName, URI baseURI, FoundURICallback cb, TagReplacerCallback trc , String maybeCharset) throws UnsafeContentTypeException, IOException { - return filter(input, output, typeName, baseURI, cb, trc, maybeCharset, null); + public static FilterStatus filter( + InputStream input, + OutputStream output, + String typeName, + URI baseURI, + String host, + FoundURICallback cb, + TagReplacerCallback trc, + String maybeCharset) throws UnsafeContentTypeException, IOException { + return filter(input, output, typeName, baseURI, host, cb, trc, maybeCharset, null); } /** @@ -224,8 +235,17 @@ public static FilterStatus filter(InputStream input, OutputStream output, String * @throws IllegalStateException * If data is invalid (e.g. corrupted file) and the filter have no way to recover. */ - public static FilterStatus filter(InputStream input, OutputStream output, String typeName, URI baseURI, FoundURICallback cb, TagReplacerCallback trc , String maybeCharset, LinkFilterExceptionProvider linkFilterExceptionProvider) throws UnsafeContentTypeException, IOException { - return filter(input, output, typeName, maybeCharset, new GenericReadFilterCallback(baseURI, cb,trc, linkFilterExceptionProvider)); + public static FilterStatus filter( + InputStream input, + OutputStream output, + String typeName, + URI baseURI, + String host, + FoundURICallback cb, + TagReplacerCallback trc, + String maybeCharset, + LinkFilterExceptionProvider linkFilterExceptionProvider) throws UnsafeContentTypeException, IOException { + return filter(input, output, typeName, maybeCharset, host, new GenericReadFilterCallback(baseURI, cb, trc, linkFilterExceptionProvider)); } /** @@ -247,11 +267,12 @@ public static FilterStatus filter(InputStream input, OutputStream output, String * @throws IllegalStateException * If data is invalid (e.g. corrupted file) and the filter have no way to recover. */ - public static FilterStatus filter(InputStream input, OutputStream output, String typeName, String maybeCharset, FilterCallback filterCallback) throws UnsafeContentTypeException, IOException { + public static FilterStatus filter(InputStream input, OutputStream output, String typeName, String maybeCharset, String hostPort, FilterCallback filterCallback) throws UnsafeContentTypeException, IOException { if(logMINOR) Logger.minor(ContentFilter.class, "Filtering data of type"+typeName); String type = typeName; String options = ""; String charset = null; + // mimeType params HashMap otherParams = null; input = new BufferedInputStream(input); @@ -306,7 +327,7 @@ public static FilterStatus filter(InputStream input, OutputStream output, String charset = detectCharset(charsetBuffer, offset, handler, maybeCharset); } try { - handler.readFilter.readFilter(input, output, charset, otherParams, filterCallback); + handler.readFilter.readFilter(input, output, charset, otherParams, hostPort, filterCallback); } catch(EOFException e) { Logger.error(ContentFilter.class, "EOFException caught: "+e,e); diff --git a/src/freenet/client/filter/FilterCallback.java b/src/freenet/client/filter/FilterCallback.java index 89ac56e2cba..8a7e0350ca2 100644 --- a/src/freenet/client/filter/FilterCallback.java +++ b/src/freenet/client/filter/FilterCallback.java @@ -26,18 +26,28 @@ public interface FilterCallback { */ public String processURI(String uri, String overrideType, boolean noRelative, boolean inline) throws CommentException; + /** + * Process a URI forcing the host. + * If it cannot be turned into something sufficiently safe, then return null. + * @param overrideType Force the return type. + * @param noRelative TODO + * @param inline TODO + * @throws CommentException If the URI is nvalid or unacceptable in some way. + */ + public String processURI(String uri, String overrideType, String forceHostPort) throws CommentException; + /** * Process a base URI in the page. Not only is this filtered, it affects all * relative uri's on the page. */ public String onBaseHref(String baseHref); - + /** * Process plain-text. Notification only; can't modify. * Type can be null, or can correspond, for example to HTML tag name around text * (for example: "title"). - * - * Note that the string will have been fed through the relevant decoder if + * + * Note that the string will have been fed through the relevant decoder if * necessary (e.g. HTMLDecoder). It must be re-encoded if it is sent out as * text to a browser. */ diff --git a/src/freenet/client/filter/FlacFilter.java b/src/freenet/client/filter/FlacFilter.java index f77f247dae2..231fb1a3df9 100644 --- a/src/freenet/client/filter/FlacFilter.java +++ b/src/freenet/client/filter/FlacFilter.java @@ -20,9 +20,10 @@ public class FlacFilter implements ContentDataFilter { static final byte[] magicNumber = new byte[] {0x66, 0x4C, 0x61, 0x43}; enum State {UNINITIALIZED, STREAMINFO_FOUND, METADATA_FOUND, STREAM_FINISHED}; - public void readFilter(InputStream input, OutputStream output, - String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, + String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { boolean logMINOR = Logger.shouldLog(LogLevel.MINOR, this.getClass()); FlacPacketFilter parser = new FlacPacketFilter(); DataInputStream in = new DataInputStream(input); diff --git a/src/freenet/client/filter/GIFFilter.java b/src/freenet/client/filter/GIFFilter.java index eeb00ec1865..172ed1c6c24 100644 --- a/src/freenet/client/filter/GIFFilter.java +++ b/src/freenet/client/filter/GIFFilter.java @@ -12,7 +12,6 @@ import java.util.HashMap; import freenet.l10n.NodeL10n; -import freenet.support.io.FileUtil; /** * Content filter for GIF's. @@ -29,11 +28,12 @@ public class GIFFilter implements ContentDataFilter { { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'7', (byte)'a' }; static final byte[] gif89aHeader = { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a' }; - - + + @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { DataInputStream dis = new DataInputStream(input); try { // Check the header diff --git a/src/freenet/client/filter/GenericReadFilterCallback.java b/src/freenet/client/filter/GenericReadFilterCallback.java index c2186ddf82c..f7815fa9a76 100644 --- a/src/freenet/client/filter/GenericReadFilterCallback.java +++ b/src/freenet/client/filter/GenericReadFilterCallback.java @@ -62,6 +62,10 @@ public void shouldUpdate(){ }); } + public GenericReadFilterCallback(URI uri, FoundURICallback cb, LinkFilterExceptionProvider linkFilterExceptionProvider) { + this(uri, cb, null, linkFilterExceptionProvider); + } + public GenericReadFilterCallback(URI uri, FoundURICallback cb,TagReplacerCallback trc, LinkFilterExceptionProvider linkFilterExceptionProvider) { this.baseURI = uri; this.cb = cb; @@ -150,30 +154,11 @@ public String processURI(String u, String overrideType, boolean forBaseHref, boo throw new CommentException(l10n("couldNotParseURIWithError", "error", e1.getMessage())); } String path = uri.getPath(); - + HTTPRequest req = new HTTPRequestImpl(uri, "GET"); if (path != null) { if (path.equals("/") && req.isParameterSet("newbookmark") && !forBaseHref) { - // allow links to the root to add bookmarks - String bookmark_key = req.getParam("newbookmark"); - String bookmark_desc = req.getParam("desc"); - String bookmark_activelink = req.getParam("hasAnActivelink", ""); - - try { - FreenetURI furi = new FreenetURI(bookmark_key); - bookmark_key = furi.toString(); - bookmark_desc = URLEncoder.encode(bookmark_desc, "UTF-8"); - } catch (UnsupportedEncodingException e) { - // impossible, UTF-8 is always supported - } catch (MalformedURLException e) { - throw new CommentException("Invalid Freenet URI: " + e); - } - - String url = "/?newbookmark="+bookmark_key+"&desc="+bookmark_desc; - if (bookmark_activelink.equals("true")) { - url = url + "&hasAnActivelink=true"; - } - return url; + return processBookmark(req); } else if(path.startsWith(StaticToadlet.ROOT_URL)) { // @see bug #2297 return path; @@ -275,22 +260,52 @@ public String processURI(String u, String overrideType, boolean forBaseHref, boo throw new CommentException(l10n("protocolNotEscaped", "protocol", uri.getScheme())); } } - + @Override - public String makeURIAbsolute(String uri) throws URISyntaxException{ - return baseURI.resolve(URIPreEncoder.encodeURI(uri).normalize()).toASCIIString(); + public String processURI(String u, String overrideType, String forceHostPort) + throws CommentException { + URI uri; + String filtered; + try { + filtered = processURI(makeURIAbsolute(u), overrideType, true, false); + uri = URIPreEncoder.encodeURI(filtered).normalize(); + } catch (URISyntaxException e1) { + if(logMINOR) Logger.minor(this, "Failed to parse URI: "+e1); + throw new CommentException(l10n("couldNotParseURIWithError", "error", e1.getMessage())); + } + if (uri.getHost() == null) { + String scheme = uri.getScheme() != null ? uri.getScheme() : "http"; + return scheme + "://" + forceHostPort + filtered; + } + return filtered; } - public String makeURIAbsoluteWithHostAndPort(String uri) throws URISyntaxException{ - // FIXME: this breaks abstraction really badly and depends on implementation details. - String fproxyAuthority = ""; - if (linkFilterExceptionProvider instanceof SimpleToadletServer) { - fproxyAuthority = ((SimpleToadletServer) linkFilterExceptionProvider).getURL(); - if (fproxyAuthority.endsWith("/")) { - fproxyAuthority = fproxyAuthority.substring(0, fproxyAuthority.length() - 1); - } + private String processBookmark(HTTPRequest req) throws CommentException { + // allow links to the root to add bookmarks + String bookmark_key = req.getParam("newbookmark"); + String bookmark_desc = req.getParam("desc"); + String bookmark_activelink = req.getParam("hasAnActivelink", ""); + + try { + FreenetURI furi = new FreenetURI(bookmark_key); + bookmark_key = furi.toString(); + bookmark_desc = URLEncoder.encode(bookmark_desc, "UTF-8"); + } catch (UnsupportedEncodingException e) { + // impossible, UTF-8 is always supported + } catch (MalformedURLException e) { + throw new CommentException("Invalid Freenet URI: " + e); } - return fproxyAuthority + makeURIAbsolute(uri); + + String url = "/?newbookmark="+bookmark_key+"&desc="+bookmark_desc; + if (bookmark_activelink.equals("true")) { + url = url + "&hasAnActivelink=true"; + } + return url; + } + + @Override + public String makeURIAbsolute(String uri) throws URISyntaxException{ + return baseURI.resolve(URIPreEncoder.encodeURI(uri).normalize()).toASCIIString(); } private static String l10n(String key, String pattern, String value) { diff --git a/src/freenet/client/filter/HTMLFilter.java b/src/freenet/client/filter/HTMLFilter.java index 2bd3b026989..57938f92246 100644 --- a/src/freenet/client/filter/HTMLFilter.java +++ b/src/freenet/client/filter/HTMLFilter.java @@ -62,8 +62,9 @@ public class HTMLFilter implements ContentDataFilter, CharsetExtractor { public static int metaRefreshRedirectMinInterval = 30; @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { if(cb == null) cb = new NullFilterCallback(); logMINOR = Logger.shouldLog(LogLevel.MINOR, this); logDEBUG = Logger.shouldLog(LogLevel.DEBUG, this); diff --git a/src/freenet/client/filter/JPEGFilter.java b/src/freenet/client/filter/JPEGFilter.java index 134c989bafe..84dd1c713be 100644 --- a/src/freenet/client/filter/JPEGFilter.java +++ b/src/freenet/client/filter/JPEGFilter.java @@ -68,8 +68,9 @@ public void shouldUpdate(){ }; @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { readFilter(input, output, charset, otherParams, cb, deleteComments, deleteExif); output.flush(); } diff --git a/src/freenet/client/filter/M3UFilter.java b/src/freenet/client/filter/M3UFilter.java index d090d0123f0..e205cf73cdc 100644 --- a/src/freenet/client/filter/M3UFilter.java +++ b/src/freenet/client/filter/M3UFilter.java @@ -61,8 +61,9 @@ public class M3UFilter implements ContentDataFilter { // { (byte)'#', (byte)'E', (byte)'X', (byte)'T', (byte)'M', (byte)'3', (byte)'U' }; @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { // TODO: Check the header whether this is an ext m3u. // TODO: Check the EXTINF headers instead of killing comments. // Check whether the line is a comment @@ -122,7 +123,6 @@ public void readFilter(InputStream input, OutputStream output, String charset, H String filtered; try { String subMimetype = ContentFilter.mimeTypeForSrc(uriold); - filtered = cb.processURI(uriold, subMimetype); // add prefix for the host name // for absolute path names, // because otherwise external @@ -139,13 +139,7 @@ public void readFilter(InputStream input, OutputStream output, String charset, H // strip the absolute path again, // so mirroring should not be // impaired. - if (cb instanceof GenericReadFilterCallback) { - try { - filtered = ((GenericReadFilterCallback)cb).makeURIAbsoluteWithHostAndPort(filtered); - } catch (URISyntaxException e) { - filtered = badUriReplacement; - } - } + filtered = cb.processURI(uriold, subMimetype, hostPort); // allow transparent pass through // for all but the largest files, // but not for external diff --git a/src/freenet/client/filter/MP3Filter.java b/src/freenet/client/filter/MP3Filter.java index 7e043b1a12f..a959175b124 100644 --- a/src/freenet/client/filter/MP3Filter.java +++ b/src/freenet/client/filter/MP3Filter.java @@ -24,7 +24,7 @@ public class MP3Filter implements ContentDataFilter { // http://www.codeproject.com/KB/audio-video/mpegaudioinfo.aspx // http://www.id3.org/mp3Frame // http://www.mp3-converter.com/mp3codec/ - + static final short[] [] [] bitRateIndices = { //Version 2.5 { @@ -88,12 +88,13 @@ public class MP3Filter implements ContentDataFilter { }; @Override - public void readFilter(InputStream input, OutputStream output, - String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, + String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { filter(input, output); } - + public void filter(InputStream input, OutputStream output) throws DataFilterException, IOException { //FIXME: Add support for free formatted files(highly uncommon) DataInputStream in = new DataInputStream(input); @@ -235,7 +236,7 @@ public void filter(InputStream input, OutputStream output) throws DataFilterExce if(totalFrames == 0) throw new DataFilterException(l10n("bogusMP3NoFrames"), l10n("bogusMP3NoFrames"), l10n("bogusMP3NoFramesExplanation")); } - + out.flush(); Logger.normal(this, totalFrames+" frames, of which "+totalCRCs+" had a CRC"); return; @@ -245,7 +246,7 @@ public void filter(InputStream input, OutputStream output) throws DataFilterExce private String l10n(String key) { return NodeL10n.getBase().getString("MP3Filter."+key); } - + public static void main(String[] args) throws DataFilterException, IOException { File f = new File(args[0]); FileInputStream fis = new FileInputStream(f); @@ -258,7 +259,7 @@ public static void main(String[] args) throws DataFilterException, IOException { // fis.read(buf); // fis.read(buf); // fis.read(buf); - filter.readFilter(fis, fos, null, null, null); + filter.readFilter(fis, fos, null, null, null, null); fis.close(); fos.close(); } diff --git a/src/freenet/client/filter/NullFilterCallback.java b/src/freenet/client/filter/NullFilterCallback.java index a98d8602944..2cfcccd7330 100644 --- a/src/freenet/client/filter/NullFilterCallback.java +++ b/src/freenet/client/filter/NullFilterCallback.java @@ -31,7 +31,13 @@ public String processForm(String method, String action) { public String processURI(String uri, String overrideType, boolean noRelative, boolean inline) throws CommentException { return null; } - + + @Override + public String processURI(String uri, String overrideType, String forceHostPort) + throws CommentException { + return null; + } + @Override public String processTag(ParsedTag pt) { return null; diff --git a/src/freenet/client/filter/OggFilter.java b/src/freenet/client/filter/OggFilter.java index 49fa9631b0b..475f811fd0f 100644 --- a/src/freenet/client/filter/OggFilter.java +++ b/src/freenet/client/filter/OggFilter.java @@ -29,9 +29,10 @@ */ public class OggFilter implements ContentDataFilter{ - public void readFilter(InputStream input, OutputStream output, - String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, + String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { HashMap streamFilters = new HashMap(); LinkedList splitPages = new LinkedList(); CountedOutputStream out = new CountedOutputStream(output); @@ -130,7 +131,7 @@ public void writeFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, FilterCallback cb) throws DataFilterException, IOException { // TODO Auto-generated method stub - + } private static String l10n(String key) { diff --git a/src/freenet/client/filter/PNGFilter.java b/src/freenet/client/filter/PNGFilter.java index d8a01c2d518..308d1737fe0 100644 --- a/src/freenet/client/filter/PNGFilter.java +++ b/src/freenet/client/filter/PNGFilter.java @@ -74,8 +74,9 @@ public void shouldUpdate(){ } @Override - public void readFilter(InputStream input, OutputStream output, String charset, HashMap otherParams, - FilterCallback cb) throws DataFilterException, IOException { + public void readFilter( + InputStream input, OutputStream output, String charset, HashMap otherParams, + String hostPort, FilterCallback cb) throws DataFilterException, IOException { readFilter(input, output, charset, otherParams, cb, deleteText, deleteTimestamp, checkCRCs); output.flush(); } @@ -219,7 +220,7 @@ public void readFilter(InputStream input, OutputStream output, String charset, H int interlaceMethod = chunkData[12]; if(interlaceMethod < 0 || interlaceMethod >1) throwError("Invalid InterlaceMethod", "Invalid InterlaceMethod! "+interlaceMethod); - + if(logMINOR) Logger.minor(this, "Info from IHDR: width="+width+"px height="+height+"px bitDepth="+bitDepth+ " colourType="+colourType+" compressionMethod="+compressionMethod+" filterMethod="+ @@ -344,7 +345,7 @@ public static void main(String arg[]) throws Throwable { Logger.setupStdoutLogging(LogLevel.MINOR, ""); ContentFilter.filter(inputStream, outputStream, "image/png", - new URI("http://127.0.0.1:8888/"), null, null, null); + new URI("http://127.0.0.1:8888/"), null, null, null, null); } finally { Closer.close(inputStream); Closer.close(outputStream); diff --git a/src/freenet/client/filter/URIProcessor.java b/src/freenet/client/filter/URIProcessor.java index e44ab798176..c6d3617a1f0 100644 --- a/src/freenet/client/filter/URIProcessor.java +++ b/src/freenet/client/filter/URIProcessor.java @@ -10,10 +10,11 @@ public interface URIProcessor { /** * Makes an URI absolute - * + * * @param uri * - The uri to be absolutize * @return The absolute URI */ public String makeURIAbsolute(String uri) throws URISyntaxException; + } diff --git a/src/freenet/clients/fcp/FilterMessage.java b/src/freenet/clients/fcp/FilterMessage.java index ed3459d9bea..c5db4f9c7d5 100644 --- a/src/freenet/clients/fcp/FilterMessage.java +++ b/src/freenet/clients/fcp/FilterMessage.java @@ -24,12 +24,12 @@ /** * Message for testing the content filter on a file. Server will respond with a FilterResultMessage. - * + * * Filter * Identifier=filter1 // identifier * Operation=BOTH // READ/WRITE/BOTH (ignored for now) * MimeType=text/html // required if DataSource=DIRECT - * + * * DataSource=DISK // read a file from disk * Filename=/home/bob/file.html // path to the file * End @@ -47,7 +47,7 @@ public class FilterMessage extends DataCarryingMessage { private final String mimeType; private final long dataLength; private final String filename; - + private final BucketFactory bf; public FilterMessage(SimpleFieldSet fs, BucketFactory bf) throws MessageInvalidException { @@ -191,7 +191,7 @@ public void run(FCPConnectionHandler handler, Node node) throws MessageInvalidEx FilterResultMessage response = new FilterResultMessage(identifier, resultCharset, resultMimeType, unsafe, resultBucket); handler.send(response); } - + private FilterStatus applyFilter(InputStream input, OutputStream output, ClientContext clientContext) throws MessageInvalidException, UnsafeContentTypeException, IOException { URI fakeUri; try { @@ -201,9 +201,9 @@ private FilterStatus applyFilter(InputStream input, OutputStream output, ClientC throw new MessageInvalidException(ProtocolErrorMessage.INTERNAL_ERROR, e.toString(), identifier, false); } //TODO: check operation, once ContentFilter supports write filtering - return ContentFilter.filter(input, output, mimeType, fakeUri, null, null, null, clientContext.linkFilterExceptionProvider); + return ContentFilter.filter(input, output, mimeType, fakeUri, null, null, null, null, clientContext.linkFilterExceptionProvider); } - + private String bestGuessMimeType(String filename) { String guessedMimeType = null; diff --git a/src/freenet/clients/http/ContentFilterToadlet.java b/src/freenet/clients/http/ContentFilterToadlet.java index e3e4f956938..8d4f5172c46 100644 --- a/src/freenet/clients/http/ContentFilterToadlet.java +++ b/src/freenet/clients/http/ContentFilterToadlet.java @@ -30,7 +30,7 @@ */ public class ContentFilterToadlet extends Toadlet implements LinkEnabledCallback { public final static String PATH = "/filterfile/"; - + /** * What to do the the output from the content filter. */ @@ -38,19 +38,19 @@ public static enum ResultHandling { DISPLAY, SAVE } - + private final NodeClientCore core; - + public ContentFilterToadlet(HighLevelSimpleClient client, NodeClientCore clientCore) { super(client); this.core = clientCore; } - + @Override public String path() { return PATH; } - + public boolean isEnabled (ToadletContext ctx) { if(ctx == null) return false; boolean fullAccess = !container.publicGatewayMode() || ctx.isAllowedFullAccess(); @@ -63,9 +63,9 @@ public void handleMethodGET(URI uri, final HTTPRequest request, final ToadletCon sendUnauthorizedPage(ctx); return; } - + PageMaker pageMaker = ctx.getPageMaker(); - + PageNode page = pageMaker.getPageNode(l10n("pageTitle"), ctx); HTMLNode pageNode = page.outer; HTMLNode contentNode = page.content; @@ -73,10 +73,10 @@ public void handleMethodGET(URI uri, final HTTPRequest request, final ToadletCon contentNode.addChild(ctx.getAlertManager().createSummary()); contentNode.addChild(createContent(pageMaker, ctx)); - + writeHTMLReply(ctx, 200, "OK", null, pageNode.generate()); } - + public void handleMethodPOST(URI uri, final HTTPRequest request, final ToadletContext ctx) throws ToadletContextClosedException, IOException, RedirectException { if (container.publicGatewayMode() && !ctx.isAllowedFullAccess()) { @@ -120,14 +120,14 @@ public void handleMethodPOST(URI uri, final HTTPRequest request, final ToadletCo request.freeParts(); } } - + private HTMLNode createContent(PageMaker pageMaker, ToadletContext ctx) { InfoboxNode infobox = pageMaker.getInfobox(l10n("filterFile"), "filter-file", true); HTMLNode filterBox = infobox.outer; HTMLNode filterContent = infobox.content; HTMLNode filterForm = ctx.addFormChild(filterContent, PATH, "filterForm"); - + // apply read filter, write filter, or both //TODO: radio buttons to select, once ContentFilter supports write filtering filterForm.addChild("input", @@ -146,7 +146,7 @@ private HTMLNode createContent(PageMaker pageMaker, ToadletContext ctx) { filterForm.addChild("#", l10n("saveResultLabel")); filterForm.addChild("br"); filterForm.addChild("br"); - + // mime type filterForm.addChild("#", l10n("mimeTypeLabel") + ": "); filterForm.addChild("input", diff --git a/src/freenet/clients/http/FProxyFetchInProgress.java b/src/freenet/clients/http/FProxyFetchInProgress.java index 3a4aa4bb989..2a95ded675d 100644 --- a/src/freenet/clients/http/FProxyFetchInProgress.java +++ b/src/freenet/clients/http/FProxyFetchInProgress.java @@ -260,7 +260,7 @@ else if(fctx.overrideMIME != null && !mimeType.equals(fctx.overrideMIME)) { output = context.tempBucketFactory.makeBucket(-1); is = data.getInputStream(); os = output.getOutputStream(); - ContentFilter.filter(is, os, fullMimeType, uri.toURI("/"), null, null, fctx.charset, context.linkFilterExceptionProvider); + ContentFilter.filter(is, os, fullMimeType, uri.toURI("/"), fctx.host, null, null, fctx.charset, context.linkFilterExceptionProvider); is.close(); is = null; os.close(); diff --git a/src/freenet/clients/http/FProxyToadlet.java b/src/freenet/clients/http/FProxyToadlet.java index 20d7823154d..e62d5b4b5f6 100644 --- a/src/freenet/clients/http/FProxyToadlet.java +++ b/src/freenet/clients/http/FProxyToadlet.java @@ -445,7 +445,6 @@ private void innerHandleMethodGET(URI uri, HTTPRequest httprequest, ToadletConte String ks = uri.getPath(); - String authority = httprequest.getHeader("host"); MultiValueTable headers = ctx.getHeaders(); final String ua = headers.get("user-agent"); final String accept = headers.get("accept"); @@ -581,7 +580,7 @@ private void innerHandleMethodGET(URI uri, HTTPRequest httprequest, ToadletConte } FetchContext fctx = getFetchContext(maxSize); - fctx.host = authority; + fctx.host = ctx.getHeaders().get("host"); // max-size=-1 => use default maxSize = fctx.maxOutputLength; diff --git a/src/freenet/io/SSLNetworkInterface.java b/src/freenet/io/SSLNetworkInterface.java index 37a14fd3ec0..8b343352aa1 100644 --- a/src/freenet/io/SSLNetworkInterface.java +++ b/src/freenet/io/SSLNetworkInterface.java @@ -72,11 +72,10 @@ protected ServerSocket createServerSocket() throws IOException { return serverSocket; } - private static final Set ALLOWED_CIPHERS = new HashSet(Arrays.asList(new String[] { + private static final Set ALLOWED_CIPHERS = new HashSet(Arrays.asList( "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", - "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" - })); + "TLS_EMPTY_RENEGOTIATION_INFO_SCSV")); } diff --git a/src/freenet/node/NodeClientCore.java b/src/freenet/node/NodeClientCore.java index fdef93e0d18..98698dec3d6 100644 --- a/src/freenet/node/NodeClientCore.java +++ b/src/freenet/node/NodeClientCore.java @@ -116,10 +116,10 @@ public class NodeClientCore implements Persistable { * When processing the POST-request, you MUST validate that the received password matches this variable. If it does not, you must NOT process the request. * In particular, you must NOT modify anything.

*

To produce a form which already contains the password, use {@link PluginRespirator#addFormChild(freenet.support.HTMLNode, String, String)}.

- *

To validate that the right password was received, use {@link WebInterfaceToadlet#isFormPassword(HTTPRequest)}.

+ *

To validate that the right password was received, use {@link WebInterfaceToadlet#isFormPassword(HTTPRequest)}.

*/ public final String formPassword; - + final ProgramDirectory downloadsDir; private File[] downloadAllowedDirs; private boolean includeDownloadDir; @@ -1980,7 +1980,7 @@ public String getMyName() { public FilterCallback createFilterCallback(URI uri, FoundURICallback cb) { if(logMINOR) Logger.minor(this, "Creating filter callback: " + uri + ", " + cb); - return new GenericReadFilterCallback(uri, cb,null, toadletContainer); + return new GenericReadFilterCallback(uri, cb, toadletContainer); } public int maxBackgroundUSKFetchers() { diff --git a/src/freenet/node/TextModeClientInterface.java b/src/freenet/node/TextModeClientInterface.java index da468c79dbb..d8a8040db72 100644 --- a/src/freenet/node/TextModeClientInterface.java +++ b/src/freenet/node/TextModeClientInterface.java @@ -449,7 +449,7 @@ public void run() { try { inputStream = input.getInputStream(); outputStream = output.getOutputStream(); - ContentFilter.filter(inputStream, outputStream, "text/html", new URI("http://127.0.0.1:8888/"), null, null, null, core.getLinkFilterExceptionProvider()); + ContentFilter.filter(inputStream, outputStream, "text/html", new URI("http://127.0.0.1:8888/"), null, null, null, null, core.getLinkFilterExceptionProvider()); inputStream.close(); inputStream = null; outputStream.close(); diff --git a/test/freenet/client/filter/BMPFilterTest.java b/test/freenet/client/filter/BMPFilterTest.java index 2c1e56d9788..518980590ec 100644 --- a/test/freenet/client/filter/BMPFilterTest.java +++ b/test/freenet/client/filter/BMPFilterTest.java @@ -125,7 +125,7 @@ private Bucket filterImage(Bucket input, Class expected) { } try { - objBMPFilter.readFilter(inStream, outStream, "", null, null); + objBMPFilter.readFilter(inStream, outStream, "", null, null, null); if(expected != null) { fail("Filter didn't throw expected exception"); diff --git a/test/freenet/client/filter/CSSParserTest.java b/test/freenet/client/filter/CSSParserTest.java index 953cf1d6730..e88ac01d7aa 100644 --- a/test/freenet/client/filter/CSSParserTest.java +++ b/test/freenet/client/filter/CSSParserTest.java @@ -15,14 +15,7 @@ import java.util.Map.Entry; import junit.framework.TestCase; -import freenet.client.filter.CSSParser; -import freenet.client.filter.CSSReadFilter; -import freenet.client.filter.ContentFilter; -import freenet.client.filter.DataFilterException; -import freenet.client.filter.GenericReadFilterCallback; -import freenet.client.filter.FilterMIMEType; -import freenet.client.filter.UnsafeContentTypeException; -import freenet.client.filter.UnsupportedCharsetInFilterException; + import freenet.client.filter.CharsetExtractor.BOMDetection; import freenet.client.filter.ContentFilter.FilterStatus; import freenet.l10n.NodeL10n; @@ -188,7 +181,7 @@ public class CSSParserTest extends TestCase { CSS3_SELECTOR.put("h1:nth-last-of-type(odd) {}","h1:nth-last-of-type(odd)"); CSS3_SELECTOR.put("h1:nth-last-of-type(even) {}","h1:nth-last-of-type(even)"); } - + private final static HashSet CSS3_BAD_SELECTOR= new HashSet(); static { @@ -1097,7 +1090,8 @@ private void getCharsetTest(String charset, String family) throws DataFilterExce assertTrue("Charset detected \""+detectedCharset+"\" should be \""+charset+"\" or \""+family+"\" from getCharsetByBOM", detectedCharset == null || charset.equalsIgnoreCase(detectedCharset) || (family != null && family.equalsIgnoreCase(detectedCharset))); detectedCharset = ContentFilter.detectCharset(bytes, bytes.length, cssMIMEType, null); assertTrue("Charset detected \""+detectedCharset+"\" should be \""+charset+"\" from ContentFilter.detectCharset bom=\""+bomCharset+"\"", charset.equalsIgnoreCase(detectedCharset)); - FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4oobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), null, null, null); + FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4oobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), + null, null, null, null); inputStream.close(); outputStream.close(); assertEquals("text/css", filterStatus.mimeType); @@ -1121,7 +1115,8 @@ private void charsetTestUnsupported(String charset) throws DataFilterException, detectedCharset = ContentFilter.detectCharset(bytes, bytes.length, cssMIMEType, null); assertTrue("Charset detected \""+detectedCharset+"\" should be unknown testing unsupported charset \""+charset+"\" from ContentFilter.detectCharset bom=\""+bomCharset+"\"", charset == null || "utf-8".equalsIgnoreCase(detectedCharset)); try { - FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), null, null, null); + FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), + null,null, null, null); // It is safe to return utf-8, as long as we clobber the actual content; utf-8 is the default, but other stuff decoded to it is unlikely to be coherent... assertTrue("ContentFilter.filter() returned charset \""+filterStatus.charset+"\" should be unknown testing unsupported charset \""+charset+"\"", filterStatus.charset.equalsIgnoreCase(charset) || filterStatus.charset.equalsIgnoreCase("utf-8"));//If we switch to JUnit 4, this may be replaced with an assertThat assertEquals("text/css", filterStatus.mimeType); @@ -1153,7 +1148,8 @@ private void testUseMaybeCharset(String charset) throws URISyntaxException, Unsa Bucket outputBucket = new ArrayBucket(); InputStream inputStream = inputBucket.getInputStream(); OutputStream outputStream = outputBucket.getOutputStream(); - FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), null, null, charset); + FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), + null,null, null, charset); inputStream.close(); outputStream.close(); assertEquals(charset, filterStatus.charset); diff --git a/test/freenet/client/filter/ContentFilterTest.java b/test/freenet/client/filter/ContentFilterTest.java index cc4ab529b8e..60f32d795ea 100644 --- a/test/freenet/client/filter/ContentFilterTest.java +++ b/test/freenet/client/filter/ContentFilterTest.java @@ -282,7 +282,9 @@ public void testEvilCharset() throws IOException { FileOutputStream fos; try { ArrayBucket out = new ArrayBucket(); - filter.readFilter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "UTF-16", null, null); + filter.readFilter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "UTF-16", null, + null, + null); fos = new FileOutputStream("output.utf16"); fos.write(out.toByteArray()); fos.close(); @@ -298,7 +300,7 @@ public void testEvilCharset() throws IOException { } try { ArrayBucket out = new ArrayBucket(); - FilterStatus fo = ContentFilter.filter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "text/html", null, null); + FilterStatus fo = ContentFilter.filter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "text/html", null, null, null); fos = new FileOutputStream("output.filtered"); fos.write(out.toByteArray()); fos.close(); @@ -340,7 +342,8 @@ public static String HTMLFilter(String data, boolean alt) throws Exception { ArrayBucket output = new ArrayBucket(); InputStream inputStream = input.getInputStream(); OutputStream outputStream = output.getOutputStream(); - ContentFilter.filter(inputStream, outputStream, typeName, baseURI, null, null, null); + ContentFilter.filter(inputStream, outputStream, typeName, baseURI, + null,null, null, null); inputStream.close(); outputStream.close(); returnValue = output.toString(); diff --git a/test/freenet/client/filter/GIFFilterTest.java b/test/freenet/client/filter/GIFFilterTest.java index 59cc45f8be4..20557dc0ee2 100644 --- a/test/freenet/client/filter/GIFFilterTest.java +++ b/test/freenet/client/filter/GIFFilterTest.java @@ -118,7 +118,7 @@ public void testReject() throws IOException { ContentDataFilter filter = new GIFFilter(); try { - filter.readFilter(inStream, outStream, "", null, null); + filter.readFilter(inStream, outStream, "", null, null, null); fail("Filter did not fail on reject sample " + reject); } catch (DataFilterException e) { // Expected. @@ -163,7 +163,7 @@ private static Bucket filterGIF(Bucket input) throws IOException { try (InputStream inStream = input.getInputStream(); OutputStream outStream = output.getOutputStream()) { - filter.readFilter(inStream, outStream, "", null, null); + filter.readFilter(inStream, outStream, "", null, null, null); } return output; diff --git a/test/freenet/client/filter/JPEGFilterTest.java b/test/freenet/client/filter/JPEGFilterTest.java index 57feabb1005..93985edda85 100644 --- a/test/freenet/client/filter/JPEGFilterTest.java +++ b/test/freenet/client/filter/JPEGFilterTest.java @@ -22,7 +22,9 @@ public void testThatAThumbnailExtensionCodeIsPreserved() throws IOException { byte[] jpegFile = createValidJpegFileWithThumbnail(); InputStream inputStream = new ByteArrayInputStream(jpegFile); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - jpegFilter.readFilter(inputStream, outputStream, "UTF-8", new HashMap(), new NullFilterCallback()); + jpegFilter.readFilter(inputStream, outputStream, "UTF-8", new HashMap(), + null, + new NullFilterCallback()); byte[] filteredJpegFile = outputStream.toByteArray(); assertTrue(Arrays.equals(jpegFile, filteredJpegFile)); } diff --git a/test/freenet/client/filter/M3UFilterTest.java b/test/freenet/client/filter/M3UFilterTest.java index 5c54f4b4cef..32bcc8bfb07 100644 --- a/test/freenet/client/filter/M3UFilterTest.java +++ b/test/freenet/client/filter/M3UFilterTest.java @@ -1,9 +1,7 @@ package freenet.client.filter; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.io.InputStream; -import java.io.ByteArrayOutputStream; import java.net.URI; import java.net.URISyntaxException; @@ -12,7 +10,6 @@ import freenet.support.api.Bucket; import freenet.support.io.ArrayBucket; import freenet.support.io.BucketTools; -import freenet.support.io.NullBucket; public class M3UFilterTest extends TestCase { protected static String[][] testPlaylists = { @@ -21,9 +18,10 @@ public class M3UFilterTest extends TestCase { }; private static final String BASE_URI_PROTOCOL = "http"; + private static final String HOST_PORT = "localhost:8888"; private static final String BASE_URI_CONTENT = "localhost:8888"; private static final String BASE_KEY = "USK@0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/FakeM3UHostingFreesite/23/"; - private static final String BASE_URI = BASE_URI_PROTOCOL+"://"+BASE_URI_CONTENT+'/'+BASE_KEY; + private static final String BASE_URI = '/'+BASE_KEY; public void testSuiteTest() throws IOException { M3UFilter filter = new M3UFilter(); @@ -49,7 +47,7 @@ public void testSuiteTest() throws IOException { try { filter.readFilter(ibo.getInputStream(), ibprocessed.getOutputStream(), "UTF-8", null, - new GenericReadFilterCallback(new URI(BASE_URI), null, null, null)); + HOST_PORT, new GenericReadFilterCallback(new URI(BASE_URI), null, null, null)); String result = ibprocessed.toString(); assertTrue(original + " should be filtered as " + correct + " but was filtered as\n" + result + "\ninstead of the correct\n" + bucketToString((ArrayBucket)ibc), result.equals(bucketToString((ArrayBucket)ibc))); diff --git a/test/freenet/client/filter/MP3FilterTest.java b/test/freenet/client/filter/MP3FilterTest.java index 5782f719f5e..df9aed0d17e 100644 --- a/test/freenet/client/filter/MP3FilterTest.java +++ b/test/freenet/client/filter/MP3FilterTest.java @@ -111,7 +111,7 @@ private static Bucket filterMP3(Bucket input) { } try { - filter.readFilter(inStream, outStream, "", null, null); + filter.readFilter(inStream, outStream, "", null, null, null); } catch (Exception e) { throw new AssertionError("Unexpected exception in the content filter.", e); } diff --git a/test/freenet/client/filter/OggFilterTest.java b/test/freenet/client/filter/OggFilterTest.java index a427d8d3f32..a9d7f19c9ba 100644 --- a/test/freenet/client/filter/OggFilterTest.java +++ b/test/freenet/client/filter/OggFilterTest.java @@ -20,7 +20,7 @@ public void testEmptyOutputRaisesException() throws IOException { DataInputStream input = new DataInputStream(getClass().getResourceAsStream("./ogg/invalid_header.ogg")); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { - filter.readFilter(input, output, null, null, null); + filter.readFilter(input, output, null, null, null, null); fail("Expected Exception not caught. Output size: "+output.toByteArray().length); } catch(DataFilterException e) {} } @@ -29,7 +29,7 @@ public void testValidSubPageStripped() throws IOException, DataFilterException { DataInputStream input = new DataInputStream(getClass().getResourceAsStream("./ogg/contains_subpages.ogg")); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { - filter.readFilter(input, output, null, null, null); + filter.readFilter(input, output, null, null, null, null); } catch(DataFilterException e) {} Assert.assertTrue(Arrays.equals(new byte[]{}, output.toByteArray())); input.close(); diff --git a/test/freenet/client/filter/PNGFilterTest.java b/test/freenet/client/filter/PNGFilterTest.java index 24f870beb5f..3bd79a48897 100644 --- a/test/freenet/client/filter/PNGFilterTest.java +++ b/test/freenet/client/filter/PNGFilterTest.java @@ -112,7 +112,9 @@ public void testSuiteTest() throws IOException { } try { - filter.readFilter(ib.getInputStream(), new NullBucket().getOutputStream(), "", null, null); + filter.readFilter(ib.getInputStream(), new NullBucket().getOutputStream(), "", null, + null, + null); assertTrue(filename + " should " + (valid ? "" : "not ") + "be valid", valid); } catch (DataFilterException dfe) { diff --git a/test/freenet/client/filter/m3u/safe.m3u b/test/freenet/client/filter/m3u/safe.m3u index 0fcaa546b11..e4c3727f913 100644 --- a/test/freenet/client/filter/m3u/safe.m3u +++ b/test/freenet/client/filter/m3u/safe.m3u @@ -15,7 +15,7 @@ http://127.0.0.1:8888/CHK@qtpnyOzrg~aiAbnw6AoKbX8ZlTCwznjY4G1y-JiiCgg,b0wkEgRPKW http://127.0.0.1:8888/CHK@qtpnyOzrg~aiAbnw6AoKbX8ZlTCwznjY4G1y-JiiCgg,b0wkEgRPKWMvedueAKLkyv0S83xOrGUT4S7FaN5J3nI,AAMC--8/next.m3u /CHK@qtpnyOzrg~aiAbnw6AoKbX8ZlTCwznjY4G1y-JiiCgg,b0wkEgRPKWMvedueAKLkyv0S83xOrGUT4S7FaN5J3nI,AAMC--8/Infinite-Hands-free-software.mp3 /CHK@qtpnyOzrg~aiAbnw6AoKbX8ZlTCwznjY4G1y-JiiCgg,b0wkEgRPKWMvedueAKLkyv0S83xOrGUT4S7FaN5J3nI,AAMC--8/next.m3u -CHK@qtpnyOzrg~aiAbnw6AoKbX8ZlTCwznjY4G1y-JiiCgg,b0wkEgRPKWMvedueAKLkyv0S83xOrGUT4S7FaN5J3nI,AAMC--8/Infinite-Hands-free-software.mp3 +/CHK@qtpnyOzrg~aiAbnw6AoKbX8ZlTCwznjY4G1y-JiiCgg,b0wkEgRPKWMvedueAKLkyv0S83xOrGUT4S7FaN5J3nI,AAMC--8/Infinite-Hands-free-software.mp3 # https://soundcloud.com/conniptions/mr-tsa-man-coming-into-los cc by-sa diff --git a/test/freenet/client/filter/m3u/unsafe_madesafe.m3u b/test/freenet/client/filter/m3u/unsafe_madesafe.m3u index 37d963f8be0..d0f832da98f 100644 --- a/test/freenet/client/filter/m3u/unsafe_madesafe.m3u +++ b/test/freenet/client/filter/m3u/unsafe_madesafe.m3u @@ -1,4 +1,4 @@ -http://localhost:8888/external-link/?_CHECKED_HTTP_=http://betray.user/simplepathname.mp3 +#bad-uri-removed #bad-uri-removed #bad-uri-removed http://localhost:8888/USK@0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/FakeM3UHostingFreesite/23/simplepathname.mp3?type=audio/mpeg&max-size=115343360