From 6b6b67ee0d30439780b829bb3e9dd5b0efa881df Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Sun, 13 Jul 2025 20:41:38 +0200 Subject: init --- go.mod | 15 +++++++++++++ go.sum | 18 +++++++++++++++ main.go | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b805579 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module upspin-keyserver + +go 1.24.5 + +require upspin.io v0.1.0 + +require ( + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-cmp v0.6.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9429200 --- /dev/null +++ b/go.sum @@ -0,0 +1,18 @@ +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +upspin.io v0.1.0 h1:NlG9u7dnJdq2fwBdMcR7Rv+x38cLQcfSzHYyKV2FAt8= +upspin.io v0.1.0/go.mod h1:qnNQxNH3d9hKrp+IBKEyins4nkq4vGNTiHG6U5KC+KY= diff --git a/main.go b/main.go new file mode 100644 index 0000000..2570c08 --- /dev/null +++ b/main.go @@ -0,0 +1,78 @@ +// Copyright 2016 The Upspin Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Keyserver is a wrapper for a key implementation that presents it as an HTTP +// interface. +package main // import "kesim.org/upspin-keyserver" + +import ( + "flag" + "os" + "path/filepath" + "strings" + + "upspin.io/flags" + "upspin.io/log" + "upspin.io/serverutil" + "upspin.io/serverutil/keyserver" + "upspin.io/upspin" + + // Load required transports + _ "upspin.io/key/transports" + + // Possible storage backends. + "upspin.io/cloud/https" + _ "upspin.io/cloud/storage/disk" +) + +var ( + keyDir = flag.String("keyDir", "", "initialize keys from this `directory`") +) + +func main() { + keyserver.Main(setupTestUser) + https.ListenAndServeFromFlags(nil) +} + +// setupTestUser uses the -test_user and -test_secrets flags to bootstrap the +// inprocess key server with an initial user. +func setupTestUser(key upspin.KeyServer) { + if *keyDir == "" { + log.Println("no keyDir provided") + return + } + + if flags.InsecureHTTP { + if !serverutil.IsLoopback(flags.HTTPAddr) { + log.Fatal("cannot use -keyDir flag on an insecure connection except on -http=localhost:port") + } + } + + entries, err := os.ReadDir(*keyDir) + if err != nil { + log.Fatalf("cannot open keyDir %q: %v", *keyDir, err) + } + + for _, entry := range entries { + name := entry.Name() + path := filepath.Join(*keyDir, name) + if !entry.IsDir() || !strings.Contains("@", name) { + continue + } + + pk, err := os.ReadFile(path) + if err != nil { + log.Fatalf("unable to read %q: %v", path, err) + } + userStruct := &upspin.User{ + Name: upspin.UserName(name), + PublicKey: upspin.PublicKey(string(pk)), + } + err = key.Put(userStruct) + if err != nil { + log.Fatalf("Put %q failed: %v", name, err) + } + log.Printf("Added user %q\n", name) + } +} -- cgit v1.2.3