java.security.cert.X509Certificate.getSubjectDN()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(548)

本文整理了Java中java.security.cert.X509Certificate.getSubjectDN()方法的一些代码示例,展示了X509Certificate.getSubjectDN()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。X509Certificate.getSubjectDN()方法的具体详情如下:
包路径:java.security.cert.X509Certificate
类名称:X509Certificate
方法名:getSubjectDN

X509Certificate.getSubjectDN介绍

[英]Returns the subject (subject distinguished name) as an implementation specific Principal object.

The ASN.1 definition of subject:

subject      Name 
Name ::= CHOICE { 
RDNSequence } 
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName 
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue 
AttributeTypeAndValue ::= SEQUENCE { 
type     AttributeType, 
value    AttributeValue } 
AttributeType ::= OBJECT IDENTIFIER 
AttributeValue ::= ANY DEFINED BY AttributeType

replaced by: #getSubjectX500Principal().
[中]将主题(主题可分辨名称)作为特定于实现的主体对象返回。
ASN。1.主题的定义:

subject      Name 
Name ::= CHOICE { 
RDNSequence } 
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName 
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue 
AttributeTypeAndValue ::= SEQUENCE { 
type     AttributeType, 
value    AttributeValue } 
AttributeType ::= OBJECT IDENTIFIER 
AttributeValue ::= ANY DEFINED BY AttributeType

替换为:#GetSubjectX500 Principal()。

代码示例

代码示例来源:origin: neo4j/neo4j

private String describeCertificate( X509Certificate certificate )
{
  return "Subject: " + certificate.getSubjectDN() +
      ", Issuer: " + certificate.getIssuerDN();
}

代码示例来源:origin: apache/activemq

protected String getDistinguishedName(final X509Certificate[] certs) {
  if (certs != null && certs.length > 0 && certs[0] != null) {
    return certs[0].getSubjectDN().getName();
  } else {
    return null;
  }
}

代码示例来源:origin: apache/nifi

putAttribute(attributes, "http.principal.name", principal.getName());
if (certs != null && certs.length > 0) {
  final X509Certificate cert = certs[0];
  subjectDn = cert.getSubjectDN().getName();
  final String issuerDn = cert.getIssuerDN().getName();

代码示例来源:origin: apache/nifi

@Override
public Object extractPrincipal(X509Certificate cert) {
  return cert.getSubjectDN().getName().trim();
}

代码示例来源:origin: square/okhttp

/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */
private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) {
 if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false;
 try {
  toVerify.verify(signingCert.getPublicKey());
  return true;
 } catch (GeneralSecurityException verifyFailed) {
  return false;
 }
}

代码示例来源:origin: org.eclipse.jetty/jetty-security

continue;
Principal principal = cert.getSubjectDN();
if (principal == null) principal = cert.getIssuerDN();
final String username = principal == null ? "clientcert" : principal.getName();

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

private String getCommonName(X509Certificate c) {
    LOG.debug("Subject DN principal name: {}", c.getSubjectDN().getName());
    for (String each : c.getSubjectDN().getName().split(",\\s*")) {
      if (each.startsWith("CN=")) {
        String result = each.substring(3);
        LOG.debug("Common Name: {}", result);
        return result;
      }
    }
    throw new IllegalStateException("Missed CN in Subject DN: "
        + c.getSubjectDN());
  }
}

代码示例来源:origin: prestodb/presto

/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */
private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) {
 if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false;
 try {
  toVerify.verify(signingCert.getPublicKey());
  return true;
 } catch (GeneralSecurityException verifyFailed) {
  return false;
 }
}

代码示例来源:origin: GluuFederation/oxTrust

public X509CertificateShortInfo(String alias, X509Certificate cert) {
  this.alias = alias;
  if (cert.getIssuerDN() != null)
    issuer = cert.getIssuerDN().getName();
  if (cert.getSubjectDN() != null)
    subject = cert.getSubjectDN().getName();
  algorithm = cert.getSigAlgName();
  notBeforeDatetime = cert.getNotBefore();
  notAfterDatetime = cert.getNotAfter();
  updateViewStyle();
}

代码示例来源:origin: apache/nifi

@Override
public String toString() {
  return new StringBuilder("NiFi OCSP Request: ")
      .append("Subject DN: ").append(subjectCertificate != null ? subjectCertificate.getSubjectDN().getName() : "<null>")
      .append(" issued by ")
      .append("Issuer DN: ").append(issuerCertificate != null ? issuerCertificate.getSubjectDN().getName() : "<null>").toString();
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */
private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) {
 if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false;
 try {
  toVerify.verify(signingCert.getPublicKey());
  return true;
 } catch (GeneralSecurityException verifyFailed) {
  return false;
 }
}

代码示例来源:origin: org.wso2.wsas/wso2wsas-admin

private CertData fillCertData(X509Certificate cert, String alise, Format formatter) {
  CertData certData = new CertData();
  certData.setAlias(alise);
  certData.setSubjectDN(cert.getSubjectDN().getName());
  certData.setIssuerDN(cert.getIssuerDN().getName());
  certData.setSerialNumber(cert.getSerialNumber());
  certData.setVersion(cert.getVersion());
  certData.setNotAfter(formatter.format(cert.getNotAfter()));
  certData.setNotBefore(formatter.format(cert.getNotBefore()));
  return certData;
}

代码示例来源:origin: apache/activemq

public String getUserName() {
  if (certs != null && certs.length > 0) {
    return certs[0].getSubjectDN().getName();
  }
  return super.getUserName();
}

代码示例来源:origin: wildfly/wildfly

private static boolean issuedBy(final X509Certificate certificate, X509Certificate issuer) {
  if (issuer.getSubjectDN().equals(certificate.getIssuerDN())) {
    try {
      certificate.verify(issuer.getPublicKey());
      return true;
    } catch (Exception e) {
      return false;
    }
  }
  return false;
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Maps certificate CommonName as identity credentials
 * 
 * @param certificate
 * @return A List of names.
 */
@Override
public List<String> mapIdentity(X509Certificate certificate) {
  String name = certificate.getSubjectDN().getName();
  Matcher matcher = cnPattern.matcher(name);
  // Create an array with the detected identities
  List<String> names = new ArrayList<>();
  while (matcher.find()) {
    names.add(matcher.group(2));
  }
  
  return names;
}

代码示例来源:origin: commonsguy/cw-omnibus

private SigModel(X509Certificate cert) {
  this.subject=cert.getSubjectDN().toString();
  this.issuer=cert.getIssuerDN().toString();
  this.validDates=
   FORMAT.format(cert.getNotBefore())+" to "+
    FORMAT.format(cert.getNotAfter());
 }
}

代码示例来源:origin: apache/nifi

public String getDn() throws CertificateException, SSLPeerUnverifiedException {
  final Certificate[] certs = engine.getSession().getPeerCertificates();
  if (certs == null || certs.length == 0) {
    throw new SSLPeerUnverifiedException("No certificates found");
  }
  final X509Certificate cert = CertificateUtils.convertAbstractX509Certificate(certs[0]);
  cert.checkValidity();
  return cert.getSubjectDN().getName().trim();
}

代码示例来源:origin: robovm/robovm

private static X509Certificate[] createChain(X509Certificate  signer, X509Certificate[] candidates) {
  LinkedList chain = new LinkedList();
  chain.add(0, signer);
  // Signer is self-signed
  if (signer.getSubjectDN().equals(signer.getIssuerDN())){
    return (X509Certificate[])chain.toArray(new X509Certificate[1]);
  }
  Principal issuer = signer.getIssuerDN();
  X509Certificate issuerCert;
  int count = 1;
  while (true) {
    issuerCert = findCert(issuer, candidates);
    if( issuerCert == null) {
      break;
    }
    chain.add(issuerCert);
    count++;
    if (issuerCert.getSubjectDN().equals(issuerCert.getIssuerDN())) {
      break;
    }
    issuer = issuerCert.getIssuerDN();
  }
  return (X509Certificate[])chain.toArray(new X509Certificate[count]);
}

代码示例来源:origin: square/okhttp

X509Certificate x509Certificate = (X509Certificate) peerCertificates.get(c);
message.append("\n    ").append(pin(x509Certificate))
  .append(": ").append(x509Certificate.getSubjectDN().getName());

代码示例来源:origin: stackoverflow.com

172           X509Certificate lastCertificate = serverCertificates[chainLength - 1];
173           Date now = new Date();
174           if (lastCertificate.getSubjectDN().equals(lastCertificate.getIssuerDN())
175               && now.after(lastCertificate.getNotAfter())) {
176             --chainLength;

相关文章