-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NNTPS support in nntplib #46220
Comments
This patch adds SSL support to nntplib. It is a followup to issue |
I assign it to janssens. He is our SSL expert. I also set the version to |
Unfortunately, it uses the deprecated socket.ssl calls. Re-worked to |
OK, I got a copy of the Subversion sources and the new SSL library looks httplib has: poplib has: imaplib has: smtplib has: Now nntplib as it stands has no SSL-using variant. The existing factory What seems most consistent with the other modules is to define: |
Sounds good. If you want to develop this with 2.5.1, you can get an |
Here's take 2. The pre-patch NNTP class has a long and complicated constructor. Rather |
Great, Ray. I don't see any test cases for the nntp library in the Lib/test/ directory. Bill On Jan 25, 2008 12:49 PM, Ray Chason <report@bugs.python.org> wrote:
|
It seems that I, or whoever writes any future test_nntplib.py, would Anyway, getting good coverage isn't something I can bang out in an |
Yeah, it took me a couple of months to do a reasonable test case for the SSL Perhaps we could test against an existing NNTP server? Like Google's? Bill On Jan 27, 2008 6:59 PM, Ray Chason <report@bugs.python.org> wrote:
|
Yes, a test could use Google or gmane (according to the FAQ, nntps is supported: http://gmane.org/faq.php ). |
The patch might need a little reworking to make it work under 3.x, although probably not much. (*) http://docs.python.org/dev/library/ssl.html#ssl-contexts |
Unfortunately nntplib lacks a test suite. |
It should be noted that there are two possibilities for encrypted NNTP:
For the record, gmane provides the former (on snews.gmane.org:563) but not the latter. |
Regarding these two possibilities, please note that the first one is discouraged (per RFC 4642). In some existing implementations, TCP port 563 has been dedicated to |
At Antoine's suggestion I've written a new patch for this for 3.2, adding support for both SSL on 563 and STARTTLS on a normal connection. A NNTP_SSL class supports the former and a NNTP.starttls() method supports the latter. As a side effect of getting starttls working I had to add a NNTP.login() method as well. (see below) The patch updates nntplib.py, test_nntplib.py, nntplib.rst, and Misc/NEWS. Some implementation notes: By default, NNTP objects attempt to log in during initialization,and there didn't seem to be any support for logging in later. This was a problem as STARTTLS has to be issued before logging in. In order to get around this and handle a STARTTLS nuance involving CAPABILITIES, I moved the authentication part of _NNTPBase.__init__ into a method of its own, NNTP.login(), and another piece of it into NNTP.getcapabilities(). This doesn't affect the observable behavior of NNTP() or the existing methods. As a side note, IMHO NNTP shouldn't attempt to log in at initialization at all. The user, password, and usenetrc args should not be part of the constructors and the program using the library should be able to choose when or if to log in after connecting. I couldn't think of any way to do this without breaking existing programs, though. At the very least I think usenetrc should default to False, but that would break programs that rely on the default behavior too, I think. I updated the test cases, with a caveat. They use gmane to perform the tests. Gmane doesn't support starttls. Therefor the tests currently only check for correct failure rather than correct success. There's test code for the starttls() method but it never runs. I checked the functionality against eternal-september to be sure it does, in fact, correctly succeed as well, but I'm not about to put my login details in the automatic test script. ;-) The NNTPS-on-563 test, OTOH, works exactly like the existing NNTP test and seems to work fine. It was a hell of a lot easier to implement that part too. Hope I didn't miss anything. First time doing this for a public project. Apparently the personal-itch theory is correct. <click> |
Also, Julien: Thanks for mentioning the 563-discouraged thing. I added a note about it to the new documentation before submitting. |
Andrew, thank you for posting a patch.
All in all, it looks good though. |
Thanks a lot for having implemented STARTTLS, Andrew! + Since the order in which certain operations need to be done varies One "varies" is enough. |
On 2 Nov 2010 at 17:05, Antoine Pitrou wrote:
I'm not sure I understand which part you're talking about here....the (if you can suggest a method-of-use that breaks it, that may enlighten
Meh. My editor wasn't set up properly when I started. I thought I'd
I'll see what I can do. Some amount of that was necessary to fit
Can do. I didn't know about self.skip; I don't really understand the
...I actually meant to do exactly that, but forgot to put the check -- Andrew. |
I'm talking about the code under "if __name__ == '__main__'".
Well, actually it's "self.skipTest(...)". My bad. |
On 2 Nov 2010 at 23:22, Antoine Pitrou wrote:
Now I feel silly. Partly because of the mistake, partly because I did Thanks for the advice; I'll fix it as best I can in the next day or -- Andrew |
And it should also make sure the user is not already authenticated. |
I too was just looking at NNTPS support because I have a need for it. The latest patch looks like great work and I think the things it implements are needed for this library. But it seems to me that the latest patch combines 3 things which might otherwise be able to be separately considered. NNTPS, START_TLS (RFC 4642) extension and AUTHINFO extension (RFC 4643). It may be that START_TLS and AUTHINFO are indivisible, I need to read those more, but shouldn't that be a new topic of discussion as this feature request is for NNTPS support? I also don't understand the difficulty with plain NNTPS as it doesn't need a new interface a very simple patch (attached) achieves NNTPS?? (Most of the patch is test case and variant defaults. The actual NNTPS code is just: I also don't understand why START_TLS and AUTHINFO need to change how the module is interfaced to (separating log in/authentication, etc), my reading of START_TLS and AUTHINFO seem to me that it should all be under the covers. It even explains this in Section 7 of "Using TLS Perhaps there needs to be a separate feature request "START_TLS and AUTHINFO extension support for nntplib" so the issues and any necessary interface changes can be considered in isolation from simple NNTP over SSL? I think it would be nice to have NNTPS in for 3.2. |
Hi Steven,
Because once you have used AUTHINFO, STARTTLS is no longer a valid command in a session. |
Hi Julien,
I understand this, but doesn't this mean the init function needs to change to something like: init: Now handle AUTHINFO Stuff Is there a case where a server advertises STARTTLS and one would not use it? If so then couldn't that just be handled with an option to the class inhibiting it? This is one of the reasons why I proposed dividing the job across two features.
There are also other bugs with properly handling capabilities at start related to this, are there not? http://bugs.python.org/issue10287 |
Hi Steven, I agree with what you suggest for the implementation.
Yes, the overhead added by the encryption. It is what people usually mention for the reason not to use it. |
(Note that smtplib can give ideas for an implementation of AUTHINFO SASL with PLAIN, LOGIN and CRAM-MD5 mechanisms.) |
Here's a second version of the previous patch taking into account the errors Antoine noticed and some odds and ends from the other comments. Specifically: Comments fixed and tabs (I think...I hope...) all removed. Added explicit skip to test_nntplib when attempting to test starttls using a server that doesn't support it. Exceptions raised when issuing STARTTLS for: Authorization already done, TLS already active, server not advertising STARTTLS. Method moving: I'm not sure why the first patch seemed to think I was e.g. moving getwelcome (I wasn't, as far as I knew), but this time I put the new functions at the end of the class and it's no longer doing it. (still a bit of a mess for the code moved from __init__ to login, starttls, and readermode though) Selftest cli option: I threw out what I did before (as pointed out, it didn't work anyway) and added a -l flag to use SSL. It uses port 563 for the test only if the user hasn't asked for a non-default port. I'd like to address some of the objections other users have to the way I implemented it the first time. NNTPS and STARTTLS separation: One objection noted that nntps and STARTTLS support are really separate things and should be handled as such. Actually they're probably right. I did both at once because I view them as simply two ways of performing the same function, as someone mentioned earlier in the thread. Unnecessary Method Separation: One objection noted that separating out login and starttls was unnecessary and the calling program shouldn't have to worry about these steps. I disagree; I think the caller should be able to choose when and if to log in or engage encryption. (in fact I think usenetrc should be false by default for this reason, but I figure that would break backwards compatibility for programs that rely on it being true by default, and I'm not sure what the rules are regarding this) More significant than my own potentially newbie-ish opinion is that the RFC suggests as a valid use case the idea of a client starting up TLS or authentication in reaction to a 483 command response, rather than right off the bat. I'm pretty sure this is impossible under the current setup, where login/encryption happens only at initialization and there's no method exposed to do it later. If I'm going to get overruled on this, I guess the other option is to add a starttls argument to the constructors. If so, I'd suggest it have settings to forbid starttls, use it if it's advertised, or insist on it (by raising an exception if it can't be used). Perhaps false/none/true respectively. Existing issue for AUTHINFO and MODE READER: One objection noted there's already an issue open for them (bpo-10287). Which is true, but the AUTHINFO and MODE READER changes were necessary to make STARTTLS work as intended. (in my opinion, I suppose) So I did them as I went along. I'm not sure if I violated custom there, but my apologies if so. At least having them functioned out will make most of what's mentioned in 10287 easier to fix, I suppose. Randomness: BTW, I've been maintaining the readermode_afterauth thing because of the comment next to it, but it sounds from that other issue like it's not supposed to be there at all...which kind of restores my faith in the universe since it smelled bad from the start to me. |
Thanks for the patch, Andrew. It looks mostly good. I would rename setreadermode to _setreadermode (there's no reason to I can take care of all that when committing, you don't need to submit a
In 3.2, the reworked nntplib already breaks compatibility. It is |
Yes. (Currently, it would only be TLS with nntplib, because
Absolutely.
Yep. According to RFC 4643: Additionally, the client MUST NOT issue a MODE READER |
On 6 Nov 2010 at 11:48, Antoine Pitrou wrote:
I'd appreciate it if you took care of it, if you feel the patch is otherwise I forgot to include a note for Misc/NEWS in the new patch version,
Okay. For the time being I left a note in the documentation pointing -- Andrew |
The only comment I have is, if the caller needs to organise when to auth and instigate tls then for completeness getcapabilities() should have an option to force a reget of the current capabilities, in line with rfc3977 5.2.2:
As it stands, the nntplib can cause the cached capabilities to be refreshed at certain points automatically (as it should), but I something like this perhaps? : mynntp.getcapabilites(refresh=True) |
On 6 Nov 2010 at 17:23, StevenJ wrote:
I agree. I actually added a way to do this when I functioned out It was ugly and not exposed to the caller though.
My method sucked, this one doesn't. Might belong in a separate issue -- Andrew |
I have committed the patch in r86365, and I've made usenetrc False by default in r86366. Thanks for contributing! |
On 9 Nov 2010 at 18:59, Antoine Pitrou wrote:
Woot. I thank you. Regarding usenetrc, the NNTP.login and NNTP.starttls documentation I'm glad that's not the case anymore but the documentation as I wrote -- Andrew |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: