Configurer OpenSSL pour l'encapsulation de clés manuelle
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Pour pouvoir importer une clé dans Cloud KMS, elle doit être encapsulée à l'aide du schéma PKCS#11CKM_RSA_AES_KEY_WRAP, qui inclut à la fois RSA-OAEP (inclus dans OpenSSL 1.1 par défaut) et l'encapsulation de clé AES avec remplissage (non inclus). Ce mécanisme n'est pas inclus dans OpenSSL.
Nous vous recommandons d'utiliser la Google Cloud CLI pour encapsuler automatiquement chaque clé lors de l'importation. Si vous devez encapsuler vos clés manuellement en raison de contraintes réglementaires ou de conformité, vous devez d'abord recompiler OpenSSL pour la prise en charge de l'encapsulation de clé AES avec remplissage. Après avoir compilé OpenSSL, vous pouvez encapsuler la clé manuellement.
Avant de commencer
Ne remplacez pas les fichiers binaires OpenSSL intégrés à votre système par les versions corrigées des fichiers binaires générées en suivant les procédures décrites dans cette rubrique. Par exemple, n'installez pas le correctif OpenSSL directement dans /usr. Si vous suivez rigoureusement cette procédure, la version corrigée OpenSSL est compilée dans $HOME/build et installée dans $HOME/local/bin.
Si ${HOME}/local/bin existe déjà, sauvegardez son contenu ou déplacez ces fichiers ailleurs avant de suivre les étapes décrites dans cette rubrique.
Appliquer le correctif et installer OpenSSL v1.1.0.
Si vous choisissez d'utiliser OpenSSL pour encapsuler manuellement vos clés avant de les importer dans Cloud KMS, OpenSSL v1.1.0 est requis, avec le correctif suivant appliqué. Vous devez compiler OpenSSL et l'installer dans un emplacement distinct de l'installation OpenSSL par défaut de votre système.
Téléchargez la source de la version OpenSSL 1.1.0l depuis l'adresse https://www.openssl.org/source.
Il s'agit de la dernière version de la ligne de code 1.1.0. N'utilisez pas une version plus récente d'OpenSSL, telle que la version 1.1.1, dans cette procédure, auquel cas le correctif échouera.
Extrayez l'archive vers ${HOME}/build/openssl/ à l'aide de la commande suivante.
Cette commande ignore le répertoire par défaut, qui inclut la version d'OpenSSL et change régulièrement. Remplacez /path/to/downloaded-openssl.tar.gz par le chemin d'accès de l'archive .tar.gz téléchargée.
# Create the directory for the eventual OpenSSL binaries
mkdir -p ${HOME}/local/ssl
# Create the build directory
mkdir -p ${HOME}/build/openssl
# Extract the archive to ${HOME}/build/openssl
tar xzvf /path/to/downloaded-openssl.tar.gz \
-C ${HOME}/build/openssl/ \
--strip-components 1
Appliquez un correctif personnalisé à la source OpenSSL extraite, en utilisant les commandes suivantes. Le correctif active l'indicateur EVP_CIPHER_CTX_FLAG_WRAP_ALLOW.
Exécutez les commandes suivantes pour créer les binaires et les bibliothèques OpenSSL à partir de la source corrigée, testez la validité de la compilation, et installez les binaires et les bibliothèques dans le répertoire ${HOME}/local.
CPUS=$(getconf _NPROCESSORS_ONLN)
cd ${HOME}/build/openssl
./config --prefix=${HOME}/local --openssldir=${HOME}/local/ssl
make -j${CPUS}
make test
make install
N'omettez pas ou ne modifiez pas les indicateurs --prefix ou --openssldir, pour vous assurer de ne pas écraser l'installation OpenSSL du système.
Exécutez la commande suivante pour vérifier que le nouveau binaire OpenSSL a bien été installé :
test -x ${HOME}/local/bin/openssl || echo FAIL
Vous ne devriez voir aucun résultat si les fichiers binaires sont correctement installés. Si FAIL s'affiche, vérifiez le résultat des commandes make, make test et make install que vous avez exécutées précédemment.
Les binaires OpenSSL corrigés sont liés de manière dynamique aux bibliothèques OpenSSL dans ${HOME}/local/ssl/lib/, mais la commande ld ne les indexe pas par défaut. Exécutez les commandes suivantes pour créer un script wrapper qui ajoute les bibliothèques corrigées à ${LD_LIBRARY_PATH} avant d'appeler la CLI pour le correctif OpenSSL.
Vérifiez que la version d'OpenSSL démarrée par le script correspond à la version que vous venez de créer et d'installer, à l'aide de la commande suivante :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[],[],null,["# Configuring OpenSSL for manual key wrapping\n\nBefore you can import a key into Cloud KMS, it must be wrapped\nusing the\n[PKCS#11](https://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/cos01/pkcs11-curr-v2.40-cos01.html#_Toc408226908)\n`CKM_RSA_AES_KEY_WRAP` scheme, which includes both `RSA-OAEP` (which is included\nin OpenSSL 1.1 by default) and AES Key Wrap\nwith Padding (which is not). That mechanism is not included in OpenSSL.\n\nWe recommend using the Google Cloud CLI to\n[wrap each key automatically](/kms/docs/importing-a-key#request_import) during\nthe import. If you must wrap your keys manually due to compliance or regulatory\nrequirements, you must first recompile OpenSSL to add support for AES Key Wrap\nwith Padding. After recompiling OpenSSL, you can\n[wrap the key manually](/kms/docs/wrapping-a-key).\n| **Important:** If you use automatic wrapping, do not follow these steps. Instead, you need to [install the Pyca cryptographic library](/kms/docs/crypto), which works with the OpenSSL binaries already installed on your local system. The Google Cloud CLI can use that library to automatically wrap your key during the import request.\n\nBefore you begin\n----------------\n\n| **Caution:** These steps require advanced knowledge of Linux. Most users should allow the Google Cloud CLI command to [automatically wrap and import](/kms/docs/importing-a-key#automatically_wrap_and_import) keys instead of following the instructions in this topic.\n\nDo not overwrite your system's built-in OpenSSL binaries with the\npatched binaries produced by following the procedures in this topic. For example,\ndo not install the patched OpenSSL directly into `/usr`. If you follow this\nprocedure exactly, the patched OpenSSL is built in `$HOME/build` and installed\ninto `$HOME/local/bin`.\n\nIf `${HOME}/local/bin` already exists, back up its contents or move those files\nelsewhere before following the steps in this topic.\n\nPatch and install OpenSSL v1.1.0\n--------------------------------\n\nIf you choose to use OpenSSL to manually wrap your keys before importing them\ninto Cloud KMS, OpenSSL v1.1.0 is required, with the following\npatch applied. You will need to compile OpenSSL and install it into a location\nseparate from your system's default OpenSSL installation.\n\n1. Download the source for OpenSSL 1.1.0l release from\n [https://www.openssl.org/source](https://www.openssl.org/source/old/1.1.0/openssl-1.1.0l.tar.gz).\n This is the latest release in the 1.1.0 code line. Do not use a newer\n version of OpenSSL, such as v1.1.1, in this procedure. The patch will fail\n to apply.\n\n2. Extract the archive to `${HOME}/build/openssl/` using the following command.\n This command overrides the default directory, which includes the version of\n OpenSSL and changes often. Replace\n \u003cvar translate=\"no\"\u003e/path/to/downloaded-openssl.tar.gz\u003c/var\u003e with the path to the downloaded\n `.tar.gz` archive.\n\n ```\n # Create the directory for the eventual OpenSSL binaries\n mkdir -p ${HOME}/local/ssl\n\n # Create the build directory\n mkdir -p ${HOME}/build/openssl\n\n # Extract the archive to ${HOME}/build/openssl\n tar xzvf /path/to/downloaded-openssl.tar.gz \\\n -C ${HOME}/build/openssl/ \\\n --strip-components 1\n ```\n3. Apply a custom patch to the extracted OpenSSL source, using the following\n commands.The patch enables the `EVP_CIPHER_CTX_FLAG_WRAP_ALLOW` flag.\n\n | **Warning:** This patch fails to apply to versions of OpenSSL other than v1.1.0l.\n\n\n ```none\n cd ${HOME}/build\n cat \u003c\u003c-EOF | patch -d . -p0\n --- orig/openssl/apps/enc.c 2020-01-17 14:39:54.991708785 -0500\n +++ openssl/apps/enc.c 2020-01-17 14:41:33.215704269 -0500\n @@ -482,6 +482,7 @@\n */\n\n BIO_get_cipher_ctx(benc, &ctx);\n + EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);\n\n if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, enc)) {\n BIO_printf(bio_err, \"Error setting cipher %s\\n\",\n EOF\n ```\n\n \u003cbr /\u003e\n\n4. Run the following commands to build the OpenSSL binaries and libraries from\n the patched source, test the build for validity, and install the binaries\n and libraries into the `${HOME}/local` directory.\n\n ```none\n CPUS=$(getconf _NPROCESSORS_ONLN)\n cd ${HOME}/build/openssl\n ./config --prefix=${HOME}/local --openssldir=${HOME}/local/ssl\n make -j${CPUS}\n make test\n make install\n ```\n\n Do not omit or modify the `--prefix` or `--openssldir` flags, to ensure that\n you do not overwrite the system's OpenSSL installation.\n5. Run the following command to check that the new OpenSSL binary installed\n successfully:\n\n ```none\n test -x ${HOME}/local/bin/openssl || echo FAIL\n ```\n\n You should see no output if the binaries are installed correctly. If you see\n `FAIL`, check the output of the `make`, `make test`, and `make install`\n commands you ran earlier.\n6. The patched OpenSSL binaries are dynamically linked against the OpenSSL\n libraries in `${HOME}/local/ssl/lib/`, but the `ld` command does not\n index these libraries by default. Run the following commands to create a\n wrapper script that adds the patched libraries to the `${LD_LIBRARY_PATH}`\n before invoking the CLI for the patched OpenSSL.\n\n\n ```\n cat \u003e ${HOME}/local/bin/openssl.sh \u003c\u003c-EOF\n #!/bin/bash\n env LD_LIBRARY_PATH=${HOME}/local/lib/ ${HOME}/local/bin/openssl \"\\$@\"\n EOF\n chmod u+x ${HOME}/local/bin/openssl.sh\n ```\n\n \u003cbr /\u003e\n\n7. Check that the version of OpenSSL that the script starts is the version you\n just built and installed, using the following command:\n\n ```\n ${HOME}/local/bin/openssl.sh version\n ```\n\nYou can now invoke the `${HOME}/local/bin/openssl.sh` wrapper script to\n[manually wrap keys for import](/kms/docs/wrapping-a-key)."]]