Git Product home page Git Product logo

Comments (14)

ixmatus avatar ixmatus commented on September 28, 2024

I also downgraded openssl from 1.0.1e1 to 0.9.8 and the program still segfaulted.

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

My machine is a MacBook OS X 10.7.x running ghc-7.4.2

I also compiled it on another machine running FreeBSD 9.1 and ghc-7.4.1. Segmentation fault still occurred when attempting to request an https URI.

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

I suspect this might have something to do with the use of unsafePerformIO and the creation of a global IORef instead of wrapping in a withOpenSSL; I'm going to re-wire some things to see if that is the case.

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

It did not have anything to do with the global IORef. I removed all of it and I still receive the segfault - I'm now assuming the use of this:
SSL.contextSetDefaultCiphers ctx

Is the culprit - it might be trying to set a cipher for which newer version of openssl doesn't support? Not sure, digging into that.

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

Okay it was none of those things.

A) The original implementation using IORef was wrong and it was causing it to crash on HTTPS because it was NOT wrapping withOpenSSL I figured this out after inspecting the stack from GDB and noticed there were threads blocking on FFI calls that I think led to the segfault.
B) withOpenSSL doesn't make the end-user use withOpenSSL if they are using the standard convenience functions unless they are setting up their own connection code; in which case use of withOpenSSL is encouraged to keep the unsafe computation "contained".

I'm submitting a pull request with my changes that fix this and clean up the usage of unsafePerformIO and IORef.

from http-streams.

istathar avatar istathar commented on September 28, 2024

So if I understand this correctly, the problem is that you are failing to call withOpenSSL in main? I'm pretty sure it is documented that you need to do so if making a request of an https URL, yeah?

The code that uses that IORef is (suppoed to be) lazy so if you're not using https then you should not hit any of it.

The default SSLContext is there so that we don't need separate get functions for http and https, which seems worth achieving in a convenience API.

AfC

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

Yes I wasn't using withOpenSSL (I wasnt initially clear on that) in my main
but we don't need to. If you look at the diff where you're branching the
connection opener on whether the passed URI leads with http or https, the
do block is wrapped by withOpenSSL. So if you only ever pass an https
leading URI, SSL context won't be set up. I could be naive though. Please
inspect the code and let me know if I'm misunderstanding the code.
On Apr 2, 2013 8:38 PM, "Andrew Cowie" [email protected] wrote:

So if I understand this correctly, the problem is that you are failing to
call withOpenSSL in main? I'm pretty sure it is documented that you need
to do so if making a request of an https URL, yeah?

The code that uses that IORef is (suppoed to be) lazy so if you're not
using https then you should not hit any of it.

The default SSLContext is there so that we don't need separate getfunctions for http and https, which seems worth achieving in a convenience
API.

AfC


Reply to this email directly or view it on GitHubhttps://github.com//issues/18#issuecomment-15813163
.

from http-streams.

istathar avatar istathar commented on September 28, 2024

I'm pretty sure you can only call withOpenSSL once. It'd be nice if it recorded internally whether it had been called or not (certainly my preferred pattern when writing C libraries), but at the moment it's quite an expensive call and reading its implementation it does a lot of work in native code. Probably best not to call it multiple times.

AfC

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

That would make sense, it appears that's what they are saying in the docs too:
Computation of withOpenSSL action initializes the OpenSSL library and computes action.

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

hs-tls looks like a more modern offerring than HsOpenSSL.

from http-streams.

istathar avatar istathar commented on September 28, 2024

@ixmatus you'll have to convince @gregorycollins of that; we've spoken about potentially using the tls package in the Snap Framework, but at the moment it is relatively unreviewed (and has had recent security flaws) and for production code you probably don't want to be relying on it; hence calling out to openssl.

AfC

from http-streams.

ixmatus avatar ixmatus commented on September 28, 2024

Fair enough and thanks for having this lengthy discussion w/ me. You can
close the pull request as I also now understand why you're doing it as you
are. Sorry to waste your time!
On Apr 3, 2013 3:58 AM, "Andrew Cowie" [email protected] wrote:

@ixmatus https://github.com/ixmatus you'll have to convince
@gregorycollins https://github.com/gregorycollins of that; we've spoken
about potentially using the tls package in the Snap Framework, but at
the moment it is relatively unreviewed (and has had recent security flaws)
and for production code you probably don't want to be relying on it; hence
calling out to openssl.

AfC


Reply to this email directly or view it on GitHubhttps://github.com//issues/18#issuecomment-15825612
.

from http-streams.

gregorycollins avatar gregorycollins commented on September 28, 2024

Calling withOpenSSL is absolutely necessary because it initializes some things in the OpenSSL library. It's unfortunately not safe to call concurrently, because it mutates global data structures without taking a lock.

As for using some other library: there are unfortunately no credible and widespread alternatives :(

from http-streams.

istathar avatar istathar commented on September 28, 2024

I'm going to raise a bug on HsOpenSSL to see if we can't hold a lock & a boolean there to allow withOpenSSL to be re-entrant. I've done such things enough times in C code, so surely we can work something out.

AfC

from http-streams.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.