public Ticket TicketTorg(string thumbprint, string fileName) { CreateAnswerResponse response = null; try { string uuid = fileName.Split('_')[5].Replace(".xml", ""); ExCert cert = GetExCertificate(thumbprint); ExSigner signer = new ExSigner(cert); CreateAnswerRequest req = new CreateAnswerRequest(authToken, uuid, new AnswerData(signer)); response = (CreateAnswerResponse)Http2.post <CreateAnswerResponse>("https://api-service.edi.su/Api/Dixy/Ticket/Generate", req); if (response.intCode != 200) { Logger.log("for file [" + fileName + "] :" + response.varMessage); return(null); } string name = GetIDFileFromTicket(response.content); byte[] body = Utils.Base64DecodeToBytes(response.content, "windows-1251"); return(new Ticket(name, body)); } catch (Exception ex) { Logger.log("for file [" + fileName + "] :" + response.varMessage); Logger.log(ex.Message); return(null); } }
public ExCert[] GetCertificates() { CAdESCOM.CPStore store = new CAdESCOM.CPStore(); store.Open(); try { CAPICOM.ICertificates icerts = store.Certificates; ExCert[] certs = new ExCert[icerts.Count]; int i = 0; foreach (CAPICOM.Certificate cert in store.Certificates) { certs[i++] = new ExCert(cert); } return(certs); } finally { store.Close(); } }
/**/ public string GetIDFileFromTicket(string ticketContent, Event e) { if (e.soapFileName.Contains("DP_OTORG1_") || e.soapFileName.Contains("DP_OTORG2_")) { return(GetIDFileFromTicket(ticketContent, "UTF-8")); } else { return(GetIDFileFromTicket(ticketContent, "windows-1251")); } } public string GetIDFileFromTicket(string ticketContent) { return(GetIDFileFromTicket(ticketContent, "windows-1251")); } public string GetIDFileFromTicket(string ticketContent, string encoding) { try { string xmlString = Utils.Base64Decode(ticketContent, encoding); XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlString); return(xml.SelectSingleNode("/Файл[@*]/@ИдФайл").InnerText + ".xml"); } catch (Exception e) { Logger.error(e.StackTrace); throw e; } } private string authorize() { string login = conf.Login; string password = conf.Api_pass; AuthorizeResponse response; try { response = (AuthorizeResponse)Http2.post <AuthorizeResponse>("https://api-service.edi.su/Api/Dixy/Index/Authorize", new AuthorizeRequest(login, password)); return(response.varToken); } catch (Exception ex) { Logger.log("ERROR: api auth fails. Api funcs will NOT be able . Reason : " + ex.Message); return(null); } } /**/ public ExCert GetExCertificate(string thumbprint) { CAdESCOM.CPStore store = new CAdESCOM.CPStore(); store.Open(); try { CAPICOM.ICertificates icerts = store.Certificates; ExCert[] certs = new ExCert[icerts.Count]; int i = 0; foreach (CAPICOM.Certificate cert in store.Certificates) { if (cert.Thumbprint.Equals(thumbprint) && cert.HasPrivateKey()) { return(new ExCert(cert)); } } throw new Exception("No certificate was found by thumbprint [" + thumbprint + "]"); } finally { store.Close(); } }
public Program(String[] args) { Program.conf = DFSHelper.GetAppConfiguration("configuration.xml"); Logger.loadConfig(); controller = new Controller(); switch (args[0]) { case "-allcerts": // testing crypto etc. testCrypto(); break; case "-infocert": ExCert cert = null; try { cert = controller.GetExCertificate(args[1]); Console.WriteLine("certificate info:"); Console.WriteLine(cert.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } break; case "-testcert": String sign = null; String base64data = Utils.Base64DecodeToString(Encoding.GetEncoding("UTF-8").GetBytes("somedata"), "UTF-8"); try { sign = controller.Sign(args[1], base64data); if (sign != null) { Console.WriteLine("signing O.K."); } } catch (Exception e) { Console.WriteLine(e.Message); } break; case "-testrestFULLDEBUG": AuthorizeRequest debugReq = new AuthorizeRequest(conf.Login, conf.Api_pass); Console.WriteLine("request body:"); Console.WriteLine(Utils.ToJson(debugReq)); AuthorizeResponse debugResp = (AuthorizeResponse)Http2.post <AuthorizeResponse>("https://api-service.edi.su/Api/Dixy/Index/Authorize", debugReq); Console.WriteLine("response body:"); Console.WriteLine(Utils.ToJson(debugResp)); if (debugResp != null) { Console.WriteLine("rest O.K."); } break; case "-testrest": AuthorizeResponse response = (AuthorizeResponse)Http2.post <AuthorizeResponse>("https://api-service.edi.su/Api/Dixy/Index/Authorize", new AuthorizeRequest(conf.Login, conf.Api_pass)); if (response != null) { Console.WriteLine("rest O.K."); } break; case "-testsoap": GetListRequest req = new GetListRequest(); req.user = new User(); req.user.login = conf.Login; req.user.pass = Utils.GetMD5String(conf.Soap_pass); GetListResponse resp = (GetListResponse)Soap.GetList <GetListResponse>(req); if (resp != null) { Console.WriteLine("soap O.K."); } break; } }