I'am really sorry if this is a duplicate question but I tried many answers in other threads and none of them worked for me.
I'am trying to send an ISO8583 message to a remote server through an SSLSocket using the TLSv1.2 protocol, I configured the certificate with the Keystore and attempted to send a sample ISO8583 message : 08002220010000800000900000011312115000000180105000003
0800: MTI
2220010000800000: Binary Hex Encoded Bitmap (Only fields 3, 7, 11, 24, 41 are present)
900000: Process code
0113121150: Transmission Date&Time
000001: STAN
801: Function code
05000003: Terminal ID
I then converted the message to an array of bytes and sent it with the socket OutputStream but no response came from the server and it is freezing when attempting to read the InputStream.
For the purpose of this question, I chose to test a manually-set sample message and not use any packaging method.
I'm very new to the ISO8583 so I don't exactly know what I'm doing wrong.
Here is the code I tried so far and thank you so much to who ever that will try to help me.
Thread thread = new Thread(() -> {
try {
X509TrustManager[] tmm;
KeyStore ks = KeyStore.getInstance("BKS");
InputStream is = getResources().openRawResource(R.raw.tunrootca2);
ks.load(is, KEY_PASSWORD.toCharArray());
tmm=tm(ks);
SSLContext ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(null, tmm, null);
SSLSocketFactory SocketFactory = ctx.getSocketFactory();
SSLSocket socket = (SSLSocket) SocketFactory
.createSocket(REMOTE_ENDPOINT, REMOTE_ENDPOINT_PORT);
String sampleMessage = "080022200100008000009000000113120000000180105000003";
byte[] bytesMessage = sampleMessage.getBytes(StandardCharsets.UTF_16LE);
byte[] bytes = packData(bytesMessage);
OutputStream out = socket.getOutputStream();
out.write(bytes);
byte[] buffer = new byte[256];
InputStream in = socket.getInputStream();
int read;
while((read = in.read(buffer)) != -1) {
String output = new String(buffer, 0, read);
Log.v("SOCKET_OUTPUT", output);
}
} catch (Exception e) {
e.printStackTrace();
}
});
thread.start();
});
PackData Function
static byte[] packData(byte[] data) {
int len = data.length;
byte buf[] = new byte[len + 2];
buf[0] = (byte) (len >> 8 & 255);
buf[1] = (byte) (len & 255);
System.arraycopy(data, 0, buf, 2, len);
return buf;
}