2024-10-11 19:16:42 +02:00
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
//
// SPDX-License-Identifier: MIT
2024-09-18 14:13:24 +02:00
package mail
import (
2024-10-17 15:49:05 +02:00
"crypto/ecdsa"
2024-10-11 18:43:04 +02:00
"crypto/rsa"
2024-09-26 16:43:58 +02:00
"crypto/tls"
2024-09-26 17:08:38 +02:00
"crypto/x509"
2024-09-18 14:13:24 +02:00
)
2024-09-26 16:43:58 +02:00
const (
2024-10-17 15:49:05 +02:00
certRSAFilePath = "dummy-chain-cert-rsa.pem"
keyRSAFilePath = "dummy-child-key-rsa.pem"
certECDSAFilePath = "dummy-chain-cert-ecdsa.pem"
2024-10-17 16:14:04 +02:00
keyECDSAFilePath = "dummy-child-key-ecdsa.pem"
2024-09-26 16:43:58 +02:00
)
2024-09-18 14:13:24 +02:00
2024-10-30 15:40:22 +01:00
// getDummyRSACryptoMaterial loads a certificate (RSA), the associated private key and certificate (RSA) is loaded from local disk for testing purposes
2024-10-17 15:49:05 +02:00
func getDummyRSACryptoMaterial ( ) ( * rsa . PrivateKey , * x509 . Certificate , * x509 . Certificate , error ) {
keyPair , err := tls . LoadX509KeyPair ( certRSAFilePath , keyRSAFilePath )
2024-09-18 14:13:24 +02:00
if err != nil {
2024-10-11 18:43:04 +02:00
return nil , nil , nil , err
2024-09-18 14:13:24 +02:00
}
2024-10-11 18:43:04 +02:00
privateKey := keyPair . PrivateKey . ( * rsa . PrivateKey )
2024-09-26 17:08:38 +02:00
2024-10-11 18:43:04 +02:00
certificate , err := x509 . ParseCertificate ( keyPair . Certificate [ 0 ] )
if err != nil {
return nil , nil , nil , err
}
intermediateCertificate , err := x509 . ParseCertificate ( keyPair . Certificate [ 1 ] )
if err != nil {
return nil , nil , nil , err
}
return privateKey , certificate , intermediateCertificate , nil
2024-09-18 14:13:24 +02:00
}
2024-10-17 15:49:05 +02:00
2024-10-30 15:40:22 +01:00
// getDummyECDSACryptoMaterial loads a certificate (ECDSA), the associated private key and certificate (ECDSA) is loaded from local disk for testing purposes
2024-10-17 15:49:05 +02:00
func getDummyECDSACryptoMaterial ( ) ( * ecdsa . PrivateKey , * x509 . Certificate , * x509 . Certificate , error ) {
keyPair , err := tls . LoadX509KeyPair ( certECDSAFilePath , keyECDSAFilePath )
if err != nil {
return nil , nil , nil , err
}
privateKey := keyPair . PrivateKey . ( * ecdsa . PrivateKey )
certificate , err := x509 . ParseCertificate ( keyPair . Certificate [ 0 ] )
if err != nil {
return nil , nil , nil , err
}
intermediateCertificate , err := x509 . ParseCertificate ( keyPair . Certificate [ 1 ] )
if err != nil {
return nil , nil , nil , err
}
return privateKey , certificate , intermediateCertificate , nil
}
2024-10-30 15:40:22 +01:00
// getDummyKeyPairTLS loads a certificate (ECDSA) as *tls.Certificate, the associated private key and certificate (ECDSA) is loaded from local disk for testing purposes
func getDummyKeyPairTLS ( ) ( * tls . Certificate , error ) {
keyPair , err := tls . LoadX509KeyPair ( certECDSAFilePath , keyECDSAFilePath )
if err != nil {
return nil , err
}
return & keyPair , err
}