Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
24540f64
Commit
24540f64
authored
5 years ago
by
Vsevolod Ivanov
Browse files
Options
Downloads
Patches
Plain Diff
jams: implement revoke device
Change-Id: I14229adb9028dd01b46c631bf3533cf2cd2859d0
parent
860a4876
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/jamidht/server_account_manager.cpp
+66
-8
66 additions, 8 deletions
src/jamidht/server_account_manager.cpp
src/jamidht/server_account_manager.h
+3
-0
3 additions, 0 deletions
src/jamidht/server_account_manager.h
with
69 additions
and
8 deletions
src/jamidht/server_account_manager.cpp
+
66
−
8
View file @
24540f64
/*
* Copyright (C) 2014-2019 Savoir-faire Linux Inc.
* Author : Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* Vsevolod Ivanov <vsevolod.ivanov@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
...
...
@@ -31,8 +32,7 @@ namespace jami {
using
Request
=
dht
::
http
::
Request
;
static
const
std
::
string
PATH_AUTH
=
"/api/auth"
;
static
const
std
::
string
PATH_DEVICE_REGISTER
=
PATH_AUTH
+
"/device"
;
static
const
std
::
string
PATH_DEVICES
=
PATH_AUTH
+
"/devices"
;
static
const
std
::
string
PATH_DEVICE
=
PATH_AUTH
+
"/device"
;
constexpr
const
char
*
const
HTTPS_PROTO
{
"https"
};
...
...
@@ -79,14 +79,14 @@ ServerAccountManager::initAuthentication(
onChange_
=
std
::
move
(
onChange
);
const
std
::
string
url
=
managerHostname_
+
PATH_DEVICE
_REGISTER
;
const
std
::
string
url
=
managerHostname_
+
PATH_DEVICE
;
JAMI_WARN
(
"[Auth] authentication with: %s to %s"
,
ctx
->
credentials
->
username
.
c_str
(),
url
.
c_str
());
auto
request
=
std
::
make_shared
<
Request
>
(
*
Manager
::
instance
().
ioContext
(),
url
,
logger_
);
auto
reqid
=
request
->
id
();
restinio
::
http_request_header_t
header
;
header
.
method
(
restinio
::
http_method_post
());
request
->
set_header
(
header
);
request
->
set_target
(
PATH_DEVICE
_REGISTER
);
request
->
set_target
(
PATH_DEVICE
);
request
->
set_auth
(
ctx
->
credentials
->
username
,
ctx
->
credentials
->
password
);
{
std
::
stringstream
ss
;
...
...
@@ -100,7 +100,7 @@ ServerAccountManager::initAuthentication(
setHeaderFields
(
*
request
);
request
->
add_on_state_change_callback
([
reqid
,
ctx
,
onAsync
=
onAsync_
]
(
Request
::
State
state
,
const
dht
::
http
::
Response
&
response
){
JAMI_
ERR
(
"[Auth] Got
server response:
%d"
,
(
int
)
state
);
JAMI_
DBG
(
"[Auth] Got
request callback with state=
%d"
,
(
int
)
state
);
if
(
state
!=
Request
::
State
::
DONE
)
return
;
if
(
response
.
status_code
==
0
)
{
...
...
@@ -202,20 +202,20 @@ ServerAccountManager::syncDevices()
{
if
(
not
creds_
)
return
;
const
std
::
string
url
=
managerHostname_
+
PATH_DEVICE
S
+
"?username="
+
creds_
->
username
;
const
std
::
string
url
=
managerHostname_
+
PATH_DEVICE
+
"?username="
+
creds_
->
username
;
JAMI_WARN
(
"[Auth] syncDevices with: %s to %s"
,
creds_
->
username
.
c_str
(),
url
.
c_str
());
auto
request
=
std
::
make_shared
<
Request
>
(
*
Manager
::
instance
().
ioContext
(),
url
,
logger_
);
auto
reqid
=
request
->
id
();
restinio
::
http_request_header_t
header
;
header
.
method
(
restinio
::
http_method_get
());
request
->
set_header
(
header
);
request
->
set_target
(
PATH_DEVICE
S
+
"?username="
+
creds_
->
username
);
request
->
set_target
(
PATH_DEVICE
+
"?username="
+
creds_
->
username
);
request
->
set_auth
(
creds_
->
username
,
creds_
->
password
);
setHeaderFields
(
*
request
);
request
->
add_on_state_change_callback
([
reqid
,
onAsync
=
onAsync_
]
(
Request
::
State
state
,
const
dht
::
http
::
Response
&
response
){
onAsync
([
reqid
,
state
,
response
]
(
AccountManager
&
accountManager
)
{
JAMI_
ERR
(
"[Auth] Got
server response:
%d"
,
(
int
)
state
);
JAMI_
DBG
(
"[Auth] Got
request callback with state=
%d"
,
(
int
)
state
);
auto
&
this_
=
*
static_cast
<
ServerAccountManager
*>
(
&
accountManager
);
if
(
state
!=
Request
::
State
::
DONE
)
return
;
...
...
@@ -253,6 +253,64 @@ ServerAccountManager::syncDevices()
requests_
[
reqid
]
=
std
::
move
(
request
);
}
bool
ServerAccountManager
::
revokeDevice
(
const
std
::
string
&
password
,
const
std
::
string
&
device
,
RevokeDeviceCallback
cb
)
{
if
(
not
info_
){
if
(
cb
)
cb
(
RevokeDeviceResult
::
ERROR_CREDENTIALS
);
return
false
;
}
const
std
::
string
url
=
managerHostname_
+
PATH_DEVICE
+
"?deviceId="
+
device
;
JAMI_WARN
(
"[Revoke] Removing device of %s at %s"
,
info_
->
username
.
c_str
(),
url
.
c_str
());
auto
request
=
std
::
make_shared
<
Request
>
(
*
Manager
::
instance
().
ioContext
(),
url
,
logger_
);
auto
reqid
=
request
->
id
();
restinio
::
http_request_header_t
header
;
header
.
method
(
restinio
::
http_method_delete
());
request
->
set_header
(
header
);
request
->
set_target
(
PATH_DEVICE
+
"?deviceId="
+
device
);
request
->
set_auth
(
info_
->
username
,
password
);
setHeaderFields
(
*
request
);
request
->
add_on_state_change_callback
([
reqid
,
cb
,
onAsync
=
onAsync_
]
(
Request
::
State
state
,
const
dht
::
http
::
Response
&
response
){
onAsync
([
reqid
,
cb
,
state
,
response
]
(
AccountManager
&
accountManager
)
{
JAMI_DBG
(
"[Revoke] Got request callback with state=%d"
,
(
int
)
state
);
auto
&
this_
=
*
static_cast
<
ServerAccountManager
*>
(
&
accountManager
);
if
(
state
!=
Request
::
State
::
DONE
)
return
;
if
(
response
.
status_code
>=
200
||
response
.
status_code
<
300
)
{
if
(
response
.
body
.
empty
())
return
;
try
{
Json
::
Value
json
;
std
::
string
err
;
Json
::
CharReaderBuilder
rbuilder
;
auto
reader
=
std
::
unique_ptr
<
Json
::
CharReader
>
(
rbuilder
.
newCharReader
());
if
(
!
reader
->
parse
(
response
.
body
.
data
(),
response
.
body
.
data
()
+
response
.
body
.
size
(),
&
json
,
&
err
)){
JAMI_ERR
(
"[Revoke] Can't parse server response: %s"
,
err
.
c_str
());
}
JAMI_WARN
(
"[Revoke] Got server response: %s"
,
response
.
body
.
c_str
());
if
(
json
[
"errorDetails"
].
empty
()){
if
(
cb
)
cb
(
RevokeDeviceResult
::
SUCCESS
);
this_
.
syncDevices
();
}
}
catch
(
const
std
::
exception
&
e
)
{
JAMI_ERR
(
"Error when loading device list: %s"
,
e
.
what
());
}
}
else
if
(
cb
)
cb
(
RevokeDeviceResult
::
ERROR_NETWORK
);
this_
.
requests_
.
erase
(
reqid
);
});
});
JAMI_DBG
(
"[Revoke] Sending revoke device '%s' to JAMS"
,
device
.
c_str
());
request
->
send
();
requests_
[
reqid
]
=
std
::
move
(
request
);
return
false
;
}
void
ServerAccountManager
::
registerName
(
const
std
::
string
&
password
,
const
std
::
string
&
name
,
RegistrationCallback
cb
)
{
...
...
This diff is collapsed.
Click to expand it.
src/jamidht/server_account_manager.h
+
3
−
0
View file @
24540f64
/*
* Copyright (C) 2014-2019 Savoir-faire Linux Inc.
* Author : Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* Vsevolod Ivanov <vsevolod.ivanov@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
...
...
@@ -48,6 +49,8 @@ public:
void
syncDevices
()
override
;
bool
revokeDevice
(
const
std
::
string
&
password
,
const
std
::
string
&
device
,
RevokeDeviceCallback
cb
);
void
registerName
(
const
std
::
string
&
password
,
const
std
::
string
&
name
,
RegistrationCallback
cb
)
override
;
private
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment