/** Setup sets up a connection and authenticates. */ public void setup(String username, char[] password, String host, int port, boolean ssl) throws MsfException { boolean haveRpcd = false; this.username = username; this.password = new String(password); this.host = host; this.port = port; this.ssl = ssl; String message = ""; try { connect(); if (username == null || username.equals("")) { rpcToken = this.password; execute("core.version"); // throws error if unsuccessful haveRpcd = true; } else { Map results = (Map) exec("auth.login", new Object[] {username, this.password}); rpcToken = results.get("token").toString(); haveRpcd = results.get("result").equals("success"); } } catch (MsfException xre) { message = xre.getLocalizedMessage(); } catch (IOException io) { message = io.getLocalizedMessage(); } catch (NullPointerException nex) { } catch (NoSuchAlgorithmException nsax) { } catch (KeyManagementException kmx) { } if (!haveRpcd) throw new MsfException("Error connecting. " + message); Map root = MsfguiApp.getPropertiesNode(); root.put("username", username); root.put("password", this.password); root.put("host", host); root.put("port", port); root.put("ssl", ssl); root.put("disableDb", disableDb); MsfguiApp.savePreferences(); }