2 回答

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以使用私鑰解密數(shù)據(jù)并加密散列數(shù)據(jù)以創(chuàng)建數(shù)字簽名。
您可以使用公鑰加密數(shù)據(jù)并解密數(shù)字簽名來驗(yàn)證它。
您需要在這里做的是使用一個(gè)密鑰對(公鑰/私鑰)生成 CA 證書,并使用該證書 + 相同的密鑰對為您的服務(wù)器生成一個(gè)或多個(gè)證書。
如果您想使用瀏覽器/curl 作為客戶端,則需要在根密鑰庫中添加 CA 證書。

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
我從上面粘貼了更正的代碼片段。希望有一天,他們可以幫助某人。
...
templateCA := &x509.Certificate{
Subject: pkix.Name{
CommonName: "test-ca",
Organization: []string{"test ca"},
Country: []string{"USA"},
Province: []string{"NY"},
Locality: []string{"New York City"},
},
SerialNumber: serialNumber,
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(0, 0, 1),
BasicConstraintsValid: true,
IsCA: true,
KeyUsage: x509.KeyUsageCertSign
DNSNames: []string{"test-ca"},
}
...
certBytes, _ := x509.CreateCertificate(rand.Reader, templateCA, templateCA, privKeyCA.Public(), privKeyCA)
...
templateServer := &x509.Certificate{
Subject: pkix.Name{
CommonName: "localhost",
Organization: []string{"Server"},
Country: []string{"USA"},
Province: []string{"NY"},
Locality: []string{"New York City"},
},
SerialNumber: serialNumber,
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(0, 0, 1),
BasicConstraintsValid: true,
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
DNSNames: []string{"localhost"},
}
...
certBytes, _ = x509.CreateCertificate(rand.Reader, templateServer, caCert, privKeyServer.Public(), privKeyCA)
...
var (
tlsMinVersion = uint16(tls.VersionTLS12)
tlsMaxVersion = uint16(tls.VersionTLS13)
cipherSuites = []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
}
curvePreferences = []tls.CurveID{
tls.X25519,
tls.CurveP256,
tls.CurveP384,
tls.CurveP521,
}
)
...
tlsServerConfig := &tls.Config{
Certificates: []tls.Certificate{*tlsSrvCert},
MinVersion: tlsMinVersion,
MaxVersion: tlsMaxVersion,
CurvePreferences: curvePreferences,
CipherSuites: cipherSuites,
PreferServerCipherSuites: true,
}
...
tlsClientConfig := &tls.Config{
ServerName: "localhost",
RootCAs: x509.NewCertPool(),
MinVersion: tlsMinVersion,
MaxVersion: tlsMaxVersion,
CurvePreferences: curvePreferences,
CipherSuites: cipherSuites,
PreferServerCipherSuites: true,
}
tlsClientConfig.RootCAs.AddCert(caCert)
- 2 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)