title: TLS with selfsigned certificate
body: <p>I'm trying to establish a TLS connection with the use of a self signed server certificate.</p>
  
  <p>I generated the certificate with this example code: <a href="http://golang.org/src/pkg/crypto/tls/generate_cert.go" rel="noreferrer">http://golang.org/src/pkg/crypto/tls/generate_cert.go</a></p>
  
  <p>My relevant client code looks like that:</p>
  
  <pre class="lang-golang prettyprint-override"><code>// server cert is self signed -&gt; 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", &amp;config)
  if err != nil {
      log.Fatalf("client: dial: %s", err)
  }
  </code></pre>
  
  <p>And the relevant server code like that:</p>
  
  
  
  <pre><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", &amp;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)
  }
  </code></pre>
  
  <p>Because the server certificate is self signed is use the same certificate for the server and the clients CA_Pool however this does not seem to work since i always get this error:</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>What's my mistake?</p>