@@ -43,6 +43,7 @@ unsafe internal class UnityTlsContext : MobileTlsContext
43
43
byte [ ] m_ReadBuffer ;
44
44
45
45
GCHandle m_handle ;
46
+ Exception lastException ;
46
47
47
48
public UnityTlsContext (
48
49
MobileAuthenticatedStream parent ,
@@ -150,10 +151,13 @@ public override (int ret, bool wantMore) Read (byte[] buffer, int offset, int co
150
151
bool wouldBlock = false ;
151
152
int numBytesRead = 0 ;
152
153
154
+ lastException = null ;
153
155
var errorState = UnityTls . NativeInterface . unitytls_errorstate_create ( ) ;
154
156
fixed ( byte * bufferPtr = buffer ) {
155
157
numBytesRead = UnityTls . NativeInterface . unitytls_tlsctx_read ( m_TlsContext , bufferPtr + offset , count , & errorState ) ;
156
158
}
159
+ if ( lastException != null )
160
+ throw lastException ;
157
161
158
162
if ( errorState . code == UnityTls . unitytls_error_code . UNITYTLS_USER_WOULD_BLOCK )
159
163
wouldBlock = true ;
@@ -168,10 +172,13 @@ public override (int ret, bool wantMore) Write (byte[] buffer, int offset, int c
168
172
bool wouldBlock = false ;
169
173
int numBytesWritten = 0 ;
170
174
175
+ lastException = null ;
171
176
var errorState = UnityTls . NativeInterface . unitytls_errorstate_create ( ) ;
172
177
fixed ( byte * bufferPtr = buffer ) {
173
178
numBytesWritten = UnityTls . NativeInterface . unitytls_tlsctx_write ( m_TlsContext , bufferPtr + offset , count , & errorState ) ;
174
179
}
180
+ if ( lastException != null )
181
+ throw lastException ;
175
182
176
183
if ( errorState . code == UnityTls . unitytls_error_code . UNITYTLS_USER_WOULD_BLOCK )
177
184
wouldBlock = true ;
@@ -233,10 +240,13 @@ public override void StartHandshake ()
233
240
234
241
public override bool ProcessHandshake ( )
235
242
{
243
+ lastException = null ;
236
244
var errorState = UnityTls . NativeInterface . unitytls_errorstate_create ( ) ;
237
245
var result = UnityTls . NativeInterface . unitytls_tlsctx_process_handshake ( m_TlsContext , & errorState ) ;
238
246
if ( errorState . code == UnityTls . unitytls_error_code . UNITYTLS_USER_WOULD_BLOCK )
239
247
return false ;
248
+ if ( lastException != null )
249
+ throw lastException ;
240
250
241
251
// Not done is not an error if we are server and don't ask for ClientCertificate
242
252
if ( result == UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_NOT_DONE && IsServer && ! AskForClientCertificate )
@@ -298,8 +308,10 @@ private size_t WriteCallback (byte* data, size_t bufferLen, UnityTls.unitytls_er
298
308
}
299
309
300
310
return bufferLen ;
301
- } catch { // handle all exceptions since we don't want to let them go through native code.
311
+ } catch ( Exception ex ) { // handle all exceptions and store them for later since we don't want to let them go through native code.
302
312
UnityTls . NativeInterface . unitytls_errorstate_raise_error ( errorState , UnityTls . unitytls_error_code . UNITYTLS_USER_UNKNOWN_ERROR ) ;
313
+ if ( lastException == null )
314
+ lastException = ex ;
303
315
return 0 ;
304
316
}
305
317
}
@@ -331,8 +343,10 @@ private size_t ReadCallback (byte* buffer, size_t bufferLen, UnityTls.unitytls_e
331
343
332
344
Marshal . Copy ( m_ReadBuffer , 0 , ( IntPtr ) buffer , bufferLen ) ;
333
345
return numBytesRead ;
334
- } catch { // handle all exceptions since we don't want to let them go through native code.
346
+ } catch ( Exception ex ) { // handle all exceptions and store them for later since we don't want to let them go through native code.
335
347
UnityTls . NativeInterface . unitytls_errorstate_raise_error ( errorState , UnityTls . unitytls_error_code . UNITYTLS_USER_UNKNOWN_ERROR ) ;
348
+ if ( lastException == null )
349
+ lastException = ex ;
336
350
return 0 ;
337
351
}
338
352
}
@@ -354,7 +368,9 @@ private UnityTls.unitytls_x509verify_result VerifyCallback (UnityTls.unitytls_x5
354
368
return UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_SUCCESS ;
355
369
else
356
370
return UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED ;
357
- } catch { // handle all exceptions since we don't want to let them go through native code.
371
+ } catch ( Exception ex ) { // handle all exceptions and store them for later since we don't want to let them go through native code.
372
+ if ( lastException == null )
373
+ lastException = ex ;
358
374
return UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FATAL_ERROR ;
359
375
}
360
376
}
0 commit comments