Commit 6a1d17d2 authored by Heiko Reese's avatar Heiko Reese
Browse files

Implemented first version of emailtocert-API

parent 0e7b576f
......@@ -16,6 +16,7 @@ import (
"path/filepath"
"sort"
"strings"
"time"
)
const (
......@@ -139,9 +140,13 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) {
func emailtocertHandler(w http.ResponseWriter, r *http.Request) {
email := mux.Vars(r)["email"]
// retrieve all certs with that email
results := ccache.IndexEmail.Get(email)
// TODO: check expiration and revocation
//c.NotAfter.After(time.Now())
// only valid certs
results = results.Filter(
func(c *SearchableCert) bool {
return AllWatchers[WatchValid].Is(c.Serial, Valid) && c.NotAfter.After(time.Now())
})
w.Header().Set("cache-control", "no-store")
w.Header().Set("Content-Type", "application/json")
w.Write(results.JSONString(AllWatchers))
......@@ -188,7 +193,7 @@ func main() {
HandlerFunc(downloadHandler)
// add emailtocert handler
r.Path("/emailtocert/v1/{email:[0-9]+}").
r.Path("/emailtocert/v1/{email:.*@.*}").
Methods("GET").
HandlerFunc(emailtocertHandler)
......
......@@ -484,7 +484,7 @@ func (c *SearchableCert) JSONResult(watchers map[int]*AttributeState) *JSONResul
CAGeneration: *c.CAGeneration,
Type: TypeToName(c.Type),
Profile: "",
Expired: c.NotAfter.After(time.Now()),
Expired: c.NotAfter.Before(time.Now()),
Validity: ValidityToName(watchers[WatchValid].Get(c.Serial)),
Public: VisibilityToName(watchers[WatchVisibile].Get(c.Serial)),
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment