Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 committed Mar 8, 2023
1 parent d7462c0 commit 7e1415d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Runtime.Caching;
using System.Security.Claims;
using System.Security.Cryptography;
Expand Down Expand Up @@ -168,8 +169,8 @@ internal class AzureAttestationInfo

public AzureAttestationInfo(byte[] attestationInfo)
{
try
{
//try
//{
int offset = 0;

// Total size of the attestation info buffer
Expand Down Expand Up @@ -203,14 +204,24 @@ 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);

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

if (secureSessionBufferSize != EnclaveDHInfo.Size)
{
throw SQL.AttestationFailed(string.Format(Strings.FailToParseAttestationInfo, exception.Message));
throw new InvalidOperationException($"enclave data mismatch, expected {secureSessionBufferSize} got {EnclaveDHInfo.Size}");
}
//}
//catch (Exception exception)
//{
// throw SQL.AttestationFailed(string.Format(Strings.FailToParseAttestationInfo, exception.Message));
//}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,20 @@ internal static class EnclaveHelpers
{
public static byte[] TakeBytesAndAdvance(byte[] input, ref int offset, int count)
{
byte[] output = new byte[count];
Buffer.BlockCopy(input, offset, output, 0, count);
offset += count;
return output;
int initialOffset = offset;
try
{
byte[] output = new byte[count];
Buffer.BlockCopy(input, offset, output, 0, count);
offset += count;
return output;
}
catch (Exception ex)
{
string message = $"TakeBytesAndAdvance(input.Length: {input.Length}, offset: {initialOffset}, count: {count}) => offset {offset}";

throw new Exception(message, ex);
}
}
}
}

0 comments on commit 7e1415d

Please sign in to comment.