na = new org.bouncycastle.asn1.x509.Time(notAfter);
}
myOptionalValidity.setNotBefore(nb);
myOptionalValidity.setNotAfter(na);
CertTemplate myCertTemplate = new CertTemplate();
myCertTemplate.setValidity( myOptionalValidity );
myCertTemplate.setIssuer(new X509Name(issuerDN));
myCertTemplate.setSubject(new X509Name(userDN));
byte[] bytes = keys.getPublic().getEncoded();
ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
ASN1InputStream dIn = new ASN1InputStream(bIn);
SubjectPublicKeyInfo keyInfo = new SubjectPublicKeyInfo((ASN1Sequence)dIn.readObject());
myCertTemplate.setPublicKey(keyInfo);
// If we did not pass any extensions as parameter, we will create some of our own, standard ones
X509Extensions exts = extensions;
if (exts == null) {
// SubjectAltName
// Some altNames
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
Vector<X509Extension> values = new Vector<X509Extension>();
Vector<DERObjectIdentifier> oids = new Vector<DERObjectIdentifier>();
if (altNames != null) {
GeneralNames san = CertTools.getGeneralNamesFromAltName(altNames);
dOut.writeObject(san);
byte[] value = bOut.toByteArray();
X509Extension sanext = new X509Extension(false, new DEROctetString(value));
values.add(sanext);
oids.add(X509Extensions.SubjectAlternativeName);
}
// KeyUsage
int bcku = 0;
bcku = X509KeyUsage.digitalSignature | X509KeyUsage.keyEncipherment | X509KeyUsage.nonRepudiation;
X509KeyUsage ku = new X509KeyUsage(bcku);
bOut = new ByteArrayOutputStream();
dOut = new DEROutputStream(bOut);
dOut.writeObject(ku);
byte[] value = bOut.toByteArray();
X509Extension kuext = new X509Extension(false, new DEROctetString(value));
values.add(kuext);
oids.add(X509Extensions.KeyUsage);
// Make the complete extension package
exts = new X509Extensions(oids, values);
}
myCertTemplate.setExtensions(exts);
if (customCertSerno != null) {
// Add serialNumber to the certTemplate, it is defined as a MUST NOT be used in RFC4211, but we will use it anyway in order
// to request a custom certificate serial number (something not standard anyway)
myCertTemplate.setSerialNumber(new DERInteger(customCertSerno));
}
CertRequest myCertRequest = new CertRequest(new DERInteger(4), myCertTemplate);
// myCertRequest.addControls(new
// AttributeTypeAndValue(CRMFObjectIdentifiers.regInfo_utf8Pairs, new