Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TLS 1.1 and TLS 1.2 on Android 4.1-4.4 #9840

Closed
wants to merge 1 commit into from

Conversation

fkoester
Copy link
Contributor

This is a proposed patch for issue #7192.

Android 4.1-4.4 has support for TLS 1.1 and 1.2 but it is disabled by default. Because of the known security issues and more and more servers switching to TLS 1.2 only, it would be nice for react-native to enable this support.

I demonstrated a demo application which showcases the problem and can be used to test this patch. All sources and documentation for it can be found here:

https://github.com/bringnow/react-native-tls-test

Credits to Alex Gotev (@gotev) for the nice implementation.

@gotev
Copy link

gotev commented Sep 10, 2016

I've done some tests and the same issue also happens on some Samsung devices with API 21. Solved by applying the solution also for API 21

@ghost
Copy link

ghost commented Sep 10, 2016

By analyzing the blame information on this pull request, we identified @AndrewJack to be a potential reviewer.

@ghost
Copy link

ghost commented Sep 10, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@fkoester fkoester changed the title Enable TLS 1.2 on Android 4.1-4.4 (See Issue #7192) Enable TLS 1.1 and TLS 1.2 on Android 4.1-4.4 Sep 11, 2016
@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 11, 2016
@fkoester
Copy link
Contributor Author

I've done some tests and the same issue also happens on some Samsung devices with API 21. Solved by applying the solution also for API 21

@gotev That's strange, since API 20 it should not be necessary. But maybe Samsung tampered a lot with their Android implementation. So maybe we should then drop the patches API check? Currently it is:

if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 20) 

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 11, 2016
@ghost
Copy link

ghost commented Sep 11, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@gotev
Copy link

gotev commented Sep 11, 2016

@fkoester that's true for stock Android roms. I thought that all the other vendors were aligned, but maybe I was wrong, since the same problem arises on a Samsung rom with API 21. To solve that I simply changed the if statement:

if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22)

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 11, 2016
@facebook-github-bot
Copy link
Contributor

It's been a while since the last commit was reviewed and the labels show this pull request needs review. Based on the blame information for the files in this pull request we identified @AndrewJack as a potential reviewer. Could you take a look please or cc someone with more context?

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 11, 2016
@duataud
Copy link

duataud commented Oct 21, 2016

Please merge. Stripe api don't acept tls < 1.2 anymore

@alexter42
Copy link

Same issue Stripe do not accept tls < 1.2. Does anyone else have the same issue?

@AndrewJack
Copy link
Contributor

cc @bestander or @mkonicek could you review this?

Copy link
Contributor

@AndrewJack AndrewJack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few suggestions


client.connectionSpecs(specs);
} catch (Exception exc) {
Log.e("OkHttpClientProvider", "Error while enabling TLS 1.2", exc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use com.facebook.common.logging.FLog instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

See also https://github.com/facebook/react-native/issues/7192
*/
public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) {
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 20) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Build.VERSION_CODES for api levels

Build.VERSION_CODES.JELLY_BEAN == 16
Build.VERSION_CODES.KITKAT_WATCH == 20 - maybe use KITKAT (v19) with a <= for readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

available but not enabled by default. The following method
enables it.

See also https://github.com/facebook/react-native/issues/7192
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this link?

Copy link
Contributor Author

@fkoester fkoester Oct 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, I removed it.

@bestander
Copy link
Contributor

It looks reasonable to me considering that it is off by default.
A few points:

Credits to Alex Gotev (@gotev) for the nice implementation.
@fkoester
Copy link
Contributor Author

I implemented the suggestions made by @AndrewJack and rebased the PR to latest master.

@bestander
Copy link
Contributor

Andrew, shipit when ready

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 23, 2016
@lacker
Copy link
Contributor

lacker commented Oct 28, 2016

@facebook-github-bot shipit

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Oct 28, 2016
@facebook-github-bot
Copy link
Contributor

@lacker has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

DanielMSchmidt pushed a commit to DanielMSchmidt/react-native that referenced this pull request Jan 4, 2017
Summary:
This is a proposed patch for issue facebook#7192.

Android 4.1-4.4 has support for TLS 1.1 and 1.2 but it is disabled by default. Because of the known security issues and more and more servers switching to TLS 1.2 only, it would be nice for react-native to enable this support.

I demonstrated a demo application which showcases the problem and can be used to test this patch. All sources and documentation for it can be found here:

https://github.com/bringnow/react-native-tls-test

Credits to Alex Gotev (gotev) for the nice implementation.
Closes facebook#9840

Differential Revision: D4099446

Pulled By: lacker

fbshipit-source-id: 94db320dce6d27f98169e63f834562360c00eef7
@ThaJay
Copy link

ThaJay commented Feb 28, 2019

I don't understand:
The issue is marked as resolved: #7192
The code from this merge request is in master, but it does not work for me. Our servers don't accept tls v1 any more and now api <20 is broken, we have test devices to check old versions of android running 4.4 and now they can't do api requests any more.

Also, this comment #7192 (comment) does not seem to work for me. Maybe it is only for api 16? We want to support 4.4 (api 19) and up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants