Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Maui Accounts DBus Daemon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Maui
Maui Accounts DBus Daemon
Commits
926fba9a
Commit
926fba9a
authored
Jul 19, 2019
by
Anupam Basak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#3
Implement functionality to share Accounts between Applications
parent
fd6d6f86
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
104 deletions
+86
-104
src/EncryptionHelper.cpp
src/EncryptionHelper.cpp
+6
-17
src/EncryptionHelper.hpp
src/EncryptionHelper.hpp
+0
-2
src/dbus-interfaces/RootDBusInterface.cpp
src/dbus-interfaces/RootDBusInterface.cpp
+78
-85
src/dbus-interfaces/RootDBusInterface.hpp
src/dbus-interfaces/RootDBusInterface.hpp
+2
-0
No files found.
src/EncryptionHelper.cpp
View file @
926fba9a
...
...
@@ -15,8 +15,9 @@ QString EncryptionHelper::encrypt(QString password, QString text) {
QString
stdout
=
process
.
readAllStandardOutput
();
QString
stderr
=
process
.
readAllStandardError
();
qDebug
()
<<
"ENCRYPT OUTPUT :"
<<
stdout
;
qDebug
()
<<
"ENCRYPT ERROR :"
<<
stderr
;
if
(
stderr
!=
""
)
{
qDebug
()
<<
"ENCRYPT ERROR :"
<<
stderr
;
}
return
stdout
;
}
...
...
@@ -31,21 +32,9 @@ QString EncryptionHelper::decrypt(QString password, QString filepath) {
QString
stdout
=
process
.
readAllStandardOutput
();
QString
stderr
=
process
.
readAllStandardError
();
qDebug
()
<<
"DECRYPT OUTPUT :"
<<
stdout
;
qDebug
()
<<
"DECRYPT ERROR :"
<<
stderr
;
if
(
stderr
!=
""
)
{
qDebug
()
<<
"DECRYPT ERROR :"
<<
stderr
;
}
return
stdout
;
}
QString
EncryptionHelper
::
inputMasterPassword
()
{
QProcess
process
;
process
.
start
(
"DISPLAY=:0 kdialog --password
\"
Enter MAUI Accounts Master Password. "
"This password "
"will be used to encrypt/decrypt secure data
\"
"
);
process
.
waitForFinished
(
-
1
);
qDebug
()
<<
"INPUT PASSWORD ERROR :"
<<
process
.
readAllStandardError
();
return
process
.
readAllStandardOutput
();
}
src/EncryptionHelper.hpp
View file @
926fba9a
...
...
@@ -7,8 +7,6 @@ class EncryptionHelper {
public:
static
QString
encrypt
(
QString
password
,
QString
text
);
static
QString
decrypt
(
QString
password
,
QString
filePath
);
static
QString
inputMasterPassword
();
};
#endif
src/dbus-interfaces/RootDBusInterface.cpp
View file @
926fba9a
...
...
@@ -75,6 +75,58 @@ void RootDBusInterface::readAccountsDB() {
}
}
QString
RootDBusInterface
::
insertAccountToDb
(
QString
appId
,
QString
type
,
QString
username
,
QString
password
,
QString
url
)
{
if
(
!
accountsJsonObject
.
contains
(
JSON_FIELD_ACCOUNTS
))
{
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
]
=
QJsonArray
();
}
bool
accountFound
=
false
;
QString
secret
=
""
;
QJsonArray
accountsArray
=
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
].
toArray
();
for
(
int
i
=
0
;
i
<
accountsArray
.
size
();
i
++
)
{
QJsonObject
obj
=
accountsArray
.
at
(
i
).
toObject
();
if
(
obj
[
JSON_ACCOUNT_ARRAY_FIELD_APPID
].
toString
()
==
appId
&&
obj
[
JSON_ACCOUNT_ARRAY_FIELD_TYPE
].
toString
()
==
type
&&
obj
[
JSON_ACCOUNT_ARRAY_FIELD_USERNAME
].
toString
()
==
username
&&
obj
[
JSON_ACCOUNT_ARRAY_FIELD_PASSWORD
].
toString
()
==
password
&&
obj
[
JSON_ACCOUNT_ARRAY_FIELD_URL
].
toString
()
==
url
)
{
qDebug
().
noquote
()
<<
" Account already added"
;
secret
=
obj
[
JSON_ACCOUNT_ARRAY_FIELD_SECRET
].
toString
();
accountFound
=
true
;
break
;
}
}
if
(
!
accountFound
)
{
secret
=
QUuid
::
createUuid
().
toString
(
QUuid
::
StringFormat
::
WithoutBraces
);
QJsonObject
accountObject
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_ID
]
=
QUuid
::
createUuid
().
toString
(
QUuid
::
StringFormat
::
WithoutBraces
);
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_SECRET
]
=
secret
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_APPID
]
=
appId
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_TYPE
]
=
type
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_USERNAME
]
=
username
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_PASSWORD
]
=
password
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_URL
]
=
url
;
accountsArray
.
append
(
accountObject
);
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
]
=
accountsArray
;
writeAccountsJsonObjectToFile
();
qDebug
().
noquote
()
<<
" Account Created"
;
}
return
secret
;
}
bool
RootDBusInterface
::
isPasswordSet
()
{
return
masterPassword
!=
""
;
}
void
RootDBusInterface
::
setPassword
(
QString
password
)
{
...
...
@@ -144,16 +196,12 @@ QMap<QString, QVariant> RootDBusInterface::getAccount(QString id) {
QString
RootDBusInterface
::
getAccountPassword
(
QString
secret
)
{
qDebug
().
noquote
()
<<
"* Account password requested"
;
QString
secretHashed
=
QCryptographicHash
::
hash
(
QByteArray
::
fromStdString
(
secret
.
toStdString
()),
QCryptographicHash
::
Sha256
);
QJsonArray
accounts
=
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
].
toArray
();
for
(
int
i
=
0
;
i
<
accounts
.
size
();
i
++
)
{
QJsonObject
account
=
accounts
[
i
].
toObject
();
if
(
account
[
JSON_ACCOUNT_ARRAY_FIELD_SECRET
].
toString
()
==
secret
Hashed
)
{
if
(
account
[
JSON_ACCOUNT_ARRAY_FIELD_SECRET
].
toString
()
==
secret
)
{
qDebug
().
noquote
()
<<
" Found user `"
+
account
[
JSON_ACCOUNT_ARRAY_FIELD_USERNAME
].
toString
()
+
"`"
;
...
...
@@ -178,47 +226,20 @@ QString RootDBusInterface::createWebDAVAccount(QString appId, QString username,
WebDAV
*
m_WebDAV
=
new
WebDAV
(
url
,
username
,
password
);
WebDAVReply
*
reply
=
m_WebDAV
->
testConnection
();
this
->
connect
(
reply
,
&
WebDAVReply
::
testConnectionResponse
,
[
=
,
&
secret
](
bool
isSuccess
)
{
if
(
isSuccess
)
{
qDebug
().
noquote
()
<<
" Success connecting to Server"
;
if
(
!
accountsJsonObject
.
contains
(
JSON_FIELD_ACCOUNTS
))
{
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
]
=
QJsonArray
();
}
secret
=
QUuid
::
createUuid
().
toString
(
QUuid
::
StringFormat
::
WithoutBraces
);
QString
secretHashed
=
QCryptographicHash
::
hash
(
QByteArray
::
fromStdString
(
secret
.
toStdString
()),
QCryptographicHash
::
Sha256
);
QJsonArray
accountsArray
=
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
].
toArray
();
QJsonObject
accountObject
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_ID
]
=
QUuid
::
createUuid
().
toString
(
QUuid
::
StringFormat
::
WithoutBraces
);
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_SECRET
]
=
secretHashed
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_APPID
]
=
appId
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_TYPE
]
=
"WEBDAV"
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_USERNAME
]
=
username
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_PASSWORD
]
=
password
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_URL
]
=
url
;
accountsArray
.
append
(
accountObject
);
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
]
=
accountsArray
;
writeAccountsJsonObjectToFile
();
qDebug
().
noquote
()
<<
" Account Created"
;
QTimer
::
singleShot
(
0
,
qloop
,
&
QEventLoop
::
quit
);
}
else
{
qDebug
().
noquote
()
<<
" [ERROR] Could not connect to server"
;
}
});
this
->
connect
(
reply
,
&
WebDAVReply
::
testConnectionResponse
,
[
=
,
&
secret
](
bool
isSuccess
)
{
if
(
isSuccess
)
{
qDebug
().
noquote
()
<<
" Success connecting to Server"
;
secret
=
insertAccountToDb
(
appId
,
"WEBDAV"
,
username
,
password
,
url
);
QTimer
::
singleShot
(
0
,
qloop
,
&
QEventLoop
::
quit
);
}
else
{
qDebug
().
noquote
()
<<
" [ERROR] Could not connect to server"
;
}
});
this
->
connect
(
reply
,
&
WebDAVReply
::
error
,
[
=
](
QNetworkReply
::
NetworkError
err
)
{
qDebug
().
noquote
()
...
...
@@ -248,45 +269,17 @@ QString RootDBusInterface::createCardDAVAccount(QString appId, QString username,
CardDAV
*
m_CardDAV
=
new
CardDAV
(
url
,
username
,
password
);
CardDAVReply
*
reply
=
m_CardDAV
->
testConnection
();
this
->
connect
(
reply
,
&
CardDAVReply
::
testConnectionResponse
,
[
=
,
&
secret
](
bool
isSuccess
)
{
if
(
isSuccess
)
{
qDebug
().
noquote
()
<<
" Success connecting to Server"
;
if
(
!
accountsJsonObject
.
contains
(
JSON_FIELD_ACCOUNTS
))
{
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
]
=
QJsonArray
();
}
secret
=
QUuid
::
createUuid
().
toString
(
QUuid
::
StringFormat
::
WithoutBraces
);
QString
secretHashed
=
QCryptographicHash
::
hash
(
QByteArray
::
fromStdString
(
secret
.
toStdString
()),
QCryptographicHash
::
Sha256
);
QJsonArray
accountsArray
=
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
].
toArray
();
QJsonObject
accountObject
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_ID
]
=
QUuid
::
createUuid
().
toString
(
QUuid
::
StringFormat
::
WithoutBraces
);
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_SECRET
]
=
secretHashed
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_APPID
]
=
appId
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_TYPE
]
=
"CARDDAV"
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_USERNAME
]
=
username
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_PASSWORD
]
=
password
;
accountObject
[
JSON_ACCOUNT_ARRAY_FIELD_URL
]
=
url
;
accountsArray
.
append
(
accountObject
);
accountsJsonObject
[
JSON_FIELD_ACCOUNTS
]
=
accountsArray
;
writeAccountsJsonObjectToFile
();
qDebug
().
noquote
()
<<
" Account Created"
;
QTimer
::
singleShot
(
0
,
qloop
,
&
QEventLoop
::
quit
);
}
});
this
->
connect
(
reply
,
&
CardDAVReply
::
testConnectionResponse
,
[
=
,
&
secret
](
bool
isSuccess
)
{
if
(
isSuccess
)
{
qDebug
().
noquote
()
<<
" Success connecting to Server"
;
secret
=
insertAccountToDb
(
appId
,
"CARDDAV"
,
username
,
password
,
url
);
QTimer
::
singleShot
(
0
,
qloop
,
&
QEventLoop
::
quit
);
}
});
this
->
connect
(
reply
,
&
CardDAVReply
::
error
,
[
=
](
QNetworkReply
::
NetworkError
err
)
{
qDebug
().
noquote
()
...
...
src/dbus-interfaces/RootDBusInterface.hpp
View file @
926fba9a
...
...
@@ -34,6 +34,8 @@ class RootDBusInterface : public DBusInterface {
void
writeAccountsJsonObjectToFile
();
QString
getManifestPath
(
QString
appId
);
void
readAccountsDB
();
QString
insertAccountToDb
(
QString
appId
,
QString
type
,
QString
username
,
QString
password
,
QString
url
);
public
slots
:
Q_SCRIPTABLE
bool
isPasswordSet
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment