Class HttpsHelper
java.lang.Object
org.nanonative.nano.services.http.HttpsHelper
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconfigureHttps(Context context, HttpServer server) Configures SSL/TLS for an existing HTTPS server.static SSLContextcreateCustomTrustedSslContext(Context context, List<Path> paths) static HttpServercreateDefaultServer(Context context) Creates a default HTTP server using the configured or fallback port.static HttpServercreateHttpsServer(Context context) Creates an HTTPS server using the configured or fallback port.static SSLContextstatic CertificatereadCertificate(Context context, KeyStore keyStore) Reads an X.509 certificate from a file and inserts it into the given key store.static voidreadKey(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.static voidLoads all entries from an existing keystore into another keystore.
-
Field Details
-
TYPE_PKCS_12
- See Also:
-
TYPE_JCEKS
- See Also:
-
TYPE_JKS
- See Also:
-
TYPE_TLS
- See Also:
-
TYPE_X_509
- See Also:
-
-
Method Details
-
createDefaultServer
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
Creates an HTTPS server using the configured or fallback port. This does not configure the SSL context; callconfigureHttps(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
Configures SSL/TLS for an existing HTTPS server. Loads certificates, keys, and keystores from the context.- Parameters:
context- configuration context with HTTPS-related keysserver- server to configure; must be an instance of HttpsServer
-
readKey
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 contextkeyStore- target key storepassword- key passwordcert- certificate to associate with the private key
-
readCertificate
Reads an X.509 certificate from a file and inserts it into the given key store.- Parameters:
context- configuration contextkeyStore- target key store- Returns:
- the loaded certificate or null if loading failed
-
readKts
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 contextpassword- keystore passwordkeyStore- target key storektsType- keystore payload (e.g., JKS, JCEKS, PKCS12)
-
findDefaultLinuxCaBundle
-
createTrustedSslContext
-
createCustomTrustedSslContext
-