This repository has been archived by the owner on Nov 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.go
61 lines (57 loc) · 1.42 KB
/
app.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"fmt"
"github.com/yahoo/spartan-go"
"io/ioutil"
"os"
)
type ConfigParams struct {
PubKeyFile string `json:"pubkey"`
PrivKeyFile string `json:"privkey"`
URL string `json:"url"`
SkipVerify bool `json:"skip_verify"`
CaCert string `json:"cacert"`
Role string `json:"role"`
ASPubKeyFile string `json:"as_pubkey"`
}
func main() {
args := os.Args
if len(args) < 2 {
fmt.Println("Invalid number of arguments specified")
os.Exit(1)
}
jsonData, err := ioutil.ReadFile(args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
input := ConfigParams{}
err = json.Unmarshal(jsonData, &input)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
tokenOptions := &spartan.TokenOptions{PubKeyFile: input.PubKeyFile,
PrivKeyFile: input.PrivKeyFile,
URL: input.URL,
InsecureSkipVerify: input.SkipVerify,
CaCertFile: input.CaCert,
}
token, err := spartan.GetToken(input.Role, tokenOptions)
if err != nil {
fmt.Println("Unable to get token from AS")
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Token received from AS: " + token)
verifyOptions := &spartan.VerifyOptions{ASPubKeyFile: input.ASPubKeyFile,
Role: input.Role}
err = spartan.VerifyToken(token, verifyOptions)
if err != nil {
fmt.Println("verifyToken failed")
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Token verification using AS public key succeeded")
}