Example #1
0
 def _unknown_error(self, error):
     return InternalError(
         "Unknown error code {0} from OpenSSL, "
         "you should probably file a bug. {1}".format(
             error.code, self._err_string(error.code)
         )
     )
 async def test():
     future = MagicMock()
     # Private key generation returns error
     generate_pk_mock.side_effect = InternalError("", 0)
     await self.manager._get_challenge_done_success(future.result)
     schedule_next_bootstrap_mock.assert_has_calls(
         [call(hard_failure=True)], )
Example #3
0
def _openssl_assert(lib, ok):
    if not ok:
        errors = _consume_errors(lib)
        raise InternalError(
            "Unknown OpenSSL error. Please file an issue at https://github.com"
            "/pyca/cryptography/issues with information on how to reproduce "
            "this.", errors)
Example #4
0
def _openssl_assert(lib, ok):
    if not ok:
        errors = _consume_errors(lib)
        errors_with_text = []
        for err in errors:
            buf = ffi.new("char[]", 256)
            lib.ERR_error_string_n(err.code, buf, len(buf))
            err_text_reason = ffi.string(buf)

            errors_with_text.append(
                _OpenSSLErrorWithText(
                    err.code, err.lib, err.func, err.reason, err_text_reason
                )
            )

        raise InternalError(
            "Unknown OpenSSL error. This error is commonly encountered when "
            "another library is not cleaning up the OpenSSL error stack. If "
            "you are using cryptography with another library that uses "
            "OpenSSL try disabling it before reporting a bug. Otherwise "
            "please file an issue at https://github.com/pyca/cryptography/"
            "issues with information on how to reproduce "
            "this. ({0!r})".format(errors_with_text),
            errors_with_text
        )
Example #5
0
 def test__get_challenge_done_pk_exception(self, retry_bootstrap_mock, generate_pk_mock):
     future = MagicMock()
     future.exception = lambda: None
     # Private key generation returns error
     generate_pk_mock.side_effect = InternalError("", 0)
     self.manager._get_challenge_done(future)
     retry_bootstrap_mock.assert_has_calls([call(hard_failure=True)])
Example #6
0
    def _handle_error_code(self, code):
        lib = self._lib.ERR_GET_LIB(code)
        func = self._lib.ERR_GET_FUNC(code)
        reason = self._lib.ERR_GET_REASON(code)

        if lib == self._lib.ERR_LIB_EVP:
            if func == self._lib.EVP_F_EVP_ENCRYPTFINAL_EX:
                if reason == self._lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH:
                    raise ValueError(
                        "The length of the provided data is not a multiple of "
                        "the block length"
                    )
            elif func == self._lib.EVP_F_EVP_DECRYPTFINAL_EX:
                if reason == self._lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH:
                    raise ValueError(
                        "The length of the provided data is not a multiple of "
                        "the block length"
                    )

        raise InternalError(
            "Unknown error code {0} from OpenSSL, "
            "you should probably file a bug. {1}".format(
                code, self._err_string(code)
            )
        )
Example #7
0
 def _check_cipher_response(self, response):
     if response == self._lib.kCCSuccess:
         return
     elif response == self._lib.kCCAlignmentError:
         # This error is not currently triggered due to a bug filed as
         # rdar://15589470
         raise ValueError(
             "The length of the provided data is not a multiple of "
             "the block length.")
     else:
         raise InternalError(
             "The backend returned an unknown error, consider filing a bug."
             " Code: {0}.".format(response))
Example #8
0
def _openssl_assert(lib, ok):
    if not ok:
        errors_with_text = _consume_errors_with_text(lib)

        raise InternalError(
            "Unknown OpenSSL error. This error is commonly encountered when "
            "another library is not cleaning up the OpenSSL error stack. If "
            "you are using cryptography with another library that uses "
            "OpenSSL try disabling it before reporting a bug. Otherwise "
            "please file an issue at https://github.com/pyca/cryptography/"
            "issues with information on how to reproduce "
            "this. ({0!r})".format(errors_with_text),
            errors_with_text,
        )
Example #9
0
def _consume_errors(lib):
    if not ok:
        errors = _consume_errors(lib)
        errors_with_text = []
        for err in errors:
            buf = ffi.new("char[]", 256)
            lib.ERR_error_string_n(err.code, buf, len(buf))
            err_text_reason = ffi.string(buf)
            err_text_reason = ffi.string(buf)

            errors_with_text.append(
                _OpenSSLErrorWithText(err.code, err.lib, err.func, err.reason,
                                      err_text_reason))

        raise InternalError(
            "xxx"
            "xxx"
            "this. ({0!r})".format(errors_with_text), errors_with_text)