mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-25 15:10:48 +01:00
42 lines
940 B
Go
42 lines
940 B
Go
|
package mail
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"crypto/rsa"
|
||
|
"crypto/x509"
|
||
|
"crypto/x509/pkix"
|
||
|
"math/big"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func getDummyPrivateKey() (*rsa.PrivateKey, error) {
|
||
|
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return privateKey, nil
|
||
|
}
|
||
|
|
||
|
func getDummyCertificate(privateKey *rsa.PrivateKey) (*x509.Certificate, error) {
|
||
|
template := &x509.Certificate{
|
||
|
SerialNumber: big.NewInt(1234),
|
||
|
Subject: pkix.Name{Organization: []string{"My Organization"}},
|
||
|
NotBefore: time.Now(),
|
||
|
NotAfter: time.Now().AddDate(1, 0, 0),
|
||
|
KeyUsage: x509.KeyUsageDigitalSignature,
|
||
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
||
|
}
|
||
|
|
||
|
certDER, err := x509.CreateCertificate(rand.Reader, template, template, &privateKey.PublicKey, privateKey)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
cert, err := x509.ParseCertificate(certDER)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return cert, nil
|
||
|
}
|