using System; using System.IO; using System.IO.Compression; using System.Security.Cryptography; using System.Xml; using System.Xml.Serialization; using Kreta.EESZTInterface.eFT.Model.AllomanyResz.Response; using Kreta.EESZTInterface.eFT.Model.IntezmenyiAllomanyLista.Response; using Kreta.EESZTInterface.eFT.Model.SikeresCimzettAllomanyLetoltes.Response; using Kreta.EESZTInterface.STS; namespace Kreta.EESZTInterface { public class EFTHelper { private readonly string eftUrl; public EFTHelper(string eftUrl) { this.eftUrl = $"{eftUrl}/EFT/AllomanyPublikalo"; } public GetIntezmenyiAllomanyListaResponse CallIntezmenyAllomanyLista(SamlAssertion samlAssertion, string clientUserId, string organizationId) { var bo = eFT.CreateSoap.GetIntezmenyiAllomanyListaBusinessObject(samlAssertion, clientUserId, organizationId); var xDoc = eFT.CreateSoap.CreateGetIntezmenyiAllomanyLista(samlAssertion.Original, bo); var (soapResponse, _) = eFT.DoRequest.GetSoapSamlResponse(eftUrl, CertificateHelper.GetSslCertificate(), xDoc, samlAssertion); var resp = (XmlElement)(soapResponse.GetElementsByTagName("getIntezmenyiAllomanyListaResponse", Namespaces.allomanyPublikaloServiceV1Ns).Item(0)); return SerializeResponseContent(resp); } public (GetAllomanyReszResponse response, byte[] attachment) CallAllomanyResz(SamlAssertion samlAssertion, string clientUserId, string organizationId, Guid publikusId, int sorszam) { var bo = eFT.CreateSoap.GetAllomanyReszBusinessObject(samlAssertion, clientUserId, organizationId, publikusId, sorszam); var xDoc = eFT.CreateSoap.CreateGetAllomanyresz(samlAssertion.Original, bo); var (soapResponse, mTOMAttachment) = eFT.DoRequest.GetSoapSamlResponse(eftUrl, CertificateHelper.GetSslCertificate(), xDoc, samlAssertion); var resp = (XmlElement)(soapResponse.GetElementsByTagName("getAllomanyReszResponse", Namespaces.allomanyPublikaloServiceV1Ns).Item(0)); return (SerializeResponseContent(resp), mTOMAttachment); } public SikeresCimzettAllomanyLetoltesResponse CallSikeresAllomanyLetoltes(SamlAssertion samlAssertion, string clientUserId, string organizationId, Guid publikusId) { var bo = eFT.CreateSoap.GetSikeresCimzettAllomanyLetoltesBO(samlAssertion, clientUserId, organizationId, publikusId); var xDoc = eFT.CreateSoap.CreateSikeresLetoltes(samlAssertion.Original, bo); var (soapResponse, _) = eFT.DoRequest.GetSoapSamlResponse(eftUrl, CertificateHelper.GetSslCertificate(), xDoc, samlAssertion); var resp = (XmlElement)(soapResponse.GetElementsByTagName("sikeresCimzettAllomanyLetoltesResponse", Namespaces.allomanyPublikaloServiceV1Ns).Item(0)); return SerializeResponseContent(resp); } private T SerializeResponseContent(XmlElement element) { var serializer = new XmlSerializer(typeof(T)); using (TextReader reader = new StringReader(element.OuterXml)) { return (T)serializer.Deserialize(reader); } } public static byte[] ComputeSha256Hash(byte[] reszadat) { using (var sha256Hash = SHA256.Create()) { return sha256Hash.ComputeHash(reszadat); } } public static byte[] Decompress(byte[] input) { using (var source = new MemoryStream(input)) { byte[] lengthBytes = new byte[4]; source.Read(lengthBytes, 0, 4); var length = BitConverter.ToInt32(lengthBytes, 0); using (var decompressionStream = new GZipStream(source, CompressionMode.Decompress)) { var result = new byte[length]; decompressionStream.Read(result, 0, length); return result; } } } } }