#region Send Alert Methods
+ internal void SendAlert(ref Exception ex)
+ {
+ var tlsEx = ex as TlsException;
+ var alert = tlsEx != null ? tlsEx.Alert : new Alert(AlertDescription.InternalError);
+
+ try {
+ SendAlert(alert);
+ } catch (Exception alertEx) {
+ ex = new IOException (string.Format ("Error while sending TLS Alert ({0}:{1}): {2}", alert.Level, alert.Description, ex), ex);
+ }
+ }
+
public void SendAlert(AlertDescription description)
{
this.SendAlert(new Alert(description));
}
- public void SendAlert(
- AlertLevel level,
- AlertDescription description)
+ public void SendAlert(AlertLevel level, AlertDescription description)
{
this.SendAlert(new Alert(level, description));
}
break;
}
}
- catch (TlsException ex)
- {
- // FIXME: should the send alert also be done asynchronously here and below?
- this.protocol.SendAlert(ex.Alert);
- negotiate.SetComplete (new IOException("The authentication or decryption has failed.", ex));
- }
catch (Exception ex)
{
- this.protocol.SendAlert(AlertDescription.InternalError);
- negotiate.SetComplete (new IOException("The authentication or decryption has failed.", ex));
+ this.protocol.SendAlert(ref ex);
+ negotiate.SetComplete(new IOException("The authentication or decryption has failed.", ex));
}
}
{
this.EndNegotiateHandshake(asyncResult);
}
- catch (TlsException ex)
- {
- this.protocol.SendAlert(ex.Alert);
-
- throw new IOException("The authentication or decryption has failed.", ex);
- }
catch (Exception ex)
{
- this.protocol.SendAlert(AlertDescription.InternalError);
-
+ this.protocol.SendAlert(ref ex);
throw new IOException("The authentication or decryption has failed.", ex);
}
}
}
}
- catch (TlsException ex)
- {
- this.negotiationComplete.Set();
- this.protocol.SendAlert(ex.Alert);
-
- throw new IOException("The authentication or decryption has failed.", ex);
- }
catch (Exception ex)
{
this.negotiationComplete.Set();
- this.protocol.SendAlert(AlertDescription.InternalError);
+ this.protocol.SendAlert(ref ex);
throw new IOException("The authentication or decryption has failed.", ex);
}
asyncResult.SetComplete(0);
}
}
- catch (TlsException ex)
- {
- this.protocol.SendAlert(ex.Alert);
-
- throw new IOException("The authentication or decryption has failed.", ex);
- }
catch (Exception ex)
{
- throw new IOException("IO exception during read.", ex);
+ this.protocol.SendAlert(ref ex);
+ throw new IOException("The authentication or decryption has failed.", ex);
}
}
record, 0, record.Length, new AsyncCallback(InternalWriteCallback), asyncResult);
}
}
- catch (TlsException ex)
+ catch (Exception ex)
{
- this.protocol.SendAlert(ex.Alert);
+ this.protocol.SendAlert (ref ex);
this.Close();
throw new IOException("The authentication or decryption has failed.", ex);
}
- catch (Exception ex)
- {
- throw new IOException("IO exception during Write.", ex);
- }
}
private void InternalWriteCallback(IAsyncResult ar)
byte[] record = this.protocol.EncodeRecord (ContentType.ApplicationData, buffer, offset, count);
this.innerStream.Write (record, 0, record.Length);
}
- catch (TlsException ex)
+ catch (Exception ex)
{
- this.protocol.SendAlert(ex.Alert);
+ this.protocol.SendAlert(ref ex);
this.Close();
throw new IOException("The authentication or decryption has failed.", ex);
}
- catch (Exception ex)
- {
- throw new IOException("IO exception during Write.", ex);
- }
}
}