/// <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 Open Enclave enclave. /// </summary> /// <param name="report">An Open Enclave "report". /// See https://github.com/openenclave/openenclave for more information.</param> /// <param name="initTimeData"></param> /// <param name="initTimeDataIsObject"></param> /// <param name="runTimeData">Data provided when the quote was generated.</param> /// <param name="runTimeDataIsObject"></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="report"/>, <paramref name="runTimeData"/>, and <paramref name="initTimeData"/></returns> private async Task <AttestationResponse <AttestationResult> > AttestOpenEnclaveInternalAsync(ReadOnlyMemory <byte> report, BinaryData initTimeData, bool initTimeDataIsObject, BinaryData runTimeData, bool runTimeDataIsObject, bool async, CancellationToken cancellationToken = default) { Argument.AssertNotNull(runTimeData, nameof(runTimeData)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(AttestationClient)}.{nameof(AttestOpenEnclave)}"); scope.Start(); try { AttestOpenEnclaveRequest request = new AttestOpenEnclaveRequest { Report = report.ToArray(), InitTimeData = initTimeData != null ? new InitTimeData { Data = initTimeData.ToArray(), DataType = initTimeDataIsObject ? DataType.Json : DataType.Binary, } : null, RuntimeData = runTimeData != null ? new RuntimeData { Data = runTimeData.ToArray(), DataType = runTimeDataIsObject ? DataType.Json : DataType.Binary, } : null, }; var response = async ? await _restClient.AttestOpenEnclaveAsync(request, cancellationToken).ConfigureAwait(false) : _restClient.AttestOpenEnclave(request, cancellationToken); var attestationToken = new AttestationToken(response.Value.Token); if (_options.TokenOptions.ValidateToken) { await attestationToken.ValidateTokenInternalAsync(_options.TokenOptions, await GetSignersAsync(cancellationToken).ConfigureAwait(false), async, cancellationToken).ConfigureAwait(false); } return(new AttestationResponse <AttestationResult>(response.GetRawResponse(), attestationToken)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Attest an Open Enclave enclave. /// </summary> /// <param name="report">An OpenEnclave "report". /// See https://github.com/openenclave/openenclave for more information.</param> /// <param name="initTimeData">Data provided when the enclave was created.</param> /// <param name="initTimeDataIsObject"></param> /// <param name="runTimeData">Data provided when the quote was generated.</param> /// <param name="runTimeDataIsObject"></param> /// <param name="cancellationToken">Cancellation token used to cancel the request.</param> /// <returns></returns> public virtual AttestationResponse <AttestationResult> AttestOpenEnclave(ReadOnlyMemory <byte> report, BinaryData initTimeData, bool initTimeDataIsObject, BinaryData runTimeData, bool runTimeDataIsObject, CancellationToken cancellationToken = default) { Argument.AssertNotNull(runTimeData, nameof(runTimeData)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(AttestationClient)}.{nameof(AttestSgxEnclave)}"); scope.Start(); try { var response = _restClient.AttestOpenEnclave( new AttestOpenEnclaveRequest { Report = report.ToArray(), InitTimeData = initTimeData != null ? new InitTimeData { Data = initTimeData.ToArray(), DataType = initTimeDataIsObject ? DataType.Json : DataType.Binary, } : null, RuntimeData = runTimeData != null ? new RuntimeData { Data = runTimeData.ToArray(), DataType = runTimeDataIsObject ? DataType.Json : DataType.Binary, } : null, }, cancellationToken); var attestationToken = new AttestationToken(response.Value.Token); if (_options.ValidateAttestationTokens) { attestationToken.ValidateToken(GetSigners(), _options.ValidationCallback); } return(new AttestationResponse <AttestationResult>(response.GetRawResponse(), attestationToken)); } catch (Exception ex) { scope.Failed(ex); throw; } }