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

Crash on Android due to missing method setEndpointIdentificationAlgorithm on 1.5.0. #1011

Closed
or-else opened this issue May 9, 2020 · 15 comments · Fixed by #1014
Closed

Crash on Android due to missing method setEndpointIdentificationAlgorithm on 1.5.0. #1011

or-else opened this issue May 9, 2020 · 15 comments · Fixed by #1014
Assignees
Milestone

Comments

@or-else
Copy link

or-else commented May 9, 2020

Websocket library 1.5.0
The same code was not crashing on 1.4.1

This is the entire stack trace. I got it through Crashlytics so I cannot describe steps that led to it.

Fatal Exception: java.lang.NoSuchMethodError: No virtual method setEndpointIdentificationAlgorithm(Ljava/lang/String;)V in class Ljavax/net/ssl/SSLParameters; or its super classes (declaration of 'javax.net.ssl.SSLParameters' appears in /system/framework/core-libart.jar)
       at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:476)
       at java.lang.Thread.run(Thread.java:831)

Android 5.0.1 (API 21).
Brand: HUAWEI
Model: P8 Lite

@marci4
Copy link
Collaborator

marci4 commented May 9, 2020

The library requires Java API Level 1.7.

I don't know what that means for supported android versions.

Could you check this for me?

Best regards,
Marcel

@marci4 marci4 added the Android label May 9, 2020
@marci4
Copy link
Collaborator

marci4 commented May 9, 2020

@PhilipRoman
If we move this inside of OnSetSSLParameters Android developers would be able to override the method, preventing the exception but disabling hostname verification.

We could document this exception and the workaround and include how do to hostname verficiation then.

What do you think?

Best regards,
Marcel

@or-else
Copy link
Author

or-else commented May 9, 2020

I'm not sure what Java 1.7 means:
https://en.m.wikipedia.org/wiki/Java_version_history

Please clarify. Thanks.

@marci4
Copy link
Collaborator

marci4 commented May 9, 2020

Java SE 7

@or-else
Copy link
Author

or-else commented May 9, 2020

Yes, Android API 21 is Java 7.

@marci4
Copy link
Collaborator

marci4 commented May 9, 2020

Looks like the added setEndpointIdentificationAlgorithm in API Version 24 -.-
https://developer.android.com/reference/javax/net/ssl/SSLParameters#setEndpointIdentificationAlgorithm(java.lang.String)

@or-else
Copy link
Author

or-else commented May 9, 2020

@marci4 Thanks!

@or-else or-else closed this as completed May 9, 2020
@marci4 marci4 reopened this May 9, 2020
@PhilipRoman
Copy link
Collaborator

PhilipRoman commented May 9, 2020

@marci4
I guess we will have to move it inside of onSetSSLParameters.

The only other way would be to check for the existence of setEndpointIdentificationAlgorithm using reflection and set a static field, for example "private static final boolean CAN_SET_ENDPOINT_IDENTIFICATION_ALGORITHM = ...".

Not sure if it is worth the extra complexity (although it would make it easier for Android users)

@marci4
Copy link
Collaborator

marci4 commented May 10, 2020

@PhilipRoman the reflection would result in a silent fail.

Then there is no indication if hostname validation is active or not.

@marci4
Copy link
Collaborator

marci4 commented May 10, 2020

@or-else what do you think about the following idea:

I will move the method call setEndpointIdentificationAlgorithm inside of OnSetSSLParameters.
You would be able to override the implementation and not call setEndpointIdentificationAlgorithm, but then you have to do your own hostname validation.
The default would still be the same and our android users would be able to work around the missing API.

It is not ideal but you would be able to use this library without being forced to require a never Android API version.

Best regards,
Marcel

@marci4 marci4 self-assigned this May 10, 2020
@marci4
Copy link
Collaborator

marci4 commented May 10, 2020

@or-else and @PhilipRoman if you are both fine with the proposed changes, I would do a hotfix release for 1.5.1.

Best regards,
Marcel

@marci4 marci4 added the Bug label May 10, 2020
@or-else
Copy link
Author

or-else commented May 10, 2020

@marci4 Yes, setting SNI parameter in protected void onSetSSLParameters(SSLParameters sslParameters) makes total sense to me.

@marci4
Copy link
Collaborator

marci4 commented May 10, 2020

Snapshot looks good, pushing release.

Workaround is documented here https://github.com/TooTallNate/Java-WebSocket/wiki/No-such-method-error-setEndpointIdentificationAlgorithm

Best regards,
Marcel

@marci4 marci4 closed this as completed May 10, 2020
@marci4 marci4 added this to the Release 1.5.1 milestone May 10, 2020
@wuyinlei
Copy link

wuyinlei commented May 18, 2020

Websocket library 1.5.1
The same code was not crashing on 1.4.1

java.lang.NoSuchMethodError

No virtual method setEndpointIdentificationAlgorithm(Ljava/lang/String;)V in class Ljavax/net/ssl/SSLParameters; or its super classes (declaration of 'javax.net.ssl.SSLParameters' appears in /system/framework/core-libart.jar)

1 e.a.f.b.a(WebSocketClient.java:5)

2 e.a.f.b.run(WebSocketClient.java:19)
3 java.lang.Thread.run(Thread.java:818)

@MohamedMedhat1998
Copy link

I think I can now understand why most of the websocket libraries I found require minSdkVersion 24.

rauljurado620 added a commit to rauljurado620/tindroid-andorid-project that referenced this issue Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants