我很难使用API<21连接到我的NGINX服务器。这里的所有结果均来自API 19模拟设备。
我尝试使用在其他地方建议的VolleyToolboxExtension
和NoSSLv3Factory
,但仍然存在如下的严重错误,除非那样而不是sslv3是TLSV1。
我当前的方法是让旧的Android版本通过SSLV33。但这仍然会产生以下错误。
注意:我知道SSLV3已损坏,但我使用的是其他证书,但我没有发送任何相关的安全性。整个想法是进行调查,以便我可以决定是否要放弃对较旧的Android SDK版本的支持。
error during request: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb8a45890: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x8d959990:0x00000000)
我正在使用以下代码进行连接:
final String url;
if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ){
url = "https://abc.badssl.example.com";
} else {
url = "https://abc.example.com";
}
final JSONObject jsonBody;
try {
jsonBody = new JSONObject("{"api":" + Build.VERSION.SDK_INT + "}");
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url,
jsonBody,
response -> {
try {
Log.d(TAG, "Response is: " + response.getInt("api"));
} catch (JSONException e) {
Log.wtf(TAG, e);
}
wasRunning = true;
loading.postValue(false);
}, e -> {
Log.e(TAG, "error during request: " + e.getMessage());
error.postValue(true);
});
jsonObjectRequest.setShouldCache(false);
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.getCache().clear();
queue.add(jsonObjectRequest);
} catch (JSONException e) {
Log.wtf(TAG, e);
}
这是我的nginx配置,用于abc.badssl.example.com,使用其他证书:
listen 443 ssl;
server_name abc.badssl.example.com;
ssl on;
ssl_protocols SSLv3;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
#worker shared ssl cache
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_ciphers 'ECDHE-ECDSA-AES256-SHA:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:!DHE-RSA-AES256-SHA256:!DHE-RSA-AES128-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!DHE-RSA-DES-CBC-SHA:!DHE-RSA-CAMELLIA256-SHA:!DHE-RSA-CAMELLIA128-SHA:!DHE-DSS-CBC-SHA:!DHE-RSA-DES-CBC3-SHA';
fastcgi_param HTTPS on;
我认为我的nginx参数错误,但我似乎找不到太多,因为99%是关于禁用sslv3或与当前版本的凌空有关(so中的死链接)。
好的,因此解决方案有些不同。
首先:SSLV3在Debian&amp;出于明显的原因,ubuntu在当前版本的OpenSSL中。有趣的是,这不会丢弃任何错误,nginx configuraton协议被简单地忽略了吗?即使在配置中只有SSLV3,我仍然可以通过TLS1.X连接到服务器。NMAP报告相同的。
在Android&lt上;21(如其他答案中所述)TLS存在,但SSLV3优先甚至强制。
在较旧设备上获得工作的HttpSurlConnection的最简单解决方案是使用NetCipher。
build.gradle:
implementation "info.guardianproject.netcipher:netcipher:2.0.0-alpha1"
然后使用NetCipher创建HTTPS连接。
您也可以通过使用自定义的HTTPSTACK将其与凌空合使用。请注意,NetCipher的 strongbuilders并不是为了建立简单的HTTPS连接!它们仅是为了通过TOR网络建立连接。因此,不要愚弄您以为您可以使用它们来避免httpstack。
使用RAW HTTPSURLCONNECTION,RAW的请求处理程序没有射线,将其删除:
final String url = "https://asd.example.com";
runner = new Thread(() -> {
final JSONObject jsonBody;
try {
HttpsURLConnection con = NetCipher.getHttpsURLConnection(new URL(url));
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
con.setDoInput(true);
jsonBody = new JSONObject("{"api":" + Build.VERSION.SDK_INT + "}");
OutputStream wr = con.getOutputStream();
wr.write(jsonBody.toString().getBytes("UTF-8"));
wr.flush();
wr.close();
InputStream in = new BufferedInputStream(con.getInputStream());
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
JSONObject jsonObject = new JSONObject(result.toString("UTF-8"));
in.close();
con.disconnect();
Log.d(TAG,"received json: "+jsonObject.toString());
loading.postValue(false);
} catch (
Exception e) {
Log.wtf(TAG, e);
}
});
runner.start();