-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added trust me project and bumped java to 21
Added trust me project and bumped java to 21
- Loading branch information
Showing
18 changed files
with
689 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Trust Me 🔐 | ||
A proof-of-concept GUI for prompting an user when a certificate is not trusted yet. The ssl configuration will be reloaded during runtime. | ||
|
||
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) | ||
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. | ||
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. | ||
|
||
## Demo | ||
![alt text](https://github.com/Hakky54/java-tutorials/blob/main/trust-me/images/demo.gif?raw=true) | ||
|
||
## Running locally | ||
|
||
### Minimum requirements | ||
- JDK 21 | ||
- Maven | ||
- Terminal | ||
|
||
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. | ||
|
||
Run the following commands in your terminal: | ||
|
||
```bash | ||
mvn clean package | ||
mvn spring-boot:run | ||
``` | ||
|
||
## Contributing | ||
|
||
There are plenty of ways to contribute to this project: | ||
|
||
* Give it a star | ||
* Submit a PR |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.hakky54</groupId> | ||
<artifactId>java-tutorials</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>trust-me</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.hakky54</groupId> | ||
<artifactId>sslcontext-kickstart</artifactId> | ||
<version>${version.sslcontext-kickstart}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openjfx</groupId> | ||
<artifactId>javafx-base</artifactId> | ||
<version>${version.javafx}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjfx</groupId> | ||
<artifactId>javafx-fxml</artifactId> | ||
<version>${version.javafx}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjfx</groupId> | ||
<artifactId>javafx-controls</artifactId> | ||
<version>${version.javafx}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjfx</groupId> | ||
<artifactId>javafx-graphics</artifactId> | ||
<version>${version.javafx}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
<version>${version.spring}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${version.maven-compiler-plugin}</version> | ||
<configuration> | ||
<target>${version.java}</target> | ||
<release>${version.java}</release> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>${version.exec-maven-plugin}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>nl.altindag.ssl.trustme.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${version.spring}</version> | ||
<configuration> | ||
<finalName>trust-me</finalName> | ||
<mainClass>nl.altindag.ssl.trustme.App</mainClass> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
|
||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>mainscreen.fxml</include> | ||
<include>banner.txt</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2022 Thunderberry. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.altindag.ssl.trustme; | ||
|
||
import javafx.application.Application; | ||
import javafx.application.Platform; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Parent; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Function; | ||
|
||
@SpringBootApplication | ||
public class App extends Application { | ||
|
||
private static final String TITLE = "Trust Me"; | ||
private ConfigurableApplicationContext applicationContext; | ||
private final Function<String, FXMLLoader> fxmlLoaderFunction = fxml -> new FXMLLoader(this.getClass().getResource(fxml)); | ||
|
||
private Parent root; | ||
|
||
@Override | ||
public void init() throws IOException { | ||
applicationContext = new SpringApplicationBuilder(App.class) | ||
.headless(false) | ||
.run(getParameters().getRaw().toArray(String[]::new)); | ||
|
||
FXMLLoader fxmlLoader = fxmlLoaderFunction.apply("/mainscreen.fxml"); | ||
fxmlLoader.setControllerFactory(applicationContext::getBean); | ||
root = fxmlLoader.load(); | ||
} | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
Scene scene = new Scene(root); | ||
stage.setTitle(TITLE); | ||
stage.setScene(scene); | ||
stage.setWidth(500); | ||
stage.setHeight(400); | ||
stage.setResizable(false); | ||
|
||
stage.show(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
Platform.exit(); | ||
applicationContext.stop(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
trust-me/src/main/java/nl/altindag/ssl/trustme/AppStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2022 Thunderberry. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.altindag.ssl.trustme; | ||
|
||
public class AppStarter { | ||
|
||
public static void main(String[] args) { | ||
App.main(args); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
trust-me/src/main/java/nl/altindag/ssl/trustme/config/ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2022 Thunderberry. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.altindag.ssl.trustme.config; | ||
|
||
import nl.altindag.ssl.SSLFactory; | ||
import nl.altindag.ssl.trustme.service.TrustMeService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
|
||
import javax.net.ssl.X509ExtendedTrustManager; | ||
import java.net.http.HttpClient; | ||
import java.nio.file.Path; | ||
|
||
@Configuration | ||
public class ClientConfig { | ||
|
||
private static final Path TRUSTSTORE_PATH = Path.of(System.getProperty("user.dir"), "truststore.jks"); | ||
private static final char[] TRUSTSTORE_PASSWORD = "changeit".toCharArray(); | ||
private static final String TRUSTSTORE_TYPE = "PKCS12"; | ||
|
||
@Bean | ||
public HttpClient httpClient(SSLFactory sslFactory) { | ||
return HttpClient.newBuilder() | ||
.sslContext(sslFactory.getSslContext()) | ||
.sslParameters(sslFactory.getSslParameters()) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public SSLFactory sslFactory(@Lazy TrustMeService trustMeService) { | ||
return SSLFactory.builder() | ||
.withInflatableTrustMaterial(TRUSTSTORE_PATH, TRUSTSTORE_PASSWORD, TRUSTSTORE_TYPE, trustMeService::verify) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public X509ExtendedTrustManager trustManager(SSLFactory sslFactory) { | ||
return sslFactory.getTrustManager().orElseThrow(); | ||
} | ||
|
||
} |
Oops, something went wrong.