diff --git a/dummy-chain-cert.pem b/dummy-chain-cert-rsa.pem similarity index 100% rename from dummy-chain-cert.pem rename to dummy-chain-cert-rsa.pem diff --git a/dummy-chain-cert.pem.license b/dummy-chain-cert-rsa.pem.license similarity index 100% rename from dummy-chain-cert.pem.license rename to dummy-chain-cert-rsa.pem.license diff --git a/dummy-child-cert-ecdsa.pem b/dummy-child-cert-ecdsa.pem new file mode 100644 index 0000000..5f9953c --- /dev/null +++ b/dummy-child-cert-ecdsa.pem @@ -0,0 +1,26 @@ +-----BEGIN CERTIFICATE----- +MIICAzCCAaqgAwIBAgIUKNWGvPrlzuYHnP4m6nGe60LalYEwCgYIKoZIzj0EAwIw +ZTELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVN0YXRlMQ0wCwYDVQQHDARDaXR5MRcw +FQYDVQQKDA5JbnRlcm1lZGlhdGVDQTEeMBwGA1UEAwwVSW50ZXJtZWRpYXRlIEVD +RFNBIENBMB4XDTI0MTAxNzEzMDg0N1oXDTI2MTAxNzEzMDg0N1owWzELMAkGA1UE +BhMCVVMxDjAMBgNVBAgMBVN0YXRlMQ0wCwYDVQQHDARDaXR5MRIwEAYDVQQKDAlF +bmRFbnRpdHkxGTAXBgNVBAMMEEVuZCBFbnRpdHkgRUNEU0EwWTATBgcqhkjOPQIB +BggqhkjOPQMBBwNCAATMkQg2RhaDYOWs+Ik/NKgZdwxm4BzagwVou6R73uiwXsRi +QgJfhBxp01S3JI4E8AiboFf4uPRnRh0HGl9cUR+po0IwQDAdBgNVHQ4EFgQUz247 +eAeMuM2We19rA5HnLzyLZEUwHwYDVR0jBBgwFoAU6oYLh690kT1bIB3DUA/SGRim +dXswCgYIKoZIzj0EAwIDRwAwRAIgI7cIpGzoiU1IoTYniEGXtK+WXq4Luv8k3BJQ +W16RAVsCICnuLaRyH/5nA3mmciAiF5R9PKDzyBnJcPGuCM1tmEpN +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB/zCCAaSgAwIBAgIURGCUhG09dwZ2DwtWHjQxGTnNT3UwCgYIKoZIzj0EAwIw +VTELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVN0YXRlMQ0wCwYDVQQHDARDaXR5MQ8w +DQYDVQQKDAZSb290Q0ExFjAUBgNVBAMMDVJvb3QgRUNEU0EgQ0EwHhcNMjQxMDE3 +MTMwODMwWhcNMjkxMDE2MTMwODMwWjBlMQswCQYDVQQGEwJVUzEOMAwGA1UECAwF +U3RhdGUxDTALBgNVBAcMBENpdHkxFzAVBgNVBAoMDkludGVybWVkaWF0ZUNBMR4w +HAYDVQQDDBVJbnRlcm1lZGlhdGUgRUNEU0EgQ0EwWTATBgcqhkjOPQIBBggqhkjO +PQMBBwNCAASYjGGvlMFZwnqUc8+jt9I7qRT8IP5gYLPZ7oiV/oaGNinmtzG7UXC/ +2PEDvdqpMPNw65IaP0d8z+c5lUxneE70o0IwQDAdBgNVHQ4EFgQU6oYLh690kT1b +IB3DUA/SGRimdXswHwYDVR0jBBgwFoAUGVvIlDmd/tCejujJcy4xTvgkw3IwCgYI +KoZIzj0EAwIDSQAwRgIhAO0rw5JvMu5y8JO958/4FThdjwOsg/IDGryQ3QQM0tw1 +AiEA07W1o81WIOVLZzwyTJAN8SnpSRIXgV/+ccst2T7s7Zs= +-----END CERTIFICATE----- diff --git a/dummy-child-key.pem.license b/dummy-child-cert-ecdsa.pem.license similarity index 100% rename from dummy-child-key.pem.license rename to dummy-child-cert-ecdsa.pem.license diff --git a/dummy-child-key-ecdsa.pem b/dummy-child-key-ecdsa.pem new file mode 100644 index 0000000..d2a1185 --- /dev/null +++ b/dummy-child-key-ecdsa.pem @@ -0,0 +1,8 @@ +-----BEGIN EC PARAMETERS----- +BggqhkjOPQMBBw== +-----END EC PARAMETERS----- +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEIG20X4lI7vocwK2W3TYOW+XtQv/bwRWYknvAf2OK8WFJoAoGCCqGSM49 +AwEHoUQDQgAEzJEINkYWg2DlrPiJPzSoGXcMZuAc2oMFaLuke97osF7EYkICX4Qc +adNUtySOBPAIm6BX+Lj0Z0YdBxpfXFEfqQ== +-----END EC PRIVATE KEY----- \ No newline at end of file diff --git a/dummy-child-key-ecdsa.pem.license b/dummy-child-key-ecdsa.pem.license new file mode 100644 index 0000000..615ea2b --- /dev/null +++ b/dummy-child-key-ecdsa.pem.license @@ -0,0 +1,3 @@ +// SPDX-FileCopyrightText: Copyright (c) 2022-2024 The go-mail Authors +// +// SPDX-License-Identifier: MIT diff --git a/dummy-child-key.pem b/dummy-child-key-rsa.pem similarity index 100% rename from dummy-child-key.pem rename to dummy-child-key-rsa.pem diff --git a/dummy-child-key-rsa.pem.license b/dummy-child-key-rsa.pem.license new file mode 100644 index 0000000..615ea2b --- /dev/null +++ b/dummy-child-key-rsa.pem.license @@ -0,0 +1,3 @@ +// SPDX-FileCopyrightText: Copyright (c) 2022-2024 The go-mail Authors +// +// SPDX-License-Identifier: MIT diff --git a/util_test.go b/util_test.go index f14f010..17821aa 100644 --- a/util_test.go +++ b/util_test.go @@ -5,19 +5,23 @@ package mail import ( + "crypto/ecdsa" "crypto/rsa" "crypto/tls" "crypto/x509" ) const ( - certFilePath = "dummy-chain-cert.pem" - keyFilePath = "dummy-child-key.pem" + certRSAFilePath = "dummy-chain-cert-rsa.pem" + keyRSAFilePath = "dummy-child-key-rsa.pem" + + certECDSAFilePath = "dummy-chain-cert-ecdsa.pem" + keyECDSAFilePath = "dummy-child-cert-ecdsa.pem" ) -// getDummyCryptoMaterial loads a certificate and a private key form local disk for testing purposes -func getDummyCryptoMaterial() (*rsa.PrivateKey, *x509.Certificate, *x509.Certificate, error) { - keyPair, err := tls.LoadX509KeyPair(certFilePath, keyFilePath) +// getDummyRSACryptoMaterial loads a certificate (RSA) and the associated private key (ECDSA) form local disk for testing purposes +func getDummyRSACryptoMaterial() (*rsa.PrivateKey, *x509.Certificate, *x509.Certificate, error) { + keyPair, err := tls.LoadX509KeyPair(certRSAFilePath, keyRSAFilePath) if err != nil { return nil, nil, nil, err } @@ -36,3 +40,25 @@ func getDummyCryptoMaterial() (*rsa.PrivateKey, *x509.Certificate, *x509.Certifi return privateKey, certificate, intermediateCertificate, nil } + +// getDummyECDSACryptoMaterial loads a certificate (ECDSA) and the associated private key (ECDSA) form local disk for testing purposes +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 +}