Quantcast
Channel: Thales Simulator Library
Viewing all articles
Browse latest Browse all 332

New Post: Thales HSM and using the TCP/IP

$
0
0
Hi!

If you need to send command to host port, first, you should configure it using CH console command.
Below is an example of HSM client on Java, usage -- java HsmClient -i <ip> -p <port>:
import java.io.*;
import java.net.*;

public class HsmClient {    

    private static Socket socket = null;
        private static int header = 0;
    private static String HSM_IP;
    private static long HSM_PORT;
    private static int HEADER_LENGTH = 4;
            
        private static void connect () throws IOException {
            socket = new Socket(HSM_IP, HSM_PORT);
    }   
    
        private static void disconnect () throws IOException {
            socket.close();
    }

        private static String setHeader () {
            header++;
            String headerStr = Integer.toString(header);
            while (headerStr.length() != HEADER_LENGTH) {
                headerString = ‘0’ + headerString;
            }
        return rs;
        }

        private static String sendCommand (String command) throws IOException {
        String response = null;
            command = setHeader() + command;
            DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
            DataInputStream in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
            out.writeUTF(command);
            out.flush();
        response = in.readUTF();
        return response;
        }

        private static String sendEcho () throws IOException {
            String to_hsm = "NC";   
            return sendCommand(to_hsm);
    }

    public static void main (String[] args) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals(„-i”)) {
                HSM_IP = args[i + 1];
            }
            else if (args[i].equals(„-p”)) {
                HSM_PORT = args[i + 1];
            }
            try {
                connect();
                sendEcho();
                System.out.println(sendEcho());
                disconnect();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>