- Home /
Android build, wwwform gives ssl.SSLHandshakeException
So, I have this code in the editor:
string email = ifemail.text;
string pssw = ifpassw.text;
WWWForm form = new WWWForm();
form.AddField("email", email);
form.AddField("password", pssw);
WWW w = new WWW("https://myserverpath/action_login.php", form);
yield return w;
if (string.IsNullOrEmpty(w.error))
{
if (w.text.Contains("invalid email or password"))
{
// wrong data
} else
{
// login successful --> Return this in editor
}
} else
{
// comunication error --> return this in apk
}
It works perfectly fine in the editor and I can both access and write on the db (so the php files work both for login and registration and db connection). Just in case this is the php code for login and connection: LOGIN :
<?php
include '../dbconnect.php';
$email = $_POST['email'];
$upass = $_POST['password'];
$email = strip_tags($email);
$upass = strip_tags($upass);
$query = "SELECT userEmail FROM users WHERE userEmail='$email' AND userPass='$upass'";
$result = mysqli_query($dbconnection, $query);
$row = mysqli_fetch_row($result);
if($row) {
$dataArray = array('success' => true, 'error' => "$email");
} else {
$dataArray = array('success' => false, 'error' => 'invalid email or password');
}
header('Content-Type: application/json');
echo json_encode($dataArray);
?>
CONNECT :
<?php
$dbuser = 'test_user';
$dbpassword = 'blurredpassword';
$db = 'test_db';
$dbhost = 'XXX.XXX.X.XXX';
$dbconnection = mysqli_connect($dbhost, $dbuser, $dbpassword, $db) or die("Connection failed " . mysql_error());
?>
If i build my apk, I cannot even get to connect to db. I searched for answers all around, but can't find a resolutive answer
I have internet access required in player settings, no custom manifest and tried both "https" and "http"
What am I missing? please help meh..
it could be the case of missing crossreference. I suggest checking what error you are getting on w.error.
I checked and posted the log down in a reply! Hopefully it helps.
Answer by Ghislo · Sep 04, 2018 at 02:26 PM
I just run on the debugger and I get this :
09-04 16:20:40.226 26328 26359 E Unity : javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
09-04 16:20:40.226 26328 26359 E Unity :
09-04 16:20:40.226 26328 26359 E Unity : (Filename: Line: 435)
09-04 16:20:40.226 26328 26359 E Unity :
09-04 16:20:40.226 26328 26341 I Unity : Error occurred :Unknown Error
09-04 16:20:40.226 26328 26341 I Unity :
09-04 16:20:40.226 26328 26341 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
09-04 16:20:40.226 26328 26341 I Unity :
Could it be related to the server provider? I'm not really an expert, but I read online it's a certification issue.. is it solvable?
Are you running the server on the same pc as you are running the editor? This would bypass a lot of security. Hence the reason it works in editor and not on mobile. If not then you have the error now, gotta do some googling to find out more.
Nope, it's a hosted server. I'll google more tomorrow but, for now, I only found out it's a self-signed/missing intermediate CAs (Certificated Authorities) issue that happens only for Android for security reasons. https://developer.android.com/training/articles/security-ssl#java It explains quite well, but I don't see any solution i can directly apply..
I think it's related to the hosted provider certificates maybe not being on point for android development? I tried mailing them the error and we'll see if they can help me.
In this case, if it is in a private server that you don;t have full control over then you might have to ask them for some assistance in enabling things. This generally should not be an issue, since you are already going through php requests, so I don't really understand why this extra layer of security.
Your answer
Follow this Question
Related Questions
How to get different variables from PHP page ? (example included)... 1 Answer
PHP Android WWW Unknown Error 1 Answer
www php send data to mysql 2 Answers
Unity - MySQL data loss 0 Answers