Page MenuHomeVyOS Platform

PKI IMPORT: Traceback is received when passphrase is given for unencrypted private key
Open, LowPublicBUG

Description

Need a valid error message "TypeError: Password was given but private key is not encrypted." if the passphrase was not given while creating the certificate previously and then trying to import it.

vyos@OVPN# run import pki certificate client10 key-file /home/vyos/clien10.key
Enter private key passphrase:  vyos
Traceback (most recent call last):
  File "/usr/libexec/vyos/op_mode/pki.py", line 1048, in <module>
    import_certificate(args.certificate, path=args.filename, key_path=args.key_filename)
  File "/usr/libexec/vyos/op_mode/pki.py", line 750, in import_certificate
    key = load_private_key(key_data, passphrase=passphrase, wrap_tags=False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/pki.py", line 273, in load_private_key
    return serialization.load_pem_private_key(bytes(raw_data, 'utf-8'), password=passphrase)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/serialization/base.py", line 22, in load_pem_private_key
    return ossl.load_pem_private_key(data, password)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 921, in load_pem_private_key
    return self._load_key(
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1199, in _load_key
    raise TypeError(
TypeError: Password was given but private key is not encrypted.

Details

Version
1.4.1, 1.5-rolling-202501140634
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Bug (incorrect behavior)

Event Timeline

SrividyaA triaged this task as Low priority.