blob: 03f8df3851bc43d3cd0eeb551df6d6cd278311c5 [file] [log] [blame]
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -07001package revocation
2
3import (
4 "fmt"
5 "time"
6
Jiri Simsa519c5072014-09-17 21:37:57 -07007 vsecurity "veyron.io/veyron/veyron/security"
8 "veyron.io/veyron/veyron/security/audit"
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -07009
Jiri Simsa519c5072014-09-17 21:37:57 -070010 "veyron.io/veyron/veyron2/security"
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -070011)
12
13// Bless creates a blessing on behalf of the identity server.
Suharsh Sivakumard308c7e2014-10-03 12:46:50 -070014func Bless(server security.PrivateID, blessee security.PublicID, email string, duration time.Duration, caveats []security.Caveat, revocationCaveat security.ThirdPartyCaveat) (security.PublicID, error) {
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -070015 if revocationCaveat != nil {
Ankurf044a8d2014-09-05 17:05:24 -070016 caveat, err := security.NewCaveat(revocationCaveat)
17 if err != nil {
18 return nil, err
19 }
Suharsh Sivakumar15e10672014-09-22 22:27:01 -070020 // revocationCaveat must be prepended because it is assumed to be first by ReadBlessAuditEntry.
21 caveats = append([]security.Caveat{caveat}, caveats...)
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -070022 }
Suharsh Sivakumar15e10672014-09-22 22:27:01 -070023 // TODO(suharshs): Extend the duration for blessings with provided revocaionCaveats.
24 return server.Bless(blessee, email, duration, caveats)
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -070025}
26
27type BlessingAuditEntry struct {
28 Blessee, Blessed security.PublicID
29 Start, End time.Time
30 RevocationCaveat security.ThirdPartyCaveat
31}
32
33// ReadBlessAuditEntry is for use in the googleauth.handler to parse the arguments to the Bless call in util.Bless.
34func ReadBlessAuditEntry(entry audit.Entry) (BlessingAuditEntry, error) {
35 var blessEntry BlessingAuditEntry
36
37 if len(entry.Arguments) < 4 || len(entry.Results) < 1 {
38 return blessEntry, fmt.Errorf("entry is invalid format")
39 }
40
41 blessEntry.Blessee, _ = entry.Arguments[0].(security.PublicID)
42 blessEntry.Start = entry.Timestamp
43 if duration, ok := entry.Arguments[2].(int64); ok {
44 blessEntry.End = blessEntry.Start.Add(time.Duration(duration))
45 }
46 blessEntry.Blessed, _ = entry.Results[0].(security.PublicID)
Ankurf044a8d2014-09-05 17:05:24 -070047 caveats, _ := entry.Arguments[3].([]security.Caveat)
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -070048 if len(caveats) > 0 {
Asim Shankarbb0f0c12014-09-09 13:32:28 -070049 revocationCaveat, err := vsecurity.CaveatValidators(caveats[0])
Ankurf044a8d2014-09-05 17:05:24 -070050 if err != nil {
51 return blessEntry, err
52 }
53 blessEntry.RevocationCaveat, _ = revocationCaveat[0].(security.ThirdPartyCaveat)
Suharsh Sivakumarfb5cbb72014-08-27 13:14:22 -070054 }
55 return blessEntry, nil
56}