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

Upgrade: forbid upgrading with a key XAPI will reject #167

Open
wants to merge 1 commit into
base: master
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
3 changes: 3 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,6 @@ def error_string(error, logname, with_hd):
# Error partitioning disk as in use
PARTITIONING_ERROR = \
'The disk appears to be in use and partition changes cannot be applied. Reboot and repeat the installation'

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

from OpenSSL import crypto

import diskutil
import product
from xcp.version import *
Expand Down Expand Up @@ -206,11 +208,21 @@ 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):
if tool.partTableType == constants.PARTITION_DOS:
raise RuntimeError("Upgrade from a DOS partition type is not supported.")
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." % (self.key_size, constants.MIN_KEY_SIZE))

prepTargetStateChanges = []
prepTargetArgs = ['primary-disk', 'target-boot-mode', 'boot-partnum', 'primary-partnum', 'logs-partnum', 'swap-partnum', 'storage-partnum']
Expand Down