From 9a135d016dd341d5093a558256f9779b662065c6 Mon Sep 17 00:00:00 2001 From: Nico Sabena Date: Tue, 26 Mar 2024 08:57:16 -0700 Subject: [PATCH 1/3] Fix thumbprint calculation --- package-lock.json | 8 -------- package.json | 1 - src/src/utils.ts | 9 ++++++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index bce6214..e3bd383 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,6 @@ "name": "saml-extension", "version": "0.0.15", "dependencies": { - "thumbprint": "0.0.1", "xml-crypto": "^1.5.3", "xml-encryption": "^0.10.0", "xmldom": "^0.6.0", @@ -1290,10 +1289,6 @@ "node": ">=6" } }, - "node_modules/thumbprint": { - "version": "0.0.1", - "license": "MIT" - }, "node_modules/to-regex-range": { "version": "5.0.1", "dev": true, @@ -2333,9 +2328,6 @@ "has-flag": "^3.0.0" } }, - "thumbprint": { - "version": "0.0.1" - }, "to-regex-range": { "version": "5.0.1", "dev": true, diff --git a/package.json b/package.json index 10a04c1..82b6f26 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,6 @@ "typescript": "^4.8.4" }, "dependencies": { - "thumbprint": "0.0.1", "xml-crypto": "^1.5.3", "xml-encryption": "^0.10.0", "xmldom": "^0.6.0", diff --git a/src/src/utils.ts b/src/src/utils.ts index ead1db2..820ef15 100644 --- a/src/src/utils.ts +++ b/src/src/utils.ts @@ -1,4 +1,4 @@ -const thumbprint = require('thumbprint'); +const crypto = require('crypto'); const xmldom = require('xmldom'); const DOMParser = xmldom.DOMParser; const whitespace = /^\s+$/; @@ -22,8 +22,11 @@ export function formatCert(cert) { } export function calculateThumbprint(pem) { - var cert = removeHeaders(pem); - return thumbprint.calculate(cert).toUpperCase(); + const cert = removeHeaders(pem); + const shasum = crypto.createHash('sha1'); + const der = Buffer.from(cert, 'base64').toString('binary') + shasum.update(der, 'binary'); + return shasum.digest('hex'); } export function removeEmptyNodes(node) { From 568230bd9702349b06a3500c15f26f859f7ae594 Mon Sep 17 00:00:00 2001 From: Nico Sabena Date: Tue, 26 Mar 2024 08:57:28 -0700 Subject: [PATCH 2/3] Add thumbprint to certificate label --- src/src/elements/BaseElement.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/src/elements/BaseElement.ts b/src/src/elements/BaseElement.ts index b1c798a..e0cc6fc 100644 --- a/src/src/elements/BaseElement.ts +++ b/src/src/elements/BaseElement.ts @@ -1,3 +1,5 @@ +import { calculateThumbprint } from "../utils"; + const vscode = require('vscode'); const xmlCrypto = require('xml-crypto'); const xpath = require('xpath'); @@ -192,9 +194,10 @@ export default class BaseElement{ for(const certificate of certificates) { const certificateText = xpath.select("text()", certificate); if (certificateText && certificateText.length === 1) { + const pem = utils.certToPEM(certificateText[0].toString().trim()); results.push({ - label: `${index} - ${BaseElement.getCertificateLabel(certificate)}`, - text: utils.certToPEM(certificateText[0].toString().trim()) + label: `${index} - ${BaseElement.getCertificateLabel(certificate)} - ${calculateThumbprint(pem)}`, + text: pem }); index++; } From 994291a81053b140a7a34086b856b8acac49ea53 Mon Sep 17 00:00:00 2001 From: Nico Sabena Date: Tue, 26 Mar 2024 08:58:52 -0700 Subject: [PATCH 3/3] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82b6f26..0443d79 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "saml-extension", "displayName": "SAML Extension", "description": "SAML Extension", - "version": "0.0.15", + "version": "0.0.16", "publisher": "mcastany", "engines": { "vscode": "^1.70.0"