nativescript-community / nativescript-community/https

error javax.net.ssl.SSLHandshakeException:

Đang mở
#33 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Vue
Star
52
Fork
40
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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);
            },

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện request từ component.ts và lần theo enableSSLPinning cùng request trong https.android.js, tập trung vào đường dẫn onFailure và SSLHandshakeException được báo cáo. Không có test nào được nêu tên; để hoàn tất, cần xác định nguyên nhân và thêm một fix đã được xác minh hoặc một reproduction và cách giải quyết rõ ràng cho Android HTTPS request.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, javascript, typescript
Lĩnh vực
mobile-dev, networking, security
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.