use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommand method getStampSigningConfiguration.
private static SigningConfiguration getStampSigningConfiguration(ParsedFlags flags, PrintStream out, SystemEnvironmentProvider systemEnvironmentProvider) {
// Signing-related flags.
Optional<Path> signingKeystorePath = KEYSTORE_FLAG.getValue(flags);
Optional<Password> signingKeystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
Optional<String> signingKeyAlias = KEY_ALIAS_FLAG.getValue(flags);
Optional<Password> signingKeyPassword = KEY_PASSWORD_FLAG.getValue(flags);
// Stamp-related flags.
Optional<Path> stampKeystorePath = STAMP_KEYSTORE_FLAG.getValue(flags);
Optional<Password> stampKeystorePassword = STAMP_KEYSTORE_PASSWORD_FLAG.getValue(flags);
Optional<String> stampKeyAlias = STAMP_KEY_ALIAS_FLAG.getValue(flags);
Optional<Password> stampKeyPassword = STAMP_KEY_PASSWORD_FLAG.getValue(flags);
Path keystorePath = null;
Optional<Password> keystorePassword = Optional.empty();
if (stampKeystorePath.isPresent()) {
keystorePath = stampKeystorePath.get();
keystorePassword = stampKeystorePassword;
} else if (signingKeystorePath.isPresent()) {
keystorePath = signingKeystorePath.get();
keystorePassword = signingKeystorePassword;
}
if (keystorePath == null) {
// Try to use debug keystore if present.
Optional<SigningConfiguration> debugConfig = DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider);
if (debugConfig.isPresent()) {
out.printf("INFO: The stamp will be signed with the debug keystore found at '%s'.%n", DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.getUnchecked(systemEnvironmentProvider).get());
return debugConfig.get();
} else {
throw InvalidCommandException.builder().withInternalMessage("No key was found to sign the stamp.").build();
}
}
String keyAlias = null;
Optional<Password> keyPassword = Optional.empty();
if (stampKeyAlias.isPresent()) {
keyAlias = stampKeyAlias.get();
keyPassword = stampKeyPassword;
} else if (signingKeyAlias.isPresent()) {
keyAlias = signingKeyAlias.get();
keyPassword = signingKeyPassword;
}
if (keyAlias == null) {
throw InvalidCommandException.builder().withInternalMessage("Flag --stamp-key-alias or --ks-key-alias are required when --stamp-ks or --ks are" + " set.").build();
}
return SigningConfiguration.extractFromKeystore(keystorePath, keyAlias, keystorePassword, keyPassword);
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildSdkApksCommand method populateSigningConfigurationFromFlags.
private static void populateSigningConfigurationFromFlags(Builder buildSdkApksCommand, ParsedFlags flags, PrintStream out, SystemEnvironmentProvider provider) {
// Signing-related arguments.
Optional<Path> keystorePath = KEYSTORE_FLAG.getValue(flags);
Optional<String> keyAlias = KEY_ALIAS_FLAG.getValue(flags);
Optional<Password> keystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
Optional<Password> keyPassword = KEY_PASSWORD_FLAG.getValue(flags);
if (keystorePath.isPresent() && keyAlias.isPresent()) {
SignerConfig signerConfig = SignerConfig.extractFromKeystore(keystorePath.get(), keyAlias.get(), keystorePassword, keyPassword);
SigningConfiguration.Builder builder = SigningConfiguration.builder().setSignerConfig(signerConfig);
buildSdkApksCommand.setSigningConfiguration(builder.build());
} else if (keystorePath.isPresent() && !keyAlias.isPresent()) {
throw InvalidCommandException.builder().withInternalMessage("Flag --ks-key-alias is required when --ks is set.").build();
} else if (!keystorePath.isPresent() && keyAlias.isPresent()) {
throw InvalidCommandException.builder().withInternalMessage("Flag --ks is required when --ks-key-alias is set.").build();
} else {
// Try to use debug keystore if present.
Optional<SigningConfiguration> debugConfig = DebugKeystoreUtils.getDebugSigningConfiguration(provider);
if (debugConfig.isPresent()) {
out.printf("INFO: The APKs will be signed with the debug keystore found at '%s'.%n", DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.getUnchecked(provider).get());
buildSdkApksCommand.setSigningConfiguration(debugConfig.get());
} else {
out.println("WARNING: The APKs won't be signed and thus not installable unless you also pass a " + "keystore via the flag --ks. See the command help for more information.");
}
}
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method populateLineage_apkFile.
@Test
public void populateLineage_apkFile() throws Exception {
SigningCertificateLineage.SignerConfig signerConfig = new SigningCertificateLineage.SignerConfig.Builder(privateKey, certificate).build();
SigningCertificateLineage.SignerConfig oldestSignerConfig = new SigningCertificateLineage.SignerConfig.Builder(oldestSignerPrivateKey, oldestSignerCertificate).build();
SigningCertificateLineage lineage = new SigningCertificateLineage.Builder(oldestSignerConfig, signerConfig).build();
com.android.tools.build.bundletool.model.SignerConfig oldestSigner = com.android.tools.build.bundletool.model.SignerConfig.builder().setPrivateKey(oldestSignerPrivateKey).setCertificates(ImmutableList.of(oldestSignerCertificate)).build();
TestComponent.useTestModule(this, TestModule.builder().withSigningConfig(SigningConfiguration.builder().setSignerConfig(privateKey, certificate).setSigningCertificateLineage(lineage).setOldestSigner(oldestSigner).build()).build());
File lineageFile = createMinimalistSignedApkFile().toFile();
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--lineage=" + lineageFile, "--oldest-signer=" + oldestSignerPropertiesPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
assertThat(signingConfiguration.getSigningCertificateLineage().get().getCertificatesInLineage()).containsExactly(oldestSignerCertificate, certificate);
assertThat(signingConfiguration.getOldestSigner().get().getPrivateKey()).isEqualTo(oldestSignerConfig.getPrivateKey());
assertThat(signingConfiguration.getOldestSigner().get().getCertificates()).containsExactly(oldestSignerConfig.getCertificate());
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeystore.
@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeystore() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true, "--stamp-ks=" + stampKeystorePath, "--stamp-ks-pass=pass:" + STAMP_KEYSTORE_PASSWORD), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
SigningConfiguration stampSigningConfiguration = SigningConfiguration.builder().setSignerConfig(stampPrivateKey, stampCertificate).build();
BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(stampSigningConfiguration).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
assertThat(commandViaBuilder.build().getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
assertThat(commandViaBuilder.build().getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_source.
@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_source() throws Exception {
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
"--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true, "--stamp-source=" + STAMP_SOURCE), fakeAdbServer);
SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
BuildApksCommand commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(signingConfiguration).setSource(STAMP_SOURCE).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get()).build();
assertThat(commandViaBuilder.getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
assertThat(commandViaBuilder.getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
Aggregations