我正在做一个https帖子,我得到ssl异常的例外不可信服务器证书.如果我做正常的http它工作得很好.我必须以某种方式接受服务器证书吗?
我只是试图使用java keytool,但我无法弄清楚如何设置主机名.
这就是我尝试的方式:
hostname[username:/this/is/a/path][640]% keytool -keystore server.keystore -genkeypair -alias hostname
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  hostname
What is the name of your organizational unit?
  [Unknown]:  hostname
What is the name of your organization?
  [Unknown]:  hostname
What is the name of your City or Locality?
  [Unknown]:  hostname
What is the name of your State or Province?
  [Unknown]:  hostname
What is the two-letter country code for this unit?
  [Unknown]:  CA
Is CN=hostname, OU=hostname, …我正在尝试使用HTTPS与自签名证书的连接.
我按照这里提到的创建自签名证书的步骤 - 创建自签名证书.
即使在浏览器中一切正常,它只向我显示我的证书由未知CA签名的消息.
但是我的证书中的FQDN(服务器名称不匹配)名称有问题,因为我在生成证书时设置了错误的名称.
我已经重新生成它,现在没有这样的错误.   
我需要从移动Android客户端使用我的服务器sertificate,我找到了关于此问题的精彩文章 - 在Android中使用自签名或未知SSL证书的Retrofit.我已经遵循了所有步骤,但遗憾的是得到了一个错误(例外).
javax.net.ssl.SSLPeerUnverifiedException: Hostname 195.xx.xx.xx not verified:
    certificate: sha1/qvH7lFeijE/ZXxNHI0B/M+AU/aA=
    DN: 1.2.840.113549.1.9.1=#160e63726f73704078616b65702e7275,CN=195.xx.xx.xx,OU=Departament of Development,O=CROSP Solutions,L=Chernihiv,ST=Chernihiv,C=UA
    subjectAltNames: []
            at com.squareup.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:124)
正如您所看到的主机名相同,但仍然存在错误.
请帮忙处理这个问题,我将不胜感激任何帮助.
谢谢.
伪解决方案
当然我之前搜索过并找到了HostName Verifier Solution.
我试过了,它有效.但是可以使用这种解决方法,我将证书添加到我的应用程序中,以便像在前面的示例中一样动态地读取它,它是否仍然在这种情况下使用.     
OkHttp的解决方案是一行.(如果您按照教程中的所有步骤操作).
 okHttpClient.setHostnameVerifier(new NullHostNameVerifier());
但我还是觉得这不是最好的解决方案,请问有什么想法吗?
运行我的应用程序获取java.io.IOException:主机名未经验证,我该如何解决?
java.io.IOException: Hostname '178.61.62.140' was not verified
01-03 16:34:37.613: W/System.err(17118):    at libcore.net.http.HttpConnection.verifySecureSocketHostname(HttpConnection.java:224)
01-03 16:34:37.615: W/System.err(17118):    at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:454)
01-03 16:34:37.615: W/System.err(17118):    at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
01-03 16:34:37.616: W/System.err(17118):    at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
01-03 16:34:37.617: W/System.err(17118):    at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
01-03 16:34:37.617: W/System.err(17118):    at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:194)
01-03 16:34:37.618: W/System.err(17118):    at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:280)
01-03 16:34:37.618: W/System.err(17118):    at com.axis.cbk.httpmodel.CustHttpClient.executeHttpPost(CustHttpClient.java:120)
01-03 16:34:37.619: W/System.err(17118):    at com.axis.cbk.MainActivity$ProcessIt.doInBackground(MainActivity.java:237)
01-03 16:34:37.619: W/System.err(17118):    at com.axis.cbk.MainActivity$ProcessIt.doInBackground(MainActivity.java:1)
01-03 16:34:37.621: W/System.err(17118):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-03 16:34:37.626: W/System.err(17118):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-03 16:34:37.626: W/System.err(17118):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-03 16:34:37.627: W/System.err(17118):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
01-03 16:34:37.628: W/System.err(17118): …我在发出齐射请求时偶尔会遇到此错误。这很奇怪,因为它有时会起作用,有时则不起作用。
com.android.volley.NoConnectionError: java.io.IOException: Hostname '--url--' was not verified
根据这个: http: //developer.android.com/training/articles/security-ssl.html它与主机名验证有关,但我的 API 调用始终在浏览器上工作,就像我之前提到的,有时通过凌空抽射。
有谁之前经历过这个吗?
我在这里看到过类似的问题,但没有一个与 Volley 有关。它们基本上都指向使用 NullHostNameVerifier ( java.io.IOException: Hostname was not verify ),我不知道是否可以在 Volley 上完成...
初始化Parse时Android,我能够在以下情况下成功连接到Parse服务器:
1)我没有指定服务器URL,或者
2)我将服务器URL设置为Parse服务器.
因为我们打算最终将数据从Parse迁移到不同的主机,所以我们希望连接到不同的服务器URL.但是,当我尝试指定一个不同的服务器URL(https://api.ourhostname.com/1/)重定向(充当代理)到Parse服务器时,该应用程序无法完全连接到服务器.从iOS项目实现时,此服务器URL工作正常.但是,在Android等效项上实现时:
Parse.initialize(new Parse.Configuration.Builder(this)
        .applicationId(APP_ID)
        .clientKey(CLIENT_KEY)
        .server("https://api.ourhostname.com/1/")
        .build()
    );
我收到i/o失败:
05-24 21:46:55.319 7140-7140/com.ourapp W/System.err: com.parse.ParseRequest$ParseRequestException: i/o failure
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:290)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at com.parse.ParseRequest$2.then(ParseRequest.java:145)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at com.parse.ParseRequest$2.then(ParseRequest.java:139)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at bolts.Task$15.run(Task.java:917)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err:     at java.lang.Thread.run(Thread.java:818)
05-24 21:46:55.324 7140-7140/com.ourapp W/System.err: Caused by: javax.net.ssl.SSLPeerUnverifiedException: Cannot verify hostname: api.ourhostname.com
05-24 21:46:55.329 …android ×5
java ×3
https ×2
ssl ×2
certificate ×1
hostname ×1
keytool ×1
okhttp ×1
web-services ×1