irmameta.go 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
package main

import (
	"encoding/base64"
	"fmt"
	"math/big"
	"os"
	"time"

	"encoding/json"

	"github.com/mhe/gabi"
13
	"github.com/privacybydesign/irmago"
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
)

func main() {
	if len(os.Args) != 3 {
		fmt.Println("Usage: irmago metadata_attribute_in_decimal path_to_irma_configuration")
	}

	metaint, ok := new(big.Int).SetString(os.Args[1], 10)
	if !ok {
		fmt.Println("Could not parse argument as decimal integer:")
		os.Exit(1)
	}

	confpath := os.Args[2]
	conf, err := irma.NewConfiguration(confpath, "")
	if err != nil {
		fmt.Println("Failed to parse irma_configuration:", err)
		os.Exit(1)
	}
	err = conf.ParseFolder()
	if err != nil {
		fmt.Println("Failed to parse irma_configuration:", err)
		os.Exit(1)
	}

	meta := irma.MetadataFromInt(metaint, conf)
	typ := meta.CredentialType()
	var key *gabi.PublicKey

	if typ == nil {
		fmt.Println("Unknown credential type, hash:", base64.StdEncoding.EncodeToString(meta.CredentialTypeHash()))
	} else {
		fmt.Println("Identifier      :", typ.Identifier())
		key, err = meta.PublicKey()
		if err != nil {
			fmt.Println("Failed to parse public key", err)
		}
	}
	fmt.Println("Signed          :", meta.SigningDate().String())
	fmt.Println("Expires         :", meta.Expiry().String())
54
55
	fmt.Println("IsValid         :", meta.IsValid())
	fmt.Println("Version         :", meta.Version())
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
	fmt.Println("KeyCounter      :", meta.KeyCounter())
	if key != nil {
		fmt.Println("KeyExpires      :", time.Unix(key.ExpiryDate, 0))
		fmt.Println("KeyModulusBitlen:", key.N.BitLen())
	}

	fmt.Println()
	fmt.Println("CredentialType  :", prettyprint(typ))
}

func prettyprint(ob interface{}) string {
	b, err := json.MarshalIndent(ob, "", "  ")
	if err != nil {
		fmt.Println("error:", err)
	}
	return string(b)
}