Skip to content

Commit

Permalink
Implement & test ed25519 support
Browse files Browse the repository at this point in the history
Keys/certs here are from rustls-0.22 (because OpenSSL cannot
parse PKCS#8.2 format keys.)
  • Loading branch information
ctz committed May 3, 2024
1 parent 54609be commit cab679f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
21 changes: 21 additions & 0 deletions rustls-libssl/src/evp_pkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,27 @@ impl EvpScheme for RsaPss {
unsafe impl Sync for RsaPss {}
unsafe impl Send for RsaPss {}

pub fn ed25519() -> Box<dyn EvpScheme + Send + Sync> {
Box::new(Ed25519)
}

#[derive(Debug)]
struct Ed25519;

impl EvpScheme for Ed25519 {
fn digest(&self) -> *mut EVP_MD {
// "When calling EVP_DigestSignInit() or EVP_DigestVerifyInit(), the
// digest type parameter MUST be set to NULL."
// <https://www.openssl.org/docs/man3.0/man7/EVP_SIGNATURE-ED25519.html>
ptr::null_mut()
}

fn configure_ctx(&self, _: &mut SignCtx) -> Option<()> {
// "No additional parameters can be set during one-shot signing or verification."
Some(())
}
}

/// Owning wrapper for a signing `EVP_MD_CTX`
pub(crate) struct SignCtx {
md_ctx: *mut EVP_MD_CTX,
Expand Down
13 changes: 12 additions & 1 deletion rustls-libssl/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustls::{SignatureAlgorithm, SignatureScheme};

use crate::error;
use crate::evp_pkey::{
rsa_pkcs1_sha256, rsa_pkcs1_sha384, rsa_pkcs1_sha512, rsa_pss_sha256, rsa_pss_sha384,
ed25519, rsa_pkcs1_sha256, rsa_pkcs1_sha384, rsa_pkcs1_sha512, rsa_pss_sha256, rsa_pss_sha384,
rsa_pss_sha512, EvpPkey, EvpScheme,
};
use crate::x509::OwnedX509Stack;
Expand Down Expand Up @@ -205,6 +205,17 @@ impl sign::SigningKey for OpenSslKey {

None
}
SignatureAlgorithm::ED25519 => {
if offered.contains(&SignatureScheme::ED25519) {
return Some(Box::new(OpenSslSigner {
pkey: self.0.clone(),
pscheme: ed25519(),
scheme: SignatureScheme::ED25519,
}));
}

None
}
_ => None,
}
}
Expand Down
9 changes: 9 additions & 0 deletions rustls-libssl/test-ca/ed25519/ca.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN CERTIFICATE-----
MIIBTDCB/6ADAgECAhR5rwmHkOFPLTkaLT9cqTrVZXkY9DAFBgMrZXAwHDEaMBgG
A1UEAwwRcG9ueXRvd24gRWREU0EgQ0EwHhcNMjMxMjIxMTcyMzE1WhcNMzMxMjE4
MTcyMzE1WjAcMRowGAYDVQQDDBFwb255dG93biBFZERTQSBDQTAqMAUGAytlcAMh
AJgNZ3ibDQ9rV85DZPPAnnwyuWh8rm3jX9ZCsU/WgG7Io1MwUTAdBgNVHQ4EFgQU
OFqGAvTdFHBY3OVdI0UB5kzHKpwwHwYDVR0jBBgwFoAUOFqGAvTdFHBY3OVdI0UB
5kzHKpwwDwYDVR0TAQH/BAUwAwEB/zAFBgMrZXADQQAsRwN+gYyaM5yN45Uo+R1y
tbiv8+TrEH0W8/oE/RCeRiPGV5qXpr2DqicljjNmNGixJ6ELuymaQ/1oMGuUDkEF
-----END CERTIFICATE-----
31 changes: 31 additions & 0 deletions rustls-libssl/test-ca/ed25519/server.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIB0DCCAYKgAwIBAgICAcgwBQYDK2VwMC4xLDAqBgNVBAMMI3Bvbnl0b3duIEVk
RFNBIGxldmVsIDIgaW50ZXJtZWRpYXRlMB4XDTIzMTIyMTE3MjMxNVoXDTI5MDYx
MjE3MjMxNVowGTEXMBUGA1UEAwwOdGVzdHNlcnZlci5jb20wKjAFBgMrZXADIQBG
aQQnDqqVjKAWWubCZJrG6S2ZZcI9/ZO65doj0GcDBqOB2DCB1TAMBgNVHRMBAf8E
AjAAMAsGA1UdDwQEAwIGwDAdBgNVHQ4EFgQUmyF3DidQ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QQDDBFwb255dG93biBFZERTQSBDQTAqMAUGAytlcAMh
AJgNZ3ibDQ9rV85DZPPAnnwyuWh8rm3jX9ZCsU/WgG7Io1MwUTAdBgNVHQ4EFgQU
OFqGAvTdFHBY3OVdI0UB5kzHKpwwHwYDVR0jBBgwFoAUOFqGAvTdFHBY3OVdI0UB
5kzHKpwwDwYDVR0TAQH/BAUwAwEB/zAFBgMrZXADQQAsRwN+gYyaM5yN45Uo+R1y
tbiv8+TrEH0W8/oE/RCeRiPGV5qXpr2DqicljjNmNGixJ6ELuymaQ/1oMGuUDkEF
-----END CERTIFICATE-----
3 changes: 3 additions & 0 deletions rustls-libssl/test-ca/ed25519/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIFAeJeUKTXguiUHfGJmqh5nG8AdqjNDKQy9nctnekBE3
-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions rustls-libssl/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ fn server_key_algorithms() {
server_with_key_algorithm("rsa", "rsa_pkcs1_sha256", "-tls1_2");
server_with_key_algorithm("rsa", "rsa_pkcs1_sha384", "-tls1_2");
server_with_key_algorithm("rsa", "rsa_pkcs1_sha512", "-tls1_2");
server_with_key_algorithm("ed25519", "ed25519", "-tls1_3");
}

const NGINX_LOG_LEVEL: &str = "info";
Expand Down

0 comments on commit cab679f

Please sign in to comment.