Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad Request - This combination of host and port requires TLS. with Spring Boot

I'm newbie with Spring Boot.

I'm trying to make a https call to a service, I have a Privake key to secure connection.

I hit:

http://localhost:8081/points/12345/search 

I tried with https:// but I get from Postman:

Could not get any response There was an error connecting to https://localhost:8081/points/12345/search. 

From the moment I wrote

server.ssl.key-store=classpath:KeyStore.jks server.ssl.key-store-password=test 

in application.properties, I get the error message:

Bad Request - This combination of host and port requires TLS

I have deleted all my code in my controller, I just let the endpoint so that I can invoke it.

@RestController @SpringBootApplication public class MainApplication {     @RequestMapping(value = "/points/{point}/search", method = RequestMethod.GET)     public PointsType getPoint(@PathVariable(value = "point") String point) {         System.out.println("hi"); // Never printed         return null;     }     public static void main(String[] args) {         SpringApplication.run(MainApplication.class, args);     } } 

Here is the file application.properties:

spring.application.name=sge server.port=8081 server.ssl.key-store=classpath:KeyStore.jks server.ssl.key-store-password=test server.ssl.key-alias=homologation-staging server.ssl.trust-store=classpath:TrustStore.jks server.ssl.trust-store-password=test server.ssl.client-auth=need security.require-ssl=true server.tomcat.remote_ip_header=x-forwarded-for server.tomcat.protocol_header=x-forwarded-proto 

What should I do ?

like image 892
Juliatzin Avatar asked Oct 28 '19 17:10

Juliatzin


People also ask

What is TLS in spring boot?

TLS provides protection for data in transit between client and server and is a key component of the HTTPS protocol. The Secure Sockets Layer (SSL) and TLS are often used interchangeably, but they aren't the same. In fact, TLS is the successor of SSL. TLS can be implemented either one-way or two-way.


2 Answers

I used https:// at the beginning instead of http://, it worked for me.

like image 70
SerdarAtalay Avatar answered Sep 18 '22 07:09

SerdarAtalay


I got this message because I was using wrong certificate.

I misunderstood Client certificate and Server certificate.

In my case, I installed my certificate on the server, for my domain, but what I needed to do instead is to use it to make the request, as a client certificate.

you can check it how to do it here.

Client Certificate Authentication with Spring Boot

So this message is basically saying: "Hey, your SSL request is not OK", I can't find the cert file, or your cert file is not the good one, as @SerdarAtalay says, it can also significate that you didn't use https:// prefix, etc.

Hope it helps!

like image 40
Juliatzin Avatar answered Sep 20 '22 07:09

Juliatzin