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

Removal of AGPL code #1140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/net/DtlsSrtp/AlertLevels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SIPSorcery.Net
{
public enum AlertLevels : byte
{
Warning = 1,
Fatal = 2
}
}
38 changes: 38 additions & 0 deletions src/net/DtlsSrtp/AlertTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace SIPSorcery.Net
{
public enum AlertTypes : byte
{
CloseNotify = 0,
UnexpectedMessage = 10,
BadRecordMac = 20,
DecryptionFailed = 21,
RecordOverflow = 22,
DecompressionFailure = 30,
HandshakeFailure = 40,
NoCertificate = 41,
BadCertificate = 42,
UnsupportedCertificate = 43,
CertificateRevoked = 44,
CertificateExpired = 45,
CertificateUnknown = 46,
IllegalParameter = 47,
UnknownCA = 48,
AccessDenied = 49,
DecodeError = 50,
DecryptError = 51,
ExportRestriction = 60,
ProtocolVersion = 70,
InsufficientSecurity = 71,
InternalError = 80,
InappropriateFallback = 86,
UserCanceled = 90,
NoRenegotiation = 100,
UnsupportedExtension = 110,
CertificateUnobtainable = 111,
UnrecognizedName = 112,
BadCertificateStatusResponse = 113,
BadCertificateHashValue = 114,
UnknownPskIdentity = 115,
Unknown = 255
}
}
73 changes: 27 additions & 46 deletions src/net/DtlsSrtp/DtlsSrtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal TlsClientContext TlsContext
/// - alert type,
/// - alert description.
/// </summary>
public event Action<AlertLevelsEnum, AlertTypesEnum, string> OnAlert;
public event Action<AlertLevels, AlertTypes, string> OnAlert;

public DtlsSrtpClient() :
this(null, null, null)
Expand Down Expand Up @@ -141,7 +141,7 @@ public DtlsSrtpClient(Certificate certificateChain, AsymmetricKeyParameter priva
{
SecureRandom random = new SecureRandom();
int[] protectionProfiles = { SrtpProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80 };
byte[] mki = new byte[(SrtpParameters.SRTP_AES128_CM_HMAC_SHA1_80.GetCipherKeyLength() + SrtpParameters.SRTP_AES128_CM_HMAC_SHA1_80.GetCipherSaltLength()) / 8];
byte[] mki = new byte[(SecureRtpParameters.SRTP_AES128_CM_HMAC_SHA1_80.EncryptionKeyLength + SecureRtpParameters.SRTP_AES128_CM_HMAC_SHA1_80.SaltLength) / 8];
random.NextBytes(mki); // Reusing our secure random for generating the key.
this.clientSrtpData = new UseSrtpData(protectionProfiles, mki);
}
Expand Down Expand Up @@ -205,35 +205,16 @@ public override void ProcessServerExtensions(IDictionary clientExtensions)
clientSrtpData = new UseSrtpData(protectionProfiles, clientSrtpData.Mki);
}

public virtual SrtpPolicy GetSrtpPolicy()
{
return srtpPolicy;
}
public virtual SrtpPolicy SrtpPolicy => srtpPolicy;

public virtual SrtpPolicy GetSrtcpPolicy()
{
return srtcpPolicy;
}
public virtual SrtpPolicy SrtcpPolicy => srtcpPolicy;

public virtual byte[] GetSrtpMasterServerKey()
{
return srtpMasterServerKey;
}
public virtual byte[] SrtpMasterServerKey => srtpMasterServerKey;
public virtual byte[] SrtpMasterServerSalt => srtpMasterServerSalt;

public virtual byte[] GetSrtpMasterServerSalt()
{
return srtpMasterServerSalt;
}
public virtual byte[] SrtpMasterClientKey => srtpMasterClientKey;

public virtual byte[] GetSrtpMasterClientKey()
{
return srtpMasterClientKey;
}

public virtual byte[] GetSrtpMasterClientSalt()
{
return srtpMasterClientSalt;
}
public virtual byte[] SrtpMasterClientSalt => srtpMasterClientSalt;

public override TlsAuthentication GetAuthentication()
{
Expand All @@ -252,10 +233,7 @@ public override void NotifyHandshakeComplete()
PrepareSrtpSharedSecret();
}

public bool IsClient()
{
return true;
}
public bool IsClient { get; } = true;

protected byte[] GetKeyingMaterial(int length)
{
Expand Down Expand Up @@ -322,12 +300,12 @@ protected virtual void PrepareSrtpSharedSecret()
//Set master secret back to security parameters (only works in old bouncy castle versions)
//mContext.SecurityParameters.MasterSecret = masterSecret;

SrtpParameters srtpParams = SrtpParameters.GetSrtpParametersForProfile(clientSrtpData.ProtectionProfiles[0]);
int keyLen = srtpParams.GetCipherKeyLength();
int saltLen = srtpParams.GetCipherSaltLength();
SecureRtpParameters srtpParams = SecureRtpParameters.GetParametersForProfile(clientSrtpData.ProtectionProfiles[0]);
int keyLen = srtpParams.EncryptionKeyLength;
int saltLen = srtpParams.SaltLength;

srtpPolicy = srtpParams.GetSrtpPolicy();
srtcpPolicy = srtpParams.GetSrtcpPolicy();
srtpPolicy = srtpParams.GetPolicy();
srtcpPolicy = srtpParams.GetRtcpPolicy();

srtpMasterClientKey = new byte[keyLen];
srtpMasterServerKey = new byte[keyLen];
Expand Down Expand Up @@ -401,7 +379,7 @@ public override void NotifyAlertRaised(byte alertLevel, byte alertDescription, s
string alertMessage = $"{AlertLevel.GetText(alertLevel)}, {AlertDescription.GetText(alertDescription)}";
alertMessage += !string.IsNullOrEmpty(description) ? $", {description}." : ".";

if (alertDescription == AlertTypesEnum.close_notify.GetHashCode())
if (alertDescription == AlertTypes.CloseNotify.GetHashCode())
{
logger.LogDebug($"DTLS client raised close notification: {alertMessage}");
}
Expand All @@ -416,29 +394,32 @@ public override void NotifyServerVersion(ProtocolVersion serverVersion)
base.NotifyServerVersion(serverVersion);
}

public Certificate GetRemoteCertificate()
public Certificate RemoteCertificate
{
return ServerCertificate;
get
{
return ServerCertificate;
}
}

public override void NotifyAlertReceived(byte alertLevel, byte alertDescription)
{
string description = AlertDescription.GetText(alertDescription);

AlertLevelsEnum level = AlertLevelsEnum.Warning;
AlertTypesEnum alertType = AlertTypesEnum.unknown;
AlertLevels level = AlertLevels.Warning;
AlertTypes alertType = AlertTypes.Unknown;

if (Enum.IsDefined(typeof(AlertLevelsEnum), alertLevel))
if (Enum.IsDefined(typeof(AlertLevels), alertLevel))
{
level = (AlertLevelsEnum)alertLevel;
level = (AlertLevels)alertLevel;
}

if (Enum.IsDefined(typeof(AlertTypesEnum), alertDescription))
if (Enum.IsDefined(typeof(AlertTypes), alertDescription))
{
alertType = (AlertTypesEnum)alertDescription;
alertType = (AlertTypes)alertDescription;
}

if (alertType == AlertTypesEnum.close_notify)
if (alertType == AlertTypes.CloseNotify)
{
logger.LogDebug($"DTLS client received close notification: {AlertLevel.GetText(alertLevel)}, {description}.");
}
Expand Down
Loading