forked from hzx1987227/rallets-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssvalidator.cpp
More file actions
66 lines (58 loc) · 1.7 KB
/
ssvalidator.cpp
File metadata and controls
66 lines (58 loc) · 1.7 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
#include "ssvalidator.h"
#include "libqtss/lib/QtShadowsocks"
QStringList SSValidator::supportedMethodList()
{
QList<QByteArray> methodBA = QSS::Cipher::getSupportedMethodList();
QStringList methodList;
for (const QByteArray &method : methodBA) {
methodList.push_back(QString(method).toUpper());
}
return methodList;
}
bool SSValidator::validate(QString input)
{
//must begin with ss:// to distinguish from random base64 encoded strings
if (input.startsWith("ss://")) {
input.remove(0, 5);
QStringList tagList = input.split('#');
QString decode(QByteArray::fromBase64(tagList.first().toUtf8()));
QStringList decList = decode.split(':');
if (decList.size() < 3) {
return false;
}
//Validate Method
QString method = decList.first().toUpper();
if (method.endsWith("-AUTH")) {
method.remove("-AUTH");
}
if (!validateMethod(method)) {
return false;
}
//Validate Port
QString port = decList.last();
if (!validatePort(port)) {
return false;
}
//Validate whether server and password exist
QStringList pwdServer = decList.at(1).split('@');
if (pwdServer.size() < 2) {
return false;
}
//it seems acceptable now
return true;
}
else {
return false;
}
}
bool SSValidator::validatePort(const QString &port)
{
bool ok;
port.toUShort(&ok);
return ok;
}
bool SSValidator::validateMethod(const QString &method)
{
static const QStringList validMethodList = supportedMethodList();
return validMethodList.contains(method, Qt::CaseInsensitive);
}