Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/jmxremote/bootstrap/SSLConfigFilePermissionTest.sh
38867 views
#!/bin/sh12#3# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#242526# @test27# @bug 655709328# @summary Check SSL config file permission for out-of-the-box management29#30# @run shell SSLConfigFilePermissionTest.sh3132createJavaFile()33{34cat << EOF > $1/$2.java35class $2 {36public static void main(String[] args) {37System.out.println("Inside main method...");38}39}40EOF41}4243createManagementConfigFile() {44cat << EOF > $145# management.properties46com.sun.management.jmxremote.authenticate=false47com.sun.management.jmxremote.ssl.config.file=$248EOF49}5051createSSLConfigFile() {52if [ -f "$1" ] ; then53rm -f $1 || echo WARNING: $1 already exists - unable to remove old copy54fi55cat << EOF > $156javax.net.ssl.keyStore=$257javax.net.ssl.keyStorePassword=password58EOF59}6061# Check we are run from jtreg62if [ -z "${TESTCLASSES}" ]; then63echo "Test is designed to be run from jtreg only"64exit 065fi6667# Test not suitable for Windows as chmod may not be able to68# security the password file.6970os=`uname -s`71if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then72echo "Test not designed to run on this operating system, skipping..."73exit 074fi7576# Create management and SSL configuration files7778LIBDIR=${TESTCLASSES}/lib79MGMT=${LIBDIR}/management.properties80SSL=${LIBDIR}/jmxremote.ssl.config81rm -f ${MGMT}82rm -f ${SSL}83mkdir ${LIBDIR} 2>&184createJavaFile ${TESTCLASSES} Dummy85createManagementConfigFile ${MGMT} ${SSL}86createSSLConfigFile ${SSL} ${TESTSRC}/ssl/keystore8788# Compile test8990${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${TESTCLASSES} ${TESTCLASSES}/Dummy.java9192JAVA=${TESTJAVA}/bin/java93CLASSPATH=${TESTCLASSES}94export CLASSPATH9596failures=09798mp=-Dcom.sun.management.config.file=${MGMT}99pp=-Dcom.sun.management.jmxremote.port=4999100101go() {102echo ''103sh -xc "$JAVA ${TESTVMOPTS} $1 $2 $3 $4 $5 $6 $7 $8" 2>&1104if [ $? != 0 ]; then failures=`expr $failures + 1`; fi105}106107# Test 1 - SSL config file is secure - VM should start108chmod 700 ${SSL}109sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Dummy" 2>&1110if [ $? != 0 ]; then failures=`expr $failures + 1`; fi111112# Test 2 - SSL config file is not secure - VM should fail to start113chmod o+rx ${SSL}114sh -xc "$JAVA ${TESTVMOPTS} $mp $pp Dummy" 2>&1115if [ $? = 0 ]; then failures=`expr $failures + 1`; fi116117# Reset the file permissions on the generated SSL config file118chmod 777 ${SSL}119120#121# Results122#123echo ''124if [ $failures -gt 0 ];125then echo "$failures test(s) failed";126else echo "All test(s) passed"; fi127exit $failures128129130