Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ func newSignerFromKey(k interface{}) (Signer, error) {
var sKey Signer
switch t := k.(type) {
case *rsa.PrivateKey:
// we only support one type
sKey = &rsaPrivKey{t}
default:
return nil, fmt.Errorf("Unsupported key type %T", k)
}
return sKey, nil
}
Expand All @@ -86,9 +85,8 @@ func newVerifierFromKey(k interface{}) (Verifier, error) {
var vKey Verifier
switch t := k.(type) {
case *rsa.PublicKey:
// we only support one type
vKey = &rsaPubKey{t}
default:
return nil, fmt.Errorf("Unsupported key type %T", k)
}
return vKey, nil
}
Expand Down
31 changes: 30 additions & 1 deletion crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,39 @@ Z4UMR7EOcpfdUE9Hf3m/hs+FUR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJw
oYi+1hqp1fIekaxsyQIDAQAB
-----END PUBLIC KEY-----`)

dsaPriv := []byte(`-----BEGIN DSA PRIVATE KEY-----
MIIBugIBAAKBgQCFTFUQWTgWhHBq5XLVQxf9mGNT7sqpqkv7rIA6E0aPy5odjTQA
cfqUqsHNttB49D5QmnFRy/PnSMTQAED8g9wmoTpC9XzxxTLTi+kwlAqi+QVg9Nf3
at1JOCdB8rxs+fo0ZmIoxcCFzhu0Rj6gNBt0BGm8Zbf3+CLZifpEPrR6cQIVANxm
WDNNSyy3sZRnHczwco2C705nAoGAcFPgrax5XjvuBVW3ivvn8E2VarwyFynqddAB
0UppC/7aRraUsBDs1m75KpMFjZOeXJJdiYsdTPqTDhorYJxFJNNOgm5fsXVxQV/i
wmpVOz2nZwdYP7jKa4Ac9VepnHwGb9XfSPSzudhXOIBNPWTURFYxB9OkI9WGPeYy
b01E6LcCgYAxCP29/tLDPjWFvZ69JamAkSqmGuCbAfbNJBIzPRocSb2h+9o15T66
ir6x/EQSr9bTtuq/C2oUNqYsZLfEgz4mJs5DICsO/eHinFojtFXK4l2gx7gvBCj7
kb+15cKkEdR2Y2ExGMME5oGwR8rzLS4e/Rektm7qInSvwpRpXYJ9FgIUP3MfsD46
UAUi/vfPLqHFncZe5pM=
-----END DSA PRIVATE KEY-----`)

dsaPub := []byte(`-----BEGIN PUBLIC DSA KEY-----
MIIBtjCCASsGByqGSM44BAEwggEeAoGBAIVMVRBZOBaEcGrlctVDF/2YY1Puyqmq
S/usgDoTRo/Lmh2NNABx+pSqwc220Hj0PlCacVHL8+dIxNAAQPyD3CahOkL1fPHF
MtOL6TCUCqL5BWD01/dq3Uk4J0HyvGz5+jRmYijFwIXOG7RGPqA0G3QEabxlt/f4
ItmJ+kQ+tHpxAhUA3GZYM01LLLexlGcdzPByjYLvTmcCgYBwU+CtrHleO+4FVbeK
++fwTZVqvDIXKep10AHRSmkL/tpGtpSwEOzWbvkqkwWNk55ckl2Jix1M+pMOGitg
nEUk006Cbl+xdXFBX+LCalU7PadnB1g/uMprgBz1V6mcfAZv1d9I9LO52Fc4gE09
ZNREVjEH06Qj1YY95jJvTUTotwOBhAACgYAxCP29/tLDPjWFvZ69JamAkSqmGuCb
AfbNJBIzPRocSb2h+9o15T66ir6x/EQSr9bTtuq/C2oUNqYsZLfEgz4mJs5DICsO
/eHinFojtFXK4l2gx7gvBCj7kb+15cKkEdR2Y2ExGMME5oGwR8rzLS4e/Rektm7q
InSvwpRpXYJ9Fg==
-----END PUBLIC DSA KEY-----`)

toSign := "some string"
claim := sha1.Sum([]byte(toSign))

_, err := ParseRSAPrivatePEMKey([]byte("test"))
_, err = ParseRSAPublicPEMKey(dsaPub)
assert.Error(t, err)

_, err := ParseRSAPrivatePEMKey(dsaPriv)
assert.Error(t, err)

_, err = ParseRSAPrivatePEMKey([]byte(`-----BEGIN RSA PRIVATE KEY-----
Expand Down
11 changes: 10 additions & 1 deletion proxy-server/proxy-server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -65,7 +66,15 @@ func main() {
}
// Agent config
if len(os.Getenv("SOLIDPROXY_AGENTPORT")) > 0 {
configAgent.Port = os.Getenv("SOLIDPROXY_AGENTPORT") // default= :3200
// default= :3200
configAgent.Port = os.Getenv("SOLIDPROXY_AGENTPORT")
}
if len(os.Getenv("REQUEST_TIMEOUT")) > 0 {
// default=2s
tOut, err := fmt.Printf("%d", os.Getenv("REQUEST_TIMEOUT"))
if err == nil {
solidproxy.SetRequestTimeout(tOut)
}
}

// Create new agent
Expand Down
26 changes: 24 additions & 2 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package solidproxy
import (
"bytes"
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
"log"
Expand All @@ -23,7 +24,7 @@ var (

privateUris = map[string]bool{}
privateUrisL = new(sync.RWMutex)
requestTimeout = 2
requestTimeout = 3
)

// Proxy is a structure that encapsulates both clients (agent and fetcher), agent object and logger object.
Expand Down Expand Up @@ -139,6 +140,14 @@ func (p *Proxy) Handler(w http.ResponseWriter, req *http.Request) {
body, _ = ioutil.ReadAll(r.Body)
// Close body
r.Body.Close()

// clear cookie in case it expired
if r.StatusCode == 401 {
err = forgetCookie(req, user, cookiesL, cookies)
if err != nil {
p.Log.Println("Could not remove cookie.", err.Error())
}
}
}
}

Expand Down Expand Up @@ -180,7 +189,7 @@ func (p *Proxy) NewRequest(req *http.Request, body []byte, user string, authenti
}

request.Header.Set("On-Behalf-Of", user)
solutionMsg := "Retrying with credentials"
solutionMsg := "Retrying with WebID-TLS"

// Retry the request
if len(cookies[user]) > 0 && len(cookies[user][req.Host]) > 0 { // Use existing cookie
Expand All @@ -196,6 +205,7 @@ func (p *Proxy) NewRequest(req *http.Request, body []byte, user string, authenti
if err == nil {
request.Header.Set("Authorization", authz)
}
solutionMsg = "Retrying with WebID-RSA"
}
}

Expand Down Expand Up @@ -251,6 +261,18 @@ func forgetURI(uri string) bool {
return false
}

func forgetCookie(req *http.Request, user string, cookiesL *sync.RWMutex, cookies map[string]map[string][]*http.Cookie) error {
// Find if cookies exists
cookiesL.Lock()
if len(cookies[user]) > 0 && len(cookies[user][req.Host]) > 0 {
delete(cookies[user], req.Host)
cookiesL.Unlock()
return nil
}
cookiesL.Unlock()
return errors.New("No cookies found for user: " + user + " and host: " + req.Host)
}

func requiresAuth(uri string) bool {
if len(privateUris) > 0 && privateUris[uri] {
return true
Expand Down
Loading