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

The following examples show how to use org.bouncycastle.asn1.DERBitString#intValue() . 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 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 4
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 5
Source File: X509Ext.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private String[] getReasonFlagsStrings(ReasonFlags reasonFlags) throws IOException {
	// @formatter:off

	/*
	 * ReasonFlags ::= BIT STRING { unused(0), keyCompromise(1),
	 * cACompromise(2), affiliationChanged(3), superseded(4),
	 * cessationOfOperation(5), certificateHold(6), privilegeWithdrawn(7),
	 * aACompromise(8)}
	 */

	// @formatter:on

	List<String> reasonFlagsList = new ArrayList<>();

	DERBitString reasonFlagsBitString = (DERBitString) reasonFlags.toASN1Primitive();

	int reasonFlagsInt = reasonFlagsBitString.intValue();

	// Go through bit string adding reason flags found to be true
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.unused)) {
		reasonFlagsList.add(res.getString("UnusedReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.keyCompromise)) {
		reasonFlagsList.add(res.getString("KeyCompromiseReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.cACompromise)) {
		reasonFlagsList.add(res.getString("CaCompromiseReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.affiliationChanged)) {
		reasonFlagsList.add(res.getString("AffiliationChangedReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.superseded)) {
		reasonFlagsList.add(res.getString("SupersededReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.cessationOfOperation)) {
		reasonFlagsList.add(res.getString("CessationOfOperationReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.certificateHold)) {
		reasonFlagsList.add(res.getString("CertificateHoldReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.privilegeWithdrawn)) {
		reasonFlagsList.add(res.getString("PrivilegeWithdrawnReasonFlag"));
	}
	if (hasReasonFlag(reasonFlagsInt, ReasonFlags.aACompromise)) {
		reasonFlagsList.add(res.getString("AaCompromiseReasonFlag"));
	}

	return reasonFlagsList.toArray(new String[reasonFlagsList.size()]);
}