1 17 18 package org.apache.james.smtpserver; 19 20 import cryptix.jce.provider.CryptixCrypto; 21 import cryptix.sasl.Base64; 22 import java.io.DataInputStream ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import javax.security.sasl.*; 26 import org.apache.avalon.framework.logger.AbstractLogEnabled; 27 import org.apache.log4j.BasicConfigurator; 28 29 class SaslProfile extends AbstractLogEnabled { 30 31 private SaslServer server = null; 32 private DataInputStream in = null; 33 private PrintWriter out = null; 34 35 static { 36 BasicConfigurator.configure(); 38 39 java.security.Security.addProvider(new CryptixCrypto()); 41 Sasl.setSaslClientFactory(new cryptix.sasl.ClientFactory()); 42 } 43 44 SaslProfile(SaslServer _server, DataInputStream _in, PrintWriter _out) { 45 this.server = _server; 46 this.in = _in; 47 this.out = _out; 48 } 49 50 boolean doAUTH(String initialResponse) { 51 52 56 try 57 { 58 64 byte[] challenge = null; 65 byte[] response = null; 66 67 challenge = 68 server.evaluateResponse(Base64.decode(initialResponse)); 69 System.err.println("1"); 70 if (challenge != null) { 71 System.err.println("334 "+Base64.encode(challenge)); 72 out.println("334 "+Base64.encode(challenge)); 73 } 74 else { 75 if (server.isComplete()) { 76 return true; 77 } else { 78 System.err.println("334 "); 79 out.println("334 "); 80 } 81 } 82 83 89 System.err.println("2"); 90 91 do { 92 try { 93 System.err.println("3"); 94 String input = in.readLine().trim(); 95 System.err.println("input: '"+input+"'"); 96 97 if (server.isComplete()) return true; 98 99 challenge = server.evaluateResponse(Base64.decode(input)); 100 if (challenge != null) { 101 System.err.println("334 "+Base64.encode(challenge)); 102 out.println("334 "+Base64.encode(challenge)); 103 } 104 else { 105 if (server.isComplete()) { 106 return true; 107 } else { 108 System.err.println("334 "); 109 out.println("334 "); 110 } 111 } 112 } 113 catch (IOException e) { 114 System.err.println("IOException: "+e.toString()); 115 return false; 116 } 117 } while (!server.isComplete()); 118 119 return true; 120 121 126 130 } 131 catch (SaslException e) { 132 System.err.println("SaslException: "+e.toString()); 133 return false; 134 } 135 } 136 137 } 138 139 | Popular Tags |