Bug #5600

OpenSSL::X509::Request can't sign() an OpenSSL::PKey::EC

Added by scaligo (Steve Caligo) about 6 years ago. Updated over 1 year ago.

Target version:
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]


Unlike the PKey::DSA and PKey::RSA classes, PKey::EC provides a private_key?() rather than private?() method and is thus incompatible with the other OpenSSL classes that rely on them, i.e. it makes impossible to generate a certificate signing request:

key ='secp521r1')

req =
req.public_key = key
req.subject = OpenSSL::X509::Name.parse('CN=whatever')

which produces the error:

in sign': undefined methodprivate?' for #OpenSSL::PKey::EC:0x000000021b4980 (NoMethodError)

ossl_pkey_ec.c should either:
- rb_define_method() the missing private? and public? methods
- rename public_key? to public? and private_key? to private?

Judging by the source code, this should be present in branch 1.8 as well.

Related issues

Related to Ruby trunk - Bug #6567: Let OpenSSL::PKey::EC follow the general PKey interface Closed


#1 [ruby-core:40854] Updated by MartinBosslet (Martin Bosslet) about 6 years ago

  • Status changed from Open to Assigned
  • Assignee set to MartinBosslet (Martin Bosslet)
  • Target version set to 2.0.0

#2 [ruby-core:45540] Updated by MartinBosslet (Martin Bosslet) over 5 years ago

Unfortunately it's not done by simply renaming the methods appropriately. It still would fail because OpenSSL::PKey::EC#public_key returns an OpenSSL::PKey::EC::Point instead of another OpenSSL::PKey::EC, and as a consequence, there's no reference to an EVP_PKEY that is needed internally. The whole EC interface needs an overhaul. I'll set up a parent task referencing all the issues that piled up since the release of 1.9.3. The goal would be to make EC follow the general PKey interface, allowing to use them interchangeably wherever a PKey instance is expected.

#3 [ruby-core:52444] Updated by mame (Yusuke Endoh) almost 5 years ago

  • Subject changed from OpenSSL::X509::Request can't sign() an OpenSSL::PKey::EC to OpenSSL::X509::Request can't sign() an OpenSSL::PKey::EC
  • Target version changed from 2.0.0 to 2.6

It is too late for "an overhaul". Postponing to next minor.

Yusuke Endoh

#4 Updated by adam (Adam M) over 2 years ago

Any updates on this?

#5 Updated by zzak (Zachary Scott) over 2 years ago

  • Assignee changed from MartinBosslet (Martin Bosslet) to openssl

#6 [ruby-core:76037] Updated by rhenium (Kazuki Yamaguchi) over 1 year ago

  • Status changed from Assigned to Closed

r55098 (openssl: add OpenSSL::PKey::EC#private? and #public?, 2016-05-21) added OpenSSL::PKey::EC#private?. The code should work now.

Please see also #6567.

#7 Updated by rhenium (Kazuki Yamaguchi) over 1 year ago

  • Related to Bug #6567: Let OpenSSL::PKey::EC follow the general PKey interface added

Also available in: Atom PDF