Skip to content

Commit

Permalink
Bug fix: allow passphrases for templates (#21)
Browse files Browse the repository at this point in the history
- update templates
  • Loading branch information
JakeWnuk committed May 15, 2024
1 parent 2502886 commit bcc6fa7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 19 deletions.
6 changes: 4 additions & 2 deletions docs/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "mask"
"TransformationMode": "mask",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "dsb",
"Bypass": false,
"TransformationMode": "mask"
"TransformationMode": "mask",
"PassphraseWords": 0
}
]
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func main() {
// Apply transformations from template files
for i, template := range transformationTemplateArray {
if i == 0 {
temporaryMap = transform.TransformationController(primaryMap, template.TransformationMode, template.StartIndex, template.EndIndex, template.Verbose, template.ReplacementMask, transformationFilesMap, template.Bypass, *debugMode, *passPhraseWords)
temporaryMap = transform.TransformationController(primaryMap, template.TransformationMode, template.StartIndex, template.EndIndex, template.Verbose, template.ReplacementMask, transformationFilesMap, template.Bypass, *debugMode, template.PassphraseWords)
} else {
temporaryMap = utils.CombineMaps(temporaryMap, transform.TransformationController(primaryMap, template.TransformationMode, template.StartIndex, template.EndIndex, template.Verbose, template.ReplacementMask, transformationFilesMap, template.Bypass, *debugMode, *passPhraseWords))
temporaryMap = utils.CombineMaps(temporaryMap, transform.TransformationController(primaryMap, template.TransformationMode, template.StartIndex, template.EndIndex, template.Verbose, template.ReplacementMask, transformationFilesMap, template.Bypass, *debugMode, template.PassphraseWords))
}
}
primaryMap = temporaryMap
Expand Down
1 change: 1 addition & 0 deletions pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type TemplateFileOperation struct {
ReplacementMask string
Bypass bool
TransformationMode string
PassphraseWords int
}

// ----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions pkg/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
// use for modes like retain-mask
// bypass (bool): If true, the map is not used for output or filtering
// debug (int): Different debug levels to use for debugging [0-2]
// passphraseWord (int): The number of words to use for passphrase generation
// passphraseWords (int): The number of words to use for passphrase generation
//
// Returns:
//
// (map[string]int): A map of transformed values
func TransformationController(input map[string]int, mode string, startingIndex int, endingIndex int, verbose bool, replacementMask string, transformationFilesMap map[string]int, bypass bool, debug int, passphraseWord int) (output map[string]int) {
func TransformationController(input map[string]int, mode string, startingIndex int, endingIndex int, verbose bool, replacementMask string, transformationFilesMap map[string]int, bypass bool, debug int, passphraseWords int) (output map[string]int) {

functionDebug := false
if debug > 1 {
Expand Down Expand Up @@ -116,11 +116,11 @@ func TransformationController(input map[string]int, mode string, startingIndex i
}
output = mask.ShuffleMap(input, replacementMask, transformationFilesMap, bypass, functionDebug)
case "passphrase", "phrase", "pp":
if passphraseWord == 0 {
if passphraseWords == 0 {
fmt.Fprintf(os.Stderr, "[!] Passphrase operations require use of the -w flag to specify the number of words to use\n")
os.Exit(1)
}
output = MakePassphraseMap(input, transformationFilesMap, bypass, functionDebug, passphraseWord)
output = MakePassphraseMap(input, transformationFilesMap, bypass, functionDebug, passphraseWords)
default:
output = input
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ func ReadJSONToArray(fs models.FileSystem, filenames []string) []models.Template
fmt.Fprintf(os.Stderr, "[!] Error: TransformationMode must be a string\n")
os.Exit(1)
}

if !numRe.MatchString(fmt.Sprintf("%v", template.PassphraseWords)) {
fmt.Fprintf(os.Stderr, "[!] Error: PassphraseWords must be an integer\n")
os.Exit(1)
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions templates/append.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "append"
"TransformationMode": "append",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "append-remove"
"TransformationMode": "append-remove",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "append-shift"
"TransformationMode": "append-shift",
"PassphraseWords": 0
}
]
6 changes: 4 additions & 2 deletions templates/inov1-6.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "insert"
"TransformationMode": "insert",
"PassphraseWords": 0
},
{
"StartIndex": 1,
"EndIndex": 6,
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "overwrite"
"TransformationMode": "overwrite",
"PassphraseWords": 0
}
]
9 changes: 6 additions & 3 deletions templates/mask.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
"Verbose": false,
"ReplacementMask": "ul",
"Bypass": false,
"TransformationMode": "mask"
"TransformationMode": "mask",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "dsb",
"Bypass": false,
"TransformationMode": "mask"
"TransformationMode": "mask",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "mask"
"TransformationMode": "mask",
"PassphraseWords": 0
}
]
9 changes: 6 additions & 3 deletions templates/prepend.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "prepend"
"TransformationMode": "prepend",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "prepend-remove"
"TransformationMode": "prepend-remove",
"PassphraseWords": 0
},
{
"StartIndex": 0,
"EndIndex": 0,
"Verbose": false,
"ReplacementMask": "uldsb",
"Bypass": false,
"TransformationMode": "prepend-shift"
"TransformationMode": "prepend-shift",
"PassphraseWords": 0
}
]

0 comments on commit bcc6fa7

Please sign in to comment.