Restrict WebSphere to TLSv1.2 (IBM MDM AE)

Server

security.xml

Change all SSL configs in security.xml to TLSv1.2 in all profiles including deployment manager profile

/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/config/cells/VPS1Cell01

/opt/IBM/WebSphere/AppServer/profiles/Dmgr01/config/cells/VPS1Cell01

Sample

*Make this change for all SSL configs defined in the file

 

<repertoire xmi:id=”SSLConfig_2″ alias=”NodeDefaultSSLSettings” managementScope=”ManagementScope_3″>
<setting xmi:id=”SecureSocketLayer_3″ clientAuthentication=”false” securityLevel=”HIGH” enabledCiphers=”” jsseProvider=”IBMJSSE2″ ssl
Protocol=”TLSv1.2” keyStore=”KeyStore_7″ trustStore=”KeyStore_2″ trustManager=”TrustManager_2″ keyManager=”KeyManager_1″>
<properties xmi:id=”Property_1529890233660″ name=”com.ibm.ssl.changed” value=”4″/>
</setting>
</repertoire>

 

ssl.client.props

Change all SSL protocol in ssl.client.xml to TLSv1.2 in all profiles including deployment manager profile

/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/properties

/opt/IBM/WebSphere/AppServer/profiles/Dmgr01/properties

Sample

com.ibm.ssl.protocol=TLSv1.2

Restart

Restart Deployment manager, node agents and nodes.

 

Client

IBM MDM BatchProcessor

If BatchProcessor could not connect to MDM instance after upgrading to TLSv1.2, change SSL protocol in ssl.client.props to TLSv1.2 in all BatchProcessor instances.

/opt/IBM/MDM/BatchProcessor/properties

Sample

com.ibm.ssl.protocol=TLSv1.2

Validation

Shell

openssl s_client -connect <hostname>:<secure port>

 

BouncyCastle PGP Encryption

Usage

-d file.encrypted privatekey.asc 12345

-e -ai file.txt publickey.asc 12345

Jars to be included:

bcmail-jdk15on-160.jar

bcpg-jdk15on-160.jar

bcpkix-jdk15on-160.jar

bcprov-ext-jdk15on-160.jar

bcprov-jdk15on-160.jar

bctls-jdk15on-160.jar

JCE Policy

Update JDK/JRE with unlimited JCE policy

Java Main


package com.sheriff

import java.io.File;

import org.bouncycastle.openpgp.examples.KeyBasedFileProcessor;

public class FileProcessor {
public static void main(String[] args) {
try {

// decryption flow
if (args[0].equalsIgnoreCase("-d")){
// if input file is empty, then skip decryption
if(new File(args[1]).length()==0L){
return;
}

//decrypt
KeyBasedFileProcessor.main(args);

// this is to delete the source file after decryption if needed
new File(args[1]).delete();

return;
}
// encryption flow
if (args[0].equalsIgnoreCase("-e")){
//encrypt
KeyBasedFileProcessor.main(args);
return;
}

} catch (Exception e) {
e.printStackTrace();
}
}
}

 

JAX-WS Client

Error

Caused by: java.lang.UnsupportedOperationException: Operation [getContextClassLoader] is not supported in jcl-over-slf4j. See also http://www.slf4j.org/codes.html#unsupported_operation_in_jcl_over_slf4j

Solution

Add -Dorg.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.SLF4JLogFactory

to VM arguments when running main.

Error

org.apache.axis2.AxisFault: WSWS7130E: No Secure Sockets Layer (SSL) configuration is available

Solution

Section Issue with Using IBM’s JAX-WS runtime at the below link

http://btarlton.blogspot.com/2013/03/ever-have-trouble-using-ssl-to-call-web.html

 

Error

org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory

Download jars from Apache Commons Logging and add to classpath

https://commons.apache.org/proper/commons-logging/download_logging.cgi

 

Set Basic Auth

//basic auth
BindingProvider bp = (BindingProvider)proxy._getDescriptor().getProxy();
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, “username”);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, “password”);

 

Print certain element as XML

https://stackoverflow.com/questions/2461232/jaxb-entity-print-out-as-xml

public String toXml(JAXBElement element) {
    try {
        JAXBContext jc = JAXBContext.newInstance(element.getValue().getClass());  
        Marshaller marshaller = jc.createMarshaller();  
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);  

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        marshaller.marshal(element, baos);
        return baos.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }      
    return "";
}

Print entire response XML

public void toXml() {
    try {
        JAXBContext ctx = JAXBContext.newInstance(User.class);
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(this, System.out);
    }
    catch (Exception e) {
    e.printStackTrace();
    }
}

Call it like:

log.info("Customers sent: "+user.toXml());

FormatXSDCForContract.java

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class FormatXSDCForContract {

 private static FileWriter fw = null;

 private static String [] baseDir = {
“C:\\sherFinancialServicesV4”,
“C:\\sherFinancialServicesV4-New”,
};
private static String [] filePath = {
“xmlns\\sher\\net\\mdm\\types\\common\\v4_0”,
“xmlns\\sher\\net\\mdm\\types\\contract\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\contract\\service\\contract\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\chain\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\party\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\party\\service\\party\\v5_0”
};
private static String [] fileName = {
“common.xsd”,
“domain.xsd”,
“domain.xsd”,
“domain.xsd”,
“party.xsd”
};

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println(FormatXSD.class.getPackage());

for (int i = 0; i < baseDir.length; i++){
for (int j = 0; j < filePath.length; j++){
try {
File inputFile = new File(baseDir[i]+”\\”+filePath[j]+”\\”+fileName[j]);
File outFile = new File(baseDir[i]+”\\copy\\”+filePath[j]);
outFile.mkdirs();
fw = new FileWriter(outFile+”\\”+fileName[j]);
String input=””;
Map ctMap = new HashMap<String, StringBuilder>();
readALineAtATime(inputFile, ctMap);
fw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

   }
}
}

private static void readALineAtATime(File inputFile, Map<String, StringBuilder> ctMap) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader(inputFile));
String line;
String ctName = null;
boolean firstLine = true;
while ((line = br.readLine()) != null) {
ctName = checkLineForComplexType(line, ctMap, ctName);
}
br.close();

// sort the keys
Set<String> keySet = ctMap.keySet();
Iterator<String> it = keySet.iterator();
List<String> keyList = new ArrayList<String>();
while (it.hasNext()){
keyList.add(it.next());
}
Collections.sort(keyList);

//print the keys
it = keyList.iterator();
while (it.hasNext()){
String key = it.next();
StringBuilder sb = ctMap.get(key);
//System.out.println(sb);
writeToFile(sb);
}

//close
fw.close();
}

 private static String checkLineForComplexType(String input, Map<String, StringBuilder> ctMap, String ctName) {
StringBuilder sb = new StringBuilder();
if (input.contains(“<?xml version=”)){
sb.append(input);
ctName = “1”;
ctMap.put(ctName, sb);
}else if (input.contains(“<xsd:complexType name=”)){
int start = input.indexOf(“\””);
int end = input.indexOf(“\”>”);
ctName = input.substring(start+1, end);
sb.append(input);
ctMap.put(ctName, sb);
}else{
sb = ctMap.get(ctName);
sb.append(“\n”);
sb.append(input);
ctMap.put(ctName, sb);
}
return ctName;
}

 private static void writeToFile(StringBuilder line) {
try {
fw.append(line);
fw.append(“\n”);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

FormatXSD.java

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class FormatXSD {

 private static FileWriter fw = null;

 private static String [] baseDir = {
“C:\\sherpartyV5”,
“C:\\sherpartyV5-New”,
};
private static String [] filePath = {
“xmlns\\sher\\net\\mdm\\types\\common\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\contract\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\chain\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\party\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\party\\service\\party\\v5_0”
};
private static String [] fileName = {
“common.xsd”,
“domain.xsd”,
“domain.xsd”,
“domain.xsd”,
“party.xsd”
};

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println(FormatXSD.class.getPackage());

for (int i = 0; i < baseDir.length; i++){
for (int j = 0; j < filePath.length; j++){
try {
File inputFile = new File(baseDir[i]+”\\”+filePath[j]+”\\”+fileName[j]);
File outFile = new File(baseDir[i]+”\\copy\\”+filePath[j]);
outFile.mkdirs();
fw = new FileWriter(outFile+”\\”+fileName[j]);
String input=””;
Map ctMap = new HashMap<String, StringBuilder>();
readALineAtATime(inputFile, ctMap);
fw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

   }
}
}

private static void readALineAtATime(File inputFile, Map<String, StringBuilder> ctMap) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader(inputFile));
String line;
String ctName = null;
boolean firstLine = true;
while ((line = br.readLine()) != null) {
ctName = checkLineForComplexType(line, ctMap, ctName);
}
br.close();

// sort the keys
Set<String> keySet = ctMap.keySet();
Iterator<String> it = keySet.iterator();
List<String> keyList = new ArrayList<String>();
while (it.hasNext()){
keyList.add(it.next());
}
Collections.sort(keyList);

//print the keys
it = keyList.iterator();
while (it.hasNext()){
String key = it.next();
StringBuilder sb = ctMap.get(key);
//System.out.println(sb);
writeToFile(sb);
}

//close
fw.close();
}

 private static String checkLineForComplexType(String input, Map<String, StringBuilder> ctMap, String ctName) {
StringBuilder sb = new StringBuilder();
if (input.contains(“<?xml version=”)){
sb.append(input);
ctName = “1”;
ctMap.put(ctName, sb);
}else if (input.contains(“<xsd:complexType name=”)){
int start = input.indexOf(“\””);
int end = input.indexOf(“\”>”);
ctName = input.substring(start+1, end);
sb.append(input);
ctMap.put(ctName, sb);
}else{
sb = ctMap.get(ctName);
sb.append(“\n”);
sb.append(input);
ctMap.put(ctName, sb);
}
return ctName;
}

 private static void writeToFile(StringBuilder line) {
try {
fw.append(line);
fw.append(“\n”);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

FormatXSD.java

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class FormatXSD {

 private static FileWriter fw = null;

 private static String [] baseDir = {
“C:\\sherpartyV5”,
“C:\\sherpartyV5-New”,
};
private static String [] filePath = {
“xmlns\\sher\\net\\mdm\\types\\common\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\contract\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\chain\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\party\\domain\\v5_0”,
“xmlns\\sher\\net\\mdm\\types\\party\\service\\party\\v5_0”
};
private static String [] fileName = {
“common.xsd”,
“domain.xsd”,
“domain.xsd”,
“domain.xsd”,
“party.xsd”
};

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println(FormatXSD.class.getPackage());

for (int i = 0; i < baseDir.length; i++){
for (int j = 0; j < filePath.length; j++){
try {
File inputFile = new File(baseDir[i]+”\\”+filePath[j]+”\\”+fileName[j]);
File outFile = new File(baseDir[i]+”\\copy\\”+filePath[j]);
outFile.mkdirs();
fw = new FileWriter(outFile+”\\”+fileName[j]);
String input=””;
Map ctMap = new HashMap<String, StringBuilder>();
readALineAtATime(inputFile, ctMap);
fw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

   }
}
}

private static void readALineAtATime(File inputFile, Map<String, StringBuilder> ctMap) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader(inputFile));
String line;
String ctName = null;
boolean firstLine = true;
while ((line = br.readLine()) != null) {
ctName = checkLineForComplexType(line, ctMap, ctName);
}
br.close();

// sort the keys
Set<String> keySet = ctMap.keySet();
Iterator<String> it = keySet.iterator();
List<String> keyList = new ArrayList<String>();
while (it.hasNext()){
keyList.add(it.next());
}
Collections.sort(keyList);

//print the keys
it = keyList.iterator();
while (it.hasNext()){
String key = it.next();
StringBuilder sb = ctMap.get(key);
//System.out.println(sb);
writeToFile(sb);
}

//close
fw.close();
}

 private static String checkLineForComplexType(String input, Map<String, StringBuilder> ctMap, String ctName) {
StringBuilder sb = new StringBuilder();
if (input.contains(“<?xml version=”)){
sb.append(input);
ctName = “1”;
ctMap.put(ctName, sb);
}else if (input.contains(“<xsd:complexType name=”)){
int start = input.indexOf(“\””);
int end = input.indexOf(“\”>”);
ctName = input.substring(start+1, end);
sb.append(input);
ctMap.put(ctName, sb);
}else{
sb = ctMap.get(ctName);
sb.append(“\n”);
sb.append(input);
ctMap.put(ctName, sb);
}
return ctName;
}

 private static void writeToFile(StringBuilder line) {
try {
fw.append(line);
fw.append(“\n”);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

IdGen.java

mport java.sql.Timestamp;
import java.util.Random;

public class IdGen {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

//Timestamp(System.currentTimeMillis());

Timestamp aTimestamp = new Timestamp(System.currentTimeMillis());
String timestamprandom=aTimestamp.toString();
String timestampRandom=timestamprandom.replaceAll(“[-:. ]”,””).trim();

String Id=”123456789012345678″+timestampRandom.trim();
int IdLength=Id.length();
Random random = new Random();
int randomInt = 0;

if(IdLength < 35)
Id = Id.substring(0, IdLength);
else
for(; Id.length() < 35; Id = (new StringBuilder()).append(Id).append(String.valueOf(randomInt)).toString())
randomInt = random.nextInt(10);

System.out.println(Id);
}

}