From 15415e369a7d07517af318d3f66d8c690d06e250 Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Wed, 25 Dec 2019 23:27:44 +0100 Subject: [PATCH] bypass ssl security while fetching invalid https url --- docs/source/configure.rst | 2 ++ feed2toot/cliparse.py | 3 +++ feed2toot/confparse.py | 9 ++++++-- feed2toot/confparsers/rss/ignoressl.py | 30 ++++++++++++++++++++++++++ feed2toot/confparsers/rss/uri.py | 7 +++++- feed2toot/confparsers/rss/urilist.py | 7 +++++- 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 feed2toot/confparsers/rss/ignoressl.py diff --git a/docs/source/configure.rst b/docs/source/configure.rst index 25677da..a6f1170 100644 --- a/docs/source/configure.rst +++ b/docs/source/configure.rst @@ -44,6 +44,7 @@ In order to configure Feed2toot, you need to create a feed2toot.ini file (or any title_pattern=Open Source title_pattern_case_sensitive=true no_uri_pattern_no_global_pattern=true + ; ignore_ssl=false [hashtaglist] several_words_hashtags_list=/etc/feed2toot/hashtags.txt @@ -85,6 +86,7 @@ For the [rss] section: - {one field of the rss feed}_pattern_case_sensitive: either the pattern matching for the specified field should be case sensitive or not. Default to true if not specified. - no_uri_pattern_no_global_pattern: don't apply global pattern (see above) when no pattern-by-uri is defined in the uri_list. Allows to get all entries of a rss in the uri_list because no pattern is defined so we match them all. Defaults to false, meaning the global patterns will be tried on every rss in the uri_list NOT HAVING specific patterns and so ONLY entries from the specific uri in the uri_list matching the global patterns will be considered. addtags: add the tags from the rss feed at the end of the toot. Defaults to true. +- ignore_ssl: when the uri or uri_list contains an https url with an invalid certificate (e.g an expired one), feed2toot will be unable to get rss content. This option allows to bypass the ssl security to catch the rss content. Defaults to false. For the [hashtaglist] section: diff --git a/feed2toot/cliparse.py b/feed2toot/cliparse.py index 971d2f3..7e36d46 100644 --- a/feed2toot/cliparse.py +++ b/feed2toot/cliparse.py @@ -50,6 +50,9 @@ class CliParse: parser.add_argument('-a', '--all', action='store_true', default=False, dest='all', help='tweet all RSS items, regardless of cache') + parser.add_argument('--ignore-ssl', action='store_true', default=False, + dest='ignore_ssl', + help='ignore ssl errors while fetching rss feeds') parser.add_argument('-l', '--limit', dest='limit', default=10, type=int, help='tweet only LIMIT items (default: %(default)s)') parser.add_argument('-t', '--lock-timeout', dest='locktimeout', default=3600, type=int, diff --git a/feed2toot/confparse.py b/feed2toot/confparse.py index f592bb1..dcf6ee1 100644 --- a/feed2toot/confparse.py +++ b/feed2toot/confparse.py @@ -34,6 +34,7 @@ from feed2toot.confparsers.feedparser import parsefeedparser from feed2toot.confparsers.lock import parselock from feed2toot.confparsers.media import parsemedia from feed2toot.confparsers.plugins import parseplugins +from feed2toot.confparsers.rss.ignoressl import parseignoressl from feed2toot.confparsers.rss.pattern import parsepattern from feed2toot.confparsers.rss.toot import parsetoot from feed2toot.confparsers.rss.uri import parseuri @@ -78,15 +79,19 @@ class ConfParse: # addtags option, default: True ############################### options['addtags'] = parseaddtags(config) + ################### + # ignore_ssl option + ################### + ignore_ssl = parseignoressl(config, self.clioptions.ignore_ssl) ################# # uri_list option ################# feeds = [] - feeds = parseurilist(config, accept_bozo_exceptions) + feeds = parseurilist(config, accept_bozo_exceptions, ignore_ssl) ############ # uri option ############ - options['rss_uri'], feed, feedname, options['nopatternurinoglobalpattern'] = parseuri(config, self.clioptions.rss_uri, feeds) + options['rss_uri'], feed, feedname, options['nopatternurinoglobalpattern'] = parseuri(config, self.clioptions.rss_uri, feeds, ignore_ssl) ########################### # the cache section ########################### diff --git a/feed2toot/confparsers/rss/ignoressl.py b/feed2toot/confparsers/rss/ignoressl.py new file mode 100644 index 0000000..269b19c --- /dev/null +++ b/feed2toot/confparsers/rss/ignoressl.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Copyright © 2015-2019 Carl Chenet +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see