Java Code Examples for org.bouncycastle.asn1.DERBitString#getInstance()

The following examples show how to use org.bouncycastle.asn1.DERBitString#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DKeyUsage.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void prepopulateWithValue(byte[] value) throws IOException {
	try (ASN1InputStream asn1InputStream = new ASN1InputStream(value)) {
		DERBitString keyUsage = DERBitString.getInstance(asn1InputStream.readObject());

		int keyUsageValue = keyUsage.intValue();

		jcbDigitalSignature.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.digitalSignature));
		jcbNonRepudiation.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.nonRepudiation));
		jcbKeyEncipherment.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.keyEncipherment));
		jcbDataEncipherment.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.dataEncipherment));
		jcbKeyAgreement.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.keyAgreement));
		jcbCertificateSigning.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.keyCertSign));
		jcbCrlSign.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.cRLSign));
		jcbEncipherOnly.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.encipherOnly));
		jcbDecipherOnly.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.decipherOnly));
	}
}
 
Example 2
Source File: DNetscapeCertificateType.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void prepopulateWithValue(byte[] value) throws IOException {
	try (ASN1InputStream asn1InputStream = new ASN1InputStream(value)) {
		DERBitString netscapeCertType = DERBitString.getInstance(asn1InputStream.readObject());

		int netscapeCertTypes = netscapeCertType.intValue();

		jcbSslClient.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.sslClient));
		jcbSslServer.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.sslServer));
		jcbSmime.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.smime));
		jcbObjectSigning.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.objectSigning));
		jcbReserved.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.reserved));
		jcbSslCa.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.sslCA));
		jcbSmimeCa.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.smimeCA));
		jcbObjectSigningCa.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.objectSigningCA));
	}
}
 
Example 3
Source File: X509Ext.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private String getBitString(byte[] octets) throws IOException {

		if (octets == null) {
			return "";
		}

		DERBitString derBitString = DERBitString.getInstance(ASN1Primitive.fromByteArray(octets));
		byte[] bitStringBytes = derBitString.getBytes();

		return new BigInteger(1, bitStringBytes).toString(2);
	}
 
Example 4
Source File: X509Ext.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private String getKeyUsageStringValue(byte[] value) throws IOException {
	// @formatter:off

	/*
	 * KeyUsage ::= BIT STRING { digitalSignature (0), nonRepudiation (1),
	 * keyEncipherment (2), dataEncipherment (3), keyAgreement (4),
	 * keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }
	 */

	// @formatter:on

	DERBitString keyUsage = DERBitString.getInstance(ASN1Primitive.fromByteArray(value));

	int keyUsages = keyUsage.intValue();

	StringBuilder sb = new StringBuilder();

	if (hasKeyUsage(keyUsages, KeyUsage.digitalSignature)) {
		sb.append(res.getString("DigitalSignatureKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.nonRepudiation)) {
		sb.append(res.getString("NonRepudiationKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.keyEncipherment)) {
		sb.append(res.getString("KeyEnciphermentKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.dataEncipherment)) {
		sb.append(res.getString("DataEnciphermentKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.keyAgreement)) {
		sb.append(res.getString("KeyAgreementKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.keyCertSign)) {
		sb.append(res.getString("KeyCertSignKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.cRLSign)) {
		sb.append(res.getString("CrlSignKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.encipherOnly)) {
		sb.append(res.getString("EncipherOnlyKeyUsage"));
		sb.append(NEWLINE);
	}
	if (hasKeyUsage(keyUsages, KeyUsage.decipherOnly)) {
		sb.append(res.getString("DecipherOnlyKeyUsage"));
		sb.append(NEWLINE);
	}

	return sb.toString();
}
 
Example 5
Source File: X509Ext.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
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();

	@SuppressWarnings("resource") // we have a ByteArrayInputStream here which does not need to be closed
	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();
}
 
Example 6
Source File: ExtensionSyntaxChecker.java    From xipki with Apache License 2.0 4 votes vote down vote up
private static ASN1Encodable getParsedImplicitValue(String name, ASN1TaggedObject taggedObject,
    FieldType fieldType) throws BadCertTemplateException {
  try {
    switch (fieldType) {
      case BIT_STRING:
        return DERBitString.getInstance(taggedObject, false);
      case BMPString:
        return DERBMPString.getInstance(taggedObject, false);
      case BOOLEAN:
        return ASN1Boolean.getInstance(taggedObject, false);
      case ENUMERATED:
        return ASN1Enumerated.getInstance(taggedObject, false);
      case GeneralizedTime:
        return DERGeneralizedTime.getInstance(taggedObject, false);
      case IA5String:
        return DERIA5String.getInstance(taggedObject, false);
      case INTEGER:
        return ASN1Integer.getInstance(taggedObject, false);
      case Name:
        return X500Name.getInstance(taggedObject, false);
      case NULL:
        if (!(taggedObject.getObject() instanceof ASN1OctetString
            && ((ASN1OctetString) taggedObject.getObject()).getOctets().length == 0)) {
          throw new BadCertTemplateException("invalid " + name);
        }
        return DERNull.INSTANCE;
      case OCTET_STRING:
        return DEROctetString.getInstance(taggedObject, false);
      case OID:
        return ASN1ObjectIdentifier.getInstance(taggedObject, false);
      case PrintableString:
        return DERPrintableString.getInstance(taggedObject, false);
      case RAW:
        return taggedObject.getObject();
      case SEQUENCE:
      case SEQUENCE_OF:
        return ASN1Sequence.getInstance(taggedObject, false);
      case SET:
      case SET_OF:
        return ASN1Set.getInstance(taggedObject, false);
      case TeletexString:
        return DERT61String.getInstance(taggedObject, false);
      case UTCTime:
        return DERUTCTime.getInstance(taggedObject, false);
      case UTF8String:
        return DERUTF8String.getInstance(taggedObject, false);
      default:
        throw new RuntimeException("Unknown FieldType " + fieldType);
    }
  } catch (IllegalArgumentException ex) {
    throw new BadCertTemplateException("invalid " + name, ex);
  }
}