{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/rocket/pulls/comments/23420841","id":23420841,"diff_hunk":"@@ -0,0 +1,230 @@\n+// Copyright 2015 CoreOS, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+//+build linux\n+\n+// implements https://github.com/coreos/rocket/issues/367\n+\n+package main\n+\n+import (\n+\t\"fmt\"\n+\t\"io\"\n+\t\"io/ioutil\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"os\"\n+\t\"strings\"\n+\n+\t\"github.com/coreos/rocket/Godeps/_workspace/src/golang.org/x/crypto/openpgp\"\n+\t\"github.com/coreos/rocket/pkg/keystore\"\n+)\n+\n+var (\n+\tcmdTrust = &Command{\n+\t\tName:    cmdTrustName,\n+\t\tSummary: \"Trust a key for image verification\",\n+\t\tUsage:   \"[--prefix PREFIX] [--do-not-ask-confirmation] PUBKEY\",\n+\t\tRun:     runTrust,\n+\t}\n+\tflagPrefix string\n+\tflagAccept bool\n+)\n+\n+const (\n+\tcmdTrustName = \"trust\"\n+)\n+\n+func init() {\n+\tcommands = append(commands, cmdTrust)\n+\tcmdTrust.Flags.StringVar(&flagPrefix, \"prefix\", \"\", \"prefix to limit trust to\")\n+\tcmdTrust.Flags.BoolVar(&flagAccept, \"do-not-ask-confirmation\", false, \"suppress interactive confirmation of key addition\")\n+}\n+\n+func runTrust(args []string) (exit int) {\n+\tif len(args) != 1 {\n+\t\tprintCommandUsageByName(cmdTrustName)\n+\t\treturn 1\n+\t}\n+\n+\tpkl, err := getPubKeyLocation(flagPrefix, args)\n+\tif err != nil {\n+\t\tfmt.Fprintf(os.Stderr, \"Error determining key location: %v\\n\", err)\n+\t\treturn 1\n+\t}\n+\n+\tpk, err := getPubKey(pkl)\n+\tif err != nil {\n+\t\tfmt.Fprintf(os.Stderr, \"Error accessing key: %v\\n\", err)\n+\t\treturn 1\n+\t}\n+\tdefer pk.Close()\n+\n+\taccepted, err := reviewKey(pk, flagAccept)\n+\tif err != nil {\n+\t\tfmt.Fprintf(os.Stderr, \"Error reviewing key: %v\\n\", err)\n+\t}\n+\n+\tif !accepted {\n+\t\tfmt.Fprintf(os.Stderr, \"Not trusting %q.\\n\", pkl)\n+\t\treturn 0\n+\t}\n+\n+\tfmt.Printf(\"Trusting %q for prefix %q.\\n\", pkl, flagPrefix)\n+\n+\tif err := addPubKey(flagPrefix, pk); err != nil {\n+\t\tfmt.Fprintf(os.Stderr, \"Error adding key: %v\\n\", err)\n+\t\treturn 1\n+\t}\n+\n+\treturn 0\n+}\n+\n+// getPubKeyLocation either returns the location supplied in argv or discovers one @ prefix\n+func getPubKeyLocation(prefix string, args []string) (string, error) {\n+\tif len(args) == 1 {\n+\t\treturn args[0], nil\n+\t}\n+\n+\tif len(args) > 1 {\n+\t\treturn \"\", fmt.Errorf(\"too many arguments\")\n+\t}\n+\n+\tif prefix == \"\" {\n+\t\treturn \"\", fmt.Errorf(\"a key or --prefix required\")\n+\t}\n+\n+\t// TODO(vc): discover location from --prefix and return it here?\n+\n+\treturn \"\", nil\n+}\n+\n+// getPubKey retrieves a public key (if remote), and verifies it's a gpg key\n+func getPubKey(location string) (*os.File, error) {\n+\tu, err := url.Parse(location)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tswitch u.Scheme {\n+\tcase \"\":\n+\t\treturn os.Open(location)\n+\tcase \"http\":\n+\t\tfallthrough\n+\tcase \"https\":\n+\t\treturn downloadKey(u.String())\n+\tdefault:\n+\t}\n+\treturn nil, fmt.Errorf(\"only http and https urls supported\")","path":"rkt/trust.go","position":129,"original_position":129,"commit_id":"5a0cab406196aa7064fb69ef4e38a9627f6ac618","original_commit_id":"5a0cab406196aa7064fb69ef4e38a9627f6ac618","user":{"login":"jonboulle","id":2601015,"avatar_url":"https://avatars.githubusercontent.com/u/2601015?v=3","gravatar_id":"","url":"https://api.github.com/users/jonboulle","html_url":"https://github.com/jonboulle","followers_url":"https://api.github.com/users/jonboulle/followers","following_url":"https://api.github.com/users/jonboulle/following{/other_user}","gists_url":"https://api.github.com/users/jonboulle/gists{/gist_id}","starred_url":"https://api.github.com/users/jonboulle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonboulle/subscriptions","organizations_url":"https://api.github.com/users/jonboulle/orgs","repos_url":"https://api.github.com/users/jonboulle/repos","events_url":"https://api.github.com/users/jonboulle/events{/privacy}","received_events_url":"https://api.github.com/users/jonboulle/received_events","type":"User","site_admin":false},"body":"Either move this into the default clause or remove the clause","created_at":"2015-01-22T23:39:05Z","updated_at":"2015-01-22T23:39:05Z","html_url":"https://github.com/coreos/rocket/pull/406#discussion_r23420841","pull_request_url":"https://api.github.com/repos/coreos/rocket/pulls/406","_links":{"self":{"href":"https://api.github.com/repos/coreos/rocket/pulls/comments/23420841"},"html":{"href":"https://github.com/coreos/rocket/pull/406#discussion_r23420841"},"pull_request":{"href":"https://api.github.com/repos/coreos/rocket/pulls/406"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/rocket/pulls/406","id":27815292,"html_url":"https://github.com/coreos/rocket/pull/406","diff_url":"https://github.com/coreos/rocket/pull/406.diff","patch_url":"https://github.com/coreos/rocket/pull/406.patch","issue_url":"https://api.github.com/repos/coreos/rocket/issues/406","number":406,"state":"open","locked":false,"title":"rkt: implement `rkt trust` command","user":{"login":"vcaputo","id":1452963,"avatar_url":"https://avatars.githubusercontent.com/u/1452963?v=3","gravatar_id":"","url":"https://api.github.com/users/vcaputo","html_url":"https://github.com/vcaputo","followers_url":"https://api.github.com/users/vcaputo/followers","following_url":"https://api.github.com/users/vcaputo/following{/other_user}","gists_url":"https://api.github.com/users/vcaputo/gists{/gist_id}","starred_url":"https://api.github.com/users/vcaputo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vcaputo/subscriptions","organizations_url":"https://api.github.com/users/vcaputo/orgs","repos_url":"https://api.github.com/users/vcaputo/repos","events_url":"https://api.github.com/users/vcaputo/events{/privacy}","received_events_url":"https://api.github.com/users/vcaputo/received_events","type":"User","site_admin":false},"body":"Example output:\r\n\r\n$ rkt trust --prefix foo.net/woot http://pengaru.com/~swivel/pubkeys.gpg\r\n  GPG key fingerprint is: BF65 1A65 AE01 DC62 C469  9CF5 E627 E9F1 4D8E F0A2\r\n      Subkey fingerprint: 0434 4CC9 525E 1348 7735  D4DF 8396 4F3D F63C F071\r\n          Kelsey Hightower (ACI signing key) <kelsey.hightower@coreos.com>\r\n  Are you sure you want to trust this key (yes/no)? no\r\n  Not trusting \"http://pengaru.com/~swivel/pubkeys.gpg\".\r\n$\r\n\r\n$ rkt trust --prefix foo.net/woot http://pengaru.com/~swivel/pubkeys.gpg\r\n  GPG key fingerprint is: BF65 1A65 AE01 DC62 C469  9CF5 E627 E9F1 4D8E F0A2\r\n      Subkey fingerprint: 0434 4CC9 525E 1348 7735  D4DF 8396 4F3D F63C F071\r\n          Kelsey Hightower (ACI signing key) <kelsey.hightower@coreos.com>\r\n  Are you sure you want to trust this key (yes/no)? yes\r\n  Trusting \"http://pengaru.com/~swivel/pubkeys.gpg\" for prefix \"foo.net/woot\".\r\n$","created_at":"2015-01-22T03:15:26Z","updated_at":"2015-01-22T23:39:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aecf0be44aa25908116eeef9ff9a988945816941","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coreos/rocket/pulls/406/commits","review_comments_url":"https://api.github.com/repos/coreos/rocket/pulls/406/comments","review_comment_url":"https://api.github.com/repos/coreos/rocket/pulls/comments/{number}","comments_url":"https://api.github.com/repos/coreos/rocket/issues/406/comments","statuses_url":"https://api.github.com/repos/coreos/rocket/statuses/5a0cab406196aa7064fb69ef4e38a9627f6ac618","head":{"label":"vcaputo:trust","ref":"trust","sha":"5a0cab406196aa7064fb69ef4e38a9627f6ac618","user":{"login":"vcaputo","id":1452963,"avatar_url":"https://avatars.githubusercontent.com/u/1452963?v=3","gravatar_id":"","url":"https://api.github.com/users/vcaputo","html_url":"https://github.com/vcaputo","followers_url":"https://api.github.com/users/vcaputo/followers","following_url":"https://api.github.com/users/vcaputo/following{/other_user}","gists_url":"https://api.github.com/users/vcaputo/gists{/gist_id}","starred_url":"https://api.github.com/users/vcaputo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vcaputo/subscriptions","organizations_url":"https://api.github.com/users/vcaputo/orgs","repos_url":"https://api.github.com/users/vcaputo/repos","events_url":"https://api.github.com/users/vcaputo/events{/privacy}","received_events_url":"https://api.github.com/users/vcaputo/received_events","type":"User","site_admin":false},"repo":{"id":27401830,"name":"rocket","full_name":"vcaputo/rocket","owner":{"login":"vcaputo","id":1452963,"avatar_url":"https://avatars.githubusercontent.com/u/1452963?v=3","gravatar_id":"","url":"https://api.github.com/users/vcaputo","html_url":"https://github.com/vcaputo","followers_url":"https://api.github.com/users/vcaputo/followers","following_url":"https://api.github.com/users/vcaputo/following{/other_user}","gists_url":"https://api.github.com/users/vcaputo/gists{/gist_id}","starred_url":"https://api.github.com/users/vcaputo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vcaputo/subscriptions","organizations_url":"https://api.github.com/users/vcaputo/orgs","repos_url":"https://api.github.com/users/vcaputo/repos","events_url":"https://api.github.com/users/vcaputo/events{/privacy}","received_events_url":"https://api.github.com/users/vcaputo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vcaputo/rocket","description":"App Container runtime","fork":true,"url":"https://api.github.com/repos/vcaputo/rocket","forks_url":"https://api.github.com/repos/vcaputo/rocket/forks","keys_url":"https://api.github.com/repos/vcaputo/rocket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vcaputo/rocket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vcaputo/rocket/teams","hooks_url":"https://api.github.com/repos/vcaputo/rocket/hooks","issue_events_url":"https://api.github.com/repos/vcaputo/rocket/issues/events{/number}","events_url":"https://api.github.com/repos/vcaputo/rocket/events","assignees_url":"https://api.github.com/repos/vcaputo/rocket/assignees{/user}","branches_url":"https://api.github.com/repos/vcaputo/rocket/branches{/branch}","tags_url":"https://api.github.com/repos/vcaputo/rocket/tags","blobs_url":"https://api.github.com/repos/vcaputo/rocket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vcaputo/rocket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vcaputo/rocket/git/refs{/sha}","trees_url":"https://api.github.com/repos/vcaputo/rocket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vcaputo/rocket/statuses/{sha}","languages_url":"https://api.github.com/repos/vcaputo/rocket/languages","stargazers_url":"https://api.github.com/repos/vcaputo/rocket/stargazers","contributors_url":"https://api.github.com/repos/vcaputo/rocket/contributors","subscribers_url":"https://api.github.com/repos/vcaputo/rocket/subscribers","subscription_url":"https://api.github.com/repos/vcaputo/rocket/subscription","commits_url":"https://api.github.com/repos/vcaputo/rocket/commits{/sha}","git_commits_url":"https://api.github.com/repos/vcaputo/rocket/git/commits{/sha}","comments_url":"https://api.github.com/repos/vcaputo/rocket/comments{/number}","issue_comment_url":"https://api.github.com/repos/vcaputo/rocket/issues/comments/{number}","contents_url":"https://api.github.com/repos/vcaputo/rocket/contents/{+path}","compare_url":"https://api.github.com/repos/vcaputo/rocket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vcaputo/rocket/merges","archive_url":"https://api.github.com/repos/vcaputo/rocket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vcaputo/rocket/downloads","issues_url":"https://api.github.com/repos/vcaputo/rocket/issues{/number}","pulls_url":"https://api.github.com/repos/vcaputo/rocket/pulls{/number}","milestones_url":"https://api.github.com/repos/vcaputo/rocket/milestones{/number}","notifications_url":"https://api.github.com/repos/vcaputo/rocket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vcaputo/rocket/labels{/name}","releases_url":"https://api.github.com/repos/vcaputo/rocket/releases{/id}","created_at":"2014-12-01T21:54:09Z","updated_at":"2014-12-01T21:54:10Z","pushed_at":"2015-01-22T21:48:42Z","git_url":"git://github.com/vcaputo/rocket.git","ssh_url":"git@github.com:vcaputo/rocket.git","clone_url":"https://github.com/vcaputo/rocket.git","svn_url":"https://github.com/vcaputo/rocket","homepage":"","size":1724,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"27acfc4ec59db792ebeed88faa25717e0ee340cf","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":26509369,"name":"rocket","full_name":"coreos/rocket","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/rocket","description":"App Container runtime","fork":false,"url":"https://api.github.com/repos/coreos/rocket","forks_url":"https://api.github.com/repos/coreos/rocket/forks","keys_url":"https://api.github.com/repos/coreos/rocket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/rocket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/rocket/teams","hooks_url":"https://api.github.com/repos/coreos/rocket/hooks","issue_events_url":"https://api.github.com/repos/coreos/rocket/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/rocket/events","assignees_url":"https://api.github.com/repos/coreos/rocket/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/rocket/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/rocket/tags","blobs_url":"https://api.github.com/repos/coreos/rocket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/rocket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/rocket/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/rocket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/rocket/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/rocket/languages","stargazers_url":"https://api.github.com/repos/coreos/rocket/stargazers","contributors_url":"https://api.github.com/repos/coreos/rocket/contributors","subscribers_url":"https://api.github.com/repos/coreos/rocket/subscribers","subscription_url":"https://api.github.com/repos/coreos/rocket/subscription","commits_url":"https://api.github.com/repos/coreos/rocket/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/rocket/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/rocket/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/rocket/issues/comments/{number}","contents_url":"https://api.github.com/repos/coreos/rocket/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/rocket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/rocket/merges","archive_url":"https://api.github.com/repos/coreos/rocket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/rocket/downloads","issues_url":"https://api.github.com/repos/coreos/rocket/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/rocket/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/rocket/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/rocket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/rocket/labels{/name}","releases_url":"https://api.github.com/repos/coreos/rocket/releases{/id}","created_at":"2014-11-11T23:13:18Z","updated_at":"2015-01-22T23:31:48Z","pushed_at":"2015-01-22T23:31:48Z","git_url":"git://github.com/coreos/rocket.git","ssh_url":"git@github.com:coreos/rocket.git","clone_url":"https://github.com/coreos/rocket.git","svn_url":"https://github.com/coreos/rocket","homepage":"","size":7865,"stargazers_count":3202,"watchers_count":3202,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":216,"mirror_url":null,"open_issues_count":56,"forks":216,"open_issues":56,"watchers":3202,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/rocket/pulls/406"},"html":{"href":"https://github.com/coreos/rocket/pull/406"},"issue":{"href":"https://api.github.com/repos/coreos/rocket/issues/406"},"comments":{"href":"https://api.github.com/repos/coreos/rocket/issues/406/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/rocket/pulls/406/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/rocket/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/coreos/rocket/pulls/406/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/rocket/statuses/5a0cab406196aa7064fb69ef4e38a9627f6ac618"}}}}