I am trying to implement a HTTPS connection in a self-signed Tomcat 8.5 server. I have spent two days trying to find the bug (thinking that It is related to the certificates).
My code to do my GET operation is very simple:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("https://myIpServer:8443");
HttpResponse response = client.execute(get);
It is added in an InstrumentTestCase2
test which it is linked to my MainActivity
(It does other things, but no related to a HTTP connection so It should not give problems)
I am receiving this error:
02-13 10:37:36.033 6215 6246 W System : ClassLoader referenced unknown path: /system/framework/tcmclient.jar
02-13 10:37:36.186 788 3961 I ActivityManager: Killing 6188:com.tumblr/u0a111 (adj 15): empty #17
02-13 10:37:36.266 788 3961 I ActivityManager: Killing 6161:com.android.keychain/1000 (adj 15): empty #18
02-13 10:37:36.323 788 3704 D GraphicsStats: Buffer count: 9
02-13 10:37:36.324 788 3704 I WindowState: WIN DEATH: Window{997cc4d u0 gasnatural.appcountermanager/myapp.main.MainActivity}
And the server certificates seem correct:
openssl s_client -connect myIpServer:8443
CONNECTED(00000003)
depth=0 C = XXX, ST = XXX, L = XXX, O = XXX, OU = XXX, CN = XXX
verify error:num=18:self signed certificate
verify return:1
depth=0 C = XXX, ST = XXX, L = XXX, O = XXX, OU = XXX, CN = XXX
verify return:1
---
Certificate chain
0 s:/C=XXX/ST=XXX/L=XXX/O=XXX/OU=XXX/CN=XXX
i:/C=XXX/ST=XXX/L=XXX/O=XXX/OU=XXX/CN=XXX
---
---
Server certificate
-----BEGIN CERTIFICATE-----
My certificate hash
-----END CERTIFICATE-----
subject=/C=XXX/ST=XXX/L=XXX/O=XXX/OU=XXX/CN=XXX
issuer=/C=XXX/ST=XXX/L=XXX/O=XXX/OU=XXX/CN=XXX
---
No client certificate CA names sent
---
SSL handshake has read 1499 bytes and written 501 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES128-GCM-SHA256
Session-ID: a_long_id_number
Session-ID-ctx:
Master-Key: a_long_id_number
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1486978425
Timeout : 300 (sec)
Verify return code: 18 (self signed certificate)
---
My server works fine for HTTP in 8080. Also, I tested another self-signed web, and the previous pasted code connect without problems...
UPDATE1:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gasnatural.appcountermanager">
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".listconcentrators.ListConcentratorsActivity" android:screenOrientation="portrait"/>
<activity android:name=".informationconcentrator.InformationConcentratorActivity" android:screenOrientation="portrait"/>
<activity android:name=".newconcentrator.NewConcentratorActivity" android:screenOrientation="portrait"/>
<activity android:name=".listcameras.ListCamerasActivity" android:screenOrientation="portrait"/>
<activity android:name=".configurecamera.ConfigureCameraActivity" android:screenOrientation="portrait"/>
<activity android:name=".mock.MockTestActivity" android:screenOrientation="portrait"/>
<activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:name=".drawrectangle.DrawRectangleActivity" />
<service android:name="gasnatural.appcountermanager.bluetooth.BTService"
android:enabled="true"
android:exported="false">
</service>
</application>
</manifest>
Comment: (I know, self-signed is insecure, but It is a prototype for our company, for a possible future production version It will be well-configured)