key_install.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. // Generated by IcedCoffeeScript 1.7.1-f
  2. (function() {
  3. var KeyInstall, chain, fpeq, hash_json, iced, keyring, log, make_esc, __iced_k, __iced_k_noop;
  4. iced = require('iced-runtime');
  5. __iced_k = __iced_k_noop = function() {};
  6. make_esc = require('iced-error').make_esc;
  7. chain = require('iced-utils').util.chain;
  8. keyring = require('gpg-wrapper').keyring;
  9. fpeq = require('pgp-utils').util.fpeq;
  10. hash_json = require('./util').hash_json;
  11. log = require('./log');
  12. exports.KeyInstall = KeyInstall = (function() {
  13. function KeyInstall(config, keyset) {
  14. this.config = config;
  15. this._keyset = keyset;
  16. this._tmp_keyring = null;
  17. this._keys = {};
  18. }
  19. KeyInstall.prototype.make_tmp_keyring = function(cb) {
  20. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  21. __iced_k = __iced_k_noop;
  22. ___iced_passed_deferral = iced.findDeferral(arguments);
  23. log.debug("| KeyInstaller::make_tmp_keyring");
  24. (function(_this) {
  25. return (function(__iced_k) {
  26. __iced_deferrals = new iced.Deferrals(__iced_k, {
  27. parent: ___iced_passed_deferral,
  28. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  29. funcname: "KeyInstall.make_tmp_keyring"
  30. });
  31. keyring.QuarantinedKeyRing.make(__iced_deferrals.defer({
  32. assign_fn: (function(__slot_1) {
  33. return function() {
  34. err = arguments[0];
  35. return __slot_1._tmp_keyring = arguments[1];
  36. };
  37. })(_this),
  38. lineno: 23
  39. }));
  40. __iced_deferrals._fulfill();
  41. });
  42. })(this)((function(_this) {
  43. return function() {
  44. return cb(err);
  45. };
  46. })(this));
  47. };
  48. KeyInstall.prototype.cleanup = function(cb) {
  49. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  50. __iced_k = __iced_k_noop;
  51. ___iced_passed_deferral = iced.findDeferral(arguments);
  52. log.debug("+ Cleaning up tmp keyring " + this._tmp_keyring);
  53. (function(_this) {
  54. return (function(__iced_k) {
  55. if (_this._tmp_keyring != null) {
  56. (function(__iced_k) {
  57. __iced_deferrals = new iced.Deferrals(__iced_k, {
  58. parent: ___iced_passed_deferral,
  59. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  60. funcname: "KeyInstall.cleanup"
  61. });
  62. _this._tmp_keyring.nuke(__iced_deferrals.defer({
  63. assign_fn: (function() {
  64. return function() {
  65. return err = arguments[0];
  66. };
  67. })(),
  68. lineno: 31
  69. }));
  70. __iced_deferrals._fulfill();
  71. })(function() {
  72. return __iced_k(typeof err !== "undefined" && err !== null ? log.warn("Error cleaning up temporary keyring: " + err.message) : void 0);
  73. });
  74. } else {
  75. return __iced_k();
  76. }
  77. });
  78. })(this)((function(_this) {
  79. return function() {
  80. log.debug("- Cleaning up tmp keyring " + _this._tmp_keyring);
  81. return cb();
  82. };
  83. })(this));
  84. };
  85. KeyInstall.prototype.temporary_import = function(cb) {
  86. var a, b, err, esc, fps, k, msg, source, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  87. __iced_k = __iced_k_noop;
  88. ___iced_passed_deferral = iced.findDeferral(arguments);
  89. esc = make_esc(cb, "KeyInstaller::temporary_import");
  90. log.debug("+ KeyInstaller::temporary_import");
  91. source = this._keyset.keys.code;
  92. this._keys.code = k = this._tmp_keyring.make_key({
  93. key_data: source.key_data,
  94. fingerprint: source.fingerprint,
  95. username: "code@keybase.io"
  96. });
  97. this._tmp_keyring.set_fingerprint(source.fingerprint);
  98. (function(_this) {
  99. return (function(__iced_k) {
  100. __iced_deferrals = new iced.Deferrals(__iced_k, {
  101. parent: ___iced_passed_deferral,
  102. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  103. funcname: "KeyInstall.temporary_import"
  104. });
  105. k.save(esc(__iced_deferrals.defer({
  106. assign_fn: (function() {
  107. return function() {
  108. return err = arguments[0];
  109. };
  110. })(),
  111. lineno: 50
  112. })));
  113. __iced_deferrals._fulfill();
  114. });
  115. })(this)((function(_this) {
  116. return function() {
  117. (function(__iced_k) {
  118. __iced_deferrals = new iced.Deferrals(__iced_k, {
  119. parent: ___iced_passed_deferral,
  120. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  121. funcname: "KeyInstall.temporary_import"
  122. });
  123. _this._tmp_keyring.list_fingerprints(esc(__iced_deferrals.defer({
  124. assign_fn: (function() {
  125. return function() {
  126. return fps = arguments[0];
  127. };
  128. })(),
  129. lineno: 51
  130. })));
  131. __iced_deferrals._fulfill();
  132. })(function() {
  133. msg = fps.length === 0 ? "key save failed; no fingerprints" : fps.length > 1 ? "keyring corruption; too many fingerprints found" : !fpeq((a = fps[0]), (b = _this._keyset.keys.code.fingerprint)) ? "fingerprint mismatch after import: " + a + " != " + b : void 0;
  134. err = msg != null ? new Error(msg) : null;
  135. log.debug("- KeyInstaller::temporary_import");
  136. return cb(err);
  137. });
  138. };
  139. })(this));
  140. };
  141. KeyInstall.prototype.check_self_sig = function(cb) {
  142. var err, payload, sig, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  143. __iced_k = __iced_k_noop;
  144. ___iced_passed_deferral = iced.findDeferral(arguments);
  145. sig = this._keyset.self_sig;
  146. this._keyset.self_sig = null;
  147. log.debug("+ KeyInstaller::check_self_sig");
  148. payload = hash_json(this._keyset);
  149. (function(_this) {
  150. return (function(__iced_k) {
  151. __iced_deferrals = new iced.Deferrals(__iced_k, {
  152. parent: ___iced_passed_deferral,
  153. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  154. funcname: "KeyInstall.check_self_sig"
  155. });
  156. _this._keys.code.verify_sig({
  157. which: "self sig on keyset",
  158. payload: payload,
  159. sig: sig
  160. }, __iced_deferrals.defer({
  161. assign_fn: (function() {
  162. return function() {
  163. return err = arguments[0];
  164. };
  165. })(),
  166. lineno: 69
  167. }));
  168. __iced_deferrals._fulfill();
  169. });
  170. })(this)((function(_this) {
  171. return function() {
  172. log.debug("- KeyInstaller::check_self_sig");
  173. return cb(err);
  174. };
  175. })(this));
  176. };
  177. KeyInstall.prototype.full_import = function(cb) {
  178. var esc, k, master, source, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  179. __iced_k = __iced_k_noop;
  180. ___iced_passed_deferral = iced.findDeferral(arguments);
  181. esc = make_esc(cb, "KeyInstall::full_import");
  182. log.debug("+ KeyInstaller::full_import");
  183. master = this.config.master_ring();
  184. source = this._keyset.keys.index;
  185. this._keys.index = k = master.make_key({
  186. key_data: source.key_data,
  187. fingerprint: source.fingerprint,
  188. username: "index@keybase.io"
  189. });
  190. (function(_this) {
  191. return (function(__iced_k) {
  192. __iced_deferrals = new iced.Deferrals(__iced_k, {
  193. parent: ___iced_passed_deferral,
  194. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  195. funcname: "KeyInstall.full_import"
  196. });
  197. k.save(esc(__iced_deferrals.defer({
  198. lineno: 85
  199. })));
  200. __iced_deferrals._fulfill();
  201. });
  202. })(this)((function(_this) {
  203. return function() {
  204. (function(__iced_k) {
  205. __iced_deferrals = new iced.Deferrals(__iced_k, {
  206. parent: ___iced_passed_deferral,
  207. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  208. funcname: "KeyInstall.full_import"
  209. });
  210. _this._keys.code.commit({
  211. ring: master
  212. }, esc(__iced_deferrals.defer({
  213. lineno: 86
  214. })));
  215. __iced_deferrals._fulfill();
  216. })(function() {
  217. log.debug("- KeyInstaller::full_import");
  218. return cb(null);
  219. });
  220. };
  221. })(this));
  222. };
  223. KeyInstall.prototype.revoke_1 = function(k, v, cb) {
  224. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  225. __iced_k = __iced_k_noop;
  226. ___iced_passed_deferral = iced.findDeferral(arguments);
  227. log.debug("| Revoking key " + k);
  228. (function(_this) {
  229. return (function(__iced_k) {
  230. __iced_deferrals = new iced.Deferrals(__iced_k, {
  231. parent: ___iced_passed_deferral,
  232. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  233. funcname: "KeyInstall.revoke_1"
  234. });
  235. keyring.master_ring().gpg({
  236. args: ["--import"],
  237. stdin: v,
  238. quiet: true
  239. }, __iced_deferrals.defer({
  240. assign_fn: (function() {
  241. return function() {
  242. return err = arguments[0];
  243. };
  244. })(),
  245. lineno: 94
  246. }));
  247. __iced_deferrals._fulfill();
  248. });
  249. })(this)((function(_this) {
  250. return function() {
  251. return cb(err);
  252. };
  253. })(this));
  254. };
  255. KeyInstall.prototype.revoke_all = function(cb) {
  256. var esc, k, v, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  257. __iced_k = __iced_k_noop;
  258. ___iced_passed_deferral = iced.findDeferral(arguments);
  259. esc = make_esc(cb, "KeyInstall::revoke_all");
  260. (function(_this) {
  261. return (function(__iced_k) {
  262. if (_this._keyset.revocation != null) {
  263. (function(__iced_k) {
  264. var _i, _k, _keys, _ref, _results, _while;
  265. _ref = _this._keyset.revocation;
  266. _keys = (function() {
  267. var _results1;
  268. _results1 = [];
  269. for (_k in _ref) {
  270. _results1.push(_k);
  271. }
  272. return _results1;
  273. })();
  274. _i = 0;
  275. _results = [];
  276. _while = function(__iced_k) {
  277. var _break, _continue, _next;
  278. _break = function() {
  279. return __iced_k(_results);
  280. };
  281. _continue = function() {
  282. return iced.trampoline(function() {
  283. ++_i;
  284. return _while(__iced_k);
  285. });
  286. };
  287. _next = function(__iced_next_arg) {
  288. _results.push(__iced_next_arg);
  289. return _continue();
  290. };
  291. if (!(_i < _keys.length)) {
  292. return _break();
  293. } else {
  294. k = _keys[_i];
  295. v = _ref[k];
  296. (function(__iced_k) {
  297. __iced_deferrals = new iced.Deferrals(__iced_k, {
  298. parent: ___iced_passed_deferral,
  299. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  300. funcname: "KeyInstall.revoke_all"
  301. });
  302. _this.revoke_1(k, v, esc(__iced_deferrals.defer({
  303. lineno: 103
  304. })));
  305. __iced_deferrals._fulfill();
  306. })(_next);
  307. }
  308. };
  309. _while(__iced_k);
  310. })(__iced_k);
  311. } else {
  312. return __iced_k();
  313. }
  314. });
  315. })(this)((function(_this) {
  316. return function() {
  317. return cb(null);
  318. };
  319. })(this));
  320. };
  321. KeyInstall.prototype.keys = function() {
  322. return this._keys;
  323. };
  324. KeyInstall.prototype.run = function(cb) {
  325. var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  326. __iced_k = __iced_k_noop;
  327. ___iced_passed_deferral = iced.findDeferral(arguments);
  328. esc = make_esc(cb, "KeyInstall:run2");
  329. log.debug("+ KeyInstaller::run");
  330. log.info("Installing keyset version " + this._keyset.version);
  331. cb = chain(cb, this.cleanup.bind(this));
  332. (function(_this) {
  333. return (function(__iced_k) {
  334. __iced_deferrals = new iced.Deferrals(__iced_k, {
  335. parent: ___iced_passed_deferral,
  336. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  337. funcname: "KeyInstall.run"
  338. });
  339. _this.make_tmp_keyring(esc(__iced_deferrals.defer({
  340. lineno: 117
  341. })));
  342. __iced_deferrals._fulfill();
  343. });
  344. })(this)((function(_this) {
  345. return function() {
  346. (function(__iced_k) {
  347. __iced_deferrals = new iced.Deferrals(__iced_k, {
  348. parent: ___iced_passed_deferral,
  349. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  350. funcname: "KeyInstall.run"
  351. });
  352. _this.temporary_import(esc(__iced_deferrals.defer({
  353. lineno: 118
  354. })));
  355. __iced_deferrals._fulfill();
  356. })(function() {
  357. (function(__iced_k) {
  358. __iced_deferrals = new iced.Deferrals(__iced_k, {
  359. parent: ___iced_passed_deferral,
  360. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  361. funcname: "KeyInstall.run"
  362. });
  363. _this.check_self_sig(esc(__iced_deferrals.defer({
  364. lineno: 119
  365. })));
  366. __iced_deferrals._fulfill();
  367. })(function() {
  368. (function(__iced_k) {
  369. __iced_deferrals = new iced.Deferrals(__iced_k, {
  370. parent: ___iced_passed_deferral,
  371. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  372. funcname: "KeyInstall.run"
  373. });
  374. _this.full_import(esc(__iced_deferrals.defer({
  375. lineno: 120
  376. })));
  377. __iced_deferrals._fulfill();
  378. })(function() {
  379. (function(__iced_k) {
  380. __iced_deferrals = new iced.Deferrals(__iced_k, {
  381. parent: ___iced_passed_deferral,
  382. filename: "/home/max/src/keybase/node-installer/src/key_install.iced",
  383. funcname: "KeyInstall.run"
  384. });
  385. _this.revoke_all(esc(__iced_deferrals.defer({
  386. lineno: 121
  387. })));
  388. __iced_deferrals._fulfill();
  389. })(function() {
  390. log.debug("- KeyInstaller::run");
  391. return cb(null);
  392. });
  393. });
  394. });
  395. });
  396. };
  397. })(this));
  398. };
  399. return KeyInstall;
  400. })();
  401. }).call(this);