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

does not take UTF-8 more byte character length into account when writing data to a file #133

Open
msproact opened this issue Jan 19, 2022 · 0 comments

Comments

@msproact
Copy link

I have:

		begin
			# Does not seem to correctly set permissions on open
			# https://stackoverflow.com/questions/7713850/unable-to-create-file-with-correct-permissions-using-netssh-library
			filehandle = @sftp.open!(newauthkeyfile, 'w', :permissions => 0600)
			@sftp.fsetstat!(filehandle, {:permissions => 0600})
			# Does not take a permissions argument this way
			@sftp.file.open(newauthkeyfile , "w" ) do | file |
				authkeys=["Dozentenschlüssel", "1234567890"]
				authkeys.each do | line |
					puts line
					file.puts line
					wantedsize += line.length + 1
				end
			end
			@sftp.loop
		rescue Net::SFTP::StatusException => exception
			puts	exception.message
			puts "ERROR: Can't open authorized_keys for writing! Skipped."
			return
		end

(source from https://github.com/proact-de/distkeys with some minor adaptions made during debugging this)

which should produce:

Dozentenschlüssel
1234567890

But it produces:

root@debiantemplate:~# cat .ssh/authorized_keys
Dozentenschlüsse
1234567890

As hexdump:

root@debiantemplate:~# hd .ssh/authorized_keys
00000000  44 6f 7a 65 6e 74 65 6e  73 63 68 6c c3 bc 73 73  |Dozentenschl..ss|
00000010  65 0a 31 32 33 34 35 36  37 38 39 30 0a           |e.1234567890.|
0000001d

Just using "puts" to terminal produces the correct result. I bet Net:SFTP overloads the method and it has to do with the SFTP specific implementation.

If you use "Dozentenschlüüssel" instead then two bytes are missing.

I did not check whether the setting permissions issue I worked around in my code is still there or not.

msproact added a commit to proact-de/distkeys that referenced this issue Jan 19, 2022
does not take UTF-8 more byte character length into account when writing data to a file #133
net-ssh/net-sftp#133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant