/// <summary> /// Attest an Open Enclave enclave. /// </summary> /// <param name="request">Aggregate type containing the information needed to perform an attestation operation.</param> /// <param name="async">true if the API call should be asynchronous, false otherwise.</param> /// <param name="cancellationToken">Cancellation token used to cancel the request.</param> /// <returns>An <see cref="AttestationResponse{AttestationResult}"/> which contains the validated claims for the supplied <paramref name="request"/>.</returns> /// <remarks>The <see cref="AttestationRequest.Evidence"/> must be an OpenEnclave Report or OpenEnclave Evidence.</remarks> /// <seealso href="https://github.com/openenclave/openenclave"/> for more information. private async Task <AttestationResponse <AttestationResult> > AttestOpenEnclaveInternalAsync(AttestationRequest request, bool async, CancellationToken cancellationToken = default) { Argument.AssertNotNull(request, nameof(request)); Argument.AssertNotNull(request.Evidence, nameof(request.Evidence)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(AttestationClient)}.{nameof(AttestOpenEnclave)}"); scope.Start(); try { var attestOpenEnclaveRequest = new AttestOpenEnclaveRequest { Report = request.Evidence.ToArray(), DraftPolicyForAttestation = request.DraftPolicyForAttestation, RuntimeData = null, InitTimeData = null, }; if (request.InittimeData != null) { attestOpenEnclaveRequest.InitTimeData = new InitTimeData { Data = request.InittimeData.BinaryData.ToArray(), DataType = request.InittimeData.DataIsJson ? DataType.Json : DataType.Binary, }; } if (request.RuntimeData != null) { attestOpenEnclaveRequest.RuntimeData = new RuntimeData { Data = request.RuntimeData.BinaryData.ToArray(), DataType = request.RuntimeData.DataIsJson ? DataType.Json : DataType.Binary, }; } var response = async ? await _restClient.AttestOpenEnclaveAsync(attestOpenEnclaveRequest, cancellationToken).ConfigureAwait(false) : _restClient.AttestOpenEnclave(attestOpenEnclaveRequest, cancellationToken); var attestationToken = AttestationToken.Deserialize(response.Value.Token, _clientDiagnostics); if (_options.TokenOptions.ValidateToken) { var signers = await GetSignersAsync(async, cancellationToken).ConfigureAwait(false); if (!await attestationToken.ValidateTokenInternal(_options.TokenOptions, signers, async, cancellationToken).ConfigureAwait(false)) { AttestationTokenValidationFailedException.ThrowFailure(signers, attestationToken); } } return(new AttestationResponse <AttestationResult>(response.GetRawResponse(), attestationToken)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Attest an Intel SGX enclave. /// </summary> /// <param name="request">Aggregate type containing the information needed to perform an attestation operation.</param> /// <param name="cancellationToken">Cancellation token used to cancel the request.</param> /// <returns>An <see cref="AttestationResponse{AttestationResult}"/> which contains the validated claims for the supplied <paramref name="request"/>.</returns> /// <remarks>The <see cref="AttestationRequest.Evidence"/> must be an Intel SGX Quote. /// <seealso href="https://software.intel.com/content/www/us/en/develop/articles/code-sample-intel-software-guard-extensions-remote-attestation-end-to-end-example.html"/> for more information. ///</remarks> public virtual AttestationResponse <AttestationResult> AttestSgxEnclave(AttestationRequest request, CancellationToken cancellationToken = default) => AttestSgxEnclaveInternal(request, false, cancellationToken).EnsureCompleted();
/// <summary> /// Attest an Open Enclave enclave. /// </summary> /// <param name="request">Aggregate type containing the information needed to perform an attestation operation.</param> /// <param name="cancellationToken">Cancellation token used to cancel the request.</param> /// <returns>An <see cref="AttestationResponse{AttestationResult}"/> which contains the validated claims for the supplied <paramref name="request"/>.</returns> /// <remarks>The <see cref="AttestationRequest.Evidence"/> must be an OpenEnclave Report or OpenEnclave Evidence.</remarks> /// <seealso href="https://github.com/openenclave/openenclave"/> for more information. public virtual async Task <AttestationResponse <AttestationResult> > AttestOpenEnclaveAsync(AttestationRequest request, CancellationToken cancellationToken = default) => await AttestOpenEnclaveInternalAsync(request, true, cancellationToken).ConfigureAwait(false);