home *** CD-ROM | disk | FTP | other *** search
- package java.security;
-
- import java.io.BufferedInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Enumeration;
- import java.util.Properties;
- import java.util.Vector;
-
- public final class Security {
- static boolean debug;
- static boolean error = true;
- private static Properties props;
- private static Properties propCache;
- private static Vector providers;
-
- private static void initialize() {
- props = new Properties();
- propCache = new Properties();
- providers = new Vector();
- File var0 = securityPropFile("java.security");
- if (!var0.exists()) {
- System.err.println("security properties not found. using defaults.");
- initializeStatic();
- } else {
- try {
- FileInputStream var1 = new FileInputStream(var0);
- BufferedInputStream var2 = new BufferedInputStream(var1);
- props.load(var2);
- ((InputStream)var2).close();
- } catch (IOException var3) {
- error("could not load security properties file from " + var0 + ". using defaults.");
- initializeStatic();
- }
- }
-
- loadProviders();
- }
-
- private static void initializeStatic() {
- props.put("security.provider.1", "sun.security.provider.Sun");
- props.put("system.scope", "sun.security.provider.IdentityDatabase");
- }
-
- private Security() {
- }
-
- private static void loadProviders() {
- int var0 = 1;
-
- while(true) {
- String var1 = props.getProperty("security.provider." + var0++);
- if (var1 == null) {
- return;
- }
-
- Provider var2 = Provider.loadProvider(var1);
- if (var2 != null) {
- providers.addElement(var2);
- }
- }
- }
-
- static File securityPropFile(String var0) {
- String var1 = File.separator;
- return new File(System.getProperty("java.home") + var1 + "lib" + var1 + "security" + var1 + var0);
- }
-
- static String getProviderProperty(String var0) {
- String var1 = propCache.getProperty(var0);
- if (var1 != null) {
- return var1;
- } else {
- for(int var2 = 0; var2 < providers.size(); ++var2) {
- Provider var3 = (Provider)providers.elementAt(var2);
- var1 = ((Properties)var3).getProperty(var0);
- if (var1 != null) {
- propCache.put(var0, var1);
- return var1;
- }
- }
-
- return var1;
- }
- }
-
- static String getStandardName(String var0, String var1) {
- return getProviderProperty("Alg.Alias." + var1 + "." + var0);
- }
-
- public static String getAlgorithmProperty(String var0, String var1) {
- return getProviderProperty("Alg." + var1 + "." + var0);
- }
-
- static String getPublicKeyClassName(String var0, String var1) {
- String var2 = getStandardName(var0, "Key");
- if (var2 == null) {
- var2 = var0;
- }
-
- String var3 = "PublicKey." + var1 + "." + var2;
- return getProviderProperty(var3);
- }
-
- static String getPrivateKeyClassName(String var0, String var1) {
- String var2 = getStandardName(var0, "Key");
- if (var2 == null) {
- var2 = var0;
- }
-
- return getProviderProperty("PrivateKey." + var1 + "." + var2);
- }
-
- static String getEngineClassName(String var0, String var1) throws NoSuchAlgorithmException {
- String var2 = getStandardName(var0, var1);
- if (var2 == null) {
- var2 = var0;
- }
-
- providers.elements();
- String var3 = getProviderProperty(var1 + "." + var2);
- if (var3 != null) {
- return var3;
- } else {
- throw new NoSuchAlgorithmException("algorithm " + var0 + " not available.");
- }
- }
-
- private static String getEngineClassName(String var0, String var1, String var2) throws NoSuchAlgorithmException, NoSuchProviderException {
- if (var1 == null) {
- return getEngineClassName(var0, var2);
- } else {
- String var3 = getStandardName(var0, var2);
- if (var3 == null) {
- var3 = var0;
- }
-
- Provider var4 = getProvider(var1);
- if (var4 == null) {
- throw new NoSuchProviderException("no such provider: " + var1);
- } else {
- String var5 = ((Properties)var4).getProperty(var2 + "." + var3);
- if (var5 == null) {
- throw new NoSuchAlgorithmException("no such algorithm: " + var0 + " for provider " + var1);
- } else {
- return var5;
- }
- }
- }
- }
-
- public static int insertProviderAt(Provider var0, int var1) {
- check();
- Provider var2 = getProvider(var0.getName());
- if (var2 != null) {
- return -1;
- } else {
- --var1;
- if (var1 < 0) {
- var1 = 0;
- }
-
- int var3 = providers.size();
- if (var1 > var3) {
- var1 = var3;
- }
-
- providers.insertElementAt(var0, var1);
- propCache = new Properties();
- return var1;
- }
- }
-
- public static int addProvider(Provider var0) {
- return insertProviderAt(var0, providers.size() + 1);
- }
-
- public static void removeProvider(String var0) {
- check();
- Provider var1 = getProvider(var0);
- if (var1 != null) {
- providers.removeElement(var1);
- }
-
- }
-
- public static Provider[] getProviders() {
- check();
- Provider[] var0 = new Provider[providers.size()];
- providers.copyInto(var0);
- return var0;
- }
-
- public static Provider getProvider(String var0) {
- check();
- Enumeration var1 = providers.elements();
-
- while(var1.hasMoreElements()) {
- Provider var2 = (Provider)var1.nextElement();
- if (var2.getName().equals(var0)) {
- return var2;
- }
- }
-
- return null;
- }
-
- private static boolean checkSuperclass(Class var0, Class var1) {
- while(!var0.equals(var1)) {
- var0 = var0.getSuperclass();
- if (var0 == null) {
- return false;
- }
- }
-
- return true;
- }
-
- static Object getImpl(String var0, String var1, String var2) throws NoSuchAlgorithmException, NoSuchProviderException {
- String var3 = getEngineClassName(var0, var2, var1);
-
- try {
- Class var4 = Class.forName("java.security." + var1);
- Class var5 = Class.forName(var3);
- if (checkSuperclass(var5, var4)) {
- return var5.newInstance();
- } else {
- throw new NoSuchAlgorithmException("class configured for " + var1 + ": " + var3 + " not a " + var1);
- }
- } catch (ClassNotFoundException var6) {
- throw new NoSuchAlgorithmException("class configured for " + var1 + "(provider: " + var2 + ")" + "cannot be found.\n" + ((Throwable)var6).getMessage());
- } catch (InstantiationException var7) {
- throw new NoSuchAlgorithmException("class " + var3 + " configured for " + var1 + "(provider: " + var2 + ") cannot be instantiated.\n" + ((Throwable)var7).getMessage());
- } catch (IllegalAccessException var8) {
- throw new NoSuchAlgorithmException("class " + var3 + " configured for " + var1 + "(provider: " + var2 + ") cannot be accessed.\n" + ((Throwable)var8).getMessage());
- }
- }
-
- public static String getProperty(String var0) {
- check();
- return props.getProperty(var0);
- }
-
- public static void setProperty(String var0, String var1) {
- check();
- props.put(var0, var1);
- }
-
- private static void check() {
- SecurityManager var0 = System.getSecurityManager();
- if (var0 != null) {
- var0.checkSecurityAccess("java");
- }
-
- }
-
- static void error(String var0) {
- if (debug) {
- System.err.println(var0);
- }
-
- }
-
- static void error(String var0, Throwable var1) {
- error(var0);
- if (debug) {
- var1.printStackTrace();
- }
-
- }
-
- static void debug(String var0) {
- if (debug) {
- System.err.println(var0);
- }
-
- }
-
- static void debug(String var0, Throwable var1) {
- if (debug) {
- var1.printStackTrace();
- System.err.println(var0);
- }
-
- }
-
- static {
- initialize();
- }
- }
-