Beispiel #1
0
def newnonce(request):
    """ new nonce """
    if request.method in ['HEAD', 'GET']:
        with Nonce(DEBUG, LOGGER) as nonce:
            if request.method == 'HEAD':
                response = HttpResponse('')
            else:
                response = HttpResponse(status=204)
            # generate nonce
            response['Replay-Nonce'] = nonce.generate_and_add()

            # logging
            logger_info(LOGGER, request.META['REMOTE_ADDR'],
                        request.META['PATH_INFO'],
                        {'header': {
                            'Replay-Nonce': response['Replay-Nonce']
                        }})
            # send response
            return response
    else:
        return JsonResponse(status=400,
                            data={
                                'status':
                                405,
                                'message':
                                'Method Not Allowed',
                                'detail':
                                'Wrong request type. Expected HEAD or GET.'
                            })
 def __init__(self, debug=None, srv_name=None, logger=None):
     self.server_name = srv_name
     self.debug = debug
     self.logger = logger
     self.dbstore = DBstore(debug, self.logger)
     self.message = Message(debug, self.server_name, self.logger)
     self.nonce = Nonce(debug, self.logger)
     self.validity = 86400
     self.expiry_check_disable = False
     self.path_dic = {'authz_path': '/acme/authz/'}
Beispiel #3
0
 def setUp(self):
     """ setup unittest """
     models_mock = MagicMock()
     models_mock.acme_srv.db_handler.DBstore.return_value = FakeDBStore
     modules = {'acme_srv.db_handler': models_mock}
     patch.dict('sys.modules', modules).start()
     import logging
     logging.basicConfig(level=logging.CRITICAL)
     self.logger = logging.getLogger('test_a2c')
     from acme_srv.nonce import Nonce
     self.nonce = Nonce(False, self.logger)
Beispiel #4
0
def newnonce(environ, start_response):
    """ generate a new nonce """
    if environ['REQUEST_METHOD'] in ['HEAD', 'GET']:
        nonce = Nonce(DEBUG, LOGGER)
        headers = [('Content-Type', 'text/plain'), ('Replay-Nonce', '{0}'.format(nonce.generate_and_add()))]
        status = '200 OK' if environ['REQUEST_METHOD'] == 'HEAD' else '204 No content'
        start_response(status, headers)
        return []
    else:
        start_response('405 {0}'.format(HTTP_CODE_DIC[405]), [('Content-Type', 'application/json')])
        return [json.dumps({'status':405, 'message':HTTP_CODE_DIC[405], 'detail': 'Wrong request type. Expected HEAD or GET.'}).encode('utf-8')]
Beispiel #5
0
 def __init__(self, debug=None, srv_name=None, logger=None):
     self.debug = debug
     self.logger = logger
     self.nonce = Nonce(self.debug, self.logger)
     self.dbstore = DBstore(self.debug, self.logger)
     self.server_name = srv_name
     self.path_dic = {
         'acct_path': '/acme/acct/',
         'revocation_path': '/acme/revokecert'
     }
     self.disable_dic = {
         'signature_check_disable': False,
         'nonce_check_disable': False
     }
     self._config_load()