Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable packet signing for anonymous login #176

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -76,6 +79,8 @@ public class Session {

let response = try await send(request)

signingRequired = response.securityMode.contains(.signingRequired)

maxTransactSize = response.maxTransactSize
maxReadSize = response.maxReadSize
maxWriteSize = response.maxWriteSize
Expand Down Expand Up @@ -131,6 +136,8 @@ public class Session {
let response = try await send(request)

sessionId = response.header.sessionId

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

return response
Expand Down Expand Up @@ -682,7 +689,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
Loading