@bubblewrap/core 1.13.6
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/LICENSE +203 -0
- package/README.md +63 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +56 -0
- package/dist/lib/BufferedLog.d.ts +20 -0
- package/dist/lib/BufferedLog.js +83 -0
- package/dist/lib/Config.d.ts +9 -0
- package/dist/lib/Config.js +50 -0
- package/dist/lib/DigitalAssetLinks.d.ts +3 -0
- package/dist/lib/DigitalAssetLinks.js +37 -0
- package/dist/lib/FetchUtils.d.ts +17 -0
- package/dist/lib/FetchUtils.js +79 -0
- package/dist/lib/GooglePlay.d.ts +41 -0
- package/dist/lib/GooglePlay.js +92 -0
- package/dist/lib/GradleWrapper.d.ts +31 -0
- package/dist/lib/GradleWrapper.js +62 -0
- package/dist/lib/ImageHelper.d.ts +37 -0
- package/dist/lib/ImageHelper.js +112 -0
- package/dist/lib/Log.d.ts +88 -0
- package/dist/lib/Log.js +114 -0
- package/dist/lib/Result.d.ts +46 -0
- package/dist/lib/Result.js +97 -0
- package/dist/lib/ShortcutInfo.d.ts +32 -0
- package/dist/lib/ShortcutInfo.js +84 -0
- package/dist/lib/TwaGenerator.d.ts +39 -0
- package/dist/lib/TwaGenerator.js +362 -0
- package/dist/lib/TwaManifest.d.ts +234 -0
- package/dist/lib/TwaManifest.js +384 -0
- package/dist/lib/androidSdk/AndroidSdkTools.d.ts +87 -0
- package/dist/lib/androidSdk/AndroidSdkTools.js +226 -0
- package/dist/lib/errors/ValidatePathError.d.ts +9 -0
- package/dist/lib/errors/ValidatePathError.js +16 -0
- package/dist/lib/features/AppsFlyerFeature.d.ts +8 -0
- package/dist/lib/features/AppsFlyerFeature.js +70 -0
- package/dist/lib/features/EmptyFeature.d.ts +28 -0
- package/dist/lib/features/EmptyFeature.js +44 -0
- package/dist/lib/features/Feature.d.ts +120 -0
- package/dist/lib/features/Feature.js +17 -0
- package/dist/lib/features/FeatureManager.d.ts +36 -0
- package/dist/lib/features/FeatureManager.js +137 -0
- package/dist/lib/features/FirstRunFlagFeature.d.ts +8 -0
- package/dist/lib/features/FirstRunFlagFeature.js +43 -0
- package/dist/lib/features/LocationDelegationFeature.d.ts +7 -0
- package/dist/lib/features/LocationDelegationFeature.js +32 -0
- package/dist/lib/features/PlayBillingFeature.d.ts +7 -0
- package/dist/lib/features/PlayBillingFeature.js +53 -0
- package/dist/lib/jdk/JarSigner.d.ts +13 -0
- package/dist/lib/jdk/JarSigner.js +55 -0
- package/dist/lib/jdk/JdkHelper.d.ts +55 -0
- package/dist/lib/jdk/JdkHelper.js +127 -0
- package/dist/lib/jdk/KeyTool.d.ts +57 -0
- package/dist/lib/jdk/KeyTool.js +136 -0
- package/dist/lib/mock/MockLog.d.ts +37 -0
- package/dist/lib/mock/MockLog.js +70 -0
- package/dist/lib/types/WebManifest.d.ts +44 -0
- package/dist/lib/types/WebManifest.js +17 -0
- package/dist/lib/util.d.ts +82 -0
- package/dist/lib/util.js +279 -0
- package/dist/lib/wrappers/svg2img.d.ts +14 -0
- package/dist/lib/wrappers/svg2img.js +39 -0
- package/package.json +58 -0
- package/template_project/app/.gitignore +1 -0
- package/template_project/app/build.gradle +211 -0
- package/template_project/app/src/main/AndroidManifest.xml +204 -0
- package/template_project/app/src/main/java/Application.java +35 -0
- package/template_project/app/src/main/java/DelegationService.java +18 -0
- package/template_project/app/src/main/java/LauncherActivity.java +62 -0
- package/template_project/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml +25 -0
- package/template_project/app/src/main/res/drawable-anydpi/shortcut_monochrome.xml +27 -0
- package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_maskable.xml +32 -0
- package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_monochrome.xml +26 -0
- package/template_project/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +33 -0
- package/template_project/app/src/main/res/values/colors.xml +18 -0
- package/template_project/app/src/main/res/values/strings.xml +50 -0
- package/template_project/app/src/main/res/xml/filepaths.xml +18 -0
- package/template_project/app/src/main/res/xml/shortcuts.xml +16 -0
- package/template_project/build.gradle +42 -0
- package/template_project/enable-debug.sh +27 -0
- package/template_project/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template_project/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/template_project/gradle.properties +14 -0
- package/template_project/gradlew +188 -0
- package/template_project/gradlew.bat +100 -0
- package/template_project/settings.gradle +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PlayBillingFeature = void 0;
|
|
19
|
+
const EmptyFeature_1 = require("./EmptyFeature");
|
|
20
|
+
class PlayBillingFeature extends EmptyFeature_1.EmptyFeature {
|
|
21
|
+
constructor() {
|
|
22
|
+
super('playbilling');
|
|
23
|
+
this.buildGradle.dependencies.push('com.google.androidbrowserhelper:billing:1.0.0-alpha08');
|
|
24
|
+
this.androidManifest.components.push(`
|
|
25
|
+
<activity
|
|
26
|
+
android:name="com.google.androidbrowserhelper.playbilling.provider.PaymentActivity"
|
|
27
|
+
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
|
28
|
+
android:configChanges="keyboardHidden|keyboard|orientation|screenLayout|screenSize"
|
|
29
|
+
android:exported="true">
|
|
30
|
+
|
|
31
|
+
<intent-filter>
|
|
32
|
+
<action android:name="org.chromium.intent.action.PAY" />
|
|
33
|
+
</intent-filter>
|
|
34
|
+
|
|
35
|
+
<meta-data
|
|
36
|
+
android:name="org.chromium.default_payment_method_name"
|
|
37
|
+
android:value="https://play.google.com/billing" />
|
|
38
|
+
</activity>
|
|
39
|
+
|
|
40
|
+
<!-- This service checks who calls it at runtime. -->
|
|
41
|
+
<service
|
|
42
|
+
android:name="com.google.androidbrowserhelper.playbilling.provider.PaymentService"
|
|
43
|
+
android:exported="true" >
|
|
44
|
+
<intent-filter>
|
|
45
|
+
<action android:name="org.chromium.intent.action.IS_READY_TO_PAY" />
|
|
46
|
+
</intent-filter>
|
|
47
|
+
</service> `);
|
|
48
|
+
this.delegationService.imports.push('com.google.androidbrowserhelper.playbilling.digitalgoods.DigitalGoodsRequestHandler');
|
|
49
|
+
this.delegationService.onCreate =
|
|
50
|
+
'registerExtraCommandHandler(new DigitalGoodsRequestHandler(getApplicationContext()));';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.PlayBillingFeature = PlayBillingFeature;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JdkHelper } from './JdkHelper';
|
|
2
|
+
import { SigningKeyInfo } from '../../lib/TwaManifest';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps the Java `jarsigner` CLI tool.
|
|
5
|
+
*/
|
|
6
|
+
export declare class JarSigner {
|
|
7
|
+
private jdkHelper;
|
|
8
|
+
constructor(jdkHelper: JdkHelper);
|
|
9
|
+
/**
|
|
10
|
+
* Signs a file
|
|
11
|
+
*/
|
|
12
|
+
sign(signingKeyInfo: SigningKeyInfo, storepass: string, keypass: string, inputFile: string, outputFile: string): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.JarSigner = void 0;
|
|
19
|
+
const util_1 = require("../util");
|
|
20
|
+
const JARSIGNER_CMD = 'jarsigner';
|
|
21
|
+
const SIGNATURE_ALGORITHM = 'SHA256withRSA';
|
|
22
|
+
const DIGEST_ALGORITHM = 'SHA-256';
|
|
23
|
+
/**
|
|
24
|
+
* Wraps the Java `jarsigner` CLI tool.
|
|
25
|
+
*/
|
|
26
|
+
class JarSigner {
|
|
27
|
+
constructor(jdkHelper) {
|
|
28
|
+
this.jdkHelper = jdkHelper;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Signs a file
|
|
32
|
+
*/
|
|
33
|
+
async sign(signingKeyInfo, storepass, keypass, inputFile, outputFile) {
|
|
34
|
+
const env = this.jdkHelper.getEnv();
|
|
35
|
+
await util_1.executeFile(JARSIGNER_CMD, [
|
|
36
|
+
'-verbose',
|
|
37
|
+
'-sigalg',
|
|
38
|
+
SIGNATURE_ALGORITHM,
|
|
39
|
+
'-digestalg',
|
|
40
|
+
DIGEST_ALGORITHM,
|
|
41
|
+
'-keystore',
|
|
42
|
+
signingKeyInfo.path,
|
|
43
|
+
inputFile,
|
|
44
|
+
signingKeyInfo.alias,
|
|
45
|
+
'-storepass',
|
|
46
|
+
storepass,
|
|
47
|
+
'-keypass',
|
|
48
|
+
keypass,
|
|
49
|
+
'-signedjar',
|
|
50
|
+
outputFile,
|
|
51
|
+
], env);
|
|
52
|
+
}
|
|
53
|
+
;
|
|
54
|
+
}
|
|
55
|
+
exports.JarSigner = JarSigner;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Config } from '../Config';
|
|
3
|
+
import { Result } from '../Result';
|
|
4
|
+
import { ValidatePathError } from '../errors/ValidatePathError';
|
|
5
|
+
/**
|
|
6
|
+
* Helps getting information relevant to the JDK installed, including
|
|
7
|
+
* the approprite environment needed to run Java commands on the JDK
|
|
8
|
+
*/
|
|
9
|
+
export declare class JdkHelper {
|
|
10
|
+
private process;
|
|
11
|
+
private config;
|
|
12
|
+
private joinPath;
|
|
13
|
+
private pathSeparator;
|
|
14
|
+
private pathEnvironmentKey;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new instance of JdkHelper.
|
|
17
|
+
*
|
|
18
|
+
* @param {NodeJS.Process} process information from the OS process
|
|
19
|
+
* @param {Config} config the bubblewrap general configuration
|
|
20
|
+
*/
|
|
21
|
+
constructor(process: NodeJS.Process, config: Config);
|
|
22
|
+
/**
|
|
23
|
+
* Runs the `java` command, passing args as parameters.
|
|
24
|
+
*/
|
|
25
|
+
runJava(args: string[]): Promise<{
|
|
26
|
+
stdout: string;
|
|
27
|
+
stderr: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns information from the JAVA_HOME, based on the config and platform.
|
|
31
|
+
*/
|
|
32
|
+
getJavaHome(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Returns information from the JAVA_HOME, based on the config and platform.
|
|
35
|
+
* @param {Config} config The bubblewrap general configuration
|
|
36
|
+
* @param {NodeJS.Process} process Information from the OS process
|
|
37
|
+
*/
|
|
38
|
+
static getJavaHome(jdkPath: string, process: NodeJS.Process): string;
|
|
39
|
+
private static getJoinPath;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if the given jdkPath is valid.
|
|
42
|
+
* @param {string} jdkPath the path to the jdk.
|
|
43
|
+
*/
|
|
44
|
+
static validatePath(jdkPath: string, currentProcess?: NodeJS.Process): Promise<Result<string, ValidatePathError>>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns information from the Java executable location, based on the config and platform.
|
|
47
|
+
* @returns {string} the value where the Java executables can be found
|
|
48
|
+
*/
|
|
49
|
+
getJavaBin(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a copy of process.env, customized with the correct JAVA_HOME and PATH.
|
|
52
|
+
* @returns {NodeJS.ProcessEnv} an env object configure to run JDK commands
|
|
53
|
+
*/
|
|
54
|
+
getEnv(): NodeJS.ProcessEnv;
|
|
55
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2019 Google Inc. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
'use strict';
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.JdkHelper = void 0;
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const path = require("path");
|
|
21
|
+
const util_1 = require("../util");
|
|
22
|
+
const Result_1 = require("../Result");
|
|
23
|
+
const ValidatePathError_1 = require("../errors/ValidatePathError");
|
|
24
|
+
/**
|
|
25
|
+
* Helps getting information relevant to the JDK installed, including
|
|
26
|
+
* the approprite environment needed to run Java commands on the JDK
|
|
27
|
+
*/
|
|
28
|
+
class JdkHelper {
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new instance of JdkHelper.
|
|
31
|
+
*
|
|
32
|
+
* @param {NodeJS.Process} process information from the OS process
|
|
33
|
+
* @param {Config} config the bubblewrap general configuration
|
|
34
|
+
*/
|
|
35
|
+
constructor(process, config) {
|
|
36
|
+
this.process = process;
|
|
37
|
+
this.config = config;
|
|
38
|
+
if (process.platform === 'win32') {
|
|
39
|
+
this.joinPath = path.win32.join;
|
|
40
|
+
this.pathSeparator = ';';
|
|
41
|
+
this.pathEnvironmentKey = 'Path';
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.joinPath = path.posix.join;
|
|
45
|
+
this.pathSeparator = ':';
|
|
46
|
+
this.pathEnvironmentKey = 'PATH';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Runs the `java` command, passing args as parameters.
|
|
51
|
+
*/
|
|
52
|
+
async runJava(args) {
|
|
53
|
+
const java = this.process.platform === 'win32' ? '/bin/java.exe' : '/bin/java';
|
|
54
|
+
const runJavaCmd = this.joinPath(this.getJavaHome(), java);
|
|
55
|
+
return await util_1.executeFile(runJavaCmd, args, this.getEnv());
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns information from the JAVA_HOME, based on the config and platform.
|
|
59
|
+
*/
|
|
60
|
+
getJavaHome() {
|
|
61
|
+
return JdkHelper.getJavaHome(this.config.jdkPath, this.process);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns information from the JAVA_HOME, based on the config and platform.
|
|
65
|
+
* @param {Config} config The bubblewrap general configuration
|
|
66
|
+
* @param {NodeJS.Process} process Information from the OS process
|
|
67
|
+
*/
|
|
68
|
+
static getJavaHome(jdkPath, process) {
|
|
69
|
+
const joinPath = (process.platform === 'win32') ? path.win32.join : path.posix.join;
|
|
70
|
+
if (process.platform === 'darwin') {
|
|
71
|
+
return joinPath(jdkPath, '/Contents/Home/');
|
|
72
|
+
}
|
|
73
|
+
else if (process.platform === 'linux' || process.platform === 'win32') {
|
|
74
|
+
return joinPath(jdkPath, '/');
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Unsupported Platform: ${process.platform}`);
|
|
77
|
+
}
|
|
78
|
+
static getJoinPath(process) {
|
|
79
|
+
switch (process.platform) {
|
|
80
|
+
case 'win32': return path.win32.join;
|
|
81
|
+
default: return path.posix.join;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks if the given jdkPath is valid.
|
|
86
|
+
* @param {string} jdkPath the path to the jdk.
|
|
87
|
+
*/
|
|
88
|
+
static async validatePath(jdkPath, currentProcess = process) {
|
|
89
|
+
const join = JdkHelper.getJoinPath(currentProcess);
|
|
90
|
+
if (!fs_1.existsSync(jdkPath)) {
|
|
91
|
+
return Result_1.Result.error(new ValidatePathError_1.ValidatePathError(`jdkPath "${jdkPath}" does not exist.`, 'PathIsNotCorrect'));
|
|
92
|
+
}
|
|
93
|
+
;
|
|
94
|
+
const javaHome = JdkHelper.getJavaHome(jdkPath, currentProcess);
|
|
95
|
+
try {
|
|
96
|
+
const releaseFilePath = join(javaHome, 'release');
|
|
97
|
+
const file = await fs_1.promises.readFile(releaseFilePath, 'utf-8');
|
|
98
|
+
if (file.indexOf('JAVA_VERSION="1.8') < 0) { // Checks if the jdk's version is 8 as needed
|
|
99
|
+
return Result_1.Result.error(new ValidatePathError_1.ValidatePathError('JDK version not supported. JDK version 1.8 is required.', 'PathIsNotSupported'));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
return Result_1.Result.error(new ValidatePathError_1.ValidatePathError(`Error reading the "release" file for the JDK at "${jdkPath}", with error: ${e} `, 'PathIsNotCorrect'));
|
|
104
|
+
}
|
|
105
|
+
return Result_1.Result.ok(jdkPath);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns information from the Java executable location, based on the config and platform.
|
|
109
|
+
* @returns {string} the value where the Java executables can be found
|
|
110
|
+
*/
|
|
111
|
+
getJavaBin() {
|
|
112
|
+
return this.joinPath(this.getJavaHome(), 'bin/');
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns a copy of process.env, customized with the correct JAVA_HOME and PATH.
|
|
116
|
+
* @returns {NodeJS.ProcessEnv} an env object configure to run JDK commands
|
|
117
|
+
*/
|
|
118
|
+
getEnv() {
|
|
119
|
+
const env = Object.assign({}, this.process.env);
|
|
120
|
+
env['JAVA_HOME'] = this.getJavaHome();
|
|
121
|
+
// Concatenates the Java binary path to the existing PATH environment variable.
|
|
122
|
+
env[this.pathEnvironmentKey] =
|
|
123
|
+
this.getJavaBin() + this.pathSeparator + env[this.pathEnvironmentKey];
|
|
124
|
+
return env;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.JdkHelper = JdkHelper;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { JdkHelper } from './JdkHelper';
|
|
2
|
+
import { Log } from '../Log';
|
|
3
|
+
export interface KeyInfo {
|
|
4
|
+
fingerprints: Map<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export interface KeyOptions {
|
|
7
|
+
path: string;
|
|
8
|
+
alias: string;
|
|
9
|
+
keypassword: string;
|
|
10
|
+
password: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateKeyOptions extends KeyOptions {
|
|
13
|
+
fullName: string;
|
|
14
|
+
organizationalUnit: string;
|
|
15
|
+
organization: string;
|
|
16
|
+
country: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A Wrapper of the Java keytool command-line tool
|
|
20
|
+
*/
|
|
21
|
+
export declare class KeyTool {
|
|
22
|
+
private jdkHelper;
|
|
23
|
+
private log;
|
|
24
|
+
constructor(jdkHelper: JdkHelper, log?: Log);
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new signing key.
|
|
27
|
+
*
|
|
28
|
+
* @param {CreateKeyOptions} keyOptions arguments to use to generate the key.
|
|
29
|
+
* @param {boolean} overwrite true if an existing key should be overwriten.
|
|
30
|
+
* @returns {Promise<void>}
|
|
31
|
+
*/
|
|
32
|
+
createSigningKey(keyOptions: CreateKeyOptions, overwrite?: boolean): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Runs `keytool --list` on the keystore / alias provided on the {@link KeyOptions}.
|
|
35
|
+
*
|
|
36
|
+
* @param {KeyOptions} keyOptions parameters for they key to be listed.
|
|
37
|
+
* @returns {Promise<string>} the raw output of the `keytool --list` command
|
|
38
|
+
*/
|
|
39
|
+
list(keyOptions: KeyOptions): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Runs `keytool --list` on the keystore / alias provided on the {@link KeyOptions}. Currently,
|
|
42
|
+
* only extracting fingerprints is implemented.
|
|
43
|
+
*
|
|
44
|
+
* @param {KeyOptions} keyOptions parameters for they key to be listed.
|
|
45
|
+
* @returns {Promise<KeyInfo>} the parsed output of the `keytool --list` command
|
|
46
|
+
*/
|
|
47
|
+
keyInfo(keyOptions: KeyOptions): Promise<KeyInfo>;
|
|
48
|
+
/**
|
|
49
|
+
* The commas in the dname field from key tool must be escaped, so that 'te,st' becomes 'te\,st'.
|
|
50
|
+
*/
|
|
51
|
+
private static escapeDName;
|
|
52
|
+
/**
|
|
53
|
+
* Parses the output of `keytool --list` and returns a structured {@link KeyInfo}. Currently,
|
|
54
|
+
* only extracts the fingerprints.
|
|
55
|
+
*/
|
|
56
|
+
static parseKeyInfo(rawKeyInfo: string): KeyInfo;
|
|
57
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2019 Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.KeyTool = void 0;
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const util_1 = require("../util");
|
|
21
|
+
const Log_1 = require("../Log");
|
|
22
|
+
/**
|
|
23
|
+
* A Wrapper of the Java keytool command-line tool
|
|
24
|
+
*/
|
|
25
|
+
class KeyTool {
|
|
26
|
+
constructor(jdkHelper, log = new Log_1.ConsoleLog('keytool')) {
|
|
27
|
+
this.jdkHelper = jdkHelper;
|
|
28
|
+
this.log = log;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new signing key.
|
|
32
|
+
*
|
|
33
|
+
* @param {CreateKeyOptions} keyOptions arguments to use to generate the key.
|
|
34
|
+
* @param {boolean} overwrite true if an existing key should be overwriten.
|
|
35
|
+
* @returns {Promise<void>}
|
|
36
|
+
*/
|
|
37
|
+
async createSigningKey(keyOptions, overwrite = false) {
|
|
38
|
+
this.log.debug('Generating Signature with keyOptions:', JSON.stringify(keyOptions));
|
|
39
|
+
// Checks if the key already exists and deletes it, if overriting is enabled.
|
|
40
|
+
if (fs_1.existsSync(keyOptions.path)) {
|
|
41
|
+
if (overwrite) {
|
|
42
|
+
await fs_1.promises.unlink(keyOptions.path);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Execute Java Keytool
|
|
49
|
+
const keytoolCmd = [
|
|
50
|
+
'keytool',
|
|
51
|
+
'-genkeypair',
|
|
52
|
+
`-dname "cn=${KeyTool.escapeDName(keyOptions.fullName)}, ` +
|
|
53
|
+
`ou=${KeyTool.escapeDName(keyOptions.organizationalUnit)}, ` +
|
|
54
|
+
`o=${KeyTool.escapeDName(keyOptions.organization)}, ` +
|
|
55
|
+
`c=${KeyTool.escapeDName(keyOptions.country)}"`,
|
|
56
|
+
`-alias \"${keyOptions.alias}\"`,
|
|
57
|
+
`-keypass \"${keyOptions.keypassword}\"`,
|
|
58
|
+
`-keystore \"${keyOptions.path}\"`,
|
|
59
|
+
`-storepass \"${keyOptions.password}\"`,
|
|
60
|
+
'-validity 20000',
|
|
61
|
+
'-keyalg RSA',
|
|
62
|
+
];
|
|
63
|
+
const env = this.jdkHelper.getEnv();
|
|
64
|
+
await util_1.execute(keytoolCmd, env);
|
|
65
|
+
this.log.info('Signing Key created successfully');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Runs `keytool --list` on the keystore / alias provided on the {@link KeyOptions}.
|
|
69
|
+
*
|
|
70
|
+
* @param {KeyOptions} keyOptions parameters for they key to be listed.
|
|
71
|
+
* @returns {Promise<string>} the raw output of the `keytool --list` command
|
|
72
|
+
*/
|
|
73
|
+
async list(keyOptions) {
|
|
74
|
+
if (!fs_1.existsSync(keyOptions.path)) {
|
|
75
|
+
throw new Error(`Couldn't find signing key at "${keyOptions.path}"`);
|
|
76
|
+
}
|
|
77
|
+
const keyListCmd = [
|
|
78
|
+
'keytool',
|
|
79
|
+
// Forces the language to 'en' in order to get the expected formatting.
|
|
80
|
+
// The JVM seems to ignore the LANG and LC_ALL variables, so we set the value
|
|
81
|
+
// when invoking the command. See https://github.com/GoogleChromeLabs/bubblewrap/issues/446
|
|
82
|
+
// for more.
|
|
83
|
+
'-J-Duser.language=en',
|
|
84
|
+
'-list',
|
|
85
|
+
'-v',
|
|
86
|
+
`-keystore \"${keyOptions.path}\"`,
|
|
87
|
+
`-alias \"${keyOptions.alias}\"`,
|
|
88
|
+
`-storepass \"${keyOptions.password}\"`,
|
|
89
|
+
`-keypass \"${keyOptions.keypassword}\"`,
|
|
90
|
+
];
|
|
91
|
+
const env = this.jdkHelper.getEnv();
|
|
92
|
+
const result = await util_1.execute(keyListCmd, env);
|
|
93
|
+
return result.stdout;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Runs `keytool --list` on the keystore / alias provided on the {@link KeyOptions}. Currently,
|
|
97
|
+
* only extracting fingerprints is implemented.
|
|
98
|
+
*
|
|
99
|
+
* @param {KeyOptions} keyOptions parameters for they key to be listed.
|
|
100
|
+
* @returns {Promise<KeyInfo>} the parsed output of the `keytool --list` command
|
|
101
|
+
*/
|
|
102
|
+
async keyInfo(keyOptions) {
|
|
103
|
+
const rawKeyInfo = await this.list(keyOptions);
|
|
104
|
+
return KeyTool.parseKeyInfo(rawKeyInfo);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The commas in the dname field from key tool must be escaped, so that 'te,st' becomes 'te\,st'.
|
|
108
|
+
*/
|
|
109
|
+
static escapeDName(input) {
|
|
110
|
+
return input.replace(/,/g, '\\,');
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parses the output of `keytool --list` and returns a structured {@link KeyInfo}. Currently,
|
|
114
|
+
* only extracts the fingerprints.
|
|
115
|
+
*/
|
|
116
|
+
static parseKeyInfo(rawKeyInfo) {
|
|
117
|
+
const lines = rawKeyInfo.split('\n');
|
|
118
|
+
const fingerprints = new Map();
|
|
119
|
+
const fingerprintTags = ['SHA1', 'SHA256'];
|
|
120
|
+
lines.forEach((line) => {
|
|
121
|
+
line = line.trim();
|
|
122
|
+
fingerprintTags.forEach((tag) => {
|
|
123
|
+
if (line.startsWith(tag)) {
|
|
124
|
+
// a fingerprint line has the format <tag>: <value>. So, we account for the extra colon
|
|
125
|
+
// when substringing and then trim to remove whitespaces.
|
|
126
|
+
const value = line.substring(tag.length + 1, line.length).trim();
|
|
127
|
+
fingerprints.set(tag, value);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
fingerprints: fingerprints,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.KeyTool = KeyTool;
|