Skip to content

Commit

Permalink
revise enclave parsing and review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 committed Mar 11, 2023
1 parent d7462c0 commit 439c8c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Expand Up @@ -87,12 +87,9 @@ private string GetStackParts()
// trims off most of the bottom of the stack because when running under xunit there's a lot of spam
string[] parts = Environment.StackTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
List<string> take = new List<string>(7);
for (int index = 0; take.Count < 7 && index < parts.Length; index++)
for (int index = 3; take.Count < 7 && index < parts.Length; index++)
{
if (index > 2)
{
take.Add(parts[index]);
}
take.Add(parts[index]);
}

return string.Join(Environment.NewLine, take.ToArray());
Expand Down
Expand Up @@ -18,23 +18,21 @@ public EnclavePublicKey(byte[] payload)

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

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

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

public EnclaveDiffieHellmanInfo(byte[] payload)
public EnclaveDiffieHellmanInfo(byte[] payload, int offset)
{
Size = payload.Length;

int publicKeySize = BitConverter.ToInt32(payload, 0);
int publicKeySignatureSize = BitConverter.ToInt32(payload, 4);
int publicKeySize = BitConverter.ToInt32(payload, offset + 0);
int publicKeySignatureSize = BitConverter.ToInt32(payload, offset + 4);

PublicKey = new byte[publicKeySize];
PublicKeySignature = new byte[publicKeySignatureSize];
Buffer.BlockCopy(payload, 8, PublicKey, 0, publicKeySize);
Buffer.BlockCopy(payload, 8 + publicKeySize, PublicKeySignature, 0, publicKeySignatureSize);
Buffer.BlockCopy(payload, offset + 8, PublicKey, 0, publicKeySize);
Buffer.BlockCopy(payload, offset + 8 + publicKeySize, PublicKeySignature, 0, publicKeySignatureSize);
}
}

Expand Down
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IdentityModel.Tokens.Jwt;
using System.Runtime.Caching;
using System.Security.Claims;
Expand Down Expand Up @@ -203,9 +204,10 @@ public AzureAttestationInfo(byte[] attestationInfo)
SessionId = BitConverter.ToInt64(attestationInfo, offset);
offset += sizeof(long);

int secureSessionBufferSize = Convert.ToInt32(secureSessionInfoResponseSize) - sizeof(uint);
byte[] secureSessionBuffer = EnclaveHelpers.TakeBytesAndAdvance(attestationInfo, ref offset, secureSessionBufferSize);
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(secureSessionBuffer);
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(attestationInfo, offset);
offset += EnclaveDHInfo.Size;

Debug.Assert(offset == attestationInfo.Length);
}
catch (Exception exception)
{
Expand Down
Expand Up @@ -4,6 +4,8 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Net.Http;
using System.Runtime.Serialization.Json;
Expand Down Expand Up @@ -150,11 +152,10 @@ public AttestationInfo(byte[] attestationInfo)
SessionId = BitConverter.ToInt64(attestationInfo, offset);
offset += sizeof(long);

int secureSessionBufferSize = Convert.ToInt32(secureSessionInfoResponseSize) - sizeof(uint);
byte[] secureSessionBuffer = EnclaveHelpers.TakeBytesAndAdvance(attestationInfo, ref offset, secureSessionBufferSize);

EnclaveDHInfo = new EnclaveDiffieHellmanInfo(secureSessionBuffer);
EnclaveDHInfo = new EnclaveDiffieHellmanInfo(attestationInfo, offset);
offset += Convert.ToInt32(EnclaveDHInfo.Size);

Debug.Assert(offset == attestationInfo.Length);
}
}

Expand Down

0 comments on commit 439c8c0

Please sign in to comment.