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

feat(xo-web/remote): show encryption in remote UI #6465

Merged
merged 4 commits into from
Oct 24, 2022
Merged
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
5 changes: 5 additions & 0 deletions @xen-orchestra/fs/src/_encryptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const { readChunk } = require('@vates/read-chunk')
const crypto = require('crypto')

export const DEFAULT_ENCRYPTION_ALGORITHM = 'aes-256-gcm'
export const UNENCRYPTED_ALGORITHM = 'none'

export function isLegacyEncryptionAlgorithm(algorithm) {
return algorithm !== UNENCRYPTED_ALGORITHM && algorithm !== DEFAULT_ENCRYPTION_ALGORITHM
}

function getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {
if (key === undefined) {
Expand Down
1 change: 1 addition & 0 deletions @xen-orchestra/fs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import RemoteHandlerLocal from './local'
import RemoteHandlerNfs from './nfs'
import RemoteHandlerS3 from './s3'
import RemoteHandlerSmb from './smb'
export { DEFAULT_ENCRYPTION_ALGORITHM, UNENCRYPTED_ALGORITHM, isLegacyEncryptionAlgorithm } from './_encryptor'

const HANDLERS = {
file: RemoteHandlerLocal,
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”

- [Backup/Encryption] Use `aes-256-gcm` instead of `aes-256-ccm` to mitigate [padding oracle attacks](https://en.wikipedia.org/wiki/Padding_oracle_attack) (PR [#6447](https://github.com/vatesfr/xen-orchestra/pull/6447))
- [Settings/Remote] Display `lock` icon for encrypted remote and a warning if the remote uses a legacy encryption algorithm (PR [#6465](https://github.com/vatesfr/xen-orchestra/pull/6465))

MathieuRA marked this conversation as resolved.
Show resolved Hide resolved
### Bug fixes

Expand Down Expand Up @@ -39,7 +40,8 @@
- @xen-orchestra/log minor
- @xen-orchestra/mixins patch
- xo-remote-parser patch
- xo-server minor
- xo-server-transport-nagios patch
- xo-web patch
- xo-web minor

<!--packages-end-->
23 changes: 21 additions & 2 deletions packages/xo-server/src/xo-mixins/remotes.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import asyncMapSettled from '@xen-orchestra/async-map/legacy.js'
import { format, parse } from 'xo-remote-parser'
import { getHandler } from '@xen-orchestra/fs'
import {
DEFAULT_ENCRYPTION_ALGORITHM,
getHandler,
isLegacyEncryptionAlgorithm,
UNENCRYPTED_ALGORITHM,
} from '@xen-orchestra/fs'
import { ignoreErrors, timeout } from 'promise-toolbox'
import { noSuchObject } from 'xo-common/api-errors.js'
import { synchronized } from 'decorator-synchronized'
Expand Down Expand Up @@ -124,6 +129,17 @@ export default class {
return
}

let encryption

if (this._handlers[remote.id] !== undefined) {
const algorithm = this._handlers[remote.id]._encryptor?.algorithm ?? UNENCRYPTED_ALGORITHM
encryption = {
algorithm,
isLegacy: isLegacyEncryptionAlgorithm(algorithm),
recommendedAlgorithm: DEFAULT_ENCRYPTION_ALGORITHM,
}
}

const promise =
remote.proxy !== undefined
? this._app.callProxyMethod(remote.proxy, 'remote.getInfo', {
Expand All @@ -134,7 +150,10 @@ export default class {
try {
await timeout.call(
promise.then(info => {
remotesInfo[remote.id] = info
remotesInfo[remote.id] = {
...info,
encryption,
}
}),
5e3
)
Expand Down
4 changes: 4 additions & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ const messages = {
remoteEncryptionKey: 'Encrypt all new data sent to this remote',
remoteEncryptionKeyStorageLocation:
"You won't be able to get your data back if you lose the encryption key. The encryption key is saved in the XO config backup, they should be secured correctly. Be careful, if you saved it on an encrypted remote, then you won't be able to access it without the remote encryption key.",
encryption: 'Encryption',
remoteEncryptionLegacy:
'A legacy encryption algorithm is used ({algorithm}), please create a new remote with the recommended algorithm {recommendedAlgorithm}',

// ------ New Storage -----

newSr: 'New SR',
Expand Down
34 changes: 34 additions & 0 deletions packages/xo-web/src/xo-app/settings/remotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ const COLUMN_PROXY = {
name: _('proxy'),
}

const COLUMN_ENCRYPTION = {
itemRenderer: remote => {
// remote.info?.encryption undefined means that remote is not enabled and synced
// we don't have the agorithm used at this step
if (remote.info?.encryption === undefined) {
return remote.encryptionKey !== undefined ? <Icon size='lg' icon='lock' /> : null
} else {
// remote enabled and not encrypted
if (remote.info.encryption.algorithm === 'none') {
return null
}
const { algorithm, isLegacy, recommendedAlgorithm } = remote.info.encryption
return (
<span>
<Tooltip content={algorithm}>
<Icon className='mr-1' icon='lock' size='lg' />
</Tooltip>

{isLegacy && (
<Tooltip content={_('remoteEncryptionLegacy', { algorithm, recommendedAlgorithm })}>
<Icon icon='error' size='lg' />
</Tooltip>
)}
</span>
)
}
},
name: _('encryption'),
}

const fixRemoteUrl = remote => editRemote(remote, { url: format(remote) })
const COLUMNS_LOCAL_REMOTE = [
COLUMN_NAME,
Expand All @@ -141,6 +171,7 @@ const COLUMNS_LOCAL_REMOTE = [
},
COLUMN_STATE,
COLUMN_DISK,
COLUMN_ENCRYPTION,
COLUMN_SPEED,
COLUMN_PROXY,
]
Expand Down Expand Up @@ -198,6 +229,7 @@ const COLUMNS_NFS_REMOTE = [
},
COLUMN_STATE,
COLUMN_DISK,
COLUMN_ENCRYPTION,
COLUMN_SPEED,
COLUMN_PROXY,
]
Expand Down Expand Up @@ -245,6 +277,7 @@ const COLUMNS_SMB_REMOTE = [
),
name: _('remoteAuth'),
},
COLUMN_ENCRYPTION,
COLUMN_SPEED,
COLUMN_PROXY,
]
Expand Down Expand Up @@ -300,6 +333,7 @@ const COLUMNS_S3_REMOTE = [
),
name: 'Key',
},
COLUMN_ENCRYPTION,
COLUMN_SPEED,
COLUMN_PROXY,
]
Expand Down