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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include "securevalidate.h"
AuthResult validateGamename(const bool &isBeacon,
const QString &gamename,
const QString &validate,
const QString &cipherIn,
const QString &secureIn,
const int &enctypeIn)
{
// output result
AuthResult authResult;
// override certain cases for UDP beacon
if ( isBeacon and _overrideValidateBeacon.contains(gamename) )
{
authResult.auth = true;
authResult.validate = "override";
return authResult;
}
// override certain cases for TCP client
if ( ! isBeacon and _overrideValidateClient.contains(gamename) )
{
authResult.auth = true;
authResult.validate = "override";
return authResult;
}
// inputs + checks
QByteArray secure = secureIn.toLatin1();
QByteArray cipher = cipherIn.toLatin1();
// get validate value
if ( 6 <= cipher.length() and cipher.length() < 16 and
6 <= secure.length() and secure.length() < 16 )
{
// safe to call validation. proceed.
authResult.validate = generateValidateString(cipher, secure, enctypeIn);
}
else
{
// incorrect input, not safe to calculate validation
authResult.auth = false;
authResult.validate = "invalid!";
}
// correct validation provided?
authResult.auth = (authResult.validate.compare(validate) == 0);
// return result as boolean and string
return authResult;
}
QString returnValidate(const QByteArray &cipher,
const QByteArray &secure,
const int &enctype)
{
// get validate value
if ( 6 <= cipher.length() and cipher.length() < 16 and
6 <= secure.length() and secure.length() < 16 )
{
return generateValidateString(cipher, secure, enctype);
}
else
{
return "invalid!";
}
}
QString genChallengeString(const int len, const bool moreChars)
{
QString randomString;
if (moreChars)
{
// use A-Za-z0-9
for(unsigned char i = 0; i < len; ++i)
{
randomString += moreCharacters[qrand() % moreCharacters.length()];
}
}
else
{
// use A-Z only
for(unsigned char i = 0; i < len; ++i)
{
randomString += possibleCharacters[qrand() % possibleCharacters.length()];
}
}
return randomString;
}
|