Exemplo n.º 1
0
func ValidateSignature(request *gottp.Request) bool {
	if config.Settings.Moire.SignRequests != true {
		return true
	}

	public_key, ok := request.GetArgument("public_key").(string)
	if !ok {
		request.Raise(gottp.HttpError{
			http.StatusPreconditionFailed,
			"public_key is a required parameter",
		})
		return false
	}

	private_key := signature.GetSecretKey(public_key)
	if private_key == "" {
		request.Raise(gottp.HttpError{
			http.StatusForbidden,
			"Invalid public_key supplied",
		})
		return false
	}

	timestamp, ok := request.GetArgument("timestamp").(string)
	if !ok {
		request.Raise(gottp.HttpError{
			http.StatusPreconditionFailed,
			"timestamp is a required parameter",
		})
		return false
	}

	sign, ok := request.GetArgument("signature").(string)
	if !ok {
		request.Raise(gottp.HttpError{
			http.StatusPreconditionFailed,
			"signature is a required parameter",
		})
		return false
	}

	sign_error := signature.IsRequestValid(
		public_key,
		private_key,
		timestamp,
		sign,
		request.Request.URL.Path,
	)

	if sign_error != nil {
		request.Raise(gottp.HttpError{http.StatusNotFound, sign_error.Error()})
		return false
	}

	return true
}
Exemplo n.º 2
0
func makeSignatureURL(path string) string {
	public_key := "HelloWorldTest"
	private_key := signature.GetSecretKey(public_key)
	timestamp := time.Now().Format(time.RFC3339)

	sign := signature.MakeSignature(public_key, private_key, timestamp, path)

	values := url.Values{
		"signature":  {sign},
		"timestamp":  {timestamp},
		"public_key": {public_key},
	}

	sorted := values.Encode()
	escaped := strings.Replace(sorted, "+", "%20", -1)
	return path + "?" + escaped
}