mirror of https://github.com/certd/certd
chore: node-acme-client转换为esm
parent
a9a0967a6f
commit
087c0b8253
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"plugin:prettier/recommended",
|
||||||
|
"prettier"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"eslint-plugin-import"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-var-requires": "off",
|
||||||
|
"@typescript-eslint/ban-ts-comment": "off",
|
||||||
|
"@typescript-eslint/ban-ts-ignore": "off",
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"@typescript-eslint/no-empty-function": "off",
|
||||||
|
// "no-unused-expressions": "off",
|
||||||
|
"max-len": [
|
||||||
|
0,
|
||||||
|
160,
|
||||||
|
2,
|
||||||
|
{
|
||||||
|
"ignoreUrls": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +0,0 @@
|
||||||
extends:
|
|
||||||
- 'airbnb-base'
|
|
||||||
|
|
||||||
env:
|
|
||||||
browser: false
|
|
||||||
node: true
|
|
||||||
mocha: true
|
|
||||||
|
|
||||||
rules:
|
|
||||||
indent: [2, 4, { SwitchCase: 1, VariableDeclarator: 1 }]
|
|
||||||
brace-style: [2, 'stroustrup', { allowSingleLine: true }]
|
|
||||||
func-names: 0
|
|
||||||
class-methods-use-this: 0
|
|
||||||
no-param-reassign: 0
|
|
||||||
max-len: [1, 200, 2, { ignoreUrls: true, ignoreComments: false }]
|
|
||||||
import/no-useless-path-segments: 0
|
|
|
@ -4,6 +4,8 @@
|
||||||
"private": false,
|
"private": false,
|
||||||
"author": "nmorsman",
|
"author": "nmorsman",
|
||||||
"version": "1.27.2",
|
"version": "1.27.2",
|
||||||
|
"type": "module",
|
||||||
|
"module": "scr/index.js",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"types": "types/index.d.ts",
|
"types": "types/index.d.ts",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -22,21 +24,23 @@
|
||||||
"debug": "^4.3.5",
|
"debug": "^4.3.5",
|
||||||
"http-proxy-agent": "^7.0.2",
|
"http-proxy-agent": "^7.0.2",
|
||||||
"https-proxy-agent": "^7.0.5",
|
"https-proxy-agent": "^7.0.5",
|
||||||
"node-forge": "^1.3.1"
|
"node-forge": "^1.3.1",
|
||||||
|
"lodash-es": "^4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.14.10",
|
"@types/node": "^20.14.10",
|
||||||
"chai": "^4.4.1",
|
"chai": "^4.4.1",
|
||||||
"chai-as-promised": "^7.1.2",
|
"chai-as-promised": "^7.1.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-config-airbnb-base": "^15.0.0",
|
|
||||||
"eslint-plugin-import": "^2.29.1",
|
"eslint-plugin-import": "^2.29.1",
|
||||||
"jsdoc-to-markdown": "^8.0.1",
|
"jsdoc-to-markdown": "^8.0.1",
|
||||||
"mocha": "^10.6.0",
|
"mocha": "^10.6.0",
|
||||||
"nock": "^13.5.4",
|
"nock": "^13.5.4",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"tsd": "^0.31.1",
|
"tsd": "^0.31.1",
|
||||||
"typescript": "^5.4.2"
|
"typescript": "^5.4.2",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-plugin-prettier": "^4.2.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-docs": "jsdoc2md src/client.js > docs/client.md && jsdoc2md src/crypto/index.js > docs/crypto.md && jsdoc2md src/crypto/forge.js > docs/forge.md",
|
"build-docs": "jsdoc2md src/client.js > docs/client.md && jsdoc2md src/crypto/index.js > docs/crypto.md && jsdoc2md src/crypto/forge.js > docs/forge.md",
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
const nodeHttp = require('node:http');
|
import nodeHttp from 'node:http'
|
||||||
const https = require('node:https');
|
import https from 'https'
|
||||||
const { HttpProxyAgent } = require('http-proxy-agent');
|
import {HttpProxyAgent} from "http-proxy-agent";
|
||||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
import {HttpsProxyAgent} from "https-proxy-agent";
|
||||||
const { log } = require('./logger');
|
import {log} from './logger.js'
|
||||||
|
import {merge} from 'lodash-es'
|
||||||
function createAgent(opts = {}) {
|
function createAgent(opts = {}) {
|
||||||
|
opts = merge(
|
||||||
|
{
|
||||||
|
autoSelectFamily: true,
|
||||||
|
autoSelectFamilyAttemptTimeout: 2000,
|
||||||
|
},
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
|
||||||
let httpAgent;
|
let httpAgent;
|
||||||
let
|
let httpsAgent;
|
||||||
httpsAgent;
|
|
||||||
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
||||||
if (httpProxy) {
|
if (httpProxy) {
|
||||||
log(`acme use httpProxy:${httpProxy}`);
|
log(`acme use httpProxy:${httpProxy}`);
|
||||||
httpAgent = new HttpProxyAgent(httpProxy, opts);
|
httpAgent = new HttpProxyAgent(httpProxy, opts);
|
||||||
|
merge(httpAgent.options, opts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
httpAgent = new nodeHttp.Agent(opts);
|
httpAgent = new nodeHttp.Agent(opts);
|
||||||
|
@ -20,6 +28,7 @@ function createAgent(opts = {}) {
|
||||||
if (httpsProxy) {
|
if (httpsProxy) {
|
||||||
log(`acme use httpsProxy:${httpsProxy}`);
|
log(`acme use httpsProxy:${httpsProxy}`);
|
||||||
httpsAgent = new HttpsProxyAgent(httpsProxy, opts);
|
httpsAgent = new HttpsProxyAgent(httpsProxy, opts);
|
||||||
|
merge(httpsAgent.options, opts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
httpsAgent = new https.Agent(opts);
|
httpsAgent = new https.Agent(opts);
|
||||||
|
@ -102,7 +111,7 @@ class HttpError extends Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
setGlobalProxy,
|
setGlobalProxy,
|
||||||
createAgent,
|
createAgent,
|
||||||
getGlobalAgents,
|
getGlobalAgents,
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* ACME API client
|
* ACME API client
|
||||||
*/
|
*/
|
||||||
|
import * as util from './util.js';
|
||||||
const util = require('./util');
|
|
||||||
const { log } = require('./logger');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AcmeApi
|
* AcmeApi
|
||||||
|
@ -248,4 +246,4 @@ class AcmeApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Export API */
|
/* Export API */
|
||||||
module.exports = AcmeApi;
|
export default AcmeApi;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* ACME auto helper
|
* ACME auto helper
|
||||||
*/
|
*/
|
||||||
|
import { readCsrDomains } from './crypto/index.js';
|
||||||
|
import { log } from './logger.js';
|
||||||
|
import { wait } from './wait.js';
|
||||||
|
import { CancelError } from './error.js';
|
||||||
|
|
||||||
const { readCsrDomains } = require('./crypto');
|
|
||||||
const { log } = require('./logger');
|
|
||||||
const { wait } = require('./wait');
|
|
||||||
const { CancelError } = require('./error');
|
|
||||||
|
|
||||||
const defaultOpts = {
|
const defaultOpts = {
|
||||||
csr: null,
|
csr: null,
|
||||||
|
@ -30,7 +30,7 @@ const defaultOpts = {
|
||||||
* @returns {Promise<buffer>} Certificate
|
* @returns {Promise<buffer>} Certificate
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = async (client, userOpts) => {
|
export default async (client, userOpts) => {
|
||||||
const opts = { ...defaultOpts, ...userOpts };
|
const opts = { ...defaultOpts, ...userOpts };
|
||||||
const accountPayload = { termsOfServiceAgreed: opts.termsOfServiceAgreed };
|
const accountPayload = { termsOfServiceAgreed: opts.termsOfServiceAgreed };
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Axios instance
|
* Axios instance
|
||||||
*/
|
*/
|
||||||
const axios = require('axios');
|
import axios from 'axios';
|
||||||
const { parseRetryAfterHeader } = require('./util');
|
import { parseRetryAfterHeader } from './util.js';
|
||||||
const { log } = require('./logger');
|
import { log } from './logger.js';
|
||||||
const pkg = require('./../package.json');
|
import * as Agents from './agents.js';
|
||||||
const Agents = require('./agents');
|
|
||||||
|
|
||||||
const { AxiosError } = axios;
|
const { AxiosError } = axios;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +14,7 @@ const { AxiosError } = axios;
|
||||||
const instance = axios.create();
|
const instance = axios.create();
|
||||||
|
|
||||||
/* Default User-Agent */
|
/* Default User-Agent */
|
||||||
instance.defaults.headers.common['User-Agent'] = `node-${pkg.name}/${pkg.version}`;
|
instance.defaults.headers.common['User-Agent'] = `@certd/acme-client`;
|
||||||
|
|
||||||
/* Default ACME settings */
|
/* Default ACME settings */
|
||||||
instance.defaults.acmeSettings = {
|
instance.defaults.acmeSettings = {
|
||||||
|
@ -144,4 +142,4 @@ instance.interceptors.response.use(null, async (error) => {
|
||||||
* Export instance
|
* Export instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = instance;
|
export default instance;
|
||||||
|
|
|
@ -3,16 +3,17 @@
|
||||||
*
|
*
|
||||||
* @namespace Client
|
* @namespace Client
|
||||||
*/
|
*/
|
||||||
|
import { createHash } from 'crypto';
|
||||||
|
import { getPemBodyAsB64u } from './crypto/index.js';
|
||||||
|
import { log } from './logger.js';
|
||||||
|
import HttpClient from './http.js';
|
||||||
|
import AcmeApi from './api.js';
|
||||||
|
import verify from './verify.js';
|
||||||
|
import * as util from './util.js';
|
||||||
|
import auto from './auto.js';
|
||||||
|
import { CancelError } from './error.js';
|
||||||
|
|
||||||
|
|
||||||
const { createHash } = require('crypto');
|
|
||||||
const { getPemBodyAsB64u } = require('./crypto');
|
|
||||||
const { log } = require('./logger');
|
|
||||||
const HttpClient = require('./http');
|
|
||||||
const AcmeApi = require('./api');
|
|
||||||
const verify = require('./verify');
|
|
||||||
const util = require('./util');
|
|
||||||
const auto = require('./auto');
|
|
||||||
const { CancelError } = require('./error');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ACME states
|
* ACME states
|
||||||
|
@ -719,4 +720,4 @@ class AcmeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Export client */
|
/* Export client */
|
||||||
module.exports = AcmeClient;
|
export default AcmeClient;
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
*
|
*
|
||||||
* @namespace forge
|
* @namespace forge
|
||||||
*/
|
*/
|
||||||
|
import net from 'net';
|
||||||
const net = require('net');
|
import { promisify } from 'util';
|
||||||
const { promisify } = require('util');
|
import forge from 'node-forge';
|
||||||
const forge = require('node-forge');
|
import { createPrivateEcdsaKey } from './index.js';
|
||||||
const { createPrivateEcdsaKey, getPublicKey } = require('./index');
|
|
||||||
|
|
||||||
const generateKeyPair = promisify(forge.pki.rsa.generateKeyPair);
|
const generateKeyPair = promisify(forge.pki.rsa.generateKeyPair);
|
||||||
|
|
||||||
|
@ -113,13 +112,12 @@ function parseDomains(obj) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function createPrivateKey(size = 2048) {
|
export async function createPrivateKey(size = 2048) {
|
||||||
const keyPair = await generateKeyPair({ bits: size });
|
const keyPair = await generateKeyPair({ bits: size });
|
||||||
const pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
const pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
|
||||||
return Buffer.from(pemKey);
|
return Buffer.from(pemKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createPrivateKey = createPrivateKey;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create public key from a private RSA key
|
* Create public key from a private RSA key
|
||||||
|
@ -133,7 +131,7 @@ exports.createPrivateKey = createPrivateKey;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createPublicKey = async (key) => {
|
export const createPublicKey = async (key) => {
|
||||||
const privateKey = forge.pki.privateKeyFromPem(key);
|
const privateKey = forge.pki.privateKeyFromPem(key);
|
||||||
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
const publicKey = forge.pki.rsa.setPublicKey(privateKey.n, privateKey.e);
|
||||||
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
const pemKey = forge.pki.publicKeyToPem(publicKey);
|
||||||
|
@ -148,7 +146,7 @@ exports.createPublicKey = async (key) => {
|
||||||
* @returns {string} PEM body
|
* @returns {string} PEM body
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPemBody = (str) => {
|
export const getPemBody = (str) => {
|
||||||
const msg = forge.pem.decode(str)[0];
|
const msg = forge.pem.decode(str)[0];
|
||||||
return forge.util.encode64(msg.body);
|
return forge.util.encode64(msg.body);
|
||||||
};
|
};
|
||||||
|
@ -160,7 +158,7 @@ exports.getPemBody = (str) => {
|
||||||
* @returns {string[]} Array of PEM bodies
|
* @returns {string[]} Array of PEM bodies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
export const splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get modulus
|
* Get modulus
|
||||||
|
@ -176,7 +174,7 @@ exports.splitPemChain = (str) => forge.pem.decode(str).map(forge.pem.encode);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getModulus = async (input) => {
|
export const getModulus = async (input) => {
|
||||||
if (!Buffer.isBuffer(input)) {
|
if (!Buffer.isBuffer(input)) {
|
||||||
input = Buffer.from(input);
|
input = Buffer.from(input);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +197,7 @@ exports.getModulus = async (input) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPublicExponent = async (input) => {
|
export const getPublicExponent = async (input) => {
|
||||||
if (!Buffer.isBuffer(input)) {
|
if (!Buffer.isBuffer(input)) {
|
||||||
input = Buffer.from(input);
|
input = Buffer.from(input);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +221,7 @@ exports.getPublicExponent = async (input) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.readCsrDomains = async (csr) => {
|
export const readCsrDomains = async (csr) => {
|
||||||
if (!Buffer.isBuffer(csr)) {
|
if (!Buffer.isBuffer(csr)) {
|
||||||
csr = Buffer.from(csr);
|
csr = Buffer.from(csr);
|
||||||
}
|
}
|
||||||
|
@ -251,7 +249,7 @@ exports.readCsrDomains = async (csr) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.readCertificateInfo = async (cert) => {
|
export const readCertificateInfo = async (cert) => {
|
||||||
if (!Buffer.isBuffer(cert)) {
|
if (!Buffer.isBuffer(cert)) {
|
||||||
cert = Buffer.from(cert);
|
cert = Buffer.from(cert);
|
||||||
}
|
}
|
||||||
|
@ -379,7 +377,7 @@ function formatCsrAltNames(altNames) {
|
||||||
* }, certificateKey);
|
* }, certificateKey);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createCsr = async (data, keyType = null) => {
|
export const createCsr = async (data, keyType = null) => {
|
||||||
let key = null;
|
let key = null;
|
||||||
if (keyType === 'ec') {
|
if (keyType === 'ec') {
|
||||||
key = await createPrivateEcdsaKey();
|
key = await createPrivateEcdsaKey();
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
*
|
*
|
||||||
* @namespace crypto
|
* @namespace crypto
|
||||||
*/
|
*/
|
||||||
|
import net from 'net';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
import crypto from 'crypto';
|
||||||
|
import asn1js from 'asn1js';
|
||||||
|
import x509 from '@peculiar/x509';
|
||||||
|
|
||||||
const net = require('net');
|
|
||||||
const { promisify } = require('util');
|
|
||||||
const crypto = require('crypto');
|
|
||||||
const asn1js = require('asn1js');
|
|
||||||
const x509 = require('@peculiar/x509');
|
|
||||||
|
|
||||||
const randomInt = promisify(crypto.randomInt);
|
const randomInt = promisify(crypto.randomInt);
|
||||||
const generateKeyPair = promisify(crypto.generateKeyPair);
|
const generateKeyPair = promisify(crypto.generateKeyPair);
|
||||||
|
@ -67,7 +67,7 @@ function getKeyInfo(keyPem) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8') {
|
export async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8') {
|
||||||
const pair = await generateKeyPair('rsa', {
|
const pair = await generateKeyPair('rsa', {
|
||||||
modulusLength,
|
modulusLength,
|
||||||
privateKeyEncoding: {
|
privateKeyEncoding: {
|
||||||
|
@ -79,7 +79,6 @@ async function createPrivateRsaKey(modulusLength = 2048, encodingType = 'pkcs8')
|
||||||
return Buffer.from(pair.privateKey);
|
return Buffer.from(pair.privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createPrivateRsaKey = createPrivateRsaKey;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias of `createPrivateRsaKey()`
|
* Alias of `createPrivateRsaKey()`
|
||||||
|
@ -87,7 +86,7 @@ exports.createPrivateRsaKey = createPrivateRsaKey;
|
||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createPrivateKey = createPrivateRsaKey;
|
export const createPrivateKey = createPrivateRsaKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a private ECDSA key
|
* Generate a private ECDSA key
|
||||||
|
@ -106,7 +105,7 @@ exports.createPrivateKey = createPrivateRsaKey;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkcs8') => {
|
export const createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkcs8') => {
|
||||||
const pair = await generateKeyPair('ec', {
|
const pair = await generateKeyPair('ec', {
|
||||||
namedCurve,
|
namedCurve,
|
||||||
privateKeyEncoding: {
|
privateKeyEncoding: {
|
||||||
|
@ -130,7 +129,7 @@ exports.createPrivateEcdsaKey = async (namedCurve = 'P-256', encodingType = 'pkc
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPublicKey = (keyPem) => {
|
export const getPublicKey = (keyPem) => {
|
||||||
const info = getKeyInfo(keyPem);
|
const info = getKeyInfo(keyPem);
|
||||||
|
|
||||||
const publicKey = info.publicKey.export({
|
const publicKey = info.publicKey.export({
|
||||||
|
@ -155,7 +154,7 @@ exports.getPublicKey = (keyPem) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getJwk(keyPem) {
|
export function getJwk(keyPem) {
|
||||||
const jwk = crypto.createPublicKey(keyPem).export({
|
const jwk = crypto.createPublicKey(keyPem).export({
|
||||||
format: 'jwk',
|
format: 'jwk',
|
||||||
});
|
});
|
||||||
|
@ -167,7 +166,6 @@ function getJwk(keyPem) {
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getJwk = getJwk;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce CryptoKeyPair and signing algorithm from a PEM encoded private key
|
* Produce CryptoKeyPair and signing algorithm from a PEM encoded private key
|
||||||
|
@ -215,7 +213,7 @@ async function getWebCryptoKeyPair(keyPem) {
|
||||||
* @returns {string[]} Array of PEM objects including headers
|
* @returns {string[]} Array of PEM objects including headers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function splitPemChain(chainPem) {
|
export function splitPemChain(chainPem) {
|
||||||
if (Buffer.isBuffer(chainPem)) {
|
if (Buffer.isBuffer(chainPem)) {
|
||||||
chainPem = chainPem.toString();
|
chainPem = chainPem.toString();
|
||||||
}
|
}
|
||||||
|
@ -225,7 +223,6 @@ function splitPemChain(chainPem) {
|
||||||
.map((params) => x509.PemConverter.encode([params]));
|
.map((params) => x509.PemConverter.encode([params]));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.splitPemChain = splitPemChain;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse body of PEM encoded object and return a Base64URL string
|
* Parse body of PEM encoded object and return a Base64URL string
|
||||||
|
@ -235,7 +232,7 @@ exports.splitPemChain = splitPemChain;
|
||||||
* @returns {string} Base64URL-encoded body
|
* @returns {string} Base64URL-encoded body
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPemBodyAsB64u = (pem) => {
|
export const getPemBodyAsB64u = (pem) => {
|
||||||
const chain = splitPemChain(pem);
|
const chain = splitPemChain(pem);
|
||||||
|
|
||||||
if (!chain.length) {
|
if (!chain.length) {
|
||||||
|
@ -286,7 +283,7 @@ function parseDomains(input) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.readCsrDomains = (csrPem) => {
|
export const readCsrDomains = (csrPem) => {
|
||||||
if (Buffer.isBuffer(csrPem)) {
|
if (Buffer.isBuffer(csrPem)) {
|
||||||
csrPem = csrPem.toString();
|
csrPem = csrPem.toString();
|
||||||
}
|
}
|
||||||
|
@ -315,7 +312,7 @@ exports.readCsrDomains = (csrPem) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.readCertificateInfo = (certPem) => {
|
export const readCertificateInfo = (certPem) => {
|
||||||
if (Buffer.isBuffer(certPem)) {
|
if (Buffer.isBuffer(certPem)) {
|
||||||
certPem = certPem.toString();
|
certPem = certPem.toString();
|
||||||
}
|
}
|
||||||
|
@ -449,7 +446,7 @@ function createSubjectAltNameExtension(altNames) {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createCsr = async (data, keyPem = null) => {
|
export const createCsr = async (data, keyPem = null) => {
|
||||||
if (!keyPem) {
|
if (!keyPem) {
|
||||||
keyPem = await createPrivateRsaKey(data.keySize);
|
keyPem = await createPrivateRsaKey(data.keySize);
|
||||||
}
|
}
|
||||||
|
@ -520,7 +517,7 @@ exports.createCsr = async (data, keyPem = null) => {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) => {
|
export const createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) => {
|
||||||
if (!keyPem) {
|
if (!keyPem) {
|
||||||
keyPem = await createPrivateRsaKey();
|
keyPem = await createPrivateRsaKey();
|
||||||
}
|
}
|
||||||
|
@ -583,7 +580,7 @@ exports.createAlpnCertificate = async (authz, keyAuthorization, keyPem = null) =
|
||||||
* @returns {boolean} True when valid
|
* @returns {boolean} True when valid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.isAlpnCertificateAuthorizationValid = (certPem, keyAuthorization) => {
|
export const isAlpnCertificateAuthorizationValid = (certPem, keyAuthorization) => {
|
||||||
const expected = crypto.createHash('sha256').update(keyAuthorization).digest('hex');
|
const expected = crypto.createHash('sha256').update(keyAuthorization).digest('hex');
|
||||||
|
|
||||||
/* Attempt to locate ALPN extension */
|
/* Attempt to locate ALPN extension */
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
class CancelError extends Error {
|
export class CancelError extends Error {
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
super(message);
|
super(message);
|
||||||
this.name = 'CancelError';
|
this.name = 'CancelError';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
CancelError,
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* ACME HTTP client
|
* ACME HTTP client
|
||||||
*/
|
*/
|
||||||
|
import { createHmac, createSign, constants } from 'crypto';
|
||||||
const { createHmac, createSign, constants: { RSA_PKCS1_PADDING } } = require('crypto');
|
const { RSA_PKCS1_PADDING } = constants;
|
||||||
const { getJwk } = require('./crypto');
|
import axios from './axios.js';
|
||||||
const { log } = require('./logger');
|
import { log } from './logger.js';
|
||||||
const axios = require('./axios');
|
import { getJwk } from './crypto/index.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ACME HTTP client
|
* ACME HTTP client
|
||||||
|
@ -324,4 +324,4 @@ class HttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Export client */
|
/* Export client */
|
||||||
module.exports = HttpClient;
|
export default HttpClient;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
/**
|
/**
|
||||||
* acme-client
|
* acme-client
|
||||||
*/
|
*/
|
||||||
|
import AcmeClinet from './client.js'
|
||||||
exports.Client = require('./client');
|
export const Client = AcmeClinet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directory URLs
|
* Directory URLs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.directory = {
|
export const directory = {
|
||||||
buypass: {
|
buypass: {
|
||||||
staging: 'https://api.test4.buypass.no/acme/directory',
|
staging: 'https://api.test4.buypass.no/acme/directory',
|
||||||
production: 'https://api.buypass.com/acme/directory',
|
production: 'https://api.buypass.com/acme/directory',
|
||||||
|
@ -31,21 +31,19 @@ exports.directory = {
|
||||||
* Crypto
|
* Crypto
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.crypto = require('./crypto');
|
export * as crypto from './crypto/index.js'
|
||||||
exports.forge = require('./crypto/forge');
|
export * from './crypto/forge.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Axios
|
* Axios
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.axios = require('./axios');
|
export * from './axios.js'
|
||||||
exports.agents = require('./agents');
|
export * as agents from './agents.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logger
|
* Logger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.setLogger = require('./logger').setLogger;
|
export * from './logger.js'
|
||||||
|
export * from './verify.js'
|
||||||
exports.walkTxtRecord = require('./verify').walkTxtRecord;
|
export * from './error.js'
|
||||||
exports.CancelError = require('./error').CancelError;
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
* ACME logger
|
* ACME logger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const debug = require('debug')('acme-client');
|
import debugg from 'debug'
|
||||||
|
const debug = debugg('acme-client');
|
||||||
|
|
||||||
let logger = () => {};
|
let logger = () => {};
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ let logger = () => {};
|
||||||
* @param {function} fn Logger function
|
* @param {function} fn Logger function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.setLogger = (fn) => {
|
export const setLogger = (fn) => {
|
||||||
logger = fn;
|
logger = fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ exports.setLogger = (fn) => {
|
||||||
* @param {string} msg Message
|
* @param {string} msg Message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.log = (...msg) => {
|
export const log = (...msg) => {
|
||||||
debug(...msg);
|
debug(...msg);
|
||||||
logger(...msg);
|
logger(...msg);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
* Utility methods
|
* Utility methods
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const tls = require('tls');
|
import tls from 'tls';
|
||||||
const dns = require('dns').promises;
|
import dnsSdk from 'dns';
|
||||||
const { readCertificateInfo, splitPemChain } = require('./crypto');
|
import { readCertificateInfo, splitPemChain }from './crypto/index.js'
|
||||||
const { log } = require('./logger');
|
import { log } from './logger.js'
|
||||||
|
|
||||||
|
const dns = dnsSdk.promises;
|
||||||
/**
|
/**
|
||||||
* Exponential backoff
|
* Exponential backoff
|
||||||
*
|
*
|
||||||
|
@ -329,7 +330,7 @@ async function retrieveTlsAlpnCertificate(host, port, timeout = 30000) {
|
||||||
* Export utils
|
* Export utils
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
retry,
|
retry,
|
||||||
parseLinkHeader,
|
parseLinkHeader,
|
||||||
parseRetryAfterHeader,
|
parseRetryAfterHeader,
|
||||||
|
@ -338,3 +339,4 @@ module.exports = {
|
||||||
getAuthoritativeDnsResolver,
|
getAuthoritativeDnsResolver,
|
||||||
retrieveTlsAlpnCertificate,
|
retrieveTlsAlpnCertificate,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
* ACME challenge verification
|
* ACME challenge verification
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const dns = require('dns').promises;
|
import dnsSdk from "dns"
|
||||||
const https = require('https');
|
import https from 'https'
|
||||||
const { log } = require('./logger');
|
import {log} from './logger.js'
|
||||||
const axios = require('./axios');
|
import axios from './axios.js'
|
||||||
const util = require('./util');
|
import * as util from './util.js'
|
||||||
const { isAlpnCertificateAuthorizationValid } = require('./crypto');
|
import {isAlpnCertificateAuthorizationValid} from './crypto/index.js'
|
||||||
|
|
||||||
|
|
||||||
|
const dns = dnsSdk.promises
|
||||||
/**
|
/**
|
||||||
* Verify ACME HTTP challenge
|
* Verify ACME HTTP challenge
|
||||||
*
|
*
|
||||||
|
@ -79,7 +81,7 @@ async function walkDnsChallengeRecord(recordName, resolver = dns) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function walkTxtRecord(recordName) {
|
export async function walkTxtRecord(recordName) {
|
||||||
try {
|
try {
|
||||||
/* Default DNS resolver first */
|
/* Default DNS resolver first */
|
||||||
log('Attempting to resolve TXT with default DNS resolver first');
|
log('Attempting to resolve TXT with default DNS resolver first');
|
||||||
|
@ -153,9 +155,8 @@ async function verifyTlsAlpnChallenge(authz, challenge, keyAuthorization) {
|
||||||
* Export API
|
* Export API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
'http-01': verifyHttpChallenge,
|
'http-01': verifyHttpChallenge,
|
||||||
'dns-01': verifyDnsChallenge,
|
'dns-01': verifyDnsChallenge,
|
||||||
'tls-alpn-01': verifyTlsAlpnChallenge,
|
'tls-alpn-01': verifyTlsAlpnChallenge,
|
||||||
walkTxtRecord,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
async function wait(ms) {
|
export async function wait(ms) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setTimeout(resolve, ms);
|
setTimeout(resolve, ms);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
wait,
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"compileOnSave": true,
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"lib": ["es6"],
|
|
||||||
"strict": true,
|
|
||||||
"noEmit": false,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"composite": false,
|
|
||||||
"paths": { "acme-client": ["."] }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@
|
||||||
"version": "1.27.2",
|
"version": "1.27.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
"module": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"version": "1.27.2",
|
"version": "1.27.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
"module": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"description": "midway with flyway, sql upgrade way ",
|
"description": "midway with flyway, sql upgrade way ",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"module": "./dist/index.js",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue