[BUG] tls.create_self_signed_cert: fails with "C" longer/shorter than 2 characters
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
Using tls.create_self_signed_cert with C being longer than 2 chars, it'll fail like this:
OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_mbstring_ncopy', 'string too long')]
Using tls.create_self_signed_cert with C being shorter than 2 chars, it'll fail like this:
OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_mbstring_ncopy', 'string too short')]
Setup
No specific prerequisites required
Steps to Reproduce the behavior
Execute:
salt-call --local tls.create_self_signed_cert \
CN=SomeCommonName C=SomeCountry \
ST=SomeState L=SomeLocation \
O=SomeOrganization OU=SomeOrganizationalUnit \
emailAddress=some@email.address.test cacert_path=/tmp/selfsigned tls_dir=tls
Alternatively, set C=C to trigger the string too short case.
This will result in the following unhandled exception/Traceback:
[ERROR ] An un-handled exception was caught by salt's global exception handler:
Error: [('asn1 encoding routines', 'ASN1_mbstring_ncopy', 'string too long')]
Traceback (most recent call last):
File "/usr/bin/salt-call", line 11, in <module>
load_entry_point('salt==3002.2', 'console_scripts', 'salt-call')()
File "/usr/lib/python3/dist-packages/salt/scripts.py", line 449, in salt_call
client.run()
File "/usr/lib/python3/dist-packages/salt/cli/call.py", line 58, in run
caller.run()
File "/usr/lib/python3/dist-packages/salt/cli/caller.py", line 112, in run
ret = self.call()
File "/usr/lib/python3/dist-packages/salt/cli/caller.py", line 219, in call
ret["return"] = self.minion.executors[fname](
File "/usr/lib/python3/dist-packages/salt/executors/direct_call.py", line 12, in execute
return func(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/modules/tls.py", line 1275, in create_self_signed_cert
cert.get_subject().C = C
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 585, in __setattr__
_raise_current_error()
File "/usr/lib/python3/dist-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_mbstring_ncopy', 'string too long')]
Traceback (most recent call last):
File "/usr/bin/salt-call", line 11, in <module>
load_entry_point('salt==3002.2', 'console_scripts', 'salt-call')()
File "/usr/lib/python3/dist-packages/salt/scripts.py", line 449, in salt_call
client.run()
File "/usr/lib/python3/dist-packages/salt/cli/call.py", line 58, in run
caller.run()
File "/usr/lib/python3/dist-packages/salt/cli/caller.py", line 112, in run
ret = self.call()
File "/usr/lib/python3/dist-packages/salt/cli/caller.py", line 219, in call
ret["return"] = self.minion.executors[fname](
File "/usr/lib/python3/dist-packages/salt/executors/direct_call.py", line 12, in execute
return func(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/modules/tls.py", line 1275, in create_self_signed_cert
cert.get_subject().C = C
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 585, in __setattr__
_raise_current_error()
File "/usr/lib/python3/dist-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_mbstring_ncopy', 'string too long')]
Expected behavior
Either the self-signed key/certificate to be created or a reasonable error message pointing out invalid values of the passed parameters.
Versions Report
salt --versions-report
Salt Version:
Salt: 3002.2
Dependency Versions:
cffi: Not Installed
cherrypy: 8.9.1
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: 0.28.3
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.6.1
pygit2: 1.0.3
Python: 3.8.5 (default, Jul 28 2020, 12:59:40)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2
System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-56-generic
system: Linux
version: Ubuntu 20.04 focal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in salt/modules/tls.py at create_self_signed_cert, where the traceback shows the C subject field is assigned. Reproduce the issue with the provided salt-call command using one- and three-character C values, then ensure invalid country values produce a reasonable error or the certificate is created for valid input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100