use of java.security.cert.CRLException in project robovm by robovm.
the class CertificateFactory method engineGenerateCRL.
/**
* Generates a certificate revocation list (CRL) object and initializes
* it with the data read from the input stream inStream.
*/
public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
if (currentCrlStream == null) {
currentCrlStream = inStream;
sCrlData = null;
sCrlDataObjectCount = 0;
} else if (// reset if input stream has changed
currentCrlStream != inStream) {
currentCrlStream = inStream;
sCrlData = null;
sCrlDataObjectCount = 0;
}
try {
if (sCrlData != null) {
if (sCrlDataObjectCount != sCrlData.size()) {
return getCRL();
} else {
sCrlData = null;
sCrlDataObjectCount = 0;
return null;
}
}
PushbackInputStream pis = new PushbackInputStream(inStream);
int tag = pis.read();
if (tag == -1) {
return null;
}
pis.unread(tag);
if (// assume ascii PEM encoded.
tag != 0x30) {
return readPEMCRL(pis);
} else {
// lazy evaluate to help processing of large CRLs
return readDERCRL(new ASN1InputStream(pis, true));
}
} catch (CRLException e) {
throw e;
} catch (Exception e) {
throw new CRLException(e.toString());
}
}
use of java.security.cert.CRLException in project robovm by robovm.
the class CertificateFactory2Test method checkResult.
private void checkResult(CertificateFactory certFactory, boolean mode) throws CertificateException, CRLException {
MyCertificateFactorySpi.putMode(mode);
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
DataInputStream dis = new DataInputStream(bais);
try {
certFactory.generateCertPath(bais);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactory.generateCertPath(dis);
if (!mode) {
fail("CertificateException must be thrown because encodings list is empty");
}
} catch (CertificateException e) {
if (mode) {
fail("Unexpected CertificateFactoryException was thrown");
}
}
try {
certFactory.generateCertPath(bais, "aa");
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactory.generateCertPath(dis, "");
if (mode) {
fail("IllegalArgumentException must be thrown");
}
} catch (IllegalArgumentException e) {
if (!mode) {
fail("Unexpected IllegalArgumentException was thrown");
}
}
certFactory.generateCertPath(dis, "ss");
try {
certFactory.generateCertificate(bais);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactory.generateCertificates(null);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
Certificate cert = certFactory.generateCertificate(dis);
assertNull("Result must be null", cert);
Collection<? extends Certificate> col = certFactory.generateCertificates(dis);
assertNull("Result must be null", col);
try {
certFactory.generateCRL(bais);
fail("CRLException must be thrown");
} catch (CRLException e) {
}
try {
certFactory.generateCRLs(null);
fail("CRLException must be thrown");
} catch (CRLException e) {
}
CRL crl = certFactory.generateCRL(dis);
assertNull("Result must be null", crl);
Collection<? extends CRL> colc = certFactory.generateCRLs(dis);
assertNull("Result must be null", colc);
List<Certificate> list = null;
CertPath cp;
try {
cp = certFactory.generateCertPath(list);
if (mode) {
fail("NullPointerException must be thrown");
} else {
assertNull("Must be null", cp);
}
} catch (NullPointerException e) {
if (!mode) {
fail("Unexpected NullPointerException was thrown");
}
}
Iterator<String> it = certFactory.getCertPathEncodings();
if (mode) {
assertTrue(it.hasNext());
} else {
assertFalse(it.hasNext());
}
}
use of java.security.cert.CRLException in project robovm by robovm.
the class CertificateFactorySpiTest method testCertificateFactorySpi02.
/**
* Test for <code>CertificateFactorySpi</code> constructor
* Assertion: constructs CertificateFactorySpi
*/
public void testCertificateFactorySpi02() throws CertificateException, CRLException {
CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi();
MyCertificateFactorySpi.putMode(true);
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
DataInputStream dis = new DataInputStream(bais);
try {
certFactorySpi.engineGenerateCertPath(bais);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
certFactorySpi.engineGenerateCertPath(dis);
try {
certFactorySpi.engineGenerateCertPath(bais, "aa");
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactorySpi.engineGenerateCertPath(dis, "");
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
certFactorySpi.engineGenerateCertPath(dis, "ss");
try {
certFactorySpi.engineGenerateCertificate(bais);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactorySpi.engineGenerateCertificates(null);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
Certificate cert = certFactorySpi.engineGenerateCertificate(dis);
assertNull("Result must be null", cert);
Collection<? extends Certificate> col = certFactorySpi.engineGenerateCertificates(dis);
assertNull("Result must be null", col);
try {
certFactorySpi.engineGenerateCRL(bais);
fail("CRLException must be thrown");
} catch (CRLException e) {
}
try {
certFactorySpi.engineGenerateCRLs(null);
fail("CRLException must be thrown");
} catch (CRLException e) {
}
CRL crl = certFactorySpi.engineGenerateCRL(dis);
assertNull("Result must be null", crl);
Collection<? extends CRL> colcrl = certFactorySpi.engineGenerateCRLs(dis);
assertNull("Result must be null", colcrl);
List<Certificate> list = null;
try {
certFactorySpi.engineGenerateCertPath(list);
fail("NullPointerException must be thrown");
} catch (NullPointerException e) {
}
Iterator<String> enc = certFactorySpi.engineGetCertPathEncodings();
assertTrue("Incorrect Iterator", enc.hasNext());
}
use of java.security.cert.CRLException in project j2objc by google.
the class X509CRLEntryImpl method parse.
private void parse(DerValue derVal) throws CRLException, IOException {
if (derVal.tag != DerValue.tag_Sequence) {
throw new CRLException("Invalid encoded RevokedCertificate, " + "starting sequence tag missing.");
}
if (derVal.data.available() == 0)
throw new CRLException("No data encoded for RevokedCertificates");
revokedCert = derVal.toByteArray();
// serial number
DerInputStream in = derVal.toDerInputStream();
DerValue val = in.getDerValue();
this.serialNumber = new SerialNumber(val);
// revocationDate
int nextByte = derVal.data.peekByte();
if ((byte) nextByte == DerValue.tag_UtcTime) {
this.revocationDate = derVal.data.getUTCTime();
} else if ((byte) nextByte == DerValue.tag_GeneralizedTime) {
this.revocationDate = derVal.data.getGeneralizedTime();
} else
throw new CRLException("Invalid encoding for revocation date");
if (derVal.data.available() == 0)
// no extensions
return;
// crlEntryExtensions
this.extensions = new CRLExtensions(derVal.toDerInputStream());
}
use of java.security.cert.CRLException in project j2objc by google.
the class X509CRLEntryImpl method encode.
/**
* Encodes the revoked certificate to an output stream.
*
* @param outStrm an output stream to which the encoded revoked
* certificate is written.
* @exception CRLException on encoding errors.
*/
public void encode(DerOutputStream outStrm) throws CRLException {
try {
if (revokedCert == null) {
DerOutputStream tmp = new DerOutputStream();
// sequence { serialNumber, revocationDate, extensions }
serialNumber.encode(tmp);
if (revocationDate.getTime() < YR_2050) {
tmp.putUTCTime(revocationDate);
} else {
tmp.putGeneralizedTime(revocationDate);
}
if (extensions != null)
extensions.encode(tmp, isExplicit);
DerOutputStream seq = new DerOutputStream();
seq.write(DerValue.tag_Sequence, tmp);
revokedCert = seq.toByteArray();
}
outStrm.write(revokedCert);
} catch (IOException e) {
throw new CRLException("Encoding error: " + e.toString());
}
}
Aggregations