public class SSLConfig extends Object implements Config
$ keytool -printcert -file EquifaxSecureGlobaleBusinessCA-1.crt Owner: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Issuer: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Serial number: 1 Valid from: Mon Jun 21 00:00:00 EDT 1999 until: Sun Jun 21 00:00:00 EDT 2020 Certificate fingerprints: MD5: 8F:5D:77:06:27:C4:98:3C:5B:93:78:E7:D7:7D:9B:CC SHA1: 7E:78:4A:10:1C:82:65:CC:2D:E1:F1:6D:47:B4:40:CA:D9:0A:19:45 Signature algorithm name: MD5withRSA Version: 3 ....Now, import that into a Java keystore file:
$ keytool -importcert -alias "equifax-ca" -file EquifaxSecureGlobaleBusinessCA-1.crt -keystore truststore_javanet.jks -storepass test1234 Owner: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Issuer: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Serial number: 1 Valid from: Mon Jun 21 00:00:00 EDT 1999 until: Sun Jun 21 00:00:00 EDT 2020 Certificate fingerprints: MD5: 8F:5D:77:06:27:C4:98:3C:5B:93:78:E7:D7:7D:9B:CC SHA1: 7E:78:4A:10:1C:82:65:CC:2D:E1:F1:6D:47:B4:40:CA:D9:0A:19:45 Signature algorithm name: MD5withRSA Version: 3 ... Trust this certificate? [no]: yes Certificate was added to keystoreNow you want to use this truststore in your client:
RestAssured.config = RestAssured.newConfig().sslConfig(new SSLConfig("/truststore_javanet.jks", "test1234");or
given().config(newConfig().sslConfig(new SSLConfig("/truststore_javanet.jks", "test1234")). ..
Constructor and Description |
---|
SSLConfig()
Creates a new SSL Config instance with the following settings:
No keystore
No truststore
No password
KeyStore.getDefaultType()
No explicit default port
No trust store
No SSLSocketFactory
SSLSocketFactory.STRICT_HOSTNAME_VERIFIER as X509HostnameVerifier implementation
|
Modifier and Type | Method and Description |
---|---|
SSLConfig |
allowAllHostnames()
Configure the SSLConfig to allow all host names.
|
SSLConfig |
and()
Syntactic sugar.
|
KeyStore |
getKeyStore() |
String |
getKeyStorePassword() |
String |
getKeyStoreType() |
Object |
getPathToKeyStore() |
Object |
getPathToTrustStore() |
int |
getPort() |
org.apache.http.conn.ssl.SSLSocketFactory |
getSSLSocketFactory() |
KeyStore |
getTrustStore() |
String |
getTrustStorePassword() |
String |
getTrustStoreType() |
org.apache.http.conn.ssl.X509HostnameVerifier |
getX509HostnameVerifier() |
boolean |
isUserConfigured() |
SSLConfig |
keyStore(File pathToJks,
String password)
Use a keystore located on the file-system.
|
SSLConfig |
keyStore(String password)
Uses the user default keystore stored in <user.home>/.keystore
|
SSLConfig |
keyStore(String pathToJks,
String password) |
SSLConfig |
keystoreType(String keystoreType)
The certificate type, will use
KeyStore.getDefaultType() by default. |
SSLConfig |
port(int port)
The port for which REST Assured will apply the SSL configuration.
|
SSLConfig |
relaxedHTTPSValidation()
Use relaxed HTTP validation.
|
SSLConfig |
relaxedHTTPSValidation(String protocol)
Use relaxed HTTP validation.
|
static SSLConfig |
sslConfig() |
SSLConfig |
sslSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
Specify a
SSLSocketFactory . |
SSLConfig |
strictHostnames()
Configure the SSLConfig to use strict host name verification (this is the default behavior).
|
SSLConfig |
trustStore(File pathToTrustStore,
String password)
Use a trustStore located on the file-system.
|
SSLConfig |
trustStore(KeyStore trustStore)
A trust store to use during SSL/Certificate authentication.
|
SSLConfig |
trustStore(String pathToTrustStore,
String password) |
SSLConfig |
trustStoreType(String trustStoreType)
The trust store type, will use
KeyStore.getDefaultType() by default. |
SSLConfig |
using()
Syntactic sugar.
|
SSLConfig |
with()
Syntactic sugar.
|
SSLConfig |
x509HostnameVerifier(org.apache.http.conn.ssl.X509HostnameVerifier x509HostnameVerifier)
Provide a custom
X509HostnameVerifier implementation that'll be used by the SSLSocketFactory . |
public SSLConfig()
KeyStore.getDefaultType()
SSLSocketFactory.STRICT_HOSTNAME_VERIFIER
as X509HostnameVerifier
implementationpublic SSLConfig keyStore(String pathToJks, String password)
pathToJks
- The path to the JKS. REST Assured will first look in the classpath and if not found it will look for the JKS in the local file-systempassword
- The store passpublic SSLConfig keyStore(File pathToJks, String password)
keyStore(String, String)
for more details.pathToJks
- The path to JKS file on the file-systempassword
- The password for the keystorekeyStore(String, String)
public SSLConfig keyStore(String password)
password
- - Use null for no passwordpublic SSLConfig trustStore(String pathToTrustStore, String password)
pathToTrustStore
- The path to the trust store. REST Assured will first look in the classpath and if not found it will look for the JKS in the local file-systempassword
- The store passpublic SSLConfig trustStore(File pathToTrustStore, String password)
trustStore(String, String)
for more details.pathToTrustStore
- The path to trust store file on the file-systempassword
- The password for the trustStoretrustStore(String, String)
public SSLConfig keystoreType(String keystoreType)
KeyStore.getDefaultType()
by default.keystoreType
- The keystore type.public SSLConfig trustStoreType(String trustStoreType)
KeyStore.getDefaultType()
by default.trustStoreType
- The trust store type.public SSLConfig port(int port)
port
- port.public SSLConfig trustStore(KeyStore trustStore)
trustStore
- The trust store to use.public SSLConfig relaxedHTTPSValidation()
keyStore(String, String)
or trust store (see trustStore(java.security.KeyStore)
.
This method assumes that the protocol for the SSLContext
instance is . If this is not the case use relaxedHTTPSValidation(String)
.public SSLConfig relaxedHTTPSValidation(String protocol)
keyStore(String, String)
or trust store (see trustStore(java.security.KeyStore)
.protocol
- The standard name of the requested protocol. See the SSLContext section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard protocol names.public SSLConfig sslSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
SSLSocketFactory
. This will override settings from trust store as well as keystore and password.sslSocketFactory
- The SSLSocketFactory
to use.public SSLConfig x509HostnameVerifier(org.apache.http.conn.ssl.X509HostnameVerifier x509HostnameVerifier)
X509HostnameVerifier
implementation that'll be used by the SSLSocketFactory
. You can replace the
X509HostnameVerifier
for example if you want to allow all host names etc.x509HostnameVerifier
- The X509HostnameVerifier to use.allowAllHostnames()
,
strictHostnames()
public SSLConfig strictHostnames()
SSLSocketFactory.STRICT_HOSTNAME_VERIFIER
public SSLConfig allowAllHostnames()
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
public static SSLConfig sslConfig()
public SSLConfig and()
public SSLConfig with()
public SSLConfig using()
public Object getPathToKeyStore()
public Object getPathToTrustStore()
public String getKeyStorePassword()
public String getTrustStorePassword()
public String getKeyStoreType()
public String getTrustStoreType()
public int getPort()
public KeyStore getTrustStore()
public KeyStore getKeyStore()
public org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory()
public org.apache.http.conn.ssl.X509HostnameVerifier getX509HostnameVerifier()
public boolean isUserConfigured()
isUserConfigured
in interface Config
true
if user has configured this SSL Configuration instance, false
otherwise.Copyright © 2010–2019. All rights reserved.