Problems using HTTPS protocol in Java (JSSE)

Status
Not open for further replies.

sorghumking

Ars Scholae Palatinae
989
I believe I've performed the JSSE installation process correctly, but I'm still unable to run even the simplest of programs, e.g. one of the API's sample applications:

code:<HR>
Code:
import java.net.*;
import java.io.*;<P>public class URLReader {
    public static void main(String[] args) throws Exception {
	System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
	URL verisign = new URL("https://www.verisign.com/");
	BufferedReader in = new BufferedReader(
				new InputStreamReader(
				verisign.openStream()));<P>		String inputLine;<P>		while ((inputLine = in.readLine()) != null)
			System.out.println(inputLine);<P>		in.close();
    }
}

The code above compiles, but I get a MalformedURLException - "unknown protocol: https" - at runtime. Any ideas as to what I'm doing wrong?

By the way, I'm registering the SunJSSE provider statically, i.e. in my java.security file, so the lack of a call to Security.addProvider(...) shouldn't be the problem.
 

sorghumking

Ars Scholae Palatinae
989
My java.policy file is below. I haven't made any changes to it since installing the JDK (v1.3), though.

code:<HR>
Code:
// Standard extensions get all permissions by default<P>grant codeBase "file:${java.home}/lib/ext/*" {
	permission java.security.AllPermission;
};<P>// default permissions granted to all domains<P>grant { 
	// Allows any thread to stop itself using the java.lang.Thread.stop()
	// method that takes no argument.
	// Note that this permission is granted by default only to remain
	// backwards compatible.
	// It is strongly recommended that you either remove this permission
	// from this policy file or further restrict it to code sources
	// that you specify, because Thread.stop() is potentially unsafe.
	// See "http://java.sun.com/notes" for more information.
	permission java.lang.RuntimePermission "stopThread";<P>	// allows anyone to listen on un-privileged ports
	permission java.net.SocketPermission "localhost:1024-", "listen";<P>	// "standard" properies that can be read by anyone<P>	permission java.util.PropertyPermission "java.version", "read";
	permission java.util.PropertyPermission "java.vendor", "read";
	permission java.util.PropertyPermission "java.vendor.url", "read";
	permission java.util.PropertyPermission "java.class.version", "read";
	permission java.util.PropertyPermission "os.name", "read";
	permission java.util.PropertyPermission "os.version", "read";
	permission java.util.PropertyPermission "os.arch", "read";
	permission java.util.PropertyPermission "file.separator", "read";
	permission java.util.PropertyPermission "path.separator", "read";
	permission java.util.PropertyPermission "line.separator", "read";<P>	permission java.util.PropertyPermission "java.specification.version", "read";
	permission java.util.PropertyPermission "java.specification.vendor", "read";
	permission java.util.PropertyPermission "java.specification.name", "read";<P>	permission java.util.PropertyPermission "java.vm.specification.version", "read";
	permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
	permission java.util.PropertyPermission "java.vm.specification.name", "read";
	permission java.util.PropertyPermission "java.vm.version", "read";
	permission java.util.PropertyPermission "java.vm.vendor", "read";
	permission java.util.PropertyPermission "java.vm.name", "read";
};

I did make changes to the java.security file, though, as described in the installation instructions for JSSE. It looks like this (I removed a few of the longer comments for the sake of pseudo-brevity - hehe):

code:<HR>
Code:
#
# List of providers and their preference orders (see above):
#
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.net.ssl.internal.ssl.Provider
security.provider.3=com.sun.rsajca.Provider<P>
#
# Class to instantiate as the system Policy. This is the name of the class
# that will be used as the Policy object.
#
policy.provider=sun.security.provider.PolicyFile<P># The default is to have a single system-wide policy file, 
# and a policy file in the user's home directory.
policy.url.1=file:${java.home}/lib/security/java.policy
policy.url.2=file:${user.home}/.java.policy<P># whether or not we expand properties in the policy file
# if this is set to false, properties (${...}) will not be expanded in policy
# files.
policy.expandProperties=true<P># whether or not we allow an extra policy to be passed on the command line
# with -Djava.security.policy=somefile. Comment out this line to disable
# this feature.
policy.allowSystemProperty=true<P># whether or not we look into the IdentityScope for trusted Identities
# when encountering a 1.1 signed JAR file. If the identity is found
# and is trusted, we grant it AllPermission.
policy.ignoreIdentityScope=false<P>#
# Default keystore type.
#
keystore.type=jks<P>#
# Class to instantiate as the system scope:
#
system.scope=sun.security.provider.IdentityDatabase<P>#
# List of comma-separated packages that start with or equal this string
# will cause a security exception to be thrown when
# passed to checkPackageAccess unless the
# corresponding RuntimePermission ("accessClassInPackage."+package) has
# been granted.
package.access=sun.<P>#
# List of comma-separated packages that start with or equal this string
# will cause a security exception to be thrown when
# passed to checkPackageDefinition unless the
# corresponding RuntimePermission ("defineClassInPackage."+package) has
# been granted.
# 
# by default, no packages are restricted for definition, and none of
# the class loaders supplied with the JDK call checkPackageDefinition.
#
#package.definition=

The exception being thrown ("MalformedURLException: unknown protocol: https") suggests to me that the problem has something to do with the protocol handler (theoretically being added in System.setProperty(...)). At this point I might just break down and install JDK1.4 (currently in beta), which includes all of the JSSE crap.

Whaddya think, Sauron?
 
Status
Not open for further replies.