Files
ipsw/pkg/kernelcache/kernelcache_test.go
T
blacktop 4f23763438 feat(extract): auto-decrypt remote kernelcaches via wiki keys
`ipsw download ipsw --kernel` now fetches firmware keys from
theapplewiki and decrypts encrypted kernelcaches inline. Unencrypted
members in the same IPSW pass through unchanged.

- pkg/img4: DecryptPayload reuses Payload.GetData for decompression,
  removing the duplicate LZSS/LZFSE branches.
- pkg/kernelcache: ParseImg4Data switches to img4.ParsePayload and
  exports ErrEncryptedKernelCache so callers can detect the missing-key
  case via errors.Is.
- internal/commands/extract: new keyed remote path with all-or-nothing
  preflight; the encryption-status peek lets unencrypted variants
  succeed even when the wiki has no entry for them.

  closes #1193
2026-04-27 15:57:23 -06:00

37 lines
833 B
Go

package kernelcache
import (
"errors"
"testing"
"github.com/blacktop/ipsw/pkg/img4"
)
func TestParseImg4DataRejectsEncryptedKernelcache(t *testing.T) {
payload, err := img4.CreatePayload(&img4.CreatePayloadConfig{
Type: img4.IM4P_KERNELCACHE,
Version: "KernelCacheBuilder-test",
Data: []byte("encrypted kernel payload"),
Compression: "none",
Keybags: []img4.Keybag{
{
IV: []byte("1234567890abcdef"),
Key: []byte("1234567890abcdef1234567890abcdef"),
},
},
})
if err != nil {
t.Fatalf("CreatePayload() error = %v", err)
}
data, err := payload.Marshal()
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
_, err = ParseImg4Data(data)
if !errors.Is(err, ErrEncryptedKernelCache) {
t.Fatalf("ParseImg4Data() error = %v, want %v", err, ErrEncryptedKernelCache)
}
}