-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce action to increase dovecot DH parameters size
Originally required by centos2alma since we upgrade rouncube during the converion process
- Loading branch information
Mikhail Sandakov
committed
Mar 12, 2024
1 parent
5c81772
commit efaf50a
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2023-2024. WebPros International GmbH. All rights reserved. | ||
import json | ||
import subprocess | ||
|
||
from pleskdistup.common import action, log, util | ||
|
||
|
||
class SetMinDovecotDhParamSize(action.ActiveAction): | ||
dhparam_size: int | ||
|
||
def __init__(self, dhparam_size: int): | ||
self.name = "increase Dovecot DH parameters size to 2048 bits" | ||
self.dhparam_size = dhparam_size | ||
|
||
def _is_required(self) -> bool: | ||
proc = subprocess.run( | ||
["/usr/sbin/plesk", "sbin", "sslmng", "--show-config"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, | ||
) | ||
if proc.returncode != 0: | ||
log.warn(f"Failed to get ssl configuration by plesk sslmng: {proc.stdout}\n{proc.stderr}") | ||
return False | ||
|
||
try: | ||
sslmng_config = json.loads(proc.stdout) | ||
if int(sslmng_config["effective"]["dovecot"]["dhparams_size"]) >= self.dhparam_size: | ||
return False | ||
except json.JSONDecodeError: | ||
log.warn(f"Failed to parse plesk sslmng results: {proc.stdout}") | ||
return False | ||
|
||
return True | ||
|
||
def _prepare_action(self) -> action.ActionResult: | ||
return action.ActionResult() | ||
|
||
def _post_action(self) -> action.ActionResult: | ||
util.logged_check_call( | ||
[ | ||
"/usr/sbin/plesk", "sbin", "sslmng", | ||
"--service", "dovecot", | ||
"--strong-dh", | ||
f"--dhparams-size={self.dhparam_size}", | ||
] | ||
) | ||
return action.ActionResult() | ||
|
||
def _revert_action(self) -> action.ActionResult: | ||
return action.ActionResult() | ||
|
||
def estimate_post_time(self) -> int: | ||
return 5 |