diff --git a/pkg/apf/processor.go b/pkg/apf/processor.go index 2badebd7..6008c697 100644 --- a/pkg/apf/processor.go +++ b/pkg/apf/processor.go @@ -275,7 +275,7 @@ func ProcessChannelOpenConfirmation(data []byte, session *Session) { session.SenderChannel = confirmationMessage.SenderChannel session.RecipientChannel = confirmationMessage.RecipientChannel session.TXWindow = confirmationMessage.InitialWindowSize - session.Status <- true + session.WaitGroup.Done() } func ProcessChannelOpenFailure(data []byte, session *Session) { diff --git a/pkg/apf/processor_test.go b/pkg/apf/processor_test.go index daafe1cb..446efca1 100644 --- a/pkg/apf/processor_test.go +++ b/pkg/apf/processor_test.go @@ -5,6 +5,7 @@ package apf import ( + "sync" "testing" "time" @@ -137,16 +138,18 @@ func TestProcessChannelOpenConfirmation(t *testing.T) { data := []byte{0x01} statusChannel := make(chan bool) + wg := &sync.WaitGroup{} session := &Session{ - Status: statusChannel, + Status: statusChannel, + WaitGroup: wg, } defer close(statusChannel) go func() { <-statusChannel - logrus.Print("Hello, status is done") }() + wg.Add(1) ProcessChannelOpenConfirmation(data, session) } diff --git a/pkg/apf/types.go b/pkg/apf/types.go index 916860a6..de4c2a4c 100644 --- a/pkg/apf/types.go +++ b/pkg/apf/types.go @@ -4,7 +4,10 @@ **********************************************************************/ package apf -import "time" +import ( + "sync" + "time" +) const ( LMS_PROTOCOL_VERSION = 4 @@ -267,4 +270,5 @@ type Session struct { ErrorBuffer chan error Status chan bool Timer *time.Timer + WaitGroup *sync.WaitGroup } diff --git a/pkg/wsman/client/hash.go b/pkg/wsman/client/hash.go index b9f696b1..e917caca 100644 --- a/pkg/wsman/client/hash.go +++ b/pkg/wsman/client/hash.go @@ -84,7 +84,7 @@ func (c *AuthChallenge) response(method, uri, cnonce string) (string, error) { return "", fmt.Errorf("%w: %w", errRandRead, err) } - c.CNonce = fmt.Sprintf("%x", b)[:16] + c.CNonce = fmt.Sprintf("%x", b)[:6] } c.Qop = "auth" @@ -115,34 +115,34 @@ func (c *AuthChallenge) authorize(method, uri string) (string, error) { sb.WriteString(`Digest username="`) sb.WriteString(c.Username) - sb.WriteString(`", realm="`) + sb.WriteString(`",realm="`) sb.WriteString(c.Realm) - sb.WriteString(`", nonce="`) + sb.WriteString(`",nonce="`) sb.WriteString(c.Nonce) - sb.WriteString(`", uri="`) + sb.WriteString(`",uri="`) sb.WriteString(uri) - sb.WriteString(`", response="`) + sb.WriteString(`",response="`) sb.WriteString(response) sb.WriteString(`"`) - if c.Algorithm != "" { - sb.WriteString(`, algorithm="`) - sb.WriteString(c.Algorithm) - sb.WriteString(`"`) - } + // if c.Algorithm != "" { + // sb.WriteString(`, algorithm="`) + // sb.WriteString(c.Algorithm) + // sb.WriteString(`"`) + // } if c.Opaque != "" { - sb.WriteString(`, opaque="`) + sb.WriteString(`,opaque="`) sb.WriteString(c.Opaque) sb.WriteString(`"`) } if c.Qop != "" { - sb.WriteString(`, qop="`) + sb.WriteString(`,qop="`) sb.WriteString(c.Qop) - sb.WriteString(`", nc="`) + sb.WriteString(`",nc="`) sb.WriteString(fmt.Sprintf("%08x", c.NonceCount)) - sb.WriteString(`", cnonce="`) + sb.WriteString(`",cnonce="`) sb.WriteString(c.CNonce) sb.WriteString(`"`) } diff --git a/pkg/wsman/client/hash_test.go b/pkg/wsman/client/hash_test.go index fee0eed1..e113976f 100644 --- a/pkg/wsman/client/hash_test.go +++ b/pkg/wsman/client/hash_test.go @@ -115,7 +115,7 @@ func TestAuthorize(t *testing.T) { uri string expected string }{ - {"POST", "/path", "Digest username=\"\", realm=\"\", nonce=\"\", uri=\"/path\", response=\"b9c5d3509b8a70d95a6204668265e6f9\""}, + {"POST", "/path", "Digest username=\"\",realm=\"\",nonce=\"\",uri=\"/path\",response=\"b9c5d3509b8a70d95a6204668265e6f9\""}, } for _, tc := range testCases { @@ -132,7 +132,7 @@ func TestAuthorize_Full(t *testing.T) { uri string expected string }{ - {"POST", "/path", "Digest username=\"admin\", realm=\"test\", nonce=\"00000001\", uri=\"/path\", response=\"99d726faaaa4e8874b3fd0f425053f5a\""}, + {"POST", "/path", "Digest username=\"admin\",realm=\"test\",nonce=\"00000001\",uri=\"/path\",response=\"99d726faaaa4e8874b3fd0f425053f5a\""}, } for _, tc := range testCases { diff --git a/pkg/wsman/client/types.go b/pkg/wsman/client/types.go index 105852c1..23287c55 100644 --- a/pkg/wsman/client/types.go +++ b/pkg/wsman/client/types.go @@ -1,5 +1,7 @@ package client +import "net/http" + // Parameters struct defines the connection settings for wsman client. type Parameters struct { Target string @@ -9,5 +11,6 @@ type Parameters struct { UseTLS bool SelfSignedAllowed bool LogAMTMessages bool + Transport http.RoundTripper IsRedirection bool } diff --git a/pkg/wsman/client/wsman.go b/pkg/wsman/client/wsman.go index 9b7528a2..7bb1ffeb 100644 --- a/pkg/wsman/client/wsman.go +++ b/pkg/wsman/client/wsman.go @@ -83,8 +83,13 @@ func NewWsman(cp Parameters) *Target { } res.Timeout = timeout - res.Transport = &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: cp.SelfSignedAllowed}, + + if cp.Transport == nil { + res.Transport = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: cp.SelfSignedAllowed}, + } + } else { + res.Transport = cp.Transport } if res.useDigest {