I am getting an Excel file signed with EDS. You must verify the certificate. Now my check is being carried out, but for some reason the certificate that I issued to myself is also recognized as correct. It is necessary to make so that only certificates from trusted centers are tested.

СертификатПослеПроверки = Неопределено; Если ЗначениеЗаполнено(Файл) Тогда ДДФайл = Новый ДвоичныеДанные(Файл); ФФайл = Новый Файл(Файл); Попытка Врап = Новый COMОбъект("NetObjectToIDispatch45"); PackageZIP = Врап.ПолучитьТипИзСборки("System.IO.Packaging.Package","WindowsBase.dll"); package = Врап.ПолучитьТип("System.IO.Packaging.Package").Open(Файл); PackageDigitalSignatureManager = Врап.ПолучитьТипИзСборки("System.IO.Packaging.PackageDigitalSignatureManager","WindowsBase.dll"); dsm = Врап.СоздатьОбъект(PackageDigitalSignatureManager, package); Если НЕ dsm.IsSigned Тогда Сообщить("Файл " + Файл + " не содержит подписи"); КонецЕсли; Для каждого pds Из dsm.Signatures Цикл Сертификат2 = Врап.СоздатьОбъект("System.Security.Cryptography.X509Certificates.X509Certificate2", pds.Signer); Результат = dsm.VerifySignatures(true); Если Результат.Equals(Врап.ПолучитьТип("System.IO.Packaging.VerifyResult").Success) Тогда Сообщить("Проверка подписи прошла успешно"); Иначе Сообщить("Подпись не прошла проверку"); КонецЕсли; Если pds.Signer.Verify() Тогда Сообщить("Сертификат действителен"); Иначе Сообщить("Сертификат недействителен."); КонецЕсли; Результат2= PackageDigitalSignatureManager.VerifyCertificate(Сертификат2); Сообщить("Ошибки: " + Врап.Встроку(Результат2)); chain = Врап.СоздатьОбъект("System.Security.Cryptography.X509Certificates.X509Chain"); chain.ChainPolicy.ExtraStore.Add(Сертификат2);// GetYourRootCert() - Ваш корневой X509Certificate2 Если chain.Build(pds.Signer) Тогда Сообщить("сертификат загружен"); Иначе Сообщить("сертификат не загружен"); КонецЕсли; //////////////// читаем данные сертификата chain.ChainPolicy.VerificationFlags = Врап.ПолучитьТип("System.Security.Cryptography.X509Certificates.X509VerificationFlags").AllowUnknownCertificateAuthority;// AllFlags; X509VerificationFlags=Врап.ПолучитьТип("System.Security.Cryptography.X509Certificates.X509VerificationFlags"); chain.ChainPolicy.VerificationFlags =врап.OR(X509VerificationFlags.NoFlag); chain.ChainPolicy.RevocationMode = Врап.ПолучитьТип("System.Security.Cryptography.X509Certificates.X509RevocationMode").Online; chain.ChainPolicy.RevocationFlag = Врап.ПолучитьТип("System.Security.Cryptography.X509Certificates.X509RevocationFlag").EntireChain; X509ChainStatusFlags = Врап.ПолучитьТип("System.Security.Cryptography.X509Certificates.X509ChainStatusFlags"); chain.ChainPolicy.VerificationTime = pds.SigningTime; chain.ChainPolicy.UrlRetrievalTimeout = Врап.СоздатьОбъект("System.TimeSpan",0, 0, 30); String = Врап.ПолучитьТип("System.String"); Сообщить(String.Format("Chain revocation flag: {0}" , chain.ChainPolicy.RevocationFlag, 0)); Сообщить(String.Format("Chain revocation mode: {0}", chain.ChainPolicy.RevocationMode, 0)); Сообщить(String.Format("Chain verification flag: {0}", chain.ChainPolicy.VerificationFlags, 0)); Сообщить(String.Format("Chain verification time: {0}", chain.ChainPolicy.VerificationTime, 0)); Сообщить(String.Format("Chain application policy count: {0}", chain.ChainPolicy.ApplicationPolicy.Count, 0)); Сообщить(String.Format("Chain certificate policy count: {0}", chain.ChainPolicy.CertificatePolicy.Count, 0)); Если chain.Build(Сертификат2) Тогда Сообщить("сертификат загружен"); Иначе Сообщить("сертификат не загружен"); КонецЕсли; Действителен = Сертификат2.Verify(); Если Действителен Тогда Сообщить("Сертификат действителен"); Иначе Сообщить("Сертификат недействителен."); КонецЕсли; КонецЦикла; Исключение КонецПопытки; Попытка Врап.ЗакрытьРесурс(package); Исключение Сообщить("Закрыть не удалось"); КонецПопытки; КонецЕсли; 
  • Add a C # tag. From 1C nobody will help you - Serginio
  • I put C, probably the moderator deleted. I'll try again now. - Albert
  • @Albert: C and C # are completely different languages. This time. And secondly, there is not a single line of C # code in your question, so I’d remove the moderator as well. - VladD
  • @Albert: On the other hand, you seem to be using .NET libraries, but do not talk about it in the question. But your C # code in the question is still not visible. - VladD
  • @VladD: yes, I use the .NET libraries as in the infostart.ru/public/417830 example, I’ll correct the question now. I am here for the first time, so please do not judge strictly :) - Albert

1 answer 1

Processing works. The left certificate was installed on the computer in Trustees, and therefore passed the test. After deleting the certificate, everything works out as it should.