Skip to content

Commit

Permalink
fix: macOS 15.0 beta2 fcs-key
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jun 27, 2024
1 parent 2d2d2b4 commit 38c5916
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/ipsw/cmd/fw/aea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
31 changes: 20 additions & 11 deletions pkg/aea/aea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Binary file modified pkg/aea/data/fcs-keys.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/aea/data/fcs-keys.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"C76OEoiX5Lfc0nRQtn1cLkOEwDtC8HGIM_M_1rJgQ9g=":"LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0hBZ0VBTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEJHMHdhd0lCQVFRZ21qWDBwYmU2WWErMDJUek4KY0laWHZ6L1VId1lMN1JwUVFka01QV1pmT2UraFJBTkNBQVRzeUsxZEJzUFJVZU15b2hWM2VJUG5JNGw2SzhjUApWeGZGRXBEd01DdXNlTUVrV0UzV0w5QXcvTTMyRk5Ta2lYZUNpQXoxMXBOdUJVWGVmTkFPSXlkSQotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg==","k_VQtA6uNC_IsMk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