Skip to content

Commit 9d397b9

Browse files
authored
Merge branch 'dotnet:main' into dotnet#46810
2 parents f39e14d + ba3460a commit 9d397b9

File tree

8 files changed

+365
-162
lines changed

8 files changed

+365
-162
lines changed

eng/Version.Details.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Dependency Name="dotnet-ef" Version="9.0.0-preview.4.24205.3">
1313
<Uri>https://github.com/dotnet/efcore</Uri>
1414
<Sha>45448efb1da8914489739bc4116f7a8f6c9374a2</Sha>
15+
<SourceBuildTarball RepoName="efcore" ManagedOnly="true" />
1516
</Dependency>
1617
<Dependency Name="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0-preview.4.24205.3">
1718
<Uri>https://github.com/dotnet/efcore</Uri>
@@ -324,14 +325,14 @@
324325
<Uri>https://github.com/dotnet/runtime</Uri>
325326
<Sha>9b57a265c7efd3732b035bade005561a04767128</Sha>
326327
</Dependency>
327-
<Dependency Name="Microsoft.Web.Xdt" Version="9.0.0-preview.24204.1">
328+
<Dependency Name="Microsoft.Web.Xdt" Version="9.0.0-preview.24208.1">
328329
<Uri>https://github.com/dotnet/xdt</Uri>
329-
<Sha>67956470ccbe5a51255b5b014811076ae99ae79f</Sha>
330+
<Sha>282e0064c30d5cef9b1c1cabb12ef6b55775c54d</Sha>
330331
</Dependency>
331332
<!-- Intermediate is necessary for source build. -->
332-
<Dependency Name="Microsoft.SourceBuild.Intermediate.xdt" Version="9.0.0-preview.24204.1">
333+
<Dependency Name="Microsoft.SourceBuild.Intermediate.xdt" Version="9.0.0-preview.24208.1">
333334
<Uri>https://github.com/dotnet/xdt</Uri>
334-
<Sha>67956470ccbe5a51255b5b014811076ae99ae79f</Sha>
335+
<Sha>282e0064c30d5cef9b1c1cabb12ef6b55775c54d</Sha>
335336
<SourceBuild RepoName="xdt" ManagedOnly="true" />
336337
</Dependency>
337338
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.24162.2">
@@ -367,9 +368,9 @@
367368
<Sha>9b57a265c7efd3732b035bade005561a04767128</Sha>
368369
</Dependency>
369370
<!-- Intermediate is necessary for source build. -->
370-
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="9.0.0-alpha.1.24201.3">
371+
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="9.0.0-alpha.1.24203.1">
371372
<Uri>https://github.com/dotnet/source-build-externals</Uri>
372-
<Sha>bcd44732882bc2b81b30146c778eb6ccb7fea793</Sha>
373+
<Sha>1e2e91d2544726b2cf68109f946178ef6bef3ad9</Sha>
373374
<SourceBuild RepoName="source-build-externals" ManagedOnly="true" />
374375
</Dependency>
375376
</ProductDependencies>
@@ -430,9 +431,9 @@
430431
<Sha>8fef55f5a55a3b4f2c96cd1a9b5ddc51d4b927f8</Sha>
431432
</Dependency>
432433
<!-- Intermediate is necessary for source build. -->
433-
<Dependency Name="Microsoft.SourceBuild.Intermediate.symreader" Version="2.1.0-beta.24171.1">
434+
<Dependency Name="Microsoft.SourceBuild.Intermediate.symreader" Version="2.1.0-beta.24177.1">
434435
<Uri>https://github.com/dotnet/symreader</Uri>
435-
<Sha>01de94d9718fd48c511cae276437edcd41b41fa4</Sha>
436+
<Sha>7ae564f9397e5d1b6035f6cf9ebe4f6b0b94882a</Sha>
436437
<SourceBuild RepoName="symreader" ManagedOnly="true" />
437438
</Dependency>
438439
</ToolsetDependencies>

eng/Versions.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,16 @@
164164
<MicrosoftDotNetRemoteExecutorVersion>9.0.0-beta.24207.1</MicrosoftDotNetRemoteExecutorVersion>
165165
<MicrosoftSourceBuildIntermediatearcadeVersion>9.0.0-beta.24207.1</MicrosoftSourceBuildIntermediatearcadeVersion>
166166
<!-- Packages from dotnet/source-build-externals -->
167-
<MicrosoftSourceBuildIntermediatesourcebuildexternalsVersion>9.0.0-alpha.1.24201.3</MicrosoftSourceBuildIntermediatesourcebuildexternalsVersion>
167+
<MicrosoftSourceBuildIntermediatesourcebuildexternalsVersion>9.0.0-alpha.1.24203.1</MicrosoftSourceBuildIntermediatesourcebuildexternalsVersion>
168168
<!-- Packages from dotnet/source-build-reference-packages -->
169169
<MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesVersion>9.0.0-alpha.1.24162.2</MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesVersion>
170170
<!-- Packages from dotnet/symreader -->
171-
<MicrosoftSourceBuildIntermediatesymreaderVersion>2.1.0-beta.24171.1</MicrosoftSourceBuildIntermediatesymreaderVersion>
171+
<MicrosoftSourceBuildIntermediatesymreaderVersion>2.1.0-beta.24177.1</MicrosoftSourceBuildIntermediatesymreaderVersion>
172172
<!-- Packages from dotnet/winforms -->
173173
<SystemDrawingCommonVersion>9.0.0-preview.4.24206.1</SystemDrawingCommonVersion>
174174
<!-- Packages from dotnet/xdt -->
175-
<MicrosoftWebXdtVersion>9.0.0-preview.24204.1</MicrosoftWebXdtVersion>
176-
<MicrosoftSourceBuildIntermediatexdtVersion>9.0.0-preview.24204.1</MicrosoftSourceBuildIntermediatexdtVersion>
175+
<MicrosoftWebXdtVersion>9.0.0-preview.24208.1</MicrosoftWebXdtVersion>
176+
<MicrosoftSourceBuildIntermediatexdtVersion>9.0.0-preview.24208.1</MicrosoftSourceBuildIntermediatexdtVersion>
177177
</PropertyGroup>
178178
<!--
179179

src/DataProtection/DataProtection/src/KeyManagement/DeferredKey.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/DataProtection/DataProtection/src/KeyManagement/Key.cs

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,156 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Xml.Linq;
67
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
78
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
9+
using Microsoft.AspNetCore.DataProtection.KeyManagement.Internal;
10+
using Microsoft.AspNetCore.DataProtection.XmlEncryption;
811

912
namespace Microsoft.AspNetCore.DataProtection.KeyManagement;
1013

1114
/// <summary>
12-
/// The basic implementation of <see cref="IKey"/>, where the <see cref="IAuthenticatedEncryptorDescriptor"/>
13-
/// has already been created.
15+
/// The basic implementation of <see cref="IKey"/>.
1416
/// </summary>
15-
internal sealed class Key : KeyBase
17+
internal sealed class Key : IKey
1618
{
19+
private readonly Lazy<IAuthenticatedEncryptorDescriptor> _lazyDescriptor;
20+
private readonly IEnumerable<IAuthenticatedEncryptorFactory> _encryptorFactories;
21+
22+
private IAuthenticatedEncryptor? _encryptor;
23+
24+
/// <summary>
25+
/// The basic implementation of <see cref="IKey"/>, where the <see cref="IAuthenticatedEncryptorDescriptor"/>
26+
/// has already been created.
27+
/// </summary>
1728
public Key(
1829
Guid keyId,
1930
DateTimeOffset creationDate,
2031
DateTimeOffset activationDate,
2132
DateTimeOffset expirationDate,
2233
IAuthenticatedEncryptorDescriptor descriptor,
2334
IEnumerable<IAuthenticatedEncryptorFactory> encryptorFactories)
24-
: base(keyId,
35+
: this(keyId,
2536
creationDate,
2637
activationDate,
2738
expirationDate,
2839
new Lazy<IAuthenticatedEncryptorDescriptor>(() => descriptor),
2940
encryptorFactories)
3041
{
3142
}
43+
44+
/// <summary>
45+
/// The basic implementation of <see cref="IKey"/>, where the incoming XML element
46+
/// hasn't yet been fully processed.
47+
/// </summary>
48+
public Key(
49+
Guid keyId,
50+
DateTimeOffset creationDate,
51+
DateTimeOffset activationDate,
52+
DateTimeOffset expirationDate,
53+
IInternalXmlKeyManager keyManager,
54+
XElement keyElement,
55+
IEnumerable<IAuthenticatedEncryptorFactory> encryptorFactories)
56+
: this(keyId,
57+
creationDate,
58+
activationDate,
59+
expirationDate,
60+
new Lazy<IAuthenticatedEncryptorDescriptor>(GetLazyDescriptorDelegate(keyManager, keyElement)),
61+
encryptorFactories)
62+
{
63+
}
64+
65+
private Key(
66+
Guid keyId,
67+
DateTimeOffset creationDate,
68+
DateTimeOffset activationDate,
69+
DateTimeOffset expirationDate,
70+
Lazy<IAuthenticatedEncryptorDescriptor> lazyDescriptor,
71+
IEnumerable<IAuthenticatedEncryptorFactory> encryptorFactories)
72+
{
73+
KeyId = keyId;
74+
CreationDate = creationDate;
75+
ActivationDate = activationDate;
76+
ExpirationDate = expirationDate;
77+
_lazyDescriptor = lazyDescriptor;
78+
_encryptorFactories = encryptorFactories;
79+
}
80+
81+
public DateTimeOffset ActivationDate { get; }
82+
83+
public DateTimeOffset CreationDate { get; }
84+
85+
public DateTimeOffset ExpirationDate { get; }
86+
87+
public bool IsRevoked { get; private set; }
88+
89+
public Guid KeyId { get; }
90+
91+
public IAuthenticatedEncryptorDescriptor Descriptor
92+
{
93+
get
94+
{
95+
return _lazyDescriptor.Value;
96+
}
97+
}
98+
99+
public IAuthenticatedEncryptor? CreateEncryptor()
100+
{
101+
if (_encryptor == null)
102+
{
103+
foreach (var factory in _encryptorFactories)
104+
{
105+
var encryptor = factory.CreateEncryptorInstance(this);
106+
if (encryptor != null)
107+
{
108+
_encryptor = encryptor;
109+
break;
110+
}
111+
}
112+
}
113+
114+
return _encryptor;
115+
}
116+
117+
internal void SetRevoked()
118+
{
119+
IsRevoked = true;
120+
}
121+
122+
internal Key Clone()
123+
{
124+
return new Key(
125+
keyId: KeyId,
126+
creationDate: CreationDate,
127+
activationDate: ActivationDate,
128+
expirationDate: ExpirationDate,
129+
lazyDescriptor: _lazyDescriptor,
130+
encryptorFactories: _encryptorFactories)
131+
{
132+
IsRevoked = IsRevoked,
133+
};
134+
}
135+
136+
private static Func<IAuthenticatedEncryptorDescriptor> GetLazyDescriptorDelegate(IInternalXmlKeyManager keyManager, XElement keyElement)
137+
{
138+
// The <key> element will be held around in memory for a potentially lengthy period
139+
// of time. Since it might contain sensitive information, we should protect it.
140+
var encryptedKeyElement = keyElement.ToSecret();
141+
142+
try
143+
{
144+
return GetLazyDescriptorDelegate;
145+
}
146+
finally
147+
{
148+
// It's important that the lambda above doesn't capture 'descriptorElement'. Clearing the reference here
149+
// helps us detect if we've done this by causing a null ref at runtime.
150+
keyElement = null!;
151+
}
152+
153+
IAuthenticatedEncryptorDescriptor GetLazyDescriptorDelegate()
154+
{
155+
return keyManager.DeserializeDescriptorFromKeyElement(encryptedKeyElement.ToXElement());
156+
}
157+
}
32158
}

src/DataProtection/DataProtection/src/KeyManagement/KeyBase.cs

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)