最近发布了一个关于HttpClient过度Https 的问题(在这里找到).我已经取得了一些进展,但我遇到了新的问题.和我的上一个问题一样,我似乎无法找到适合我的任何地方的例子.基本上,我希望我的客户端接受任何证书(因为我只指向一个服务器),但我一直在接受javax.net.ssl.SSLException: Not trusted server certificate exception.
所以这就是我所拥有的:
public void connect() throws A_WHOLE_BUNCH_OF_EXCEPTIONS {
HttpPost post = new HttpPost(new URI(PROD_URL));
post.setEntity(new StringEntity(BODY));
KeyStore trusted = KeyStore.getInstance("BKS");
trusted.load(null, "".toCharArray());
SSLSocketFactory sslf = new SSLSocketFactory(trusted);
sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme ("https", sslf, 443));
SingleClientConnManager cm = new SingleClientConnManager(post.getParams(),
schemeRegistry);
HttpClient client = new DefaultHttpClient(cm, post.getParams());
HttpResponse result = client.execute(post);
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
W/System.err( 901): javax.net.ssl.SSLException: Not trusted server certificate
W/System.err( 901): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:360)
W/System.err( 901): …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用HttpClientlib 进行HTTPS连接,但问题在于,由于证书未由Verisign,GlobalSIgn等公认的证书颁发机构(CA)签署,并列在Android受信任证书集上,我一直在javax.net.ssl.SSLException: Not trusted server certificate.
我已经看到了你只接受所有证书的解决方案,但如果我想询问用户该怎么办?
我想得到一个类似于浏览器的对话框,让用户决定是否继续.我最好使用与浏览器相同的证书库.有任何想法吗?
我正在与客户端证书身份验证进行斗争.当服务器需要凭证(在这种情况下是证书)时,从NSURLConnection委托调用此方法:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Run Code Online (Sandbox Code Playgroud)
我想从文件加载证书,填写凭证并运行此方法:
[[challenge sender] useCredential:[self credential] forAuthenticationChallenge:challenge];
Run Code Online (Sandbox Code Playgroud)
但我不知道如何初始化(或填充)SecIdentityRef参数.这是我创建凭据的代码:
NSString *certPath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"cer"];
NSData *certData = [[NSData alloc] initWithContentsOfFile:certPath];
SecIdentityRef myIdentity; // ???
SecCertificateRef myCert = SecCertificateCreateWithData(NULL, (CFDataRef)certData);
[certData release];
SecCertificateRef certArray[1] = { myCert };
CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
CFRelease(myCert);
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity
certificates:(NSArray *)myCerts
persistence:NSURLCredentialPersistencePermanent];
CFRelease(myCerts);
Run Code Online (Sandbox Code Playgroud)
有人知道怎么解决吗?谢谢.
我终于找到了解决方案,但是这里出现了一个新问题:
我的客户端不会将证书发送到服务器.服务器请求证书后,应用程序运行此方法:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Run Code Online (Sandbox Code Playgroud)
并填写凭证(如上所述),但连接以错误结束:NSURLErrorDomain -1206.根据服务器日志,应用程序不会发送客户端证书.
有没有人有这种行为的经验?我是否需要以某种方式验证应用程序中的证书?或其他任何使其有效的方法?如果它有帮助,我可以提供我当前的代码.谢谢你的任何想法......
我正在开发一个iPhone应用程序,我需要从iPhone向服务器发送一些数据(XML格式),在服务器端,我将解析该XML并获取每个XML节点的数据,而不是按照我的要求使用它们.
我的问题是:
我将使用哪种方法.
此致,Pratik
ssl ×3
certificate ×2
https ×2
iphone ×2
android ×1
ca ×1
httpclient ×1
java ×1
web-services ×1
xml ×1