Skip to content

Commit

Permalink
Merge pull request #21 from jhaals/flags
Browse files Browse the repository at this point in the history
Migrate to command line flags
  • Loading branch information
jhaals committed Sep 2, 2018
2 parents 42b121f + 4a2f11a commit fd3bfc7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ RUN yarn install && yarn build
FROM gcr.io/distroless/base
COPY --from=app /yopass/cmd/yopass/yopass /
COPY --from=website /website/build /public
CMD ["/yopass"]
ENTRYPOINT ["/yopass"]
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Yopass - Share Secrets Securely

[![Build Status](https://travis-ci.org/jhaals/yopass.svg)](https://travis-ci.org/jhaals/yopass)
[![Go Report Card](https://goreportcard.com/badge/github.com/jhaals/yopass)](https://goreportcard.com/report/github.com/jhaals/yopass)

Yopass is a project for sharing secrets in a quick and secure manner*.
The sole purpose of Yopass is to minimize the amount of passwords floating around in ticket management systems, IRC logs and emails. The message is encrypted/decrypted locally in the browser and then sent to yopass without the decryption key which is only visible once to the user during encryption, yopass then returns a one-time URL with specified expiry date.
Expand All @@ -15,23 +16,20 @@ __[Demo available here](https://yopass.se)__. It's recommended to host your own
* Secrets self destruct after X hours

### Installation / Configuration

It's highly recommended to run TLS encryption using nginx/apache or the Golang built-in TLS server.

#### Docker

Start memcached to store secrets in memory

docker run --name memcached_yopass -d memcached

TLS encryption

docker run -p 1337:1337 -v /local/certs/:/certs -e TLS_CERT=/certs/tls.crt \
-e TLS_KEY=/certs/tls.key -e 'MEMCACHED=memcache:11211' --link memcached_yopass:memcache -d jhaals/yopass
docker run -p 1337:1337 -v /local/certs/:/certs \
--link memcached_yopass:memcache -d jhaals/yopass -memcached=memcache:11211 -tls.key=/certs/tls.key -tls.cert=/certs/tls.crt

Plain(make sure this is restricted to localhost)

docker run -p 1337:1337 -e 'MEMCACHED=memcache:11211' --link memcached_yopass:memcache -d jhaals/yopass


##### Install locally

go get github.com/jhaals/yopass
MEMCACHED=memcache:11211 go run yopass.go
docker run -p 1337:1337 --link memcached_yopass:memcache -d jhaals/yopass -memcached=memcache:11211
29 changes: 17 additions & 12 deletions cmd/yopass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ package main

import (
"crypto/tls"
"flag"
"fmt"
"log"
"net/http"
"os"

"github.com/jhaals/yopass/pkg/yopass"
)

func main() {
if os.Getenv("MEMCACHED") == "" {
log.Println("MEMCACHED environment variable must be specified")
os.Exit(1)
}
db := yopass.NewMemcached(os.Getenv("MEMCACHED"))
var (
memcached = flag.String("memcached", "localhost:11211", "memcached address")
port = flag.Int("port", 1337, "yopass server port")
tlsCert = flag.String("tls.cert", "", "path to TLS certificate")
tlsKey = flag.String("tls.key", "", "path to TLS key")
)

log.Println("Starting yopass. Listening on port 1337")
if os.Getenv("TLS_CERT") != "" && os.Getenv("TLS_KEY") != "" {
func main() {
flag.Parse()
log.Printf("Starting yopass. Listening on port %d", *port)
addr := fmt.Sprintf(":%d", *port)
db := yopass.NewMemcached(*memcached)
if *tlsCert != "" && *tlsKey != "" {
server := &http.Server{
Addr: ":1337",
Addr: addr,
Handler: yopass.HTTPHandler(db),
TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12}}
log.Fatal(server.ListenAndServeTLS(os.Getenv("TLS_CERT"), os.Getenv("TLS_KEY")))
log.Fatal(server.ListenAndServeTLS(*tlsCert, *tlsKey))
} else {
log.Fatal(http.ListenAndServe(":1337", yopass.HTTPHandler(db)))
log.Fatal(http.ListenAndServe(addr, yopass.HTTPHandler(db)))
}
}
2 changes: 1 addition & 1 deletion pkg/yopass/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func GetSecret(w http.ResponseWriter, request *http.Request, db Database) {
w.Write(resp)
}

// HTTPHandler containg all routes
// HTTPHandler containing all routes
func HTTPHandler(db Database) http.Handler {
mx := mux.NewRouter()
// GET secret
Expand Down
2 changes: 1 addition & 1 deletion pkg/yopass/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (m Memcached) Get(key string) (string, error) {
return string(r.Value), nil
}

// Set key in Memcached
// Put key in Memcached
func (m Memcached) Put(key, value string, expiration int32) error {
return m.Client.Set(&memcache.Item{
Key: key,
Expand Down

0 comments on commit fd3bfc7

Please sign in to comment.