Esempio n. 1
0
    def on_delete(self, req, resp, **params):
        if hasattr(self.resource.on_delete, 'no_retry'):
            return self.resource.on_delete(req, resp, **params)

        def wrapped_responder():
            return self.resource.on_delete(req, resp, **params)

        return run_transaction(wrapped_responder)
Esempio n. 2
0
def _read_secret_key_from_file_or_generate(path):

    if os.path.exists(path):
        return _validate_secretkey(_get_key_from_file(path))

    log.info('Secret key file `%s` does not exist.', path)

    def callback():
        return db.achieve_value_consensus(
            key='sharedkey', value=_generate_token_sign_sharedkey())

    key = run_transaction(callback)
    _write_new_keyfile(path, key)
    return key
Esempio n. 3
0
def read_private_key_from_file_or_generate_through_database(path):

    # Expose private key and public key as module-level globals as native
    # `cryptography` objects.
    global _public_key_cryptography
    global _private_key_cryptography

    if not os.path.exists(path):
        log.info('Private key file `%s` does not exist.', path)
        privkey_pem_proposal, _ = generate_RSA_keypair()

        def callback():
            return db.achieve_value_consensus(key='privkey',
                                              value=privkey_pem_proposal)

        privkey_pem_consens = run_transaction(callback)
        _write_new_keyfile(path, privkey_pem_consens)

    # Go through validation function, although input is trusted: the validation
    # function returns the private key as a native `cryptography` object which
    # is what we want.
    _private_key_cryptography = _validate_privatekey_pem(
        _get_key_from_file(path))
    _public_key_cryptography = _private_key_cryptography.public_key()
Esempio n. 4
0
    def on_delete(self, req, resp, **params):
        def wrapped_responder():
            return self.resource.on_delete(req, resp, **params)

        return run_transaction(wrapped_responder)