added /v1/rate-limit-challenge endpoint

see #456
This commit is contained in:
Bernhard B
2023-12-01 21:01:58 +01:00
parent 6f2fadf5ac
commit 13236b7c66
6 changed files with 208 additions and 3 deletions

View File

@@ -162,6 +162,11 @@ type AddDeviceRequest struct {
Uri string `json:"uri"`
}
type RateLimitChallengeRequest struct {
ChallengeToken string `json:"challenge_token" example:"<challenge token>"`
Captcha string `json:"captcha" example:"signalcaptcha://{captcha value}"`
}
type Api struct {
signalClient *client.SignalClient
}
@@ -1677,3 +1682,35 @@ func (a *Api) SendContacts(c *gin.Context) {
}
c.Status(http.StatusNoContent)
}
// @Summary Lift rate limit restrictions by solving a captcha.
// @Tags Accounts
// @Description When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The "challenge_token" is the token from the failed send attempt. The "captcha" is the captcha result, starting with signalcaptcha://
// @Accept json
// @Produce json
// @Param number path string true "Registered Phone Number"
// @Param data body RateLimitChallengeRequest true "Request"
// @Success 204
// @Failure 400 {object} Error
// @Router /v1/accounts/{number}/rate-limit-challenge [post]
func (a *Api) SubmitRateLimitChallenge(c *gin.Context) {
number := c.Param("number")
if number == "" {
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
return
}
var req RateLimitChallengeRequest
err := c.BindJSON(&req)
if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
return
}
err = a.signalClient.SubmitRateLimitChallenge(number, req.ChallengeToken, req.Captcha)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
c.Status(http.StatusNoContent)
}

View File

@@ -1797,3 +1797,23 @@ func (s *SignalClient) GetTrustMode(number string) utils.SignalCliTrustMode {
}
return trustMode
}
func (s *SignalClient) SubmitRateLimitChallenge(number string, challengeToken string, captcha string) error {
if s.signalCliMode == JsonRpc {
type Request struct {
Challenge string `json:"challenge"`
Captcha string `json:"captcha"`
}
request := Request{Challenge: challengeToken, Captcha: captcha}
jsonRpc2Client, err := s.getJsonRpc2Client()
if err != nil {
return err
}
_, err = jsonRpc2Client.getRaw("submitRateLimitChallenge", &number, request)
return err
} else {
cmd := []string{"--config", s.signalCliConfig, "-a", number, "submitRateLimitChallenge", "--challenge", challengeToken, "--captcha", captcha}
_, err := s.cliClient.Execute(true, cmd, "")
return err
}
}

View File

@@ -47,7 +47,7 @@ var doc = `{
},
"/v1/accounts": {
"get": {
"description": "Lists all of the devices linked or registered",
"description": "Lists all of the accounts linked or registered",
"produces": [
"application/json"
],
@@ -74,6 +74,48 @@ var doc = `{
}
}
},
"/v1/accounts/{number}/rate-limit-challenge": {
"post": {
"description": "When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The \"challenge_token\" is the token from the failed send attempt. The \"captcha\" is the captcha result, starting with signalcaptcha://",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Accounts"
],
"summary": "Lift rate limit restrictions by solving a captcha.",
"parameters": [
{
"type": "string",
"description": "Registered Phone Number",
"name": "number",
"in": "path",
"required": true
},
{
"description": "Request",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.RateLimitChallengeRequest"
}
}
],
"responses": {
"204": {},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
},
"/v1/attachments": {
"get": {
"description": "List all downloaded attachments",
@@ -1779,6 +1821,19 @@ var doc = `{
}
}
},
"api.RateLimitChallengeRequest": {
"type": "object",
"properties": {
"captcha": {
"type": "string",
"example": "signalcaptcha://{captcha value}"
},
"challenge_token": {
"type": "string",
"example": "\u003cchallenge token\u003e"
}
}
},
"api.Reaction": {
"type": "object",
"properties": {

View File

@@ -31,7 +31,7 @@
},
"/v1/accounts": {
"get": {
"description": "Lists all of the devices linked or registered",
"description": "Lists all of the accounts linked or registered",
"produces": [
"application/json"
],
@@ -58,6 +58,48 @@
}
}
},
"/v1/accounts/{number}/rate-limit-challenge": {
"post": {
"description": "When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The \"challenge_token\" is the token from the failed send attempt. The \"captcha\" is the captcha result, starting with signalcaptcha://",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Accounts"
],
"summary": "Lift rate limit restrictions by solving a captcha.",
"parameters": [
{
"type": "string",
"description": "Registered Phone Number",
"name": "number",
"in": "path",
"required": true
},
{
"description": "Request",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.RateLimitChallengeRequest"
}
}
],
"responses": {
"204": {},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
},
"/v1/attachments": {
"get": {
"description": "List all downloaded attachments",
@@ -1763,6 +1805,19 @@
}
}
},
"api.RateLimitChallengeRequest": {
"type": "object",
"properties": {
"captcha": {
"type": "string",
"example": "signalcaptcha://{captcha value}"
},
"challenge_token": {
"type": "string",
"example": "\u003cchallenge token\u003e"
}
}
},
"api.Reaction": {
"type": "object",
"properties": {

View File

@@ -73,6 +73,15 @@ definitions:
Level:
type: string
type: object
api.RateLimitChallengeRequest:
properties:
captcha:
example: signalcaptcha://{captcha value}
type: string
challenge_token:
example: <challenge token>
type: string
type: object
api.Reaction:
properties:
reaction:
@@ -313,7 +322,7 @@ paths:
- General
/v1/accounts:
get:
description: Lists all of the devices linked or registered
description: Lists all of the accounts linked or registered
produces:
- application/json
responses:
@@ -330,6 +339,34 @@ paths:
summary: List all accounts
tags:
- Accounts
/v1/accounts/{number}/rate-limit-challenge:
post:
consumes:
- application/json
description: 'When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The "challenge_token" is the token from the failed send attempt. The "captcha" is the captcha result, starting with signalcaptcha://'
parameters:
- description: Registered Phone Number
in: path
name: number
required: true
type: string
- description: Request
in: body
name: data
required: true
schema:
$ref: '#/definitions/api.RateLimitChallengeRequest'
produces:
- application/json
responses:
"204": {}
"400":
description: Bad Request
schema:
$ref: '#/definitions/api.Error'
summary: Lift rate limit restrictions by solving a captcha.
tags:
- Accounts
/v1/attachments:
get:
description: List all downloaded attachments

View File

@@ -204,6 +204,7 @@ func main() {
accounts := v1.Group("accounts")
{
accounts.GET("", api.GetAccounts)
accounts.POST(":number/rate-limit-challenge", api.SubmitRateLimitChallenge)
}
devices := v1.Group("devices")