public async Task SetPolicyUnsecuredIsolated() { var adminclient = GetIsolatedAdministrationClient(); byte[] disallowDebuggingHash; { var policySetToken = new UnsecuredAttestationToken(new StoredAttestationPolicy { AttestationPolicy = Base64Url.EncodeString(disallowDebugging) }); var shaHasher = SHA256Managed.Create(); disallowDebuggingHash = shaHasher.ComputeHash(Encoding.UTF8.GetBytes(policySetToken.ToString())); var error = Assert.ThrowsAsync <Azure.RequestFailedException>(async() => await adminclient.SetPolicyAsync(AttestationType.OpenEnclave, policySetToken)); Assert.AreEqual(400, error.Status); await Task.Yield(); } }
public async Task SetPolicySecured(AttestationAdministrationClient adminClient, bool isIsolated) { // Reset the current attestation policy to a known state. Necessary if there were previous runs that failed. await ResetAttestationPolicy(adminClient, AttestationType.OpenEnclave, true, isIsolated); string originalPolicy; { var policyResult = await adminClient.GetPolicyAsync(AttestationType.OpenEnclave); var result = policyResult.Value.AttestationPolicy; var policyRaw = Base64Url.Decode(result); originalPolicy = System.Text.Encoding.UTF8.GetString(policyRaw); } X509Certificate2 x509Certificate; RSA rsaKey; if (isIsolated) { x509Certificate = TestEnvironment.PolicyManagementCertificate; rsaKey = TestEnvironment.PolicyManagementKey; } else { x509Certificate = TestEnvironment.PolicyCertificate0; rsaKey = TestEnvironment.PolicySigningKey0; } byte[] disallowDebuggingHash; { var policySetToken = new SecuredAttestationToken(new StoredAttestationPolicy { AttestationPolicy = Base64Url.EncodeString(disallowDebugging) }, rsaKey, x509Certificate); var policySetResult = await adminClient.SetPolicyAsync(AttestationType.OpenEnclave, policySetToken); var shaHasher = SHA256Managed.Create(); disallowDebuggingHash = shaHasher.ComputeHash(Encoding.UTF8.GetBytes(policySetToken.ToString())); Assert.AreEqual(200, policySetResult.GetRawResponse().Status); Assert.AreEqual(PolicyModification.Updated, policySetResult.Value.PolicyResolution); CollectionAssert.AreEqual(disallowDebuggingHash, policySetResult.Value.PolicyTokenHash); Assert.AreEqual(x509Certificate, policySetResult.Value.PolicySigner.SigningCertificates[0]); } { var policyResult = await adminClient.GetPolicyAsync(AttestationType.OpenEnclave); var result = policyResult.Value.AttestationPolicy; var policyRaw = Base64Url.Decode(result); var policy = System.Text.Encoding.UTF8.GetString(policyRaw); Assert.AreEqual(disallowDebugging, policy); } { var policyResetToken = new SecuredAttestationToken(rsaKey, x509Certificate); var policySetResult = await adminClient.ResetPolicyAsync(AttestationType.OpenEnclave, policyResetToken); Assert.AreEqual(200, policySetResult.GetRawResponse().Status); Assert.AreEqual(PolicyModification.Removed, policySetResult.Value.PolicyResolution); } { var policyResult = await adminClient.GetPolicyAsync(AttestationType.OpenEnclave); var result = policyResult.Value.AttestationPolicy; var policyRaw = Base64Url.Decode(result); var policy = System.Text.Encoding.UTF8.GetString(policyRaw); // And when we're done, policy should be reset to the original value. Assert.AreEqual(originalPolicy, policy); } }
public async Task SetPolicyUnsecuredAad() { var adminclient = GetAadAdministrationClient(); // Reset the current attestation policy to a known state. Necessary if there were previous runs that failed. await ResetAttestationPolicy(adminclient, AttestationType.OpenEnclave, false, false); string originalPolicy; { var policyResult = await adminclient.GetPolicyAsync(AttestationType.OpenEnclave); var result = policyResult.Value.AttestationPolicy; var policyRaw = Base64Url.Decode(result); originalPolicy = System.Text.Encoding.UTF8.GetString(policyRaw); } byte[] disallowDebuggingHash; { var policySetToken = new UnsecuredAttestationToken(new StoredAttestationPolicy { AttestationPolicy = Base64Url.EncodeString(disallowDebugging) }); var policySetResult = await adminclient.SetPolicyAsync(AttestationType.OpenEnclave, policySetToken); var shaHasher = SHA256Managed.Create(); disallowDebuggingHash = shaHasher.ComputeHash(Encoding.UTF8.GetBytes(policySetToken.ToString())); Assert.AreEqual(200, policySetResult.GetRawResponse().Status); Assert.AreEqual(PolicyModification.Updated, policySetResult.Value.PolicyResolution); CollectionAssert.AreEqual(disallowDebuggingHash, policySetResult.Value.PolicyTokenHash); } { var policyResult = await adminclient.GetPolicyAsync(AttestationType.OpenEnclave); var result = policyResult.Value.AttestationPolicy; var policyRaw = Base64Url.Decode(result); var policy = System.Text.Encoding.UTF8.GetString(policyRaw); Assert.AreEqual(disallowDebugging, policy); } { var policyResetToken = new UnsecuredAttestationToken(); var policySetResult = await adminclient.ResetPolicyAsync(AttestationType.OpenEnclave, policyResetToken); Assert.AreEqual(200, policySetResult.GetRawResponse().Status); Assert.AreEqual(PolicyModification.Removed, policySetResult.Value.PolicyResolution); } { var policyResult = await adminclient.GetPolicyAsync(AttestationType.OpenEnclave); var result = policyResult.Value.AttestationPolicy; var policyRaw = Base64Url.Decode(result); var policy = System.Text.Encoding.UTF8.GetString(policyRaw); // And when we're done, policy should be reset to the original value. Assert.AreEqual(originalPolicy, policy); } }