Spring Boot starter provides fast SSL RestTemplate setup for your backend
- Add to your build.gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
- Add dependency (do not forget to change the tag):
dependencies {
implementation 'com.github.EugeneLesnov:spring-boot-starter-rest:Tag'
}
- Provide required SSL properties:
server:
ssl:
enabled: true
key-store: /path/to/key.keystore
key-store-password: password
key-alias: alias
trust-store: /path/to/truststore
trust-store-password: password
connection-default-max-per-route: 40 # optional property, defaults to 25
- Additionally, you can implement HostnameVerifier interface and make it a bean. Otherwise, starter uses NoopHostnameVerifier instance (verification is off).
Here's a short example:
public class CustomHostnameVerifier implements HostnameVerifier {
public CustomHostnameVerifier() {}
@Override
public boolean verify(String hostname, SSLSession session) {
// do your verify stuff
return false;
}
}
Then:
@Bean
public HostnameVerifier hostnameVerifier() {
return new CustomHostnameVerifier();
}
1. keytool -genkey -keystore key.keystore -alias certificateAlias -keyalg RSA -keysize 2048 -validity 3950
2. keytool -selfcert -alias certificateAlias -keystore key.keystore -validity 3950
3. keytool -export -alias certificateAlias -keystore key.keystore -rfc -file certificateAlias.cer
4. keytool -importcert -alias certificateAlias -file certificateAlias.cer -keystore truststore