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

adjust asn1 export and cleanup #54

Merged
merged 5 commits into from
Oct 5, 2024
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
20 changes: 10 additions & 10 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/node-opcua-crypto-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
},
"dependencies": {
"@peculiar/webcrypto": "^1.5.0",
"@peculiar/x509": "^1.12.2",
"@peculiar/x509": "^1.12.3",
"@types/jsrsasign": "^10.5.14",
"@types/mocha": "^10.0.8",
"@types/node": "^22.6.1",
"@types/node": "^22.7.4",
"cross-env": "^7.0.3",
"jsrsasign": "^11.1.0",
"lorem-ipsum": "^2.0.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-crypto-test/test-cjs/test_cjs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { exploreCertificateInfo } = require("../../node-opcua-crypto");
const { exploreCertificateInfo } = require("node-opcua-crypto");
// eslint-disable-next-line no-undef


Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-crypto-test/test-esm/test_esm.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exploreCertificateInfo } from "../../node-opcua-crypto/index.mjs";
import { exploreCertificateInfo } from "node-opcua-crypto/web";
// eslint-disable-next-line no-undef


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import fs from "fs";
import path from "path";
import os from "os";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";

import "should";

Expand Down
6 changes: 3 additions & 3 deletions packages/node-opcua-crypto-test/test/test_create_key_pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import fs from "fs";
import path from "path";
import os from "os";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import should from "should";

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import fs from "fs";
import path from "path";
import os from "os";
import util from "util";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import util from "node:util";
import should from "should";
import x509 from "@peculiar/x509";
import {
Expand Down
6 changes: 3 additions & 3 deletions packages/node-opcua-crypto-test/test/test_crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// ---------------------------------------------------------------------------------------------------------------------

import assert from "assert";
import fs from "node:fs";
import path from "node:path";
import {
createHmac,
createCipheriv,
Expand All @@ -32,9 +34,7 @@ import {
publicEncrypt as publicEncrypt_fromCrypto,
randomBytes,
KeyObject,
} from "crypto";
import fs from "fs";
import path from "path";
} from "node:crypto";
import should from "should";
import * as loremIpsum1 from "lorem-ipsum";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// ---------------------------------------------------------------------------------------------------------------------

import should from "should";
import path from "path";
import fs from "fs";
import path from "node:path";
import fs from "node:fs";

import {
readCertificate,
Expand Down
6 changes: 3 additions & 3 deletions packages/node-opcua-crypto-test/test/test_crypto_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import fs from "fs";
import os from "os";
import path from "path";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import * as loremIpsum from "lorem-ipsum";
import "should";
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-crypto-test/test/test_explore_crl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import path from "node:path";
import {
verifyCertificateRevocationListSignature,
exploreCertificateRevocationList,
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-crypto-test/test/test_explore_csr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import path from "node:path";
import { exploreCertificateSigningRequest } from "node-opcua-crypto";

import { readCertificateSigningRequest } from "node-opcua-crypto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import path from "node:path";
import { explorePrivateKey } from "node-opcua-crypto";
import { readPrivateRsaKey, readPrivateKey } from "node-opcua-crypto";
import "should";
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-crypto-test/test/test_extKeyUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import { exploreCertificate, readCertificate } from "node-opcua-crypto";
import path from "node:path";
import should from "should";
import { exploreCertificate, readCertificate } from "node-opcua-crypto";

describe("X509ExtKeyUsage", () => {
it("should parse extKeyUsage 1", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-crypto-test/test/test_makeThumprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import path from "node:path";
import { makeSHA1Thumbprint } from "node-opcua-crypto";
import { readCertificate } from "node-opcua-crypto";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import "should";
import {
makePrivateKeyFromPem,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import fs from "fs";
import { tmpdir } from "os";
import path from "node:path";
import fs from "node:fs";
import { tmpdir } from "node:os";
import { Crypto as PeculiarWebCrypto } from "@peculiar/webcrypto";
import * as x509 from "@peculiar/x509";
import { AsnConvert, AsnUtf8StringConverter } from "@peculiar/asn1-schema";
Expand Down Expand Up @@ -116,7 +116,7 @@ declare const window: any;

const ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;

import nativeCrypto from "crypto";
import nativeCrypto from "node:crypto";

if (typeof window === "undefined") {
_crypto = nativeCrypto as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import path from "node:path";
import { exploreCertificate, explorePrivateKey } from "node-opcua-crypto";
import { publicKeyAndPrivateKeyMatches, certificateMatchesPrivateKey } from "node-opcua-crypto";
import { readCertificate, readPrivateKey } from "node-opcua-crypto";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { coerceCertificate, readTag, _readStruct, readTbsCertificate } from "node-opcua-crypto";
import { coerceCertificate, readTbsCertificate } from "node-opcua-crypto";
import { asn1 } from "node-opcua-crypto";

import assert from "assert";

/*
Expand Down Expand Up @@ -135,8 +137,8 @@ nPgNSo9ViIrAO7PVmvJ8ikE7Bi9io4fFSA0Jzok+tx9WFpta

function extractBasicConstraintsExtension(certificate: string | Buffer) {
certificate = coerceCertificate(certificate);
const block_info = readTag(certificate, 0);
const blocks = _readStruct(certificate, block_info);
const block_info = asn1.readTag(certificate, 0);
const blocks = asn1.readStruct(certificate, block_info);
const { extensions } = readTbsCertificate(certificate, blocks[0]);
return extensions?.basicConstraints;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import { createPublicKey } from "crypto";
import path from "path";
import { createPublicKey } from "node:crypto";
import path from "node:path";
import { rsaLengthPublicKey } from "node-opcua-crypto";
import { readCertificate, readCertificatePEM } from "node-opcua-crypto";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { exploreCertificate } from "node-opcua-crypto/web";
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import { verifyCertificateChain } from "node-opcua-crypto";
import { readCertificate } from "node-opcua-crypto";
import path from "node:path";
import { verifyCertificateChain, readCertificate } from "node-opcua-crypto";

describe("Test Certificate Chain", () => {
it("DX should verify a certificate chain", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ---------------------------------------------------------------------------------------------------------------------

import path from "path";
import { SignPrivateKeyInput, constants, createSign } from "crypto";
import path from "node:path";
import { SignPrivateKeyInput, constants, createSign } from "node:crypto";
import { verifyCertificateSignature, Certificate, toPem2, PrivateKey } from "node-opcua-crypto";
import { readTag, _readStruct, _readAlgorithmIdentifier, _readSignatureValueBin } from "node-opcua-crypto";
import { asn1 } from "node-opcua-crypto";
import { readCertificate, readPrivateKey } from "node-opcua-crypto";

export function investigateCertificateSignature(certificate: Certificate, caPrivateKey?: PrivateKey): void {
const block_info = readTag(certificate, 0);
const blocks = _readStruct(certificate, block_info);
const block_info = asn1.readTag(certificate, 0);
const blocks = asn1.readStruct(certificate, block_info);

// console.log(block_info, blocks[0], blocks[1], blocks[2]);
const bufferTbsCertificate = certificate.subarray(block_info.position, block_info.position + 4 + blocks[0].length);

// console.log("bufferTbsCertificate = ", bufferTbsCertificate.length);
const signatureAlgorithm = _readAlgorithmIdentifier(certificate, blocks[1]);
const signatureAlgorithm = asn1.readAlgorithmIdentifier(certificate, blocks[1]);

const signatureValue = _readSignatureValueBin(certificate, blocks[2]);
const signatureValue = asn1.readSignatureValueBin(certificate, blocks[2]);
// console.log("", ellipsis(signatureValue.toString("hex")), signatureValue.length);

function testPadding(padding: number, saltLength?: number): boolean {
Expand Down
Loading