-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add unit tests for SSL/TLS #413
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,4 +62,4 @@ | |
| <ProjectConfigurationsDeclaredAsItems /> | ||
| </ProjectCapabilities> | ||
| </ProjectExtensions> | ||
| </Project> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,4 +71,4 @@ | |
| <ProjectConfigurationsDeclaredAsItems /> | ||
| </ProjectCapabilities> | ||
| </ProjectExtensions> | ||
| </Project> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Security.Cryptography.X509Certificates; | ||
|
|
||
| namespace NetworkTestCompanion; | ||
|
|
||
| /// <summary> | ||
| /// Provides the static test certificate used by the companion's TLS echo server. | ||
| /// | ||
| /// This is a self-signed RSA-2048 test certificate (CN=nanoFramework Test Server). | ||
| /// The device connects to the companion's TLS echo server with certificate | ||
| /// verification disabled, so the certificate only needs to be valid enough for | ||
| /// the Windows SChannel server side to complete a handshake. | ||
| /// | ||
| /// The SAME certificate and key are embedded on the device side (SslServerTests.cs) | ||
| /// for the reverse scenario (device acting as TLS server). Not a secret — a | ||
| /// throw-away test certificate. | ||
| /// </summary> | ||
| internal static class TestCertificates | ||
| { | ||
| private static readonly Lazy<X509Certificate2> _serverCert = new(LoadServerCertificate); | ||
|
|
||
| internal static X509Certificate2 ServerCert => _serverCert.Value; | ||
|
|
||
| private static X509Certificate2 LoadServerCertificate() | ||
| { | ||
| // Load cert + key from PEM, then re-import via PFX so Windows SChannel | ||
| // can use the private key (SChannel rejects the ephemeral key handle | ||
| // that CreateFromPem produces). | ||
| using var fromPem = X509Certificate2.CreateFromPem(ServerCertPem, ServerKeyPem); | ||
| var pfxBytes = fromPem.Export(X509ContentType.Pfx); | ||
| var cert = X509CertificateLoader.LoadPkcs12(pfxBytes, null, X509KeyStorageFlags.Exportable); | ||
|
|
||
| Console.WriteLine("[CERTS] Loaded static test server certificate"); | ||
| return cert; | ||
| } | ||
|
|
||
| // Self-signed RSA-2048 test certificate, CN=nanoFramework Test Server. | ||
| // Valid 2026..2036. Throw-away test cert — not a secret. | ||
| internal const string ServerCertPem = | ||
| @"-----BEGIN CERTIFICATE----- | ||
| MIIDRTCCAi2g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3EyWfQM6eX3ghnq6CsE+ | ||
| MQw94r5CV1kZDA/R9IdXh4aRIVCyN0ZmMvfNNrmIJRdr/eLzQc/6DBeh5Wrg7Sc/ | ||
| 9oUAfyIiPqXG3sW0Txof2L5qbTmallrooQ== | ||
| -----END CERTIFICATE-----"; | ||
|
|
||
| // PKCS#1 (traditional RSA) encoding — kept identical to the device-side key | ||
| // (SslServerTests.cs), which requires this format for mbedTLS SecureServerInit. | ||
| internal const string ServerKeyPem = | ||
| @"-----BEGIN RSA PRIVATE KEY----- | ||
| MIIEpAIBAAKCAQEArvsjPl/WXGmsHcH4aSYlmuKpawP9WldAqBDXITD+lzq+BKu4 | ||
| f2PIx/kJSnRtoRXt9cFC4sCyaukME0Nt2u70RQYE2QmSUrOUGOeKNq+zuqTt+2Nc | ||
| Pv3dP+G5RSzVndD0KjJvE1CnStyddXb/p/6GPfvuLxR0egaN8YxxQb5tN73ChE3h | ||
| d1CF/oOifOJXzZnT7AN1CBapFl4qAu2tvmn50XMwB660tD8tinEr/huRPeGWEB7N | ||
| FZY2PAqThFdpmsYfUgY6HL+KOh1HoyqFr216pH7bsc7Y2Me+6fvo4SAqZzWY6TTm | ||
| 9u6yYbRsNxz8LZ/CGCN4yGUu9op7AREICksQYQIDAQABAoIBAB8L2Bj9EB+dcDhn | ||
| bhfZ+NoeVUjzkEQzLvmi40i0VLeoaIaToUyY+8rfWNKpDbqDFZGBFMj+v6lQaCAS | ||
| 2q75rsWAZ+PKWvfpfOFeU5uYWR9InCD6ZCeZC2SGPEUVy2EQ7gF+qU6YBNa3hgiN | ||
| cJbyBgeBZ6Vaz7/G4fB1prKvgtlcunjtXAwdme9nkHR2kuG+pGGtNs/qc71bQeOt | ||
| 5gphHdls+lHX+D6QD/gB2biR1bSJW+Cegz0zNM0nUUz6cA3K9dUTMeyGyI4c8FNt | ||
| u/FuRZlri/I7yUAPngVnmq46rJg1Ih0OvXI+jIEHp7SI0e9MiRLnZhB4x3/76940 | ||
| qAJ+nnECgYEA5692QqZ0eovLlqlWSrRNP0mG31HxCTrWYvfvfWkfhGPskdsJoOeQ | ||
| RXk5Mvfp84miIezv8aXxmQEquxQiP8HRtzQ0TrsvKdlM9XOGwUJULyqtFfSs6vmj | ||
| HTD16GGPxWqEy0xAcaQcM31pb8YwuZ5MCNRdhuL4ladWBfMR0z75GssCgYEAwVg8 | ||
| hPsX+H4LzCfu32MQCMh+sAR+1xPTLSG3ydJFbx6PE9pX408ZJKc9CtkG8Xz29+y1 | ||
| EZnymB1IUpNZxms/4pybyFaKXUa20SpPgSoIrBaL/wdgM4h4Pvs2FSceYN9qY7Z5 | ||
| d4DhJEiuez+CAFVqQnrNaLJI7xD094SEv91nQAMCgYA+rq8dOzG6UgYj3e61yXA4 | ||
| 1ijCVMYUzDFil1fZI07en7ZKg+tn+B6FXVXHX2GRfUQ7T4Jfa5kg3zrzYHAftc2K | ||
| dnpMbsJE3UDAC6CCuvJRzIcFsKvz6tRhunRdib+/FqGU6y1oUZE7sQuMrR9TqOtD | ||
| XEltjAzbWGmitG+3Kot03wKBgQCunriaCgWOQpj5HB/b1aaHqDzzUDwWmCskGc3a | ||
| E3TudRUYAx1ZiPjWZ8zz3SsuM4UCSeEHMpkt1VSab8anM/oQ+wyflbmFoPZAVwxT | ||
| RdlrQznRbaHvKRQhHdWsqRYAvAdkY0u1KMsucA5V9fe9wWck/7BBHLROZmw4mJEk | ||
| kBxObQKBgQCCrcUNFhm3dxCdi+VgMwrhMOqiO5XYAGw4raQ/BbXwpb1PLbj4xtSZ | ||
| WVb3utTBP0WPhf58EcHc8ko4B+1xCMR4B9rntQACfngbUN4wETQ1Gz+bNgaHQyJo | ||
| gHYA38gnEOJurr2VLZFaqLgwj+7kpTRL2a0ZTDz8pCxlwDpsi4n1YA== | ||
| -----END RSA PRIVATE KEY-----"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.