age: reject leading zeroes and sign in scrypt work factor

This commit is contained in:
Filippo Valsorda
2022-06-19 17:28:39 +02:00
parent 2088adf268
commit 2e090545df
42 changed files with 456 additions and 11 deletions

27
tests/scrypt_bad_tag.go Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import (
"encoding/base64"
"filippo.io/age/internal/testkit"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, _ := base64.RawStdEncoding.DecodeString(f.UnreadLine())
body[len(body)-1] ^= 0xff
f.TextLine(base64.RawStdEncoding.EncodeToString(body))
f.HMAC()
f.Payload("age")
f.ExpectNoMatch()
f.Comment("the ChaCha20Poly1305 authentication tag on the body of the scrypt stanza is wrong")
f.Generate()
}

View File

@@ -0,0 +1,23 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadLine()
f.TextLine(args + " 10")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Comment("the base64 encoding of the share is not canonical")
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body := f.UnreadLine()
f.TextLine(testkit.NotCanonicalBase64(body))
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Comment("the base64 encoding of the share is not canonical")
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], testkit.NotCanonicalBase64(args[1]), args[2])
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

20
tests/scrypt_salt_long.go Normal file
View File

@@ -0,0 +1,20 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.ScryptRecordPassphrase("password")
f.ScryptNoRecordPassphraseWithSalt("password", 10, f.Rand(20))
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,23 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.ScryptRecordPassphrase("password")
f.ScryptNoRecordPassphraseWithSalt("password", 10, nil)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[2])
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,20 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.ScryptRecordPassphrase("password")
f.ScryptNoRecordPassphraseWithSalt("password", 10, f.Rand(12))
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

22
tests/scrypt_uppercase.go Normal file
View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine("Scrypt", args[1], args[2])
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectNoMatch()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "0xa")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "aaaa10")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "+10")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "010")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "012")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 18) // cmd/age default
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1])
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "-10")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import (
"math"
"strconv"
"filippo.io/age/internal/testkit"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], strconv.FormatUint(math.MaxInt64+1+10, 10))
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "aaaa10")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 18) // cmd/go default
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "10")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectNoMatch()
f.Generate()
}

View File

@@ -0,0 +1,22 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.Scrypt("password", 10)
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine(args[0], args[1], "0")
f.TextLine(body)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.Generate()
}

View File

@@ -6,18 +6,14 @@
package main
import (
"strings"
"filippo.io/age/internal/testkit"
)
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
body, args := f.UnreadLine(), f.UnreadLine()
f.TextLine(strings.Replace(args, "X25519", "x25519", -1))
body, args := f.UnreadLine(), f.UnreadArgsLine()
f.ArgsLine("x25519", args[1])
f.TextLine(body)
f.HMAC()
f.Payload("age")

View File

@@ -12,8 +12,7 @@ func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
body, args := f.UnreadLine(), f.UnreadLine()
f.TextLine(args)
body := f.UnreadLine()
f.TextLine(testkit.NotCanonicalBase64(body))
f.HMAC()
f.Payload("age")