UglyFix.java
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package fi.insomnia.bortal.utilities;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UglyFix {
// Don't touch. Fix old byte to String conversion bugs in passwords
private static final byte FIXSTR[] = { -17, -65, -67 };
private final byte[] newarray;
private final byte[] oldarray;
private int newint;
private int oldint;
private static final Logger logger = LoggerFactory.getLogger(UglyFix.class);
public UglyFix(String newBase64, String oldBase64) {
newint = 0;
oldint = 0;
newarray = Base64.decodeBase64(newBase64);
oldarray = Base64.decodeBase64(oldBase64);
}
public boolean check() {
boolean ret = true;
for (oldint = 0; oldint < oldarray.length && newint < newarray.length; ++oldint) {
if (oldarray[oldint] != newarray[newint]) {
logger.debug("No match checking against FIXSTR");
if (!checkForHITA()) {
logger.debug("hitacheck not ok. Returning false!");
ret = false;
break;
}
}
++newint;
}
return ret;
}
private boolean checkForHITA() {
boolean ret = false;
if (oldint + 3 < oldarray.length &&
oldarray[oldint] == FIXSTR[0] &&
oldarray[oldint + 1] == FIXSTR[1] &&
oldarray[oldint + 2] == FIXSTR[2]) {
logger.debug("FOUND hita string");
/*
* we have found the "hands in the air string" and thus skipped at
* least one newarray character, but maybe more.. So let's check.
*/
oldint = oldint + 3;
++newint;
for (int testnew = newint; testnew < newarray.length; ++testnew) {
logger.debug("checking char at newarray {} matches the character at oldarray:{}", newarray[testnew], oldarray[oldint]);
if (newarray[testnew] == oldarray[oldint]) {
ret = true;
break;
}
}
if (!ret && oldarray[oldint] == FIXSTR[0]) {
logger.debug("Recursive HITAcheck");
ret = checkForHITA();
}
}
return ret;
}
}