Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi Guys,

Who can help you.

I'm developing a SSL client in Brew. But I don't know how to do it.

Is there any reference code for it?

The java sample code are the following:

public class MNSSLClient {

public static void main(String[] args) {

try{

File f = new File("D:\\Dropbox\\Emporia\\emporiaME\\Persistant Connection Test\\client.truststore.ks");

if(f.exists()) {

System.setProperty("javax.net.ssl.trustStore", f.getAbsolutePath());

// System.setProperty("javax.net.debug", "ssl");

System.out.println("Key store loaded");

}

System.out.println("Trying to open SSL socket");

SocketFactory socketFactory = SSLSocketFactory.getDefault();

//Socket socket = socketFactory.createSocket("ec2-46-137-71-192.eu-west-1.compute.amazonaws.com", 443);

Socket socket = socketFactory.createSocket("ec2-46-137-6-20.eu-west-1.compute.amazonaws.com", 443);

socket.setKeepAlive(true);

System.out.println("Socket opened from "

+ socket.getLocalAddress() + ":" + socket.getLocalPort() + " to "

+ socket.getInetAddress() + ":" + socket.getPort()

);

System.out.println("Open time: " + new Date() );

System.out.println("Keep alive: " + socket.getKeepAlive() );

ObjectOutputStream writer = new ObjectOutputStream(socket.getOutputStream());

ObjectInputStream reader = new ObjectInputStream(socket.getInputStream());

System.out.println("Receiving bytes");

byte[] inbuf = new byte[255];

int bRead;

while( (bRead = reader.read(inbuf)) > 0){

System.out.println(new Date() + " (" + bRead + ") : " + new String(inbuf, 0, bRead));

}

reader.close();

} catch (Exception e) {

//e.printStackTrace();

}

}

}

Thank you very much!
Tom.Song

You can use ISocket and ISockPort1 interface API's for creating socket, reading from socket port and writing to port.
For SSL Brew exposes ISSL interface. This interface provides SSL/TLS security for a network connection. This interface inherits from IWebOpts. It uses either ISocket or IPort in the interface. Note that this functionality is available combined with HTTP to form HTTPS in the IWeb interface. The web opts described here and in IX509Chain do apply to https.
Please refer Brew Api refernece for more info.

You can use ISocket and ISockPort1 interface API's for creating socket, reading from socket port and writing to port.
For SSL Brew exposes ISSL interface. This interface provides SSL/TLS security for a network connection. This interface inherits from IWebOpts. It uses either ISocket or IPort in the interface. Note that this functionality is available combined with HTTP to form HTTPS in the IWeb interface. The web opts described here and in IX509Chain do apply to https.
Please refer Brew Api refernece for more info.

thanks.
But I don't know how to load the certificate file (client.truststore.ks) which sent from the server.
Is there any reference code?

thanks.
But I don't know how to load the certificate file (client.truststore.ks) which sent from the server.
Is there any reference code?

The following demonstrates how an application may load and set custom root certificates.
Sample code:
IFileMgr*  pIFileMgr;
IFile*     pIFile;
WebOpt     apwoz;
 
if(ISHELL_CreateInstance(piShell, AEECLSID_FILEMGR, &pIFileMgr)) != 
                         SUCCESS
        goto Failure;
pIFile = IFILEMGR_OpenFile(pIFileMgr, “myCert.cer”, _OFM_READ);
IFILE_Read(pIFile, buffer, sizeof(buffer));
apwoz.nID = WEBOPT_X509_ROOT_CERT;
apwoz.pVal = buffer;
IWEB_AddOpt(pMe->pIWeb, apwoz);
IFILE_Release(pIFile);
IFILEMGR_Release(pIFileMgr);

The following demonstrates how an application may load and set custom root certificates.
Sample code:
IFileMgr*  pIFileMgr;
IFile*     pIFile;
WebOpt     apwoz;
 
if(ISHELL_CreateInstance(piShell, AEECLSID_FILEMGR, &pIFileMgr)) != 
                         SUCCESS
        goto Failure;
pIFile = IFILEMGR_OpenFile(pIFileMgr, “myCert.cer”, _OFM_READ);
IFILE_Read(pIFile, buffer, sizeof(buffer));
apwoz.nID = WEBOPT_X509_ROOT_CERT;
apwoz.pVal = buffer;
IWEB_AddOpt(pMe->pIWeb, apwoz);
IFILE_Release(pIFile);
IFILEMGR_Release(pIFileMgr);

The following demonstrates how an application may load and set custom root certificates.
Sample code:
IFileMgr* pIFileMgr;

IFile* pIFile;

WebOpt apwoz;

if(ISHELL_CreateInstance(piShell, AEECLSID_FILEMGR, &pIFileMgr)) !=

SUCCESS

goto Failure;

pIFile = IFILEMGR_OpenFile(pIFileMgr, “myCert.cer”, _OFM_READ);

IFILE_Read(pIFile, buffer, sizeof(buffer));

apwoz.nID = WEBOPT_X509_ROOT_CERT;

apwoz.pVal = buffer;

IWEB_AddOpt(pMe->pIWeb, apwoz);

IFILE_Release(pIFile);

IFILEMGR_Release(pIFileMgr);

The following demonstrates how an application may load and set custom root certificates.
Sample code:
IFileMgr* pIFileMgr;

IFile* pIFile;

WebOpt apwoz;

if(ISHELL_CreateInstance(piShell, AEECLSID_FILEMGR, &pIFileMgr)) !=

SUCCESS

goto Failure;

pIFile = IFILEMGR_OpenFile(pIFileMgr, “myCert.cer”, _OFM_READ);

IFILE_Read(pIFile, buffer, sizeof(buffer));

apwoz.nID = WEBOPT_X509_ROOT_CERT;

apwoz.pVal = buffer;

IWEB_AddOpt(pMe->pIWeb, apwoz);

IFILE_Release(pIFile);

IFILEMGR_Release(pIFileMgr);