{"action":"created","comment":{"url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments/44269181","id":44269181,"diff_hunk":"@@ -0,0 +1,116 @@\n+// -*- Mode: Go; indent-tabs-mode: t -*-\n+\n+/*\n+ * Copyright (C) 2014-2015 Canonical Ltd\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+// Package asserts implements snappy assertions and a store\n+// abstraction for managing and holding them.\n+package asserts\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/hex\"\n+\t\"errors\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\n+\t\"golang.org/x/crypto/openpgp/packet\"\n+\n+\t\"github.com/ubuntu-core/snappy/helpers\"\n+)\n+\n+// StoreConfig for an assertion store.\n+type StoreConfig struct {\n+\t// store backstore path\n+\tPath string\n+}\n+\n+// AssertStore holds assertions and can be used to sign or check\n+// further assertions.\n+type AssertStore struct {\n+\troot string\n+}\n+\n+const (\n+\tprivateKeysLayoutVersion = \"v0\"\n+\tprivateKeysRoot          = \"private-keys-\" + privateKeysLayoutVersion\n+)\n+\n+// errors\n+var (\n+\tErrStoreRootCreate        = errors.New(\"failed to create assert store root\")\n+\tErrStoreRootWorldReadable = errors.New(\"assert store root unexpectedly world-writable\")\n+\tErrStoreKeyGen            = errors.New(\"failed to generate private key\")\n+\tErrStoreStoringKey        = errors.New(\"failed to store private key\")\n+)\n+\n+// OpenStore opens the assertion store based on the configuration.\n+func OpenStore(cfg *StoreConfig) (*AssertStore, error) {\n+\terr := os.MkdirAll(cfg.Path, 0775)\n+\tif err != nil {\n+\t\treturn nil, ErrStoreRootCreate\n+\t}\n+\tinfo, err := os.Stat(cfg.Path)\n+\tif err != nil {\n+\t\treturn nil, ErrStoreRootCreate\n+\t}\n+\tif info.Mode().Perm()&0002 != 0 {\n+\t\treturn nil, ErrStoreRootWorldReadable\n+\t}\n+\treturn &AssertStore{root: cfg.Path}, nil\n+}\n+\n+func (astore *AssertStore) atomicWriteEntry(data []byte, secret bool, hier ...string) error {\n+\tfpath := filepath.Join(astore.root, filepath.Join(hier...))\n+\tdir := filepath.Dir(fpath)\n+\terr := os.MkdirAll(dir, 0775)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tfperm := 0664\n+\tif secret {\n+\t\tfperm = 0600\n+\t}\n+\treturn helpers.AtomicWriteFile(fpath, data, os.FileMode(fperm), 0)\n+}\n+\n+// GenerateKey generates a private/public key pair for identity and\n+// stores it returning its fingerprint.\n+func (astore *AssertStore) GenerateKey(authorityID string) (fingerprint []byte, err error) {\n+\t// TODO: support specifying different key types/algorithms\n+\tprivKey, err := generatePrivateKey()\n+\tif err != nil {\n+\t\treturn nil, ErrStoreKeyGen","path":"asserts/store.go","position":97,"original_position":97,"commit_id":"9859c27e2cc4603f131ef30619e68dd7ac575a5e","original_commit_id":"9859c27e2cc4603f131ef30619e68dd7ac575a5e","user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"body":"Why is the actual error, generated by our own local function, being thrown away? How can we tell what actually happened?","created_at":"2015-11-09T12:25:56Z","updated_at":"2015-11-09T12:25:56Z","html_url":"https://github.com/ubuntu-core/snappy/pull/66#discussion_r44269181","pull_request_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66","_links":{"self":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments/44269181"},"html":{"href":"https://github.com/ubuntu-core/snappy/pull/66#discussion_r44269181"},"pull_request":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66"}}},"pull_request":{"url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66","id":50114687,"html_url":"https://github.com/ubuntu-core/snappy/pull/66","diff_url":"https://github.com/ubuntu-core/snappy/pull/66.diff","patch_url":"https://github.com/ubuntu-core/snappy/pull/66.patch","issue_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/66","number":66,"state":"open","locked":false,"title":"start of asserts  package with AssertStore implementing GenerateKey and ImportKey","user":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"body":"started with AssertStore just a concrete struct. As discussed for now hardcode the choice of key algorithm type (RSA).","created_at":"2015-11-09T12:06:46Z","updated_at":"2015-11-09T12:25:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"184db3bb525d16429ed450ef030d7293c8af0194","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66/commits","review_comments_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66/comments","review_comment_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/66/comments","statuses_url":"https://api.github.com/repos/ubuntu-core/snappy/statuses/9859c27e2cc4603f131ef30619e68dd7ac575a5e","head":{"label":"pedronis:asserts-generate-key-and-import-key","ref":"asserts-generate-key-and-import-key","sha":"9859c27e2cc4603f131ef30619e68dd7ac575a5e","user":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"repo":{"id":45828707,"name":"snappy","full_name":"pedronis/snappy","owner":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pedronis/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/pedronis/snappy","forks_url":"https://api.github.com/repos/pedronis/snappy/forks","keys_url":"https://api.github.com/repos/pedronis/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pedronis/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pedronis/snappy/teams","hooks_url":"https://api.github.com/repos/pedronis/snappy/hooks","issue_events_url":"https://api.github.com/repos/pedronis/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/pedronis/snappy/events","assignees_url":"https://api.github.com/repos/pedronis/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/pedronis/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/pedronis/snappy/tags","blobs_url":"https://api.github.com/repos/pedronis/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pedronis/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pedronis/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/pedronis/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pedronis/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/pedronis/snappy/languages","stargazers_url":"https://api.github.com/repos/pedronis/snappy/stargazers","contributors_url":"https://api.github.com/repos/pedronis/snappy/contributors","subscribers_url":"https://api.github.com/repos/pedronis/snappy/subscribers","subscription_url":"https://api.github.com/repos/pedronis/snappy/subscription","commits_url":"https://api.github.com/repos/pedronis/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/pedronis/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/pedronis/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/pedronis/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/pedronis/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/pedronis/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pedronis/snappy/merges","archive_url":"https://api.github.com/repos/pedronis/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pedronis/snappy/downloads","issues_url":"https://api.github.com/repos/pedronis/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/pedronis/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/pedronis/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/pedronis/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pedronis/snappy/labels{/name}","releases_url":"https://api.github.com/repos/pedronis/snappy/releases{/id}","created_at":"2015-11-09T09:40:46Z","updated_at":"2015-11-09T09:40:49Z","pushed_at":"2015-11-09T12:03:48Z","git_url":"git://github.com/pedronis/snappy.git","ssh_url":"git@github.com:pedronis/snappy.git","clone_url":"https://github.com/pedronis/snappy.git","svn_url":"https://github.com/pedronis/snappy","homepage":null,"size":24704,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ubuntu-core:master","ref":"master","sha":"ea93ba5cb295a3d9f6fa1913678e77ee96733103","user":{"login":"ubuntu-core","id":15022473,"avatar_url":"https://avatars.githubusercontent.com/u/15022473?v=3","gravatar_id":"","url":"https://api.github.com/users/ubuntu-core","html_url":"https://github.com/ubuntu-core","followers_url":"https://api.github.com/users/ubuntu-core/followers","following_url":"https://api.github.com/users/ubuntu-core/following{/other_user}","gists_url":"https://api.github.com/users/ubuntu-core/gists{/gist_id}","starred_url":"https://api.github.com/users/ubuntu-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubuntu-core/subscriptions","organizations_url":"https://api.github.com/users/ubuntu-core/orgs","repos_url":"https://api.github.com/users/ubuntu-core/repos","events_url":"https://api.github.com/users/ubuntu-core/events{/privacy}","received_events_url":"https://api.github.com/users/ubuntu-core/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snappy","full_name":"ubuntu-core/snappy","owner":{"login":"ubuntu-core","id":15022473,"avatar_url":"https://avatars.githubusercontent.com/u/15022473?v=3","gravatar_id":"","url":"https://api.github.com/users/ubuntu-core","html_url":"https://github.com/ubuntu-core","followers_url":"https://api.github.com/users/ubuntu-core/followers","following_url":"https://api.github.com/users/ubuntu-core/following{/other_user}","gists_url":"https://api.github.com/users/ubuntu-core/gists{/gist_id}","starred_url":"https://api.github.com/users/ubuntu-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubuntu-core/subscriptions","organizations_url":"https://api.github.com/users/ubuntu-core/orgs","repos_url":"https://api.github.com/users/ubuntu-core/repos","events_url":"https://api.github.com/users/ubuntu-core/events{/privacy}","received_events_url":"https://api.github.com/users/ubuntu-core/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubuntu-core/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":false,"url":"https://api.github.com/repos/ubuntu-core/snappy","forks_url":"https://api.github.com/repos/ubuntu-core/snappy/forks","keys_url":"https://api.github.com/repos/ubuntu-core/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubuntu-core/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubuntu-core/snappy/teams","hooks_url":"https://api.github.com/repos/ubuntu-core/snappy/hooks","issue_events_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/ubuntu-core/snappy/events","assignees_url":"https://api.github.com/repos/ubuntu-core/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/ubuntu-core/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/ubuntu-core/snappy/tags","blobs_url":"https://api.github.com/repos/ubuntu-core/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubuntu-core/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubuntu-core/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubuntu-core/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubuntu-core/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/ubuntu-core/snappy/languages","stargazers_url":"https://api.github.com/repos/ubuntu-core/snappy/stargazers","contributors_url":"https://api.github.com/repos/ubuntu-core/snappy/contributors","subscribers_url":"https://api.github.com/repos/ubuntu-core/snappy/subscribers","subscription_url":"https://api.github.com/repos/ubuntu-core/snappy/subscription","commits_url":"https://api.github.com/repos/ubuntu-core/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubuntu-core/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubuntu-core/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubuntu-core/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/ubuntu-core/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubuntu-core/snappy/merges","archive_url":"https://api.github.com/repos/ubuntu-core/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubuntu-core/snappy/downloads","issues_url":"https://api.github.com/repos/ubuntu-core/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/ubuntu-core/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/ubuntu-core/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubuntu-core/snappy/labels{/name}","releases_url":"https://api.github.com/repos/ubuntu-core/snappy/releases{/id}","created_at":"2015-10-21T11:51:46Z","updated_at":"2015-11-06T01:51:18Z","pushed_at":"2015-11-09T12:16:46Z","git_url":"git://github.com/ubuntu-core/snappy.git","ssh_url":"git@github.com:ubuntu-core/snappy.git","clone_url":"https://github.com/ubuntu-core/snappy.git","svn_url":"https://github.com/ubuntu-core/snappy","homepage":null,"size":24704,"stargazers_count":30,"watchers_count":30,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":15,"forks":12,"open_issues":15,"watchers":30,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66"},"html":{"href":"https://github.com/ubuntu-core/snappy/pull/66"},"issue":{"href":"https://api.github.com/repos/ubuntu-core/snappy/issues/66"},"comments":{"href":"https://api.github.com/repos/ubuntu-core/snappy/issues/66/comments"},"review_comments":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66/comments"},"review_comment":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/66/commits"},"statuses":{"href":"https://api.github.com/repos/ubuntu-core/snappy/statuses/9859c27e2cc4603f131ef30619e68dd7ac575a5e"}}}}