use of org.bouncycastle.asn1.ASN1Primitive in project robovm by robovm.
the class Pfx method toASN1Primitive.
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(3));
v.add(contentInfo);
if (macData != null) {
v.add(macData);
}
return new BERSequence(v);
}
use of org.bouncycastle.asn1.ASN1Primitive in project robovm by robovm.
the class PrivateKeyInfo method toASN1Primitive.
/**
* write out an RSA private key with its associated information
* as described in PKCS8.
* <pre>
* PrivateKeyInfo ::= SEQUENCE {
* version Version,
* privateKeyAlgorithm AlgorithmIdentifier {{PrivateKeyAlgorithms}},
* privateKey PrivateKey,
* attributes [0] IMPLICIT Attributes OPTIONAL
* }
* Version ::= INTEGER {v1(0)} (v1,...)
*
* PrivateKey ::= OCTET STRING
*
* Attributes ::= SET OF Attribute
* </pre>
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(0));
v.add(algId);
v.add(privKey);
if (attributes != null) {
v.add(new DERTaggedObject(false, 0, attributes));
}
return new DERSequence(v);
}
use of org.bouncycastle.asn1.ASN1Primitive in project robovm by robovm.
the class RSAPublicKey method toASN1Primitive.
/**
* This outputs the key in PKCS1v2 format.
* <pre>
* RSAPublicKey ::= SEQUENCE {
* modulus INTEGER, -- n
* publicExponent INTEGER, -- e
* }
* </pre>
* <p>
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(getModulus()));
v.add(new ASN1Integer(getPublicExponent()));
return new DERSequence(v);
}
use of org.bouncycastle.asn1.ASN1Primitive in project robovm by robovm.
the class PEMUtil method readPEMObject.
ASN1Sequence readPEMObject(InputStream in) throws IOException {
String line;
StringBuffer pemBuf = new StringBuffer();
while ((line = readLine(in)) != null) {
if (line.startsWith(_header1) || line.startsWith(_header2)) {
break;
}
}
while ((line = readLine(in)) != null) {
if (line.startsWith(_footer1) || line.startsWith(_footer2)) {
break;
}
pemBuf.append(line);
}
if (pemBuf.length() != 0) {
ASN1Primitive o = new ASN1InputStream(Base64.decode(pemBuf.toString())).readObject();
if (!(o instanceof ASN1Sequence)) {
throw new IOException("malformed PEM data encountered");
}
return (ASN1Sequence) o;
}
return null;
}
use of org.bouncycastle.asn1.ASN1Primitive in project robovm by robovm.
the class RFC3280CertPathUtilities method processCRLB1.
/**
* If the DP includes cRLIssuer, then verify that the issuer field in the
* complete CRL matches cRLIssuer in the DP and that the complete CRL
* contains an issuing distribution point extension with the indirectCRL
* boolean asserted. Otherwise, verify that the CRL issuer matches the
* certificate issuer.
*
* @param dp The distribution point.
* @param cert The certificate ot attribute certificate.
* @param crl The CRL for <code>cert</code>.
* @throws AnnotatedException if one of the above conditions does not apply or an error
* occurs.
*/
protected static void processCRLB1(DistributionPoint dp, Object cert, X509CRL crl) throws AnnotatedException {
ASN1Primitive idp = CertPathValidatorUtilities.getExtensionValue(crl, ISSUING_DISTRIBUTION_POINT);
boolean isIndirect = false;
if (idp != null) {
if (IssuingDistributionPoint.getInstance(idp).isIndirectCRL()) {
isIndirect = true;
}
}
byte[] issuerBytes = CertPathValidatorUtilities.getIssuerPrincipal(crl).getEncoded();
boolean matchIssuer = false;
if (dp.getCRLIssuer() != null) {
GeneralName[] genNames = dp.getCRLIssuer().getNames();
for (int j = 0; j < genNames.length; j++) {
if (genNames[j].getTagNo() == GeneralName.directoryName) {
try {
if (Arrays.areEqual(genNames[j].getName().toASN1Primitive().getEncoded(), issuerBytes)) {
matchIssuer = true;
}
} catch (IOException e) {
throw new AnnotatedException("CRL issuer information from distribution point cannot be decoded.", e);
}
}
}
if (matchIssuer && !isIndirect) {
throw new AnnotatedException("Distribution point contains cRLIssuer field but CRL is not indirect.");
}
if (!matchIssuer) {
throw new AnnotatedException("CRL issuer of CRL does not match CRL issuer of distribution point.");
}
} else {
if (CertPathValidatorUtilities.getIssuerPrincipal(crl).equals(CertPathValidatorUtilities.getEncodedIssuerPrincipal(cert))) {
matchIssuer = true;
}
}
if (!matchIssuer) {
throw new AnnotatedException("Cannot find matching CRL issuer for certificate.");
}
}
Aggregations