> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/entrust-hsm.md).

# Entrust HSMでの暗号化

<figure><img src="/files/cC8vPabnd3OfgCzgmbdV" alt=""><figcaption></figcaption></figure>

Keeper Secrets ManagerはEntrust HSMと連携して、Keeper Secrets Managerの設定ファイルを保護します。 この連携により、マシン上の接続に関する詳細情報を保護しながら、すべてのシークレットのクレデンシャルに対して、Keeperのゼロ知識暗号化を利用できます。

## 機能

* Entrust HSMを使用して、KSM設定ファイルを暗号化および復号化します
* Secrets Manager接続に対する不正アクセスから保護します
* 必要なのはコードにわずかな変更を加えるだけで、即座に保護できます。 KSM Python SDKのすべての機能を使用できます

## 要件

* [Python シークレットマネージャーSDK](/keeperpam/jp/secrets-manager/developer-sdk-library/python-sdk.md)に対応
* Python 3.9.2以降が必要
* Pythonモジュールは、SDK ISOイメージの `nfpython` モジュールを使用してnShieldネイティブアプリケーションとしてビルドする必要があります (Entrust nShield Security World 12.80以降)
* virtualenvの使用を推奨

{% hint style="warning" %}
`keeper-secrets-manager-storage` パッケージのv1.1.0以降にはPython 3.9.2以降が必要です。Entrust nShield SDKに同梱されているPython 3.8.5は、v1.1.0と互換性がありません。

対応方法は次の2通りです。

* **v1.0.xのまま**同梱のEntrust Python 3.8.5を使用する: `pip3 install "keeper-secrets-manager-storage<1.1.0"` でバージョンを固定してください。
* **v1.1.0へアップグレード**する: venv用に別途インストールしたPython 3.9.2以降 (LinuxまたはWindows) を使用し、そのvenvに `nfpython*.whl` をインストールしてください。同梱以外のPythonインタプリタでのnShield Python 3サポートについては、Entrustサポートにお問い合わせください。
  {% endhint %}

## 設定

### 1.Virtualenvを作成して設定

この手順はオプションですが、開発では推奨されます

{% tabs %}
{% tab title="Linux" %}
virtualenv作業環境を作成します

`/opt/nfast/python3/bin/python3 -m venv --copies venv`

開発を始める前にvirtualenv環境を有効化します

`. venv/bin/activate`
{% endtab %}

{% tab title="Windows" %}
virtualenv作業環境を作成します

`c:\Program Files\nCipher\nfast\python3\python --copies -m venv venv`

開発を始める前にvirtualenv環境を有効化します

`venv\Scripts\activate.ps1`
{% endtab %}
{% endtabs %}

### 2.KSMストレージとnfpythonモジュールのインストール

Secrets Manager HSMモジュールは、Keeper Secrets Managerストレージモジュールに格納されており、pipを使用してインストールできます

```
pip3 install keeper-secrets-manager-storage
```

Entrust HSMを利用するには、nfpythonパッケージもインストールする必要があります。 このパッケージは、EntrustインストールでnShieldパッケージの一部としてインストールされます。

Linuxの場合:

```
pip install /opt/nfast/python3/additional-packages/nfpython*.whl 
```

Windowsの場合:

```
pip install c:\Program Files\nCipher\nfast\python3\additional-packages\nfpython*.whl
```

### 3.Entrust HSMストレージをコードに追加

`SecretsManager`コンストラクタで、`HsmNfastKeyValueStorage`をSecrets Managerストレージとして使用します。

`HsmNfastKeyValueStorage`には、メソッドとID (この例ではそれぞれ `simple` と `ksmkey`) が必要です。

{% hint style="info" icon="comment-question" %}
**v1.0.xからのアップグレードについて**

v1.1.0では、以下の動作が変わります。

* `decrypt_config()` のデフォルトは `autosave=False` になりました。従来の動作を維持するには `decrypt_config(autosave=True)` を呼び出してください。
* 破損した、または空の復号結果は、`JSONDecodeError` をそのまま返すのではなく、`"is not a valid encrypted config file"` の例外が発生します。
* 有効な暗号化ブロブではない非UTF8バイトも、同じ例外が発生します。
* 暗号化および復号に失敗した場合、エラーを出さずにストレージ状態を破損させるのではなく、例外が発生します。
* 構成の書き込みはアトミック (書き込み後にリネーム) になり、書き込み失敗時に既存の構成が0バイトに切り詰められることはありません。
* `delete_all()` は空の暗号化ブロブを書き込むのではなく、暗号化された構成ファイルをディスクから削除します。
* `HsmNfastKeyValueStorage` は、同時読み書きに対してスレッドセーフになりました。
  {% endhint %}

{% code title="entrust\_hsm\_example.py" %}

```python
from keeper_secrets_manager_core import SecretsManager
from keeper_secrets_manager_hsm.storage_hsm_nfast import HsmNfastKeyValueStorage

config=HsmNfastKeyValueStorage('simple', 'ksmkey', 'client-config.json')

secrets_manager = SecretsManager(config=config, verify_ssl_certs=True)

all_records = secrets_manager.get_secrets()

```

{% endcode %}

{% hint style="success" %}
これで、Secrets ManagerとEntrust NShield HSMを連携する準備が整いました。
{% endhint %}

## Secrets ManagerとEntrust HSMの連携

設定が完了すると、Secrets ManagerとEntrustの連携により、Secrets Manager SDKのすべての機能が利用できます。 実行時に設定ファイルの復号化を管理するには、コードがnShield HSMにアクセスできる必要があります。

{% hint style="info" %}
その他の例と機能については、[KSM SDKのドキュメント](/keeperpam/jp/secrets-manager/developer-sdk-library.md)をご参照ください。
{% endhint %}

### テスト用の暗号化キーの作成

Entrust nShield HSMによる暗号化をテストするには、以下のコマンドを使用します。

これらの例の「ksmkey」は、HSM内のIDに置き換えてください。

Linuxの場合:

```bash
/opt/nfast/bin/generatekey -b simple protect=module type=AES size=256 ident=ksmkey
```

Windowsの場合:

{% code overflow="wrap" %}

```bash
c:\Program Files\nShield\nfast\bin\generatekey -b simple protect=module type=AES size=256 ident=ksmkey
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/entrust-hsm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
