njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

Add support for encrypted key files, with a passphrase, to Client::key_file=() #71

Closed brianvh closed 8 years ago

brianvh commented 8 years ago

Hi. I didn't see any info for submitting PRs to the main project, but when I realized how simple a change this was, sending the request seemed to be the best option.

I ran into this need because the app I'm building, which uses MQTT, needs to have the cert files added to the repo. Even though the repo is private, having an un-encrypted private key file is still a non-starter for us, security-wise.

This solution allows for the optional addition of a passphrase, along with the path to the private key file, as an Array tuple. This array is then deconstructed down into the original path argument, and a passphrase argument, if present.

When these two arguments, the second of which might be nil, are passed to OpenSSL::PKey::RSA.new(), it basically just works.

I've added two additional RSpec examples, specific to the private key file:

I've also generated an encrypted version of spec/fixtures/client.key, named client.pass.key, which has been AES256 encrypted, using a passphrase of mqtt.

brianvh commented 8 years ago

Hm... Not sure what the cause of those travis bundle errors are. I'm not a travis-ci user, nor have I used this form of the bundle command:

bundle install --jobs=3 --retry=3

But, if this is something you want me to try and track down, I'm certainly willing to do so. Just point me in the right direction.

I'm guessing I might need to install all of the ruby versions you're testing against, and then run those builds locally to ensure they all work? But, that wouldn't replicate the travis-ci environment, so I'm not sure how useful that would ultimately be...

njh commented 8 years ago

Thanks for this pull request Brian. There shouldn't be anything different/special about the the Travis environment.

I suspect that the problems aren't related to your change but have something to do with a new version of the Gem gem. I will try re-running the tests on Master.

njh commented 8 years ago

Hm, build just succeeded: https://travis-ci.org/njh/ruby-mqtt/builds/87757971

njh commented 8 years ago

Unable to re-produce the Travis errors. I checked out your branch and it works fine on my own machine:

$ rbenv version
1.9.3-p551 (set by /Users/humfrn01/Projects/ruby-mqtt/.ruby-version)
$ ruby --version
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin14.5.0]
$ bundle --version
Bundler version 1.11.2
$ gem --version
2.5.2
$ bundle install --jobs=3 --retry=3
Resolving dependencies...
Using rake 10.4.2
Using diff-lcs 1.2.5
Using docile 1.1.5
Using mqtt 0.4.0 from source at `.`
Using multi_json 1.11.1
Using rspec-support 3.0.4
Using simplecov-html 0.9.0
Using yard 0.8.7.6
Using bundler 1.11.2
Using rspec-core 3.0.4
Using rspec-expectations 3.0.4
Using rspec-mocks 3.0.4
Using simplecov 0.9.2
Using rspec 3.0.0
Bundle complete! 6 Gemfile dependencies, 14 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ bundle exec rake 
/Users/humfrn01/.rbenv/versions/1.9.3-p551/bin/ruby -I/Users/humfrn01/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rspec-core-3.0.4/lib:/Users/humfrn01/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rspec-support-3.0.4/lib -S /Users/humfrn01/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rspec-core-3.0.4/exe/rspec ./spec/mqtt_client_spec.rb ./spec/mqtt_packet_spec.rb ./spec/mqtt_proxy_spec.rb ./spec/mqtt_sn_packet_spec.rb ./spec/mqtt_version_spec.rb ./spec/zz_client_integration_spec.rb
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 11.13 seconds (files took 0.27677 seconds to load)
692 examples, 0 failures
Coverage report generated for RSpec to /Users/humfrn01/Projects/ruby-mqtt/coverage. 2999 / 3052 LOC (98.26%) covered.
njh commented 8 years ago

Thanks for submitting the PR!

njh commented 8 years ago

Problem was with a dodgy version of Bundler on Travis.

Fixed with 7e7a7de3c196aeb4ccb8368792e507dd32c38f97

brianvh commented 8 years ago

You're welcome. Thanks for the quick merge turnaround!