Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/NIOSSH/ByteBuffer+SSH.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ extension ByteBuffer {
mutating func writeCompositeSSHString(_ compositeFunction: (inout ByteBuffer) throws -> Int) rethrows -> Int {
// Reserve 4 bytes for the length.
let originalWriterIndex = self.writerIndex
self.moveWriterIndex(forwardBy: 4)
self.writeInteger(UInt32(0))

var writtenLength: Int
do {
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOSSH/SSHPacketSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension ByteBuffer {
/// byte[m] mac (Message Authentication Code - MAC); m = mac_length

/// payload
self.moveWriterIndex(forwardBy: 5)
self.writeMultipleIntegers(UInt32(0), UInt8(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's also writeRepeatedBytes (or something similar to that) which might be a teeny tiny bit more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I actually thought this one made more sense given the packet format laid out above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I was looking at it as the diff from “move the writer by 5”.

let messageLength = self.writeSSHMessage(message)

// Depending on on whether packet length is encrypted, padding should reflect that
Expand Down
27 changes: 27 additions & 0 deletions Tests/NIOSSHTests/ByteBuffer+SSHTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,33 @@ final class ByteBufferSSHTests: XCTestCase {

XCTAssertNoThrow(XCTAssertNotNil(try buffer.readSSHHostKey()))
}

func testCompositeStringDoesTheRightThingWithBB() throws {
var buffer = ByteBuffer()
XCTAssertEqual(buffer.capacity, 0)

buffer.writeCompositeSSHString {
$0.writeInteger(UInt64(9))
}
let writtenBytes = buffer.readBytes(length: buffer.readableBytes)
XCTAssertEqual(
writtenBytes,
[0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 9]
)
}

func testWriteSSHPacketDoesTheRightThingWithBB() throws {
var buffer = ByteBuffer()
XCTAssertEqual(buffer.capacity, 0)

buffer.writeSSHPacket(message: .version("Tests_v1.0"), lengthEncrypted: false, blockSize: 8)

let writtenBytes = buffer.readBytes(length: 5)
XCTAssertEqual(
writtenBytes,
[0, 0, 0, 24, 11]
)
}
}

extension ByteBuffer {
Expand Down