diff options
Diffstat (limited to 'src/main/ui/JCA.java')
-rw-r--r-- | src/main/ui/JCA.java | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/src/main/ui/JCA.java b/src/main/ui/JCA.java index 7892850..882c546 100644 --- a/src/main/ui/JCA.java +++ b/src/main/ui/JCA.java @@ -1,16 +1,11 @@ package ui; import model.asn1.exceptions.ParseException; -import model.ca.AuditLogEntry; -import model.ca.CACertificate; -import model.ca.Template; +import model.ca.CertificationAuthority; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.security.spec.InvalidKeySpecException; import java.util.Scanner; /** @@ -26,31 +21,19 @@ public class JCA { private final UIHandler templatesScreen; private final UIHandler templateSetScreen; /** - * Templates - */ - private final List<Template> templates; - /** * The CA */ - private final CACertificate ca; - /** - * Audit logs - */ - private final List<AuditLogEntry> logs; - /** - * Current user - */ - private final String user; + private final CertificationAuthority ca; /** * The current screen. */ private UIHandler screen; /** - * EFFECTS: Init with main screen, empty templates, logs, user 'yuuta', and generate a private key with no CA cert. + * EFFECTS: Init with main screen and empty CA. No private key and no CA cert. * Throws {@link NoSuchAlgorithmException} when crypto issue happens. */ - public JCA() throws NoSuchAlgorithmException { + public JCA() throws NoSuchAlgorithmException, InvalidKeySpecException { this.mainScreen = new MainScreen(this); this.mgmtScreen = new MgmtScreen(this); this.issueScreen = new IssueScreen(this); @@ -59,12 +42,7 @@ public class JCA { setScreen(Screen.MAIN); - this.templates = new ArrayList<>(); - this.ca = new CACertificate(); - this.logs = new ArrayList<>(); - this.user = "yuuta"; - - this.ca.generateKey(); + this.ca = new CertificationAuthority(); } /** @@ -73,10 +51,10 @@ public class JCA { */ public boolean checkCA(boolean requireInstalled) { if (requireInstalled && ca.getCertificate() == null) { - System.out.println("The CA is not installed yet"); + System.out.println("No CA installed"); return false; } else if (!requireInstalled && ca.getCertificate() != null) { - System.out.println("The CA is already installed"); + System.out.println("CA already installed"); return false; } return true; @@ -101,19 +79,6 @@ public class JCA { } /** - * EFFECTS: Find the template based on name, or null if not found. - */ - public Template findTemplate(String name, boolean requireEnabled) { - Optional<Template> opt = templates.stream().filter(temp -> { - if (requireEnabled && !temp.isEnabled()) { - return false; - } - return temp.getName().equals(name); - }).findFirst(); - return opt.orElse(null); - } - - /** * EFFECT: Set the current screen with optional args. Exit the program when mode is null. * MODIFIES: this */ @@ -143,7 +108,7 @@ public class JCA { private void handleLine(String... args) { if (args[0].equals("log")) { - getLogs().forEach(System.out::println); + ca.getLogs().forEach(System.out::println); return; } switch (args[0]) { @@ -168,15 +133,7 @@ public class JCA { } private void printPS1() { - System.out.printf("%s@JCA %s ", user, screen.getPS1()); - } - - /** - * EFFECT: Log an action to the audit log - * MODIFIES: this - */ - public void log(String action) { - this.logs.add(new AuditLogEntry(user, ZonedDateTime.now(), action)); + System.out.printf("%s@JCA %s ", ca.getUser(), screen.getPS1()); } /** @@ -195,15 +152,7 @@ public class JCA { } } - public List<Template> getTemplates() { - return templates; - } - - public CACertificate getCa() { + public CertificationAuthority getCa() { return ca; } - - public List<AuditLogEntry> getLogs() { - return logs; - } } |