From 1036d0dabce9e0b442c915431b385936a40ea27e Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Wed, 4 Dec 2024 13:20:49 +0100 Subject: [PATCH] import openpgp --- .../epm/packages/package_verification.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/packages/package_verification.ts b/x-pack/plugins/fleet/server/services/epm/packages/package_verification.ts index 92068dfcd424d..013da46986d4a 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/package_verification.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/package_verification.ts @@ -7,7 +7,8 @@ import { readFile } from 'fs/promises'; -import * as openpgp from 'openpgp'; +import type { Key } from 'openpgp'; +import { readKey, readSignature, createMessage, verify } from 'openpgp'; import type { Logger } from '@kbn/logging'; import type { PackageVerificationResult } from '../../../types'; @@ -22,7 +23,7 @@ interface VerificationResult { keyId: string; } -let cachedKey: openpgp.Key | undefined | null = null; +let cachedKey: Key | undefined | null = null; export async function getGpgKeyIdOrUndefined(): Promise { const key = await getGpgKeyOrUndefined(); @@ -32,14 +33,14 @@ export async function getGpgKeyIdOrUndefined(): Promise { return key.getKeyID().toHex(); } -export async function getGpgKeyOrUndefined(): Promise { +export async function getGpgKeyOrUndefined(): Promise { if (cachedKey !== null) return cachedKey; cachedKey = await _readGpgKey(); return cachedKey; } -export async function _readGpgKey(): Promise { +export async function _readGpgKey(): Promise { const config = appContextService.getConfig(); const logger = appContextService.getLogger(); const gpgKeyPath = config?.packageVerification?.gpgKeyPath; @@ -57,7 +58,7 @@ export async function _readGpgKey(): Promise { } let key; try { - key = await openpgp.readKey({ + key = await readKey({ armoredKey: buffer.toString(), }); } catch (e) { @@ -115,18 +116,18 @@ async function _verifyPackageSignature({ }: { pkgArchiveBuffer: Buffer; pkgArchiveSignature: string; - verificationKey: openpgp.Key; + verificationKey: Key; logger: Logger; }): Promise { - const signature = await openpgp.readSignature({ + const signature = await readSignature({ armoredSignature: pkgArchiveSignature, }); - const message = await openpgp.createMessage({ + const message = await createMessage({ binary: pkgArchiveBuffer, }); - const verificationResult = await openpgp.verify({ + const verificationResult = await verify({ verificationKeys: verificationKey, signature, message,