Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jws-inspect
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Go
jws-inspect
Commits
8f09e0bf
Commit
8f09e0bf
authored
Oct 22, 2018
by
Erik Hedenström
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.go
+58
-0
58 additions, 0 deletions
main.go
test.jws
+2
-0
2 additions, 0 deletions
test.jws
with
60 additions
and
0 deletions
main.go
0 → 100644
+
58
−
0
View file @
8f09e0bf
package
main
import
(
"crypto"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
jose
"gopkg.in/square/go-jose.v1"
)
func
exitOnError
(
err
error
,
msg
string
)
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%s: %s
\n
"
,
msg
,
err
)
os
.
Exit
(
1
)
}
}
func
main
()
{
data
,
err
:=
ioutil
.
ReadAll
(
os
.
Stdin
)
exitOnError
(
err
,
"unable to read stdin"
)
jws
,
err
:=
jose
.
ParseSigned
(
string
(
data
))
exitOnError
(
err
,
"unable to parse signed JWS"
)
b
,
err
:=
jws
.
Verify
(
jws
.
Signatures
[
0
]
.
Header
.
JsonWebKey
)
exitOnError
(
err
,
"unable to verify JWS"
)
fmt
.
Println
(
"---[ Payload ]-----------------------------------------------------"
)
fmt
.
Printf
(
"%s
\n
"
,
indent
(
b
))
fmt
.
Println
(
"---[ Signatures ]--------------------------------------------------"
)
for
_
,
signature
:=
range
jws
.
Signatures
{
jwk
:=
signature
.
Header
.
JsonWebKey
b
,
err
=
jwk
.
MarshalJSON
()
exitOnError
(
err
,
"unable to marshal JWK to JSON"
)
fmt
.
Printf
(
"SHA256 %s
\n
%s
\n
"
,
thumbprint
(
jwk
),
indent
(
b
))
}
}
func
indent
(
b
[]
byte
)
string
{
var
m
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
(
b
,
&
m
)
exitOnError
(
err
,
"payload is not JSON"
)
b
,
err
=
json
.
MarshalIndent
(
m
,
""
,
" "
)
exitOnError
(
err
,
"unable to marshal to JSON"
)
return
string
(
b
)
}
func
thumbprint
(
key
*
jose
.
JsonWebKey
)
string
{
b
,
err
:=
key
.
Thumbprint
(
crypto
.
SHA256
)
exitOnError
(
err
,
"unable to get thumbprint"
)
return
hex
.
EncodeToString
(
b
)
}
This diff is collapsed.
Click to expand it.
test.jws
0 → 100644
+
2
−
0
View file @
8f09e0bf
eyJhbGciOiJFUzI1NiIsImp3ayI6eyJrdHkiOiJFQyIsImNydiI6IlAtMjU2IiwieCI6Imw3N0lRVExQU2NuM3hXcHJYNnYwZ3I5bGtKUEMzdVpWT2k1ZHRmSDVOVUkiLCJ5IjoibHVCWXZ4b2t0QzlBUHdGUC1ZUy1mY01lWTR6bFp4T2M1ZkVCMVg3UGMtSSJ9LCJraWQiOiJUQlkxQy1TekJqLWZ0N3RtOGVIUUFfZFRiXzcwbVRhOXRQNXRfQXBFUmNNPSJ9.eyJAdHlwZSI6Imh0dHBzOi8vc2NoZW1hLmJyaWNrY2hhaW4uY29tL3YyL2NlcnRpZmljYXRlLmpzb24iLCJAdGltZXN0YW1wIjoiMjAxOC0wOS0xMVQxNDo0NDoxOC4wNDQ0NjJaIiwiaXNzdWVyIjp7Imt0eSI6IkVDIiwia2lkIjoiVEJZMUMtU3pCai1mdDd0bThlSFFBX2RUYl83MG1UYTl0UDV0X0FwRVJjTT0iLCJjcnYiOiJQLTI1NiIsImFsZyI6IkVTMjU2IiwieCI6Imw3N0lRVExQU2NuM3hXcHJYNnYwZ3I5bGtKUEMzdVpWT2k1ZHRmSDVOVUkiLCJ5IjoibHVCWXZ4b2t0QzlBUHdGUC1ZUy1mY01lWTR6bFp4T2M1ZkVCMVg3UGMtSSJ9LCJzdWJqZWN0Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJhbGciOiJFUzI1NiIsIngiOiJQOUpTdG5Pd2h1amQ0TmV6X1oxNDlaOHQ4enlFN1h2MHV0eWUwTV93TnprIiwieSI6ImJDazFIYkJSaWVVTWFZWlN4UHpVY3hZUGdNanNLRjRZN1pDWVU2aEZhTkUifSwiZG9jdW1lbnRUeXBlcyI6WyJodHRwczovL3NjaGVtYS5icmlja2NoYWluLmNvbS92Mi9tYW5kYXRlLmpzb24iLCJodHRwczovL3NjaGVtYS5icmlja2NoYWluLmNvbS92Mi9hY3Rpb24tZGVzY3JpcHRvci5qc29uIl0sImtleUxldmVsIjoxMH0.dRhCTwbUv5g2k3PZ7fQEvJGXddJgH-ufVmeg9eHkcBJshpU6uiSk9ujvao53vRDpG25Z7RMhXHH102fubYLkGQ
\ No newline at end of file
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
sign in
to comment