Home / Class/ RevocationServer Class — netty Architecture

RevocationServer Class — netty Architecture

Architecture documentation for the RevocationServer class in RevocationServer.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7182e924_897c_1916_3c7b_3c294ba4f4a0["RevocationServer"]
  472b4c1d_cdef_78a7_ce1c_ab5706b45e49["RevocationServer.java"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|defined in| 472b4c1d_cdef_78a7_ce1c_ab5706b45e49
  060a2846_db89_ebb0_8d22_619b65267204["RevocationServer()"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|method| 060a2846_db89_ebb0_8d22_619b65267204
  b888b869_279d_8665_9465_94cc45f8b927["start()"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|method| b888b869_279d_8665_9465_94cc45f8b927
  b0420ce0_5bee_9c08_61ea_27e0475ed293["register()"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|method| b0420ce0_5bee_9c08_61ea_27e0475ed293
  f8343225_c714_8894_957d_69650478adc0["revoke()"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|method| f8343225_c714_8894_957d_69650478adc0
  20143b9e_3f10_3f9d_9571_610cf718b8a1["URI()"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|method| 20143b9e_3f10_3f9d_9571_610cf718b8a1
  b0ef870e_e513_bcce_79d7_f1b8b7969de4["generateCrl()"]
  7182e924_897c_1916_3c7b_3c294ba4f4a0 -->|method| b0ef870e_e513_bcce_79d7_f1b8b7969de4

Relationship Graph

Source Code

pkitesting/src/main/java/io/netty/pkitesting/RevocationServer.java lines 46–202

public final class RevocationServer {
    private static volatile RevocationServer instance;

    private final HttpServer crlServer;
    private final String crlBaseAddress;
    private final AtomicInteger issuerCounter;
    private final ConcurrentMap<X509Certificate, CrlInfo> issuers;
    private final ConcurrentMap<String, CrlInfo> paths;

    /**
     * Get the shared revocation server instance.
     * This will start the server, if it isn't already running, and bind it to a random port on the loopback address.
     * @return The revocation server instance.
     * @throws Exception If the server failed to start.
     */
    public static RevocationServer getInstance() throws Exception {
        if (instance != null) {
            return instance;
        }
        synchronized (RevocationServer.class) {
            RevocationServer server = instance;
            if (server == null) {
                server = new RevocationServer();
                server.start();
                instance = server;
            }
            return server;
        }
    }

    private RevocationServer() throws Exception {
        // Use the JDK built-in HttpServer to avoid any circular dependencies with Netty itself.
        crlServer = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
        crlBaseAddress = "http://localhost:" + crlServer.getAddress().getPort();
        issuerCounter = new AtomicInteger();
        issuers = new ConcurrentHashMap<>();
        paths = new ConcurrentHashMap<>();
        crlServer.createContext("/", exchange -> {
            if ("GET".equals(exchange.getRequestMethod())) {
                String path = exchange.getRequestURI().getPath();
                CrlInfo info = paths.get(path);
                if (info == null) {
                    exchange.sendResponseHeaders(404, 0);
                    exchange.close();
                    return;
                }
                byte[] crl = generateCrl(info);
                exchange.getResponseHeaders().put("Content-Type", Collections.singletonList("application/pkix-crl"));
                exchange.sendResponseHeaders(200, crl.length);
                try (OutputStream out = exchange.getResponseBody()) {
                    out.write(crl);
                    out.flush();
                }
            } else {
                exchange.sendResponseHeaders(405, 0);
            }
            exchange.close();
        });
    }

    private void start() {
        if (Thread.currentThread().isDaemon()) {
            crlServer.start();
        } else {
            // It's important the CRL server creates a daemon thread,
            // because it's a singleton and won't be stopped except by terminating the JVM.
            // Threads in the ForkJoin common pool are always daemon, and JUnit 5 initializes
            // it anyway, so we can let it call start() for us.
            ForkJoinPool.commonPool().execute(crlServer::start);
        }
    }

    /**
     * Register an issuer with the revocation server.
     * This must be done before CRLs can be served for that issuer, and before any of its certificates can be revoked.
     * @param issuer The issuer to register.
     */
    public void register(X509Bundle issuer) {
        register(issuer, null);
    }

Frequently Asked Questions

What is the RevocationServer class?
RevocationServer is a class in the netty codebase, defined in pkitesting/src/main/java/io/netty/pkitesting/RevocationServer.java.
Where is RevocationServer defined?
RevocationServer is defined in pkitesting/src/main/java/io/netty/pkitesting/RevocationServer.java at line 46.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free