public Task <ApiResponse <string> > PutEventLog(V1EventLogRequest request) { return(Task.Factory.StartNew(() => { return new ApiResponse <string>((int)HttpStatusCode.Created, ""); })); }
public static byte[] CreateAndroidNonceV3(V1EventLogRequest eventLogRequest) { var cleartext = GetNonceClearTextV3(eventLogRequest); var nonce = GetSha256(cleartext); return(nonce); }
private async Task <bool> SendAsync(string idempotencyKey, List <EventLog> eventLogList) { _loggerService.StartMethod(); try { var request = new V1EventLogRequest() { IdempotencyKey = idempotencyKey, Platform = _essentialsService.Platform, AppPackageName = _essentialsService.AppPackageName, EventLogs = eventLogList, }; // Create device verification payload PolicyResult <string> policyResult = await Policy .HandleResult <string>(result => _deviceVerifier.IsErrorPayload(result)) .WaitAndRetryAsync(3, retryAttempt => { double delay = Math.Pow(2, retryAttempt + 1); _loggerService.Warning($"Payload creation failed. retryAttempt:{retryAttempt} delay:{delay}sec"); return(TimeSpan.FromSeconds(delay)); }) .ExecuteAndCaptureAsync(() => _deviceVerifier.VerifyAsync(request)); if (policyResult.Outcome == OutcomeType.Failure) { _loggerService.Error("Payload creation failed all."); return(false); } _loggerService.Info("Payload creation successful."); request.DeviceVerificationPayload = policyResult.Result; ApiResponse <string> response = await _httpDataService.PutEventLog(request); _loggerService.Info($"PutEventLog() StatusCode:{response.StatusCode}"); if (response.StatusCode == (int)HttpStatusCode.Created) { _loggerService.Info("Send event log succeeded"); return(true); } } catch (Exception ex) { _loggerService.Exception("Exception occurred, SendAsync", ex); } finally { _loggerService.EndMethod(); } _loggerService.Error("Send event log failure"); return(false); }
public void AndroidClearTextTestV3() { string expectedClearText = GetTestJson(EXPECTED_CLEAR_TEXT_FILENAME); string eventLogsText = GetTestJson(JSON_EVENTLOG_SUBMISSION_PARAMETERS1); V1EventLogRequest eventLogRequest = JsonConvert.DeserializeObject <V1EventLogRequest>(eventLogsText); string clearText = DeviceVerifierUtils.GetNonceClearTextV3(eventLogRequest); Assert.Equal( expectedClearText, clearText ); }
// PUT /api/v*/event_log public async Task <ApiResponse <string> > PutEventLog(V1EventLogRequest request) { loggerService.StartMethod(); try { await serverConfigurationRepository.LoadAsync(); string url = serverConfigurationRepository.EventLogApiEndpoint; string requestBody = JsonConvert.SerializeObject(request); var content = new StringContent(requestBody, Encoding.UTF8, "application/json"); HttpResponseMessage response = await apiClient.PutAsync(url, content); string responseContent = await response.Content.ReadAsStringAsync(); return(new ApiResponse <string>((int)response.StatusCode, responseContent)); } finally { loggerService.EndMethod(); } }
private async Task SendExposureDataAsync( string idempotencyKey, ExposureData exposureData ) { _loggerService.StartMethod(); SendEventLogState sendEventLogState = _userDataRepository.GetSendEventLogState(); bool isEnabled = sendEventLogState == SendEventLogState.Enable; if (!isEnabled) { _loggerService.Debug($"Send event-log function is not enabled."); _loggerService.EndMethod(); return; } await _serverConfigurationRepository.LoadAsync(); string exposureDataCollectServerEndpoint = _serverConfigurationRepository.EventLogApiEndpoint; _loggerService.Debug($"exposureDataCollectServerEndpoint: {exposureDataCollectServerEndpoint}"); try { var contentJson = exposureData.ToJsonString(); var eventLog = new V1EventLogRequest.EventLog() { HasConsent = isEnabled, Epoch = _dateTimeUtility.UtcNow.ToUnixEpoch(), Type = "ExposureData", Subtype = "Debug", Content = contentJson, }; var eventLogs = new[] { eventLog }; var request = new V1EventLogRequest() { IdempotencyKey = idempotencyKey, Platform = _essentialsService.Platform, AppPackageName = _essentialsService.AppPackageName, EventLogs = eventLogs, }; request.DeviceVerificationPayload = await _deviceVerifier.VerifyAsync(request); var requestJson = request.ToJsonString(); var httpContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); Uri uri = new Uri(exposureDataCollectServerEndpoint); HttpResponseMessage response = await _httpClient.PutAsync(uri, httpContent); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); _loggerService.Debug($"{responseJson}"); } else { _loggerService.Info($"UploadExposureDataAsync {response.StatusCode}"); } } finally { _loggerService.EndMethod(); } }
public async Task <string> VerifyAsync(V1EventLogRequest _) { var token = await DeviceCheck.DCDevice.CurrentDevice.GenerateTokenAsync(); return(Convert.ToBase64String(token.ToArray())); }
public Task <string> VerifyAsync(V1EventLogRequest eventLogRequest) { var nonce = DeviceVerifierUtils.CreateAndroidNonceV3(eventLogRequest); return(GetSafetyNetAttestationAsync(nonce)); }
public async Task PutEventLogTests_Success() { HttpContent requestContent = null; var mockHttpClient = new HttpClient(new MockHttpHandler((r, c) => { var absoluteUri = r.RequestUri.AbsoluteUri; if (absoluteUri.EndsWith("/api/v1/event_log")) { requestContent = r.Content; var response = new HttpResponseMessage(HttpStatusCode.Created); response.Content = new StringContent(""); return(response); } return(new HttpResponseMessage(HttpStatusCode.NotFound)); })); mockHttpClientService.Setup(x => x.Create()).Returns(mockHttpClient); var unitUnderTest = CreateService(); var request = new V1EventLogRequest() { IdempotencyKey = "05A6A158-E216-4599-B99E-3708D360FF2F", Platform = "platform", AppPackageName = "app-package-name", DeviceVerificationPayload = "device-verification-payload", EventLogs = new List <EventLog>() { new EventLog() { HasConsent = true, Epoch = 1000, Type = "type", Subtype = "subtype", Content = JObject.FromObject(new { key = 2000 }) } } }; var result = await unitUnderTest.PutEventLog(request); Assert.Equal((int)HttpStatusCode.Created, result.StatusCode); Assert.NotNull(requestContent); var stringContent = await requestContent.ReadAsStringAsync(); Assert.NotEmpty(stringContent); var jsonContent = JsonConvert.DeserializeObject(stringContent) as JObject; Assert.NotNull(jsonContent); Assert.Equal("05A6A158-E216-4599-B99E-3708D360FF2F", jsonContent["idempotencyKey"].Value <string>()); Assert.Equal("platform", jsonContent["platform"].Value <string>()); Assert.Equal("app-package-name", jsonContent["appPackageName"].Value <string>()); Assert.Equal("device-verification-payload", jsonContent["deviceVerificationPayload"].Value <string>()); var eventLogs = jsonContent["eventLogs"] as JArray; Assert.Single(eventLogs); Assert.True(eventLogs[0]["hasConsent"].Value <bool>()); Assert.Equal(1000, eventLogs[0]["epoch"].Value <long>()); Assert.Equal("type", eventLogs[0]["type"].Value <string>()); Assert.Equal("subtype", eventLogs[0]["subtype"].Value <string>()); Assert.Equal("{\"key\":2000}", eventLogs[0]["content"].Value <JToken>().ToString(Formatting.None)); Assert.Null(mockHttpClient.DefaultRequestHeaders.Authorization); }
public Task <string> VerifyAsync(V1EventLogRequest _) => Task.Run(() => "DUMMY RESPONSE");