// Turn off the authentication dialog blocking for this test. var prefs = Services.prefs;
prefs.setIntPref("network.auth.subresource-http-auth-allow", 2);
function URL(domain, path = "") { if (path.startsWith("/")) {
path = path.substring(1);
} return `http://${domain}:${httpserv.identity.primaryPort}/${path}`;
}
ChromeUtils.defineLazyGetter(this, "PORT", function () { return httpserv.identity.primaryPort;
});
prompt: function ap1_prompt() {
do_throw("unexpected prompt call");
},
promptUsernameAndPassword: function ap1_promptUP(
title,
text,
realm,
savePW,
user,
pw
) { if (!(this.flags & CROSS_ORIGIN)) { if (!text.includes(this.expectedRealm)) {
do_throw("Text must indicate the realm");
}
} elseif (text.includes(this.expectedRealm)) {
do_throw("There should not be realm for cross origin");
} if (!text.includes("localhost")) {
do_throw("Text must indicate the hostname");
} if (!text.includes(String(PORT))) {
do_throw("Text must indicate the port");
} if (text.includes("-1")) {
do_throw("Text must contain negative numbers");
}
if (this.flags & FLAG_RETURN_FALSE) { returnfalse;
}
getInterface: function requestor_gi(iid) { if (this.versions & 1 && iid.equals(Ci.nsIAuthPrompt)) { // Allow the prompt to store state by caching it here if (!this.prompt1) { this.prompt1 = new AuthPrompt1(this.flags);
} returnthis.prompt1;
} if (this.versions & 2 && iid.equals(Ci.nsIAuthPrompt2)) { // Allow the prompt to store state by caching it here if (!this.prompt2) { this.prompt2 = new AuthPrompt2(this.flags);
} returnthis.prompt2;
}
// // Digest functions // function bytesFromString(str) { const encoder = new TextEncoder(); return encoder.encode(str);
}
// return the two-digit hexadecimal code for a byte function toHexString(charCode) { return ("0" + charCode.toString(16)).slice(-2);
}
function H(str) { var data = bytesFromString(str); var ch = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
ch.init(Ci.nsICryptoHash.MD5);
ch.update(data, data.length); var hash = ch.finish(false); return Array.from(hash, (c, i) => toHexString(hash.charCodeAt(i))).join("");
}
const nonce = "6f93719059cf8d568005727f3250e798"; const opaque = "1234opaque1234"; const digestChallenge = `Digest realm="secret", domain="/", qop=auth,algorithm=MD5, nonce="${nonce}" opaque="${opaque}"`; // // Digest handler // // /auth/digest function authDigest(metadata, response) { var cnonceRE = /cnonce="(\w+)"/; var responseRE = /response="(\w+)"/; var usernameRE = /username="(\w+)"/; var body = ""; // check creds if we have them if (metadata.hasHeader("Authorization")) { var auth = metadata.getHeader("Authorization"); var cnonce = auth.match(cnonceRE)[1]; var clientDigest = auth.match(responseRE)[1]; var username = auth.match(usernameRE)[1]; var nc = "00000001";
if (username != "guest") {
response.setStatusLine(metadata.httpVersion, 400, "bad request");
body = "should never get here";
} else { // see RFC2617 for the description of this calculation var A1 = "guest:secret:guest"; var A2 = "GET:/path"; var noncebits = [nonce, nc, cnonce, "auth", H(A2)].join(":"); var digest = H([H(A1), noncebits].join(":"));
if (clientDigest == digest) {
response.setStatusLine(metadata.httpVersion, 200, "OK, authorized");
body = "digest";
} else {
info(clientDigest);
info(digest);
handle_unauthorized(metadata, response); return;
}
}
} else { // no header, send one
handle_unauthorized(metadata, response); return;
}
chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2);
let [req, buf] = await new Promise(resolve => {
chan.asyncOpen( new ChannelListener((request, buffer) => resolve([request, buffer]), null)
);
}); Assert.equal(buf, "OK"); Assert.equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200);
});
add_task(async function test_choose_most_secure() { // By default, we rank the challenges by how secure they are. // In this case, NTLM should be the most secure.
challenges = [digestChallenge, `Basic realm="secret"`, "NTLM"];
httpserv.identity.add( "http", "ntlmstrong.com",
httpserv.identity.primaryPort
);
let chan = makeChan(URL("ntlmstrong.com", "/path"));
chan.notificationCallbacks = new Requestor(FLAG_RETURN_FALSE, 2);
let [req, buf] = await new Promise(resolve => {
chan.asyncOpen( new ChannelListener((request, buffer) => resolve([request, buffer]), null)
);
}); Assert.equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200); Assert.equal(buf, "OK");
});
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.