1111import java .util .List ;
1212import java .util .logging .Level ;
1313import java .util .logging .Logger ;
14- import javax .crypto .Mac ;
1514
1615/**
1716 * Generates host information used by spyware to identify requests coming from
@@ -55,7 +54,11 @@ private static JsonMaker getStaticHostInformation() {
5554 while (iterator .hasMoreElements ()) {
5655 NetworkInterface networkInterface = iterator .nextElement ();
5756 if (!networkInterface .isLoopback ()) {
58- macs .add (trySecureHash (networkInterface .getHardwareAddress ()));
57+ byte [] address = networkInterface .getHardwareAddress ();
58+ if (address == null ) {
59+ continue ;
60+ }
61+ macs .add (trySecureHash (address ));
5962 }
6063 }
6164 builder .add ("mac_addresses" , macs );
@@ -81,10 +84,20 @@ private static JsonMaker getStaticHostInformation() {
8184 * algorithm be missing original string is returned.
8285 */
8386 private static String trySecureHash (String mac ) {
84- return trySecureHash (mac .getBytes (UTF8 ));
87+ if (mac == null ) {
88+ return "mac_is_null" ;
89+ }
90+ try {
91+ return trySecureHash (mac .getBytes (UTF8 ));
92+ } catch (Exception e ) {
93+ return "error" ;
94+ }
8595 }
8696
8797 private static String trySecureHash (byte [] mac ) {
98+ if (mac == null ) {
99+ return "bmac_is_null" ;
100+ }
88101 try {
89102 byte [] bytes = MessageDigest .getInstance ("SHA-256" ).digest (mac );
90103 return byteToHex (bytes );
@@ -96,12 +109,15 @@ private static String trySecureHash(byte[] mac) {
96109 try {
97110 return byteToHex (mac );
98111 } catch (Exception ex ) {
99- return "error, e: " + ex . toString () ;
112+ return "error" ;
100113 }
101114 }
102115 }
103116
104117 private static String byteToHex (byte [] bytes ) {
118+ if (bytes == null ) {
119+ return "byte_to_hex_null" ;
120+ }
105121 StringBuilder sb = new StringBuilder ();
106122 for (int i = 0 ; i < bytes .length ; i ++) {
107123 sb .append (String .format ("%02X" , bytes [i ]));
0 commit comments