Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SteamOS Devkit Service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
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
devkit
SteamOS Devkit Service
Commits
6095ad80
Commit
6095ad80
authored
3 years ago
by
Timothee Besset
Browse files
Options
Downloads
Patches
Plain Diff
use the better error response protocol
parent
19673648
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hooks/approve-ssh-key
+39
-27
39 additions, 27 deletions
hooks/approve-ssh-key
with
39 additions
and
27 deletions
hooks/approve-ssh-key
+
39
−
27
View file @
6095ad80
...
...
@@ -6,6 +6,7 @@ import logging
import
tempfile
from
urllib.parse
import
quote_plus
as
urllib_quote_plus
import
subprocess
import
json
ENABLE_SSHD
=
'
/usr/bin/steamos-polkit-helpers/steamos-enable-sshd
'
...
...
@@ -25,35 +26,46 @@ if __name__ == '__main__':
try
:
requestIP
=
sys
.
argv
[
2
]
except
NameError
:
logger
.
debu
g
(
'
request IP not given as argument to hook
'
)
logger
.
warnin
g
(
'
request IP not given as argument to hook
'
)
pass
if
os
.
environ
.
get
(
'
DEVKIT_BYPASS_STEAM_PROMPT
'
,
None
)
==
'
1
'
:
# Still using for the standalone dev-kit service application
logger
.
warning
(
'
Bypassing the Steam client approval - this is potentially insecure!
'
)
MAGIC_PHRASE
=
'
900b919520e4cf601998a71eec318fec
'
tokens
=
request
.
split
(
'
'
)
if
tokens
[
-
1
].
strip
(
'
\n
'
)
!=
MAGIC_PHRASE
:
raise
Exception
(
'
Invalid request
'
)
sys
.
exit
(
0
)
key_identifier
=
request
.
split
(
'
'
)[
2
]
request
=
f
'
Development host at IP
{
requestIP
}
key:
{
key_identifier
!r}
'
devkit_utils
.
validate_steam_client
()
with
tempfile
.
TemporaryDirectory
(
prefix
=
'
approve-ssh-key
'
)
as
tempdir
:
logger
.
debug
(
'
Issue approve-ssh-key request to the running Steam client
'
)
response
=
os
.
path
.
join
(
tempdir
,
'
response
'
)
cmd
=
'
approve-ssh-key?response={}&request={}
'
.
format
(
urllib_quote_plus
(
response
),
urllib_quote_plus
(
request
),
)
devkit_utils
.
execute_steam_client_command
(
cmd
)
with
devkit_utils
.
wait_on_file_response
(
response
,
timeout
=
30
)
as
f
:
logger
.
debug
(
'
Got response from Steam client
'
)
# Make sure sshd is enabled to support development features
if
os
.
path
.
exists
(
ENABLE_SSHD
):
subprocess
.
check_call
(
ENABLE_SSHD
)
else
:
subprocess
.
check_call
(
'
sudo systemctl enable --now sshd
'
,
shell
=
True
)
ret
=
{}
try
:
devkit_utils
.
validate_steam_client
()
except
devkit_utils
.
SteamClientNotRunningException
as
e
:
msg
=
'
Steam is not running
'
logger
.
warning
(
msg
)
ret
[
'
error
'
]
=
msg
else
:
with
tempfile
.
TemporaryDirectory
(
prefix
=
'
approve-ssh-key
'
)
as
tempdir
:
logger
.
info
(
'
Sending pairing request to Steam
'
)
response
=
os
.
path
.
join
(
tempdir
,
'
response
'
)
cmd
=
'
approve-ssh-key?response={}&request={}
'
.
format
(
urllib_quote_plus
(
response
),
urllib_quote_plus
(
request
),
)
devkit_utils
.
execute_steam_client_command
(
cmd
)
try
:
with
devkit_utils
.
wait_on_file_response
(
response
,
timeout
=
30
)
as
f
:
logger
.
debug
(
'
Got response from Steam client
'
)
# Make sure sshd is enabled to support development features
if
os
.
path
.
exists
(
ENABLE_SSHD
):
subprocess
.
check_call
(
ENABLE_SSHD
)
else
:
subprocess
.
check_call
(
'
sudo systemctl enable --now sshd
'
,
shell
=
True
)
except
devkit_utils
.
SteamResponse_Timeout
:
ret
[
'
error
'
]
=
'
timeout - Steam did not respond to the pairing request
'
except
devkit_utils
.
SteamResponse_Error
as
e
:
ret
[
'
error
'
]
=
e
.
error_response
# json dictionary response gets written to stdout
# NOTE: the devkit service unfortunately smashes stdout/stderr all together in a text response, but we can still work with that
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
print
(
json
.
dumps
(
ret
))
retcode
=
1
if
'
error
'
in
ret
else
0
sys
.
exit
(
retcode
)
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