Example #1
0
        public SendAccessResponseModel(Send send, GlobalSettings globalSettings)
            : base("send-access")
        {
            if (send == null)
            {
                throw new ArgumentNullException(nameof(send));
            }

            Id   = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
            Type = send.Type;

            SendData sendData;

            switch (send.Type)
            {
            case SendType.File:
                var fileData = JsonConvert.DeserializeObject <SendFileData>(send.Data);
                sendData = fileData;
                File     = new SendFileModel(fileData, globalSettings);
                break;

            case SendType.Text:
                var textData = JsonConvert.DeserializeObject <SendTextData>(send.Data);
                sendData = textData;
                Text     = new SendTextModel(textData);
                break;

            default:
                throw new ArgumentException("Unsupported " + nameof(Type) + ".");
            }

            Name           = sendData.Name;
            ExpirationDate = send.ExpirationDate;
        }
Example #2
0
 public void AlterIdentityTokenHeaders(HttpRequestHeaders headers)
 {
     if (MasterPasswordHash != null && Email != null)
     {
         headers.Add("Auth-Email", CoreHelpers.Base64UrlEncode(Encoding.UTF8.GetBytes(Email)));
     }
 }
Example #3
0
 /// <summary>
 /// Create the response to the server, for it to be validate
 /// </summary>
 private void SignInUserResponse(Intent data)
 {
     try
     {
         // Extract the AuthenticatorAssertionResponse.
         AuthenticatorAssertionResponse response = AuthenticatorAssertionResponse.DeserializeFromBytes(data.GetByteArrayExtra(Fido.Fido2KeyResponseExtra));
         // Preparing the response
         var responseJson = Newtonsoft.Json.JsonConvert.SerializeObject(new Fido2AuthenticationChallengeRequest
         {
             Id       = CoreHelpers.Base64UrlEncode(response.GetKeyHandle()),
             RawId    = CoreHelpers.Base64UrlEncode(response.GetKeyHandle()),
             Type     = "public-key",
             Response = new Fido2AssertionResponse
             {
                 AuthenticatorData = CoreHelpers.Base64UrlEncode(response.GetAuthenticatorData()),
                 ClientDataJson    = CoreHelpers.Base64UrlEncode(response.GetClientDataJSON()),
                 Signature         = CoreHelpers.Base64UrlEncode(response.GetSignature()),
                 UserHandle        = (response.GetUserHandle() != null?CoreHelpers.Base64UrlEncode(response.GetUserHandle()):null),
             },
             Extensions = null
         }
                                                                        );
         // Sending the response
         // Messaging Service doesn't run completed if is on UI Thread, this (Device.BeginInvokeOnMainThread) is just to use message service out of UI Thread
         Xamarin.Forms.Device.BeginInvokeOnMainThread(() => ((MainActivity)this.application).Fido2Submission(responseJson));
     } catch (Exception e) {
         Log.Error(_tag_log, e.Message);
     } finally
     {
         Log.Info(_tag_log, "SignInUserResponse() -> finally()");
     }
 }
Example #4
0
        public SendResponseModel(Send send, GlobalSettings globalSettings)
            : base("send")
        {
            if (send == null)
            {
                throw new ArgumentNullException(nameof(send));
            }

            Id             = send.Id.ToString();
            AccessId       = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
            Type           = send.Type;
            Key            = send.Key;
            MaxAccessCount = send.MaxAccessCount;
            AccessCount    = send.AccessCount;
            RevisionDate   = send.RevisionDate;
            ExpirationDate = send.ExpirationDate;
            DeletionDate   = send.DeletionDate;
            Password       = send.Password;
            Disabled       = send.Disabled;
            HideEmail      = send.HideEmail.GetValueOrDefault();

            SendData sendData;

            switch (send.Type)
            {
            case SendType.File:
                var fileData = JsonConvert.DeserializeObject <SendFileData>(send.Data);
                sendData = fileData;
                File     = new SendFileModel(fileData, globalSettings);
                break;

            case SendType.Text:
                var textData = JsonConvert.DeserializeObject <SendTextData>(send.Data);
                sendData = textData;
                Text     = new SendTextModel(textData);
                break;

            default:
                throw new ArgumentException("Unsupported " + nameof(Type) + ".");
            }

            Name  = sendData.Name;
            Notes = sendData.Notes;
        }
Example #5
0
        public async Task SendsController_WhenSendHidesEmail_CreatorIdentifierShouldBeNull(
            Guid id, Send send, User user)
        {
            var accessId = CoreHelpers.Base64UrlEncode(id.ToByteArray());

            send.Id        = default;
            send.Type      = SendType.Text;
            send.Data      = JsonConvert.SerializeObject(new Dictionary <string, string>());
            send.HideEmail = true;

            _sendService.AccessAsync(id, null).Returns((send, false, false));
            _userService.GetUserByIdAsync(Arg.Any <Guid>()).Returns(user);

            var request      = new SendAccessRequestModel();
            var actionResult = await _sut.Access(accessId, request);

            var response = (actionResult as ObjectResult)?.Value as SendAccessResponseModel;

            Assert.NotNull(response);
            Assert.Null(response.CreatorIdentifier);
        }