This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
/
DeviceCheckService.cs
46 lines (42 loc) · 1.47 KB
/
DeviceCheckService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Covid19Radar.Services;
using Covid19Radar.Droid.Services;
using Xamarin.Forms;
using Covid19Radar.Model;
using Covid19Radar.Common;
using Android.Gms.SafetyNet;
[assembly: Dependency(typeof(DeviceCheckService))]
namespace Covid19Radar.Droid.Services
{
public class DeviceCheckService : IDeviceVerifier
{
public Task<string> VerifyAsync(DiagnosisSubmissionParameter submission)
{
var nonce = submission.GetAndroidNonce();
return GetSafetyNetAttestationAsync(nonce);
}
/// <summary>
/// Verification device information required for positive submissions
/// </summary>
/// <returns>Device Verification Payload</returns>
async Task<string> GetSafetyNetAttestationAsync(byte[] nonce)
{
using var client = SafetyNetClass.GetClient(Android.App.Application.Context);
using var response = await client.AttestAsync(nonce, AppSettings.Instance.AndroidSafetyNetApiKey);
return response.JwsResult;
}
}
}