private void initDirectory(boolean noLocalFileSystemAccess) throws IOException { // what to do, if no local files shall be touched if (noLocalFileSystemAccess) { dir = new Directory(this, privateKeyHandler.getIdentity()); return; } // load stable dir first // log.logDirectory(Logger.INFO,"Tor.initDirectory(): load stable dir"); // dir = new Directory(this,privateKeyHandler.getIdentity(), config.TOR_STABLE_DIR_FILENAME, // ""); // load cache-file over stable-dir long age = System.currentTimeMillis() - TorConfig.cacheMaxAgeSeconds * 1000L; File cacheFile = new File(TorConfig.getCacheFilename()); if (cacheFile.exists() && cacheFile.lastModified() >= age) { try { // TODO-FIXME-SECURITY-BUG-FIX: use fingerprint of dirServerKeys // dir.readDirectoryFromFile(config.getCacheFilename(), ""); dir = new Directory(this, privateKeyHandler.getIdentity(), TorConfig.getCacheFilename(), ""); } catch (Exception e) { Logger.logDirectory(Logger.WARNING, "Tor.initDirectory(): " + e.getMessage()); } } else { dir = new Directory(this, privateKeyHandler.getIdentity()); } /* uneccessary // check if in cache-file and/or stable-file have been some tor nodes if ((dir==null) || (dir.torServers==null) || (dir.torServers.size()<1)) throw new IOException("no Tor nodes found"); */ // update from network in the background // -> will be done by TorBackgroundMgmt! }
public Server(int port) { enc = null; dec = null; char[] password = null; char[] passwordcopy = null; try { password = PrivateKeyHandler.checkPassword(GenerateKeys.getPasswordInput()); if (password == null) { System.err.println("Please enter admin password to start the server"); System.exit(1); } passwordcopy = Arrays.copyOf(password, password.length); this.network = new ServerNetworkWrapper(port, password); dec = LoginManager.load(password); enc = LoginManager.save(passwordcopy); } finally { if (password != null) { for (int i = 0; i < password.length; i++) { password[i] = '\0'; passwordcopy[i] = '\0'; } } } // In-case LoginManager.load isn't reached challengeHanlder = new ChallengeHandler(); }
private void addCourse() { JTextField pf = new JTextField(); int okCxl = JOptionPane.showConfirmDialog( null, pf, "Enter Course Name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); String courseName = null; if (okCxl == JOptionPane.OK_OPTION) { courseName = new String(pf.getText()); } else { return; } JComboBox<Person> profList = new JComboBox<Person>(); profList.addItem(null); for (Person p : LoginManager.getPersons()) { profList.addItem(p); } okCxl = JOptionPane.showConfirmDialog( null, profList, "Select Professor", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); Person prof = null; if (okCxl == JOptionPane.OK_OPTION) { prof = (Person) profList.getSelectedItem(); } else { return; } Course c = new Course(courseName, prof); char[] password = null; try { password = PrivateKeyHandler.checkPassword( GenerateKeys.getPasswordInput()); // This window shows garbage if (password == null) { System.err.println("Please enter admin password to apply changes"); return; } LoginManager.putCourse(c.getCID(), c); enc = LoginManager.save(password); } finally { if (password != null) { for (int i = 0; i < password.length; i++) { password[i] = '\0'; } } } }
private void apply() { String action = (String) StatusList.getSelectedItem(); Person p = (Person) PersonList.getSelectedItem(); Course c = (Course) CourseList.getSelectedItem(); if (!checkValidAction(action, p, c)) { System.err.println("Invalid action... Ignoring..."); return; } StatusList.setSelectedIndex(0); PersonList.setSelectedIndex(0); CourseList.setSelectedIndex(0); char[] password = null; try { password = PrivateKeyHandler.checkPassword( GenerateKeys.getPasswordInput()); // This window shows garbage if (password == null) { System.err.println("Please enter admin password to apply changes"); return; } if (action == STUDENT) { LoginManager.setStudent(p.getPID(), c.getCID()); } else if (action == TA) { LoginManager.setTA(p.getPID(), c.getCID()); } else if (action == PROF) { LoginManager.setProf(p.getPID(), c.getCID()); } else if (action == REMOVE) { LoginManager.remove(p.getPID(), c.getCID()); } else if (action == REMOVEPERSON) { LoginManager.remove(p.getPID()); } else if (action == REMOVECOURSE) { LoginManager.removeCourse(c.getCID()); } else if (action == EDITCOURSE) { JTextField pf = new JTextField(); int okCxl = JOptionPane.showConfirmDialog( null, pf, "Change Course name to", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); String courseName = null; if (okCxl == JOptionPane.OK_OPTION) { courseName = new String(pf.getText()); } else { return; } LoginManager.changeCoursename(c.getCID(), courseName); } else if (action == EDITUSERNAME) { JTextField pf = new JTextField(); int okCxl = JOptionPane.showConfirmDialog( null, pf, "Change username to", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); String username = null; if (okCxl == JOptionPane.OK_OPTION) { username = new String(pf.getText()); } else { return; } LoginManager.changeUsername(p.getPID(), username); } enc = LoginManager.save(password); } finally { if (password != null) { for (int i = 0; i < password.length; i++) { password[i] = '\0'; } } } }