{"action":"created","comment":{"url":"https://api.github.com/repos/cloudflare/redoctober/pulls/comments/73614375","id":73614375,"diff_hunk":"@@ -117,6 +128,177 @@ func TestDuplicates(t *testing.T) {\n \t\t\tt.Fatalf(\"That shouldn't have worked!\")\n \t\t}\n \n-\t\tcache.FlushCache()\n+\t\tcache.Flush()\n+\t}\n+}\n+\n+func TestEncryptDecrypt(t *testing.T) {\n+\t// Setup total names and partitions.\n+\tnames := []string{\"Alice\", \"Bob\", \"Carl\"}\n+\trecs := make(map[string]passvault.PasswordRecord, 0)\n+\tleft := []string{\"Alice\", \"Bob\"}\n+\tright := []string{\"Bob\", \"Carl\"}\n+\n+\t// Add each user to the keycache.\n+\tcache := keycache.NewCache()\n+\trecords, err := passvault.InitFrom(\"memory\")\n+\tif err != nil {\n+\t\tt.Fatalf(\"%v\", err)\n+\t}\n+\n+\tcfg := &config.Delegations{Persist: false}\n+\tstore, err := persist.New(cfg)\n+\tif err != nil {\n+\t\tt.Fatal(err.Error())\n+\t}\n+\n+\tc := Cryptor{&records, &cache, store}\n+\n+\tfor _, name := range names {\n+\t\tpr, err := records.AddNewRecord(name, \"weakpassword\", true, passvault.DefaultRecordType)\n+\t\tif err != nil {\n+\t\t\tt.Fatalf(\"%v\", err)\n+\t\t}\n+\n+\t\trecs[name] = pr\n+\t}\n+\n+\t// Create candidate encryption of message.\n+\tac := AccessStructure{\n+\t\tLeftNames:  left,\n+\t\tRightNames: right,\n+\t}\n+\n+\tresp, err := c.Encrypt([]byte(\"Hello World!\"), []string{}, ac)\n+\tif err != nil {\n+\t\tt.Fatalf(\"Error: %s\", err)\n+\t}\n+\n+\t// Delegate all the things.\n+\tfor name, pr := range recs {\n+\t\terr = cache.AddKeyFromRecord(pr, name, \"weakpassword\", nil, nil, 2, \"\", \"1h\")\n+\t\tif err != nil {\n+\t\t\tt.Fatalf(\"%v\", err)\n+\t\t}\n+\t}\n+\n+\t// (resp []byte, labels, names []string, secure bool, err error)\n+\t_, _, _, _, err = c.Decrypt(resp, \"alice\")\n+\tif err != nil {\n+\t\tt.Fatalf(\"%v\", err)\n+\t}\n+}\n+\n+func tempName() (string, error) {\n+\ttmpf, err := ioutil.TempFile(\"\", \"transport_cachedkp_\")\n+\tif err != nil {\n+\t\treturn \"\", err\n+\t}\n+\n+\tname := tmpf.Name()\n+\ttmpf.Close()\n+\treturn name, nil\n+}\n+\n+func TestRestore(t *testing.T) {\n+\t// Get the temporary persisted file.\n+\ttemp, err := tempName()\n+\tif err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\tdefer os.Remove(temp)\n+\n+\t// Setup total names and partitions.\n+\tnames := []string{\"Alice\", \"Bob\", \"Carl\"}\n+\trecs := make(map[string]passvault.PasswordRecord, 0)\n+\n+\t// Add each user to the keycache.\n+\tcache := keycache.NewCache()\n+\trecords, err := passvault.InitFrom(\"memory\")\n+\tif err != nil {\n+\t\tt.Fatalf(\"%v\", err)\n+\t}\n+\n+\tfor _, name := range names {\n+\t\tpr, err := records.AddNewRecord(name, \"weakpassword\", true, passvault.DefaultRecordType)\n+\t\tif err != nil {\n+\t\t\tt.Fatalf(\"%v\", err)\n+\t\t}\n+\n+\t\trecs[name] = pr\n+\t}\n+\n+\talice, ok := records.GetRecord(\"Alice\")\n+\tif !ok {\n+\t\tt.Fatal(\"Alice not found in password vault.\")\n+\t}\n+\n+\tcarl, ok := records.GetRecord(\"Carl\")\n+\tif !ok {\n+\t\tt.Fatal(\"Carl not found in password vault.\")\n+\t}\n+\n+\t// First, simulate a running Red October with persistence.\n+\tcfg := &config.Delegations{\n+\t\tPersist:   true,\n+\t\tMechanism: persist.FileMechanism,\n+\t\tLocation:  temp,\n+\t\tPolicy:    \"(Alice & Bob) | (Bob & Carl)\",\n+\t\tUsers:     []string{\"Alice\", \"Bob\", \"Carl\"},\n+\t}\n+\n+\tstore, err := persist.New(cfg)\n+\tif err != nil {\n+\t\tt.Fatal(err.Error())\n+\t}\n+\n+\tc := Cryptor{&records, &cache, store}\n+\tc.persist.Persist()\n+\n+\terr = c.Delegate(alice, \"Alice\", \"weakpassword\", []string{\"Bob\"}, []string{},\n+\t\t5, \"\", \"1h\")\n+\tif err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\n+\terr = c.Delegate(carl, \"Carl\", \"weakpassword\", []string{\"Bob\"}, []string{},\n+\t\t5, \"\", \"1h\")\n+\n+\t// Next, simulate restarting that server.\n+\tstore, err = persist.New(cfg)\n+\tif err != nil {\n+\t\tt.Fatal(err.Error())\n+\t}\n+\n+\tc = Cryptor{&records, &cache, store}\n+\tif _, err := os.Stat(temp); err != nil {\n+\t\tt.Fatalf(\"Not persisting: %v\", err)\n+\t}\n+\n+\terr = c.Restore(\"Alice\", \"weakpassword\", 5, \"\", \"1h\")\n+\tif err != ErrRestoreDelegations {\n+\t\tt.Fatal(err)\n+\t}\n+\n+\terr = c.Restore(\"Carl\", \"weakpassword\", 5, \"\", \"1h\")\n+\tif err != ErrRestoreDelegations {\n+\t\tt.Fatal(err)\n+\t}\n+\n+\tstatus := c.persist.Status()\n+\tif status.State != persist.Inactive {\n+\t\tt.Fatalf(\"The persistent delegations should be %s, not %s\",\n+\t\t\tpersist.Inactive, status.State)\n+\t}\n+\n+\terr = c.Restore(\"Bob\", \"weakpassword\", 5, \"\", \"1h\")\n+\tif err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\n+\tstatus = c.persist.Status()","path":"cryptor/cryptor_test.go","position":206,"original_position":204,"commit_id":"15a81261f9426665589650d802de4ccd740221d1","original_commit_id":"84d30a50f0263b23789501a644ccd2ebd4ffc63f","user":{"login":"kisom","id":175578,"avatar_url":"https://avatars.githubusercontent.com/u/175578?v=3","gravatar_id":"","url":"https://api.github.com/users/kisom","html_url":"https://github.com/kisom","followers_url":"https://api.github.com/users/kisom/followers","following_url":"https://api.github.com/users/kisom/following{/other_user}","gists_url":"https://api.github.com/users/kisom/gists{/gist_id}","starred_url":"https://api.github.com/users/kisom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kisom/subscriptions","organizations_url":"https://api.github.com/users/kisom/orgs","repos_url":"https://api.github.com/users/kisom/repos","events_url":"https://api.github.com/users/kisom/events{/privacy}","received_events_url":"https://api.github.com/users/kisom/received_events","type":"User","site_admin":false},"body":"This is checked now.","created_at":"2016-08-04T22:32:04Z","updated_at":"2016-08-04T22:32:04Z","html_url":"https://github.com/cloudflare/redoctober/pull/160#discussion_r73614375","pull_request_url":"https://api.github.com/repos/cloudflare/redoctober/pulls/160","_links":{"self":{"href":"https://api.github.com/repos/cloudflare/redoctober/pulls/comments/73614375"},"html":{"href":"https://github.com/cloudflare/redoctober/pull/160#discussion_r73614375"},"pull_request":{"href":"https://api.github.com/repos/cloudflare/redoctober/pulls/160"}}},"pull_request":{"url":"https://api.github.com/repos/cloudflare/redoctober/pulls/160","id":79666668,"html_url":"https://github.com/cloudflare/redoctober/pull/160","diff_url":"https://github.com/cloudflare/redoctober/pull/160.diff","patch_url":"https://github.com/cloudflare/redoctober/pull/160.patch","issue_url":"https://api.github.com/repos/cloudflare/redoctober/issues/160","number":160,"state":"open","locked":false,"title":"kyle/keycache interface","user":{"login":"kisom","id":175578,"avatar_url":"https://avatars.githubusercontent.com/u/175578?v=3","gravatar_id":"","url":"https://api.github.com/users/kisom","html_url":"https://github.com/kisom","followers_url":"https://api.github.com/users/kisom/followers","following_url":"https://api.github.com/users/kisom/following{/other_user}","gists_url":"https://api.github.com/users/kisom/gists{/gist_id}","starred_url":"https://api.github.com/users/kisom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kisom/subscriptions","organizations_url":"https://api.github.com/users/kisom/orgs","repos_url":"https://api.github.com/users/kisom/repos","events_url":"https://api.github.com/users/kisom/events{/privacy}","received_events_url":"https://api.github.com/users/kisom/received_events","type":"User","site_admin":false},"body":"Implementation of a file-backed persistence store.\r\n\r\nThis is a rather large change. It consists of the following changes:\r\n\r\n+ Direct access to the keycache has been removed from the core package. This forces all interaction with the cache to go through the Cryptor, which is required for persistence. The Cryptor needs to know when the cache has changed, and the only way to do this effectively is to make the Cryptor responsible for managing the keycache.\r\n\r\n+ A new persist package has been added. This provides a Store interface, for which two implementations are provided. The first is a null persister: this is used when no persistence is configured. The second is a file-backed persistence store.\r\n\r\n+ The Cryptor now persists the cache every time it changes.\r\n\r\nAdditionally, a number of missing returns in a function in the core package have been added.\r\n","created_at":"2016-08-02T02:18:55Z","updated_at":"2016-08-04T22:32:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0124de1ff4b30d13e5180ab424b1361069de32d0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/cloudflare/redoctober/pulls/160/commits","review_comments_url":"https://api.github.com/repos/cloudflare/redoctober/pulls/160/comments","review_comment_url":"https://api.github.com/repos/cloudflare/redoctober/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudflare/redoctober/issues/160/comments","statuses_url":"https://api.github.com/repos/cloudflare/redoctober/statuses/15a81261f9426665589650d802de4ccd740221d1","head":{"label":"cloudflare:kyle/keycache-interface","ref":"kyle/keycache-interface","sha":"15a81261f9426665589650d802de4ccd740221d1","user":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"repo":{"id":14510383,"name":"redoctober","full_name":"cloudflare/redoctober","owner":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudflare/redoctober","description":"Go server for two-man rule style file encryption and decryption.","fork":false,"url":"https://api.github.com/repos/cloudflare/redoctober","forks_url":"https://api.github.com/repos/cloudflare/redoctober/forks","keys_url":"https://api.github.com/repos/cloudflare/redoctober/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudflare/redoctober/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudflare/redoctober/teams","hooks_url":"https://api.github.com/repos/cloudflare/redoctober/hooks","issue_events_url":"https://api.github.com/repos/cloudflare/redoctober/issues/events{/number}","events_url":"https://api.github.com/repos/cloudflare/redoctober/events","assignees_url":"https://api.github.com/repos/cloudflare/redoctober/assignees{/user}","branches_url":"https://api.github.com/repos/cloudflare/redoctober/branches{/branch}","tags_url":"https://api.github.com/repos/cloudflare/redoctober/tags","blobs_url":"https://api.github.com/repos/cloudflare/redoctober/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudflare/redoctober/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudflare/redoctober/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudflare/redoctober/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudflare/redoctober/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudflare/redoctober/languages","stargazers_url":"https://api.github.com/repos/cloudflare/redoctober/stargazers","contributors_url":"https://api.github.com/repos/cloudflare/redoctober/contributors","subscribers_url":"https://api.github.com/repos/cloudflare/redoctober/subscribers","subscription_url":"https://api.github.com/repos/cloudflare/redoctober/subscription","commits_url":"https://api.github.com/repos/cloudflare/redoctober/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudflare/redoctober/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudflare/redoctober/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudflare/redoctober/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudflare/redoctober/contents/{+path}","compare_url":"https://api.github.com/repos/cloudflare/redoctober/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudflare/redoctober/merges","archive_url":"https://api.github.com/repos/cloudflare/redoctober/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudflare/redoctober/downloads","issues_url":"https://api.github.com/repos/cloudflare/redoctober/issues{/number}","pulls_url":"https://api.github.com/repos/cloudflare/redoctober/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudflare/redoctober/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudflare/redoctober/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudflare/redoctober/labels{/name}","releases_url":"https://api.github.com/repos/cloudflare/redoctober/releases{/id}","deployments_url":"https://api.github.com/repos/cloudflare/redoctober/deployments","created_at":"2013-11-19T01:15:58Z","updated_at":"2016-08-03T01:15:43Z","pushed_at":"2016-08-04T22:31:55Z","git_url":"git://github.com/cloudflare/redoctober.git","ssh_url":"git@github.com:cloudflare/redoctober.git","clone_url":"https://github.com/cloudflare/redoctober.git","svn_url":"https://github.com/cloudflare/redoctober","homepage":"http://blog.cloudflare.com/red-october-cloudflares-open-source-implementation-of-the-two-man-rule","size":618,"stargazers_count":963,"watchers_count":963,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":87,"mirror_url":null,"open_issues_count":30,"forks":87,"open_issues":30,"watchers":963,"default_branch":"master"}},"base":{"label":"cloudflare:master","ref":"master","sha":"7546ac3c766bf1b9ba8bc5dd662a07d091d09d75","user":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"repo":{"id":14510383,"name":"redoctober","full_name":"cloudflare/redoctober","owner":{"login":"cloudflare","id":314135,"avatar_url":"https://avatars.githubusercontent.com/u/314135?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudflare","html_url":"https://github.com/cloudflare","followers_url":"https://api.github.com/users/cloudflare/followers","following_url":"https://api.github.com/users/cloudflare/following{/other_user}","gists_url":"https://api.github.com/users/cloudflare/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudflare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudflare/subscriptions","organizations_url":"https://api.github.com/users/cloudflare/orgs","repos_url":"https://api.github.com/users/cloudflare/repos","events_url":"https://api.github.com/users/cloudflare/events{/privacy}","received_events_url":"https://api.github.com/users/cloudflare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudflare/redoctober","description":"Go server for two-man rule style file encryption and decryption.","fork":false,"url":"https://api.github.com/repos/cloudflare/redoctober","forks_url":"https://api.github.com/repos/cloudflare/redoctober/forks","keys_url":"https://api.github.com/repos/cloudflare/redoctober/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudflare/redoctober/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudflare/redoctober/teams","hooks_url":"https://api.github.com/repos/cloudflare/redoctober/hooks","issue_events_url":"https://api.github.com/repos/cloudflare/redoctober/issues/events{/number}","events_url":"https://api.github.com/repos/cloudflare/redoctober/events","assignees_url":"https://api.github.com/repos/cloudflare/redoctober/assignees{/user}","branches_url":"https://api.github.com/repos/cloudflare/redoctober/branches{/branch}","tags_url":"https://api.github.com/repos/cloudflare/redoctober/tags","blobs_url":"https://api.github.com/repos/cloudflare/redoctober/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudflare/redoctober/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudflare/redoctober/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudflare/redoctober/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudflare/redoctober/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudflare/redoctober/languages","stargazers_url":"https://api.github.com/repos/cloudflare/redoctober/stargazers","contributors_url":"https://api.github.com/repos/cloudflare/redoctober/contributors","subscribers_url":"https://api.github.com/repos/cloudflare/redoctober/subscribers","subscription_url":"https://api.github.com/repos/cloudflare/redoctober/subscription","commits_url":"https://api.github.com/repos/cloudflare/redoctober/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudflare/redoctober/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudflare/redoctober/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudflare/redoctober/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudflare/redoctober/contents/{+path}","compare_url":"https://api.github.com/repos/cloudflare/redoctober/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudflare/redoctober/merges","archive_url":"https://api.github.com/repos/cloudflare/redoctober/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudflare/redoctober/downloads","issues_url":"https://api.github.com/repos/cloudflare/redoctober/issues{/number}","pulls_url":"https://api.github.com/repos/cloudflare/redoctober/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudflare/redoctober/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudflare/redoctober/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudflare/redoctober/labels{/name}","releases_url":"https://api.github.com/repos/cloudflare/redoctober/releases{/id}","deployments_url":"https://api.github.com/repos/cloudflare/redoctober/deployments","created_at":"2013-11-19T01:15:58Z","updated_at":"2016-08-03T01:15:43Z","pushed_at":"2016-08-04T22:31:55Z","git_url":"git://github.com/cloudflare/redoctober.git","ssh_url":"git@github.com:cloudflare/redoctober.git","clone_url":"https://github.com/cloudflare/redoctober.git","svn_url":"https://github.com/cloudflare/redoctober","homepage":"http://blog.cloudflare.com/red-october-cloudflares-open-source-implementation-of-the-two-man-rule","size":618,"stargazers_count":963,"watchers_count":963,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":87,"mirror_url":null,"open_issues_count":30,"forks":87,"open_issues":30,"watchers":963,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudflare/redoctober/pulls/160"},"html":{"href":"https://github.com/cloudflare/redoctober/pull/160"},"issue":{"href":"https://api.github.com/repos/cloudflare/redoctober/issues/160"},"comments":{"href":"https://api.github.com/repos/cloudflare/redoctober/issues/160/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudflare/redoctober/pulls/160/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudflare/redoctober/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudflare/redoctober/pulls/160/commits"},"statuses":{"href":"https://api.github.com/repos/cloudflare/redoctober/statuses/15a81261f9426665589650d802de4ccd740221d1"}}}}
{"actor":{"display_login":"kisom"}}