Ejemplo n.º 1
0
        private XmlDocument CreateInitRequest()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    var initReq = new EbicsRequest
                    {
                        StaticHeader = new StaticHeader
                        {
                            Namespaces        = Namespaces,
                            HostId            = Config.User.HostId,
                            PartnerId         = Config.User.PartnerId,
                            UserId            = Config.User.UserId,
                            SecurityMedium    = Params.SecurityMedium,
                            Nonce             = CryptoUtils.GetNonce(),
                            Timestamp         = CryptoUtils.GetUtcTimeNow(),
                            BankPubKeyDigests = new BankPubKeyDigests
                            {
                                Namespaces      = Namespaces,
                                Bank            = Config.Bank,
                                DigestAlgorithm = s_digestAlg
                            },
                            OrderDetails = new OrderDetails
                            {
                                Namespaces          = Namespaces,
                                OrderAttribute      = OrderAttribute,
                                OrderType           = OrderType,
                                StandardOrderParams = new EmptyOrderParams
                                {
                                    Namespaces = Namespaces,
                                }
                            }
                        },
                        MutableHeader = new MutableHeader
                        {
                            Namespaces       = Namespaces,
                            TransactionPhase = "Initialisation"
                        },
                        Body = new Body
                        {
                            Namespaces = Namespaces
                        },
                        Namespaces = Namespaces,
                        Version    = Config.Version,
                        Revision   = Config.Revision,
                    };

                    return(AuthenticateXml(initReq.Serialize().ToXmlDocument(), null, null));
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create init request for {OrderType}", ex);
                }
            }
        }
Ejemplo n.º 2
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 EbicsRequest
                        {
                            Namespaces   = Namespaces,
                            Version      = Config.Version,
                            Revision     = Config.Revision,
                            StaticHeader = new StaticHeader
                            {
                                HostId        = Config.User.HostId,
                                TransactionId = _transactionId,
                            },
                            MutableHeader = new MutableHeader
                            {
                                Namespaces       = Namespaces,
                                TransactionPhase = "Transfer",
                                SegmentNumber    = i + _initSegment,
                                LastSegment      = i + _initSegment == _numSegments
                            },
                            Body = new Body
                            {
                                Namespaces = Namespaces
                            }
                        };

                        reqs.Add(AuthenticateXml(req.Serialize().ToXmlDocument(), null, null));
                    }

                    return(reqs);
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create {OrderType} requests", ex);
                }
            }
        }
Ejemplo n.º 3
0
        private XmlDocument CreateReceiptRequest()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    var receiptReq = new EbicsRequest
                    {
                        Version      = Config.Version,
                        Revision     = Config.Revision,
                        Namespaces   = Namespaces,
                        StaticHeader = new StaticHeader
                        {
                            Namespaces    = Namespaces,
                            HostId        = Config.User.HostId,
                            TransactionId = _transactionId
                        },
                        MutableHeader = new MutableHeader
                        {
                            Namespaces       = Namespaces,
                            TransactionPhase = "Receipt"
                        },
                        Body = new Body
                        {
                            Namespaces      = Namespaces,
                            TransferReceipt = new TransferReceipt
                            {
                                Namespaces  = Namespaces,
                                ReceiptCode = "0"
                            }
                        }
                    };

                    return(AuthenticateXml(receiptReq.Serialize().ToXmlDocument(), null, null));
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create {OrderType} receipt request", ex);
                }
            }
        }
Ejemplo n.º 4
0
        private XmlDocument CreateInitRequest()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    var signedData = SignData(Encoding.ASCII.GetBytes(" "), Config.User.SignKeys);

                    var userSigData = new UserSignatureData
                    {
                        Namespaces         = Namespaces,
                        OrderSignatureData = new OrderSignatureData
                        {
                            Namespaces     = Namespaces,
                            PartnerId      = Config.User.PartnerId,
                            UserId         = Config.User.UserId,
                            SignatureValue = signedData,
                            SignKeys       = Config.User.SignKeys
                        }
                    };

                    s_logger.LogDebug("User signature data:\n{data}", userSigData.ToString());

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

                    XNamespace nsEbics = Namespaces.Ebics;

                    var initReq = new EbicsRequest
                    {
                        Namespaces   = Namespaces,
                        Version      = Config.Version,
                        Revision     = Config.Revision,
                        StaticHeader = new StaticHeader
                        {
                            Namespaces   = Namespaces,
                            HostId       = Config.User.HostId,
                            Nonce        = CryptoUtils.GetNonce(),
                            Timestamp    = CryptoUtils.GetUtcTimeNow(),
                            PartnerId    = Config.User.PartnerId,
                            UserId       = Config.User.UserId,
                            NumSegments  = 0,
                            OrderDetails = new OrderDetails
                            {
                                Namespaces          = Namespaces,
                                OrderType           = OrderType,
                                OrderAttribute      = OrderAttribute,
                                StandardOrderParams = new EmptyOrderParams(),
                            },
                            BankPubKeyDigests = new BankPubKeyDigests
                            {
                                Namespaces      = Namespaces,
                                DigestAlgorithm = s_digestAlg,
                                Bank            = Config.Bank
                            }
                        },
                        MutableHeader = new MutableHeader
                        {
                            Namespaces       = Namespaces,
                            TransactionPhase = "Initialisation"
                        },
                        Body = new Body
                        {
                            Namespaces   = Namespaces,
                            DataTransfer = new DataTransfer
                            {
                                Namespaces         = Namespaces,
                                DataEncryptionInfo = new DataEncryptionInfo
                                {
                                    Namespaces             = Namespaces,
                                    EncryptionPubKeyDigest = new EncryptionPubKeyDigest
                                    {
                                        Namespaces      = Namespaces,
                                        Bank            = Config.Bank,
                                        DigestAlgorithm = s_digestAlg
                                    },
                                    TransactionKey = Convert.ToBase64String(EncryptRsa(_transactionKey))
                                },
                                SignatureData = new SignatureData
                                {
                                    Namespaces = Namespaces
                                }
                            }
                        }
                    };

                    var xmlInitReq = initReq.Serialize();
                    xmlInitReq.Descendants(nsEbics + XmlNames.SignatureData).FirstOrDefault()
                    .Add(Convert.ToBase64String(userSigDataEnc));
                    return(AuthenticateXml(xmlInitReq.ToXmlDocument(), null, null));
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create init request for {OrderType}", ex);
                }
            }
        }
Ejemplo n.º 5
0
        private (XmlDocument request, IList <string> segments) CreateInitRequest()
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    XNamespace nsEbics = Namespaces.Ebics;

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

                    var userSigData = CreateUserSigData(cctDoc);
                    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 cctDocXmlStr = FormatCctXml(cctDoc);
                    var cctDocComp   = Compress(Encoding.UTF8.GetBytes(cctDocXmlStr));
                    var cctDocEnc    = EncryptAes(cctDocComp, _transactionKey);
                    var cctDocB64    = Convert.ToBase64String(cctDocEnc);

                    var segments = Segment(cctDocB64);

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

                    var initReq = new EbicsRequest
                    {
                        Namespaces   = Namespaces,
                        Version      = Config.Version,
                        Revision     = Config.Revision,
                        StaticHeader = new StaticHeader
                        {
                            Namespaces     = Namespaces,
                            HostId         = Config.User.HostId,
                            Nonce          = CryptoUtils.GetNonce(),
                            Timestamp      = CryptoUtils.GetUtcTimeNow(),
                            PartnerId      = Config.User.PartnerId,
                            UserId         = Config.User.UserId,
                            SecurityMedium = Params.SecurityMedium,
                            NumSegments    = segments.Count,
                            OrderDetails   = new OrderDetails
                            {
                                Namespaces          = Namespaces,
                                OrderType           = OrderType,
                                OrderAttribute      = OrderAttribute,
                                StandardOrderParams = new EmptyOrderParams
                                {
                                    Namespaces = Namespaces
                                },
                            },
                            BankPubKeyDigests = new BankPubKeyDigests
                            {
                                Namespaces      = Namespaces,
                                DigestAlgorithm = s_digestAlg,
                                Bank            = Config.Bank
                            }
                        },
                        MutableHeader = new MutableHeader
                        {
                            Namespaces       = Namespaces,
                            TransactionPhase = "Initialisation"
                        },
                        Body = new Body
                        {
                            Namespaces   = Namespaces,
                            DataTransfer = new DataTransfer
                            {
                                Namespaces         = Namespaces,
                                DataEncryptionInfo = new DataEncryptionInfo
                                {
                                    Namespaces             = Namespaces,
                                    EncryptionPubKeyDigest = new EncryptionPubKeyDigest
                                    {
                                        Namespaces      = Namespaces,
                                        Bank            = Config.Bank,
                                        DigestAlgorithm = s_digestAlg
                                    },
                                    TransactionKey = Convert.ToBase64String(EncryptRsa(_transactionKey))
                                },
                                SignatureData = new SignatureData
                                {
                                    Namespaces = Namespaces
                                }
                            }
                        }
                    };

                    var doc = initReq.Serialize();
                    doc.Descendants(nsEbics + XmlNames.SignatureData).FirstOrDefault()
                    ?.Add(Convert.ToBase64String(userSigDataEnc));
                    return(request : AuthenticateXml(doc.ToXmlDocument(), null, null), segments : segments);
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CreateRequestException($"can't create {OrderType} init request", ex);
                }
            }
        }