Changeset View
Changeset View
Standalone View
Standalone View
vpn/openvpn/openvpn.cpp
Show All 19 Lines | 1 | /* | |||
---|---|---|---|---|---|
20 | You should have received a copy of the GNU General Public License | 20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "openvpn.h" | 24 | #include "openvpn.h" | ||
25 | 25 | | |||
26 | #include <QLatin1Char> | 26 | #include <QLatin1Char> | ||
27 | #include <QStringBuilder> | 27 | #include <QStringBuilder> | ||
28 | #include <QStandardPaths> | ||||
29 | | ||||
28 | #include <KPluginFactory> | 30 | #include <KPluginFactory> | ||
29 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
30 | #include <KMessageBox> | 32 | #include <KMessageBox> | ||
31 | #include <KStandardDirs> | | |||
32 | 33 | | |||
33 | #include <NetworkManagerQt/Connection> | 34 | #include <NetworkManagerQt/Connection> | ||
34 | #include <NetworkManagerQt/VpnSetting> | 35 | #include <NetworkManagerQt/VpnSetting> | ||
35 | #include <NetworkManagerQt/Ipv4Setting> | 36 | #include <NetworkManagerQt/Ipv4Setting> | ||
36 | 37 | | |||
37 | #include "openvpnwidget.h" | 38 | #include "openvpnwidget.h" | ||
38 | #include "openvpnauth.h" | 39 | #include "openvpnauth.h" | ||
39 | 40 | | |||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
81 | #define BEGIN_KEY_SECRET_TAG "<secret>" | 82 | #define BEGIN_KEY_SECRET_TAG "<secret>" | ||
82 | #define END_KEY_SECRET_TAG "</secret>" | 83 | #define END_KEY_SECRET_TAG "</secret>" | ||
83 | #define BEGIN_TLS_AUTH_TAG "<tls-auth>" | 84 | #define BEGIN_TLS_AUTH_TAG "<tls-auth>" | ||
84 | #define END_TLS_AUTH_TAG "</tls-auth>" | 85 | #define END_TLS_AUTH_TAG "</tls-auth>" | ||
85 | 86 | | |||
86 | #define PROC_TYPE_TAG "Proc-Type: 4,ENCRYPTED" | 87 | #define PROC_TYPE_TAG "Proc-Type: 4,ENCRYPTED" | ||
87 | #define PKCS8_TAG "-----BEGIN ENCRYPTED PRIVATE KEY-----" | 88 | #define PKCS8_TAG "-----BEGIN ENCRYPTED PRIVATE KEY-----" | ||
88 | 89 | | |||
90 | QString localCertPath() | ||||
91 | { | ||||
92 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + | ||||
93 | QLatin1String("/networkmanagement/certificates/"); | ||||
94 | } | ||||
95 | | ||||
89 | QString unQuote(QString &certVal, const QString &fileName) | 96 | QString unQuote(QString &certVal, const QString &fileName) | ||
90 | { | 97 | { | ||
91 | /* Unquote according to openvpn rules | 98 | /* Unquote according to openvpn rules | ||
92 | * Unquoted filename is returned, and @certVal is modified | 99 | * Unquoted filename is returned, and @certVal is modified | ||
93 | * to the leftover string | 100 | * to the leftover string | ||
94 | */ | 101 | */ | ||
95 | int nextSep; | 102 | int nextSep; | ||
96 | QString certFile = certVal.trimmed(); | 103 | QString certFile = certVal.trimmed(); | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 188 | if (!impFile.open(QFile::ReadOnly|QFile::Text)) { | |||
182 | mError = VpnUiPlugin::Error; | 189 | mError = VpnUiPlugin::Error; | ||
183 | mErrorMessage = i18n("Could not open file"); | 190 | mErrorMessage = i18n("Could not open file"); | ||
184 | return result; | 191 | return result; | ||
185 | } | 192 | } | ||
186 | 193 | | |||
187 | bool copyCertificates; | 194 | bool copyCertificates; | ||
188 | KMessageBox::ButtonCode buttonCode; | 195 | KMessageBox::ButtonCode buttonCode; | ||
189 | if (KMessageBox::shouldBeShownYesNo(QLatin1String("copyCertificatesDialog"), buttonCode)) { | 196 | if (KMessageBox::shouldBeShownYesNo(QLatin1String("copyCertificatesDialog"), buttonCode)) { | ||
190 | copyCertificates = KMessageBox::questionYesNo(nullptr, i18n("Do you want to copy your certificates to %1?", KStandardDirs::locateLocal("data", "networkmanagement/certificates/")), | 197 | copyCertificates = KMessageBox::questionYesNo(nullptr, i18n("Do you want to copy your certificates to %1?", localCertPath()), | ||
191 | i18n("Copy certificates"), KStandardGuiItem::yes(), KStandardGuiItem::no(), QLatin1String("copyCertificatesDialog")) == KMessageBox::Yes; | 198 | i18n("Copy certificates"), KStandardGuiItem::yes(), KStandardGuiItem::no(), QLatin1String("copyCertificatesDialog")) == KMessageBox::Yes; | ||
192 | } else { | 199 | } else { | ||
193 | copyCertificates = buttonCode == KMessageBox::Yes; | 200 | copyCertificates = buttonCode == KMessageBox::Yes; | ||
194 | } | 201 | } | ||
195 | 202 | | |||
196 | const QString connectionName = QFileInfo(fileName).completeBaseName(); | 203 | const QString connectionName = QFileInfo(fileName).completeBaseName(); | ||
197 | NMStringMap dataMap; | 204 | NMStringMap dataMap; | ||
198 | NMStringMap secretData; | 205 | NMStringMap secretData; | ||
▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Line(s) | |||||
655 | } | 662 | } | ||
656 | 663 | | |||
657 | impFile.close(); | 664 | impFile.close(); | ||
658 | return result; | 665 | return result; | ||
659 | } | 666 | } | ||
660 | 667 | | |||
661 | QString OpenVpnUiPlugin::saveFile(QTextStream &in, const QString &endTag, const QString &connectionName, const QString &fileName) | 668 | QString OpenVpnUiPlugin::saveFile(QTextStream &in, const QString &endTag, const QString &connectionName, const QString &fileName) | ||
662 | { | 669 | { | ||
663 | const QString certificatesDirectory = KStandardDirs::locateLocal("data", "networkmanagement/certificates/" + connectionName); | 670 | const QString certificatesDirectory = localCertPath() + connectionName; | ||
664 | const QString absoluteFilePath = certificatesDirectory + '/' + fileName; | 671 | const QString absoluteFilePath = certificatesDirectory + '/' + fileName; | ||
665 | QFile outFile(absoluteFilePath); | 672 | QFile outFile(absoluteFilePath); | ||
666 | 673 | | |||
667 | QDir().mkpath(certificatesDirectory); | 674 | QDir().mkpath(certificatesDirectory); | ||
668 | if (!outFile.open(QFile::WriteOnly | QFile::Text)) { | 675 | if (!outFile.open(QFile::WriteOnly | QFile::Text)) { | ||
669 | KMessageBox::information(nullptr, i18n("Error saving file %1: %2", absoluteFilePath, outFile.errorString())); | 676 | KMessageBox::information(nullptr, i18n("Error saving file %1: %2", absoluteFilePath, outFile.errorString())); | ||
670 | return QString(); | 677 | return QString(); | ||
671 | } | 678 | } | ||
Show All 10 Lines | |||||
682 | } | 689 | } | ||
683 | 690 | | |||
684 | outFile.close(); | 691 | outFile.close(); | ||
685 | return absoluteFilePath; | 692 | return absoluteFilePath; | ||
686 | } | 693 | } | ||
687 | 694 | | |||
688 | QString OpenVpnUiPlugin::tryToCopyToCertificatesDirectory(const QString &connectionName, const QString &sourceFilePath) | 695 | QString OpenVpnUiPlugin::tryToCopyToCertificatesDirectory(const QString &connectionName, const QString &sourceFilePath) | ||
689 | { | 696 | { | ||
690 | const QString certificatesDirectory = KStandardDirs::locateLocal("data", "networkmanagement/certificates/"); | 697 | const QString certificatesDirectory = localCertPath(); | ||
691 | const QString absoluteFilePath = certificatesDirectory + connectionName + '_' + QFileInfo(sourceFilePath).fileName(); | 698 | const QString absoluteFilePath = certificatesDirectory + connectionName + '_' + QFileInfo(sourceFilePath).fileName(); | ||
692 | 699 | | |||
693 | QFile sourceFile(sourceFilePath); | 700 | QFile sourceFile(sourceFilePath); | ||
694 | 701 | | |||
695 | QDir().mkpath(certificatesDirectory); | 702 | QDir().mkpath(certificatesDirectory); | ||
696 | if (!sourceFile.copy(absoluteFilePath)) { | 703 | if (!sourceFile.copy(absoluteFilePath)) { | ||
697 | KMessageBox::information(nullptr, i18n("Error copying certificate to %1: %2", absoluteFilePath, sourceFile.errorString())); | 704 | KMessageBox::information(nullptr, i18n("Error copying certificate to %1: %2", absoluteFilePath, sourceFile.errorString())); | ||
698 | return sourceFilePath; | 705 | return sourceFilePath; | ||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |