0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

License System Day 10: クライアント・サーバーアーキテクチャ

Last updated at Posted at 2025-12-09

🎄 科学と神々株式会社 アドベントカレンダー 2025

License System Day 10: クライアント・サーバーアーキテクチャ


📖 今日のテーマ

システムアーキテクチャ編に突入です!

今日は、ライセンス認証システム全体のクライアント・サーバーアーキテクチャを理解します。


🏗️ 全体アーキテクチャ

┌────────────────────────────────────────────────────────────┐
│                   License Authentication System             │
├────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌──────────────┐         HTTPS/TLS         ┌────────────┐ │
│  │              │◄───────────────────────────►│            │ │
│  │  Client App  │                             │  Server    │ │
│  │  (Node.js)   │  1. Activation Request     │ (Express)  │ │
│  │              ├────────────────────────────►│            │ │
│  │              │    {email, password}        │            │ │
│  │              │                             │            │ │
│  │              │  2. JWT + Signature         │            │ │
│  │              │◄────────────────────────────┤            │ │
│  │              │    {activation_key, sig}    │            │ │
│  │              │                             │            │ │
│  │  ┌────────┐  │                             │  ┌───────┐ │ │
│  │  │ Public │  │  3. Service Request         │  │Private│ │ │
│  │  │  Key   │  ├────────────────────────────►│  │  Key  │ │ │
│  │  └────────┘  │    + Activation Key         │  └───────┘ │ │
│  │              │                             │            │ │
│  │              │  4. Response + Signature    │  ┌───────┐ │ │
│  │              │◄────────────────────────────┤  │  DB   │ │ │
│  │              │                             │  └───────┘ │ │
│  └──────────────┘                             └────────────┘ │
│                                                             │
└────────────────────────────────────────────────────────────┘

🔄 通信フロー詳細

フロー1: アクティベーション

1. ユーザーがメール・パスワードを入力
   ↓
2. クライアントがPOST /api/v1/license/activate
   {
     "email": "user@example.com",
     "password": "password123",
     "client_id": "device-001"
   }
   ↓
3. サーバーが認証
   - パスワード検証(bcrypt)
   - プラン確認
   - ライセンス発行
   ↓
4. JWTを生成
   payload = {user_id, plan, features}
   token = jwt.sign(payload, privateKey, {algorithm: 'ES256'})
   ↓
5. レスポンスに署名
   signature = ECDSA_Sign(response, privateKey)
   ↓
6. クライアントに返却
   {
     "activation_key": "eyJhbGc...",
     "license_id": "uuid",
     "plan_type": "premium",
     "signature": "MEUCIQDz..."
   }
   ↓
7. クライアントが署名検証
   isValid = ECDSA_Verify(response, signature, publicKey)
   ↓
8. ライセンスファイルに保存
   .license ファイルに書き込み

フロー2: サービス利用

1. クライアントがサービスリクエスト
   POST /api/v1/service/echo
   Headers: X-Activation-Key: eyJhbGc...
   Body: {"message": "Hello"}
   ↓
2. サーバーがJWT検証
   decoded = jwt.verify(token, publicKey)
   ↓
3. プラン確認
   if (decoded.plan === 'premium') {
     // プレミアム機能を提供
   }
   ↓
4. レート制限チェック
   if (requestCount > limit) {
     return 429 Too Many Requests
   }
   ↓
5. サービス提供
   echo = processMessage(message, decoded.plan)
   ↓
6. レスポンスに署名
   signature = ECDSA_Sign(response, privateKey)
   ↓
7. クライアントに返却
   {
     "echo": "[PREMIUM] HELLO",
     "plan": "premium",
     "signature": "MEUCIQDz..."
   }

🌟 まとめ

システム全体の流れを理解できました!

次回はRESTful API設計を学びます。


前回: Day 9: 改ざん防止の仕組み
次回: Day 11: RESTful API設計

Happy Learning! 🎉

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?