Skip to content

refactor: CertCacheManager のシングルトンをやめ、CA ごとにキャッシュを持たせる - #281

Draft
toku-sa-n wants to merge 1 commit into
DeNA:masterfrom
toku-sa-n:refactor/certcachemanager-remove-singleton
Draft

toku-sa-n wants to merge 1 commit into
DeNA:masterfrom
toku-sa-n:refactor/certcachemanager-remove-singleton

Conversation

@toku-sa-n

Copy link
Copy Markdown
Contributor

CertCacheManager のシングルトン(getInstance() / static な clearCache())を削除し、各 CA が自分の CertCacheManager を持つようにしました。#271(OpenVPN)と同じく、シングルトンを減らしてテストで差し替えやすくするための変更です。

変更点

  • CertCacheManager: instance と getInstance() を削除。clearCache() をインスタンスメソッドにし、getKeyStore() は synchronized メソッドに変更
  • CA: CertCacheManager をフィールドに持ち、getCachedKeyStore(commonName, domainNames) と clearCertCache() を追加
  • Https / ServerHandshake: CertCacheManager.getInstance().getKeyStore(..., ca) を ca.getCachedKeyStore(...) に置き換え
  • PacketProxyCAPerUser: CertCacheManager.clearCache() を clearCertCache() に置き換え

挙動への影響

  • CA のインスタンスは CAFactory が起動時に1つずつ作って使い回すため、キャッシュの寿命は変わりません
  • これまで PacketProxyCAPerUser の再生成・インポートで全 CA のキャッシュが消えていましたが、その CA のキャッシュだけが消えるようになります(キャッシュのキーに CA 名が入っていたため、他の CA の証明書は元々影響を受けません)

確認

  • ./gradlew build(テストを含む)が成功(JDK 21)

  • By placing an "x" in the box, I hereby understand, accept and agree to be bound by the terms and conditions of the Contribution License Agreement.

🤖 Generated with Claude Code

…ache

CertCacheManager was a lazily created global singleton, which made the
certificate cache impossible to replace in tests and let
PacketProxyCAPerUser clear entries that belonged to every CA.

Each CA now holds its own CertCacheManager and exposes
getCachedKeyStore() / clearCertCache(). CA instances are created once by
CAFactory, so the cache lifetime is unchanged, and regenerating or
importing the per-user CA now clears only that CA's certificates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant