mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-24 18:38:15 +01:00
Show challenge when requested by server
This commit is contained in:
@@ -306,7 +306,8 @@ function getContentType(response: Response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
type HeaderListType = { [name: string]: string };
|
||||
type FetchHeaderListType = { [name: string]: string };
|
||||
type HeaderListType = { [name: string]: string | ReadonlyArray<string> };
|
||||
type HTTPCodeType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
||||
|
||||
type RedactUrl = (url: string) => string;
|
||||
@@ -397,7 +398,7 @@ async function _promiseAjax(
|
||||
'User-Agent': getUserAgent(options.version),
|
||||
'X-Signal-Agent': 'OWD',
|
||||
...options.headers,
|
||||
} as HeaderListType,
|
||||
} as FetchHeaderListType,
|
||||
redirect: options.redirect,
|
||||
agent,
|
||||
ca: options.certificateAuthority,
|
||||
@@ -500,6 +501,7 @@ async function _promiseAjax(
|
||||
makeHTTPError(
|
||||
'promiseAjax: invalid response',
|
||||
response.status,
|
||||
response.headers.raw(),
|
||||
result,
|
||||
options.stack
|
||||
)
|
||||
@@ -563,6 +565,7 @@ async function _promiseAjax(
|
||||
makeHTTPError(
|
||||
'promiseAjax: error response',
|
||||
response.status,
|
||||
response.headers.raw(),
|
||||
result,
|
||||
options.stack
|
||||
)
|
||||
@@ -576,7 +579,7 @@ async function _promiseAjax(
|
||||
window.log.error(options.type, url, 0, 'Error');
|
||||
}
|
||||
const stack = `${e.stack}\nInitial stack:\n${options.stack}`;
|
||||
reject(makeHTTPError('promiseAjax catch', 0, e.toString(), stack));
|
||||
reject(makeHTTPError('promiseAjax catch', 0, {}, e.toString(), stack));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -614,6 +617,7 @@ declare global {
|
||||
interface Error {
|
||||
code?: number | string;
|
||||
response?: any;
|
||||
responseHeaders?: HeaderListType;
|
||||
warn?: boolean;
|
||||
}
|
||||
}
|
||||
@@ -621,6 +625,7 @@ declare global {
|
||||
function makeHTTPError(
|
||||
message: string,
|
||||
providedCode: number,
|
||||
headers: HeaderListType,
|
||||
response: any,
|
||||
stack?: string
|
||||
) {
|
||||
@@ -628,6 +633,7 @@ function makeHTTPError(
|
||||
const e = new Error(`${message}; code: ${code}`);
|
||||
e.name = 'HTTPError';
|
||||
e.code = code;
|
||||
e.responseHeaders = headers;
|
||||
if (DEBUG && response) {
|
||||
e.stack += `\nresponse: ${response}`;
|
||||
}
|
||||
@@ -670,6 +676,7 @@ const URL_CALLS = {
|
||||
supportUnauthenticatedDelivery: 'v1/devices/unauthenticated_delivery',
|
||||
updateDeviceName: 'v1/accounts/name',
|
||||
whoami: 'v1/accounts/whoami',
|
||||
challenge: 'v1/challenge',
|
||||
};
|
||||
|
||||
type InitializeOptionsType = {
|
||||
@@ -875,6 +882,7 @@ export type WebAPIType = {
|
||||
options: GroupCredentialsType
|
||||
) => Promise<string>;
|
||||
whoami: () => Promise<any>;
|
||||
sendChallengeResponse: (challengeResponse: ChallengeType) => Promise<any>;
|
||||
getConfig: () => Promise<
|
||||
Array<{ name: string; enabled: boolean; value: string | null }>
|
||||
>;
|
||||
@@ -912,6 +920,12 @@ export type ServerKeysType = {
|
||||
identityKey: ArrayBuffer;
|
||||
};
|
||||
|
||||
export type ChallengeType = {
|
||||
readonly type: 'recaptcha';
|
||||
readonly token: string;
|
||||
readonly captcha: string;
|
||||
};
|
||||
|
||||
export type ProxiedRequestOptionsType = {
|
||||
returnArrayBuffer?: boolean;
|
||||
start?: number;
|
||||
@@ -1035,6 +1049,7 @@ export function initialize({
|
||||
updateDeviceName,
|
||||
uploadGroupAvatar,
|
||||
whoami,
|
||||
sendChallengeResponse,
|
||||
};
|
||||
|
||||
async function _ajax(param: AjaxOptionsType): Promise<any> {
|
||||
@@ -1105,6 +1120,14 @@ export function initialize({
|
||||
});
|
||||
}
|
||||
|
||||
async function sendChallengeResponse(challengeResponse: ChallengeType) {
|
||||
return _ajax({
|
||||
call: 'challenge',
|
||||
httpType: 'PUT',
|
||||
jsonData: challengeResponse,
|
||||
});
|
||||
}
|
||||
|
||||
async function getConfig() {
|
||||
type ResType = {
|
||||
config: Array<{ name: string; enabled: boolean; value: string | null }>;
|
||||
|
||||
Reference in New Issue
Block a user