B2G/gecko/services/sync/modules/service.js
/*
   * Returns whether to try again.
   */
Returns whether to try again.
Returns whether to try again .
function handleHMACEvent() {
    let now = Date.now();
    if ((now - this.lastHMACEvent) < HMAC_EVENT_INTERVAL)
      return false;
    this._log.info("Bad HMAC event detected. Attempting recovery " +
                   "or signaling to other clients.");
    this.lastHMACEvent = now;
    let cryptoKeys = new CryptoWrapper(CRYPTO_COLLECTION, KEYS_WBO);
    try {
      let cryptoResp = cryptoKeys.fetch(this.cryptoKeysURL).response;
      let cipherText = cryptoKeys.ciphertext;
      if (!cryptoResp.success) {
        this._log.warn("Failed to download keys.");
        return false;
      }
      let keysChanged = this.handleFetchedKeys(this._identity.syncKeyBundle,
                                               cryptoKeys, true);
      if (keysChanged) {
        this._log.info("Suggesting retry.");
        return true;              
      }
      cryptoKeys.ciphertext = cipherText;
      cryptoKeys.cleartext  = null;
      let uploadResp = cryptoKeys.upload(this.cryptoKeysURL);
      if (uploadResp.success)
        this._log.info("Successfully re-uploaded keys. Continuing sync.");
      else
        this._log.warn("Got error response re-uploading keys. " +
                       "Continuing sync; let's try again later.");
      return false;            
    } catch (ex) {
      this._log.warn("Got exception \"" + ex + "\" fetching and handling " +
                     "crypto keys. Will try again later.");
      return false;
    }
  }
function handleHMACEvent ( ) { let now = Date . now ( ) ; if ( ( now - this . lastHMACEvent ) < HMAC_EVENT_INTERVAL ) return false ; this . _log . info ( "Bad HMAC event detected. Attempting recovery " + "or signaling to other clients." ) ; this . lastHMACEvent = now ; let cryptoKeys = new CryptoWrapper ( CRYPTO_COLLECTION , KEYS_WBO ) ; try { let cryptoResp = cryptoKeys . fetch ( this . cryptoKeysURL ) . response ; let cipherText = cryptoKeys . ciphertext ; if ( ! cryptoResp . success ) { this . _log . warn ( "Failed to download keys." ) ; return false ; } let keysChanged = this . handleFetchedKeys ( this . _identity . syncKeyBundle , cryptoKeys , true ) ; if ( keysChanged ) { this . _log . info ( "Suggesting retry." ) ; return true ; } cryptoKeys . ciphertext = cipherText ; cryptoKeys . cleartext = null ; let uploadResp = cryptoKeys . upload ( this . cryptoKeysURL ) ; if ( uploadResp . success ) this . _log . info ( "Successfully re-uploaded keys. Continuing sync." ) ; else this . _log . warn ( "Got error response re-uploading keys. " + "Continuing sync; let's try again later." ) ; return false ; } catch ( ex ) { this . _log . warn ( "Got exception \"" + ex + "\" fetching and handling " + "crypto keys. Will try again later." ) ; return false ; } }
Returns whether to try again.
Returns whether to try again .
// Leave a sizable delay between HMAC recovery attempts. This gives us // time for another client to fix themselves if we touch the record. // Set the last handled time so that we don't act again. // Fetch keys. // Save out the ciphertext for when we reupload. If there's a bug in // CollectionKeys, this will prevent us from uploading junk. // Did they change? If so, carry on. // Try again. // If not, reupload them and continue the current sync. // Don't try again: same keys.