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

Convert CSR to string #5067

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions lemur/plugins/lemur_acme/challenge_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

.. moduleauthor:: Mathias Petermann <[email protected]>
"""
from datetime import datetime, timedelta
import json
from datetime import datetime, timedelta

from acme import challenges
from acme.errors import WildcardUnsupportedError
from acme.messages import errors, STATUS_VALID, ERROR_CODES
from botocore.exceptions import ClientError
from flask import current_app
from retrying import retry
from sentry_sdk import capture_exception

from lemur.authorizations import service as authorization_service
from lemur.constants import ACME_ADDITIONAL_ATTEMPTS
from lemur.common.utils import drop_last_cert_from_chain
from lemur.constants import ACME_ADDITIONAL_ATTEMPTS
from lemur.destinations import service as destination_service
from lemur.exceptions import LemurException, InvalidConfiguration
from lemur.extensions import metrics
from lemur.plugins.base import plugins
from lemur.destinations import service as destination_service
from lemur.plugins.lemur_acme.acme_handlers import AcmeHandler, AcmeDnsHandler

from retrying import retry
from lemur.plugins.lemur_acme.plugin import csr_to_string


class AcmeChallengeMissmatchError(LemurException):
Expand Down Expand Up @@ -86,7 +86,7 @@ def create_certificate(self, csr, issuer_options):
authority = issuer_options.get("authority")
acme_client, registration = self.acme.setup_acme_client(authority)

orderr = acme_client.new_order(csr)
orderr = acme_client.new_order(csr_to_string(csr))

chall = []
deployed_challenges = []
Expand Down Expand Up @@ -266,7 +266,7 @@ def create_certificate(self, csr, issuer_options):
@retry(stop_max_attempt_number=ACME_ADDITIONAL_ATTEMPTS, wait_fixed=5000)
def create_certificate_immediately(self, acme_client, order_info, csr):
try:
order = acme_client.new_order(csr)
order = acme_client.new_order(csr_to_string(csr))
except WildcardUnsupportedError:
metrics.send("create_certificte_immediately_wildcard_unsupported", "counter", 1)
raise Exception(
Expand Down
13 changes: 8 additions & 5 deletions lemur/plugins/lemur_acme/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_ordered_certificate(self, pending_cert):
self.acme.autodetect_dns_providers(domain)

try:
order = acme_client.new_order(pending_cert.csr)
order = acme_client.new_order(csr_to_string(pending_cert.csr))
except WildcardUnsupportedError:
metrics.send("get_ordered_certificate_wildcard_unsupported", "counter", 1)
raise Exception(
Expand Down Expand Up @@ -191,10 +191,7 @@ def get_ordered_certificates(self, pending_certs):
self.acme.autodetect_dns_providers(domain)

try:
csr = pending_cert.csr
if isinstance(csr, str):
csr = csr.encode("ascii")
order = acme_client.new_order(csr)
order = acme_client.new_order(csr_to_string(pending_cert.csr))
except WildcardUnsupportedError:
capture_exception()
metrics.send(
Expand Down Expand Up @@ -469,3 +466,9 @@ def revoke_certificate(self, certificate, reason):
crl_reason = CRLReason[reason["crl_reason"]]

return self.acme.revoke_certificate(certificate, crl_reason.value)


def csr_to_string(csr):
if isinstance(csr, str):
return csr.encode("ascii")
return csr
Loading