package model.ca; import model.asn1.*; import model.asn1.exceptions.ParseException; import model.pki.cert.TbsCertificate; import model.x501.AttributeTypeAndValue; import model.x501.Name; import model.x501.RelativeDistinguishedName; import java.util.List; /** * Represents a certificate template. Certificate templates are like policies the define part of the issued certificates * of what to have in common. */ public class Template { /** * Name of the template. */ private String name; /** * Whether the template is usable or not. */ private boolean enabled; /** * Subject of the issued certs. Null -> unspecified */ private Name subject; /** * Length of validity in days since the point of issue. */ private long validity; /** * EFFECTS: Init with all given parameters. * REQUIRES: name should be non-null; subject should be a valid X.509 subject name; validity should be > 0 */ public Template(String name, boolean enabled, Name subject, long validity) { this.name = name; this.enabled = enabled; this.subject = subject; this.validity = validity; } public String getName() { return name; } public void setName(String name) { this.name = name; } public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public Name getSubject() { return subject; } public void setSubject(Name subject) { this.subject = subject; } /** * EFFECTS: Set the subject to CN=commonName,C=CA * Throws {@link ParseException} if commonName is not a valid PrintableString */ public void setSubject(String commonName) throws ParseException { if (commonName == null) { this.subject = null; return; } setSubject(new Name(ASN1Object.TAG_SEQUENCE, null, new RelativeDistinguishedName[]{ new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{ new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null, new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_CN), new PrintableString(PrintableString.TAG, null, commonName))}), new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{ new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null, new ObjectIdentifier(ObjectIdentifier.TAG, null, ObjectIdentifier.OID_C), new PrintableString(PrintableString.TAG, null, "CA"))})})); } public long getValidity() { return validity; } public void setValidity(long validity) { this.validity = validity; } }