|
|
@ -1,9 +1,9 @@ |
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"crypto/tls" |
|
|
|
|
|
|
|
"bufio" |
|
|
|
"bufio" |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
|
|
|
|
"crypto/tls" |
|
|
|
"encoding/base64" |
|
|
|
"encoding/base64" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
@ -52,53 +52,54 @@ func NewProxyMessageListener(logger *log.Logger, iproxy *InterceptingProxy) *Mes |
|
|
|
l.AddHandler("closestorage", closeStorageHandler) |
|
|
|
l.AddHandler("closestorage", closeStorageHandler) |
|
|
|
l.AddHandler("setproxystorage", setProxyStorageHandler) |
|
|
|
l.AddHandler("setproxystorage", setProxyStorageHandler) |
|
|
|
l.AddHandler("liststorage", listProxyStorageHandler) |
|
|
|
l.AddHandler("liststorage", listProxyStorageHandler) |
|
|
|
|
|
|
|
l.AddHandler("setproxy", setProxyHandler) |
|
|
|
|
|
|
|
|
|
|
|
return l |
|
|
|
return l |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Message input structs
|
|
|
|
// Message input structs
|
|
|
|
type RequestJSON struct { |
|
|
|
type RequestJSON struct { |
|
|
|
DestHost string |
|
|
|
DestHost string |
|
|
|
DestPort int |
|
|
|
DestPort int |
|
|
|
UseTLS bool |
|
|
|
UseTLS bool |
|
|
|
Method string |
|
|
|
Method string |
|
|
|
Path string |
|
|
|
Path string |
|
|
|
ProtoMajor int |
|
|
|
ProtoMajor int |
|
|
|
ProtoMinor int |
|
|
|
ProtoMinor int |
|
|
|
Headers map[string][]string |
|
|
|
Headers map[string][]string |
|
|
|
Body string |
|
|
|
Body string |
|
|
|
Tags []string |
|
|
|
Tags []string |
|
|
|
|
|
|
|
|
|
|
|
StartTime int64 `json:"StartTime,omitempty"` |
|
|
|
StartTime int64 `json:"StartTime,omitempty"` |
|
|
|
EndTime int64 `json:"EndTime,omitempty"` |
|
|
|
EndTime int64 `json:"EndTime,omitempty"` |
|
|
|
|
|
|
|
|
|
|
|
Unmangled *RequestJSON `json:"Unmangled,omitempty"` |
|
|
|
Unmangled *RequestJSON `json:"Unmangled,omitempty"` |
|
|
|
Response *ResponseJSON `json:"Response,omitempty"` |
|
|
|
Response *ResponseJSON `json:"Response,omitempty"` |
|
|
|
WSMessages []*WSMessageJSON `json:"WSMessages,omitempty"` |
|
|
|
WSMessages []*WSMessageJSON `json:"WSMessages,omitempty"` |
|
|
|
DbId string `json:"DbId,omitempty"` |
|
|
|
DbId string `json:"DbId,omitempty"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type ResponseJSON struct { |
|
|
|
type ResponseJSON struct { |
|
|
|
ProtoMajor int |
|
|
|
ProtoMajor int |
|
|
|
ProtoMinor int |
|
|
|
ProtoMinor int |
|
|
|
StatusCode int |
|
|
|
StatusCode int |
|
|
|
Reason string |
|
|
|
Reason string |
|
|
|
|
|
|
|
|
|
|
|
Headers map[string][]string |
|
|
|
Headers map[string][]string |
|
|
|
Body string |
|
|
|
Body string |
|
|
|
|
|
|
|
|
|
|
|
Unmangled *ResponseJSON `json:"Unmangled,omitempty"` |
|
|
|
Unmangled *ResponseJSON `json:"Unmangled,omitempty"` |
|
|
|
DbId string |
|
|
|
DbId string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type WSMessageJSON struct { |
|
|
|
type WSMessageJSON struct { |
|
|
|
Message string |
|
|
|
Message string |
|
|
|
IsBinary bool |
|
|
|
IsBinary bool |
|
|
|
ToServer bool |
|
|
|
ToServer bool |
|
|
|
Timestamp int64 |
|
|
|
Timestamp int64 |
|
|
|
|
|
|
|
|
|
|
|
Unmangled *WSMessageJSON `json:"Unmangled,omitempty"` |
|
|
|
Unmangled *WSMessageJSON `json:"Unmangled,omitempty"` |
|
|
|
DbId string |
|
|
|
DbId string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (reqd *RequestJSON) Validate() error { |
|
|
|
func (reqd *RequestJSON) Validate() error { |
|
|
@ -162,7 +163,7 @@ func (reqd *RequestJSON) Parse() (*ProxyRequest, error) { |
|
|
|
req.EndDatetime = time.Unix(0, reqd.EndTime) |
|
|
|
req.EndDatetime = time.Unix(0, reqd.EndTime) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, tag := range(reqd.Tags) { |
|
|
|
for _, tag := range reqd.Tags { |
|
|
|
req.AddTag(tag) |
|
|
|
req.AddTag(tag) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -186,7 +187,7 @@ func (reqd *RequestJSON) Parse() (*ProxyRequest, error) { |
|
|
|
return req, nil |
|
|
|
return req, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewRequestJSON(req *ProxyRequest, headersOnly bool) (*RequestJSON) { |
|
|
|
func NewRequestJSON(req *ProxyRequest, headersOnly bool) *RequestJSON { |
|
|
|
|
|
|
|
|
|
|
|
newHeaders := make(map[string][]string) |
|
|
|
newHeaders := make(map[string][]string) |
|
|
|
for k, vs := range req.Header { |
|
|
|
for k, vs := range req.Header { |
|
|
@ -217,23 +218,23 @@ func NewRequestJSON(req *ProxyRequest, headersOnly bool) (*RequestJSON) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret := &RequestJSON{ |
|
|
|
ret := &RequestJSON{ |
|
|
|
DestHost: req.DestHost, |
|
|
|
DestHost: req.DestHost, |
|
|
|
DestPort: req.DestPort, |
|
|
|
DestPort: req.DestPort, |
|
|
|
UseTLS: req.DestUseTLS, |
|
|
|
UseTLS: req.DestUseTLS, |
|
|
|
Method: req.Method, |
|
|
|
Method: req.Method, |
|
|
|
Path: req.HTTPPath(), |
|
|
|
Path: req.HTTPPath(), |
|
|
|
ProtoMajor: req.ProtoMajor, |
|
|
|
ProtoMajor: req.ProtoMajor, |
|
|
|
ProtoMinor: req.ProtoMinor, |
|
|
|
ProtoMinor: req.ProtoMinor, |
|
|
|
Headers: newHeaders, |
|
|
|
Headers: newHeaders, |
|
|
|
Tags: req.Tags(), |
|
|
|
Tags: req.Tags(), |
|
|
|
|
|
|
|
|
|
|
|
StartTime: req.StartDatetime.UnixNano(), |
|
|
|
StartTime: req.StartDatetime.UnixNano(), |
|
|
|
EndTime: req.EndDatetime.UnixNano(), |
|
|
|
EndTime: req.EndDatetime.UnixNano(), |
|
|
|
|
|
|
|
|
|
|
|
Unmangled: unmangled, |
|
|
|
Unmangled: unmangled, |
|
|
|
Response: rsp, |
|
|
|
Response: rsp, |
|
|
|
WSMessages: wsms, |
|
|
|
WSMessages: wsms, |
|
|
|
DbId: req.DbId, |
|
|
|
DbId: req.DbId, |
|
|
|
} |
|
|
|
} |
|
|
|
if !headersOnly { |
|
|
|
if !headersOnly { |
|
|
|
ret.Body = base64.StdEncoding.EncodeToString(req.BodyBytes()) |
|
|
|
ret.Body = base64.StdEncoding.EncodeToString(req.BodyBytes()) |
|
|
@ -294,7 +295,7 @@ func (rspd *ResponseJSON) Parse() (*ProxyResponse, error) { |
|
|
|
return rsp, nil |
|
|
|
return rsp, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewResponseJSON(rsp *ProxyResponse, headersOnly bool) (*ResponseJSON) { |
|
|
|
func NewResponseJSON(rsp *ProxyResponse, headersOnly bool) *ResponseJSON { |
|
|
|
newHeaders := make(map[string][]string) |
|
|
|
newHeaders := make(map[string][]string) |
|
|
|
for k, vs := range rsp.Header { |
|
|
|
for k, vs := range rsp.Header { |
|
|
|
for _, v := range vs { |
|
|
|
for _, v := range vs { |
|
|
@ -317,10 +318,10 @@ func NewResponseJSON(rsp *ProxyResponse, headersOnly bool) (*ResponseJSON) { |
|
|
|
ProtoMajor: rsp.ProtoMajor, |
|
|
|
ProtoMajor: rsp.ProtoMajor, |
|
|
|
ProtoMinor: rsp.ProtoMinor, |
|
|
|
ProtoMinor: rsp.ProtoMinor, |
|
|
|
StatusCode: rsp.StatusCode, |
|
|
|
StatusCode: rsp.StatusCode, |
|
|
|
Reason: rsp.HTTPStatus(), |
|
|
|
Reason: rsp.HTTPStatus(), |
|
|
|
Headers: newHeaders, |
|
|
|
Headers: newHeaders, |
|
|
|
DbId: rsp.DbId, |
|
|
|
DbId: rsp.DbId, |
|
|
|
Unmangled: unmangled, |
|
|
|
Unmangled: unmangled, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !headersOnly { |
|
|
|
if !headersOnly { |
|
|
@ -359,18 +360,18 @@ func (wsmd *WSMessageJSON) Parse() (*ProxyWSMessage, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
retData := &ProxyWSMessage{ |
|
|
|
retData := &ProxyWSMessage{ |
|
|
|
Message: message, |
|
|
|
Message: message, |
|
|
|
Type: mtype, |
|
|
|
Type: mtype, |
|
|
|
Direction: Direction, |
|
|
|
Direction: Direction, |
|
|
|
Timestamp: time.Unix(0, wsmd.Timestamp), |
|
|
|
Timestamp: time.Unix(0, wsmd.Timestamp), |
|
|
|
Unmangled: unmangled, |
|
|
|
Unmangled: unmangled, |
|
|
|
DbId: wsmd.DbId, |
|
|
|
DbId: wsmd.DbId, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return retData, nil |
|
|
|
return retData, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewWSMessageJSON(wsm *ProxyWSMessage) (*WSMessageJSON) { |
|
|
|
func NewWSMessageJSON(wsm *ProxyWSMessage) *WSMessageJSON { |
|
|
|
isBinary := false |
|
|
|
isBinary := false |
|
|
|
if wsm.Type == websocket.BinaryMessage { |
|
|
|
if wsm.Type == websocket.BinaryMessage { |
|
|
|
isBinary = true |
|
|
|
isBinary = true |
|
|
@ -387,12 +388,12 @@ func NewWSMessageJSON(wsm *ProxyWSMessage) (*WSMessageJSON) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret := &WSMessageJSON{ |
|
|
|
ret := &WSMessageJSON{ |
|
|
|
Message: base64.StdEncoding.EncodeToString(wsm.Message), |
|
|
|
Message: base64.StdEncoding.EncodeToString(wsm.Message), |
|
|
|
IsBinary: isBinary, |
|
|
|
IsBinary: isBinary, |
|
|
|
ToServer: toServer, |
|
|
|
ToServer: toServer, |
|
|
|
Timestamp: wsm.Timestamp.UnixNano(), |
|
|
|
Timestamp: wsm.Timestamp.UnixNano(), |
|
|
|
Unmangled: unmangled, |
|
|
|
Unmangled: unmangled, |
|
|
|
DbId: wsm.DbId, |
|
|
|
DbId: wsm.DbId, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ret |
|
|
|
return ret |
|
|
@ -427,11 +428,11 @@ type successResult struct { |
|
|
|
/* |
|
|
|
/* |
|
|
|
Ping |
|
|
|
Ping |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
type pingMessage struct {} |
|
|
|
type pingMessage struct{} |
|
|
|
|
|
|
|
|
|
|
|
type pingResponse struct { |
|
|
|
type pingResponse struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
Ping string |
|
|
|
Ping string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func pingHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func pingHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
@ -448,7 +449,7 @@ type submitMessage struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type submitResponse struct { |
|
|
|
type submitResponse struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
SubmittedRequest *RequestJSON |
|
|
|
SubmittedRequest *RequestJSON |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -475,8 +476,8 @@ func submitHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Interceptin |
|
|
|
} |
|
|
|
} |
|
|
|
SaveNewRequest(storage, req) |
|
|
|
SaveNewRequest(storage, req) |
|
|
|
} |
|
|
|
} |
|
|
|
logger.Println("Submitting request to", req.FullURL(),"...") |
|
|
|
logger.Println("Submitting request to", req.FullURL(), "...") |
|
|
|
if err := req.Submit(); err != nil { |
|
|
|
if err := iproxy.SubmitRequest(req); err != nil { |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -504,7 +505,7 @@ type saveNewMessage struct { |
|
|
|
|
|
|
|
|
|
|
|
type saveNewResponse struct { |
|
|
|
type saveNewResponse struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
DbId string |
|
|
|
DbId string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func saveNewHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func saveNewHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
@ -540,7 +541,7 @@ func saveNewHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercepti |
|
|
|
|
|
|
|
|
|
|
|
response := &saveNewResponse{ |
|
|
|
response := &saveNewResponse{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
DbId: req.DbId, |
|
|
|
DbId: req.DbId, |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, response) |
|
|
|
MessageResponse(c, response) |
|
|
|
} |
|
|
|
} |
|
|
@ -549,10 +550,10 @@ func saveNewHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercepti |
|
|
|
QueryRequests |
|
|
|
QueryRequests |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
type storageQueryMessage struct { |
|
|
|
type storageQueryMessage struct { |
|
|
|
Query StrMessageQuery |
|
|
|
Query StrMessageQuery |
|
|
|
HeadersOnly bool |
|
|
|
HeadersOnly bool |
|
|
|
MaxResults int64 |
|
|
|
MaxResults int64 |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type storageQueryResult struct { |
|
|
|
type storageQueryResult struct { |
|
|
@ -562,9 +563,9 @@ type storageQueryResult struct { |
|
|
|
|
|
|
|
|
|
|
|
func storageQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func storageQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
mreq := storageQueryMessage{ |
|
|
|
mreq := storageQueryMessage{ |
|
|
|
Query: nil, |
|
|
|
Query: nil, |
|
|
|
HeadersOnly: false, |
|
|
|
HeadersOnly: false, |
|
|
|
MaxResults: 0, |
|
|
|
MaxResults: 0, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &mreq); err != nil { |
|
|
|
if err := json.Unmarshal(b, &mreq); err != nil { |
|
|
@ -658,10 +659,9 @@ func validateQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Inte |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
SetScope |
|
|
|
SetScope |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -690,7 +690,7 @@ func setScopeHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercept |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
@ -701,9 +701,9 @@ type viewScopeMessage struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type viewScopeResult struct { |
|
|
|
type viewScopeResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
IsCustom bool |
|
|
|
IsCustom bool |
|
|
|
Query StrMessageQuery |
|
|
|
Query StrMessageQuery |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func viewScopeHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func viewScopeHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
@ -712,7 +712,7 @@ func viewScopeHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
|
|
|
|
|
|
|
|
if scopeQuery == nil && scopeChecker != nil { |
|
|
|
if scopeQuery == nil && scopeChecker != nil { |
|
|
|
MessageResponse(c, &viewScopeResult{ |
|
|
|
MessageResponse(c, &viewScopeResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
IsCustom: true, |
|
|
|
IsCustom: true, |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
@ -726,9 +726,9 @@ func viewScopeHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &viewScopeResult{ |
|
|
|
MessageResponse(c, &viewScopeResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
IsCustom: false, |
|
|
|
IsCustom: false, |
|
|
|
Query: strQuery, |
|
|
|
Query: strQuery, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -737,8 +737,8 @@ Tag messages |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
type addTagMessage struct { |
|
|
|
type addTagMessage struct { |
|
|
|
ReqId string |
|
|
|
ReqId string |
|
|
|
Tag string |
|
|
|
Tag string |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -779,12 +779,12 @@ func addTagHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Interceptin |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type removeTagMessage struct { |
|
|
|
type removeTagMessage struct { |
|
|
|
ReqId string |
|
|
|
ReqId string |
|
|
|
Tag string |
|
|
|
Tag string |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -825,11 +825,11 @@ func removeTagHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type clearTagsMessage struct { |
|
|
|
type clearTagsMessage struct { |
|
|
|
ReqId string |
|
|
|
ReqId string |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -866,7 +866,7 @@ func clearTagHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercept |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
@ -874,12 +874,12 @@ Intercept |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
type interceptMessage struct { |
|
|
|
type interceptMessage struct { |
|
|
|
InterceptRequests bool |
|
|
|
InterceptRequests bool |
|
|
|
InterceptResponses bool |
|
|
|
InterceptResponses bool |
|
|
|
InterceptWS bool |
|
|
|
InterceptWS bool |
|
|
|
|
|
|
|
|
|
|
|
UseQuery bool |
|
|
|
UseQuery bool |
|
|
|
Query MessageQuery |
|
|
|
Query MessageQuery |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type intHandshakeResult struct { |
|
|
|
type intHandshakeResult struct { |
|
|
@ -891,49 +891,49 @@ var getNextIntId = IdCounter() |
|
|
|
|
|
|
|
|
|
|
|
type intRequest struct { |
|
|
|
type intRequest struct { |
|
|
|
// A request to have a message mangled
|
|
|
|
// A request to have a message mangled
|
|
|
|
Id int |
|
|
|
Id int |
|
|
|
Type string |
|
|
|
Type string |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
Result chan *intResponse `json:"-"` |
|
|
|
Result chan *intResponse `json:"-"` |
|
|
|
|
|
|
|
|
|
|
|
Request *RequestJSON `json:"Request,omitempty"` |
|
|
|
Request *RequestJSON `json:"Request,omitempty"` |
|
|
|
Response *ResponseJSON `json:"Response,omitempty"` |
|
|
|
Response *ResponseJSON `json:"Response,omitempty"` |
|
|
|
WSMessage *WSMessageJSON `json:"WSMessage,omitempty"` |
|
|
|
WSMessage *WSMessageJSON `json:"WSMessage,omitempty"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type intResponse struct { |
|
|
|
type intResponse struct { |
|
|
|
// response from the client with a mangled http request
|
|
|
|
// response from the client with a mangled http request
|
|
|
|
Id int |
|
|
|
Id int |
|
|
|
Dropped bool |
|
|
|
Dropped bool |
|
|
|
|
|
|
|
|
|
|
|
Request *RequestJSON `json:"Request,omitempty"` |
|
|
|
Request *RequestJSON `json:"Request,omitempty"` |
|
|
|
Response *ResponseJSON `json:"Response,omitempty"` |
|
|
|
Response *ResponseJSON `json:"Response,omitempty"` |
|
|
|
WSMessage *WSMessageJSON `json:"WSMessage,omitempty"` |
|
|
|
WSMessage *WSMessageJSON `json:"WSMessage,omitempty"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type intErrorMessage struct { |
|
|
|
type intErrorMessage struct { |
|
|
|
// a message template for sending an error to client if there is an error
|
|
|
|
// a message template for sending an error to client if there is an error
|
|
|
|
// with the mangled message they sent
|
|
|
|
// with the mangled message they sent
|
|
|
|
Id int |
|
|
|
Id int |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
Reason string |
|
|
|
Reason string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func intErrorResponse(id int, conn net.Conn, reason string) { |
|
|
|
func intErrorResponse(id int, conn net.Conn, reason string) { |
|
|
|
m := &intErrorMessage{ |
|
|
|
m := &intErrorMessage{ |
|
|
|
Id: id, |
|
|
|
Id: id, |
|
|
|
Success: false, |
|
|
|
Success: false, |
|
|
|
Reason: reason, |
|
|
|
Reason: reason, |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(conn, m) |
|
|
|
MessageResponse(conn, m) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func interceptHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func interceptHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
mreq := interceptMessage{ |
|
|
|
mreq := interceptMessage{ |
|
|
|
InterceptRequests: false, |
|
|
|
InterceptRequests: false, |
|
|
|
InterceptResponses: false, |
|
|
|
InterceptResponses: false, |
|
|
|
InterceptWS: false, |
|
|
|
InterceptWS: false, |
|
|
|
UseQuery: false, |
|
|
|
UseQuery: false, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &mreq); err != nil { |
|
|
|
if err := json.Unmarshal(b, &mreq); err != nil { |
|
|
@ -1002,9 +1002,9 @@ func interceptHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
|
|
|
|
|
|
|
|
// convert request data to an intRequest
|
|
|
|
// convert request data to an intRequest
|
|
|
|
intReq := &intRequest{ |
|
|
|
intReq := &intRequest{ |
|
|
|
Id: getNextIntId(), |
|
|
|
Id: getNextIntId(), |
|
|
|
Type: "httprequest", |
|
|
|
Type: "httprequest", |
|
|
|
Result: make(chan *intResponse), |
|
|
|
Result: make(chan *intResponse), |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
|
|
|
|
|
|
|
|
Request: reqData, |
|
|
|
Request: reqData, |
|
|
@ -1059,12 +1059,12 @@ func interceptHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
CleanRspJSON(rspData) |
|
|
|
CleanRspJSON(rspData) |
|
|
|
|
|
|
|
|
|
|
|
intReq := &intRequest{ |
|
|
|
intReq := &intRequest{ |
|
|
|
Id: getNextIntId(), |
|
|
|
Id: getNextIntId(), |
|
|
|
Type: "httpresponse", |
|
|
|
Type: "httpresponse", |
|
|
|
Result: make(chan *intResponse), |
|
|
|
Result: make(chan *intResponse), |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
|
|
|
|
|
|
|
|
Request: reqData, |
|
|
|
Request: reqData, |
|
|
|
Response: rspData, |
|
|
|
Response: rspData, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1124,15 +1124,14 @@ func interceptHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
rspData := NewResponseJSON(rsp, false) |
|
|
|
rspData := NewResponseJSON(rsp, false) |
|
|
|
CleanRspJSON(rspData) |
|
|
|
CleanRspJSON(rspData) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
intReq := &intRequest{ |
|
|
|
intReq := &intRequest{ |
|
|
|
Id: getNextIntId(), |
|
|
|
Id: getNextIntId(), |
|
|
|
Type: msgType, |
|
|
|
Type: msgType, |
|
|
|
Result: make(chan *intResponse), |
|
|
|
Result: make(chan *intResponse), |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
|
|
|
|
|
|
|
|
Request: reqData, |
|
|
|
Request: reqData, |
|
|
|
Response: rspData, |
|
|
|
Response: rspData, |
|
|
|
WSMessage: wsData, |
|
|
|
WSMessage: wsData, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1296,7 +1295,7 @@ func allSavedQueriesHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *In |
|
|
|
savedQueries := make([]*StrSavedQuery, 0) |
|
|
|
savedQueries := make([]*StrSavedQuery, 0) |
|
|
|
for _, q := range goQueries { |
|
|
|
for _, q := range goQueries { |
|
|
|
strSavedQuery := &StrSavedQuery{ |
|
|
|
strSavedQuery := &StrSavedQuery{ |
|
|
|
Name: q.Name, |
|
|
|
Name: q.Name, |
|
|
|
Query: nil, |
|
|
|
Query: nil, |
|
|
|
} |
|
|
|
} |
|
|
|
sq, err := GoQueryToStrQuery(q.Query) |
|
|
|
sq, err := GoQueryToStrQuery(q.Query) |
|
|
@ -1312,8 +1311,8 @@ func allSavedQueriesHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *In |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type saveQueryMessage struct { |
|
|
|
type saveQueryMessage struct { |
|
|
|
Name string |
|
|
|
Name string |
|
|
|
Query StrMessageQuery |
|
|
|
Query StrMessageQuery |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1358,17 +1357,17 @@ func saveQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type loadQueryMessage struct { |
|
|
|
type loadQueryMessage struct { |
|
|
|
Name string |
|
|
|
Name string |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type loadQueryResult struct { |
|
|
|
type loadQueryResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
Query StrMessageQuery |
|
|
|
Query StrMessageQuery |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func loadQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func loadQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
@ -1408,14 +1407,14 @@ func loadQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Intercep |
|
|
|
|
|
|
|
|
|
|
|
result := &loadQueryResult{ |
|
|
|
result := &loadQueryResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
Query: strQuery, |
|
|
|
Query: strQuery, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, result) |
|
|
|
MessageResponse(c, result) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type deleteQueryMessage struct { |
|
|
|
type deleteQueryMessage struct { |
|
|
|
Name string |
|
|
|
Name string |
|
|
|
Storage int |
|
|
|
Storage int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1442,7 +1441,7 @@ func deleteQueryHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Interc |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
@ -1450,10 +1449,10 @@ Listener management |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
type activeListener struct { |
|
|
|
type activeListener struct { |
|
|
|
Id int |
|
|
|
Id int |
|
|
|
Listener net.Listener `json:"-"` |
|
|
|
Listener net.Listener `json:"-"` |
|
|
|
Type string |
|
|
|
Type string |
|
|
|
Addr string |
|
|
|
Addr string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type addListenerMessage struct { |
|
|
|
type addListenerMessage struct { |
|
|
@ -1463,7 +1462,7 @@ type addListenerMessage struct { |
|
|
|
|
|
|
|
|
|
|
|
type addListenerResult struct { |
|
|
|
type addListenerResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
Id int |
|
|
|
Id int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var getNextMsgListenerId = IdCounter() |
|
|
|
var getNextMsgListenerId = IdCounter() |
|
|
@ -1500,10 +1499,10 @@ func addListenerHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Interc |
|
|
|
iproxy.AddListener(listener) |
|
|
|
iproxy.AddListener(listener) |
|
|
|
|
|
|
|
|
|
|
|
alistener := &activeListener{ |
|
|
|
alistener := &activeListener{ |
|
|
|
Id: getNextMsgListenerId(), |
|
|
|
Id: getNextMsgListenerId(), |
|
|
|
Listener: listener, |
|
|
|
Listener: listener, |
|
|
|
Type: mreq.Type, |
|
|
|
Type: mreq.Type, |
|
|
|
Addr: mreq.Addr, |
|
|
|
Addr: mreq.Addr, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
msgActiveListenersMtx.Lock() |
|
|
|
msgActiveListenersMtx.Lock() |
|
|
@ -1511,7 +1510,7 @@ func addListenerHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Interc |
|
|
|
msgActiveListeners[alistener.Id] = alistener |
|
|
|
msgActiveListeners[alistener.Id] = alistener |
|
|
|
result := &addListenerResult{ |
|
|
|
result := &addListenerResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
Id: alistener.Id, |
|
|
|
Id: alistener.Id, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, result) |
|
|
|
MessageResponse(c, result) |
|
|
@ -1538,11 +1537,10 @@ func removeListenerHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Int |
|
|
|
|
|
|
|
|
|
|
|
iproxy.RemoveListener(alistener.Listener) |
|
|
|
iproxy.RemoveListener(alistener.Listener) |
|
|
|
delete(msgActiveListeners, alistener.Id) |
|
|
|
delete(msgActiveListeners, alistener.Id) |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type getListenersMessage struct{} |
|
|
|
type getListenersMessage struct {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type getListenersResult struct { |
|
|
|
type getListenersResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
@ -1567,7 +1565,7 @@ Certificate Management |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
type loadCertificatesMessage struct { |
|
|
|
type loadCertificatesMessage struct { |
|
|
|
KeyFile string |
|
|
|
KeyFile string |
|
|
|
CertificateFile string |
|
|
|
CertificateFile string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1583,18 +1581,18 @@ func loadCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *I |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
caCert, err := tls.LoadX509KeyPair(mreq.CertificateFile, mreq.KeyFile) |
|
|
|
caCert, err := tls.LoadX509KeyPair(mreq.CertificateFile, mreq.KeyFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
iproxy.SetCACertificate(&caCert) |
|
|
|
iproxy.SetCACertificate(&caCert) |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type setCertificatesMessage struct { |
|
|
|
type setCertificatesMessage struct { |
|
|
|
KeyPEMData []byte |
|
|
|
KeyPEMData []byte |
|
|
|
CertificatePEMData []byte |
|
|
|
CertificatePEMData []byte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1610,23 +1608,23 @@ func setCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *In |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
caCert, err := tls.X509KeyPair(mreq.CertificatePEMData, mreq.KeyPEMData) |
|
|
|
caCert, err := tls.X509KeyPair(mreq.CertificatePEMData, mreq.KeyPEMData) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
ErrorResponse(c, err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
iproxy.SetCACertificate(&caCert) |
|
|
|
iproxy.SetCACertificate(&caCert) |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func clearCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func clearCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
iproxy.SetCACertificate(nil) |
|
|
|
iproxy.SetCACertificate(nil) |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type generateCertificatesMessage struct { |
|
|
|
type generateCertificatesMessage struct { |
|
|
|
KeyFile string |
|
|
|
KeyFile string |
|
|
|
CertFile string |
|
|
|
CertFile string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1639,13 +1637,13 @@ func generateCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iprox |
|
|
|
|
|
|
|
|
|
|
|
pair, err := GenerateCACerts() |
|
|
|
pair, err := GenerateCACerts() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, "error generating certificates: " + err.Error()) |
|
|
|
ErrorResponse(c, "error generating certificates: "+err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pkeyFile, err := os.OpenFile(mreq.KeyFile, os.O_RDWR|os.O_CREATE, 0600) |
|
|
|
pkeyFile, err := os.OpenFile(mreq.KeyFile, os.O_RDWR|os.O_CREATE, 0600) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, "could not save private key: " + err.Error()) |
|
|
|
ErrorResponse(c, "could not save private key: "+err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
pkeyFile.Write(pair.PrivateKeyPEM()) |
|
|
|
pkeyFile.Write(pair.PrivateKeyPEM()) |
|
|
@ -1656,7 +1654,7 @@ func generateCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iprox |
|
|
|
|
|
|
|
|
|
|
|
certFile, err := os.OpenFile(mreq.CertFile, os.O_RDWR|os.O_CREATE, 0600) |
|
|
|
certFile, err := os.OpenFile(mreq.CertFile, os.O_RDWR|os.O_CREATE, 0600) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, "could not save private key: " + err.Error()) |
|
|
|
ErrorResponse(c, "could not save private key: "+err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
certFile.Write(pair.CACertPEM()) |
|
|
|
certFile.Write(pair.CACertPEM()) |
|
|
@ -1665,12 +1663,12 @@ func generateCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, iprox |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type generatePEMCertificatesResult struct { |
|
|
|
type generatePEMCertificatesResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
KeyPEMData []byte |
|
|
|
KeyPEMData []byte |
|
|
|
CertificatePEMData []byte |
|
|
|
CertificatePEMData []byte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1683,13 +1681,13 @@ func generatePEMCertificatesHandler(b []byte, c net.Conn, logger *log.Logger, ip |
|
|
|
|
|
|
|
|
|
|
|
pair, err := GenerateCACerts() |
|
|
|
pair, err := GenerateCACerts() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, "error generating certificates: " + err.Error()) |
|
|
|
ErrorResponse(c, "error generating certificates: "+err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result := &generatePEMCertificatesResult{ |
|
|
|
result := &generatePEMCertificatesResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
KeyPEMData: pair.PrivateKeyPEM(), |
|
|
|
KeyPEMData: pair.PrivateKeyPEM(), |
|
|
|
CertificatePEMData: pair.CACertPEM(), |
|
|
|
CertificatePEMData: pair.CACertPEM(), |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, result) |
|
|
|
MessageResponse(c, result) |
|
|
@ -1700,12 +1698,12 @@ Storage functions |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
type addSQLiteStorageMessage struct { |
|
|
|
type addSQLiteStorageMessage struct { |
|
|
|
Path string |
|
|
|
Path string |
|
|
|
Description string |
|
|
|
Description string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type addSQLiteStorageResult struct { |
|
|
|
type addSQLiteStorageResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
StorageId int |
|
|
|
StorageId int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1723,13 +1721,13 @@ func addSQLiteStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *I |
|
|
|
|
|
|
|
|
|
|
|
storage, err := OpenSQLiteStorage(mreq.Path, logger) |
|
|
|
storage, err := OpenSQLiteStorage(mreq.Path, logger) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, "error opening SQLite databae: " + err.Error()) |
|
|
|
ErrorResponse(c, "error opening SQLite databae: "+err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sid := iproxy.AddMessageStorage(storage, mreq.Description) |
|
|
|
sid := iproxy.AddMessageStorage(storage, mreq.Description) |
|
|
|
result := &addSQLiteStorageResult{ |
|
|
|
result := &addSQLiteStorageResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
StorageId: sid, |
|
|
|
StorageId: sid, |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, result) |
|
|
|
MessageResponse(c, result) |
|
|
@ -1740,7 +1738,7 @@ type addInMemoryStorageMessage struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type addInMemoryStorageResult struct { |
|
|
|
type addInMemoryStorageResult struct { |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
StorageId int |
|
|
|
StorageId int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1753,13 +1751,13 @@ func addInMemoryStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy |
|
|
|
|
|
|
|
|
|
|
|
storage, err := InMemoryStorage(logger) |
|
|
|
storage, err := InMemoryStorage(logger) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ErrorResponse(c, "error creating in memory storage: " + err.Error()) |
|
|
|
ErrorResponse(c, "error creating in memory storage: "+err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sid := iproxy.AddMessageStorage(storage, mreq.Description) |
|
|
|
sid := iproxy.AddMessageStorage(storage, mreq.Description) |
|
|
|
result := &addInMemoryStorageResult{ |
|
|
|
result := &addInMemoryStorageResult{ |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
StorageId: sid, |
|
|
|
StorageId: sid, |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, result) |
|
|
|
MessageResponse(c, result) |
|
|
@ -1786,7 +1784,7 @@ func closeStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *Inter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
iproxy.CloseMessageStorage(mreq.StorageId) |
|
|
|
iproxy.CloseMessageStorage(mreq.StorageId) |
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type setProxyStorageMessage struct { |
|
|
|
type setProxyStorageMessage struct { |
|
|
@ -1811,17 +1809,17 @@ func setProxyStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *In |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success:true}) |
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type savedStorageJSON struct { |
|
|
|
type savedStorageJSON struct { |
|
|
|
Id int |
|
|
|
Id int |
|
|
|
Description string |
|
|
|
Description string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type listProxyStorageResult struct { |
|
|
|
type listProxyStorageResult struct { |
|
|
|
Storages []*savedStorageJSON |
|
|
|
Storages []*savedStorageJSON |
|
|
|
Success bool |
|
|
|
Success bool |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func listProxyStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
func listProxyStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
@ -1832,7 +1830,49 @@ func listProxyStorageHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *I |
|
|
|
} |
|
|
|
} |
|
|
|
result := &listProxyStorageResult{ |
|
|
|
result := &listProxyStorageResult{ |
|
|
|
Storages: storagesJSON, |
|
|
|
Storages: storagesJSON, |
|
|
|
Success: true, |
|
|
|
Success: true, |
|
|
|
} |
|
|
|
} |
|
|
|
MessageResponse(c, result) |
|
|
|
MessageResponse(c, result) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
SetProxy |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type setProxyMessage struct { |
|
|
|
|
|
|
|
UseProxy bool |
|
|
|
|
|
|
|
ProxyHost string |
|
|
|
|
|
|
|
ProxyPort int |
|
|
|
|
|
|
|
ProxyIsSOCKS bool |
|
|
|
|
|
|
|
UseCredentials bool |
|
|
|
|
|
|
|
Username string |
|
|
|
|
|
|
|
Password string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setProxyHandler(b []byte, c net.Conn, logger *log.Logger, iproxy *InterceptingProxy) { |
|
|
|
|
|
|
|
mreq := setProxyMessage{} |
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &mreq); err != nil { |
|
|
|
|
|
|
|
ErrorResponse(c, "error parsing message") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var creds *ProxyCredentials = nil |
|
|
|
|
|
|
|
if mreq.UseCredentials { |
|
|
|
|
|
|
|
creds = &ProxyCredentials{ |
|
|
|
|
|
|
|
Username: mreq.Username, |
|
|
|
|
|
|
|
Password: mreq.Password, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !mreq.UseProxy { |
|
|
|
|
|
|
|
iproxy.ClearUpstreamProxy() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if mreq.ProxyIsSOCKS { |
|
|
|
|
|
|
|
iproxy.SetUpstreamSOCKSProxy(mreq.ProxyHost, mreq.ProxyPort, creds) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
iproxy.SetUpstreamProxy(mreq.ProxyHost, mreq.ProxyPort, creds) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MessageResponse(c, &successResult{Success: true}) |
|
|
|
|
|
|
|
} |
|
|
|