javax.xml.crypto.dsig.keyinfo.KeyName Java Examples

The following examples show how to use javax.xml.crypto.dsig.keyinfo.KeyName. 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: XMLSignatureUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
    try {
        KeyName keyNameEl = KeyInfoTools.getKeyName(keyInfo);
        this.keyName = keyNameEl == null ? null : keyNameEl.getName();
        final Key key = locator.getKey(keyName);
        this.keyLocated = key != null;
        return new KeySelectorResult() {
            @Override public Key getKey() {
                return key;
            }
        };
    } catch (KeyManagementException ex) {
        throw new KeySelectorException(ex);
    }

}
 
Example #2
Source File: KeyValueKeySelectorTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test()
public void select_wrong_structType() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    KeyName struct = mock(KeyName.class);
    list.add(struct);
    doReturn(list).when(keyinfo).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains(
                "No RSA/DSA KeyValue element found"));
    }
}
 
Example #3
Source File: X509KeySelectorTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test()
public void select_wrong_structType() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    KeyName struct = mock(KeyName.class);
    list.add(struct);
    doReturn(list).when(keyinfo).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
Example #4
Source File: DOMKeyName.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #5
Source File: DOMKeyName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #6
Source File: DOMKeyName.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #7
Source File: DOMKeyName.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #8
Source File: DOMKeyName.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #9
Source File: DOMKeyName.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #10
Source File: DOMKeyName.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #11
Source File: DOMKeyName.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #12
Source File: DOMKeyName.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #13
Source File: DOMKeyName.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #14
Source File: DOMKeyName.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #15
Source File: XMLDSigVerifier.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private XMLDsigVerificationResult validateCertificateIssuer(XMLSignature signature, XMLDsigVerificationResult result) {
    try
    {
        KeyInfo xmlKeyInfo = signature.getKeyInfo();
        List<X509Certificate> certList = getCertificateChainFromXML(xmlKeyInfo.getContent());
        List<X509Certificate> orderedCerts = reorderCertificateChain(certList);
        X509Certificate signingCert = selectSigningKeyFromXML(xmlKeyInfo.getContent());
        //Throws if invalid
        validateCertificateChain(orderedCerts);
        result.issuerPrincipal = signingCert.getIssuerX500Principal().getName();
        result.subjectPrincipal = signingCert.getSubjectX500Principal().getName();
        result.keyType = signingCert.getSigAlgName();
        for (Object o : xmlKeyInfo.getContent())
        {
            XMLStructure xmlStructure = (XMLStructure) o;
            if (xmlStructure instanceof KeyName)
            {
                result.keyName = ((KeyName) xmlStructure).getName();
            }
        }
    }
    catch(Exception e)
    {
        result.isValid = false;
        result.failureReason = e.getMessage();
    }
    return result;
}
 
Example #16
Source File: DOMKeyName.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #17
Source File: DOMKeyName.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyName)) {
        return false;
    }
    KeyName okn = (KeyName)obj;
    return name.equals(okn.getName());
}
 
Example #18
Source File: HttpAdapterUtilsTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Test
public void testExtractKeysFromSamlDescriptor() throws ParsingException {
    InputStream xmlStream = HttpAdapterUtilsTest.class.getResourceAsStream("saml-descriptor-valid.xml");
    MultivaluedHashMap<String, KeyInfo> res = HttpAdapterUtils.extractKeysFromSamlDescriptor(xmlStream);

    assertThat(res, notNullValue());
    assertThat(res.keySet(), hasItems(KeyTypes.SIGNING.value()));
    assertThat(res.get(KeycloakSamlAdapterV1QNames.ATTR_SIGNING.getQName().getLocalPart()), notNullValue());
    assertThat(res.get(KeycloakSamlAdapterV1QNames.ATTR_SIGNING.getQName().getLocalPart()).size(), equalTo(2));

    KeyInfo ki;
    KeyName keyName;
    X509Data x509data;
    X509Certificate x509certificate;

    Matcher<Iterable<? super XMLStructure>> x509DataMatcher = hasItem(instanceOf(X509Data.class));
    Matcher<Iterable<? super XMLStructure>> keyNameMatcher = hasItem(instanceOf(KeyName.class));

    ki = res.get(KeycloakSamlAdapterV1QNames.ATTR_SIGNING.getQName().getLocalPart()).get(0);
    assertThat(ki.getContent().size(), equalTo(2));

    assertThat((Iterable<? super XMLStructure>) ki.getContent(), x509DataMatcher);
    assertThat((Iterable<? super XMLStructure>) ki.getContent(), keyNameMatcher);

    keyName = getContent(ki.getContent(), KeyName.class);
    assertThat(keyName.getName(), equalTo("rJkJlvowmv1Id74GznieaAC5jU5QQp_ILzuG-GsweTI"));

    x509data = getContent(ki.getContent(), X509Data.class);
    assertThat(x509data, notNullValue());
    x509certificate = getContent(x509data.getContent(), X509Certificate.class);
    assertThat(x509certificate, notNullValue());
    assertThat(x509certificate.getSigAlgName(), equalTo("SHA256withRSA"));

    ki = res.get(KeycloakSamlAdapterV1QNames.ATTR_SIGNING.getQName().getLocalPart()).get(1);
    assertThat(ki.getContent().size(), equalTo(2));
    assertThat((Iterable<? super XMLStructure>) ki.getContent(), x509DataMatcher);
    assertThat((Iterable<? super XMLStructure>) ki.getContent(), keyNameMatcher);

    keyName = getContent(ki.getContent(), KeyName.class);
    assertThat(keyName.getName(), equalTo("BzYc4GwL8HVrAhNyNdp-lTah2DvU9jU03kby9Ynohr4"));

    x509data = getContent(ki.getContent(), X509Data.class);
    assertThat(x509data, notNullValue());
    x509certificate = getContent(x509data.getContent(), X509Certificate.class);
    assertThat(x509certificate, notNullValue());
    assertThat(x509certificate.getSigAlgName(), equalTo("SHA256withRSA"));

}
 
Example #19
Source File: KeyInfoTools.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static KeyName getKeyName(KeyInfo keyInfo) {
    return keyInfo == null ? null : getContent(keyInfo.getContent(), KeyName.class);
}