From: Joseph Jones Date: 2015-12-17T21:06:04-07:00 Subject: [ruby-core:72254] [Ruby trunk - Bug #11774] [Open] OpenSSL::PKey.read produces ArgumentError on invalid passphrases --5673862c_7c83e458_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 5, 2015 at 09:54:= 34 MST, code=40temik.me wrote:Issue =2311774 has been reported by Artem Y= akimenko.----------------------------------------Bug =2311774: OpenSSL::P= Key.read produces ArgumentError on invalid passphraseshttps://bugs.ruby-l= ang.org/issues/11774* Author: Artem Yakimenko* Status: Open* Priority: No= rmal* Assignee: * ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) =5B= x86=5F64-darwin15=5D* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOW= N----------------------------------------If we try to read out an RSA enc= rypted key with an invalid passphrase like so:=60=60=60require 'openssl'O= penSSL::PKey.read(=46ile.read(=22=23=7BENV=5B'HOME'=5D=7D/.ssh/id=5Frsa=22= ), 'invalid')=60=60=60We get an argument error:=60=60=60ArgumentError: Co= uld not parse PKey: no start linefrom (pry):6:in =60read'=60=60=60However= , if I understand the situation correctly, it should produce a decode err= or: =60OpenSSL::PKey::RSAError=60, as per the doc:=60=60=60OpenSSL::PKey:= :RSAErrorGeneric exception that is raised if an operation on an RSA PKey = fails unexpectedly or in case an instantiation of an instance of RSA fail= s due to non-conformant input data.=60=60=60Reproduction:1) Create a pass= word protected ssh key (if none exists):ssh-keygen -t rsa -b 40962) Run t= he following snippet (assuming =7E/.ssh/id=5Frsa is the key location)=60=60= =60require 'openssl'OpenSSL::PKey.read(=46ile.read(=22=23=7BENV=5B'HOME'=5D= =7D/.ssh/id=5Frsa=22), 'invalid=5Fpassphrase')=60=60=60Tested on:MacOSX 1= 0.11.1OpenSSL 1.0.2d 9 Jul 2015Ruby 2.1.7Ruby 2.2.3-- https://bugs.ruby-l= ang.org/ --5673862c_7c83e458_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 5, 2015 at 09:54:34 MST, code=40temik.me wrote:
Issue =2311774 has been reported by= Artem Yakimenko.

----------------------------------------
Bug =2311774: OpenSSL::PKey.read produces ArgumentError on invalid pass= phrases
https://bugs.ruby-lang.org/issues/11774

* Author:= Artem Yakimenko
* Status: Open
* Priority: Normal
* Assig= nee:
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) =5Bx86=5F= 64-darwin15=5D
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOW= N
----------------------------------------
If we try to read ou= t an RSA encrypted key with an invalid passphrase like so:
=60=60=60=
require 'openssl'
OpenSSL::PKey.read(=46ile.read(=22=23=7BENV=5B= 'HOME'=5D=7D/.ssh/id=5Frsa=22), 'invalid')
=60=60=60
We get an = argument error:
=60=60=60
ArgumentError: Could not parse PKey: = no start line
from (pry):6:in =60read'
=60=60=60
However, = if I understand the situation correctly, it should produce a decode error= : =60OpenSSL::PKey::RSAError=60, as per the doc:
=60=60=60
Open= SSL::PKey::RSAError
Generic exception that is raised if an operation= on an RSA PKey fails unexpectedly or in case an instantiation of an inst= ance of RSA fails due to non-conformant input data.
=60=60=60
<= br />Reproduction:
1) Create a password protected ssh key (if none e= xists):
ssh-keygen -t rsa -b 4096
2) Run the following snippet = (assuming =7E/.ssh/id=5Frsa is the key location)
=60=60=60
requ= ire 'openssl'

OpenSSL::PKey.read(=46ile.read(=22=23=7BENV=5B'H= OME'=5D=7D/.ssh/id=5Frsa=22), 'invalid=5Fpassphrase')
=60=60=60
Tested on:
MacOSX 10.11.1
OpenSSL 1.0.2d 9 Jul 2015
Ruby = 2.1.7
Ruby 2.2.3



--
https://bugs.ruby-l= ang.org/
--5673862c_7c83e458_16c--