Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r3080 - in trunk/geant2_java-sshtelnet-mp: ant conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters

Subject: perfsonar development work

List archive

perfsonar: r3080 - in trunk/geant2_java-sshtelnet-mp: ant conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r3080 - in trunk/geant2_java-sshtelnet-mp: ant conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters
  • Date: Fri, 30 Nov 2007 09:57:00 -0500

Author: melis
Date: 2007-11-30 09:56:59 -0500 (Fri, 30 Nov 2007)
New Revision: 3080

Modified:
trunk/geant2_java-sshtelnet-mp/ant/configure-targets.xml

trunk/geant2_java-sshtelnet-mp/conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.class

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
Log:
changed password encryption implementation
uses wssj4 Base64 class instead of the other one I found on the internet

Modified: trunk/geant2_java-sshtelnet-mp/ant/configure-targets.xml
===================================================================
--- trunk/geant2_java-sshtelnet-mp/ant/configure-targets.xml 2007-11-29
10:24:45 UTC (rev 3079)
+++ trunk/geant2_java-sshtelnet-mp/ant/configure-targets.xml 2007-11-30
14:56:59 UTC (rev 3080)
@@ -64,6 +64,12 @@
<fileset dir="./build">
<include name="*.jar"/>
</fileset>
+ <fileset
dir="./lib/repository/commons-logging/commons-logging/1.0.4">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset
dir="./lib/repository/wss4j/wss4j/1.5.1">
+ <include name="*.jar"/>
+ </fileset>
</classpath>
<arg value="../conf/service.properties"/>
</java>

Modified:
trunk/geant2_java-sshtelnet-mp/conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.class
===================================================================
(Binary files differ)

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
2007-11-29 10:24:45 UTC (rev 3079)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
2007-11-30 14:56:59 UTC (rev 3080)
@@ -19,6 +19,8 @@
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

+import org.apache.ws.security.util.Base64;
+
public class PasswordEncryptor {

public static String encryptPassword (String pass) {
@@ -52,19 +54,8 @@

ciphertext = desCipher.doFinal(cleartext);

- //System.out.println("encrypted text: " + new
String(ciphertext));
+ return Base64.encode(ciphertext);

- //System.out.println("ciphertext.length: " +
ciphertext.length);
-
- //for (int i = 0; i < ciphertext.length; i++)
- // System.out.println("ciphertext[" + i + "]: "
+ (char) ciphertext[i] + " (numeriek: "+ ciphertext[i] + ")");
-
- //System.out.println("file encoding: " +
System.getProperty("file.encoding"));
-
- //result = new String (ciphertext);
-
- return encodeBase64(ciphertext);
-
//System.out.println("result.length()" +
result.length());
} catch (InvalidKeyException e) {
e.printStackTrace();
@@ -108,7 +99,7 @@
desCipher.init(Cipher.DECRYPT_MODE, desKey);

//byte[] encrypted = pass.getBytes("ISO-8859-1");
- byte[] encrypted = decodeBase64(pass);
+ byte[] encrypted = Base64.decode(pass);

//System.out.println("lengte van het te decrypteren
gedoe: " + encrypted.length);
//for (int i = 0; i < encrypted.length; i++)
@@ -137,132 +128,6 @@
return result;
}

- /**
- * Decodes BASE64 encoded string.
- * @param encoded BASE64 string to decode
- * @return decoded data
- */
- public static byte[] decodeBase64(String encoded) {
- int i;
- byte output[] = new byte[3];
- int state;
- final String ILLEGAL_STRING = "Illegal BASE64 string";
-
- ByteArrayOutputStream data = new
ByteArrayOutputStream(encoded.length());
-
- state = 1;
- for(i=0; i < encoded.length(); i++) {
- byte c;
- {
- char alpha = encoded.charAt(i);
- if (Character.isWhitespace(alpha)) continue;
-
- if ((alpha >= 'A') && (alpha <= 'Z')) c =
(byte)(alpha - 'A');
- else if ((alpha >= 'a') && (alpha <= 'z')) c
= (byte)(26 + (alpha - 'a'));
- else if ((alpha >= '0') && (alpha <= '9')) c
= (byte)(52 + (alpha - '0'));
- else if (alpha=='+') c = 62;
- else if (alpha=='/') c = 63;
- else if (alpha=='=') break; // end
- else throw new
IllegalArgumentException(ILLEGAL_STRING); // error
- }
-
- switch(state) {
- case 1: output[0] = (byte)(c << 2);
- break;
- case 2: output[0] |= (byte)(c >>> 4);
- output[1] = (byte)((c & 0x0F) << 4);
- break;
- case 3: output[1] |= (byte)(c >>> 2);
- output[2] = (byte)((c & 0x03) << 6);
- break;
- case 4: output[2] |= c;
- data.write(output,0,output.length);
- break;
- }
- state = (state < 4 ? state+1 : 1);
- } // for
-
- if (i < encoded.length()) /* then '=' found, but the end of
string */
- switch(state) {
- case 3: data.write(output,0,1);
- if ((encoded.charAt(i)=='=') &&
(encoded.charAt(i+1)=='='))
- return data.toByteArray();
- else throw new
IllegalArgumentException(ILLEGAL_STRING);
-
- case 4:
- data.write(output,0,2);
- if (encoded.charAt(i)=='=') return
data.toByteArray();
- else throw new
IllegalArgumentException(ILLEGAL_STRING);
-
- default:
- throw new
IllegalArgumentException(ILLEGAL_STRING);
- }
- else { // end of string
- if (state==1) return data.toByteArray();
- else throw new
IllegalArgumentException(ILLEGAL_STRING);
- //return data.toByteArray();
- }
-
- } // decode
-
- private final static String BASE64 =
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
- /**
- * Encodes binary data by BASE64 method.
- * @param data binary data to encode
- * @return BASE64 encoded data
- */
- public static String encodeBase64(byte[] data) {
-
- char output[] = new char[4];
- int state = 1;
- int restbits = 0;
- int chunks = 0;
-
- StringBuffer encoded = new StringBuffer();
-
- for(int i=0; i < data.length; i++) {
-
- int ic = (data[i] >= 0 ? data[i] : (data[i] & 0x7F) +
128);
- switch (state)
- { case 1: output[0] = BASE64.charAt(ic >>> 2);
- restbits = ic & 0x03;
- break;
- case 2: output[1] = BASE64.charAt((restbits << 4) |
(ic >>> 4));
- restbits = ic & 0x0F;
- break;
- case 3: output[2] = BASE64.charAt((restbits << 2) |
(ic >>> 6));
- output[3] = BASE64.charAt(ic & 0x3F);
- encoded.append(output);
-
- // keep no more then 76 character per line
- chunks++;
- if ((chunks % 19)==0) encoded.append("\r\n");
- break;
- }
- state = (state < 3 ? state+1 : 1);
- } // for
-
- /* finalize */
- switch (state)
- { case 2:
- output[1] = BASE64.charAt((restbits << 4));
- output[2] = output[3] = '=';
- encoded.append(output);
- break;
- case 3:
- output[2] = BASE64.charAt((restbits << 2));
- output[3] = '=';
- encoded.append(output);
- break;
- }
-
- return encoded.toString();
- } // encode()
-
-
-
public static void main (String[] args) {
Properties pr = new Properties();
String encrypted = encryptPassword("thisisasmalltest");

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2007-11-29 10:24:45 UTC (rev 3079)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2007-11-30 14:56:59 UTC (rev 3080)
@@ -56,7 +56,7 @@

File outpFile = new File (outputFile);

- System.out.println("outputFile object created");
+ //System.out.println("outputFile object created");

if (outpFile.exists()) {
System.out.println("Loading existing
properties...");
@@ -90,32 +90,7 @@
System.out
.println("Please enter the path to this
configuration file");
String file = br.readLine();
- /*BufferedReader previousIn = null;
- previousIn = new BufferedReader(new
FileReader(file));
- String line = "";
- line = previousIn.readLine();
- while (line != null) {
- if ((line.startsWith("service.mp")
- &&
!line.startsWith("service.mp.message_types")
- &&
!line.startsWith("service.mp.class_name"))
- ||
line.startsWith("service.r.mp")){
-
if(line.startsWith("service.mp.devices")){
-
previousDevices=line.substring(line.indexOf("=")+1);
- out.write((line +
"\n").getBytes());
- }else
if(line.contains("commands=")){
-
previousCommands.add(line);
- out.write((line +
"\n").getBytes());
- }else{
-
System.out.println(line);
- out.write((line +
"\n").getBytes());
- }
- }
- line = previousIn.readLine();
- }
-
-
- out.close();*/
-
+
prop.load(new FileInputStream(new
File(file)));

} else { // answer == no
@@ -145,8 +120,7 @@
}

prop.store(new FileOutputStream(outputFile),
"Service.properties");
- //prop.store(System.out, "Service.properties");
-
+
} catch (IOException e) {
e.printStackTrace();
}
@@ -154,10 +128,6 @@

private void parseCSVFile(String file, String outputFile) {
try {
- //BufferedWriter out = null;
- //out = new BufferedWriter(new FileWriter(outputFile,
true));
- //FileOutputStream out = new
FileOutputStream(outputFile, true);
-
// Read all lines from txt file
lines = readLinesFromFile(file);

@@ -169,8 +139,6 @@
String deviceType;
String[] devicesArray = new String[lines.length];
for (int i=0; i<lines.length && lines[i] != null;
i++){
- //System.out.println(" Writing: Line
"+(i+1)+": "+lines[i]);
- //out.write("Line "+(i+1)+":
"+lines[i]+"\n");
tok = new StringTokenizer(lines[i],"%%%");

// First the device info
@@ -275,14 +243,12 @@
addSelectedCommandsToConfig(device,
outputFile, tempFile.toString());
}

- //out.write("service.mp.devices=".getBytes());
String tmp = "";
for (int i=0; i<devicesArray.length &&
devicesArray[i] != null ; i++){
tmp += devicesArray[i]+",";
}
- //out.write((tmp.substring(0,tmp.length()-1));
prop.setProperty("service.mp.devices",
tmp.substring(0, tmp.length()-1));
- //out.close();
+
} catch (IOException e) {
e.printStackTrace();
}
@@ -315,10 +281,6 @@
BufferedReader br = new BufferedReader(new
InputStreamReader(
System.in));

- //BufferedWriter out = null;
- //out = new BufferedWriter(new FileWriter(outputFile,
true));
- //FileOutputStream out = new
FileOutputStream(outputFile, true);
-
List devices = new ArrayList();

List types = new ArrayList();
@@ -326,8 +288,6 @@

// service.properties (also in String format)

- //List allCommands = new ArrayList();
-
System.out.println("First the names of the devices
that have to be supported will " +
"be asked.\nHere you can specify
anything you like, but mostly this is the " +
"URL or\nthe hostname of the machine.");
@@ -448,7 +408,7 @@
System.out.println();

if (type.equalsIgnoreCase("1")) {
- System.out.println("Please
give the url for device: "
+ System.out.println("Please
give the hostname or IP address for device: "
+ device + ":
");
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".url", input );
@@ -461,7 +421,7 @@
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".prompt", input);
System.out
- .println("Please give the
access rate for device: "
+ .println("Please give the
access rate for device (in ms): "
+ device + ":
");
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".rate", input);
@@ -496,7 +456,7 @@
||
type.equalsIgnoreCase("3")
||
type.equalsIgnoreCase("5")
||
type.equalsIgnoreCase("6")) {
- System.out.println("Please
give the url for device: "
+ System.out.println("Please
give the hostname or IP address for device: "
+ device + ":
");
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".url", input);
@@ -510,7 +470,7 @@
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".prompt", input);
System.out
- .println("Please give the
access rate for device: "
+ .println("Please give the
access rate for device (in ms): "
+ device + ":
");
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".rate", input);
@@ -541,7 +501,7 @@

//System.out.println("Encrypted password: " +
PasswordEncryptor.encryptPassword(input));
} else if (type.equalsIgnoreCase("4")
||
type.equalsIgnoreCase("7")) {
- System.out.println("Please
give the url for device: "
+ System.out.println("Please
give the hostname or IP address for device: "
+ device + ":
");
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".url", input);
@@ -555,7 +515,7 @@
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".prompt", input);
System.out
- .println("Please give the
access rate for device: "
+ .println("Please give the
access rate for device (in ms): "
+ device + ":
");
input = br.readLine();

prop.setProperty("service.r.mp." + device + ".rate", input);



  • perfsonar: r3080 - in trunk/geant2_java-sshtelnet-mp: ant conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters, svnlog, 11/30/2007

Archive powered by MHonArc 2.6.16.

Top of Page