Skip to content

Commit 8f68e9a

Browse files
committed
Fixed up JKS for self-signed certs. Removed it for certbot certs
1 parent e73bd6b commit 8f68e9a

File tree

4 files changed

+4
-43
lines changed

4 files changed

+4
-43
lines changed

ecs-files-input.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,6 @@
415415
"certificates_registry_table_region": {
416416
"type": "string",
417417
"description": "Override the top level certificates_registry_table_region"
418-
},
419-
"jksConfig": {
420-
"$ref": "#/definitions/jksConfig",
421-
"description": "Automatically creates a JKS with the retrieved certificate."
422418
}
423419
}
424420
}

ecs_files_composer/certbot_aws_store.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,15 @@
1313
from boto3.session import Session
1414

1515
if TYPE_CHECKING:
16-
from .input import Model, CertbotAwsStoreCertificate
16+
from .input import Model
1717

1818
from os import makedirs, path
1919

20-
import jks as pyjks
2120
from certbot_aws_store.certificate import AcmeCertificate
22-
from OpenSSL import crypto
2321

2422
from ecs_files_composer.common import LOG
2523

2624

27-
def create_jks_config(
28-
certificate_name: str, certificate_job: CertbotAwsStoreCertificate
29-
):
30-
with open(
31-
f"{certificate_job.storage_path}/{AcmeCertificate.full_chain_file_name}"
32-
) as full_chain_fd:
33-
full_chain = crypto.load_certificate(crypto.FILETYPE_PEM, full_chain_fd.read())
34-
with open(
35-
f"{certificate_job.storage_path}/{AcmeCertificate.private_key_file_name}"
36-
) as priv_key_fd:
37-
private_key = priv_key_fd.read()
38-
39-
jks_path = path.abspath(
40-
f"{certificate_job.storage_path}/{certificate_job.jks_config.file_name}"
41-
)
42-
pkey = pyjks.jks.PrivateKeyEntry.new(
43-
certificate_name,
44-
certs=[crypto.dump_certificate(crypto.FILETYPE_ASN1, full_chain)],
45-
key=private_key,
46-
key_format="rsa_raw",
47-
)
48-
pkey.encrypt(certificate_job.jks_config.passphrase)
49-
keystore = pyjks.KeyStore.new("jks", [pkey])
50-
keystore.save(jks_path, certificate_job.jks_config.passphrase)
51-
52-
5325
def process_certbot_aws_store_certificates(job: Model) -> None:
5426
"""
5527
Pulls certificates from certbot-aws-store to local filesystem
@@ -83,5 +55,3 @@ def process_certbot_aws_store_certificates(job: Model) -> None:
8355
LOG.error(
8456
"Failed to download certificate from certbot-aws-store", _hostname
8557
)
86-
if _definition.jks_config:
87-
create_jks_config(_hostname, _definition)

ecs_files_composer/certificates_mgmt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class X509Certificate(X509CertDef):
2020

2121
def __init__(self, **data: Any):
2222
super().__init__(**data)
23-
self.key = None
23+
self.key: crypto.PKey = None
2424
self.cert = None
2525
self.key_content = None
2626
self.cert_content = None
@@ -106,7 +106,7 @@ def generate_jks(self):
106106
pkey = pyjks.jks.PrivateKeyEntry.new(
107107
self.key_file_name,
108108
certs=[crypto.dump_certificate(crypto.FILETYPE_ASN1, self.cert)],
109-
key=self.key_content,
109+
key=crypto.dump_privatekey(crypto.FILETYPE_ASN1, self.key),
110110
key_format="rsa_raw",
111111
)
112112
pkey.encrypt(self.jks_config.passphrase)

ecs_files_composer/input.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: ecs-files-input.json
3-
# timestamp: 2023-02-23T00:15:22+00:00
3+
# timestamp: 2023-02-28T08:48:36+00:00
44

55
from __future__ import annotations
66

@@ -111,11 +111,6 @@ class CertbotAwsStoreCertificate(BaseModel):
111111
certificates_registry_table_region: Optional[str] = Field(
112112
None, description="Override the top level certificates_registry_table_region"
113113
)
114-
jks_config: Optional[JksConfig] = Field(
115-
None,
116-
alias="jksConfig",
117-
description="Automatically creates a JKS with the retrieved certificate.",
118-
)
119114

120115

121116
class CertbotStore(BaseModel):

0 commit comments

Comments
 (0)