{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/comments/75895362","id":75895362,"diff_hunk":"@@ -0,0 +1,115 @@\n+// Copyright 2016 Google Inc. All Rights Reserved.\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+package webpush\n+\n+import (\n+\t\"crypto\"\n+\t\"crypto/ecdsa\"\n+\t\"crypto/elliptic\"\n+\t\"crypto/rand\"\n+\t\"encoding/base64\"\n+\t\"encoding/json\"\n+\t\"math/big\"\n+\t\"net/url\"\n+\t\"time\"\n+)\n+\n+var (\n+\t// JWT header is always the same, so use a pre-encoded string\n+\tvapidPrefix = []byte(\"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.\")\n+\tdot         = []byte(\".\")\n+)\n+\n+type jwtBody struct {\n+\tAud string `json:\"aud\"`\n+\tSub string `json:\"sub,omitempty\"`\n+\tExp int64  `json:\"exp\"`\n+}\n+\n+// Vapid provides helpers for authenticating the sender of a push message\n+type Vapid struct {\n+\t// The application's private key\n+\tpriv *ecdsa.PrivateKey\n+\n+\t// Sub should be an email or URL, for identification\n+\tSub string\n+}\n+\n+// PublicKey returns an uncompressed EC point representing the\n+// application's public key\n+func (v *Vapid) PublicKey() []byte {\n+\tpub := v.priv.PublicKey\n+\treturn elliptic.Marshal(pub.Curve, pub.X, pub.Y)\n+}\n+\n+// Token creates a token with the specified endpoint, using configured Sub id\n+// and a default expiration (1h).\n+func (v *Vapid) Token(aud string) (string, error) {\n+\turl, err := url.Parse(aud)\n+\tif err != nil {\n+\t\treturn \"\", err\n+\t}\n+\tjwt := jwtBody{Aud: url.Scheme + \"://\" + url.Host}\n+\tif v.Sub != \"\" {\n+\t\tjwt.Sub = v.Sub\n+\t}\n+\tjwt.Exp = int64(time.Now().Unix() + 3600)\n+\tt, err := json.Marshal(jwt)\n+\tif err != nil {\n+\t\treturn \"\", err\n+\t}\n+\tenc := base64.RawURLEncoding\n+\n+\tt64 := make([]byte, enc.EncodedLen(len(t)))\n+\tenc.Encode(t64, t)\n+\n+\ttoken := make([]byte, len(t)+len(vapidPrefix)+100)\n+\ttoken = append(token[:0], vapidPrefix...)\n+\ttoken = append(token, t64...)\n+\n+\thasher := crypto.SHA256.New()\n+\thasher.Write(token)\n+\n+\tr, s, err := ecdsa.Sign(rand.Reader, v.priv, hasher.Sum(nil))","path":"webpush/vapid.go","position":85,"original_position":85,"commit_id":"d00644ee80b2c526918c0a6a88c63d4206fccb0a","original_commit_id":"d00644ee80b2c526918c0a6a88c63d4206fccb0a","user":{"login":"crhym3","id":25405,"avatar_url":"https://avatars.githubusercontent.com/u/25405?v=3","gravatar_id":"","url":"https://api.github.com/users/crhym3","html_url":"https://github.com/crhym3","followers_url":"https://api.github.com/users/crhym3/followers","following_url":"https://api.github.com/users/crhym3/following{/other_user}","gists_url":"https://api.github.com/users/crhym3/gists{/gist_id}","starred_url":"https://api.github.com/users/crhym3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crhym3/subscriptions","organizations_url":"https://api.github.com/users/crhym3/orgs","repos_url":"https://api.github.com/users/crhym3/repos","events_url":"https://api.github.com/users/crhym3/events{/privacy}","received_events_url":"https://api.github.com/users/crhym3/received_events","type":"User","site_admin":false},"body":"I don't think you can actually use sha256.Sum directly. Please, ignore the above comment.","created_at":"2016-08-23T15:52:11Z","updated_at":"2016-08-23T15:52:11Z","html_url":"https://github.com/GoogleChrome/push-encryption-go/pull/17#discussion_r75895362","pull_request_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17","_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/comments/75895362"},"html":{"href":"https://github.com/GoogleChrome/push-encryption-go/pull/17#discussion_r75895362"},"pull_request":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17","id":80674552,"html_url":"https://github.com/GoogleChrome/push-encryption-go/pull/17","diff_url":"https://github.com/GoogleChrome/push-encryption-go/pull/17.diff","patch_url":"https://github.com/GoogleChrome/push-encryption-go/pull/17.patch","issue_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/17","number":17,"state":"open","locked":false,"title":"Add Vapid support, mostly a subset of #11","user":{"login":"wibblymat","id":393358,"avatar_url":"https://avatars.githubusercontent.com/u/393358?v=3","gravatar_id":"","url":"https://api.github.com/users/wibblymat","html_url":"https://github.com/wibblymat","followers_url":"https://api.github.com/users/wibblymat/followers","following_url":"https://api.github.com/users/wibblymat/following{/other_user}","gists_url":"https://api.github.com/users/wibblymat/gists{/gist_id}","starred_url":"https://api.github.com/users/wibblymat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wibblymat/subscriptions","organizations_url":"https://api.github.com/users/wibblymat/orgs","repos_url":"https://api.github.com/users/wibblymat/repos","events_url":"https://api.github.com/users/wibblymat/events{/privacy}","received_events_url":"https://api.github.com/users/wibblymat/received_events","type":"User","site_admin":false},"body":"I was surprised to find the other day that we never resolved the VAPID PR (#11). \r\n\r\nSince the comment thread had stalled, I've put together this smaller counter-proposal that is hopefully less controversial.\r\n\r\n@costinm @crhym3 @gauntface ","created_at":"2016-08-09T18:53:13Z","updated_at":"2016-08-23T15:52:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4ef4a865ce1c019d24315b1e1474caaee058527b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17/commits","review_comments_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17/comments","review_comment_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/17/comments","statuses_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/statuses/d00644ee80b2c526918c0a6a88c63d4206fccb0a","head":{"label":"GoogleChrome:vapid","ref":"vapid","sha":"d00644ee80b2c526918c0a6a88c63d4206fccb0a","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":56687351,"name":"push-encryption-go","full_name":"GoogleChrome/push-encryption-go","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/push-encryption-go","description":"","fork":false,"url":"https://api.github.com/repos/GoogleChrome/push-encryption-go","forks_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/forks","keys_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/events","assignees_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/merges","archive_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/deployments","created_at":"2016-04-20T13:04:09Z","updated_at":"2016-08-09T09:02:09Z","pushed_at":"2016-08-11T18:47:56Z","git_url":"git://github.com/GoogleChrome/push-encryption-go.git","ssh_url":"git@github.com:GoogleChrome/push-encryption-go.git","clone_url":"https://github.com/GoogleChrome/push-encryption-go.git","svn_url":"https://github.com/GoogleChrome/push-encryption-go","homepage":null,"size":18936,"stargazers_count":42,"watchers_count":42,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":7,"forks":3,"open_issues":7,"watchers":42,"default_branch":"master"}},"base":{"label":"GoogleChrome:master","ref":"master","sha":"0f83f6c09c8b4778fae6bc88597f1b2cd96719db","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":56687351,"name":"push-encryption-go","full_name":"GoogleChrome/push-encryption-go","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/push-encryption-go","description":"","fork":false,"url":"https://api.github.com/repos/GoogleChrome/push-encryption-go","forks_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/forks","keys_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/events","assignees_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/merges","archive_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleChrome/push-encryption-go/deployments","created_at":"2016-04-20T13:04:09Z","updated_at":"2016-08-09T09:02:09Z","pushed_at":"2016-08-11T18:47:56Z","git_url":"git://github.com/GoogleChrome/push-encryption-go.git","ssh_url":"git@github.com:GoogleChrome/push-encryption-go.git","clone_url":"https://github.com/GoogleChrome/push-encryption-go.git","svn_url":"https://github.com/GoogleChrome/push-encryption-go","homepage":null,"size":18936,"stargazers_count":42,"watchers_count":42,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":7,"forks":3,"open_issues":7,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17"},"html":{"href":"https://github.com/GoogleChrome/push-encryption-go/pull/17"},"issue":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/17"},"comments":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleChrome/push-encryption-go/statuses/d00644ee80b2c526918c0a6a88c63d4206fccb0a"}}}}
{"actor":{"display_login":"crhym3"}}