use of org.gudy.bouncycastle.asn1.ASN1InputStream in project android_packages_apps_Settings by LineageOS.
the class CertInstallerHelper method isCa.
private boolean isCa(X509Certificate cert) {
try {
byte[] asn1EncodedBytes = cert.getExtensionValue("2.5.29.19");
if (asn1EncodedBytes == null) {
return false;
}
DEROctetString derOctetString = (DEROctetString) new ASN1InputStream(asn1EncodedBytes).readObject();
byte[] octets = derOctetString.getOctets();
ASN1Sequence sequence = (ASN1Sequence) new ASN1InputStream(octets).readObject();
return BasicConstraints.getInstance(sequence).isCA();
} catch (IOException e) {
return false;
}
}
use of org.gudy.bouncycastle.asn1.ASN1InputStream in project BiglyBT by BiglySoftware.
the class Dump method main.
public static void main(String[] args) throws Exception {
FileInputStream fIn = new FileInputStream(args[0]);
ASN1InputStream bIn = new ASN1InputStream(fIn);
Object obj = null;
while ((obj = bIn.readObject()) != null) {
System.out.println(ASN1Dump.dumpAsString(obj));
}
}
use of org.gudy.bouncycastle.asn1.ASN1InputStream in project BiglyBT by BiglySoftware.
the class X509NameEntryConverter method convertHexEncoded.
/**
* Convert an inline encoded hex string rendition of an ASN.1
* object back into its corresponding ASN.1 object.
*
* @param str the hex encoded object
* @param off the index at which the encoding starts
* @return the decoded object
*/
protected DERObject convertHexEncoded(String str, int off) throws IOException {
str = Strings.toLowerCase(str);
byte[] data = new byte[(str.length() - off) / 2];
for (int index = 0; index != data.length; index++) {
char left = str.charAt((index * 2) + off);
char right = str.charAt((index * 2) + off + 1);
if (left < 'a') {
data[index] = (byte) ((left - '0') << 4);
} else {
data[index] = (byte) ((left - 'a' + 10) << 4);
}
if (right < 'a') {
data[index] |= (byte) (right - '0');
} else {
data[index] |= (byte) (right - 'a' + 10);
}
}
ASN1InputStream aIn = new ASN1InputStream(data);
return aIn.readObject();
}
use of org.gudy.bouncycastle.asn1.ASN1InputStream in project BiglyBT by BiglySoftware.
the class PrincipalUtil method getSubjectX509Principal.
/**
* return the subject of the given cert as an X509PrincipalObject.
*/
public static X509Principal getSubjectX509Principal(X509Certificate cert) throws CertificateEncodingException {
try {
ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getTBSCertificate());
ASN1InputStream aIn = new ASN1InputStream(bIn);
TBSCertificateStructure tbsCert = new TBSCertificateStructure((ASN1Sequence) aIn.readObject());
return new X509Principal(tbsCert.getSubject());
} catch (IOException e) {
throw new CertificateEncodingException(e.toString());
}
}
use of org.gudy.bouncycastle.asn1.ASN1InputStream in project keystore-explorer by kaikramer.
the class X509Ext method getNetscapeCertificateTypeStringValue.
private String getNetscapeCertificateTypeStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* NetscapeCertType ::= BIT STRING { sslClient (0), sslServer (1), smime
* (2), objectSigning (3), reserved (4), sslCA (5), smimeCA (6),
* objectSigningCA (7) }
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
// we have a ByteArrayInputStream here which does not need to be closed
@SuppressWarnings("resource") DERBitString netscapeCertType = DERBitString.getInstance(new ASN1InputStream(value).readObject());
int netscapeCertTypes = netscapeCertType.intValue();
if (isCertType(netscapeCertTypes, NetscapeCertType.sslClient)) {
sb.append(res.getString("SslClientNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.sslServer)) {
sb.append(res.getString("SslServerNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.smime)) {
sb.append(res.getString("SmimeNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.objectSigning)) {
sb.append(res.getString("ObjectSigningNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.reserved)) {
sb.append(res.getString("ReservedNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.sslCA)) {
sb.append(res.getString("SslCaNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.smimeCA)) {
sb.append(res.getString("SmimeCaNetscapeCertificateType"));
sb.append(NEWLINE);
}
if (isCertType(netscapeCertTypes, NetscapeCertType.objectSigningCA)) {
sb.append(res.getString("ObjectSigningCaNetscapeCertificateType"));
sb.append(NEWLINE);
}
return sb.toString();
}
Aggregations