Changeset ebbfb2b in mod_gnutls
- Timestamp:
- Apr 24, 2020, 2:08:26 PM (3 years ago)
- Branches:
- asyncio, main, master, proxy-ticket
- Children:
- 2089d49
- Parents:
- 199acff
- git-author:
- Krista Karppinen <krista.celestia@…> (04/24/20 13:20:47)
- git-committer:
- Krista Karppinen <krista.celestia@…> (04/24/20 14:08:26)
- Location:
- test
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/tests/36_OCSP_server_nonce/hooks.py
r199acff rebbfb2b 1 import base64 1 2 import os 2 3 import re 3 import subprocess 4 from mgstest import require_match 4 from mgstest import require_match, TestExpectationFailed 5 from mgstest.ocsp import OCSPRequest, OCSPResponse 6 from pathlib import Path 5 7 from unittest import SkipTest 6 8 9 10 LOGFILE = Path('logs/36_OCSP_server_nonce.ocsp.error.log') 11 LOGFILE_POSITION = 0 12 13 7 14 def prepare_env(): 8 if not 'OCSP_PORT'in os.environ:15 if 'OCSP_PORT' not in os.environ: 9 16 raise SkipTest('OCSP_PORT is not set, check if openssl is available.') 17 18 # Seek to the end of server log 19 if LOGFILE.exists(): 20 global LOGFILE_POSITION 21 LOGFILE_POSITION = LOGFILE.stat().st_size 22 10 23 11 24 def post_check(conn_log, response_log): … … 13 26 print(require_match(re.compile(r'^- Options: .*OCSP status request,'), 14 27 conn_log).group(0)) 28 29 print('Checking for outputs/36-ocsp.der:') 30 ocsp_response = OCSPResponse.parse_file('outputs/36-ocsp.der') 31 print(ocsp_response) 32 15 33 print('Checking if the client got a nonce in the stapled response:') 16 print(require_match( 17 re.compile(r'^\s*Nonce: [0-9a-fA-F]{46}$'), 18 parse_ocsp_response('outputs/36-ocsp.der').split('\n') 19 ).group(0)) 34 resp_nonce = ocsp_response.get_field('nonce').get_value() 35 print(resp_nonce) 20 36 21 def parse_ocsp_response(der_filename): 22 command = ['ocsptool', '--response-info', 23 '--infile', der_filename] 24 return subprocess.check_output(command).decode() 37 print('Checking if the server log contains an OCSP request') 38 with LOGFILE.open() as log: 39 print(f'Seeking to position {LOGFILE_POSITION}') 40 log.seek(LOGFILE_POSITION) 41 ocsp_request = None 42 43 while ocsp_request is None: 44 log_match = require_match( 45 re.compile(r"Received OCSP request: '([^']*)'"), 46 log 47 ) 48 test_request = OCSPRequest.parse_str( 49 base64.b64decode(log_match.group(1))) 50 print(repr(test_request)) 51 if ocsp_response.matches_request(test_request): 52 print("Request matches response") 53 ocsp_request = test_request 54 else: 55 print("Request doesn't match response") 56 57 print('Checking if the OCSP request has a nonce') 58 req_nonce = ocsp_request.get_field('nonce').get_value() 59 print(req_nonce) 60 61 print('Checking if the request and response nonces match') 62 if resp_nonce != req_nonce: 63 raise TestExpectationFailed('Nonce mismatch!')
Note: See TracChangeset
for help on using the changeset viewer.