Skip to content

Fix to support windows#164

Merged
dblock merged 9 commits intoslack-ruby:masterfrom
leifcr:bugfix_openssl_windows_compatible_detection
Sep 13, 2017
Merged

Fix to support windows#164
dblock merged 9 commits intoslack-ruby:masterfrom
leifcr:bugfix_openssl_windows_compatible_detection

Conversation

@leifcr
Copy link
Copy Markdown
Contributor

@leifcr leifcr commented Sep 12, 2017

The syntax for grep/awk/sed is problematic under cmdline on windows

This removes the dependency of awk/grep/sed., openssldir is parsed in ruby instead.

This can close #91, since everything else works as it should on Windows.

@dangerpr-bot
Copy link
Copy Markdown

dangerpr-bot commented Sep 12, 2017

1 Warning
⚠️ There’re library changes, but not tests. That’s OK as long as you’re refactoring existing code.

Generated by 🚫 danger

Comment thread lib/slack/web/config.rb Outdated
self.user_agent = "Slack Ruby Client/#{Slack::VERSION}"
self.ca_path = `openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g'`
self.ca_file = "#{ca_path}/ca-certificates.crt"
self.ca_path = openssl_ca_path if ca_path.nil?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be just using OpenSSL::X509::DEFAULT_CERT_DIR and OpenSSL::X509::DEFAULT_CERT_FILE ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. OpenSSL::X509::DEFAULT_CERT_DIR points to the correct ca-folder.
However, OpenSSL::X509::DEFAULT_CERT_FILE points to cert.pem and not to ca-certificates.crt Not sure if .pem or .crt is the correct to use here. ?

Looking closer at this `openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g'` returns /usr/lib/ssl on *nix, which is results in ca_file to be /usr/lib/ssl/ca-certificates.crt, which both are wrong paths/files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (openssl version -a) does not work on MacOS Sierra (10.12) also.

My OPENSSLDIR is /System/Library/OpenSSL.

But /System/Library/OpenSSL/ca-certificates.crt does not exist.

When using system ruby then OpenSSL::X509::DEFAULT_CERT_FILE points to /System/Library/OpenSSL/cert.pem which also does not exist.

But at least it works with own compiled ruby.

Also it is reasonable to use SSL_CERT_DIR and SSL_CERT_FILE env variables before the openssl default. (like https://github.com/mikz/httpclient/blob/ba21d0d44c9f5f4602c7fc151f7c24f827480361/lib/httpclient/ssl_config.rb#L418-L419)

As those are used by OpenSSL to set custom cert dir/path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change the pr to use OpenSSL::X509::DEFAULT_CERT_DIR and OpenSSL::X509::DEFAULT_CERT_FILE, since that works on nix, win and osx.

Comment thread CHANGELOG.md Outdated
@@ -1,5 +1,5 @@
### 0.9.2 (Next)

* [#163](https://github.com/slack-ruby/slack-ruby-client/pull/164): Use OpenSSL::X509::DEFAULT_CERT_DIR and OpenSSL::X509::DEFAULT_CERT_FILE for default ca_cert and ca_file [@leifcr](https://github.com/leifcr)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to highlight code constants as code with `CODE`

Comment thread lib/slack/web/config.rb Outdated
@@ -1,3 +1,4 @@
require 'openssl'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would make OpenSSL hard dependency.

Might be better to wrap it in a block and rescue LoadError.

Comment thread lib/slack/web/config.rb Outdated
self.user_agent = "Slack Ruby Client/#{Slack::VERSION}"
self.ca_path = `openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g'`
self.ca_file = "#{ca_path}/ca-certificates.crt"
self.ca_path = OpenSSL::X509::DEFAULT_CERT_DIR
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If OpenSSL is not defined (guess we don't want hard dependency) then this would crash. So this can be done as

self.ca_path = OpenSSL::X509::DEFAULT_CERT_DIR if defined?(OpenSSL)

@leifcr
Copy link
Copy Markdown
Contributor Author

leifcr commented Sep 12, 2017

@mikz I added check for OpenSSL, so that vars are set to nil if missing as suggested.

Comment thread lib/slack/web/faraday/connection.rb Outdated
options[:headers]['User-Agent'] = user_agent if user_agent
options[:proxy] = proxy if proxy
options[:ssl] = { ca_path: ca_path, ca_file: ca_file }
options[:ssl] = { ca_path: ca_path, ca_file: ca_file } unless ca_path.nil? || ca_file.nil?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be tricky.

Do both options have to be specified? Can't just one do the trick? I think one certificate chain can work just fine as well as just the cert directory.

So this could be nicer as if ca_path || ca_file. Unless with || can be evil.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. if ca_path || ca_file is better. And only one needs to be present.

@mikz
Copy link
Copy Markdown
Contributor

mikz commented Sep 12, 2017

@leifcr great change! I commented one last time #164 (comment) to clarify the ca info assignment.

Then it would get mine 👍 Good job 🥇

Comment thread CHANGELOG.md
@@ -1,5 +1,5 @@
### 0.9.2 (Next)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put back the line, please.

Comment thread CHANGELOG.md Outdated
@@ -1,5 +1,5 @@
### 0.9.2 (Next)

* [#163](https://github.com/slack-ruby/slack-ruby-client/pull/164): Use `OpenSSL::X509::DEFAULT_CERT_DIR` and `OpenSSL::X509::DEFAULT_CERT_FILE` for default ca_cert and ca_file [@leifcr](https://github.com/leifcr)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this in the same format as everything else, needs a - before your name and a . at the end.

Comment thread lib/slack/web/config.rb Outdated
begin
require 'openssl'
rescue LoadError # rubocop:disable Lint/HandleExceptions
end
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a great place to put this, lib/slack-ruby-client.rb is better, it has all the require.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblock Agree. Will move it there.

@dblock
Copy link
Copy Markdown
Collaborator

dblock commented Sep 12, 2017

Made some minor comments. Thanks for making this happen @leifcr. Do you think we can get a Windows CI somewhere?

@mikz
Copy link
Copy Markdown
Contributor

mikz commented Sep 12, 2017

@dblock seen https://www.appveyor.com a few times.

@leifcr
Copy link
Copy Markdown
Contributor Author

leifcr commented Sep 12, 2017

@mikz and @dblock Thanks for feedback. Appveyor supports ruby: https://www.appveyor.com/docs/lang/ruby/

@dblock
Copy link
Copy Markdown
Collaborator

dblock commented Sep 12, 2017

Run rubocop -a ; rubocop --auto-gen-config to fix CI.

@dblock
Copy link
Copy Markdown
Collaborator

dblock commented Sep 12, 2017

@leifcr If you want to PR Appveyor support (appveyor.yml, etc.), I can help enable if something needs to be done here. I used it in https://github.com/Waffle/waffle and https://github.com/resourcelib/resourcelib :)

@leifcr
Copy link
Copy Markdown
Contributor Author

leifcr commented Sep 13, 2017

@dblock I'll create a new branch for Appveyor and do a separate PR For that.

@dblock dblock merged commit 385b30b into slack-ruby:master Sep 13, 2017
@dblock
Copy link
Copy Markdown
Collaborator

dblock commented Sep 13, 2017

Merged, thanks.

@leifcr
Copy link
Copy Markdown
Contributor Author

leifcr commented Sep 20, 2017

Thanks

@leifcr leifcr deleted the bugfix_openssl_windows_compatible_detection branch September 20, 2017 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Windows

4 participants