[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-24 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset c82451eeb595 by Christian Heimes in branch 'default': Issue #15061: Re-implemented hmac.compare_digest() in C http://hg.python.org/cpython/rev/c82451eeb595 -- ___ Python

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-24 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Thanks to all for your input and assistance! -- resolution: - fixed stage: commit review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Updated patch with volatile, better error report for non-ASCII strings and updated comments -- Added file: http://bugs.python.org/file26106/timingsafe_cmp-2.patch ___ Python tracker

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I'm not really happy with the addition of a separate extension module for a single private function. You could just put it in the operator module, for instance. Also, the idea was not to expose timingsafe_cmp but to use it in compare_digest().

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Me neither but you didn't want it in the operator module in the first place (msg162882). :) Please make a decision. I'm happy to follow it. My idea is to drop the pure Python implementation of compare_digest() and just use the C

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Me neither but you didn't want it in the operator module in the first place (msg162882). :) Please make a decision. I'm happy to follow it. Oh, sorry. I've changed my mind about it, but I think the operator module should only export a private

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: Doesn't belong into operator IMO. We used to have a strop module where it would have fitted... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: This is why I wanted to close the issue with the pure Python implementation, and punt on the question of a C accelerator for the moment. compare_digest is effectively the same as what all the Python web servers and frameworks do now for

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Doesn't belong into operator IMO. We used to have a strop module where it would have fitted... Again, it can be a private function in the operator module that happens to be wrapped or exposed in the hmac module. Practicality beats purity.

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: Yes. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___ ___ Python-bugs-list mailing list

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Again, it can be a private function in the operator module that happens to be wrapped or exposed in the hmac module. Practicality beats purity. Yes, we just need a place for the function. The operator module is a good place if we don't want

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Hynek Schlawack
Hynek Schlawack h...@ox.cx added the comment: For 3.4, I hope to see a discussion open up regarding the idea of something like a securitytools module that aims to provide some basic primitives for operations where Python's standard assumptions (such as flexibility and short circuiting

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: New patch. The compare_digest method now lives in the operator module as operator._compare_digest -- Added file: http://bugs.python.org/file26112/compare_digest_c.patch ___ Python tracker

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: About code. Instead (PyBytes_CheckExact(a) PyBytes_CheckExact(b)) you should use ((PyBytes_CheckExact(a) != 0) (PyBytes_CheckExact(b) != 0)). What's the difference? They are the same. Laziness. If a (a secret key) is not bytes then

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Gregory P. Smith
Changes by Gregory P. Smith g...@krypto.org: -- nosy: +gregory.p.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___ ___

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-23 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: New patch. I've removed the special handling of PyBytes_CheckExact, support subclasses of str, non compact ASCII str and updated the docs. (Next time I'll create a sandbox and push my work to its own branch.) -- Added file:

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-22 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: We could handle all bytes-compatible objects, using the buffer API. It is timing unsafe. How so? I checked myself, and I see that most likely I was wrong. At least for bytes and bytearrays it is timing safe. I don't think that's

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-22 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: The error will be if code works for developer from ASCII word, and then on the other side of ocean it will no longer work with non-ASCII strings. You are expected to be familiar with such issues. In any case, the obvious (and simplest, and

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-22 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: In order to get the patch in before the beta release I'm willing to drop the promise and document that the function may leak some information if the arguments differ in length or the arguments' types are incompatible. --

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-22 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: In order to get the patch in before the beta release I'm willing to drop the promise and document that the function may leak some information if the arguments differ in length or the arguments' types are incompatible. That's not a problem to

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Shall explore option 2b) optionally create a C implementation as it's much easier to check C code for timing issues Definitely. I'm not sure whether that can go in 3.3 post-beta, though. -- ___

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: Hi. This is what we did with Armin: http://bpaste.net/show/32123/ It seems there is still *some* information leaking via side-channels, although it's a bit unclear what. Feel free to play with it (try swapping, having different object

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: I've attached a header for that implements a single C function timingsafe_eq(a, b). The file is targeted for Objects/stringlib/timingsafe.h. Please review the file. Comments - I only handle exact byte or unicode types (no

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: The file is targeted for Objects/stringlib/timingsafe.h. stringlib is for type-generic functions, so I don't think it should be put there. - I only handle exact byte or unicode types (no subclasses) since a user may have overwritten __eq__

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: - I only handle exact byte or unicode types (no subclasses) since a user may have overwritten __eq__ and I don't want to special case it. We could handle all bytes-compatible objects, using the buffer API. It is timing unsafe. -

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: The user can just do timingsafe_eq(a.decode('ascii'), b.decode('ascii')). You mean .encode()? I do not see a necessity in support of unicode strings. Support ASCII strings will create the false impression that all strings are

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: You mean .encode()? Yes, of cause. timingsafe_eq(a.encode('ascii'), b.encode('ascii')). About code. Instead (PyBytes_CheckExact(a) PyBytes_CheckExact(b)) you should use ((PyBytes_CheckExact(a) != 0) (PyBytes_CheckExact(b) != 0)).

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: - I only handle exact byte or unicode types (no subclasses) since a user may have overwritten __eq__ and I don't want to special case it. We could handle all bytes-compatible objects, using the buffer API. It is timing unsafe. How so?

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: I'm a bit rusty and I hope I got it right. The ASCII unicode case is a good idea and IMO timing safe. The buffer path is also timing safe once I have both views. The function leaks some timing information when an error occurs. Since the

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-21 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: The patch has another flaw. The compiler may choose to fold and optimize code in _tscmp(). I'm going to declare the length of the right side and both char* as volatile. That should stop any compiler. I could also add some pragmas: MSVC:

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: I've increased the priority to release blocker. Reason: We should come to an agreement how to handle the issue. In particular we must not pronounce something as secure that isn't secure. Options: 1) Remove the function. 2) Rename the

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Hynek Schlawack
Hynek Schlawack h...@ox.cx added the comment: I thought this is settled as of f36af3766a20 (option 2)? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Oh, I totally missed Nick's checkin. Sorry for the noise. Should we add the encode('unicode-internal') trick from #14955 as the next best way to compare to unicode strings? -- stage: needs patch - commit review

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Should we add the encode('unicode-internal') trick from #14955 as the next best way to compare to unicode strings? I don't think so. -- ___ Python tracker rep...@bugs.python.org

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Alex Gaynor
Changes by Alex Gaynor alex.gay...@gmail.com: -- nosy: +alex ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___ ___ Python-bugs-list mailing

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Unicode string timing depends on the string implementation which depends on the maximum character code in the string. Strings 'A'*+'$' 'A'*+'€' have different timings for almost all operations (inluding

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Oh, I see, Antoine said the same thing (msg162771). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: I'm well aware of the fact that they have different timings. That's why I argued against including a unicode aware variant of the timing safe compare function. I've used Guido's time machine and seen requests for a unicode function in the

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I'm well aware of the fact that they have different timings. That's why I argued against including a unicode aware variant of the timing safe compare function. I would not want to repeat myself, but the compare function can be made safe if it

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Alright, Antoine. Shall explore option 2b) optionally create a C implementation as it's much easier to check C code for timing issues as I suggested in http://bugs.python.org/issue15061#msg162893 ? --

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-19 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: So it's not a blocker anymore, right? -- nosy: +georg.brandl priority: release blocker - normal ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Hynek Schlawack
Hynek Schlawack h...@ox.cx added the comment: Secure vs not secure is not a binary state - it's about making attacks progressively more difficult. Something that is secure against a casual script kiddie scatter gunning attacks on various sites with an automated script won't stand up to a

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: On 14.06.2012 14:26, Antoine Pitrou wrote: Antoine Pitrou pit...@free.fr added the comment: It's either secure or it's not. I don't think that's true. By that reasoning, Python is not secure so there's no point in fixing crashes or

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Being able to tell people using hmac.total_compare will make you less vulnerable to timing attacks than using ordinary short circuiting comparisons is a *good thing*. No, it's not. It's a *bad thing*. The two issues that have been opened

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Why not write a C function which can be more secure than Python code? For Unicode strings, it's impossible to write a time-independent comparison function even in C I would argue that would be an general asset for the stdlib I would

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Hynek Schlawack
Hynek Schlawack h...@ox.cx added the comment: Why not write a C function which can be more secure than Python code? For Unicode strings, it's impossible to write a time-independent comparison function even in C Really? Some comments sounded different. That's too bad but also what I

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: Can people please stop raising a false dichotomy and using that as an excuse not to do anything? The decision is not between leak some information and leak no information. It is between leak more information and leak less information. The

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Well, one example: https://github.com/mitsuhiko/python-pbkdf2/blob/master/pbkdf2.py It says that it needs that, but I fail to understand why. pbkdf2 is used to generate encryption keys from passwords, where you don't need to compare

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: To repeat, the specific feature being proposed for retention is: * a function called hmac.total_compare() that is clearly documented as being still vulnerable to timing analysis given a sufficiently sophisticated attacker, while still being

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: The timing variations with standard comparison are relatively massive and relatively easy to analyse (if the time taken goes up, you got the previous digit correct). If you have an application that is vulnerable to such an attack, you

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: To repeat, the specific feature being proposed for retention is: To repeat, no use case has been demonstrated for that function. It has been added because it was fun to write, not because it is useful. --

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: On Fri, Jun 15, 2012 at 9:41 AM, Nick Coghlan rep...@bugs.python.orgwrote: Nick Coghlan ncogh...@gmail.com added the comment: To repeat, the specific feature being proposed for retention is: * a function called hmac.total_compare()

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: On Fri, Jun 15, 2012 at 9:47 AM, Martin v. Löwis rep...@bugs.python.orgwrote: Martin v. Löwis mar...@v.loewis.de added the comment: To repeat, the specific feature being proposed for retention is: To repeat, no use case has been

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Hynek Schlawack
Hynek Schlawack h...@ox.cx added the comment: and any other place that compares passwords, tokens, … No no no. Any sensible place to compare passwords would use some sort of one-way function (password hash) before the comparison, so that someone breaking into the machine will not gain the

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: I'm not really opposed to writing it in C - I just don't think rewriting it in C should be a requirement for keeping it. Even in pure Python, it still leaks less information than the standard comparison operator. --

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: On Fri, Jun 15, 2012 at 9:55 AM, Hynek Schlawack rep...@bugs.python.orgwrote: Hynek Schlawack h...@ox.cx added the comment: and any other place that compares passwords, tokens, … No no no. Any sensible place to compare passwords

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Is comparing passwords against a secure one not useful? I claim that this use case doesn't occur in practice. Everybody uses hashed passwords. If they do compare against a plain-text password, and they want to change something about it,

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: This point was discussed in #14532 when the new API was added. From http://bugs.python.org/issue14532#msg158045: Given that this issue has affected a lot of security-sensitive third-party code (keyczar, openid providers, almost every python

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: I see your point that adding such a function would leverage bad security behavior and thus may be a bad thing. The usefulness of such a function to some(?) people is IMHO not disputable though. I think this entire issue is out of scale.

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Note that this does not relief you from using a time-independent comparison function. If you call some hash function (which time is known to the attacker), then you compare it against a stored hashed version. If you use a normal compare

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: On Fri, Jun 15, 2012 at 10:09 AM, Martin v. Löwis rep...@bugs.python.orgwrote: Martin v. Löwis mar...@v.loewis.de added the comment: Note that this does not relief you from using a time-independent comparison function. If you call

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: For password hashing, the attacker is unlikely to be able to provide the digest directly, but for signature checking it's far more likely to be the case. Can you elaborate? What is the application, where is the digest checking, and what

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Martin, you fail to understand how this works. You don't do 2**32 tries to leak the 4 charaters, you need 4 * 256, that's why this attack is so bad, because the time needed for the next character is brute force, but then you can move on

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: That's why the vulnerable cases are far more likely to be related to *signature* checking. In those you can generally provide both the hash input (the message) and the hash target (the purported signature). If the signature check uses a

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Petri Lehtinen
Petri Lehtinen pe...@digip.org added the comment: For example, Django uses time independent comparison to compare signatures of signed cookies. A signed cookie consists of a plain-text value followed by a signature. An attacker wants to construct a cookie that has a malformed value and a

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: FWIW, Petri's example also explains why leaking the expected length of the string is considered an acceptable optimisation in most reimplementations of this signature check comparison: the attacker is assumed to already know the expected

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: That's why the vulnerable cases are far more likely to be related to *signature* checking. In those you can generally provide both the hash input (the message) and the hash target (the purported signature). I see. I wonder how feasible

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Armin Rigo
Changes by Armin Rigo ar...@users.sourceforge.net: -- nosy: -arigo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___ ___ Python-bugs-list

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Oh dead god, what have I done ... I threw a small stone and caused a major landslide. :) I'm all with Nick on this topic. A correctly named and documented function provides a tool to users that greatly reduced the change of a side channel

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I could wrap up a quick C implementation if you like. The operator module is a better place for a total_compare() function. Do you a agree? I think the function is fine in either hashlib or hmac. Putting it in one of these modules is a hint

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: As a first step, I'm going to make a change to: 1. Rename the function to compare_digest 2. Remove the support for comparing strings 3. Update the documentation to be much clearer about its limitations (including why it's considered OK to leak

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset f36af3766a20 by Nick Coghlan in branch 'default': Issue #15061: Don't oversell the capabilities of the new non-shortcircuiting comparison function in hmac http://hg.python.org/cpython/rev/f36af3766a20 --

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: OK, the worst aspects (the misleading name and documentation) have been dealt with, so that leaves the questions of: 1. Avoiding leaking the length information (seems unnecessary, since most digests are part of protocols where they have a

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: 2. Providing a C implementation via the operator module (given the restriction to bytes values, and the assumption of caching for all relevant integers, would a C reimplementation really be buying us much additional security?) I like the fact

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: Am 15.06.2012 14:21, schrieb Antoine Pitrou: I like the fact that a C implementation can be audited much more easily. Who knows what kind of effects the Python implementation can trigger, if some optimizations get added in the future.

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: The point of supporting unicode would precisely be to avoid a unicode-bytes conversion when unicode strings are received. A byte-wise comparison of the memory representation would work IFF both sides have the same type and unicode kind.

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: (Ah, the dangers of using a real text editor for edit fields. This got rather long, but I think it's all still relevant) I'm persuaded that a C implementation is a good idea in the long run. However, I *don't* think we should rush the design

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Secondly, it seems to me that the proposed lower level feature may make more sense as a bytes method rather than as a function in the operator module. If it's a function, though, it can compare all kinds of buffer-like objects (bytearrays,

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Jon Oberheide
Jon Oberheide j...@oberheide.org added the comment: Wow, that escalated quickly. :-) Nick, thanks for keeping things focused and on track. To recap, the primary motivation here is two-fold. First, folks are using == pretty frequently in an unsafe manner when comparing digests, signatures, and

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-15 Thread Jon Oberheide
Jon Oberheide j...@oberheide.org added the comment: On a side note, it may be useful to follow the conventions that already exist in OpenBSD for their timingsafe_bcmp(3): http://www.rootr.net/man/man/timingsafe_bcmp/3 timingsafe may be a more reasonable naming convention that is a bit less

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: I don't see how the function is going to leak this information when both this patch and the patch in #14955 are applied. With http://bugs.python.org/file25801/secure-compare-fix-v2.patch ord() is no longer used and thus avoid the timing

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: Ah unicodes. is encode('unicode-internal') independent on the string characters? I heavily doubt so. you leak at least some information through that function alone. -- ___ Python tracker

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: With PEP 393 unicode objects can have several representations, which makes it unlikely that *really* constant-timing functions can be devised. Speaking about this particular patch, I don't understand the point. secure_compare() is obviously

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: IMHO it's not obvious to all users. Better safe than sorry. ;) The invariant 'known and equal length' impresses an artificial limitation. Code may need to compare outside data with internal data without exposing too many details about the

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Hynek Schlawack
Hynek Schlawack h...@ox.cx added the comment: I don’t want to be the killjoy but I find it highly questionable to add a function that is advertised as secure while we can't fully grok the complexities at play. If we can't produce a provable secure one, we should scrub the function for good;

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I don’t want to be the killjoy but I find it highly questionable to add a function that is advertised as secure while we can't fully grok the complexities at play. If we can't produce a provable secure one, we should scrub the function for

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: Antoine, seriously? You want to explore a function that's called secure when the only thing you know about it is probably secure? This is extremely tricky business and I think it should be called secure only if you can prove it's secure.

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: export not explore. Why can't I edit my own post? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061 ___

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Antoine, seriously? You want to explore a function that's called secure when the only thing you know about it is probably secure? This is extremely tricky business and I think it should be called secure only if you can prove it's secure.

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: For unicode at the very least it's not an improvement at all. With the patch mentioned that does encode it's also not an improvement at all. Prove as in reason about the function in C and make sure it does not do any conditionals

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: I recommend to revert the addition of the function, given that it can't be made secure. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15061

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Christian Heimes
Christian Heimes li...@cheimes.de added the comment: I've two suggestions: * rename the function to 'total_compare'. The name explains what the function actually does in comparison to '=='. It takes the total input values into account instead of using short circuit comparison. * restrict the

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Maciej Fijalkowski
Maciej Fijalkowski fij...@gmail.com added the comment: Hi Christian. It's either secure or it's not. If it's not, there is no point in introducing it at all as I don't think it's a good idea to have a kind-of-secure-but-i-dont-know functions in stdlib. If you restrict input to bytes it looks

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: It's either secure or it's not. I don't think that's true. By that reasoning, Python is not secure so there's no point in fixing crashes or providing a hashlib module. That said, I think renaming to total_compare isn't really helpful. The

[issue15061] hmac.secure_compare() leaks information about length of strings

2012-06-14 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: Maciej, please read http://mjg59.dreamwidth.org/13061.html Secure vs not secure is not a binary state - it's about making attacks progressively more difficult. Something that is secure against a casual script kiddie scatter gunning attacks on