Thales HSM and using the TCP/IP

May 18, 2014 at 6:21 AM
Hi,
we have the Thales HSM(P3CM) and i could connect to it via serial port and run commands.but
i can't connect to it via ethernet,i downloaded thalessim 0.9.6 but it doesn't work for connecting to
hsm(i think) .
how can i connect hsm via ethernet and run commands?
Editor
May 19, 2014 at 8:23 AM
Hi!

Thales SIM is HSM simolator, not a host simulator and can not be connected to P3CM (if i understood you correctly) since both of them are servers. What way are you trying to connect to P3CM? If you are writing you software to work with P3CM, you should note that each command must contais SW header, first two bytes of command must contain whole message length in binary representation:

<SW header (2 bytes)><HSM header><Command code><command data>
May 20, 2014 at 10:06 AM
hi,
thanks for your reply
i connect to P3CM by Hyperterminal via Serial Port but i don't know how i can connect to P3CM via ethernet ,i don't know any consol.do you have the console and sample code?
i have only,an Installation and operation guide for it and there is some Example for sending command to P3CM via serial and thernet,
for example the command format in ethernet is:
X'00 X'06 X'31 X'32 X'33 X'34 X'4E X'43 (for NC command)
but as i told i don't know how i send them and how get response?
Editor
May 20, 2014 at 10:18 AM
Edited May 20, 2014 at 10:20 AM
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();
            }
        }
    }
}