Skip to content

Commit fe37ada

Browse files
committed
Merge in 'release/2.1' changes
2 parents 2981743 + 569dbf9 commit fe37ada

File tree

10 files changed

+147
-91
lines changed

10 files changed

+147
-91
lines changed

.config/CredScanSuppressions.json

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,58 @@
2020
{
2121
"placeholder": "1qaz@WSX",
2222
"_justification": "This is a fake password used in test code."
23-
}
23+
},
24+
{
25+
"file": "\\src\\DataProtection\\Extensions\\test\\TestFiles\\TestCert.pfx",
26+
"_justification": "Legitimate UT certificate file with private key"
27+
},
28+
{
29+
"file": "\\src\\DataProtection\\Extensions\\test\\TestFiles\\TestCert2.pfx",
30+
"_justification": "Legitimate UT certificate file with private key"
31+
},
32+
{
33+
"file": "\\src\\DefaultBuilder\\test\\Microsoft.AspNetCore.FunctionalTests\\testCert.pfx",
34+
"_justification": "Legitimate UT certificate file with private key"
35+
},
36+
{
37+
"file": "\\src\\DataProtection\\DataProtection\\test\\TestFiles\\TestCert1.pfx",
38+
"_justification": "Legitimate UT certificate file with private key"
39+
},
40+
{
41+
"file": "\\src\\DataProtection\\DataProtection\\test\\TestFiles\\TestCert2.pfx",
42+
"_justification": "Legitimate UT certificate file with private key"
43+
},
44+
{
45+
"file": "\\src\\Middleware\\WebSockets\\test\\ConformanceTests\\AutobahnTestApp\\TestResources\\testCert.pfx",
46+
"_justification": "Legitimate UT certificate file with private key"
47+
},
48+
{
49+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\aspnetdevcert.pfx",
50+
"_justification": "Legitimate UT certificate file with private key"
51+
},
52+
{
53+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\eku.client.pfx",
54+
"_justification": "Legitimate UT certificate file with private key"
55+
},
56+
{
57+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\eku.code_signing.pfx",
58+
"_justification": "Legitimate UT certificate file with private key"
59+
},
60+
{
61+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\eku.multiple_usages.pfx",
62+
"_justification": "Legitimate UT certificate file with private key"
63+
},
64+
{
65+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\eku.server.pfx",
66+
"_justification": "Legitimate UT certificate file with private key"
67+
},
68+
{
69+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\no_extensions.pfx",
70+
"_justification": "Legitimate UT certificate file with private key"
71+
},
72+
{
73+
"file": "\\src\\Servers\\Kestrel\\shared\\test\\TestCertificates\\testCert.pfx",
74+
"_justification": "Legitimate UT certificate file with private key"
75+
},
2476
]
2577
}

src/DataProtection/DataProtection/test/AuthenticatedEncryption/ConfigurationModel/AuthenticatedEncryptorDescriptorTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Globalization;
66
using System.Security.Cryptography;
7+
using System.Text;
78
using System.Text.RegularExpressions;
89
using Microsoft.AspNetCore.Cryptography.Cng;
910
using Microsoft.AspNetCore.Cryptography.SafeHandles;
@@ -118,20 +119,20 @@ public void CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation(
118119
public void ExportToXml_ProducesCorrectPayload_Cbc()
119120
{
120121
// Arrange
121-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
122-
var descriptor = CreateDescriptor(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512, masterKey);
122+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
123+
var descriptor = CreateDescriptor(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512, masterKey.ToSecret());
123124

124125
// Act
125126
var retVal = descriptor.ExportToXml();
126127

127128
// Assert
128129
Assert.Equal(typeof(AuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
129-
const string expectedXml = @"
130+
var expectedXml = $@"
130131
<descriptor>
131132
<encryption algorithm='AES_192_CBC' />
132133
<validation algorithm='HMACSHA512' />
133134
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
134-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
135+
<value>{masterKey}</value>
135136
</masterKey>
136137
</descriptor>";
137138
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
@@ -141,20 +142,20 @@ public void ExportToXml_ProducesCorrectPayload_Cbc()
141142
public void ExportToXml_ProducesCorrectPayload_Gcm()
142143
{
143144
// Arrange
144-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
145-
var descriptor = CreateDescriptor(EncryptionAlgorithm.AES_192_GCM, ValidationAlgorithm.HMACSHA512, masterKey);
145+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
146+
var descriptor = CreateDescriptor(EncryptionAlgorithm.AES_192_GCM, ValidationAlgorithm.HMACSHA512, masterKey.ToSecret());
146147

147148
// Act
148149
var retVal = descriptor.ExportToXml();
149150

150151
// Assert
151152
Assert.Equal(typeof(AuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
152-
const string expectedXml = @"
153+
var expectedXml = $@"
153154
<descriptor>
154155
<encryption algorithm='AES_192_GCM' />
155156
<!-- some comment here -->
156157
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
157-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
158+
<value>{masterKey}</value>
158159
</masterKey>
159160
</descriptor>";
160161
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);

src/DataProtection/DataProtection/test/AuthenticatedEncryption/ConfigurationModel/CngCbcAuthenticatedEncryptorDescriptorTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Text;
56
using Xunit;
67

78
namespace Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel
@@ -12,27 +13,27 @@ public class CngCbcAuthenticatedEncryptorDescriptorTests
1213
public void ExportToXml_WithProviders_ProducesCorrectPayload()
1314
{
1415
// Arrange
15-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
16+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
1617
var descriptor = new CngCbcAuthenticatedEncryptorDescriptor(new CngCbcAuthenticatedEncryptorConfiguration()
1718
{
1819
EncryptionAlgorithm = "enc-alg",
1920
EncryptionAlgorithmKeySize = 2048,
2021
EncryptionAlgorithmProvider = "enc-alg-prov",
2122
HashAlgorithm = "hash-alg",
2223
HashAlgorithmProvider = "hash-alg-prov"
23-
}, masterKey);
24+
}, masterKey.ToSecret());
2425

2526
// Act
2627
var retVal = descriptor.ExportToXml();
2728

2829
// Assert
2930
Assert.Equal(typeof(CngCbcAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
30-
const string expectedXml = @"
31+
var expectedXml = $@"
3132
<descriptor>
3233
<encryption algorithm='enc-alg' keyLength='2048' provider='enc-alg-prov' />
3334
<hash algorithm='hash-alg' provider='hash-alg-prov' />
3435
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
35-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
36+
<value>{masterKey}</value>
3637
</masterKey>
3738
</descriptor>";
3839
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
@@ -42,25 +43,25 @@ public void ExportToXml_WithProviders_ProducesCorrectPayload()
4243
public void ExportToXml_WithoutProviders_ProducesCorrectPayload()
4344
{
4445
// Arrange
45-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
46+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
4647
var descriptor = new CngCbcAuthenticatedEncryptorDescriptor(new CngCbcAuthenticatedEncryptorConfiguration()
4748
{
4849
EncryptionAlgorithm = "enc-alg",
4950
EncryptionAlgorithmKeySize = 2048,
5051
HashAlgorithm = "hash-alg"
51-
}, masterKey);
52+
}, masterKey.ToSecret());
5253

5354
// Act
5455
var retVal = descriptor.ExportToXml();
5556

5657
// Assert
5758
Assert.Equal(typeof(CngCbcAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
58-
const string expectedXml = @"
59+
var expectedXml = $@"
5960
<descriptor>
6061
<encryption algorithm='enc-alg' keyLength='2048' />
6162
<hash algorithm='hash-alg' />
6263
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
63-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
64+
<value>{masterKey}</value>
6465
</masterKey>
6566
</descriptor>";
6667
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);

src/DataProtection/DataProtection/test/AuthenticatedEncryption/ConfigurationModel/CngGcmAuthenticatedEncryptorDescriptorDeserializerTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Text;
56
using System.Xml.Linq;
67
using Microsoft.AspNetCore.Cryptography;
78
using Microsoft.AspNetCore.DataProtection.KeyManagement;
@@ -19,20 +20,21 @@ public class CngGcmAuthenticatedEncryptorDescriptorDeserializerTests
1920
public void ImportFromXml_CreatesAppropriateDescriptor()
2021
{
2122
// Arrange
23+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
2224
var descriptor = new CngGcmAuthenticatedEncryptorDescriptor(
2325
new CngGcmAuthenticatedEncryptorConfiguration()
2426
{
2527
EncryptionAlgorithm = Constants.BCRYPT_AES_ALGORITHM,
2628
EncryptionAlgorithmKeySize = 192,
2729
EncryptionAlgorithmProvider = null
2830
},
29-
"k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret());
31+
masterKey.ToSecret());
3032
var control = CreateEncryptorInstanceFromDescriptor(descriptor);
3133

32-
const string xml = @"
34+
var xml = $@"
3335
<descriptor version='1' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
3436
<encryption algorithm='AES' keyLength='192' />
35-
<masterKey enc:requiresEncryption='true'>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</masterKey>
37+
<masterKey enc:requiresEncryption='true'>{masterKey}</masterKey>
3638
</descriptor>";
3739
var deserializedDescriptor = new CngGcmAuthenticatedEncryptorDescriptorDeserializer().ImportFromXml(XElement.Parse(xml));
3840
var test = CreateEncryptorInstanceFromDescriptor(deserializedDescriptor as CngGcmAuthenticatedEncryptorDescriptor);

src/DataProtection/DataProtection/test/AuthenticatedEncryption/ConfigurationModel/CngGcmAuthenticatedEncryptorDescriptorTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Text;
56
using Xunit;
67

78
namespace Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel
@@ -12,24 +13,24 @@ public class CngGcmAuthenticatedEncryptorDescriptorTests
1213
public void ExportToXml_WithProviders_ProducesCorrectPayload()
1314
{
1415
// Arrange
15-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
16+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
1617
var descriptor = new CngGcmAuthenticatedEncryptorDescriptor(new CngGcmAuthenticatedEncryptorConfiguration()
1718
{
1819
EncryptionAlgorithm = "enc-alg",
1920
EncryptionAlgorithmKeySize = 2048,
2021
EncryptionAlgorithmProvider = "enc-alg-prov"
21-
}, masterKey);
22+
}, masterKey.ToSecret());
2223

2324
// Act
2425
var retVal = descriptor.ExportToXml();
2526

2627
// Assert
2728
Assert.Equal(typeof(CngGcmAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
28-
const string expectedXml = @"
29+
var expectedXml = $@"
2930
<descriptor>
3031
<encryption algorithm='enc-alg' keyLength='2048' provider='enc-alg-prov' />
3132
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
32-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
33+
<value>{masterKey}</value>
3334
</masterKey>
3435
</descriptor>";
3536
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
@@ -39,23 +40,23 @@ public void ExportToXml_WithProviders_ProducesCorrectPayload()
3940
public void ExportToXml_WithoutProviders_ProducesCorrectPayload()
4041
{
4142
// Arrange
42-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
43+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
4344
var descriptor = new CngGcmAuthenticatedEncryptorDescriptor(new CngGcmAuthenticatedEncryptorConfiguration()
4445
{
4546
EncryptionAlgorithm = "enc-alg",
4647
EncryptionAlgorithmKeySize = 2048
47-
}, masterKey);
48+
}, masterKey.ToSecret());
4849

4950
// Act
5051
var retVal = descriptor.ExportToXml();
5152

5253
// Assert
5354
Assert.Equal(typeof(CngGcmAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
54-
const string expectedXml = @"
55+
var expectedXml = $@"
5556
<descriptor>
5657
<encryption algorithm='enc-alg' keyLength='2048' />
5758
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
58-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
59+
<value>{masterKey}</value>
5960
</masterKey>
6061
</descriptor>";
6162
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);

src/DataProtection/DataProtection/test/AuthenticatedEncryption/ConfigurationModel/ManagedAuthenticatedEncryptorDescriptorTests.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Security.Cryptography;
6+
using System.Text;
67
using Xunit;
78

89
namespace Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel
@@ -13,28 +14,27 @@ public class ManagedAuthenticatedEncryptorDescriptorTests
1314
public void ExportToXml_CustomTypes_ProducesCorrectPayload()
1415
{
1516
// Arrange
16-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
17+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
1718
var descriptor = new ManagedAuthenticatedEncryptorDescriptor(new ManagedAuthenticatedEncryptorConfiguration()
1819
{
1920
EncryptionAlgorithmType = typeof(MySymmetricAlgorithm),
2021
EncryptionAlgorithmKeySize = 2048,
2122
ValidationAlgorithmType = typeof(MyKeyedHashAlgorithm)
22-
}, masterKey);
23+
}, masterKey.ToSecret());
2324

2425
// Act
2526
var retVal = descriptor.ExportToXml();
2627

2728
// Assert
2829
Assert.Equal(typeof(ManagedAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
29-
string expectedXml = string.Format(@"
30+
var expectedXml = $@"
3031
<descriptor>
31-
<encryption algorithm='{0}' keyLength='2048' />
32-
<validation algorithm='{1}' />
32+
<encryption algorithm='{typeof(MySymmetricAlgorithm).AssemblyQualifiedName}' keyLength='2048' />
33+
<validation algorithm='{typeof(MyKeyedHashAlgorithm).AssemblyQualifiedName}' />
3334
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
34-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
35+
<value>{masterKey}</value>
3536
</masterKey>
36-
</descriptor>",
37-
typeof(MySymmetricAlgorithm).AssemblyQualifiedName, typeof(MyKeyedHashAlgorithm).AssemblyQualifiedName);
37+
</descriptor>";
3838
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
3939
}
4040

@@ -46,28 +46,27 @@ public void ExportToXml_CustomTypes_ProducesCorrectPayload()
4646
public void ExportToXml_BuiltInTypes_ProducesCorrectPayload(Type encryptionAlgorithmType, Type validationAlgorithmType)
4747
{
4848
// Arrange
49-
var masterKey = "k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==".ToSecret();
49+
var masterKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("[PLACEHOLDER]"));
5050
var descriptor = new ManagedAuthenticatedEncryptorDescriptor(new ManagedAuthenticatedEncryptorConfiguration()
5151
{
5252
EncryptionAlgorithmType = encryptionAlgorithmType,
5353
EncryptionAlgorithmKeySize = 2048,
5454
ValidationAlgorithmType = validationAlgorithmType
55-
}, masterKey);
55+
}, masterKey.ToSecret());
5656

5757
// Act
5858
var retVal = descriptor.ExportToXml();
5959

6060
// Assert
6161
Assert.Equal(typeof(ManagedAuthenticatedEncryptorDescriptorDeserializer), retVal.DeserializerType);
62-
string expectedXml = string.Format(@"
62+
var expectedXml = $@"
6363
<descriptor>
64-
<encryption algorithm='{0}' keyLength='2048' />
65-
<validation algorithm='{1}' />
64+
<encryption algorithm='{encryptionAlgorithmType.Name}' keyLength='2048' />
65+
<validation algorithm='{validationAlgorithmType.Name}' />
6666
<masterKey enc:requiresEncryption='true' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'>
67-
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
67+
<value>{masterKey}</value>
6868
</masterKey>
69-
</descriptor>",
70-
encryptionAlgorithmType.Name, validationAlgorithmType.Name);
69+
</descriptor>";
7170
XmlAssert.Equal(expectedXml, retVal.SerializedDescriptorElement);
7271
}
7372

0 commit comments

Comments
 (0)