TLS with self-signed certificate


Zapp

I am trying to establish a TLS connection using a self signed server certificate.

I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go

My relevant client code looks like this:

// server cert is self signed -> server_cert == ca_cert
CA_Pool := x509.NewCertPool()
severCert, err := ioutil.ReadFile("./cert.pem")
if err != nil {
    log.Fatal("Could not load server certificate!")
}
CA_Pool.AppendCertsFromPEM(severCert)

config := tls.Config{RootCAs: CA_Pool}

conn, err := tls.Dial("tcp", "127.0.0.1:8000", &config)
if err != nil {
    log.Fatalf("client: dial: %s", err)
}

and similar server code:

cert, err := tls.LoadX509KeyPair("./cert.pem", "./key.pem")
config := tls.Config{Certificates: []tls.Certificate{cert}}
listener, err := tls.Listen("tcp", "127.0.0.1:8000", &config)

for {
    conn, err := listener.Accept()
    if err != nil {
        log.Printf("server: accept: %s", err)
        break
    }
    log.Printf("server: accepted from %s", conn.RemoteAddr())
    go handleConnection(conn)
}

Since the server certificate is self-signed, the server and client CA_Pool use the same certificate, but this doesn't seem to work because I always get this error:

client: dial: x509: certificate signed by unknown authority 
(possibly because of "x509: invalid signature: parent certificate
cannot sign this kind of certificate" while trying to verify 
candidate authority certificate "serial:0")

What's wrong with me

Zapp

It ended up working with the go built in x509.CreateCertificate, the problem was that I didn't set the IsCA:true flag , but only x509.KeyUsageCertSign , which made creating a self-signed certificate work, but crashed when validating the certificate chain.

Related


TLS connection via self-signed certificate fails

Integrator: The following reduced test case code works when run locally on my laptop using my own "developer" certificate to access internal services If I run on a remote machine with dynamically generated certificates (all handled by separate teams in the org

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

Implement tls.Config.GetCertificate with self-signed certificate

MH carbon I am trying to figure out how to implement tls.Config.GetCertificatethe functionality with a self signed certificate. I base this bin source, https://golang.org/src/crypto/tls/generate_cert.go Also read this, https://ericchiang.github.io/tls/go/https

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Implement tls.Config.GetCertificate with self-signed certificate

MH carbon I am trying to figure out how to implement tls.Config.GetCertificatethe functionality with a self signed certificate. I base this bin source, https://golang.org/src/crypto/tls/generate_cert.go Also read this, https://ericchiang.github.io/tls/go/https

Implement tls.Config.GetCertificate with self-signed certificate

MH carbon I am trying to figure out how to implement tls.Config.GetCertificatethe functionality with a self signed certificate. I base this bin source, https://golang.org/src/crypto/tls/generate_cert.go Also read this, https://ericchiang.github.io/tls/go/https

TLS connection via self-signed certificate fails

Integrator: The following reduced test case code works when run locally on my laptop using my own "developer" certificate to access internal services If I run on a remote machine with dynamically generated certificates (all handled by separate teams in the org

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

TLS connection via self-signed certificate fails

Integrator: The following reduced test case code works when run locally on my laptop using my own "developer" certificate to access internal services If I run on a remote machine with dynamically generated certificates (all handled by separate teams in the org

Implement tls.Config.GetCertificate with self-signed certificate

MH carbon I am trying to figure out how to implement tls.Config.GetCertificatethe functionality with a self signed certificate. I base this bin source, https://golang.org/src/crypto/tls/generate_cert.go Also read this, https://ericchiang.github.io/tls/go/https

TLS secure TCP server and client with self-signed certificate

frank I'm developing an application that connects two Android devices via Wifi so that they can exchange files/data using TCP. Since Android Oreo (API level 26) there is finally an official API: . This will create a Wifi hotspot/network without internet access

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Verify self-signed TLS certificate for HTTPS in Ruby

Ashima Sood How to use SSL certificate verification (using password parameter in URL) in RUBY's GET Request? -> require 'net/https' require 'uri' uri = URI.parse(ARGV[0] || 'https://example.com?password=my_password') http = Net::HTTP.new(uri.host, uri.port)

Converting from self-signed to commercial certificate TLS error

phantom When installing the cluster, I used a self-signed certificate from an internal CA authority. Everything was fine until I started getting certificate errors from the application I was deploying to the OKD cluster. We decided to stop trying to fix one bu

Self-signed server certificate for Postfix TLS

Tufel I'm trying to create a self-signed server certificate for Postfix users: thufir@dur:~$ thufir@dur:~$ sudo ./tls.script Error opening Private Key 3073578684:error:02001002:system library:fopen:No such file or directory:bss_file.c:398:fopen('','r') 3073

TLS 1.3 server socket with Java 11 and self-signed certificate

Simon I want to create a simple TLS 1.3 server socket listener which uses a self signed certificate. First I created an RSA public/private key pair: openssl req -x509 -newkey rsa:2048 -sha256 -days 9125 -nodes -keyout test.key -out test.crt I am adding public

TLS connection via self-signed certificate fails

Integrator: The following reduced test case code works when run locally on my laptop using my own "developer" certificate to access internal services If I run on a remote machine with dynamically generated certificates (all handled by separate teams in the org

TLS connection via self-signed certificate fails

Integrator: The following reduced test case code works when run locally on my laptop using my own "developer" certificate to access internal services If I run on a remote machine with dynamically generated certificates (all handled by separate teams in the org

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

Implement tls.Config.GetCertificate with self-signed certificate

MH carbon I am trying to figure out how to implement tls.Config.GetCertificatethe functionality with a self signed certificate. I base this bin source, https://golang.org/src/crypto/tls/generate_cert.go Also read this, https://ericchiang.github.io/tls/go/https

TLS with self-signed certificate

breakdown I am trying to establish a TLS connection using a self signed server certificate. I generated the certificate using the following sample code : http://golang.org/src/pkg/crypto/tls/generate_cert.go My relevant client code looks like this: // server c

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Tokio Tls Self-Signed Certificate

lad Update: This seems to be related to properly generating and trusting the self-signed certificate. I am building a server and client using tokio-rs. I have everything working fine but now trying to add SSL/TLS to the system. As far as I can tell, I have gen

Converting from self-signed to commercial certificate TLS error

phantom When installing the cluster, I used a self-signed certificate from an internal CA authority. Everything was fine until I started getting certificate errors from the application I was deploying to the OKD cluster. We decided to stop trying to fix one bu

Verify self-signed TLS certificate for HTTPS in Ruby

Ashima Sood How to use SSL certificate verification (using password parameter in URL) in RUBY's GET Request? -> require 'net/https' require 'uri' uri = URI.parse(ARGV[0] || 'https://example.com?password=my_password') http = Net::HTTP.new(uri.host, uri.port)

Self-signed server certificate for Postfix TLS

Tufel I'm trying to create a self-signed server certificate for Postfix users: thufir@dur:~$ thufir@dur:~$ sudo ./tls.script Error opening Private Key 3073578684:error:02001002:system library:fopen:No such file or directory:bss_file.c:398:fopen('','r') 3073