GameNetworkingSockets.Net.Certificates
0.3.3
dotnet add package GameNetworkingSockets.Net.Certificates --version 0.3.3
NuGet\Install-Package GameNetworkingSockets.Net.Certificates -Version 0.3.3
<PackageReference Include="GameNetworkingSockets.Net.Certificates" Version="0.3.3" />
<PackageVersion Include="GameNetworkingSockets.Net.Certificates" Version="0.3.3" />
<PackageReference Include="GameNetworkingSockets.Net.Certificates" />
paket add GameNetworkingSockets.Net.Certificates --version 0.3.3
#r "nuget: GameNetworkingSockets.Net.Certificates, 0.3.3"
#:package GameNetworkingSockets.Net.Certificates@0.3.3
#addin nuget:?package=GameNetworkingSockets.Net.Certificates&version=0.3.3
#tool nuget:?package=GameNetworkingSockets.Net.Certificates&version=0.3.3
GameNetworkingSockets.Net
Cross-platform .NET bindings for Valve's GameNetworkingSockets (the open-source standalone variant of Steam's networking transport), with native binaries bundled for win-x64, linux-x64, osx-arm64, and Android (android-arm64, android-x64).
The managed surface is derived from Stanislav Denisov's ValveSockets-CSharp wrapper, modernized for LibraryImport (source-generated P/Invoke, AOT-compatible) and updated against the current steamnetworkingsockets_flat.h API.
Packages
| Package | Contents |
|---|---|
GameNetworkingSockets.Net |
Managed bindings (net8.0/net10.0) plus GameNetworkingSockets.dll / libGameNetworkingSockets.so / libGameNetworkingSockets.dylib under runtimes/{rid}/native/ (desktop + Android). AOT-compatible. |
GameNetworkingSockets.Net.Certificates |
Managed minting and reading of certificates: a root authority, the identity-bound certificates it signs, and the public root peers trust (net10.0). Needs no native GameNetworkingSockets binary; Ed25519 comes from NSec. |
Quick start
using Valve.Sockets;
if (!Library.Initialize(out var error))
throw new Exception(error);
var sockets = new NetworkingSockets();
using var utils = new NetworkingUtils();
utils.SetDebugCallback(DebugType.Important, (type, msg) => Console.WriteLine($"[{type}] {msg}"));
var address = default(Address);
address.SetLocalHost(7777);
var listenSocket = sockets.CreateListenSocket(ref address);
while (!Console.KeyAvailable)
{
sockets.RunCallbacks();
Thread.Sleep(1);
}
sockets.CloseListenSocket(listenSocket);
Library.Deinitialize();
Identity & authentication
GameNetworkingSockets.Net builds GameNetworkingSockets with STEAMNETWORKINGSOCKETS_ALLOW_DYNAMIC_SELFSIGNED_CERTS, so Valve's hardcoded root CA is not installed: outside Steam you bring your own root.
Out of the box the open-source build authenticates nothing. IPAllowWithoutAuth and IPLocalHostAllowWithoutAuth both default to 2, so a client accepts whatever server answers. To require a server signed by your root:
Mint a root authority once, offline, with
GameNetworkingSockets.Net.Certificates, and issue each server a certificate from it. No native binary is involved.using Valve.Sockets; var now = DateTimeOffset.UtcNow; using var authority = NetworkingCertificateAuthority.Create(now, TimeSpan.FromDays(3650)); File.WriteAllBytes("authority.bin", authority.Export()); // secret, keep offline string root = authority.RootCertificate; // public, ship it in the client byte[] server = authority.Issue("str:game-1", now, TimeSpan.FromDays(365)); // secret, deploy to that serverLater,
NetworkingCertificateAuthority.Import(File.ReadAllBytes("authority.bin"))loads it to issue more. An identity isstr:and 1 to 31 bytes, orgen:and 2 to 64 hex digits.On the server, trust the root and take the certificate before opening listen sockets:
sockets.AddTrustedRootCA(root, out var error); sockets.SetCertificate(server, out error);On the client, trust the root and dial with authentication required:
sockets.AddTrustedRootCA(root, out var error); var connection = sockets.Connect(ref address, [Configuration.Int32(ConfigurationValue.IPAllowWithoutAuth, 0)]);
What GameNetworkingSockets checks, and what it lets through:
- A root carries no identity. Identity-bound certificates are kept out of the trust store, which is why an authority names none and
Importrefuses a certificate that does. - A root carries no private key either.
AddTrustedRootCAaccepts the authority itself and ignores its key, so the binding refuses any blob that carries one rather than let the key ship in a client. - An identity-bound certificate must list the app id its peers run as. The open-source build runs as app 0, the default of
Issue. - A process must trust the root of its own certificate, or
SetCertificatecannot read the certificate and fails. SetCertificateinstalls an expired certificate and only peers refuse it, so checkNetworkingCertificate.Read(certificate).Expiryat startup.- Expiries end at 2038-01-19 03:14:07 UTC: GameNetworkingSockets on Windows reads a later one as already passed, so the minter refuses it.
- Loopback stays exempt: a peer on the same machine connects unauthenticated unless the client also sets
IPLocalHostAllowWithoutAuthto 0. - A process holds one certificate, so every socket in it presents the same identity.
The package also ships Valve's steamnetworkingsockets_certtool under tools/{rid}/, whose PEM output NetworkingSockets.SetCertificateAndPrivateKey takes. It cannot bind a certificate to an identity, so it does not cover server authentication.
Socket buffers
GameNetworkingSockets asks the kernel for 256 KiB send and receive buffers on every UDP socket. A listen socket receives every client's packets through its one buffer, so a server with a crowd of clients overflows it in a burst, and the kernel drops what does not fit, handshakes included. Clients then wait out their retries, and lost data waits out its retransmissions. Ask for more before opening the listen socket:
Library.SetUdpSocketBufferSize(8 * 1024 * 1024);
var listenSocket = sockets.CreateListenSocket(ref address);
The setting applies to sockets opened after the call. The kernel caps the request without an error, on Linux at net.core.rmem_max and net.core.wmem_max, so raise those on the host as well.
Runtime dependencies
The native libraries inside the NuGet package have these external runtime dependencies:
| RID | Bundled in package | Required on host |
|---|---|---|
win-x64 |
OpenSSL, protobuf, abseil (DLLs ship next to GameNetworkingSockets.dll) |
UCRT (universal on Win10+) |
linux-x64 |
OpenSSL and protobuf (statically linked) | Standard C/C++ runtime libraries |
osx-arm64 |
OpenSSL and protobuf (statically linked) | macOS system libraries |
android-arm64, android-x64 |
OpenSSL, protobuf, and libc++ (statically linked) | Android system libraries only (liblog, libc, libm, libdl); min API 21 |
The Unix and Android builds download protobuf 21.12 and OpenSSL 3.5.7 from their
official release archives, verify their SHA-256 checksums, and build both from
source as position-independent static libraries. This avoids coupling package
consumers to distribution or Homebrew native ABIs. The Android library links
libc++ statically as well, so each .so carries no extra runtime dependency.
.NET-for-Android consumers get the per-ABI .so placed into the APK
(lib/<abi>/) automatically via the bundled buildTransitive targets.
Building from source
Prerequisites:
- .NET SDK 10 (see
global.json) - CMake 3.15+, curl, and Perl
- A C++ toolchain (MSVC on Windows, gcc/clang on Linux, Apple clang on macOS)
- For Android: the Android NDK (r27 tested), located via
ANDROID_NDK_ROOTorANDROID_NDK_LATEST_HOME - PowerShell 7+ (for the Windows native build script)
- Windows: installed automatically via vcpkg manifest mode (
external/GameNetworkingSockets/vcpkg.json); the build script bootstraps a local vcpkg underbuild/vcpkg-localon first run - Linux (Debian/Ubuntu):
sudo apt install build-essential cmake curl perl - macOS (Homebrew):
brew install cmake
- Windows: installed automatically via vcpkg manifest mode (
Protobuf and OpenSSL are fetched and built by build-native-unix.sh; system
installations of either library are neither used nor required.
Steps:
# 1. Initialize the GameNetworkingSockets submodule and its dependencies.
pwsh build/bootstrap.ps1
# 2. Build the native shared library for your platform.
pwsh build/build-native-win.ps1 # Windows
bash build/build-native-unix.sh linux-x64 # Linux
bash build/build-native-unix.sh osx-arm64 # macOS (Apple Silicon)
bash build/build-native-android.sh arm64-v8a # Android arm64-v8a (-> android-arm64)
bash build/build-native-android.sh x86_64 # Android x86_64 (-> android-x64)
# 3. Build the managed solution.
dotnet build GameNetworkingSockets.Net.sln
Output is staged into artifacts/native/{rid}/ and packed into the NuGet package via the runtimes/{rid}/native/ convention.
When working only on the managed side (no native binaries available), suppress the pack-time warning with:
dotnet build GameNetworkingSockets.Net.sln -p:SkipNativeWarning=true
Layout
external/GameNetworkingSockets/ # git submodule, pinned to a specific upstream SHA
build/ # CMakeLists.txt, vcpkg manifest, per-platform build scripts
src/GameNetworkingSockets.Net/ # managed wrapper library (multi-targets net8.0;net10.0)
src/GameNetworkingSockets.Net.Certificates/ # managed certificate minting (net10.0)
src/Shared/ # source compiled into both packages
tests/ # xunit smoke tests + AOT sample
artifacts/native/ # staging for native binaries before packing
.github/workflows/ # ci-pr, build-native, package
License
MIT — matches the upstream ValveSockets-CSharp wrapper. See THIRD-PARTY-NOTICES.md for the GameNetworkingSockets (BSD 3-Clause), OpenSSL/libsodium, and Protocol Buffers attributions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- NSec.Cryptography (>= 26.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.