Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
bin/
.vscode/
.gradle/
build/
.api-dev/
*.so
.vscode
bin/
zos-utils/.api-dev/
*.DS_Store
.api-dev/
*.jar
build/
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ artifactoryPublishingMavenRepo=https://zowe.jfrog.io/zowe/libs-release-local
artifactoryPublishingMavenSnapshotRepo=https://zowe.jfrog.io/zowe/libs-snapshot-local

# Artifacts version
version=2.0.8-SNAPSHOT
version=2.1.0-SNAPSHOT

defaultSpringBootVersion=2.0.2.RELEASE
defaultSpringBootCloudVersion=2.0.0.RELEASE
Expand Down
1 change: 1 addition & 0 deletions zos-utils/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ deploy/templates/jcl/out
deploy/config/local.ts
node_modules

build/
*.so
150 changes: 27 additions & 123 deletions zos-utils/src/main/java/org/zowe/commons/attls/AttlsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,225 +9,129 @@
*/
package org.zowe.commons.attls;

/**
* This class publish all AT-TLS information about the session. As input are two parameters:
* - id - id of filedescription to attach right session
* - alwaysLoadCertificate - define, if certificate should be fetch together with basic information. It can save one
* more call of IOCTL in case certificate is always required. Otherwise library fetch certificate only if you call
* method getCertificate.
* <p>
* This context read value lazy, it means that until you call any method, no data are fetched. In case of getting any
* information, library make call on first time to query or certificate and cache them in internal block of bytes
* (see {@link AttlsContext#ioctl}. All java object are then created just once time and store into cache properties.
* Next calling returns only those cached value. If you want to fetch new data, you should call method
* {@link AttlsContext#clean()}.
* <p>
* For fetching a certificate is needed to prepare memory before, its size is defined by
* {@link AttlsContext#BUFFER_CERTIFICATE_LENGTH}.
*/
public class AttlsContext {
public interface AttlsContext {

/**
* Name of native library
*/
public static final String ATTLS_LIBRARY_NAME = "zowe-attls";
/**
* Size of buffer to fetch certificate
*/
private static final int BUFFER_CERTIFICATE_LENGTH = 10240;

static {
if ("z/os".equalsIgnoreCase(System.getProperty("os.name"))) {
System.loadLibrary(ATTLS_LIBRARY_NAME);
}
}

/**
* Control flag to identify if certificate should be fetch in each query call or not
*/
private final boolean alwaysLoadCertificate;

/**
* FileDescriptior of socket
*/
private int id;
/**
* Request memory data
*/
private byte[] ioctl;
/**
* Buffer for storing certificate
*/
private byte[] bufferCertificate;

/**
* true if query data are loaded
*/
private boolean queryLoaded;
/**
* true if certificate is loaded
*/
private boolean certificateLoaded;

/**
* cache for loaded values from ioctl
*/
private StatPolicy statPolicyCache;
private StatConn statConnCache;
private Protocol protocolCache;
private String negotiatedCipher2Cache;
private SecurityType securityTypeCache;
private String userIdCache;
private Fips140 fips140Cache;
private String negotiatedCipher4Cache;
private String negotiatedKeyShareCache;
private byte[] certificateCache;

/**
* Create context of socket identified by FileDescriptor id ({@link java.io.FileDescriptor},
* {@link sun.nio.ch.IOUtil#fdVal(java.io.FileDescriptor)}).
*
* @param id filedescriptor of socket
* @param alwaysLoadCertificate if set true, first query call will fetch also a certificate, otherwise it will be
* loaded in first call of {@link AttlsContext#getCertificate}
*/
public AttlsContext(int id, boolean alwaysLoadCertificate) {
this.id = id;
this.alwaysLoadCertificate = alwaysLoadCertificate;
}
String ATTLS_LIBRARY_NAME = "zowe-attls";

/**
* Clean all cached value. Next call will fetch new data via ioctl.
*/
public native void clean();
void clean();

/**
* Indicates the policy status for the connection at the time of policy lookup always returned (except in error cases)
*
* @return policy status
* @throws UnknownEnumValueException StatPolicy does not contain a value (AT-TLS is newer than library)
* @throws IoctlCallException unexpected error in call of ioctl
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native StatPolicy getStatPolicy() throws UnknownEnumValueException, IoctlCallException;
StatPolicy getStatPolicy() throws UnknownEnumValueException, IoctlCallException;

/**
* Indicates the security status for the connection - always returned (except in error cases)
*
* @return security status
* @throws UnknownEnumValueException StatConn does not contain a value (AT-TLS is newer than library)
* @throws IoctlCallException unexpected error in call of ioctl
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native StatConn getStatConn() throws UnknownEnumValueException, IoctlCallException;
StatConn getStatConn() throws UnknownEnumValueException, IoctlCallException;

/**
* Indicates the SSL protocol in use for the connection. If connection is not secure, returns
* {@link Protocol#NON_SECURE}
*
* @return SSL protocol
* @throws UnknownEnumValueException Protocol does not contain a value (AT-TLS is newer than library)
* @throws IoctlCallException unexpected error in call of ioctl
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native Protocol getProtocol() throws UnknownEnumValueException, IoctlCallException;
Protocol getProtocol() throws UnknownEnumValueException, IoctlCallException;

/**
* Indicates the negotiated cipher in use for the connection - returned when connection is secure
* Note: When the negotiated cipher requires four characters, this field will contain the characters '4X'.
* {@link org.zowe.commons.attls.AttlsContext#getNegotiatedCipher4()}
*
* {@link AttlsContext#getNegotiatedCipher4()}
* @return negotiated cipher in use (2 character)
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native String getNegotiatedCipher2() throws IoctlCallException;
String getNegotiatedCipher2() throws IoctlCallException;

/**
* Indicates the security type for the connection - returned when policy defined for connection
*
* @return the security type for the connection
* @throws UnknownEnumValueException Protocol does not contain a value (AT-TLS is newer than library)
* @throws IoctlCallException unexpected error in call of ioctl
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native SecurityType getSecurityType() throws UnknownEnumValueException, IoctlCallException;
SecurityType getSecurityType() throws UnknownEnumValueException, IoctlCallException;

/**
* Indicates the partner user ID - returned when available.
*
* @return partner user ID
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native String getUserId() throws IoctlCallException;
String getUserId() throws IoctlCallException;

/**
* Indicates the level of FIPS compliance, if any - returned when connection is secure for connection
*
* @return level of FIPS compliance
* @throws UnknownEnumValueException Protocol does not contain a value (AT-TLS is newer than library)
* @throws IoctlCallException unexpected error in call of ioctl
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native Fips140 getFips140() throws UnknownEnumValueException, IoctlCallException;
Fips140 getFips140() throws UnknownEnumValueException, IoctlCallException;

/**
* Reserved for IBM use
* <p>
*
* Constants for TTLSi_Flags:
* TTLS_FTPDATACONN 0x01
* TTLS_FTPDATACONN 0x01
*
* @return AT-TLS flags
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native byte getFlags() throws IoctlCallException;
byte getFlags() throws IoctlCallException;

/**
* Indicates the four character negotiated cipher in use for the connection - returned when connection is secure
*
* @return negotiated cipher in use (4 character)
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native String getNegotiatedCipher4() throws IoctlCallException;

String getNegotiatedCipher4() throws IoctlCallException;

/**
* Returns partner certificate - returned when available. Maximum length of certificate is determinated by
* {@link AttlsContext#BUFFER_CERTIFICATE_LENGTH}
*
* {@link AttlsContextImpl#BUFFER_CERTIFICATE_LENGTH}
* @return partner certificate
* @throws IoctlCallException unexpected error in call of ioctl
*/
public native byte[] getCertificate() throws IoctlCallException;
byte[] getCertificate() throws IoctlCallException;

/**
* Initialize the SSL connection
*
* @throws IoctlCallException cannot initialize (ie. not in controlled mode, missing configuration etc.)
*/
public native void initConnection() throws IoctlCallException;
void initConnection() throws IoctlCallException;

/**
* Reset the Session
*
* @throws IoctlCallException cannot reset session (ie. not in controlled mode, missing configuration etc.)
*/
public native void resetSession() throws IoctlCallException;
void resetSession() throws IoctlCallException;

/**
* Reset the Cipher
*
* @throws IoctlCallException cannot reset cipher (ie. not in controlled mode, missing configuration etc.)
*/
public native void resetCipher() throws IoctlCallException;
void resetCipher() throws IoctlCallException;

/**
* Stop the SSL connection
*
* @throws IoctlCallException cannot stop connection (ie. not in controlled mode, missing configuration etc.)
*/
public native void stopConnection() throws IoctlCallException;
void stopConnection() throws IoctlCallException;

/**
* Allow SSL handshake to timeout
*
* @throws IoctlCallException cannot allow hand shake timeout (ie. not in controlled mode, missing configuration etc.)
*/
public native void allowHandShakeTimeout() throws IoctlCallException;

void allowHandShakeTimeout() throws IoctlCallException;

}
Loading