2 twisted SSL certificates


calombo

I have the following code:

from twisted.web.server import Site
from twisted.web.static import Data
from twisted.internet import reactor, ssl

root = Data("", "text/plain")
site = Site(root)
reactor.listenSSL(config.ws_port, site,
                      ssl.DefaultOpenSSLContextFactory(
                        '/etc/apache2/ssl/wc.key',
                        '/etc/apache2/ssl/wc.crt')
                      )

But I have other domain names and other certificates. I need to use 2 certificates for each domain. How do I add a second twisted certificate?

Jean-Paul Calderone

The way TLS is used with HTTP to support multiple hostnames is by using a single certificate that contains all of these hostnames (for example, as an subjectAltNameextension) or by using multiple certificates (each certificate has less hostname than the full hostname) ) and SNI​​ TLS extension.

If you want to use the previous solution, all you have to do is get a properly constructed certificate. How you do this may depend on where you got the certificate from. The certificate vendor may have a special UI for this, or the certificate request generator you are using has options to control it.

If you want to use the latter solution, investigate txSNI :

from txsni.snimap import SNIMap
from txsni.tlsendpoint import TLSEndpoint

from twisted.web.server import Site
from twisted.web.static import Data
from twisted.internet import reactor
from twisted.internet.ssl import Certificate, KeyPair, PrivateCertificate
from twisted.internet.endpoints import serverFromString

def main(reactor):
    root = Data("", "text/plain")
    site = Site(root)

    def load(key_path, cert_path):
        with open(key_path) as key_file:
            key = KeyPair.loadPEM(key_file.read())

        with open(cert_path) as cert_file:
             cert = cert.read()

        return PrivateCertificate.fromCertificateAndKeyPair(cert, key)

    snimap = SNIMap({
        "DEFAULT": load('/etc/apache2/ssl/wc.key', '/etc/apache2/ssl/wc.crt').options(),
        "another.host.name": load(another_key, another_cert).options(),
        ...
    })

    endpoint = TLSEndpoint(serverFromString(reactor, "tcp:80"))
    endpoint.listen(site)

    reactor.run()

Related


2 twisted SSL certificates

calombo I have the following code: from twisted.web.server import Site from twisted.web.static import Data from twisted.internet import reactor, ssl root = Data("", "text/plain") site = Site(root) reactor.listenSSL(config.ws_port, site,

2 twisted SSL certificates

calombo I have the following code: from twisted.web.server import Site from twisted.web.static import Data from twisted.internet import reactor, ssl root = Data("", "text/plain") site = Site(root) reactor.listenSSL(config.ws_port, site,

Apache: 2 SSL certificates, same DocumentRoot

Dusty Grist My website is configured apacheand now I'm trying to setup redirects correctly. My website uses wildcard SSL authentication and my ssl certificate covers *.mydomain.com. My certificate provider only covers one level of subdomains. My website URL is

Twisted SMTP server, add SSL support, 2 factories?

Steve Hall Recently asked about Twisted mail server with TLS - no portal? It seems like I'm barking up the wrong tree, so it seems appropriate and appropriate to ask a new, revised question now. So I tried to extend the basic SMTP server example found at http:

Express.js with multiple SSL certificates and HTTP/2

dsp_099 Scenes: I have an express.js server that serves variations of the same static login page based on req.headers.hostthe source the user says - like an A/B test. GET tulip.flower.comsupplypages/flower.com/tulip.html GET rose.flower.comsupplypages/flower.c

Express.js with multiple SSL certificates and HTTP/2

dsp_099 Scenes: I have an express.js server that serves variations of the same static login page based on req.headers.hostthe source the user says - like an A/B test. GET tulip.flower.comsupplypages/flower.com/tulip.html GET rose.flower.comsupplypages/flower.c

Express.js with multiple SSL certificates and HTTP/2

dsp_099 Scenes: I have an express.js server that serves variations of the same static login page based on req.headers.hostthe source the user says - like an A/B test. GET tulip.flower.comsupplypages/flower.com/tulip.html GET rose.flower.comsupplypages/flower.c

Express.js with multiple SSL certificates and HTTP/2

dsp_099 Scenes: I have an express.js server that serves variations of the same static login page based on req.headers.hostthe source the user says - like an A/B test. GET tulip.flower.comsupplypages/flower.com/tulip.html GET rose.flower.comsupplypages/flower.c

Express.js with multiple SSL certificates and HTTP/2

dsp_099 Scenes: I have an express.js server that serves variations of the same static login page based on req.headers.hostthe source the user says - like an A/B test. GET tulip.flower.comsupplypages/flower.com/tulip.html GET rose.flower.comsupplypages/flower.c

Java and SSL certificates

Andy: I'm trying to use Secure Sockets Layer (HTTPS) to connect to a PHP script in Java, but I've found that for maximum security/validity I have to import the SSL certificate used by the website into my application. ..I do not know what to do. If it helps, my

Where are SSL certificates stored?

iOS Monkey I understand how SSL works, but my question is more about the storage of certificates on the client side. To understand the exact context, let's assume I'm writing my own browser. My rendering part will be done by WebKit and the HTTP request handlin

Where are SSL certificates stored?

iOS Monkey I understand how SSL works, but my question is more about the storage of certificates on the client side. To understand the exact context, let's assume I'm writing my own browser. My rendering part will be done by WebKit and the HTTP request handlin

SSL certificates break CSS

Sam Recently purchased an SSL certificate, but the site doesn't seem to be able to load the site CSS. Here is the link https://www.rentpayment.com/ By looking at the console error message this seems to be the problem: <link rel="stylesheet" href="http://www.re

Java and SSL certificates

Andy: I'm trying to use Secure Sockets Layer (HTTPS) to connect to a PHP script in Java, but I've found that for maximum security/validity I have to import the SSL certificate used by the website into my application. ..I do not know what to do. If it helps, my

Pinning SSL certificates with libcurl

SP Miguel Jenner I wonder if this example is enough to provide a way to do certificate pinning with libcurl : http://curl.haxx.se/libcurl/c/cacertinmem.html Because I found out that curl also allows http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html Si

Certificates returned by free SSL

O. Shekri Raz Today I installed a free ssl certificate on my website and it was easy, but I have some questions about it. FreeSSL returned three files: "private.key", "certificate.crt", "ca_bundle.crt". So there are my questions: 1) Who does this private key b

Where are SSL certificates stored?

iOS Monkey I understand how SSL works, but my question is more about the storage of certificates on the client side. To understand the exact context, let's assume I'm writing my own browser. My rendering part will be done by WebKit and the HTTP request handlin

SSL certificates and links

Eric Sometimes I use elink for web browsing and it happens that some HTTP sites fail to load due to it SSL error. An example is https://www.rust-lang.org , which doesn't load in elink but works fine on other browsers like Chrome and firefox. Checking the https

SSL certificates break CSS

Sam Recently purchased an SSL certificate, but the site doesn't seem to be able to load the site CSS. Here is the link https://www.rentpayment.com/ By looking at the console error message this seems to be the problem: <link rel="stylesheet" href="http://www.re

SSL certificates break CSS

Sam Recently purchased an SSL certificate, but the site doesn't seem to be able to load the site CSS. Here is the link https://www.rentpayment.com/ By looking at the console error message this seems to be the problem: <link rel="stylesheet" href="http://www.re

SSL certificates break CSS

Sam Recently purchased an SSL certificate, but the site doesn't seem to be able to load the site CSS. Here is the link https://www.rentpayment.com/ By looking at the console error message this seems to be the problem: <link rel="stylesheet" href="http://www.re

SSL certificates break CSS

Sam Recently purchased an SSL certificate, but the site doesn't seem to be able to load the site CSS. Here is the link https://www.rentpayment.com/ By looking at the console error message this seems to be the problem: <link rel="stylesheet" href="http://www.re

SSL certificates break CSS

Sam Recently purchased an SSL certificate, but the site doesn't seem to be able to load the site CSS. Here is the link https://www.rentpayment.com/ By looking at the console error message this seems to be the problem: <link rel="stylesheet" href="http://www.re

Nginx and SSL certificates

Lesha Ppiev I want to provide ssl support for my website under Nginx. First, I tried to use a self-signed certificate, but as you know, the browser complains The current connection cannot be trusted Second, I tried ordering a free certificate from a reputable