6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/bugs/gh_6858_test.py

92 lines
3.2 KiB
Python
Raw Normal View History

#coding:utf-8
#
# id: bugs.gh_6858
# title: RSA_DECRYPT() can not decrypt data if it relates to BLOB type
# decription:
# https://github.com/FirebirdSQL/firebird/issues/6858
#
# Confirmed bug on 4.0.0.2508; 5.0.0.75.
# Checked on intermediate builds 4.0.1.2517 (17.06.2021 15:12), 5.0.0.79 (17.06.2021 14:44) - all OK.
#
#
# tracker_id:
# min_versions: ['4.0']
# versions: 4.0
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
# version: 4.0
# resources: None
substitutions_1 = []
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
test_script_1 = """
recreate table test(
id int generated by default as identity constraint pk_txt primary key
,blb blob character set utf8
--,blb varchar(1) character set utf8
);
insert into test(blb) values('A');
commit;
-- NO errors must be issued during following EB execution:
-- ##############
-- Previous error messages see in commented lines below:
set term ^;
execute block
as
declare k_prv varbinary(16384);
declare k_pub varbinary(8192);
declare blob_encrypted blob character set octets;
declare vchr_encrypted varchar(256) character set octets;
declare blob_decrypted blob character set utf8;
declare vchr_decrypted varchar(10) character set utf8;
begin
k_prv = rsa_private(256);
k_pub = rsa_public(k_prv);
for select id, blb from test as cursor c
do begin
blob_encrypted = rsa_encrypt(c.blb key k_pub hash md5);
vchr_encrypted = rsa_encrypt(c.blb key k_pub hash md5);
--------------------------### 1 ###-------------------------------
-- SQLSTATE = 22023 / TomCrypt library error: Invalid input packet. / -Decrypting using cipher RSA
blob_decrypted = rsa_decrypt(blob_encrypted key k_prv hash md5);
--------------------------### 2 ###------------------------------------------
-- if declared length of `vchr_decrypted` is 256 then:
-- SQLSTATE = 22023 / TomCrypt library error: Invalid input packet. / -Decrypting using cipher RSA
-- if declared length of `vchr_decrypted` is 10, then OK:
vchr_decrypted = rsa_decrypt(blob_encrypted key k_prv hash md5);
--------------------------### 3 ###-------------------------------
-- malformed string
blob_decrypted = rsa_decrypt(vchr_encrypted key k_prv hash md5);
--------------------------### 4 ###-------------------------------
-- malformed string
vchr_decrypted = rsa_decrypt(vchr_encrypted key k_prv hash md5);
end
end
^
set term ;^
"""
act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
@pytest.mark.version('>=4.0')
def test_1(act_1: Action):
act_1.execute()
assert act_1.clean_stdout == act_1.clean_expected_stdout