Esempio n. 1
0
        private IList <XmlDocument> CreateRequests()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    if (_initLastSegment)
                    {
                        s_logger.LogDebug("lastSegment is {lastSegment}. Not creating any transfer requests",
                                          _initLastSegment);
                        return(null);
                    }

                    var reqs = new List <XmlDocument>();

                    for (var i = 1; i < _numSegments; i++)
                    {
                        s_logger.LogDebug("Creating transfer request {no}", i);
                        var req = new ebics.ebicsRequest
                        {
                            Version  = "H004",
                            Revision = "1",
                            header   = new ebics.ebicsRequestHeader
                            {
                                @static = new ebics.StaticHeaderType
                                {
                                    HostID           = Config.User.HostId,
                                    ItemsElementName = new ebics.ItemsChoiceType3[] { ebics.ItemsChoiceType3.TransactionID },
                                    Items            = new object[] { _transactionID }
                                },
                                mutable = new ebics.MutableHeaderType
                                {
                                    TransactionPhase = ebics.TransactionPhaseType.Transfer,
                                    SegmentNumber    = new ebics.MutableHeaderTypeSegmentNumber
                                    {
                                        Value       = (i + _initSegment).ToString(),
                                        lastSegment = i + _initSegment == _numSegments
                                    }
                                },
                            },
                            body = new ebics.ebicsRequestBody
                            {
                            }
                        };

                        reqs.Add(Authenticate(req));
                    }

                    return(reqs);
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create {OrderType} requests", ex);
                }
            }
        }
Esempio n. 2
0
        protected XmlDocument Authenticate(ebics.ebicsRequest initReq, Type type)
        {
            initReq.AuthSignature = new ebics.SignatureType {
                SignatureValue = new ebics.SignatureValueType {
                }
            };
            var doc = XMLSerializeToDocument(initReq, type);

            Sign(doc, Config.User.AuthKeys.PrivateKey);
            return(doc);
        }
Esempio n. 3
0
        private XmlDocument CreateReceiptRequest()
        {
            try
            {
                var receiptReq = new ebics.ebicsRequest
                {
                    Version  = "H004",
                    Revision = "1",
                    header   = new ebics.ebicsRequestHeader
                    {
                        authenticate = true,
                        @static      = new ebics.StaticHeaderType
                        {
                            HostID           = Config.User.HostId,
                            ItemsElementName = new ebics.ItemsChoiceType3[]
                            {
                                ebics.ItemsChoiceType3.TransactionID
                            },
                            Items = new object[]
                            {
                                _transactionID
                            },
                        },
                        mutable = new ebics.MutableHeaderType
                        {
                            TransactionPhase = ebics.TransactionPhaseType.Receipt
                        },
                    }
                    ,
                    body = new ebics.ebicsRequestBody
                    {
                        Items = new object[] {
                            new ebics.ebicsRequestBodyTransferReceipt
                            {
                                authenticate = true,
                                ReceiptCode  = "0"
                            }
                        }
                    }
                };

                return(Authenticate(receiptReq));
            }
            catch (EbicsException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new CreateRequestException($"can't create receipt request for {OrderType}", ex);
            }
        }
Esempio n. 4
0
        private (XmlDocument request, IList <string> segments) CreateInitRequest()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    //XNamespace nsEBICS = Namespaces.Ebics;

                    var hvdDoc = _Params;
                    s_logger.LogDebug("Created {OrderType} document:\n{doc}", OrderType, hvdDoc.ToString());

                    var userSigData = CreateUserSigData(hvdDoc);
                    s_logger.LogDebug("Created user signature data:\n{data}", userSigData.ToString());

                    var userSigDataXmlStr = userSigData.ToString(SaveOptions.DisableFormatting);
                    var userSigDataComp   = Compress(Encoding.UTF8.GetBytes(userSigDataXmlStr));
                    var userSigDataEnc    = EncryptAes(userSigDataComp, _transactionKey);

                    var hvdDocXmlStr = FormatXml(hvdDoc);
                    var hvdDocComp   = Compress(Encoding.UTF8.GetBytes(hvdDocXmlStr));
                    var hvdDocEnc    = EncryptAes(hvdDocComp, _transactionKey);
                    var hvdDocB64    = Convert.ToBase64String(hvdDocEnc);

                    var segments = Segment(hvdDocB64);

                    s_logger.LogDebug("Number of segments: {segments}", segments.Count);

                    var initReq = new ebics.ebicsRequest
                    {
                        Version  = "H004",
                        Revision = "1",
                        header   = new ebics.ebicsRequestHeader
                        {
                            authenticate = true,
                            @static      = new ebics.StaticHeaderType
                            {
                                HostID           = Config.User.HostId,
                                ItemsElementName = new ebics.ItemsChoiceType3[]
                                {
                                    ebics.ItemsChoiceType3.Nonce,
                                    ebics.ItemsChoiceType3.Timestamp,
                                    ebics.ItemsChoiceType3.PartnerID,
                                    ebics.ItemsChoiceType3.UserID,
                                    ebics.ItemsChoiceType3.Product,
                                    ebics.ItemsChoiceType3.OrderDetails,
                                    ebics.ItemsChoiceType3.BankPubKeyDigests,
                                    ebics.ItemsChoiceType3.SecurityMedium,
                                    ebics.ItemsChoiceType3.NumSegments
                                },
                                Items = new object[]
                                {
                                    CryptoUtils.GetNonceBinary(),
                        DateTime.UtcNow,
                        Config.User.PartnerId,
                        Config.User.UserId,
                        Config.StaticHeaderTypeProduct,
                                    new ebics.StaticHeaderOrderDetailsType
                                    {
                                        OrderType = new ebics.StaticHeaderOrderDetailsTypeOrderType {
                                            Value = OrderType
                                        },
                                        OrderAttribute = (ebics.OrderAttributeType)Enum.Parse(typeof(ebics.OrderAttributeType), this.OrderAttribute),
                                        OrderParams    = new ebics.GenericOrderParamsType(),
                                    },
                                    Config.Bank.pubkeydigests,
                                    SecurityMedium,
                                    segments.Count.ToString(),
                                }
                            },
                            mutable = new ebics.MutableHeaderType {
                                TransactionPhase = ebics.TransactionPhaseType.Initialisation
                            }
                        },
                        body = new ebics.ebicsRequestBody
                        {
                            Items = new object[] {
                                new ebics.DataTransferRequestType
                                {
                                    Items = new object[]
                                    {
                                        new ebics.DataTransferRequestTypeDataEncryptionInfo
                                        {
                                            EncryptionPubKeyDigest = new ebics.DataEncryptionInfoTypeEncryptionPubKeyDigest
                                            {
                                                Algorithm = S_digestAlg,
                                                Value     = Config.Bank.CryptKeys.Digest,
                                                Version   = Config.Bank.CryptKeys.Version.ToString()
                                            },
                                            TransactionKey = EncryptRsa(_transactionKey)
                                        },
                                        new ebics.DataTransferRequestTypeSignatureData
                                        {
                                            Value = userSigDataEnc
                                        }
                                    }
                                }
                            }
                        }
                    };

                    return(request : Authenticate(initReq, typeof(ebics.GenericOrderParamsType)), segments : segments);
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create {OrderType} init request", ex);
                }
            }
        }
Esempio n. 5
0
        private XmlDocument CreateInitRequest()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    //XNamespace nsEBICS = Namespaces.Ebics;

                    var initReq = new ebics.ebicsRequest
                    {
                        Version  = "H004",
                        Revision = "1",
                        header   = new ebics.ebicsRequestHeader
                        {
                            authenticate = true,
                            @static      = new ebics.StaticHeaderType
                            {
                                HostID           = Config.User.HostId,
                                ItemsElementName = new ebics.ItemsChoiceType3[]
                                {
                                    ebics.ItemsChoiceType3.Nonce,
                                    ebics.ItemsChoiceType3.Timestamp,
                                    ebics.ItemsChoiceType3.PartnerID,
                                    ebics.ItemsChoiceType3.UserID,
                                    ebics.ItemsChoiceType3.Product,
                                    ebics.ItemsChoiceType3.OrderDetails,
                                    ebics.ItemsChoiceType3.BankPubKeyDigests,
                                    ebics.ItemsChoiceType3.SecurityMedium
                                },
                                Items = new object[]
                                {
                                    CryptoUtils.GetNonceBinary(),
                        DateTime.UtcNow,
                        Config.User.PartnerId,
                        Config.User.UserId,
                        Config.StaticHeaderTypeProduct,
                                    new ebics.StaticHeaderOrderDetailsType
                                    {
                                        OrderType = new ebics.StaticHeaderOrderDetailsTypeOrderType {
                                            Value = OrderType
                                        },
                                        OrderAttribute = (ebics.OrderAttributeType)Enum.Parse(typeof(ebics.OrderAttributeType), this.OrderAttribute),
                                        OrderParams    = _Params,
                                    },
                                    Config.Bank.pubkeydigests,
                                    SecurityMedium,
                                }
                            },
                            mutable = new ebics.MutableHeaderType {
                                TransactionPhase = ebics.TransactionPhaseType.Initialisation
                            },
                        },
                        body = new ebics.ebicsRequestBody()
                        {
                        }
                    };


                    return(Authenticate(initReq, _Params?.GetType()));
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create {OrderType} init request", ex);
                }
            }
        }