{"action":"created","comment":{"url":"https://api.github.com/repos/keybase/client/pulls/comments/117279406","pull_request_review_id":38973193,"id":117279406,"diff_hunk":"@@ -0,0 +1,334 @@\n+// Copyright 2015 Keybase, Inc. All rights reserved. Use of\n+// this source code is governed by the included BSD license.\n+\n+package engine\n+\n+import (\n+\t\"crypto/hmac\"\n+\t\"crypto/sha512\"\n+\t\"encoding/base64\"\n+\t\"encoding/binary\"\n+\t\"errors\"\n+\t\"fmt\"\n+\n+\t\"github.com/keybase/client/go/libkb\"\n+\t\"github.com/keybase/client/go/protocol/keybase1\"\n+\n+\t\"golang.org/x/crypto/nacl/box\"\n+)\n+\n+type TeamCreateEngine struct {\n+\tlibkb.Contextified\n+\tname string\n+}\n+\n+func NewTeamCreateEngine(g *libkb.GlobalContext, name string) *TeamCreateEngine {\n+\treturn &TeamCreateEngine{\n+\t\tContextified: libkb.NewContextified(g),\n+\t\tname:         name,\n+\t}\n+}\n+\n+func (e *TeamCreateEngine) Name() string {\n+\treturn \"NewTeam\"\n+}\n+\n+func (e *TeamCreateEngine) Prereqs() Prereqs {\n+\treturn Prereqs{\n+\t\tDevice: true,\n+\t}\n+}\n+\n+func (e *TeamCreateEngine) RequiredUIs() []libkb.UIKind {\n+\treturn []libkb.UIKind{\n+\t\tlibkb.LogUIKind,\n+\t\tlibkb.SecretUIKind,\n+\t}\n+}\n+\n+func (e *TeamCreateEngine) SubConsumers() []libkb.UIConsumer {\n+\treturn []libkb.UIConsumer{}\n+}\n+\n+func (e *TeamCreateEngine) Run(ctx *Context) (err error) {\n+\tdefer e.G().CTrace(ctx.GetNetContext(), \"TeamCreateEngine\", func() error { return err })()\n+\n+\tme, err := libkb.LoadMe(libkb.NewLoadUserArg(e.G()))\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tdeviceSigningKey, deviceEncryptionKey, err := e.getDeviceKeys(ctx, me)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tperTeamSecret, perTeamSigningKey, perTeamEncryptionKey, err := generatePerTeamKeys()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\townerLatest := me.GetComputedKeyFamily().GetLatestPerUserKey()\n+\tif ownerLatest == nil {\n+\t\treturn errors.New(\"can't create a new team without having provisioned a per-user key\")\n+\t}\n+\tsecretboxRecipients := map[string]keybase1.PerUserKey{\n+\t\tme.GetName(): *ownerLatest,\n+\t}\n+\t// These boxes will get posted along with the sig below.\n+\tsecretboxes, err := boxTeamSharedSecret(perTeamSecret, deviceEncryptionKey, secretboxRecipients)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tteamSection, err := makeRootTeamSectionNoReverse(e.name, me, perTeamSigningKey.GetKID(), perTeamEncryptionKey.GetKID())\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// At this point the team section has every field filled out except the\n+\t// reverse sig. Now we'll wrap it into a full sig, marshal it to JSON, and\n+\t// sign it, *twice*. The first time with the per-team signing key, to\n+\t// produce the reverse sig, and the second time with the device signing\n+\t// key, after the reverse sig has been written in.\n+\n+\tsigBodyForReverse, err := me.TeamRootSig(deviceSigningKey, teamSection)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\t// Note that this (sigchain-v1-style) reverse sig is made with the derived *per-team* signing key.\n+\treverseSig, _, _, err := libkb.SignJSON(sigBodyForReverse, perTeamSigningKey)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tteamSection.PerTeamKey.ReverseSig = &reverseSig\n+\n+\t// Update the team section to include the reverse sig, format it again, and make a sigchain-v2-style sig out of it.\n+\tsigBodyAfterReverse, err := me.TeamRootSig(deviceSigningKey, teamSection)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tsigJSONAfterReverse, err := sigBodyAfterReverse.Marshal()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tv2Sig, err := makeSigchainV2OuterSig(\n+\t\tdeviceSigningKey,\n+\t\tlibkb.LinkTypeTeamRoot,\n+\t\t1, /* seqno */\n+\t\tsigJSONAfterReverse,\n+\t\tnil,   /* prevLinkID */\n+\t\tfalse, /* hasRevokes */\n+\t)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tsigMultiItem := libkb.SigMultiItem{\n+\t\tSig:        v2Sig,\n+\t\tSigningKID: deviceSigningKey.GetKID(),\n+\t\tType:       string(libkb.LinkTypeTeamRoot),\n+\t\tSigInner:   string(sigJSONAfterReverse),\n+\t\tTeamID:     libkb.RootTeamIDFromName(e.name),\n+\t}\n+\tsigMultiItem.PublicKeys.Encryption = perTeamEncryptionKey.GetKID()\n+\tsigMultiItem.PublicKeys.Signing = perTeamSigningKey.GetKID()\n+\n+\tpayload := make(libkb.JSONPayload)\n+\tpayload[\"sigs\"] = []interface{}{sigMultiItem}\n+\tpayload[\"per_team_key\"] = secretboxes\n+\n+\t_, err = e.G().API.PostJSON(libkb.APIArg{\n+\t\tEndpoint:    \"sig/multi\",\n+\t\tSessionType: libkb.APISessionTypeREQUIRED,\n+\t\tJSONPayload: payload,\n+\t})\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\treturn nil\n+}\n+\n+func (e *TeamCreateEngine) getDeviceKeys(ctx *Context, me *libkb.User) (sigKey libkb.NaclSigningKeyPair, encKey libkb.NaclDHKeyPair, err error) {","path":"go/engine/team_create.go","position":153,"original_position":153,"commit_id":"ca6efd5bdc7768019ddd37b3be0d1ef89e922934","original_commit_id":"ca6efd5bdc7768019ddd37b3be0d1ef89e922934","user":{"login":"mlsteele","id":705646,"avatar_url":"https://avatars1.githubusercontent.com/u/705646?v=3","gravatar_id":"","url":"https://api.github.com/users/mlsteele","html_url":"https://github.com/mlsteele","followers_url":"https://api.github.com/users/mlsteele/followers","following_url":"https://api.github.com/users/mlsteele/following{/other_user}","gists_url":"https://api.github.com/users/mlsteele/gists{/gist_id}","starred_url":"https://api.github.com/users/mlsteele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlsteele/subscriptions","organizations_url":"https://api.github.com/users/mlsteele/orgs","repos_url":"https://api.github.com/users/mlsteele/repos","events_url":"https://api.github.com/users/mlsteele/events{/privacy}","received_events_url":"https://api.github.com/users/mlsteele/received_events","type":"User","site_admin":false},"body":"at some point we gotta factor this out","created_at":"2017-05-18T15:27:36Z","updated_at":"2017-05-18T15:27:36Z","html_url":"https://github.com/keybase/client/pull/7030#discussion_r117279406","pull_request_url":"https://api.github.com/repos/keybase/client/pulls/7030","_links":{"self":{"href":"https://api.github.com/repos/keybase/client/pulls/comments/117279406"},"html":{"href":"https://github.com/keybase/client/pull/7030#discussion_r117279406"},"pull_request":{"href":"https://api.github.com/repos/keybase/client/pulls/7030"}}},"pull_request":{"url":"https://api.github.com/repos/keybase/client/pulls/7030","id":121162381,"html_url":"https://github.com/keybase/client/pull/7030","diff_url":"https://github.com/keybase/client/pull/7030.diff","patch_url":"https://github.com/keybase/client/pull/7030.patch","issue_url":"https://api.github.com/repos/keybase/client/issues/7030","number":7030,"state":"open","locked":false,"title":"CreateTeamEngine","user":{"login":"oconnor663","id":860932,"avatar_url":"https://avatars3.githubusercontent.com/u/860932?v=3","gravatar_id":"","url":"https://api.github.com/users/oconnor663","html_url":"https://github.com/oconnor663","followers_url":"https://api.github.com/users/oconnor663/followers","following_url":"https://api.github.com/users/oconnor663/following{/other_user}","gists_url":"https://api.github.com/users/oconnor663/gists{/gist_id}","starred_url":"https://api.github.com/users/oconnor663/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oconnor663/subscriptions","organizations_url":"https://api.github.com/users/oconnor663/orgs","repos_url":"https://api.github.com/users/oconnor663/repos","events_url":"https://api.github.com/users/oconnor663/events{/privacy}","received_events_url":"https://api.github.com/users/oconnor663/received_events","type":"User","site_admin":false},"body":"r? @mlsteele @maxtaco \r\n\r\nTrying to follow the example here: https://gist.github.com/maxtaco/2cb8ddbd023a355b85fe0b5babdba927\r\n\r\nThings intentionally left out of the code so far:\r\n- Adding multiple users. Right now it just adds the one creator.\r\n- Formatting the `Prev` box. It's always null for the root link, so there's no implementation here.\r\n- Opening the `per_team_key.boxes` format. Nothing does this yet, so their formatting might be wrong, but I eyeballed the output at it at least looks right.","created_at":"2017-05-17T22:03:12Z","updated_at":"2017-05-18T15:27:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd8827a72ad678a7c6d00c8049f39ac9b7e4eefd","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/keybase/client/pulls/7030/commits","review_comments_url":"https://api.github.com/repos/keybase/client/pulls/7030/comments","review_comment_url":"https://api.github.com/repos/keybase/client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/keybase/client/issues/7030/comments","statuses_url":"https://api.github.com/repos/keybase/client/statuses/ca6efd5bdc7768019ddd37b3be0d1ef89e922934","head":{"label":"keybase:jack/CORE-5112/postchanges","ref":"jack/CORE-5112/postchanges","sha":"ca6efd5bdc7768019ddd37b3be0d1ef89e922934","user":{"login":"keybase","id":5400834,"avatar_url":"https://avatars1.githubusercontent.com/u/5400834?v=3","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"repo":{"id":29099181,"name":"client","full_name":"keybase/client","owner":{"login":"keybase","id":5400834,"avatar_url":"https://avatars1.githubusercontent.com/u/5400834?v=3","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/keybase/client","description":"Keybase Go Library, Client, Service, OS X, iOS, Android, Electron","fork":false,"url":"https://api.github.com/repos/keybase/client","forks_url":"https://api.github.com/repos/keybase/client/forks","keys_url":"https://api.github.com/repos/keybase/client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keybase/client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keybase/client/teams","hooks_url":"https://api.github.com/repos/keybase/client/hooks","issue_events_url":"https://api.github.com/repos/keybase/client/issues/events{/number}","events_url":"https://api.github.com/repos/keybase/client/events","assignees_url":"https://api.github.com/repos/keybase/client/assignees{/user}","branches_url":"https://api.github.com/repos/keybase/client/branches{/branch}","tags_url":"https://api.github.com/repos/keybase/client/tags","blobs_url":"https://api.github.com/repos/keybase/client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keybase/client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keybase/client/git/refs{/sha}","trees_url":"https://api.github.com/repos/keybase/client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keybase/client/statuses/{sha}","languages_url":"https://api.github.com/repos/keybase/client/languages","stargazers_url":"https://api.github.com/repos/keybase/client/stargazers","contributors_url":"https://api.github.com/repos/keybase/client/contributors","subscribers_url":"https://api.github.com/repos/keybase/client/subscribers","subscription_url":"https://api.github.com/repos/keybase/client/subscription","commits_url":"https://api.github.com/repos/keybase/client/commits{/sha}","git_commits_url":"https://api.github.com/repos/keybase/client/git/commits{/sha}","comments_url":"https://api.github.com/repos/keybase/client/comments{/number}","issue_comment_url":"https://api.github.com/repos/keybase/client/issues/comments{/number}","contents_url":"https://api.github.com/repos/keybase/client/contents/{+path}","compare_url":"https://api.github.com/repos/keybase/client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keybase/client/merges","archive_url":"https://api.github.com/repos/keybase/client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keybase/client/downloads","issues_url":"https://api.github.com/repos/keybase/client/issues{/number}","pulls_url":"https://api.github.com/repos/keybase/client/pulls{/number}","milestones_url":"https://api.github.com/repos/keybase/client/milestones{/number}","notifications_url":"https://api.github.com/repos/keybase/client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keybase/client/labels{/name}","releases_url":"https://api.github.com/repos/keybase/client/releases{/id}","deployments_url":"https://api.github.com/repos/keybase/client/deployments","created_at":"2015-01-11T17:17:12Z","updated_at":"2017-05-18T11:52:32Z","pushed_at":"2017-05-18T15:20:24Z","git_url":"git://github.com/keybase/client.git","ssh_url":"git@github.com:keybase/client.git","clone_url":"https://github.com/keybase/client.git","svn_url":"https://github.com/keybase/client","homepage":"","size":187119,"stargazers_count":1851,"watchers_count":1851,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":159,"mirror_url":null,"open_issues_count":971,"forks":159,"open_issues":971,"watchers":1851,"default_branch":"master"}},"base":{"label":"keybase:master","ref":"master","sha":"a9e4cba986c1abb18e200eea443168d65f69be39","user":{"login":"keybase","id":5400834,"avatar_url":"https://avatars1.githubusercontent.com/u/5400834?v=3","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"repo":{"id":29099181,"name":"client","full_name":"keybase/client","owner":{"login":"keybase","id":5400834,"avatar_url":"https://avatars1.githubusercontent.com/u/5400834?v=3","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/keybase/client","description":"Keybase Go Library, Client, Service, OS X, iOS, Android, Electron","fork":false,"url":"https://api.github.com/repos/keybase/client","forks_url":"https://api.github.com/repos/keybase/client/forks","keys_url":"https://api.github.com/repos/keybase/client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keybase/client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keybase/client/teams","hooks_url":"https://api.github.com/repos/keybase/client/hooks","issue_events_url":"https://api.github.com/repos/keybase/client/issues/events{/number}","events_url":"https://api.github.com/repos/keybase/client/events","assignees_url":"https://api.github.com/repos/keybase/client/assignees{/user}","branches_url":"https://api.github.com/repos/keybase/client/branches{/branch}","tags_url":"https://api.github.com/repos/keybase/client/tags","blobs_url":"https://api.github.com/repos/keybase/client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keybase/client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keybase/client/git/refs{/sha}","trees_url":"https://api.github.com/repos/keybase/client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keybase/client/statuses/{sha}","languages_url":"https://api.github.com/repos/keybase/client/languages","stargazers_url":"https://api.github.com/repos/keybase/client/stargazers","contributors_url":"https://api.github.com/repos/keybase/client/contributors","subscribers_url":"https://api.github.com/repos/keybase/client/subscribers","subscription_url":"https://api.github.com/repos/keybase/client/subscription","commits_url":"https://api.github.com/repos/keybase/client/commits{/sha}","git_commits_url":"https://api.github.com/repos/keybase/client/git/commits{/sha}","comments_url":"https://api.github.com/repos/keybase/client/comments{/number}","issue_comment_url":"https://api.github.com/repos/keybase/client/issues/comments{/number}","contents_url":"https://api.github.com/repos/keybase/client/contents/{+path}","compare_url":"https://api.github.com/repos/keybase/client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keybase/client/merges","archive_url":"https://api.github.com/repos/keybase/client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keybase/client/downloads","issues_url":"https://api.github.com/repos/keybase/client/issues{/number}","pulls_url":"https://api.github.com/repos/keybase/client/pulls{/number}","milestones_url":"https://api.github.com/repos/keybase/client/milestones{/number}","notifications_url":"https://api.github.com/repos/keybase/client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keybase/client/labels{/name}","releases_url":"https://api.github.com/repos/keybase/client/releases{/id}","deployments_url":"https://api.github.com/repos/keybase/client/deployments","created_at":"2015-01-11T17:17:12Z","updated_at":"2017-05-18T11:52:32Z","pushed_at":"2017-05-18T15:20:24Z","git_url":"git://github.com/keybase/client.git","ssh_url":"git@github.com:keybase/client.git","clone_url":"https://github.com/keybase/client.git","svn_url":"https://github.com/keybase/client","homepage":"","size":187119,"stargazers_count":1851,"watchers_count":1851,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":159,"mirror_url":null,"open_issues_count":971,"forks":159,"open_issues":971,"watchers":1851,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/keybase/client/pulls/7030"},"html":{"href":"https://github.com/keybase/client/pull/7030"},"issue":{"href":"https://api.github.com/repos/keybase/client/issues/7030"},"comments":{"href":"https://api.github.com/repos/keybase/client/issues/7030/comments"},"review_comments":{"href":"https://api.github.com/repos/keybase/client/pulls/7030/comments"},"review_comment":{"href":"https://api.github.com/repos/keybase/client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/keybase/client/pulls/7030/commits"},"statuses":{"href":"https://api.github.com/repos/keybase/client/statuses/ca6efd5bdc7768019ddd37b3be0d1ef89e922934"}}}}
{"actor":{"display_login":"mlsteele"}}