Skip to content

Commit

Permalink
fix: properly wire --proxy and --insecure flags up in `ipsw dl pc…
Browse files Browse the repository at this point in the history
…c` cmd
  • Loading branch information
blacktop committed Nov 24, 2024
1 parent db2b352 commit 4a176a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cmd/ipsw/cmd/download/download_pcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ var pccCmd = &cobra.Command{

// settings
proxy := viper.GetString("download.proxy")
// insecure := viper.GetBool("download.insecure")
insecure := viper.GetBool("download.insecure")
// skipAll := viper.GetBool("download.skip-all")
// resumeAll := viper.GetBool("download.resume-all")
// restartAll := viper.GetBool("download.restart-all")

releases, err := download.GetPCCReleases(proxy)
releases, err := download.GetPCCReleases(proxy, insecure)
if err != nil {
return err
}
Expand Down Expand Up @@ -124,7 +124,7 @@ var pccCmd = &cobra.Command{
return nil
}
log.Infof("Downloading PCC Release for %d", releases[choice].Index)
return releases[choice].Download(viper.GetString("download.pcc.output"))
return releases[choice].Download(viper.GetString("download.pcc.output"), proxy, insecure)
}

return nil
Expand Down
33 changes: 19 additions & 14 deletions internal/download/pcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r PCCRelease) String() string {
return out
}

func (r PCCRelease) Download(output string) error {
func (r PCCRelease) Download(output, proxy string, insecure bool) error {
if err := os.MkdirAll(output, 0755); err != nil {
return fmt.Errorf("failed to create output directory: %v", err)
}
Expand All @@ -167,7 +167,7 @@ func (r PCCRelease) Download(output string) error {
"digest": hex.EncodeToString(asset.Digest.GetValue()),
"variant": asset.GetVariant(),
}).Info("Downloading Asset")
downloader := NewDownload("", false, false, false, false, false, false)
downloader := NewDownload(proxy, insecure, false, false, false, false, false)
downloader.URL = assetURL
downloader.DestName = filePath
if err := downloader.Do(); err != nil {
Expand Down Expand Up @@ -250,17 +250,29 @@ func parseAtLeaf(r *bytes.Reader) (*ATLeaf, error) {
return &leaf, nil
}

func GetPCCReleases(proxy string) ([]PCCRelease, error) {
func GetPCCReleases(proxy string, insecure bool) ([]PCCRelease, error) {
var releases []PCCRelease

res, err := http.Get(bagURL)
client := &http.Client{
Transport: &http.Transport{
Proxy: GetProxy(proxy),
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
},
}

req, err := http.NewRequest("GET", bagURL, nil)
if err != nil {
return nil, fmt.Errorf("cannot create http POST request: %v", err)
}

res, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to GET bag: %v", err)
return nil, fmt.Errorf("failed to GET pcc atresearch bag: %v", err)
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bag GET returned status: %s", res.Status)
return nil, fmt.Errorf("pcc atresearch bag GET returned status: %s", res.Status)
}

body, err := io.ReadAll(res.Body)
Expand All @@ -284,21 +296,14 @@ func GetPCCReleases(proxy string) ([]PCCRelease, error) {
return nil, fmt.Errorf("cannot marshal ListTreesRequest: %v", err)
}

req, err := http.NewRequest("POST", bag.AtResearcherListTrees, bytes.NewReader(data))
req, err = http.NewRequest("POST", bag.AtResearcherListTrees, bytes.NewReader(data))
if err != nil {
return nil, fmt.Errorf("cannot create http POST request: %v", err)
}
req.Header.Set("X-Apple-Request-UUID", uuid)
req.Header.Set("Content-Type", "application/protobuf")
req.Header.Add("User-Agent", utils.RandomAgent())

client := &http.Client{
Transport: &http.Transport{
Proxy: GetProxy(proxy),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}

res, err = client.Do(req)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4a176a1

Please sign in to comment.