public void Download_source() { var testProduct = new TestProduct("Тестовый продукт"); session.Save(testProduct); var product = Product.Find(testProduct.Id); var source = new KatrenSource(); var certificateSource = new CertificateSource(); certificateSource.SourceClassName = source.GetType().Name; session.Save(certificateSource); var line = new DocumentLine { ProductEntity = product, SerialNumber = "012011", }; var sourceCatalog = new CertificateSourceCatalog { CertificateSource = certificateSource, SerialNumber = line.SerialNumber, CatalogProduct = product.CatalogProduct, SupplierCode = "34266440", SupplierProducerCode = "13483667", OriginFilePath = KatrenSource.ToOriginFileName(0x1B9EFC8), }; session.Save(sourceCatalog); var task = new CertificateTask(certificateSource, line); var files = source.GetCertificateFiles(task, null); Assert.That(files.Count, Is.EqualTo(4)); }
/// <exception cref="System.IO.IOException"></exception> public virtual ValidationContext ValidateCertificate(X509Certificate cert, DateTime validationDate, CertificateSource optionalCertificateSource, ICrlSource optionalCRLSource , IOcspSource optionalOCSPSource) { if (cert == null || validationDate == null) { throw new ArgumentNullException("A validation context must contains a cert and a validation date" ); } ValidationContext previous = validationContextThreadLocal.Value; if (previous != null && previous.GetCertificate().Equals(cert) && previous.GetValidationDate ().Equals(validationDate)) { //LOG.Info("We don't need to check twice for the same"); return(previous); } ValidationContext context = new ValidationContext(cert, validationDate); context.SetCrlSource(CrlSource); context.SetOcspSource(OcspSource); context.SetTrustedListCertificatesSource(TrustedListCertificatesSource); context.Validate(validationDate, optionalCertificateSource, optionalCRLSource, optionalOCSPSource ); validationContextThreadLocal.Value = context; return(context); }
public static X509Certificate2 GetCertificate(CertificateSource source, string value) { ArgCheck.NotNullOrDefault(nameof(source), source); ArgCheck.NotNullOrEmpty(nameof(value), value); if (source == CertificateSource.FileName) { var fileName = value; if (!File.Exists(fileName)) { throw new ArgumentException($"Certificate at {fileName} not found.", nameof(fileName)); } return(new X509Certificate2(fileName)); } if (source == CertificateSource.Thumbprint) { var thumbprint = value; using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser)) { store.Open(OpenFlags.ReadOnly); var certs = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); if (certs.Count == 0) { throw new ArgumentException($"Certificate with thumbprint {thumbprint} not found.", nameof(thumbprint)); } return(certs[0]); } } throw new ArgumentOutOfRangeException(nameof(source), $"Parameter {nameof(source)} is not a valid value."); }
public void TestLoadAllCertificates( CertificateSource certificateSource, string container, string referenceOrValue) { List <CertificateDescription> certDescriptions = CreateCertificateDescriptions( certificateSource, container, referenceOrValue).ToList(); certDescriptions.Add(new CertificateDescription { SourceType = certificateSource, Container = container, ReferenceOrValue = referenceOrValue, }); certDescriptions.Add(CertificateDescription.FromCertificate(null)); IEnumerable <X509Certificate2> certificates = DefaultCertificateLoader.LoadAllCertificates(certDescriptions); Assert.NotNull(certificates); Assert.Equal(2, certificates.Count()); Assert.Equal(3, certDescriptions.Count); Assert.Equal("CN=ACS2ClientCertificate", certificates.First().Issuer); Assert.Equal("CN=ACS2ClientCertificate", certificates.Last().Issuer); Assert.Null(certDescriptions.ElementAt(2).Certificate); }
private void UpdateInputFileProperties(ReadDesigner designer, IFunctionData data) { designer.Properties[PropertyNames.PdfFilePath].Value = data.Properties["Pdf filename"].Value; AuthenticationType authenticationType = data.Properties["Authentication type"].GetValue <AuthenticationType>(); designer.Properties[PropertyNames.AuthenticationType].Value = authenticationType; switch (authenticationType) { case AuthenticationType.Password: designer.Properties[PropertyNames.PdfPassword].Value = data.Properties["Pdf password"].Value; break; case AuthenticationType.Certificate: CertificateSource certificateSource = data.Properties["Certificate source"].GetValue <CertificateSource>(); designer.Properties[PropertyNames.CertificateSource].Value = certificateSource; switch (certificateSource) { case CertificateSource.File: designer.Properties[PropertyNames.CertificateFilePath].Value = data.Properties["Certificate file path"].Value; designer.Properties[PropertyNames.CertificateFilePassword].Value = data.Properties["Certificate file password"].Value; break; case CertificateSource.Store: designer.Properties[PropertyNames.Certificate].Value = data.Properties["Certificate"].Value; break; } break; } }
/// <summary>Validate the timestamp</summary> /// <param name="timestamp"></param> /// <param name="optionalSource"></param> /// <param name="optionalCRLSource"></param> /// <param name="optionalOCPSSource"></param> /// <exception cref="System.IO.IOException"></exception> public virtual void ValidateTimestamp(TimestampToken timestamp, CertificateSource optionalSource, ICrlSource optionalCRLSource, IOcspSource optionalOCPSSource) { AddNotYetVerifiedToken(timestamp); Validate(timestamp.GetTimeStamp().TimeStampInfo.GenTime, new CompositeCertificateSource (timestamp.GetWrappedCertificateSource(), optionalSource), optionalCRLSource, optionalOCPSSource ); }
/// <exception cref="System.IO.IOException"></exception> //private IDictionary<DerObjectIdentifier, Asn1Encodable> ExtendUnsignedAttributes(IDictionary // <DerObjectIdentifier, Asn1Encodable> unsignedAttrs, X509Certificate signingCertificate // , DateTime signingDate, CertificateSource optionalCertificateSource) private IDictionary ExtendUnsignedAttributes(IDictionary unsignedAttrs , X509Certificate signingCertificate, DateTime signingDate , CertificateSource optionalCertificateSource) { ValidationContext validationContext = certificateVerifier.ValidateCertificate(signingCertificate , signingDate, optionalCertificateSource, null, null); try { IList <X509CertificateStructure> certificateValues = new AList <X509CertificateStructure >(); AList <CertificateList> crlValues = new AList <CertificateList>(); AList <BasicOcspResponse> ocspValues = new AList <BasicOcspResponse>(); foreach (CertificateAndContext c in validationContext.GetNeededCertificates()) { if (!c.Equals(signingCertificate)) { certificateValues.AddItem(X509CertificateStructure.GetInstance(((Asn1Sequence)Asn1Object.FromByteArray (c.GetCertificate().GetEncoded())))); } } foreach (X509Crl relatedcrl in validationContext.GetNeededCRL()) { crlValues.AddItem(CertificateList.GetInstance((Asn1Sequence)Asn1Object.FromByteArray(((X509Crl )relatedcrl).GetEncoded()))); } foreach (BasicOcspResp relatedocspresp in validationContext.GetNeededOCSPResp()) { ocspValues.AddItem((BasicOcspResponse.GetInstance((Asn1Sequence)Asn1Object.FromByteArray( relatedocspresp.GetEncoded())))); } CertificateList[] crlValuesArray = new CertificateList[crlValues.Count]; BasicOcspResponse[] ocspValuesArray = new BasicOcspResponse[ocspValues.Count]; RevocationValues revocationValues = new RevocationValues(Sharpen.Collections.ToArray (crlValues, crlValuesArray), Sharpen.Collections.ToArray(ocspValues, ocspValuesArray ), null); //unsignedAttrs.Put(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new Attribute unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new BcCms.Attribute (PkcsObjectIdentifiers.IdAAEtsRevocationValues, new DerSet(revocationValues)) ); X509CertificateStructure[] certValuesArray = new X509CertificateStructure[certificateValues .Count]; //unsignedAttrs.Put(PkcsObjectIdentifiers.IdAAEtsCertValues, new Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(Sharpen.Collections.ToArray(certificateValues unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsCertValues, new BcCms.Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(Sharpen.Collections.ToArray(certificateValues , certValuesArray))))); } catch (CertificateEncodingException e) { throw new RuntimeException(e); } catch (CrlException e) { throw new RuntimeException(e); } return(unsignedAttrs); }
private AuthenticationType UpdateProtectProtectionProperties(PdfOperationsDesigner designer, IFunctionData data) { #pragma warning disable 618 Obsolete.Protection oldProtection = data.Properties["Output pdf protection"].GetValue <Obsolete.Protection>(); AuthenticationType newAuthenticationType = 0; switch (oldProtection) { case Obsolete.Protection.None: newAuthenticationType = AuthenticationType.None; break; case Obsolete.Protection.Password: newAuthenticationType = AuthenticationType.Password; break; case Obsolete.Protection.Certificate: newAuthenticationType = AuthenticationType.Certificate; break; } #pragma warning restore 618 designer.Properties[PropertyNames.ProtectProtection].Value = newAuthenticationType; switch (newAuthenticationType) { case AuthenticationType.Password: bool addDocumentRestrictions = data.Properties["Allow user access"].GetValue <bool>(); if (addDocumentRestrictions) { designer.Properties[PropertyNames.ProtectDocumentOpenPassword].Value = data.Properties["User password"].Value; } else { designer.Properties[PropertyNames.ProtectDocumentOpenPassword].Value = data.Properties["Owner password"].Value; } break; case AuthenticationType.Certificate: CertificateSource certificateSource = data.Properties["Certificate source"].GetValue <CertificateSource>(); designer.Properties[PropertyNames.ProtectCertificateSource].Value = certificateSource; switch (certificateSource) { case CertificateSource.File: designer.Properties[PropertyNames.ProtectCertificateFilePath].Value = data.Properties["Certificate file path"].Value; designer.Properties[PropertyNames.ProtectCertificateFilePassword].Value = data.Properties["Certificate file password"].Value; break; case CertificateSource.Store: designer.Properties[PropertyNames.ProtectCertificate].Value = data.Properties["Certificate"].Value; break; } break; } return(newAuthenticationType); }
/// <exception cref="System.IO.IOException"></exception> //private IDictionary<DerObjectIdentifier, Asn1Encodable> ExtendUnsignedAttributes(IDictionary // <DerObjectIdentifier, Asn1Encodable> unsignedAttrs, X509Certificate signingCertificate // , DateTime signingDate, CertificateSource optionalCertificateSource) private IDictionary ExtendUnsignedAttributes(IDictionary unsignedAttrs , X509Certificate signingCertificate, DateTime signingDate , CertificateSource optionalCertificateSource) { ValidationContext validationContext = certificateVerifier.ValidateCertificate(signingCertificate , signingDate, optionalCertificateSource, null, null); try { IList<X509CertificateStructure> certificateValues = new AList<X509CertificateStructure >(); AList<CertificateList> crlValues = new AList<CertificateList>(); AList<BasicOcspResponse> ocspValues = new AList<BasicOcspResponse>(); foreach (CertificateAndContext c in validationContext.GetNeededCertificates()) { if (!c.Equals(signingCertificate)) { certificateValues.AddItem(X509CertificateStructure.GetInstance(((Asn1Sequence)Asn1Object.FromByteArray (c.GetCertificate().GetEncoded())))); } } foreach (X509Crl relatedcrl in validationContext.GetNeededCRL()) { crlValues.AddItem(CertificateList.GetInstance((Asn1Sequence)Asn1Object.FromByteArray(((X509Crl )relatedcrl).GetEncoded()))); } foreach (BasicOcspResp relatedocspresp in validationContext.GetNeededOCSPResp()) { ocspValues.AddItem((BasicOcspResponse.GetInstance((Asn1Sequence)Asn1Object.FromByteArray( relatedocspresp.GetEncoded())))); } CertificateList[] crlValuesArray = new CertificateList[crlValues.Count]; BasicOcspResponse[] ocspValuesArray = new BasicOcspResponse[ocspValues.Count]; RevocationValues revocationValues = new RevocationValues(Sharpen.Collections.ToArray (crlValues, crlValuesArray), Sharpen.Collections.ToArray(ocspValues, ocspValuesArray ), null); //unsignedAttrs.Put(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new Attribute unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsRevocationValues, new BcCms.Attribute (PkcsObjectIdentifiers.IdAAEtsRevocationValues, new DerSet(revocationValues)) ); X509CertificateStructure[] certValuesArray = new X509CertificateStructure[certificateValues .Count]; //unsignedAttrs.Put(PkcsObjectIdentifiers.IdAAEtsCertValues, new Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(Sharpen.Collections.ToArray(certificateValues unsignedAttrs.Add(PkcsObjectIdentifiers.IdAAEtsCertValues, new BcCms.Attribute(PkcsObjectIdentifiers.IdAAEtsCertValues, new DerSet(new DerSequence(Sharpen.Collections.ToArray(certificateValues , certValuesArray))))); } catch (CertificateEncodingException e) { throw new RuntimeException(e); } catch (CrlException e) { throw new RuntimeException(e); } return unsignedAttrs; }
private static void CreateFiles(CertificateSource certificateSource, Certificate certificate, int count) { for (var i = 0; i < count; i++) { certificate.NewFile( new CertificateFile { OriginFilename = Path.GetRandomFileName(), CertificateSource = certificateSource, Extension = ".tif" }); } }
public void Get_local_file() { using (var cleaner = new FileCleaner()) { var tmpFile = cleaner.TmpFile(); var fileInfo = new FileInfo(tmpFile); fileInfo.LastWriteTime = DateTime.Now.AddDays(1); var source = new CertificateSource { DecodeTableUrl = new Uri(fileInfo.FullName).ToString() }; var file = handler.GetCatalogFile(source, cleaner); Assert.IsNotNull(file); } }
/// <summary>An X509Certificate may contain information about his issuer in the AIA attribute. /// </summary> /// <remarks>An X509Certificate may contain information about his issuer in the AIA attribute. /// </remarks> public virtual CertificateSource GetWrappedCertificateSource() { if (sourceFactory != null) { CertificateSource source = sourceFactory.CreateAIACertificateSource(GetCertificate ()); return(source); } else { return(null); } }
public void SetUp() { session.DeleteEach <CertificateSource>(); _supplier = TestSupplier.CreateNaked(session); _source = new CertificateSource(); _source.SourceClassName = ""; _source.Suppliers.Add(session.Load <Supplier>(_supplier.Id)); session.Save(_source); handler = new CertificateCatalogHandler(); handler.CreateDownHandlerPath(); }
private static Certificate CreateCertificateWithFiles(CertificateSource certificateSource, TestCatalogProduct catalog, string serialNumber) { var certificate = new Certificate(); using (new TransactionScope()) { certificate.CatalogProduct = Catalog.Find(catalog.Id); certificate.SerialNumber = serialNumber; CreateFiles(certificateSource, certificate, 2); certificate.Save(); } return(certificate); }
public static void InitializeCertificateProperties( this PropertyCollection properties, string certificateSourcePropertyName, string certificateFilePathPropertyName, string certificateFilePasswordPropertyName, string certificatePropertyName, ref int propertyOrder, VisibleDependency visibleDependency) { Action <bool> applyVisibility = (isVisible) => { CertificateSource certificateSourceValue = properties[certificateSourcePropertyName].GetValue <CertificateSource>(); properties[certificateSourcePropertyName].IsVisible = isVisible; properties[certificateFilePathPropertyName].IsVisible = (isVisible && certificateSourceValue == CertificateSource.File); properties[certificateFilePasswordPropertyName].IsVisible = (isVisible && certificateSourceValue == CertificateSource.File); properties[certificatePropertyName].IsVisible = (isVisible && certificateSourceValue == CertificateSource.Store); }; EventHandler updateVisibility = (sender, args) => applyVisibility(visibleDependency.Visible); visibleDependency.VisibleChanged += (visible) => applyVisibility(visible); Property certificateSource = properties.AddOrRetrieve(certificateSourcePropertyName, typeof(CertificateSource), ValueUseOption.DesignTime, CertificateSource.File); certificateSource.Order = propertyOrder++; certificateSource.Description = "Source to load the certificate from."; certificateSource.ValueChanged += updateVisibility; Property certificateFilePath = properties.AddOrRetrieve(certificateFilePathPropertyName, typeof(string), ValueUseOption.RuntimeRead, string.Empty); certificateFilePath.Order = propertyOrder++; certificateFilePath.Description = "Path to the file containing a certificate."; certificateFilePath.Editor = typeof(FilePathEditor); certificateFilePath.Validations.Add(new RequiredValidator()); Property certificateFilePassword = properties.AddOrRetrieve(certificateFilePasswordPropertyName, typeof(string), ValueUseOption.RuntimeRead, string.Empty); certificateFilePassword.Order = propertyOrder++; certificateFilePassword.Description = "Password required to open the certificate file."; Property certificate = properties.AddOrRetrieve(certificatePropertyName, typeof(StoredCertificate), ValueUseOption.DesignTime, new StoredCertificate()); certificate.Order = propertyOrder++; certificate.Description = "Certificate in the windows keystore."; certificate.Validations.Add(new StoredCertificateValidator()); certificate.Editor = typeof(CertificateEditor); applyVisibility(visibleDependency.Visible); }
public void TestLoadFirstCertificate( CertificateSource certificateSource, string container, string referenceOrValue) { IEnumerable <CertificateDescription> certDescriptions = CreateCertificateDescriptions( certificateSource, container, referenceOrValue); X509Certificate2 certificate = DefaultCertificateLoader.LoadFirstCertificate(certDescriptions); Assert.NotNull(certificate); Assert.Equal("CN=ACS2ClientCertificate", certificate.Issuer); }
private IEnumerable <CertificateDescription> CreateCertificateDescriptions( CertificateSource certificateSource, string container, string referenceOrValue) { List <CertificateDescription> certificateDescription = new List <CertificateDescription>(); certificateDescription.Add(new CertificateDescription { SourceType = certificateSource, Container = container, ReferenceOrValue = referenceOrValue, }); return(certificateDescription); }
public void TestDefaultCertificateLoader(CertificateSource certificateSource, string container, string referenceOrValue) { CertificateDescription certificateDescription; switch (certificateSource) { case CertificateSource.KeyVault: certificateDescription = CertificateDescription.FromKeyVault(container, referenceOrValue); break; case CertificateSource.Base64Encoded: certificateDescription = CertificateDescription.FromBase64Encoded(referenceOrValue); break; case CertificateSource.Path: certificateDescription = CertificateDescription.FromPath(container, referenceOrValue); break; case CertificateSource.StoreWithThumbprint: certificateDescription = new CertificateDescription() { SourceType = CertificateSource.StoreWithThumbprint }; certificateDescription.CertificateThumbprint = referenceOrValue; certificateDescription.CertificateStorePath = container; break; case CertificateSource.StoreWithDistinguishedName: certificateDescription = new CertificateDescription() { SourceType = CertificateSource.StoreWithDistinguishedName }; certificateDescription.CertificateDistinguishedName = referenceOrValue; certificateDescription.CertificateStorePath = container; break; default: certificateDescription = null; break; } ICertificateLoader loader = new DefaultCertificateLoader(); loader.LoadIfNeeded(certificateDescription); Assert.NotNull(certificateDescription.Certificate); }
public void SetUp() { var supplier = TestSupplier.Create(); var realSupplier = Supplier.Find(supplier.Id); using (new TransactionScope()) { var certificateSources = CertificateSource.Queryable.Where(s => s.SourceClassName == typeof(RostaCertificateSource).Name).ToList(); certificateSources.ForEach(c => c.Delete()); _source = new CertificateSource { SourceClassName = typeof(RostaCertificateSource).Name }; _source.Suppliers = new List <Supplier>(); _source.Suppliers.Add(realSupplier); _source.Save(); } }
private void UpdateSignCertificateProperties(PdfOperationsDesigner designer, IFunctionData data) { CertificateSource certificateSource = data.Properties["Signing certificate source"].GetValue <CertificateSource>(); designer.Properties[PropertyNames.SignCertificateSource].Value = certificateSource; switch (certificateSource) { case CertificateSource.File: designer.Properties[PropertyNames.SignCertificateFilePath].Value = data.Properties["Signing certificate file path"].Value; designer.Properties[PropertyNames.SignCertificateFilePassword].Value = data.Properties["Signing certificate file password"].Value; break; case CertificateSource.Store: designer.Properties[PropertyNames.SignCertificate].Value = data.Properties["Signing certificate"].Value; break; } }
private CertificateSource CreateSourceForSupplier() { var source = CertificateSource.Queryable.FirstOrDefault(s => s.Suppliers.FirstOrDefault(certificateSupplier => certificateSupplier.Id == supplier.Id) != null); if (source == null) { using (new TransactionScope()) { source = new CertificateSource { SourceClassName = Path.GetRandomFileName() }; source.Suppliers = new List <Supplier>(); source.Suppliers.Add(supplier); source.Save(); } } return(source); }
public static DomainCertificate FromX509Certificate2(X509Certificate2 cert, CertificateSource source) { if (cert == null) { return(null); } var publicPortion = cert.Export(X509ContentType.Cert); var rawData = Convert.ToBase64String(publicPortion); var serial = cert.GetSerialNumberString(); var thumb = cert.GetCertHashString(); var issuer = cert.GetNameInfo(X509NameType.DnsName, true); var subject = cert.GetNameInfo(X509NameType.DnsName, false); if (string.IsNullOrWhiteSpace(issuer)) { issuer = cert.Issuer; } if (string.IsNullOrWhiteSpace(subject)) { if (cert.Subject.StartsWith("CN=")) { subject = cert.Subject.Substring(3); } else { subject = cert.Subject; } } var domain = DomainParser.RegistrableDomain(subject); var domainCert = new DomainCertificate { DateCreated = DateTime.UtcNow, Subject = subject, RegistrableDomain = domain, IssuerName = issuer, RawData = rawData, CertificateSource = source, SerialNumber = serial, Thumbprint = thumb, ValidNotAfter = cert.NotAfter, ValidNotBefore = cert.NotBefore }; return(domainCert); }
public ClientCertificateCredentialsFromFile(CertificateSource certificateSource, string certificateLocation) { if (!Enum.IsDefined(typeof(CertificateSource), certificateSource)) { throw new ArgumentOutOfRangeException(nameof(certificateSource), $"{nameof(certificateSource)} contained an unexpected value."); } if (string.IsNullOrWhiteSpace(certificateLocation)) { throw new ArgumentNullException(nameof(certificateLocation)); } _certificateSource = certificateSource; _certificateLocation = certificateLocation; ClientCertificate.Certificate = certificateSource == CertificateSource.EmbeddedResource ? GetCertificateFromEmbeddedResource(certificateLocation) : GetCertificateFromDisk(certificateLocation); }
public void Set_sertificate_source() { var newCertificate = new CertificateSource { Name = "Test_Source", SourceClassName = "Test_class_Name" }; session.Save(newCertificate); Open(supplier); Css("#editChangerButton").Click(); Css("select[name='sertificateSourceId']").SelectByValue(newCertificate.Id.ToString()); Css("#saveCertificateSourceButton").Click(); AssertText("Сохранено"); session.Refresh(supplier); Assert.That(supplier.GetSertificateSource().Name, Is.StringContaining("Test_Source")); session.Delete(newCertificate); }
public void SetUp() { _testSupplier = TestSupplier.Create(); _realSupplier = session.Query <Supplier>().FirstOrDefault(s => s.Id == _testSupplier.Id); var certificateSources = session.Query <CertificateSource>().Where(s => s.SourceClassName == typeof(RostaCertificateSource).Name).ToList(); certificateSources.ForEach(c => session.Delete(c)); _source = new CertificateSource { SourceClassName = typeof(RostaCertificateSource).Name }; _source.Suppliers = new List <Supplier>(); _source.Suppliers.Add(_realSupplier); session.Save(_source); _testUser = TestClient.Create().Users[0]; }
private CertificateSource CreateSourceForSupplier(Supplier supplier, string sourceClassName) { var source = new CertificateSource { SourceClassName = sourceClassName }; var deletedSource = CertificateSource.Queryable.FirstOrDefault(s => s.SourceClassName == sourceClassName); if (deletedSource != null) { deletedSource.Delete(); } source.Suppliers = new List <Supplier>(); source.Suppliers.Add(supplier); source.Save(); return(source); }
public void Load_file_without_dir() { FTP_Server server = null; try { server = new FTP_Server(); var port = new Random().Next(10000, 20000); server.BindInfo = new[] { new BindInfo(BindInfoProtocol.TCP, IPAddress.Loopback, port), }; server.StartServer(); var testProduct = new TestProduct("Тестовый продукт"); session.Save(testProduct); var product = session.Load <Product>(testProduct.Id); var line = new DocumentLine { ProductEntity = product, SerialNumber = "012011", }; var source = new KatrenSource(); var certificateSource = new CertificateSource(); certificateSource.SourceClassName = source.GetType().Name; session.Save(certificateSource); var sourceCatalog = new CertificateSourceCatalog { CertificateSource = certificateSource, SerialNumber = line.SerialNumber, CatalogProduct = product.CatalogProduct, SupplierCode = "34266440", SupplierProducerCode = "13483667", OriginFilePath = KatrenSource.ToOriginFileName(0x1B9EFC8), }; session.Save(sourceCatalog); certificateSource.LookupUrl = String.Format("ftp://127.0.0.1:{0}/", port); source.GetFilesFromSource(new CertificateTask(certificateSource, line), new List <CertificateFile>()); } finally { if (server != null) { server.Dispose(); } } }
#pragma warning restore 618 private void UpdateInputFileProperties(PdfOperationsDesigner designer, IFunctionData data, string propertyPrefix, string filePathPropertyName, string authenticationTypePropertyName, string passwordPropertyName, string certificateSourcePropertyName, string certificateFilePathPropertyName, string certificateFilePasswordPropertyName, string certificatePropertyName) { Func <string, string> addPrefix = (value) => (string.IsNullOrEmpty(propertyPrefix)) ? value : propertyPrefix + " " + char.ToLower(value[0]) + value.Substring(1); designer.Properties[filePathPropertyName].Value = data.Properties[addPrefix("Pdf filename")].Value; AuthenticationType authenticationType = data.Properties[addPrefix("Authentication type")].GetValue <AuthenticationType>(); designer.Properties[authenticationTypePropertyName].Value = authenticationType; switch (authenticationType) { case AuthenticationType.Password: designer.Properties[passwordPropertyName].Value = data.Properties[addPrefix("Pdf password")].Value; break; case AuthenticationType.Certificate: CertificateSource certificateSource = data.Properties[addPrefix("Certificate source")].GetValue <CertificateSource>(); designer.Properties[certificateSourcePropertyName].Value = certificateSource; switch (certificateSource) { case CertificateSource.File: designer.Properties[certificateFilePathPropertyName].Value = data.Properties[addPrefix("Certificate file path")].Value; designer.Properties[certificateFilePasswordPropertyName].Value = data.Properties[addPrefix("Certificate file password")].Value; break; case CertificateSource.Store: designer.Properties[certificatePropertyName].Value = data.Properties[addPrefix("Certificate")].Value; break; } break; } }
public void Load_certificates() { var source = new NadezhdaFarmCertificateSource(); var line = new DocumentLine { ProductEntity = new Product(), CertificateFilename = "1473052_1_1.tif;1072321_1_0.tif;" }; var sourceConfig = new CertificateSource { FtpSupplier = new Supplier { Id = 1 } }; var task = new CertificateTask(sourceConfig, line); TestHelper.InitFiles(task.GetLocalPath(), new[] { "1473052_1_1.tif" }); Assert.IsTrue(source.CertificateExists(line)); var files = new List <CertificateFile>(); source.GetFilesFromSource(task, files); Assert.AreEqual(1, files.Count, task.DocumentLine.CertificateError); }
public virtual CertificateCatalogFile GetCatalogFile(CertificateSource source, FileCleaner cleaner) { var downloader = new FtpDownloader(); var uri = new Uri(source.DecodeTableUrl); if (uri.Scheme.Match("ftp")) { var downloadFiles = downloader.DownloadedFiles(uri, source.LastDecodeTableDownload.HasValue ? source.LastDecodeTableDownload.Value : DateTime.MinValue, DownHandlerPath); if (downloadFiles.Count > 0) { return(new CertificateCatalogFile(source, downloadFiles[0].FileDate, downloadFiles[0].FileName)); } else { _logger.DebugFormat("Файл {0} не найден", uri); } } else if (uri.Scheme.Match("file")) { var src = new FileInfo(uri.LocalPath); if (!src.Exists) { return(null); } //в базе даты хранятся с точнотью до секунды сравнивать их нужно так же if (Math.Abs((DateTime.Now - src.LastWriteTime).TotalMilliseconds) > Settings.Default.FileDownloadInterval && Math.Abs((source.LastDecodeTableDownload.GetValueOrDefault() - src.LastWriteTime).TotalSeconds) > 1) { var dst = src.CopyTo(cleaner.TmpFile(), true); return(new CertificateCatalogFile(source, src.LastWriteTime, dst.FullName)); } } return(null); }
public void View_document_certificates() { var log = DataMother.CreateTestDocumentLog(supplier, client); var document = DataMother.CreateTestDocument(supplier, client, log); var line = document.Lines[0]; //Добавим CertificateSource т.к. изменилась выборка для сертификатов - теперь необходим еще Id источника для CertificateFile var newCertificate = new CertificateSource { Supplier = supplier, Name = "Test_Source", SourceClassName = "Test_class_Name" }; supplier.CertificateSource = newCertificate; session.Save(newCertificate); line.CatalogProduct = DataMother.Product(); line.Product = line.CatalogProduct.Catalog.Name; line.Certificate = DataMother.Certificate(line.CatalogProduct.Catalog, newCertificate.Id.ToString()); session.Save(line); var dir = Directory.CreateDirectory(Path.Combine(DataRoot, "Certificates")); var filename = line.Certificate.Files[0].Filename; File.WriteAllText(Path.Combine(dir.FullName, filename), ""); Open("Logs/Documents?filter.Client.Id={0}", client.Id); AssertText("Тестовый поставщик"); Click("TestFile.txt"); WaitForText("Страна"); AssertText("Страна"); Click(line.Product); WaitForText(filename); AssertText(filename); session.Delete(newCertificate); }