nativescript-community / https Goto Github PK
View Code? Open in Web Editor NEWSecure HTTP client with SSL pinning for Nativescript - iOS/Android
Home Page: https://nativescript-community.github.io/https/
License: Other
Secure HTTP client with SSL pinning for Nativescript - iOS/Android
Home Page: https://nativescript-community.github.io/https/
License: Other
I was stuck with soap call with xml input using Nativescript-https in iOS.
I have added code for making soap call with xml input using Nativescript-https. Code was working fine in Android without any exceptions. But in the case of iOS, AFNetworking is throwing failure all the time when making a soap call with xml input.
AFNetworking 3.0 is used in Nativescript-https.
When i logged the Failure reason for AFNetworking, The reason mentioned in AFNetworking (https.ios.is) file is
"An SSL error has occurred and a secure connection to the server cannot be made".
Is it possible to make soap call with xml input using Nativescript-https in iOS.?
Any chance of making this work with NTLM authentication? How can I use this with something like JCIFS (https://jcifs.samba.org/)?
I have a big problem in my code, In https.androif.js I have :
"use strict";
var peer = {
enabled: false,
allowInvalidCertificates: false,
validatesDomainName: true,
};
function enableSSLPinning(options) {
if (!peer.host && !peer.certificate
) {
var certificate = void 0;
var InputSteram = void 0;
try {
var file = new java.io.file((options.certificate));
inputstream = new java.io.fileinputstream(file);
var x509certificate = java.security.cert.certificatefactory.getinstance('x509').generatecertificate(inputstream);
peer.x509certificate = x509certificate;
certificate = okhttp3.certificatepinner.pin(x509certificate);
inputstream.close();
}
catch (error) {
try {
if (inputStream) {
console.log('inputStream', inputStream)
inputStream.close();
}
}
catch (e) { }
console.error('nativescript-https > enableSSLPinning error', error);
return;
}
peer.host = options.host;
peer.certificate = certificate;
if (options.allowInvalidCertificates == true) {
peer.allowInvalidCertificates = true;
}
if (options.validatesDomainName == false) {
peer.validatesDomainName = false;
}
}
peer.enabled = true;
getClient(true);
console.log('nativescript-https > Enabled SSL pinning');
}
exports.enableSSLPinning = enableSSLPinning;
function disableSSLPinning() {
peer.enabled = false;
getClient(true);
console.log('nativescript-https > Disabled SSL pinning');
}
exports.disableSSLPinning = disableSSLPinning;
console.info('nativescript-https > Disabled SSL pinning by default');
var Client;
function getClient(reload) {
console.log(reload)
if (reload === void 0) { reload = false; }
if (Client && reload == false) {
return Client;
}
var client = new okhttp3.OkHttpClient.Builder();
if (peer.enabled == true) {
if (peer.host || peer.certificate) {
var spec = okhttp3.ConnectionSpec.MODERN_TLS;
client.connectionSpecs(java.util.Collections.singletonList(spec));
var pinner = new okhttp3.CertificatePinner.Builder();
pinner.add(peer.host, [peer.certificate]);
client.certificatePinner(pinner.build());
if (peer.allowInvalidCertificates == true) {
try {
var x509Certificate = peer.x509Certificate;
var keyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry('CA', x509Certificate);
var keyManagerFactory = javax.net.ssl.KeyManagerFactory.getInstance('X509');
keyManagerFactory.init(keyStore, null);
var keyManagers = keyManagerFactory.getKeyManagers();
var trustManagerFactory = javax.net.ssl.TrustManagerFactory.getInstance(javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
var sslContext = javax.net.ssl.SSLContext.getInstance('TLS');
sslContext.init(keyManagers, trustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
client.sslSocketFactory(sslContext.getSocketFactory());
}
catch (error) {
console.error('nativescript-https > client.allowInvalidCertificates error', error);
}
}
if (peer.validatesDomainName == false) {
try {
client.hostnameVerifier(new javax.net.ssl.HostnameVerifier({
verify: function (hostname, session) {
var pp = session.getPeerPrincipal().getName();
var hv = javax.net.ssl.HttpsURLConnection.getDefaultHostnameVerifier();
return (hv.verify(peer.host, session) &&
peer.host == hostname &&
peer.host == session.getPeerHost() &&
pp.indexOf(peer.host) != -1);
},
}));
}
catch (error) {
console.error('nativescript-https > client.validatesDomainName error', error);
}
}
}
else {
console.warn('nativescript-https > Undefined host or certificate. SSL pinning NOT working!!!');
}
}
Client = client.build();
console.log('Client', Client)
return Client;
}
function request(opts) {
return new Promise(function (resolve, reject) {
try {
var client = getClient();
var request_1 = new okhttp3.Request.Builder();
request_1.url(opts.url);
var reqheads_1 = opts.headers;
Object.keys(reqheads_1).forEach(function (key) {
request_1.addHeader(key, reqheads_1[key]);
});
if (opts.method == 'GET') {
request_1.get();
}
else if (opts.method == 'POST') {
var type = okhttp3.MediaType.parse('application/json');
var body = okhttp3.RequestBody.create(type, opts.content);
request_1.post(body);
}
client.newCall(request_1.build()).enqueue(new okhttp3.Callback({
onResponse: function (task, response) {
var content;
try {
content = JSON.parse(response.body().string());
}
catch (error) {
return reject(error);
}
var statusCode = response.code();
var headers = {};
var heads = response.headers();
var i, len = heads.size();
for (i = 0; i < len; i++) {
var key = heads.name(i);
var value = heads.value(i);
headers[key] = value;
}
resolve({ content: content, statusCode: statusCode, headers: headers });
},
onFailure: function (task, error) {
reject(error);
},
}));
}
catch (error) {
reject(error);
}
});
}
exports.request = request;
in component.ts I used this code:
let dir = knownFolders.currentApp().getFolder('certificate')
let certificate = dir.getFile('certificate.pem').path
Https.enableSSLPinning({ host: 'XX.XXX.XX.XX', certificate, allowInvalidCertificates: true, validatesDomainName: false })
Https.request({
url: 'https://XX.XXX.XX.XX:3333/login',
method: 'GET',
headers: {
"Content-type": "application/x-www-form-urlencoded",
},
}).then(function (response) {
console.log('Https.request response', response);
}).catch(function (error) {
console.error('Https.request error', error);
})
I used self signed certificate that generate from server. I want to
allowInvalidCertificates: true,
validatesDomainName: false
From this code I get error:
JS: Https.request error javax.net.ssl.SSLPeerUnverifiedException: Hostname XX.XXX.XX.XX not verified:
JS: certificate: sha256/hfR9N2GN2WS1NQuHAAnOUc1gVQCf4f4HrhdlfXXP+Ko=
JS: DN: 1.2.840.113549.1.9.1=#16111315727473401578616d706c652e636f6d,CN=localhost,OU=techops,O=Example > Co,L=Boston,ST=MA,C=US
JS: subjectAltNames: []
I think that a problem is in this parts of code:
... onFailure: function (task, error) {
console.log('test1', error)
reject(error);
},....
Can you ask me any idea please, how to solution this error? How is the problem?
Many thax
Hello.
I just created a new NativeScript test application. When I run "tns run ios --syncAllFiles" and then do a request behind a proxy (which fails because the emulator is not behind that proxy) the plugin throws an error.
In https.ios.js on line 64 "error.userInfo.objectForKey('NSErrorFailingURLKey')" evaluates to "null" which crashes the app because "null is not an object (evaluating 'error.userInfo.objectForKey('NSErrorFailingURLKey').description')".
I am installing the addin with
tns plugin add nativescript-https
Next, I am adding the basic call:
import * as Https from 'nativescript-https'
Https.request({
url: 'https://wegossipapp.com/api/newuser',
method: 'GET',
headers: {
'Authorization': 'Basic ZWx1c3VhcmlvOnlsYWNsYXZl',
'x-uuid': 'aHR0cHdhdGNoOmY',
'x-version': '4.2.0',
'x-env': 'DEVELOPMENT',
},
}).then(function(response) {
console.log('Https.request response', response)
}).catch(function(error) {
console.error('Https.request error', error)
})
and, I am getting the url parameter doesn't exist in type "HttpsRequestOptions".
After some investigation of the github code i can see that the https.common.d.ts file is not the same and its missing bunch of stuff like url param:
export interface HttpsRequestOptions extends HttpRequestOptions {
method: 'GET' | 'POST';
headers?: Headers;
content?: string;
}
am i missing something?
Highly appreciated someone can help me how to figure-out this issue. I have tried-out so many days,different certs, different domain names. nothing works.
I have to enable ssl pining in my app. So, I had to use https://github.com/gethuman/nativescript-https 1 plugin. I have follow the implementation steps correctly. But when I make the https request, iOS app crash in AFNetworking EXC_BAD_Access error. I have added two NSLogs to AFHTTPSSessionManager class.
Output
Securitypolicy AFSSLPinningModePublicKey
baseURL scheme (null)
It seems something wrong with setting the certificate and host in the angular code. By right, Securitypolicy should be AFSSLPinningModeCertificate and baseURL schme should have https.
Android app gives this error
Https.request error javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Implementation details as bellow
reference.d.ts
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
imports
import { File, Folder, knownFolders, path } from 'file-system'
import * as Https from 'nativescript-https'
in the constructor
let dir = knownFolders.currentApp().getFolder('certs')
let certificate = dir.getFile('httpbin.org.cer').path
Https.enableSSLPinning({ host: 'httpbin.org', certificate: certificate});
method
clickLogin(){
Https.request({
url: 'https://httpbin.org/get',
method: 'GET',
headers: {
'content-type': 'application/json'
},
}).then(function(response) {
console.log('Https.request response', response)
}).catch(function(error) {
console.error('Https.request error', error)
})
}
tns version 4.0.1 node v6.11.5
Does this library provide the ability to programmatically add or automatically select client authentication certificate to the request?
When I make a request on a device running Android 5.0.1 it works correctly but in Android 4.4.4 I get an error, any solution?
Error obtained:
Https.request error javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x72699f10: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x39fa31e3:0x00000000)
When performing a HTTP request (any HTTP Verb), for the iOS, the response of the plugin has headers as an empty object: {}.
After a some investigation, it's clear that line 125 of https.ios.js, is always undefined and therefore we never get all headers from response. (AFResponse.task.response is always undefined)
**var response = AFResponse.task.response;**
if (!types_1.isNullOrUndefined(response)) {
sendi.statusCode = response.statusCode;
var dict = response.allHeaderFields;
dict.enumerateKeysAndObjectsUsingBlock(function (k, v) {
sendi.headers[k] = v;
});
}
if (AFResponse.reason) {
sendi.reason = AFResponse.reason;
}
return Promise.resolve(sendi);
});
Does anyone has the same issue? Or is there any workaround to get the headers from the response?
Thank you. @jeffwhelpley
Hi guys, I'm using this plugin to connect my app with a Rest API, and when I get an error, my API returns what's wrong on failure response but on iOS, I can't get raw data only I get a general error description like error 500 and I need to know specifically whats happen, How can I do this on this plugin?
Hi @EddyVerbruggen ,
Just a little report about an issu with this plugin.
When I send the a request with the content-type
: application/json; charset=utf-8
I receive an empty body on the server side ; The issu come from the charset=utf-8
.. declaring the content-type without it solve the issu .. but I think is preferable to keep the charset.
This lib uses body
(on POST for example).
NS http lib uses content
Was this intentional or did NS lib change signature and nativescript-https just didn't keep up?
Also, I noice the request body object (HttpsRequestObject) only supports a map of string
to string|number
. How would one post a boolean ({"isSet":true}
) or a list (["a","b"]
)
Thanks in advance.
I have to enable ssl pining in my app. I have follow the implementation steps correctly. But when I make the https request, iOS app crash in AFNetworking EXC_BAD_Access error
Android app gives this error
JS: nativescript-https > Disabled SSL pinning by default
JS: nativescript-https > enableSSLPinning error ReferenceError: okhttp3 is not defined
JS: Https.request error ReferenceError: okhttp3 is not defined
reference.d.ts
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
imports
import { File, Folder, knownFolders, path } from 'file-system'
import * as Https from 'nativescript-https'
in the constructor
let dir = knownFolders.currentApp().getFolder('certs')
let certificate = dir.getFile('httpbin.org.cer').path
Https.enableSSLPinning({ host: 'httpbin.org', certificate: certificate});
method
clickLogin(){
//this.UserService.loginP();
Https.request({
url: 'https://httpbin.org/get',
method: 'GET',
headers: {
'content-type': 'application/json'
,
},
}).then(function(response) {
console.log('Https.request response', response)
}).catch(function(error) {
console.error('Https.request error', error)
})
}
Please help me to identify whats is the issue here.
tns version 4.0.1
node v6.11.5
The HttpsRequestOptions object seems to be modelled after NativeScript's built in HttpRequestOptions object, as seen from the example in the documentation. However, in the current code the "content" field of HttpsRequestOptions is actually named "body" so the example code as is would not work.
Hi! when my request return response, JSON arrays format is different that I expect, this is the format I want:
JSON: {array:["one", "two", "three"]}
Response I have:
JSON: {array:("one", "two", "three")}
brackets for array are normal brackets instead of square brackets... what's wrong?
Hi! when I do request to my webservice, Android side throws this exception:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
What I'm doing wrong? same code works on iOS. please help me.
var dir = fileSystem.knownFolders.currentApp().getFolder('certs');
console.log("Dir: "+JSON.stringify(dir));
var certificate = dir.getFile('APISICAR.cer').path;
console.log("Certificado path: "+certificate);
Https.enableSSLPinning({ host: "192.168.0.130", certificate, allowInvalidCertificates:true});
Can someone explain why this piece of code stopped working when I use the latest version:
const http = require("nativescript-https");
http.disableSSLPinning();
http.request({
url: `${config.apiURL}/circular/`,
method: "POST",
headers: { "Content-Type": "application/json" },
content: JSON.stringify({
schoolID:config.schoolID
})
})
in that I stopped seeing the schoolID on the server side but when I switched back to "nativescript-https": "^1.0.1" it worked as expected? The only difference is that one is the latest version while the other is version 1.0.1.
Hi, i have a problem on nativescript-https 1.0.1.
I installed plugin with tns plugin add nativescript-https
but when launch the app, his result is:
nativescript-https > Disabled SSL pinning
JS: Https.request error javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
The code is:
Https.disableSSLPinning();
Https.request({
url: 'https://dominio.com:6943/rest/api/',
method: 'GET',
headers: {
'content-type': 'application/json'
},
}).then(function(response) {
console.log('Https.request response', response)
}).catch(function(error) {
console.error('Https.request error', error)
})
Why? Any idea?
Thanks for the plugin. It may be helpful to allow a timeout property in the HttpRequestOptions interface to be used to override the okhttp3 Request default 10 seconds timeout
How to avoid certificate or call correct everytime and whene certificate is invalid. Any idea please?
Hello,
I am aware that from the Readme, it already said that "Once you've enabled SSL pinning you CAN NOT re-enable with a different host or certificate file." which means that for now the SSL Pinning can only work for 1 certificates.
Is there any workaround to make it works on more than 1 certificate in case we need to do SSL Pinning on more than one API endpoint?
Hi @EddyVerbruggen ,
I try to implement your plugin but I receive a malformed data from php ! with fetch module it work as expected
To debug I send a response like this from php :
$headers = [
'Content-type' => 'application/json; charset=utf-8',
'Accept' => 'application/json',
];
$l = ["id", "l", "lol"];
error_log(json_encode($l));
$data = \GuzzleHttp\json_encode($l);
return new Response(200, $headers, $data);
look it is malformed
CONSOLE LOG file:///app/views/menuManager/menuManagerVM.ts:57:24: (
id,
l,
lol
)
Do this plugin allow wildcard subdomain verification?
I have wildcard SSL Certificate (*.mydomain.com) and imported into App Service.
Can I declare wildcard domain in host paramater as below? or use naked domain?
Https.enableSSLPinning({ host: '*.mydomain.com', certificate }) or
Https.enableSSLPinning({ host: 'mydomain.com', certificate })
Using this module on NS view-model i get NetworkOnMainThreadException, Im confused since documentation states:
Im using:
https.enableSSLPinning({ host: '192.168.1.15', certificate, allowInvalidCertificates: false, validatesDomainName: false })
This plugin seems to be causing this error from Apple, the email from Apple is below
Dear Developer, We identified one or more issues with a recent delivery for your app. Your delivery was successful, but you may wish to correct the following issues in your next delivery:ITMS-90809: Deprecated API Usageย - Apple will stop accepting submissions of apps that use UIWebView APIs. Seeย https://developer.apple.com/documentation/uikit/uiwebviewย for more information. After youโve corrected the issues, you can use Xcode or Application Loader to upload a new binary to App Store Connect. Best regards, The App Store Team
I went through all the plugins I'm using and it only throws this error when I add this plugin, is it possible for a fix to be released?
Hi all,
I am using NS 3.0, I followed installation instructions but I keep get error:
./node_modules/tns-platform-declarations/ios.d.ts and ./node_modules/tns-platform-declarations/android.d.ts not found. Do you have any ideas? thanks
Hi!
I have cloned your repo in my laptop but following your steps is not working;
git clone https://github.com/gethuman/nativescript-https
cd nativescript-https
npm run setup
npm run demo.ios
npm run demo.android
`https.android.ts:4:30 - error TS2307: Cannot find module 'application'.
4 import * as application from 'application'
~~~~~~~~~~~~~
https.android.ts:5:59 - error TS2307: Cannot find module 'http'.
5 import { HttpRequestOptions, Headers, HttpResponse } from 'http'
~~~~~~
https.android.ts:6:46 - error TS2307: Cannot find module 'utils/types'.
6 import { isDefined, isNullOrUndefined } from 'utils/types'
~~~~~~~~~~~~~
https.android.ts:59:4 - error TS2304: Cannot find name 'console'.
59 console.error('nativescript-https > enableSSLPinning error', error)
~~~~~~~
https.android.ts:73:2 - error TS2304: Cannot find name 'console'.
73 console.log('nativescript-https > Enabled SSL pinning')
~~~~~~~
https.android.ts:78:2 - error TS2304: Cannot find name 'console'.
78 console.log('nativescript-https > Disabled SSL pinning')
~~~~~~~
https.android.ts:80:1 - error TS2304: Cannot find name 'console'.
80 console.info('nativescript-https > Disabled SSL pinning by default')
https.android.ts:135:6 - error TS2304: Cannot find name 'console'.
135 console.error('nativescript-https > client.allowInvalidCertificates error', error)
~~~~~~~
https.android.ts:154:6 - error TS2304: Cannot find name 'console'.
154 console.error('nativescript-https > client.validatesDomainName error', error)
~~~~~~~
https.android.ts:159:4 - error TS2304: Cannot find name 'console'.
159 console.warn('nativescript-https > Undefined host or certificate. SSL pinning NOT working!!!')
~~~~~~~
https.ios.ts:3:30 - error TS2307: Cannot find module 'application'.
3 import * as application from 'application'
~~~~~~~~~~~~~
https.ios.ts:4:59 - error TS2307: Cannot find module 'http'.
4 import { HttpRequestOptions, Headers, HttpResponse } from 'http'
~~~~~~
https.ios.ts:5:56 - error TS2307: Cannot find module 'utils/types'.
5 import { isDefined, isNullOrUndefined, isObject } from 'utils/types'
~~~~~~~~~~~~~
https.ios.ts:38:2 - error TS2304: Cannot find name 'console'.
38 console.log('nativescript-https > Enabled SSL pinning')
~~~~~~~
https.ios.ts:42:2 - error TS2304: Cannot find name 'console'.
42 console.log('nativescript-https > Disabled SSL pinning')
~~~~~~~
https.ios.ts:44:1 - error TS2304: Cannot find name 'console'.
44 console.info('nativescript-https > Disabled SSL pinning by default')
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Oscar/.npm/_logs/2018-06-07T16_55_52_448Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] setup: npm i && cd demo && npm i && cd .. && npm run build && cd demo && tns plugin add .. && cd ..
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] setup script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.`
this is the output terminal.
Thank you in advance
I tried to compile the latest NS with this plugin and here is what it told me
Found peer TypeScript 2.2.2
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(45,18): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(500,19): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(502,28): error TS2314: Generic type 'Map<K, V>' requires 2 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(503,24): error TS2314: Generic type 'Map<K, V>' requires 2 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(530,33): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(597,37): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(605,35): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(605,69): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(757,32): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(764,33): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(764,67): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(931,34): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(938,33): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(938,67): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1042,36): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1123,25): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1346,52): error TS2314: Generic type 'WeakReference<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1425,56): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1621,35): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1632,35): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1632,69): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1994,32): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2042,134): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2042,159): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2061,32): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2061,86): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2759,39): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2759,80): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2762,41): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2762,82): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2767,31): error TS2314: Generic type 'AbstractList<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2768,28): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2770,25): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2776,22): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2777,30): error TS2694: Namespace 'java.util' has no exported member 'stream'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2778,35): error TS2694: Namespace 'java.util' has no exported member 'Spliterator'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2785,40): error TS2314: Generic type 'ListIterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2787,41): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2788,23): error TS2314: Generic type 'Comparator<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2789,28): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2793,26): error TS2314: Generic type 'ListIterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2794,38): error TS2694: Namespace 'java.util' has no exported member 'stream'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2796,30): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
my refrences.d.ts
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
my tsconfig
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"lib": [
"es6",
"dom",
"es2015.iterable"
],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
},
"skipLibCheck": true,
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts"
]
}
Hi Robert,
Thank you for your great implementation and plugin.
I am trying to connect my app to WS based in XML-SOAP but I am having the next error in the console:
JS: 'Error: javax.net.ssl.SSLPeerUnverifiedException: Hostname XX-XX-XX not verified:
JS: certificate: sha256//zAeFdL0ymoNZ6XuKCOGJ3FwR/lYqAhkxku0wH3SE0k=
JS: DN: CN=localhost,OU=FOR TESTING ONLY,O=MyOrganization,L=MyTown,ST=MyState,C=US
JS: subjectAltNames: []'
Any clue about what would it be the problem?
Thank you in advance.
Has anybody seen a crash on Android with (slightly) larger responses?
Even a call to https://httpbin.org will crash the app, but the smaller https://httpbin.org/get won't.
It's because of the line response.body().string()
which runs the main thread and Android detects that as something that can degrade app responsiveness.
I have a fix for this in my fork but won't submit a PR until someone else can confirm it's a real issue instead of the way I use it.
When using the plugin with NativeScript 3.1., tns-core-modules 3.1.0 and TypeScript 2.2.1 the below error appears when we try to import the plugin as a module.
Reproducible on both iOS and Android. Test application demonstrating the issue can be found here (to reproduce just clone the app and execute tns run
command)
e.g.
import * as https from "nativescript-https";
results to
Executing before-prepare hook from /Users/Jey/Desktop/suresh/fp/MyBlue2/hooks/before-prepare/nativescript-dev-android-snapshot.js
Executing before-prepare hook from /Users/Jey/Desktop/suresh/fp/MyBlue2/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.2.2
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(45,18): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(500,19): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(502,28): error TS2314: Generic type 'Map<K, V>' requires 2 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(503,24): error TS2314: Generic type 'Map<K, V>' requires 2 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(530,33): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(597,37): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(605,35): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(605,69): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(757,32): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(764,33): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(764,67): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(931,34): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(938,33): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(938,67): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1042,36): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1123,25): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1346,52): error TS2314: Generic type 'WeakReference<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1425,56): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1621,35): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1632,35): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1632,69): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1994,32): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2042,134): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2042,159): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2061,32): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2061,86): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2759,39): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2759,80): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2762,41): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2762,82): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2767,31): error TS2314: Generic type 'AbstractList<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2768,28): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2770,25): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2776,22): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2777,30): error TS2694: Namespace 'java.util' has no exported member 'stream'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2778,35): error TS2694: Namespace 'java.util' has no exported member 'Spliterator'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2785,40): error TS2314: Generic type 'ListIterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2787,41): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2788,23): error TS2314: Generic type 'Comparator<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2789,28): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2793,26): error TS2314: Generic type 'ListIterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2794,38): error TS2694: Namespace 'java.util' has no exported member 'stream'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2796,30): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/index.d.ts(1,15): error TS2306: File '/Users/Jey/Desktop/suresh/fp/MyBlue2/node_modules/nativescript-https/AFNetworking.d.ts' is not a module.
node_modules/nativescript-https/index.d.ts(2,15): error TS2306: File '/Users/Jey/Desktop/suresh/fp/MyBlue2/node_modules/nativescript-https/com.squareup.okhttp3.d.ts' is not a module.
TypeScript compiler failed with exit code 1
As a temporary solution I have wrapped both declaration files (AFNetworking.d.ts
and com.squareup.okhttp3.d.ts
) in a module export statements
e.g.
export module AFNetworking {
.. file content follows here
}
The above solution seems to resolve the issue - please advice for the best approach.
I need really your support.
I have a big problem that I don't understand why happens.
I used this plugin because I want to communicate with protocol https.
So, Firstly I install this plugin, and write in component.ts this code:
enableSSLpinning() {
let certificate: any;
Https.enableSSLPinning({ host: 'xx.xxx.xx.xx:3333', certificate, allowInvalidCertificates: true, validatesDomainName: false })
Https.request({
url: 'https://xx.xxx.xx.xx:3333/user',
method: 'GET',
headers: {
"Content-type": "application/x-www-form-urlencoded",
},
}).then(function (response) {
console.log('Https.request response', response);
}).catch(function (error) {
console.error('Https.request error', error);
})
}
in https.android.js I modify only certificate in this part:
function enableSSLPinning(options) {
if (!peer.host && !peer.certificate
) {
var certificate = void 0;
var InputSteram = void 0;
try {
var inputStream = new java.io.ByteArrayInputStream(new java.lang.String("-----BEGIN CERTIFICATE-----\n"
+ "MIIFjDCCA3SgAwIBAgIJAMOXpEn+QQSVMA0GCSqGSIb3DQEBCwUAMIGBMQswCQYD\n"
+ "VQQGEwJVUzELMAkGA1UECAwCTUExDzANBgNVBAcMBkJvc3RvbjETMBEGA1UECgwK\n"
..................
+ "1AYJwo2yFqmetdmOYaFh6Cli8OerUERDqPB1UKPmYQE=\n"
+ "-----END CERTIFICATE-----").getBytes("UTF-8"));
var x509Certificate = java.security.cert.CertificateFactory.getInstance('X.509').generateCertificate(inputStream);
peer.x509Certificate = x509Certificate;
certificate = okhttp3.CertificatePinner.pin(x509Certificate);
inputStream.close();
}
catch (error) {
try {
if (inputStream) {
console.log('inputStream', inputStream)
inputStream.close();
}
}
catch (e) { }
console.error('nativescript-https > enableSSLPinning error', error);
return;
}
peer.host = options.host;
peer.certificate = certificate;
if (options.allowInvalidCertificates == true) {
peer.allowInvalidCertificates = true;
}
if (options.validatesDomainName == false) {
peer.validatesDomainName = false;
}
}
peer.enabled = true;
getClient(true);
console.log('nativescript-https > Enabled SSL pinning');
}
This parts execute correct, in console print 'nativescript-https > Enabled SSL pinning'
Error show in this part: console.error('Https.request error', error);
JS: Https.request error javax.net.ssl.SSLHandshakeException:
java.security.cert.CertPathValidatorException: Trust anchor for
certification path not found.
And in https.android.js
call this function
function request(opts) {
console.log('opts', opts)
return new Promise(function (resolve, reject) {
try {
var client = getClient();
var request_1 = new okhttp3.Request.Builder();
request_1.url(opts.url);
var reqheads_1 = opts.headers;
Object.keys(reqheads_1).forEach(function (key) {
request_1.addHeader(key, reqheads_1[key]);
});
if (opts.method == 'GET') {
request_1.get();
}
else if (opts.method == 'POST') {
var type = okhttp3.MediaType.parse('application/json');
var body = okhttp3.RequestBody.create(type, opts.content);
request_1.post(body);
}
client.newCall(request_1.build()).enqueue(new okhttp3.Callback({
onResponse: function (task, response) {
var content;
try {
content = JSON.parse(response.body().string());
}
catch (error) {
return reject(error);
}
var statusCode = response.code();
var headers = {};
var heads = response.headers();
var i, len = heads.size();
for (i = 0; i < len; i++) {
var key = heads.name(i);
var value = heads.value(i);
headers[key] = value;
}
resolve({ content: content, statusCode: statusCode, headers: headers });
},
onFailure: function (task, error) {
reject(error);
},
}));
}
catch (error) {
reject(error);
}
});
}
Please, can you ask me any idea, which is the problem in my code? Thank you
Thanks!
Update:
I think that a problem is in this part of code:
onResponse: function (task, response) {
console.load('testfdsfsdfsdfsd')
var content;
console.log('content', content)
try {
content = JSON.parse(response.body().string());
console.log('content1', content)
}
catch (error) {
console.log('error111111', error)
return reject(error);
}
var statusCode = response.code();
var headers = {};
var heads = response.headers();
var i, len = heads.size();
for (i = 0; i < len; i++) {
var key = heads.name(i);
var value = heads.value(i);
headers[key] = value;
}
resolve({ content: content, statusCode: statusCode, headers: headers });
},
because this part is not executed, it passes directly to onFailure
onFailure: function (task, error) {
reject(error);
},
On the android platform I see several issues:
There's a problem with function:
function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<string, any> & NSData & NSArray)
if (data.enumerateKeysAndObjectsUsingBlock || data.class().name === 'NSArray' || **(data instanceof NSArray) === true**) {
let serial = NSJSONSerialization.dataWithJSONObjectOptionsError(data, NSJSONWritingOptions.PrettyPrinted);
content = NSString.alloc().initWithDataEncoding(serial, NSUTF8StringEncoding).toString();
} else if (data.class().name === 'NSData' || **(data instanceof NSData) === true**) {
Should be used "instanceof"!
AFNetworking is not supported by MobileIron :(
NSUrlSession is faster.
I see that cert pinning is supported, but how much extra work would it be to add a method for pinning just a public key?
This would be much more convenient in most cases I think, given that key pairs are generally long-lived while certificates change on a regular basis โ more so now with the rising popularity of Let's Encrypt which issues 90-day certs. With public key pining, I can just commit the public key (or hash) as a static file once and forget about it, whereas it seems like cert pinning would require me to implement additional logic to ensure that the latest version of the cert is always stored locally.
(Note: I've looked at the readme, but haven't yet used this library or done much digging into how Android, iOS, or the linked libraries handle TLS pinning; so my assumptions about what is and/or can be supported may be completely off.)
I think the package in the tns plugin repo is outdated (1.0.1)
I'm with the folowing to run the application after instalation.
node_modules/nativescript-https/index.d.ts(1,15): error TS2306: File 'C:/dev/fm-transportes/src/FM.Transportes/node_modules/nativescript-https/AFNetworking.d.ts' is not a module.
node_modules/nativescript-https/index.d.ts(2,15): error TS2306: File 'C:/dev/fm-transportes/src/FM.Transportes/node_modules/nativescript-https/com.squareup.okhttp3.d.ts' is not a module.
node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/typescript/lib/lib.d.ts(14991,11): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/typescript/lib/lib.d.ts(14997,13): error TS2300: Duplicate identifier 'UIEvent'.
I've added the references.d.ts.
Need sample to make soap request using xml input
Hi, I'm trying to webpack my app, but I'm getting this error from this plugin:
nativescript-https > enableSSLPinning error Error: java.security.cert.CertificateException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: inStream is empty
JS: com.android.org.conscrypt.OpenSSLX509CertificateFactory.engineGenerateCertificate(OpenSSLX509CertificateFactory.java:274)
JS: java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:196)
JS: com.tns.Runtime.runModule(Native Method)
JS: com.tns.Runtime.runModule(Runtime.java:530)
JS: com.tns.Runtime.run(Runtime.java:522)
JS: com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
JS: android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1018)
JS: android.app.ActivityThread.handleBindApplication(ActivityThread.java:4959)
JS: android.app.ActivityThread.-wrap1(ActivityThread.java)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1549)
JS: android.os.Handler.dispatchMessage(Handler.java:111)
JS: android.os.Looper.loop(Looper.java:207)
JS: android.app.ActivityThread.main(ActivityThread.java:5728)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
JS: Caused by: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: inStream is empty
JS: com.android.org.conscrypt.OpenSSLX509CertificateFactory$Parser.generateItem(OpenSSLX509CertificateFactory.java:115)
JS: com.android.org.conscrypt.OpenSSLX509CertificateFactory.engineGenerateCertificate(OpenSSLX509CertificateFactory.java:272)
JS: java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:196)
JS: com.tns.Runtime.runModule(Native Method)
JS: com.tns.Runtime.runModule(Runtime.java:530)
JS: com.tns.Runtime.run(Runtime.java:522)
JS: com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
JS: android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1018)
JS: android.app.ActivityThread.handleBindApplication(ActivityThread.java:4959)
JS: android.app.ActivityThread.-wrap1(ActivityThread.java)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1549)
JS: android.os.Handler.dispatchMessage(Handler.java:111)
JS: android.os.Looper.loop(Looper.java:207)
JS: android.app.ActivityThread.main(ActivityThread.java:5728)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
JS: Caused by: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: inStream is empty
JS: com.android.org.conscrypt.OpenSSLX509CertificateFactory$Parser.generateItem(OpenSSLX509CertificateFactory.java:82)
JS: com.android.org.conscrypt.OpenSSLX509CertificateFactory.engineGenerateCertificate(OpenSSLX509CertificateFactory.java:272)
JS: java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:196)
JS: com.tns.Runtime.runModule(Native Method)
JS: com.tns.Runtime.runModule(Runtime.java:530)
JS: com.tns.Runtime.run(Runtime.java:522)
JS: com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
JS: android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1018)
JS: android.app.ActivityThread.handleBindApplication(ActivityThread.java:4959)
JS: android.app.ActivityThread.-wrap1(ActivityThread.java)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1549)
JS: android.os.Handler.dispatchMessage(Handler.java:111)
JS: android.os.Looper.loop(Looper.java:207)
JS: android.app.ActivityThread.main(ActivityThread.java:5728)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
JS: com.android.internal.os
JS: .ZygoteInit.main(ZygoteInit.java:749)
this plugin is compatible with webpack or there's is something more to config to make it work?
Hi!
Thanks for your great work on this plugin ๐๐๐
Strange things I noticed (and will send a PR for) when testing error flows on iOS. For instance when an error 500 is returned (tested with https://httpbin.org/status/500).
Hi,
I'm going to add the nativescript-https to my Nativescript/Angular app. I already have a very large number of API calls created using HTTPClient Module.
So, for example, my API calls are so structured:
firstApiCall() {
let httpParams = new HttpParams();
...adding parameters...
return this.http.get<number>(`my_url`, {
params: httpParams
})
.pipe(
map((data) => {
return data
})
);
}
secondApiCall(data) {
return this.http.post<boolean>('my_second_url', {
data: data
})
.pipe(
map((res) => {
return res;
})
);
}
with interceptor:
import { HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest } from
"@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor() {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const headerSettings: { [name: string]: string | string[]; } = {};
for (const key of req.headers.keys()) {
headerSettings[key] = req.headers.getAll(key);
}
headerSettings['Authorization'] = 'Bearer .....................';
if (!(req.body instanceof FormData)) {
headerSettings['Content-Type'] = 'application/json';
}
const newHeader = new HttpHeaders(headerSettings);
const changedReq = req.clone({
headers: newHeader
});
return next.handle(changedReq);
}
}
To avoid manually changing each call (which would take an infinite amount of time) is there a way to create a wrapper?
Hi
Great plugin.
I'm just wondering about how to accept self signed certificates?
E.g: How do you manipulate the options.allowInvalidCertificates without enabling SSL pinning.
Cheers
We're implementing a rest server and a mobile client to call the various rest endpoints (via https, with nativescript-https).
On Android, the response is a plain JSON, ready to be used (accessing the fields can be done with response.field1, response.field2 etc.)
On iOS, the response is a NSDictionary object, getting the actual data from it has to be done with response.valueForKey("field1"), response.valueForKey("field2") etc.
This is not optimal, it brings a platform dependency that we would like to avoid.
We have rest calls througout the application, thus a lot of potentially platform dependent points.
CLI: 3.4.0
Cross-platform modules: 3.4.0
Runtime(s): android 3.4.0 and ios 3.4.0
var https = require("nativescript-https");
function someHttpsCall = function() {
return https.request({
url: "serverURL/restEndPoint",
method: "GET",
headers: {
"Content-type": "application/json",
},
}).then(handleErrors) // implemented somewhere else
.then(function(response) {
return response.content.data;
})
.then(function(data) {
// ------> Here, data is a JSON in Android, and a NSDictionary in iOS
}
}
Need some assist.
Why when i enabled the SSL pinning and Test HTTPS, always getting javax.net.ssl.SSLPeerUnverifiedException error message as below:
JS: Https.request error javax.net.ssl.SSLPeerUnverifiedException: Hostname xxxx.azurewebsites.net not verified:
JS: certificate: sha256/nrmpk4ZI3wbRBmUZIT5aKAgP0LlKHRgfA2Snjzeg9iY=
JS: DN: CN=.azurewebsites.net
JS: subjectAltNames: [.azurewebsites.net, *.scm.azurewebsites.net, *.azure-mobile.net, *.scm.azure-mobile.net]
while disabled SSL, it called to api sucessfully.
Any idea?
thanks
The doc states that we require to make a post request like this:
Https.request({
url: 'https://myendpoint',
method: 'POST',
content: JSON.stringify({'username': 'name', 'password': 'pwd'}),
headers: {
'Content-Type': 'application/json'
},
}).then(function(response) {
console.log(response)
}).catch(function(error) {
console.error(error)
})
But it actually is:
Https.request({
url: 'https://myendpoint',
method: 'POST',
body: {'username': 'name', 'password': 'pwd'},
headers: {
'Content-Type': 'application/json'
},
}).then(function(response) {
console.log(response)
}).catch(function(error) {
console.error(error)
})
It would probably save a few hours to all of us
Thanks!
Ed
Https.request error javax.net.ssl.SSLPeerUnverifiedException: Hostname xxx.com not verified
From @smartsanja2013 on August 23, 2018 10:36
Highly appreciated someone can help me how to figure-out this issue. I have tried-out so many days,different certs, different domain names. nothing works.
I have to enable ssl pining in my app. So, I had to use https://github.com/gethuman/nativescript-https 1 plugin. I have follow the implementation steps correctly. But when I make the https request, iOS app crash in AFNetworking EXC_BAD_Access error. I have added two NSLogs to AFHTTPSSessionManager class.
Output
Securitypolicy AFSSLPinningModePublicKey
baseURL scheme (null)
It seems something wrong with setting the certificate and host in the angular code. By right, Securitypolicy should be AFSSLPinningModeCertificate and baseURL schme should have https.
Android app gives this error
Https.request error javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Implementation details as bellow
reference.d.ts
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
imports
import { File, Folder, knownFolders, path } from 'file-system'
import * as Https from 'nativescript-https'
in the constructor
let dir = knownFolders.currentApp().getFolder('certs')
let certificate = dir.getFile('httpbin.org.cer').path
Https.enableSSLPinning({ host: 'httpbin.org', certificate: certificate});
method
clickLogin(){
Https.request({
url: 'https://httpbin.org/get',
method: 'GET',
headers: {
'content-type': 'application/json'
},
}).then(function(response) {
console.log('Https.request response', response)
}).catch(function(error) {
console.error('Https.request error', error)
})
}
tns version 4.0.1 node v6.11.5
Copied from original issue: NativeScript/NativeScript#6211
Hi Eddy,
In iOS, is there a good reason why the support for arrays was removed post 1.0.2
Version 1.0.2
let dict_1 = null;
if (opts.body) {
var cont_1 = opts.body;
** removed code
if (Array.isArray(cont_1)) {
dict_1 = NSMutableArray.new();
cont_1.forEach(function (item, idx) {
dict_1.addObject(item);
});
}
** eof removed code
else if (types_1.isObject(cont_1)) {
dict_1 = NSMutableDictionary.new();
Object.keys(cont_1).forEach(function (key) {
dict_1.setValueForKey(cont_1[key], key);
});
}
}
Version 1.2.1
let dict: NSMutableDictionary<string, any> = null;
if (opts.body) {
let cont = opts.body;
if (isObject(cont)) {
dict = NSMutableDictionary.new<string, any>();
Object.keys(cont).forEach(key => dict.setValueForKey(cont[key] as any, key));
}
}
Please let me know as this is holding back things here.
I'm having trouble getting an HTTPS PUT method to work. Currently, the app just sort of freezes when it gets to the PUT.
Debugging the library I found that the file node_modules/nativescript-https/https-ios.js at approximately line 70, has an if for GET and then an else if for POST, but nothing PUT or DELETE.
I thought this was a drop in replacement for the http module. Am I missing something?
I installed the plugin as follows:
tns add plugin nativescript-https
Any suggestions would be greatly appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.