Commit 06aad1ff authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Commenting

parent 6182cb83
......@@ -65,7 +65,7 @@ type clientConfiguration struct {
ravenDSN string
}
var defaultClientConfig clientConfiguration = clientConfiguration{
var defaultClientConfig = clientConfiguration{
SendCrashReports: true,
ravenDSN: "", // Set this in the init() function, empty string -> no crash reports
}
......@@ -77,6 +77,8 @@ type KeyshareHandler interface {
EnrollmentSuccess(manager irma.SchemeManagerIdentifier)
}
// ClientHandler informs the user that the configuration or the list of attributes
// that this client uses has been updated.
type ClientHandler interface {
KeyshareHandler
......@@ -274,10 +276,12 @@ func (client *Client) remove(id irma.CredentialTypeIdentifier, index int, storen
return nil
}
// RemoveCredential removes the specified credential.
func (client *Client) RemoveCredential(id irma.CredentialTypeIdentifier, index int) error {
return client.remove(id, index, true)
}
// RemoveCredentialByHash removes the specified credential.
func (client *Client) RemoveCredentialByHash(hash string) error {
cred, index, err := client.credentialByHash(hash)
if err != nil {
......@@ -286,6 +290,7 @@ func (client *Client) RemoveCredentialByHash(hash string) error {
return client.RemoveCredential(cred.CredentialType().Identifier(), index)
}
// RemoveAllCredentials removes all credentials.
func (client *Client) RemoveAllCredentials() error {
removed := map[irma.CredentialTypeIdentifier][]irma.TranslatedString{}
for _, attrlistlist := range client.attributes {
......@@ -699,6 +704,7 @@ func (client *Client) KeyshareRemove(manager irma.SchemeManagerIdentifier) error
return client.storage.StoreKeyshareServers(client.keyshareServers)
}
// KeyshareRemoveAll removes all keyshare server registrations.
func (client *Client) KeyshareRemoveAll() error {
client.keyshareServers = map[irma.SchemeManagerIdentifier]*keyshareServer{}
client.UnenrolledSchemeManagers = client.unenrolledSchemeManagers()
......@@ -710,9 +716,9 @@ func (client *Client) KeyshareRemoveAll() error {
func (client *Client) addLogEntry(entry *LogEntry) error {
client.logs = append(client.logs, entry)
return client.storage.StoreLogs(client.logs)
return nil
}
// Logs returns the log entries of past events.
func (client *Client) Logs() ([]*LogEntry, error) {
if client.logs == nil || len(client.logs) == 0 {
var err error
......@@ -724,6 +730,8 @@ func (client *Client) Logs() ([]*LogEntry, error) {
return client.logs, nil
}
// SendCrashReports toggles whether or not crash reports should be sent to Sentry.
// Has effect only after restarting.
func (client *Client) SendCrashReports(val bool) {
if val == client.config.SendCrashReports {
return
......
......@@ -9,6 +9,7 @@ import (
"github.com/mhe/gabi"
)
// LogEntry is a log entry of a past event.
type LogEntry struct {
// General info
Type irma.Action
......@@ -91,10 +92,13 @@ func (session *session) createLogEntry(response interface{}) (*LogEntry, error)
return entry, nil
}
// Jwt returns the JWT from the requestor that started the IRMA session which the
// current log entry tracks.
func (entry *LogEntry) Jwt() (irma.RequestorJwt, error) {
return irma.ParseRequestorJwt(entry.Type, entry.SessionInfo.Jwt)
}
// GetResponse returns our response to the requestor from the log entry.
func (entry *LogEntry) GetResponse() (interface{}, error) {
if entry.response == nil {
switch entry.Type {
......@@ -132,6 +136,7 @@ type jsonLogEntry struct {
Response json.RawMessage
}
// UnmarshalJSON implements json.Unmarshaler.
func (entry *LogEntry) UnmarshalJSON(bytes []byte) error {
var err error
temp := &jsonLogEntry{}
......@@ -164,6 +169,7 @@ func (entry *LogEntry) UnmarshalJSON(bytes []byte) error {
return nil
}
// MarshalJSON implements json.Marshaler.
func (entry *LogEntry) MarshalJSON() ([]byte, error) {
// If the entry was created using createLogEntry(), then entry.rawResponse == nil
if len(entry.rawResponse) == 0 && entry.response != nil {
......
......@@ -20,6 +20,7 @@ import (
// and specifying the attributes to be disclosed.
type PermissionHandler func(proceed bool, choice *irma.DisclosureChoice)
// PinHandler is used to provide the user's PIN code.
type PinHandler func(proceed bool, pin string)
// A Handler contains callbacks for communication to the user.
......@@ -39,6 +40,7 @@ type Handler interface {
RequestPin(remainingAttempts int, callback PinHandler)
}
// SessionDismisser can dismiss the current IRMA session.
type SessionDismisser interface {
Dismiss()
}
......
......@@ -44,8 +44,12 @@ type Configuration struct {
initialized bool
}
// ConfigurationFileHash encodes the SHA256 hash of an authenticated
// file under a scheme manager within the configuration folder.
type ConfigurationFileHash []byte
// SchemeManagerIndex is a (signed) list of files under a scheme manager
// along with their SHA266 hash
type SchemeManagerIndex map[string]ConfigurationFileHash
// NewConfiguration returns a new configuration. After this
......@@ -80,7 +84,7 @@ func (conf *Configuration) ParseFolder() error {
err := iterateSubfolders(conf.path, func(dir string) error {
manager := &SchemeManager{}
if err := conf.ParseIndex(manager, dir); err != nil {
if err := conf.ParseIndex(manager); err != nil {
return err
}
exists, err := conf.pathToDescription(manager, dir+"/description.xml", manager)
......@@ -262,6 +266,8 @@ func (conf *Configuration) Contains(cred CredentialTypeIdentifier) bool {
conf.CredentialTypes[cred] != nil
}
// Copy recursively copies the directory tree at source into the directory
// of this Configuration.
func (conf *Configuration) Copy(source string, parse bool) error {
if err := fs.EnsureDirectoryExists(conf.path); err != nil {
return err
......@@ -329,6 +335,8 @@ func (conf *Configuration) DownloadSchemeManager(url string) (*SchemeManager, er
return manager, nil
}
// RemoveSchemeManager removes the specified scheme manager and all associated issuers,
// public keys and credential types from this Configuration.
func (conf *Configuration) RemoveSchemeManager(id SchemeManagerIdentifier) error {
// Remove everything falling under the manager's responsibility
for credid := range conf.CredentialTypes {
......@@ -352,6 +360,8 @@ func (conf *Configuration) RemoveSchemeManager(id SchemeManagerIdentifier) error
// or, remove above iterations and call .ParseFolder()?
}
// AddSchemeManager adds the specified scheme manager to this Configuration,
// provided its signature is valid.
func (conf *Configuration) AddSchemeManager(manager *SchemeManager) error {
name := manager.ID
if err := fs.EnsureDirectoryExists(fmt.Sprintf("%s/%s", conf.path, name)); err != nil {
......@@ -369,11 +379,20 @@ func (conf *Configuration) AddSchemeManager(manager *SchemeManager) error {
if err := conf.DownloadSchemeManagerSignature(manager); err != nil {
return err
}
valid, err := conf.VerifySignature(manager.Identifier())
if err != nil {
return err
}
if !valid {
return errors.New("Scheme manager signature invalid")
}
conf.SchemeManagers[NewSchemeManagerIdentifier(name)] = manager
return nil
}
// DownloadSchemeManagerSignature downloads and stores the latest version
// of the index file and signature of the specified manager.
func (conf *Configuration) DownloadSchemeManagerSignature(manager *SchemeManager) error {
t := NewHTTPTransport(manager.URL)
path := fmt.Sprintf("%s/%s", conf.path, manager.ID)
......@@ -387,6 +406,9 @@ func (conf *Configuration) DownloadSchemeManagerSignature(manager *SchemeManager
return nil
}
// Download downloads the issuers, credential types and public keys specified in set
// if the current Configuration does not already have them, and checks their authenticity
// using the scheme manager index.
func (conf *Configuration) Download(set *IrmaIdentifierSet) (*IrmaIdentifierSet, error) {
var contains bool
var err error
......@@ -489,6 +511,7 @@ func (i SchemeManagerIndex) String() string {
return b.String()
}
// FromString populates this index by parsing the specified string.
func (i SchemeManagerIndex) FromString(s string) error {
for j, line := range strings.Split(s, "\n") {
if len(line) == 0 {
......@@ -508,11 +531,13 @@ func (i SchemeManagerIndex) FromString(s string) error {
return nil
}
func (conf *Configuration) ParseIndex(manager *SchemeManager, dir string) error {
if err := fs.AssertPathExists(dir + "/index"); err != nil {
// ParseIndex parses the index file of the specified manager.
func (conf *Configuration) ParseIndex(manager *SchemeManager) error {
path := filepath.Join(conf.path, manager.ID, "index")
if err := fs.AssertPathExists(path); err != nil {
return errors.New("Missing scheme manager index file")
}
indexbts, err := ioutil.ReadFile(dir + "/index")
indexbts, err := ioutil.ReadFile(path)
if err != nil {
return err
}
......
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