Skip to content

ADFA-4684 | Fix Gemini API key entry: show/hide, trim, and at-rest encryption - #49

Merged
jatezzz merged 3 commits into
mainfrom
fix/ADFA-4684-secure-gemini-api-key
Jul 30, 2026
Merged

ADFA-4684 | Fix Gemini API key entry: show/hide, trim, and at-rest encryption#49
jatezzz merged 3 commits into
mainfrom
fix/ADFA-4684-secure-gemini-api-key

Conversation

@jatezzz

@jatezzz jatezzz commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes the Gemini API key input in the AI Assistant plugin, reported in appdevforall/CodeOnTheGo#1514 where keys wouldn't save correctly and produced 400 "invalid API key" errors. The field now has a working show/hide (eye) toggle that reveals the actual saved key, trims the value on save (dropping the trailing spaces/newlines Gemini rejects), and stops corrupting the key with a masked placeholder on edit. The key is also encrypted at rest with a hardware-backed Android Keystore secret instead of being stored as plaintext.

Details

Changes:

  • Show/hide toggle: new ic_visibility / ic_visibility_off drawables and an ImageButton beside the input; toggle swaps inputType via an explicit visibility flag (the previous bit-check never flipped back, so it always read "hidden").
  • Edit loads the real key: Edit now populates the field with the actual saved key (masked) rather than 16 placeholder bullets, so the eye can reveal it and Save can't re-store the placeholder as the key.
  • Trim on save: saveButton trims before persisting (read side already trimmed).
  • Encryption at rest: SecureApiKeyStore (AES/GCM, Android Keystore) in both ai-assistant (write/read) and ai-core (read for API calls); only ciphertext hits SharedPreferences, and legacy plaintext keys migrate transparently on next save.
  • Strings: hint, content descriptions, and trings.xml`.
document_5111703426673150080.mp4

Ticket

ADFA-4684

Fixes:

Observation

  • The Gemini model list is intentionally left as t (kept for compatibility); retired models can still be selected but now surface a clearer error.
  • SecureApiKeyStore is duplicated in ai-assistay're separate Gradle projects with no shared module; the two copies must stay in sync (same alias cotg_ai_gemini_key_v1 and transform) or ai-core can't decrypt what ai-assistant wrote. They interoperate because both plugins run in the host app's process (shared Keystore).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@jatezzz

jatezzz commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, comment @claude review on this pull request to trigger a review.

@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch from c809089 to 4426b31 Compare July 21, 2026 21:30
@jatezzz

jatezzz commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Build Pass

image

@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch 4 times, most recently from 086fe7b to 3ded9d8 Compare July 22, 2026 17:48

@hal-eisen-adfa hal-eisen-adfa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. Two blocking items scoped to this PR's diff (the API-key security + FilePicker rewrite). The larger AI-plugin findings from the review belong to the base PR #41 and are posted there, not here.

The rest of the PR is solid: AES/GCM at-rest encryption with legacy-plaintext passthrough, inputType="textPassword" on the key field, save-failure surfaced instead of crashing, and the in-place FilePicker refresh that fixes the second-"Toggle All" crash.

@jatezzz
jatezzz force-pushed the refactor/ADFA-4589-ai-hackathon-plugin branch from 3d33b7a to b939ff5 Compare July 23, 2026 18:27
@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch from 3ded9d8 to 759d71d Compare July 23, 2026 19:54
@jatezzz
jatezzz requested a review from hal-eisen-adfa July 23, 2026 20:41
@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch 2 times, most recently from 5764d1f to b44608f Compare July 24, 2026 18:45
@jatezzz
jatezzz force-pushed the refactor/ADFA-4589-ai-hackathon-plugin branch from 45aa44d to 8f1b26a Compare July 27, 2026 14:39
@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch 2 times, most recently from 6f2ea13 to b91dd63 Compare July 27, 2026 18:37
Base automatically changed from refactor/ADFA-4589-ai-hackathon-plugin to main July 28, 2026 13:43
@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch 5 times, most recently from a830c7a to 3739da0 Compare July 28, 2026 21:53

@hal-eisen-adfa hal-eisen-adfa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of the Gemini API-key security work. The crypto core is sound — AES/GCM with a fresh random 12-byte IV per encrypt, GCM tag verification, fail-closed decrypt, and a sensible legacy-plaintext migration. No blockers; 6 non-critical findings inline below, ranked by severity. Note this is a static review — the encryption, on-device migration, and FLAG_SECURE screenshot-blocking still need device verification (install both .cgp, save a key, confirm ciphertext in prefs, revoke the Keystore alias to exercise the 'unreadable' path).

Comment thread ai-assistant/src/main/AndroidManifest.xml Outdated
Comment thread ai-core/src/main/kotlin/com/itsaky/androidide/plugins/aicore/LocalLlmBackend.kt Outdated
jatezzz added 2 commits July 29, 2026 08:07
- Fix file picker empty state and `BadTokenException` by using the correct project context (`IdeProjectService`) and moving I/O off the main thread.
- Secure Gemini API key with hardware-backed Keystore encryption (including legacy migration) and add a show/hide toggle.
- Improve UI by replacing emoji markers with vector drawables and extracting hardcoded strings to `strings.xml`.
…the file picker

Encrypt the key with AES/GCM under an Android Keystore secret and run all crypto off the UI thread; confine the context-file picker to the open project via normalized canonical-path checks with off-thread listing and no fallback root.
@jatezzz
jatezzz force-pushed the fix/ADFA-4684-secure-gemini-api-key branch from 3739da0 to c25ee89 Compare July 29, 2026 13:10
Encrypt the key with AES/GCM under an Android Keystore secret, migrating existing plaintext on first read; send it as a header, never a query string. Confine the context-file picker to the open project, failing closed on an unresolvable root, and fix the crash on a second "Toggle All".
@jatezzz
jatezzz requested a review from hal-eisen-adfa July 29, 2026 15:09
@jatezzz
jatezzz merged commit d04a7b3 into main Jul 30, 2026
@jatezzz
jatezzz deleted the fix/ADFA-4684-secure-gemini-api-key branch July 30, 2026 13:02
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.

2 participants