-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcylance.sh
More file actions
executable file
·40 lines (31 loc) · 1.53 KB
/
Copy pathcylance.sh
File metadata and controls
executable file
·40 lines (31 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
TID="$CYLANCE_TID" # Cylance Tenant ID
APP_ID="$CYLANCE_APP_ID"
APP_SECRET="$CYLANCE_APP_SECRET"
REGION="$CYLANCE_REGION"
API_HOST="https://protectapi${REGION}.cylance.com"
AUTH_URL="${API_HOST}/auth/v2/token"
JTI_VAL=$(uuidgen)
TIMEOUT=1800
EPOCH_TIME=$(date +%s)
EPOCH_TIMEOUT=$(expr "$EPOCH_TIME" + "$TIMEOUT")
HEADER=$(echo -n '{"typ":"JWT","alg":"HS256"}' | /bin/base64 -w 0 | sed 's/+/-/g; s/\//_/g ; s/=\+$//g')
PAYLOAD=$(jq -n -c -r \
--argjson exp "$EPOCH_TIMEOUT" \
--argjson iat "$EPOCH_TIME" \
--arg iss "http://cylance.com" \
--arg sub "$APP_ID" \
--arg tid "$TID" \
--arg jti "$JTI_VAL" \
'{"exp": $exp,"iat": $iat,"iss": $iss,"sub": $sub,"tid": $tid,"jti": $jti}' \
| base64 -w 0 | sed 's/+/-/g; s/\//_/g; s/=\+$//g' )
SIGNATURE=$(echo -n "${HEADER}"."${PAYLOAD}" | openssl dgst -sha256 -hmac "${APP_SECRET}" -binary | openssl base64 -e -A | sed 's/+/-/g; s/\//_/g; s/=\+$//g')
TOKEN="${HEADER}.${PAYLOAD}.${SIGNATURE}"
CYLANCE_AUTH_TOKEN=$(jq -n -c \
--arg auth_token "$TOKEN" \
'{"auth_token": $auth_token}')
BEARER=$(curl -vv -s -X POST -H 'Content-Type: application/json; charset=utf-8' "$AUTH_URL" -d "$CYLANCE_AUTH_TOKEN" | jq -r .access_token)
# Example fetching some Device records from Cylance Protect API
PAGE=$(curl -s --location --request GET "${API_HOST}/devices/v2?page=1&page_size=200" \
--header 'Accept: application/json' \
--header "Authorization: Bearer ${BEARER}")