Repository navigation
Import SideStore P12 exports and keep P12 passwords off the command line - #198
Merged
Merged
Conversation
SideStore's "Export Full (.p12)" stores the private key as a plain keyBag without a MAC, and its export dialog ignores the password it asks for. The signing engine reads such a file as holding no private key, so the import failed with "no private key found in p12 file" (issue #195). The P12 is now decoded in process and encoded again as a shrouded, MAC-protected legacy file before the engine runs. LegacyDES is used because the engine's reader refuses PBES2 files, and the certificate chain of the input is dropped: the engine rebuilds the chain from the certificate of the account it signs with. The password of the user only decodes the upload here. The engine is handed a throwaway random password instead, so no password of the user reaches the command line or the debug log; Cmd.WithSecret masks it. The same masking now covers certificate export and Apple ID login. The upload is decoded in memory and never written to disk: only the re-wrapped copy is, in a 0600 temporary file removed when the engine returns. The route reports a stable signing code (p12_invalid, p12_wrong_password, ...) instead of a plain message. Related to #195
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
SideStore's Export Full (.p12) produces a file atvloadly refuses with
no private key found in p12 file, so a certificate already installed on thedevice cannot be reused on the Accounts page (issue #195).
Two things are wrong with that export:
engine's PKCS#12 reader (
p12-keystore) only collects keys from a shroudedkey bag, and only when the bag carries a
localKeyIdattribute, so itreturns zero entries and reports a missing private key.
never reads its
passwordargument. Users who type a password get a filethat no tool can open with it.
Approach
Decode the upload in process and encode it again as a shrouded, MAC-protected
file before the engine runs. The in-process decoder already handles the plain
keyBag shape, so this needs no change to the pinned engine and no user action
beyond importing the file.
LegacyDESis used rather than a modern encoder on purpose: the engine'sreader refuses PBES2 files, so a stronger algorithm would break the import.
A test asserts the output uses PBES1 3DES, so a future upgrade cannot silently
regress this.
Two side effects are fixed while the upload passes through the process:
throwaway random password instead, so no user password reaches
argvor thedebug log. The previous code passed it as
-pand logged the full commandline at
--debug, against the project rule to filter passwords from logs.the uploaded file; only the re-wrapped copy is, as a 0600 temporary file
removed when the engine returns.
How it works
signing.RewrapP12decodes with the existingDecodeP12and re-encodes withpkcs12.LegacyDESunder a fresh 16-byte hexadecimal password. Hexadecimalkeeps the password inside the Unicode BMP, which PKCS#12 password encoding
requires.
CertificateManager.ImportCertificatenow takes the P12 bytes instead of apath, re-wraps them, writes the result to a private temporary file and hands
the engine that file plus the throwaway password.
exec.Cmd.WithSecretmasks values in the debug log while leaving the realargument list untouched. It matches by value rather than by flag position,
because PlumeImpactor reuses
-pfor a password in some subcommands and forthe package path in
sign. The same masking is applied to certificate exportand Apple ID login, which passed passwords the same way.
The route returns a stable signing code (
p12_invalid,p12_wrong_password,p12_unsupported, ...) instead of a plain message, so the UI can translate it.Links