use of com.android.tools.build.bundletool.model.Password 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.Password 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.Password in project bundletool by google.
the class FlagTest method passwordFlag_inFile_withLineFeedAtTheEnd.
@Test
public void passwordFlag_inFile_withLineFeedAtTheEnd() throws Exception {
Path passwordFile = tempFolder.getRoot().toPath().resolve("myPassword.txt");
Files.write(passwordFile, new String("hello\n").getBytes(UTF_8));
Flag<Password> flag = Flag.password("testFlag");
ParsedFlags parsedFlags = new FlagParser().parse("--testFlag=file:" + passwordFile);
String password = new String(flag.getRequiredValue(parsedFlags).getValue().getPassword());
assertThat(password).isEqualTo("hello");
}
use of com.android.tools.build.bundletool.model.Password in project bundletool by google.
the class FlagTest method passwordFlag_inFile.
@Test
public void passwordFlag_inFile() throws Exception {
Path passwordFile = tempFolder.getRoot().toPath().resolve("myPassword.txt");
Files.write(passwordFile, ImmutableList.of("hello\n"));
Flag<Password> flag = Flag.password("testFlag");
ParsedFlags parsedFlags = new FlagParser().parse("--testFlag=file:" + passwordFile);
String password = new String(flag.getRequiredValue(parsedFlags).getValue().getPassword());
assertThat(password).isEqualTo("hello");
}
use of com.android.tools.build.bundletool.model.Password in project bundletool by google.
the class FlagTest method passwordFlag_inFile_withCarriageReturnAtTheEnd.
@Test
public void passwordFlag_inFile_withCarriageReturnAtTheEnd() throws Exception {
Path passwordFile = tempFolder.getRoot().toPath().resolve("myPassword.txt");
Files.write(passwordFile, new String("hello\r").getBytes(UTF_8));
Flag<Password> flag = Flag.password("testFlag");
ParsedFlags parsedFlags = new FlagParser().parse("--testFlag=file:" + passwordFile);
String password = new String(flag.getRequiredValue(parsedFlags).getValue().getPassword());
assertThat(password).isEqualTo("hello");
}
Aggregations