Skip to content

Import SideStore P12 exports and keep P12 passwords off the command line - #198

Merged
bitxeno merged 1 commit into
masterfrom
fix/sidestore-p12-import
Oct 8, 2026
Merged

bitxeno merged 1 commit into
masterfrom
fix/sidestore-p12-import

Conversation

@bitxeno

@bitxeno bitxeno commented Oct 8, 2026

Copy link
Copy Markdown
Owner

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 the
device cannot be reused on the Accounts page (issue #195).

Two things are wrong with that export:

  • The private key is written as a plain keyBag without a MAC. The signing
    engine's PKCS#12 reader (p12-keystore) only collects keys from a shrouded
    key bag, and only when the bag carries a localKeyId attribute, so it
    returns zero entries and reports a missing private key.
  • The export dialog asks for a password and then ignores it: the builder
    never reads its password argument. Users who type a password get a file
    that 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.

LegacyDES is used rather than a modern encoder on purpose: the engine's
reader 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:

  • The password of the user only decodes the upload. The engine receives a
    throwaway random password instead, so no user password reaches argv or the
    debug log. The previous code passed it as -p and logged the full command
    line at --debug, against the project rule to filter passwords from logs.
  • The upload is decoded in memory and never written to disk under the name of
    the uploaded file; only the re-wrapped copy is, as a 0600 temporary file
    removed when the engine returns.

How it works

signing.RewrapP12 decodes with the existing DecodeP12 and re-encodes with
pkcs12.LegacyDES under a fresh 16-byte hexadecimal password. Hexadecimal
keeps the password inside the Unicode BMP, which PKCS#12 password encoding
requires.

CertificateManager.ImportCertificate now takes the P12 bytes instead of a
path, re-wraps them, writes the result to a private temporary file and hands
the engine that file plus the throwaway password.

exec.Cmd.WithSecret masks values in the debug log while leaving the real
argument list untouched. It matches by value rather than by flag position,
because PlumeImpactor reuses -p for a password in some subcommands and for
the package path in sign. The same masking is applied to certificate export
and 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

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
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@bitxeno
bitxeno merged commit c53d2d9 into master Oct 8, 2026
@bitxeno
bitxeno deleted the fix/sidestore-p12-import branch October 23, 2026 06:41
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

⌂ 换网址