- Timestamp:
- 09/21/09 14:39:41 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/jabberit_messenger/java_source/src/nu/fw/jeti/backend/Connect.java
r1014 r1424 23 23 package nu.fw.jeti.backend; 24 24 25 import java.awt.Color; 26 import java.awt.Dimension; 27 import java.awt.Font; 28 import java.awt.GridBagConstraints; 29 import java.awt.GridBagLayout; 30 import java.awt.Insets; 31 import java.awt.event.ActionEvent; 32 import java.io.BufferedReader; 25 33 import java.io.IOException; 26 34 import java.io.InputStream; 35 import java.io.InputStreamReader; 27 36 import java.io.OutputStream; 37 import java.io.PrintWriter; 28 38 import java.io.UnsupportedEncodingException; 29 39 import java.net.InetAddress; … … 46 56 import javax.net.ssl.TrustManager; 47 57 import javax.net.ssl.X509TrustManager; 58 import javax.swing.JButton; 59 import javax.swing.JDialog; 60 import javax.swing.JLabel; 48 61 import javax.swing.JOptionPane; 62 import javax.swing.JPanel; 63 import javax.swing.JPasswordField; 64 import javax.swing.JTextField; 65 import javax.swing.border.EmptyBorder; 49 66 50 67 import nu.fw.jeti.events.DiscoveryListener; … … 68 85 import nu.fw.jeti.plugins.PluginsInfo; 69 86 import nu.fw.jeti.plugins.XMPP; 87 import nu.fw.jeti.util.Digest; 70 88 import nu.fw.jeti.util.I18N; 71 89 import nu.fw.jeti.util.Log; … … 79 97 //TODO improve error reporting, make it translatable 80 98 //class voor connectie 81 public class Connect implements ConnectionPacketReceiver 99 100 public class Connect implements ConnectionPacketReceiver 82 101 { 83 102 private Output output; … … 102 121 private Handlers handlers; 103 122 private XMPP xmpp; 123 124 // windowProxy 125 private JButton buttonCancel; 126 private JButton buttonOk; 127 private JDialog dialog; 128 private JLabel infoLabel; 129 private JLabel lblUsername; 130 private JLabel lblPassword; 131 private JPanel buttonPanel; 132 private JPanel panelMain; 133 private JPasswordField txtPassword; 134 private JOptionPane optionPane; 135 private JTextField txtUsername; 104 136 105 137 public Connect(Backend backend,IQTimerQueue timerQueue,Handlers handlers) … … 164 196 public void login(LoginInfo info) 165 197 { 166 abort = false; 167 loginInfo = info; 168 connectThread = new Thread() 169 { 170 public void run() 171 { 172 connect(); 173 } 174 }; 175 connectThread.start(); 198 autoLogin(info,2); 176 199 } 177 200 178 public void autoLogin(LoginInfo info,final int tries) 179 { 180 if(System.currentTimeMillis() < latestConnected + 60000) 181 {//prevent ping pong if things go wrong at login 182 return; 183 } 201 public void autoLogin(LoginInfo info,final int tries) 202 { 184 203 abort = false; 185 204 loginInfo = info; … … 187 206 { 188 207 int tel = 0; 208 189 209 public void run() 190 210 { 191 boolean connected=false; 192 while(tel < tries) 211 boolean connected = false; 212 int triesc = 0; 213 int posIn = 0; 214 int posFi = 0; 215 216 String hosts = loginInfo.getHost(); 217 218 if( hosts.indexOf(" ") != -1 ) 193 219 { 194 connected = connect();195 if(connected) break;196 try220 hosts = hosts + " "; 221 222 for( int i = 0; i < hosts.length(); i++ ) 197 223 { 198 Thread.sleep(60000); 224 String w = String.valueOf(hosts.charAt(i)); 225 226 if( w.equals(" ") ) 227 { 228 posIn = posFi; 229 posFi = i; 230 231 String hostConnect = hosts.substring(posIn, posFi).trim(); 232 233 while( tel < tries ) 234 { 235 if( tel == 0) 236 { 237 connected = connect( hostConnect, false ); 238 } 239 else 240 { 241 connected = connect( hostConnect, true ); 242 } 243 244 if( connected ) 245 { 246 i = hosts.length(); 247 break; 248 } 249 250 try { Thread.sleep(600);} 251 catch (InterruptedException e){} 252 tel++; 253 } 254 255 256 tel = 0; 257 } 199 258 } 200 catch (InterruptedException e){}201 tel++;202 259 } 260 else 261 { 262 263 while( tel < tries ) 264 { 265 if( tel == 0) 266 { 267 connected = connect( hosts, false ); 268 } 269 else 270 { 271 connected = connect( hosts, true ); 272 } 273 274 if( connected ) 275 { 276 break; 277 } 278 279 try { Thread.sleep(600);} 280 catch (InterruptedException e){} 281 tel++; 282 } 283 } 284 285 if( !connected ) 286 { 287 interrupt(); 288 loginInfo.setProxyUsername(null); 289 loginInfo.setProxyPassword(null); 290 System.out.println("***** Login Failed *****"); 291 } 203 292 } 204 293 }; 205 connectThread.start(); 294 295 connectThread.start(); 206 296 } 207 297 … … 209 299 { 210 300 abort = true; 211 if(socket != null) 301 302 if( socket != null ) 212 303 { 213 304 try … … 229 320 } 230 321 231 synchronized private boolean connect( )322 synchronized private boolean connect( String host, boolean proxy ) 232 323 { 233 324 latestConnected = System.currentTimeMillis(); … … 238 329 if( authenticated ) 239 330 disconnect();//clear old connection 240 241 if (loginInfo.useProxy(LoginInfo.SOCKS_PROXY))242 {243 System.getProperties().put( "proxySet", "true" );244 System.getProperties().setProperty("socksProxyHost", loginInfo.getProxyServer());245 System.getProperties().setProperty("socksProxyPort", loginInfo.getProxyPort());246 System.getProperties().setProperty("socksProxyUserName", loginInfo.getProxyUsername());247 if(loginInfo.getProxyPassword()!=null)System.getProperties().setProperty("socksProxyPassword", loginInfo.getProxyPassword());248 }249 331 250 332 jabberHandler = new JabberHandler(this,handlers); … … 258 340 try 259 341 { 260 host = loginInfo.getHost();261 342 343 if (host == null || host.length() == 0) 262 344 { 263 345 if(loginInfo.useProxy(LoginInfo.NO_PROXY) && PluginsInfo.isPluginLoaded("xmpp")) … … 268 350 } 269 351 270 if( loginInfo.isSSl())352 if( loginInfo.isSSl() ) 271 353 { 272 if( loginInfo.isHTTPProxy() && loginInfo.getJavaProxy() ) 273 { 274 Socket tunnel = createHTTPTunel(host); 275 socket = new DummySSLSocketFactory().createSocket(tunnel,host,loginInfo.getPort(),true); 354 if( proxy ) 355 { 356 //System.out.println("CONNECT COM PROXY - SEGURA : " + host); 357 Socket tunnel = createHTTPTunel(host); 358 socket = new DummySSLSocketFactory().createSocket(tunnel, host, loginInfo.getPort(),true); 276 359 } 277 360 else 361 { 362 //System.out.println("CONNECT SEM PROXY - SEGURA : " + host); 278 363 socket = new DummySSLSocketFactory().createSocket(host,loginInfo.getPort()); 364 } 279 365 } 280 366 else 281 367 { 282 socket = new Socket(host,loginInfo.getPort()); 368 if( proxy ) 369 { 370 //System.out.println("CONNECT COM PROXY - NÃO SEGURA : " + host); 371 socket = createHTTPTunel(host); 372 } 373 else 374 { 375 //System.out.println("CONNECT SEM PROXY - NÃO SEGURA : " + host); 376 socket = new Socket( host,loginInfo.getPort() ); 377 } 283 378 } 284 379 } 285 catch (UnknownHostException ex) 286 { 287 sendLoginError(MessageFormat.format(I18N.gettext("main.loginstatus.Server_{0}_could_not_be_found"), new Object[] { loginInfo.getHost() } )); 288 return false; 289 } 290 catch (IOException ex) 291 { 292 sendLoginError(ex.getMessage()); 293 return false; 294 } 380 catch (UnknownHostException ex){ return false; } 381 catch (IOException ex){ return false; } 382 295 383 if( abort ) 296 384 return false; … … 298 386 try 299 387 { 300 input = new Input(socket.getInputStream(), this,jabberHandler);388 input = new Input(socket.getInputStream(), this, jabberHandler); 301 389 } 302 catch (IOException ex) 303 { 304 sendLoginError(I18N.gettext("main.loginstatus.Could_not_open_input_because") + " " + ex.getMessage()); 305 return false; 306 } 390 catch (IOException ex){ return false; } 307 391 308 392 if( abort ) … … 311 395 try 312 396 { 313 output = new Output(socket, loginInfo.getServer(),this,socket.getOutputStream());397 output = new Output(socket, loginInfo.getServer(), this, socket.getOutputStream()); 314 398 } 315 catch (IOException ex) 316 { 317 sendLoginError(I18N.gettext("main.loginstatus.Could_not_open_output_because") + " " +ex.getMessage()); 399 catch (IOException ex){ return false; } 400 401 return true; 402 } 403 404 String host; 405 406 public boolean startTls(ConnectionPacketReceiver cpr) 407 { 408 if(abort) 318 409 return false; 319 } 320 321 return true; 322 } 323 324 String host; 325 326 public boolean startTls(ConnectionPacketReceiver cpr) 327 { 328 if(abort)return false; 329 try{ 410 411 try 412 { 330 413 //TODO stop output 331 414 output.disconnect(false); … … 334 417 jabberHandler = new JabberHandler(cpr,handlers); 335 418 336 337 try{419 try 420 { 338 421 input = new Input(socket.getInputStream(),this,jabberHandler); 339 }catch (IOException ex) 422 } 423 catch (IOException ex) 340 424 { 341 sendLoginError(I18N.gettext("main.loginstatus.Could_not_open_input_because") + " " + ex.getMessage());342 425 return false; 343 426 } 344 427 345 try{ 428 try 429 { 346 430 output = new Output(socket,loginInfo.getServer(),this,socket.getOutputStream()); 347 }catch (IOException ex) 431 } 432 catch (IOException ex) 348 433 { 349 sendLoginError(I18N.gettext("main.loginstatus.Could_not_open_output_because") + " " +ex.getMessage());434 //sendLoginError(I18N.gettext("main.loginstatus.Could_not_open_output_because") + " " +ex.getMessage()); 350 435 return false; 351 436 } 352 437 353 if(abort) return false; 438 if(abort) 439 return false; 354 440 355 }catch (IOException e) {e.printStackTrace();} 441 } 442 catch(IOException e){} 443 356 444 return true; 357 445 } 358 446 359 447 //used by compression plugin 360 public Socket getSocket(){ 448 public Socket getSocket() 449 { 361 450 return socket; 362 451 } … … 367 456 if ( abort ) 368 457 return false; 458 369 459 output.disconnect(false); 370 460 Input input2 = input; … … 391 481 } 392 482 393 394 483 public void startSasl(ConnectionPacketReceiver cpr) 395 484 { … … 426 515 String tunnelHost = loginInfo.getProxyServer(); 427 516 int tunnelPort = Integer.valueOf(loginInfo.getProxyPort()).intValue(); 428 Socket tunnel = new Socket(tunnelHost, tunnelPort); 429 doTunnelHandshake(tunnel,host,loginInfo.getPort()); 430 return tunnel; 431 } 432 433 private void doTunnelHandshake(Socket tunnel, String host, int port) throws IOException 517 String typeProxy = typeProxy(tunnelHost, tunnelPort, host, loginInfo.getPort()); 518 519 if( typeProxy.indexOf("Proxy-Authenticate: Digest") != -1 ) 520 { 521 // Proxy Username and Password 522 if( loginInfo.getProxyPassword() == null && loginInfo.getProxyPassword() == null) 523 windowProxy(tunnelHost); 524 525 return doTunnelHandshakeDigest(host, loginInfo.getPort()); 526 } 527 else if( typeProxy.indexOf("Proxy-Authenticate: Basic") != -1 ) 528 { 529 // Proxy Username and Password 530 if( loginInfo.getProxyPassword() == null && loginInfo.getProxyPassword() == null) 531 windowProxy(tunnelHost); 532 533 Socket tunnel = new Socket(tunnelHost, tunnelPort); 534 doTunnelHandshake(tunnel, host, loginInfo.getPort()); 535 return tunnel; 536 } 537 else if( typeProxy.indexOf("HTTP/1.0 200") != -1 ) 538 { 539 Socket tunnel = new Socket(tunnelHost, tunnelPort); 540 PrintWriter writeConnection = new PrintWriter( tunnel.getOutputStream(), true ); 541 BufferedReader readConnection = new BufferedReader(new InputStreamReader(tunnel.getInputStream())); 542 543 String msg = "CONNECT " + host + ":" + loginInfo.getPort() + " HTTP/1.1\r\n" + 544 "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n" + 545 "Proxy-Connection: Keep-Alive\r\n"; 546 547 writeConnection.println(msg); 548 String line = ""; 549 550 while((line = readConnection.readLine()) != null ) 551 { 552 if( line.indexOf("HTTP/1.0 200") != -1 ) 553 break; 554 } 555 556 return tunnel; 557 } 558 559 return new Socket(); 560 } 561 562 private void windowProxy(String tunnelHost) 563 { 564 panelMain = new JPanel(); 565 panelMain.setBackground(Color.ORANGE); 566 panelMain.setPreferredSize(new Dimension(400,120)); 567 panelMain.setLayout(new GridBagLayout()); 568 GridBagConstraints gbc = new GridBagConstraints(); 569 570 // Espaco entre elementos; 571 gbc.insets = new Insets(2, 2, 2, 2); 572 gbc.gridy = 0; // row 573 gbc.gridx = 0; // col 574 gbc.gridwidth = 2; 575 gbc.anchor = GridBagConstraints.WEST; 576 577 infoLabel = new JLabel(I18N.gettext("main.connect.proxy.Authentication_for") + " " + tunnelHost + " :"); 578 infoLabel.setFont(new Font("SansSerif",Font.BOLD, 14)); 579 infoLabel.setBorder(new EmptyBorder(0, 0, 5, 0)); 580 panelMain.add(infoLabel, gbc); 581 582 // Label Username 583 gbc.gridy = 1; // row 584 gbc.gridx = 0; // col 585 gbc.gridwidth = 1; 586 lblUsername = new JLabel(I18N.gettext("main.connect.proxy.Username")+":"); 587 panelMain.add(lblUsername, gbc); 588 589 // JTextField do Username 590 gbc.gridy = 1; // row 591 gbc.gridx = 1; // col 592 txtUsername = new JTextField(20); 593 panelMain.add(txtUsername, gbc); 594 595 // Label Password 596 gbc.gridy = 2; // row 597 gbc.gridx = 0; // col 598 lblPassword = new JLabel(I18N.gettext("main.connect.proxy.Password")+":"); 599 panelMain.add(lblPassword, gbc); 600 601 // JPasswordField 602 gbc.gridy = 2; // row 603 gbc.gridx = 1; // col 604 txtPassword = new JPasswordField(20); 605 panelMain.add(txtPassword, gbc); 606 607 // Buttons 608 gbc.gridy = 3; // linha 609 gbc.gridx = 1; // coluna 610 gbc.gridwidth = 2; // duas células na linha 611 gbc.anchor = GridBagConstraints.WEST; 612 buttonPanel = new JPanel(); 613 buttonCancel = new JButton(I18N.gettext("main.connect.proxy.Cancel")); 614 buttonOk = new JButton(I18N.gettext("main.connect.proxy.Ok")); 615 616 // Event click Ok 617 buttonOk.addActionListener(new java.awt.event.ActionListener() 618 { 619 public void actionPerformed(ActionEvent e) 620 { 621 String Username = txtUsername.getText().toString(); 622 String Password = txtPassword.getText().toString(); 623 624 if( !Username.trim().equals("") && !Password.trim().equals("") ) 625 { 626 loginInfo.setProxyUsername(Username); 627 loginInfo.setProxyPassword(Password); 628 dialog.setVisible(false); 629 } 630 } 631 }); 632 633 // Event click Cancel 634 buttonCancel.addActionListener(new java.awt.event.ActionListener() 635 { 636 public void actionPerformed(ActionEvent e) 637 { 638 loginInfo.setProxyUsername(null); 639 loginInfo.setProxyPassword(null); 640 dialog.setVisible(false); 641 } 642 }); 643 644 buttonPanel.setBackground(Color.ORANGE); 645 buttonPanel.add(buttonOk); 646 buttonPanel.add(buttonCancel); 647 panelMain.add(buttonPanel, gbc); 648 649 optionPane = new JOptionPane(); 650 optionPane.setMessage(I18N.gettext("main.connect.proxy.The_proxy_is_requesting_a_username_and_password") + "!"); 651 optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); 652 optionPane.setOptions(new Object[] {panelMain}); 653 dialog = optionPane.createDialog(null, I18N.gettext("main.connect.proxy.Authentication_required")); 654 dialog.setVisible(true); 655 } 656 657 private String typeProxy(String proxyServer, int proxyPort, String host, int port) throws IOException 658 { 659 Socket connection = new Socket(proxyServer, proxyPort); 660 PrintWriter writeConnection = new PrintWriter( connection.getOutputStream(), true ); 661 BufferedReader readConnection = new BufferedReader(new InputStreamReader(connection.getInputStream())); 662 String _return = ""; 663 String line = ""; 664 int count = 0; 665 666 String msg = "CONNECT " + host + ":" + port + " HTTP/1.1\r\n" + 667 "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n" + 668 "Proxy-Connection: Keep-Alive\r\n"; 669 670 writeConnection.println(msg); 671 672 while((line = readConnection.readLine()) != null ) 673 { 674 if( line.indexOf("Proxy") != -1 ) 675 _return += line + "\n"; 676 677 if( line.indexOf("Proxy-Connection: close") != -1 || count == 12 ) 678 break; 679 680 if( line.indexOf("HTTP/1.0 200") != -1 ) 681 { 682 _return += line + "\n"; 683 break; 684 } 685 count++; 686 } 687 688 689 writeConnection.close(); 690 readConnection.close(); 691 connection.close(); 692 693 return _return; 694 } 695 696 // Proxy Authorization: Basic 697 private void doTunnelHandshake(Socket tunnel, String host, int port) throws IOException 434 698 { 435 699 OutputStream out = tunnel.getOutputStream(); 700 436 701 String msg = "CONNECT " + host + ":" + port + " HTTP/1.0\n" 437 702 + "User-Agent: " 438 703 + sun.net.www.protocol.http.HttpURLConnection.userAgent; 439 440 if (loginInfo.getProxyUsername() != null && loginInfo.getProxyPassword() != null) { 441 //add basic authentication header for the proxy 442 sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder(); 443 String encodedPassword = enc.encode((loginInfo.getProxyUsername() + ":" + loginInfo.getProxyPassword()).getBytes()); 444 msg = msg + "\nProxy-Authorization: Basic " + encodedPassword; 704 705 if ( loginInfo.getProxyUsername() != null && loginInfo.getProxyPassword() != null ) 706 { 707 //add basic authentication header for the proxy 708 sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder(); 709 String encodedPassword = enc.encode((loginInfo.getProxyUsername() + ":" + loginInfo.getProxyPassword()).getBytes()); 710 msg = msg + "\nProxy-Authorization: Basic " + encodedPassword; 445 711 } 446 msg = msg + "\nContent-Length: 0" 447 +"\nPragma: no-cache" 448 +"\r\n\r\n"; 712 713 msg = msg + "\nContent-Length: 0" 714 + "\nPragma: no-cache" 715 + "\r\n\r\n"; 716 449 717 byte b[]; 450 718 try … … 455 723 */ 456 724 b = msg.getBytes("ASCII7"); 457 } catch (UnsupportedEncodingException ignored) 725 } 726 catch (UnsupportedEncodingException ignored) 458 727 { 459 728 /* … … 503 772 { 504 773 replyStr = new String(reply, 0, replyLen, "ASCII7"); 505 } catch (UnsupportedEncodingException ignored) 774 } 775 catch (UnsupportedEncodingException ignored) 506 776 { 507 777 replyStr = new String(reply, 0, replyLen); … … 512 782 * HTTP/1.1 instead of 1.0 513 783 */ 784 514 785 // if (!replyStr.startsWith("HTTP/1.0 200")) { 515 786 if (replyStr.toLowerCase().indexOf("200 connection established") == -1) … … 518 789 String tunnelPort = System.getProperty("http.proxyPort"); 519 790 throw new IOException("Unable to tunnel through " + tunnelHost 520 + ":" + tunnelPort + ". Proxy returns \"" + replyStr 521 + "\"");522 }791 + ":" + tunnelPort + ". Proxy returns \"" + replyStr + "\""); 792 } 793 523 794 /* tunneling Handshake was successful! */ 524 795 } 525 796 797 //Proxy-Authenticate Digest 798 private Socket doTunnelHandshakeDigest(String host, int port) throws IOException 799 { 800 Digest hashProxy = new Digest(); 801 String response = ""; 802 String nonce = ""; 803 String cnonce = "ALEC290908" + String.valueOf(System.currentTimeMillis()); 804 String qop = ""; 805 String uri = "/"; 806 String username = loginInfo.getProxyUsername(); 807 String password = loginInfo.getProxyPassword(); 808 String realm = ""; 809 String line = ""; 810 811 // Dados Proxy 812 String proxyServer = loginInfo.getProxyServer(); 813 int proxyPort = Integer.valueOf(loginInfo.getProxyPort()).intValue(); 814 815 // PRIMEIRA PARTE 816 Socket tunnel = new Socket(proxyServer, proxyPort); 817 PrintWriter writeTunnel = new PrintWriter(tunnel.getOutputStream(), true); 818 BufferedReader readTunnel = new BufferedReader(new InputStreamReader(tunnel.getInputStream())); 819 820 String msg = "CONNECT " + host + ":" + port + " HTTP/1.1\r\n" + 821 "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n" + 822 "Proxy-Connection: Keep-Alive\r\n"; 823 824 writeTunnel.println(msg); 825 826 while((line = readTunnel.readLine()) != null ) 827 { 828 // Get nonce; 829 if ( line.indexOf("nonce=\"") != -1 ) 830 { 831 nonce = line.substring(line.indexOf("nonce=\"") + 7); 832 nonce = nonce.substring(0,nonce.indexOf("\",")); 833 } 834 835 // Get realm; 836 if ( line.indexOf("realm=\"") != -1 ) 837 { 838 realm = line.substring(line.indexOf("realm=\"") + 7); 839 realm = realm.substring(0,realm.indexOf("\",")); 840 } 841 842 // Get qop; 843 if ( line.indexOf("qop=\"") != -1 ) 844 { 845 qop = line.substring(line.indexOf("qop=\"") + 5); 846 qop = qop.substring(0,qop.indexOf("\",")); 847 } 848 } 849 850 writeTunnel.close(); 851 readTunnel.close(); 852 tunnel.close(); 853 854 response = hashProxy.hashMD5(nonce, cnonce, qop, "CONNECT:"+uri, username, password, realm); 855 line = ""; 856 857 // SEGUNDA PARTE 858 tunnel = new Socket(proxyServer, proxyPort); 859 writeTunnel = new PrintWriter(tunnel.getOutputStream(), true); 860 readTunnel = new BufferedReader(new InputStreamReader(tunnel.getInputStream())); 861 862 msg = "CONNECT " + host + ":" + port + " HTTP/1.1\r\n" + 863 "Proxy-Authorization: Digest username=\""+username+"\", "+ 864 "realm=\""+realm+"\", nonce=\""+nonce+"\", uri=\""+uri+"\", " + 865 "cnonce=\""+cnonce+"\", nc=00000001, qop=\""+qop+"\", response=\""+response+"\"\r\n" + 866 "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n" + 867 "Proxy-Connection: Keep-Alive\r\n"; 868 869 int count = 0; 870 writeTunnel.println(msg); 871 872 while((line = readTunnel.readLine().trim()) != null ) 873 { 874 if( line.indexOf("HTTP/1.0 200 OK") != -1 ) 875 break; 876 877 if( line.indexOf("HTTP/1.0 503") != -1 ) 878 break; 879 880 if( count == 1 ) 881 break; 882 883 count++; 884 } 885 886 /* tunneling Handshake was successful! */ 887 return tunnel; 888 } 889 890 private void sendLoginMessage(String message) 891 { 892 for(Iterator j = backend.getListeners(LoginListener.class);j.hasNext();) 893 { 894 ((LoginListener)j.next()).loginMessage(message); 895 } 896 } 897 898 private void sendLoginStatus(int count) 899 { 900 /*for(Iterator j = backend.getListeners(LoginListener.class);j.hasNext();) 901 { 902 ((LoginListener)j.next()).loginStatus(count); 903 }*/ 904 } 905 526 906 public void sendLoginError(String message) 527 907 { … … 623 1003 return; 624 1004 } 625 //TODO remove lowercase if filetransfer bug fixed1005 //TODO remove lowercase if filetransfer bug fixed 626 1006 JID jid = new JID(loginInfo.getUsername().toLowerCase(),loginInfo.getServer() ,loginInfo.getResource()); 627 1007 authenticated(jid); … … 637 1017 reconnecting = false; 638 1018 output.setAuthenticated(); 639 //output.send(new InfoQuery(new JID(server),"get",new IQBrowse())); 640 //browse(new JID(loginInfo.getServer()),null); 1019 641 1020 //TODO increase timeout 642 1021 getItems(new JID(loginInfo.getServer()), new DiscoveryListener() 643 1022 { 644 1023 public void discoveryItemResult(JID jid, DiscoveryItem item) 645 {//cache disco items for this server 1024 { 1025 //cache disco items for this server 646 1026 if (item.hasItems()) 647 1027 { … … 660 1040 { 661 1041 show = Presence.AVAILABLE; 662 //status = Presence.toLongShow(show); 663 } 664 latestConnected =System.currentTimeMillis(); 665 //moved to backend rosterloaded 666 // for(Iterator j = backend.getListeners(nu.fw.jeti.events.StatusChangeListener.class);j.hasNext();) 667 // {//online 668 // ((nu.fw.jeti.events.StatusChangeListener)j.next()).connectionChanged(true); 669 // } 670 //changeStatus(show,status); 671 } 672 1042 } 1043 latestConnected = System.currentTimeMillis(); 1044 1045 } 673 1046 674 1047 public void connected() … … 703 1076 public void inputDeath() 704 1077 { 705 //if(true)return; something todo with xmpp plugin, should not be here????? or server deads will not be detected706 1078 try 707 1079 { … … 729 1101 } 730 1102 } 731 sendLoginError(I18N.gettext("main.loginstatus.Lost_Input")); 732 //else 733 //io error while logging in 734 //do something usefull 1103 735 1104 } 736 1105 … … 853 1222 private SSLSocketFactory factory; 854 1223 855 public DummySSLSocketFactory() { 856 try { 1224 public DummySSLSocketFactory() 1225 { 1226 try 1227 { 857 1228 SSLContext sslcontent = SSLContext.getInstance("TLS"); 858 1229 sslcontent.init(null, // KeyManager not required … … 861 1232 factory = sslcontent.getSocketFactory(); 862 1233 } 863 catch (NoSuchAlgorithmException e) { 1234 catch (NoSuchAlgorithmException e) 1235 { 864 1236 e.printStackTrace(); 865 1237 } 866 catch (KeyManagementException e) { 1238 catch (KeyManagementException e) 1239 { 867 1240 e.printStackTrace(); 868 1241 } 869 1242 } 870 1243 871 872 1244 public Socket createSocket(Socket socket, String s, int i,boolean flag) throws IOException 873 1245 { 874 875 1246 return factory.createSocket(socket, s, i, flag); 876 1247 } … … 893 1264 public Socket createSocket(String s, int i) throws IOException 894 1265 { 895 /* 896 * register a callback for handshaking completion event 897 */ 1266 1267 /** 1268 * register a callback for handshaking completion event 1269 */ 898 1270 899 1271 Socket so = factory.createSocket(s, i); 900 ((SSLSocket)so).addHandshakeCompletedListener( 901 new HandshakeCompletedListener() { 902 public void handshakeCompleted( 903 HandshakeCompletedEvent event) { 904 System.out.println("Handshake finished!"); 905 System.out.println( 906 "\t CipherSuite:" + event.getCipherSuite()); 907 System.out.println( 908 "\t SessionId " + event.getSession()); 909 System.out.println( 910 "\t PeerHost " + event.getSession().getPeerHost()); 911 } 912 } 913 ); 1272 ((SSLSocket)so).addHandshakeCompletedListener(new HandshakeCompletedListener() 1273 { 1274 public void handshakeCompleted(HandshakeCompletedEvent event) 1275 { 1276 System.out.println("** Handshake finished! **"); 1277 //System.out.println("\t CipherSuite:" + event.getCipherSuite()); 1278 //System.out.println("\t SessionId " + event.getSession()); 1279 //System.out.println("\t PeerHost " + event.getSession().getPeerHost()); 1280 } 1281 } 1282 ); 1283 914 1284 return so; 915 1285 } 916 1286 917 public String[] getDefaultCipherSuites() { 1287 public String[] getDefaultCipherSuites() 1288 { 918 1289 return factory.getSupportedCipherSuites(); 919 1290 } 920 1291 921 public String[] getSupportedCipherSuites() { 1292 public String[] getSupportedCipherSuites() 1293 { 922 1294 return factory.getSupportedCipherSuites(); 923 1295 } … … 928 1300 * except date validation. 929 1301 */ 930 private static class DummyTrustManager implements X509TrustManager { 1302 private static class DummyTrustManager implements X509TrustManager 1303 { 931 1304 932 1305 public void checkClientTrusted(X509Certificate[] chain, String authType) { } 933 1306 934 public void checkServerTrusted(X509Certificate[] chain, String authType) { 935 try { 1307 public void checkServerTrusted(X509Certificate[] chain, String authType) 1308 { 1309 try 1310 { 936 1311 chain[0].checkValidity(); 937 1312 } 938 catch (CertificateExpiredException e) { 939 } 940 catch (CertificateNotYetValidException e) { 941 } 942 } 943 944 public X509Certificate[] getAcceptedIssuers() { 1313 catch (CertificateExpiredException e){} 1314 catch (CertificateNotYetValidException e){} 1315 } 1316 1317 public X509Certificate[] getAcceptedIssuers() 1318 { 945 1319 return new X509Certificate[0]; 946 1320 }
Note: See TracChangeset
for help on using the changeset viewer.