Ошибка генерации ключей с помощью OpenSSL в Ubuntu 22.04.4Python

Программы на Python
Anonymous
Ошибка генерации ключей с помощью OpenSSL в Ubuntu 22.04.4

Сообщение Anonymous »


I have a python script with functions for generating keys, signing messages, encrypting and decrypting them.

def gen_keys(key_name): result1 = subprocess.call([ 'openssl', 'genpkey', '-algorithm', 'RSA', '-provider-path', '/usr/lib/x86_64-linux-gnu/ossl-modules', '-provider', 'legacy', '-out', f'{key_name}_private_key.pem' ]) result2 = subprocess.call([ 'openssl', 'pkey', '-pubout', '-in', f'{key_name}_private_key.pem', '-out', f'{key_name}_public_key.pem' ]) if result1 != 0 or result2 != 0: print(f"Error gen {key_name} keys") return False return True def sign_message(key_name, message): with open('message.txt', 'w') as file: file.write(message) result = subprocess.call([ 'openssl', 'dgst', '-sha256', '-sign', f'{key_name}_private_key.pem', '-out', 'signature.sig', 'message.txt' ]) if result != 0: print(f"Error signing message with {key_name}'s private key") return False return True def verify_signature(key_name, message_path, signature_path): result = subprocess.call([ 'openssl', 'dgst', '-sha256', '-verify', f'{key_name}_public_key.pem', '-signature', signature_path, message_path ]) return result == 0 def encrypt_message(key_name, message_path, encrypted_message_path): result = subprocess.call([ 'openssl', 'cms', '-encrypt', '-in', message_path, '-out', encrypted_message_path, '-recip', f'{key_name}_public_key.pem', '-keyopt', 'rsa_padding_mode:oaep', '-cipher', 'aes-256-cbc' ]) if result != 0: print(f"Error encrypting message with {key_name}'s public key") return False return True def decrypt_message(key_name, encrypted_message_path, decrypted_message_path): result = subprocess.call([ 'openssl', 'cms', '-decrypt', '-in', encrypted_message_path, '-out', decrypted_message_path, '-recip', f'{key_name}_private_key.pem' ]) if result != 0: print(f"Error decrypting message with {key_name}'s private key") return False return True Then I use keys for verifying signatures, decrypting and encrypting messages, but I get this error:

Verified OK Verified OK Could not read recipient certificate file from client_private_key.pem 4027E61AB47F0000:error:1608010C:STORE routines:ossl_store_handle_load_result:unsupported:../crypto/store/store_result.c:151: Unable to load recipient certificate file Error decrypting message with client's private key Could not read recipient certificate file from server_private_key.pem 40575BD9937F0000:error:1608010C:STORE routines:ossl_store_handle_load_result:unsupported:../crypto/store/store_result.c:151: Unable to load recipient certificate file Error decrypting message with server's private key I checked if files are in path (they are), I have full access to them. So I don't know why I always receiving error like this, but I'm not an expert in OpenSSL


Источник: https://stackoverflow.com/questions/780 ... tu-22-04-4

Вернуться в «Python»