Consistently use "age" when referencing age files, not "aging"

This commit is contained in:
2025-11-23 03:25:20 -05:00
parent 50d51f9d96
commit 3ddce4bdf5
8 changed files with 22 additions and 25 deletions
+3 -6
View File
@@ -29,7 +29,7 @@ func AgeEntry(vanityPath string, timestamp int64) error {
return nil return nil
} }
// AgeAllPasswordEntries adds aging data for all un-aged entries containing passwords. // AgeAllPasswordEntries adds age data for all un-aged entries containing passwords.
// Each entry is aged with a random timestamp from within the last year to prevent // Each entry is aged with a random timestamp from within the last year to prevent
// all entries having their passwords expire at the same time. // all entries having their passwords expire at the same time.
func AgeAllPasswordEntries(forceReage bool) error { func AgeAllPasswordEntries(forceReage bool) error {
@@ -39,7 +39,7 @@ func AgeAllPasswordEntries(forceReage bool) error {
} }
for _, vanityPath := range allVanityPaths { for _, vanityPath := range allVanityPaths {
// ensure entry is not already aged (unless forcing re-aging) // ensure entry is not already aged (unless forcing re-age)
if !forceReage { if !forceReage {
// ignore error; we only care if we can access the path or not // ignore error; we only care if we can access the path or not
isAccessible, _ := back.TargetIsFile(global.AgeDir+global.PathSeparator+strings.ReplaceAll(vanityPath, "/", global.FSPath), true) isAccessible, _ := back.TargetIsFile(global.AgeDir+global.PathSeparator+strings.ReplaceAll(vanityPath, "/", global.FSPath), true)
@@ -68,7 +68,7 @@ func AgeAllPasswordEntries(forceReage bool) error {
} }
// TranslateAgeTimestamp returns a uint8 value indicating // TranslateAgeTimestamp returns a uint8 value indicating
// the interpreted age status of an aging timestamp associated // the interpreted age status of an age timestamp associated
// with an entry. // with an entry.
// Magic number legend: // Magic number legend:
// 0 -> no age, 1 -> fresh, 2 -> expiring soon (within a month), 3 -> expired // 0 -> no age, 1 -> fresh, 2 -> expiring soon (within a month), 3 -> expired
@@ -86,6 +86,3 @@ func TranslateAgeTimestamp(timestamp int64) uint8 {
return 1 // fresh return 1 // fresh
} }
} }
// TODO
// 1. Add sync support for the aging directory
+6 -6
View File
@@ -18,7 +18,7 @@ import (
) )
// WriteEntry writes entryData to an encrypted file at realPath. // WriteEntry writes entryData to an encrypted file at realPath.
// If the entry contains an updated password, an aging file is also created. // If the entry contains an updated password, an age file is also created.
func WriteEntry(realPath string, decSlice []string, passwordIsNew bool) error { func WriteEntry(realPath string, decSlice []string, passwordIsNew bool) error {
err := os.WriteFile(realPath, crypt.EncryptBytes([]byte(strings.Join(decSlice, "\n"))), 0600) err := os.WriteFile(realPath, crypt.EncryptBytes([]byte(strings.Join(decSlice, "\n"))), 0600)
if err != nil { if err != nil {
@@ -26,16 +26,16 @@ func WriteEntry(realPath string, decSlice []string, passwordIsNew bool) error {
} }
if decSlice != nil { if decSlice != nil {
if passwordIsNew { // update aging data when password changes if passwordIsNew { // update age data when password changes
if decSlice[0] != "" { // if the password change was NOT a removal, update the aging file if decSlice[0] != "" { // if the password change was NOT a removal, update the age file
err = age.AgeEntry(global.GetVanityPath(realPath), time.Now().Unix()) err = age.AgeEntry(global.GetVanityPath(realPath), time.Now().Unix())
if err != nil { if err != nil {
return errors.New("unable to update aging data: " + err.Error()) return errors.New("unable to update age data: " + err.Error())
} }
} else { // if the password change was a removal, remove the associated aging file } else { // if the password change was a removal, remove the associated age file
err = syncclient.ShearRemoteFromClient(global.GetVanityPath(realPath), true) err = syncclient.ShearRemoteFromClient(global.GetVanityPath(realPath), true)
if err != nil { if err != nil {
return errors.New("unable to remove aging data: " + err.Error()) return errors.New("unable to remove age data: " + err.Error())
} }
} }
} }
+1 -1
View File
@@ -8,7 +8,7 @@ var (
EntryRoot = back.Home + "/.local/share/libmutton" // Path to libmutton entry directory EntryRoot = back.Home + "/.local/share/libmutton" // Path to libmutton entry directory
ConfigDir = back.Home + "/.config/libmutton" // Path to libmutton configuration directory ConfigDir = back.Home + "/.config/libmutton" // Path to libmutton configuration directory
ConfigPath = ConfigDir + "/libmutton.ini" // Path to libmutton configuration file ConfigPath = ConfigDir + "/libmutton.ini" // Path to libmutton configuration file
AgeDir = ConfigDir + "/aging" // Path to libmutton password aging database AgeDir = ConfigDir + "/age" // Path to libmutton password age directory
) )
const ( const (
+1 -1
View File
@@ -8,7 +8,7 @@ var (
EntryRoot = back.Home + "\\AppData\\Local\\libmutton\\entries" // Path to libmutton entry directory EntryRoot = back.Home + "\\AppData\\Local\\libmutton\\entries" // Path to libmutton entry directory
ConfigDir = back.Home + "\\AppData\\Local\\libmutton\\config" // Path to libmutton configuration directory ConfigDir = back.Home + "\\AppData\\Local\\libmutton\\config" // Path to libmutton configuration directory
ConfigPath = ConfigDir + "\\libmutton.ini" // Path to libmutton configuration file ConfigPath = ConfigDir + "\\libmutton.ini" // Path to libmutton configuration file
AgeDir = ConfigDir + "\\aging" // Path to libmutton password aging database AgeDir = ConfigDir + "\\age" // Path to libmutton password age directory
) )
const ( const (
+1 -1
View File
@@ -39,7 +39,7 @@ func DirInit(preserveOldConfigDir bool) (string, error) {
return "", errors.New("unable to create \"" + ConfigDir + "\": " + err.Error()) return "", errors.New("unable to create \"" + ConfigDir + "\": " + err.Error())
} }
// create password aging directory // create password age directory
err = os.MkdirAll(AgeDir, 0700) err = os.MkdirAll(AgeDir, 0700)
if err != nil { if err != nil {
return "", errors.New("unable to create \"" + AgeDir + "\": " + err.Error()) return "", errors.New("unable to create \"" + AgeDir + "\": " + err.Error())
+1 -1
View File
@@ -51,7 +51,7 @@ func main() {
// stdin[1] is expected to be the vanityPath with FSPath representing path separators - Always pass in UNIX format // stdin[1] is expected to be the vanityPath with FSPath representing path separators - Always pass in UNIX format
_, _, _ = synccommon.ShearLocal(strings.ReplaceAll(stdin[1], global.FSPath, "/"), stdin[0], false) _, _, _ = synccommon.ShearLocal(strings.ReplaceAll(stdin[1], global.FSPath, "/"), stdin[0], false)
case "shear-age": case "shear-age":
// shear ONLY the aging file associated with an entry from the server and add it to the deletions directory // shear ONLY the age file associated with an entry from the server and add it to the deletions directory
// stdin[0] is expected to be the device ID // stdin[0] is expected to be the device ID
// stdin[1] is expected to be the vanityPath with FSPath representing path separators - Always pass in UNIX format // stdin[1] is expected to be the vanityPath with FSPath representing path separators - Always pass in UNIX format
_, _, _ = synccommon.ShearLocal(strings.ReplaceAll(stdin[1], global.FSPath, "/"), stdin[0], true) _, _, _ = synccommon.ShearLocal(strings.ReplaceAll(stdin[1], global.FSPath, "/"), stdin[0], true)
+3 -3
View File
@@ -15,8 +15,8 @@ import (
// It can safely be called in offline mode, as well, so this is // It can safely be called in offline mode, as well, so this is
// the intended interface for shearing (ShearLocal should only // the intended interface for shearing (ShearLocal should only
// be used directly by the server binary). // be used directly by the server binary).
func ShearRemoteFromClient(vanityPath string, onlyShearAgingFile bool) error { func ShearRemoteFromClient(vanityPath string, onlyShearAgeFile bool) error {
deviceID, isDir, err := synccommon.ShearLocal(vanityPath, "", onlyShearAgingFile) // remove the target from the local system and get the device ID of the client deviceID, isDir, err := synccommon.ShearLocal(vanityPath, "", onlyShearAgeFile) // remove the target from the local system and get the device ID of the client
if err != nil { if err != nil {
return errors.New("unable to shear target locally: " + err.Error()) return errors.New("unable to shear target locally: " + err.Error())
} }
@@ -39,7 +39,7 @@ func ShearRemoteFromClient(vanityPath string, onlyShearAgingFile bool) error {
} }
// call the server to remotely shear the target and add it to the deletions list // call the server to remotely shear the target and add it to the deletions list
if onlyShearAgingFile { if onlyShearAgeFile {
modifier = "-age" modifier = "-age"
} }
_, err = GetSSHOutput(sshClient, "libmuttonserver shear"+modifier, deviceID+"\n"+strings.ReplaceAll(vanityPath, global.PathSeparator, global.FSPath)) _, err = GetSSHOutput(sshClient, "libmuttonserver shear"+modifier, deviceID+"\n"+strings.ReplaceAll(vanityPath, global.PathSeparator, global.FSPath))
+6 -6
View File
@@ -32,7 +32,7 @@ func GetModTimes(entryList []string) []int64 {
// isDir (only on client; for use in ShearRemoteFromClient). // isDir (only on client; for use in ShearRemoteFromClient).
// If the local system is a server, it will also add the target to the deletions list for all clients (except the requesting client). // If the local system is a server, it will also add the target to the deletions list for all clients (except the requesting client).
// This function should only be used directly by the server binary. // This function should only be used directly by the server binary.
func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgingFile bool) (string, bool, error) { func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error) {
// determine if running on a server // determine if running on a server
var onServer bool var onServer bool
if clientDeviceID != "" { if clientDeviceID != "" {
@@ -48,7 +48,7 @@ func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgingFile bool) (str
if onServer { if onServer {
for _, device := range deviceIDList { for _, device := range deviceIDList {
if device.Name() != clientDeviceID { if device.Name() != clientDeviceID {
if !onlyShearAgingFile { if !onlyShearAgeFile {
f, err := os.OpenFile(global.ConfigDir+global.PathSeparator+"deletions"+global.PathSeparator+device.Name()+global.FSSpace+"entry"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600) f, err := os.OpenFile(global.ConfigDir+global.PathSeparator+"deletions"+global.PathSeparator+device.Name()+global.FSSpace+"entry"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600)
if err != nil { if err != nil {
// do not print error as there is currently no way of seeing server-side errors // do not print error as there is currently no way of seeing server-side errors
@@ -80,7 +80,7 @@ func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgingFile bool) (str
isFile = true isFile = true
} }
} }
if !onlyShearAgingFile { if !onlyShearAgeFile {
err = os.RemoveAll(realPath) err = os.RemoveAll(realPath)
if err != nil { if err != nil {
return "", false, errors.New("unable to remove local entry (" + vanityPath + "): " + err.Error()) return "", false, errors.New("unable to remove local entry (" + vanityPath + "): " + err.Error())
@@ -109,12 +109,12 @@ func ShearAgeFileLocal(vanityPath string) error {
return nil return nil
} }
// GetEntryAges reads the aging directory and returns a // GetEntryAges reads the age directory and returns a
// map of vanity paths to their corresponding age timestamps. // map of vanity paths to their corresponding age timestamps.
func GetEntryAges() (map[string]int64, error) { func GetEntryAges() (map[string]int64, error) {
contents, err := os.ReadDir(global.AgeDir) contents, err := os.ReadDir(global.AgeDir)
if err != nil { if err != nil {
return nil, errors.New("unable to read aging directory contents: " + err.Error()) return nil, errors.New("unable to read age directory contents: " + err.Error())
} }
var vanityPathsToTimestamps = make(map[string]int64) var vanityPathsToTimestamps = make(map[string]int64)
@@ -123,7 +123,7 @@ func GetEntryAges() (map[string]int64, error) {
vanityPath := strings.ReplaceAll(dirEntry.Name(), global.FSPath, "/") vanityPath := strings.ReplaceAll(dirEntry.Name(), global.FSPath, "/")
info, err := dirEntry.Info() info, err := dirEntry.Info()
if err != nil { if err != nil {
return nil, errors.New("unable to read aging file modtime for " + vanityPath + ": " + err.Error()) return nil, errors.New("unable to read age file modtime for " + vanityPath + ": " + err.Error())
} }
vanityPathsToTimestamps[vanityPath] = info.ModTime().Unix() vanityPathsToTimestamps[vanityPath] = info.ModTime().Unix()
} }