All files / lib/icloud constants.ts

100% Statements 118/118
100% Branches 2/2
100% Functions 0/0
100% Lines 118/118

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 1181x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x
/**
 * File holding constant values for the iCloud class
 */
 
/**
 * Hard coded client id, extracted from previous requests
 */
export const CLIENT_ID = `d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d`;
/**
 * User Agent this CLI is using. Emulating a Firefox Browser
 */
export const USER_AGENT = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:97.0) Gecko/20100101 Firefox/97.0`;
/**
 * Client information shared with the iCloud backend
 */
export const CLIENT_INFO = JSON.stringify({
    "U": USER_AGENT,
    "L": `en-US`,
    "Z": `GMT+01:00`,
    "V": `1.1`,
    "F": ``,
});
 
/**
 * Header used for authentication flow
 */
export const DEFAULT_AUTH_HEADER = {
    'User-Agent': USER_AGENT,
    "Accept": `application/json`,
    "Connection": `keep-alive`,
    "Origin": `https://idmsa.apple.com`,
    "Referer": `https://idmsa.apple.com/`,
    'Accept-Encoding': `gzip, deflate, br`,
    'Content-Type': `application/json`,
    'X-Apple-Widget-Key': CLIENT_ID,
    'X-Apple-OAuth-Client-Id': CLIENT_ID,
    'X-Apple-I-FD-Client-Info': CLIENT_INFO,
    'X-Apple-OAuth-Response-Type': `code`,
    'X-Apple-OAuth-Response-Mode': `web_message`,
    'X-Apple-OAuth-Client-Type': `firstPartyAuth`,
};
 
/**
 * Default header for most iCloud requests
 */
export const DEFAULT_HEADER = {
    'User-Agent': USER_AGENT,
    "Accept": `application/json`,
    'Content-Type': `application/json`,
    "Origin": `https://www.icloud.com`,
};
 
/**
 * Values extracted from auth response headers
 */
export enum AUTH_RESPONSE_HEADER {
    SESSION_TOKEN = `X-Apple-Session-Token`,
    SCNT = `scnt`,
    TRUST_TOKEN = `X-Apple-TwoSV-Trust-Token`,
    AASP_COOKIE = `aasp`
}
 
/**
 * Events lifecycle of the iCloud class
 */
export enum EVENTS {
    AUTHENTICATION_STARTED = `auth_started`,
    MFA_REQUIRED = `mfa_req`, // Will provide port as arg
    MFA_RECEIVED = `mfa_rec`,
    AUTHENTICATED = `auth`,
    TRUSTED = `trusted`,
    ACCOUNT_READY = `account_ready`,
    READY = `ready`,
    ERROR = `error`, // Error - will reject 'ready' promise and be handled on top level
    TOKEN = `token` // TokenString - only fired if needed to be picked up
}
 
/**
 * List of endpoints, required by the iCloud class
 */
export const ENPOINT = {
    "AUTH": {
        "BASE": `https://idmsa.apple.com/appleauth/auth`,
        "PATH": {
            "SIGNIN": `/signin`,
            "MFA": {
                "DEVICE": `/verify/trusteddevice`,
                "PHONE": `/verify/phone`,
            },
            "TRUST": `/2sv/trust`,
        },
    },
    "SETUP": {
        "BASE": `https://setup.icloud.com`,
        "PATH": {
            "ACCOUNT": `/setup/ws/1/accountLogin`,
        },
    },
};
 
/**
 * Pre-composing URLs, required by iCloud class
 */
export const URL = {
    "SIGNIN": `${ENPOINT.AUTH.BASE}${ENPOINT.AUTH.PATH.SIGNIN}`,
    "MFA_DEVICE": `${ENPOINT.AUTH.BASE}${ENPOINT.AUTH.PATH.MFA.DEVICE}/securitycode`, // Maybe??
    "MFA_DEVICE_ENTER": `${ENPOINT.AUTH.BASE}${ENPOINT.AUTH.PATH.MFA.DEVICE}/securitycode`,
    "MFA_PHONE": `${ENPOINT.AUTH.BASE}${ENPOINT.AUTH.PATH.MFA.PHONE}`,
    "MFA_PHONE_ENTER": `${ENPOINT.AUTH.BASE}${ENPOINT.AUTH.PATH.MFA.PHONE}/securitycode`,
    "TRUST": `${ENPOINT.AUTH.BASE}${ENPOINT.AUTH.PATH.TRUST}`,
    "SETUP": `${ENPOINT.SETUP.BASE}${ENPOINT.SETUP.PATH.ACCOUNT}`,
};
 
/**
 * Filename of persistent trust token file
 */
export const TRUST_TOKEN_FILE_NAME = `.trust-token.icloud`;
export const TRUST_TOKEN_FILE_ENCODING = `utf8`;