Skip to content

Commit 439c8c0

Browse files
committed
revise enclave parsing and review feedback
1 parent d7462c0 commit 439c8c0

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIPhysicalHandle.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,9 @@ private string GetStackParts()
8787
// trims off most of the bottom of the stack because when running under xunit there's a lot of spam
8888
string[] parts = Environment.StackTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
8989
List<string> take = new List<string>(7);
90-
for (int index = 0; take.Count < 7 && index < parts.Length; index++)
90+
for (int index = 3; take.Count < 7 && index < parts.Length; index++)
9191
{
92-
if (index > 2)
93-
{
94-
take.Add(parts[index]);
95-
}
92+
take.Add(parts[index]);
9693
}
9794

9895
return string.Join(Environment.NewLine, take.ToArray());

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AlwaysEncryptedEnclaveProviderUtils.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ public EnclavePublicKey(byte[] payload)
1818

1919
internal class EnclaveDiffieHellmanInfo
2020
{
21-
public int Size { get; private set; }
21+
public int Size => sizeof(int) + sizeof(int) + PublicKey?.Length ?? 0 + PublicKeySignature?.Length ?? 0;
2222

2323
public byte[] PublicKey { get; private set; }
2424

2525
public byte[] PublicKeySignature { get; private set; }
2626

27-
public EnclaveDiffieHellmanInfo(byte[] payload)
27+
public EnclaveDiffieHellmanInfo(byte[] payload, int offset)
2828
{
29-
Size = payload.Length;
30-
31-
int publicKeySize = BitConverter.ToInt32(payload, 0);
32-
int publicKeySignatureSize = BitConverter.ToInt32(payload, 4);
29+
int publicKeySize = BitConverter.ToInt32(payload, offset + 0);
30+
int publicKeySignatureSize = BitConverter.ToInt32(payload, offset + 4);
3331

3432
PublicKey = new byte[publicKeySize];
3533
PublicKeySignature = new byte[publicKeySignatureSize];
36-
Buffer.BlockCopy(payload, 8, PublicKey, 0, publicKeySize);
37-
Buffer.BlockCopy(payload, 8 + publicKeySize, PublicKeySignature, 0, publicKeySignatureSize);
34+
Buffer.BlockCopy(payload, offset + 8, PublicKey, 0, publicKeySize);
35+
Buffer.BlockCopy(payload, offset + 8 + publicKeySize, PublicKeySignature, 0, publicKeySignatureSize);
3836
}
3937
}
4038

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AzureAttestationBasedEnclaveProvider.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.IdentityModel.Tokens.Jwt;
89
using System.Runtime.Caching;
910
using System.Security.Claims;
@@ -203,9 +204,10 @@ public AzureAttestationInfo(byte[] attestationInfo)
203204
SessionId = BitConverter.ToInt64(attestationInfo, offset);
204205
offset += sizeof(long);
205206

206-
int secureSessionBufferSize = Convert.ToInt32(secureSessionInfoResponseSize) - sizeof(uint);
207-
byte[] secureSessionBuffer = EnclaveHelpers.TakeBytesAndAdvance(attestationInfo, ref offset, secureSessionBufferSize);
208-
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(secureSessionBuffer);
207+
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(attestationInfo, offset);
208+
offset += EnclaveDHInfo.Size;
209+
210+
Debug.Assert(offset == attestationInfo.Length);
209211
}
210212
catch (Exception exception)
211213
{

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/VirtualSecureModeEnclaveProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.IdentityModel.Tokens.Jwt;
79
using System.IO;
810
using System.Net.Http;
911
using System.Runtime.Serialization.Json;
@@ -150,11 +152,10 @@ public AttestationInfo(byte[] attestationInfo)
150152
SessionId = BitConverter.ToInt64(attestationInfo, offset);
151153
offset += sizeof(long);
152154

153-
int secureSessionBufferSize = Convert.ToInt32(secureSessionInfoResponseSize) - sizeof(uint);
154-
byte[] secureSessionBuffer = EnclaveHelpers.TakeBytesAndAdvance(attestationInfo, ref offset, secureSessionBufferSize);
155-
156-
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(secureSessionBuffer);
155+
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(attestationInfo, offset);
157156
offset += Convert.ToInt32(EnclaveDHInfo.Size);
157+
158+
Debug.Assert(offset == attestationInfo.Length);
158159
}
159160
}
160161

0 commit comments

Comments
 (0)