jdk/test/sun/security/krb5/auto/SaslGSS.java
changeset 18793 4d9455e24050
parent 17209 6f556e154816
child 30820 0d4717a011d3
equal deleted inserted replaced
18792:dbac92e2a5e8 18793:4d9455e24050
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8012082
    26  * @bug 8012082 8019267
    27  * @summary SASL: auth-conf negotiated, but unencrypted data is accepted,
    27  * @summary SASL: auth-conf negotiated, but unencrypted data is accepted,
    28   *         reset to unencrypt
    28   *         reset to unencrypt
    29  * @compile -XDignore.symbol.file SaslGSS.java
    29  * @compile -XDignore.symbol.file SaslGSS.java
    30  * @run main/othervm SaslGSS
    30  * @run main/othervm SaslGSS
    31  */
    31  */
    35 import javax.security.auth.callback.UnsupportedCallbackException;
    35 import javax.security.auth.callback.UnsupportedCallbackException;
    36 import javax.security.sasl.AuthorizeCallback;
    36 import javax.security.sasl.AuthorizeCallback;
    37 import javax.security.sasl.RealmCallback;
    37 import javax.security.sasl.RealmCallback;
    38 import javax.security.sasl.Sasl;
    38 import javax.security.sasl.Sasl;
    39 import javax.security.sasl.SaslServer;
    39 import javax.security.sasl.SaslServer;
       
    40 import java.io.ByteArrayOutputStream;
    40 import java.io.IOException;
    41 import java.io.IOException;
       
    42 import java.io.PrintStream;
    41 import java.util.HashMap;
    43 import java.util.HashMap;
    42 import java.util.Locale;
    44 import java.util.Locale;
       
    45 import java.util.logging.ConsoleHandler;
       
    46 import java.util.logging.Handler;
       
    47 import java.util.logging.Level;
       
    48 import java.util.logging.Logger;
       
    49 
    43 import org.ietf.jgss.*;
    50 import org.ietf.jgss.*;
    44 import sun.security.jgss.GSSUtil;
    51 import sun.security.jgss.GSSUtil;
    45 
    52 
    46 public class SaslGSS {
    53 public class SaslGSS {
    47 
    54 
    77                             }
    84                             }
    78                         }
    85                         }
    79                     }
    86                     }
    80                 });
    87                 });
    81 
    88 
    82         // Handshake
    89         ByteArrayOutputStream bout = new ByteArrayOutputStream();
       
    90         PrintStream oldErr = System.err;
       
    91         System.setErr(new PrintStream(bout));
       
    92 
       
    93         Logger.getLogger("javax.security.sasl").setLevel(Level.ALL);
       
    94         Handler h = new ConsoleHandler();
       
    95         h.setLevel(Level.ALL);
       
    96         Logger.getLogger("javax.security.sasl").addHandler(h);
       
    97 
    83         byte[] token = new byte[0];
    98         byte[] token = new byte[0];
    84         token = sc.initSecContext(token, 0, token.length);
    99 
    85         token = ss.evaluateResponse(token);
   100         try {
    86         token = sc.unwrap(token, 0, token.length, new MessageProp(0, false));
   101             // Handshake
    87         token[0] = (byte)(((token[0] & 4) != 0) ? 4 : 2);
   102             token = sc.initSecContext(token, 0, token.length);
    88         token = sc.wrap(token, 0, token.length, new MessageProp(0, false));
   103             token = ss.evaluateResponse(token);
    89         ss.evaluateResponse(token);
   104             token = sc.unwrap(token, 0, token.length, new MessageProp(0, false));
       
   105             token[0] = (byte)(((token[0] & 4) != 0) ? 4 : 2);
       
   106             token = sc.wrap(token, 0, token.length, new MessageProp(0, false));
       
   107             ss.evaluateResponse(token);
       
   108         } finally {
       
   109             System.setErr(oldErr);
       
   110         }
    90 
   111 
    91         // Talk
   112         // Talk
    92         // 1. Client sends a auth-int message
   113         // 1. Client sends a auth-int message
    93         byte[] hello = "hello".getBytes();
   114         byte[] hello = "hello".getBytes();
    94         MessageProp qop = new MessageProp(0, false);
   115         MessageProp qop = new MessageProp(0, false);
   100         // 4. Client accepts, should be auth-conf
   121         // 4. Client accepts, should be auth-conf
   101         sc.unwrap(token, 0, token.length, qop);
   122         sc.unwrap(token, 0, token.length, qop);
   102         if (!qop.getPrivacy()) {
   123         if (!qop.getPrivacy()) {
   103             throw new Exception();
   124             throw new Exception();
   104         }
   125         }
       
   126 
       
   127         for (String s: bout.toString().split("\\n")) {
       
   128             if (s.contains("KRB5SRV04") && s.contains("NULL")) {
       
   129                 return;
       
   130             }
       
   131         }
       
   132         System.out.println("=======================");
       
   133         System.out.println(bout.toString());
       
   134         System.out.println("=======================");
       
   135         throw new Exception("Haven't seen KRB5SRV04 with NULL");
   105     }
   136     }
   106 }
   137 }