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

Fix new certificates #151

Merged
merged 7 commits into from
Dec 22, 2023
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
10 changes: 7 additions & 3 deletions lib/certUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { ab2str, coerceToArrayBuffer, isPem, pemToBase64, tools } from "./utils.

class Certificate {
constructor(cert) {

let decoded;

// Clean up base64 string
if (typeof cert === "string" || cert instanceof String) {
cert = cert.replace(/\r/g, "");
cert = cert.replace(/\r/g, "").trim();
decoded = ab2str(coerceToArrayBuffer(cert, "certificate"));
}

if (isPem(cert)) {
cert = pemToBase64(cert);
} else if (decoded && isPem(decoded)) {
cert = pemToBase64(decoded);
}

// Clean up certificate
if (typeof cert === "string" || cert instanceof String) {
cert = cert.replace(/\n/g, "");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fido2-lib",
"version": "3.4.3",
"version": "3.4.4",
"description": "A library for performing FIDO 2.0 / WebAuthn functionality",
"type": "module",
"main": "dist/main.cjs",
Expand Down
6 changes: 6 additions & 0 deletions test/certUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe("cert utils", function() {
assert.isObject(cert._cert);
});

it("can decode base64 encoded cert", function() {
const cert = new Certificate(h.certs.truUCert);
assert.instanceOf(cert, Certificate);
assert.isObject(cert._cert);
});

it("throws if no arg to constructor", function() {
assert.throws(() => {
new Certificate();
Expand Down
3 changes: 3 additions & 0 deletions test/helpers/fido2-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3782,11 +3782,14 @@ const tpmAttestation =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WJnRlBGTWdJanlXeENLcXcvZDhDSUZpbUxOWExESXdBK29JYlAxeU9mcUU4CnhrNnE3LzRMV09WWWtSQUxvQkMyCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=";

const certs = {
yubiKeyAttestation,
yubicoRoot,
feitianFido2,
tpmAttestation,
truUCert,
};

/** ******************************************************************************
Expand Down
Loading