Skip to content
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

Revert -out option checks #6033

Closed
wants to merge 13 commits into from

Conversation

levitte
Copy link
Member

@levitte levitte commented Apr 20, 2018

The checks were over elaborate and became so increasingly the more we kept trying.

This reverses #4008 and #3709, i.e. reinstates that very light checks, but keeps test/recipes/15-test_out_option.t. This puts us back at where we started with #3404 and allows us to deal with it differently that we have 'til now. This also fixes #5590, and cancels out #5592 and #5638.

The first commit is from #6031

Test writing to the null device.  This should be successful.
Test writing to a writable file in a write protected directory.  This
should be successful.

Also, refactor so the planned number of tests is calculated.

[extended tests]
@levitte
Copy link
Member Author

levitte commented Apr 20, 2018

@petrovr, I know this has been a pet peeve. Your comments would be appreciated.

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's time to just walk away from this whole issue for this release, so this PR is good.

@richsalz richsalz added the approval: done This pull request has the required number of approvals label Apr 20, 2018
@bernd-edlinger
Copy link
Member

There appveyor failure seems relevant:

[00:12:33] Generating RSA private key, 16384 bit long modulus (2 primes)
[00:12:33] ...................................................................................................................++
[00:12:33] ....................................................................................................................++
[00:12:33] e is 65537 (0x010001)
[00:12:33] ..\..\apps\openssl.exe genrsa -out test_out_option-nowrite-2628\unwritable.pem 16384 => 0
[00:12:33] not ok 9 - invalid output path: test_out_option-nowrite-2628\unwritable.pem
[00:12:33] 
[00:12:33] #   Failed test 'invalid output path: test_out_option-nowrite-2628\unwritable.pem'
[00:12:33] #   at ..\test\recipes\15-test_out_option.t line 82.
[00:12:33] not ok 10 - check time consumed
[00:12:33] 
[00:12:33] #   Failed test 'check time consumed'
[00:12:33] #   at ..\test\recipes\15-test_out_option.t line 85.

@bernd-edlinger
Copy link
Member

also the travis mingw test is failing in a similar way:

genrsa: Cannot open output file /dev/null, Invalid argument

genrsa: Use -help for summary.

wine ../../apps/openssl.exe genrsa -out /dev/null 2048 => 1
not ok 14 - valid output path: /dev/null

@levitte
Copy link
Member Author

levitte commented Apr 22, 2018

@bernd-edlinger, I've added a fixup that should help.

@levitte
Copy link
Member Author

levitte commented Apr 23, 2018

Hmmm, is it just me, or does MSVC's _access not recognise NUL? @dot-asm, you seem to know these things better than most, would you be willing to shed some light on this?

@levitte levitte changed the title Revert -out option checks WIP: Revert -out option checks Apr 23, 2018
@dot-asm
Copy link
Contributor

dot-asm commented Apr 23, 2018

is it just me, or does MSVC's _access not recognise NUL?

Hmmm... It apparently varies with CRT version... I don't know that it changed, but latest CRT apparently returns EINVAL upon attempt to _access("NUL"). On the other hand default CRT, c:\windows\system32\msvcrt.dll, one mingw links with, acknowledges NUL's existence and recognizes it as writable... I suppose MSC's _access is not to be trusted...

@levitte
Copy link
Member Author

levitte commented Apr 24, 2018

So basically, we (and any application, really) have to handle the magic file "nul" ourselves. That's kinda crappy... But ok, I can add that. Do we have to be equally attentive with the rest of the "POSIX API" (thinking of _open in particular)?

@bernd-edlinger
Copy link
Member

Why do we have to ask first if we can open NUL?

@levitte
Copy link
Member Author

levitte commented Apr 24, 2018

Because the check of -out parameter calls app_access on its argument. I think we could remove that check, really, but haven't dared to, yet. Either way, we may have to handle "nul" specifically when opening the file...

@bernd-edlinger
Copy link
Member

bernd-edlinger commented Apr 24, 2018

and "con", "com1", etc...?
and "\\.\nul" as well?

@levitte
Copy link
Member Author

levitte commented Apr 24, 2018

Good question, and I would rather not have to, so alternate solutions are welcome.
/notawindowsguy

@bernd-edlinger
Copy link
Member

Me neither....
I haven't looked at the code yet, but my feeling is we should probably remove the _access test,
maybe instead only check that the string is not empty, and be prepared that open can fail.

@dot-asm
Copy link
Contributor

dot-asm commented Apr 24, 2018

Ready for another surprise? \\.\GLOBALROOT\device\null. No, double-l is not a typo.

If I may. First step is done, user is claimed to be ultimately responsible for actions. Just make the next step, omit the test. It's user responsibility even to pick the suitable file name for the environment, it's really between user and underlying OS. To be completely honest, I'd even go as far as arguing for omitting whole recipe. What is it that is tested really? OS ability to tell apart files from directories? Ability to note non-existing directory? Are these actually our problems? Ability to chmod 0555 to make directory non-writable? Well, even on Linux it's actually file-system-specific. For example, you can chmod 0555 a directory on vfat as much as you like, it won't make any difference... You can argue that nobody would run test on vfat file system, but then nobody would use /dev/null as output for key generation either....

@dot-asm
Copy link
Contributor

dot-asm commented Apr 24, 2018

For example, you can chmod 0555 a directory on [Linux] vfat as much as you like, it won't make any difference...

Same can be said about Windows, either FAT or NTFS. chmod 0555 adds read-only attribute to directory, but it has no effect on your ability to create files in the directory.

@levitte
Copy link
Member Author

levitte commented Apr 24, 2018

I wouldn't remove the test yet, I wanna see that our code can handle what the user throws at us correctly (i.e in a manner that a user should be able to expect, such as "nul" on the command prompt being correctly interpreted as the null device and not generating a silly error).
Considering _access doesn't seem to handle "nul" (i.e treats it as invalid), I'm questioning the whole "POSIX API" (including _open), and until we have shown for ourselves that we are treating this right, I think the recipe should stay. Perhaps not in its entirety, but still...

@dot-asm
Copy link
Contributor

dot-asm commented Apr 24, 2018

I wouldn't remove the test yet,

Then for negative testing I'd say one directory is sufficient, ".", and test for file in non-existing directory. I'd also say that there is no need to test for time (it's unreliable anyway), just check for exit code would do.

I wanna see that our code can handle what the user throws at us correctly (i.e in a manner that a user should be able to expect, such as "nul" on the command prompt being correctly interpreted as the null device and not generating a silly error).

Do [Windows] users actually have such specific expectations? Besides, you really can't do better than underlying system and systems do perform differently. So that there is no such thing as universal expectations, they have to be adjusted to specifics.

I'm questioning the whole "POSIX API" (including _open)

_open can open "nul". Because it actually translates to native system call. But what "POSIX API"? Does POSIX specify "_access" or "_open"? No. It's "access" and "open". What Microsoft provides is a porting aid, not actual POSIX API. It has limitations, and user should be aware of them. Once again, you can't do better than underlying system.

@levitte
Copy link
Member Author

levitte commented Apr 24, 2018

But what "POSIX API"? Does POSIX specify "_access" or "_open"? No. It's "access" and "open".

Exactly, that's why I wrote POSIX API within quotes, because it isn't really.

Do [Windows] users actually have such specific expectations?

I don't understand the question... in Unix and on VMS, there is a null device, and users on those platforms expect whatever they send that way to disappear. Are you telling me Windows users don't want to do something like that as well?

Reduce the amount of testing.  We only need to check that one attempt
to write to a directory fails, and we can skip checking writability to
"protected" directories.  Finally, we skip trying to check by timing,
and we can further reduce the testing code to make it look less
complex.

foreach (@failure_paths) {
my $path = File::Spec->canonpath($_);
ok(!run(app([ 'openssl', 'genrsa', '-out', $path, '2048'])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have be such expensive operation? Of course it's hardly noticeable on your desktop, but do you have to make Raspberry Pi user suffer [more than necessary]? rand -out $path would do... Or why not convert something from pem to der?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I suppose it applies more to success tests. That is if we assume that failure test would fail early....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for it is that this was already in the recipe before I started fiddling with it, and I simply didn't think further. Of course we can change that to something better suited for quick checks...

use "openssl rand" rather than "openssl genrsa"
# For example, if cross compiled and tested on the build host, perl will
# generate an incorrect NULL device name.
# We might expand the exceptions...
unless (config('target') =~ m|^mingw| && $^O ne 'msys') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's possible to test Linux cross-compiled targets with qemu-user (since they use same file system), it's not really inappropriate to simply assume that perl's devnull has no meaning to any cross-compiled target. Incidentally this will work out even for mingw builds performed under Linux and Cygwin. Because they are customarily performed with --cross-compile-prefix. In other words one can wonder if simple check for cross-compile prefix would be adequate. Do note "adequate", as this is really what it's about. I mean it's effectively impossible to specify condition that is guaranteed to work in all circumstances, you can only go for what has best chances to work in most cases. Of course it has to work with CIs, but as long as _access is out of picture check for cross-compile prefix should do the trick...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so now I should check config('CROSS_COMPILE')? 'cause back over here, you told me a different story.

... buuuuuuut ok, you say check cross compile prefix, I will check cross compile prefix.

Copy link
Contributor

@dot-asm dot-asm Apr 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so now I should check config('CROSS_COMPILE')?

I said "one can wonder if it would be adequate," which is not same [as to] say "do this" :-)

'cause back over here, you told me a different story.

But then I also said "Grrrr! MSYS2 cheats!" I.e. by that time I didn't actually realize that msys perl would convert "/dev/null" to "nul" when starting native binary such as "mingw". I thought that it would do same as Linux and Cygwin perls, i.e. actually pass "/dev/null".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Grrrr! MSYS2 cheats!"

Besides, context is different now. That's what makes it hard to nail, which can be frustrating and appear contradicting at different occasions. It's multi-variable problem with no exact solution. Change one variable, like _access call removal, and suddenly check for cross-compile prefix makes more sense than other possible options. But it's just that it makes more sense, not that it's absolutely "the right thing to do ever"...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said "one can wonder if it would be adequate," which is not same [as to] say "do this" :-)

True that... well, it does cover the mingw on Linux cases, and I've been wondering more than once what happens with other explicitly cross compiled environments. I think this covers quite a lot of the cases we commonly test for, though... right?

@dot-asm
Copy link
Contributor

dot-asm commented Apr 24, 2018

As soon as WIP is removed...

@mspncp
Copy link
Contributor

mspncp commented Apr 24, 2018

i.e. lower their expectations.

For something as well know as "nul"? I think that's harsh, really.

I don't think it's necessary to lower their expectations. Peoply which are stuck with cmd.exe generally have very low expectations about their shell. ;-)

@levitte levitte changed the title WIP: Revert -out option checks Revert -out option checks Apr 25, 2018
@levitte
Copy link
Member Author

levitte commented Apr 25, 2018

WIP removed.

'./',
);
my @success_paths = (
'test.pem'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now with rand -out this is no longer suitable name. test.bin perhaps? Or random.bin? Or randomly generated name with .bin extension?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the reminder, that was on my mind before going to sleep yesterday

Copy link
Contributor

@dot-asm dot-asm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Red cross from appveyor is unrelated.

levitte added a commit that referenced this pull request Apr 25, 2018
Test writing to the null device.  This should be successful.

Also, refactor so the planned number of tests is calculated.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #6033)
levitte added a commit that referenced this pull request Apr 25, 2018
This reverts commit f6d7659.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #6033)
levitte added a commit that referenced this pull request Apr 25, 2018
This reverts commit 215a673.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #6033)
levitte added a commit that referenced this pull request Apr 25, 2018
This reverts commit 555c94a.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #6033)
levitte added a commit that referenced this pull request Apr 25, 2018
[extended tests]

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #6033)
levitte added a commit that referenced this pull request Apr 25, 2018
open() will take care of the checks anyway

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #6033)
@levitte
Copy link
Member Author

levitte commented Apr 25, 2018

Merged (including commit from #6031)

4522e13 apps/opt.c: Remove the access checks of input and output files
c36e909 Better check of return values from app_isdir and app_access
96de2e5 Revert "Check directory is able to create files for various -out option"
b47b665 Revert "Add VMS version of app_dirname()"
b9a354d Revert "Check on VMS as well"
39e32be test/recipes/15-test_out_option.t: refine tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rand -out /dev/null gives permission denied
5 participants