aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/MgmtScreen.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/ui/MgmtScreen.java')
-rw-r--r--src/main/ui/MgmtScreen.java30
1 files changed, 30 insertions, 0 deletions
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/ #";