Skip to content

SSL TLS Configuration

sea edited this page May 23, 2023 · 5 revisions

To establish a secured HTTPS connection to your webPDF server, you can add a "TLSContext" to your session´s SessionContext.

Be aware: TLS is the official successor of SSL, the webPDF wsclient library only supports the protocol versions:

  • TLSv1, TLSv1.1, TLSv1.2, TLSv1.3
// Select the TLS protocol used for the connection.
let tlsProtocol: TLSProtocol = TLSProtocol.TLSV1_3;
// Select the cert chains in PEM format
let certificate: Buffer = fs.readFileSync("./someCertificateFile");
// Select the private key in PEM format
let privateKey: Buffer = fs.readFileSync("./someKeyFile");
// PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with a passphrase
let passphrase: string = "passphrase";

// The AgentOptions provide a set of options, that allow to specify the trusted CA certificates, the used security protocol, etc.
let options: AgentOptions = {
   secureProtocol: tlsProtocol,
   cert: certificate,
   key: privateKey,
   passphrase: keystorePassword
};

// The SessionContext allows to set advanced options via setters.
// Make sure, that the provided port (in this example port 8443) actually has been set up as a secure HTTPS port for
// your webPDF server.
let sessionContext: SessionContext = new SessionContext(WebServiceProtocol.REST, new URL("https://localhost:8443/webPDF"));
sessionContext.setTlsContext(new Agent(options));

// Next create the Session via the "SessionFactory".
// Also be aware: If no "AuthProvider" is selected in the "createInstance" Method, this will default to
// the "AnonymousAuthProvider".
try {
   let session: RestSession<RestDocument> = await SessionFactory.createInstance(sessionContext);
   // Do something.
   // don't forget to close your session at the end
   await session.close();
} catch (ResultException ex) {
   // Handle exceptions as you see fit.
}

Clone this wiki locally