bypass ssl security while fetching invalid https url

This commit is contained in:
Carl Chenet 2019-12-25 23:27:44 +01:00
parent bae51858e6
commit 15415e369a
6 changed files with 54 additions and 4 deletions

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright © 2015-2019 Carl Chenet <carl.chenet@ohmytux.com>
# 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 <http://www.gnu.org/licenses/
# Get values of the ignoressl option of the rss section
'''Get values of the ignoressl option of the rss section'''
# standard library imports
import ssl
def parseignoressl(config, ignore_ssl_from_cli):
'''Parse configuration values and get values of the feedparser section'''
section = 'rss'
option = 'ignore_ssl'
if config.has_option(section, option):
ignoressl = config.getboolean(section, option)
else:
ignoressl = ignore_ssl_from_cli
return ignoressl

View file

@ -18,10 +18,11 @@
# standard library imports
import feedparser
import ssl
import sys
import re
def parseuri(config, clioption, feeds):
def parseuri(config, clioption, feeds, ignoressl):
'''Parse configuration value of the uri option of the rss section'''
rssuri = ''
feedname =''
@ -48,6 +49,10 @@ def parseuri(config, clioption, feeds):
sys.exit('{confoption} parameter in the [{section}] section of the configuration file is mandatory. Exiting.'.format(section=section, confoption=confoption))
else:
rssuri = clioption
# ignore ssl if asked
if ignoressl:
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context
# get the rss feed for rss parameter of [rss] section
feed = feedparser.parse(rssuri)
if not feed:

View file

@ -20,10 +20,11 @@
import feedparser
import logging
import os.path
import ssl
import sys
import re
def parseurilist(config, accept_bozo_exceptions):
def parseurilist(config, accept_bozo_exceptions, ignoressl):
'''Parse configuration value of the uri_list option of the rss section'''
bozoexception = False
feeds = []
@ -62,6 +63,10 @@ def parseurilist(config, accept_bozo_exceptions):
patternstring = ''
# split different searched patterns
patterns = [i for i in patternstring.split(stringsep) if i]
# ignore ssl if asked
if ignoressl:
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context
# retrieve the content of the rss
feed = feedparser.parse(rss)
if 'bozo_exception' in feed: