Esempio n. 1
0
        public StamperManager(IOptions <FileLoaction> fileOptions, IOptions <CertConfig> certOption)
        {
            this.fileLoaction = fileOptions.Value;
            this.certConfig   = certOption.Value;

            using (FileStream fs = new FileStream(fileLoaction.Cert, FileMode.Open))
            {
                stamper = ImageDataFactory.Create(fileLoaction.Stamper);

                Pkcs12Store store = new Pkcs12Store(fs, certConfig.Password.ToCharArray());

                X509CertificateEntry[] entries = store.GetCertificateChain(certConfig.Alias);

                int length = entries.Length;
                chain = new X509Certificate[entries.Length];
                for (int i = 0; i != length; ++i)
                {
                    chain[i] = entries[i].Certificate;
                }

                pk = store.GetKey(certConfig.Alias).Key;
            }

            this.outBaseDir = fileLoaction.OutBaseDir;
        }
Esempio n. 2
0
 public EnvConfig(IConfigurationRoot root)
 {
     this._root   = root;
     this._csp    = new CspConfig(root);
     this._cert   = new CertConfig(root);
     this._uri    = new UriConfig(root);
     this._db     = new DatabaseConfig(root);
     this._client = new ClientConfig(root);
     this._smtp   = new SmtpConfig(root);
     this._dp     = new DpConfig(root, this._uri, AppName);
 }
Esempio n. 3
0
 public UpdateCustomDomainRequest(string domainName, string protocal = null, string apiVersion = null, RouteConfig routeConfig = null, Dictionary <string, string> customHeaders = null, CertConfig certConfig = null)
 {
     Contract.Requires(string.IsNullOrEmpty(domainName) == false);
     this.DomainName             = domainName;
     this.UpdateCustomDomainMeta = new UpdateCustomDomainMeta(protocal, apiVersion, routeConfig, certConfig);
     this.Headers = customHeaders;
 }
Esempio n. 4
0
        public void TestCustomDomainCRUD()
        {
            RouteConfig routeConfig = new RouteConfig();

            PathConfig pathConfig1 = new PathConfig
            {
                ServiceName  = "s1",
                FunctionName = "f1",
                Path         = "/a"
            };

            PathConfig pathConfig2 = new PathConfig
            {
                ServiceName  = "s2",
                FunctionName = "f2",
                Path         = "/b",
            };

            routeConfig.Routes = new PathConfig[] { pathConfig1, pathConfig2 };

            CertConfig certConfig = new CertConfig {
                CertName = "csharp-test-ssl", Certificate = SERVER_CERT, PrivateKey = SERVER_KEY
            };

            //tf.Client.DeleteCustomDomain(new DeleteCustomDomainRequest(tf.DomainName));

            var response = tf.Client.CreateCustomDomain(new CreateCustomDomainRequest(tf.DomainName, "HTTP,HTTPS", null, routeConfig, null, certConfig));

            if (response.StatusCode == 200)
            {
                this.Domains.Add(tf.DomainName);
            }

            //Console.WriteLine(response.Content);
            Assert.Equal(response.Data.RouteConfig.Routes.GetLength(0), routeConfig.Routes.Length);
            Assert.Equal(response.Data.DomainName, tf.DomainName);
            Assert.Equal(response.Data.RouteConfig.Routes[0].Path, pathConfig1.Path);
            Assert.Equal(response.Data.RouteConfig.Routes[1].Path, pathConfig2.Path);
            Assert.Equal("csharp-test-ssl", response.Data.CertConfig.CertName);
            Assert.Equal(SERVER_CERT, response.Data.CertConfig.Certificate);
            Assert.Null(response.Data.CertConfig.PrivateKey);
            Assert.Equal("HTTP,HTTPS", response.Data.Protocol);

            pathConfig2 = new PathConfig
            {
                ServiceName  = "s2",
                FunctionName = "f2",
                Path         = "/c",
            };

            routeConfig.Routes = new PathConfig[] { pathConfig1, pathConfig2 };

            var response2 = tf.Client.UpdateCustomDomain(new UpdateCustomDomainRequest(tf.DomainName, "HTTP", null, routeConfig, null, null));

            //Console.WriteLine(response2.Content);
            Assert.Equal(response2.Data.RouteConfig.Routes.GetLength(0), routeConfig.Routes.Length);
            Assert.Equal(response2.Data.DomainName, tf.DomainName);
            Assert.Equal(response2.Data.RouteConfig.Routes[0].Path, pathConfig1.Path);
            Assert.Equal(response2.Data.RouteConfig.Routes[1].Path, pathConfig2.Path);
            Assert.Null(response2.Data.CertConfig);
            Assert.Equal("HTTP", response2.Data.Protocol);


            var response3 = tf.Client.GetCustomDomain(new GetCustomDomainRequest(tf.DomainName));

            //Console.WriteLine(response3.Content);
            Assert.Equal(response3.Data.RouteConfig.Routes.GetLength(0), routeConfig.Routes.Length);
            Assert.Equal(response3.Data.DomainName, tf.DomainName);
            Assert.Equal(response3.Data.RouteConfig.Routes[0].Path, pathConfig1.Path);
            Assert.Equal(response3.Data.RouteConfig.Routes[1].Path, pathConfig2.Path);
            Assert.Null(response3.Data.CertConfig.CertName);
            Assert.Null(response3.Data.CertConfig.Certificate);
            Assert.Null(response3.Data.CertConfig.PrivateKey);
            Assert.Equal("HTTP", response3.Data.Protocol);

            var response4 = tf.Client.ListCustomDomains(new ListCustomDomainsRequest(100, "pythonSDK"));

            Console.WriteLine(response4.Content);
            Assert.Equal(1, response4.Data.CustomDomains.GetLength(0));
            var firstData = response4.Data.CustomDomains[0];

            Assert.Equal(firstData.RouteConfig.Routes.GetLength(0), routeConfig.Routes.Length);
            Assert.Equal(firstData.DomainName, tf.DomainName);
            Assert.Equal(firstData.RouteConfig.Routes[0].Path, pathConfig1.Path);
            Assert.Equal(firstData.RouteConfig.Routes[1].Path, pathConfig2.Path);


            var response5 = tf.Client.DeleteCustomDomain(new DeleteCustomDomainRequest(tf.DomainName));

            Console.WriteLine(response5.Content);
            if (response.StatusCode == 204)
            {
                this.Domains.Remove(tf.DomainName);
            }
        }
Esempio n. 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            CertConfig conf = new CertConfig();

            _conf.Bind("Hosting:CertConfig", conf);

            services.AddRouting();


            if (_conf.GetValue <bool>("Hosting:UseLetsEncrypt"))
            {
                //the following line adds the automatic renewal service.
                services.AddFluffySpoonLetsEncrypt(new LetsEncryptOptions()
                {
                    Email      = conf.EmailAddress,                          // "*****@*****.**", //LetsEncrypt will send you an e-mail here when the certificate is about to expire
                    UseStaging = false,                                      //switch to true for testing
                    Domains    = conf.DomainNames,                           // new[] { "staging.lab.aper-lab.com" },
                    TimeUntilExpiryBeforeRenewal    = TimeSpan.FromDays(30), //renew automatically 30 days before expiry
                    TimeAfterIssueDateBeforeRenewal = TimeSpan.FromDays(7),  //renew automatically 7 days after the last certificate was issued
                    CertificateSigningRequest       = new CsrInfo()          //these are your certificate details
                    {
                        CountryName      = conf.Country,
                        Locality         = conf.Country,
                        Organization     = conf.Organization,
                        OrganizationUnit = conf.OrganizationUnit ?? "",
                        State            = conf.State ?? ""
                    }
                });

                //the following line tells the library to persist the certificate to a file, so that if the server restarts, the certificate can be re-used without generating a new one.
                services.AddFluffySpoonLetsEncryptFileCertificatePersistence();

                //the following line tells the library to persist challenges in-memory. challenges are the "/.well-known" URL codes that LetsEncrypt will call.
                services.AddFluffySpoonLetsEncryptMemoryChallengePersistence();
            }

            services.AddCors(s =>
            {
                s.AddDefaultPolicy(p =>
                {
                    p.AllowAnyOrigin();
                });
            });

            services.AddControllers().AddNewtonsoftJson();

            services.AddApiVersioning(conf =>
            {
                conf.UseApiBehavior = false;
                conf.AssumeDefaultVersionWhenUnspecified = false;
                conf.DefaultApiVersion = new ApiVersion(1, 0);
            });
            services.AddVersionedApiExplorer(options =>
            {
                options.SubstituteApiVersionInUrl = true;
                options.GroupNameFormat           = "'v'VVV";
            });

            services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>();
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(options =>
            {
                // add a custom operation filter which sets default values
                options.OperationFilter <SwaggerDefaultValues>();

                // integrate xml comments
                options.IncludeXmlComments(XmlCommentsFilePath);
            });


            services.AddScoped <DiscordValidationFilter>();
        }