diff --git a/client_handler.go b/client_handler.go index 54c7d78e..ce5d0581 100644 --- a/client_handler.go +++ b/client_handler.go @@ -2,6 +2,7 @@ package ftpserver import ( "bufio" + "crypto/tls" "errors" "fmt" "io" @@ -51,6 +52,7 @@ var ( errNoTransferConnection = errors.New("unable to open transfer: no transfer connection") errTLSRequired = errors.New("unable to open transfer: TLS is required") errInvalidTLSRequirement = errors.New("invalid TLS requirement") + errNonTLSConnection = errors.New("GetTLSCiphersuite called on a nonTLS connection") ) func getHashMapping() map[string]HASHAlgo { @@ -259,6 +261,16 @@ func (c *clientHandler) HasTLSForTransfers() bool { return c.transferTLS } +func (c *clientHandler) GetTLSCipherSuite() (uint16, error) { + conn := c.conn + tlsConn, ok := conn.(*tls.Conn) + if !ok { + return 0, errNonTLSConnection + } + + return tlsConn.ConnectionState().CipherSuite, nil +} + func (c *clientHandler) SetExtra(extra any) { c.extra = extra } diff --git a/driver.go b/driver.go index 8860a99f..87f04437 100644 --- a/driver.go +++ b/driver.go @@ -188,6 +188,9 @@ type ClientContext interface { // HasTLSForTransfers returns true if the transfer connection is over TLS HasTLSForTransfers() bool + // GetTlSCipherSuite returns ID + GetTLSCipherSuite() (uint16, error) + // GetLastCommand returns the last received command GetLastCommand() string