Skip to content

Commit b172f7d

Browse files
author
Digital-Larry
authored
CTD-592 add access key login to connectd installer (#140)
* CTD-592 added access key login method to connectd_installer * CTD-592 more changes to support access key. Not done yet. * CTD-592-update URL for access key to production * CTD-592 updated changelog and version in control file * CTD-592 updating CI routines to add access key/secret test * CTD-592-allow auto reg test to be skipped with env. variable * CTD-592 fixing CI test for access key * CTD-592 added sleep to login menu loop for debug * CTD-592 debugging CI * CTD-592 debugging CI * CTD-592 debugging CI * CTD-592 removed extra sleep statements * CTD-592 debugging CI some more * CTD-592 cleanup. bump versions, check dates * CTD-592 updated changelog and copyright notice and fixed connectd_register * CTD-592 little tweak on some curly brackets * CTD-592 fixed a typo * CTD-592 streamlined second pass of interactive test to save time * CTD-592 making calls to check_service_counts() consistent * CTD-592 added function run_test_and_check() * CTD-592 added keystroke file to "remove all" with access key login. * CTD-592 - build URL from $HOST and $URL_PATH * CTD-592 added back 4 inadvertently deleted lines * CTD-592 added missing "$"
1 parent 3d58652 commit b172f7d

File tree

11 files changed

+239
-83
lines changed

11 files changed

+239
-83
lines changed

connectd/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: connectd
2-
Version: 2.5.38
2+
Version: 2.6.39
33
Section: non-free/net
44
Priority: optional
55
Homepage: https://remote.it

connectd/usr/bin/connectd_installer

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
#
1010

1111
##### Settings #####
12-
VERSION=v2.0.5
12+
VERSION=v2.6.6
1313
AUTHOR="Gary Worsham"
14-
MODIFIED="April 13, 2019"
14+
MODIFIED="April 24, 2021"
1515

1616
USERNAME=""
1717
PASSWORD=""
18+
# access key and secret are available in account page and can be used
19+
# when user has Google login only
20+
ACCESSKEY=""
21+
KEYSECRET=""
1822
AUTHHASH="REPLACE_AUTHHASH"
1923
DEVELOPERKEY=""
2024
MAXSEL=6

connectd/usr/bin/connectd_library

Lines changed: 108 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
# attachment services for tcp listeners.
77
# Interactive and preconfigured modes supported.
88
#
9-
# Copyright (C) 2019-2020 remot3.it, Inc. All rights reserved.
9+
# Copyright (C) 2019-2021 remot3.it, Inc. All rights reserved.
1010

1111
##### Settings #####
12-
LIBVERSION=lib_v2.1.26
12+
LIBVERSION=lib_v2.6.29
1313
AUTHOR="Gary Worsham"
14-
LIBMODIFIED="November 10, 2020"
14+
LIBMODIFIED="April 24, 2021"
1515
GREPFLAGS=
1616
apikey="remote.it.developertoolsHW9iHnd"
1717

@@ -48,6 +48,19 @@ projectCreateURL="${apiMethod}${apiServer}${apiVersion}"/project/create
4848
projectFileLinkURL="${apiMethod}${apiServer}${apiVersion}"/project/provisioning
4949

5050
# ----------------------------------------
51+
# the variables in this section are used by the login by access key function only.
52+
key_alias=""
53+
secret_base64=""
54+
HOST="device.remote.it"
55+
URL_PATH="api/user/info"
56+
URL="https://${HOST}/${URL_PATH}"
57+
DATA=""
58+
VERB="GET"
59+
CONTENT_TYPE="application/json"
60+
LC_VERB=`echo "${VERB}" | tr '[:upper:]' '[:lower:]'`
61+
CONTENT_LENGTH=0
62+
#
63+
#
5164
##### End Settings #####
5265

5366
##### Version #####
@@ -983,22 +996,25 @@ askRegisterLogin()
983996
# printf "\n\n"
984997
printf "********************* Sign In Menu *********************\n"
985998
printf " \n"
986-
printf " 1) Sign in to your remote.it account \n"
987-
printf " 2) Exit \n"
999+
printf " 1) Sign in to your remote.it account with username and password \n"
1000+
printf " 2) Sign in to your remote.it account with access key and secret \n"
1001+
printf " 3) Exit \n"
9881002
printf " \n"
9891003
printf "********************************************************\n"
9901004
printf "* To create a remote.it account, please visit *\n"
9911005
printf "* https://remote.it *\n"
9921006
printf "********************************************************\n\n"
993-
994-
getNumRange 1 2 "Choose a menu selection"
1007+
getNumRange 1 3 "Choose a menu selection"
9951008
get_num="$getNumRangeValue"
9961009
debug "get_num: $get_num"
9971010

9981011
if [ "$get_num" = 1 ]; then
9991012
userLogin
10001013
testLogin
10011014
elif [ "$get_num" = 2 ]; then
1015+
userLogin key
1016+
debug "token: $token"
1017+
elif [ "$get_num" = 3 ]; then
10021018
if ask "Are you sure?"; then
10031019
exit 0
10041020
fi
@@ -1008,69 +1024,110 @@ askRegisterLogin()
10081024
######### End askRegisterLogin #########
10091025

10101026
######### Begin Portal Login #########
1011-
userLogin() #Portal login function
1027+
# if parameter "key" is passed in, then it uses access key and secret
1028+
# otherwise it uses account username and password.
1029+
#
1030+
userLogin()
10121031
{
1013-
# echo "connectd_library Username = $USERNAME Password = $PASSWORD"
1014-
1015-
if [ "$USERNAME" != "" ]; then
1016-
username="$USERNAME"
1017-
else
1018-
printf "Please enter your remote.it Username (e-mail address): \n"
1019-
read username
1020-
fi
1021-
if [ "$AUTHHASH" != "REPLACE_AUTHHASH" ]; then
1022-
authhash="$AUTHHASH"
1032+
# use access key and secret
1033+
1034+
if [ "$1" = "key" ]; then
1035+
if [ "$ACCESSKEY" != "" ]; then
1036+
key_alias="$ACCESSKEY"
1037+
else
1038+
printf "Please enter your remote.it access key: \n"
1039+
read key_alias
1040+
fi
1041+
if [ "$KEYSECRET" != "" ]; then
1042+
secret_base64="$KEYSECRET"
1043+
else
1044+
printf "Please enter your remote.it access key secret: \n"
1045+
read secret_base64
1046+
fi
1047+
# use account username and password
10231048
else
1024-
if [ "$PASSWORD" != "" ]; then
1025-
password="$PASSWORD"
1049+
if [ "$USERNAME" != "" ]; then
1050+
username="$USERNAME"
1051+
else
1052+
printf "Please enter your remote.it Username (e-mail address): \n"
1053+
read username
1054+
fi
1055+
if [ "$AUTHHASH" != "REPLACE_AUTHHASH" ]; then
1056+
authhash="$AUTHHASH"
10261057
else
1058+
if [ "$PASSWORD" != "" ]; then
1059+
password="$PASSWORD"
1060+
else
10271061
# use stty to suppress password, if stty exists.
1028-
if [ "$(which stty)" != "" ]; then
1029-
stty -echo
1030-
fi
1031-
printf "\nPlease enter your remote.it password: \n"
1032-
password=""
1033-
read password
1034-
if [ "$(which stty)" != "" ]; then
1035-
stty echo
1036-
fi
1037-
fi
1062+
if [ "$(which stty)" != "" ]; then
1063+
stty -echo
1064+
fi
1065+
printf "\nPlease enter your remote.it password: \n"
1066+
password=""
1067+
read password
1068+
if [ "$(which stty)" != "" ]; then
1069+
stty echo
1070+
fi
1071+
fi
1072+
fi
1073+
debug $username $password $authhash
10381074
fi
1039-
debug $username $password $authhash
10401075
signInAPI
10411076
}
10421077
######### End Portal Login #########
10431078

10441079
####### SignInAPI ###################
10451080
signInAPI()
10461081
{
1047-
debug "U:$username P:$password A:$authhash D:$apikey"
1048-
# if AUTHHASH is REPLACE_AUTHHASH it means user just wants to use password
1049-
if [ "$AUTHHASH" = "REPLACE_AUTHHASH" ]; then
1050-
resp=$(curl ${CURL_OPTS} 'POST' -H "apikey:$apikey" -H "Content-Type:application/json" -H "Cache-Control:no-cache" -d "{ \"username\" : \"$username\", \"password\" : \"$password\" }" "$loginURL" 2> "$TMP_DIR"/.curlerr)
1082+
if [ "$key_alias" != "" ]; then
1083+
DATE=$(LANG=en_US date "+%a, %d %b %Y %H:%M:%S %Z")
1084+
# note that the formatting of the SIGNING_STRING is critical and should not be changed.
1085+
SIGNING_STRING="(request-target): ${LC_VERB} /${URL_PATH}
1086+
host: ${HOST}
1087+
date: ${DATE}
1088+
content-type: ${CONTENT_TYPE}
1089+
content-length: ${CONTENT_LENGTH}"
1090+
SECRET=`echo ${secret_base64} | base64 --decode`
1091+
SIGNATURE=`echo -n "${SIGNING_STRING}" | openssl dgst -binary -sha256 -hmac "${SECRET}" | base64`
1092+
SIGNATURE_HEADER="Signature keyId=\"$key_alias\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"${SIGNATURE}\""
1093+
resp=$(curl -s -X ${VERB} -H "Authorization:${SIGNATURE_HEADER}" -H "apikey:${apikey}" -H "Date:${DATE}" -H "Content-Type:${CONTENT_TYPE}" ${URL} -d "${DATA}" --insecure 2> "$TMP_DIR"/.curlerr)
1094+
debug "Resp = $resp"
1095+
checkAPIResult "${URL}" "$resp"
1096+
status=$(jsonval "$resp" 'status')
1097+
if [ "$status" = 'true' ]; then
1098+
token=$(jsonval "$resp" "token")
1099+
debug "Login token: $token"
1100+
else
1101+
exit 1
1102+
fi
10511103
else
1104+
# if AUTHHASH is REPLACE_AUTHHASH it means user just wants to use password
1105+
if [ "$AUTHHASH" = "REPLACE_AUTHHASH" ]; then
1106+
resp=$(curl ${CURL_OPTS} 'POST' -H "apikey:$apikey" -H "Content-Type:application/json" -H "Cache-Control:no-cache" -d "{ \"username\" : \"$username\", \"password\" : \"$password\" }" "$loginURL" 2> "$TMP_DIR"/.curlerr)
1107+
else
10521108
resp=$(curl ${CURL_OPTS} 'POST' -H "apikey:$apikey" -H "Content-Type:application/json" -H "Cache-Control:no-cache" -d "{ \"username\" : \"$username\", \"authhash\" : \"$AUTHHASH\" }" "$loginAuthURL" 2> "$TMP_DIR"/.curlerr)
1053-
fi
1109+
fi
10541110
# checkAPIResult 'login' "$resp"
10551111

1056-
debug "Resp = $resp"
1057-
status=$(jsonval "$resp" 'status')
1058-
debug "Status = $status"
1059-
if [ "$status" = 'true' ]; then
1060-
token=$(jsonval "$resp" "token")
1061-
debug "Login token: $token"
1062-
else
1063-
noSuchUser=$(echo "$resp" | grep "missing user" | sed 's/"//g')
1112+
debug "Resp = $resp"
1113+
status=$(jsonval "$resp" 'status')
1114+
debug "Status = $status"
1115+
if [ "$status" = 'true' ]; then
1116+
token=$(jsonval "$resp" "token")
1117+
debug "Login token: $token"
1118+
else
1119+
noSuchUser=$(echo "$resp" | grep "missing user" | sed 's/"//g')
10641120
# look for [0102] api return for invalid login
1065-
loginFailed=$(echo "$resp" | grep "\[0102\]" | sed 's/"//g')
1066-
slimError=$(echo "$resp" | grep "Slim Application Error" | sed 's/"//g')
1121+
loginFailed=$(echo "$resp" | grep "\[0102\]" | sed 's/"//g')
1122+
slimError=$(echo "$resp" | grep "Slim Application Error" | sed 's/"//g')
10671123
# 404 is triggered when you enter some special character in e-mail. this specific search may fail if API
10681124
# "$apiServer" is moved
1069-
login404=$(echo "$resp" | grep "404 Page Not Found" | sed 's/"//g')
1070-
login400=$(echo "$resp" | grep "400 Bad Request" | sed 's/"//g')
1071-
apikeyerror=$(echo "$resp" | grep "The API application key is invalid" | sed 's/"//g')
1072-
devkeyerror=$(echo "$resp" | grep "api key failed validation" | sed 's/"//g')
1073-
debug "Login Error: $noSuchUser $loginFailed $slimError $login404 $login400 $apikeyerror $devkeyerror"
1125+
login404=$(echo "$resp" | grep "404 Page Not Found" | sed 's/"//g')
1126+
login400=$(echo "$resp" | grep "400 Bad Request" | sed 's/"//g')
1127+
apikeyerror=$(echo "$resp" | grep "The API application key is invalid" | sed 's/"//g')
1128+
devkeyerror=$(echo "$resp" | grep "api key failed validation" | sed 's/"//g')
1129+
debug "Login Error: $noSuchUser $loginFailed $slimError $login404 $login400 $apikeyerror $devkeyerror"
1130+
fi
10741131
fi
10751132
# invalid cert can happen if system date is set to before current date
10761133
invalidCert=$(grep "SSL certificate problem" "$TMP_DIR"/.curlerr)

connectd/usr/bin/connectd_register

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ DEBUG="1"
3535
USERNAME=""
3636
PASSWORD=""
3737
AUTHHASH="REPLACE_AUTHHASH"
38+
ACCESSKEY=""
39+
KEYSECRET=""
3840
APIKEY="remote.it.developertoolsHW9iHnd"
39-
41+
# set USEACCESSKEY=1 to use Access Key and Secret
42+
# Access Keys and secrets can be set in the Account area of the web portal at
43+
# https://remote.it
44+
# by default, USEACCESSKEY=0 and this script will use your account username and password.
45+
USEACCESSKEY=0
4046
#==================================================================================
4147
# include all of the registration functions
4248

@@ -55,15 +61,25 @@ main()
5561
exit 1
5662
fi
5763
#-----------------------------------------------------------------------
58-
59-
if [ "$1" != "" ]; then
60-
USERNAME=$1
61-
fi
62-
if [ "$2" != "" ]; then
63-
PASSWORD=$2
64+
if [ "$USEACCESSKEY" = "0" ]; then
65+
if [ "$1" != "" ]; then
66+
USERNAME=$1
67+
fi
68+
if [ "$2" != "" ]; then
69+
PASSWORD=$2
70+
fi
71+
userLogin
72+
testLogin
73+
else
74+
if [ "$1" != "" ]; then
75+
ACCESSKEY=$1
76+
fi
77+
if [ "$2" != "" ]; then
78+
KEYSECRET=$2
79+
fi
80+
userLogin key
81+
testLogin
6482
fi
65-
userLogin
66-
testLogin
6783

6884
# =============================================
6985
# $SERVICEBASENAME is the base name of all installed services installed
130 Bytes
Binary file not shown.

connectd/usr/share/doc/connectd/copyright

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Modified Work Copyright (C) 2018 remot3.it, Inc. <[email protected]>
77
License: MIT
88

99
Files: *
10-
Copyright (C) 2020 remot3.it, Inc. <[email protected]>
10+
Copyright (C) 2021 remot3.it, Inc. <[email protected]>
1111
License: BSD-3-Clause
1212

1313
Files: debian/*
14-
Copyright (C) 2020 remot3.it, Inc. <[email protected]>
14+
Copyright (C) 2021 remot3.it, Inc. <[email protected]>
1515
License: BSD-3-Clause
1616

1717
License: BSD-3-Clause

test/Auto_Registration/auto-test.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
# auto-test.sh
33
# script to test auto registration and present summary at end
44

5-
ver=2.1.14
6-
MODIFIED="June 21, 2020"
5+
ver=2.6.16
6+
MODIFIED="April 24, 2021"
77
SCRIPT_DIR="$(cd $(dirname $0) && pwd)"
88
TEST_DIR="$SCRIPT_DIR"
99

10+
# use the CI_SUPPRESS_AUTO_TEST environment variable to skip the auto test
11+
# because it takes a long time. During test development anyway.
12+
if [ "${CI_SUPPRESS_AUTO_TEST}" != "" ]; then
13+
exit 0
14+
fi
15+
16+
1017
sudo -E "$TEST_DIR"/auto-reg-test.sh | tee /tmp/auto-reg-result.txt
1118
grep "failed" /tmp/auto-reg-result.txt
1219
if [ $? -eq 0 ]; then
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2
2+
SERVICENAME-_ device
3+
1
4+
1
5+
y
6+
SERVICENAME-_ ssh
7+
5
8+
y
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2
2+
1
3+
2
4+
y
5+
SERVICENAME-web
6+
5
7+
y

0 commit comments

Comments
 (0)