Conversation
|
Can someone check on what TLS settings end up being used here, in particular the TLS version, cipher suite, and SNI? (If no one is able, I'll get around to it once my computer maintenance is under control and I have my data back.) |
|
As far as I've seen, the cipher suites (and possibly more) can be configured on the server using |
|
I suggest we mark it as "experimental" or something and merge. |
|
I will try to review this over the weekend. If I can't then we can merge as long as it's marked as experimental and not for end users. |
|
@domob1812 Can you post a sample config file line for the fingerprint verification? I'm not quite sure how it's supposed to be specified. |
|
So, I'm looking at the code, and it's very messy due to use of "urllib" directly. I would really prefer to use the "requests" library which makes this kind of thing much simpler. Requests also can verify TLS certs with a single extra argument (although it wants the cert file rather than a fingerprint). I can possibly write the requests code if @domob1812 is too busy. |
|
I've mostly ported to requests; is there a public REST server available to test with? The one @domob1812 linked on the forum ( http://chain.huntercoin.org:8336/rest/name/d%2fdomob.json ) isn't loading for me. (Both HTTP and HTTPS would be nice to test against.) |
|
Without having tested it, the example config line should be something like |
|
Okay, so it seems that using requests to validate by fingerprint only allows SHA1 fingerprints, not SHA256 (which I don't think is acceptable). I've just filed a bug report, so hopefully they'll deal with that soon. In the meantime we can use @domob1812 's code (once the TLS settings are confirmed valid) and replace it once requests supports SHA256. @domob1812 is there a public REST server (both HTTP and HTTPS) that I can test with? |
|
I just did some testing, looks like this code uses some ciphersuites which are weak and/or don't have forward secrecy. I'm looking into how easy this will be to fix. Also, @domob1812 's example config line was missing a forward slash between the port number and the semicolon, in case anyone else wants to test this. |
|
Okay, so to properly fix the TLS settings, we need Python 2.7.9 or Python 3.4. Unfortunately 2.7.9 isn't yet in most Linux distros (Fedora 21 has 2.7.8). Also, I believe that the current code from @domob1812 supports insecure SSL/TLS versions such as SSLv3 (I couldn't easily test this). I am against recommending to end users a system that is known to be insecure, but it's not clear to me how fast this will be properly fixable. I don't think most end users will need to contact a non-localhost REST server. If they do, they can tunnel over SSH or something like that, bypassing the need for secure TLS. So I think I'm okay with merging insecure TLS code, on the condition that it is clearly labeled to end users as insecure and nonrecommended, and we fix it once we have access to newer Python code. Upgrading to Python3 (as planned) will also fix this (Fedora 21 has Python 3.4.1). Thoughts on what to do here? |
|
My ticket regarding SHA-256 fingerprint support in the dependency that requests uses has been fixed -- that was fast. So once that makes its way into a release, we should switch to using requests. |
|
I've not made any efforts to select ciphers / suites, but from what I read it should be enough to add some more config lines. Not sure about the requirement for new Python versions, though. I've no idea how that requests library works, so if you think that the fix makes its way into stable distros fast enough, feel free to submit a competing pull request so I can see how much easier the code is. Regarding API server: If the one at chain.huntercoin.org does not work (not sure, maybe I disabled the config), I have none usable at the moment. Sorry. |
|
I figure I will put this here instead of commenting on Jeremy's pull request, because this is where all the discussion seems to be. I'd just like to note that Debian Jessie, which will be released as the new stable release of Debian soon and then is set to be the stable release for approximately another couple of years, has version 2.7.8 of Python 2. Since Debian Jessie is frozen, new upstream versions of packages can't get into Debian Jessie. So there is pretty much zero chance of Debian Jessie shipping with 2.7.9 or greater. So if you want to retain support across the stable releases of all the popular distros, you need to either go with Python 3 (which I mentioned at the last irc meeting that I had been working on Python 3 support, I should upload what I have of that), wait a couple of years for when distros support sufficient versions of Python 2 to merge Jeremy's code, or just not merge the code. I think going with Python 3 is the best option. |
|
I will try and take a look whether I can make it work with 2.7.8. |
|
Just for reference, the ciphersuites can be fixed in older Pythons. However, enforcing usage of TLS 1.1 or 1.2 rather than 1.0 is not supported by Pythons earlier than 2.7.9. See https://docs.python.org/2.7/library/ssl.html |
|
Hey guys. So I've got TLS 1.2 enforcement working (I think) on older Pythons. Turns out that the ciphersuite selection can be rigged so that it intentionally breaks on previous TLS versions (which is what we want). Learn something new every day in this job, I do. There however is a big issue that I neglected to mention. As far as I can tell, @domob1812 's code is validating the TLS fingerprint after the request is sent (is this correct as far as you know?). This means that anyone can do a MITM and see the names being requested (although this will trigger a TLS error in NMControl and they won't be able to make NMControl receive false data). So, the question is, which is preferable: using @domob1812 's code (with my fixes), where impersonation requires breaking SHA256 but surveillance is trivially easy, or using requests (without the latest change that isn't in a release), where impersonation and surveillance both require breaking SHA1? My opinion is that the latter is preferable. I can also make the requests code so that if the user supplies an exact cert, then that will be matched instead (so people who are afraid of SHA1 can do that until the latest code is in distros). Thoughts? |
|
Okay, good news. I was able to get everything working using requests. What works: TLS 1.2; secure ciphers; SNI; SHA256 fingerprint verification before sending data. And this is using Python 2.7.8, so it should work most places. The only issue is that a few packages need to be loaded via pip (such as PyOpenSSL). I will post my code asap, but I'd like to test it on a Namecore instance first (I've been testing on SSLLabs's server). /me does victory lap |
|
:) Thank you for your perseverance. |
|
Testing my requests-based code on Namecoin Core is currently blocked by domob1812/namecoin-core#6 , since I cannot build Namecoin Core until that's fixed. |
|
Okay, see #58 for my rewrite using python-requests. |
|
OK, I looked into this. My thoughts: |
Three side notes:
EDIT: Also I'm totally fine with making it show a friendly error in case Requests isn't installed. I already did that for the TLS modules, I should have done it for Requests too but I forgot. I can fix that too. |
|
1.) OK Requests has quite some advantages and I don't see any real disadvantages so I am fine with using it. IMHO there should be a separate queryapiserver module, though. |
|
Users can't always upgrade Python 3 to a newer version than that provided by their distro easily. For example, python3.4-minimal (which is a dependency of python3 in Debian Jessie and Sid) requires libc6 2.15 or greater for the amd64 architecture. Debian Wheezy has libc6 2.13. Trying to upgrade libc6 is almost guaranteed to break your system, since there are so many packages that depend on libc6. So it is at best non-trivial to port Python 3.4 to Debian Wheezy. At worst, it is completely impossible. Since Debian Jessie will hopefully be released soon, this particular example isn't really a concern, but I haven't analyized the entire dependency chain for Python 3.4, or looked at distros other than Debian, so it is possible there are similar issues. |
|
I have set up the experimental API server with https. You can query it like this to experiment: https://github.com/phelixnmc/nmcontrol/blob/rest-simple/lib/nmcapiclient.py |
|
@phelixbtc Only the callback function at https://github.com/namecoin/nmcontrol/pull/58/files#diff-f0642a76a70a05557239a272a3cd10c6R18 and the try clause at https://github.com/namecoin/nmcontrol/pull/58/files#diff-f0642a76a70a05557239a272a3cd10c6R41 are relevant to the secure HTTPS with fingerprint validation. I can break this out into a separate file if you like, I just don't think it's much code. Anyway, I'll fix the issue @domob1812 reported in my requests version, then I'll ask for a merge, and once merged I'll address the other minor issues you bring up. |
|
The more I look into this the more I get the impression that both the standard Python https functions as well as the requests code is not meant to be used with fingerprints. Maybe we should leave it out for now - people can still add certificates to their system ca store I think. Requests seems prone to complication on Windows (especially so with the fingerprint check), maybe we should use builtin functions where available and fall back to requests on systems where up to date libs are not available. |
Allow to use a REST API server as backend for NMControl. Supports both HTTP and HTTPS connections, and allows to optionally specify the expected TLS certificate. This makes it safe to use with a remote host.
Note, though, that I'm not a TLS nor Python expert. So I can't guarantee that the code is safe (but I expect it to be, review welcome).
See #48.