Skip to content

Commit

Permalink
Merge branch 'v3.x.x' into reboot/fix/authentication_header_for_route…
Browse files Browse the repository at this point in the history
…d_requests
  • Loading branch information
richard-salac authored Feb 24, 2025
2 parents 4f65e6b + d7bf3bb commit 7163495
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
39 changes: 39 additions & 0 deletions client-cert-auth-sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Run Client Certificate Authentication Sample

This project is a Java-based client that performs authentication using a client certificate.
It utilizes the Apache HTTP Client to send an HTTPS request with client certificate authentication.

## Prerequisites

1. Java 17
2. A valid trusted client certificate stored in a PKCS12 keystore (.p12 or .pfx file)

## Running the application

1. Build the client-cert-auth-sample
2. Export the following environment variables:

**macOS:**

```shell
export API_URL="<API_URL>"
export CLIENT_CERT_PATH="<CLIENT_CERT_PATH>"
export CLIENT_CERT_PASSWORD="<CLIENT_CERT_PASSWORD>"
export CLIENT_CERT_ALIAS="<CLIENT_CERT_ALIAS>"
export PRIVATE_KEY_ALIAS="<PRIVATE_KEY_ALIAS>"
```
**Windows:**

```shell
set API_URL="<API_URL>"
set CLIENT_CERT_PATH="<CLIENT_CERT_PATH>"
set CLIENT_CERT_PASSWORD="<CLIENT_CERT_PASSWORD>"
set CLIENT_CERT_ALIAS="<CLIENT_CERT_ALIAS>"
set PRIVATE_KEY_ALIAS="<PRIVATE_KEY_ALIAS>"
```

3. Run the JAR located inside the `build/libs` folder with the SSL debug argument:
```shell
java -jar client-cert-auth-sample.jar -Djavax.net.debug=all
```
This will output detailed information about the SSL handshake and certificate validation process.
11 changes: 11 additions & 0 deletions client-cert-auth-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ dependencies {
test {
useJUnitPlatform()
}

jar {
manifest {
attributes 'Main-Class': 'org.zowe.apiml.Main'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

11 changes: 6 additions & 5 deletions client-cert-auth-sample/src/main/java/org/zowe/apiml/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.util.Optional;

public class Main {

private static final String API_URL = "https://localhost:8080/gateway/api/v1/auth/login"; // Replace with your API URL
private static final String CLIENT_CERT_PATH = "../keystore/client_cert/client-certs.p12"; // Replace with your client cert path
private static final String CLIENT_CERT_PASSWORD = "password"; // Replace with your cert password
private static final String CLIENT_CERT_ALIAS = "apimtst"; // Replace with your signed client cert alias
private static final String PRIVATE_KEY_ALIAS = "apimtst"; // Replace with your private key alias
private static final String API_URL = Optional.ofNullable(System.getenv("API_URL")).orElse("https://localhost:8080") + "/gateway/api/v1/auth/login"; // Replace with your API URL
private static final String CLIENT_CERT_PATH = Optional.ofNullable(System.getenv("CLIENT_CERT_PATH")).orElse("client-cert.p12"); // Replace with your client cert path
private static final String CLIENT_CERT_PASSWORD = Optional.ofNullable(System.getenv("CLIENT_CERT_PASSWORD")).orElse("password"); // Replace with your cert password
private static final String CLIENT_CERT_ALIAS = Optional.ofNullable(System.getenv("CLIENT_CERT_ALIAS")).orElse("apimtst"); // Replace with your signed client cert alias
private static final String PRIVATE_KEY_ALIAS = Optional.ofNullable(System.getenv("PRIVATE_KEY_ALIAS")).orElse("apimtst"); // Replace with your private key alias


public static void main(String[] args) {
Expand Down

0 comments on commit 7163495

Please sign in to comment.