Methods Summary |
---|
public void | addCertificate(java.security.Certificate certificate)Adds a {@code Certificate} to this {@code Identity}.
If a {@code SecurityManager} is installed, code calling this method needs
the {@code SecurityPermission} {@code addIdentityCertificate} to be
granted, otherwise a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkSecurityAccess("addIdentityCertificate"); //$NON-NLS-1$
}
PublicKey certPK = certificate.getPublicKey();
if (publicKey != null) {
if (!checkKeysEqual(publicKey, certPK)) {
throw new KeyManagementException(Messages.getString("security.13")); //$NON-NLS-1$
}
} else {
publicKey = certPK;
}
if (certificates == null) {
certificates = new Vector<Certificate>();
}
certificates.add(certificate);
|
public java.security.Certificate[] | certificates()Returns the certificates for this {@code Identity}. External
modifications of the returned array has no impact on this {@code
Identity}.
if (certificates == null) {
return new Certificate[0];
}
Certificate[] ret = new Certificate[certificates.size()];
certificates.copyInto(ret);
return ret;
|
private static boolean | checkKeysEqual(java.security.PublicKey pk1, java.security.PublicKey pk2)
// first, they should have the same format
// second, their encoded form must be the same
// assert(pk1 != null);
// assert(pk2 != null);
String format1 = pk1.getFormat();
String format2;
if ((pk2 == null)
|| (((format2 = pk2.getFormat()) != null) ^ (format1 != null))
|| ((format1 != null) && !format1.equals(format2))) {
return false;
}
return Arrays.equals(pk1.getEncoded(), pk2.getEncoded());
|
public final boolean | equals(java.lang.Object obj)Compares the specified object with this {@code Identity} for equality and
returns {@code true} if the specified object is equal, {@code false}
otherwise. {@code Identity} objects are considered equal, if they have
the same name and are in the same scope.
if (this == obj) {
return true;
}
if (!(obj instanceof Identity)) {
return false;
}
Identity i = (Identity) obj;
if ((name == i.name || (name != null && name.equals(i.name)))
&& (scope == i.scope || (scope != null && scope.equals(i.scope)))) {
return true;
}
return identityEquals(i);
|
public java.lang.String | getInfo()Returns the information string of this {@code Identity}.
return info;
|
public final java.lang.String | getName()Returns the name of this {@code Identity}.
return name;
|
public java.security.PublicKey | getPublicKey()Returns the {@code PublicKey} associated with this {@code Identity}.
return publicKey;
|
public final java.security.IdentityScope | getScope()Returns the {@code IdentityScope} of this {@code Identity}.
return scope;
|
public int | hashCode()Returns the hash code value for this {@code Identity}. Returns the same
hash code for {@code Identity}s that are equal to each other as required
by the general contract of {@link Object#hashCode}.
int hash = 0;
if (name != null) {
hash += name.hashCode();
}
if (scope != null) {
hash += scope.hashCode();
}
return hash;
|
protected boolean | identityEquals(java.security.Identity identity)Compares the specified {@code Identity} with this {@code Identity} for
equality and returns {@code true} if the specified object is equal,
{@code false} otherwise.
To be equal, two {@code Identity} objects need to have the same name and
the same public keys.
if (!name.equals(identity.name)) {
return false;
}
if (publicKey == null) {
return (identity.publicKey == null);
}
return checkKeysEqual(publicKey, identity.publicKey);
|
public void | removeCertificate(java.security.Certificate certificate)Removes the specified {@code Certificate} from this {@code Identity}.
If a {@code SecurityManager} is installed, code calling this method needs
the {@code SecurityPermission} {@code "removeIdentityCertificate"} to be
granted, otherwise a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkSecurityAccess("removeIdentityCertificate"); //$NON-NLS-1$
}
if (certificates != null) {
// BEGIN android-added
if (!certificates.contains(certificate)) {
throw new KeyManagementException("Certificate not found");
}
// END android-added
certificates.removeElement(certificate);
}
|
public void | setInfo(java.lang.String info)Sets an information string for this {@code Identity}.
If a {@code SecurityManager} is installed, code calling this method needs
the {@code SecurityPermission} {@code setIdentityInfo} to be granted,
otherwise a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkSecurityAccess("setIdentityInfo"); //$NON-NLS-1$
}
this.info = info;
|
public void | setPublicKey(java.security.PublicKey key)Sets the specified {@code PublicKey} to this {@code Identity}.
If a {@code SecurityManager} is installed, code calling this method needs
the {@code SecurityPermission} {@code setIdentityPublicKey} to be
granted, otherwise a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkSecurityAccess("setIdentityPublicKey"); //$NON-NLS-1$
}
// this check does not always work
if ((scope != null) && (key != null)) {
Identity i = scope.getIdentity(key);
//System.out.println("###DEBUG## Identity: "+i);
if ((i != null) && (i != this)) {
throw new KeyManagementException(Messages.getString("security.14")); //$NON-NLS-1$
}
}
this.publicKey = key;
certificates = null;
|
public java.lang.String | toString()Returns a string containing a concise, human-readable description of the
this {@code Identity} including its name and its scope.
If a {@code SecurityManager} is installed, code calling this method
needs the {@code SecurityPermission} {@code printIdentity} to be granted,
otherwise a {@code SecurityException} will be thrown.
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkSecurityAccess("printIdentity"); //$NON-NLS-1$
}
String s = (this.name == null? "" : this.name);
if (scope != null) {
s += " [" + scope.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
}
return s;
|
public java.lang.String | toString(boolean detailed)Returns a string containing a concise, human-readable description of the
this {@code Identity}.
String s = toString();
if (detailed) {
s += " " + info; //$NON-NLS-1$
}
return s;
|