From 55df54e5dbf26e6824123410784d00aa793c3781 Mon Sep 17 00:00:00 2001 From: Yuuta Liang Date: Sat, 14 Oct 2023 07:53:12 +0800 Subject: Fix comments in UI Signed-off-by: Yuuta Liang --- src/main/ui/MgmtScreen.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/main/ui/MgmtScreen.java') diff --git a/src/main/ui/MgmtScreen.java b/src/main/ui/MgmtScreen.java index 613aa50..1957c7e 100644 --- a/src/main/ui/MgmtScreen.java +++ b/src/main/ui/MgmtScreen.java @@ -16,6 +16,9 @@ import java.util.Arrays; import java.util.Base64; import java.util.BitSet; +/** + * Manage the private key and CA certificate. It can print the public key, generate CSR, and install CA cert. + */ public class MgmtScreen implements UIHandler { private final JCA session; @@ -26,6 +29,9 @@ public class MgmtScreen implements UIHandler { this.session = session; } + /** + * EFFECTS: Print help + */ @Override public void help() { System.out.print("show\tView the public key and CA certificate\n" @@ -55,6 +61,9 @@ public class MgmtScreen implements UIHandler { .getSubjectPublicKey().getConvertedVal()))); } + /** + * EFFECT: Generate a CSR + */ private void handleCSR() { if (!session.checkCA(false)) { return; @@ -68,6 +77,9 @@ public class MgmtScreen implements UIHandler { } } + /** + * EFFECTS: Throw {@link ParseException} if the incoming cert is not v3. + */ private void validateCACertificateVersion(Certificate cert) throws ParseException { if (cert.getCertificate().getVersion() == null || cert.getCertificate().getVersion().getLong() != TbsCertificate.VERSION_V3) { @@ -75,6 +87,9 @@ public class MgmtScreen implements UIHandler { } } + /** + * EFFECTS: Throw {@link ParseException} if the incoming cert does not have the matching public key. + */ private void validateCACertificatePublicKey(Certificate cert) throws ParseException { final SubjectPublicKeyInfo expectedPKInfo = session.getCa().getCAPublicKeyInfo(); if (!Arrays.equals(cert.getCertificate().getSubjectPublicKeyInfo().getAlgorithm().getType().getInts(), @@ -85,6 +100,9 @@ public class MgmtScreen implements UIHandler { } } + /** + * EFFECTS: Throw {@link ParseException} if the incoming cert does not have cA = true in its basicConstraints. + */ private void validateCACertificateBasicConstraints(Certificate cert) throws ParseException { final Extension basicConstraints = cert.getCertificate().getExtension(ObjectIdentifier.OID_BASIC_CONSTRAINTS); if (basicConstraints == null @@ -104,6 +122,9 @@ public class MgmtScreen implements UIHandler { } } + /** + * EFFECTS: Throw {@link ParseException} if the incoming cert does not have valid key usages. + */ private void validateCACertificateKeyUsage(Certificate cert) throws ParseException { final Extension keyUsage = cert.getCertificate().getExtension(ObjectIdentifier.OID_KEY_USAGE); if (keyUsage == null @@ -122,6 +143,9 @@ public class MgmtScreen implements UIHandler { } } + /** + * EFFECTS: Handle the 'install' command. Read incoming certificate and validate it. + */ private void handleInstall() { if (!session.checkCA(false)) { return; @@ -140,6 +164,9 @@ public class MgmtScreen implements UIHandler { } } + /** + * EFFECTS: Handle commands. + */ @Override public void command(String... args) { switch (args[0]) { @@ -163,6 +190,9 @@ public class MgmtScreen implements UIHandler { return Screen.MAIN; } + /** + * EFFECTS: return "/ca/ #" + */ @Override public String getPS1() { return "/ca/ #"; -- cgit v1.2.3