本文整理汇总了Java中org.bouncycastle.asn1.x509.ExtendedKeyUsage.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ExtendedKeyUsage.getInstance方法的具体用法?Java ExtendedKeyUsage.getInstance怎么用?Java ExtendedKeyUsage.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.x509.ExtendedKeyUsage
的用法示例。
在下文中一共展示了ExtendedKeyUsage.getInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtendedKeyUsageStringValue
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
/**
* Get Extended Key Usage (2.5.29.37) extension value as a string.
*
* <pre>
* ExtendedKeyUsage ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
* KeyPurposeId ::= OBJECT IDENTIFIER
* </pre>
*
* @param bValue The octet string value
* @return Extension value as a string
* @throws IOException If an I/O problem occurs
*/
private String getExtendedKeyUsageStringValue(byte[] bValue)
throws IOException
{
StringBuilder strBuff = new StringBuilder();
ExtendedKeyUsage eku = ExtendedKeyUsage.getInstance(bValue);
KeyPurposeId[] usages = eku.getUsages();
for (KeyPurposeId usage : usages)
{
if (strBuff.length() != 0)
{
strBuff.append("<br><br>");
}
String sOid = usage.getId();
String sEku = getRes(sOid, "UnrecognisedExtKeyUsageString");
strBuff.append(MessageFormat.format(sEku, sOid));
}
return strBuff.toString();
}
示例2: addRequestedExtKeyusage
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
private static void addRequestedExtKeyusage(List<ASN1ObjectIdentifier> usages,
Extensions requestedExtensions, Set<ExtKeyUsageControl> usageOccs) {
Extension extension = requestedExtensions.getExtension(Extension.extendedKeyUsage);
if (extension == null) {
return;
}
ExtendedKeyUsage reqKeyUsage =
ExtendedKeyUsage.getInstance(extension.getParsedValue());
for (ExtKeyUsageControl k : usageOccs) {
if (k.isRequired()) {
continue;
}
if (reqKeyUsage.hasKeyPurposeId(KeyPurposeId.getInstance(k.extKeyUsage()))) {
usages.add(k.extKeyUsage());
}
}
}
示例3: validateCertificate
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
/**
* Validate the passed in certificate as being of the correct type to be used
* for time stamping. To be valid it must have an ExtendedKeyUsage extension
* which has a key purpose identifier of id-kp-timeStamping.
*
* @param cert the certificate of interest.
* @throws TSPValidationException if the certicate fails on one of the check points.
*/
public static void validateCertificate(
X509CertificateHolder cert)
throws TSPValidationException
{
if (cert.toASN1Structure().getVersionNumber() != 3)
{
throw new IllegalArgumentException("Certificate must have an ExtendedKeyUsage extension.");
}
Extension ext = cert.getExtension(Extension.extendedKeyUsage);
if (ext == null)
{
throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension.");
}
if (!ext.isCritical())
{
throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
}
ExtendedKeyUsage extKey = ExtendedKeyUsage.getInstance(ext.getParsedValue());
if (!extKey.hasKeyPurposeId(KeyPurposeId.id_kp_timeStamping) || extKey.size() != 1)
{
throw new TSPValidationException("ExtendedKeyUsage not solely time stamping.");
}
}
示例4: validateCertificate
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
/**
* Validate the passed in certificate as being of the correct type to be used
* for time stamping. To be valid it must have an ExtendedKeyUsage extension
* which has a key purpose identifier of id-kp-timeStamping.
*
* @param cert the certificate of interest.
* @throws TSPValidationException if the certificate fails on one of the check points.
*/
public static void validateCertificate(
X509CertificateHolder cert)
throws TSPValidationException
{
if (cert.toASN1Structure().getVersionNumber() != 3)
{
throw new IllegalArgumentException("Certificate must have an ExtendedKeyUsage extension.");
}
Extension ext = cert.getExtension(Extension.extendedKeyUsage);
if (ext == null)
{
throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension.");
}
if (!ext.isCritical())
{
throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
}
ExtendedKeyUsage extKey = ExtendedKeyUsage.getInstance(ext.getParsedValue());
if (!extKey.hasKeyPurposeId(KeyPurposeId.id_kp_timeStamping) || extKey.size() != 1)
{
throw new TSPValidationException("ExtendedKeyUsage not solely time stamping.");
}
}
示例5: getExtendedKeyUsageStringValue
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
private String getExtendedKeyUsageStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* ExtendedKeyUsage ::= ASN1Sequence SIZE (1..MAX) OF KeyPurposeId
*
* KeyPurposeId ::= OBJECT IDENTIFIER
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
ExtendedKeyUsage extendedKeyUsage = ExtendedKeyUsage.getInstance(value);
for (KeyPurposeId keyPurposeId : extendedKeyUsage.getUsages()) {
String oid = keyPurposeId.getId();
ExtendedKeyUsageType type = ExtendedKeyUsageType.resolveOid(oid);
if (type != null) {
sb.append(type.friendly());
} else {
// Unrecognised key purpose ID
sb.append(oid);
}
sb.append(NEWLINE);
}
return sb.toString();
}
示例6: prepopulateWithValue
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
private void prepopulateWithValue(byte[] value) throws IOException {
ExtendedKeyUsage extendedKeyUsage = ExtendedKeyUsage.getInstance(value);
for (KeyPurposeId keyPurposeId : extendedKeyUsage.getUsages()) {
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) keyPurposeId.toASN1Primitive();
ExtendedKeyUsageType type = ExtendedKeyUsageType.resolveOid(oid.getId());
if (type == SERVER_AUTH) {
jcbTlsWebServerAuthentication.setSelected(true);
} else if (type == CLIENT_AUTH) {
jcbTlsWebClientAuthentication.setSelected(true);
} else if (type == CODE_SIGNING) {
jcbCodeSigning.setSelected(true);
} else if (type == DOCUMENT_SIGNING) {
jcbDocumentSigning.setSelected(true);
} else if (type == ADOBE_PDF_SIGNING) {
jcbAdobePDFSigning.setSelected(true);
} else if (type == EMAIL_PROTECTION) {
jcbEmailProtection.setSelected(true);
} else if (type == ENCRYPTED_FILE_SYSTEM) {
jcbEncryptedFileSystem.setSelected(true);
} else if (type == IPSEC_END_SYSTEM) {
jcbIpSecurityEndSystem.setSelected(true);
} else if (type == IPSEC_TUNNEL) {
jcbIpSecurityTunnelTermination.setSelected(true);
} else if (type == IPSEC_USER) {
jcbIpSecurityUser.setSelected(true);
} else if (type == SMARTCARD_LOGON) {
jcbSmartcardLogon.setSelected(true);
} else if (type == TIME_STAMPING) {
jcbTimeStamping.setSelected(true);
} else if (type == OCSP_SIGNING) {
jcbOcspStamping.setSelected(true);
} else if (type == ANY_EXTENDED_KEY_USAGE) {
jcbAnyExtendedKeyUsage.setSelected(true);
}
}
}
示例7: validateCertificate
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; //导入方法依赖的package包/类
/**
* Validate the passed in certificate as being of the correct type to be used
* for time stamping. To be valid it must have an ExtendedKeyUsage extension
* which has a key purpose identifier of id-kp-timeStamping.
*
* @param cert the certificate of interest.
* @throws TSPValidationException if the certicate fails on one of the check points.
*/
public static void validateCertificate(
X509Certificate cert)
throws TSPValidationException
{
if (cert.getVersion() != 3)
{
throw new IllegalArgumentException("Certificate must have an ExtendedKeyUsage extension.");
}
byte[] ext = cert.getExtensionValue(X509Extensions.ExtendedKeyUsage.getId());
if (ext == null)
{
throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension.");
}
if (!cert.getCriticalExtensionOIDs().contains(X509Extensions.ExtendedKeyUsage.getId()))
{
throw new TSPValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
}
ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(ext));
try
{
aIn = new ASN1InputStream(new ByteArrayInputStream(((ASN1OctetString)aIn.readObject()).getOctets()));
ExtendedKeyUsage extKey = ExtendedKeyUsage.getInstance(aIn.readObject());
if (!extKey.hasKeyPurposeId(KeyPurposeId.id_kp_timeStamping) || extKey.size() != 1)
{
throw new TSPValidationException("ExtendedKeyUsage not solely time stamping.");
}
}
catch (IOException e)
{
throw new TSPValidationException("cannot process ExtendedKeyUsage extension");
}
}