Skip to content

fix: add more signing validations #5079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages } from "../constants";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
import { ValidatePlatformCommandBase } from "./command-base";
import { hasValidAndroidSigning } from "../common/helpers";

export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
constructor($options: IOptions,
Expand Down Expand Up @@ -123,8 +124,12 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
let canExecute = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (canExecute) {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
if ((this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
if (this.$options.release) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
} else {
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
}
}

canExecute = await super.validateArgs(args, platform);
Expand Down
15 changes: 12 additions & 3 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { cache } from "../common/decorators";
import { ValidatePlatformCommandBase } from "./command-base";
import { hasValidAndroidSigning } from "../common/helpers";
import { ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";

export class DebugPlatformCommand extends ValidatePlatformCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];
Expand Down Expand Up @@ -155,7 +157,8 @@ export class DebugAndroidCommand implements ICommand {
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $injector: IInjector,
private $projectData: IProjectData,
private $markingModeService: IMarkingModeService) {
private $markingModeService: IMarkingModeService,
private $options: IOptions) {
this.$projectData.initializeProjectData();
}

Expand All @@ -164,8 +167,14 @@ export class DebugAndroidCommand implements ICommand {
return this.debugPlatformCommand.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
const result = await this.debugPlatformCommand.canExecute(args);
return result;
const canExecuteBase = await this.debugPlatformCommand.canExecute(args);
if (canExecuteBase) {
if (this.$options.aab && !hasValidAndroidSigning(this.$options)) {
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
}
}

return canExecuteBase;
}

public platform = this.$devicePlatformsConstants.Android;
Expand Down
11 changes: 8 additions & 3 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
import { ValidatePlatformCommandBase } from "./command-base";
import { DeployCommandHelper } from "../helpers/deploy-command-helper";
import { hasValidAndroidSigning } from "../common/helpers";

export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];
Expand Down Expand Up @@ -47,8 +48,12 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
return false;
}

if (this.$mobileHelper.isAndroidPlatform(platform) && this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
if (this.$mobileHelper.isAndroidPlatform(platform) && (this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
if (this.$options.release) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
} else {
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
}
}

const result = await super.canExecuteCommandBase(platform, { validateOptions: true });
Expand Down
11 changes: 8 additions & 3 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
import { cache } from "../common/decorators";
import { hasValidAndroidSigning } from "../common/helpers";

export class RunCommandBase implements ICommand {
private liveSyncCommandHelperAdditionalOptions: ILiveSyncCommandHelperAdditionalOptions = <ILiveSyncCommandHelperAdditionalOptions>{};
Expand Down Expand Up @@ -126,8 +127,12 @@ export class RunAndroidCommand implements ICommand {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.Android} can not be built on this OS`);
}

if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
if ((this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
if (this.$options.release) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
} else {
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
}
}

return this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$devicePlatformsConstants.Android.toLowerCase());
Expand Down
18 changes: 18 additions & 0 deletions lib/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { hasValidAndroidSigning } from "../common/helpers";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";

abstract class TestCommandBase {
public allowedParameters: ICommandParameter[] = [];
public dashedOptions = {
Expand Down Expand Up @@ -111,6 +114,21 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
await super.execute(args);
}

async canExecute(args: string[]): Promise<boolean> {
const canExecuteBase = await super.canExecute(args);
if (canExecuteBase) {
if ((this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
if (this.$options.release) {
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
} else {
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
}
}
}

return canExecuteBase;
}
}

class TestIosCommand extends TestCommandBase implements ICommand {
Expand Down
15 changes: 15 additions & 0 deletions lib/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,19 @@ export function annotate(fn: any) {
return $inject;
}

/**
* Returns true if all Android signing options are provided, false otherwise.
* @param {IAndroidSigningData} signingData The signing data to be validated.
* @return {void}
*/
export function hasValidAndroidSigning(signingData: Partial<IAndroidSigningData>): boolean {
const isValid = signingData &&
signingData.keyStorePath &&
signingData.keyStorePassword &&
signingData.keyStoreAlias &&
signingData.keyStoreAliasPassword;

return !!isValid;
}

//--- end part copied from AngularJS
4 changes: 3 additions & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export const DEBUGGER_DETACHED_EVENT_NAME = "debuggerDetached";
export const VERSION_STRING = "version";
export const INSPECTOR_CACHE_DIRNAME = "ios-inspector";
export const POST_INSTALL_COMMAND_NAME = "post-install-cli";
export const ANDROID_RELEASE_BUILD_ERROR_MESSAGE = "When producing a release build, you need to specify all --key-store-* options.";
const ANDROID_SIGNING_REQUIRED_MESSAGE = "you need to specify all --key-store-* options.";
export const ANDROID_RELEASE_BUILD_ERROR_MESSAGE = `When producing a release build, ${ANDROID_SIGNING_REQUIRED_MESSAGE}`;
export const ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE = `When producing Android App Bundle, ${ANDROID_SIGNING_REQUIRED_MESSAGE}`;
export const CACACHE_DIRECTORY_NAME = "_cacache";

export const FILES_CHANGE_EVENT_NAME = "filesChangeEvent";
Expand Down
5 changes: 3 additions & 2 deletions lib/services/android/android-bundle-tool-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve, join } from "path";
import { hasValidAndroidSigning } from "../../common/helpers";

export class AndroidBundleToolService implements IAndroidBundleToolService {
private javaPath: string;
Expand All @@ -12,8 +13,8 @@ export class AndroidBundleToolService implements IAndroidBundleToolService {
}

public async buildApks(options: IBuildApksOptions): Promise<void> {
if (!options.signingData) {
this.$errors.fail(`Unable to build "apks" without a signing information.`);
if (!hasValidAndroidSigning(options.signingData)) {
this.$errors.fail(`Unable to build "apks" without a full signing information.`);
}

const aabToolResult = await this.execBundleTool([
Expand Down