Sobes.tech
Junior

Что такое TLS и зачем нужен сертификат?

sobes.tech AI

Answer from AI

TLS (Transport Layer Security) is a cryptographic protocol that ensures secure data transmission over a network. It protects data from interception and tampering, ensuring confidentiality and integrity.

A certificate is needed to verify the authenticity of the server (or client) during the TLS connection establishment. The certificate contains the public key and information about the owner, signed by a trusted certification authority (CA). This allows the client to verify that it is connecting to the correct server, not an attacker.

Example of using TLS in Go:

package main

import (
    "crypto/tls"
    "fmt"
    "net/http"
)

func main() {
    // Create an HTTPS client with TLS settings
    client := &http.Client{
        Transport: &http.Transport{
            TLSClientConfig: &tls.Config{
                MinVersion: tls.VersionTLS12,
            },
        },
    }

    resp, err := client.Get("https://example.com")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("Status:", resp.Status)
}