From c8003213e56d3156f9d51e2c99fda9176b450011 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Wed, 5 Oct 2011 03:45:43 +0000 Subject: [PATCH] More fixes for bug #3418256. Copied jarsigning routine from TurboVNC in order to produce a signed applet so the system clipboard can be accessed from when used in applet mode. These changes will need some testing to make sure that there aren't any corner-cases where something breaks. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4695 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/src/com/tigervnc/vncviewer/CConn.java | 2 +- .../tigervnc/vncviewer/ClipboardDialog.java | 22 ++++--- .../com/tigervnc/vncviewer/DesktopWindow.java | 32 +++++----- java/src/com/tigervnc/vncviewer/Makefile | 8 +++ .../com/tigervnc/vncviewer/OptionsDialog.java | 29 +++------ .../com/tigervnc/vncviewer/ServerDialog.java | 34 +++++----- .../src/com/tigervnc/vncviewer/UserPrefs.java | 62 ++++++++++++++----- java/src/com/tigervnc/vncviewer/index.vnc | 1 - 8 files changed, 114 insertions(+), 76 deletions(-) diff --git a/java/src/com/tigervnc/vncviewer/CConn.java b/java/src/com/tigervnc/vncviewer/CConn.java index 87847501..ee969477 100644 --- a/java/src/com/tigervnc/vncviewer/CConn.java +++ b/java/src/com/tigervnc/vncviewer/CConn.java @@ -154,7 +154,7 @@ public class CConn extends CConnection encodingChange = false; sameMachine = false; fullScreen = viewer.fullScreen.getValue(); menuKey = Keysyms.F8; - options = new OptionsDialog(this, this); + options = new OptionsDialog(this); options.initDialog(); clipboardDialog = new ClipboardDialog(this); firstUpdate = true; pendingUpdate = false; diff --git a/java/src/com/tigervnc/vncviewer/ClipboardDialog.java b/java/src/com/tigervnc/vncviewer/ClipboardDialog.java index ef479edd..dca85f25 100644 --- a/java/src/com/tigervnc/vncviewer/ClipboardDialog.java +++ b/java/src/com/tigervnc/vncviewer/ClipboardDialog.java @@ -62,16 +62,20 @@ class ClipboardDialog extends Dialog implements ActionListener { public void serverCutText(String str, int len) { setContents(str); - Clipboard cb = null; - if (!cc.viewer.applet) - cb = Toolkit.getDefaultToolkit().getSystemClipboard(); - if (cb != null) { - StringSelection ss = new StringSelection(str); - try { - cb.setContents(ss, ss); - } catch(Exception e) { - vlog.debug(e.toString()); + SecurityManager sm = System.getSecurityManager(); + try { + if (sm != null) sm.checkSystemClipboardAccess(); + Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); + if (cb != null) { + StringSelection ss = new StringSelection(str); + try { + cb.setContents(ss, ss); + } catch(Exception e) { + vlog.debug(e.toString()); + } } + } catch(SecurityException e) { + System.err.println("Cannot access the system clipboard"); } } diff --git a/java/src/com/tigervnc/vncviewer/DesktopWindow.java b/java/src/com/tigervnc/vncviewer/DesktopWindow.java index d6704e01..1ecc0e3f 100644 --- a/java/src/com/tigervnc/vncviewer/DesktopWindow.java +++ b/java/src/com/tigervnc/vncviewer/DesktopWindow.java @@ -364,23 +364,27 @@ class DesktopWindow extends JPanel implements String oldContents = ""; synchronized public void checkClipboard() { - Clipboard cb = null; - if (!cc.viewer.applet) - cb = Toolkit.getDefaultToolkit().getSystemClipboard(); - if (cb != null && cc.viewer.sendClipboard.getValue()) { - Transferable t = cb.getContents(null); - if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { - try { - String newContents = (String)t.getTransferData(DataFlavor.stringFlavor); - if (newContents != null && !newContents.equals(oldContents)) { - cc.writeClientCutText(newContents, newContents.length()); - oldContents = newContents; - cc.clipboardDialog.setContents(newContents); + SecurityManager sm = System.getSecurityManager(); + try { + if (sm != null) sm.checkSystemClipboardAccess(); + Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); + if (cb != null && cc.viewer.sendClipboard.getValue()) { + Transferable t = cb.getContents(null); + if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { + try { + String newContents = (String)t.getTransferData(DataFlavor.stringFlavor); + if (newContents != null && !newContents.equals(oldContents)) { + cc.writeClientCutText(newContents, newContents.length()); + oldContents = newContents; + cc.clipboardDialog.setContents(newContents); + } + } catch (java.lang.Exception e) { + System.out.println("Exception getting clipboard data: " + e.getMessage()); } - } catch (java.lang.Exception e) { - System.out.println("Exception getting clipboard data: " + e.getMessage()); } } + } catch(SecurityException e) { + System.err.println("Cannot access the system clipboard"); } } diff --git a/java/src/com/tigervnc/vncviewer/Makefile b/java/src/com/tigervnc/vncviewer/Makefile index 614057b5..51d4917d 100644 --- a/java/src/com/tigervnc/vncviewer/Makefile +++ b/java/src/com/tigervnc/vncviewer/Makefile @@ -40,6 +40,14 @@ $(ARCHIVE): $(CLASSES) $(MANIFEST) $(TIMESTAMP) com/jcraft/jzlib/*.class \ com/tigervnc/vncviewer/tigervnc.png \ com/tigervnc/vncviewer/tigervnc.ico + rm -f tigervnc.keystore + keytool -genkey -alias TigerVNC -keystore tigervnc.keystore -keyalg RSA \ + -storepass tigervnc -keypass tigervnc -validity 7300 \ + -dname "CN=TigerVNC, OU=Software Development, O=The TigerVNC Project, L=Austin, S=Texas, C=US" + jarsigner -keystore tigervnc.keystore -storepass tigervnc -keypass tigervnc \ + $(ARCHIVE) TigerVNC + rm -f tigervnc.keystore + $(TIMESTAMP): $(shell cat $(MANIFEST) > $(TIMESTAMP)) diff --git a/java/src/com/tigervnc/vncviewer/OptionsDialog.java b/java/src/com/tigervnc/vncviewer/OptionsDialog.java index 265c7d2e..4913fade 100644 --- a/java/src/com/tigervnc/vncviewer/OptionsDialog.java +++ b/java/src/com/tigervnc/vncviewer/OptionsDialog.java @@ -57,17 +57,13 @@ class OptionsDialog extends Dialog implements boolean autoScale = false; boolean fixedRatioScale = false; - boolean applet = false; - public OptionsDialog(OptionsDialogCallback cb_, CConn cc_) { + public OptionsDialog(OptionsDialogCallback cb_) { super(false); cb = cb_; - CConn cc = cc_; - applet = cc.viewer.applet; setResizable(false); setTitle("VNC Viewer Options"); - if (!applet) - defaults = new UserPrefs("vncviewer"); + defaults = new UserPrefs("vncviewer"); getContentPane().setLayout( new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)); @@ -196,7 +192,7 @@ class OptionsDialog extends Dialog implements addGBComponent(cfSaveAsButton,configPanel, 0, 2, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8)); cfReloadButton.setEnabled(false); cfSaveButton.setEnabled(false); - cfSaveAsButton.setEnabled(!applet); + //cfSaveAsButton.setEnabled(!applet); JPanel defaultsPanel = new JPanel(new GridBagLayout()); defaultsPanel.setBorder(BorderFactory.createTitledBorder("Defaults")); @@ -209,8 +205,8 @@ class OptionsDialog extends Dialog implements addGBComponent(configPanel,DefaultsPanel, 0, 0, 1, GridBagConstraints.REMAINDER, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.PAGE_START, new Insets(4,4,4,4)); addGBComponent(defaultsPanel,DefaultsPanel, 1, 0, 1, GridBagConstraints.REMAINDER, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.PAGE_START, new Insets(4,4,4,4)); - defReloadButton.setEnabled(!applet); - defSaveButton.setEnabled(!applet); + //defReloadButton.setEnabled(!applet); + //defSaveButton.setEnabled(!applet); // security tab SecPanel=new JPanel(new GridBagLayout()); @@ -349,8 +345,7 @@ class OptionsDialog extends Dialog implements endDialog(); } else if (s instanceof JButton && (JButton)s == defSaveButton) { try { - if (!applet) - defaults.Save(); + defaults.Save(); } catch (java.lang.Exception x) { } } else if (s instanceof JButton && (JButton)s == ca) { JFileChooser fc = new JFileChooser(); @@ -378,18 +373,15 @@ class OptionsDialog extends Dialog implements mediumColour.setEnabled(!autoSelect.isSelected()); lowColour.setEnabled(!autoSelect.isSelected()); veryLowColour.setEnabled(!autoSelect.isSelected()); - if (!applet) - defaults.setPref("autoSelect",(autoSelect.isSelected()) ? "on" : "off"); + defaults.setPref("autoSelect",(autoSelect.isSelected()) ? "on" : "off"); } if (s instanceof JCheckBox && (JCheckBox)s == customCompressLevel) { compressLevel.setEnabled(customCompressLevel.isSelected()); - if (!applet) - defaults.setPref("customCompressLevel",(customCompressLevel.isSelected()) ? "on" : "off"); + defaults.setPref("customCompressLevel",(customCompressLevel.isSelected()) ? "on" : "off"); } if (s instanceof JCheckBox && (JCheckBox)s == noJpeg) { qualityLevel.setEnabled(noJpeg.isSelected()); - if (!applet) - defaults.setPref("noJpeg",(noJpeg.isSelected()) ? "on" : "off"); + defaults.setPref("noJpeg",(noJpeg.isSelected()) ? "on" : "off"); } if (s instanceof JComboBox && (JComboBox)s == scalingFactor) { autoScale = fixedRatioScale = false; @@ -400,8 +392,7 @@ class OptionsDialog extends Dialog implements } } if (s instanceof JCheckBox && (JCheckBox)s == sendLocalUsername) { - if (!applet) - defaults.setPref("sendLocalUsername",(sendLocalUsername.isSelected()) ? "on" : "off"); + defaults.setPref("sendLocalUsername",(sendLocalUsername.isSelected()) ? "on" : "off"); } if (s instanceof JCheckBox && (JCheckBox)s == secVeNCrypt) { encNone.setEnabled(secVeNCrypt.isSelected()); diff --git a/java/src/com/tigervnc/vncviewer/ServerDialog.java b/java/src/com/tigervnc/vncviewer/ServerDialog.java index 1ba6dc21..00a7e183 100644 --- a/java/src/com/tigervnc/vncviewer/ServerDialog.java +++ b/java/src/com/tigervnc/vncviewer/ServerDialog.java @@ -137,24 +137,28 @@ class ServerDialog extends Dialog implements } public void endDialog() { - if (ok && !cc.viewer.applet) { - options.defaults.setPref("encryption",(encryption.getSelectedIndex()==1) ? "off" : "on"); - if (!server.getSelectedItem().toString().equals("")) { - String t = (options.defaults.getString("server")==null) ? "" : options.defaults.getString("server"); - StringTokenizer st = new StringTokenizer(t, ","); - StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem()); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - if (!s.equals((String)server.getSelectedItem()) && !s.equals("")) { - sb.append(','); - sb.append(s); + if (ok) { + try { + options.defaults.setPref("encryption",(encryption.getSelectedIndex()==1) ? "off" : "on"); + if (!server.getSelectedItem().toString().equals("")) { + String t = (options.defaults.getString("server")==null) ? "" : options.defaults.getString("server"); + StringTokenizer st = new StringTokenizer(t, ","); + StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem()); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + if (!s.equals((String)server.getSelectedItem()) && !s.equals("")) { + sb.append(','); + sb.append(s); + } } + options.defaults.setPref("server", sb.toString()); } - options.defaults.setPref("server", sb.toString()); - } - try { options.defaults.Save(); - } catch (java.lang.Exception x) { } + } catch (java.io.IOException e) { + System.out.println(e.toString()); + } catch(java.security.AccessControlException e) { + System.out.println(e.toString()); + } } done = true; if (modal) { diff --git a/java/src/com/tigervnc/vncviewer/UserPrefs.java b/java/src/com/tigervnc/vncviewer/UserPrefs.java index 51b8b904..b3702210 100644 --- a/java/src/com/tigervnc/vncviewer/UserPrefs.java +++ b/java/src/com/tigervnc/vncviewer/UserPrefs.java @@ -58,13 +58,19 @@ public class UserPrefs extends Properties { public UserPrefs(String appName_) { appName = appName_; - systemprops=System.getProperties(); + try { + systemprops=System.getProperties(); + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access system properties"); + } // This is guaranteed as always being some valid directory, // according to spec. prefFile= getHomeDir()+getFileSeperator()+ "."+appName; try { load(new java.io.FileInputStream(prefFile)); + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access system properties"); } catch (Exception err) { if(err instanceof java.io.FileNotFoundException) { try { @@ -109,33 +115,55 @@ public class UserPrefs extends Properties { */ final public static String getHomeDir() { String homeDir = null; - String os = System.getProperty("os.name"); - try { - if (os.startsWith("Windows")) { - // JRE prior to 1.5 cannot reliably determine USERPROFILE - // return user.home and hope it's right... - if (Integer.parseInt(System.getProperty("java.version").split("\\.")[1]) < 5) { - homeDir = System.getProperty("user.home"); + try { + String os = System.getProperty("os.name"); + try { + if (os.startsWith("Windows")) { + // JRE prior to 1.5 cannot reliably determine USERPROFILE + // return user.home and hope it's right... + if (Integer.parseInt(System.getProperty("java.version").split("\\.")[1]) < 5) { + try { + homeDir = System.getProperty("user.home"); + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access user.home system property"); + } + } else { + homeDir = System.getenv("USERPROFILE"); + } } else { - homeDir = System.getenv("USERPROFILE"); + try { + homeDir = FileSystemView.getFileSystemView(). + getDefaultDirectory().getCanonicalPath(); + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access system property"); + } } - } else { - homeDir = FileSystemView.getFileSystemView(). - getDefaultDirectory().getCanonicalPath(); + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); - } + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access os.name system property"); + } return homeDir; } final private String getUserName() { - String userName = (String) System.getProperties().get("user.name"); + String userName = null; + try { + userName = (String) System.getProperties().get("user.name"); + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access user.name system property"); + } return userName; } final public static String getFileSeperator() { - String seperator = System.getProperties().get("file.separator").toString(); + String seperator = null; + try { + seperator = System.getProperties().get("file.separator").toString(); + } catch(java.security.AccessControlException e) { + System.out.println("Cannot access file.separator system property"); + } return seperator; } diff --git a/java/src/com/tigervnc/vncviewer/index.vnc b/java/src/com/tigervnc/vncviewer/index.vnc index ba9e57c9..fdd4f70a 100644 --- a/java/src/com/tigervnc/vncviewer/index.vnc +++ b/java/src/com/tigervnc/vncviewer/index.vnc @@ -18,7 +18,6 @@ $USER's $DESKTOP desktop ($DISPLAY) -$PARAMS
TigerVNC site -- 2.39.5