Skip to content

Commit

Permalink
feat: enables hw calls if lms not available (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdmike authored Jun 17, 2024
1 parent c0a26d1 commit ac30948
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/apf/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions pkg/apf/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package apf

import (
"sync"
"testing"
"time"

Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/apf/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
**********************************************************************/
package apf

import "time"
import (
"sync"
"time"
)

const (
LMS_PROTOCOL_VERSION = 4
Expand Down Expand Up @@ -267,4 +270,5 @@ type Session struct {
ErrorBuffer chan error
Status chan bool
Timer *time.Timer
WaitGroup *sync.WaitGroup
}
28 changes: 14 additions & 14 deletions pkg/wsman/client/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(`"`)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/wsman/client/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/wsman/client/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package client

import "net/http"

// Parameters struct defines the connection settings for wsman client.
type Parameters struct {
Target string
Expand All @@ -9,5 +11,6 @@ type Parameters struct {
UseTLS bool
SelfSignedAllowed bool
LogAMTMessages bool
Transport http.RoundTripper
IsRedirection bool
}
9 changes: 7 additions & 2 deletions pkg/wsman/client/wsman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ac30948

Please sign in to comment.