-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Generate SslConnectionInfo.Unix.cs with T4 template #84690
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 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7cfe88e
Generate SslConnectionInfo.Unix.cs with T4 template
am11 4104ab6
Fix indentation
am11 db1307f
Address CR feedback
am11 b3d656b
Encode 16x4 bits as ulong
am11 9ba4ed2
Fix unpacking
am11 09cde7d
Move packed data selection to private method
am11 2d15328
Switch to ROS version
am11 a584dac
Fix index
am11 92e23da
Revert "Fix index"
am11 b34d3cc
Revert "Switch to ROS version"
am11 47cee99
Divide raw data into two `int`s
am11 3b5a682
Switch other values to 32-bit as well
am11 e2a4930
Switch to single int version
am11 ad8a803
Reposition
am11 ea29344
Pack first two as nibbles and third as ushort
am11 3bd4400
Try fitting into ushort
am11 c58574c
Fix cipherAlgorithmStrength mapping
am11 4eeea0a
Address CR feedback
am11 d67f01c
Change return type to int
am11 8699298
Address CR feedback
am11 2eb6b62
Keep KeyExchKeySize
am11 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
411 changes: 403 additions & 8 deletions
411
src/libraries/System.Net.Security/src/System/Net/Security/SslConnectionInfo.Unix.cs
Large diffs are not rendered by default.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
src/libraries/System.Net.Security/src/System/Net/Security/SslConnectionInfo.Unix.tt
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,124 @@ | ||
| <#@ template debug="false" hostspecific="false" language="C#" #> | ||
| <#@ import namespace="System" #> | ||
| <#@ assembly name="System.Core" #> | ||
| <#@ assembly name="System.Net.Primitives" #> | ||
| <#@ import namespace="System.Linq" #> | ||
| <#@ import namespace="System.Text" #> | ||
| <#@ import namespace="System.Collections.Generic" #> | ||
| <#@ output extension=".cs" #> | ||
| <#@ include file="TlsCipherSuiteNameParser.ttinclude" #><#@ | ||
| include file="TlsCipherSuite.cs" #> | ||
| <# Array tlsEnumValues = typeof(TlsCipherSuite).GetEnumValues(); #> | ||
| <# Array exchangeEnumValues = typeof(ExchangeAlgorithmTypeIndex).GetEnumValues(); #> | ||
| <# Array cipherEnumValues = typeof(CipherAlgorithmTypeIndex).GetEnumValues(); #> | ||
| <# Array cipherStrengthEnumValues = typeof(CipherAlgorithmStrengthIndex).GetEnumValues(); #> | ||
| <# Array hashEnumValues = typeof(HashAlgorithmTypeIndex).GetEnumValues(); #> | ||
|
|
||
|
|
||
| using System.Diagnostics; | ||
| using System.Security.Authentication; | ||
|
|
||
| namespace System.Net.Security | ||
| { | ||
| internal partial struct SslConnectionInfo | ||
| { | ||
| private void MapCipherSuite(TlsCipherSuite cipherSuite) | ||
| { | ||
| TlsCipherSuite = cipherSuite; | ||
| KeyExchKeySize = 0; | ||
|
|
||
| ushort data = GetPackedData(cipherSuite); | ||
| Debug.Assert(data != 0, $"No mapping found for cipherSuite {cipherSuite}"); | ||
|
|
||
| KeyExchangeAlg = (int)s_exchangeAlgorithmTypes[(data >> (16 - (4 * 1)) & 0xF)]; | ||
| DataCipherAlg = (int)s_cipherEnumValues[(data >> (16 - (4 * 2)) & 0xF)]; | ||
| DataKeySize = (int)s_cipherStrengthEnumValues[(data >> (16 - (4 * 3)) & 0xF)]; | ||
| DataHashAlg = (int)s_hashEnumValues[(data >> (16 - (4 * 4)) & 0xF)]; | ||
| DataHashKeySize = GetHashSize((HashAlgorithmType)DataHashAlg); | ||
am11 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| static int GetHashSize(HashAlgorithmType hash) | ||
| { | ||
| switch (hash) | ||
| { | ||
| case HashAlgorithmType.None: | ||
| return 0; | ||
| case HashAlgorithmType.Md5: | ||
| return 128; | ||
| case HashAlgorithmType.Sha1: | ||
| return 160; | ||
| case HashAlgorithmType.Sha256: | ||
| return 256; | ||
| case HashAlgorithmType.Sha384: | ||
| return 384; | ||
| case HashAlgorithmType.Sha512: | ||
| return 512; | ||
| default: | ||
| throw new ArgumentOutOfRangeException(nameof(hash)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static ReadOnlySpan<int> s_exchangeAlgorithmTypes => | ||
| new[] { <# | ||
| foreach (ExchangeAlgorithmTypeIndex val in exchangeEnumValues) | ||
| { | ||
| #>(int)ExchangeAlgorithmType.<#= val #>, <# | ||
| } | ||
| #>}; | ||
|
|
||
| private static ReadOnlySpan<int> s_cipherEnumValues => | ||
| new[] { <# | ||
| foreach (CipherAlgorithmTypeIndex val in cipherEnumValues) | ||
| { | ||
| #>(int)CipherAlgorithmType.<#= val #>, <# | ||
| } | ||
| #>}; | ||
|
|
||
| private static ReadOnlySpan<int> s_cipherStrengthEnumValues => | ||
| new[] { <# | ||
| foreach (CipherAlgorithmStrengthIndex val in cipherStrengthEnumValues) | ||
| { | ||
| #>(int)CipherAlgorithmStrength.<#= val #>, <# | ||
| } | ||
| #>}; | ||
|
|
||
| private static ReadOnlySpan<int> s_hashEnumValues => | ||
| new[] { <# | ||
| foreach (HashAlgorithmTypeIndex val in hashEnumValues) | ||
| { | ||
| #>(int)HashAlgorithmType.<#= val #>, <# | ||
| } | ||
| #>}; | ||
|
|
||
| private static ushort GetPackedData(TlsCipherSuite cipherSuite) | ||
| { | ||
| switch (cipherSuite) | ||
| { | ||
| <# | ||
| foreach (TlsCipherSuite val in tlsEnumValues) | ||
| { | ||
| TlsCipherSuiteData data = new CipherSuiteNameData(val.ToString()).Data; | ||
| byte exchangeAlgorithmType = (byte)Enum.Parse<ExchangeAlgorithmTypeIndex>(EnumHelpers.ToFrameworkName(data.KeyExchangeAlgorithm)); | ||
| byte cipherAlgorithmType = (byte)Enum.Parse<CipherAlgorithmTypeIndex>(EnumHelpers.ToFrameworkName(data.CipherAlgorithm)); | ||
| byte cipherAlgorithmStrength = (byte)Enum.Parse<CipherAlgorithmStrengthIndex>(EnumHelpers.CipherAlgorithmStrengthIndexToName(data.CipherAlgorithmStrength)); | ||
| byte hashAlgorithmType = (byte)Enum.Parse<HashAlgorithmTypeIndex>(EnumHelpers.ToFrameworkName(data.MACAlgorithm)); | ||
| #> | ||
| case TlsCipherSuite.<#= val #>: return <#= exchangeAlgorithmType #> << (16 - (4 * 1)) | <#= cipherAlgorithmType #> << (16 - (4 * 2)) | <#= cipherAlgorithmStrength #> << (16 - (4 * 3)) | <#= hashAlgorithmType #> << (16 - (4 * 4)); | ||
am11 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <# | ||
| } | ||
| #> | ||
| default: return 0; | ||
| } | ||
| } | ||
|
|
||
| private enum CipherAlgorithmStrength | ||
| { | ||
| Zero = 0, | ||
| Forty = 40, | ||
| FiftySix = 56, | ||
| OneTwentyEight = 128, | ||
| OneSixtyEight = 168, | ||
| TwoFiftySix = 256 | ||
| } | ||
| } | ||
| } | ||
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.