Skip to content
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
2 changes: 2 additions & 0 deletions src/models/RCS.Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ export interface TLSConfigFlow {
setTimeSynch?: boolean
rootCertKey?: any
issuedCertPEM?: string
/** Existing leaf approved by live/Vault and requested-profile verification. */
validatedCertPEM?: string
mpsRootCertPEM?: string
}

Expand Down
181 changes: 181 additions & 0 deletions src/stateMachines/activation.revalidation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*********************************************************************
* Copyright (c) Intel Corporation 2026
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

import { AMT } from '@device-management-toolkit/wsman-messages'
import { fromPromise } from 'xstate'
import { runMachineSegment } from '../test/helper/xstate.js'
import { devices } from '../devices.js'
import { Environment } from '../utils/Environment.js'
import { config } from '../test/helper/Config.js'
import { ClientAction } from '../models/RCS.Config.js'

vi.mock('../Configurator.js', () => ({
Configurator: function () {
return { ready: Promise.resolve() }
}
}))
vi.mock('../factories/DbCreatorFactory.js', () => ({ DbCreatorFactory: vi.fn() }))
const { Activation } = await import('./activation.js')

// A certificate that this run installed, or that was already validated earlier in this run,
// must not be probed, validated and port-switched a second time.
const clientId = 'revalidation-test'

beforeEach(() => {
Environment.Config = config
devices[clientId] = {
uuid: clientId,
status: {},
tlsEnforced: true,
ClientData: { payload: { currentMode: 1 } },
connectionParams: { port: 16993 }
} as any
})
afterEach(() => {
delete devices[clientId]
})

const base = () => ({
clientId,
amt: new AMT.Messages(),
profile: { activation: ClientAction.ADMINCTLMODE },
message: { Envelope: { Body: { AMT_GeneralSettings: { DigestRealm: 'Digest:ABCDEF0123456789ABCDEF0123456789' } } } }
})

describe('TLS activation Phase 2 re-entry', () => {
// The digest realm check precedes the routing under test; it is not what these tests exercise.
const machine = () => new Activation().machine.provide({ guards: { isDigestRealmInvalid: () => false } })

it('goes straight to the ACM upgrade after CCM over TLS in the same run', async () => {
const snapshot = await runMachineSegment(
machine(),
'CHECK_DIGEST_REALM',
{ ...base(), isActivated: true, tlsCCMComplete: true, tlsACMComplete: false, tlsNeedsProvisioning: true },
['CHECK_AMT_TLS_STATE', 'IPS_HOST_BASED_SETUP_SERVICE']
)
expect(snapshot.value).toBe('IPS_HOST_BASED_SETUP_SERVICE')
expect(snapshot.context.tlsNeedsProvisioning).toBe(false)
})

it('still probes TLS state for a device that was already activated before this run', async () => {
const snapshot = await runMachineSegment(
machine(),
'CHECK_DIGEST_REALM',
{ ...base(), isActivated: true, tlsCCMComplete: false, tlsACMComplete: false },
['CHECK_AMT_TLS_STATE', 'IPS_HOST_BASED_SETUP_SERVICE']
)
expect(snapshot.value).toBe('CHECK_AMT_TLS_STATE')
})

it('still probes TLS state once the ACM upgrade has completed', async () => {
const snapshot = await runMachineSegment(
machine(),
'CHECK_DIGEST_REALM',
{ ...base(), isActivated: true, tlsCCMComplete: true, tlsACMComplete: true },
['CHECK_AMT_TLS_STATE', 'IPS_HOST_BASED_SETUP_SERVICE']
)
expect(snapshot.value).toBe('CHECK_AMT_TLS_STATE')
})
})

describe('--tls-tunnel re-validation after saving device info', () => {
const machine = () =>
new Activation().machine.provide({ actors: { saveDeviceInfoToMPS: fromPromise(async () => ({})) } })

it('does not validate and port-switch again for an activated device whose certificate already passed', async () => {
devices[clientId].tlsTunnelActivation = true
const snapshot = await runMachineSegment(
machine(),
'SAVE_DEVICE_TO_MPS',
{ ...base(), isActivated: true, tlsNeedsProvisioning: false, tlsTunnelCCMComplete: false },
['FETCH_MPS_ROOT_KEY', 'UNCONFIGURATION']
)
expect(snapshot.value).toBe('UNCONFIGURATION')
})

it.each([
'12.0.95',
'15.0.0',
'18.0.0',
'19.0.0',
'21.0.2'
])('still routes first-time --tls-tunnel activation to TLS validation after CCM on AMT %s', async (ver) => {
devices[clientId].tlsTunnelActivation = true
Object.assign(devices[clientId].ClientData.payload, { currentMode: 0, ver })
const snapshot = await runMachineSegment(
machine(),
'SAVE_DEVICE_TO_MPS',
{ ...base(), isActivated: true, tlsNeedsProvisioning: false, tlsTunnelCCMComplete: false },
['FETCH_MPS_ROOT_KEY', 'UNCONFIGURATION']
)
expect(snapshot.value).toBe('FETCH_MPS_ROOT_KEY')
})

it('keeps first-time CCM tunnel routing after CHECK_SETUP marks the device activated', async () => {
devices[clientId].tlsTunnelActivation = true
Object.assign(devices[clientId].ClientData.payload, { currentMode: 0, ver: '19.0.0' })
const committed = machine().provide({
actors: { saveDeviceInfoToSecretProvider: fromPromise(async () => ({})) },
actions: { 'Update AMT Credentials': () => {}, 'Set activation status': () => {} },
delays: { DELAY_TIME_ACTIVATION_SYNC: 0 }
})
const snapshot = await runMachineSegment(
committed,
'CHECK_SETUP',
{
...base(),
profile: { activation: ClientAction.CLIENTCTLMODE },
message: { Envelope: { Body: { CommitChanges_OUTPUT: { ReturnValue: 0 } } } },
isActivated: false,
tlsNeedsProvisioning: false,
tlsTunnelCCMComplete: false
},
['FETCH_MPS_ROOT_KEY', 'UNCONFIGURATION']
)
expect(snapshot.context.isActivated).toBe(true)
expect(snapshot.value).toBe('FETCH_MPS_ROOT_KEY')
})

it('still provisions TLS for an activated --tls-tunnel device whose certificate did not pass', async () => {
devices[clientId].tlsTunnelActivation = true
const snapshot = await runMachineSegment(
machine(),
'SAVE_DEVICE_TO_MPS',
{ ...base(), isActivated: true, tlsNeedsProvisioning: true, tlsTunnelCCMComplete: false },
['FETCH_MPS_ROOT_KEY', 'UNCONFIGURATION']
)
expect(snapshot.value).toBe('FETCH_MPS_ROOT_KEY')
})

it('does not repeat TLS setup after the first-time tunnel has completed', async () => {
devices[clientId].tlsTunnelActivation = true
devices[clientId].ClientData.payload.currentMode = 0
const snapshot = await runMachineSegment(
machine(),
'SAVE_DEVICE_TO_MPS',
{ ...base(), isActivated: true, tlsNeedsProvisioning: false, tlsTunnelCCMComplete: true },
['FETCH_MPS_ROOT_KEY', 'UNCONFIGURATION']
)
expect(snapshot.value).toBe('UNCONFIGURATION')
})

it('marks provisioning needed when the TLS probe itself fails', async () => {
devices[clientId].tlsTunnelActivation = true
const failing = new Activation().machine.provide({
actors: {
checkAmtTlsState: fromPromise(async () => {
throw new Error('probe failed')
})
}
})
const snapshot = await runMachineSegment(
failing,
'CHECK_AMT_TLS_STATE',
{ ...base(), isActivated: true, tlsNeedsProvisioning: false },
['IPS_HOST_BASED_SETUP_SERVICE', 'CHANGE_AMT_PASSWORD']
)
expect(snapshot.context.tlsNeedsProvisioning).toBe(true)
})
})
Loading