Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

3.1 KB
Raw Blame
package opensuite.core;

import javax.swing.JMenu;

/**
 * The contract every tool implements. The shell knows nothing else about a
 * tool: it asks for a name, some tabs, and optionally some menus, then renders
 * whatever it is given. Adding a tenth tool costs one registration call.
 *
 * <p>A tool loaded at run time, from a jar under Extensions > Installed, runs
 * under the same contract with one more rule: none of its methods is called on
 * the event thread. Each runs on a thread of the extension's own, one at a
 * time, and {@link #tabs()} and {@link #menus()} build their components before
 * anything is put on screen. Anything that has to happen on the event thread
 * is the extension's to post there with {@code SwingUtilities.invokeLater}.
 * {@link #name()} is read once, when the extension loads.
 *
 * <p>A listener the extension registers with the suite is never called on the
 * thread that raised the event: each event is offered to the extension's
 * thread, in order, from a queue of 256. A callback that runs for more than
 * five seconds has the extension marked unresponsive, with new events paused
 * until it is removed or resumed. A saved state may hold only the types a
 * project file admits (the JDK's value and collection types, and the suite's
 * own classes); one that holds anything else is left out when the project is
 * saved, and the extension's Errors say so.
 */
public interface ToolModule {

    /** Lower-case display name used on the tab and in "send to" menus. */
    String name();

    /** Tabs shown inside this tool. One entry means no inner tab bar. */
    Tab[] tabs();

    /** Menus contributed to the suite menu bar, or null for none. */
    default JMenu[] menus() { return null; }

    /** Force an inner tab bar even with a single tab. */
    default boolean alwaysTabbed() { return false; }

    /**
     * Where messages sent to this tool from a "send to" menu go, or null for
     * none. It is read when the tool is loaded at run time, from a jar, and
     * the loader registers it under {@link #name()} and takes it down when
     * the tool leaves. A tool built into the suite is not asked: it calls
     * {@code ctx.registerSink} in {@link #init} instead, as a tool may for a
     * destination under another name; what it registers that way is its own
     * to remove in {@link #shutdown()}.
     */
    default SuiteContext.MessageSink sink() { return null; }

    /** Called once after every tool is registered and the context is live. */
    default void init(SuiteContext ctx) {}

    /** Called when the suite is shutting down. */
    default void shutdown() {}

    /**
     * A serialisable snapshot of this tool's working state, saved with the
     * project. Return null if the tool has nothing worth persisting.
     */
    default java.io.Serializable saveState() { return null; }

    /** Restore a snapshot previously produced by {@link #saveState()}. */
    default void restoreState(java.io.Serializable state) {}

    /** A tab inside a tool: a title and the component to show. */
    record Tab(String title, javax.swing.JComponent component) {}
}