httprb / http

HTTP (The Gem! a.k.a. http.rb) - a fast Ruby HTTP client with a chainable API, streaming support, and timeouts
MIT License
3k stars 321 forks source link

SSLERROR occurred when running http method in the executable file: certificate verify failed. #749

Closed Vucius closed 1 year ago

Vucius commented 1 year ago

I was able to run my GUI program normally under RubyMine. Here is the test code:

require 'http'
require 'glimmer-dsl-libui'
require 'json'

class MyWindow
  include Glimmer

  def initialize
    @main_window = window('Hello, World!', 300, 200) {
      horizontal_box {
        @label = label('Hello, Glimmer DSL for LibUI!')
        button('Click me!') {
          on_clicked do
            sss = returnstr
            msg_box('Hello', sss)
          end
        }
      }

      on_closing do
        puts 'Closing window...'
      end
    }
  end

  def show
    @main_window.show
  end
end

def returnstr
  ccoo = 'my_cookie'
  aim_url = 'https://leetcode.com/graphql/'
  submissionlist_data_query =
    {
      "query": "\n    query submissionList($offset: Int!, $limit: Int!, $lastKey: String, $questionSlug: String!, $lang: Int, $status: Int) {\n  questionSubmissionList(\n    offset: $offset\n    limit: $limit\n    lastKey: $lastKey\n    questionSlug: $questionSlug\n    lang: $lang\n    status: $status\n  ) {\n    lastKey\n    hasNext\n    submissions {\n      id\n      title\n      titleSlug\n      status\n      statusDisplay\n      lang\n      langName\n      runtime\n      timestamp\n      url\n      isPending\n      memory\n      hasNotes\n    }\n  }\n}\n    ",
      "variables": {
        "questionSlug": 'two-sum',
        "offset": 0,
        "limit": 20,
        "lastKey": nil
      },
      "operationName": "submissionList"
    }
  submissionlist_data_header = {
    'content-type' => 'application/json',
    'Cookie' => ccoo
  }
  #ctx = OpenSSL::SSL::SSLContext.new
  #ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
  #submissionlist_data = HTTP.post(URI(aim_url), :body => submissionlist_data_query.to_json, :headers => submissionlist_data_header, :ssl_context => ctx)
submissionlist_data = HTTP.post(URI(aim_url), :body => submissionlist_data_query.to_json, :headers => submissionlist_data_header
  p submissionlist_data.code
  submissionlist_data_json = JSON.load(submissionlist_data.body)
  p submissionlist_data_json
  #submissionlist_data_json["data"]["questionSubmissionList"]["submissions"]
  "fuck"
end

my_window = MyWindow.new
my_window.show

However, when I used ocra to package the .rb file into an .exe and ran the .exe, the program crashed.

After disabling certificate verification and repackaging the .exe, the program ran normally.

Although the problem was solved, I am still confused about whether it is an issue with httprb or ocra. I did not continue to investigate and just wanted to share this information here.

tarcieri commented 1 year ago

Certificate verification is handled by Ruby/OpenSSL, at a layer much lower than http.rb.

It sounds like there is something wrong with the certificates in the system truststore.