Skip to content

Commit

Permalink
Merge pull request #40 from xcp-ng/certificate-keysize-protection
Browse files Browse the repository at this point in the history
Upgrade: forbid upgrading with a key XAPI will reject
  • Loading branch information
ydirson authored Sep 24, 2024
2 parents 121e7a7 + 5c8d6a7 commit 46df38e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ def error_string(error, logname, with_hd):
SR_TYPE_LARGE_BLOCK = value
except IOError:
pass

# crypto configuration
MIN_KEY_SIZE = 2048
15 changes: 15 additions & 0 deletions upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import re
import shutil

from OpenSSL import crypto

import diskutil
import product
from xcp.version import *
Expand Down Expand Up @@ -221,12 +223,25 @@ def __init__(self, source):
input_data = util.readKeyValueFile(default_storage_conf_path)
self.storage_type = input_data['TYPE']

self.key_size = None
cert_path = os.path.join(primary_fs.mount_point, "etc/xensource/xapi-ssl.pem")
with open(cert_path, "r") as cert_file:
cert_text = cert_file.read()
cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_text)
self.key_size = cert.get_pubkey().bits()
logger.info("ExistingInstallation %s: certificate key size %s", source, self.key_size)

primary_fs.unmount()

def testUpgradeForbidden(self, tool):
utilparts = tool.utilityPartitions()
if tool.partTableType == constants.PARTITION_DOS and utilparts is not None:
raise RuntimeError("Util partition detected on DOS partition type, upgrade forbidden.")
if self.key_size < constants.MIN_KEY_SIZE:
raise RuntimeError("Current server certificate is too small (%s bits),"
" please regenerate with at least %s bits.\n\n"
"See the Release Notes for XCP-ng 8.3.0" %
(self.key_size, constants.MIN_KEY_SIZE))

convertTargetStateChanges = []
convertTargetArgs = ['primary-disk', 'target-boot-mode', 'boot-partnum', 'primary-partnum', 'logs-partnum', 'swap-partnum', 'storage-partnum', 'backup-partnum']
Expand Down

0 comments on commit 46df38e

Please sign in to comment.