Example #1
0
        public object Read(
            object data,
            string masterPassphrase,
            params KeyValuePair <string, string>[] parameters)
        {
            FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType());

            DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Reading AuditLogEntry from JSON using serialiser '{0}'.", formatVersion);

            JObject   dataJSON  = (JObject)data;
            EntryType entryType = (EntryType)Enum.Parse(typeof(EntryType), JSONHelpers.ReadString(dataJSON, "TypeOfEntry"), true);
            DateTime  dateTime  = JSONHelpers.ReadDateTime(dataJSON, "DateTime", "HH:mm:ss dd-MM-yyyy");
            Dictionary <String, String> paramsDictionary = new Dictionary <String, String>();
            JObject entyryParams = dataJSON["Parameters"].Value <JObject>();

            foreach (JToken curToken in entyryParams.Children())
            {
                JProperty curProperty = (JProperty)curToken;
                paramsDictionary.Add(curProperty.Name,
                                     curProperty.Value.ToString());
            }
            AuditLogEntry entry = new AuditLogEntry(dateTime,
                                                    entryType,
                                                    paramsDictionary.ToArray());

            return(entry);
        }
        public object Read(
            object data,
            string masterPassphrase,
            params KeyValuePair <string, string>[] parameters)
        {
            FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType());

            DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Writing Credential from JSON using serialiser '{0}'.", formatVersion);

            JObject       dataJSON               = (JObject)data;
            String        id                     = JSONHelpers.ReadString(dataJSON, "ID");
            String        glyphKey               = JSONHelpers.ReadString(dataJSON, "GlyphKey");
            String        glyphColour            = JSONHelpers.ReadString(dataJSON, "GlyphColour");
            String        name                   = JSONHelpers.ReadString(dataJSON, "Name");
            String        description            = JSONHelpers.ReadString(dataJSON, "Description");
            String        website                = JSONHelpers.ReadString(dataJSON, "Website");
            DateTime      createdAt              = JSONHelpers.ReadDateTime(dataJSON, "CreatedAt");
            DateTime      lastUpdatedAt          = JSONHelpers.ReadDateTime(dataJSON, "LastUpdatedAt");
            DateTime      passwordLastModifiedAt = JSONHelpers.ReadDateTime(dataJSON, "PasswordLastModifiedAt", createdAt);
            String        username               = JSONHelpers.ReadString(dataJSON, "Username");
            String        password               = JSONHelpers.ReadString(dataJSON, "Password");
            JArray        tagsArray              = JSONHelpers.ReadJArray(dataJSON, "Tags", true);;
            List <String> tags                   = new List <String>();

            foreach (JValue curValue in tagsArray)
            {
                tags.Add(curValue.Value <String>());
            }
            String notes = JSONHelpers.ReadString(dataJSON, "Notes");
            List <AuditLogEntry> auditLogEntriesList = new List <AuditLogEntry>();

            if (dataJSON.ContainsKey("AuditLogEntries"))
            {
                ISerialiser auditLogEntrySerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(AuditLogEntry));
                JArray      auditLogEntries         = JSONHelpers.ReadJArray(dataJSON, "AuditLogEntries", true);
                foreach (JObject curEntry in auditLogEntries)
                {
                    AuditLogEntry entry = (AuditLogEntry)auditLogEntrySerialiser.Read(curEntry, String.Empty);
                    auditLogEntriesList.Add(entry);
                }
                if (auditLogEntriesList.Count > 0)
                {
                    auditLogEntriesList = auditLogEntriesList.OrderByDescending(ale => ale.DateTime).ToList();
                }
            }
            return(new Credential(id,
                                  glyphKey,
                                  glyphColour,
                                  name,
                                  description,
                                  website,
                                  createdAt,
                                  lastUpdatedAt,
                                  passwordLastModifiedAt,
                                  username,
                                  password,
                                  tags.ToArray(),
                                  notes,
                                  auditLogEntriesList.ToArray()));
        }
        public object Read(
            object data,
            string masterPassphrase,
            params KeyValuePair <string, string>[] parameters)
        {
            FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType());

            DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Reading Vault from JSON using serialiser '{0}'.", formatVersion);

            JObject dataJSON = (JObject)data;

            String            id             = JSONHelpers.ReadString(dataJSON, "ID");
            String            name           = JSONHelpers.ReadString(dataJSON, "Name");
            String            description    = JSONHelpers.ReadString(dataJSON, "Description");
            DateTime          createdAt      = JSONHelpers.ReadDateTime(dataJSON, "CreatedAt");
            DateTime          lastUpdatedAt  = JSONHelpers.ReadDateTime(dataJSON, "LastUpdatedAt");
            List <Credential> credentialList = new List <Credential>();

            ISerialiser credentialSerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(Credential));
            JArray      credentials          = JSONHelpers.ReadJArray(dataJSON, "Credentials", true);

            foreach (JObject curCredential in credentials)
            {
                Credential credential = (Credential)credentialSerialiser.Read(curCredential, String.Empty);
                credentialList.Add(credential);
            }
            List <AuditLogEntry> auditLogEntriesList = new List <AuditLogEntry>();

            if (dataJSON.ContainsKey("AuditLogEntries"))
            {
                ISerialiser auditLogEntrySerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(AuditLogEntry));
                JArray      auditLogEntries         = JSONHelpers.ReadJArray(dataJSON, "AuditLogEntries", true);
                foreach (JObject curEntry in auditLogEntries)
                {
                    AuditLogEntry entry = (AuditLogEntry)auditLogEntrySerialiser.Read(curEntry, String.Empty);
                    auditLogEntriesList.Add(entry);
                }
                if (auditLogEntriesList.Count > 0)
                {
                    auditLogEntriesList = auditLogEntriesList.OrderByDescending(ale => ale.DateTime).ToList();
                }
            }
            return(new Vault(id,
                             name,
                             description,
                             createdAt,
                             lastUpdatedAt,
                             credentialList.ToArray(),
                             auditLogEntriesList.ToArray()));
        }
        public object Write(
            object data,
            string masterPassphrase,
            params KeyValuePair <string, string>[] parameters)
        {
            FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType());

            DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Writing Vault to JSON using serialiser '{0}'.", formatVersion);

            Dictionary <string, string> parametersDict = parameters.ToDictionary(x => x.Key, x => x.Value);

            Vault   vault = (Vault)data;
            JObject json  = new JObject();

            JObject header = new JObject();

            header.Add("FormatVersion", new JValue(formatVersion.Version));
            json.Add("Header", header);

            json.Add("ID", new JValue(vault.ID));
            json.Add("Name", new JValue(vault.Name));
            json.Add("Description", new JValue(vault.Description));
            json.Add("CreatedAt", new JValue(vault.CreatedAt.ToString(Common.DATETIMESERIALISATIONFORMAT)));
            json.Add("LastUpdatedAt", new JValue(vault.LastUpdatedAt.ToString(Common.DATETIMESERIALISATIONFORMAT)));

            ISerialiser credentialSerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(Credential));
            JArray      credentialJSON       = new JArray();

            foreach (Credential curCredential in vault.Credentials)
            {
                credentialJSON.Add(credentialSerialiser.Write(curCredential, String.Empty));
            }

            json.Add("Credentials", credentialJSON);
            ISerialiser auditLogEntrySerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(AuditLogEntry));
            JArray      auditLogEntries         = new JArray();

            foreach (AuditLogEntry curEntry in vault.AuditLogEntries)
            {
                auditLogEntries.Add(auditLogEntrySerialiser.Write(curEntry, String.Empty));
            }
            json.Add("AuditLogEntries", auditLogEntries);
            return(json);
        }
        public object Write(
            object data,
            string masterPassphrase,
            params KeyValuePair <string, string>[] parameters)
        {
            FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType());

            DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Writing Credential to JSON using serialiser '{0}'.", formatVersion);

            Credential credential = (Credential)data;
            JObject    json       = new JObject();

            json.Add("ID", new JValue(credential.ID));
            json.Add("GlyphKey", new JValue(credential.GlyphKey));
            json.Add("GlyphColour", new JValue(credential.GlyphColour));
            json.Add("Name", new JValue(credential.Name));
            json.Add("Description", new JValue(credential.Description));
            json.Add("Website", new JValue(credential.Website));
            json.Add("CreatedAt", new JValue(credential.CreatedAt.ToString(Common.DATETIMESERIALISATIONFORMAT)));
            json.Add("LastUpdatedAt", new JValue(credential.LastModifiedAt.ToString(Common.DATETIMESERIALISATIONFORMAT)));
            json.Add("PasswordLastModifiedAt", new JValue(credential.PasswordLastModifiedAt.ToString(Common.DATETIMESERIALISATIONFORMAT)));
            json.Add("Username", new JValue(credential.Username));
            json.Add("Password", new JValue(credential.Password));
            JArray tagsArray = new JArray();

            foreach (String curTag in credential.Tags)
            {
                tagsArray.Add(new JValue(curTag));
            }
            json.Add("Tags", tagsArray);
            ISerialiser auditLogEntrySerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(AuditLogEntry));
            JArray      auditLogEntries         = new JArray();

            foreach (AuditLogEntry curEntry in credential.AuditLogEntries)
            {
                auditLogEntries.Add(auditLogEntrySerialiser.Write(curEntry, String.Empty));
            }
            json.Add("Notes", credential.Notes);
            json.Add("AuditLogEntries", auditLogEntries);
            return(json);
        }
Example #6
0
        public object Write(
            object data,
            string masterPassphrase,
            params KeyValuePair <string, string>[] parameters)
        {
            FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType());

            DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Writing AuditLogEntry to JSON using serialiser '{0}'.", formatVersion);

            AuditLogEntry auditLogEntry = (AuditLogEntry)data;
            JObject       json          = new JObject();

            json.Add("DateTime", auditLogEntry.DateTime.ToString("HH:mm:ss dd-MM-yyyy"));
            json.Add("TypeOfEntry", auditLogEntry.TypeOfEntry.ToString());
            JObject paramaters = new JObject();

            foreach (String curKey in auditLogEntry.Parameters.Keys)
            {
                String curValue = auditLogEntry.Parameters[curKey];
                paramaters.Add(curKey, new JValue(curValue));
            }
            json.Add("Parameters", paramaters);
            return(json);
        }