Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenVPN password authentication #854

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions client/core/controllers/serverController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,19 @@ ErrorCode ServerController::startupContainerWorker(const ServerCredentials &cred
if (e)
return e;

if (container == DockerContainer::OpenVpn)
{
QFile file(":/server_scripts/openvpn/password_auth.sh");
file.open(QIODevice::ReadOnly);
QString scriptContent = QString(file.readAll());
const QString serverScriptPath = "/opt/amnezia/password_auth.sh";

uploadTextFileToContainer(container, credentials, scriptContent, serverScriptPath);
runScript(credentials,
replaceVars(QStringLiteral("sudo docker exec -d $CONTAINER_NAME sh -c \"chmod +rx %1\"").arg(serverScriptPath),
genVarsForScript(credentials, container, config)));
}

return runScript(credentials,
replaceVars("sudo docker exec -d $CONTAINER_NAME sh -c \"chmod a+x /opt/amnezia/start.sh && "
"/opt/amnezia/start.sh\"",
Expand Down
1 change: 1 addition & 0 deletions client/core/scripts_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ QString amnezia::scriptName(ProtocolScriptType type)
case ProtocolScriptType::configure_container: return QLatin1String("configure_container.sh");
case ProtocolScriptType::container_startup: return QLatin1String("start.sh");
case ProtocolScriptType::openvpn_template: return QLatin1String("template.ovpn");
case ProtocolScriptType::openvpn_password_auth: return QLatin1String("password_auth.sh");
case ProtocolScriptType::wireguard_template: return QLatin1String("template.conf");
case ProtocolScriptType::awg_template: return QLatin1String("template.conf");
case ProtocolScriptType::xray_template: return QLatin1String("template.json");
Expand Down
1 change: 1 addition & 0 deletions client/core/scripts_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum ProtocolScriptType {
configure_container,
container_startup,
openvpn_template,
openvpn_password_auth,
wireguard_template,
awg_template,
xray_template
Expand Down
1 change: 1 addition & 0 deletions client/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<file>server_scripts/openvpn/template.ovpn</file>
<file>server_scripts/openvpn/Dockerfile</file>
<file>server_scripts/openvpn/start.sh</file>
<file>server_scripts/openvpn/password_auth.sh</file>
<file>server_scripts/openvpn_shadowsocks/configure_container.sh</file>
<file>server_scripts/openvpn_shadowsocks/Dockerfile</file>
<file>server_scripts/openvpn_shadowsocks/run_container.sh</file>
Expand Down
15 changes: 15 additions & 0 deletions client/server_scripts/openvpn/password_auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

readarray -t lines < $1
current_login=${lines[0]}
current_password=${lines[1]}

credentials_file_path=/opt/amnezia/openvpn/auth_credentials.txt

saved_login=$(awk 'NR==1' $credentials_file_path)
saved_password=$(awk 'NR==2' $credentials_file_path)

if [ "$current_login" == "$saved_login" ] && [ "$current_password" == "$saved_password" ]; then
exit 0
fi
exit 1
10 changes: 10 additions & 0 deletions client/ui/models/protocols/openvpnConfigModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ bool OpenVpnConfigModel::setData(const QModelIndex &index, const QVariant &value
break;
case Roles::AdditionalServerCommandsRole:
m_protocolConfig.insert(config_key::additional_server_config, value.toString());
break;
case Roles::AuthLogin:

break;
case Roles::AuthPassword:

break;
}

Expand Down Expand Up @@ -72,6 +78,8 @@ QVariant OpenVpnConfigModel::data(const QModelIndex &index, int role) const
case Roles::IsPortEditable: return m_container == DockerContainer::OpenVpn ? true : false;
case Roles::IsTransportProtoEditable: return m_container == DockerContainer::OpenVpn ? true : false;
case Roles::HasRemoveButton: return m_container == DockerContainer::OpenVpn ? true : false;
case Roles::AuthLogin:return {};
case Roles::AuthPassword: return {};
}
return QVariant();
}
Expand Down Expand Up @@ -146,6 +154,8 @@ QHash<int, QByteArray> OpenVpnConfigModel::roleNames() const
roles[IsTransportProtoEditable] = "isTransportProtoEditable";

roles[HasRemoveButton] = "hasRemoveButton";
roles[AuthLogin] = "authLogin";
roles[AuthPassword] = "authPassword";

return roles;
}
5 changes: 4 additions & 1 deletion client/ui/models/protocols/openvpnConfigModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class OpenVpnConfigModel : public QAbstractListModel
IsPortEditable,
IsTransportProtoEditable,

HasRemoveButton
HasRemoveButton,

AuthLogin,
AuthPassword,
};

explicit OpenVpnConfigModel(QObject *parent = nullptr);
Expand Down
63 changes: 63 additions & 0 deletions client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,68 @@ PageType {
}
}

SwitcherType {
id: authCredentialsSwitcher
Layout.fillWidth: true
Layout.topMargin: 24
parentFlickable: fl

checked: authLogin !== "" && authPassword !== ""

text: qsTr("Authentication credentials")

onCheckedChanged: {
//if (!checked) {
// additionalServerCommands = ""
//}
}
}

TextFieldWithHeaderType {
id: loginTextField

Layout.fillWidth: true
parentFlickable: fl

//enabled: isPortEditable

headerText: qsTr("Login")
textFieldText: authLogin
//textField.maximumLength: 5
//textField.validator: IntValidator { bottom: 1; top: 65535 }

textField.onEditingFinished: {
if (textFieldText !== authLogin) {
authLogin = textFieldText
}
}

// KeyNavigation.tab: autoNegotiateEncryprionSwitcher
}

TextFieldWithHeaderType {
id: passwordTextField

Layout.fillWidth: true
Layout.topMargin: 20
parentFlickable: fl

//enabled: isPortEditable

headerText: qsTr("Password")
textFieldText: authPassword
//textField.maximumLength: 5
//textField.validator: IntValidator { bottom: 1; top: 65535 }

textField.onEditingFinished: {
if (textFieldText !== authPassword) {
authPassword = textFieldText
}
}

// KeyNavigation.tab: autoNegotiateEncryprionSwitcher
}

BasicButtonType {
id: saveRestartButton

Expand All @@ -449,6 +511,7 @@ PageType {
InstallController.updateContainer(OpenVpnConfigModel.getConfig())
}
}

}
}
}
Expand Down
Loading