Skip to content

Commit

Permalink
Add support for SSLKEYLOGFILE
Browse files Browse the repository at this point in the history
  • Loading branch information
bmteller committed May 11, 2023
1 parent efda299 commit 0c94bdc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
28 changes: 25 additions & 3 deletions pkg/appstore/appstore_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package appstore
import (
"archive/zip"
"bytes"
"crypto/tls"
"fmt"
"github.com/blacktop/ranger"
"github.com/majd/ipatool/pkg/http"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/schollz/progressbar/v3"
"howett.net/plist"
"io"
nhttp "net/http"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -49,14 +51,34 @@ type DownloadOutput struct {
DestinationPath string
}

func newPartialZipReader(urlStr string) (*zip.Reader, error) {
func keylogWriter() io.Writer {

value, exists := os.LookupEnv("SSLKEYLOGFILE")
if exists {
writer, _ := os.OpenFile(value, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0775)
return writer
} else {
return nil
}
}

func (a *appstore) newPartialZipReader(urlStr string) (*zip.Reader, error) {

url, err := url.Parse(urlStr)
if err != nil {
return nil, err
}

reader, err := ranger.NewReader(&ranger.HTTPRanger{URL: url})
transport := nhttp.DefaultTransport.(*nhttp.Transport).Clone()
transport.TLSClientConfig = &tls.Config{
KeyLogWriter: keylogWriter(),
}

client := nhttp.Client{
Transport: transport,
}

reader, err := ranger.NewReader(&ranger.HTTPRanger{URL: url, Client: &client})

if err != nil {
return nil, err
Expand Down Expand Up @@ -118,7 +140,7 @@ func (a *appstore) DownloadPaths(bundleID string, outputPath string, ipaPaths []
return DownloadOutput{}, err
}

zip, err := newPartialZipReader(item.URL)
zip, err := a.newPartialZipReader(item.URL)

if err != nil {
return DownloadOutput{}, errors.Wrap(err, ErrDownloadFile.Error())
Expand Down
23 changes: 22 additions & 1 deletion pkg/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package http

import (
"bytes"
"crypto/tls"
"encoding/json"
"github.com/pkg/errors"
"howett.net/plist"
"io"
"net/http"
"os"
"strings"
)

Expand Down Expand Up @@ -38,16 +40,35 @@ func (adt *AddHeaderTransport) RoundTrip(req *http.Request) (*http.Response, err
}

func NewClient[R interface{}](args ClientArgs) Client[R] {

transport := http.DefaultTransport.(*http.Transport).Clone()

transport.TLSClientConfig = &tls.Config{
KeyLogWriter: keylogWriter(),
}

return &client[R]{
internalClient: http.Client{
Timeout: 0,
Jar: args.CookieJar,
Transport: &AddHeaderTransport{http.DefaultTransport},
Transport: &AddHeaderTransport{transport},
},
cookieJar: args.CookieJar,
}
}

func keylogWriter() io.Writer {

value, exists := os.LookupEnv("SSLKEYLOGFILE")
if exists {
writer, _ := os.OpenFile(value, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0775)
return writer
} else {
return nil
}

}

func (c *client[R]) Send(req Request) (Result[R], error) {
var data []byte
var err error
Expand Down

0 comments on commit 0c94bdc

Please sign in to comment.