I have enabled ssl in my spring boot application and anytime I want to use a Rest service like googleapis or facebook I have to add the certificate in the truststore. 

I use openssl to get the certificate: 

> 
> openssl s\_client -connect googleapis.com:443
> 
> 
> 

and I import it into the truststore : 

> 
> keytool.exe -import -noprompt -trustcacerts -alias googleapis.com
>  -file googleapis.com.cer -keystore app-server.p12 -storepass \*\*\*\*\*
> 
> 
> 

The problem is that it's very inconvenient to manage, when the certificate expires I have to update the certificates in the truststore everytime. 

Also even if I add the right certificate sometimes I get an error: 

> 
> Caused by: javax.net.ssl.SSLHandshakeException:
>  sun.security.validator.ValidatorException: PKIX path building failed:
>  sun.security.provider.certpath.SunCertPathBuilderException: unable to
>  find valid certification path to requested target
> 
> 
> 

I know these certificates are valid so, is there a possibility to trust them automatically without adding them in the truststore?

Here is my ssl configuration

```
  ssl:
    enabled: true
    key-store: classpath:keystore/app-server.p12
    key-store-password: ******
    key-alias: app-server
    key-store-type: PKCS12
    trust-store: classpath:keystore/app-server.p12
    trust-store-password: *****
    trust-store-type: PKCS12
    keyStorePath: config/keystore/app-server.p12

```

Also I had to add system properties in the main method

```
private static String keyStorePath;

private static String keyStorePassword;

@Value("${server.ssl.keyStorePath}")
public void setKeyStorePath(String keyStorePath) {
    ClientUiApplication.keyStorePath = keyStorePath;
}

@Value("${server.ssl.key-store-password}")
public void setKeyStorePassword(String keyStorePassword) {
    ClientUiApplication.keyStorePassword = keyStorePassword;
}

public static void main(String[] args) {

    SpringApplication.run(ClientUiApplication.class, args);
    System.setProperty("javax.net.ssl.trustStore", keyStorePath);
    System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);
}

```

Another important detail, I need a truststore because I use self-signed certificates generated with Keytool. Without, my services cannot communicate with each other.