@adobe/ccweb-add-on-ssl 3.0.1 → 3.1.0
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/.c8rc.json +12 -1
- package/dist/app/CommandExecutor.d.ts +6 -7
- package/dist/app/CommandExecutor.d.ts.map +1 -1
- package/dist/app/PurgeCommandExecutor.d.ts +4 -3
- package/dist/app/PurgeCommandExecutor.d.ts.map +1 -1
- package/dist/app/PurgeCommandExecutor.js +8 -8
- package/dist/app/SSLReader.d.ts +22 -3
- package/dist/app/SSLReader.d.ts.map +1 -1
- package/dist/app/SSLReader.js +143 -1
- package/dist/app/SetupCommandExecutor.d.ts +5 -4
- package/dist/app/SetupCommandExecutor.d.ts.map +1 -1
- package/dist/app/SetupCommandExecutor.js +12 -12
- package/dist/app/index.d.ts +1 -2
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +0 -2
- package/dist/commands/purge.js +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +1 -1
- package/dist/config/inversify.config.d.ts +1 -1
- package/dist/config/inversify.config.d.ts.map +1 -1
- package/dist/config/inversify.config.js +5 -3
- package/dist/models/{Types.d.ts → SSLTypes.d.ts} +1 -6
- package/dist/models/SSLTypes.d.ts.map +1 -0
- package/dist/models/{Types.js → SSLTypes.js} +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/validators/CommandValidator.d.ts +5 -6
- package/dist/validators/CommandValidator.d.ts.map +1 -1
- package/dist/validators/SetupCommandValidator.d.ts +2 -3
- package/dist/validators/SetupCommandValidator.d.ts.map +1 -1
- package/dist/validators/SetupCommandValidator.js +1 -2
- package/dist/validators/index.d.ts +1 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +0 -1
- package/package.json +6 -6
- package/src/app/CommandExecutor.ts +6 -8
- package/src/app/PurgeCommandExecutor.ts +9 -9
- package/src/app/SSLReader.ts +144 -6
- package/src/app/SetupCommandExecutor.ts +14 -14
- package/src/app/index.ts +1 -2
- package/src/commands/purge.ts +1 -1
- package/src/commands/setup.ts +11 -5
- package/src/config/inversify.config.ts +11 -8
- package/src/models/{Types.ts → SSLTypes.ts} +0 -7
- package/src/models/index.ts +1 -1
- package/src/test/app/PurgeCommandExecutor.spec.ts +6 -5
- package/src/test/app/{WxpSSLReader.spec.ts → SSLReader.spec.ts} +5 -6
- package/src/test/app/SetupCommandExecutor.spec.ts +8 -6
- package/src/test/commands/command.spec.ts +2 -1
- package/src/test/commands/purge.spec.ts +1 -1
- package/src/test/commands/setup.spec.ts +1 -1
- package/src/test/models/SetupCommandOptions.spec.ts +1 -1
- package/src/test/validators/SetupCommandValidator.spec.ts +3 -3
- package/src/validators/CommandValidator.ts +5 -7
- package/src/validators/SetupCommandValidator.ts +2 -3
- package/src/validators/index.ts +1 -1
- package/dist/app/WxpSSLReader.d.ts +0 -67
- package/dist/app/WxpSSLReader.d.ts.map +0 -1
- package/dist/app/WxpSSLReader.js +0 -167
- package/dist/models/Types.d.ts.map +0 -1
- package/src/app/WxpSSLReader.ts +0 -187
|
@@ -22,16 +22,14 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
********************************************************************************/
|
|
24
24
|
|
|
25
|
-
import type { CommandOptions } from "../models/index.js";
|
|
26
|
-
|
|
27
25
|
/**
|
|
28
26
|
* Command validator interface.
|
|
29
27
|
*/
|
|
30
|
-
export interface CommandValidator {
|
|
28
|
+
export interface CommandValidator<TOptions> {
|
|
31
29
|
/**
|
|
32
|
-
* Validate command options.
|
|
33
|
-
* @param options - Command
|
|
34
|
-
* @returns Promise.
|
|
30
|
+
* Validate command options provided by user.
|
|
31
|
+
* @param options - Command specific options.
|
|
32
|
+
* @returns Promise that resolves when the options are valid.
|
|
35
33
|
*/
|
|
36
|
-
validate(options:
|
|
34
|
+
validate(options: TOptions): Promise<void>;
|
|
37
35
|
}
|
|
@@ -31,20 +31,19 @@ import isValidDomain from "is-valid-domain";
|
|
|
31
31
|
import process from "process";
|
|
32
32
|
import "reflect-metadata";
|
|
33
33
|
import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
|
|
34
|
-
import type { SetupCommandOptions } from "../models/
|
|
34
|
+
import type { SetupCommandOptions } from "../models/SetupCommandOptions.js";
|
|
35
35
|
import type { CommandValidator } from "./CommandValidator.js";
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Setup command validator implementation class.
|
|
39
39
|
*/
|
|
40
40
|
@injectable()
|
|
41
|
-
export class SetupCommandValidator implements CommandValidator {
|
|
41
|
+
export class SetupCommandValidator implements CommandValidator<SetupCommandOptions> {
|
|
42
42
|
private readonly _analyticsService: AnalyticsService;
|
|
43
43
|
private readonly _logger: Logger;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Instantiate {@link SetupCommandValidator}.
|
|
47
|
-
* @param accountService - {@link AccountService} reference.
|
|
48
47
|
* @param analyticsService - {@link AnalyticsService} reference.
|
|
49
48
|
* @param logger - {@link Logger} reference.
|
|
50
49
|
* @returns Reference to a new {@link SetupCommandValidator} instance.
|
package/src/validators/index.ts
CHANGED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
import type { Logger, Preferences } from "@adobe/ccweb-add-on-core";
|
|
25
|
-
import "reflect-metadata";
|
|
26
|
-
import type { SSLData } from "../models/index.js";
|
|
27
|
-
/**
|
|
28
|
-
* Implementation class for reading the SSL artifacts.
|
|
29
|
-
*/
|
|
30
|
-
export declare class WxpSSLReader {
|
|
31
|
-
private readonly _preferences;
|
|
32
|
-
private readonly _logger;
|
|
33
|
-
/**
|
|
34
|
-
* Instantiate {@link WxpSSLReader}.
|
|
35
|
-
* @param Preferences - {@link Preferences} reference.
|
|
36
|
-
* @param logger - {@link Logger} reference.
|
|
37
|
-
* @returns Reference to a new {@link WxpSSLReader} instance.
|
|
38
|
-
*/
|
|
39
|
-
constructor(preferences: Preferences, logger: Logger);
|
|
40
|
-
/**
|
|
41
|
-
* Is SSL set up manually by the user.
|
|
42
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
43
|
-
* @returns Boolean value representing whether SSL is set up manually.
|
|
44
|
-
*/
|
|
45
|
-
isCustomSSL(hostname: string): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Is SSL set up automatically by the tool.
|
|
48
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
49
|
-
* @returns Boolean value representing whether SSL is set up automatically.
|
|
50
|
-
*/
|
|
51
|
-
isWxpSSL(hostname: string): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Read the SSL artifacts.
|
|
54
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
55
|
-
* @param port - Port where the add-on is being hosted.
|
|
56
|
-
* @returns Promise of {@link SSLData}.
|
|
57
|
-
*/
|
|
58
|
-
read(hostname: string, port: number): Promise<SSLData>;
|
|
59
|
-
private _getUserDefinedSSL;
|
|
60
|
-
private _handleExpiredSSLCertificate;
|
|
61
|
-
private _handleNearingExpirySSLCertificate;
|
|
62
|
-
private _handleNoSSLCertificateFound;
|
|
63
|
-
private _handleInvalidUserSSLCertificate;
|
|
64
|
-
private _handleUnknownExpirySSLCertificate;
|
|
65
|
-
private _recreateSSLCertificate;
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=WxpSSLReader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WxpSSLReader.d.ts","sourceRoot":"","sources":["../../src/app/WxpSSLReader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAe,MAAM,0BAA0B,CAAC;AAKjF,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,qBACa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;;;OAKG;gBACyC,WAAW,EAAE,WAAW,EAA6B,MAAM,EAAE,MAAM;IAK/G;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAItC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAInC;;;;;OAKG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA8C5D,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,4BAA4B;IAMpC,OAAO,CAAC,kCAAkC;IAK1C,OAAO,CAAC,4BAA4B;IAMpC,OAAO,CAAC,gCAAgC;IAKxC,OAAO,CAAC,kCAAkC;IAO1C,OAAO,CAAC,uBAAuB;CAOlC"}
|
package/dist/app/WxpSSLReader.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
import { __decorate, __metadata, __param } from "tslib";
|
|
25
|
-
import { ITypes as ICoreTypes, isFile } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import devcert from "@adobe/ccweb-add-on-devcert";
|
|
27
|
-
import fs from "fs-extra";
|
|
28
|
-
import { inject, injectable } from "inversify";
|
|
29
|
-
import "reflect-metadata";
|
|
30
|
-
import format from "string-template";
|
|
31
|
-
/**
|
|
32
|
-
* Implementation class for reading the SSL artifacts.
|
|
33
|
-
*/
|
|
34
|
-
let WxpSSLReader = class WxpSSLReader {
|
|
35
|
-
_preferences;
|
|
36
|
-
_logger;
|
|
37
|
-
/**
|
|
38
|
-
* Instantiate {@link WxpSSLReader}.
|
|
39
|
-
* @param Preferences - {@link Preferences} reference.
|
|
40
|
-
* @param logger - {@link Logger} reference.
|
|
41
|
-
* @returns Reference to a new {@link WxpSSLReader} instance.
|
|
42
|
-
*/
|
|
43
|
-
constructor(preferences, logger) {
|
|
44
|
-
this._preferences = preferences;
|
|
45
|
-
this._logger = logger;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Is SSL set up manually by the user.
|
|
49
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
50
|
-
* @returns Boolean value representing whether SSL is set up manually.
|
|
51
|
-
*/
|
|
52
|
-
isCustomSSL(hostname) {
|
|
53
|
-
return this._getUserDefinedSSL(hostname) !== undefined;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Is SSL set up automatically by the tool.
|
|
57
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
58
|
-
* @returns Boolean value representing whether SSL is set up automatically.
|
|
59
|
-
*/
|
|
60
|
-
isWxpSSL(hostname) {
|
|
61
|
-
return devcert.hasCertificateFor(hostname);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Read the SSL artifacts.
|
|
65
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
66
|
-
* @param port - Port where the add-on is being hosted.
|
|
67
|
-
* @returns Promise of {@link SSLData}.
|
|
68
|
-
*/
|
|
69
|
-
async read(hostname, port) {
|
|
70
|
-
const sslSettings = this._getUserDefinedSSL(hostname);
|
|
71
|
-
// When SSL is set up manuually by the `user`.
|
|
72
|
-
if (sslSettings !== undefined) {
|
|
73
|
-
const { certificatePath, keyPath } = sslSettings;
|
|
74
|
-
if (!certificatePath || !isFile(certificatePath)) {
|
|
75
|
-
this._handleInvalidUserSSLCertificate(LOGS.invalidCertificatePath);
|
|
76
|
-
return process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
if (!keyPath || !isFile(keyPath)) {
|
|
79
|
-
this._handleInvalidUserSSLCertificate(LOGS.invalidKeyPath);
|
|
80
|
-
return process.exit(1);
|
|
81
|
-
}
|
|
82
|
-
this._handleUnknownExpirySSLCertificate(hostname, port);
|
|
83
|
-
return {
|
|
84
|
-
cert: fs.readFileSync(certificatePath),
|
|
85
|
-
key: fs.readFileSync(keyPath)
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
// When SSL is set up automatically by `devcert`.
|
|
89
|
-
if (this.isWxpSSL(hostname)) {
|
|
90
|
-
const caExpiry = devcert.caExpiryInDays();
|
|
91
|
-
const certificateExpiry = devcert.certificateExpiryInDays(hostname);
|
|
92
|
-
const expiry = Math.min(certificateExpiry, caExpiry);
|
|
93
|
-
if (expiry <= 0) {
|
|
94
|
-
this._handleExpiredSSLCertificate();
|
|
95
|
-
return process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
if (expiry <= 7) {
|
|
98
|
-
this._handleNearingExpirySSLCertificate(expiry);
|
|
99
|
-
}
|
|
100
|
-
return await devcert.certificateFor(hostname);
|
|
101
|
-
}
|
|
102
|
-
this._handleNoSSLCertificateFound();
|
|
103
|
-
return process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
_getUserDefinedSSL(hostname) {
|
|
106
|
-
const { ssl } = this._preferences.get();
|
|
107
|
-
if (ssl === undefined) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
return ssl.get(hostname);
|
|
111
|
-
}
|
|
112
|
-
_handleExpiredSSLCertificate() {
|
|
113
|
-
this._logger.error(LOGS.noValidSSLCertificateFound);
|
|
114
|
-
this._logger.error(LOGS.expiredSSLCertificate);
|
|
115
|
-
this._recreateSSLCertificate();
|
|
116
|
-
}
|
|
117
|
-
_handleNearingExpirySSLCertificate(expiry) {
|
|
118
|
-
this._logger.warning(format(LOGS.nearingExpirySSLCertificate, { expiry }));
|
|
119
|
-
this._recreateSSLCertificate();
|
|
120
|
-
}
|
|
121
|
-
_handleNoSSLCertificateFound() {
|
|
122
|
-
this._logger.error(LOGS.noValidSSLCertificateFound);
|
|
123
|
-
this._logger.error(LOGS.invalidatedSSLCertificate);
|
|
124
|
-
this._recreateSSLCertificate();
|
|
125
|
-
}
|
|
126
|
-
_handleInvalidUserSSLCertificate(errorMessage) {
|
|
127
|
-
this._logger.error(errorMessage);
|
|
128
|
-
this._recreateSSLCertificate();
|
|
129
|
-
}
|
|
130
|
-
_handleUnknownExpirySSLCertificate(hostname, port) {
|
|
131
|
-
this._logger.warning(LOGS.undeterminedExpirySSLCertificate);
|
|
132
|
-
this._logger.warning(LOGS.unableToSideloadAddOn);
|
|
133
|
-
this._logger.warning(format(LOGS.checkCertificateValidity, { hostname, port }));
|
|
134
|
-
this._recreateSSLCertificate();
|
|
135
|
-
}
|
|
136
|
-
_recreateSSLCertificate() {
|
|
137
|
-
this._logger.warning(LOGS.recreateSSLCertificate, { prefix: LOGS.newLine });
|
|
138
|
-
this._logger.information(LOGS.setupSSLCommand, { prefix: LOGS.tab });
|
|
139
|
-
this._logger.warning(LOGS.example, { prefix: LOGS.newLine });
|
|
140
|
-
this._logger.information(LOGS.setupSSLCommandExample, { prefix: LOGS.tab, postfix: LOGS.newLine });
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
WxpSSLReader = __decorate([
|
|
144
|
-
injectable(),
|
|
145
|
-
__param(0, inject(ICoreTypes.Preferences)),
|
|
146
|
-
__param(1, inject(ICoreTypes.Logger)),
|
|
147
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
148
|
-
], WxpSSLReader);
|
|
149
|
-
export { WxpSSLReader };
|
|
150
|
-
const LOGS = {
|
|
151
|
-
newLine: "\n",
|
|
152
|
-
tab: " ",
|
|
153
|
-
invalidCertificatePath: "Invalid SSL certificate file path.",
|
|
154
|
-
invalidKeyPath: "Invalid SSL key file path.",
|
|
155
|
-
noValidSSLCertificateFound: "Could not locate a valid SSL certificate to host the add-on.",
|
|
156
|
-
expiredSSLCertificate: "The SSL certificate has expired.",
|
|
157
|
-
nearingExpirySSLCertificate: "Your SSL certificate will expire in {expiry} days.",
|
|
158
|
-
invalidatedSSLCertificate: "If you had previously set it up, it may have been invalidated due to a version upgrade.",
|
|
159
|
-
undeterminedExpirySSLCertificate: "Could not determine the expiry of your SSL certificate.",
|
|
160
|
-
unableToSideloadAddOn: "If you are unable to sideload your add-on, please check the validity of:",
|
|
161
|
-
checkCertificateValidity: "https://{hostname}:{port} certificate in your browser.",
|
|
162
|
-
recreateSSLCertificate: "To re-create the SSL certificate, you may run:",
|
|
163
|
-
setupSSLCommand: "npx @adobe/ccweb-add-on-ssl setup --hostname [hostname]",
|
|
164
|
-
example: "Example:",
|
|
165
|
-
setupSSLCommandExample: "npx @adobe/ccweb-add-on-ssl setup --hostname localhost"
|
|
166
|
-
};
|
|
167
|
-
//# sourceMappingURL=WxpSSLReader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../src/models/Types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAEjD;;GAEG;AACH,oBAAY,cAAc;IACtB,aAAa,kBAAkB;IAC/B,QAAQ,aAAa;CACxB;AAED;;GAEG;AACH,oBAAY,eAAe;IACvB,MAAM,WAAW;IACjB,IAAI,SAAS;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IAClB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAEtB;;OAEG;IACH,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC"}
|
package/src/app/WxpSSLReader.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
|
|
25
|
-
import type { Logger, Preferences, SSLSettings } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import { ITypes as ICoreTypes, isFile } from "@adobe/ccweb-add-on-core";
|
|
27
|
-
import devcert from "@adobe/ccweb-add-on-devcert";
|
|
28
|
-
import fs from "fs-extra";
|
|
29
|
-
import { inject, injectable } from "inversify";
|
|
30
|
-
import "reflect-metadata";
|
|
31
|
-
import format from "string-template";
|
|
32
|
-
import type { SSLData } from "../models/index.js";
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Implementation class for reading the SSL artifacts.
|
|
36
|
-
*/
|
|
37
|
-
@injectable()
|
|
38
|
-
export class WxpSSLReader {
|
|
39
|
-
private readonly _preferences: Preferences;
|
|
40
|
-
private readonly _logger: Logger;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Instantiate {@link WxpSSLReader}.
|
|
44
|
-
* @param Preferences - {@link Preferences} reference.
|
|
45
|
-
* @param logger - {@link Logger} reference.
|
|
46
|
-
* @returns Reference to a new {@link WxpSSLReader} instance.
|
|
47
|
-
*/
|
|
48
|
-
constructor(@inject(ICoreTypes.Preferences) preferences: Preferences, @inject(ICoreTypes.Logger) logger: Logger) {
|
|
49
|
-
this._preferences = preferences;
|
|
50
|
-
this._logger = logger;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Is SSL set up manually by the user.
|
|
55
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
56
|
-
* @returns Boolean value representing whether SSL is set up manually.
|
|
57
|
-
*/
|
|
58
|
-
isCustomSSL(hostname: string): boolean {
|
|
59
|
-
return this._getUserDefinedSSL(hostname) !== undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Is SSL set up automatically by the tool.
|
|
64
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
65
|
-
* @returns Boolean value representing whether SSL is set up automatically.
|
|
66
|
-
*/
|
|
67
|
-
isWxpSSL(hostname: string): boolean {
|
|
68
|
-
return devcert.hasCertificateFor(hostname);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Read the SSL artifacts.
|
|
73
|
-
* @param hostname - Hostname in the SSL certificate.
|
|
74
|
-
* @param port - Port where the add-on is being hosted.
|
|
75
|
-
* @returns Promise of {@link SSLData}.
|
|
76
|
-
*/
|
|
77
|
-
async read(hostname: string, port: number): Promise<SSLData> {
|
|
78
|
-
const sslSettings = this._getUserDefinedSSL(hostname);
|
|
79
|
-
|
|
80
|
-
// When SSL is set up manuually by the `user`.
|
|
81
|
-
if (sslSettings !== undefined) {
|
|
82
|
-
const { certificatePath, keyPath } = sslSettings;
|
|
83
|
-
if (!certificatePath || !isFile(certificatePath)) {
|
|
84
|
-
this._handleInvalidUserSSLCertificate(LOGS.invalidCertificatePath);
|
|
85
|
-
return process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!keyPath || !isFile(keyPath)) {
|
|
89
|
-
this._handleInvalidUserSSLCertificate(LOGS.invalidKeyPath);
|
|
90
|
-
return process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
this._handleUnknownExpirySSLCertificate(hostname, port);
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
cert: fs.readFileSync(certificatePath),
|
|
97
|
-
key: fs.readFileSync(keyPath)
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// When SSL is set up automatically by `devcert`.
|
|
102
|
-
if (this.isWxpSSL(hostname)) {
|
|
103
|
-
const caExpiry = devcert.caExpiryInDays();
|
|
104
|
-
const certificateExpiry = devcert.certificateExpiryInDays(hostname);
|
|
105
|
-
|
|
106
|
-
const expiry = Math.min(certificateExpiry, caExpiry);
|
|
107
|
-
if (expiry <= 0) {
|
|
108
|
-
this._handleExpiredSSLCertificate();
|
|
109
|
-
return process.exit(1);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (expiry <= 7) {
|
|
113
|
-
this._handleNearingExpirySSLCertificate(expiry);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return await devcert.certificateFor(hostname);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this._handleNoSSLCertificateFound();
|
|
120
|
-
return process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private _getUserDefinedSSL(hostname: string): SSLSettings | undefined {
|
|
124
|
-
const { ssl } = this._preferences.get();
|
|
125
|
-
if (ssl === undefined) {
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return ssl.get(hostname);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private _handleExpiredSSLCertificate() {
|
|
133
|
-
this._logger.error(LOGS.noValidSSLCertificateFound);
|
|
134
|
-
this._logger.error(LOGS.expiredSSLCertificate);
|
|
135
|
-
this._recreateSSLCertificate();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private _handleNearingExpirySSLCertificate(expiry: number) {
|
|
139
|
-
this._logger.warning(format(LOGS.nearingExpirySSLCertificate, { expiry }));
|
|
140
|
-
this._recreateSSLCertificate();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private _handleNoSSLCertificateFound() {
|
|
144
|
-
this._logger.error(LOGS.noValidSSLCertificateFound);
|
|
145
|
-
this._logger.error(LOGS.invalidatedSSLCertificate);
|
|
146
|
-
this._recreateSSLCertificate();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private _handleInvalidUserSSLCertificate(errorMessage: string) {
|
|
150
|
-
this._logger.error(errorMessage);
|
|
151
|
-
this._recreateSSLCertificate();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
private _handleUnknownExpirySSLCertificate(hostname: string, port: number) {
|
|
155
|
-
this._logger.warning(LOGS.undeterminedExpirySSLCertificate);
|
|
156
|
-
this._logger.warning(LOGS.unableToSideloadAddOn);
|
|
157
|
-
this._logger.warning(format(LOGS.checkCertificateValidity, { hostname, port }));
|
|
158
|
-
this._recreateSSLCertificate();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private _recreateSSLCertificate() {
|
|
162
|
-
this._logger.warning(LOGS.recreateSSLCertificate, { prefix: LOGS.newLine });
|
|
163
|
-
this._logger.information(LOGS.setupSSLCommand, { prefix: LOGS.tab });
|
|
164
|
-
|
|
165
|
-
this._logger.warning(LOGS.example, { prefix: LOGS.newLine });
|
|
166
|
-
this._logger.information(LOGS.setupSSLCommandExample, { prefix: LOGS.tab, postfix: LOGS.newLine });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const LOGS = {
|
|
171
|
-
newLine: "\n",
|
|
172
|
-
tab: " ",
|
|
173
|
-
invalidCertificatePath: "Invalid SSL certificate file path.",
|
|
174
|
-
invalidKeyPath: "Invalid SSL key file path.",
|
|
175
|
-
noValidSSLCertificateFound: "Could not locate a valid SSL certificate to host the add-on.",
|
|
176
|
-
expiredSSLCertificate: "The SSL certificate has expired.",
|
|
177
|
-
nearingExpirySSLCertificate: "Your SSL certificate will expire in {expiry} days.",
|
|
178
|
-
invalidatedSSLCertificate:
|
|
179
|
-
"If you had previously set it up, it may have been invalidated due to a version upgrade.",
|
|
180
|
-
undeterminedExpirySSLCertificate: "Could not determine the expiry of your SSL certificate.",
|
|
181
|
-
unableToSideloadAddOn: "If you are unable to sideload your add-on, please check the validity of:",
|
|
182
|
-
checkCertificateValidity: "https://{hostname}:{port} certificate in your browser.",
|
|
183
|
-
recreateSSLCertificate: "To re-create the SSL certificate, you may run:",
|
|
184
|
-
setupSSLCommand: "npx @adobe/ccweb-add-on-ssl setup --hostname [hostname]",
|
|
185
|
-
example: "Example:",
|
|
186
|
-
setupSSLCommandExample: "npx @adobe/ccweb-add-on-ssl setup --hostname localhost"
|
|
187
|
-
};
|