certapi 0.2.3__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {certapi-0.2.3 → certapi-0.2.4}/PKG-INFO +3 -1
  2. {certapi-0.2.3 → certapi-0.2.4}/README.md +2 -0
  3. {certapi-0.2.3 → certapi-0.2.4}/setup.py +1 -1
  4. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/Acme.py +3 -3
  5. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/certauthority.py +8 -4
  6. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/crypto.py +5 -0
  7. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/db.py +25 -15
  8. {certapi-0.2.3 → certapi-0.2.4}/src/certapi.egg-info/PKG-INFO +3 -1
  9. {certapi-0.2.3 → certapi-0.2.4}/MANIFEST.in +0 -0
  10. {certapi-0.2.3 → certapi-0.2.4}/pyproject.toml +0 -0
  11. {certapi-0.2.3 → certapi-0.2.4}/setup.cfg +0 -0
  12. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/__init__.py +0 -0
  13. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/challenge.py +0 -0
  14. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/cloudflare_challenge_store.py +0 -0
  15. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/cloudflare_client.py +0 -0
  16. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/crypto_classes.py +0 -0
  17. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/custom_certauthority.py +0 -0
  18. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/digitalocean_challenge_store.py +0 -0
  19. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/digitalocean_client.py +0 -0
  20. {certapi-0.2.3 → certapi-0.2.4}/src/certapi/util.py +0 -0
  21. {certapi-0.2.3 → certapi-0.2.4}/src/certapi.egg-info/SOURCES.txt +0 -0
  22. {certapi-0.2.3 → certapi-0.2.4}/src/certapi.egg-info/dependency_links.txt +0 -0
  23. {certapi-0.2.3 → certapi-0.2.4}/src/certapi.egg-info/requires.txt +0 -0
  24. {certapi-0.2.3 → certapi-0.2.4}/src/certapi.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: certapi
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Python Package for managing keys, request SSL certificates from ACME.
5
5
  Home-page: https://github.com/mesudip/certapi
6
6
  Author: Sudip Bhattarai
@@ -16,6 +16,8 @@ Description-Content-Type: text/markdown
16
16
  CertApi is a Python package for requesting SSL certificates from ACME.
17
17
  This is supposed to be used as a base library for building other tools, or to integrate Certificate creation feature in you app.
18
18
 
19
+ > ⚠️ Warning: This project is not polished for production use. Please stay tuned for the LTS `v1.0.0` release.
20
+
19
21
  ## Installation
20
22
 
21
23
  You can install CertApi using pip:
@@ -3,6 +3,8 @@
3
3
  CertApi is a Python package for requesting SSL certificates from ACME.
4
4
  This is supposed to be used as a base library for building other tools, or to integrate Certificate creation feature in you app.
5
5
 
6
+ > ⚠️ Warning: This project is not polished for production use. Please stay tuned for the LTS `v1.0.0` release.
7
+
6
8
  ## Installation
7
9
 
8
10
  You can install CertApi using pip:
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="certapi",
5
- version="0.2.3",
5
+ version="0.2.4",
6
6
  packages=find_packages(where="src"),
7
7
  package_dir={"": "src"},
8
8
  install_requires=[
@@ -326,7 +326,7 @@ class Order:
326
326
  self.status = self._data["status"]
327
327
  return response
328
328
 
329
- def get_certificate(self) -> Certificate:
329
+ def get_certificate(self) -> Tuple[str, List[Certificate]]:
330
330
  if self.status == "processing":
331
331
  raise ValueError(
332
332
  "Order is still in 'processing' state! Wait until the order is finalized, and call `Order.refresh()` to update the state"
@@ -337,8 +337,8 @@ class Order:
337
337
  certificate_res = self._acme._signed_req(
338
338
  self._data["certificate"], step="Get Certificate from Successful Order"
339
339
  )
340
- certificate = crypto.x509.load_pem_x509_certificate(certificate_res.content)
341
- return certificate
340
+ certificate = crypto.x509.load_pem_x509_certificates(certificate_res.content)
341
+ return ( certificate_res.content, certificate)
342
342
 
343
343
  def finalize(self, csr: CertificateSigningRequest):
344
344
  """
@@ -121,10 +121,10 @@ class CertAuthority:
121
121
  order.refresh() # is this refresh necessary?
122
122
 
123
123
  if order.status == "valid":
124
- certificate = order.get_certificate()
124
+ fullchain_cert,certificate = order.get_certificate()
125
125
  key_id = self.key_store.save_key(private_key, missing[0])
126
126
  cert_id = self.key_store.save_cert(key_id, certificate, missing)
127
- issued_cert = IssuedCert(key_to_pem(private_key), certificate, missing)
127
+ issued_cert = IssuedCert(key_to_pem(private_key), fullchain_cert, missing)
128
128
  # Clean up challenges after successful certificate issuance
129
129
  for c in challenges:
130
130
  challenge_name = f"_acme-challenge.{c.domain}" if has_wildcard else c.token
@@ -145,24 +145,28 @@ class CertAuthority:
145
145
  return createExistingResponse(existing, [])
146
146
 
147
147
 
148
- def createExistingResponse(existing: Dict[str, Tuple[int | str, Key, Certificate]], issued_certs: List["IssuedCert"]):
148
+ def createExistingResponse(existing: Dict[str, Tuple[int | str, Key, Certificate | str]], issued_certs: List["IssuedCert"]):
149
149
  certs = []
150
150
  certMap = {}
151
+
151
152
  for h, (id, key, cert) in existing.items():
152
153
  if id in certMap:
153
154
  certMap[id][0].append(h)
154
155
  else:
156
+ cert_pem = cert if isinstance(cert, str) else cert_to_pem(cert).decode("utf-8")
155
157
  certMap[id] = (
156
158
  [h],
157
159
  key.to_pem().decode("utf-8"),
158
- cert_to_pem(cert).decode("utf-8"),
160
+ cert_pem,
159
161
  )
162
+
160
163
  for hosts, key, cert in certMap.values():
161
164
  certs.append(IssuedCert(key, cert, hosts))
162
165
 
163
166
  return CertificateResponse(certs, issued_certs)
164
167
 
165
168
 
169
+
166
170
  class CertificateResponse:
167
171
  def __init__(self, existing, issued):
168
172
  self.existing: List[IssuedCert] = existing
@@ -106,6 +106,11 @@ def key_from_pem(data: bytes):
106
106
  def cert_from_pem(data: bytes) -> Certificate:
107
107
  return x509.load_pem_x509_certificate(data)
108
108
 
109
+ def certs_from_pem(data: bytes) -> List[Certificate]:
110
+ return x509.load_pem_x509_certificates(data)
111
+
112
+ def cert_to_der(cert):
113
+ return cert.public_bytes(serialization.Encoding.DER)
109
114
 
110
115
  def cert_to_pem(cert):
111
116
  return cert.public_bytes(serialization.Encoding.PEM)
@@ -21,7 +21,7 @@ class KeyStore(ABC):
21
21
  pass
22
22
 
23
23
  @abstractmethod
24
- def save_cert(self, private_key_id: int, cert: Certificate, domains: List[str], name: str = None) -> int:
24
+ def save_cert(self, private_key_id: int, cert: Certificate|str, domains: List[str], name: str = None) -> int:
25
25
  pass
26
26
 
27
27
  @abstractmethod
@@ -91,12 +91,12 @@ class SqliteKeyStore(KeyStore):
91
91
  self.save_key(key, name)
92
92
  return key
93
93
 
94
- def save_cert(self, private_key_id: int, cert: Certificate, domains: List[str], name: str = None) -> int:
94
+ def save_cert(self, private_key_id: int, cert: Certificate|str, domains: List[str], name: str = None) -> int:
95
95
  conn = self._get_db_connection()
96
96
  cur = conn.cursor()
97
97
  cur.execute(
98
98
  "INSERT INTO certificates (name, priv_id, content) VALUES (?, ?, ?)",
99
- (name, private_key_id, cert.public_bytes(serialization.Encoding.DER)),
99
+ (name, private_key_id, cert_to_der(cert)),
100
100
  )
101
101
  cert_id = cur.lastrowid
102
102
 
@@ -182,32 +182,42 @@ class FilesystemKeyStore(KeyStore):
182
182
  return cert_from_pem(cert_data)
183
183
  return None
184
184
 
185
- def save_cert(self, private_key_id: str, cert: Certificate, domains: list, name: str = None) -> int:
185
+
186
+ def save_cert(self, private_key_id: str, cert: Certificate | str, domains: list, name: str = None) -> int:
187
+ def get_cert_pem(cert) -> bytes:
188
+ return cert.encode() if isinstance(cert, str) else cert_to_pem(cert)
189
+
190
+ cert_pem = get_cert_pem(cert)
191
+
186
192
  if name:
187
193
  cert_path = os.path.join(self.certs_dir, f"{name}.crt")
188
194
  with open(cert_path, "wb") as f:
189
- f.write(cert_to_pem(cert))
195
+ f.write(cert_pem)
196
+
190
197
  key_content = None
191
198
  key_path = os.path.join(self.keys_dir, f"{private_key_id}.key")
192
199
  with open(key_path, "rb") as f:
193
200
  key_content = f.read()
194
-
201
+
195
202
  for domain in domains:
203
+ domain_name = domain
196
204
  if name is not None and name.endswith(".selfsigned"):
197
- domain = domain + ".selfsigned"
205
+ domain_name += ".selfsigned"
198
206
 
199
- if domain != private_key_id:
200
- with open(os.path.join(self.keys_dir, f"{domain}.key"), "wb") as f:
207
+ if domain_name != private_key_id:
208
+ with open(os.path.join(self.keys_dir, f"{domain_name}.key"), "wb") as f:
201
209
  f.write(key_content)
202
- domain_cert_path = os.path.join(self.certs_dir, f"{domain}.crt")
210
+
211
+ domain_cert_path = os.path.join(self.certs_dir, f"{domain_name}.crt")
203
212
  with open(domain_cert_path, "wb") as f:
204
- f.write(cert_to_pem(cert))
213
+ f.write(cert_pem)
214
+
205
215
 
206
216
  return name if name else domains[0] # Dummy ID since filesystem does not use numeric IDs
207
217
 
208
- def get_cert(self, domain: str) -> None | Tuple[str, Key, Certificate]:
209
- cert_path = os.path.join(self.certs_dir, f"{domain}.crt")
210
- key_path = os.path.join(self.keys_dir, f"{domain}.key")
218
+ def get_cert(self, name: str) -> None | Tuple[str, Key, Certificate]:
219
+ cert_path = os.path.join(self.certs_dir, f"{name}.crt")
220
+ key_path = os.path.join(self.keys_dir, f"{name}.key")
211
221
  key = None
212
222
  cert = None
213
223
  if os.path.exists(key_path):
@@ -226,7 +236,7 @@ class FilesystemKeyStore(KeyStore):
226
236
 
227
237
  if cert is None or key is None:
228
238
  return None
229
- return (domain, key, cert)
239
+ return (name, key, cert)
230
240
 
231
241
 
232
242
  class PostgresKeyStore(KeyStore):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: certapi
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Python Package for managing keys, request SSL certificates from ACME.
5
5
  Home-page: https://github.com/mesudip/certapi
6
6
  Author: Sudip Bhattarai
@@ -16,6 +16,8 @@ Description-Content-Type: text/markdown
16
16
  CertApi is a Python package for requesting SSL certificates from ACME.
17
17
  This is supposed to be used as a base library for building other tools, or to integrate Certificate creation feature in you app.
18
18
 
19
+ > ⚠️ Warning: This project is not polished for production use. Please stay tuned for the LTS `v1.0.0` release.
20
+
19
21
  ## Installation
20
22
 
21
23
  You can install CertApi using pip:
File without changes
File without changes
File without changes
File without changes
File without changes