Class Security
Three states, and the names are the documentation:
Security.required() // verify the chain and the hostname. The default.
Security.fromKeystore(Path.of("certs")) // the same, with a client certificate for mutual TLS
Security.disabled() // plaintext. For tests.
Security.insecure() // TLS with no verification. Almost always wrong.
insecure() exists because sometimes it is genuinely needed, and because a library
that omits it gets a verify=false added to a properties file by somebody in a hurry.
Making it a named method keeps it greppable: one search finds every place it was used, which a
boolean buried in configuration does not.
Hostname verification is the setting people turn off first and should turn off last. Without it any valid certificate satisfies the connection, whoever it was issued to, which reduces TLS to an encrypted conversation with whoever happened to answer.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhat a connection does about transport security. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringWhatfromKeystore(java.nio.file.Path)assumes when nothing says otherwise, and whatacemq-security-devwrites.static final StringSubject the development certificate generator stamps, so this library can refuse it. -
Method Summary
Modifier and TypeMethodDescriptionPermits certificates the development generator produced.static Securitydisabled()static SecurityfromKeystore(Path directory) TLS using the keystores in a directory, as written by the development generator or by your own tooling:keystore.p12for this client,truststore.p12for the certificates it will accept.static Securityinsecure()TLS with no verification at all.keystorePassword(String password) mode()static Securityrequired()Builds the context to connect with.toString()booleanwithCredentials(CredentialsProvider provider)
-
Field Details
-
DEVELOPMENT_MARKER
Subject the development certificate generator stamps, so this library can refuse it.- See Also:
-
DEFAULT_KEYSTORE_PASSWORD
WhatfromKeystore(java.nio.file.Path)assumes when nothing says otherwise, and whatacemq-security-devwrites.Six characters, because
keytoolrefuses to create a PKCS12 keystore with a shorter password. The previous default was five, which meant the library's own default described a keystore the standard JDK tooling could not produce — a default nobody could use is worse than no default.It protects a store on a developer's machine and is not a secret. Anything real passes
keystorePassword(String)with a value from a secret store.- See Also:
-
-
Method Details
-
required
- Returns:
- TLS with the chain and the hostname verified, using the JVM's trust store
-
fromKeystore
TLS using the keystores in a directory, as written by the development generator or by your own tooling:keystore.p12for this client,truststore.p12for the certificates it will accept.- Parameters:
directory- where the two stores live- Returns:
- the policy
-
disabled
- Returns:
- plaintext, for tests and for a broker on this machine
-
insecure
TLS with no verification at all.Encrypts the conversation and proves nothing about who is on the other end, which stops a passive eavesdropper and does nothing about an active one. Named so that finding every use of it is one search.
- Returns:
- the policy
-
keystorePassword
- Parameters:
password- the password protecting the keystores- Returns:
- a copy of this policy using it
-
allowDevelopmentCertificates
Permits certificates the development generator produced.Needed on a developer's machine and nowhere else. Without it, a certificate carrying
DEVELOPMENT_MARKERis refused however the trust store was configured — because a throwaway certificate authority that drifts into production is worse than no encryption: everything looks protected and nothing is.- Returns:
- a copy of this policy permitting them
-
withCredentials
- Parameters:
provider- where credentials come from, consulted on every connection- Returns:
- a copy of this policy using it
-
mode
- Returns:
- what this policy does about transport security
-
verifiesHostname
public boolean verifiesHostname()- Returns:
- whether the hostname on the certificate must match the host connected to
-
credentials
- Returns:
- where credentials come from, if this policy carries a provider
-
sslContext
Builds the context to connect with.- Returns:
- an
SSLContext, or empty when this policy isSecurity.Mode.DISABLED - Throws:
SecurityConfigurationException- if the keystores cannot be read
-
toString
-