“无法找到到请求目标的有效认证路径"在 Camel 组件测试中 [英] "unable to find valid certification path to requested target" in Camel Component Test

查看:35
本文介绍了“无法找到到请求目标的有效认证路径"在 Camel 组件测试中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发和测试骆驼端点.我现在想测试 SSL 连接.每当我运行测试(尝试进行相互 SSL 身份验证)时,我都会收到错误无法找到到请求目标的有效认证路径".我的证书链对于客户端和服务器来说是这样的.除了 ID 之外,两者都相同.CA -> SubCA -> Client1(用作客户端")-> Client2(用作服务器"

i am trying to develop and test a camel endpoint. I now want to test SSL connectivity. Whenever i run the test (which tries to do a mutual SSL authentication) i get the error "unable to find valid certification path to requested target". My certificate chain looks like this for client and server. Both are identical besides an ID. CA -> SubCA -> Client1 (used as "client") -> Client2 (used as "server"

我为客户端创建了一个 PKCS12 文件,并将 CA、SubCA 和客户端证书导入密钥库:

I created a PKCS12 file for both clients and imported CA, SubCA and client certificate into a keystore:

keytool -keystore store.jks -importcert -alias ca -file test_ca_certs/rootca.cert
keytool -keystore store.jsk -importcert -alias subca -file test_ca_certs/subca.cert
keytool -v -importkeystore -srckeystore source.p12 -srcstoretype PKCS12 -destkeystore store.jsk -deststoretype JKS

所以可以说,我有一个客户端和服务器的商店,仅在客户端证书上有所不同.我尽量避免使用不同的信任/密钥库,但这应该没问题,对吧?

So lets say, i have a store for client and server only differing in the client cert. I tried to avoid having different trust/keystores, but this should be fine, right?

几乎直接取自骆驼源示例,我在我的测试类中使用了这些方法:

Pretty much directly taken from camel source examples, i have this methods used in my test class:

private static SSLContextParameters defineClientSSLContextClientParameters() {

    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource(Thread.currentThread().getContextClassLoader().getResource("jsse/source.jks").toString());
    ksp.setPassword(PWD);

    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword(PWD);
    kmp.setKeyStore(ksp);

    TrustManagersParameters tmp = new TrustManagersParameters();
    tmp.setKeyStore(ksp);

    SSLContextServerParameters scsp = new SSLContextServerParameters();
    scsp.setClientAuthentication(ClientAuthentication.REQUIRE.name());

    SSLContextParameters sslContextParameters = new SSLContextParameters();
    sslContextParameters.setKeyManagers(kmp);
    sslContextParameters.setTrustManagers(tmp);
    sslContextParameters.setServerParameters(scsp);

    return sslContextParameters;
}

private static SSLContextParameters defineServerSSLContextParameters() {
       KeyStoreParameters ksp = new KeyStoreParameters();
       ksp.setResource(Thread.currentThread().getContextClassLoader().getResource("jsse/target.jks").toString());
       ksp.setPassword(PWD);

       KeyManagersParameters kmp = new KeyManagersParameters();
       kmp.setKeyPassword(PWD);
       kmp.setKeyStore(ksp);

       TrustManagersParameters tmp = new TrustManagersParameters();
       tmp.setKeyStore(ksp);

       SSLContextServerParameters scsp = new SSLContextServerParameters();
       scsp.setClientAuthentication(ClientAuthentication.REQUIRE.name());

       SSLContextParameters sslContextParameters = new SSLContextParameters();
       sslContextParameters.setKeyManagers(kmp);
       sslContextParameters.setTrustManagers(tmp);
       sslContextParameters.setServerParameters(scsp);


       return sslContextParameters;
}

@Override
protected RouteBuilder[] createRouteBuilders() throws Exception {
    RouteBuilder[] rbs = new RouteBuilder[2];

    // A protocol consumer
    rbs[0] = new RouteBuilder() {
        public void configure() {

            // Needed to configure TLS on the client side
            WsComponent wsComponent = (WsComponent) context.getComponent("protocolclient");
            wsComponent.setSslContextParameters(defineClientSSLContextClientParameters());

            from("direct:input").routeId("foo")
                .log(">>> Message from direct to WebSocket Client : ${body}")
                .to("protocolclient://localhost:9292/echo")
                .log(">>> Message from WebSocket Client to server: ${body}");
            }
    };

    // A protocol provider
    rbs[1] = new RouteBuilder() {
        public void configure() {

                // Needed to configure TLS on the server side
                WebsocketComponent websocketComponent = (WebsocketComponent) context.getComponent("protocolserver");
                websocketComponent.setSslContextParameters(defineServerSSLContextParameters());

                // This route is set to use TLS, referring to the parameters set above
                from("protocolserver:localhost:9292/echo")
                .log(">>> Message from WebSocket Server to mock: ${body}")
                .to("mock:result");
        }
    };
    return rbs;
}

为了完整起见,这里是我用来生成客户端证书的配置文件:

For completeness, here is the config file i used to generate the client certs:

HOME            = .
RANDFILE        = $ENV::HOME/.rnd

####################################################################
[ req ]
default_bits        = 2048
#default_keyfile     = client.key
distinguished_name  = client_distinguished_name
req_extensions      = client_req_extensions
string_mask         = utf8only

####################################################################
[ client_distinguished_name ]
countryName         = Country Name (2 letter code)
countryName_default     = DE

stateOrProvinceName     = State or Province Name (full name)
stateOrProvinceName_default = Bayern

localityName            = Locality Name (eg, city)
localityName_default        = Muenchen

organizationName         = Organization Name (eg, company)
organizationName_default    = Company

organizationalUnitName  = Organizational Unit Name (department, division)
organizationalUnitName_default  = Department

commonName          = Common Name (e.g. server FQDN or YOUR name)
commonName_default      = Test Client X

emailAddress            = Email Address
emailAddress_default        = stuff@mail.de


####################################################################
[ connector_req_extensions ]

subjectKeyIdentifier        = hash
basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment, nonRepudiation
extendedKeyUsage    = clientAuth
subjectAltName          = @alternate_names

[ alternate_names ]

DNS.1       = localhost
DNS.2       = 127.0.0.1
DNS.3       = client.companyname.de

我是否犯了一些明显的错误?我很困惑:(

Did i do some obvious mistake? I am quite puzzled :(

谢谢!

我添加了一些调试输出.这是应该的样子吗?

I added some debug output. Is this how it should look like?

keystore (...) has type [jks], and contains aliases [1].
***
found key for : 1
chain [0] = [
[
  Version: V3
  Subject: CN=cnname, OU=ouname, O=oname, L=location, ST=bavaria, C=DE
  Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11

  Key:  Sun RSA public key, 2048 bits
  modulus: 2999...
  public exponent: 65537
  Validity: [From: Wed Oct 19 10:16:33 CEST 2016,
               To: Fri Oct 19 10:16:33 CEST 2018]
  Issuer: CN=My SubCA 2016, O=organization, C=DE
  SerialNumber: [    01]

Certificate Extensions: 8
[1]: ObjectId: 1.3.6.1.5.5.7.1.1 Criticality=false
AuthorityInfoAccess [
  [
   accessMethod: caIssuers
   accessLocation: URIName: http://someurl
]
]

[2]: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 58 DD 29 BF F2 31 7B 34   3F F2 7D B5 1F 2B 7D A3  X.)..1.4?....+..
0010: EB 71 EC 62                                        .q.b
]
]

[3]: ObjectId: 2.5.29.19 Criticality=false
BasicConstraints:[
  CA:false
  PathLen: undefined
]

[4]: ObjectId: 2.5.29.31 Criticality=false
CRLDistributionPoints [
  [DistributionPoint:
     [URIName: http://crl.someurl.crl]
]]

[5]: ObjectId: 2.5.29.37 Criticality=false
ExtendedKeyUsages [
  clientAuth
]

[6]: ObjectId: 2.5.29.15 Criticality=false
KeyUsage [
  DigitalSignature
  Key_Encipherment
]

[7]: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
  DNSName: localhost
  DNSName: 127.0.0.1
]

[8]: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: F8 8E 73 ED 12 6A 61 2D   A0 7F 15 F9 9D 84 BD BF  ..s..ja-........
0010: 5E 96 B6 FF                                        ^...
]
]

]
  Algorithm: [SHA256withRSA]
  Signature:
...

]
***
...
12:32:55.621 [main] TRACE org.apache.camel.util.jsse.TrustManagersParameters - Creating TrustManager[] from TrustManagersParameters [TrustManagerType [keyStore=KeyStoreParameters [type=null, password=********, provider=null, resource=file:/home/gbrost/GIT/karaf-policy-platform/camel-ids/target/test-classes/jsse/source-truststore.jks, getContext()=null], provider=null, algorithm=null, getContext()=null]]
---
12:32:55.644 [main] DEBUG org.apache.camel.util.jsse.JsseParameters - Opened resource [file:/home/gbrost/GIT/karaf-policy-platform/camel-ids/target/test-classes/jsse/source-truststore.jks] as a URL.
...
keystore has type [jks], and contains aliases [ca, subca].
adding as trusted cert:
  Subject: CN=my Root CA 2016, O=organization, C=DE
  Issuer:  CN=my Root CA 2016, O=organization, C=DE
  Algorithm: RSA; Serial number: 0xfc8239c0355555c1
  Valid from Wed Oct 19 10:14:36 CEST 2016 until Tue Oct 14 10:14:36 CEST 2036

adding as trusted cert:
  Subject: CN=my SubCA 2016, O=Fraunhofer, C=DE
  Issuer:  CN=my Root CA 2016, O=Fraunhofer, C=DE
  Algorithm: RSA; Serial number: 0x1
  Valid from Wed Oct 19 10:14:38 CEST 2016 until Thu Oct 17 10:14:38 CEST 2024

12:32:55.649 [main] DEBUG org.apache.camel.util.jsse.TrustManagersParameters - TrustManager[] [[sun.security.ssl.X509TrustManagerImpl@6b5176f2]], initialized from TrustManagerFactory [javax.net.ssl.TrustManagerFactory@209775a9].
12:32:56.099 [main] DEBUG org.apache.camel.util.jsse.SSLContextParameters - 
...

推荐答案

我终于找到了解决方案.我只将调试设置为 SSL.这是我的错误.我需要将调试输出设置为全部".然后我可以看到此错误消息:

I finally found the solution. I only set debugging to SSL. This was my mistake. I would have needed to set the debug output to "all". Then i can see this error message:

引起:sun.security.validator.ValidatorException:扩展密钥用法不允许用于 TLS 服务器身份验证

Caused by: sun.security.validator.ValidatorException: Extended key usage does not permit use for TLS server authentication

这个更具体.为了解决这个问题,我确实需要将我的扩展密钥用法更改为:

This is much more specific. To fix that, indeed i needed to change my extended key usage to this:

keyUsage            = digitalSignature, keyEncipherment, nonRepudiation
extendedKeyUsage    = clientAuth, serverAuth

非常感谢!

这篇关于“无法找到到请求目标的有效认证路径"在 Camel 组件测试中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆