APIdia Launch Partner
Top Description Fields Constructors Methods
java.security

public Class CodeSource

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.net.URL, .SocketPermission, java.util.ArrayList, .List, .Hashtable, .Objects, java.io.ByteArrayInputStream, .IOException, java.security.cert.*, sun.net.util.URLUtil, sun.security.util.IOUtils

This class extends the concept of a codebase to encapsulate not only the location (URL) but also the certificate chains that were used to verify signed code originating from that location.

Authors
Li Gong, Roland Schemers
Since
1.2

Field Summary

Modifier and TypeField and Description
private transient Certificate[]
private transient CertificateFactory
private final URL
location

The code location.

private transient String
locationNoFragString

A String form of the URL for use as a key in HashMaps/Sets.

private static final long
private transient CodeSigner[]
private transient SocketPermission
sp

References Deprecated SocketPermission is deprecated or references (maybe indirectly) at least one deprecated element.

Constructor Summary

AccessConstructor and Description
public
CodeSource(URL
the location (URL). It may be null.
url
,
Certificate[]
the certificate(s). It may be null. The contents of the array are copied to protect against subsequent modification.
certs
)

Constructs a CodeSource and associates it with the specified location and set of certificates.

public
CodeSource(URL
the location (URL). It may be null.
url
,
CodeSigner[]
the code signers. It may be null. The contents of the array are copied to protect against subsequent modification.
signers
)

Constructs a CodeSource and associates it with the specified location and set of code signers.

Method Summary

Modifier and TypeMethod and Description
private CodeSigner[]
public boolean

Returns:

true if the objects are considered equal, false otherwise.
equals
(Object
the object to test for equality with this object.
obj
)

Overrides java.lang.Object.equals.

Tests for equality between the specified object and this object.

public final Certificate[]

Returns:

a copy of the certificate array, or null if there is none.
getCertificates
()

Returns the certificates associated with this CodeSource.

public final CodeSigner[]

Returns:

a copy of the code signer array, or null if there is none.
getCodeSigners
()

Returns the code signers associated with this CodeSource.

public final URL

Returns:

the location (URL), or null if no URL was supplied during construction.
getLocation
()

Returns the location associated with this CodeSource.

pack-priv String
getLocationNoFragString()

Returns a String form of the URL for use as a key in HashMaps/Sets.

public int

Returns:

the hash code value for this object
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hash code value for this object.

public boolean

Returns:

true if the specified codesource is implied by this codesource, false if not.
implies
(CodeSource
CodeSource to compare against.
codesource
)

Returns true if this CodeSource object "implies" the specified CodeSource.

pack-priv boolean
matchCerts(CodeSource
the CodeSource to check against.
that
,
boolean
if true then a strict equality match is performed. Otherwise, a subset match is performed.
strict
)

Returns true if all the certs in this CodeSource are also in that.

private boolean
matchLocation(CodeSource
CodeSource to compare against
that
)

Returns true if two CodeSource's have the "same" location.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
ois
)

Restores this object from a stream (i.e., deserializes it).

public String

Returns:

information about this CodeSource.
toString
()

Overrides java.lang.Object.toString.

Returns a string describing this CodeSource, telling its URL and certificates.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
oos
)

Writes this object out to a stream (i.e., serializes it).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

certsback to summary
private transient Certificate[] certs
factoryback to summary
private transient CertificateFactory factory
locationback to summary
private final URL location

The code location.

locationNoFragStringback to summary
private transient String locationNoFragString

A String form of the URL for use as a key in HashMaps/Sets. The String form should behave in the same manner as the URL when compared for equality in a HashMap/Set, except that no nameservice lookup is done on the hostname (only string comparison), and the fragment is not considered.

serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
signersback to summary
private transient CodeSigner[] signers
spback to summary
private transient SocketPermission sp

References Deprecated

SocketPermission is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Annotations
@SuppressWarnings:removal

Constructor Detail

CodeSourceback to summary
public CodeSource(URL url, Certificate[] certs)

Constructs a CodeSource and associates it with the specified location and set of certificates.

Parameters
url:URL

the location (URL). It may be null.

certs:Certificate[]

the certificate(s). It may be null. The contents of the array are copied to protect against subsequent modification.

CodeSourceback to summary
public CodeSource(URL url, CodeSigner[] signers)

Constructs a CodeSource and associates it with the specified location and set of code signers.

Parameters
url:URL

the location (URL). It may be null.

signers:CodeSigner[]

the code signers. It may be null. The contents of the array are copied to protect against subsequent modification.

Since
1.5

Method Detail

convertCertArrayToSignerArrayback to summary
private CodeSigner[] convertCertArrayToSignerArray(Certificate[] certs)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Tests for equality between the specified object and this object. Two CodeSource objects are considered equal if their locations are of identical value and if their signer certificate chains are of identical value. It is not required that the certificate chains be in the same order.

Parameters
obj:Object

the object to test for equality with this object.

Returns:boolean

true if the objects are considered equal, false otherwise.

Annotations
@Override
getCertificatesback to summary
public final Certificate[] getCertificates()

Returns the certificates associated with this CodeSource.

If this CodeSource object was created using the CodeSource(URL url, CodeSigner[] signers) constructor then its certificate chains are extracted and used to create an array of Certificate objects. Each signer certificate is followed by its supporting certificate chain (which may be empty). Each signer certificate and its supporting certificate chain is ordered bottom-to-top (i.e., with the signer certificate first and the (root) certificate authority last).

Returns:Certificate[]

a copy of the certificate array, or null if there is none.

getCodeSignersback to summary
public final CodeSigner[] getCodeSigners()

Returns the code signers associated with this CodeSource.

If this CodeSource object was created using the CodeSource(URL url, java.security.cert.Certificate[] certs) constructor then its certificate chains are extracted and used to create an array of CodeSigner objects. Note that only X.509 certificates are examined - all other certificate types are ignored.

Returns:CodeSigner[]

a copy of the code signer array, or null if there is none.

Since
1.5
getLocationback to summary
public final URL getLocation()

Returns the location associated with this CodeSource.

Returns:URL

the location (URL), or null if no URL was supplied during construction.

getLocationNoFragStringback to summary
pack-priv String getLocationNoFragString()

Returns a String form of the URL for use as a key in HashMaps/Sets.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code value for this object.

Returns:int

the hash code value for this object

Annotations
@Override
impliesback to summary
public boolean implies(CodeSource codesource)

Returns true if this CodeSource object "implies" the specified CodeSource.

More specifically, this method makes the following checks. If any fail, it returns false. If they all succeed, it returns true.

  • codesource must not be null.
  • If this object's certificates are not null, then all of this object's certificates must be present in codesource's certificates.
  • If this object's location (getLocation()) is not null, then the following checks are made against this object's location and codesource's:
    • codesource's location must not be null.
    • If this object's location equals codesource's location, then return true.
    • This object's protocol (getLocation().getProtocol()) must be equal to codesource's protocol, ignoring case.
    • If this object's host (getLocation().getHost()) is not null, then the following checks are made in order:
      • If this object's host was initialized with a single IP address then one of codesource's IP addresses must be equal to this object's IP address.
      • If this object's host is a wildcard domain (such as *.example.com), then codesource's canonical host name (the name without any preceding *) must end with this object's canonical host name. For example, *.example.com implies *.foo.example.com.
      • If this object's host was not initialized with a single IP address, then one of this object's IP addresses must equal one of codesource's IP addresses or this object's canonical host name must equal codesource's canonical host name.
    • If this object's port (getLocation().getPort()) is not equal to -1 (that is, if a port is specified), it must equal codesource's port or default port (codesource.getLocation().getDefaultPort()).
    • If this object's file (getLocation().getFile()) doesn't equal codesource's file, then the following checks are made: If this object's file ends with "/-", then codesource's file must start with this object's file (exclusive the trailing "-"). If this object's file ends with a "/*", then codesource's file must start with this object's file and must not have any further "/" separators. If this object's file doesn't end with a "/", then codesource's file must match this object's file with a '/' appended.
    • If this object's reference (getLocation().getRef()) is not null, it must equal codesource's reference.

For example, the codesource objects with the following locations and null certificates all imply the codesource with the location http://www.example.com/classes/foo.jar and null certificates:

    http:
    http://*.example.com/classes/*
    http://www.example.com/classes/-
    http://www.example.com/classes/foo.jar
Note that if this CodeSource has a null location and a null certificate chain, then it implies every other CodeSource.
Parameters
codesource:CodeSource

CodeSource to compare against.

Returns:boolean

true if the specified codesource is implied by this codesource, false if not.

matchCertsback to summary
pack-priv boolean matchCerts(CodeSource that, boolean strict)

Returns true if all the certs in this CodeSource are also in that.

Parameters
that:CodeSource

the CodeSource to check against.

strict:boolean

if true then a strict equality match is performed. Otherwise, a subset match is performed.

matchLocationback to summary
private boolean matchLocation(CodeSource that)

Returns true if two CodeSource's have the "same" location.

Parameters
that:CodeSource

CodeSource to compare against

Annotations
@SuppressWarnings:removal
readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException

Restores this object from a stream (i.e., deserializes it).

Parameters
ois:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string describing this CodeSource, telling its URL and certificates.

Returns:String

information about this CodeSource.

Annotations
@Override
writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Writes this object out to a stream (i.e., serializes it).

Parameters
oos:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
Serial data
An initial URL is followed by an int indicating the number of certificates to follow (a value of "zero" denotes that there are no certificates associated with this object). Each certificate is written out starting with a String denoting the certificate type, followed by an int specifying the length of the certificate encoding, followed by the certificate encoding itself which is written out as an array of bytes. Finally, if any code signers are present then the array of code signers is serialized and written out too.