Path: blob/master/test/jdk/com/sun/security/sasl/digest/AuthNoUtf8.java
41154 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 463489226* @summary Ensure that setting com.sun.security.sasl.digest.utf8 to "false"27* for the SASL server causes server to not issue a charset=utf-8 directive.28*/29/**30* Default is to use UTF-8 (server will by default issue charset directive).31* Can set logging to FINEST to view exchange.32*/3334import javax.security.sasl.*;35import javax.security.auth.callback.*;36import java.security.Security;37import java.util.*;3839public class AuthNoUtf8 {40private static final String MECH = "DIGEST-MD5";41private static final String SERVER_FQDN = "machineX.imc.org";42private static final String PROTOCOL = "jmx";4344private static final byte[] EMPTY = new byte[0];4546private static String pwfile, namesfile, proxyfile;47private static boolean auto;48private static boolean verbose = false;4950private static void init(String[] args) throws Exception {51if (args.length == 0) {52pwfile = "pw.properties";53namesfile = "names.properties";54auto = true;55} else {56int i = 0;57if (args[i].equals("-m")) {58i++;59auto = false;60}61if (args.length > i) {62pwfile = args[i++];6364if (args.length > i) {65namesfile = args[i++];6667if (args.length > i) {68proxyfile = args[i];69}70}71} else {72pwfile = "pw.properties";73namesfile = "names.properties";74}75}76}7778public static void main(String[] args) throws Exception {7980init(args);8182CallbackHandler clntCbh = new ClientCallbackHandler(auto);8384CallbackHandler srvCbh =85new PropertiesFileCallbackHandler(pwfile, namesfile, proxyfile);8687Map props = new HashMap();88props.put("com.sun.security.sasl.digest.utf8", "false");8990SaslClient clnt = Sasl.createSaslClient(91new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null, clntCbh);9293SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, props,94srvCbh);9596if (clnt == null) {97throw new IllegalStateException(98"Unable to find client impl for " + MECH);99}100if (srv == null) {101throw new IllegalStateException(102"Unable to find server impl for " + MECH);103}104105byte[] response = (clnt.hasInitialResponse()?106clnt.evaluateChallenge(EMPTY) : EMPTY);107byte[] challenge;108109while (!clnt.isComplete() || !srv.isComplete()) {110challenge = srv.evaluateResponse(response);111112if (challenge != null) {113response = clnt.evaluateChallenge(challenge);114}115}116117if (clnt.isComplete() && srv.isComplete()) {118if (verbose) {119System.out.println("SUCCESS");120System.out.println("authzid is " + srv.getAuthorizationID());121}122} else {123throw new IllegalStateException("FAILURE: mismatched state:" +124" client complete? " + clnt.isComplete() +125" server complete? " + srv.isComplete());126}127128clnt.dispose();129srv.dispose();130}131}132133134