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

Fixed Certificate Names with Slashes or Paratheses #222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions certipy/commands/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ def configuration_to_json(self, configuration: dict) -> str:
return json.dumps(output)

def get_configuration(self, template) -> LDAPEntry:
ldap_formatted_template = (template.replace("\\", "\\5c")
.replace("(", "\\28")
.replace(")", "\\29")
.replace("*", "\\2a")
)
print(ldap_formatted_template)
results = self.connection.search(
"(&(cn=%s)(objectClass=pKICertificateTemplate))" % template,
search_filter=f"(&(cn={ldap_formatted_template})(objectClass=pKICertificateTemplate))",
search_base=self.connection.configuration_path,
query_sd=True,
)

if len(results) == 0:
results = self.connection.search(
"(&(displayName=%s)(objectClass=pKICertificateTemplate))" % template,
f"(&(displayName={ldap_formatted_template})(objectClass=pKICertificateTemplate))",
search_base=self.connection.configuration_path,
query_sd=True,
)
Expand Down Expand Up @@ -166,6 +172,8 @@ def set_configuration(self) -> bool:
)

out_file = "%s.json" % old_configuration.get("cn")
# Get rid of slashes to ensure template names with slashes don't break the filenames:
out_file = out_file.replace("\\", "").replace("/", "")
with open(out_file, "w") as f:
f.write(old_configuration_json)

Expand Down