11
11
import java .util .List ;
12
12
import java .util .logging .Level ;
13
13
import java .util .logging .Logger ;
14
- import javax .crypto .Mac ;
15
14
16
15
/**
17
16
* Generates host information used by spyware to identify requests coming from
@@ -55,7 +54,11 @@ private static JsonMaker getStaticHostInformation() {
55
54
while (iterator .hasMoreElements ()) {
56
55
NetworkInterface networkInterface = iterator .nextElement ();
57
56
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 ));
59
62
}
60
63
}
61
64
builder .add ("mac_addresses" , macs );
@@ -81,10 +84,20 @@ private static JsonMaker getStaticHostInformation() {
81
84
* algorithm be missing original string is returned.
82
85
*/
83
86
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
+ }
85
95
}
86
96
87
97
private static String trySecureHash (byte [] mac ) {
98
+ if (mac == null ) {
99
+ return "bmac_is_null" ;
100
+ }
88
101
try {
89
102
byte [] bytes = MessageDigest .getInstance ("SHA-256" ).digest (mac );
90
103
return byteToHex (bytes );
@@ -96,12 +109,15 @@ private static String trySecureHash(byte[] mac) {
96
109
try {
97
110
return byteToHex (mac );
98
111
} catch (Exception ex ) {
99
- return "error, e: " + ex . toString () ;
112
+ return "error" ;
100
113
}
101
114
}
102
115
}
103
116
104
117
private static String byteToHex (byte [] bytes ) {
118
+ if (bytes == null ) {
119
+ return "byte_to_hex_null" ;
120
+ }
105
121
StringBuilder sb = new StringBuilder ();
106
122
for (int i = 0 ; i < bytes .length ; i ++) {
107
123
sb .append (String .format ("%02X" , bytes [i ]));
0 commit comments