From a0d836befc62b0c5ada6fa93886114ee7d633a5f Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Fri, 25 Nov 2011 01:12:58 +0000 Subject: [PATCH] add PasswordFile parameter as requested in tracker #3441859 git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4817 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/com/tigervnc/rfb/VncAuth.java | 2 +- java/com/tigervnc/vncviewer/CConn.java | 25 ++++++++++++++++++++++ java/com/tigervnc/vncviewer/VncViewer.java | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/java/com/tigervnc/rfb/VncAuth.java b/java/com/tigervnc/rfb/VncAuth.java index cce8d81c..dd84f6af 100644 --- a/java/com/tigervnc/rfb/VncAuth.java +++ b/java/com/tigervnc/rfb/VncAuth.java @@ -49,7 +49,7 @@ public class VncAuth { des.encrypt(obfuscated,0,obfuscated,0); } - String unobfuscatePasswd(byte[] obfuscated) { + public static String unobfuscatePasswd(byte[] obfuscated) { DesCipher des = new DesCipher(obfuscationKey); des.decrypt(obfuscated,0,obfuscated,0); int len; diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java index f49e3342..136ad7c5 100644 --- a/java/com/tigervnc/vncviewer/CConn.java +++ b/java/com/tigervnc/vncviewer/CConn.java @@ -39,6 +39,8 @@ import java.awt.Event; import java.io.IOException; import java.io.InputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.util.jar.Attributes; import java.util.jar.Manifest; import javax.swing.*; @@ -242,7 +244,30 @@ public class CConn extends CConnection public final boolean getUserPasswd(StringBuffer user, StringBuffer passwd) { String title = ("VNC Authentication [" +csecurity.description() + "]"); + String passwordFileStr = viewer.passwordFile.getValue(); PasswdDialog dlg; + + if (user == null && passwordFileStr != "") { + InputStream fp = null; + try { + fp = new FileInputStream(passwordFileStr); + } catch(FileNotFoundException e) { + throw new Exception("Opening password file failed"); + } + byte[] obfPwd = new byte[256]; + try { + fp.read(obfPwd); + fp.close(); + } catch(IOException e) { + throw new Exception("Failed to read VncPasswd file"); + } + String PlainPasswd = + VncAuth.unobfuscatePasswd(obfPwd); + passwd.append(PlainPasswd); + passwd.setLength(PlainPasswd.length()); + return true; + } + if (user == null) { dlg = new PasswdDialog(title, (user == null), (passwd == null)); } else { diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java index 604069c4..97b9427c 100644 --- a/java/com/tigervnc/vncviewer/VncViewer.java +++ b/java/com/tigervnc/vncviewer/VncViewer.java @@ -253,6 +253,11 @@ public class VncViewer extends java.applet.Applet implements Runnable = new BoolParameter("SendLocalUsername", "Send the local username for SecurityTypes "+ "such as Plain rather than prompting", true); + StringParameter passwordFile + = new StringParameter("PasswordFile", + "Password file for VNC authentication", ""); + AliasParameter passwd + = new AliasParameter("passwd", "Alias for PasswordFile", passwordFile); BoolParameter autoSelect = new BoolParameter("AutoSelect", "Auto select pixel format and encoding", true); -- 2.39.5