Пример #1
0
    def test_succeeds_if_level_less_than_block_to_sign(self):
        class DummyRPCClient:
            def get_current_level(self):
                return 649

        rs = RemoteSigner(self.TEST_CONFIG, self.VALID_BLOCK, DummyRPCClient())
        self.assertTrue(rs.is_within_level_threshold())
Пример #2
0
    def test_signs_block(self):
        class DummyRPCClient:
            def get_current_level(self):
                return 649

        rs = RemoteSigner(self.TEST_CONFIG, self.VALID_BLOCK, DummyRPCClient())
        self.assertEqual(rs.sign(7, test_mode=True), self.SIGNED_BLOCK)
Пример #3
0
    def test_fails_if_level_equal_to_block_to_sign(self):
        class DummyRPCClient:
            def get_current_level(self):
                return 650

        rs = RemoteSigner(self.TEST_CONFIG, self.VALID_BLOCK, DummyRPCClient())
        self.assertFalse(rs.is_within_level_threshold())
Пример #4
0
    def test_succeeds_if_level_greater_than_endorsement_to_sign(self):
        class DummyRPCClient:
            def get_current_level(self):
                return 635

        rs = RemoteSigner(self.TEST_CONFIG, self.VALID_ENDORSEMENT,
                          DummyRPCClient())
        self.assertTrue(rs.is_within_level_threshold())
Пример #5
0
def sign(key_hash):
    p2sig = ''
    response = None
    try:
        data = request.get_json(force=True)
        if key_hash in config['keys']:
            info('Found key_hash {} in config'.format(key_hash))
            key = config['keys'][key_hash]
            kvclient = KeyVaultClient(
                MSIAuthentication(resource='https://vault.azure.net'))
            info('Calling remote-signer method {}'.format(data))
            p2sig = RemoteSigner(kvclient, key['kv_keyname'], config,
                                 request.environ['REMOTE_ADDR'], data).sign()
            response = jsonify({'signature': p2sig})
            info('Response is {}'.format(response))
        else:
            warning("Couldn't find key {}".format(key_hash))
            response = Response('Key not found', status=404)
    except Exception as e:
        data = {'error': str(e)}
        error('Exception thrown during request: {}'.format(str(e)))
        response = app.response_class(response=json.dumps(data),
                                      status=500,
                                      mimetype='application/json')
    info('Returning flask response {}'.format(response))
    return response
Пример #6
0
def sign(key_hash):
    response = None
    try:
        data = request.get_json(force=True)
        if key_hash in config['keys']:
            logging.info('Found key_hash {} in config'.format(key_hash))
            key = config['keys'][key_hash]
            logging.info('Attempting to sign {}'.format(data))
            rs = RemoteSigner(config, data)
            response = jsonify({'signature': rs.sign(key['private_handle'])})
            logging.info('Response is {}'.format(response))
        else:
            logging.warning("Couldn't find key {}".format(key_hash))
            response = Response('Key not found', status=404)
    except Exception as e:
        data = {'error': str(e)}
        logging.error('Exception thrown during request: {}'.format(str(e)))
        response = app.response_class(response=json.dumps(data),
                                      status=500,
                                      mimetype='application/json')
    logging.info('Returning flask response {}'.format(response))
    return response
Пример #7
0
 def test_decodes_block_level(self):
     rs = RemoteSigner(self.TEST_CONFIG, self.VALID_BLOCK)
     self.assertEqual(rs.get_block_level(), 650)
Пример #8
0
 def test_identifies_valid_endorsement_preamble(self):
     rs = RemoteSigner(self.TEST_CONFIG, self.VALID_ENDORSEMENT)
     self.assertTrue(rs.is_endorsement())
Пример #9
0
 def test_identifies_valid_block_preamble(self):
     rs = RemoteSigner(self.TEST_CONFIG, self.VALID_BLOCK)
     self.assertTrue(rs.is_block())
Пример #10
0
 def test_identifies_invalid_block_preamble(self):
     rs = RemoteSigner(self.TEST_CONFIG, self.INVALID_PREAMBLE)
     self.assertFalse(rs.is_block())