From patchwork Wed Mar 28 14:41:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 1716 Return-Path: Received: from mail01.ipfire.org (mail01.ipfire.org [IPv6:2001:470:7183:25::1]) by web02.i.ipfire.org (Postfix) with ESMTP id 7E24560ACF for ; Wed, 28 Mar 2018 05:42:09 +0200 (CEST) X-Virus-Scanned: ClamAV at mail01.ipfire.org X-Spam-Flag: NO X-Spam-Score: -0.345 X-Spam-Level: X-Spam-Status: No, score=-0.345 tagged_above=-999 required=5 tests=[FROM_EXCESS_BASE64=0.105, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from mail01.i.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 47CF71008072; Wed, 28 Mar 2018 04:42:07 +0100 (BST) X-Virus-Scanned: ClamAV at mail01.ipfire.org Received: from mx-nbg.link38.eu (mx-nbg.link38.eu [37.120.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx-nbg.link38.eu", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 180AB108C399 for ; Wed, 28 Mar 2018 04:42:02 +0100 (BST) Authentication-Results: mail01.ipfire.org; dmarc=pass (p=none dis=none) header.from=link38.eu Authentication-Results: mail01.ipfire.org; spf=pass smtp.mailfrom=peter.mueller@link38.eu Date: Wed, 28 Mar 2018 05:41:50 +0200 From: Peter =?utf-8?q?M=C3=BCller?= To: Michael Tremer Subject: [PATCH v2] use protocol defined in server-list.db for mirror communication Message-ID: <20180328054150.2b9c8dd5.peter.mueller@link38.eu> In-Reply-To: <1522157838.556038.75.camel@ipfire.org> References: <20180324162218.28f9d594.peter.mueller@link38.eu> <1522071363.556038.31.camel@ipfire.org> <20180326205021.711a8437.peter.mueller@link38.eu> <1522157838.556038.75.camel@ipfire.org> MIME-Version: 1.0 Cc: development@lists.ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" For each mirror server, a protocol can be specified in the server-list.db database. However, it was not used for the actual URL query to a mirror before. This might be useful for deploy HTTPS pinning for Pakfire. If a mirror is known to support HTTPS, all queries to it will be made with this protocol. This saves some overhead if HTTPS is enforced on a mirror via 301 redirects. To enable this, the server-list.db needs to be adjusted. The second version of this patch only handles protocols HTTP and HTTPS, since we do not expect anything else here at the moment. Partially fixes #11661. Signed-off-by: Peter Müller Cc: Michael Tremer --- src/pakfire/lib/functions.pl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index c97d4254d..6cc177128 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -31,6 +31,8 @@ use HTTP::Message; use HTTP::Request; use Net::Ping; +use Switch; + package Pakfire; # A small color-hash :D @@ -172,7 +174,18 @@ sub fetchfile { } $final_data = undef; - my $url = "http://$host/$file"; + + my $url; + switch ($proto) { + case "HTTP" { $url = "http://$host/$file"; } + case "HTTPS" { $url = "https://$host/$file"; } + else { + # skip all lines with unknown protocols + logger("DOWNLOAD WARNING: Skipping Host: $host due to unknown protocol ($proto) in mirror database"); + next; + } + } + my $response; unless ($bfile =~ /^counter.py\?.*/) {