Skip to content

Commit f463f56

Browse files
committed
Pass through nil as digest when signing certificates
In order to sign certificates with Ed25519 keys, NULL must be passed as md to X509_sign. This NULL is then passed (via ASN1_item_sign_ex) as type to EVP_DigestSignInit. The documentation[1] of EVP_DigestSignInit states that type must be NULL for various key types, including Ed25519. [1]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSignInit.html
1 parent 818aa9f commit f463f56

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

ext/openssl/ossl_x509cert.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,11 @@ ossl_x509_sign(VALUE self, VALUE key, VALUE digest)
539539
const EVP_MD *md;
540540

541541
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
542-
md = ossl_evp_get_digestbyname(digest);
542+
if (NIL_P(digest)) {
543+
md = NULL; /* needed for some key types, e.g. Ed25519 */
544+
} else {
545+
md = ossl_evp_get_digestbyname(digest);
546+
}
543547
GetX509(self, x509);
544548
if (!X509_sign(x509, pkey, md)) {
545549
ossl_raise(eX509CertError, NULL);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MC4CAQAwBQYDK2VwBCIEIFfR9+7eHflbSCNLLWz50cKZG9J/dzNTyYCggFG1MKG9
3+
-----END PRIVATE KEY-----

test/openssl/test_x509cert.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,26 @@ def test_sign_and_verify_dsa_md5
222222
}
223223
end
224224

225+
def test_sign_and_verify_ed25519
226+
# See test_ed25519 in test_pkey.rb
227+
228+
# Ed25519 is not FIPS-approved.
229+
omit_on_fips
230+
231+
begin
232+
ed25519 = Fixtures.pkey("ed25519")
233+
rescue OpenSSL::PKey::PKeyError => e
234+
# OpenSSL < 1.1.1
235+
#
236+
pend "Ed25519 is not implemented" unless openssl?(1, 1, 1)
237+
238+
raise e
239+
end
240+
241+
cert = issue_cert(@ca, ed25519, 1, [], nil, nil, digest: nil)
242+
assert_equal(true, cert.verify(ed25519))
243+
end
244+
225245
def test_dsa_with_sha2
226246
cert = issue_cert(@ca, @dsa256, 1, [], nil, nil, digest: "sha256")
227247
assert_equal("dsa_with_SHA256", cert.signature_algorithm)

0 commit comments

Comments
 (0)