Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x509: fix type issues; a 2019.2-based variant of PR #52014, fixes #52026 #52456

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions salt/modules/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def read_crl(crl):
text = get_pem_entry(text, pem_type="X509 CRL")

crltempfile = tempfile.NamedTemporaryFile()
crltempfile.write(salt.utils.stringutils.to_str(text))
crltempfile.write(salt.utils.stringutils.to_bytes(text, encoding="ascii"))
crltempfile.flush()
crlparsed = _parse_openssl_crl(crltempfile.name)
crltempfile.close()
Expand Down Expand Up @@ -742,7 +742,7 @@ def get_public_key(key, passphrase=None, asObj=False):
return evppubkey

rsa.save_pub_key_bio(bio)
return bio.read_all()
return bio.read_all().decode()


def get_private_key_size(private_key, passphrase=None):
Expand Down Expand Up @@ -1410,9 +1410,11 @@ def create_certificate(path=None, text=False, overwrite=True, ca_server=None, **
"if requesting remote certificate from ca_server {0}.".format(ca_server)
)
if "csr" in kwargs:
kwargs["csr"] = get_pem_entry(
kwargs["csr"], pem_type="CERTIFICATE REQUEST"
).replace("\n", "")
kwargs["csr"] = (
get_pem_entry(kwargs["csr"], pem_type="CERTIFICATE REQUEST")
.decode()
.replace("\n", "")
)
if "public_key" in kwargs:
# Strip newlines to make passing through as cli functions easier
kwargs["public_key"] = salt.utils.stringutils.to_str(
Expand Down Expand Up @@ -1842,13 +1844,13 @@ def verify_crl(crl, cert):
crltext = _text_or_file(crl)
crltext = get_pem_entry(crltext, pem_type="X509 CRL")
crltempfile = tempfile.NamedTemporaryFile()
crltempfile.write(salt.utils.stringutils.to_str(crltext))
crltempfile.write(salt.utils.stringutils.to_bytes(crltext, encoding="ascii"))
crltempfile.flush()

certtext = _text_or_file(cert)
certtext = get_pem_entry(certtext, pem_type="CERTIFICATE")
certtempfile = tempfile.NamedTemporaryFile()
certtempfile.write(salt.utils.stringutils.to_str(certtext))
certtempfile.write(salt.utils.stringutils.to_bytes(certtext, encoding="ascii"))
certtempfile.flush()

cmd = "openssl crl -noout -in {0} -CAfile {1}".format(
Expand Down
2 changes: 1 addition & 1 deletion salt/states/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def certificate_managed(
):
private_key = __salt__["x509.get_pem_entry"](
private_key_args["name"], pem_type="RSA PRIVATE KEY"
)
).decode()
else:
new_private_key = True
private_key = __salt__["x509.create_private_key"](
Expand Down