- Hirofumi Ukawa hirofumi@ukawa.biz
- The BlueDM protocol is a protocol designed to achieve End-to-End Encryption (E2EE) as an extension of the ATProtocol.
- The BlueDM protocol is implemented only on the client side.
- Matters related to the client's user interface.
- Matters related to the laws and regulations of various countries.
- Matters related to defects in the specification.
- Matters related to defects in implementation or legal responsibilities.
- ATProtocol
- Public Key Encryption
- Mutual exchange of symmetric encryption keys.
- Signing other fields.
- This version does not address signing.
- Symmetric Encryption
- Used for encrypting messages.
- Strive for a simple design whenever possible.
- Allow flexibility in adapting to the obsolescence of encryption methods over time.
- Describe the method of 1-to-1 communication.
- In Version 1.0:
- Use RSA as the public key encryption algorithm with a key length of 2048 bits. Use OAEP padding.
- Use AES as the symmetric encryption algorithm with a key length of 256 bits.
- https://atproto.com/lexicons/app-bsky-actor#appbskyactorprofile
- Required: Text indicating the BlueDM protocol version.
- app.bsky.actor.profile.record.properties.bluedmVersion
- Use Numeric. If following this document, set to 1.0
- Required: Include the public key PEM file as-is in JSON.
- app.bsky.actor.profile.record.properties.bluedmPublicKey
- Place the PEM public key file as-is. Use \r\n for line breaks.
- app.bsky.actor.profile.record.properties.bluedmPublicKey
- Required: Text indicating the BlueDM protocol version.
- https://atproto.com/lexicons/app-bsky-feed#appbskyfeedpost
- Required: Text indicating the BlueDM protocol version.
- app.bsky.feed.post.record.properties.bluedmVersion
- Use Numeric. If following this document, set to 1.0
- Encrypt the sender-generated shared key with the recipient's public key and encode in Base64.
- app.bsky.feed.post.record.properties.bluedmSharedKey
- Use Base64 Text. Include in the Required: First Mention Post from sender to recipient only.
- Ensure Base64 padding on the sender side.
Encrypt the sender-generated shared key with the sender's public key and encode in Base64.app.bsky.feed.post.record.properties.bluedmSrcSharedKeyUse Base64 Text. Include in the Required: First Mention Post from sender to recipient only.Usage: Used by the sender to later view DM history.Ensure Base64 padding on the sender side.
- Encrypt messages both parties want to send using the shared key and encode in Base64.
- app.bsky.feed.post.record.properties.bluedmSecretMessage
- Encode the Post content in Base64 and provide as Text.
- Ensure Base64 padding on the sender side.
- Regarding content:
- TEXT
- Encrypt UTF-8 text, encode it in Base64, and include it.
- If the text starts with '{', the behavior on the recipient's side is not defined.
- Maximum character limit is not specified.
- TEXT
- The sender may include this message when initially sending the key.
- Required: Text indicating the BlueDM protocol version.
- Fundamental Concepts
- A series of messages starts with a Mentioned Post at the beginning of the DM and is realized by Replies to that message.
- Clients detect this process from Notifications. Ignore the message even if it's included in a Repost.
- How to handle past DM history is implementation-dependent.
- When Sending the First DM
- The sender verifies whether the recipient can receive DMs.
- Obtain the recipient's Profile and verify bluedmVersion and bluedmPublicKey.
- Verification method is implementation-dependent.
- Behavior for recipients who can't receive the message is implementation-dependent.
- The sender generates the shared key using random numbers and performs the following
twoencryptions:- Encrypt with the recipient's public key.
Encrypt with the sender's public key.
- The recipient decrypts the received shared key using the recipient's private key for future use.
The sender decrypts the sent shared key using the sender's private key for future use.
- The sender verifies whether the recipient can receive DMs.
- Subsequent DM Sending
- To prevent the DM from appearing on the timeline, subtract 100 years from the createdAt timestamp when sending.
- When displaying the recipient's message, add 100 years to the displayed timestamp.
- Both parties can exchange messages interactively.
- Message History
- If there's an initiating mention, the message can be reconstructed, allowing continued sending and receiving.
- Handling of Public and Private Keys
- The generated public key is stored in the Profile.
- The generated private key is stored in the client software.
- Considering use by multiple individuals and clients, it's desirable for each DID to store private keys separately, even within the same software environment. Exporting is also desired.
- When Switching Browsers or When Saved Public and Private Keys Don't Match
- Ability to import private keys is desired.
- Ability to regenerate public and private keys when private key is missing is desired.
- Regeneration would render past data unreadable, but this is acceptable.
- As the private key can calculate the public key, it's acceptable to recalculate and set the public key when importing the user's private key.
- Polling interval for Notification retrieval is implementation-dependent.
- There is no defined way for the sender to restore the message afterwards. Implementation also.
- Some suggestions are described with strikeout lines.
- Hirofumi Ukawa hirofumi@ukawa.biz
- BlueDMプロトコルはATProtocolの拡張として定義されるE2EEを実現するプロトコルである
- BlueDMプロトコルはクライアントのみで実装される
- クライアントのユーザーインターフェースに関わる事
- 各国の法令に関わる事
- 仕様の不具合に関する事
- 実装の不具合や、法的な責任に関する事
- ATProtocol
- 公開鍵暗号
- 共通鍵暗号の相互交換
- 他のフィールドへの署名
- 本バージョンでは署名に関して言及しない
- 共通鍵暗号
- メッセージの暗号化に用いる
- 可能な限りシンプルな設計とする
- 暗号方式は時間の経過に伴って陳腐化する為、柔軟に対応できるようにする
- 1対1の通信方法について記載する
- Version 1.0 では
- 公開鍵暗号として RSAを採用し、キー長は2048ビットを利用する。パディング方式はOAEPとする
- 共通鍵暗号として AESを採用し、キー長は256ビットを利用する
- https://atproto.com/lexicons/app-bsky-actor#appbskyactorprofile
- 必須:BlueDMのプロトコルバージョンのテキスト
- app.bsky.actor.profile.record.properties.bluedmVersion
- Numericで記述する。本ドキュメントに従う場合、1.0 である
- 必須:公開鍵PEMファイルをそのままJSONに記載する
- app.bsky.actor.profile.record.properties.bluedmPublicKey
- PEM公開鍵ファイルをそのまま入れる。改行は\r\nで表記する
- app.bsky.actor.profile.record.properties.bluedmPublicKey
- 必須:BlueDMのプロトコルバージョンのテキスト
- https://atproto.com/lexicons/app-bsky-feed#appbskyfeedpost
- 必須:BlueDMのプロトコルバージョンのテキスト
- app.bsky.feed.post.record.properties.bluedmVersion
- Numericで記述する。本ドキュメントに従う場合、1.0 である
- 送信元で生成した共通鍵を送信先の公開鍵で暗号化しBase64エンコードしたテキスト
- app.bsky.feed.post.record.properties.bluedmSharedKey
- Base64のTextで記述する。本キーは送信元から送信先への必須:最初のMentionのPostにのみ入れる
- Base64のパディングは送信側で保証する
送信元で生成した共通鍵を送信元の公開鍵で暗号化しBase64エンコードしたテキストapp.bsky.feed.post.record.properties.bluedmSrcSharedKeyBase64のTextで記述する。本キーは送信元から送信先への必須:最初のMentionのPostにのみ入れる利用方法: 送信元が後からDM履歴を閲覧する為に利用するBase64のパディングは送信側で保証する
- 双方が送りたいメッセージを共通鍵で暗号化しBase64エンコードしたテキスト
- app.bsky.feed.post.record.properties.bluedmSecretMessage
- Post内容をBase64でエンコードした内容を、Textで記述する。
- Base64のパディングは送信側で保証する
- 中身について
- TEXT
- UTF-8のテキストを暗号化しBase64でエンコードした物を入れる
- テキストの先頭に文字'{'が含まれている場合の受信側の処理は規定しない
- 利用できる文字数の最大値については規定しない
- TEXT
- 送信側は、最初の鍵送信時に一緒にこのメッセージを追記してもよい
- 必須:BlueDMのプロトコルバージョンのテキスト
- 基本的な考え方
- 一連のメッセージは、全て最初のDM開始のMention付きのPostから開始され、そのメッセージへのReplyによって実現される
- クライアントはNotificationから、1. を検知する。Repostに本メッセージが含まれていても無視する
- 過去のDM履歴をどのように扱うかは実装依存とする
- 最初のDM送信時
- 送信側は送信先がDM送信可能な相手かどうか検証する
- 送信先のProfileを取得し、bluedmVersionとbluedmPublicKeyを確認する
- 確認方法は実装依存とする
- 送信できない相手の場合の動作は実装依存とする
- 送信側は共有鍵を乱数により生成し下記
2つの暗号化を行う- 送信先の公開鍵により暗号化
送信元の公開鍵により暗号化
- 受信側は受けた共通鍵を受信側の秘密鍵で復号化し利用する
送信側は送信した共通鍵を送信側の秘密鍵で複合化し以降、もしくは後で利用する
- 送信側は送信先がDM送信可能な相手かどうか検証する
- 以降のDM送信時
- DMがタイムラインに浮上しないよう送信時のcreatedAtを送信日時から100年減算した値とする
- 相手のメッセージを表示する時、表示上は100年加算した値とする
- 双方が対照的にメッセージをやりとりできる
- メッセージの履歴
- 起点となるメンションがあれば、メッセージは再現でき、かつ継続して送受信も継続できる
- 公開鍵と秘密鍵の扱い
- 生成した公開鍵は、Profileに保存
- 生成した秘密鍵は、クライアントソフトで保存
- 複数名での利用、複数クライアントでの利用を加味し、秘密鍵は同一環境の同一ソフトであってもDID別に保存できる事が望ましく、またエクスポートができる事が望まれる
- ブラウザを変更した時など保存された公開鍵と秘密鍵がペアでは無い場合
- 秘密鍵のインポートができる事が望まれる
- 秘密鍵が無い場合に、公開鍵と秘密鍵を再生成できる事が望まれる
- 再生成の結果、過去の送受信のデータは閲覧不能になるがこれを許容する
- Notification取得のポーリング間隔は実装に依存する
- 送信元が後からメッセージを復元する方法が定義されていない。実装も同様である
- 取り消し線で一部提案を記載している