29 |
|
private final char[] KEYSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); |
30 |
|
|
31 |
|
/** |
32 |
< |
* The length of our keys |
32 |
> |
* Default key length |
33 |
|
*/ |
34 |
< |
public static final int KEYLEN = 15; |
34 |
> |
public static final int DEFKEYLEN = 15; |
35 |
|
|
36 |
|
//---STATIC METHODS--- |
37 |
|
|
52 |
|
* Private constructor to avoid external construction. |
53 |
|
*/ |
54 |
|
private KeyManager() { |
55 |
< |
// do nothing |
55 |
> |
try { |
56 |
> |
String keylen = ConfigurationProxy.getInstance().getProperty("Filter." + FilterMain.NAME, "Filter.KeyLength"); |
57 |
> |
_keylen = Integer.parseInt(keylen); |
58 |
> |
} |
59 |
> |
catch (PropertyNotFoundException e) { |
60 |
> |
_keylen = DEFKEYLEN; |
61 |
> |
_logger.write(toString(), Logger.WARNING, "No key length found, using default of " +_keylen+ " : " + e); |
62 |
> |
} |
63 |
> |
catch (NumberFormatException e) { |
64 |
> |
_keylen = DEFKEYLEN; |
65 |
> |
_logger.write(toString(), Logger.WARNING, "Malformed key length found, using default of " +_keylen+ " : " + e); |
66 |
> |
} |
67 |
|
} |
68 |
|
|
69 |
|
//---PUBLIC METHODS--- |
127 |
|
public String genKey() { |
128 |
|
Random r = new Random(); |
129 |
|
StringBuffer s = new StringBuffer(); |
130 |
< |
for(int i=0; i < KEYLEN; i++) { |
130 |
> |
for(int i=0; i < _keylen; i++) { |
131 |
|
s.append(KEYSET[r.nextInt(KEYSET.length)]); |
132 |
|
} |
133 |
|
return s.toString(); |
160 |
|
* the hosts we're authenticating |
161 |
|
*/ |
162 |
|
private HashMap _keys = new HashMap(); |
163 |
+ |
|
164 |
+ |
/** |
165 |
+ |
* The length of our keys |
166 |
+ |
*/ |
167 |
+ |
private int _keylen; |
168 |
|
|
169 |
|
/** |
170 |
|
* This holds a reference to the |