TLS with selfsigned certificate

前端 未结 6 2028
再見小時候
再見小時候 2020-12-07 17:10

I\'m trying to establish a TLS connection with the use of a self signed server certificate.

I generated the certificate with this example code: http://golang.org/src

6条回答
  •  情书的邮戳
    2020-12-07 18:01

    You need to use the InsecureSkipVerify flag, refer to https://groups.google.com/forum/#!topic/golang-nuts/c9zEiH6ixyw.

    The related code of this post (incase the page is offline):

    smtpbox := "mail.foo.com:25"
    c, err := smtp.Dial(smtpbox)
    
    host, _, _ := net.SplitHostPort(smtpbox)
    tlc := &tls.Config{
        InsecureSkipVerify: true,
        ServerName:         host,
    }
    if err = c.StartTLS(tlc); err != nil {
        fmt.Printf(err)
        os.Exit(1)
    } 
    // carry on with rest of smtp transaction 
    // c.Auth, c.Mail, c.Rcpt, c.Data, etc
    

提交回复
热议问题