forked from PhilippC/keepass2android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeeShareAuditLog.cs
More file actions
78 lines (69 loc) · 2.15 KB
/
KeeShareAuditLog.cs
File metadata and controls
78 lines (69 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using KeePassLib;
using keepass2android.KeeShare;
namespace keepass2android.KeeShare
{
public static class KeeShareAuditLog
{
public enum AuditAction
{
ImportSuccess,
ImportFailure,
ExportSuccess,
ExportFailure,
TrustDecision,
SignatureVerified,
SignatureRejected
}
public class AuditEntry
{
public DateTime Timestamp { get; set; }
public AuditAction Action { get; set; }
public string SourcePath { get; set; }
public string Details { get; set; }
public string Fingerprint { get; set; }
}
private static List<AuditEntry> _entries = new List<AuditEntry>();
public static void Log(AuditAction action, string path, string details, string fingerprint = null)
{
var entry = new AuditEntry
{
Timestamp = DateTime.UtcNow,
Action = action,
SourcePath = path,
Details = details,
Fingerprint = fingerprint
};
lock (_entries)
{
_entries.Add(entry);
if (_entries.Count > 1000)
_entries.RemoveAt(0); // Keep last 1000
}
// Also log to system log for now
Kp2aLog.Log($"[KeeShare Audit] {action}: {path} - {details}");
}
public static List<AuditEntry> GetEntries()
{
lock (_entries)
{
return new List<AuditEntry>(_entries);
}
}
public static AuditEntry GetLastEntryForPath(string path)
{
if (string.IsNullOrEmpty(path)) return null;
lock (_entries)
{
// Traverse backwards to find latest
for (int i = _entries.Count - 1; i >= 0; i--)
{
if (_entries[i].SourcePath == path)
return _entries[i];
}
}
return null;
}
}
}