diff --git a/ZUtil.jar b/ZUtil.jar new file mode 100644 index 00000000..800ed0c2 Binary files /dev/null and b/ZUtil.jar differ diff --git a/src/zutil/Hasher.java b/src/zutil/Hasher.java index 7278efcb..77967f40 100644 --- a/src/zutil/Hasher.java +++ b/src/zutil/Hasher.java @@ -25,6 +25,8 @@ package zutil; import zutil.converters.Converter; import javax.crypto.Mac; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; import java.io.*; import java.math.BigInteger; @@ -65,7 +67,7 @@ public class Hasher { /** * Returns the MD5 hash of the given object * - * @param object is the String to hash + * @param str is the String to hash * @return an String containing the hash */ public static String MD5(String str){ @@ -175,6 +177,23 @@ public class Hasher { } return null; } + + public static String PBKDF2(String data, String salt, int iterations){ + try { + PBEKeySpec spec = new PBEKeySpec( + data.toCharArray(), + salt.getBytes(), + iterations, + 256); + SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); + byte[] raw = f.generateSecret(spec).getEncoded(); + + return Converter.toHexString(raw); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } /** * Hashes the given String as UTF8 diff --git a/src/zutil/net/ssdp/SSDPClient.java b/src/zutil/net/ssdp/SSDPClient.java index 48b4ab7f..6b926ea4 100644 --- a/src/zutil/net/ssdp/SSDPClient.java +++ b/src/zutil/net/ssdp/SSDPClient.java @@ -50,22 +50,7 @@ public class SSDPClient extends ThreadedUDPNetwork implements ThreadedUDPNetwork private HashMap services_usn; private SSDPServiceListener listener; - - - public static void main(String[] args) throws IOException{ - System.out.println(LogUtil.getCalingClass()); - LogUtil.setGlobalLevel(Level.FINEST); - SSDPClient ssdp = new SSDPClient(); - //ssdp.requestService("upnp:rootdevice"); - ssdp.requestService("zap:discover"); - ssdp.start(); - - for(int i=0; true ;++i){ - while( i==ssdp.getServicesCount("upnp:rootdevice") ){ try{Thread.sleep(100);}catch(Exception e){} } - logger.log(Level.FINEST, "************************" ); - logger.log(Level.FINEST, ""+ssdp.getServices("upnp:rootdevice").get(i) ); - } - } + /** * Creates new instance of this class. An UDP diff --git a/src/zutil/net/ssdp/SSDPServer.java b/src/zutil/net/ssdp/SSDPServer.java index 03501343..44d0d435 100644 --- a/src/zutil/net/ssdp/SSDPServer.java +++ b/src/zutil/net/ssdp/SSDPServer.java @@ -77,20 +77,6 @@ public class SSDPServer extends ThreadedUDPNetwork implements ThreadedUDPNetwork private HashMap services; - public static void main(String[] args) throws IOException{ - LogUtil.setGlobalLevel(Level.FINEST); - StandardSSDPInfo service = new StandardSSDPInfo(); - service.setLocation("nowhere"); - service.setST("zep:discover"); - HashMap headers = new HashMap(); - headers.put("Alias", "Desktop"); - headers.put("PublicKey", "SuperDesktopKey"); - service.setHeaders(headers); - SSDPServer ssdp = new SSDPServer(); - ssdp.addService(service); - ssdp.start(); - logger.info("SSDP Server running"); - } public SSDPServer() throws IOException{ super( null, SSDP_MULTICAST_ADDR, SSDP_PORT ); diff --git a/src/zutil/test/SSDPClientTest.java b/src/zutil/test/SSDPClientTest.java new file mode 100644 index 00000000..10ffcdf9 --- /dev/null +++ b/src/zutil/test/SSDPClientTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015 Ziver + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.test; + +import zutil.log.LogUtil; +import zutil.net.ssdp.SSDPClient; + +import java.io.IOException; +import java.util.logging.Level; + +/** + * Created by Ziver on 2015-09-29. + */ +public class SSDPClientTest { + + public static void main(String[] args) throws IOException { + System.out.println(LogUtil.getCalingClass()); + LogUtil.setGlobalLevel(Level.FINEST); + SSDPClient ssdp = new SSDPClient(); + ssdp.requestService("upnp:rootdevice"); + ssdp.start(); + + for(int i=0; true ;++i){ + while( i==ssdp.getServicesCount("upnp:rootdevice") ){ try{Thread.sleep(100);}catch(Exception e){} } + System.out.println("************************" ); + System.out.println("" + ssdp.getServices("upnp:rootdevice").get(i)); + } + } +} diff --git a/src/zutil/test/SSDPServerTest.java b/src/zutil/test/SSDPServerTest.java new file mode 100644 index 00000000..073320b4 --- /dev/null +++ b/src/zutil/test/SSDPServerTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Ziver + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.test; + +import zutil.log.LogUtil; +import zutil.net.ssdp.SSDPServer; +import zutil.net.ssdp.StandardSSDPInfo; + +import java.io.IOException; +import java.util.HashMap; +import java.util.logging.Level; + +/** + * Created by Ziver on 2015-09-29. + */ +public class SSDPServerTest { + + public static void main(String[] args) throws IOException { + LogUtil.setGlobalLevel(Level.FINEST); + + StandardSSDPInfo service = new StandardSSDPInfo(); + service.setLocation("nowhere"); + service.setST("zep:discover"); + HashMap headers = new HashMap(); + headers.put("Alias", "Desktop"); + headers.put("PublicKey", "SuperDesktopKey"); + service.setHeaders(headers); + + SSDPServer ssdp = new SSDPServer(); + ssdp.addService(service); + ssdp.start(); + System.out.println("SSDP Server running"); + } +}