Class HttpsHelper

java.lang.Object
org.nanonative.nano.services.http.HttpsHelper

public class HttpsHelper extends Object
Utility class for configuring and creating HTTP and HTTPS servers using the built-in Java HTTP server APIs. Primarily responsible for setting up SSL contexts and reading certificates/keys from the file system.
  • Field Details

  • Method Details

    • createDefaultServer

      public static HttpServer createDefaultServer(Context context) throws IOException
      Creates a default HTTP server using the configured or fallback port.
      Parameters:
      context - configuration context, expected to provide CONFIG_SERVICE_HTTP_PORT
      Returns:
      an HTTP server bound to the selected port
      Throws:
      IOException - if the server cannot be created
    • createHttpsServer

      public static HttpServer createHttpsServer(Context context) throws IOException
      Creates an HTTPS server using the configured or fallback port. This does not configure the SSL context; call configureHttps(Context, com.sun.net.httpserver.HttpServer) after creation.
      Parameters:
      context - configuration context, expected to provide CONFIG_SERVICE_HTTP_PORT
      Returns:
      an HTTPS server bound to the selected port
      Throws:
      IOException - if the server cannot be created
    • configureHttps

      public static void configureHttps(Context context, HttpServer server)
      Configures SSL/TLS for an existing HTTPS server. Loads certificates, keys, and keystores from the context.
      Parameters:
      context - configuration context with HTTPS-related keys
      server - server to configure; must be an instance of HttpsServer
    • readKey

      public static void readKey(Context context, KeyStore keyStore, char[] password, Certificate cert)
      Reads a private key file (PEM or PKCS#8) and inserts it into the provided key store. Converts keys to PKCS#8 format using OpenSSL if needed.
      Parameters:
      context - configuration context
      keyStore - target key store
      password - key password
      cert - certificate to associate with the private key
    • readCertificate

      public static Certificate readCertificate(Context context, KeyStore keyStore)
      Reads an X.509 certificate from a file and inserts it into the given key store.
      Parameters:
      context - configuration context
      keyStore - target key store
      Returns:
      the loaded certificate or null if loading failed
    • readKts

      public static void readKts(Context context, char[] password, KeyStore keyStore, String ktsType)
      Loads all entries from an existing keystore into another keystore. Typically used to merge user-provided entries into a runtime key store.
      Parameters:
      context - configuration context
      password - keystore password
      keyStore - target key store
      ktsType - keystore payload (e.g., JKS, JCEKS, PKCS12)
    • findDefaultLinuxCaBundle

      public static List<Path> findDefaultLinuxCaBundle()
    • createTrustedSslContext

      public static SSLContext createTrustedSslContext()
    • createCustomTrustedSslContext

      public static SSLContext createCustomTrustedSslContext(Context context, List<Path> paths)