Skip to content

Commit 1331f5a

Browse files
authored
* Initial .NET 10 support (#1479)
* Use 'latest' C# language version * TFM conditional compilation * update packages * additional extensions
1 parent 4a5cf6f commit 1331f5a

File tree

17 files changed

+86
-31
lines changed

17 files changed

+86
-31
lines changed

src/SIPSorcery.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Concentus" Version="2.2.2" />
22-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />
22+
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
2323
<PackageReference Include="DnsClient" Version="1.8.0" />
2424
<PackageReference Include="SIPSorcery.WebSocketSharp" Version="0.0.1" />
2525
<PackageReference Include="SIPSorceryMedia.Abstractions" Version="8.0.12" />
@@ -29,15 +29,15 @@
2929
<!-- The packages below are transitive references included to overcome vulnerabilities in a top level package. -->
3030
<PackageReference Include="System.Net.Security" Version="4.3.2" /> <!-- Vuln version referenced by System.Net.WebSockets.Client. -->
3131
</ItemGroup>
32-
32+
3333
<ItemGroup Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'netstandard2.0'">
3434
<PackageReference Include="System.Memory" Version="4.6.3" />
3535
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
3636
</ItemGroup>
3737

3838
<PropertyGroup>
39-
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net462;net5.0;net6.0;net8.0</TargetFrameworks>
40-
<LangVersion>12.0</LangVersion>
39+
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net462;net5.0;net6.0;net8.0;net9.0;net10.0</TargetFrameworks>
40+
<LangVersion>latest</LangVersion>
4141
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
4242
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
4343
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>

src/app/Media/Sources/VideoTestPatternSource.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ public VideoTestPatternSource(IVideoEncoder encoder = null)
9595
else
9696
{
9797
_testI420Buffer = new byte[TEST_PATTERN_WIDTH * TEST_PATTERN_HEIGHT * 3 / 2];
98+
#if NET9_0_OR_GREATER
99+
testPatternStm.ReadExactly(_testI420Buffer, 0, _testI420Buffer.Length);
100+
#else
98101
testPatternStm.Read(_testI420Buffer, 0, _testI420Buffer.Length);
102+
#endif
99103
testPatternStm.Close();
100104
_sendTestPatternTimer = new Timer(GenerateTestPattern, null, Timeout.Infinite, Timeout.Infinite);
101105
_frameSpacing = 1000 / DEFAULT_FRAMES_PER_SECOND;

src/core/SIP/Channels/SIPTLSChannel.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,15 @@ private void DisplayCertificateChain(X509Certificate2 certificate)
355355

356356
private void DisplaySecurityLevel(SslStream stream)
357357
{
358-
logger.LogDebug("Cipher: {CipherAlgorithm} strength {CipherStrength}, Hash: {HashAlgorithm} strength {HashStrength}, Key exchange: {KeyExchangeAlgorithm} strength {KeyExchangeStrength}, Protocol: {SslProtocol}", stream.CipherAlgorithm, stream.CipherStrength, stream.HashAlgorithm, stream.HashStrength, stream.KeyExchangeAlgorithm, stream.KeyExchangeStrength, stream.SslProtocol);
358+
#if NET5_0_OR_GREATER
359+
// Use the negotiated cipher suite property available in .NET 5+.
360+
var cipherSuite = stream.NegotiatedCipherSuite;
361+
logger.LogDebug("Negotiated cipher suite: {CipherSuite}, Protocol: {SslProtocol}", cipherSuite, stream.SslProtocol);
362+
#else
363+
logger.LogDebug("Cipher: {CipherAlgorithm} strength {CipherStrength}, Hash: {HashAlgorithm} strength {HashStrength}, Key exchange: {KeyExchangeAlgorithm} strength {KeyExchangeStrength}, Protocol: {SslProtocol}",
364+
stream.CipherAlgorithm, stream.CipherStrength, stream.HashAlgorithm, stream.HashStrength, stream.KeyExchangeAlgorithm, stream.KeyExchangeStrength, stream.SslProtocol
365+
);
366+
#endif
359367
}
360368

361369
private void DisplaySecurityServices(SslStream stream)
@@ -399,6 +407,6 @@ private void DisplayCertificateInformation(SslStream stream)
399407
}
400408
}
401409

402-
#endregion
410+
#endregion
403411
}
404412
}

src/core/SIPTransportConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ private static X509Certificate2 LoadCertificate(string certificateType, string c
126126

127127
if (certificateType == "file")
128128
{
129+
#if NET9_0_OR_GREATER
130+
var serverCertificate = X509CertificateLoader.LoadPkcs12FromFile(certifcateLocation, certKeyPassword);
131+
#else
129132
var serverCertificate = new X509Certificate2(certifcateLocation, certKeyPassword);
133+
#endif
130134
//DisplayCertificateChain(m_serverCertificate);
131135
var verifyCert = serverCertificate.Verify();
132136
logger.LogDebug("Server Certificate loaded from file, Subject={Subject}, valid={Valid}.", serverCertificate.Subject, verifyCert);

src/net/DtlsSrtp/DtlsUtils.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,11 @@ public static X509Certificate2 ConvertBouncyCert(Org.BouncyCastle.X509.X509Certi
435435
{
436436
pkcs12Store.Save(pfxStream, new char[] { }, new SecureRandom());
437437
pfxStream.Seek(0, SeekOrigin.Begin);
438+
#if NET9_0_OR_GREATER
439+
keyedCert = X509CertificateLoader.LoadPkcs12(pfxStream.ToArray(), string.Empty, X509KeyStorageFlags.Exportable);
440+
#else
438441
keyedCert = new X509Certificate2(pfxStream.ToArray(), string.Empty, X509KeyStorageFlags.Exportable);
442+
#endif
439443
}
440444

441445
return keyedCert;

src/net/ICE/IceChecklistEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ internal void GotStunResponse(STUNMessage stunResponse, IPEndPoint remoteEndPoin
310310
if (lifetime != null)
311311
{
312312
LocalCandidate.IceServer.TurnTimeToExpiry = DateTime.Now +
313-
TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetime.Value.Reverse().ToArray(), 0));
313+
TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetime.Value.FluentReverse().ToArray(), 0));
314314
}
315315
}
316316
else if (stunResponse.Header.MessageType == STUNMessageTypesEnum.RefreshErrorResponse)

src/net/ICE/IceServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ internal bool GotStunResponse(STUNMessage stunResponse, IPEndPoint remoteEndPoin
428428
if (lifetime != null)
429429
{
430430
TurnTimeToExpiry = DateTime.Now +
431-
TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetime.Value.Reverse().ToArray(), 0));
431+
TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetime.Value.FluentReverse().ToArray(), 0));
432432
}
433433
else
434434
{
@@ -536,7 +536,7 @@ internal bool GotStunResponse(STUNMessage stunResponse, IPEndPoint remoteEndPoin
536536
if (lifetime != null)
537537
{
538538
TurnTimeToExpiry = DateTime.Now +
539-
TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetime.Value.Reverse().ToArray(), 0));
539+
TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetime.Value.FluentReverse().ToArray(), 0));
540540
}
541541

542542
}

src/net/STUN/STUNAttributes/STUNXORAddressAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public STUNXORAddressAttribute(STUNAttributeTypesEnum attributeType, byte[] attr
5959
if (BitConverter.IsLittleEndian)
6060
{
6161
Port = NetConvert.DoReverseEndian(BitConverter.ToUInt16(attributeValue, 2)) ^ (UInt16)(STUNHeader.MAGIC_COOKIE >> 16);
62-
address = BitConverter.GetBytes(NetConvert.DoReverseEndian(BitConverter.ToUInt32(attributeValue, 4)) ^ STUNHeader.MAGIC_COOKIE).Reverse().ToArray();
62+
address = BitConverter.GetBytes(NetConvert.DoReverseEndian(BitConverter.ToUInt32(attributeValue, 4)) ^ STUNHeader.MAGIC_COOKIE).FluentReverse().ToArray();
6363
}
6464
else
6565
{

src/net/TURN/TurnClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private void GotStunResponse(STUNMessage stunResponse, IPEndPoint remoteEndPoint
271271

272272
if (permissionLifetime != null)
273273
{
274-
permissionDuration = TimeSpan.FromSeconds(BitConverter.ToUInt32(permissionLifetime.Value.Reverse().ToArray(), 0));
274+
permissionDuration = TimeSpan.FromSeconds(BitConverter.ToUInt32(permissionLifetime.Value.FluentReverse().ToArray(), 0));
275275

276276
logger.LogDebug("TURN permission lifetime attribute value {lifetimeSeconds}s.", permissionDuration.TotalSeconds);
277277
}
@@ -349,7 +349,7 @@ private void ScheduleAllocateRefresh(STUNAttribute lifetimeAttribute)
349349

350350
if (lifetimeAttribute != null)
351351
{
352-
var lifetimeSpan = TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetimeAttribute.Value.Reverse().ToArray(), 0));
352+
var lifetimeSpan = TimeSpan.FromSeconds(BitConverter.ToUInt32(lifetimeAttribute.Value.FluentReverse().ToArray(), 0));
353353

354354
logger.LogDebug("TURN allocate lifetime attribute value {lifetimeSeconds}s.", lifetimeSpan.TotalSeconds);
355355

src/sys/Crypto/Crypto.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ public static string GetHash(string filepath)
269269

270270
// Buffer to read in plain text blocks.
271271
byte[] fileBuffer = new byte[fileStream.Length];
272+
#if NET9_0_OR_GREATER
273+
fileStream.ReadExactly(fileBuffer, 0, (int)fileStream.Length);
274+
#else
272275
fileStream.Read(fileBuffer, 0, (int)fileStream.Length);
276+
#endif
273277
fileStream.Close();
274278

275279
byte[] overallHash = shaM.ComputeHash(fileBuffer);

0 commit comments

Comments
 (0)