aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/pki/crl/RevokedCertificate.java
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-12 12:10:33 +0800
committerYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-12 12:10:33 +0800
commitd342a45d98c4795b3a3fe1aaef5236ad4a782b55 (patch)
treef4ebc0ad962b138d9371413fcc71c97a559df506 /src/main/model/pki/crl/RevokedCertificate.java
parente60c9c76243cfe0a408af98dc60bedb973e815db (diff)
downloadjca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar
jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.gz
jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.bz2
jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.zip
Implement data structures from X.680, X.501, X.509, and PKCS#10, with X.690 encoding / decoding support
The implementation took four days, and it is still a little bit rough. Updated version should arrive soon. Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
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;
+ }
+}