private void ButtonGetInfo_Click(object sender, RoutedEventArgs e) { object userCertSubjectName = ListBoxUserCerts.SelectedItem; object fssCertSubjectName = ListBoxFssCerts.SelectedItem; if (userCertSubjectName == null || fssCertSubjectName == null) { MessageBox.Show(this, "Необходимо выбрать сертификаты для продолжения", "", MessageBoxButton.OK, MessageBoxImage.Information); return; } DateTime dateBegin = DatePickerBegin.SelectedDate.Value.Date; DateTime dateEnd = DatePickerEnd.SelectedDate.Value.Date; if (dateBegin > dateEnd) { MessageBox.Show(this, "Дата начала выбранного периода не может быть больше даты окончания", "", MessageBoxButton.OK, MessageBoxImage.Information); return; } X509Certificate2 userCert = CryptoTools.GetCertificate( (StoreLocation)ComboBoxUserCertStoreLocation.SelectedItem, (StoreName)ComboBoxUserCertStoreName.SelectedItem, (string)userCertSubjectName); X509Certificate2 fssCert = CryptoTools.GetCertificate( (StoreLocation)ComboBoxFssCertStoreLocation.SelectedItem, (StoreName)ComboBoxFssCertStoreName.SelectedItem, (string)fssCertSubjectName); WsdlServiceHandle.Instance.Initialize( dateBegin, dateEnd, userCert, fssCert); WindowFssList windowFssList = new WindowFssList(); windowFssList.Owner = this; windowFssList.ShowDialog(); }
public void AfterReceiveReply(ref Message reply, object correlationState) { string messageRef = MessageString(ref reply); string response = CryptoTools.DecryptXml(messageRef, WsdlServiceHandle.userCert).Replace("ns1:", "").Replace(":ns1", ""); if (response.Contains("getLNListByDateResponse")) { WsdlServiceHandle.Instance.ParseGetLNListByDateResponse(response); } else if (response.Contains("getLNDataResponse")) { WsdlServiceHandle.Instance.ParseGetLnDataResponse(response); } reply = CreateMessageFromString(response, reply.Version); }
private void ComboBoxFssCert_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBoxFssCerts.Items.Clear(); object location = ComboBoxFssCertStoreLocation.SelectedItem; object name = ComboBoxFssCertStoreName.SelectedItem; if (location == null || name == null) { return; } foreach (string str in CryptoTools.GetStoreSertificatesList((StoreLocation)location, (StoreName)name)) { ListBoxFssCerts.Items.Add(str); } }
static private X509Certificate2 GetCertificate(bool isUserCertificate) { string storeLocation; string storeName; string subjectDN; if (isUserCertificate) { storeLocation = Properties.Settings.Default.CertificateUserStoreLocation; storeName = Properties.Settings.Default.CertificateUserStoreName; subjectDN = Properties.Settings.Default.CertificateUserSubjectDN; } else { storeLocation = Properties.Settings.Default.CertificateFssStoreLocation; storeName = Properties.Settings.Default.CertificateFssStoreName; subjectDN = Properties.Settings.Default.CertificateFssSubjectDN; } bool isStoreLocationOK = Enum.TryParse(storeLocation, out StoreLocation storeLocationEnum); if (!isStoreLocationOK) { Logging.ToLog("!!! Не удалось определить расположение хранилища для параметра: " + storeLocation); return(null); } bool isStoreNameOK = Enum.TryParse(storeName, out StoreName storeNameEnum); if (!isStoreNameOK) { Logging.ToLog("!!! Не удалось определить имя хранилища для параметра: " + storeName); return(null); } try { return(CryptoTools.GetCertificate(storeLocationEnum, storeNameEnum, subjectDN)); } catch (Exception e) { Logging.ToLog("!!! Не удалось найти сертификат: " + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace); return(null); } }
public object BeforeSendRequest(ref Message request, IClientChannel channel) { string messageRef = MessageString(ref request); XmlDocument docRequest = new XmlDocument(); docRequest.LoadXml(messageRef); WsdlServiceHandle.RequestType type; DateTime?dateTime = null; string lnNum = string.Empty; string lnSnils = string.Empty; if (messageRef.Contains("getLNListByDate")) { type = WsdlServiceHandle.RequestType.GetLnListByDate; XmlNodeList nodeDate = docRequest.GetElementsByTagName("date"); if (nodeDate != null && nodeDate.Count == 1) { dateTime = DateTime.Parse(nodeDate[0].InnerText); } } else if (messageRef.Contains("getLNData")) { type = WsdlServiceHandle.RequestType.GetLnData; XmlNodeList nodeLnCode = docRequest.GetElementsByTagName("lnCode"); if (nodeLnCode != null && nodeLnCode.Count == 1) { lnNum = nodeLnCode[0].InnerText; } XmlNodeList nodeLnSnils = docRequest.GetElementsByTagName("snils"); if (nodeLnSnils != null && nodeLnCode.Count == 1) { lnSnils = nodeLnSnils[0].InnerText; } } else { throw new Exception("Неподдерживаемый тип запроса"); } XmlDocument docCustomSigned = WsdlServiceHandle.GetSignedRequestXml(type, dateTime, lnNum, lnSnils); XmlDocument docCustomEncrypted = CryptoTools.EncryptionXML(docCustomSigned, WsdlServiceHandle.fssCert, WsdlServiceHandle.userCert); request = CreateMessageFromString(docCustomEncrypted.OuterXml, request.Version); //var _url = "https://docs.fss.ru/WSLnCryptoV11/FileOperationsLnPort?WSDL"; //var _action = "http://ru/ibs/fss/ln/ws/FileOperationsLn.wsdl/getLNListByDate"; ////XmlDocument soapEnvelopeXml = CreateSoapEnvelope(); //HttpWebRequest webRequest = CreateWebRequest(_url, _action); //InsertSoapEnvelopeIntoWebRequest(docCustomEncrypted, webRequest); //// begin async call to web request. //IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null); //// suspend this thread until call is complete. You might want to //// do something usefull here like update your UI. //asyncResult.AsyncWaitHandle.WaitOne(); //// get the response from the completed web request. //string soapResult; //using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) { // using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) { // soapResult = rd.ReadToEnd(); // } // Console.Write(soapResult); //} return(request); }
public static XmlDocument GetSignedRequestXml(RequestType type, DateTime?dateTime = null, string lnNum = "", string lnSnils = "") { XmlDocument doc = new XmlDocument(); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("soapenv", xmlns_soapenv); ns.AddNamespace("ds", xmlns_ds); ns.AddNamespace("wsse", xmlns_wsse); ns.AddNamespace("wsu", xmlns_xsd); ns.AddNamespace("xsd", xmlns_xsd); ns.AddNamespace("xsi", xmlns_xsi); string xmlTemplate; if (type == RequestType.GetLnListByDate) { xmlTemplate = templateSoapMessageGetLnListByDate; } else { xmlTemplate = templateSoapMessageGetLnData; } doc.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(xmlTemplate))); XmlNodeList ogrnNode = doc.GetElementsByTagName("ogrn", wsdl); if (ogrnNode != null && ogrnNode.Count == 1) { ogrnNode[0].InnerText = ogrn; } if (type == RequestType.GetLnListByDate) { XmlNodeList date = doc.GetElementsByTagName("date", wsdl); if (date != null && date.Count == 1) { date[0].InnerText = dateTime.Value.ToString("yyyy-MM-dd"); } } else { XmlNodeList lnCode = doc.GetElementsByTagName("lnCode", wsdl); if (lnCode != null && lnCode.Count == 1) { lnCode[0].InnerText = lnNum; } XmlNodeList snils = doc.GetElementsByTagName("snils", wsdl); if (snils != null && snils.Count == 1) { snils[0].InnerText = lnSnils; } } XmlNodeList bodyNode = doc.GetElementsByTagName("Body", xmlns_soapenv); if (bodyNode != null && bodyNode.Count == 1) { XmlElement body = bodyNode[0] as XmlElement; body.SetAttribute("xmlns:wsu", xmlns_wsu); body.SetAttribute("Id", xmlns_wsu, $"OGRN_{ogrn}"); CryptoTools.GenerateSecurity(doc, userCert, "OGRN", ogrn); } return(doc); }