diff options
author | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-03-20 19:10:20 -0300 |
---|---|---|
committer | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-03-23 12:18:50 -0300 |
commit | 1d649b6476aa50e3158cc5641ce9201f859e818f (patch) | |
tree | b88d043b51607ae0db276f62022ccd6541340723 /service | |
parent | 8a83d8701d8d233cdbbcb7c06133fea13797a4d5 (diff) |
#333 Implemented downlload ca.crt when pixelated-user-agent doesn't find a cert file to connect on LEAP provider
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/bitmask_libraries/certs.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/service/pixelated/bitmask_libraries/certs.py b/service/pixelated/bitmask_libraries/certs.py index ed597ca8..4ee28a19 100644 --- a/service/pixelated/bitmask_libraries/certs.py +++ b/service/pixelated/bitmask_libraries/certs.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import os +import requests +import json from leap.common import ca_bundle @@ -46,7 +48,17 @@ class LeapCertificate(object): def _local_server_cert(self): cert_file = os.path.join(self._certs_home, '%s.ca.crt' % self._server_name) - if os.path.isfile(cert_file): - return cert_file - else: - return None + if not os.path.isfile(cert_file): + self._download_server_cert(cert_file) + + return cert_file + + def _download_server_cert(self, cert_file_name): + response = requests.get('https://%s/provider.json' % self._server_name) + provider_data = json.loads(response.content) + ca_cert_uri = str(provider_data['ca_cert_uri']) + + response = requests.get(ca_cert_uri) + with open(cert_file_name, 'w') as file: + file.write(response.content) + file.close |