Skip to content

Commit

Permalink
Outsource appId encoding/decoding to go.sandstorm
Browse files Browse the repository at this point in the history
  • Loading branch information
zenhack committed Jul 24, 2020
1 parent 04cf699 commit f800fe9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 140 deletions.
18 changes: 6 additions & 12 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/binary"
"flag"
"os"

"zenhack.net/go/sandstorm/exp/spk"
)

type PkgDefParams struct {
Expand All @@ -27,26 +29,18 @@ func randU64() uint64 {
func initCmd() {
flag.Parse()

keyFile, err := GenerateKey()
key, err := spk.GenerateKey(nil)
chkfatal("Generating a key", err)

pubKey, err := keyFile.PublicKey()
appId, err := key.AppId()
chkfatal("Getting public key", err)

params := &PkgDefParams{
AppId: SandstormBase32Encoding.EncodeToString(pubKey),
AppId: appId.String(),
SchemaId: randU64() | (1 << 63),
}

keyBytes, err := keyFile.Struct.Message().Marshal()
chkfatal("Serializing app key", err)

keyringFile, err := os.OpenFile(*keyringPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
chkfatal("Opening the keyring for writing", err)
defer keyringFile.Close()

_, err = keyringFile.Write(keyBytes)
chkfatal("Saving the app key", err)
chkfatal("Saving the app key", key.AddToFile(*keyringPath))

pkgDefFile, err := os.Create("sandstorm-pkgdef.capnp")
chkfatal("Creating sandstorm-pkgdef.capnp", err)
Expand Down
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/base32"
"errors"
"flag"
"fmt"
Expand All @@ -10,11 +9,6 @@ import (
)

var (
// Sandstorm uses a custom base32 alphabet when displaying
// app-ids/public keys.
SandstormBase32Encoding = base32.NewEncoding("0123456789acdefghjkmnpqrstuvwxyz").
WithPadding(base32.NoPadding)

ErrNotADir = errors.New("Not a directory")
)

Expand Down
5 changes: 3 additions & 2 deletions pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ func doPack(pFlags *packFlags) {
metadata.appId = pFlags.altAppKey
}

appPubKey, err := SandstormBase32Encoding.DecodeString(metadata.appId)
var appId spk.AppId
err = (&appId).UnmarshalText([]byte(metadata.appId))
chkfatal("Parsing the app id", err)

appKey, err := keyring.GetKey(appPubKey)
appKey, err := keyring.GetKey(appId)
chkfatal("Fetching the app private key", err)

var archive capnp_spk.Archive
Expand Down
120 changes: 0 additions & 120 deletions sign.go

This file was deleted.

0 comments on commit f800fe9

Please sign in to comment.