Socket
Socket
Sign inDemoInstall

xml-crypto

Package Overview
Dependencies
Maintainers
5
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-crypto - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

4

lib/exclusive-canonicalization.js

@@ -201,5 +201,5 @@ "use strict";

if (!utils.isArrayHasLength(inclusiveNamespacesPrefixList)) {
const CanonicalizationMethod = utils.findChilds(node, "CanonicalizationMethod");
const CanonicalizationMethod = utils.findChildren(node, "CanonicalizationMethod");
if (CanonicalizationMethod.length !== 0) {
const inclusiveNamespaces = utils.findChilds(CanonicalizationMethod[0], "InclusiveNamespaces");
const inclusiveNamespaces = utils.findChildren(CanonicalizationMethod[0], "InclusiveNamespaces");
if (inclusiveNamespaces.length !== 0) {

@@ -206,0 +206,0 @@ inclusiveNamespacesPrefixList = (inclusiveNamespaces[0].getAttribute("PrefixList") || "").split(" ");

@@ -5,3 +5,3 @@ "use strict";

const xpath = require("xpath");
const xmldom_1 = require("@xmldom/xmldom");
const xmldom = require("@xmldom/xmldom");
const utils = require("./utils");

@@ -143,3 +143,3 @@ const c14n = require("./c14n-canonicalization");

x509Certs = publicCertMatches
.map((c) => `<X509Certificate>${utils.pemToDer(c)}</X509Certificate>`)
.map((c) => `<X509Certificate>${utils.pemToDer(c).toString("base64")}</X509Certificate>`)
.join("");

@@ -171,3 +171,3 @@ }

this.signedXml = xml;
const doc = new xmldom_1.DOMParser().parseFromString(xml);
const doc = new xmldom.DOMParser().parseFromString(xml);
if (!this.validateReferences(doc)) {

@@ -206,3 +206,3 @@ if (!callback) {

}
const signedInfo = utils.findChilds(this.signatureNode, "SignedInfo");
const signedInfo = utils.findChildren(this.signatureNode, "SignedInfo");
if (signedInfo.length === 0) {

@@ -351,3 +351,3 @@ throw new Error("could not find SignedInfo element in the message");

if (typeof signatureNode === "string") {
this.signatureNode = signatureNode = new xmldom_1.DOMParser().parseFromString(signatureNode);
this.signatureNode = signatureNode = new xmldom.DOMParser().parseFromString(signatureNode);
}

@@ -393,3 +393,3 @@ else {

var _a;
let nodes = utils.findChilds(ref, "DigestMethod");
let nodes = utils.findChildren(ref, "DigestMethod");
if (nodes.length === 0) {

@@ -404,3 +404,3 @@ throw new Error(`could not find DigestMethod in reference ${ref.toString()}`);

const digestAlgo = attr.value;
nodes = utils.findChilds(ref, "DigestValue");
nodes = utils.findChildren(ref, "DigestValue");
if (nodes.length === 0) {

@@ -416,6 +416,6 @@ throw new Error(`could not find DigestValue node in reference ${ref.toString()}`);

let inclusiveNamespacesPrefixList = [];
nodes = utils.findChilds(ref, "Transforms");
nodes = utils.findChildren(ref, "Transforms");
if (nodes.length !== 0) {
const transformsNode = nodes[0];
const transformsAll = utils.findChilds(transformsNode, "Transform");
const transformsAll = utils.findChildren(transformsNode, "Transform");
for (const transform of transformsAll) {

@@ -428,3 +428,3 @@ const transformAttr = utils.findAttr(transform, "Algorithm");

// This is a little strange, we are looking for children of the last child of `transformsNode`
const inclusiveNamespaces = utils.findChilds(transformsAll[transformsAll.length - 1], "InclusiveNamespaces");
const inclusiveNamespaces = utils.findChildren(transformsAll[transformsAll.length - 1], "InclusiveNamespaces");
if (utils.isArrayHasLength(inclusiveNamespaces)) {

@@ -497,3 +497,3 @@ // Should really only be one prefix list, but maybe there's some circumstances where more than one to let's handle it

}
const doc = new xmldom_1.DOMParser().parseFromString(xml);
const doc = new xmldom.DOMParser().parseFromString(xml);
let xmlNsAttr = "xmlns";

@@ -553,3 +553,3 @@ const signatureAttrs = [];

const dummySignatureWrapper = `<Dummy ${existingPrefixesString}>${signatureXml}</Dummy>`;
const nodeXml = new xmldom_1.DOMParser().parseFromString(dummySignatureWrapper);
const nodeXml = new xmldom.DOMParser().parseFromString(dummySignatureWrapper);
// Because we are using a dummy wrapper hack described above, we know there will be a `firstChild`

@@ -588,3 +588,3 @@ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion

this.signatureNode = signatureDoc;
const signedInfoNodes = utils.findChilds(this.signatureNode, "SignedInfo");
const signedInfoNodes = utils.findChildren(this.signatureNode, "SignedInfo");
if (signedInfoNodes.length === 0) {

@@ -775,3 +775,3 @@ const err3 = new Error("could not find SignedInfo element in the message");

const dummySignatureWrapper = `<${prefix}Signature ${xmlNsAttr}="http://www.w3.org/2000/09/xmldsig#">${signatureValueXml}</${prefix}Signature>`;
const doc = new xmldom_1.DOMParser().parseFromString(dummySignatureWrapper);
const doc = new xmldom.DOMParser().parseFromString(dummySignatureWrapper);
// Because we are using a dummy wrapper hack described above, we know there will be a `firstChild`

@@ -778,0 +778,0 @@ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion

/// <reference types="node" />
import * as crypto from "crypto";
export type ErrorFirstCallback<T> = (err: Error | null, result?: T) => void;
export type CanonicalizationAlgorithmType = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" | "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" | "http://www.w3.org/2001/10/xml-exc-c14n#" | "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
export type CanonicalizationOrTransformAlgorithmType = CanonicalizationAlgorithmType | "http://www.w3.org/2000/09/xmldsig#enveloped-signature" | string;
export type CanonicalizationAlgorithmType = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" | "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" | "http://www.w3.org/2001/10/xml-exc-c14n#" | "http://www.w3.org/2001/10/xml-exc-c14n#WithComments" | string;
export type CanonicalizationOrTransformAlgorithmType = CanonicalizationAlgorithmType | "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
export type HashAlgorithmType = "http://www.w3.org/2000/09/xmldsig#sha1" | "http://www.w3.org/2001/04/xmlenc#sha256" | "http://www.w3.org/2001/04/xmlenc#sha512" | string;

@@ -12,10 +12,10 @@ export type SignatureAlgorithmType = "http://www.w3.org/2000/09/xmldsig#rsa-sha1" | "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" | "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" | "http://www.w3.org/2000/09/xmldsig#hmac-sha1" | string;

*/
export type GetKeyInfoContentArgs = {
export interface GetKeyInfoContentArgs {
publicCert?: crypto.KeyLike;
prefix?: string | null;
};
}
/**
* Options for the SignedXml constructor.
*/
export type SignedXmlOptions = {
export interface SignedXmlOptions {
idMode?: "wssecurity";

@@ -32,12 +32,12 @@ idAttribute?: string;

getCertFromKeyInfo?(keyInfo?: Node | null): string | null;
};
export type NamespacePrefix = {
}
export interface NamespacePrefix {
prefix: string;
namespaceURI: string;
};
export type RenderedNamespace = {
}
export interface RenderedNamespace {
rendered: string;
newDefaultNs: string;
};
export type CanonicalizationOrTransformationAlgorithmProcessOptions = {
}
export interface CanonicalizationOrTransformationAlgorithmProcessOptions {
defaultNs?: string;

@@ -48,3 +48,7 @@ defaultNsForPrefix?: Record<string, string>;

inclusiveNamespacesPrefixList?: string[];
};
}
export interface ComputeSignatureOptionsLocation {
reference?: string;
action?: "append" | "prepend" | "before" | "after";
}
/**

@@ -62,15 +66,8 @@ * Options for the computeSignature method.

*/
export type ComputeSignatureOptions = {
export interface ComputeSignatureOptions {
prefix?: string;
attrs?: {
[attrName: string]: string;
};
location?: {
reference?: string;
action?: "append" | "prepend" | "before" | "after";
};
existingPrefixes?: {
[prefix: string]: string;
};
};
attrs?: Record<string, string>;
location?: ComputeSignatureOptionsLocation;
existingPrefixes?: Record<string, string>;
}
/**

@@ -87,6 +84,7 @@ * Represents a reference node for XML digital signature.

isEmptyUri: boolean;
ancestorNamespaces?: NamespacePrefix[];
}
/** Implement this to create a new CanonicalizationOrTransformationAlgorithm */
export interface CanonicalizationOrTransformationAlgorithm {
process(node: Node, options: CanonicalizationOrTransformationAlgorithmProcessOptions): Node;
process(node: Node, options: CanonicalizationOrTransformationAlgorithmProcessOptions): Node | string;
getAlgorithmName(): CanonicalizationOrTransformAlgorithmType;

@@ -93,0 +91,0 @@ includeComments: boolean;

@@ -5,2 +5,4 @@ /// <reference types="node" />

export declare function findAttr(element: Element, localName: string, namespace?: string): Attr | null;
export declare function findChildren(node: Node | Document, localName: string, namespace?: string): Element[];
/** @deprecated */
export declare function findChilds(node: Node | Document, localName: string, namespace?: string): Element[];

@@ -48,3 +50,3 @@ export declare function encodeSpecialCharactersInAttribute(attributeValue: any): any;

*/
export declare function pemToDer(pem: string): string;
export declare function pemToDer(pem: string): Buffer;
/**

@@ -54,3 +56,3 @@ * @param der The DER-encoded base64 certificate to add PEM headers too

*/
export declare function derToPem(der: string | Buffer, pemLabel: "CERTIFICATE" | "PRIVATE KEY" | "RSA PUBLIC KEY"): string;
export declare function derToPem(der: string | Buffer, pemLabel?: "CERTIFICATE" | "PRIVATE KEY" | "RSA PUBLIC KEY"): string;
/**

@@ -60,3 +62,3 @@ * Extract ancestor namespaces in order to import it to root of document subset

*
* @param {object} doc - Usually a product from `new DOMParser().parseFromString()`
* @param {object} doc - Usually a product from `new xmldom.DOMParser().parseFromString()`
* @param {string} docSubsetXpath - xpath query to get document subset being canonicalized

@@ -63,0 +65,0 @@ * @param {object} namespaceResolver - xpath namespace resolver

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateDigestValue = exports.findAncestorNs = exports.derToPem = exports.pemToDer = exports.normalizePem = exports.BASE64_REGEX = exports.EXTRACT_X509_CERTS = exports.PEM_FORMAT_REGEX = exports.encodeSpecialCharactersInText = exports.encodeSpecialCharactersInAttribute = exports.findChilds = exports.findAttr = exports.isArrayHasLength = void 0;
exports.validateDigestValue = exports.findAncestorNs = exports.derToPem = exports.pemToDer = exports.normalizePem = exports.BASE64_REGEX = exports.EXTRACT_X509_CERTS = exports.PEM_FORMAT_REGEX = exports.encodeSpecialCharactersInText = exports.encodeSpecialCharactersInAttribute = exports.findChilds = exports.findChildren = exports.findAttr = exports.isArrayHasLength = void 0;
const xpath = require("xpath");

@@ -27,3 +27,3 @@ function isArrayHasLength(array) {

exports.findAttr = findAttr;
function findChilds(node, localName, namespace) {
function findChildren(node, localName, namespace) {
var _a;

@@ -42,2 +42,7 @@ const element = (_a = node.documentElement) !== null && _a !== void 0 ? _a : node;

}
exports.findChildren = findChildren;
/** @deprecated */
function findChilds(node, localName, namespace) {
return findChildren(node, localName, namespace);
}
exports.findChilds = findChilds;

@@ -123,6 +128,9 @@ const xml_special_to_encoded_attribute = {

function pemToDer(pem) {
return pem
.replace(/(\r\n|\r)/g, "\n")
if (!exports.PEM_FORMAT_REGEX.test(pem.trim())) {
throw new Error("Invalid PEM format.");
}
return Buffer.from(pem
.replace(/(\r\n|\r)/g, "")
.replace(/-----BEGIN [A-Z\x20]{1,48}-----\n?/, "")
.replace(/-----END [A-Z\x20]{1,48}-----\n?/, "");
.replace(/-----END [A-Z\x20]{1,48}-----\n?/, ""), "base64");
}

@@ -135,3 +143,5 @@ exports.pemToDer = pemToDer;

function derToPem(der, pemLabel) {
const base64Der = Buffer.isBuffer(der) ? der.toString("latin1").trim() : der.trim();
const base64Der = Buffer.isBuffer(der)
? der.toString("base64").trim()
: der.replace(/(\r\n|\r)/g, "").trim();
if (exports.PEM_FORMAT_REGEX.test(base64Der)) {

@@ -141,2 +151,5 @@ return normalizePem(base64Der);

if (exports.BASE64_REGEX.test(base64Der)) {
if (pemLabel == null) {
throw new Error("PEM label is required when DER is given.");
}
const pem = `-----BEGIN ${pemLabel}-----\n${base64Der}\n-----END ${pemLabel}-----`;

@@ -186,3 +199,3 @@ return normalizePem(pem);

*
* @param {object} doc - Usually a product from `new DOMParser().parseFromString()`
* @param {object} doc - Usually a product from `new xmldom.DOMParser().parseFromString()`
* @param {string} docSubsetXpath - xpath query to get document subset being canonicalized

@@ -189,0 +202,0 @@ * @param {object} namespaceResolver - xpath namespace resolver

{
"name": "xml-crypto",
"version": "4.0.1",
"version": "4.1.0",
"private": false,

@@ -5,0 +5,0 @@ "description": "Xml digital signature and encryption library for Node.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc