// this sets the background color of the master UIView (when there are no windows/tab groups on it)
var https = require('appcelerator.https');
var securityManager = https.createX509CertificatePinningSecurityManager([
{
url: "https://www.wellsfargo.com",
serverCertificate: "wells.cert"
},
{
url: "https://www.americanexpress.com",
serverCertificate: "wells.cert"
}
]);
var win = Titanium.UI.createWindow({
title: 'Pin Example',
backgroundColor: 'white'
});
var view = Ti.UI.createView({
backgroundColor: 'white',
layout: 'vertical',
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
top:20
});
var button1 = Titanium.UI.createButton({
title: 'Load wellsfargo',
color: 'green',
top:20,
});
var button2 = Titanium.UI.createButton({
title: 'Load americanexpress',
color: 'red',
top:20,
});
var button3 = Titanium.UI.createButton({
title: 'Load appcelerator',
color: 'blue',
top:20,
});
var label1 = Titanium.UI.createLabel({
text: 'Desc:',
color: 'black',
top:20,
});
var label2 = Titanium.UI.createLabel({
text: 'Status:',
color: 'black',
top:20,
});
view.add(button1);
view.add(button2);
view.add(button3);
view.add(label1);
view.add(label2);
win.add(view);
win.open();
function getXHR(url) {
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
label2.text = 'onload called. Request succeeded';
},
onerror: function(e) {
label2.text = 'onerror called. Request failed.';
},
timeout : 30000,
securityManager: securityManager
});
xhr.open('GET',url);
return xhr;
}
var wf = "https://www.wellsfargo.com";
var amex = "https://www.americanexpress.com";
var appc = "https://dashboard.appcelerator.com";
button1.addEventListener('click',function(e){
var xhr = getXHR(wf);
label1.text = 'SecurityManager is configured correctly for this request. Request must succeed. ';
label1.color = 'green';
xhr.send();
});
button2.addEventListener('click',function(e){
var xhr = getXHR(amex);
label1.text = 'SecurityManager is configured incorrectly for this request. Request must fail. ';
label1.color = 'red';
xhr.send();
});
button3.addEventListener('click',function(e){
var xhr = getXHR(appc);
label1.text = 'SecurityManager does not participate in the validation of this request.';
label1.color = 'blue';
xhr.send();
});
Note: If the certificate is no longer valid, it WILL throw an error. Please use a valid certificate. To inspect the certificate, use the commands mentioned earlier in this comment.
A GeoTrust cert will work.