Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #41 from stellar/scott-fixes
Browse files Browse the repository at this point in the history
Random fixes and refactoring
  • Loading branch information
nullstyle authored Oct 4, 2016
2 parents 94b5101 + af06932 commit f0ef028
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"encoding/base64"
"encoding/hex"
"encoding/json"
log "github.com/Sirupsen/logrus"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"

log "github.com/Sirupsen/logrus"

"github.com/stellar/gateway/db/entities"
"github.com/stellar/gateway/protocols"
"github.com/stellar/gateway/protocols/compliance"
Expand All @@ -26,10 +27,10 @@ import (

// HandlerAuth implements authorize endpoint
func (rh *RequestHandler) HandlerAuth(c web.C, w http.ResponseWriter, r *http.Request) {
request := &compliance.AuthRequest{}
request.FromRequest(r)
authreq := &compliance.AuthRequest{}
authreq.FromRequest(r)

err := request.Validate()
err := authreq.Validate()
if err != nil {
errorResponse := err.(*protocols.ErrorResponse)
log.WithFields(errorResponse.LogData).Error(errorResponse.Error())
Expand All @@ -38,9 +39,9 @@ func (rh *RequestHandler) HandlerAuth(c web.C, w http.ResponseWriter, r *http.Re
}

var authData compliance.AuthData
err = json.Unmarshal([]byte(request.Data), &authData)
err = json.Unmarshal([]byte(authreq.Data), &authData)
if err != nil {
errorResponse := protocols.NewInvalidParameterError("data", request.Data)
errorResponse := protocols.NewInvalidParameterError("data", authreq.Data)
log.WithFields(errorResponse.LogData).Warn(errorResponse.Error())
server.Write(w, errorResponse)
return
Expand All @@ -61,21 +62,21 @@ func (rh *RequestHandler) HandlerAuth(c web.C, w http.ResponseWriter, r *http.Re
}

// Verify signature
signatureBytes, err := base64.StdEncoding.DecodeString(request.Signature)
signatureBytes, err := base64.StdEncoding.DecodeString(authreq.Signature)
if err != nil {
errorResponse := protocols.NewInvalidParameterError("sig", request.Signature)
errorResponse := protocols.NewInvalidParameterError("sig", authreq.Signature)
log.WithFields(errorResponse.LogData).Warn("Error decoding signature")
server.Write(w, errorResponse)
return
}
err = rh.SignatureSignerVerifier.Verify(senderStellarToml.SigningKey, []byte(request.Data), signatureBytes)
err = rh.SignatureSignerVerifier.Verify(senderStellarToml.SigningKey, []byte(authreq.Data), signatureBytes)
if err != nil {
log.WithFields(log.Fields{
"signing_key": senderStellarToml.SigningKey,
"data": request.Data,
"sig": request.Signature,
"data": authreq.Data,
"sig": authreq.Signature,
}).Warn("Invalid signature")
errorResponse := protocols.NewInvalidParameterError("sig", request.Signature)
errorResponse := protocols.NewInvalidParameterError("sig", authreq.Signature)
server.Write(w, errorResponse)
return
}
Expand Down Expand Up @@ -351,7 +352,7 @@ func (rh *RequestHandler) HandlerAuth(c web.C, w http.ResponseWriter, r *http.Re
Memo: base64.StdEncoding.EncodeToString(memoBytes[:]),
TransactionXdr: authData.Tx,
AuthorizedAt: time.Now(),
Data: request.Data,
Data: authreq.Data,
}
err = rh.EntityManager.Persist(authorizedTransaction)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
log "github.com/Sirupsen/logrus"
"io/ioutil"
"net/http"

log "github.com/Sirupsen/logrus"
"github.com/stellar/gateway/protocols"
"github.com/stellar/gateway/protocols/compliance"
"github.com/stellar/gateway/protocols/memo"
Expand Down Expand Up @@ -143,7 +143,7 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re
memoPreimage := &memo.Memo{
Transaction: memo.Transaction{
SenderInfo: senderInfo,
Route: request.Destination,
Route: destinationObject.Memo,
Extra: request.ExtraMemo,
},
}
Expand Down Expand Up @@ -182,7 +182,6 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re
server.Write(w, protocols.InternalServerError)
return
}

sig, err := rh.SignatureSignerVerifier.Sign(rh.Config.Keys.SigningSeed, data)
if err != nil {
log.Error("Error signing authData")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ func TestRequestHandlerSend(t *testing.T) {
"bob*stellar.org",
).Return(federation.Response{
AccountID: "GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE",
MemoType: "text",
Memo: "bob",
}, stellartoml.StellarToml{
AuthServer: authServer,
}, nil).Once()

transactionXdr := "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANGzcuG2Z4WMLeEJJfEHFImaPhGJrZklOKsbdZFw+6kIwAAAAEAAAAAAAAAAQAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAFVU0QAAAAAABlS/NwyRcB9LCpsugCICWA+xnsYg9GLs0jIqAQgFDicAAAAAAvrwgAAAAAA"
data := "{\"sender\":\"alice*stellar.org\",\"need_info\":false,\"tx\":\"" + transactionXdr + "\",\"memo\":\"{\\n \\\"transaction\\\": {\\n \\\"sender_info\\\": \\\"{\\\\\\\"name\\\\\\\": \\\\\\\"Alice Doe\\\\\\\"}\\\",\\n \\\"route\\\": \\\"bob*stellar.org\\\",\\n \\\"extra\\\": \\\"hello world\\\",\\n \\\"note\\\": \\\"\\\"\\n },\\n \\\"operations\\\": null\\n}\"}"
transactionXdr := "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANLw6drH5OZQsQFOcJZvFBrx8zFYFlryZWs/9cwBTVH5QAAAAEAAAAAAAAAAQAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAFVU0QAAAAAABlS/NwyRcB9LCpsugCICWA+xnsYg9GLs0jIqAQgFDicAAAAAAvrwgAAAAAA"
data := "{\"sender\":\"alice*stellar.org\",\"need_info\":false,\"tx\":\"" + transactionXdr + "\",\"memo\":\"{\\n \\\"transaction\\\": {\\n \\\"sender_info\\\": \\\"{\\\\\\\"name\\\\\\\": \\\\\\\"Alice Doe\\\\\\\"}\\\",\\n \\\"route\\\": \\\"bob\\\",\\n \\\"extra\\\": \\\"hello world\\\",\\n \\\"note\\\": \\\"\\\"\\n },\\n \\\"operations\\\": null\\n}\"}"
sig := "YeMlOYWNysyGBfsAe40z9dGgpRsKSQrqFIGAEsyJQ8osnXlLPynvJ2WQDGcBq2n5AA96YZdABhQz5ymqvxfQDw=="

authResponse := compliance.AuthResponse{
Expand Down Expand Up @@ -171,7 +173,7 @@ func TestRequestHandlerSend(t *testing.T) {
"info_status": "ok",
"tx_status": "ok"
},
"transaction_xdr": "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANGzcuG2Z4WMLeEJJfEHFImaPhGJrZklOKsbdZFw+6kIwAAAAEAAAAAAAAAAQAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAFVU0QAAAAAABlS/NwyRcB9LCpsugCICWA+xnsYg9GLs0jIqAQgFDicAAAAAAvrwgAAAAAA"
"transaction_xdr": "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANLw6drH5OZQsQFOcJZvFBrx8zFYFlryZWs/9cwBTVH5QAAAAEAAAAAAAAAAQAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAFVU0QAAAAAABlS/NwyRcB9LCpsugCICWA+xnsYg9GLs0jIqAQgFDicAAAAAAvrwgAAAAAA"
}`)
assert.Equal(t, expected, test.StringToJSONMap(responseString))
})
Expand All @@ -195,12 +197,14 @@ func TestRequestHandlerSend(t *testing.T) {
"bob*stellar.org",
).Return(federation.Response{
AccountID: "GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE",
MemoType: "text",
Memo: "bob",
}, stellartoml.StellarToml{
AuthServer: authServer,
}, nil).Once()

transactionXdr := "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANGzcuG2Z4WMLeEJJfEHFImaPhGJrZklOKsbdZFw+6kIwAAAAEAAAAAAAAAAgAAAAFVU0QAAAAAAEbpO2riZmlZMkHuBxUBYAAas3hWyo9VL1IOdnfXAVFBAAAAADuaygAAAAAAGVL83DJFwH0sKmy6AIgJYD7GexiD0YuzSMioBCAUOJwAAAABVVNEAAAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAAL68IAAAAAAgAAAAAAAAABRVVSAAAAAAALt4SwWfv1PIJvDRMenW0zu91YxZbphRFLA4O+gbAaigAAAAA="
data := "{\"sender\":\"alice*stellar.org\",\"need_info\":false,\"tx\":\"" + transactionXdr + "\",\"memo\":\"{\\n \\\"transaction\\\": {\\n \\\"sender_info\\\": \\\"{\\\\\\\"name\\\\\\\": \\\\\\\"Alice Doe\\\\\\\"}\\\",\\n \\\"route\\\": \\\"bob*stellar.org\\\",\\n \\\"extra\\\": \\\"hello world\\\",\\n \\\"note\\\": \\\"\\\"\\n },\\n \\\"operations\\\": null\\n}\"}"
transactionXdr := "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANLw6drH5OZQsQFOcJZvFBrx8zFYFlryZWs/9cwBTVH5QAAAAEAAAAAAAAAAgAAAAFVU0QAAAAAAEbpO2riZmlZMkHuBxUBYAAas3hWyo9VL1IOdnfXAVFBAAAAADuaygAAAAAAGVL83DJFwH0sKmy6AIgJYD7GexiD0YuzSMioBCAUOJwAAAABVVNEAAAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAAL68IAAAAAAgAAAAAAAAABRVVSAAAAAAALt4SwWfv1PIJvDRMenW0zu91YxZbphRFLA4O+gbAaigAAAAA="
data := "{\"sender\":\"alice*stellar.org\",\"need_info\":false,\"tx\":\"" + transactionXdr + "\",\"memo\":\"{\\n \\\"transaction\\\": {\\n \\\"sender_info\\\": \\\"{\\\\\\\"name\\\\\\\": \\\\\\\"Alice Doe\\\\\\\"}\\\",\\n \\\"route\\\": \\\"bob\\\",\\n \\\"extra\\\": \\\"hello world\\\",\\n \\\"note\\\": \\\"\\\"\\n },\\n \\\"operations\\\": null\\n}\"}"
sig := "ACamNqa0dF8gf97URhFVKWSD7fmvZKc5At+8dCLM5ySR0HsHySF3G2WuwYP2nKjeqjKmu3U9Z3+u1P10w1KBCA=="

authResponse := compliance.AuthResponse{
Expand Down Expand Up @@ -240,7 +244,7 @@ func TestRequestHandlerSend(t *testing.T) {
"info_status": "ok",
"tx_status": "ok"
},
"transaction_xdr": "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANGzcuG2Z4WMLeEJJfEHFImaPhGJrZklOKsbdZFw+6kIwAAAAEAAAAAAAAAAgAAAAFVU0QAAAAAAEbpO2riZmlZMkHuBxUBYAAas3hWyo9VL1IOdnfXAVFBAAAAADuaygAAAAAAGVL83DJFwH0sKmy6AIgJYD7GexiD0YuzSMioBCAUOJwAAAABVVNEAAAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAAL68IAAAAAAgAAAAAAAAABRVVSAAAAAAALt4SwWfv1PIJvDRMenW0zu91YxZbphRFLA4O+gbAaigAAAAA="
"transaction_xdr": "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAANLw6drH5OZQsQFOcJZvFBrx8zFYFlryZWs/9cwBTVH5QAAAAEAAAAAAAAAAgAAAAFVU0QAAAAAAEbpO2riZmlZMkHuBxUBYAAas3hWyo9VL1IOdnfXAVFBAAAAADuaygAAAAAAGVL83DJFwH0sKmy6AIgJYD7GexiD0YuzSMioBCAUOJwAAAABVVNEAAAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAAL68IAAAAAAgAAAAAAAAABRVVSAAAAAAALt4SwWfv1PIJvDRMenW0zu91YxZbphRFLA4O+gbAaigAAAAA="
}`)
assert.Equal(t, expected, test.StringToJSONMap(responseString))
})
Expand Down
4 changes: 2 additions & 2 deletions src/github.com/stellar/gateway/db/drivers/postgres/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CREATE TABLE ReceivedPayment (

CREATE TABLE SentTransaction (
id serial,
transaction_id varchar(64) NOT NULL,
status varchar(10) NOT NULL,
source varchar(56) NOT NULL,
submitted_at timestamp NOT NULL,
Expand Down
7 changes: 6 additions & 1 deletion src/github.com/stellar/gateway/protocols/federation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -54,7 +55,11 @@ func (r *Resolver) GetDestination(federationURL, address string) (response Respo
return
}

resp, err := http.Get(federationURL + "?type=name&q=" + address)
qstr := url.Values{}
qstr.Add("type", "name")
qstr.Add("q", address)

resp, err := http.Get(federationURL + "?" + qstr.Encode())
if err != nil {
return
}
Expand Down

0 comments on commit f0ef028

Please sign in to comment.