diff --git a/.github/workflows/nuget-preview.yml b/.github/workflows/nuget-preview.yml index 174618bb..5e056538 100644 --- a/.github/workflows/nuget-preview.yml +++ b/.github/workflows/nuget-preview.yml @@ -115,5 +115,37 @@ jobs: run: | test -n "$NUGET_API_KEY" for package in packages/*.nupkg; do - dotnet nuget push "$package" --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" + dotnet nuget push "$package" --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" --skip-duplicate done + + - name: Verify published packages restore + timeout-minutes: 6 + env: + PUBLISHED_SDK_VERSION: ${{ needs.verify.outputs.version }} + run: | + python3 - <<'PYTHON' + import json, os, pathlib, subprocess, tempfile, time + version = os.environ['PUBLISHED_SDK_VERSION'] + with tempfile.TemporaryDirectory(prefix='published-sdk-consumer-') as directory: + root = pathlib.Path(directory) + project = root / 'PublishedSdkConsumer.csproj' + project.write_text('net8.0') + config = root / 'NuGet.Config' + config.write_text('') + for attempt in range(10): + result = subprocess.run(['dotnet', 'restore', str(project), '--configfile', str(config), '--packages', str(root / 'packages'), '--use-lock-file', '--no-cache', '--force-evaluate'], text=True, capture_output=True, timeout=30) + if result.returncode == 0: + break + print(result.stdout[-2000:] + result.stderr[-2000:], flush=True) + if attempt == 9: + raise RuntimeError('Published SDK packages did not become restorable') + time.sleep(5) + locked = json.loads((root / 'packages.lock.json').read_text())['dependencies']['net8.0'] + hashes = {} + for name in ('DolphinDotNet.Core', 'DolphinDotNet.GameCube'): + package = locked[name] + if package['resolved'] != version or not package.get('contentHash'): + raise RuntimeError('Published SDK dependency identity differs: ' + name) + hashes[name] = {'version': package['resolved'], 'contentHash': package['contentHash']} + print('PUBLISHED_PACKAGE_HASHES ' + json.dumps(hashes, sort_keys=True), flush=True) + PYTHON diff --git a/docs/https.md b/docs/https.md index 2fdd2ada..93e06e77 100644 --- a/docs/https.md +++ b/docs/https.md @@ -92,8 +92,12 @@ peer close-notify, so cancellation never blocks on TLS shutdown. Relative and scheme-relative redirects retain HTTPS. Cross-origin redirects (including scheme or effective-port changes) drop authorization/cookie headers. HTTPS-to-HTTP redirects fail. No application request bytes are sent until the -TLS handshake and server verification succeed. Existing Connection: close, -response buffering and body/header limits remain in force. +TLS handshake and server verification succeed. HTTP/1.1 requests allow the peer +to keep the connection open while the complete framed response is consumed. The +SDK still owns one connection per response and closes it at the content-length +or final chunk boundary, on disposal, cancellation or failure. Close-delimited +bodies still finish at peer EOF. There is no connection pooling. Response +buffering and body/header limits remain in force. ## Validation @@ -143,3 +147,10 @@ and unpredictable WebSocket masks; pool small draws. The existing bounded DRBG reseed interval still applies. Exhaustion fails closed: dispose connections, collect fresh platform entropy and reconfigure before reconnecting. This API never manufactures replacement entropy or changes certificate validation. + +`TlsConfiguration.LastErrorCode` exposes the existing native provider's last +numeric error for diagnostics. Successful initialization clears it to zero; +provider failures record a negative code. Read it immediately after failure, +before another TLS operation can replace this process-wide value. It contains +no credentials, certificate contents or application payloads and does not +change validation, cancellation or retry behavior. diff --git a/docs/network-runtime.md b/docs/network-runtime.md index 48d1ce75..da748b22 100644 --- a/docs/network-runtime.md +++ b/docs/network-runtime.md @@ -66,7 +66,7 @@ This is ordinary DNS, not DNSSEC or encrypted DNS. Query IDs combine a local cou HTTP uses an incremental parser over TCP. It supports fixed-length, chunked and close-delimited responses, informational responses, HEAD/no-body statuses, trailers, selected automatic GET/HEAD redirects, response headers and body streaming. Credentials are removed when redirects change authority. Redirect count defaults to five. Request framing headers are generated by the implementation and cannot be overridden. Ambiguous/duplicate framing, truncation, header injection and unsupported transfer/content encodings fail explicitly. -Headers are capped at 8 KiB/64 fields; chunk metadata at 256 bytes per line; trailers at 8 KiB. Convenience response buffering defaults to 64 KiB and can be configured through the Dolphin HttpClient API. Streamed bodies default to a 16 MiB cap. Set `Dolphin.Network.Http.HttpClient.MaximumStreamBytes` before sending a request to opt in to larger streamed bodies (up to `int.MaxValue` bytes). The limit is captured per request and applies to fixed, chunked and close-delimited bodies; buffered response limits remain independent. Use ResponseHeadersRead or GetStreamAsync for large data. GetStringAsync validates UTF-8. Connections use `Connection: close`; pooling, cookies, proxy support and decompression are deferred. +Headers are capped at 8 KiB/64 fields; chunk metadata at 256 bytes per line; trailers at 8 KiB. Convenience response buffering defaults to 64 KiB and can be configured through the Dolphin HttpClient API. Streamed bodies default to a 16 MiB cap. Set `Dolphin.Network.Http.HttpClient.MaximumStreamBytes` before sending a request to opt in to larger streamed bodies (up to `int.MaxValue` bytes). The limit is captured per request and applies to fixed, chunked and close-delimited bodies; buffered response limits remain independent. Use ResponseHeadersRead or GetStreamAsync for large data. GetStringAsync validates UTF-8. Requests use `Connection: keep-alive` so the peer can remain open until the complete framed response is consumed. Each response still owns one connection: the SDK closes it at the content-length or final chunk boundary, on disposal, cancellation or failure. Close-delimited bodies finish at peer EOF. Pooling, cookies, proxy support and decompression are deferred. `https://` is supported through the SDK native TLS provider after explicit trust, entropy and UTC initialization; see [HTTPS setup and limits](https.md). Missing configuration fails closed. There is no insecure certificate bypass. HTTP/2, HTTP/3/QUIC, HttpListener/ASP.NET, reflection serializers and legacy WebRequest/WebClient remain outside this subset. diff --git a/scripts/ci_https.py b/scripts/ci_https.py index 0e886f58..bebd82b0 100644 --- a/scripts/ci_https.py +++ b/scripts/ci_https.py @@ -31,6 +31,7 @@ class Program { Wait(NetworkRuntime.StartAsync(new NetworkOptions{DnsServers=new[]{Dolphin.Network.IPAddress.Loopback},DnsPort=15353},default)); var ca=Dolphin.Text.Encoding.ASCII.GetBytes($CA);var seed=new byte[]{$ENTROPY};TlsConfiguration.Initialize(ca,seed,$UTC); for(int i=0;i=0)return 33; var noPipe=new System.Threading.CancellationTokenSource();noPipe.Cancel();try{TlsStream.ConnectAsync("localhost",$PORT,noPipe.Token);return 30;}catch(OperationCanceledException){} using(var client=new HttpClient()){ client.DefaultRequestHeaders.Add("authorization","test-secret"); -foreach(string path in new[]{"/final","/relative","/network","/cross","/chunked"}){var task=client.GetStringAsync($URL+path);Wait(task);if(task.GetAwaiter().GetResult()!="OK")return 2;} +foreach(string path in new[]{"/final","/relative","/network","/cross","/chunked","/close-delimited"}){Console.WriteLine("HTTP_PATH="+path);var task=client.GetStringAsync($URL+path);Wait(task);if(task.GetAwaiter().GetResult()!="OK")return 2;} try{Wait(client.GetStringAsync($URL+"/downgrade"));return 3;}catch(IOException){} var streamTask=client.GetStreamAsync($URL+"/chunked");Wait(streamTask);using(var stream=streamTask.GetAwaiter().GetResult()){var b=new byte[8];int total=0;while(true){var r=stream.ReadAsync(b,0,b.Length);Wait(r);int n=r.GetAwaiter().GetResult();if(n==0)break;total+=n;}if(total!=2)return 4;} try{Wait(client.GetStringAsync($WRONG));return 5;}catch(IOException){} @@ -57,12 +59,14 @@ class Program { } foreach(int quantum in new[]{4096,16384}){ using(var client=new Dolphin.Network.Http.HttpClient()){client.StreamReadBufferSize=quantum; -foreach(string path in new[]{"/bulk","/bulk-chunked"}){ +foreach(string path in new[]{"/bulk","/bulk-chunked","/client-owned-close","/client-owned-close-chunked"}){ +Console.WriteLine("HTTP_STREAM_PATH="+path+" QUANTUM="+quantum); var pending=client.GetStreamAsync($URL+path);Wait(pending);using(var stream=pending.GetAwaiter().GetResult()){ var data=new byte[16384];int total=0,calls=0,largest=0; while(true){var read=stream.ReadAsync(data,0,data.Length);Wait(read);int n=read.GetAwaiter().GetResult();if(n==0)break;calls++;if(n>largest)largest=n;for(int i=0;iquantum||quantum==16384&&largest<=4096)return 21; Console.WriteLine("HTTP_QUANTUM="+quantum+" CALLS="+calls+" MAX="+largest+" BYTES="+total); +if(path=="/client-owned-close"||path=="/client-owned-close-chunked"){var closed=client.GetStringAsync($URL+"/client-owned-close-observed");Wait(closed);if(closed.GetAwaiter().GetResult()!="OK")return 35;} }}}} using(var bounds=new Dolphin.Network.Http.HttpClient()){foreach(int bad in new[]{0,4095,16385}){try{bounds.StreamReadBufferSize=bad;return 22;}catch(ArgumentOutOfRangeException){}}} TlsConfiguration.Reset();using(var client=new HttpClient()){try{Wait(client.GetStringAsync($URL+"/final"));return 6;}catch(IOException){}} @@ -74,10 +78,11 @@ class Program { for(int i=0;i8192||(payload!=null&&payload.Length>65536))throw new IOException("HTTP request exceeds limits.");var all=new byte[head.Length+(payload==null?0:payload.Length)];Array.Copy(head,all,head.Length);if(payload!=null)Array.Copy(payload,0,all,head.Length,payload.Length);return all; } diff --git a/src/DolphinDotNet.Core/Dolphin/Network/NativeNetwork.cs b/src/DolphinDotNet.Core/Dolphin/Network/NativeNetwork.cs index 58ce9b15..bda83118 100644 --- a/src/DolphinDotNet.Core/Dolphin/Network/NativeNetwork.cs +++ b/src/DolphinDotNet.Core/Dolphin/Network/NativeNetwork.cs @@ -6,6 +6,7 @@ internal static class NativeNetwork internal static int TlsConfigure(byte[] roots,byte[] entropy,long unixSeconds)=>throw Unsupported(); internal static int TlsConfigureLocalClock(byte[] roots,byte[] entropy,long localUnixSeconds)=>throw Unsupported(); internal static int TlsReset()=>throw Unsupported(); + internal static int TlsError()=>throw Unsupported(); internal static int TlsStart(int handle,string hostname)=>throw Unsupported(); internal static int TlsRandom(int handle,byte[] buffer,int offset,int count)=>throw Unsupported(); internal static int TlsHandshake(int handle)=>throw Unsupported(); diff --git a/src/DolphinDotNet.Core/Dolphin/Network/TlsConfiguration.cs b/src/DolphinDotNet.Core/Dolphin/Network/TlsConfiguration.cs index 9d563051..736b422f 100644 --- a/src/DolphinDotNet.Core/Dolphin/Network/TlsConfiguration.cs +++ b/src/DolphinDotNet.Core/Dolphin/Network/TlsConfiguration.cs @@ -6,6 +6,12 @@ namespace Dolphin.Network; /// copied natively. The entropy array is cleared, including on failure. public static class TlsConfiguration { + /// Last native TLS provider error, for immediate numeric diagnostics. + /// Zero follows successful initialization; a provider failure records a + /// negative code. Read before another TLS operation can replace it. This is + /// process-wide diagnostic state, not a connection result or retry policy. + public static int LastErrorCode=>NativeNetwork.TlsError(); + /// Explicit PEM trust anchors, maximum 256 KiB. /// 48–64 cryptographically random secret bytes, fresh /// for every initialization and process boot. Never use Random, ticks, public diff --git a/tools/DolphinDotNet.Compiler/NativeStorageBindings.cs b/tools/DolphinDotNet.Compiler/NativeStorageBindings.cs index 47121492..df5b5baf 100644 --- a/tools/DolphinDotNet.Compiler/NativeStorageBindings.cs +++ b/tools/DolphinDotNet.Compiler/NativeStorageBindings.cs @@ -225,6 +225,7 @@ internal static class NativeStorageBindings ["TlsConfigureLocalClock"]=("dnd_net_tls_configure_local_clock","aal",false), ["Fill"]=("dnd_platform_entropy_fill_array","ai",false), ["TlsReset"]=("dnd_net_tls_reset","",false), + ["TlsError"]=("dnd_net_tls_error","",false), ["TlsRandom"]=("dnd_net_tls_random","iaii",false), ["TlsStart"]=("dnd_net_tls_start","is",false),["TlsHandshake"]=("dnd_net_tls_handshake","i",false), ["NetStart"]=("dnd_net_start","iiii",false),["NetStatus"]=("dnd_net_status","",false),["NetTime"]=("dnd_net_time","",false),["NetError"]=("dnd_net_error","",false),