fatal alert: Protocol Version

pdudday
Regular Visitor

fatal alert: Protocol Version

Hi there,

 

I'm trying to run the tests provided in the visa developer account; the java tests.

 

I followed the guidelines mentioned in the VISA developer website for setting up the Two-way mutual SSL

 

However when I execute the tests I get the following error.

 

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://sandbox.api.visa.com/globalatmlocator/v1/localatms/routesinquiry": Received fatal alert: protocol_version; nested exception is javax.net.ssl.SSLException: Received fatal alert: protocol_version

at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)

at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628)

at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)

at com.visa.developer.sample.locate_atms_api.ApiClient.invokeAPI(ApiClient.java:735)

at com.visa.developer.sample.locate_atms_api.api.AtmlocatorApi.postroutesInquiry(AtmlocatorApi.java:234)

at com.visa.developer.sample.locate_atms_api.api.AtmlocatorApiTest.postroutesInquiryTest(AtmlocatorApiTest.java:125)

 

Please let me know what could  be going wrong

3 REPLIES 3
jvenkata
Community Moderator

Re: fatal alert: Protocol Version

Hi Pavan,



What version of Java are you using ? Can you try with Java 1.8 or above and let me know if you are still facing the below issue ?



Thanks,

Jai
pdudday
Regular Visitor

Re: fatal alert: Protocol Version

Hi Jai, thanks for the quick response.

I am using Java 1.8 already. So Yes the issue is also on Java 1.8

Other Details:
Mac OS
Java 1.8
Eclipse IDE. 2019-03 (VERSION 4.3)

Thanks
Pavan.
jvenkata
Community Moderator

Re: fatal alert: Protocol Version

Hi Pavan,

 

Please try to connect explicitly using TLSv1.2 protocol on APIClient.getRestTemplateForMutualAuth() method as shown below and let me know if this works out.

 

protected RestTemplate getRestTemplateForMutualAuth() {
        try {
            KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
            FileInputStream keystoreInputStream = new FileInputStream(keystorePath);
            keystore.load(keystoreInputStream, keystorePassword.toCharArray());
            keystoreInputStream.close();

            SSLContext sslcontext = SSLContexts.custom().useProtocol("TLSv1.2")
                    .loadKeyMaterial(keystore, keystorePassword.toCharArray()).build();

            HostnameVerifier hostnameverifier = null;
            SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, null, null,
                    hostnameverifier);
            CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();

            HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
            HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

            requestFactory.setHttpClient(httpClient);
            RestTemplate restTemplate = new RestTemplate(requestFactory);

            for(HttpMessageConverter converter:restTemplate.getMessageConverters()){
                if(converter instanceof AbstractJackson2HttpMessageConverter){
                    ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
                    ThreeTenModule module = new ThreeTenModule();
                    module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
                    module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
                    module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
                    mapper.registerModule(module);
                }
            }
            restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
            return restTemplate;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

Thanks,

Jai