Skip to content

Instantly share code, notes, and snippets.

@antitree
Last active February 4, 2019 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antitree/76a54088c380c3bf0aa679cbcc60d941 to your computer and use it in GitHub Desktop.
Save antitree/76a54088c380c3bf0aa679cbcc60d941 to your computer and use it in GitHub Desktop.
Authy iterations
function(t, e, n) {
var r, o;
r = [n(34), n(35)], o = function(t, e) {
var n;
return n = function() {
function n() {}
return n.prototype.changePhone = function(n, r, o, i) {
var s, a;
a = e.get().userId, s = "/json/users/" + a + "/change_phone/request", t.postAuth(s, {
new_cellphone: n,
new_country_code: r
}, function() {
return o()
}, i)
}, n.prototype.confirmChangePhone = function(n, r, o) {
var i, s;
s = e.get().userId, i = "/json/users/" + s + "/change_phone/confirm", t.postAuth(i, {
pin: n
}, r, o)
}, n.prototype.requestConfirmationPin = function(n, r, o) {
var i, s;
s = e.get().userId, i = "/json/users/" + s + "/change_phone/request_pin", t.postAuth(i, {
via: n
}, r, o)
}, n.prototype.changeEmail = function(n, r, o) {
var i, s;
s = e.get().userId, i = "/json/users/" + s + "/change_email/request", t.postAuth(i, {
new_email: n
}, function() {
return r()
}, o)
}, n.prototype.getUserInfo = function(n, r) {
var o, i, s;
return o = e.get().deviceId, s = e.get().userId, i = "/json/users/" + s + "/devices/" + o, t.getAuth(i, function(t) {
var e;
return e = {
multiDevicesEnabled: t.multidevices_enabled,
countryCode: t.country_code,
cellphone: t.cellphone,
email: t.email,
userId: s
}, n(e)
}, r)
}, n
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o;
r = [n(9), n(35), n(54), n(8), n(42), n(58)], o = function(t, e, n, r, o, i) {
var s;
return s = function() {
function s() {}
return s.COMMON_PARAMS = {
api_key: t.API_KEY,
locale: window.navigator.language
}, s.HTTP_GET = "GET", s.HTTP_PUT = "PUT", s.HTTP_POST = "POST", s.parseResponse = function(t) {
var e;
if ("string" == typeof t) try {
t = JSON.parse(t)
} catch (t) {
e = t, r.w(e)
}
return t
}, s.get = function(e, n, o, i, a) {
var u;
return null == i && (i = {}), null == a && (a = function() {}), u = this, s.request({
url: t.SERVER_URL + e,
params: s.getParams(i),
type: s.HTTP_GET,
success: function(t) {
return t = u.parseResponse(t), r.d(t), n(t)
},
error: function(t) {
return s.onFailedRequest(t.responseJSON, o)
},
beforeSend: a
})
}, s.getAuth = function(t, n, r, o, i) {
var a, u;
return null == o && (o = {}), null == i && (i = function() {}), a = e.get(), u = a.getOtps(), o.otp1 = u[0], o.otp2 = u[1], o.otp3 = u[2], o.device_id = a.deviceId, s.get(t, n, r, o, i)
}, s.post = function(e, n, o, i) {
return null == n && (n = {}), s.request({
url: t.SERVER_URL + e,
params: s.getParams(n),
type: s.HTTP_POST,
success: function(t) {
return r.d(t), o(t)
},
error: function(t) {
return s.onFailedRequest(t.responseJSON, i)
}
})
}, s.postAuth = function(t, n, r, o) {
var i;
return null == n && (n = {}), i = e.get().getOtps(), n.otp1 = i[0], n.otp2 = i[1], n.otp3 = i[2], n.device_id = e.get().deviceId, s.post(t, n, r, o)
}, s.put = function(e, n, o, i) {
return null == n && (n = {}), s.request({
url: t.SERVER_URL + e,
params: s.getParams(n),
type: s.HTTP_PUT,
success: function(t) {
return r.d(t), o(t)
},
error: function(t) {
return s.onFailedRequest(t.responseJSON, i)
}
})
}, s.putAuth = function(t, n, r, o) {
var i;
return null == n && (n = {}), i = e.get().getOtps(), n.otp1 = i[0], n.otp2 = i[1], n.otp3 = i[2], n.device_id = e.get().deviceId, s.put(t, n, r, o)
}, s.request = function(e) {
var i, s, a;
return s = "", i = e.beforeSend || function() {}, a = "undefined" == typeof e.processData || e.processData, o.ajax({
url: e.url,
data: e.params || {},
type: e.type,
processData: a,
beforeSend: function(o, a) {
return s = a.url, r.d(e.type + ": " + s), o.setRequestHeader("X-User-Agent", t.USER_AGENT), o.setRequestHeader("X-Authy-Device-App", t.getFlavor()), o.setRequestHeader("X-Authy-Private-IP", t.getPrivateIPS()), o.setRequestHeader("X-Authy-Request-ID", n.get().getSessionUUID()), i(o, a)
},
success: function(t) {
return r.d(e.type + " OK for: " + s), e.success(t)
},
error: function(t, n, o) {
return r.e(e.type + " FAILED for: " + s + "\nText Status: " + n + "\nError Thrown: " + o), e.error(t)
}
})
}, s.getParams = function(t) {
return o.extend({}, s.COMMON_PARAMS, t)
}, s.camelizeResponse = function(t) {
var e, n, r;
n = {};
for (e in t) r = t[e], !(r instanceof Object) || r instanceof Array ? n[i(e)] = r : n[i(e)] = s.camelizeResponse(r);
return n
}, s.onFailedRequest = function(t, e) {
return e(null != t ? t : {
message: "It looks like there is no internet connection."
})
}, s
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o, i = function(t, e) {
return function() {
return t.apply(e, arguments)
}
};
r = [n(36), n(49), n(37), n(7), n(53), n(8)], o = function(t, e, n, r, o, s, a) {
var u;
return u = function() {
function a() {}
var MasterTokenSingleton, u;
return u = null, MasterTokenSingleton = function() {
function MasterTokenSingleton(t, r, s) {
this.userId = t, this.deviceId = r, this.secretKey = s, this.cleanUpBeforeClose = i(this.cleanUpBeforeClose, this), this.otpGenerator = new e(this.secretKey, !1), o.subscribeToCloseAppEvent(this), n.addChangePasswordEventListener(this)
}
return MasterTokenSingleton.prototype.getOtps = function(t) {
return this.otpGenerator.getOtps(t)
}, MasterTokenSingleton.prototype.save = function(e) {
return null == e && (e = function() {}), null != this.secretKey && null != this.userId && null != this.deviceId ? t.save("MasterToken", {
userId: this.userId,
deviceId: this.deviceId,
secretKey: this.secretKey
}, e) : (s.w("Skipping save for " + this.constructor.name + " since it hasn't been loaded into memory."), e())
}, MasterTokenSingleton.prototype.cleanUpBeforeClose = function(t) {
var e;
return e = this, a.save(function() {
return e.userId = null, e.deviceId = null, e.secretKey = null, t()
})
}, MasterTokenSingleton
}(), a.get = function() {
return u
}, a.initialize = function(t, e, n) {
return null == u || null == u.secretKey || null == u.userId || null == u.deviceId ? u = new MasterTokenSingleton(t, e, n) : (u.userId = t, u.deviceId = e, u.secretKey = n)
}, a.save = function(t) {
if (null == t && (t = function() {}), null !== u) return u.save(t)
}, a.load = function(e) {
return t.load("MasterToken", function(t) {
return null != t && null != t.userId && null != t.deviceId && null != t.secretKey && (a.initialize(t.userId, t.deviceId, t.secretKey), r.emit("master_token_loaded")), e(u)
})
}, a.hasBeenCreated = function(e) {
t.hasKey("MasterToken", function(t) {
return e(t)
})
}, a.setSecretKey = function(t) {
return u = new MasterTokenSingleton(u.userId, u.deviceId, t), a.save()
}, a
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o;
r = [n(37), n(31), n(20), n(32)], o = function(t, e, n, r) {
var o;
return o = function() {
function n() {}
return n.verifyEncriptionKeyIsLoaded = function() {
if (!t.isLoaded()) throw {
name: "EncryptionKey not loaded",
message: "For this class to function correctly you must call EncryptionKey.load first"
}
}, n.save = function(r, o, i) {
var s, a, u, c;
n.verifyEncriptionKeyIsLoaded(), c = t.get(), u = n.JSON_stringify(o), a = c.encrypt(u), s = {
crypto: a
}, e.save(r, s, i)
}, n.JSON_stringify = function(t) {
return JSON.stringify(t).replace(/[\u007f-\uffff]/g, function(t) {
return "\\u" + ("0000" + t.charCodeAt(0).toString(16)).slice(-4)
})
}, n.load = function(o, i) {
var s;
return s = r.defer(), e.loadObject(o, function(e) {
var r, o, a, u;
return null == e ? (i(null), void s.resolve(null)) : (n.verifyEncriptionKeyIsLoaded(), u = t.get(), r = e.crypto, o = u.decrypt(r), a = JSON.parse(o), i(a), void s.resolve(a))
}), s.promise
}, n.hasKey = function(t, n) {
e.loadObject(t, function(t) {
return n(null != t)
})
}, n
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o;
r = [n(38), n(31), n(8), n(39), n(7), n(4)], o = function(t, e, n, r, o, i) {
var s;
return s = function() {
function s() {}
var a, u;
return s.STORAGE_KEY = "authy.EncryptionKey", s.CHANGE_PWD_EVENT_LISTENERS = [], s.STORAGE_KEY_HAS_PWD = "authy.HasSetPassword", s.USER_HAS_SET_PWD = null, s.DEFAULT_PASSWORD = "123qweASD", u = null, a = function() {
function r(e, r, o) {
var i, s;
this.salt = r, null == o && (o = {}), i = o.fromData || !1, i ? (this.key = o.key, this.verification = o.verification || this.encrypt(this.salt)) : (s = o.keyLength || 256, n.bm("Generating password"), this.key = t.generatePBKDF2Key(e, this.salt, {
iterations: 1e3,
keySize: s,
decodeSalt: !0
}), n.bm("Generated"), this.verification = o.verification || this.encrypt(this.salt))
}
return r.prototype.save = function(t) {
var n;
return null == t && (t = function() {}), n = {
salt: this.salt,
verification: this.verification
}, e.save(s.STORAGE_KEY, n, t)
}, r.prototype.encrypt = function(e) {
return t.encryptAESWithKey(this.key, e)
}, r.prototype.decrypt = function(e) {
return t.decryptAESWithKey(this.key, e)
}, r.prototype.decryptToHex = function(e) {
return t.toHex(this.decrypt(e))
}, r.prototype.cleanUpBeforeClose = function(t) {
var e;
return e = this, this.save(function() {
return e.salt = null, e.verification = null, e.key = null, t()
})
}, r
}(), s.create = function(e) {
var n;
return n = t.generateSalt(), new a(e, n)
}, s.createDefaultKey = function() {
return s.create(s.DEFAULT_PASSWORD)
}, s.createFromData = function(t, e, n) {
return new a("", e, {
fromData: !0,
verification: n,
key: t
})
}, s.isLoaded = function() {
return null != u && null != u.key
}, s.get = function() {
return u
}, s.set = function(t) {
return u = t
}, s.hasBeenCreated = function(t) {
e.loadObject(s.STORAGE_KEY, function(e) {
return t(null != e && null != e.salt)
})
}, s.load = function(t, r, i) {
var c;
return c = this, e.loadObject(s.STORAGE_KEY, function(e) {
return null != e && null != e.salt ? (n.d("Creating key from local storage"), u = new a(t, e.salt, {
verification: e.verification
}), i(u)) : (n.d("Creating key for first time. Using default password: " + r), u = s.create(t), s.saveKey(u, r), i(u)), o.emit("encryption_key")
})
}, s.saveKey = function(t, n, r) {
return null == r && (r = function() {}), t.save(), e.save(s.STORAGE_KEY_HAS_PWD, {
isDefaultPassword: n
}, r)
}, s.verifyPassword = function(t, e, r) {
return s.hasBeenCreated(function(o) {
if (o) return s.load(t, e, function(t) {
var e;
try {
return r(t.salt === t.decrypt(t.verification) ? !0 : !1)
} catch (t) {
return e = t, n.e(e), r(!1)
}
});
throw new i("Can't verify password if it hasn't been set for the first time")
})
}, s.addChangePasswordEventListener = function(t) {
return s.CHANGE_PWD_EVENT_LISTENERS.push(t)
}, s.changePassword = function(t, n) {
return s.USER_HAS_SET_PWD = !0, e.save(s.STORAGE_KEY_HAS_PWD, {
userHasSetPassword: s.USER_HAS_SET_PWD
}, function() {
return u = s.create(t), u.save(function() {
var t;
return r.addCommonParam("hasPassword", !0), (t = function(e) {
var r;
if (e < s.CHANGE_PWD_EVENT_LISTENERS.length) {
if (r = s.CHANGE_PWD_EVENT_LISTENERS[e], "function" == typeof r.save) return r.save(function() {
return t(e + 1)
});
throw new Error("The listener " + r.constructor.name + " must implement the method save")
}
return n()
})(0)
})
})
}, s.userHasSetPassword = function(t) {
null != s.USER_HAS_SET_PWD ? t(s.USER_HAS_SET_PWD) : e.loadObject(s.STORAGE_KEY_HAS_PWD, function(n) {
return null != n && null != n.userHasSetPassword ? (s.USER_HAS_SET_PWD = n.userHasSetPassword, t(s.USER_HAS_SET_PWD)) : s.hasBeenCreated(function(r) {
return s.isUserMigrating(r, n) ? (s.USER_HAS_SET_PWD = !0, e.save(s.STORAGE_KEY_HAS_PWD, {
userHasSetPassword: s.USER_HAS_SET_PWD
})) : s.USER_HAS_SET_PWD = !1, t(s.USER_HAS_SET_PWD)
})
})
}, s.isUserMigrating = function(t, e) {
return (null == e || null == e.isDefaultPassword || !e.isDefaultPassword) && !!t
}, s
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o;
r = [n(20)], o = function(t) {
var e;
return e = function() {
function e() {}
return e.PBKDF2_PARAMS = {
keySize: 8,
iterations: 1e3
}, e.IV = t.util.decodeUtf8("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"), e.encryptAES = function(t, e, n) {
var r;
return r = this.generatePBKDF2Key(e, t, {
iterations: 1e3,
keySize: 256,
decodeSalt: !1
}), this.encryptAESWithKey(r, n)
}, e.decryptAES = function(t, e, n) {
var r;
return r = this.generatePBKDF2Key(e, t, {
iterations: 1e3,
keySize: 256,
decodeSalt: !1
}), this.decryptAESWithKey(r, n)
}, e.encryptAESWithKey = function(n, r) {
var o, i;
return i = t.util.createBuffer(n), o = t.aes.createEncryptionCipher(i, "CBC"), o.start(t.util.createBuffer(e.IV)), o.update(t.util.createBuffer(r)), o.finish() ? t.util.encode64(o.output.data) : null
}, e.decryptAESWithKey = function(n, r) {
var o, i, s;
return s = t.util.createBuffer(n), o = t.aes.createDecryptionCipher(s, "CBC"), o.start(t.util.createBuffer(e.IV)), i = t.util.createBuffer(t.util.decode64(r)), o.update(i), o.finish() ? o.output.data : null
}, e.generatePBKDF2Key = function(e, n, r) {
var o, i, s;
if (null == r && (r = {}), "string" != typeof n) throw {
name: "Illegal Argument",
message: "salt must be a string"
};
return o = r.iterations || 1e3, i = (r.keySize || 256) / 8, null === r.decodeSalt && (r.decodeSalt = !0), r.decodeSalt === !0 && (n = t.util.hexToBytes(n)), s = t.pkcs5.pbkdf2(e, n, o, i)
}, e.generateSHA256 = function(e) {
var n;
if ("string" != typeof e) throw new Error("Message must be a string");
return n = t.md.sha256.create(), n.update(e), n.digest().toHex()
}, e.generateSalt = function(e) {
var n;
return null == e && (e = 256), n = t.random.getBytesSync(e / 8), t.util.createBuffer(n).toHex()
}, e.generateHmacSHA1 = function(e, n) {
var r;
return r = t.hmac.create(), r.start("sha1", n), r.update(e), r.digest().toHex()
}, e.generateHmacSHA256 = function(e, n) {
var r;
return r = t.hmac.create(), r.start("sha256", n), r.update(e), t.util.encode64(r.digest().getBytes())
}, e.SHA256withRSA = function(e, n) {
var r, o, i;
return o = t.pki.privateKeyFromPem(n), r = t.md.sha256.create(), r.update(e, "utf8"), i = o.sign(r), t.util.encode64(i)
}, e.toHex = function(e) {
return t.util.createBuffer(e).toHex()
}, e.fromHex = function(e) {
return t.util.hexToBytes(e)
}, e.rsaKeyPair = function(e) {
return t.pki.rsa.generateKeyPair({
bits: 2048,
workers: -1,
e: 65537
}, function(t, n) {
return e(n)
})
}, e.rsaKeyPairJSON = function(n) {
var r;
return r = e.rsaKeyPair(function(e) {
return n({
publicKey: t.pki.publicKeyToPem(e.publicKey),
privateKey: t.pki.privateKeyToPem(e.privateKey)
})
})
}, e.getNonce = function() {
return (new Date).getTime()
}, e
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o, i = function(t, e) {
return function() {
return t.apply(e, arguments)
}
};
r = [n(40), n(41), n(8), n(42), n(10), n(43), n(48)], o = function(t, e, n, r, o, s, a) {
var u;
return u = function() {
function n(t) {
this.where = null != t ? t : "body", this.getCommonParams = i(this.getCommonParams, this), this.render = i(this.render, this), this.template = null, this.output = null, this.partials = null, this.modelClone = null, this.cachingEnabled = !1, this.cacheValid = !0
}
return n.MUSTACHES_LOCATION = "ui/mustaches", n.PARTIALS_CACHE = {}, n.COMMON_VIEW_PARAMS = {}, n.prototype.render = function(t, e) {
var n, o;
return null == e && (e = function() {}), n = this, o = this.getTemplateName(), this.cachingEnabled === !1 ? null != n.partials ? n.loadPartials(function(r) {
return n.loadTemplate(function(o) {
return n.renderMustache(o, t, e, r)
})
}) : n.loadTemplate(function(r) {
return n.renderMustache(r, t, e)
}) : this.shouldIgnoreCache(t) ? (null != n.partials ? n.loadPartials(function(r) {
return n.loadTemplate(function(o) {
return n.renderMustache(o, t, e, r)
})
}) : n.loadTemplate(function(r) {
return n.renderMustache(r, t, e)
}), n.modelClone = r.extend(!0, {}, t), n.cacheValid = !0) : void 0
}, n.prototype.renderMustache = function(t, e, n, o) {
var i, s, u, c, l;
if (null == o && (o = {}), u = this.getCommonParams(e), this.output = a.render(t, u, o), r(this.where).html(this.output), null != this.partials)
for (l = this.partials, i = 0, s = l.length; i < s; i++) c = l[i], c.update();
return this.update(u), n()
}, n.prototype.getCommonParams = function(t) {
var e;
return e = {
shouldDisplayNotifIcon: !n.COMMON_VIEW_PARAMS.hasPassword || n.COMMON_VIEW_PARAMS.hasDeviceRequest
}, r.extend({}, t, n.COMMON_VIEW_PARAMS, e)
}, n.prototype.shouldIgnoreCache = function(t) {
var e, n;
return e = !this.cacheValid, n = o.isEqual(t, this.modelClone), !n || e
}, n.prototype.invalidateCache = function() {
return this.cacheValid = !1
}, n.prototype.loadFile = function(t, e) {
return r.get(t, {}).success(function(t) {
return e(t)
})
}, n.prototype.loadPartials = function(t) {
var e, r, o;
return o = this, r = {}, (e = function(i) {
var s, a, u;
return i < o.partials.length ? (s = o.partials[i].getPartialName(), a = o.partials[i].getPartialLocation(), u = o.partials[i], u.setPartialParent(o.getTemplateName()), u.template && n.addPartialToCache(s, u.template), n.isPartialLoaded(s) ? (r[s] = n.getPartial(s), e(i + 1)) : o.loadFile(a, function(t) {
return r[s] = t, n.addPartialToCache(s, t), e(i + 1)
})) : t(r)
})(0)
}, n.prototype.loadTemplate = function(t) {
var e;
return e = this, this.isTemplateLoaded() ? t(this.template) : this.loadFile(this.getTemplateLocation() + "/" + this.getTemplateName() + ".mustache", function(n) {
return e.template = n, t(n)
})
}, n.prototype.onLoad = function(t) {
this.isTemplateLoaded() ? t() : this.loadTemplate(t)
}, n.prototype.getTemplateLocation = function() {
return n.MUSTACHES_LOCATION
}, n.prototype.update = function(e) {
throw new t
}, n.prototype.getTemplateName = function() {
return s(this.constructor.name).replace("_view", "_screen")
}, n.prototype.isTemplateLoaded = function() {
return null != this.template
}, n.prototype.bindClickAndEnterEvents = function(t, n, r, o) {
var i, s;
return null == o && (o = !1), s = function(o) {
if (e.isEnter(o)) return t.blur(), r(o, t, n, !1, s)
}, i = function(e) {
return r(e, t, n, !0, i)
}, t.on("keyup.clickAndEnter", s), n.on("click.clickAndEnter", i)
}, n.prototype.unbindClickAndEnterEvents = function(t, e, n) {
return t.off("keyup.clickAndEnter", n), e.off("click.clickAndEnter", n)
}, n.prototype.bindEnterEvent = function(t, n) {
return t.on("keyup", function(t) {
if (e.isEnter(t)) return n(t, this)
})
}, n.addCommonParam = function(t, e) {
return n.COMMON_VIEW_PARAMS[t] = e
}, n.isPartialLoaded = function(t) {
return t in n.PARTIALS_CACHE
}, n.addPartialToCache = function(t, e) {
n.PARTIALS_CACHE[t] = e
}, n.getPartial = function(t) {
return n.PARTIALS_CACHE[t]
}, n
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o, i = function(t, e) {
function n() {
this.constructor = t
}
for (var r in e) s.call(e, r) && (t[r] = e[r]);
return n.prototype = e.prototype, t.prototype = new n, t.__super__ = e.prototype, t
},
s = {}.hasOwnProperty;
r = [n(4)], o = function(t) {
var e;
return e = function(t) {
function e() {
return e.__super__.constructor.apply(this, arguments)
}
return i(e, t), e
}(t)
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o;
r = [], o = function() {
var t;
return t = function() {
function t() {}
return t.ENTER = 13, t.C = 67, t.isEnter = function(e) {
var n;
return n = e.keyCode || e.which, n === t.ENTER
}, t
}()
}.apply(e, r), !(void 0 !== o && (t.exports = o))
},
function(t, e, n) {
var r, o;
! function(e, n) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment