1

I'm trying to modify an ActionScript 3 FTP library to support explicit secure (FTP-ES) connections.

With FTP-ES, the client initially makes an insecure FTP connection, then explicitly asks the server to switch to a secure SSL/TLS connection.

Right now, I initially connect to the FTP server with a regular Socket, ask the server to switch to TLS, and then try connect with a SecureSocket after the server returns FTP code 234:

if (code.indexOf('220 ') == 0 || code.indexOf('220-') == 0) { //Send user name
    if (_useTLS) {
        trace("AUTH TLS");
        cmdSocket.writeUTFBytes('AUTH TLS\r\n');
    } else {
        cmdSocket.writeUTFBytes('USER ' + _username + '\r\n');
    }
    cmdSocket.flush();
}

if (responseCode.indexOf('234 ') == 0) { //Auth OK, expecting SSL/TLS negotatiation
    if (SecureSocket.isSupported) {
        secureCommandSocket = new SecureSocket();
        secureCommandSocket.addEventListener(ProgressEvent.SOCKET_DATA, onReceivedSCmd);
        secureCommandSocket.addEventListener(Event.CONNECT, onConnectSCmd);
        secureCommandSocket.addEventListener(IOErrorEvent.IO_ERROR, onSocketError);
        secureCommandSocket.addEventListener(Event.CLOSE, onCloseSCmd);
        secureCommandSocket.connect(_host, _port);
    } else {
        throw new Error("Secure socket is not supported on this platform");
    }
}

However, the socket returns an IOError 2031 (socket error). Here's the output:

MESSAGE: CONNECTED TO FTP
MESSAGE: Received command: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.

AUTH TLS
MESSAGE: Received command: 234 AUTH TLS OK.

MESSAGE: 2031:Error #2031: Socket Error. URL: xx.xx.xxx.xx
ERROR: Connection failed

With no more information about what's going wrong, I have no idea why the secure socket connection is failing. Is it because I'm trying to switch from a regular Socket to a SecureSocket mid-connection? If so, is there any other way to handle this in AS3?

Kevin
  • 269
  • 3
  • 13
  • I'm not a socket or protocol expert, but there's a wild guess for you to check. Might that be that your FTP server switches **the same socket** you are asking into TLS, while each new connection starts as non-secure, and that's why your **SecurreSocket** is unable to handshake? – Organis Nov 01 '18 at 00:38
  • @Organis Probably, but I don't know how to handle that when `Socket` and `SecureSocket` are two separate classes in ActionScript 3 – Kevin Nov 01 '18 at 23:58
  • You can try checking if that so (and in that case there's nothing you can do in AS3) with something simple, like https://docs.python.org/3/library/ssl.html – Organis Nov 02 '18 at 00:31

0 Answers0