2018-08-27 23:23:48 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-12-18 11:55:55 +00:00
|
|
|
"crypto/x509/pkix"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2018-08-27 23:23:48 +01:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2018-12-18 11:55:55 +00:00
|
|
|
"storj.io/storj/internal/fpath"
|
|
|
|
"storj.io/storj/pkg/peertls"
|
2018-08-27 23:23:48 +01:00
|
|
|
"storj.io/storj/pkg/process"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "identity",
|
|
|
|
Short: "Identity management",
|
|
|
|
}
|
|
|
|
|
2018-12-18 11:55:55 +00:00
|
|
|
defaultConfDir = fpath.ApplicationDir("storj", "identity")
|
2018-08-27 23:23:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
process.Exec(rootCmd)
|
|
|
|
}
|
2018-12-18 11:55:55 +00:00
|
|
|
|
|
|
|
func printExtensions(cert []byte, exts []pkix.Extension) error {
|
|
|
|
hash, err := peertls.SHA256Hash(cert)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
b64Hash, err := json.Marshal(hash)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("Cert hash: %s\n", b64Hash)
|
|
|
|
fmt.Println("Extensions:")
|
|
|
|
for _, e := range exts {
|
|
|
|
var data interface{}
|
|
|
|
switch e.Id.String() {
|
|
|
|
case peertls.ExtensionIDs[peertls.RevocationExtID].String():
|
|
|
|
var rev peertls.Revocation
|
|
|
|
if err := rev.Unmarshal(e.Value); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
data = rev
|
|
|
|
default:
|
|
|
|
data = e.Value
|
|
|
|
}
|
|
|
|
out, err := json.MarshalIndent(data, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("\t%s: %s\n", e.Id, out)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func backupPath(path string) string {
|
|
|
|
pathExt := filepath.Ext(path)
|
|
|
|
base := strings.TrimSuffix(path, pathExt)
|
|
|
|
return fmt.Sprintf(
|
|
|
|
"%s.%s%s",
|
|
|
|
base,
|
|
|
|
strconv.Itoa(int(time.Now().Unix())),
|
|
|
|
pathExt,
|
|
|
|
)
|
|
|
|
}
|