public static void send ( final PacketOutputStream pos , final String username , final String password , final HostAddress currentHost , final String database , final long clientCapabilities , final long serverCapabilities , final byte serverLanguage , final byte packetSeq , final Options options , final ReadInitialHandShakePacket greetingPacket ) throws IOException { pos . startPacket ( packetSeq ) ; final byte [ ] authData ; switch ( greetingPacket . getPluginName ( ) ) { case "" : //CONJ-274 : permit connection mysql 5.1 db case DefaultAuthenticationProvider . MYSQL_NATIVE_PASSWORD : pos . permitTrace ( false ) ; try { authData = Utils . encryptPassword ( password , greetingPacket . getSeed ( ) , options . passwordCharacterEncoding ) ; break ; } catch ( NoSuchAlgorithmException e ) { //cannot occur : throw new IOException ( "Unknown algorithm SHA-1. Cannot encrypt password" , e ) ; } case DefaultAuthenticationProvider . MYSQL_CLEAR_PASSWORD : pos . permitTrace ( false ) ; if ( options . passwordCharacterEncoding != null && ! options . passwordCharacterEncoding . isEmpty ( ) ) { authData = password . getBytes ( options . passwordCharacterEncoding ) ; } else { authData = password . getBytes ( ) ; } break ; default : authData = new byte [ 0 ] ; } pos . writeInt ( ( int ) clientCapabilities ) ; pos . writeInt ( 1024 * 1024 * 1024 ) ; pos . write ( serverLanguage ) ; //1 pos . writeBytes ( ( byte ) 0 , 19 ) ; //19 pos . writeInt ( ( int ) ( clientCapabilities >> 32 ) ) ; //Maria extended flag if ( username == null || username . isEmpty ( ) ) { pos . write ( System . getProperty ( "user.name" ) . getBytes ( ) ) ; //to permit SSO } else { pos . write ( username . getBytes ( ) ) ; //strlen username } pos . write ( ( byte ) 0 ) ; //1 if ( ( serverCapabilities & MariaDbServerCapabilities . PLUGIN_AUTH_LENENC_CLIENT_DATA ) != 0 ) { pos . writeFieldLength ( authData . length ) ; pos . write ( authData ) ; } else if ( ( serverCapabilities & MariaDbServerCapabilities . SECURE_CONNECTION ) != 0 ) { pos . write ( ( byte ) authData . length ) ; pos . write ( authData ) ; } else { pos . write ( authData ) ; pos . write ( ( byte ) 0 ) ; } if ( ( serverCapabilities & MariaDbServerCapabilities . CONNECT_WITH_DB ) != 0 ) { pos . write ( database ) ; pos . write ( ( byte ) 0 ) ; } if ( ( serverCapabilities & MariaDbServerCapabilities . PLUGIN_AUTH ) != 0 ) { pos . write ( greetingPacket . getPluginName ( ) ) ; pos . write ( ( byte ) 0 ) ; } if ( ( serverCapabilities & MariaDbServerCapabilities . CONNECT_ATTRS ) != 0 ) { writeConnectAttributes ( pos , options . connectionAttributes , currentHost ) ; } pos . flush ( ) ; pos . permitTrace ( true ) ; }
Send handshake response packet .