Skip to content

OpenSSL 3 FIPS mode - creating encrypted RSA key pair fails with PEM_write_bio_PrivateKey_traditional: initialization error (OpenSSL::PKey::PKeyError) #643

@tarnowsc

Description

@tarnowsc

I'm trying to execute the first example from docs: https://docs.ruby-lang.org/en/master/OpenSSL.html#module-OpenSSL-label-Examples

And I'm not able to execute the following code:

require 'openssl'

key = OpenSSL::PKey::RSA.new 2048
cipher = OpenSSL::Cipher.new 'aes-256-cbc'
pass_phrase = 'my secure pass phrase goes here'

key_secure = key.export cipher, pass_phrase

The error I'm getting is:

irb(main):013:0> key_secure = key.export cipher, pass_phrase
(irb):13:in `export': PEM_write_bio_PrivateKey_traditional: initialization error (OpenSSL::PKey::PKeyError)
        from (irb):13:in `<main>'                    
        from /var/lib/ruby/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /var/lib/ruby/bin/irb:25:in `load'      
        from /var/lib/ruby/bin/irb:25:in `<main>'

The same code works fine without the FIPS mode.

I'm using Ubuntu 22.04LTS with the following versions:

root@b6b9c4cc9cb7:/opt/conjur-server# ruby --version      
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
root@b6b9c4cc9cb7:/opt/conjur-server# openssl version     
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)

...

irb(main):014:0> OpenSSL::VERSION
=> "3.1.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions