Nativescript-https


#1

I have the same issue as seen here: https://github.com/gethuman/nativescript-https/issues/21 and the solution is listed as:

new CopyWebpackPlugin([
{ from: mainSheet },
{ from: “css/" },
{ from: "fonts/
” },
{ from: “/*.jpg" },
{ from: "
/.png" },
{ from: "**/
.xml” },
{ from: “/*.cer" }, // This one!
], { ignore: ["App_Resources/
”] }),

however I am using nativescript with vanilla javascript and do not know where to implement this as I have never seen it in any of my vanilla apps. Any idea how this should be done?


#2

This solution is for developers who uses webpack to bundle their app. If you are not using webpack by default app resources for respective platforms and anything placed inside app folder will be copied.

Just make sure you are accessing right file path / try a clean build.


#3

Thank you. The issue is I am actually seeing the file, but I am still getting this:

JS: nativescript-https > Disabled SSL pinning by default
JS: nativescript-https > enableSSLPinning error Error: java.security.cert.CertificateException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: inStream is empty

Here is the code That I use:

const knownFolders = require(“tns-core-modules/file-system”).knownFolders;
const http = require(“nativescript-https”);

exports.onPageLoaded = function onPageLoaded(args){
var dir = knownFolders.currentApp().getFolder(‘certs/’);
var certificate = dir.getFile(‘cert-name.Der.cer’).path;
http.enableSSLPinning({ host: ‘certname.com’, certificate });
console.log(" this is the file "+certificate);
// this is the file /data/data/org.nativescript.dcikwlmobile2/files/app/certs/cert-name.Der.cer

}

If I am seeing the file why do I still get the error


#4

May I know what do you mean by you are seeing the file? Did you literally see the file existence in the complied android project?

The reason I’m asking is getFile will create a file even if one doesn’t exists. So on a fresh install try to make sure the file exists by doing

// `File` / `path` are to be imported from `file-system` module
File.exists(path.join(knownFolders.currentApp().path, "certs", "cert-name.Der.cer"))

If the above statement returns true, at least we have a guarantee that the file exists. If still fails, try to validate whether the certificate is valid.


#5

Thank you. it worked. I think the file was corrupted.