mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
iscsi: offer CHAP method during security negotiation
This commit is contained in:
1 parent
92c6cc126c
commit
5d6f0efd66
2 files changed
+44
-7
No files matched your search
@@ -290,9 +290,7 @@ func (ln *LoginNegotiator) HandleLoginPDU(req *PDU, resolver TargetResolver) *PD
|
||||
if tpgt <= 0 {
|
||||
tpgt = 1
|
||||
}
|
||||
if !(csg == StageSecurityNeg && ln.chapRequiredForSession()) {
|
||||
respParams.Set("TargetPortalGroupTag", strconv.Itoa(tpgt))
|
||||
}
|
||||
respParams.Set("TargetPortalGroupTag", strconv.Itoa(tpgt))
|
||||
|
||||
if respParams.Len() > 0 {
|
||||
resp.DataSegment = respParams.Encode()
|
||||
@@ -463,8 +461,8 @@ func (ln *LoginNegotiator) handleCHAPSecurity(req *Params, resp *PDU, respParams
|
||||
}
|
||||
|
||||
if !ln.chapMethodOK {
|
||||
setLoginReject(resp, LoginStatusInitiatorErr, LoginDetailAuthFailed)
|
||||
return false
|
||||
respParams.Set("AuthMethod", "CHAP")
|
||||
return true
|
||||
}
|
||||
respParams.Set("AuthMethod", "CHAP")
|
||||
return true
|
||||
|
||||
@@ -238,8 +238,8 @@ func TestLoginNegotiator_CHAP_ChallengeThenLoginOp(t *testing.T) {
|
||||
if v, _ := resp2Params.Get("CHAP_C"); v != "0x"+hex.EncodeToString(challenge) {
|
||||
t.Fatalf("CHAP_C=%q want deterministic challenge", v)
|
||||
}
|
||||
if v, ok := resp2Params.Get("TargetPortalGroupTag"); ok {
|
||||
t.Fatalf("TargetPortalGroupTag=%q should not be sent during CHAP SecurityNeg", v)
|
||||
if v, _ := resp2Params.Get("TargetPortalGroupTag"); v != "1" {
|
||||
t.Fatalf("TargetPortalGroupTag=%q want 1", v)
|
||||
}
|
||||
|
||||
r3Params := iscsi.NewParams()
|
||||
@@ -311,6 +311,45 @@ func TestLoginNegotiator_CHAP_ChallengeIgnoresPrematureTransit(t *testing.T) {
|
||||
if v, _ := respParams.Get("AuthMethod"); v != "CHAP" {
|
||||
t.Fatalf("AuthMethod=%q want CHAP", v)
|
||||
}
|
||||
if v, _ := respParams.Get("TargetPortalGroupTag"); v != "1" {
|
||||
t.Fatalf("TargetPortalGroupTag=%q want 1", v)
|
||||
}
|
||||
if v, ok := respParams.Get("CHAP_C"); ok {
|
||||
t.Fatalf("CHAP_C=%q should not be emitted before CHAP_A is offered", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginNegotiator_CHAP_EmptySecurityRequestOffersMethod(t *testing.T) {
|
||||
challenge := []byte("1234567890abcdef")
|
||||
cfg := iscsi.DefaultNegotiableConfig()
|
||||
cfg.CHAP = iscsi.CHAPConfig{Username: "user1", Secret: "secret1", Challenge: challenge}
|
||||
neg := iscsi.NewLoginNegotiator(cfg)
|
||||
resolver := &fakeResolver{names: map[string]bool{"iqn.example:t1": true}}
|
||||
|
||||
params := iscsi.NewParams()
|
||||
params.Set("InitiatorName", "iqn.example.host:1")
|
||||
params.Set("SessionType", "Normal")
|
||||
params.Set("TargetName", "iqn.example:t1")
|
||||
req := mkLoginReq(iscsi.StageSecurityNeg, iscsi.StageLoginOp, true, params)
|
||||
|
||||
resp := neg.HandleLoginPDU(req, resolver)
|
||||
if resp.LoginStatusClass() != iscsi.LoginStatusSuccess {
|
||||
t.Fatalf("status=0x%02x detail=0x%02x want Success",
|
||||
resp.LoginStatusClass(), resp.LoginStatusDetail())
|
||||
}
|
||||
if resp.LoginTransit() {
|
||||
t.Fatal("response should not transit before CHAP method is accepted")
|
||||
}
|
||||
respParams, err := iscsi.ParseParams(resp.DataSegment)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseParams: %v", err)
|
||||
}
|
||||
if v, _ := respParams.Get("AuthMethod"); v != "CHAP" {
|
||||
t.Fatalf("AuthMethod=%q want CHAP", v)
|
||||
}
|
||||
if v, _ := respParams.Get("TargetPortalGroupTag"); v != "1" {
|
||||
t.Fatalf("TargetPortalGroupTag=%q want 1", v)
|
||||
}
|
||||
if v, ok := respParams.Get("CHAP_C"); ok {
|
||||
t.Fatalf("CHAP_C=%q should not be emitted before CHAP_A is offered", v)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user