Skip to content

Commit 02fb2ff

Browse files
authored
Try to use JDK console to prompt for pass (#270)
Avoids echoing password and issues with carriage returns across platforms. Fixes jruby/jruby#5588 when console is available.
1 parent a7994b3 commit 02fb2ff

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/org/jruby/ext/openssl/PKey.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
package org.jruby.ext.openssl;
2929

3030
import java.io.ByteArrayInputStream;
31+
import java.io.Console;
3132
import java.io.IOException;
3233
import java.io.InputStreamReader;
3334
import java.io.StringReader;
@@ -406,6 +407,12 @@ protected static char[] passwordPrompt(final ThreadContext context) {
406407
}
407408

408409
protected static char[] passwordPrompt(final ThreadContext context, final String prompt) {
410+
Console console = System.console();
411+
if (console != null) {
412+
return console.readPassword(prompt);
413+
}
414+
415+
// fall back on simple IO, but may be broken (jruby/jruby#5588)
409416
final RubyModule Kernel = context.runtime.getKernel();
410417
// NOTE: just a fast and simple print && gets - hopefully better than nothing!
411418
Kernel.callMethod("print", context.runtime.newString(prompt));

0 commit comments

Comments
 (0)