A certificate store that can be used with HTTPClient in Titanium.
To access this module from JavaScript, you would do the following:
var certificatestore = require("com.certificatestore");
The certificatestore variable is a reference to the Module object.
Adds a certificate to the certificate store. Path is the path to the certificate (must be in .p12 format). Password is the password for the given certificate.
Returns the trust manager proxy associated with the certificate store. This should be used with the addTrustManager() method from HTTPClient in titanium.
// This should be the url of the webserver you are trying to test
var url = "https://10.0.2.2:5678";
var certificateStore = require('com.certificatestore');
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
// Enable certificate validation
client.validatesSecureCertificate = true;
// Add the certificate to the certificate store
certificateStore.addCertificate('client.p12', 'password');
// Add the trust manager to the http client
client.addTrustManager(certificateStore.getTrustManager());
client.open("GET", url);
client.send();
Allen Yeung
Copyright(c) 2012 by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.