Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supporting android and ios rp origins #121

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,23 @@ function derToRaw(signature) {
...extractBigNum(signature, sStart, signature.length, 32),
]);
}
function isAndroidFacetId(str) {
return str.startsWith("android:apk-key-hash:");
}

function isIOSFacetId(str) {
return str.startsWith("ios:bundle-id:");
}


function checkOrigin(str) {
if(!str)
throw new Error("Empty Origin");

if (isAndroidFacetId(str) || isIOSFacetId(str)) {
return str;
}

const originUrl = new URL(str);
const origin = originUrl.origin;

Expand Down
2 changes: 1 addition & 1 deletion test/parseExpectations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("parseExpectations", function() {
assert.strictEqual(ret.get("challenge"), exp.challenge);
});

it("throws on invalid origin", function() {
it("throws on invalid url", function() {
const exp = {
origin: "asdf",
challenge: "4BS1YJKRCeCVoLdfG_b66BuSQ-I2n34WsLFvy62fpIVFjrm32_tFRQixX9U8EBVTriTkreAp-1nDvYboRK9WFg",
Expand Down
15 changes: 14 additions & 1 deletion test/toolbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,23 @@ describe("toolbox", function() {
checkOrigin(undefined);
},
Error,
"Invalid URL",
"Empty Origin",
);
});


it("accepts android FacetID", function() {
const androidFacetId = "android:apk-key-hash:addf120b430021c36c232c99ef8d926aea2acd6b";
const androidOrigin = checkOrigin(androidFacetId);
assert.strictEqual(androidFacetId, androidOrigin);
});

it("accepts ios FacetID", function() {
const iOSFacetId = "ios:bundle-id:addf120b430021c36c232c99ef8d926aea2acd6b";
const iOSOrigin = checkOrigin(iOSFacetId);
assert.strictEqual(iOSFacetId, iOSOrigin);
});

it("throws invalid url", function() {
assert.throws(
() => {
Expand Down