gecko/security/manager/ssl/tests/mochitest/bugs/test_bug480509.html

89 lines
2.5 KiB
HTML

<html>
<head>
<title>Test bug 483437 and bug 480509</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="onWindowLoad()">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
function badCertListener()
{
}
badCertListener.prototype = {
badCertCaught: false,
getInterface: function (aIID) {
return this.QueryInterface(aIID);
},
QueryInterface: function(aIID) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (aIID.equals(Components.interfaces.nsIBadCertListener2) ||
aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
testCert: function(cert1, expected)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var certDumpTree1 = Components.classes["@mozilla.org/security/nsASN1Tree;1"]
.createInstance(Components.interfaces.nsIASN1Tree);
certDumpTree1.loadASN1Structure(cert1.ASN1Structure);
var value1 = certDumpTree1.getDisplayData(9);
is(value1, expected, "Incorrect subject recognized");
},
notifyCertProblem: function(socketInfo, sslStatus, targetHost) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var cert = sslStatus.QueryInterface(Components.interfaces.nsISSLStatus)
.serverCert;
this.testCert(cert, "CN = www.bank1.com\\00www.bad-guy.com\n");
this.badCertCaught = true;
return true;
}
}
function onFrameLoad()
{
ok(false, "Attackers page failed to load");
}
function onWindowLoad()
{
var req = new XMLHttpRequest();
var certListener = new badCertListener();
try
{
req.open("GET", "https://www.bank1.com/", false);
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
req.channel.notificationCallbacks = certListener;
req.send(null);
}
catch(ex)
{
// ignore
}
ok(certListener.badCertCaught, "We Caught the invalid certificate");
SimpleTest.finish();
}
</script>
<iframe src="https://www.bank1.com/" onload="onFrameLoad()"></iframe>
</body>
</html>