Skip to content

RFC: Making SSL_verify safer #152

Open
@shadowcat-mst

Description

@shadowcat-mst

BACKGROUND

Before I start: The actual patch in #151 is not honestly a bad starting point here, it appears this fact has been obscured in the pre-existing discussion due to the description being right at the end of the PR text - and the start of said text seeming sufficiently absolutist that people pattern matched to previous less well thought out proposals.

However, before anybody tries to put together another PR I think it's probably best if we actually discuss what's desired as a matter of policy first (also I owe xdg a debt of thanks still for providing me with Nagios Enterprises as a chew toy a few years back, so I'm inclined to at least -try- and be nice).

I'll note that if we'd had a time machine, having SSL_verify default to 1 out of the box could have turned out to be better overall, but I don't have a TARDIS and Let's Encrypt didn't exist when that decision was made, and, welp, so it goes.

CURRENT SITUATION

SSL_verify defaults to 0, which is not the worst idea for maximally enabling bootstrapping of cpan, but since lots of people have decided to use this module all over CPAN rather than depending on a proper useragent it's fairly clear the playing field is not what it was.

(and believe me, if we'd only cored it as CPAN::HTTP::Client then cpan authors would've used that anyway, humans are gonna human)

Debian keeps having "let's just force it to 1" flare ups which they understandably keep rejecting due to the compat and user confusion issues.

NixOS has apparently applied that patch anyway, but it basically specialises in "everything is different and confusing" so I somehow doubt anybody who's got as far as actually being able to install it will be surprised or troubled by that (and everybody should try doing it at least once, because nixos' qemu/kvm based configuration integration testing system is in fact really cool).

DEFINITELY A GOOD IDEA

In order to not break anything existing but make users aware of potential problems, I think @nrdvana's proposal to have a once-per-process warning plus environment variables is actually excellent - and having an env var for setting default behaviour and one for overriding provides a nice level of flexibility.

I would, in fact, endorse a completed version of the existing PR as being a substantial improvement on the status quo (and the single-warning model means it's unlikely to cause carnage).

It may also be preferable to allow a user to add something like:

use HTTP::Tiny::Defaults { SSL_verify => 1 };

at the top of a script in order to deal with a recalcitrant cpan module used multiple layers down.

POSSIBLY AN EVEN BETTER IDEA

Rather than preserving the undef value internally and modifying the accessor, I think we can go one better.

(please consider all names both below to have been pulled out of whichever orifice is least traumatic for you to imagine)

If we add an C<SSL_verify_cb> constructor option, and if it's present invoke it something like:

if (my $cb = $self->SSL_verify_cb) {
  weaken(my $weak = $self);
  Net::SSLeay::set_verify ($ssl, Net::SSLeay::VERIFY_PEER, sub { $weak->$cb(@_) });
}

then in the case where SSL_verify isn't provided, the code can set this to C<SSL_verify_warn_on_mismatch> to call

sub SSL_verify_warn_on_mismatch {
  my ($self, $ok, $ctx) = @_;
  return $ok if $ok;
  my $error = Net::SSLeay::X509_STORE_CTX_get_error($ctx);
  warn "Certificate mismatch: ${error}";
  return 1;
}

(note, I lifted the callback arguments and the how to get the error part from an SSLeay test, so any part of it that works should be credited to that and any part that doesn't is presumably me being daft)

which should mean that users running in what's effectively "dunno if they wanted verification and forgot to ask" mode will still get to see problems without AFAICT breaking anything except possibly people's Test::NoWarnings (or equivalent) using t/ files.

This would also allow users who're unsure what their current situation is to set this option themselves so they can -see- if there are verification failures in the code they're running without breaking anything - which seems like an excellent way of making people less scared of turning the security feature properly at some point.

SUMMARY

I think the number of previous attempts at "just turn it on, obviously that couldn't possibly cause any problems" has made this issue trickier to discuss than would've been optimal, but I think if we actually -have- a discussion about it we can get somewhere.

I'll also drop this into #toolchain for comments, and if the consensus is "we like this idea but let's get the PSC to ack it" (for whichever value of "this idea" eventually gets agreed upon) I'm happy to go chase them down.

-- mst

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions