Skip to content

Commit

Permalink
Update project to have a somewhat working Signer proxy
Browse files Browse the repository at this point in the history
Quentin-M committed Mar 10, 2016
1 parent d759b4c commit 76d282f
Showing 2 changed files with 24 additions and 18 deletions.
12 changes: 3 additions & 9 deletions cmd/hmacproxy/main.go
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ package main

import (
"flag"
"net/http"
"net/http/httptest"
"net/url"
"os"

log "github.com/Sirupsen/logrus"
@@ -58,17 +58,11 @@ func main() {
proxyConfig.Signer.Key.Region,
}

signingDest, err := url.Parse("https://www.google.com")
signingProxy, err := hmacproxy.NewSigningProxy(signingCredential)
if err != nil {
log.Fatal(err)
}

signingProxy, err := hmacproxy.NewSigningProxy(signingDest, signingCredential)
if err != nil {
log.Fatal(err)
}
signingServer := httptest.NewServer(signingProxy)
defer signingServer.Close()
log.Fatal(http.ListenAndServe(proxyConfig.Signer.ListenerAddr, signingProxy))
}

if proxyConfig.Verifier != nil {
30 changes: 21 additions & 9 deletions handlers.go
Original file line number Diff line number Diff line change
@@ -15,23 +15,35 @@
package hmacproxy

import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"

"github.com/coreos-inc/hmacproxy/credential"
"github.com/elazarl/goproxy"
)

// NewSigningProxy instantiates a new signing proxy with the target url and the
// statc credential specified.
func NewSigningProxy(target *url.URL, cred credential.Credential) (*httputil.ReverseProxy, error) {
director := func(req *http.Request) {
log.Printf("Proxying request %v", req)
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
}
return &httputil.ReverseProxy{Director: director}, nil
// NewSigningProxy instantiates a new signing proxy with the static credential specified.
func NewSigningProxy(cred credential.Credential) (*goproxy.ProxyHttpServer, error) {
proxy := goproxy.NewProxyHttpServer()

proxy.OnRequest().DoFunc(
func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
if err := Sign4(r, cred); err != nil {
response := goproxy.NewResponse(
r,
goproxy.ContentTypeText,
http.StatusBadRequest,
fmt.Sprintf("Could not sign request: %v", err),
)
return r, response
}
return r, nil
})

return proxy, nil
}

// NewVerifyingProxy instantiates a new verifying proxy with the specified

0 comments on commit 76d282f

Please sign in to comment.