Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -124,8 +124,8 @@ namespace Mono.Security.Protocol.Tls
public Alert(AlertDescription description)
{
this.inferAlertLevel();
this.description = description;
this.level = inferAlertLevel(description);
}
public Alert(
@@ -140,15 +140,14 @@ namespace Mono.Security.Protocol.Tls
#region Private Methods
private void inferAlertLevel()
private static AlertLevel inferAlertLevel(AlertDescription description)
{
switch (description)
{
case AlertDescription.CloseNotify:
case AlertDescription.NoRenegotiation:
case AlertDescription.UserCancelled:
this.level = AlertLevel.Warning;
break;
return AlertLevel.Warning;
case AlertDescription.AccessDenied:
case AlertDescription.BadCertificate:
@@ -171,8 +170,7 @@ namespace Mono.Security.Protocol.Tls
case AlertDescription.UnknownCA:
case AlertDescription.UnsupportedCertificate:
default:
this.level = AlertLevel.Fatal;
break;
return AlertLevel.Fatal;
}
}

View File

@@ -477,12 +477,8 @@ namespace Mono.Security.Protocol.Tls
break;
case CipherAlgorithmType.Rijndael:
#if MOBILE || NET_4_0
// only AES is really used - and we can use CommonCrypto for iOS and OSX this way
this.encryptionAlgorithm = Aes.Create();
#else
this.encryptionAlgorithm = Rijndael.Create();
#endif
break;
}
@@ -548,12 +544,8 @@ namespace Mono.Security.Protocol.Tls
break;
case CipherAlgorithmType.Rijndael:
#if MOBILE || NET_4_0
// only AES is really used - and we can use CommonCrypto for iOS and OSX this way
this.decryptionAlgorithm = Aes.Create();
#else
this.decryptionAlgorithm = Rijndael.Create();
#endif
break;
}

View File

@@ -589,14 +589,24 @@ namespace Mono.Security.Protocol.Tls
#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));
}

View File

@@ -40,9 +40,7 @@ namespace Mono.Security.Protocol.Tls
Ssl2 = 12,
Ssl3 = 48,
Tls = 192,
#if NET_4_5
Tls11 = 768,
Tls12 = 3072,
#endif
}
}

View File

@@ -590,7 +590,7 @@ namespace Mono.Security.Protocol.Tls
{
try {
Exception e = ex;
this.protocol.SendAlert(ex.Alert != null ? ex.Alert : new Alert (AlertDescription.InternalError));
this.protocol.SendAlert(ref e);
} catch {
}
negotiate.SetComplete(new IOException("The authentication or decryption has failed.", ex));

View File

@@ -98,16 +98,9 @@ namespace Mono.Security.Protocol.Tls
{
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);
}
@@ -502,17 +495,10 @@ namespace Mono.Security.Protocol.Tls
}
}
}
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);
}
@@ -628,15 +614,10 @@ namespace Mono.Security.Protocol.Tls
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);
}
}
@@ -781,17 +762,13 @@ namespace Mono.Security.Protocol.Tls
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)
@@ -1121,15 +1098,11 @@ namespace Mono.Security.Protocol.Tls
byte[] record = this.protocol.EncodeRecord (ContentType.ApplicationData, buffer, offset, count);
this.innerStream.Write (record, 0, record.Length);
}
catch (TlsException ex)
{
this.protocol.SendAlert(ex.Alert);
this.Close();
throw new IOException("The authentication or decryption has failed.", ex);
}
catch (Exception ex)
{
throw new IOException("IO exception during Write.", ex);
this.protocol.SendAlert(ref ex);
this.Close();
throw new IOException("The authentication or decryption has failed.", ex);
}
}
}