首页
/ 开源项目 `mutual-tls-ssl` 使用教程

开源项目 `mutual-tls-ssl` 使用教程

2024-09-08 09:29:10作者:宗隆裙
mutual-tls-ssl
🔐 Tutorial of setting up Security for your API with one way authentication with TLS/SSL and mutual authentication for a java based web server and a client with both Spring Boot. Different clients are provided such as Apache HttpClient, OkHttp, Spring RestTemplate, Spring WebFlux WebClient Jetty and Netty, the old and the new JDK HttpClient, the old and the new Jersey Client, Google HttpClient, Unirest, Retrofit, Feign, Methanol, vertx, Scala client Finagle, Featherbed, Dispatch Reboot, AsyncHttpClient, Sttp, Akka, Requests Scala, Http4s Blaze, Kotlin client Fuel, http4k, Kohttp and ktor. Also other server examples are available such as jersey with grizzly. Also gRPC, WebSocket and ElasticSearch examples are included

1. 项目的目录结构及介绍

mutual-tls-ssl/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── hakky54/
│   │   │           └── mutualssl/
│   │   │               ├── client/
│   │   │               │   ├── Client.java
│   │   │               │   └── ClientConfiguration.java
│   │   │               ├── server/
│   │   │               │   ├── Server.java
│   │   │               │   └── ServerConfiguration.java
│   │   │               └── MutualSslApplication.java
│   │   └── resources/
│   │       ├── application.properties
│   │       ├── keystore.jks
│   │       └── truststore.jks
│   └── test/
│       └── java/
│           └── com/
│               └── hakky54/
│                   └── mutualssl/
│                       └── MutualSslApplicationTests.java
├── .gitignore
├── LICENSE
├── README.md
└── pom.xml

目录结构介绍

  • src/main/java/com/hakky54/mutualssl/: 包含项目的主要代码文件。
    • client/: 客户端相关代码。
      • Client.java: 客户端主类。
      • ClientConfiguration.java: 客户端配置类。
    • server/: 服务器端相关代码。
      • Server.java: 服务器主类。
      • ServerConfiguration.java: 服务器配置类。
    • MutualSslApplication.java: 项目启动类。
  • src/main/resources/: 包含项目的配置文件和资源文件。
    • application.properties: 项目的配置文件。
    • keystore.jks: 密钥库文件。
    • truststore.jks: 信任库文件。
  • src/test/java/com/hakky54/mutualssl/: 包含项目的测试代码。
    • MutualSslApplicationTests.java: 项目测试类。
  • .gitignore: Git 忽略文件配置。
  • LICENSE: 项目许可证文件。
  • README.md: 项目说明文件。
  • pom.xml: Maven 项目配置文件。

2. 项目的启动文件介绍

MutualSslApplication.java

package com.hakky54.mutualssl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MutualSslApplication {

    public static void main(String[] args) {
        SpringApplication.run(MutualSslApplication.class, args);
    }

}

启动文件介绍

  • MutualSslApplication.java 是项目的启动类,使用 Spring Boot 框架。
  • @SpringBootApplication 注解用于启用 Spring Boot 的自动配置、组件扫描和配置类功能。
  • main 方法是程序的入口点,调用 SpringApplication.run 方法启动 Spring Boot 应用程序。

3. 项目的配置文件介绍

application.properties

server.port=8443
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=changeit
server.ssl.key-password=changeit
server.ssl.trust-store=classpath:truststore.jks
server.ssl.trust-store-password=changeit
server.ssl.client-auth=need

配置文件介绍

  • server.port: 指定服务器监听的端口,这里设置为 8443
  • server.ssl.key-store: 指定密钥库文件的路径,这里使用 classpath:keystore.jks
  • server.ssl.key-store-password: 密钥库的密码,这里设置为 changeit
  • server.ssl.key-password: 密钥的密码,这里设置为 changeit
  • server.ssl.trust-store: 指定信任库文件的路径,这里使用 classpath:truststore.jks
  • server.ssl.trust-store-password: 信任库的密码,这里设置为 changeit
  • server.ssl.client-auth: 指定客户端认证模式,这里设置为 need,表示需要客户端认证。

通过以上配置,项目可以实现双向 TLS/SSL 认证,确保通信的安全性。

mutual-tls-ssl
🔐 Tutorial of setting up Security for your API with one way authentication with TLS/SSL and mutual authentication for a java based web server and a client with both Spring Boot. Different clients are provided such as Apache HttpClient, OkHttp, Spring RestTemplate, Spring WebFlux WebClient Jetty and Netty, the old and the new JDK HttpClient, the old and the new Jersey Client, Google HttpClient, Unirest, Retrofit, Feign, Methanol, vertx, Scala client Finagle, Featherbed, Dispatch Reboot, AsyncHttpClient, Sttp, Akka, Requests Scala, Http4s Blaze, Kotlin client Fuel, http4k, Kohttp and ktor. Also other server examples are available such as jersey with grizzly. Also gRPC, WebSocket and ElasticSearch examples are included
热门项目推荐
相关项目推荐

项目优选

收起
CangjieCommunity
为仓颉编程语言开发者打造活跃、开放、高质量的社区环境
Markdown
672
0
RuoYi-Vue
🎉 基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统,同时提供了 Vue3 的版本
Java
136
18
openHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
12
8
redis-sdk
仓颉语言实现的Redis客户端SDK。已适配仓颉0.53.4 Beta版本。接口设计兼容jedis接口语义,支持RESP2和RESP3协议,支持发布订阅模式,支持哨兵模式和集群模式。
Cangjie
322
26
advanced-java
Advanced-Java是一个Java进阶教程,适合用于学习Java高级特性和编程技巧。特点:内容深入、实例丰富、适合进阶学习。
JavaScript
75.83 K
19.04 K
qwerty-learner
为键盘工作者设计的单词记忆与英语肌肉记忆锻炼软件 / Words learning and English muscle memory training software designed for keyboard workers
TSX
15.56 K
1.44 K
Jpom
🚀简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件
Java
1.41 K
292
Yi-Coder
Yi Coder 编程模型,小而强大的编程助手
HTML
30
5
easy-es
Elasticsearch 国内Top1 elasticsearch搜索引擎框架es ORM框架,索引全自动智能托管,如丝般顺滑,与Mybatis-plus一致的API,屏蔽语言差异,开发者只需要会MySQL语法即可完成对Es的相关操作,零额外学习成本.底层采用RestHighLevelClient,兼具低码,易用,易拓展等特性,支持es独有的高亮,权重,分词,Geo,嵌套,父子类型等功能...
Java
1.42 K
231
taro
开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
TypeScript
35.34 K
4.77 K