Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class ClientCertificate
- Object
- ClientCertificate
A TLS client credential for mutual TLS: a certificate chain and its private
key, presented to a server that asks for one. Given to a WebClient through
WebClient.setClientCertificate(ClientCertificate).
Two encodings, the two a credential is actually delivered in:
- PEM – [#pem(byte[], byte[], String)]: the certificate (leaf first, then any intermediates) and the private key, as the text files a CA or a secrets manager hands out. The key may be in a file of its own or in the same one as the certificate.
- PKCS#12 – [#pkcs12(byte[], String)]: the single
.p12/.pfxarchive holding both, protected by a password.
The bytes are copied in, never written to disk and never logged: toString names the encoding and nothing else, so a credential that reaches a log line by accident carries nothing secret with it.
What each runtime accepts. The packaged binary hands both encodings to
libcurl and OpenSSL, which take every PEM key format OpenSSL reads –
PKCS#8, encrypted PKCS#8 with a passphrase, traditional RSA and EC keys. The
local Java SE runtime reads PKCS#12, and PEM keys in unencrypted PKCS#8
(BEGIN PRIVATE KEY) or traditional RSA (BEGIN RSA PRIVATE KEY) form; any
other PEM key fails there with an IOException that names the conversion,
openssl pkcs8 -topk8 -nocrypt. Prefer PKCS#12 when one credential has to
work identically on both.
Methods
public static ClientCertificate pem(byte[] certificateChain, byte[] privateKey, String passphrase) | A PEM certificate chain and private key. |
public static ClientCertificate pkcs12(byte[] archive, String password) | A PKCS#12 archive holding the certificate chain and its private key. |
public String toString() | The encoding only; the credential itself never reaches a string. |
Inherited methods
Method details
pem
public static ClientCertificate pem(byte[] certificateChain, byte[] privateKey, String passphrase)Parameters
certificateChainbyte[]- the PEM certificate, leaf first, then any intermediates
privateKeybyte[]- the PEM private key, or null when it is in
certificateChain passphraseString- the key’s passphrase, or null for an unencrypted key
pkcs12
public static ClientCertificate pkcs12(byte[] archive, String password)Parameters
archivebyte[]- the
.p12/.pfxbytes passwordString- the archive’s password, or null for none
toString
public String toString()