@cocreate/acme 1.2.1 → 1.2.2
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 +7 -0
- package/package.json +1 -1
- package/src/index.js +53 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.2.2](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.2.1...v1.2.2) (2024-01-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* ssl syncing ([65b226a](https://github.com/CoCreate-app/CoCreate-acme/commit/65b226a16487f3b8b6862092f6b3e83d8f119f51))
|
|
7
|
+
|
|
1
8
|
## [1.2.1](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.2.0...v1.2.1) (2024-01-08)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -243,11 +243,62 @@ class CoCreateAcme {
|
|
|
243
243
|
|
|
244
244
|
const hostKeyPath = keyPath + host + '/';
|
|
245
245
|
if (fs.existsSync(hostKeyPath + 'fullchain.pem')) {
|
|
246
|
-
let
|
|
247
|
-
expires = await forge.readCertificateInfo(
|
|
246
|
+
let cert = fs.readFileSync(hostKeyPath + 'fullchain.pem', 'utf8');
|
|
247
|
+
let expires = await forge.readCertificateInfo(cert);
|
|
248
248
|
expires = expires.notAfter;
|
|
249
249
|
if (this.isValid(expires)) {
|
|
250
250
|
this.setCertificate(host, expires, organization_id)
|
|
251
|
+
|
|
252
|
+
// TODO: remove after certs are synced
|
|
253
|
+
let key = fs.readFileSync(hostKeyPath + 'private-key.pem', 'utf8');
|
|
254
|
+
let hostPosition, org
|
|
255
|
+
|
|
256
|
+
if (!organization_id) {
|
|
257
|
+
let org = await this.crud.getHost(host)
|
|
258
|
+
if (org.error)
|
|
259
|
+
// console.log('Organization could not be found');
|
|
260
|
+
return false
|
|
261
|
+
else
|
|
262
|
+
organization_id = org._id
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
let organization = await this.crud.getOrganization(organization_id, false);
|
|
266
|
+
if (organization.error)
|
|
267
|
+
return false
|
|
268
|
+
|
|
269
|
+
if (organization.host) {
|
|
270
|
+
for (let i = 0; i < organization.host.length; i++) {
|
|
271
|
+
if (organization.host[i].name === host) {
|
|
272
|
+
hostPosition = i
|
|
273
|
+
console.log(`Found host: ${host} at postion: ${hostPosition}`)
|
|
274
|
+
|
|
275
|
+
if (organization.host[i].cert && organization.host[i].key) {
|
|
276
|
+
let expires = await forge.readCertificateInfo(organization.host[i].cert);
|
|
277
|
+
expires = expires.notAfter;
|
|
278
|
+
if (this.isValid(expires)) {
|
|
279
|
+
this.setCertificate(host, expires, organization_id, hostKeyPath, organization.host[i].cert, organization.host[i].key)
|
|
280
|
+
return true
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!hostPosition && hostPosition !== 0)
|
|
288
|
+
return false
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
this.crud.send({
|
|
292
|
+
method: 'object.update',
|
|
293
|
+
host,
|
|
294
|
+
array: 'organizations',
|
|
295
|
+
object: {
|
|
296
|
+
_id: organization_id,
|
|
297
|
+
[`host[${hostPosition}]`]: { name: host, cert, key, expires },
|
|
298
|
+
},
|
|
299
|
+
organization_id
|
|
300
|
+
});
|
|
301
|
+
|
|
251
302
|
return true
|
|
252
303
|
}
|
|
253
304
|
}
|