MoEngageにおけるPGP暗号化の使用

概要 - PGP暗号化プロセス

PGP (Pretty Good Privacy) は、機密ファイルを暗号化するために使用できるセキュリティプログラムです。MoEngageはファイルインポート(S3インポート、SFTPインポート)でPGP暗号化をサポートしています。この記事では、暗号化を使用したい場合に、機密ファイルにPGP暗号化をどのように使用できるかについて詳しく説明します。

要件

  1. PGPキー ペア - PGPキー ペアは、公開鍵と秘密鍵で構成されています。公開鍵はファイルを暗号化するために使用され、秘密鍵はファイルを復号化するために使用されます。秘密鍵は、ファイル内の機密情報を復号化するために使用されるため、誰とも共有するべきではありません。特に、この秘密鍵はMoEngageとのSFTP(SSHファイル転送プロトコル)統合プロセスにおいて重要な役割を果たし、入力として機能します。
  2. 署名鍵ペアは、公開鍵と秘密鍵で構成されています。公開鍵はファイルに署名するために使用され、MoEngage SFTP統合で入力として取られます。内部的には、秘密鍵が署名を検証するために使用されます。

PGP_Encryption.png

PGPキー ペアの使用手順

以下の手順は、PGP標準の無料の実装である GnuPG を通じてPGP暗号化を使用する方法を説明しています。

ステップ 1: 標準のキー ペア (公開鍵と秘密鍵) を生成します

PGPツールのGnuPGを使用してPGPキーのペアを生成できます。鍵ペアを生成する場合は、以下の例に従ってください。MoEngageがキー ペアを生成している場合は、ステップ 1 および 2 をスキップしてください。

(env) ubuntu@ip-10-66-67-30:~$ gpg --full-generate-key
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(14) Existing key from card
Your selection? 1
RSA keys may be between 1024 and 2048 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
 = key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: Moengage
Email address: secops@moengage.com
Comment:
You selected this USER-ID:
"Moengage <secops@moengage.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key 625A24E04B26F243 marked as ultimately trusted
gpg: revocation certificate stored as '/home/ubuntu/.gnupg/openpgp-revocs.d/F4CDDF1A7B223A63BF90787E625A24E04B26F243.rev'
public and secret key created and signed.
pub rsa2048 2023-01-18 [SC]
F4CDDF1A7B223A63BF90787E625A24E04B26F243
uid Moengage <secops@moengage.com>
sub rsa2048 2023-01-18 [E]
</secops@moengage.com></secops@moengage.com>

info

情報

MoEngageは、最大2048ビットの長さのRSAキーを使用したファイル暗号化をサポートしています。高いビットは推奨されません。

ステップ2:公開鍵を生成し、ファイルを暗号化します

もしMoEngageが公開鍵を生成した場合、彼らはそれをあなたと共有します。逆に、生成した場合は、この公開鍵を使用してファイルを暗号化し、暗号化されたファイルをS3/SFTPフォルダにアップロードする必要があります。

公開鍵を暗号化する

gpg --import <public-key.pgp>
gpg --encrypt --sign --armor -r secops@moengage.com <File-name>

この --sign オプションは、ファイルに署名することによってファイルを暗号化するために使用されます。

ステップ 3: MoEngage ダッシュボードにキーを追加します

キーを生成する場合、手順はプライベートキーをMoEngageダッシュボードの復号化キーセグメントに入力し、キーのパスフレーズセクションにパスフレーズを記入することです。一方で、MoEngageによってキーが生成される場合は、データインポートの最初のステップで ファイルは暗号化されていますか? チェックボックスが選択されていることを確認してください。詳細については、 S3インポートのためのS3認証情報の追加 および SFTPインポートのためのS3認証情報の追加 セクションを参照してください。

ステップ 4: ファイルを復号化する

暗号化されたファイルを復号するには、2つの重要な要素が必要です。あなたの秘密鍵と、鍵ペアを作成した際に設定した対応するパスフレーズです。PGPソフトウェアで、目的の暗号化ファイルに移動して選択し、パスフレーズを入力します。ソフトウェアはファイルの復号を進め、元の文書の暗号化されていない版を生成します。

Pythonユーザー向けには、gpgコマンドのPythonラッパーであるpython-gnupgパッケージを検討してください。

import gnupg
import os
# intialising
gpg = gnupg.GPG(gnupghome=os.path.expanduser( '~' ))
gpg.encoding = 'utf-8'
# importing the private key to the server where we are going to decrypt the file
key_data = ""
import_result = gpg.import_keys(key_data)
gpg.trust_keys(import_result.fingerprints, "TRUST_ULTIMATE")
#
encrypted_file_path = "/path/to/encrypted/file"
with open(encrypted_file_path, 'rb') as file:
status=gpg.decrypt_file(file, passphrase="", output="/path/where we want to store the decrypted file")
print(status.ok)
print(status.stderr)

ステップ5: ファイルの署名を確認する【オプションのステップ】

ファイルに署名するために署名キーが使用されている場合は、MoEngageダッシュボードのそれぞれのセクションに公開鍵と署名キーのペアをコピーしてください。MoEngageは、以下に示すように、S3/SFTPフォルダに配置されたファイルの署名一致を確認します。

if status.signature_id: # if signature verified then it has value else None
print("signature verified")
else:
print("Not")
    

次のステップ

  1. S3 Imports
  2. SFTPインポート

この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています

How can we improve this article?