silkimen / cordova-plugin-advanced-http

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!
MIT License
395 stars 314 forks source link

TLS connection could not be established: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found #453

Open klochko7 opened 2 years ago

klochko7 commented 2 years ago

Good day. Could you suggest please how to solve this problem? I use..

Ionic:

   Ionic CLI                     : 5.4.16
   Ionic Framework               : @ionic/angular 5.1.1
   @angular-devkit/build-angular : 0.803.10
   @angular-devkit/schematics    : 8.3.10
   @angular/cli                  : 8.3.10
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.3, (and 26 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   Android SDK Tools : 26.1.1 (C:\Users\anton\AppData\Local\Android\Sdk)
   NodeJS            : v12.15.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.13.4
   OS                : Windows 10

I add to config.xml

<preference name="AndroidBlacklistSecureSocketProtocols" value="SSLv3,TLSv1" />

My function:

     post(link, data): Promise<any> {
        return new Promise((resolve, reject) => {
          if (this.isOnline()) {

            data = Object.assign(data, {rnd: new Date().getTime()});

            if (this.debug_mode) {
              console.log("datadata", data);
            }

            let params = " params: ";
            for (let field in data) {
              if (field == "p") {
                params += " p:*****"
              }
              else
                params += " " + field + ":" + data[field];
            }

            if (this.debug_mode) {
              console.log('data_params', data);
              console.log("params", params);
            }

            this.logProvider.writeLog("RETRIEVE: start post on link " + link + " " + params);

            this.http.sendRequest(link,
                {
                  method: 'post',
                  data: data,
                  timeout: 30000
                }
            ).then(result => {

              // prints 200
              console.log(result.status);

              try {
                result.data = JSON.parse(result.data);
                // prints test
                console.log(result.data.message);
              } catch (e) {
                console.error('JSON parsing error');
              }

              this.logProvider.writeLog("RETRIEVE: finish post on link " + link);

              if (this.debug_mode) {
                console.log("result.data", result.data);
              }

              //console.log("result", result);
              resolve(result.data);

              // prints 200
              console.log(result.status);
            }).catch(err => {

              // A client-side or network error occurred. Handle it accordingly.

              if (this.debug_mode) {
                console.log('An error occurred post:', err);
              }

              this.logProvider.writeLog("ERROR: error in answer from server " + err.error + " status " + err.status + " link " + link + params);

              reject(err.error);

              // prints 403
              console.log(err.status);

              // prints Permission denied
              console.log(err.error);
            });

          } else {
            this.logProvider.writeLog("going to post on link " + link + " but device is offline");
            reject({text: "device is offline"});
          }

        });
      }
silkimen commented 2 years ago

Please provide a minimal version to reproduce your problem.

Romulogss commented 2 years ago

Hi, I'm having the same problem. My .cer certificates are already at www/certificates and the Trust anchor for certification path not found error still appears.

Ionic CLI : 6.18.1 Ionic Framework : ionic-angular 3.8.0 @ionic/app-scripts : 3.2.4 @ionic-native/http: 4.20.0 cordova-plugin-advanced-http: 2.4.1

naresh33 commented 1 year ago

Hi, Having the same issue. Certificate are already at www/certificates and android/app/src/main/assets/public/certificates.

"error":"TLS connection could not be established: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

@ionic-native/http: 5.36.0 cordova-plugin-advanced-http: 3.2.2

Ionic:

Ionic CLI : 6.18.2 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.9.1 @angular-devkit/build-angular : 13.3.5 @angular-devkit/schematics : 13.3.5 @angular/cli : 13.3.5 @ionic/angular-toolkit : 5.0.3

Capacitor:

Capacitor CLI : 3.6.0 @capacitor/android : 3.6.0 @capacitor/core : 3.6.0 @capacitor/ios : 3.6.0

System:

NodeJS : v16.14.0 (/usr/local/bin/node) npm : 2.15.12 OS : macOS Monterey

windcloudit commented 1 year ago

I also have same error I already create www/certificates and put the key file DER in there but I got this error after run. currently I use "cordova": "^10.0.0" and "cordova-plugin-advanced-http": "3.0.0". My project is cordova monaca. Anyone have solution for this? Thank you so much. error

windcloudit commented 1 year ago

I already solved this problem because I mistaken convert file to .der instead .cer files. Thank you so much.

liuminyu2989 commented 2 days ago

I already solved this problem because I mistaken convert file to .der instead .cer files. Thank you so much.

I also encountered the same error. My certificate was generated by openssl. What tool was used to generate your certificate?