Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
b-Nollet committed Sep 18, 2024
1 parent f969056 commit 840c36f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/xo-server/src/api/host.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createLogger } from '@xen-orchestra/log'
import assert from 'assert'
import { format } from 'json-rpc-peer'
import { incorrectState } from 'xo-common/api-errors.js'
import { X509Certificate } from 'node:crypto'

import backupGuard from './_backupGuard.mjs'

Expand Down Expand Up @@ -530,6 +531,29 @@ setControlDomainMemory.resolve = {
host: ['id', 'host', 'administrate'],
}

// -------------------------------------------------------------------

export async function isPubKeyTooShort({ host }) {
const certificate = await this.getXapi(host).callAsync('host.get_server_certificate', host._xapiRef)
// begin and end of certificate need to be on separate lines for correct parsing
const correctedCertificate = certificate.replace(/(-----BEGIN CERTIFICATE-----)([^\n]+)/, '$1\n$2').replace(/([^\n]+)(-----END CERTIFICATE-----)/, '$1\n$2')

const cert = new X509Certificate(correctedCertificate)
const isPubKeyTooShort = cert.publicKey.asymmetricKeyDetails.modulusLength < 2048
console.log("====> isPubKeyTooShort :", isPubKeyTooShort, cert.publicKey.asymmetricKeyDetails.modulusLength)

Check failure on line 543 in packages/xo-server/src/api/host.mjs

View workflow job for this annotation

GitHub Actions / CI

Unexpected console statement
return isPubKeyTooShort
}

isPubKeyTooShort.description = 'get TLS key information'

isPubKeyTooShort.params = {
id: { type: 'string' },
}

isPubKeyTooShort.resolve = {
host: ['id', 'host', 'view'],
}

// -------------------------------------------------------------------
/**
*
Expand Down
1 change: 1 addition & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ const messages = {
hostNoSupport: 'No XCP-ng Pro Support enabled on this host',
hostSupportEnabled: 'XCP-ng Pro Support enabled on this host',
noMoreMaintained: 'This host version is no longer maintained',
pubKeyTooShort: 'TLS key is too small to update to XCP-ng 8.3',

// ----- Host actions ------
disableMaintenanceMode: 'Disable maintenance mode',
Expand Down
2 changes: 2 additions & 0 deletions packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,8 @@ export const installCertificateOnHost = (id, props) => _call('host.installCertif

export const setControlDomainMemory = (id, memory) => _call('host.setControlDomainMemory', { id, memory })

export const isPubKeyTooShort = (id) => _call('host.isPubKeyTooShort', { id })

// for XCP-ng now
export const installAllPatchesOnHost = ({ host }) =>
confirm({
Expand Down
34 changes: 33 additions & 1 deletion packages/xo-web/src/xo-app/home/host-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
editHost,
fetchHostStats,
isHostTimeConsistentWithXoaTime,
isPubKeyTooShort,
removeTag,
startHost,
stopHost,
Expand All @@ -37,13 +38,17 @@ import styles from './index.css'

import BulkIcons from '../../common/bulk-icons'
import { LICENSE_WARNING_BODY } from '../host/license-warning'
// import { LICENSE_WARNING_BODY } from '../host/license-warning'
import { getXoaPlan, SOURCES } from '../../common/xoa-plans'

@addSubscriptions({
hvSupportedVersions: subscribeHvSupportedVersions,
})
@connectStore(() => ({
container: createGetObject((_, props) => props.item.$pool),
isPubKeyTooShort: createSelector((_, props) => props.item.id, hostId => {
return isPubKeyTooShort(hostId)
}),
needsRestart: createDoesHostNeedRestart((_, props) => props.item),
nVms: createGetObjectsOfType('VM').count(
createSelector(
Expand Down Expand Up @@ -136,7 +141,7 @@ export default class HostItem extends Component {
() => this.state.isHostTimeConsistentWithXoaTime,
this._getAreHostsVersionsEqual,
() => this.props.state.hostsByPoolId[this.props.item.$pool],
(needsRestart, host, isMaintained, isHostTimeConsistentWithXoaTime, areHostsVersionsEqual, poolHosts) => {
(needsRestart, host, isMaintained, isHostTimeConsistentWithXoaTime, isPubKeyTooShort, areHostsVersionsEqual, poolHosts) => {
const alerts = []

if (needsRestart) {
Expand Down Expand Up @@ -195,6 +200,33 @@ export default class HostItem extends Component {
})
}

if (isPubKeyTooShort) {
console.log("=====> isPubKeyTooShort:", isPubKeyTooShort)
alerts.push({
level: 'warning',
render: (
<span>
<Icon icon='alarm' /> {_('pubKeyTooShort')} (
<span>
<a href='https://xcp-ng.com/pricing.html#xcpngvsxenserver' rel='noopener noreferrer' target='_blank'>
{_('actionsRestricted')}
</a>{' '}
{_('counterRestrictionsOptions')}
<ul>
<li>
<a href='https://github.com/xcp-ng/xcp/wiki/Upgrade-from-XenServer' rel='noopener noreferrer' target='_blank'>
{_('counterRestrictionsOptionsXcp')}
</a>
</li>
<li>{_('counterRestrictionsOptionsXsLicense')}</li>
</ul>
</span>
)
</span>
),
})
}

if (!host.hvmCapable) {
alerts.push({
level: 'warning',
Expand Down

0 comments on commit 840c36f

Please sign in to comment.