unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/8] net_reader: avoid IO::Socket::SSL 2.079..2.081 warning
Date: Tue,  3 Oct 2023 06:43:46 +0000	[thread overview]
Message-ID: <20231003064352.2902298-3-e@80x24.org> (raw)
In-Reply-To: <20231003064352.2902298-1-e@80x24.org>

IO::Socket::SSL had an unitialized variable warning from a bad
regexp for a few releases.  This will also prepare us to support
imap.sslverify as git does and possibly other TLS-related
options.
---
 lib/PublicInbox/NetReader.pm | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 32e4c20f..e14b5805 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -40,6 +40,15 @@ EOM
 	die "$val not understood (only socks5h:// is supported)\n";
 }
 
+# gives an arrayref suitable for the Mail::IMAPClient Ssl or Starttls arg
+sub mic_tls_opt ($$) {
+	my ($o, $hostname) = @_;
+	require IO::Socket::SSL;
+	$o = {} if !ref($o);
+	$o->{SSL_hostname} //= $hostname;
+	[ map { ($_, $o->{$_}) } keys %$o ];
+}
+
 sub mic_new ($$$$) {
 	my ($self, $mic_arg, $sec, $uri) = @_;
 	my %mic_arg = (%$mic_arg, Keepalive => 1);
@@ -54,12 +63,20 @@ sub mic_new ($$$$) {
 		$opt{ConnectPort} = delete $mic_arg{Port};
 		my $s = IO::Socket::Socks->new(%opt) or die
 			"E: <$uri> ".eval('$IO::Socket::Socks::SOCKS_ERROR');
-		if ($mic_arg->{Ssl}) { # for imaps://
-			require IO::Socket::SSL;
-			$s = IO::Socket::SSL->start_SSL($s) or die
+		if (my $o = delete $mic_arg{Ssl}) { # for imaps://
+			$o = mic_tls_opt($o, $opt{ConnectAddr});
+			$s = IO::Socket::SSL->start_SSL($s, @$o) or die
 				"E: <$uri> ".(IO::Socket::SSL->errstr // '');
+		} elsif ($o = $mic_arg{Starttls}) {
+			# Mail::IMAPClient will use this:
+			$mic_arg{Starttls} = mic_tls_opt($o, $opt{ConnectAddr});
 		}
 		$mic_arg{Socket} = $s;
+	} elsif ($mic_arg{Ssl} || $mic_arg{Starttls}) {
+		for my $f (qw(Ssl Starttls)) {
+			my $o = $mic_arg{$f} or next;
+			$mic_arg{$f} = mic_tls_opt($o, $mic_arg{Server});
+		}
 	}
 	PublicInbox::IMAPClient->new(%mic_arg);
 }

  parent reply	other threads:[~2023-10-03  6:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03  6:43 [PATCH 0/8] IMAP/NNTP client improvements Eric Wong
2023-10-03  6:43 ` [PATCH 1/8] net_reader: bail out on NNTP SOCKS connection failure Eric Wong
2023-10-03  6:43 ` Eric Wong [this message]
2023-10-03  6:43 ` [PATCH 3/8] config: fix key-only truthy values with urlmatch Eric Wong
2023-10-03  6:43 ` [PATCH 4/8] net_reader: support imap.sslVerify + nntp.sslVerify Eric Wong
2023-10-03  6:43 ` [PATCH 5/8] lei: workers exit after they tell lei-daemon Eric Wong
2023-10-03  6:43 ` [PATCH 6/8] net_reader: process title reflects NNTP article Eric Wong
2023-10-03  6:43 ` [PATCH 7/8] xt/lei-onion-convert: test TLS + SOCKS Eric Wong
2023-10-03  6:43 ` [PATCH 8/8] net_reader: note glob support in .onion hint Eric Wong
2023-10-03  7:11 ` "SSL" in option names is weird in 2023 Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231003064352.2902298-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).