public ReceiveTransactionsController(
     IBanksService banksService,
     IMapper mapper,
     IOptions <CentralApiConfiguration> configuration)
 {
     this.banksService  = banksService;
     this.mapper        = mapper;
     this.configuration = configuration.Value;
 }
Beispiel #2
0
        private async Task <bool> IsValidRequest(
            ActionExecutingContext context)
        {
            var request       = context.HttpContext.Request;
            var bankService   = request.HttpContext.RequestServices.GetService <IBanksService>();
            var configOptions = request.HttpContext.RequestServices
                                .GetService <IOptions <CentralApiConfiguration> >();

            this.configuration = configOptions.Value;

            var actionArguments = context.ActionArguments;
            var model           = actionArguments.Values.First();

            if (model == null)
            {
                return(false);
            }

            try
            {
                var     incomingData     = Encoding.UTF8.GetString(Convert.FromBase64String(model.ToString()));
                dynamic deserializedData = JsonConvert.DeserializeObject(incomingData);
                string  bankName         = deserializedData.BankName;
                string  bankSwiftCode    = deserializedData.BankSwiftCode;
                string  bankCountry      = deserializedData.BankCountry;

                var bank = await bankService.GetBankAsync <BankServiceModel>(bankName, bankSwiftCode, bankCountry);

                if (bank == null)
                {
                    return(false);
                }

                string encryptedKey = deserializedData.EncryptedKey;
                string encryptedIv  = deserializedData.EncryptedIv;
                string data         = deserializedData.Data;
                string signature    = deserializedData.Signature;

                var decryptedData = SignatureVerificationUtil
                                    .DecryptDataAndVerifySignature(new SignatureVerificationModel
                {
                    DecryptionPrivateKey = this.configuration.Key,
                    SignaturePublicKey   = bank.ApiKey,
                    EncryptedKey         = encryptedKey,
                    EncryptedIv          = encryptedIv,
                    Data      = data,
                    Signature = signature
                });

                if (decryptedData == null)
                {
                    return(false);
                }

                // Modify body
                var key = actionArguments.Keys.First();
                actionArguments.Remove(key);
                actionArguments.Add(key, decryptedData);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
 public CardPaymentsController(IBanksService banksService, IOptions <CentralApiConfiguration> configuration)
 {
     this.banksService  = banksService;
     this.configuration = configuration.Value;
 }