Skip to content

Commit

Permalink
Disable packet signing for anonymous login
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Dec 8, 2024
1 parent 450165f commit 5324b2a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/SMBClient/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class Session {
private var sessionId: UInt64 = 0
private(set) var treeId: UInt32 = 0

private var isAnonymous = false
private var signingRequired = false
private var signingKey: Data?

public private(set) var maxTransactSize: UInt32 = 0
Expand Down Expand Up @@ -42,6 +44,7 @@ public class Session {
session.sessionId = sessionId
session.treeId = 0

session.signingRequired = signingRequired
session.signingKey = signingKey

session.maxTransactSize = maxTransactSize
Expand Down Expand Up @@ -77,6 +80,8 @@ public class Session {
let data = try await send(request.encoded())
let response = Negotiate.Response(data: data)

signingRequired = response.securityMode.contains(.signingRequired)

maxTransactSize = response.maxTransactSize
maxReadSize = response.maxReadSize
maxWriteSize = response.maxWriteSize
Expand Down Expand Up @@ -133,6 +138,8 @@ public class Session {
let response = SessionSetup.Response(data: data)

sessionId = response.header.sessionId

isAnonymous = (username ?? "").isEmpty && (password ?? "").isEmpty
self.signingKey = signingKey

return response
Expand Down Expand Up @@ -707,7 +714,7 @@ public class Session {
}

private func sign(_ packet: Data) -> Data {
if let signingKey {
if let signingKey, signingRequired, !isAnonymous {
var header = Header(data: packet[..<64])
let payload = packet[64...]

Expand Down

0 comments on commit 5324b2a

Please sign in to comment.