Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed userdata to attestationUrl #17

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;
import java.util.Map;

public class AzureCCAttestationProvider implements IAttestationProvider {
private final String maaServerBaseUrl;
Expand Down Expand Up @@ -87,7 +86,7 @@ public byte[] getAttestationRequest(byte[] publicKey, byte[] userData) throws At
var runtimeData = new RuntimeData();
runtimeData.location = this.location;
runtimeData.publicKey = base64Encoder.encodeToString(publicKey);
runtimeData.userData = base64Encoder.encodeToString(userData);
runtimeData.attestationUrl = base64Encoder.encodeToString(userData);
String runtimeDataJson = gson.toJson(runtimeData);

var skrRequest = new SkrRequest();
Expand Down Expand Up @@ -131,7 +130,7 @@ private String getLocation() {
private static class RuntimeData {
private String location;
private String publicKey;
private String userData;
private String attestationUrl;
}

private static class SkrRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class AzureCCAttestationProviderTest {
final private byte[] publicTokenMock = new byte[] {0x01, 0x02};
final private byte[] userDataMock = new byte[] {0x03, 0x04};
final private byte[] attestationUrlMock = new byte[] {0x03, 0x04};

@Test
public void testGetAttestationRequestSuccess() throws Exception {
Expand All @@ -37,7 +37,7 @@ public void testGetAttestationRequestSuccess() throws Exception {

// Verify output
final var provider = new AzureCCAttestationProvider(null, skrUrlMock, httpClientMock);
var output = provider.getAttestationRequest(publicTokenMock, userDataMock);
var output = provider.getAttestationRequest(publicTokenMock, attestationUrlMock);
Assert.assertArrayEquals(maaTokenMock.getBytes(), output);

// Verify sent request
Expand All @@ -56,7 +56,7 @@ public void testGetAttestationRequestFailure_InvalidStatusCode() throws Exceptio
when(httpClientMock.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(httpResponseMock);

final var provider = new AzureCCAttestationProvider(null, null, httpClientMock);
var thrown = Assert.assertThrows(AttestationException.class, () -> provider.getAttestationRequest(publicTokenMock, userDataMock));
var thrown = Assert.assertThrows(AttestationException.class, () -> provider.getAttestationRequest(publicTokenMock, attestationUrlMock));
Assert.assertTrue(thrown.getMessage().startsWith("Skr failed with status code: " + HttpURLConnection.HTTP_INTERNAL_ERROR));
}

Expand All @@ -69,7 +69,7 @@ public void testGetAttestationRequestFailure_EmptyResponseBody() throws Exceptio
when(httpClientMock.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(httpResponseMock);

final var provider = new AzureCCAttestationProvider(null, null, httpClientMock);
var thrown = Assert.assertThrows(AttestationException.class, () -> provider.getAttestationRequest(publicTokenMock, userDataMock));
var thrown = Assert.assertThrows(AttestationException.class, () -> provider.getAttestationRequest(publicTokenMock, attestationUrlMock));
Assert.assertEquals("response is null", thrown.getMessage());
}

Expand All @@ -84,7 +84,7 @@ public void testGetAttestationRequestFailure_InvalidResponseBody() throws Except
when(httpClientMock.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(httpResponseMock);

final var provider = new AzureCCAttestationProvider(null, null, httpClientMock);
var thrown = Assert.assertThrows(AttestationException.class, () -> provider.getAttestationRequest(publicTokenMock, userDataMock));
var thrown = Assert.assertThrows(AttestationException.class, () -> provider.getAttestationRequest(publicTokenMock, attestationUrlMock));
Assert.assertEquals("token field not exist in Skr response", thrown.getMessage());
}
}
Loading