342N/A#!/bin/sh
4196N/A
342N/A#
342N/A# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
342N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A#
342N/A# This code is free software; you can redistribute it and/or modify it
342N/A# under the terms of the GNU General Public License version 2 only, as
342N/A# published by the Free Software Foundation.
342N/A#
342N/A# This code is distributed in the hope that it will be useful, but WITHOUT
342N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A# version 2 for more details (a copy is included in the LICENSE file that
342N/A# accompanied this code).
342N/A#
342N/A# You should have received a copy of the GNU General Public License version
342N/A# 2 along with this work; if not, write to the Free Software Foundation,
1472N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1472N/A#
1472N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
342N/A# or visit www.oracle.com if you need additional information or have any
342N/A# questions.
342N/A#
1879N/A
1879N/A
1879N/A# @test
1879N/A# @bug 6557093
3678N/A# @summary Check SSL config file permission for out-of-the-box management
1879N/A#
1879N/A# @run shell SSLConfigFilePermissionTest.sh
1879N/A
1879N/AcreateJavaFile()
342N/A{
342N/A cat << EOF > $1/$2.java
342N/A class $2 {
342N/A public static void main(String[] args) {
342N/A System.out.println("Inside main method...");
342N/A }
342N/A }
342N/AEOF
342N/A}
342N/A
342N/AcreateManagementConfigFile() {
342N/A cat << EOF > $1
342N/A# management.properties
342N/Acom.sun.management.jmxremote.authenticate=false
3119N/Acom.sun.management.jmxremote.ssl.config.file=$2
342N/AEOF
342N/A}
342N/A
342N/AcreateSSLConfigFile() {
342N/A if [ -f "$1" ] ; then
342N/A rm -f $1 || echo WARNING: $1 already exists - unable to remove old copy
342N/A fi
342N/A cat << EOF > $1
342N/Ajavax.net.ssl.keyStore=$2
342N/Ajavax.net.ssl.keyStorePassword=password
342N/AEOF
342N/A}
342N/A
342N/A# Check we are run from jtreg
342N/Aif [ -z "${TESTCLASSES}" ]; then
342N/A echo "Test is designed to be run from jtreg only"
342N/A exit 0
342N/Afi
342N/A
342N/A# Test not suitable for Windows as chmod may not be able to
342N/A# security the password file.
342N/A
342N/Aos=`uname -s`
342N/Aif [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
342N/A echo "Test not designed to run on this operating system, skipping..."
342N/A exit 0
342N/Afi
342N/A
342N/A# Create management and SSL configuration files
342N/A
342N/ALIBDIR=${TESTCLASSES}/lib
342N/AMGMT=${LIBDIR}/management.properties
342N/ASSL=${LIBDIR}/jmxremote.ssl.config
342N/Arm -f ${MGMT}
342N/Arm -f ${SSL}
2037N/Amkdir ${LIBDIR} 2>&1
2037N/AcreateJavaFile ${TESTCLASSES} Dummy
342N/AcreateManagementConfigFile ${MGMT} ${SSL}
342N/AcreateSSLConfigFile ${SSL} ${TESTSRC}/ssl/keystore
342N/A
342N/A# Compile test
342N/A
342N/A${TESTJAVA}/bin/javac -d ${TESTCLASSES} ${TESTCLASSES}/Dummy.java
342N/A
342N/AJAVA=${TESTJAVA}/bin/java
342N/ACLASSPATH=${TESTCLASSES}
342N/Aexport CLASSPATH
342N/A
3120N/Afailures=0
3120N/A
3120N/Amp=-Dcom.sun.management.config.file=${MGMT}
3120N/App=-Dcom.sun.management.jmxremote.port=4999
3120N/A
3120N/Ago() {
3120N/A echo ''
3120N/A sh -xc "$JAVA $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
3120N/A if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
3120N/A}
3678N/A
3120N/A# Test 1 - SSL config file is secure - VM should start
3120N/Achmod 700 ${SSL}
3120N/Ash -xc "$JAVA $mp $pp Dummy" 2>&1
3120N/Aif [ $? != 0 ]; then failures=`expr $failures + 1`; fi
3120N/A
3120N/A# Test 2 - SSL config file is not secure - VM should fail to start
3120N/Achmod o+rx ${SSL}
3120N/Ash -xc "$JAVA $mp $pp Dummy" 2>&1
3678N/Aif [ $? = 0 ]; then failures=`expr $failures + 1`; fi
3120N/A
3120N/A# Reset the file permissions on the generated SSL config file
4440N/Achmod 777 ${SSL}
3120N/A
3120N/A#
3120N/A# Results
3120N/A#
3120N/Aecho ''
3678N/Aif [ $failures -gt 0 ];
342N/A then echo "$failures test(s) failed";
342N/A else echo "All test(s) passed"; fi
619N/Aexit $failures
342N/A