什么的日子| 乳腺应该挂什么科| 浑身乏力吃什么药| 什么地走| 什么东西补钙| 五月七日是什么星座| 大脑供血不足头晕吃什么药最好| 舌头有红点是什么原因| 玉竹有什么功效| 黄疸是什么意思| 即使什么也什么造句| 蚊子怕什么植物| 什么大| 吃米饭配什么菜好吃| 家财万贯是什么生肖| 山及念什么| 诺如病毒是什么病| 属羊女和什么属相最配| 无可奈何是什么生肖| 做肠镜检查需要提前做什么准备| 种草莓什么意思| zoe是什么意思| 透析病人吃什么水果好| 熬夜吃什么对身体好| qq邮箱的格式是什么| 玫瑰花语是什么| 膀胱炎有什么症状| 脾虚气滞吃什么中成药| 经期吃榴莲有什么好处| ab型血为什么容易得精神病| 体贴是什么意思| 胃胀什么原因| 多五行属什么| everytime什么意思| 姻缘是什么意思| bv是什么| 带状疱疹后遗神经痛用什么药| 磨牙齿是什么原因| 低血糖吃什么食物| 什么叫等离子| 为什么眨眼睛| 胃痛吃什么药效果最好| 聚少离多是什么意思| 一般什么人会有美人尖| 宫颈炎是什么原因引起的| 24是什么生肖| 吃什么降血脂最快| 女孩子学什么专业好| 火疖子用什么药膏| 许愿是什么意思| 低压108有什么危险| 四面弹是什么面料| 枇杷什么季节成熟| 眼睛视力模糊用什么眼药水| 汗疱疹用什么药膏最好| 例假少是什么原因| 点字五行属什么| ckd3期是什么意思| 老当益壮是什么意思| 30岁属什么的生肖| 鼻涕是绿色的是什么原因| 手被辣椒辣了用什么方法解辣| 命里有时终须有命里无时莫强求什么意思| 戒的部首是什么| 鹿鞭泡酒有什么功效| 子婴是秦始皇什么人| 什么是原发性高血压和继发性高血压| 女性喝红茶有什么好处| gg是什么牌子| 睡眠时间短是什么原因| 女攻男受是什么意思| 筋道是什么意思| 吃什么东西可以降压| 高兴的什么| 周围神经病是什么意思| 神经性皮炎用什么药膏好| 小腹胀是什么原因女性| 高什么阔什么| 恩裳是什么档次的衣服| 自媒体是什么| 电磁炉用什么锅最好| in77是什么意思| 脚心是什么穴位| 黑头是什么| l什么意思| 漱口杯什么材质好| 胰腺炎恢复期吃什么好| AX是什么意思| 盆腔炎吃什么药效果最好| 什么是反流性食管炎| 母鸡什么意思| 键盘侠是什么意思| 2月25号是什么星座| 坦诚相待下一句是什么| 癫痫病是什么原因引起的| bg是什么| 赵丽颖的真名叫什么| 1996五行属什么| 韩束属于什么档次| 心功能不全是什么意思| 烫伤忌口不能吃什么| 近视眼睛什么牌子好| 湿气太重吃什么药最好| 朱元璋为什么不杀朱棣| 拔完牙后能吃什么| 50岁女人出轨为了什么| 血氧是什么| 蟑螂喜欢吃什么| 养老院护工都做些什么| 四级警长是什么级别| 知我者莫若你什么意思| 亩产是什么意思| 吃苦瓜对身体有什么好处| 什么是耳石症| 泰勒为什么叫霉霉| 匀字五行属什么| 吃什么帮助消化| 乳糖酶是什么东西| 大本营是什么意思| 什么叫高潮| 低血糖吃什么| 迷失自我是什么意思| 接吻要注意什么| 鼻烟壶是干什么用的| 社保卡是干什么用的| 什么是体脂率| 抗hcv是什么意思| 古惑仔是什么| 什么开什么笑| 为什么心脏会突然刺痛| 万年历是什么| 丸吞是什么意思| 木字旁的字有什么| 甲亢与甲减有什么区别| 装可以组什么词| 玛丽苏是什么意思| 取其轻前一句是什么| 小肠气挂什么科| 开山鼻祖是什么意思| 什么叫朋友| gi是什么| 思钱想厚什么意思| 属鸡与什么属相最配| 鲜牛奶和纯牛奶有什么区别| 肝癌是什么| 为什么会细菌感染| 内痔疮吃什么药最好| 理想主义者是什么意思| 为什么都开头孢不开阿莫西林| 圣大保罗属于什么档次| 为什么嘴唇发紫| 三位一体是什么意思| 蛇肉吃了有什么好处| 吃什么可以让子宫内膜变薄| 什么样的夕阳| 什么时候取环最合适| 馋肉是身体里缺什么| 太原有什么特产| thc是什么费用| 花椒水泡脚有什么好处| 童五行属什么| 甲沟炎是什么引起的| 心悸心慌焦虑吃什么药能缓解| 女人喝什么调节内分泌| 小孩脚麻是什么原因| 沙棘不能和什么一起吃| 控是什么意思| 益生菌什么牌子最好| 为什么不建议开眼角| 荆芥不能和什么一起吃| vivo是什么牌子的手机| 海鲜过敏吃什么药| 叶酸是什么东西| 自身免疫性胃炎是什么意思| 梦见被追杀预示什么| 中医的精髓是什么| 尿失禁是什么意思| 世界上最长的英文单词是什么| soso什么意思| 什么时候喝牛奶效果最佳| ala是什么氨基酸| 耳朵痛吃什么药| 什么是对的人| 为什么都开头孢不开阿莫西林| 胆固醇高会引起什么病| 什么狗聪明| 3月15号是什么星座| 失代偿期是什么意思| 为什么一饿就胃疼| 莫名其妙的心情不好是什么原因| 印度人属于什么人种| 大男子主义的男人喜欢什么样的女人| 神经损伤吃什么药最好| 飞蚊症是什么原因| 拉屎的时候拉出血来是什么原因| 心脾两虚吃什么食物补最快| 玫瑰花和什么一起泡水喝好| 鱼油有什么好处| 尿胆红素阳性什么意思| 学中医需要什么学历| 婴儿喝什么牌奶粉好| 双龙戏珠是什么生肖| 吃什么补阳气最快| 未羊是什么意思| 宝宝肠胃炎吃什么药| 痱子粉和爽身粉有什么区别| 蛇和什么属相相冲| 牛与什么生肖最配| 坐月子可以吃什么菜| 陪伴是最长情的告白下一句是什么| 琉璃和玻璃有什么区别| 八月二十八是什么星座| 信奥是什么| 梦见好多葡萄是什么意思| 人为什么要日b| 尿道痒男吃什么消炎药| 力不到不为财是什么意思| 11月份生日是什么星座| 月子期间可以吃什么水果| 煲电话粥什么意思| 长期低烧是什么原因| 头皮长疙瘩是什么原因| 月经不来是什么原因| giuseppe是什么牌子| 什么药降糖效果最好| 丈夫的弟弟叫什么| 车震是什么意思| 经常喝蜂蜜水有什么好处和坏处| 奥美拉唑治什么病| 咳嗽嗓子疼吃什么药| 意象是什么意思| 须菩提是什么意思| 血液是什么组织| 生物科学是什么专业| 低脂高钙牛奶适合什么人群| bpa是什么材料| 早泄什么意思| 4.12是什么星座| 意念灰是什么意思| 省检察长是什么级别| 芥子是什么意思| 6月3号是什么星座| 什么阻力| n2是什么| 子五行属什么| 支原体感染咳嗽吃什么药| 蓝脸的窦尔敦盗御马是什么歌| 九知道指的是什么| 吃虾不能吃什么| 心眼小是什么意思| 淫秽是什么意思| 山药炖什么好吃| 新疆是什么族| 小众是什么意思| 影像是什么意思| 退步是什么意思| 飞亚达手表什么档次| 云南白药治什么| 查肝肾功能挂什么科| 男人阴囊潮湿吃什么药| 低烧头疼吃什么药| 支气管炎吃什么药| 贫血有什么症状表现| 骇人听闻是什么意思| 百度
DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Attention Kubernetes users! DZone is researching how K8s usage is evolving in 2025 — tell us the good, the bad, + the frustrating.

Getting Started With DevSecOps: This Refcard provides actionable insights for embedding security into your DevOps culture and workflows.

Data Engineering: Not your average "AI is changing everything" report. Dive into tooling, strategy, + systems in scalable data ecosystems.

Java Caching: This Refcard explores core caching concepts and demonstrates how to implement them using Java’s JCache API.

Related

  • Be Punctual! Avoiding Kotlin’s lateinit In Spring Boot Testing
  • Exploring Hazelcast With Spring Boot
  • Testcontainers With Kotlin and Spring Data R2DBC
  • Smart-Doc: Generating gRPC API Documentation in Java Projects

Trending

  • How to Improve Software Architecture in a Cloud Environment
  • From Development to Deployment: Automating Machine Learning
  • Effective Exception Handling in Java and Spring Boot Applications
  • Agentic DevOps for the Rest of Us: A New Era of Intelligent SDLC
  1. DZone
  2. Coding
  3. Languages
  4. Easily Update and Reload SSL for a Server and an HTTP Client

无战不与!外媒解析“战斧”导弹20年来战场表现

In this tutorial, learn how to update and reload your SSL configuration whenever needed without restarting your server or recreating your HTTP client.

By 
Hakan Alt?nda? user avatar
Hakan Alt?nda?
·
Oct. 04, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
9.8K Views
百度 因此,标枪导弹对乌克兰的出口,将可能为俄制坦克带来实打实的灭顶之灾。

Join the DZone community and get the full member experience.

Join For Free

This tutorial walks through the process of configuring your server or HTTP client to enable hot reloading of the SSL configuration at runtime. This will result in no longer restarting your server when the certificates need to be updated, and you won't need to recreate your HTTP client when you want to use your new certificates. In this tutorial, we will cover only a Spring Boot application with Jetty as an embedded server to demonstrate the basic configuration and the different ways to trigger an update. However, every server or HTTP client which uses a SSLContext, SSLServerSocketFactory/SSLSocketFactory, TrustManager or KeyManager to configure SSL can also enable hot reloading, including Scala and Kotlin-based servers and HTTP clients. 

The hot reloading mechanism is provided by the SSLContext Kickstart library and all of the code examples shown in this tutorial can also be found on GitHub: Java Tutorials.

This tutorial will cover the following topics:

  • Required dependencies
  • Server configuration
  • Reloading examples
    • Basic SSL reloading
    • File-based SSL reloading
    • Database-based SSL reloading
    • Endpoint/Resource/Controller-based SSL reloading
  • Demo video
  • Tested servers
  • Compatible HTTP Clients

Dependencies

XML
 
<dependency>
    <groupId>io.github.hakky54</groupId>
    <artifactId>sslcontext-kickstart-for-jetty</artifactId>
</dependency>
<dependency>
    <groupId>io.github.hakky54</groupId>
    <artifactId>sslcontext-kickstart-for-pem</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


Examples

Server Configuration

The server will be initially configured with a keystore and trust store from the classpath which will also be swappable. The swappable option will enable the hot reloading feature.

Java
 
import nl.altindag.ssl.SSLFactory;
import nl.altindag.ssl.util.JettySslUtils;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SSLConfig {

    @Bean
    public SSLFactory sslFactory(@Value("${ssl.keystore-path}") String keyStorePath,
                                 @Value("${ssl.keystore-password}") char[] keyStorePassword,
                                 @Value("${ssl.truststore-path}") String trustStorePath,
                                 @Value("${ssl.truststore-password}") char[] trustStorePassword) {

        return SSLFactory.builder()
                .withIdentityMaterial(keyStorePath, keyStorePassword)
                .withTrustMaterial(trustStorePath, trustStorePassword)
                .withSwappableIdentityMaterial()
                .withSwappableTrustMaterial()
                .build();
    }

    @Bean
    public SslContextFactory.Server sslContextFactory(SSLFactory sslFactory) {
        return JettySslUtils.forServer(sslFactory);
    }

}


The SSL configuration needs to be injected into the Jetty web server, which is done as with the example below:

Java
 
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

@Configuration
public class ServerConfig {

    @Bean
    public ConfigurableServletWebServerFactory webServerFactory(SslContextFactory.Server sslContextFactory) {
        JettyServletWebServerFactory factory = new JettyServletWebServerFactory();

        JettyServerCustomizer jettyServerCustomizer = server -> {
            ServerConnector serverConnector = new ServerConnector(server, sslContextFactory);
            serverConnector.setPort(8443);
            server.setConnectors(new Connector[]{serverConnector});
        };
        factory.setServerCustomizers(Collections.singletonList(jettyServerCustomizer));

        return factory;
    }

}


Basic SSL Reloading

This part will demonstrate the easiest way to reload the SSL configuration and also demonstrates what is needed to get you started. First of all, you need a new instance of SSLFactory which is constructed with the new/updated keystores as shown below.

Java
 
SSLFactory updatedSslFactory = SSLFactory.builder()
        .withIdentityMaterial(Path.of("/path/to/your/identity.jks"), "secret".toCharArray())
        .withTrustMaterial(Path.of("/path/to/your/truststore.jks"), "secret".toCharArray())
        .build();

SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);


The base SSLFactory is the initial SSL configuration which was created with the swappable options. The base and the new SSLFactory need to be passed to the SSLFactoryUtils to reload the SSL configuration. The cache will also be cleared so a new SSL handshake will be initialized.

File-Based

The file-based SSL update service will validate every 10 seconds if the identity and trust store files have been updated. If that is the case, it will get the content and create a new SSLFactory out of it and update the base SSL configuration. The job is configured to check every 10 seconds, but this can be adjusted to your own needs with a cron statement.

Java
 
import nl.altindag.ssl.SSLFactory;
import nl.altindag.ssl.util.SSLFactoryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

@Service
public class FileBasedSslUpdateService {

    private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedSslUpdateService.class);

    private static final Path identityPath = Path.of("/path/to/your/identity.jks");
    private static final Path trustStorePath = Path.of("/path/to/your/truststore.jks");
    private static final char[] identityPassword = "secret".toCharArray();
    private static final char[] trustStorePassword = "secret".toCharArray();

    private ZonedDateTime lastModifiedTimeIdentityStore = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);
    private ZonedDateTime lastModifiedTimeTrustStore = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);

    private final SSLFactory baseSslFactory;

    public FileBasedSslUpdateService(SSLFactory baseSslFactory) {
        this.baseSslFactory = baseSslFactory;
    }

    /**
     * Checks every 10 seconds if the keystore files have been updated.
     * If the files have been updated the service will read the content and update the ssl material
     * within the existing ssl configuration.
     */
    @Scheduled(cron = "*/10 * * * * *")
    private void updateSslMaterial() throws IOException {
        if (Files.exists(identityPath) && Files.exists(trustStorePath)) {
            BasicFileAttributes identityAttributes = Files.readAttributes(identityPath, BasicFileAttributes.class);
            BasicFileAttributes trustStoreAttributes = Files.readAttributes(trustStorePath, BasicFileAttributes.class);

            boolean identityUpdated = lastModifiedTimeIdentityStore.isBefore(ZonedDateTime.ofInstant(identityAttributes.lastModifiedTime().toInstant(), ZoneOffset.UTC));
            boolean trustStoreUpdated = lastModifiedTimeTrustStore.isBefore(ZonedDateTime.ofInstant(trustStoreAttributes.lastModifiedTime().toInstant(), ZoneOffset.UTC));

            if (identityUpdated && trustStoreUpdated) {
                LOGGER.info("Keystore files have been changed. Trying to read the file content and preparing to update the ssl material");

                SSLFactory updatedSslFactory = SSLFactory.builder()
                        .withIdentityMaterial(identityPath, identityPassword)
                        .withTrustMaterial(trustStorePath, trustStorePassword)
                        .build();

                SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);

                lastModifiedTimeIdentityStore = ZonedDateTime.ofInstant(identityAttributes.lastModifiedTime().toInstant(), ZoneOffset.UTC);
                lastModifiedTimeTrustStore = ZonedDateTime.ofInstant(trustStoreAttributes.lastModifiedTime().toInstant(), ZoneOffset.UTC);

                LOGGER.info("Updating ssl material finished");
            }
        }
    }

}


Database-Based

This example will use the database as a source for getting the SSL material. The previous example used keystore files; however, the database will use PEM formatted strings. First, we need a data class: 

Java
 
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Timestamp;

@Entity
@Table(name = "SSL_MATERIAL")
public class SSLMaterial {

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Long id;

    private Timestamp updatedAt;
    private String identityContent;
    private String identityPassword;
    private String trustedCertificates;
    
    // Getters and Setters

}


We also need a JPA repository to get the row from the database as a Java object. This can be done with the following snippet:

Java
 
import nl.altindag.server.model.SSLMaterial;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface SSLMaterialRepository extends JpaRepository<SSLMaterial, Long> {

}


The database-based SSL update service will validate every 10 seconds if the identity and trusted certificates have been updated. If that is the case, it will get the content and create a new SSLFactory out of it and update the base SSL configuration. The job is configured to check every 10 seconds, but this can be adjusted to your own needs with a cron statement.

Java
 
import nl.altindag.server.model.SSLMaterial;
import nl.altindag.server.repository.SSLMaterialRepository;
import nl.altindag.ssl.SSLFactory;
import nl.altindag.ssl.util.PemUtils;
import nl.altindag.ssl.util.SSLFactoryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.net.ssl.X509ExtendedKeyManager;
import javax.net.ssl.X509ExtendedTrustManager;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

@Service
public class DatabaseBasedSslUpdateService {

    private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBasedSslUpdateService.class);

    private final SSLFactory baseSslFactory;
    private final SSLMaterialRepository sslMaterialRepository;

    private ZonedDateTime lastModifiedTime = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);

    public DatabaseBasedSslUpdateService(SSLFactory baseSslFactory, SSLMaterialRepository sslMaterialRepository) {
        this.baseSslFactory = baseSslFactory;
        this.sslMaterialRepository = sslMaterialRepository;
    }

    /**
     * This setup is very basic, and therefore currently does not validate if the content on the database has been updated.
     * Fetches every 10 seconds the ssl material from the database to update the server.
     */
    @Scheduled(cron = "*/10 * * * * *")
    private void updateSslMaterial() {
        LOGGER.info("Fetching ssl material...");

        SSLMaterial sslMaterial = sslMaterialRepository.findById(1L)
                .orElseThrow();

        ZonedDateTime sslMaterialUpdatedAt = ZonedDateTime.ofInstant(sslMaterial.getUpdatedAt().toInstant(), ZoneOffset.UTC);

        if(sslMaterialUpdatedAt.isBefore(lastModifiedTime) || sslMaterialUpdatedAt.isEqual(lastModifiedTime)) {
            LOGGER.info("No changes detected. Skipping of refreshing the ssl configuration");
            return;
        }

        LOGGER.info("Changes detected. Starting to update ssl material and refreshing the ssl configuration");

        X509ExtendedKeyManager keyManager = PemUtils.parseIdentityMaterial(sslMaterial.getIdentityContent(), sslMaterial.getIdentityPassword().toCharArray());
        X509ExtendedTrustManager trustManager = PemUtils.parseTrustMaterial(sslMaterial.getTrustedCertificates());

        SSLFactory updatedSslFactory = SSLFactory.builder()
                .withIdentityMaterial(keyManager)
                .withTrustMaterial(trustManager)
                .build();

        SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);

        lastModifiedTime = sslMaterialUpdatedAt;

        LOGGER.info("Finished updating ssl material and refreshing the ssl configuration");
    }

}


Endpoint/Resource/Controller-Based

The endpoint-based SSL update service makes it possible to supply the new SSL material from an HTTP Post request. The new keystore files can be sent as a byte array within the SSLUpdateRequest model. The server can consume that request by constructing an in-memory keystore object and using that to create an SSLFactory. 

First, we need an SSLUpdateRequest model as shown below:

Java
 
public class SSLUpdateRequest {

    private byte[] keyStore;
    private char[] keyStorePassword;
    private byte[] trustStore;
    private char[] trustStorePassword;

    public SSLUpdateRequest() {}

    public SSLUpdateRequest(byte[] keyStore, char[] keyStorePassword, byte[] trustStore, char[] trustStorePassword) {
        this.keyStore = keyStore;
        this.keyStorePassword = keyStorePassword;
        this.trustStore = trustStore;
        this.trustStorePassword = trustStorePassword;
    }

    // Getters and Setters

}


Next, we need to create an endpoint. In this case, it will be http://localhost:8443/admin/ssl, which consumes a JSON request of the SSLUpdateRequest model. Below is an example of the actual endpoint which takes SSLUpdateRequest and maps it into an SSLFactory and reloads the SSL configuration.

Java
 
import nl.altindag.server.model.SSLUpdateRequest;
import nl.altindag.ssl.SSLFactory;
import nl.altindag.ssl.util.SSLFactoryUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

@RestController
public class AdminController {

    private final SSLFactory baseSslFactory;

    public AdminController(SSLFactory baseSslFactory) {
        this.baseSslFactory = baseSslFactory;
    }

    @PostMapping(value = "/admin/ssl", consumes = MediaType.APPLICATION_JSON_VALUE)
    public void updateKeyManager(@RequestBody SSLUpdateRequest request) throws IOException {
        try (InputStream keyStoreStream = new ByteArrayInputStream(request.getKeyStore());
             InputStream trustStoreStream = new ByteArrayInputStream(request.getTrustStore())) {

            SSLFactory updatedSslFactory = SSLFactory.builder()
                    .withIdentityMaterial(keyStoreStream, request.getKeyStorePassword())
                    .withTrustMaterial(trustStoreStream, request.getTrustStorePassword())
                    .build();

            SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);
        }
    }

}


Demo

Tested Servers

  • Spring Boot
  • gRPC
  • Vert.x
  • Netty

The above list of servers have been tested and proven to be working. Other Java, Kotlin, or Scala-based servers which accept an SSLContext, KeyManager, TrustManager, or SSLServerSocketFactory will also work. All of the source code for the different examples and different servers listed above is available at the Java Tutorial link on GitHub given earlier in this article. You can follow the steps within the README file to try it out yourself locally.

Compatible HTTP Clients

The above list of HTTP clients is not tested on this functionality of hot reloading SSL at runtime; however, it will work as it is fully compatible with the library. The list of supported HTTP clients for Java, Kotlin, and Scala are as follows:

Java

  • Apache HttpClient
  • Apache HttpAsyncClient
  • Apache 5 HttpClient
  • Apache 5 HttpAsyncClient
  • JDK HttpClient
  • Old JDK HttpClient
  • Netty Reactor
  • Jetty Reactive HttpClient
  • Spring RestTemplate
  • Spring WebFlux WebClient Netty
  • Spring WebFlux WebClient Jetty
  • OkHttp
  • Jersey Client
  • Old Jersey Client
  • Apache CXF JAX-RS
  • Apache CXF using ConduitConfigurer
  • Google HttpClient
  • Unirest
  • Retrofit
  • Async Http Client
  • Feign
  • Methanol
  • Vert.x Web Client
  • gRPC
  • Elasticsearch
  • Jetty WebSocket

Kotlin

  • Fuel
  • http4k with Apache 4
  • http4k with Async Apache 4
  • http4k with Apache 5
  • http4k with Async Apache 5
  • http4k with Java Net
  • http4k with Jetty
  • http4k with OkHttp
  • kohttp
  • Ktor with Android engine
  • Ktor with Apache engine
  • Ktor with Java engine
  • Ktor with Okhttp engine

Scala

  • Twitter Finagle
  • Twitter Finagle Featherbed
  • Akka HTTP Client
  • Dispatch Reboot
  • ScalaJ/Simplified HTTP Client
  • STTP
  • Requests-Scala
  • Http4s Blaze Client
  • Http4s Java Net Client
Apache CXF Engine gRPC Java Development Kit Java (programming language) Jetty (web server) Kotlin (programming language) Netty (software) Scala (programming language) Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • Be Punctual! Avoiding Kotlin’s lateinit In Spring Boot Testing
  • Exploring Hazelcast With Spring Boot
  • Testcontainers With Kotlin and Spring Data R2DBC
  • Smart-Doc: Generating gRPC API Documentation in Java Projects

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

香松是什么 结婚下雨有什么说法 猫怕什么气味 脸上有痣去医院挂什么科 智齿发炎肿痛吃什么药
带状疱疹有什么症状 七个月宝宝可以吃什么辅食 咽炎咳嗽吃什么药 直销是什么意思 儿童过敏性结膜炎用什么眼药水
肺大泡是什么 pro是什么意思 卧推100公斤什么水平 金黄的稻田像什么 中暑是什么原因
is是什么组织 2.1是什么星座 肚子疼吃什么食物好 肛周脓肿吃什么消炎药 为国为民是什么生肖
秋天有什么植物hcv9jop2ns4r.cn 贪污是什么意思hcv7jop5ns0r.cn 什么叫特应性皮炎hcv9jop1ns0r.cn 胸闷喘不上气什么原因hcv9jop1ns4r.cn 风寒感冒吃什么食物hcv8jop5ns3r.cn
血清检查能测出什么xianpinbao.com 眼睛出现飞蚊症什么原因怎么办kuyehao.com 神经梅毒有什么症状hcv9jop7ns4r.cn 辐射是什么意思hcv8jop7ns5r.cn 喝什么降尿酸hcv9jop7ns1r.cn
发际线高的人说明什么hcv9jop2ns3r.cn 为什么胸口疼hcv8jop1ns0r.cn 农历8月13日是什么星座hcv8jop5ns3r.cn 落下帷幕什么意思jingluanji.com 直男什么意思hcv9jop1ns5r.cn
闪卡是什么意思hcv8jop9ns7r.cn 脑堵塞有什么症状bfb118.com 睡觉后脑勺出汗多是什么原因hcv8jop3ns6r.cn 咽颊炎吃什么药hcv8jop9ns7r.cn 什么是包皮cj623037.com
百度 技术支持:蜘蛛池 www.kelongchi.com