Skip to content

Commit

Permalink
Merge pull request #21 from nicosabena/master
Browse files Browse the repository at this point in the history
Fix thumbprint calculation
  • Loading branch information
nicosabena authored Mar 26, 2024
2 parents f9a82a7 + 994291a commit ab82cf3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/src/elements/BaseElement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { calculateThumbprint } from "../utils";

const vscode = require('vscode');
const xmlCrypto = require('xml-crypto');
const xpath = require('xpath');
Expand Down Expand Up @@ -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++;
}
Expand Down
9 changes: 6 additions & 3 deletions src/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const thumbprint = require('thumbprint');
const crypto = require('crypto');
const xmldom = require('xmldom');
const DOMParser = xmldom.DOMParser;
const whitespace = /^\s+$/;
Expand All @@ -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) {
Expand Down

0 comments on commit ab82cf3

Please sign in to comment.