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

cert_pem_extract_expiration_date #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions ejbca_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
"EjbcaClient",
"SubjectDN",
"cert_pem_extract_serial",
"cert_pem_extract_expiration_date",
]
21 changes: 20 additions & 1 deletion ejbca_client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
from pathlib import Path
from typing import Optional, Union, List, Tuple
from typing import Dict, Optional, Union, List, Tuple

import zeep
import zeep.exceptions
Expand Down Expand Up @@ -423,3 +423,22 @@ def _cert_data_to_pem(self, cert_data: "certificate") -> str:
"""Extract from certificate object only certificate"""
cert = "-----BEGIN CERTIFICATE-----\n{}\n-----END CERTIFICATE-----"
return cert.format(cert_data.certificateData.decode())

def get_available_certificate_profiles(self, entity_profile_id: int) -> List[Dict[str, Union[str, int]]]:
"""
Fetches available certificate profiles in an end entity profile.

Args:
entity_profile_id: ID of end entity profile

Returns:
[{'name': 'EndEntityProfile', 'id': 123}, ...]

"""
try:
profiles = self._client.service.getAvailableCertificateProfiles(entity_profile_id)
except zeep.exceptions.Fault as e:
raise EjbcaClientException(str(e))
except zeep.exceptions.Error as e:
raise ZeepError(str(e))
return profiles
6 changes: 6 additions & 0 deletions ejbca_client/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import Optional
from dataclasses import dataclass

Expand Down Expand Up @@ -29,3 +30,8 @@ def __str__(self):
def cert_pem_extract_serial(cert: str) -> str:
cert_obj = x509.load_pem_x509_certificate(cert.encode())
return "{:x}".format(cert_obj.serial_number)


def cert_pem_extract_expiration_date(cert: str) -> datetime:
cert_obj = x509.load_pem_x509_certificate(cert.encode())
return cert_obj.not_valid_after