Add support for ML-DSA-44 keys (#39747)

This commit is contained in:
Claire
2026-07-10 13:39:42 +02:00
committed by GitHub
parent ae6898648e
commit 86cdb0bc3d
4 changed files with 6 additions and 4 deletions

View File

@@ -33,7 +33,7 @@ class ActivityPub::LinkedDataSignature
to_be_verified = options_hash + document_hash
keypair.actor if keypair.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), Base64.decode64(signature), to_be_verified)
rescue OpenSSL::PKey::RSAError
rescue OpenSSL::PKey::PKeyError
false
end

View File

@@ -7,6 +7,7 @@ class Multibase
MULTICODEC_PREFIXES = {
'rsa-pub': 0x1205,
'ed25519-pub': 0xED,
'mldsa-44-pub': 0x1210,
}.transform_values do |code|
bytes = []
@@ -66,7 +67,7 @@ class Multibase
else
raise Error, 'Unsupported key type'
end
rescue OpenSSL::PKey::RSAError => e
rescue OpenSSL::PKey::PKeyError => e
raise Error, e
end
end

View File

@@ -101,7 +101,7 @@ class SignedRequest
def verify_signature(keypair, signature, compare_signed_string)
true if keypair.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), signature, compare_signed_string)
rescue OpenSSL::PKey::RSAError
rescue OpenSSL::PKey::PKeyError
nil
end

View File

@@ -29,6 +29,7 @@ class Keypair < ApplicationRecord
enum :type, {
rsa: 0,
ed25519: 1,
'ml-dsa-44': 2,
}, validate: true
validates :uri, presence: true, uniqueness: true, if: -> { account.remote? }
@@ -57,7 +58,7 @@ class Keypair < ApplicationRecord
case type
when 'rsa'
OpenSSL::PKey::RSA.new(private_key || public_key)
when 'ed25519'
when 'ed25519', 'ml-dsa-44'
OpenSSL::PKey.read(private_key || public_key)
end
end