Example #1
0
 def _get_installed_certificates_details(self, bundles, dests):
     app.logger.debug(f'_get_installed_certificates_details:\n{locals}')
     summary = self._get_installed_summary(bundles, dests)
     details = {}
     if summary:
         common_names, paths, dests = zip(*summary)
         calls = self.gets(paths=paths,
                           dests=dests,
                           product=False,
                           verify_ssl=False)
         for common_name, path, dest, call in zip(common_names, paths,
                                                  dests, calls):
             try:
                 crt = windows2unix(
                     call.recv.json.properties.basic.get(
                         'public', 'missing'))
                 csr = windows2unix(
                     call.recv.json.properties.basic.get(
                         'request', 'missing'))
                 key = windows2unix(
                     call.recv.json.properties.basic.get(
                         'private', 'missing'))
                 note = call.recv.json.properties.basic.get('note', '')
             except Exception as ex:
                 app.logger.debug(f'call.send.url={call.send.url}')
                 app.logger.debug(f'call.recv.json=\n{call.recv.json}')
                 raise ex
             details[(common_name, crt[:40])] = details.get(
                 (common_name, crt[:40]), {})
             details[(common_name, crt[:40])][dest] = (key, csr, crt, note)
     return details
Example #2
0
    async def _request(self,
                       method,
                       url=None,
                       auth=None,
                       headers=None,
                       json=None,
                       raise_if=None,
                       raise_ex=None,
                       repeat_if=None,
                       repeat_wait=3,
                       repeat_delta=None,
                       verify_ssl=True,
                       **kwargs):

        start = datetime.now()
        connector = aiohttp.TCPConnector(verify_ssl=verify_ssl)
        async with aiohttp.ClientSession(connector=connector,
                                         loop=self._loop) as session:
            repeat = 0
            while True:
                send_datetime = datetime.utcnow()
                async with session.request(
                        method,
                        url,
                        headers=headers,
                        auth=aiohttp.helpers.BasicAuth(*auth),
                        data=json_dumps(json) if json else None,
                        **kwargs) as response:

                    text = await response.text()
                    recv_datetime = datetime.utcnow()
                    send = AttrDict(method=method,
                                    url=url,
                                    json=json,
                                    headers=headers,
                                    datetime=send_datetime)
                    json = None
                    if response.headers['Content-Type'] == 'application/json':
                        json = await response.json()
                    recv = AttrDict(headers=dict(response.headers.items()),
                                    status=response.status,
                                    text=windows2unix(text),
                                    json=json,
                                    repeat=repeat,
                                    datetime=datetime.utcnow())
                    call = AttrDict(response=response, send=send, recv=recv)
                self.calls += [call]
                if repeat_if and repeat_if(call):
                    delta = datetime.now() - start
                    if repeat_delta and delta < repeat_delta:
                        repeat += 1
                        pfmt('{delta} < {repeat_delta}; repeat {repeat}')
                        await asyncio.sleep(repeat_wait)
                        continue
                if raise_if and raise_if(call):
                    if raise_ex:
                        raise raise_ex(call)
                    raise RaiseIfError(call)
                break
        return call
Example #3
0
 def _get_installed_certificates_details(self, certs, *dests):
     summary = self._get_installed_summary(certs, *dests)
     details = {}
     if summary:
         common_names, paths, dests = zip(*summary)
         calls = self.gets(paths=paths, dests=dests, verify_ssl=False)
         for common_name, path, dest, call in zip(common_names, paths,
                                                  dests, calls):
             crt = windows2unix(call.recv.json.properties.basic.public)
             csr = windows2unix(call.recv.json.properties.basic.request)
             key = windows2unix(call.recv.json.properties.basic.private)
             note = call.recv.json.properties.basic.note
             details[(common_name, crt[:40])] = details.get(
                 (common_name, crt[:40]), {})
             details[(common_name, crt[:40])][dest] = dict(crt=crt,
                                                           csr=csr,
                                                           key=key,
                                                           note=note)
     return details
Example #4
0
 def display_certificates(self, bundles, repeat_delta=None):
     app.logger.info(f'display_certificates:\n{locals}')
     order_ids = [bundle.authority['digicert']['order_id'] for bundle in bundles]
     calls = self._get_certificate_order_detail(order_ids)
     certificate_ids = [call.recv.json.certificate.id for call in calls]
     crts = self._download_certificates(certificate_ids, repeat_delta=repeat_delta)
     expiries = [expiryify(call) for call in calls]
     csrs = [windows2unix(call.recv.json.certificate.csr) for call in calls]
     for expiry, csr, crt, bundle in zip(expiries, csrs, crts, bundles):
         matched = csr.strip() == bundle.csr.strip() and crt.strip() == bundle.crt.strip()
         bundle.authority['digicert']['matched'] = matched
     return bundles