Java 类org.bouncycastle.asn1.x500.RDN 实例源码

项目:ipack    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:ipack    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], DefaultSymbols);
    }

    return buf.toString();
}
项目:ipack    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], DefaultSymbols);
    }

    return buf.toString();
}
项目:xitk    文件:X509Util.java   
public static String getCommonName(X500Name name) {
    ParamUtil.requireNonNull("name", name);
    RDN[] rdns = name.getRDNs(ObjectIdentifiers.DN_CN);
    if (rdns != null && rdns.length > 0) {
        RDN rdn = rdns[0];
        AttributeTypeAndValue atv = null;
        if (rdn.isMultiValued()) {
            for (AttributeTypeAndValue m : rdn.getTypesAndValues()) {
                if (m.getType().equals(ObjectIdentifiers.DN_CN)) {
                    atv = m;
                    break;
                }
            }
        } else {
            atv = rdn.getFirst();
        }
        return (atv == null) ? null : rdnValueToString(atv.getValue());
    }
    return null;
}
项目:gwt-crypto    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:gwt-crypto    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:gwt-crypto    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:portecle    文件:NameUtil.java   
/**
 * Gets the common name from the given X500Name.
 * 
 * @param name the X.500 name
 * @return the common name, null if not found
 */
public static String getCommonName(X500Name name)
{
    if (name == null)
    {
        return null;
    }

    RDN[] rdns = name.getRDNs(BCStyle.CN);
    if (rdns.length == 0)
    {
        return null;
    }

    return rdns[0].getFirst().getValue().toString();
}
项目:Aki-SSL    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:Aki-SSL    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:Aki-SSL    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:athenz    文件:ZTSClientTest.java   
@Test
public void testGenerateInstanceRefreshRequestSubDomain() {

    File privkey = new File("./src/test/resources/test_private_k0.pem");
    PrivateKey privateKey = Crypto.loadPrivateKey(privkey);

    InstanceRefreshRequest req = ZTSClient.generateInstanceRefreshRequest("coretech.system",
            "test", privateKey, "aws", 3600);
    assertNotNull(req);

    PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(req.getCsr());
    assertEquals("coretech.system.test", Crypto.extractX509CSRCommonName(certReq));

    X500Name x500name = certReq.getSubject();
    RDN cnRdn = x500name.getRDNs(BCStyle.CN)[0];
    assertEquals("coretech.system.test", IETFUtils.valueToString(cnRdn.getFirst().getValue()));
    assertEquals("test.coretech-system.aws.athenz.cloud", Crypto.extractX509CSRDnsNames(certReq).get(0));
}
项目:keystore-explorer    文件:X500NameUtils.java   
/**
 * Returns the (first) value of the (first) RDN of type rdnOid
 *
 * @param dn The X500Name
 * @param rdnOid OID of wanted RDN
 * @return Value of requested RDN
 */
public static String getRdn(X500Name dn, ASN1ObjectIdentifier rdnOid) {

    if (dn == null || rdnOid == null) {
        return "";
    }

    RDN[] rdns = dn.getRDNs(rdnOid);
    String value = "";

    if (rdns.length > 0) {
        RDN rdn = rdns[0];
        value = rdn.getFirst().getValue().toString();
    }

    return value;
}
项目:keystore-explorer    文件:RdnPanelList.java   
public RdnPanelList(X500Name x500Name, boolean editable) {
    setLayout(new MigLayout("insets dialog, flowy", "[right]", "[]rel[]"));

    // we have to reverse RDN order for dialog
    List<RDN> rdnsAsList = Arrays.asList(x500Name.getRDNs());
    Collections.reverse(rdnsAsList);

    for (RDN rdn : rdnsAsList) {
        this.editable = editable;
        for (AttributeTypeAndValue atav : rdn.getTypesAndValues()) {
            String type = OidDisplayNameMapping.getDisplayNameForOid(atav.getType().getId());
            String value = atav.getValue().toString();
            addItem(new RdnPanel(new JComboBox<Object>(comboBoxEntries), type, value, this, editable));
        }
    }
}
项目:keywhiz    文件:LdapAuthenticator.java   
private Set<String> rolesFromDN(String userDN) throws LDAPException, GeneralSecurityException {
  SearchRequest searchRequest = new SearchRequest(config.getRoleBaseDN(),
      SearchScope.SUB, Filter.createEqualityFilter("uniqueMember", userDN));
  Set<String> roles = Sets.newLinkedHashSet();

  LDAPConnection connection = connectionFactory.getLDAPConnection();
  try {
    SearchResult sr = connection.search(searchRequest);

    for (SearchResultEntry sre : sr.getSearchEntries()) {
      X500Name x500Name = new X500Name(sre.getDN());
      RDN[] rdns = x500Name.getRDNs(BCStyle.CN);
      if (rdns.length == 0) {
        logger.error("Could not create X500 Name for role:" + sre.getDN());
      } else {
        String commonName = IETFUtils.valueToString(rdns[0].getFirst().getValue());
        roles.add(commonName);
      }
    }
  } finally {
    connection.close();
  }

  return roles;
}
项目:TinyTravelTracker    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:TinyTravelTracker    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:TinyTravelTracker    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:ksi-java-sdk    文件:X509CertificateSubjectRdnSelector.java   
public boolean match(Certificate cert) {
    if (!(cert instanceof X509Certificate)) {
        return false;
    }
    if (rdnArray == null) {
        return true;
    }
    try {
        X500Name x500name = getX500SubjectName((X509Certificate) cert);
        boolean ok = true;
        for (RDN rdn : rdnArray) {
            AttributeTypeAndValue expectedTypeAndValue = rdn.getFirst();

            ok = ok && contains(x500name, expectedTypeAndValue);
        }
        return ok;
    } catch (CertificateEncodingException e) {
        return false;
    }
}
项目:ksi-java-sdk    文件:X509CertificateSubjectRdnSelector.java   
private boolean checkRdn(RDN certRDN, AttributeTypeAndValue expectedTypeAndValue) {
    String expectedValue = IETFUtils.valueToString(expectedTypeAndValue.getValue());
    boolean constraintFound = false;
    AttributeTypeAndValue[] typesAndValues = certRDN.getTypesAndValues();
    for (AttributeTypeAndValue typesAndValue : typesAndValues) {
        if (typesAndValue.getType().equals(expectedTypeAndValue.getType())) {
            String actualValue = IETFUtils.valueToString(typesAndValue.getValue());
            if (actualValue.equals(expectedValue)) {
                constraintFound = true;
            } else {
                constraintFound = false;
                break;
            }
        }
    }

    return constraintFound;
}
项目:CryptMeme    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:CryptMeme    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:CryptMeme    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:nsi-dds    文件:ExtendedRFC4519Style.java   
@Override
public String toString(X500Name name)
{
    StringBuilder buf = new StringBuilder();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        ExtendedIETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:xipki    文件:CaUtil.java   
public static X500Name sortX509Name(X500Name name) {
    ParamUtil.requireNonNull("name", name);
    RDN[] requstedRdns = name.getRDNs();

    List<RDN> rdns = new LinkedList<>();

    List<ASN1ObjectIdentifier> sortedDNs = SubjectDnSpec.getForwardDNs();
    int size = sortedDNs.size();
    for (int i = 0; i < size; i++) {
        ASN1ObjectIdentifier type = sortedDNs.get(i);
        RDN[] thisRdns = getRdns(requstedRdns, type);
        if (thisRdns == null) {
            continue;
        }
        if (thisRdns.length == 0) {
            continue;
        }

        for (RDN m : thisRdns) {
            rdns.add(m);
        }
    }

    return new X500Name(rdns.toArray(new RDN[0]));
}
项目:irma_future_id    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:irma_future_id    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:irma_future_id    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:bc-java    文件:BCStrictStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!rdnAreEqual(rdns1[i], rdns2[i]))
        {
            return false;
        }
    }

    return true;
}
项目:bc-java    文件:RFC4519Style.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = rdns.length - 1; i >= 0; i--)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:bc-java    文件:BCStyle.java   
public String toString(X500Name name)
{
    StringBuffer buf = new StringBuffer();
    boolean first = true;

    RDN[] rdns = name.getRDNs();

    for (int i = 0; i < rdns.length; i++)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            buf.append(',');
        }

        IETFUtils.appendRDN(buf, rdns[i], defaultSymbols);
    }

    return buf.toString();
}
项目:ipack    文件:IETFUtils.java   
public static void appendRDN(
    StringBuffer          buf,
    RDN                   rdn,
    Hashtable             oidSymbols)
{
    if (rdn.isMultiValued())
    {
        AttributeTypeAndValue[] atv = rdn.getTypesAndValues();
        boolean firstAtv = true;

        for (int j = 0; j != atv.length; j++)
        {
            if (firstAtv)
            {
                firstAtv = false;
            }
            else
            {
                buf.append('+');
            }

            IETFUtils.appendTypeAndValue(buf, atv[j], oidSymbols);
        }
    }
    else
    {
        IETFUtils.appendTypeAndValue(buf, rdn.getFirst(), oidSymbols);
    }
}
项目:ipack    文件:RFC4519Style.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    boolean reverse = false;

    if (rdns1[0].getFirst() != null && rdns2[0].getFirst() != null)
    {
        reverse = !rdns1[0].getFirst().getType().equals(rdns2[0].getFirst().getType());  // guess forward
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!foundMatch(reverse, rdns1[i], rdns2))
        {
            return false;
        }
    }

    return true;
}
项目:ipack    文件:RFC4519Style.java   
private boolean foundMatch(boolean reverse, RDN rdn, RDN[] possRDNs)
{
    if (reverse)
    {
        for (int i = possRDNs.length - 1; i >= 0; i--)
        {
            if (possRDNs[i] != null && rdnAreEqual(rdn, possRDNs[i]))
            {
                possRDNs[i] = null;
                return true;
            }
        }
    }
    else
    {
        for (int i = 0; i != possRDNs.length; i++)
        {
            if (possRDNs[i] != null && rdnAreEqual(rdn, possRDNs[i]))
            {
                possRDNs[i] = null;
                return true;
            }
        }
    }

    return false;
}
项目:ipack    文件:RFC4519Style.java   
public RDN[] fromString(String dirName)
{
    RDN[] tmp = IETFUtils.rDNsFromString(dirName, this);
    RDN[] res = new RDN[tmp.length];

    for (int i = 0; i != tmp.length; i++)
    {
        res[res.length - i - 1] = tmp[i];
    }

    return res;
}
项目:ipack    文件:RFC4519Style.java   
public int calculateHashCode(X500Name name)
{
    int hashCodeValue = 0;
    RDN[] rdns = name.getRDNs();

    // this needs to be order independent, like equals
    for (int i = 0; i != rdns.length; i++)
    {
        if (rdns[i].isMultiValued())
        {
            AttributeTypeAndValue[] atv = rdns[i].getTypesAndValues();

            for (int j = 0; j != atv.length; j++)
            {
                hashCodeValue ^= atv[j].getType().hashCode();
                hashCodeValue ^= calcHashCode(atv[j].getValue());
            }
        }
        else
        {
            hashCodeValue ^= rdns[i].getFirst().getType().hashCode();
            hashCodeValue ^= calcHashCode(rdns[i].getFirst().getValue());
        }
    }

    return hashCodeValue;
}
项目:ipack    文件:BCStyle.java   
public boolean areEqual(X500Name name1, X500Name name2)
{
    RDN[] rdns1 = name1.getRDNs();
    RDN[] rdns2 = name2.getRDNs();

    if (rdns1.length != rdns2.length)
    {
        return false;
    }

    boolean reverse = false;

    if (rdns1[0].getFirst() != null && rdns2[0].getFirst() != null)
    {
        reverse = !rdns1[0].getFirst().getType().equals(rdns2[0].getFirst().getType());  // guess forward
    }

    for (int i = 0; i != rdns1.length; i++)
    {
        if (!foundMatch(reverse, rdns1[i], rdns2))
        {
            return false;
        }
    }

    return true;
}
项目:ipack    文件:BCStyle.java   
private boolean foundMatch(boolean reverse, RDN rdn, RDN[] possRDNs)
{
    if (reverse)
    {
        for (int i = possRDNs.length - 1; i >= 0; i--)
        {
            if (possRDNs[i] != null && rdnAreEqual(rdn, possRDNs[i]))
            {
                possRDNs[i] = null;
                return true;
            }
        }
    }
    else
    {
        for (int i = 0; i != possRDNs.length; i++)
        {
            if (possRDNs[i] != null && rdnAreEqual(rdn, possRDNs[i]))
            {
                possRDNs[i] = null;
                return true;
            }
        }
    }

    return false;
}
项目:ipack    文件:BCStyle.java   
public int calculateHashCode(X500Name name)
{
    int hashCodeValue = 0;
    RDN[] rdns = name.getRDNs();

    // this needs to be order independent, like equals
    for (int i = 0; i != rdns.length; i++)
    {
        if (rdns[i].isMultiValued())
        {
            AttributeTypeAndValue[] atv = rdns[i].getTypesAndValues();

            for (int j = 0; j != atv.length; j++)
            {
                hashCodeValue ^= atv[j].getType().hashCode();
                hashCodeValue ^= calcHashCode(atv[j].getValue());
            }
        }
        else
        {
            hashCodeValue ^= rdns[i].getFirst().getType().hashCode();
            hashCodeValue ^= calcHashCode(rdns[i].getFirst().getValue());
        }
    }

    return hashCodeValue;
}