I am involved with my final year project and I try to connect my Android App with my remote MySQL server. One of the requirements is that the connection is encrypted. For this I have activated SSL on the MySQL server and I have generated a TrustStore.
I downloaded that TrustStore and added it to my project on android. From android I have the following code using the Connector / J that MySQL provides me:
try {
Class.forName(driver).newInstance();
conexion = DriverManager.getConnection(cadenaConexion, usuario, contrasena);
if (!conexion.isClosed()) {
Toast.makeText(ShowsEverywhereApplication.getContext(), "¡CONEXIÓN ESTABLECIDA CON LA BASE DE DATOS!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ShowsEverywhereApplication.getContext(), "¡La conexión no ha podido ser establecida...!", Toast.LENGTH_LONG).show();
}
} catch (InstantiationException e) {
Toast.makeText(ShowsEverywhereApplication.getContext(), "ERROR EN LA CONEXIÓN A LA BASE DE DATOS: " + e.getMessage(), Toast.LENGTH_LONG).show();
} catch (IllegalAccessException e) {
Toast.makeText(ShowsEverywhereApplication.getContext(), "ERROR EN LA CONEXIÓN A LA BASE DE DATOS: " + e.getMessage(), Toast.LENGTH_LONG).show();
} catch (ClassNotFoundException e) {
Toast.makeText(ShowsEverywhereApplication.getContext(), "ERROR EN LA CONEXIÓN A LA BASE DE DATOS: " + e.getMessage(), Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(ShowsEverywhereApplication.getContext(), "ERROR EN LA CONEXIÓN A LA BASE DE DATOS: \n" + e.getSQLState() + "\n\n" + "Código de error: " + e.getErrorCode(), Toast.LENGTH_LONG).show();
}
Now what I want to know is ... what do I have to do with the server keystore, since I have created a user in MySQL that can only be connected through SSL, and I have no idea how to make this connection from android with SSL ... The connection is made but I get the error '08S01' from the database, that is, error indicating that it can not perform the SSL HandShake correctly, and of course, it is because in the android part I'm missing something ..