aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/pki/crl/RevokedCertificate.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/model/pki/crl/RevokedCertificate.java')
-rw-r--r--src/main/model/pki/crl/RevokedCertificate.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/model/pki/crl/RevokedCertificate.java b/src/main/model/pki/crl/RevokedCertificate.java
new file mode 100644
index 0000000..457ecb8
--- /dev/null
+++ b/src/main/model/pki/crl/RevokedCertificate.java
@@ -0,0 +1,72 @@
+package model.pki.crl;
+
+import model.asn1.*;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.stream.Stream;
+
+/**
+ * Indicates the revocation status of a certificate, given its serial number, revocation date, and reason.
+ * <pre>
+ * SEQUENCE {
+ * serialNumber CertificateSerialNumber,
+ * revocationDate Time,
+ * crlEntryExtensions Extensions OPTIONAL,
+ * ...}
+ * </pre>
+ */
+public class RevokedCertificate extends ASN1Object {
+ private final Int serialNumber;
+ private final ASN1Time revocationDate;
+ private final Reason reason;
+
+ /**
+ * EFFECT: Init with tags and parameters. See {@link ASN1Object} for tags.
+ * REQUIRES: revocationDate should be either UtcTime or GeneralTime.
+ */
+ public RevokedCertificate(Tag tag, Tag parentTag,
+ Int serialNumber,
+ ASN1Time revocationDate,
+ Reason reason) {
+ super(tag, parentTag);
+ this.serialNumber = serialNumber;
+ this.revocationDate = revocationDate;
+ this.reason = reason;
+ }
+
+ @Override
+ public Byte[] encodeValueDER() {
+ final Byte[] r = new OctetString(OctetString.TAG,
+ null,
+ new Byte[]{ 0x0A, 0x01, (byte) reason.getVal() })
+ .encodeDER();
+ final Byte[] oid = new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_CRL_REASON)
+ .encodeDER();
+ final Byte[] seqExt = Stream.of(Arrays.asList(TAG_SEQUENCE.encodeDER()),
+ Arrays.asList(new ASN1Length(r.length + oid.length).encodeDER()),
+ Arrays.asList(oid),
+ Arrays.asList(r))
+ .flatMap(Collection::stream)
+ .toArray(Byte[]::new);
+ return Stream.of(Arrays.asList(serialNumber.encodeDER()),
+ Arrays.asList(revocationDate.encodeDER()),
+ Arrays.asList(TAG_SEQUENCE.encodeDER()),
+ Arrays.asList(new ASN1Length(seqExt.length).encodeDER()),
+ Arrays.asList(seqExt))
+ .flatMap(Collection::stream)
+ .toArray(Byte[]::new);
+ }
+
+ public Int getSerialNumber() {
+ return serialNumber;
+ }
+
+ public ASN1Time getRevocationDate() {
+ return revocationDate;
+ }
+
+ public Reason getReason() {
+ return reason;
+ }
+}