Skip to content

Commit e104f84

Browse files
Merge pull request #609 from zowe/aug7
Basic connection does not work on untrusted z/OSMF server.
2 parents 8b47e34 + ee2717d commit e104f84

5 files changed

Lines changed: 171 additions & 72 deletions

File tree

README.md

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -168,82 +168,66 @@ and the JSON error report document body response is:
168168
{"rc":4,"reason":13,"category":1,"message":"query parm dslevel= or volser= must be specified"}
169169

170170
## Authenticating to z/OSMF
171-
172-
Since the release of the SDK, the authentication of each REST API call is done with BASIC authentication.
173-
174-
With SDK release version 3, Web TOKEN authentication was added.
175-
176-
With project version 4, SSL authentication from a certificate file was added.
177-
178-
With three types of authentication available, the AuthType enum class was introduced to represent each type.
179-
180-
This enum is used to send it to the ZosConnection constructor denoting the type of authentication to perform.
181171

182-
For BASIC, the following ZosConnection object is specified to perform BASIC authentication:
172+
All REST API calls to z/OSMF are transmitted over an **HTTPS** encrypted transport channel (TLS). The SDK supports three authentication types (`AuthType`) to prove client identity over that encrypted channel:
183173

184-
```java
185-
ZosConnection connection = ZosConnectionFactory.createBasicConnection("host", "zosmfPort", "user", "password");
186-
```
174+
- **BASIC (`AuthType.BASIC`)**: Authenticates client identity using a username and password sent in the HTTP `Authorization: Basic` header over HTTPS.
175+
- **TOKEN (`AuthType.TOKEN`)**: Authenticates client identity using an authentication token/cookie (e.g. JWT or LTPA token) retrieved via `zosmfLogin` over HTTPS.
176+
- **SSL (`AuthType.SSL`)**: Authenticates client identity via **Mutual TLS (mTLS)** using a PKCS12 (`.p12`) client certificate file containing the client's certificate and private key. No username or password is required because z/OSMF maps the client certificate directly to a mainframe security ID (RACF / ACF2 / Top Secret).
187177

188-
Basic authentication means that the http request contains a BASIC header representing the username and password encrypted.
178+
### Client Authentication Examples
189179

190-
For web TOKEN, the following ZosConnection object is specified:
180+
For **BASIC** authentication, specify username and password:
191181

192-
```java
193-
ZosConnection connection = ZosConnectionFactory.createTokenConnection("host", "port", new Cookie("xxx", "xxx"));
182+
```java
183+
ZosConnection connection = ZosConnectionFactory.createBasicConnection("host", 10443, "user", "password");
194184
```
195185

196-
With the zosmfauth package, ZosmfAuth provides an API (zosmfLogin) to retrieve authentication tokens (a JSON Web and an LTPA TOKEN) on a BASIC authentication request. This package contains an API that can also be used to delete the current store of JSON Web and LPTA tokens.
197-
198-
See the README.MD in the zosmfauth package for code examples on retrieving an initial token and then using it for further requests without needing user and password information.
186+
For **Web TOKEN** authentication, specify the token cookie:
199187

200-
Web TOKEN support must be enabled on your z/OSMF system. For more information, see Enabling JSON Web TOKEN support in the IBM z/OS Management Facility Configuration Guide.
188+
```java
189+
ZosConnection connection = ZosConnectionFactory.createTokenConnection("host", 10443, new Cookie("xxx", "xxx"));
190+
```
201191

202-
See [README.md](https://github.com/zowe/zowe-client-java-sdk/blob/main/src/main/java/zowe/client/sdk/zosmfauth/README.md) in zosmfauth package for further details.
192+
With the `zosmfauth` package, `ZosmfAuth` provides an API (`zosmfLogin`) to retrieve authentication tokens (JSON Web and LTPA tokens) using a BASIC request. Web TOKEN support must be enabled on your z/OSMF system. See [README.md](https://github.com/zowe/zowe-client-java-sdk/blob/main/src/main/java/zowe/client/sdk/zosmfauth/README.md) in the `zosmfauth` package for further details and code examples.
203193

204-
For SSL/TLS client certificate authentication (mTLS), create a `ZosConnection` object using a PKCS12 (`.p12`) key store file:
194+
For **SSL/TLS Client Certificate Authentication (mTLS)**, create a `ZosConnection` object using a PKCS12 (`.p12`) key store file:
205195

206196
```java
207-
ZosConnection connection = ZosConnectionFactory.createSslConnection("host", 443, "c:/file.p12", "certpassword");
197+
ZosConnection connection = ZosConnectionFactory.createSslConnection("host", 10443, "c:/file.p12", "certpassword");
208198
```
209199

210-
The `.p12` file houses your client certificate and private key, which z/OSMF uses to authenticate your client application.
211-
212-
For `certFilePath`, specify the location and file name of the `.p12` file. For `certPassword`, specify the password/passphrase for the key store.
200+
The `.p12` file houses your client certificate and private key, which z/OSMF uses to authenticate your client application without needing a username or password. For `certFilePath`, specify the location and file name of the `.p12` file. For `certPassword`, specify the password for the key store.
213201

214202
### Server Certificate Validation Modes
215203

216-
When validating the z/OSMF server's SSL certificate during an SSL connection, the SDK supports three modes:
204+
During the HTTPS TLS handshake, Java validates the z/OSMF **server's SSL certificate**. Server certificate validation applies across all authentication types (`BASIC`, `TOKEN`, and `SSL`). The SDK supports three server certificate validation modes:
217205

218206
**Default Mode (Standard Certificate Authority Validation)**
219-
- **How it works**: By default (when no system properties are set), the SDK validates the z/OSMF server certificate against the JVM's standard CA truststore (`cacerts`) and enforces standard hostname verification.
220-
- **When to use**: Production or standard enterprise environments where z/OSMF uses a certificate issued by a public CA or an enterprise Root CA installed in your Java runtime's `cacerts`.
221-
207+
- **How it works**: By default (when no system properties are set), the SDK validates the z/OSMF server certificate against the JVM's standard CA truststore (`cacerts`) and enforces standard hostname verification. In many enterprise-managed environments, corporate CAs or public CAs are already pre-installed in Java's `cacerts` out-of-the-box, so no additional configuration is needed. If your corporate CA is installed only in the Windows Certificate Store and not in Java's `cacerts`, setting `-Djavax.net.ssl.trustStoreType=WINDOWS-ROOT` is an optional fallback to instruct Java to read the OS truststore.
208+
- **When to use**: Production or enterprise environments where z/OSMF uses a certificate issued by a public CA or an enterprise Root CA installed in your Java runtime's `cacerts` or Windows certificate store.
209+
222210
**Custom TrustStore (`zowe.sdk.truststore.path`)**
223-
- **How it works**: To support self-signed z/OSMF servers securely without using `TRUST_ALL_CERTS`, the SDK allows users to specify a separate TrustStore file (`.p12` or `.jks`) that contains the server's certificate or CA, rather than reusing the client's mTLS `.p12` file (which contains client credentials). Set system property `zowe.sdk.truststore.path` to the path of the server TrustStore and optionally `zowe.sdk.truststore.password`. The SDK loads this TrustStore into a `TrustManagerFactory` to validate the server certificate against it while disabling hostname verification.
224-
- **How to set**:
225-
211+
- **How it works**: To support self-signed z/OSMF servers securely without bypassing TLS validation, the SDK allows users to specify a separate TrustStore file (`.p12` or `.jks`) that contains the server's public certificate or CA. Set system property `zowe.sdk.truststore.path` to the path of the server TrustStore and optionally `zowe.sdk.truststore.password`. The SDK loads this TrustStore into a `TrustManagerFactory` to validate the server certificate against it while disabling hostname verification.
212+
- **How to set**:
226213

227214
System.setProperty("zowe.sdk.truststore.path", "/path/to/server-truststore.p12");
228215
System.setProperty("zowe.sdk.truststore.password", "truststorePassword"); // Optional
229-
216+
230217
Or via JVM launch argument: `-Dzowe.sdk.truststore.path=/path/to/server-truststore.p12`
231218

232-
- **When to use**: Staging, testing, or enterprise environments where z/OSMF uses a self-signed or internal CA certificate and you want strict certificate validation without modifying global JVM `cacerts` or disabling TLS verification.
219+
- **When to use**: Staging, testing, or enterprise environments where z/OSMF uses a self-signed or internal CA certificate and you want strict certificate validation without modifying global JVM `cacerts` or disabling TLS verification.
233220

234221
**Insecure Mode (`zowe.sdk.allow.insecure.connection=true`)**
235-
- **How it works**: Insecure mode is an explicit, optional developer opt-in (disabled by default) designed specifically to bypass server TLS certificate checks for self-signed test environments when users do not have the server certificate or CA in a truststore file. Setting system property `zowe.sdk.allow.insecure.connection` to `"true"` uses `TRUST_ALL_CERTS` to bypass server certificate validation (similar to `curl -k` or `git config http.sslVerify false`) and disables hostname verification. A prominent warning is logged on connection setup.
236-
- **How to set**:
222+
- **How it works**: Insecure mode is an explicit, optional developer opt-in (disabled by default) designed specifically to bypass server TLS certificate checks for self-signed test environments when users do not have the server certificate or CA in a truststore file. Setting system property `zowe.sdk.allow.insecure.connection` to `"true"` uses `TRUST_ALL_CERTS` to bypass server certificate validation (similar to `curl -k` or `git config http.sslVerify false`) and disables hostname verification. A prominent warning is logged on connection setup.
223+
- **How to set**:
237224

225+
System.setProperty("zowe.sdk.allow.insecure.connection", "true");
238226

239-
System.setProperty("zowe.sdk.allow.insecure.connection", "true");
240-
241227
Or via JVM launch argument: `-Dzowe.sdk.allow.insecure.connection=true`
242-
- **When to use**: Isolated test, local sandbox, or lab environments when connecting to self-signed z/OSMF servers without a truststore file.
243-
244-
This same `zowe.sdk.allow.insecure.connection` system property also controls SSH host key verification for the zosuss package (see below). By default, both are verified/enforced; setting this property to `true` disables verification for both and is logged as a warning each time it happens, so only use it when the risk (a man-in-the-middle presenting a forged certificate or host key) is understood and accepted, such as in isolated test environments.
228+
- **When to use**: Isolated test, local sandbox, or lab environments when connecting to self-signed z/OSMF servers without a truststore file.
245229

246-
BASIC and TOKEN authentication always verify the server's TLS certificate using the JVM's default trust store and have no insecure opt-out - self-signed certificates are only a concern for SSL (client-certificate) authentication, so the options above apply specifically to SSL authentication and SSH host key checking.
230+
This same `zowe.sdk.allow.insecure.connection` system property also controls SSH host key verification for the `zosuss` package (see below). By default, both are verified/enforced; setting this property to `true` disables verification for both and is logged as a warning each time it happens.
247231

248232
## SSH Connections (USS Commands)
249233

@@ -318,27 +302,27 @@ Thin JAR (recommended):
318302
<dependency>
319303
<groupId>org.zowe.client.java.sdk</groupId>
320304
<artifactId>zowe-client-java-sdk</artifactId>
321-
<version>7.0.1</version>
305+
<version>7.0.2</version>
322306
</dependency>
323307

324308
Fat JAR (with dependencies):
325309

326310
<dependency>
327311
<groupId>org.zowe.client.java.sdk</groupId>
328312
<artifactId>zowe-client-java-sdk</artifactId>
329-
<version>7.0.1</version>
313+
<version>7.0.2</version>
330314
<classifier>jar-with-dependencies</classifier>
331315
</dependency>
332316

333317
For a Gradle project add the SDK as a dependency by updating your `build.gradle` as follows:
334318

335319
Thin JAR (recommended):
336320

337-
implementation group: 'org.zowe.client.java.sdk', name: 'zowe-client-java-sdk', version: '7.0.1'
321+
implementation group: 'org.zowe.client.java.sdk', name: 'zowe-client-java-sdk', version: '7.0.2'
338322

339323
Fat JAR (with dependencies):
340324

341-
implementation group: 'org.zowe.client.java.sdk', name: 'zowe-client-java-sdk', version: '7.0.1', classifier: 'jar-with-dependencies'
325+
implementation group: 'org.zowe.client.java.sdk', name: 'zowe-client-java-sdk', version: '7.0.2', classifier: 'jar-with-dependencies'
342326

343327
## Publishing to Maven Central
344328

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.zowe.client.java.sdk</groupId>
88
<artifactId>zowe-client-java-sdk</artifactId>
9-
<version>7.0.1</version>
9+
<version>7.0.2</version>
1010

1111
<packaging>jar</packaging>
1212
<name>${project.groupId}:${project.artifactId}</name>

src/main/java/zowe/client/sdk/core/AuthType.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,50 @@
1010
package zowe.client.sdk.core;
1111

1212
/**
13-
* Class to represent an authentication type used for the http request.
13+
* Represents the authentication method used for HTTP/HTTPS requests to z/OSMF.
14+
* <p>
15+
* <b>Transport Encryption (HTTPS/TLS) vs. Client Authentication:</b>
16+
* <br>
17+
* All requests to z/OSMF are transmitted over HTTPS, which requires transport-layer TLS encryption.
18+
* The {@link AuthType} enum defines how the <i>client's identity</i> is proven over that encrypted channel:
19+
* <ul>
20+
* <li>{@link #BASIC}: Authenticates client identity using a username and password in the HTTP
21+
* {@code Authorization: Basic} header.</li>
22+
* <li>{@link #TOKEN}: Authenticates client identity using a token or cookie (e.g. JWT or LTPA)
23+
* retrieved from a z/OSMF login request.</li>
24+
* <li>{@link #SSL}: Authenticates client identity using Mutual TLS (mTLS) via a PKCS12 ({@code .p12})
25+
* keystore containing a client certificate and private key. No username or password is required.</li>
26+
* </ul>
27+
* <p>
28+
* Server certificate validation across all authentication types can be configured using system properties
29+
* such as {@value zowe.client.sdk.rest.RestConstant#TRUSTSTORE_PATH_PROPERTY_NAME} ("zowe.sdk.truststore.path")
30+
* or {@value zowe.client.sdk.rest.RestConstant#INSECURE_PROPERTY_NAME} ("zowe.sdk.allow.insecure.connection").
1431
*
1532
* @author Frank Giordano
1633
* @version 7.0
1734
*/
1835
public enum AuthType {
1936

2037
/**
21-
* Authentication classic type. This represents the bearer header with the requirement
22-
* for the username and password to be specified within the ZosConnection object.
38+
* Classic Basic Authentication type.
39+
* <p>
40+
* Authenticates the client's identity by sending an HTTP {@code Authorization: Basic <base64>} header
41+
* containing the username and password specified in the {@link ZosConnection} object over an HTTPS encrypted channel.
2342
*/
2443
BASIC,
2544
/**
26-
* Authentication token type. This case represents using a cookie value to use for
27-
* authentication for the http request. A token can be retrieved by ZosmfLogin response payload
28-
* containing JSON Web and LPTA token(s).
45+
* Web Token Authentication type.
46+
* <p>
47+
* Authenticates the client's identity using a cookie/token value (e.g. JSON Web Token or LTPA token)
48+
* retrieved from a z/OSMF login response payload over an HTTPS encrypted channel.
2949
*/
3050
TOKEN,
3151
/**
32-
* Authentication SSL/TLS (mTLS) type. Represents using a PKCS12 certificate file (.p12) containing
33-
* the client certificate and private key for HTTPS requests.
52+
* Client Certificate Authentication (Mutual TLS / mTLS) type.
53+
* <p>
54+
* Authenticates the client's identity during the TLS handshake using a PKCS12 ({@code .p12}) key store
55+
* containing a client certificate and private key. Unlike {@link #BASIC}, no username or password is required
56+
* because the client's identity is verified directly by z/OSMF using the certificate.
3457
*/
3558
SSL
3659

0 commit comments

Comments
 (0)