@cocreate/acme 1.1.3 → 1.2.1
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/CHANGELOG.md +23 -0
- package/package.json +1 -1
- package/src/index.js +51 -67
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## [1.2.1](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.2.0...v1.2.1) (2024-01-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* handling hostPosition ([fa105b1](https://github.com/CoCreate-app/CoCreate-acme/commit/fa105b1a35927380cd88549d7675eebd2d80a163))
|
|
7
|
+
|
|
8
|
+
# [1.2.0](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.1.3...v1.2.0) (2024-01-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* applied host to define environment/branch ([6931a9b](https://github.com/CoCreate-app/CoCreate-acme/commit/6931a9b81bfdf5b095534f7f42c6b9df1ea99141))
|
|
14
|
+
* handle ssl from host array ([fd45091](https://github.com/CoCreate-app/CoCreate-acme/commit/fd450914804b389647af52a1c40f6569e44066cf))
|
|
15
|
+
* setCertificate handle writeFileSync and hostPosition defined to save to host object ([29e794d](https://github.com/CoCreate-app/CoCreate-acme/commit/29e794de6d38584462ea926f3ef957d42b97c0bf))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* bumped CoCreate dependencies to their latest versions ([c25e34d](https://github.com/CoCreate-app/CoCreate-acme/commit/c25e34de1e47f660c773c7ea242e4ff2b060c936))
|
|
21
|
+
* host contains sert and key ([11380ac](https://github.com/CoCreate-app/CoCreate-acme/commit/11380acb7463e13d14a3e6ea856c288cef1d26c4))
|
|
22
|
+
* use crud.getHost and crud.getorganization ([574718b](https://github.com/CoCreate-app/CoCreate-acme/commit/574718b0ae035b63f6e70f4423ea1fd484bc80cc))
|
|
23
|
+
|
|
1
24
|
## [1.1.3](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.1.2...v1.1.3) (2024-01-03)
|
|
2
25
|
|
|
3
26
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -76,7 +76,7 @@ class CoCreateAcme {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
async requestCertificate(host, organization_id, wildcard = false) {
|
|
79
|
+
async requestCertificate(host, hostPosition, organization_id, wildcard = false) {
|
|
80
80
|
try {
|
|
81
81
|
|
|
82
82
|
const self = this
|
|
@@ -102,9 +102,12 @@ class CoCreateAcme {
|
|
|
102
102
|
email: [email], // Replace with your email
|
|
103
103
|
termsOfServiceAgreed: true,
|
|
104
104
|
challengeCreateFn: async (authz, challenge, keyAuthorization) => {
|
|
105
|
+
console.log(`Challenge added for host: ${host} token: ${challenge.token}`);
|
|
106
|
+
|
|
105
107
|
if (challenge.type === 'http-01') {
|
|
106
108
|
const httpChallenge = await self.crud.send({
|
|
107
109
|
method: 'object.create',
|
|
110
|
+
host,
|
|
108
111
|
array: 'files',
|
|
109
112
|
object: {
|
|
110
113
|
"content-type": "text/plain",
|
|
@@ -148,6 +151,7 @@ class CoCreateAcme {
|
|
|
148
151
|
if (challenge.type === 'http-01') {
|
|
149
152
|
self.crud.send({
|
|
150
153
|
method: 'object.delete',
|
|
154
|
+
host,
|
|
151
155
|
array: 'files',
|
|
152
156
|
object: {
|
|
153
157
|
_id: challenge_id
|
|
@@ -163,32 +167,25 @@ class CoCreateAcme {
|
|
|
163
167
|
|
|
164
168
|
let expires = await forge.readCertificateInfo(cert);
|
|
165
169
|
expires = expires.notAfter;
|
|
166
|
-
this.setCertificate(host, expires, organization_id)
|
|
167
|
-
|
|
168
|
-
/* Save the certificate and key */
|
|
169
|
-
fs.writeFileSync(hostKeyPath + 'fullchain.pem', cert);
|
|
170
|
-
// fs.chmodSync(keyPath + 'fullchain.pem', '444')
|
|
170
|
+
this.setCertificate(host, expires, organization_id, hostKeyPath, cert, key)
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
// fs.chmodSync(keyPath + 'private-key.pem', '400')
|
|
172
|
+
console.log(`saving host: ${host} at postion: ${hostPosition}`)
|
|
174
173
|
|
|
175
|
-
|
|
176
|
-
this.proxy.createServer(host)
|
|
177
|
-
|
|
178
|
-
let safeKey = host.replace(/\./g, '_');
|
|
179
|
-
let organization = await this.crud.send({
|
|
174
|
+
this.crud.send({
|
|
180
175
|
method: 'object.update',
|
|
176
|
+
host,
|
|
181
177
|
array: 'organizations',
|
|
182
178
|
object: {
|
|
183
179
|
_id: organization_id,
|
|
184
|
-
[
|
|
180
|
+
[`host[${hostPosition}]`]: { name: host, cert, key, expires },
|
|
185
181
|
},
|
|
186
|
-
organization_id
|
|
182
|
+
organization_id
|
|
187
183
|
});
|
|
188
184
|
|
|
189
|
-
console.log(
|
|
185
|
+
console.log(`Certificate successfully created for ${host}!'`);
|
|
190
186
|
return true
|
|
191
187
|
} catch (error) {
|
|
188
|
+
console.log(`Certificate failed to create for ${host}!`);
|
|
192
189
|
delete hosts[host]
|
|
193
190
|
return false
|
|
194
191
|
}
|
|
@@ -197,68 +194,42 @@ class CoCreateAcme {
|
|
|
197
194
|
|
|
198
195
|
async getCertificate(host, organization_id) {
|
|
199
196
|
const hostKeyPath = keyPath + host + '/';
|
|
197
|
+
let hostPosition
|
|
200
198
|
|
|
201
199
|
if (!organization_id) {
|
|
202
|
-
let org = await this.crud.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
$filter: {
|
|
206
|
-
query: [
|
|
207
|
-
{ key: "host", value: [host], operator: "$in" }
|
|
208
|
-
]
|
|
209
|
-
},
|
|
210
|
-
organization_id: process.env.organization_id
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
if (!org || !org.object || !org.object[0]) {
|
|
214
|
-
console.log('Organization could not be found');
|
|
200
|
+
let org = await this.crud.getHost(host)
|
|
201
|
+
if (org.error)
|
|
202
|
+
// console.log('Organization could not be found');
|
|
215
203
|
return false
|
|
216
|
-
|
|
217
|
-
organization_id = org.
|
|
218
|
-
}
|
|
219
|
-
|
|
204
|
+
else
|
|
205
|
+
organization_id = org._id
|
|
220
206
|
}
|
|
221
207
|
|
|
222
|
-
let organization = await this.crud.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
object: {
|
|
226
|
-
_id: organization_id
|
|
227
|
-
},
|
|
228
|
-
organization_id,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
if (organization && organization.object && organization.object[0]) {
|
|
232
|
-
|
|
233
|
-
if (!organization.object[0].host || !organization.object[0].host.includes(host))
|
|
234
|
-
return false
|
|
208
|
+
let organization = await this.crud.getOrganization(organization_id, false);
|
|
209
|
+
if (organization.error)
|
|
210
|
+
return false
|
|
235
211
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
fs.mkdirSync(hostKeyPath, { recursive: true });
|
|
212
|
+
if (organization.host) {
|
|
213
|
+
for (let i = 0; i < organization.host.length; i++) {
|
|
214
|
+
if (organization.host[i].name === host) {
|
|
215
|
+
hostPosition = i
|
|
216
|
+
if (organization.host[i].cert && organization.host[i].key) {
|
|
217
|
+
let expires = await forge.readCertificateInfo(organization.host[i].cert);
|
|
218
|
+
expires = expires.notAfter;
|
|
219
|
+
if (this.isValid(expires)) {
|
|
220
|
+
this.setCertificate(host, expires, organization_id, hostKeyPath, organization.host[i].cert, organization.host[i].key)
|
|
221
|
+
return true
|
|
247
222
|
}
|
|
248
|
-
|
|
249
|
-
fs.writeFileSync(hostKeyPath + 'fullchain.pem', cert);
|
|
250
|
-
// fs.chmodSync(keyPath + 'fullchain.pem', '444')
|
|
251
|
-
fs.writeFileSync(hostKeyPath + 'private-key.pem', key);
|
|
252
|
-
// fs.chmodSync(keyPath + 'private-key.pem', '400')
|
|
253
|
-
|
|
254
|
-
this.proxy.createServer(host)
|
|
255
|
-
return true
|
|
256
223
|
}
|
|
224
|
+
break
|
|
257
225
|
}
|
|
258
226
|
}
|
|
227
|
+
|
|
228
|
+
if (!hostPosition && hostPosition !== 0)
|
|
229
|
+
return false
|
|
259
230
|
}
|
|
260
231
|
|
|
261
|
-
return await this.requestCertificate(host, organization_id, false)
|
|
232
|
+
return await this.requestCertificate(host, hostPosition, organization_id, false)
|
|
262
233
|
}
|
|
263
234
|
|
|
264
235
|
async checkCertificate(host, organization_id, pathname = '') {
|
|
@@ -297,7 +268,7 @@ class CoCreateAcme {
|
|
|
297
268
|
}
|
|
298
269
|
}
|
|
299
270
|
|
|
300
|
-
setCertificate(host, expires, organization_id) {
|
|
271
|
+
setCertificate(host, expires, organization_id, hostKeyPath, cert, key) {
|
|
301
272
|
// let expireDate = new Date(expires);
|
|
302
273
|
// let currentDate = new Date();
|
|
303
274
|
|
|
@@ -323,6 +294,19 @@ class CoCreateAcme {
|
|
|
323
294
|
// }, timeoutDuration);
|
|
324
295
|
|
|
325
296
|
// Store the timeout and organization_id for later reference or cancellation
|
|
297
|
+
|
|
298
|
+
if (hostKeyPath) {
|
|
299
|
+
if (!fs.existsSync(hostKeyPath)) {
|
|
300
|
+
fs.mkdirSync(hostKeyPath, { recursive: true });
|
|
301
|
+
}
|
|
302
|
+
fs.writeFileSync(hostKeyPath + 'fullchain.pem', cert);
|
|
303
|
+
// fs.chmodSync(keyPath + 'fullchain.pem', '444')
|
|
304
|
+
fs.writeFileSync(hostKeyPath + 'private-key.pem', key);
|
|
305
|
+
// fs.chmodSync(keyPath + 'private-key.pem', '400')
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
this.proxy.createServer(host)
|
|
309
|
+
|
|
326
310
|
certificates[host] = { expires, organization_id }
|
|
327
311
|
|
|
328
312
|
}
|