我正在使用 ReSTLet 2.0.8 和简单设置:
component = new Component();
component.getClients().add(Protocol.FILE);
Server httpsServer = component.getServers().add(Protocol.HTTPS, 444);
Series<Parameter> parameters = httpsServer.getContext().getParameters();
File pwd = new File(".");
String path = pwd.getCanonicalPath();
String keystorePath = path + "/keystore/keypair.jks";
parameters.add("SSLContextFactory", "org.restlet.ext.ssl.PkixSslContextFactory");
parameters.add("keystorePath", keystorePath);
parameters.add("keystorePassword", "xxx");
parameters.add("keyPassword", "xxx");
parameters.add("keystoreType", "JKS");
parameters.add("threadMaxIdleTimeMs", "60000"); //default idle time
parameters.add("needClientAuthentication", "true");
// Guard the restlet with BASIC authentication (encrypted under SSL).
ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "xxx");
//new pagerreceiver
Restlet resty = new PagerReceiverApplication();
LoginChecker loginVerifier = new LoginChecker();
guard.setVerifier(loginVerifier);
guard.setNext(resty);
component.getDefaultHost().attachDefault(guard);
overrideStatus statusService = new overrideStatus();
component.setStatusService(statusService);
component.start();
SSL 工作正常,但它接受任何连接,无论它们是否有客户端证书!这里到底发生了什么,我错过了什么吗?
最佳答案
一段时间,直到this patch in the Simple Framework (rev. 1785) , Simple 总是使用“想要客户端身份验证”,没有任何方式配置它(“需要”或“无”)。
因此,Simple ReSTLet 连接器的needClientAuthentication
参数从未得到支持,因为 ReSTLet 连接器本身无法更改此行为。
据我所知,Simple rev. 1785 只删除任何形式的客户端身份验证(没有“需要”或“想要”)。我不确定 ReSTLet 2.0.8 是否使用此补丁之前或之后的 Simple 版本,但迄今为止,似乎没有任何东西提供此支持。
这里有关于此主题的简单邮件列表的讨论:
- > http://sourceforge.net/mailarchive/message.php?msg_id=24865296
- > http://sourceforge.net/mailarchive/message.php?msg_id=25704572
有一些解决方法:
- 为您的 ReSTLet 应用程序使用与 Simple 不同的连接器。其他的应该支持
needClientAuthentication
。 - 继续使用
wantClientAuthentication
(前提是是打过补丁的Simple版本),检查是否确实有证书,否则禁止请求。 (我认为 IIS 就是这样做的,即使它“需要”证书也是如此。)
作为旁注,查看您的代码,我不确定您为什么要坚持要求客户端同时提供客户端证书和 HTTP 基本身份验证凭据。基本授权在客户端证书之上似乎有点矫枉过正。
关于authentication - ReSTLet with Simple - 尽管 needClientAuthentication 设置为 true,它接受任何没有客户端证书的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481656/