Commit 78d71579 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Group credential removal log entries

parent 8925f452
...@@ -15,9 +15,9 @@ type LogEntry struct { ...@@ -15,9 +15,9 @@ type LogEntry struct {
SessionInfo *SessionInfo // Message that started the session SessionInfo *SessionInfo // Message that started the session
// Session type-specific info // Session type-specific info
RemovedCredential CredentialTypeIdentifier // In case of credential removal
Disclosed map[CredentialTypeIdentifier]map[int]TranslatedString // Any session type Disclosed map[CredentialTypeIdentifier]map[int]TranslatedString // Any session type
Received map[CredentialTypeIdentifier][]TranslatedString // In case of issuance session Received map[CredentialTypeIdentifier][]TranslatedString // In case of issuance session
Removed map[CredentialTypeIdentifier][]TranslatedString // In case of credential removal
SignedMessage []byte // In case of signature sessions SignedMessage []byte // In case of signature sessions
SignedMessageType string // In case of signature sessions SignedMessageType string // In case of signature sessions
...@@ -122,9 +122,9 @@ type jsonLogEntry struct { ...@@ -122,9 +122,9 @@ type jsonLogEntry struct {
Time Timestamp Time Timestamp
SessionInfo *logSessionInfo SessionInfo *logSessionInfo
RemovedCredential string `json:",omitempty"`
Disclosed map[CredentialTypeIdentifier]map[int]TranslatedString `json:",omitempty"` Disclosed map[CredentialTypeIdentifier]map[int]TranslatedString `json:",omitempty"`
Received map[CredentialTypeIdentifier][]TranslatedString `json:",omitempty"` Received map[CredentialTypeIdentifier][]TranslatedString `json:",omitempty"`
Removed map[CredentialTypeIdentifier][]TranslatedString `json:",omitempty"`
SignedMessage []byte `json:",omitempty"` SignedMessage []byte `json:",omitempty"`
SignedMessageType string `json:",omitempty"` SignedMessageType string `json:",omitempty"`
...@@ -147,7 +147,7 @@ func (entry *LogEntry) UnmarshalJSON(bytes []byte) error { ...@@ -147,7 +147,7 @@ func (entry *LogEntry) UnmarshalJSON(bytes []byte) error {
Context: temp.SessionInfo.Context, Context: temp.SessionInfo.Context,
Keys: make(map[IssuerIdentifier]int), Keys: make(map[IssuerIdentifier]int),
}, },
RemovedCredential: NewCredentialTypeIdentifier(temp.RemovedCredential), Removed: temp.Removed,
Disclosed: temp.Disclosed, Disclosed: temp.Disclosed,
Received: temp.Received, Received: temp.Received,
SignedMessage: temp.SignedMessage, SignedMessage: temp.SignedMessage,
...@@ -191,7 +191,7 @@ func (entry *LogEntry) MarshalJSON() ([]byte, error) { ...@@ -191,7 +191,7 @@ func (entry *LogEntry) MarshalJSON() ([]byte, error) {
Time: entry.Time, Time: entry.Time,
Response: entry.rawResponse, Response: entry.rawResponse,
SessionInfo: si, SessionInfo: si,
RemovedCredential: entry.RemovedCredential.String(), Removed: entry.Removed,
Disclosed: entry.Disclosed, Disclosed: entry.Disclosed,
Received: entry.Received, Received: entry.Received,
SignedMessage: entry.SignedMessage, SignedMessage: entry.SignedMessage,
......
...@@ -227,11 +227,17 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor ...@@ -227,11 +227,17 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor
return err return err
} }
return cm.addLogEntry(&LogEntry{ removed := map[CredentialTypeIdentifier][]TranslatedString{}
Type: actionRemoval, removed[id] = attrs.Strings()
Time: Timestamp(time.Now()),
RemovedCredential: id, if storenow {
}, storenow) return cm.addLogEntry(&LogEntry{
Type: actionRemoval,
Time: Timestamp(time.Now()),
Removed: removed,
})
}
return nil
} }
func (cm *CredentialManager) RemoveCredential(id CredentialTypeIdentifier, index int) error { func (cm *CredentialManager) RemoveCredential(id CredentialTypeIdentifier, index int) error {
...@@ -247,19 +253,31 @@ func (cm *CredentialManager) RemoveCredentialByHash(hash string) error { ...@@ -247,19 +253,31 @@ func (cm *CredentialManager) RemoveCredentialByHash(hash string) error {
} }
func (cm *CredentialManager) RemoveAllCredentials() error { func (cm *CredentialManager) RemoveAllCredentials() error {
removed := map[CredentialTypeIdentifier][]TranslatedString{}
list := cm.CredentialInfoList() list := cm.CredentialInfoList()
for _, cred := range list { for _, cred := range list {
if err := cm.remove(NewCredentialTypeIdentifier(cred.ID), cred.Index, false); err != nil { id := NewCredentialTypeIdentifier(cred.ID)
removed[id] = cred.Attributes
if err := cm.remove(id, cred.Index, false); err != nil {
return err return err
} }
} }
if err := cm.storage.StoreAttributes(cm.attributes); err != nil { if err := cm.storage.StoreAttributes(cm.attributes); err != nil {
return err return err
} }
logentry := &LogEntry{
Type: actionRemoval,
Time: Timestamp(time.Now()),
Removed: removed,
}
if err := cm.addLogEntry(logentry); err != nil {
return err
}
return cm.storage.StoreLogs(cm.logs) return cm.storage.StoreLogs(cm.logs)
} }
// Getter methods // Attribute and credential getter methods
// attrs returns cm.attributes[id], initializing it to an empty slice if neccesary // attrs returns cm.attributes[id], initializing it to an empty slice if neccesary
func (cm *CredentialManager) attrs(id CredentialTypeIdentifier) []*AttributeList { func (cm *CredentialManager) attrs(id CredentialTypeIdentifier) []*AttributeList {
...@@ -607,11 +625,9 @@ func (cm *CredentialManager) KeyshareRemove(manager SchemeManagerIdentifier) err ...@@ -607,11 +625,9 @@ func (cm *CredentialManager) KeyshareRemove(manager SchemeManagerIdentifier) err
// Add, load and store log entries // Add, load and store log entries
func (cm *CredentialManager) addLogEntry(entry *LogEntry, storenow bool) error { func (cm *CredentialManager) addLogEntry(entry *LogEntry) error {
cm.logs = append(cm.logs, entry) cm.logs = append(cm.logs, entry)
if storenow { return cm.storage.StoreLogs(cm.logs)
return cm.storage.StoreLogs(cm.logs)
}
return nil return nil
} }
......
...@@ -289,6 +289,6 @@ func (session *session) sendResponse(message interface{}) { ...@@ -289,6 +289,6 @@ func (session *session) sendResponse(message interface{}) {
log, _ = session.createLogEntry(message) // TODO err log, _ = session.createLogEntry(message) // TODO err
} }
_ = session.credManager.addLogEntry(log, true) // TODO err _ = session.credManager.addLogEntry(log) // TODO err
session.Handler.Success(session.Action) session.Handler.Success(session.Action)
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment