karlentwistle / ruby_home

Ruby HAP Server - HomeKit support for the Rubyist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to pair ("setup code is incorrect")

tpolly opened this issue Β· comments

Hi there!
I seem to be unable to add RubyHome to HomeKit (iOS 12.1.4, RubyHome running on Debian 9.8, Ruby 2.4.0), it says the code is incorrect (though I'm pretty sure i haven't mistyped it a hundred times). Pairing with HomeBridge works though, so I think the iOS-Devices are fine. I've tried resetting everything several times by deleting the yml files, but the new codes didn't work either.

I've looked at it - this check fails. The values look something like @M="af70fee65c32f5ccffd292e394a23bfccba43463fd9c481b96c6a6b7ecf3ffaa95ea6f06eb2349e5721ca7a7f0ee9042305d139f3edceab077d5ef9eb4137465"
client_M="\xF8\x00\x00\x8C\r\x7F\x00\x00\xA0H\x02\x8C\r\x7F\x00\x00a9d23346f1e4f698b01240ad830cf029d5d57fc79f1b1fc5e2c40862dfb3828fd2c58aa80f678a45a7f4d78b9c4ac33fec5546f2a10430a3"

I don't really know anything about SRP...
Any ideas? Thanks for your help!

Hey, @tpolly thanks very much for providing me with the information. I was just wondering if you could provide me with a further piece of information. What version of the RubyHome gem are you running?

You can find this out with the following command:

gem list ruby_home

Hi @karlentwistle,
Thanks so much for the quick reply!
I cloned the repo today (git version eb0ce13), version number is 0.1.20.

Ok, that's great. I thought I'd check just in case it was an older version πŸ˜„

Would you be able to share another piece of information with me, please? If possible could you please run the following two commands, from within the root of the project, to deleting the yml files again.

rm accessory_info.yml
rm identifier_cache.yml

Then run

DEBUG=true bin/ruby_home

Then please attempt the pairing again but copy and paste the entire output that has occurred.

Thanks!

This is the terminal output when I try to pair:

Please enter this code with your HomeKit app on your iOS device to pair with RubyHome                       
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     
    β”‚ 326-45-511 β”‚    
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     
                       
Listening on 0.0.0.0:4567
[2019-02-20 09:16:56] INFO  WEBrick 1.3.1
[2019-02-20 09:16:56] INFO  ruby 2.4.0 (2016-12-24) [x86_64-linux]
D, [2019-02-20T09:16:56.049801 #3892] DEBUG -- : Session
D, [2019-02-20T09:16:56.050020 #3892] DEBUG -- : #<RubyHome::HAP::Session:0x0055e6d2579090 @socket=#<TCPSocket:fd 16>, @encrypter_class=RubyHome::HAP::Session::Encrypter, @decrypter_class=RubyHome::HAP::Decrypter>
D, [2019-02-20T09:16:56.051575 #3892] DEBUG -- : Request
D, [2019-02-20T09:16:56.051719 #3892] DEBUG -- : {:method=>0, :state=>1}
D, [2019-02-20T09:16:56.096339 #3892] DEBUG -- : Response
D, [2019-02-20T09:16:56.096423 #3892] DEBUG -- : {:salt=>"l\\\xF1?\xFA\x9E\xB0 \xAE\xD9\xB0\x92\v\x90\\\x95", :public_key=>"b\x98\x8F\x92\xF4af\xA4x\x7F\xAFR+\\\xE2\xCE^\xE10\x12\xD9\xB8X\xCDz\xD7cF^c\x1C\xFF\xA0\xB3\n\xA7\n\xD2\xEB\xA7aUsb5\xCCX\xEE}\xD7\x14\x00\xCA\xB0F\x8D\xD8rW\xD9\xCF\x84\x04}\xF2\x93\xCA\xBC\x16\x10\xE4\x86\xF9\\\v\x9C\xC6\xC7\x8F\x81\x90\xD0r\xA9\xFA\xBB\xDC\x17\x9A\xBCH5\xDF\xAF;Kg\x88\xF9\xDEq:\xE4\x14\x80\x86\xD3\xAE\xC0B\x1D+O(\x90\x9D\xDBm\xE6_E8\xA6\xF6v\x14\xDE\xF9\x84KA\xC3c\xFA\xA7<VU\xB9\x98\x92(\x89oE\x9D\xEF\x16Z;\x06I\xFF\xD1\xCA\n8\xE4}~\x97\xC1\xD2\xA5F\x8E\xCE\x90{u\xAD\xBF%\xD6\x04}\x87\xEF\xBBZ\xFA\x92\x15\x96\x1F\x15\a\x86K\xF6p\xA1U\x00imsH\t\xFD\xD0\x83?\x9D\xCD\b~\x113g\xF1=\x0E\xFD\xFDy\x12\xF1\xE3%eF\x92w8\xB3\xFB\x8F\x13km\xE9\xD5\xF9\xC8\x8B\x9F\x9E\xF5\xA44\e\xB9N\x12\xC3\xCD\xC2\xFCwH5\f\xA2\x0Een\xF1\xB6\xFD\xE6X\xFE\xB8\xCA\x9BpM\x80T\x87u\x9A\xE42w\xAC\x90\xFA\xCC\xEC\xEC\xD5<\xB0\xBC3m<p\x8D\x13\xA6\x10Z\xB9\x17\x90\x01\xC1982\xB7\x81\xCF\x87.S\xFD\x90\x94,\x12\x8BF\xAB\xAA\xB2\xA5\xEAV\x12gI/8W\x83\x19\xD2\xD2\xD8\xFF33Q=mVVw\xBF\xC8\x04\x8D%\x93x\x7F\xCCwi\xDAJ\xBB\xEAUdP\xFA\x05\xEC\x1E\xBB<\x13\xACZn\x8C\xE0=\x97_\xEF\x86\xC8HZ9\x105\x94", :state=>2}
172.20.10.1 - - [20/Feb/2019:09:16:56 +0100] "POST /pair-setup HTTP/1.1" 200 409 0.0515
D, [2019-02-20T09:17:03.481987 #3892] DEBUG -- : Session
D, [2019-02-20T09:17:03.482411 #3892] DEBUG -- : #<RubyHome::HAP::Session:0x0055e6d2579090 @socket=#<TCPSocket:fd 16>, @encrypter_class=RubyHome::HAP::Session::Encrypter, @decrypter_class=RubyHome::HAP::Decrypter, @srp_session={:B=>"62988f92f46166a4787faf522b5ce2ce5ee13012d9b858cd7ad763465e631cffa0b30aa70ad2eba76155736235cc58ee7dd71400cab0468dd87257d9cf84047df293cabc1610e486f95c0b9cc6c78f8190d072a9fabbdc179abc4835dfaf3b4b6788f9de713ae4148086d3aec0421d2b4f28909ddb6de65f4538a6f67614def9844b41c363faa73c5655b9989228896f459def165a3b0649ffd1ca0a38e47d7e97c1d2a5468ece907b75adbf25d6047d87efbb5afa9215961f1507864bf670a15500696d734809fdd0833f9dcd087e113367f13d0efdfd7912f1e3256546927738b3fb8f136b6de9d5f9c88b9f9ef5a4341bb94e12c3cdc2fc7748350ca20e656ef1b6fde658feb8ca9b704d805487759ae43277ac90faccececd53cb0bc336d3c708d13a6105ab9179001c1393832b781cf872e53fd90942c128b46abaab2a5ea561267492f38578319d2d2d8ff3333513d6d565677bfc8048d2593787fcc7769da4abbea556450fa05ec1ebb3c13ac5a6e8ce03d975fef86c8485a39103594", :b=>"1246c7ca3d074a1dc85ed19af93e72d4eddbd87975b2403c74027e7ea071a4cc", :I=>"Pair-Setup", :s=>"6c5cf13ffa9eb020aed9b0920b905c95", :v=>"7122c17ac84d1acbcd72df42d8653af94a6479f3327ca07ea1a31e0d5f398fd1f8dab39638745000809bb95b903dbc0ac03ac241ce4d171672cee4a0c9b44634c2798b71d86f341e96403a3a48b38e62038258a7e7f68a40c2b97426f15d06c82cee894251d19676918fecf0d11f1388962aefa803c28c4cce607308b979e317e69e5f184682e469f202d1711d006993f1e72e39f77431c475417bf08c765a0a82b586277da00ad69265932977351c3c01f3353537ad6ec30750cc0f02316ec0715064bebaed364f33a5ea83ecc6558fdfdfc9b07313d62e8fc23d6277ff60e65ad8fff0370245e296035ab4e56563322545832ec1d2e817014b10e7991c72a7ee3f8663d0626ba243fd470502cbbe4f0a698b1795aa8f16e33b01f91cc73929c150615f4d0b91a9f4ec56015b7d27f5298e7ccc46042a37be3efceae1e55ef062c8de180d9902c7102efb804e9dde64cfca8e5eefbde6cfbbc8f25d995775615e8ce1022d7eaccf4841e3b901a3be15c70c7d1b1507cfb8f514e43a37aa1a1b"}>
D, [2019-02-20T09:17:03.483026 #3892] DEBUG -- : Request
D, [2019-02-20T09:17:03.483106 #3892] DEBUG -- : {:state=>3, :public_key=>"\xA3\x98\x12N\x0F\xC0y/8\xCCK\x1E/\xC5\xA6&\xDA\x8C\x7Fj\xDF\xC2\xD2\x83\x15\xFAr\xF4M\x12?\x03\f\x18\xF5\xC4;D\xD1];\xA9\x8F\x9D\xD2\xBDs6\xE5\x88(r5)\xAB\x10\x82\xA9\x05\xEC\xEBvGDo\xCA\xE6\x0E\x85`\eYIr\x84\xE1Xh\xB5\xA6\xE4!\x88\x8D\xE3o\x98\xAB\x85\x14\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, :error=>2}
172.20.10.1 - - [20/Feb/2019:09:17:03 +0100] "POST /pair-setup HTTP/1.1" 200 6 0.0237
D, [2019-02-20T09:17:03.637334 #3892] DEBUG -- : Session
D, [2019-02-20T09:17:03.637797 #3892] DEBUG -- : #<RubyHome::HAP::Session:0x0055e6d2579090 @socket=#<TCPSocket:fd 16>, @encrypter_class=RubyHome::HAP::Session::Encrypter, @decrypter_class=RubyHome::HAP::Decrypter, @srp_session={:B=>"62988f92f46166a4787faf522b5ce2ce5ee13012d9b858cd7ad763465e631cffa0b30aa70ad2eba76155736235cc58ee7dd71400cab0468dd87257d9cf84047df293cabc1610e486f95c0b9cc6c78f8190d072a9fabbdc179abc4835dfaf3b4b6788f9de713ae4148086d3aec0421d2b4f28909ddb6de65f4538a6f67614def9844b41c363faa73c5655b9989228896f459def165a3b0649ffd1ca0a38e47d7e97c1d2a5468ece907b75adbf25d6047d87efbb5afa9215961f1507864bf670a15500696d734809fdd0833f9dcd087e113367f13d0efdfd7912f1e3256546927738b3fb8f136b6de9d5f9c88b9f9ef5a4341bb94e12c3cdc2fc7748350ca20e656ef1b6fde658feb8ca9b704d805487759ae43277ac90faccececd53cb0bc336d3c708d13a6105ab9179001c1393832b781cf872e53fd90942c128b46abaab2a5ea561267492f38578319d2d2d8ff3333513d6d565677bfc8048d2593787fcc7769da4abbea556450fa05ec1ebb3c13ac5a6e8ce03d975fef86c8485a39103594", :b=>"1246c7ca3d074a1dc85ed19af93e72d4eddbd87975b2403c74027e7ea071a4cc", :I=>"Pair-Setup", :s=>"6c5cf13ffa9eb020aed9b0920b905c95", :v=>"7122c17ac84d1acbcd72df42d8653af94a6479f3327ca07ea1a31e0d5f398fd1f8dab39638745000809bb95b903dbc0ac03ac241ce4d171672cee4a0c9b44634c2798b71d86f341e96403a3a48b38e62038258a7e7f68a40c2b97426f15d06c82cee894251d19676918fecf0d11f1388962aefa803c28c4cce607308b979e317e69e5f184682e469f202d1711d006993f1e72e39f77431c475417bf08c765a0a82b586277da00ad69265932977351c3c01f3353537ad6ec30750cc0f02316ec0715064bebaed364f33a5ea83ecc6558fdfdfc9b07313d62e8fc23d6277ff60e65ad8fff0370245e296035ab4e56563322545832ec1d2e817014b10e7991c72a7ee3f8663d0626ba243fd470502cbbe4f0a698b1795aa8f16e33b01f91cc73929c150615f4d0b91a9f4ec56015b7d27f5298e7ccc46042a37be3efceae1e55ef062c8de180d9902c7102efb804e9dde64cfca8e5eefbde6cfbbc8f25d995775615e8ce1022d7eaccf4841e3b901a3be15c70c7d1b1507cfb8f514e43a37aa1a1b"}>
D, [2019-02-20T09:17:03.640321 #3892] DEBUG -- : Request
D, [2019-02-20T09:17:03.640478 #3892] DEBUG -- : {:method=>0, :state=>1}
D, [2019-02-20T09:17:03.700273 #3892] DEBUG -- : Response
D, [2019-02-20T09:17:03.700356 #3892] DEBUG -- : {:salt=>"FS\xD5u\xF0V\x12R\xA1\x99\xBC_\xB4\xF4\x06\x8E", :public_key=>"\x9Cr`\xD2\xE4\xBF\x13\xB1\xB6N\xA4\f\x97\x92.\x1Du\xBEd.'\x0E\x1A\xE3\xBB\xB0\xEA\xFC\x01\xB3[\b\x80G\xF3e\xD6\xDA\xB6f\xA8\x0EN\xBF\xAF\x12\x8B\xD4\x93\xA2<:\xE5\xC1q\xBC\x00\xFF\xA3\xDD\tVt\rb9]\xC2\x92a\xB8tL\xAEb\xE6\x9D\xF9>?\xBD\xAB!\xD0\xC4i'3\xCC\x8F`\b\xA7\x93\v\xD2\xCD\x93#c\x92\x8C_ 4\xAD7\xC7\x13\x9E\x9E\x14qb CDK\xF0\xF5\xFAf;0jr\xEB\xBC\xD1\xCF\xFA\xDE\xC1Ls.\x88\x18j\x1F\x87\xE839\xF7\xED(\xE5t\xABMy5\xF7&=\xE73\x12a1\r9\xC8\xCCq\xE2\xB4\xF2\xA7s\x14\xAE\xC5\x84z\xED #\xAF(\x19\x82\xBD\xB5 J\vH\xC1\x9A\xD9=\xCE\xB2\xF1\xF6M\\$\xEFz0\x15\x1A\xC1\x19\xFF%\xD0\xC3\xC2W6Q\xE2\xB4wE\x95\x8D\x98\xC7g,C\xC8e\xB2A\xF1\xF6\xDF\x83\x98\xD5\x81p\xFC\xD4C\x93\x82\xAC\xCB\xB5y\xA3\x90Y\xC5Nk'\x19\xC9\xB1L\xD1\x92\x12\xB9\x8Eo\xC7\xA7\x88\xE2\xF2`&<\x8D\bA@\xBF\xF1\x8E\x9A\xA8\x95\xDE=!\xA0nTn%\x9F\xE4\x01\xB66\xFE\xC1\xA2\a`>\x8E\x81g\x0E\xD5\r\xBB7bz\x01\xBB\".\x9F\x0F\xA65\x8E\x8F\xCA\x8C'E\x9B\xBE~\xEB\xAA=\x16\xB6j\x8F\xBBJ\xA6%\x83\xFB\xD6b\xB3\x95\e|U\x85\xD3B )\xBF\xEF\x02\xDB\xE9\xA7\x99\xFC\r\xAE\xD6WwW\x7F\x9B\xAD\x1F\xFC\vb}R\xB1\\\xB3\x8D\x15\x83\x01\xFC", :state=>2}
172.20.10.1 - - [20/Feb/2019:09:17:03 +0100] "POST /pair-setup HTTP/1.1" 200 409 0.0642

This is where it stops after a failed pairing attempt.

Thanks again for your time!

Hey, @tpolly thanks for the ongoing help debugging this. I think I finally know what the underlying issue is. I have discovered that in Ruby 2.4.0 there appears to be a bit of an issue with the method unpack1.

For example:

Ruby 2.4.0

'8d'.unpack('H*') #=> ["3864"]
'8d'.unpack1('H*') #=> "\x00\x00\x00\x00"

However, in Ruby 2.4.1 and future versions, it correctly returns:

Ruby 2.4.1

'8d'.unpack('H*') #=> ["3864"]
'8d'.unpack1('H*') #=> "3864"

I think this is/was a bug in Ruby 2.4.0 that was fixed in 2.4.1. This means RubyHome is currently incompatible with Ruby 2.4.0. Since RubyHome uses the method unpack1 quite extensively I am somewhat tempted to update the required_ruby_version to make the requirement for Ruby versions >= 2.4.1.

So I was wondering is it possible for you to update the Ruby version installed on your computer?

It works in Ruby 2.4.1!
Thanks so much, very much appreciated!

Setting the required ruby version to 2.4.1 for ruby_home-srp fixes this issue (or changing the usage to .unpack('H*').first)

Thanks again for bringing this my attention. I updated the required_ruby_version and confirmed attempting to install RubyHome on Ruby 2.4.0 now returns.

Fetching: ruby_home-0.1.21.gem (100%)
ERROR:  Error installing ruby_home:
	ruby_home requires Ruby version >= 2.4.1.