93
96
def get_ppa_info_from_lp(owner_name, ppa_name):
94
97
lp_url = LAUNCHPAD_PPA_API % (owner_name, ppa_name)
97
request = urllib.request.Request(str(lp_url), headers={"Accept":" application/json"})
98
lp_page = urllib.request.urlopen(request, cafile=LAUNCHPAD_PPA_CERT)
99
json_data = lp_page.read().decode("utf-8", "strict")
100
except URLError as e:
101
raise PPAException("Error reading %s: %s" % (lp_url, e.reason), e)
107
callback = CurlCallback()
109
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
110
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
111
curl.setopt(pycurl.WRITEFUNCTION, callback.body_callback)
112
if LAUNCHPAD_PPA_CERT:
113
curl.setopt(pycurl.CAINFO, LAUNCHPAD_PPA_CERT)
114
curl.setopt(pycurl.URL, str(lp_url))
115
curl.setopt(pycurl.HTTPHEADER, ["Accept: application/json"])
118
json_data = callback.contents
119
except pycurl.error as e:
120
raise PPAException("Error reading %s: %s" % (lp_url, e), e)
121
return json.loads(json_data)
99
# python2 has no cert verification so we need pycurl
100
return _get_https_content_pycurl(lp_url)
102
# python3 has cert verification so we can use the buildin urllib
103
return _get_https_content_py3(lp_url)
105
def _get_https_content_py3(lp_url):
107
request = urllib.request.Request(str(lp_url), headers={"Accept":" application/json"})
108
lp_page = urllib.request.urlopen(request, cafile=LAUNCHPAD_PPA_CERT)
109
json_data = lp_page.read().decode("utf-8", "strict")
110
except (URLError, HTTPException) as e:
111
# HTTPException doesn't have a reason but might have a string
113
reason = hasattr(e, "reason") and e.reason or e
114
raise PPAException("Error reading %s: %s" % (lp_url, reason), e)
115
return json.loads(json_data)
117
def _get_https_content_pycurl(lp_url):
118
# this is the fallback code for python2
120
callback = CurlCallback()
122
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
123
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
124
curl.setopt(pycurl.WRITEFUNCTION, callback.body_callback)
125
if LAUNCHPAD_PPA_CERT:
126
curl.setopt(pycurl.CAINFO, LAUNCHPAD_PPA_CERT)
127
curl.setopt(pycurl.URL, str(lp_url))
128
curl.setopt(pycurl.HTTPHEADER, ["Accept: application/json"])
131
json_data = callback.contents
132
except pycurl.error as e:
133
raise PPAException("Error reading %s: %s" % (lp_url, e), e)
134
return json.loads(json_data)
124
136
def verify_keyid_is_v4(signing_key_fingerprint):
125
137
"""Verify that the keyid is a v4 fingerprint with at least 160bit"""