예제 #1
0
def test_readSMIMEsig_not_real_sig():
    l = mockLogger()
    eml_bytes = get_email_bytes('from-bob-attachment-not-sig.eml')
    cfg = mockConfig()
    read_smime_email(eml_bytes, cfg, l)
    assert l.contains('DKIM passed')
    assert not l.contains('written file')
예제 #2
0
def test_readSMIMEsig_valid():
    l = mockLogger()
    eml_bytes = get_email_bytes('signed-from-bob.eml')
    cfg = mockConfig()
    read_smime_email(eml_bytes, cfg, l)
    assert l.contains('DKIM passed')
    assert l.contains('user certificate passed')
    assert l.contains('written file')
예제 #3
0
def test_readSMIMEsig_corrupt_sig():
    l = mockLogger()
    eml_bytes = get_email_bytes('from-bob-corrupt-signature.eml')
    cfg = mockConfig()
    read_smime_email(eml_bytes, cfg, l)
    assert l.contains('DKIM passed')
    assert l.contains('verifying intermediate certificates')
    assert l.contains('unable to get local issuer certificate')
    assert not l.contains('written file')
예제 #4
0
def handle_inbound_relay():
    """
    Flask application entry point. Log actions to local application logfile.
    """
    logfile = 'webapp.log'
    logger = createLogger(logfile)
    logger.info('Request from {},scheme={},path={}'.format(
        request.remote_addr, request.scheme, request.path))
    logger.info('| len(headers)={},len(body)={}'.format(
        len(request.headers), request.content_length))

    # Check request data format, header token value is correct (if present)
    if request.content_type != 'application/json':
        logger.info('| Unknown Content-Type: {}'.format(request.content_type))
        raise InvalidUsage('Unknown Content-Type in request headers')

    config = configparser.ConfigParser()
    config.read('webapp.ini')
    cfg = config['webapp']

    expected_token = cfg.get('x-messagesystems-webhook-token')
    try:
        got_token = request.headers.get('X-MessageSystems-Webhook-Token')
    except KeyError:
        got_token = None
    if expected_token != None:
        if got_token != expected_token:
            logger.info(
                '| Invalid X-MessageSystems-Webhook-Token in request headers: {}, must match {}'
                .format(got_token, expected_token))
            raise InvalidUsage(
                'Invalid X-MessageSystems-Webhook-Token in request headers')

    req = request.get_json()
    for i in req:
        m = i['msys']['relay_message']
        c = m['content']
        rxMail = c['email_rfc822'].encode('utf8')
        logger.info('| msg_from={},rcpt_to={},len(email_rfc822)={}'.format(
            m['msg_from'], m['rcpt_to'], len(rxMail)))
        read_smime_email(rxMail, cfg, logger)
    return 'OK'
예제 #5
0
def test_readSMIMEsig_bad_DKIM():
    l = mockLogger()
    eml_bytes = get_email_bytes('signed-from-bob-bad-dkim.eml')
    cfg = mockConfig()
    read_smime_email(eml_bytes, cfg, l)
    assert l.contains('DKIM FAIL')