Esempio n. 1
0
def _getinfos_cert(spec):
    """Extract info from a certificate (hash values, issuer, subject,
    algorithm) in an handy-to-index-and-query form.

    """
    try:
        cert = utils.decode_b64(spec.get('fullvalue', spec['value']).encode())
    except Exception:
        utils.LOGGER.info("Cannot parse certificate for record %r", spec,
                          exc_info=True)
        return {}
    info = utils.get_cert_info(cert)
    fullinfo = {}
    for key, value in list(viewitems(info)):
        if key in ['issuer', 'subject']:
            for skey, svalue in list(viewitems(value)):
                if len(svalue) > utils.MAXVALLEN:
                    fullinfo.setdefault(key, {})[skey] = svalue
                    info[key][skey] = svalue[:utils.MAXVALLEN]
        elif len(value) > utils.MAXVALLEN:
            fullinfo[key] = value
            info[key] = value[:utils.MAXVALLEN]
    res = {}
    if info:
        res['infos'] = info
    if fullinfo:
        res['fullinfos'] = fullinfo
    return res
Esempio n. 2
0
def _getinfos_cert(spec):
    """Extract info from a certificate (hash values, issuer, subject,
    algorithm) in an handy-to-index-and-query form.

    """
    # TODO: move to mongodb specific functions.
    try:
        cert = utils.decode_b64(spec["value"].encode())
    except Exception:
        utils.LOGGER.info("Cannot parse certificate for record %r", spec, exc_info=True)
        return {}
    info = utils.get_cert_info(cert)
    res = {}
    if info:
        res["infos"] = info
    return res
Esempio n. 3
0
def _getinfos_cert(spec):
    """Extract info from a certificate (hash values, issuer, subject,
    algorithm) in an handy-to-index-and-query form.

    """
    # TODO: move to mongodb specific functions.
    try:
        cert = utils.decode_b64(spec['value'].encode())
    except Exception:
        utils.LOGGER.info("Cannot parse certificate for record %r", spec,
                          exc_info=True)
        return {}
    info = utils.get_cert_info(cert)
    res = {}
    if info:
        res['infos'] = info
    return res
Esempio n. 4
0
def _getinfos_cert(spec, to_binary):
    """Extract info from a certificate (hash values, issuer, subject,
    algorithm) in an handy-to-index-and-query form.

    """
    try:
        cert = utils.decode_b64(spec.pop('fullvalue', spec['value']).encode())
    except Exception:
        utils.LOGGER.info("Cannot parse certificate for record %r",
                          spec,
                          exc_info=True)
        return {}
    if len(cert) > utils.MAXVALLEN:
        spec['fullvalue'] = to_binary(cert)
        spec['value'] = hashlib.sha1(cert).hexdigest()
    else:
        spec['value'] = to_binary(cert)
    info = utils.get_cert_info(cert)
    fullinfo = {}
    for key, value in list(viewitems(info)):
        if key in ['issuer', 'subject']:
            for skey, svalue in list(viewitems(value)):
                # We enforce a utils.MAXVALLEN // 10 size limits for
                # subkey values in subject and issuer; this is because
                # MongoDB cannot index values longer than 1024 bytes,
                # and subject and issuer fields may have more than one
                # key.
                if len(svalue) > utils.MAXVALLEN // 10:
                    fullinfo.setdefault(key, {})[skey] = svalue
                    info[key][skey] = svalue[:utils.MAXVALLEN // 10]
        elif len(value) > utils.MAXVALLEN:
            fullinfo[key] = value
            info[key] = value[:utils.MAXVALLEN]
    res = {}
    if info:
        res['infos'] = info
    if fullinfo:
        res['fullinfos'] = fullinfo
    return res