From: rtrimana Date: Thu, 1 Feb 2018 22:37:32 +0000 (-0800) Subject: Reverting local HTTP gateway back from HTTPS to HTTP; there was a change regarding... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=58404eb06e020d4920832fc2bf3b55c4c54a866e;p=iot2.git Reverting local HTTP gateway back from HTTPS to HTTP; there was a change regarding TLS contexts for user added CAs - this disrupts our self-signed certificate scheme; see https://github.com/owntracks/android/issues/481; the phone side at this point uses Android Studio 3.0.1 and the app runs on Nexus 5X running Android 7.1.2 --- diff --git a/benchmarks/drivers/Java/GPSPhoneGateway/GPSPhoneGateway.java b/benchmarks/drivers/Java/GPSPhoneGateway/GPSPhoneGateway.java index 404292b..7f401ae 100644 --- a/benchmarks/drivers/Java/GPSPhoneGateway/GPSPhoneGateway.java +++ b/benchmarks/drivers/Java/GPSPhoneGateway/GPSPhoneGateway.java @@ -83,10 +83,17 @@ public class GPSPhoneGateway implements GPSGateway { // Launch IoTRemoteCall server in a separate thread workerThread = new Thread(new Runnable() { + /* TODO: We revert back to HTTP because of new scheme for TLS context in Android 7 + This disrupts the usual setting for self-signed certificate + See this link for more info: https://github.com/owntracks/android/issues/481 public void run() { iotRemCall = new IoTRemoteCall(PhoneInfoInterface.class, phoneInfo, iotDevAdd.getDestinationPortNumber(), IoTDeviceAddress.getLocalHostAddress()); + }*/ + public void run() { + iotRemCall = new IoTRemoteCall(PhoneInfoInterface.class, + phoneInfo, iotDevAdd.getDestinationPortNumber()); } }); workerThread.start(); diff --git a/benchmarks/drivers/Java/WeatherPhoneGateway/WeatherPhoneGateway.java b/benchmarks/drivers/Java/WeatherPhoneGateway/WeatherPhoneGateway.java index 50b4450..7ac5b85 100644 --- a/benchmarks/drivers/Java/WeatherPhoneGateway/WeatherPhoneGateway.java +++ b/benchmarks/drivers/Java/WeatherPhoneGateway/WeatherPhoneGateway.java @@ -101,10 +101,17 @@ public class WeatherPhoneGateway implements WeatherGateway { // Launch IoTRemoteCall server in a separate thread workerThread = new Thread(new Runnable() { + /* TODO: We revert back to HTTP because of new scheme for TLS context in Android 7 + This disrupts the usual setting for self-signed certificate + See this link for more info: https://github.com/owntracks/android/issues/481 public void run() { iotRemCall = new IoTRemoteCall(WeatherInfoInterface.class, weatherInfo, iotDevAdd.getDestinationPortNumber(), IoTDeviceAddress.getLocalHostAddress()); + }*/ + public void run() { + iotRemCall = new IoTRemoteCall(WeatherInfoInterface.class, + weatherInfo, iotDevAdd.getDestinationPortNumber()); } }); workerThread.start(); diff --git a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/Helper.java b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/Helper.java index 2ff9b49..77f4ccf 100644 --- a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/Helper.java +++ b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/Helper.java @@ -10,7 +10,6 @@ import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; @@ -26,12 +25,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.BufferedInputStream; import java.util.List; -import java.security.cert.CertificateFactory; -import java.security.cert.Certificate; -import java.security.cert.X509Certificate; -import java.security.KeyStore; /** * Created by xubin on 4/26/16. @@ -39,16 +33,13 @@ import java.security.KeyStore; public class Helper { private static final int Driver_port = 8000; private static final String Tag = "http"; - private static final String KEYEXT = ".pem"; HttpClient httpclient; //Set up - void setConnection(String destIP) { - - httpclient = createClient(destIP); + void setConnection() { + httpclient = createClient(); } - - HttpClient createClient(String destIP) { + HttpClient createClient() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET); @@ -58,22 +49,21 @@ public class Helper { SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Driver_port)); - schReg.register(new Scheme("https", newSslSocketFactory(destIP), 443)); + //schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(conMgr, params); } - //Make http request public void makeRequest(String destIP, List paramObjects, String methodName) { - String url = "https://"+ destIP + ":"+Driver_port+ "/"+methodName; - System.out.println("URL: " + url); + String url = "http://"+ destIP + ":"+Driver_port+ "/"+methodName; InputStream inputStream = null; String result = ""; try { HttpPost httpPost = new HttpPost(url); JSONArray params = new JSONArray(); + JSONObject parent = new JSONObject(); for (int i = 0; i < paramObjects.size(); i++) { JSONObject content = new JSONObject(); @@ -103,31 +93,6 @@ public class Helper { ex.printStackTrace(); } } - - private SSLSocketFactory newSslSocketFactory(String destIP) { - try { - // Load CAs from an InputStream - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - InputStream caInput = new - BufferedInputStream(MainActivity.context.getAssets().open(destIP + KEYEXT)); - Certificate ca; - try { - ca = cf.generateCertificate(caInput); - System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN()); - } finally { - caInput.close(); - } - String keyStoreType = KeyStore.getDefaultType(); - KeyStore keyStore = KeyStore.getInstance(keyStoreType); - keyStore.load(null, null); - keyStore.setCertificateEntry("ca", ca); - SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore); - return socketFactory; - } catch (Exception e) { - throw new AssertionError(e); - } - } - private static String convertInputStreamToString(InputStream inputStream) throws IOException { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream)); String line = ""; diff --git a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/MainActivity.java b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/MainActivity.java index 65c7c34..ba573ec 100644 --- a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/MainActivity.java +++ b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/MainActivity.java @@ -11,20 +11,17 @@ import android.view.Menu; import android.view.MenuItem; import android.widget.Button; import android.widget.EditText; -import android.content.Context; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { - private EditText gatewayIP; private EditText inchesPerWeek; private EditText weatherZipCode; private EditText daysToWaterOn; private EditText inchesPerMinute; private Button submit_button; - protected static Context context; private Helper helper = new Helper(); @Override @@ -33,8 +30,6 @@ public class MainActivity extends AppCompatActivity { setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - context = getApplicationContext(); - gatewayIP = (EditText) findViewById(R.id.gatewayip); inchesPerWeek = (EditText) findViewById(R.id.week); weatherZipCode = (EditText) findViewById(R.id.zip); daysToWaterOn = (EditText) findViewById(R.id.water); @@ -50,7 +45,7 @@ public class MainActivity extends AppCompatActivity { params.add(Integer.parseInt(daysToWaterOn.getText().toString())); params.add(Double.parseDouble(inchesPerMinute.getText().toString())); - String ip = gatewayIP.getText().toString(); + String ip = getApplicationContext().getResources().getString(R.string.destination_ip); new MakeRequestTask(params).execute(ip, "getIrrigationInfo"); } @@ -65,7 +60,6 @@ public class MainActivity extends AppCompatActivity { }); } - @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -95,11 +89,9 @@ public class MainActivity extends AppCompatActivity { @Override protected Void doInBackground(String... argus) { if (helper.httpclient == null) { - helper.setConnection(argus[0]); + helper.setConnection(); } - helper.makeRequest(argus[0],params, argus[1]); - return null; } } diff --git a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/layout/content_main.xml b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/layout/content_main.xml index 53eecbf..facc2b0 100644 --- a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/layout/content_main.xml +++ b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/layout/content_main.xml @@ -129,5 +129,5 @@ android:layout_weight="1" android:ems="10" android:inputType="number|numberDecimal" - android:text="192.168.0.84" /> + android:text="192.168.2.191" /> diff --git a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/values/strings.xml b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/values/strings.xml index 56f8e53..2b20a3d 100644 --- a/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/values/strings.xml +++ b/benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ Irrigation Settings - 192.168.2.244 + 192.168.2.191 diff --git a/benchmarks/other/PhoneInterface/Irrigation/build.gradle b/benchmarks/other/PhoneInterface/Irrigation/build.gradle index c2eea8e..a47fa4b 100644 --- a/benchmarks/other/PhoneInterface/Irrigation/build.gradle +++ b/benchmarks/other/PhoneInterface/Irrigation/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/benchmarks/other/PhoneInterface/Irrigation/gradle/wrapper/gradle-wrapper.properties b/benchmarks/other/PhoneInterface/Irrigation/gradle/wrapper/gradle-wrapper.properties index 39c4280..7041afd 100644 --- a/benchmarks/other/PhoneInterface/Irrigation/gradle/wrapper/gradle-wrapper.properties +++ b/benchmarks/other/PhoneInterface/Irrigation/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jan 16 09:22:38 PST 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +#Fri Jan 19 14:40:37 PST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar b/benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar new file mode 100644 index 0000000..21ca4c0 Binary files /dev/null and b/benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar differ diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/app/build.gradle b/benchmarks/other/PhoneInterface/SpeakerLocator/app/build.gradle index d56e243..b860e1c 100644 --- a/benchmarks/other/PhoneInterface/SpeakerLocator/app/build.gradle +++ b/benchmarks/other/PhoneInterface/SpeakerLocator/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion '25.0.0' + buildToolsVersion '26.0.2' useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "com.example.xub3.speakerlocator" @@ -25,6 +25,7 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:design:23.3.0' - compile files('Libs/indoor-positioning-1.0.jar') + compile files('Libs/indoor-positioning-1.1.jar') compile 'com.google.android.gms:play-services-appindexing:8.1.0' + implementation files('Libs/indoor-positioning-1.1.jar') } diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/Helper.java b/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/Helper.java index c599781..0d57b85 100644 --- a/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/Helper.java +++ b/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/Helper.java @@ -37,105 +37,78 @@ import java.security.cert.X509Certificate; * Created by xub3 on 4/14/16. */ public class Helper { - private static final int Driver_port = 8000; - private static final String Tag = "CallReceiver"; - private static final String KEYEXT = ".pem"; - HttpClient httpclient; - //Set up - //Set up - void setConnection(String destIP) { - - httpclient = createClient(destIP); - } - - HttpClient createClient(String destIP) { - HttpParams params = new BasicHttpParams(); - params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); - params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET); - params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); - params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30 * 1000); - params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 30 * 1000); - - SchemeRegistry schReg = new SchemeRegistry(); - schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Driver_port)); - schReg.register(new Scheme("https", newSslSocketFactory(destIP), 443)); - ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); - - return new DefaultHttpClient(conMgr, params); - } - - private SSLSocketFactory newSslSocketFactory(String destIP) { - try { - // Load CAs from an InputStream - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - InputStream caInput = new - BufferedInputStream(MainActivity.context.getAssets().open(destIP + KEYEXT)); - Certificate ca; - try { - ca = cf.generateCertificate(caInput); - System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN()); - } finally { - caInput.close(); - } - String keyStoreType = KeyStore.getDefaultType(); - KeyStore keyStore = KeyStore.getInstance(keyStoreType); - keyStore.load(null, null); - keyStore.setCertificateEntry("ca", ca); - SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore); - return socketFactory; - } catch (Exception e) { - throw new AssertionError(e); - } - } - - //Make http request - public void makeRequest(String destIP, Object contentStr, String methodName) { - String url = "https://"+ destIP+":" + Driver_port + "/"+methodName; - System.out.println("URL: " + url); - - InputStream inputStream = null; - String result = ""; - StringBuilder sb = new StringBuilder(); - try { - HttpPost httpPost = new HttpPost(url); - JSONArray params = new JSONArray(); - - JSONObject content = new JSONObject(); - JSONObject parent = new JSONObject(); - content.put("type", contentStr.getClass().getName()); - content.put("value", contentStr); - params.put(0,content); - parent.put("params", params); - StringEntity se = new StringEntity(parent.toString()); - httpPost.setEntity(se); - httpPost.setHeader("Accept", "application/json"); - httpPost.setHeader("Content-type", "application/json"); - HttpResponse httpResponse = httpclient.execute(httpPost); - // 9. receive response as inputStream - inputStream = httpResponse.getEntity().getContent(); - - // 10. convert inputstream to string - if(inputStream != null) - result = convertInputStreamToString(inputStream); - else - result = "Did not work!"; - Log.v(Tag, result); - } catch (Exception ex) { - if (ex.getMessage() != null) { - Log.v(Tag, ex.getMessage()); - } - ex.printStackTrace(); - } - } - private static String convertInputStreamToString(InputStream inputStream) throws IOException{ - BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream)); - String line = ""; - String result = ""; - while((line = bufferedReader.readLine()) != null) - result += line; - - inputStream.close(); - return result; - } + private static final int Driver_port = 8000; + private static final String Tag = "CallReceiver"; + HttpClient httpclient; + //Set up + void setConnection() { + httpclient = createClient(); + } + HttpClient createClient() { + HttpParams params = new BasicHttpParams(); + params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); + params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET); + params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); + params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30 * 1000); + params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 30 * 1000); + + SchemeRegistry schReg = new SchemeRegistry(); + schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 8000)); + ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); + + return new DefaultHttpClient(conMgr, params); + } + + //Make http request + public void makeRequest(String destIP, Object contentStr, String methodName) { + String url = "http://"+ destIP+":" + Driver_port + "/"+methodName; + + + InputStream inputStream = null; + String result = ""; + StringBuilder sb = new StringBuilder(); + try { + HttpPost httpPost = new HttpPost(url); + JSONArray params = new JSONArray(); + + JSONObject content = new JSONObject(); + JSONObject parent = new JSONObject(); + content.put("type", contentStr.getClass().getName()); + content.put("value", contentStr); + params.put(0,content); + parent.put("params", params); + StringEntity se = new StringEntity(parent.toString()); + httpPost.setEntity(se); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + HttpResponse httpResponse = httpclient.execute(httpPost); + // 9. receive response as inputStream + inputStream = httpResponse.getEntity().getContent(); + + // 10. convert inputstream to string + if(inputStream != null) + result = convertInputStreamToString(inputStream); + else + result = "Did not work!"; + Log.v(Tag, result); + } catch (Exception ex) { + if (ex.getMessage() != null) { + Log.v(Tag, ex.getMessage()); + } + ex.printStackTrace(); + } + } + + private static String convertInputStreamToString(InputStream inputStream) throws IOException{ + BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream)); + String line = ""; + String result = ""; + while((line = bufferedReader.readLine()) != null) + result += line; + + inputStream.close(); + return result; + + } } diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/MainActivity.java b/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/MainActivity.java index a8b6b92..a12a1f7 100644 --- a/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/MainActivity.java +++ b/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/MainActivity.java @@ -67,9 +67,9 @@ public class MainActivity extends AppCompatActivity implements PositionListener initializePositioning(); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); tv = (TextView) findViewById(R.id.hellotext); -// if (helper.httpclient == null) { -// helper.setConnection(getApplicationContext().getResources().getString(R.string.gateway_ip)); -// } + if (helper.httpclient == null) { + helper.setConnection(); + } fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -120,7 +120,7 @@ public class MainActivity extends AppCompatActivity implements PositionListener File file = new File(Environment.getExternalStorageDirectory(), "positioningPersistence.xml"); try { positionManager = new PositionManager(file); - //Log.d("positionManager", "initialized"); + Log.d("positionManager", "initialized"); //System.out.println("PositionManager: Initialized successfully!"); } catch (PositioningPersistenceException e) { e.printStackTrace(); diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/res/values/strings.xml b/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/res/values/strings.xml index c87cf7f..d05272a 100644 --- a/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/res/values/strings.xml +++ b/benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ SpeakerLocator Settings - 192.168.0.84 + 192.168.2.191 b0:b9:8a:73:69:f4 b0:b9:8a:73:69:f3 00:24:98:9a:92:ef diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/build.gradle b/benchmarks/other/PhoneInterface/SpeakerLocator/build.gradle index c2eea8e..a47fa4b 100644 --- a/benchmarks/other/PhoneInterface/SpeakerLocator/build.gradle +++ b/benchmarks/other/PhoneInterface/SpeakerLocator/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/gradle/wrapper/gradle-wrapper.properties b/benchmarks/other/PhoneInterface/SpeakerLocator/gradle/wrapper/gradle-wrapper.properties index 1dd327c..f1a51cd 100644 --- a/benchmarks/other/PhoneInterface/SpeakerLocator/gradle/wrapper/gradle-wrapper.properties +++ b/benchmarks/other/PhoneInterface/SpeakerLocator/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jan 16 09:33:57 PST 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +#Fri Jan 19 15:48:36 PST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/iotjava/iotruntime/stub/IoTRemoteCall.java b/iotjava/iotruntime/stub/IoTRemoteCall.java index 0b261ff..359b875 100644 --- a/iotjava/iotruntime/stub/IoTRemoteCall.java +++ b/iotjava/iotruntime/stub/IoTRemoteCall.java @@ -4,23 +4,13 @@ package iotruntime.stub; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; -import com.sun.net.httpserver.HttpsServer; -import com.sun.net.httpserver.HttpsConfigurator; -import com.sun.net.httpserver.HttpsParameters; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; -import java.security.KeyStore; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLParameters; -import javax.net.ssl.TrustManagerFactory; import java.lang.Class; import java.lang.reflect.*; @@ -51,77 +41,33 @@ public class IoTRemoteCall { final private Class _interface; final private Object _callback; final private int iPort; - final private String strAddress; private static final Logger logger = Logger.getLogger(IoTRemoteCall.class.getName()); /** * IoTRemoteCall class constants */ private final String USER_AGENT = "Mozilla/5.0"; - private final String PASSWORD = "password"; - private final String KEYEXT = ".jks"; - private final String KEYTYPE = "SunX509"; - private final String KEYINSTANCE = "JKS"; /** * Constructor */ - public IoTRemoteCall(Class _interface, Object _callback, int _iPort, String _strAddress) { + public IoTRemoteCall(Class _interface, Object _callback, int iPort) { - this._interface = _interface; - this._callback = _callback; - this.iPort = _iPort; - this.strAddress = _strAddress; - startHttpsServer(); + this._interface=_interface; + this._callback=_callback; + this.iPort=iPort; + startHttpServer(); } /** * Get Objects from a HTTP request */ - private void startHttpsServer() { + private void startHttpServer() { // Run a separate thread as the HTTP server IncomingMessageHandler imh=new IncomingMessageHandler(_interface, _callback); try { - HttpsServer server = HttpsServer.create(new InetSocketAddress(iPort), 0); - SSLContext sslContext = SSLContext.getInstance("TLS"); - - // initialise the keystore - char[] password = PASSWORD.toCharArray(); - KeyStore ks = KeyStore.getInstance(KEYINSTANCE); - FileInputStream fis = new FileInputStream(strAddress + KEYEXT); - ks.load(fis, password); - - // setup the key manager factory - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEYTYPE); - kmf.init(ks, password); - - // setup the trust manager factory - TrustManagerFactory tmf = TrustManagerFactory.getInstance(KEYTYPE); - tmf.init(ks); - - // setup the HTTPS context and parameters - sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); - server.setHttpsConfigurator(new HttpsConfigurator(sslContext) { - public void configure(HttpsParameters params) { - try { - // initialise the SSL context - SSLContext c = SSLContext.getDefault(); - SSLEngine engine = c.createSSLEngine(); - params.setNeedClientAuth(false); - params.setCipherSuites(engine.getEnabledCipherSuites()); - params.setProtocols(engine.getEnabledProtocols()); - - // get the default parameters - SSLParameters defaultSSLParameters = c.getDefaultSSLParameters(); - params.setSSLParameters(defaultSSLParameters); - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); - + HttpServer server = HttpServer.create(new InetSocketAddress(iPort), 0); // Context name is according to method name, e.g. getRingStatus Class inter=_interface; for (Method m:inter.getDeclaredMethods()) { @@ -129,7 +75,7 @@ public class IoTRemoteCall { } server.setExecutor(null); // creates a default executor server.start(); - } catch (Exception ex) { + } catch (IOException ex) { ex.printStackTrace(); } } @@ -169,7 +115,6 @@ public class IoTRemoteCall { System.out.println(uri); try { String strJSONString = sbResponse.toString(); - System.out.println(strJSONString); Class[][] cr = new Class[1][]; Object[] params = decodeJSONArray(strJSONString,cr); @@ -457,13 +402,14 @@ public class IoTRemoteCall { + /* TODO: Uncomment this if we want to do HTTP gateway test public static void main(String[] args) throws Exception { Fooimpl fooimp = new Fooimpl(); //IoTRemoteCall iotremcall = new IoTRemoteCall(foo.class, new Fooimpl(), 8000); new Thread() { public void run() { - IoTRemoteCall iotremcall = new IoTRemoteCall(foo.class, fooimp, 8000, "192.168.2.244"); + IoTRemoteCall iotremcall = new IoTRemoteCall(foo.class, fooimp, 8000); } }.start(); System.out.println("server has started!"); @@ -477,5 +423,6 @@ public class IoTRemoteCall { // } //} - } + }*/ } +