From 1edb7950d3d5fca4124ed9404ecbc6fd7948852d Mon Sep 17 00:00:00 2001 From: Elizabeth Fong Date: Mon, 18 Dec 2006 09:35:31 +0000 Subject: [PATCH] Fail a tiny bit more gracefully if the user rejects the signing certificate. --- .../threerings/getdown/launcher/Getdown.java | 1 + .../getdown/launcher/GetdownApplet.java | 71 +++++++++++++------ .../threerings/getdown/messages.properties | 6 ++ 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index f1208b3..722c754 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -114,6 +114,7 @@ public abstract class Getdown extends Thread createInterface(true); } catch (Exception e) { Log.warning("Failed to preinit: " + e); + createInterface(true); } } diff --git a/src/java/com/threerings/getdown/launcher/GetdownApplet.java b/src/java/com/threerings/getdown/launcher/GetdownApplet.java index 275f935..b3f09e7 100644 --- a/src/java/com/threerings/getdown/launcher/GetdownApplet.java +++ b/src/java/com/threerings/getdown/launcher/GetdownApplet.java @@ -53,6 +53,21 @@ public class GetdownApplet extends JApplet @Override // documentation inherited public void init () { + // Getdown absolutely requires full read/write permissions to the system. If we don't + // have this, then we need to not do anything unsafe, and display a message to the user + // telling them they need to (groan) close out of the web browser entirely and re-launch + // the browser, go to our site, and accept the certificate. + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + try { + sm.checkWrite("getdown"); + sm.checkPropertiesAccess(); + } catch (SecurityException se) { + Log.warning("Signed applet rejected by user [se=" + se + "]."); + _permissioned = false; + } + } + // First off, verify that we are not being hijacked to execute // malicious code in the name of the signer. String appbase = getParameter("appbase"); @@ -97,12 +112,11 @@ public class GetdownApplet extends JApplet if (!_safe) { Log.warning("Signed getdown invoked on unsigned application; " + "aborting installation."); - return; } // Pass through properties parameter. String properties = getParameter("properties"); - if (properties != null) { + if (properties != null && _permissioned) { String[] proparray = properties.split(" "); for (String property : proparray) { String key = property.substring(property.indexOf("-D") + 2, @@ -122,12 +136,14 @@ public class GetdownApplet extends JApplet root = ".getdown"; } - String appdir = System.getProperty("user.home") + - File.separator + root + File.separator + appname; + String appdir = root + File.separator + appname; + if (_permissioned) { + appdir = System.getProperty("user.home") + File.separator + appdir; + } // if our application directory does not exist, auto-create it File appDir = new File(appdir); - if (!appDir.exists() || !appDir.isDirectory()) { + if (_permissioned && (!appDir.exists() || !appDir.isDirectory())) { if (!appDir.mkdirs()) { Log.warning("Unable to create app_dir '" + appdir + "'."); // TODO: report error @@ -137,7 +153,7 @@ public class GetdownApplet extends JApplet // if an installer.txt file is desired, create that String inststr = getParameter("installer"); - if (!StringUtil.isBlank(inststr)) { + if (_permissioned && !StringUtil.isBlank(inststr)) { File infile = new File(appDir, "installer.txt"); if (!infile.exists()) { writeToFile(infile, inststr); @@ -145,17 +161,19 @@ public class GetdownApplet extends JApplet } // if our getdown.txt file does not exist, auto-create it - File gdfile = new File(appDir, "getdown.txt"); - if (!gdfile.exists()) { - if (StringUtil.isBlank(appbase)) { - Log.warning("Missing 'appbase' cannot auto-create " + - "application directory."); - // TODO: report - return; - } - if (!writeToFile(gdfile, "appbase = " + appbase)) { - // TODO: report the error - return; + if (_permissioned) { + File gdfile = new File(appDir, "getdown.txt"); + if (!gdfile.exists()) { + if (StringUtil.isBlank(appbase)) { + Log.warning("Missing 'appbase' cannot auto-create " + + "application directory."); + // TODO: report + return; + } + if (!writeToFile(gdfile, "appbase = " + appbase)) { + // TODO: report the error + return; + } } } @@ -175,10 +193,12 @@ public class GetdownApplet extends JApplet Log.info("-- OS Arch: " + System.getProperty("os.arch")); Log.info("-- OS Vers: " + System.getProperty("os.version")); Log.info("-- Java Vers: " + System.getProperty("java.version")); - Log.info("-- Java Home: " + System.getProperty("java.home")); - Log.info("-- User Name: " + System.getProperty("user.name")); - Log.info("-- User Home: " + System.getProperty("user.home")); - Log.info("-- Cur dir: " + System.getProperty("user.dir")); + if (_permissioned) { + Log.info("-- Java Home: " + System.getProperty("java.home")); + Log.info("-- User Name: " + System.getProperty("user.name")); + Log.info("-- User Home: " + System.getProperty("user.home")); + Log.info("-- Cur dir: " + System.getProperty("user.dir")); + } Log.info("---------------------------------------------"); try { @@ -228,9 +248,13 @@ public class GetdownApplet extends JApplet public void start () { if (!_safe) { + _getdown.updateStatus("m.corrupt_param_signature_error"); + return; + } + if (!_permissioned) { + _getdown.updateStatus("m.insufficient_permissions_error"); return; } - try { _getdown.start(); } catch (Exception e) { @@ -269,4 +293,7 @@ public class GetdownApplet extends JApplet * parameters are not validated to prevent malicious code from being run. */ protected boolean _safe = false; + + /** Whether Getdown has been trusted by the user with system access */ + protected boolean _permissioned = true; } diff --git a/src/java/com/threerings/getdown/messages.properties b/src/java/com/threerings/getdown/messages.properties index d53db53..208083a 100644 --- a/src/java/com/threerings/getdown/messages.properties +++ b/src/java/com/threerings/getdown/messages.properties @@ -67,6 +67,12 @@ m.readonly_error = The directory in which this application is installed: \ m.missing_resource = The application has failed to launch due to a \ missing resource:\n{0}\n\nPlease visit\n{1} for information on how to handle such problems. +m.insufficient_permissions_error = You did not accept the application's digital signature. \ + \nPlease quit and re-open your web browser and attempt to \nre-launch the application, \ + making sure that you accept \nthe application's digital signature. +m.corrupt_param_signature_error = We couldn't verify the application's digital signature.\n\ + Please check that you are launching the application from \nthe application's website. + m.default_install_error = the support section of the website # application/digest errors