Skip to content

Commit 76d0c04

Browse files
committed
Added trust me project and bumped java to 21
1 parent 99d4c98 commit 76d0c04

File tree

17 files changed

+687
-3
lines changed

17 files changed

+687
-3
lines changed

README.MD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
A repository containing different java tutorials
55

66
**Minimum requirements:**
7-
1. Java 17
7+
1. Java 21
88
2. Maven 3.5.0
99
3. Eclipse, Intellij IDEA (or any other text editor like VIM)
1010
4. A terminal
@@ -36,6 +36,7 @@ A repository containing different java tutorials
3636
- [Spring Boot Reactive Server with Common Name Validation based on Spring Security](spring-security-cn-validation-for-reactive-server)
3737
- [Spring Boot Server with Common Name Validation based on AOP with AspectJ Weaver](spring-cn-validation-with-aop)
3838
- [Bypassing and overruling SSL configuration of libraries](bypassing-overruling-ssl-configuration)
39+
- [Prompting to trust an unknown certificate in a GUI and reloading the ssl configuration](trust-me)
3940

4041
## Serialization & Deserialization ☢️
4142
- [Two-way object serialization while using one model with Jackson and Spring Boot](two-way-object-serialization)

mock-statics-with-mockito/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<version>${version.assertj-core}</version>
4444
<scope>test</scope>
4545
</dependency>
46+
<dependency>
47+
<groupId>net.bytebuddy</groupId>
48+
<artifactId>byte-buddy</artifactId>
49+
<version>${version.byte-buddy}</version>
50+
<scope>test</scope>
51+
</dependency>
4652
</dependencies>
4753

4854
</project>

pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<module>instant-server-ssl-reloading-with-quarkus</module>
2525
<module>instant-ssl-reloading-with-spring-tomcat</module>
2626
<module>bypassing-overruling-ssl-configuration</module>
27+
<module>trust-me</module>
2728
</modules>
2829

2930
<licenses>
@@ -47,7 +48,7 @@
4748
</developers>
4849

4950
<properties>
50-
<version.java>11</version.java>
51+
<version.java>21</version.java>
5152
<version.maven-surefire-plugin>3.0.0-M7</version.maven-surefire-plugin>
5253
<version.maven-fail-safe>3.0.0-M7</version.maven-fail-safe>
5354
<version.maven-compiler-plugin>3.10.1</version.maven-compiler-plugin>
@@ -62,6 +63,7 @@
6263
<version.sslcontext-kickstart>8.3.6</version.sslcontext-kickstart>
6364
<version.logcaptor>2.9.3</version.logcaptor>
6465
<version.spring>3.3.2</version.spring>
66+
<version.javafx>21.0.3</version.javafx>
6567
<version-tomcat>10.1.26</version-tomcat>
6668
<version.aspectweaver>1.9.22.1</version.aspectweaver>
6769
<version.jackson>2.17.2</version.jackson>
@@ -86,8 +88,9 @@
8688
<version.assertj-core>3.23.1</version.assertj-core>
8789
<version.junit>5.10.3</version.junit>
8890
<version.junit-platform>1.10.3</version.junit-platform>
89-
<version.mockito>5.12.0</version.mockito>
91+
<version.mockito>5.13.0</version.mockito>
9092
<version.mockito-inline>5.2.0</version.mockito-inline>
93+
<version.byte-buddy>1.15.1</version.byte-buddy>
9194
<version.consolecaptor>1.0.3</version.consolecaptor>
9295
<version.postgresql>42.5.0</version.postgresql>
9396
<version.testcontainers-postgresql>1.17.3</version.testcontainers-postgresql>

trust-me/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Trust Me 🔐
2+
A proof-of-concept GUI for prompting an user when a certificate is not trusted yet. The ssl configuration will be reloaded during runtime.
3+
4+
This GUI app demonstrates the feature of [Trusting additional new certificates at runtime](https://github.com/Hakky54/sslcontext-kickstart?tab=readme-ov-file#trust-additional-new-certificates-at-runtime) from the library [sslcontext-kickstart](https://github.com/Hakky54/sslcontext-kickstart)
5+
It might occur that your truststore has outdated certificates and is not easy to maintain or it just calls servers which has recently updated their certificates.
6+
This option demonstrates how to integrate it in your GUI app, and it will prompt when the certificate is not trusted yet, which gives the option to the end-user to either trust or reject it.
7+
8+
## Demo
9+
![alt text](https://github.com/Hakky54/java-tutorials/blob/main/trust-me/blob/master/images/demo.gif?raw=true)
10+
11+
## Running locally
12+
13+
### Minimum requirements
14+
- JDK 21
15+
- Maven
16+
- Terminal
17+
18+
Although this project requires JDK 21, the [library](https://github.com/Hakky54/sslcontext-kickstart) itself is compatible with JDK 8 and therefor will work with that version.
19+
20+
Run the following commands in your terminal:
21+
22+
```bash
23+
mvn clean package
24+
mvn spring-boot:run
25+
```
26+
27+
## Contributing
28+
29+
There are plenty of ways to contribute to this project:
30+
31+
* Give it a star
32+
* Submit a PR

trust-me/images/demo.gif

2.41 MB
Loading

trust-me/pom.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.github.hakky54</groupId>
8+
<artifactId>java-tutorials</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>trust-me</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.github.hakky54</groupId>
17+
<artifactId>sslcontext-kickstart</artifactId>
18+
<version>${version.sslcontext-kickstart}</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.openjfx</groupId>
23+
<artifactId>javafx-base</artifactId>
24+
<version>${version.javafx}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.openjfx</groupId>
28+
<artifactId>javafx-fxml</artifactId>
29+
<version>${version.javafx}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.openjfx</groupId>
33+
<artifactId>javafx-controls</artifactId>
34+
<version>${version.javafx}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.openjfx</groupId>
38+
<artifactId>javafx-graphics</artifactId>
39+
<version>${version.javafx}</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter</artifactId>
45+
<version>${version.spring}</version>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<version>${version.maven-compiler-plugin}</version>
55+
<configuration>
56+
<target>${version.java}</target>
57+
<release>${version.java}</release>
58+
</configuration>
59+
</plugin>
60+
61+
<plugin>
62+
<groupId>org.codehaus.mojo</groupId>
63+
<artifactId>exec-maven-plugin</artifactId>
64+
<version>${version.exec-maven-plugin}</version>
65+
<executions>
66+
<execution>
67+
<goals>
68+
<goal>java</goal>
69+
</goals>
70+
</execution>
71+
</executions>
72+
<configuration>
73+
<mainClass>nl.altindag.ssl.trustme.App</mainClass>
74+
</configuration>
75+
</plugin>
76+
77+
<plugin>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-maven-plugin</artifactId>
80+
<version>${version.spring}</version>
81+
<configuration>
82+
<finalName>trust-me</finalName>
83+
<mainClass>nl.altindag.ssl.trustme.App</mainClass>
84+
</configuration>
85+
<executions>
86+
<execution>
87+
<goals>
88+
<goal>repackage</goal>
89+
</goals>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
94+
</plugins>
95+
96+
<resources>
97+
<resource>
98+
<directory>src/main/resources</directory>
99+
<includes>
100+
<include>mainscreen.fxml</include>
101+
<include>banner.txt</include>
102+
</includes>
103+
</resource>
104+
</resources>
105+
</build>
106+
107+
</project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.ssl.trustme;
17+
18+
import javafx.application.Application;
19+
import javafx.application.Platform;
20+
import javafx.fxml.FXMLLoader;
21+
import javafx.scene.Parent;
22+
import javafx.scene.Scene;
23+
import javafx.stage.Stage;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.boot.builder.SpringApplicationBuilder;
26+
import org.springframework.context.ConfigurableApplicationContext;
27+
28+
import java.io.IOException;
29+
import java.util.function.Function;
30+
31+
@SpringBootApplication
32+
public class App extends Application {
33+
34+
private static final String TITLE = "Trust Me";
35+
private ConfigurableApplicationContext applicationContext;
36+
private final Function<String, FXMLLoader> fxmlLoaderFunction = fxml -> new FXMLLoader(this.getClass().getResource(fxml));
37+
38+
private Parent root;
39+
40+
@Override
41+
public void init() throws IOException {
42+
applicationContext = new SpringApplicationBuilder(App.class)
43+
.headless(false)
44+
.run(getParameters().getRaw().toArray(String[]::new));
45+
46+
FXMLLoader fxmlLoader = fxmlLoaderFunction.apply("/mainscreen.fxml");
47+
fxmlLoader.setControllerFactory(applicationContext::getBean);
48+
root = fxmlLoader.load();
49+
}
50+
51+
@Override
52+
public void start(Stage stage) {
53+
Scene scene = new Scene(root);
54+
stage.setTitle(TITLE);
55+
stage.setScene(scene);
56+
stage.setWidth(500);
57+
stage.setHeight(400);
58+
stage.setResizable(false);
59+
60+
stage.show();
61+
}
62+
63+
@Override
64+
public void stop() {
65+
Platform.exit();
66+
applicationContext.stop();
67+
}
68+
69+
public static void main(String[] args) {
70+
launch(args);
71+
}
72+
73+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.ssl.trustme;
17+
18+
public class AppStarter {
19+
20+
public static void main(String[] args) {
21+
App.main(args);
22+
}
23+
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.altindag.ssl.trustme.config;
17+
18+
import nl.altindag.ssl.SSLFactory;
19+
import nl.altindag.ssl.trustme.service.TrustMeService;
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.context.annotation.Lazy;
23+
24+
import javax.net.ssl.X509ExtendedTrustManager;
25+
import java.net.http.HttpClient;
26+
import java.nio.file.Path;
27+
28+
@Configuration
29+
public class ClientConfig {
30+
31+
private static final Path TRUSTSTORE_PATH = Path.of(System.getProperty("user.dir"), "truststore.jks");
32+
private static final char[] TRUSTSTORE_PASSWORD = "changeit".toCharArray();
33+
private static final String TRUSTSTORE_TYPE = "PKCS12";
34+
35+
@Bean
36+
public HttpClient httpClient(SSLFactory sslFactory) {
37+
return HttpClient.newBuilder()
38+
.sslContext(sslFactory.getSslContext())
39+
.sslParameters(sslFactory.getSslParameters())
40+
.build();
41+
}
42+
43+
@Bean
44+
public SSLFactory sslFactory(@Lazy TrustMeService trustMeService) {
45+
return SSLFactory.builder()
46+
.withInflatableTrustMaterial(TRUSTSTORE_PATH, TRUSTSTORE_PASSWORD, TRUSTSTORE_TYPE, trustMeService::verify)
47+
.build();
48+
}
49+
50+
@Bean
51+
public X509ExtendedTrustManager trustManager(SSLFactory sslFactory) {
52+
return sslFactory.getTrustManager().orElseThrow();
53+
}
54+
55+
}

0 commit comments

Comments
 (0)