-1

I want to use a php API to connect to my MySql database but I get the following error all the time: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found

I know I need a certificate but I have no clue how to create one, because I am the host which is why I need to create it my self.

The php code is the following from this github : https://github.com/VishnuSivadasVS/LogIn-SignUp

<?php
require "DataBase.php";
$db = new DataBase();
if (isset($_POST['fullname']) && isset($_POST['email']) && isset($_POST['username']) && isset($_POST['password'])) {
    if ($db->dbConnect()) {
        if ($db->signUp("users", $_POST['fullname'], $_POST['email'], $_POST['username'], $_POST['password'])) {
            echo "Sign Up Success";
        } else echo "Sign up Failed";
    } else echo "Error: Database connection";
} else echo "All fields are required";
?>

And this is how I try to connect in my Java/Android Code:

                        public void run() {
                            //Starting Write and Read data with URL
                            //Creating array for parameters
                            String[] field = new String[4];
                            field[0] = "fullname";
                            field[1] = "username";
                            field[2] = "password";
                            field[3] = "email";
                            //Creating array for data
                            String[] data = new String[4];
                            data[0] = fullnametext;
                            data[1] = usernametext;
                            data[2] = passwordtext;
                            data[3] = emailtext;
                            PutData putData = new PutData("https://127.0.0.1/LoginRegister/signup.php", "POST", field, data);
                            if (putData.startPut()) {
                                if (putData.onComplete()) {
                                    String result = putData.getResult();
                                    progressBar.setVisibility(View.GONE);
                                    if(result.equals("Sign Up Success")){
                                        Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
                                        Log.i("Result", result);
                                        Intent intent = new Intent(getApplicationContext(), LogIn.class);
                                        startActivity(intent);
                                        finish();

                                    }

It would really help me if anybody could tell me how to create the certificate I need and where to put it in my android code.

Thanks for any help :)

I already searched for information, but I only ran into more questions. Like do I need a certificate for my database or the php Code?

  • You don't need to create a certificate. You need to import the server's certificate, or that of one of its signers, into your truststore. Duplicate. – user207421 Apr 16 '23 at 09:43

1 Answers1

0

You need a certificate in the PHP instance that your Java trusts.

Either you get a real cert, eg https://letsencrypt.org/ and install it to PHP

Or you make your own, install in PHP and add it to your JRE security CACERTS.

John Williams
  • 4,252
  • 2
  • 9
  • 18