8339347: keytool -importpass insists prompting the user even if there is no terminal

Reviewed-by: weijun
This commit is contained in:
Hai-May Chao 2024-09-05 20:17:52 +00:00
parent 9e1af8cc7c
commit 8fb8cd85b7
2 changed files with 51 additions and 2 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1789,7 +1789,8 @@ public final class Main {
*/
private char[] promptForCredential() throws Exception {
// Handle password supplied via stdin
if (System.console() == null) {
Console console = System.console();
if (console == null || !console.isTerminal()) {
char[] importPass = Password.readPassword(System.in);
passwords.add(importPass);
return importPass;