ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:60588] [ruby-trunk - Bug #9504] [Open] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
       [not found] <redmine.issue-9504.20140208204325@ruby-lang.org>
@ 2014-02-08 20:43 ` ms
  2014-02-08 20:46 ` [ruby-core:60589] [ruby-trunk - Bug #9504] " ms
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: ms @ 2014-02-08 20:43 UTC (permalink / raw
  To: ruby-core

Issue #9504 has been reported by Mark Schloesser.

----------------------------------------
Bug #9504: X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
https://bugs.ruby-lang.org/issues/9504

* Author: Mark Schloesser
* Status: Open
* Priority: Normal
* Assignee: 
* Category: ext/openssl
* Target version: next minor
* ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
Ruby's openssl extension tries to load certificates as PEM format first, and on failure will try to do DER / ASN1. The PEM format loading ignores junk in the beginning and end of the given buffer, which can lead to a DER certificate being incorrectly loaded. This occurs on 1.9.3 and 2.2.0.

More concretely this occurs in the wild when a server certificate has a X509 extension comment that includes another certificate in PEM format. Example below.

To fix this, one could allow the user to optionally specify the format, and do DER directly if specified. That would keep things backwards compatible and allow these certificates to be correctly parsed.

Example certificate - http://pastebin.com/V90dDSez
Openssl output for this - http://pastebin.com/GSsLtP8J

Ruby script to show the bug/problem - http://pastebin.com/Q7ap7FjN

I currently patched my ruby version (1.9.3) like this: http://pastebin.com/HzyyAm0p

Thanks for feedback and incorporating the patch / a similar solution for this into Ruby.



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:60589] [ruby-trunk - Bug #9504] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
       [not found] <redmine.issue-9504.20140208204325@ruby-lang.org>
  2014-02-08 20:43 ` [ruby-core:60588] [ruby-trunk - Bug #9504] [Open] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1) ms
@ 2014-02-08 20:46 ` ms
  2014-03-03 16:29 ` [ruby-core:61259] [ruby-trunk - Bug #9504] [Assigned] " nagachika00
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: ms @ 2014-02-08 20:46 UTC (permalink / raw
  To: ruby-core

Issue #9504 has been updated by Mark Schloesser.


My patch means you can load the certificate like this:

    x509 = OpenSSL::X509::Certificate.new(cert, "DER")

I guess having some module level constants for this (`FILETYPE_PEM`, `FILETYPE_ASN1`) would be better. Sadly I'm not a ruby guy by day, and I'd appreciate if someone cleans this up to be more clean :)


----------------------------------------
Bug #9504: X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
https://bugs.ruby-lang.org/issues/9504#change-45032

* Author: Mark Schloesser
* Status: Open
* Priority: Normal
* Assignee: 
* Category: ext/openssl
* Target version: next minor
* ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
Ruby's openssl extension tries to load certificates as PEM format first, and on failure will try to do DER / ASN1. The PEM format loading ignores junk in the beginning and end of the given buffer, which can lead to a DER certificate being incorrectly loaded. This occurs on 1.9.3 and 2.2.0.

More concretely this occurs in the wild when a server certificate has a X509 extension comment that includes another certificate in PEM format. Example below.

To fix this, one could allow the user to optionally specify the format, and do DER directly if specified. That would keep things backwards compatible and allow these certificates to be correctly parsed.

Example certificate - http://pastebin.com/V90dDSez
Openssl output for this - http://pastebin.com/GSsLtP8J

Ruby script to show the bug/problem - http://pastebin.com/Q7ap7FjN

I currently patched my ruby version (1.9.3) like this: http://pastebin.com/HzyyAm0p

Thanks for feedback and incorporating the patch / a similar solution for this into Ruby.



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:61259] [ruby-trunk - Bug #9504] [Assigned] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
       [not found] <redmine.issue-9504.20140208204325@ruby-lang.org>
  2014-02-08 20:43 ` [ruby-core:60588] [ruby-trunk - Bug #9504] [Open] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1) ms
  2014-02-08 20:46 ` [ruby-core:60589] [ruby-trunk - Bug #9504] " ms
@ 2014-03-03 16:29 ` nagachika00
  2015-09-13  3:10 ` [ruby-core:70745] [Ruby trunk - Bug #9504] " zzak
  2019-08-11 17:41 ` [ruby-core:94278] [Ruby master Bug#9504] " merch-redmine
  4 siblings, 0 replies; 5+ messages in thread
From: nagachika00 @ 2014-03-03 16:29 UTC (permalink / raw
  To: ruby-core

Issue #9504 has been updated by Tomoyuki Chikanaga.

Status changed from Open to Assigned
Assignee set to Martin Bosslet

Hello, Mark.
Thank you for your reporting.

Martin, could you handle this?

----------------------------------------
Bug #9504: X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
https://bugs.ruby-lang.org/issues/9504#change-45599

* Author: Mark Schloesser
* Status: Assigned
* Priority: Normal
* Assignee: Martin Bosslet
* Category: ext/openssl
* Target version: next minor
* ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
Ruby's openssl extension tries to load certificates as PEM format first, and on failure will try to do DER / ASN1. The PEM format loading ignores junk in the beginning and end of the given buffer, which can lead to a DER certificate being incorrectly loaded. This occurs on 1.9.3 and 2.2.0.

More concretely this occurs in the wild when a server certificate has a X509 extension comment that includes another certificate in PEM format. Example below.

To fix this, one could allow the user to optionally specify the format, and do DER directly if specified. That would keep things backwards compatible and allow these certificates to be correctly parsed.

Example certificate - http://pastebin.com/V90dDSez
Openssl output for this - http://pastebin.com/GSsLtP8J

Ruby script to show the bug/problem - http://pastebin.com/Q7ap7FjN

I currently patched my ruby version (1.9.3) like this: http://pastebin.com/HzyyAm0p

Thanks for feedback and incorporating the patch / a similar solution for this into Ruby.



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:70745] [Ruby trunk - Bug #9504] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
       [not found] <redmine.issue-9504.20140208204325@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2014-03-03 16:29 ` [ruby-core:61259] [ruby-trunk - Bug #9504] [Assigned] " nagachika00
@ 2015-09-13  3:10 ` zzak
  2019-08-11 17:41 ` [ruby-core:94278] [Ruby master Bug#9504] " merch-redmine
  4 siblings, 0 replies; 5+ messages in thread
From: zzak @ 2015-09-13  3:10 UTC (permalink / raw
  To: ruby-core

Issue #9504 has been updated by Zachary Scott.

Assignee changed from Martin Bosslet to openssl

----------------------------------------
Bug #9504: X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
https://bugs.ruby-lang.org/issues/9504#change-54124

* Author: Mark Schloesser
* Status: Assigned
* Priority: Normal
* Assignee: openssl
* ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
Ruby's openssl extension tries to load certificates as PEM format first, and on failure will try to do DER / ASN1. The PEM format loading ignores junk in the beginning and end of the given buffer, which can lead to a DER certificate being incorrectly loaded. This occurs on 1.9.3 and 2.2.0.

More concretely this occurs in the wild when a server certificate has a X509 extension comment that includes another certificate in PEM format. Example below.

To fix this, one could allow the user to optionally specify the format, and do DER directly if specified. That would keep things backwards compatible and allow these certificates to be correctly parsed.

Example certificate - http://pastebin.com/V90dDSez
Openssl output for this - http://pastebin.com/GSsLtP8J

Ruby script to show the bug/problem - http://pastebin.com/Q7ap7FjN

I currently patched my ruby version (1.9.3) like this: http://pastebin.com/HzyyAm0p

Thanks for feedback and incorporating the patch / a similar solution for this into Ruby.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94278] [Ruby master Bug#9504] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
       [not found] <redmine.issue-9504.20140208204325@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-09-13  3:10 ` [ruby-core:70745] [Ruby trunk - Bug #9504] " zzak
@ 2019-08-11 17:41 ` merch-redmine
  4 siblings, 0 replies; 5+ messages in thread
From: merch-redmine @ 2019-08-11 17:41 UTC (permalink / raw
  To: ruby-core

Issue #9504 has been updated by jeremyevans0 (Jeremy Evans).

Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN)
Status changed from Assigned to Feedback
File nested-asn1-9504.patch added

I worked on implementing support for adding a :format keyword to `OpenSSL::X509::Certificate#initialize`, allowing you to specify `format: :der` if you didn't want to try loading it as a PEM.  A patch for that is attached (for the ruby-openssl repository).

For the certificate provided, using LibreSSL 3.0.0, both `PEM_read_bio_X509` and `d2i_X509_bio` with the certificate return NULL, with the OpenSSL error: "nested asn1 error".  Are you actually able to get the certificate to work with a modern version of OpenSSL or LibreSSL?

----------------------------------------
Bug #9504: X509 certificate incorrectly loaded (because of try-pem-first-else-asn1)
https://bugs.ruby-lang.org/issues/9504#change-80601

* Author: rep (Mark Schloesser)
* Status: Feedback
* Priority: Normal
* Assignee: openssl
* Target version: 
* ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
* Backport: 
----------------------------------------
Ruby's openssl extension tries to load certificates as PEM format first, and on failure will try to do DER / ASN1. The PEM format loading ignores junk in the beginning and end of the given buffer, which can lead to a DER certificate being incorrectly loaded. This occurs on 1.9.3 and 2.2.0.

More concretely this occurs in the wild when a server certificate has a X509 extension comment that includes another certificate in PEM format. Example below.

To fix this, one could allow the user to optionally specify the format, and do DER directly if specified. That would keep things backwards compatible and allow these certificates to be correctly parsed.

Example certificate - http://pastebin.com/V90dDSez
Openssl output for this - http://pastebin.com/GSsLtP8J

Ruby script to show the bug/problem - http://pastebin.com/Q7ap7FjN

I currently patched my ruby version (1.9.3) like this: http://pastebin.com/HzyyAm0p

Thanks for feedback and incorporating the patch / a similar solution for this into Ruby.

---Files--------------------------------
nested-asn1-9504.patch (4.75 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-11 17:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-9504.20140208204325@ruby-lang.org>
2014-02-08 20:43 ` [ruby-core:60588] [ruby-trunk - Bug #9504] [Open] X509 certificate incorrectly loaded (because of try-pem-first-else-asn1) ms
2014-02-08 20:46 ` [ruby-core:60589] [ruby-trunk - Bug #9504] " ms
2014-03-03 16:29 ` [ruby-core:61259] [ruby-trunk - Bug #9504] [Assigned] " nagachika00
2015-09-13  3:10 ` [ruby-core:70745] [Ruby trunk - Bug #9504] " zzak
2019-08-11 17:41 ` [ruby-core:94278] [Ruby master Bug#9504] " merch-redmine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).