def verify_certsh(domain):
    crt_results = crtsh.get_results(domain) 
    in_db = False
    malicious = False
    if not crt_results:
        malicious = True
    else:
        certs = Certs.get_all_certs()
        for c in certs:
            if crt_results.get('caid') == c.get('caid'):
                malicious = c.get('is_bad') 
                in_db = True

    if not malicious and not in_db and crt_results:
        Certs.add_cert(
            _caid=crt_results.get('caid'), 
            _subject_organizationName=crt_results.get('subject').get('org_name'), 
            _subject_countryName=crt_results.get('subject').get('country'),
            _issuer_commonName=crt_results.get('issuer').get('common_name'),
            _registered_at=crt_results.get('registered_at'),
            _multi_dns=crt_results.get('multi_dns_amount')
        )
    elif malicious and not in_db and crt_results:
        Certs.add_cert(
            _caid=crt_results.get('caid'), 
            _subject_organizationName=crt_results.get('subject').get('org_name'), 
            _subject_countryName=crt_results.get('subject').get('country'),
            _issuer_commonName=crt_results.get('issuer').get('common_name'),
            _registered_at=crt_results.get('registered_at'),
            _multi_dns=crt_results.get('multi_dns_amount'),
            _is_bad=True
        )
    return malicious
 def test_get_cert_results_empty(self):
     domain = "http://."
     info("Requested domain - {}".format(domain))
     l = get_results(domain)
     assert_none(
         l,
         "Check if returned object with unexisting certificate details is empty/None"
     )
 def test_get_cert_results(self):
     domain = "example.com"
     info("Requested domain - {}".format(domain))
     l = get_results(domain)
     assert_type(
         l, dict,
         "Check if returned object with certificate details is proper dict")
     assert_not_empty(l, "Check if cert details dict is not empty")
Exemple #4
0
def get_crtsh_details(url_body):
    try:
        jsonschema.validate(url_body, details_url_schema)
    except jsonschema.exceptions.ValidationError as exc:
        raise BadRequest(exc.message)

    domain = url_to_domain(url_body.get('url'))
    results = crtsh.get_results(domain)
    if not results:
        return _no_data_response()

    response_text = {
        "details": results
    }
    return Response(json.dumps(
            response_text,
            default=_default_json_model
            ), 200, mimetype="application/json")
Exemple #5
0
def add_cert(domain, is_bad=False):
    """

    Returns:
        True if successfully added cert + add id
        False if not successful and None

    """
    crt_results = crtsh.get_results(domain)
    if not crt_results:
        return False, -1

    crt_id = Certs.add_cert(crt_results.get('caid'),
                            crt_results.get('subject').get('org_name'),
                            crt_results.get('subject').get('country'),
                            crt_results.get('issuer').get('common_name'),
                            crt_results.get('registered_at'),
                            crt_results.get('multi_dns_amount'), is_bad)
    if crt_id:
        return True, crt_id
    else:
        return False, -1