home *** CD-ROM | disk | FTP | other *** search
Wrap
package sun.security.provider; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InvalidClassException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.io.StreamCorruptedException; import java.security.Identity; import java.security.IdentityScope; import java.security.InvalidParameterException; import java.security.Key; import java.security.KeyManagementException; import java.security.MessageDigest; import java.security.PublicKey; import java.security.Security; import java.security.Signer; import java.util.Enumeration; import java.util.Hashtable; public class IdentityDatabase extends IdentityScope implements Serializable { private static boolean debug; private static boolean error = true; File sourceFile; Hashtable identities; IdentityDatabase() throws InvalidParameterException { this("restoring..."); } public IdentityDatabase(File var1) throws InvalidParameterException { this(var1.getName()); this.sourceFile = var1; } public IdentityDatabase(String var1) throws InvalidParameterException { super(var1); this.identities = new Hashtable(); } public static IdentityDatabase fromStream(InputStream var0) throws IOException { IdentityDatabase var1 = null; try { ObjectInputStream var2 = new ObjectInputStream(var0); var1 = (IdentityDatabase)var2.readObject(); } catch (ClassNotFoundException var3) { debug("This should not be happening.", var3); error("The version of the database is obsolete. Cannot initialize."); } catch (InvalidClassException var4) { debug("This should not be happening.", var4); error("Unable to initialize system identity scope: InvalidClassException. \nThis is most likely due to a serialization versioning problem: a class used in key management was obsoleted"); } catch (StreamCorruptedException var5) { debug("The serialization stream is corrupted. Unable to load.", var5); error("Unable to initialize system identity scope. StreamCorrputedException."); } if (var1 == null) { var1 = new IdentityDatabase("uninitialized"); } return var1; } public static IdentityDatabase fromFile(File var0) throws IOException { FileInputStream var1 = new FileInputStream(var0); IdentityDatabase var2 = fromStream(var1); var2.sourceFile = var0; return var2; } public int size() { return this.identities.size(); } public Identity getIdentity(String var1) { Identity var2 = (Identity)this.identities.get(var1); if (var2 instanceof Signer) { this.localCheck("get.signer"); } return var2; } public Identity getIdentity(PublicKey var1) { if (var1 == null) { return null; } else { Enumeration var2 = this.identities(); while(var2.hasMoreElements()) { Identity var3 = (Identity)var2.nextElement(); PublicKey var4 = var3.getPublicKey(); if (var4 != null && this.keyEqual(var4, var1)) { if (var3 instanceof Signer) { this.localCheck("get.signer"); } return var3; } } return null; } } private boolean keyEqual(Key var1, Key var2) { return var1 == var2 ? true : MessageDigest.isEqual(var1.getEncoded(), var2.getEncoded()); } public void addIdentity(Identity var1) throws KeyManagementException { this.localCheck("add.identity"); Identity var2 = this.getIdentity(var1.getName()); Identity var3 = this.getIdentity(var1.getPublicKey()); String var4 = null; if (var2 != null) { var4 = "name conflict"; } if (var3 != null) { var4 = "key conflict"; } if (var4 != null) { throw new KeyManagementException(var4); } else { this.identities.put(var1.getName(), var1); } } public void removeIdentity(Identity var1) throws KeyManagementException { this.localCheck("remove.identity"); String var2 = var1.getName(); if (this.identities.get(var2) == null) { throw new KeyManagementException("there is no identity named " + var2 + " in " + this); } else { this.identities.remove(var2); } } public Enumeration identities() { return this.identities.elements(); } void setSourceFile(File var1) { this.sourceFile = var1; } File getSourceFile() { return this.sourceFile; } public void save(OutputStream var1) throws IOException { try { ObjectOutputStream var2 = new ObjectOutputStream(var1); var2.writeObject(this); var2.flush(); } catch (InvalidClassException var3) { debug("This should not be happening.", var3); } } void save(File var1) throws IOException { this.setSourceFile(var1); FileOutputStream var2 = new FileOutputStream(var1); this.save((OutputStream)var2); } public void save() throws IOException { if (this.sourceFile == null) { throw new IOException("this database has no source file"); } else { this.save(this.sourceFile); } } private static File systemDatabaseFile() { String var0 = Security.getProperty("identity.database"); if (var0 == null) { var0 = System.getProperty("user.home") + File.separatorChar + "identitydb.obj"; } return new File(var0); } private static void initializeSystem() { File var1 = systemDatabaseFile(); try { IdentityDatabase var0; if (var1.exists()) { debug("loading system database from file: " + var1); var0 = fromFile(var1); } else { var0 = new IdentityDatabase(var1); } IdentityScope.setSystemScope(var0); debug("System database initialized: " + var0); } catch (IOException var3) { debug("Error initializing identity database: " + var1, var3); } catch (InvalidParameterException var4) { debug("Error trying to instantiate a system identities db in " + var1, var4); } } private static File securityPropFile(String var0) { String var1 = File.separator; return new File(System.getProperty("java.home") + var1 + "lib" + var1 + "security" + var1 + var0); } public String toString() { return "sun.security.IdentityDatabase, source file: " + this.sourceFile; } private static void debug(String var0) { if (debug) { System.err.println(var0); } } private static void debug(String var0, Throwable var1) { if (debug) { var1.printStackTrace(); System.err.println(var0); } } private static void error(String var0) { if (error) { System.err.println(var0); } } void localCheck(String var1) { SecurityManager var2 = System.getSecurityManager(); if (var2 != null) { var1 = this.getClass().getName() + "." + var1 + "." + this.localFullName(); var2.checkSecurityAccess(var1); } } String localFullName() { String var1 = ((Identity)this).getName(); if (((Identity)this).getScope() != null) { var1 = var1 + "." + ((Identity)this).getScope().getName(); } return var1; } private synchronized void writeObject(ObjectOutputStream var1) throws IOException { this.localCheck("serialize.identity.database"); var1.writeObject(this.identities); var1.writeObject(this.sourceFile); } static { initializeSystem(); } }