Repository navigation
Conversation
…r FTP FTPClient.login(String, char[]) sends the password as a char array and clears the array once it has been transmitted to the server. The command is built and written to the control connection as char[] end-to-end so that sensitive data is never materialized into a String; command listeners receive a masked ProtocolCommandEvent. FTPSClient gets a symmetric sendCommand(String, char[]) override so the CCC transition is preserved for the new overload. Signed-off-by: Inf1mum <vadim.lazuk@mail.ru>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
NET-746:
FTPClient#login(String, String)takes the password as aString, which cannot be reliably wiped after use. This PR adds achar[]-based login path so that sensitive data never has to be materialized into aString, and zeroes the password array once it has been transmitted to the server.Changes
FTPClient.login(String user, char[] password)(new): mirrors the existinglogin(String, String)flow, sendsPASSthrough the newchar[]path, and clears the password array withArrays.fill(password, '\0')in afinallyblock once the password has been handed to the control connection (i.e. only when the password was actually transmitted; if the server never asks for a password, the array is left untouched).FTP.pass(char[])(new): symmetric with the existingpass(String).FTP.sendCommand(String, char[])andFTP.sendCommand(FTPCmd, char[])(new): build and write the command aschar[]end-to-end (buildMessage(String, char[])andsend(char[])are new private helpers), so the sensitive arguments are never converted to aString. TheProtocolCommandEventfired to command listeners reports the arguments as masked (PASS ******), unlike theStringpath, to keep secrets out of listener logs.FTPSClient: theCCCpost-processing was extracted into a privatepostSendCCC(...)helper and a matchingsendCommand(String, char[])override was added so thatFTPSClientbehaves identically for the new overload (previously onlysendCommand(String, String)restored the plain socket afterCCC).nullcall sites (sendCommand(command, null)inFTP) with(String)casts, since the new overloads otherwise make those calls ambiguous.Tests
FTPClientLoginCharPasswordTestwith a local scripted FTP server:login(String, char[])sendsPASS <password>on the wire and clears the array afterwards (even on a530rejection);ProtocolCommandListeners (they seePASS ******);FTP.pass(char[])returns the expected reply code.FTPTest: CR/LF rejection tests for the newchar[]argument path, symmetric with the existingStringtests.mvn test -Dtest=FTPTest,FTPClientTest,FTPClientLoginCharPasswordTest,FTPSClientTestpasses.Notes
String-based API is unchanged; the new overloads are additive (@since 3.13.1).changes.xmlentry added under 3.13.1.Thanks for considering this contribution!