@certd/acme-client 1.38.4 → 1.38.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Simple and unopinionated ACME client",
4
4
  "private": false,
5
5
  "author": "nmorsman",
6
- "version": "1.38.4",
6
+ "version": "1.38.5",
7
7
  "type": "module",
8
8
  "module": "scr/index.js",
9
9
  "main": "src/index.js",
@@ -18,7 +18,7 @@
18
18
  "types"
19
19
  ],
20
20
  "dependencies": {
21
- "@certd/basic": "^1.38.4",
21
+ "@certd/basic": "^1.38.5",
22
22
  "@peculiar/x509": "^1.11.0",
23
23
  "asn1js": "^3.0.5",
24
24
  "axios": "^1.9.0",
@@ -70,5 +70,5 @@
70
70
  "bugs": {
71
71
  "url": "https://github.com/publishlab/node-acme-client/issues"
72
72
  },
73
- "gitHead": "84291482732687cc8162c6505666ba2b29b02918"
73
+ "gitHead": "eeb1f27fa47ddc616451f3e5a8fb8d1de345d252"
74
74
  }
package/src/client.js CHANGED
@@ -103,7 +103,9 @@ class AcmeClient {
103
103
  max: this.opts.backoffMax,
104
104
  };
105
105
 
106
- this.http = new HttpClient(this.opts.directoryUrl, this.opts.accountKey, this.opts.externalAccountBinding, this.opts.urlMapping, opts.logger);
106
+ const cacheNonce = true
107
+ // const cacheNonce = this.sslProvider === 'litessl';
108
+ this.http = new HttpClient(this.opts.directoryUrl, this.opts.accountKey, this.opts.externalAccountBinding, this.opts.urlMapping, opts.logger, cacheNonce);
107
109
  this.api = new AcmeApi(this.http, this.opts.accountUrl);
108
110
  this.logger = opts.logger;
109
111
  }
package/src/http.js CHANGED
@@ -19,7 +19,7 @@ import { getJwk } from './crypto/index.js';
19
19
  */
20
20
 
21
21
  class HttpClient {
22
- constructor(directoryUrl, accountKey, externalAccountBinding = {}, urlMapping = {},logger) {
22
+ constructor(directoryUrl, accountKey, externalAccountBinding = {}, urlMapping = {}, logger, cacheNonce= false) {
23
23
  this.directoryUrl = directoryUrl;
24
24
  this.accountKey = accountKey;
25
25
  this.externalAccountBinding = externalAccountBinding;
@@ -31,7 +31,34 @@ class HttpClient {
31
31
  this.directoryMaxAge = 86400;
32
32
  this.directoryTimestamp = 0;
33
33
  this.urlMapping = urlMapping;
34
- this.log = logger? logger.info.bind(logger) : log;
34
+ this.log = logger ? logger.info.bind(logger) : log;
35
+ this.nonces = [];
36
+ this.cacheNonce = cacheNonce;
37
+ }
38
+
39
+ pushNonce(nonce) {
40
+ if (!this.cacheNonce || !nonce) {
41
+ return;
42
+ }
43
+ this.nonces.push({
44
+ nonce,
45
+ expires: Date.now() + 30*1000,
46
+ });
47
+ }
48
+ popNonce() {
49
+ while (true) {
50
+ if (this.nonces.length === 0) {
51
+ return null;
52
+ }
53
+ const item = this.nonces.shift();
54
+ if (!item) {
55
+ return null;
56
+ }
57
+ if (item.expires < Date.now()) {
58
+ continue;
59
+ }
60
+ return item.nonce;
61
+ }
35
62
  }
36
63
 
37
64
  /**
@@ -70,6 +97,13 @@ class HttpClient {
70
97
  const resp = await axios.request(opts);
71
98
 
72
99
  this.log(`RESP ${resp.status} ${method} ${url}`);
100
+
101
+ const nonce = resp.headers['replay-nonce'];
102
+ if (nonce) {
103
+ //如果有nonce
104
+ this.pushNonce(nonce);
105
+ }
106
+
73
107
  return resp;
74
108
  }
75
109
 
@@ -127,6 +161,13 @@ class HttpClient {
127
161
  */
128
162
 
129
163
  async getNonce() {
164
+
165
+ //尝试从队列中pop一个nonce
166
+ const nonce = this.popNonce();
167
+ if (nonce) {
168
+ return nonce;
169
+ }
170
+
130
171
  const url = await this.getResourceUrl('newNonce');
131
172
  const resp = await this.request(url, 'head');
132
173
 
@@ -134,7 +175,11 @@ class HttpClient {
134
175
  throw new Error('Failed to get nonce from ACME provider');
135
176
  }
136
177
 
178
+ if (this.cacheNonce) {
179
+ return this.popNonce();
180
+ }
137
181
  return resp.headers['replay-nonce'];
182
+
138
183
  }
139
184
 
140
185
  /**