Skip to content

Commit

Permalink
Use different endpoint for WhatsApp registration on Instagram
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Feb 12, 2024
1 parent 8987adf commit c861d54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions messagix/data/endpoints/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func makeFacebookEndpoints(host string) map[string]string {
"cookie_consent": baseURL + "/cookie/consent/",
"graphql": baseURL + "/api/graphql/",
"media_upload": baseURL + "/ajax/mercury/upload.php?",

"icdc_fetch": "https:/reg-e2ee.facebook.com/v2/fb_icdc_fetch",
"icdc_register": "https:/reg-e2ee.facebook.com/v2/fb_register_v2",
}
if host == messengerHost {
urls["messages"] = baseURL + "/"
Expand Down
3 changes: 3 additions & 0 deletions messagix/data/endpoints/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var InstagramEndpoints = map[string]string{
"cookie_consent": "https://graphql.instagram.com/graphql/",
"default_graphql": "https://graphql.instagram.com/graphql/",

"icdc_fetch": "https:/reg-e2ee.instagram.com/v2/fb_icdc_fetch",
"icdc_register": "https:/reg-e2ee.instagram.com/v2/fb_register_v2",

"media_upload": instaBaseUrl + "/ajax/mercury/upload.php?",

"web_login_page_v1": instaWebApiV1Url + "/login_page/",
Expand Down
14 changes: 7 additions & 7 deletions messagix/e2ee-register.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ type ICDCRegisterResponse struct {
WADeviceID int `json:"wa_device_id"`
}

func (c *Client) doE2EERequest(ctx context.Context, path string, body url.Values, into any) error {
url := "https://reg-e2ee.facebook.com" + path
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(body.Encode()))
func (c *Client) doE2EERequest(ctx context.Context, endpoint string, body url.Values, into any) error {
addr := c.getEndpoint(endpoint)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, addr, strings.NewReader(body.Encode()))
if err != nil {
return fmt.Errorf("failed to prepare request: %w", err)
}
Expand All @@ -88,7 +88,7 @@ func (c *Client) doE2EERequest(ctx context.Context, path string, body url.Values
req.Header.Set("origin", c.getEndpoint("base_url"))
req.Header.Set("referer", c.getEndpoint("messages")+"/")
zerolog.Ctx(ctx).Trace().
Str("url", url).
Str("url", addr).
Any("body", body).
Msg("ICDC request")
resp, err := c.http.Do(req)
Expand All @@ -98,7 +98,7 @@ func (c *Client) doE2EERequest(ctx context.Context, path string, body url.Values
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
logEvt := zerolog.Ctx(ctx).Trace().
Str("url", url).
Str("url", addr).
Int("status_code", resp.StatusCode)
if json.Valid(respBody) {
logEvt.RawJSON("response_body", respBody)
Expand All @@ -124,7 +124,7 @@ func (c *Client) fetchICDC(ctx context.Context, fbid int64, deviceUUID uuid.UUID
"device_id": {deviceUUID.String()},
}
var icdcResp ICDCFetchResponse
err := c.doE2EERequest(ctx, "/v2/fb_icdc_fetch", formBody, &icdcResp)
err := c.doE2EERequest(ctx, "icdc_fetch", formBody, &icdcResp)
return &icdcResp, err
}

Expand Down Expand Up @@ -207,7 +207,7 @@ func (c *Client) RegisterE2EE(ctx context.Context) error {
"ihash": {base64.StdEncoding.EncodeToString(calculateIdentitiesHash(deviceIdentities))},
}
var icdcResp ICDCRegisterResponse
err = c.doE2EERequest(ctx, "/v2/fb_register_v2", formBody, &icdcResp)
err = c.doE2EERequest(ctx, "icdc_register", formBody, &icdcResp)
if err != nil {
return err
} else if icdcResp.Status != 200 {
Expand Down

0 comments on commit c861d54

Please sign in to comment.