Skip to content

Commit

Permalink
Fix OSSH prefix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
adotkhan committed Jun 20, 2023
1 parent 908e393 commit cf7d725
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
7 changes: 6 additions & 1 deletion psiphon/common/parameters/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,12 @@ func (p *Parameters) Set(
return nil, errors.Trace(err)
}
case transforms.Specs:
err := v.Validate()
bytemode := false
if name == OSSHPrefixSpecs || name == ServerOSSHPrefixSpecs {
// Specs for OSSH prefixes use generator in ByteMode.
bytemode = true
}
err := v.Validate(bytemode)
if err != nil {
if skipOnError {
continue
Expand Down
29 changes: 24 additions & 5 deletions psiphon/common/transforms/transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,35 @@ type Specs map[string]Spec

// Validate checks that all entries in a set of Specs is well-formed, with
// valid regular expressions.
func (specs Specs) Validate() error {
func (specs Specs) Validate(bytemode bool) error {
seed, err := prng.NewSeed()
if err != nil {
return errors.Trace(err)
}
for _, spec := range specs {
// Call Apply to compile/validate the regular expressions and generators.
_, err := spec.ApplyString(seed, "")
if err != nil {
return errors.Trace(err)
if bytemode {

args := &regen.GeneratorArgs{
RngSource: prng.NewPRNGWithSeed(seed),
ByteMode: true,
}

gen, err := regen.NewGenerator(spec[0][1], args)
if err != nil {
return errors.Trace(err)
}

_, err = gen.Generate()
if err != nil {
return errors.Trace(err)
}

} else {
// Call Apply to compile/validate the regular expressions and generators.
_, err := spec.ApplyString(seed, "")
if err != nil {
return errors.Trace(err)
}
}
}

Expand Down

0 comments on commit cf7d725

Please sign in to comment.