首页 > 解决方案 > 使用从 ESP32 到 Spring Boot 安全 API 的预共享密钥

问题描述

我正在尝试将一些数据从 ESP32 设备发送到安全的 Spring Boot API。我正在尝试使用 Github WiFiClientPSK上提供的简单 WiFiClientPSK.ino 草图

它正在使用 client.setPreSharedKey(pskIdent, psKey); 设置预共享密钥

在服务器端,我已经设置了 Spring Boot 应用程序以接受 SSL 连接,并且我正在尝试在标头中获取 PSK。下面是代码

@RestController
public class WebController {
    @RequestMapping(value="/", method = {RequestMethod.GET,RequestMethod.POST})
    public String check(@RequestHeader HttpHeaders headers) {
        System.out.println("Header = "+headers.toString());
        return "";
    }
}

这是 SSL 配置

server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:springboot.p12
server.ssl.key-store-password=password
server.ssl.key-alias=springboot
server.port=8443

当我在 DEVKIT 中安装草图后尝试从 SPE32 建立连接时,我在串行监视器上收到此错误

11:58:59.169 -> Starting connection to server...
11:58:59.169 -> [V][WiFiClientSecure.cpp:146] connect(): start_ssl_client with PSK
11:58:59.169 -> [V][ssl_client.cpp:59] start_ssl_client(): Free internal heap before TLS 280500
11:58:59.169 -> [V][ssl_client.cpp:65] start_ssl_client(): Starting socket
11:58:59.342 -> [V][ssl_client.cpp:141] start_ssl_client(): Seeding the random number generator
11:58:59.342 -> [V][ssl_client.cpp:150] start_ssl_client(): Setting up the SSL/TLS structure...
11:58:59.342 -> [V][ssl_client.cpp:178] start_ssl_client(): Setting up PSK
11:58:59.377 -> [V][ssl_client.cpp:234] start_ssl_client(): Setting hostname for TLS session...
11:58:59.377 -> [V][ssl_client.cpp:249] start_ssl_client(): Performing the SSL/TLS handshake...
11:58:59.583 -> [E][ssl_client.cpp:36] _handle_error(): [start_ssl_client():253]: (-30336) SSL - No CA Chain is set, but required to operate
11:58:59.583 -> [E][WiFiClientSecure.cpp:153] connect(): start_ssl_client: -30336
11:58:59.583 -> [V][ssl_client.cpp:302] stop_ssl_socket(): Cleaning SSL connection.
11:58:59.583 -> Connection failed!

在 Spring Boot 应用程序上,我没有任何流量。有没有人这样做过或知道如何解决这个问题?

标签: javaspring-bootesp32

解决方案


推荐阅读