本文整理汇总了Java中java.security.cert.CertificateParsingException类的典型用法代码示例。如果您正苦于以下问题:Java CertificateParsingException类的具体用法?Java CertificateParsingException怎么用?Java CertificateParsingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CertificateParsingException类属于java.security.cert包,在下文中一共展示了CertificateParsingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCertAppliesToString
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
public static String buildCertAppliesToString(X509Certificate cert) {
List<String> elements = new ArrayList<>();
try {
Collection<List<?>> altNames = cert.getSubjectAlternativeNames();
if (altNames != null) {
for (List<?> altName : altNames) {
Integer altNameType = (Integer) altName.get(0);
if (altNameType != 2 && altNameType != 7) // dns or ip
continue;
elements.add((String) altName.get(1));
}
}
} catch (CertificateParsingException ignored) {
}
if (elements.size() == 0)
return "none";
return TextUtils.join(",", elements.toArray());
}
示例2: resolvePrincipalInternal
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
/**
* Retrieves Subject Alternative Name UPN extension as a principal id String.
*
* @param certificate X.509 certificate credential.
*
* @return Resolved principal ID or null if no SAN UPN extension is available in provided certificate.
*
* @see AbstractX509PrincipalResolver#resolvePrincipalInternal(java.security.cert.X509Certificate)
* @see java.security.cert.X509Certificate#getSubjectAlternativeNames()
*/
@Override
protected String resolvePrincipalInternal(final X509Certificate certificate) {
logger.debug("Resolving principal from Subject Alternative Name UPN for {}", certificate);
try {
final Collection<List<?>> subjectAltNames = certificate.getSubjectAlternativeNames();
if (subjectAltNames != null) {
for (final List<?> sanItem : subjectAltNames) {
final ASN1Sequence seq = getAltnameSequence(sanItem);
final String upnString = getUPNStringFromSequence(seq);
if (upnString != null) {
return upnString;
}
}
}
} catch (final CertificateParsingException e) {
logger.error("Error is encountered while trying to retrieve subject alternative names collection from certificate", e);
logger.debug("Returning null principal id...");
return null;
}
logger.debug("Returning null principal id...");
return null;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:33,代码来源:X509SubjectAlternativeNameUPNPrincipalResolver.java
示例3: resolvePrincipalInternal
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
/**
* Retrieves Subject Alternative Name UPN extension as a principal id String.
*
* @param certificate X.509 certificate credential.
* @return Resolved principal ID or null if no SAN UPN extension is available in provided certificate.
* @see AbstractX509PrincipalResolver#resolvePrincipalInternal(java.security.cert.X509Certificate)
* @see java.security.cert.X509Certificate#getSubjectAlternativeNames()
*/
@Override
protected String resolvePrincipalInternal(final X509Certificate certificate) {
LOGGER.debug("Resolving principal from Subject Alternative Name UPN for [{}]", certificate);
try {
final Collection<List<?>> subjectAltNames = certificate.getSubjectAlternativeNames();
if (subjectAltNames != null) {
for (final List<?> sanItem : subjectAltNames) {
final ASN1Sequence seq = getAltnameSequence(sanItem);
final String upnString = getUPNStringFromSequence(seq);
if (upnString != null) {
return upnString;
}
}
}
} catch (final CertificateParsingException e) {
LOGGER.error("Error is encountered while trying to retrieve subject alternative names collection from certificate", e);
LOGGER.debug("Returning null principal...");
return null;
}
LOGGER.debug("Returning null principal id...");
return null;
}
示例4: AttributeCertificateHolder
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
public AttributeCertificateHolder(X509Certificate cert)
throws CertificateParsingException
{
X509Principal name;
try
{
name = PrincipalUtil.getIssuerX509Principal(cert);
}
catch (Exception e)
{
throw new CertificateParsingException(e.getMessage());
}
holder = new Holder(new IssuerSerial(generateGeneralNames(name),
new ASN1Integer(cert.getSerialNumber())));
}
示例5: generateJcaObject
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private X509Certificate generateJcaObject(TBSCertificate tbsCert, byte[] signature)
throws CertificateEncodingException
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(tbsCert);
v.add(sigAlgId);
v.add(new DERBitString(signature));
try
{
return new X509CertificateObject(Certificate.getInstance(new DERSequence(v)));
}
catch (CertificateParsingException e)
{
throw new ExtCertificateEncodingException("exception producing certificate object", e);
}
}
示例6: copyAndAddExtension
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
/**
* add a given extension field for the standard extensions tag (tag 3)
* copying the extension value from another certificate.
* @throws CertificateParsingException if the extension cannot be extracted.
*/
public void copyAndAddExtension(
String oid,
boolean critical,
X509Certificate cert)
throws CertificateParsingException
{
byte[] extValue = cert.getExtensionValue(oid);
if (extValue == null)
{
throw new CertificateParsingException("extension " + oid + " not present");
}
try
{
ASN1Encodable value = X509ExtensionUtil.fromExtensionValue(extValue);
this.addExtension(oid, critical, value);
}
catch (IOException e)
{
throw new CertificateParsingException(e.toString());
}
}
示例7: addAdditionalStoresFromAltNames
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
protected static void addAdditionalStoresFromAltNames(
X509Certificate cert,
ExtendedPKIXParameters pkixParams)
throws CertificateParsingException
{
// if in the IssuerAltName extension an URI
// is given, add an additinal X.509 store
if (cert.getIssuerAlternativeNames() != null)
{
Iterator it = cert.getIssuerAlternativeNames().iterator();
while (it.hasNext())
{
// look for URI
List list = (List)it.next();
if (list.get(0).equals(Integers.valueOf(GeneralName.uniformResourceIdentifier)))
{
// found
String temp = (String)list.get(1);
CertPathValidatorUtilities.addAdditionalStoreFromLocation(temp, pkixParams);
}
}
}
}
示例8: readDERCertificate
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private Certificate readDERCertificate(
InputStream in)
throws IOException, CertificateParsingException
{
ASN1InputStream dIn = new ASN1InputStream(in);
ASN1Sequence seq = (ASN1Sequence)dIn.readObject();
if (seq.size() > 1
&& seq.getObjectAt(0) instanceof DERObjectIdentifier)
{
if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData))
{
sData = new SignedData(ASN1Sequence.getInstance(
(ASN1TaggedObject)seq.getObjectAt(1), true)).getCertificates();
return getCertificate();
}
}
return new X509CertificateObject(
org.bouncycastle.asn1.x509.Certificate.getInstance(seq));
}
示例9: getCertificate
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private Certificate getCertificate()
throws CertificateParsingException
{
if (sData != null)
{
while (sDataObjectCount < sData.size())
{
Object obj = sData.getObjectAt(sDataObjectCount++);
if (obj instanceof ASN1Sequence)
{
return new X509CertificateObject(
org.bouncycastle.asn1.x509.Certificate.getInstance(obj));
}
}
}
return null;
}
示例10: readDERCertificate
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private java.security.cert.Certificate readDERCertificate(
ASN1InputStream dIn)
throws IOException, CertificateParsingException
{
ASN1Sequence seq = (ASN1Sequence)dIn.readObject();
if (seq.size() > 1
&& seq.getObjectAt(0) instanceof ASN1ObjectIdentifier)
{
if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData))
{
sData = SignedData.getInstance(ASN1Sequence.getInstance(
(ASN1TaggedObject)seq.getObjectAt(1), true)).getCertificates();
return getCertificate();
}
}
return new X509CertificateObject(
Certificate.getInstance(seq));
}
示例11: getCertificate
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private java.security.cert.Certificate getCertificate()
throws CertificateParsingException
{
if (sData != null)
{
while (sDataObjectCount < sData.size())
{
Object obj = sData.getObjectAt(sDataObjectCount++);
if (obj instanceof ASN1Sequence)
{
return new X509CertificateObject(
Certificate.getInstance(obj));
}
}
}
return null;
}
示例12: generateSignedCertificate
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private X509Certificate generateSignedCertificate(
PKCS10CertificationRequest csr) throws NoSuchAlgorithmException,
NoSuchProviderException, InvalidKeyException,
CertificateParsingException, CertificateEncodingException,
SignatureException {
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(rootCert.getSubjectX500Principal());
Calendar c = Calendar.getInstance();
certGen.setNotBefore(c.getTime());
c.add(Calendar.YEAR, 1);
certGen.setNotAfter(c.getTime());
certGen.setSubjectDN(csr.getCertificationRequestInfo().getSubject());
certGen.setPublicKey(csr.getPublicKey("BC"));
certGen.setSignatureAlgorithm(ALGORITHM_SHA256_RSA);
certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false,
new AuthorityKeyIdentifierStructure(rootCert.getPublicKey()));
certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false,
new SubjectKeyIdentifierStructure(csr.getPublicKey("BC")));
certGen.addExtension(X509Extensions.BasicConstraints, true,
new BasicConstraints(false));
certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(
KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
X509Certificate issuedCert = certGen.generate(rootPrivateKeyEntry
.getPrivateKey());
return issuedCert;
}
示例13: processResponse
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
/**
* Process response data and, if applicable, HTTPS information. The {@link org.symphonyoss.symphony.jcurl.JCurl.Response} object returned can be printed
* out with response.print().
*
* @param con a {@link java.net.HttpURLConnection} object.
* @return a {@link org.symphonyoss.symphony.jcurl.JCurl.Response} object.
* @throws java.io.IOException if any.
* @throws java.security.cert.CertificateParsingException if any.
*/
public Response processResponse(HttpURLConnection con) throws IOException, CertificateParsingException {
Response response = new Response();
long startTime = System.nanoTime();
con.connect();
long endTime = System.nanoTime();
response.timeTaken = endTime - startTime;
processResponseHeaders(con, response);
processResponseCode(con, response);
processResponseCertificates(con, response);
processResponseOutput(con, response);
processResponseTags(response);
return response;
}
示例14: getSubjectAltName
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private static Object getSubjectAltName(X509Certificate cert, int type) {
Collection<List<?>> subjectAltNames;
try {
subjectAltNames = cert.getSubjectAlternativeNames();
} catch (CertificateParsingException cpe) {
if (debug != null && Debug.isOn("handshake")) {
System.out.println(
"Attempt to obtain subjectAltNames extension failed!");
}
return null;
}
if (subjectAltNames != null) {
for (List<?> subjectAltName : subjectAltNames) {
int subjectAltNameType = (Integer)subjectAltName.get(0);
if (subjectAltNameType == type) {
return subjectAltName.get(1);
}
}
}
return null;
}
示例15: getSubjectAltNames
import java.security.cert.CertificateParsingException; //导入依赖的package包/类
private static List<String> getSubjectAltNames(X509Certificate certificate, int type) {
List<String> result = new ArrayList();
try {
Collection<?> subjectAltNames = certificate.getSubjectAlternativeNames();
if (subjectAltNames == null) {
return Collections.emptyList();
}
Iterator it = subjectAltNames.iterator();
while (it.hasNext()) {
List<?> entry = (List) it.next();
if (entry != null && entry.size() >= 2) {
Integer altNameType = (Integer) entry.get(0);
if (altNameType != null && altNameType.intValue() == type) {
String altName = (String) entry.get(1);
if (altName != null) {
result.add(altName);
}
}
}
}
return result;
} catch (CertificateParsingException e) {
return Collections.emptyList();
}
}