javax.net.ssl.SSLException: java.io.EOFException: Read error
Hello Koush, I am using your library ~ androidasync for websockets in my project & getting following stacktrace..
02-20 13:49:51.551 19415 5027 W System.err: javax.net.ssl.SSLException: java.io.EOFException: Read error 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.SSLUtils.toSSLException(SSLUtils.java:295) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.convertException(ConscryptEngine.java:1093) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:851) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:678) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:644) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.AsyncSSLSocketWrapper$5.ON-DATAAVAILABLE(AsyncSSLSocketWrapper.java:194) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.Util.emitAllData(Util.java:23) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:152) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:821) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:658) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.AsyncServer.access$800(AsyncServer.java:44) 02-20 13:49:51.551 19415 5027 W System.err: at com.koushikdutta.async.AsyncServer$14.run(AsyncServer.java:600) 02-20 13:49:51.551 19415 5027 W System.err: Caused by: java.io.EOFException: Read error 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.NativeCrypto.ENGINE_SSL_read_direct(Native Method) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.SslWrapper.readDirectByteBuffer(SslWrapper.java:492) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.readPlaintextDataDirect(ConscryptEngine.java:1052) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.readPlaintextDataHeap(ConscryptEngine.java:1072) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.readPlaintextData(ConscryptEngine.java:1044) 02-20 13:49:51.551 19415 5027 W System.err: at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:805) 02-20 13:49:51.552 19415 5027 W System.err: ... 9 more
Issue is coming only for Android Oreo 8.1.0 on Nexus 6P. It's running fine on other devices running lower Android versions.
Can confirm, same issue on 8.1.0
Since Android 8.1, it seems unwrap method is returning an EOFException "read error" instead of the result "BUFFER_OVERFLOW" when your application buffer is too small. How can we deal with this issue ? Allocate a very large buffer seems a very dirty solution...
I got same issue on 8.1.0. Do you have any solution?
Yes, I found a solution.
The problem is the BUFFER_OVERFLOW in the unwrap method because in 8.1.0 it throws an EOFException.
So, now, I simply check first the remaining space in my buffer and if this method return 0, I increase the size of my buffer and then I call the unwrap method.
This way, there is never a BUFFER_OVERFLOW in the unwrap and now it works.
Good luck
Guillaume
De : atakankersit [email protected] Envoyé : lundi 13 août 2018 16:19 À : koush/AndroidAsync Cc : Guilack1; Comment Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
I got same issue on 8.1.0. Do you have any solution?
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-412576315, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BA8i7hsHRk3QSo4HKFQ5LEoVqV9Oks5uQacSgaJpZM4SNYDX.
@Guilack1 please provide buffer overflow method snippet
Simply call "buffer.remaining()" method before call "buffer.unwrap()".
If the remaining method returns 0, just reallocate your buffer and then call unwrap method
De : msameera96 [email protected] Envoyé : vendredi 5 octobre 2018 06:24 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
@Guilack1https://github.com/Guilack1 please provide buffer overflow method snippet
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-427259012, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BKA02TGNgNjTu-YUfAEh99dElz_Tks5uhvsTgaJpZM4SNYDX.
Here?
https://github.com/koush/AndroidAsync/blob/0ce329dbca0ee5294ad4cbc47a89d3ab6844ecba/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java#L194
Yes, just before calling 'unwrap' method.
You just need to be sure there is some space in your buffer
De : Mike [email protected] Envoyé : vendredi 5 octobre 2018 21:04 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
Here?
https://github.com/koush/AndroidAsync/blob/0ce329dbca0ee5294ad4cbc47a89d3ab6844ecba/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java#L194
[https://avatars3.githubusercontent.com/u/73924?s=400&v=4]https://github.com/koush/AndroidAsync/blob/0ce329dbca0ee5294ad4cbc47a89d3ab6844ecba/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java#L194
koush/AndroidAsynchttps://github.com/koush/AndroidAsync/blob/0ce329dbca0ee5294ad4cbc47a89d3ab6844ecba/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java#L194 github.com Asynchronous socket, http (client+server), websocket, and socket.io library for android. Based on nio, not threads. - koush/AndroidAsync
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-427498206, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BGSf6rHsVHr5u8_b6tziyawFbPAuks5uh8lKgaJpZM4SNYDX.
@Guilack1 Can you show a code snippet with the fix? I'm not really sure how to reallocate the buffer (and which one).
Simply call "buffer.remaining()" method before call "buffer.unwrap()". If the remaining method returns 0, just reallocate your buffer and then call unwrap method … ________________________________ De : msameera96 [email protected] Envoyé : vendredi 5 octobre 2018 06:24 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594) @Guilack1https://github.com/Guilack1 please provide buffer overflow method snippet — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#594 (comment)>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BKA02TGNgNjTu-YUfAEh99dElz_Tks5uhvsTgaJpZM4SNYDX.
I added if (readBuf.remaining() == 0) likes this but it never returns true, while the java.io.EOFException: Read error still exists.
Please, show me more of you code because I don't see enough and there is probably a mistake somewhere.
In your example (readBuf.remaining() == 0) is always false because you allocate your buffer just before (so of course remaining() is never equals to 0)
My code looks like that :
if(_bufferAppRead.remaining() == 0) { ByteBuffer tmp = _bufferAppRead; _bufferAppRead = ByteBuffer.allocate(tmp.capacity() * 2); tmp.flip(); _bufferAppRead.put(tmp); }
result = _engine.unwrap(_bufferNetRead, _bufferAppRead);
De : 知还 [email protected] Envoyé : vendredi 9 novembre 2018 08:22 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
Simply call "buffer.remaining()" method before call "buffer.unwrap()". If the remaining method returns 0, just reallocate your buffer and then call unwrap method … ________________________________ De : msameera96 [email protected]mailto:[email protected] Envoyé : vendredi 5 octobre 2018 06:24 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594https://github.com/koush/AndroidAsync/issues/594) @Guilack1https://github.com/Guilack1https://github.com/Guilack1 please provide buffer overflow method snippet — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#594 (comment)https://github.com/koush/AndroidAsync/issues/594#issuecomment-427259012>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BKA02TGNgNjTu-YUfAEh99dElz_Tks5uhvsTgaJpZM4SNYDX.
[image]https://user-images.githubusercontent.com/6789406/48251010-364cb400-e43b-11e8-9469-d2015a73ba03.png I added if (readBuf.remaining() == 0) likes this but it never returns true, while the java.io.EOFException: Read error still exists.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-437284868, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BKiiw7hpTBDGEWPUuCfOCj1UDr8Bks5utTs_gaJpZM4SNYDX.
if(_bufferAppRead.remaining() == 0) { ByteBuffer tmp = _bufferAppRead; _bufferAppRead = ByteBuffer.allocate(tmp.capacity() * 2); tmp.flip(); _bufferAppRead.put(tmp); }
result = _engine.unwrap(_bufferNetRead, _bufferAppRead);
De : msameera96 [email protected] Envoyé : vendredi 5 octobre 2018 06:24 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
@Guilack1https://github.com/Guilack1 please provide buffer overflow method snippet
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-427259012, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BKA02TGNgNjTu-YUfAEh99dElz_Tks5uhvsTgaJpZM4SNYDX.
Here is an example. _bufferNetRead is where are received ciphered data from your socket _bufferAppRead is the buffer destination for you deciphered data (after unwrap)
if(_bufferAppRead.remaining() == 0) { ByteBuffer tmp = _bufferAppRead; _bufferAppRead = ByteBuffer.allocate(tmp.capacity() * 2); tmp.flip(); _bufferAppRead.put(tmp); }
result = _engine.unwrap(_bufferNetRead, _bufferAppRead);
De : msameera96 [email protected] Envoyé : vendredi 5 octobre 2018 06:24 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
@Guilack1https://github.com/Guilack1 please provide buffer overflow method snippet
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-427259012, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BKA02TGNgNjTu-YUfAEh99dElz_Tks5uhvsTgaJpZM4SNYDX.
How to edit library for add these lines. I found class but that class was locked in android studio. Or Please update the library with latest patch.
Sir, Is this possible, if you release minor update in which these issues has been solved? Please respond me back. My application is dependent on this library otherwise I will do something else. Thanks.
I don't understand your request? I'm not responsible for the library, I'm just a developer (like you) who use it. I've sent you the way I use the library to avoid the exception problem.
Télécharger Outlook pour Androidhttps://aka.ms/ghei36
From: msameera96 [email protected] Sent: Monday, December 17, 2018 6:02:40 AM To: koush/AndroidAsync Cc: Guilack1; Mention Subject: Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
Sir, Is this possible, if you release minor update in which these issues has been solved? Please respond me back. My application is dependent on this library otherwise I will do something else. Thanks.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-447723502, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BJsd2mGFGGlv5lBHFm3UMWU-ZHQ6ks5u5yVwgaJpZM4SNYDX.
Sir, I am facing error javax.net.ssl.SSLException, so you provided me snippet but I didn't understand, how to add that lines in my project. Please guide me soon as possible. My project is completed but my client facing issues on oreo, sometimes data response not get by library. But, in Android Pie version application running perfectly.
I don't know what looks like your code but you just have to check if the remaining() method of your buffer is not equals to '0' before calling the unwrap() method. If it's equal to '0', you have to allocate a bigger buffer and then call the unwrap() method
Télécharger Outlook pour Androidhttps://aka.ms/ghei36
From: msameera96 [email protected] Sent: Tuesday, December 18, 2018 5:54:52 AM To: koush/AndroidAsync Cc: Guilack1; Mention Subject: Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
Sir, I am facing error in javax.net.ssl.SSLException, so you provided me snippet but I didn't understood, how to add that lines in my project. Please guide me soon as possible. My project is completed but my client facing issues on oreo, sometimes data response not get by library. But, in Android Pie version application running perfectly.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-448096154, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BJ-zt6feprYBYh-GTc021PHAfRiGks5u6HUcgaJpZM4SNYDX.
Sir, do we edit in library if yes then please guide me how to edit in library in android studio.
I don't patch the library (I can't do that) Just do it in your code where you call the 'unwrap' method
Télécharger Outlook pour Androidhttps://aka.ms/ghei36
From: msameera96 [email protected] Sent: Tuesday, December 18, 2018 7:07:03 PM To: koush/AndroidAsync Cc: Guilack1; Mention Subject: Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
Sir how to add that in library?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-448314729, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BF8Wb9ILTtvP9BDQT-AT6Pl-VM_kks5u6S7HgaJpZM4SNYDX.
I am not calling unwrap method I am providing my code below so please check it if possible
public void getnewArrivalProducts(){ dialog.setMessage(context.getString(R.string.loading_products)); dialog.show();
Ion.getDefault(context).getConscryptMiddleware().enable(true); Ion.with(context) .load(KeysString.getKeysStringObj().GET_NEW_ARRIVAL_PRODUCTS+"?lat="+ Splash.user_lat+"&lng="+Splash.user_lng) .setHeader("Content-Type", "application/x-www-form-urlencoded") .asString() .setCallback(new FutureCallback<String>() { @Override public void onCompleted(Exception e, String result) { // TODO Auto-generated method stub try { if (result != null) { //dialog.dismiss(); stopDialog(); new ParsenewArrivalProductsJsonResponse().execute(result).get(); if(Constants.LOGG) { Log.d(Constants.TAG, "New arrival products: "+result); } //setting adapter after adding data in ListViewModel Object // setListViewAdapter(); // parseJsonResponse(result); // setListViewAdapter(); //dialog.dismiss(); }else { stopDialog(); } } catch (Exception ex) { //dialog.dismiss(); stopDialog(); if(Constants.LOGG) { Log.d(Constants.TAG, ex.toString()); ex.printStackTrace(); } mDialogAlert.showDialog("error",context.getString(R.string.not_responding),""); // Toast.makeText(context,context.getString(R.string.not_responding), Toast.LENGTH_LONG).show(); } } }); }
Sorry but I'm using directly the "javax.net.ssl" package. As far as I can see, you use a wrapper library (=> "Ion") and I don't know it and, unless you have access to the code, you can't modify it.
You have two possibilities :
- ask help to the developers of this "Ion" library
- get the code of the "Ion" library and patch it (near the unwrap() method)
I wish you good luck
De : msameera96 [email protected] Envoyé : mardi 18 décembre 2018 18:28 À : koush/AndroidAsync Cc : Guilack1; Mention Objet : Re: [koush/AndroidAsync] javax.net.ssl.SSLException: java.io.EOFException: Read error (#594)
I am not calling unwrap method I am providing my code below so please check it if possible
public void getnewArrivalProducts(){ dialog.setMessage(context.getString(R.string.loading_products)); dialog.show();
Ion.getDefault(context).getConscryptMiddleware().enable(true);
Ion.with(context)
.load(KeysString.getKeysStringObj().GET_NEW_ARRIVAL_PRODUCTS+"?lat="+ Splash.user_lat+"&lng="+Splash.user_lng)
.setHeader("Content-Type",
"application/x-www-form-urlencoded")
.asString()
.setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
// TODO Auto-generated method stub
try {
if (result != null) {
//dialog.dismiss();
stopDialog();
new ParsenewArrivalProductsJsonResponse().execute(result).get();
if(Constants.LOGG) {
Log.d(Constants.TAG, "New arrival products: "+result);
}
//setting adapter after adding data in ListViewModel Object
// setListViewAdapter();
// parseJsonResponse(result);
// setListViewAdapter();
//dialog.dismiss();
}else
{
stopDialog();
}
} catch (Exception ex) {
//dialog.dismiss();
stopDialog();
if(Constants.LOGG) {
Log.d(Constants.TAG, ex.toString());
ex.printStackTrace();
}
mDialogAlert.showDialog("error",context.getString(R.string.not_responding),"");
// Toast.makeText(context,context.getString(R.string.not_responding), Toast.LENGTH_LONG).show();
}
}
});
}
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/koush/AndroidAsync/issues/594#issuecomment-448321273, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Alg-BLazb0vL1fe-rPMGHPHpqNeXrAcAks5u6TOzgaJpZM4SNYDX.
this patch is taken from https://github.com/MegatronKing/NetBare/commit/9b870af1bc8435cdc82adecf5170bfadeecfe878
it works, though I do not know why.
diff --git a/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java b/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java
index 367a592..87d5887 100644
--- a/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java
+++ b/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java
@@ -30,6 +30,7 @@ import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import java.io.ByteArrayInputStream;
+import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -289,11 +290,22 @@ public class AsyncSSLSocketWrapper implements AsyncSocketWrapper, AsyncSSLSocket
int remaining = b.remaining();
int before = pending.remaining();
- SSLEngineResult res;
+ SSLEngineResult res = null;
{
// wrap to prevent access to the readBuf
ByteBuffer readBuf = allocator.allocate();
- res = engine.unwrap(b, readBuf);
+ try {
+ res = engine.unwrap(b, readBuf);
+ } catch (SSLException e) {
+ // workaround bug of android 8.1
+ if (e.getCause() instanceof EOFException && remaining == 31 &&
+ b.remaining() == 0 && readBuf.remaining() == readBuf.capacity()) {
+ // Create a new SSLEngineResult.
+ res = new SSLEngineResult(SSLEngineResult.Status.OK,
+ SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING,
+ remaining, 0);
+ }
+ }
addToPending(pending, readBuf);
allocator.track(pending.remaining() - before);
}
@@ -321,8 +333,8 @@ public class AsyncSSLSocketWrapper implements AsyncSocketWrapper, AsyncSSLSocket
AsyncSSLSocketWrapper.this.onDataAvailable();
}
- catch (SSLException ex) {
-// ex.printStackTrace();
+ catch (Exception ex) {
+ //ex.printStackTrace();
report(ex);
}
finally {
@zhiwenzheng that patch works by masking the underflow error as a success, which causes the allocator to increase the allocation size. the bug is in the underlying SSL library, which is returning an EOF Exception instead of the appropriate buffer underflow hint that it is supposed to return.