From 38c59168104acef7c1a2e03c82e1e67b9d90bdb5 Mon Sep 17 00:00:00 2001 From: blacktop Date: Thu, 27 Jun 2024 12:11:13 -0600 Subject: [PATCH] fix: macOS 15.0 beta2 fcs-key --- cmd/ipsw/cmd/fw/aea.go | 2 +- internal/commands/extract/extract.go | 2 +- pkg/aea/aea.go | 31 +++++++++++++++++---------- pkg/aea/data/fcs-keys.gz | Bin 933 -> 830 bytes pkg/aea/data/fcs-keys.json | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/cmd/ipsw/cmd/fw/aea.go b/cmd/ipsw/cmd/fw/aea.go index 683e8fdfb..3ed3522a4 100644 --- a/cmd/ipsw/cmd/fw/aea.go +++ b/cmd/ipsw/cmd/fw/aea.go @@ -115,7 +115,7 @@ var aeaCmd = &cobra.Command{ if err != nil { return fmt.Errorf("failed to parse AEA: %v", err) } - pkmap, err := metadata.GetPrivateKey(nil) + pkmap, err := metadata.GetPrivateKey(nil, false) if err != nil { return fmt.Errorf("failed to get private key: %v", err) } diff --git a/internal/commands/extract/extract.go b/internal/commands/extract/extract.go index 216c7e104..df5f0d29b 100644 --- a/internal/commands/extract/extract.go +++ b/internal/commands/extract/extract.go @@ -571,7 +571,7 @@ func FcsKeys(c *Config) ([]string, error) { if err != nil { return nil, fmt.Errorf("failed to parse AEA1 metadata: %v", err) } - pkmap, err := metadata.GetPrivateKey(nil) + pkmap, err := metadata.GetPrivateKey(nil, true) if err != nil { return nil, err } diff --git a/pkg/aea/aea.go b/pkg/aea/aea.go index 53a842824..8376e0c57 100644 --- a/pkg/aea/aea.go +++ b/pkg/aea/aea.go @@ -59,6 +59,9 @@ type PrivateKey []byte func (k PrivateKey) UnmarshalBinaryPrivateKey() ([]byte, error) { block, _ := pem.Decode(k) + if block == nil { + return nil, fmt.Errorf("failed to decode p8 key") + } parsedKey, err := x509.ParsePKCS8PrivateKey(block.Bytes) if err != nil { return nil, fmt.Errorf("failed to parse p8 key: %v", err) @@ -72,7 +75,7 @@ func (k PrivateKey) UnmarshalBinaryPrivateKey() ([]byte, error) { type Metadata map[string][]byte -func (md Metadata) GetPrivateKey(data []byte) (map[string]PrivateKey, error) { +func (md Metadata) GetPrivateKey(data []byte, skipEmbedded bool) (map[string]PrivateKey, error) { out := make(map[string]PrivateKey) if len(data) > 0 { @@ -86,15 +89,17 @@ func (md Metadata) GetPrivateKey(data []byte) (map[string]PrivateKey, error) { } // check if keys are already loaded - if keys, err := getKeys(); err == nil { - u, err := url.Parse(string(privKeyURL)) - if err != nil { - return nil, err - } - for k, v := range keys { - if strings.EqualFold(k, path.Base(u.Path)) { - out[k] = PrivateKey(v) - return out, nil + if !skipEmbedded { + if keys, err := getKeys(); err == nil { + u, err := url.Parse(string(privKeyURL)) + if err != nil { + return nil, err + } + for k, v := range keys { + if strings.EqualFold(k, path.Base(u.Path)) { + out[k] = PrivateKey(v) + return out, nil + } } } } @@ -105,6 +110,10 @@ func (md Metadata) GetPrivateKey(data []byte) (map[string]PrivateKey, error) { } defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("failed to connect to fcs-key URL: %s", resp.Status) + } + privKey, err := io.ReadAll(resp.Body) if err != nil { return nil, err @@ -137,7 +146,7 @@ func (md Metadata) DecryptFCS(pemData []byte) ([]byte, error) { return nil, err } - pkmap, err := md.GetPrivateKey(pemData) + pkmap, err := md.GetPrivateKey(pemData, false) if err != nil { return nil, err } diff --git a/pkg/aea/data/fcs-keys.gz b/pkg/aea/data/fcs-keys.gz index c95929f0904ebbbf816dca7b7df81c555b3d980f..ee0bc962770acc136316a8063822f4f0b5638323 100644 GIT binary patch literal 830 zcmV-E1Ht?siwFP!000001HIHuZ>u;I2H^etjIO5=hR~ag)J6F)iNQ{7V;k61Bu+zu zNhqb|<7)o58Lp1%G~62Z(SJeFJPb4+i(baf4Pn} z_yxa!4jt+0_;~l%UBazC;lO7?qx9raQ5!`igPX92>Q~R|{Td)?R;0<{rY^A~u2S^<1MVwovRO{j)0dk{( z!33Z|N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