Our first Android build almost shipped with a leaked key
A signing key that has been committed is not made safe again by deleting the file.
Why deleting a keystore does not undo the leak
While turning Cubicle Crusher from a Google Playground ZIP into its first signed Android build, we found a file that should never have been in the repository.
What a keystore actually is
A keystore is not game art, and it is not source code you can replace later without consequences. It is the file that holds the private key used to sign an Android app.
That signature is how later updates are recognized as coming from the same developer. If someone else has the key, they may be able to sign a build as if it were yours. A keystore has to stay private for the same reason a password does.
What we found, and what we did
An old keystore had been committed to the repository. We treated that key as exposed, removed the file, and created a new upload key.
The upload key is what signs the Android package you send for release. Once the old keystore had been committed, we could not keep trusting it. The safe move was to treat it as burned and replace it.
Why deleting the file is not enough
It is tempting to think the problem ends when the file disappears from the project. It does not. Anyone who already cloned or copied the repository may still have that file. Git history can still contain it after you delete it from the latest version.
Deleting a file does not undo exposure. Never commit a keystore. Keep signing files out of source control from the first commit, not after something has already gone wrong.
Vì sao xóa keystore vẫn không xóa được việc đã lộ
Khi biến Cubicle Crusher từ một file ZIP trên Google Playground thành bản Android đã ký đầu tiên, chúng tôi phát hiện một file không bao giờ được nằm trong kho mã nguồn.
Keystore thực ra là gì
Keystore không phải ảnh game, cũng không phải đoạn mã có thể thay sau mà không để lại hậu quả. Đó là file chứa khóa riêng dùng để ký ứng dụng Android.
Chữ ký đó giúp các bản cập nhật sau này được nhận là đến từ cùng một nhà phát triển. Nếu người khác có được khóa, họ có thể ký một bản build như thể đó là của bạn. Keystore phải được giữ kín, giống như mật khẩu.
Chúng tôi đã thấy gì, và đã làm gì
Một keystore cũ đã bị commit vào kho mã nguồn. Chúng tôi coi khóa đó là đã lộ, xóa file và tạo khóa upload mới.
Khóa upload là khóa dùng để ký gói Android gửi đi phát hành. Khi keystore cũ đã bị commit, chúng tôi không thể tiếp tục tin vào khóa đó. Cách an toàn là coi nó như đã cháy và thay bằng khóa mới.
Vì sao xóa file vẫn chưa đủ
Rất dễ nghĩ rằng chuyện sẽ xong khi file biến mất khỏi dự án. Không phải vậy. Ai đã từng sao chép kho mã nguồn vẫn có thể còn file đó. Lịch sử Git vẫn có thể chứa file sau khi bạn xóa nó khỏi phiên bản mới nhất.
Xóa file không hoàn tác việc đã lộ. Đừng bao giờ commit một keystore. Hãy giữ file ký ra khỏi mã nguồn ngay từ commit đầu tiên, chứ đừng đợi đến khi sự cố đã xảy ra.
キーストアを消しても、露出は取り消せない
Cubicle CrusherをGoogle PlaygroundのZIPから、初めての署名済みAndroidビルドにする過程で、リポジトリに置いてはいけないファイルが見つかりました。
キーストアとは何か
キーストアはゲームの画像でも、後から気軽に差し替えられるソースコードでもありません。Androidアプリの署名に使う秘密鍵を収めたファイルです。
その署名があるから、後の更新も同じ開発者からのものだと認識されます。他人がこの鍵を手に入れれば、あなたであるかのようにビルドへ署名できる恐れがあります。キーストアはパスワードと同じく、非公開のまま守る必要があります。
何が見つかり、何をしたか
古いキーストアがリポジトリにコミットされていました。その鍵は露出したものとして扱い、ファイルを削除し、新しいアップロード鍵を作りました。
アップロード鍵は、公開用に送るAndroidパッケージへ署名するための鍵です。古いキーストアが一度コミットされた以上、その鍵を信じ続けることはできません。安全な判断は、使いものにならないものとして扱い、新しい鍵に差し替えることです。
ファイルを消すだけでは足りない理由
プロジェクトからファイルが消えたら問題も終わった、と考えたくなります。そうではありません。すでにリポジトリを複製したりコピーしたりした人の手元に、そのファイルが残っているかもしれません。最新版から消しても、Gitの履歴には残ることがあります。
ファイルを消しても、露出した事実は取り消せません。キーストアをコミットしてはいけません。署名用のファイルは、問題が起きてからではなく、最初のコミットからソース管理の外に置いてください。

Comments
Post a Comment