2024-06-17 11:36:53 +00:00
|
|
|
//go:build gofuzz
|
|
|
|
// +build gofuzz
|
|
|
|
|
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
2024-09-04 14:35:39 +00:00
|
|
|
"context"
|
2024-06-17 11:36:53 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2024-09-04 14:35:39 +00:00
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
2024-06-17 11:36:53 +00:00
|
|
|
utils "github.com/trailofbits/go-fuzz-utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
fuzzSuccessExitCode = 0
|
|
|
|
fuzzFailExitCode = -1
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitFuzzAuthenticate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func DoFuzzAuthenticate(input []byte) int {
|
|
|
|
// FUZZER INIT
|
|
|
|
if len(input) < 100 {
|
|
|
|
return fuzzFailExitCode
|
|
|
|
}
|
|
|
|
|
|
|
|
tp, err := utils.NewTypeProvider(input)
|
|
|
|
if err != nil {
|
|
|
|
return fuzzFailExitCode
|
|
|
|
}
|
|
|
|
|
|
|
|
var accessKeyAddr oid.Address
|
|
|
|
err = tp.Fill(accessKeyAddr)
|
|
|
|
if err != nil {
|
|
|
|
return fuzzFailExitCode
|
|
|
|
}
|
|
|
|
|
|
|
|
accessKeyID := strings.ReplaceAll(accessKeyAddr.String(), "/", "0")
|
|
|
|
secretKey, err := tp.GetString()
|
2024-09-04 14:35:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return fuzzFailExitCode
|
|
|
|
}
|
|
|
|
awsCreds := aws.Credentials{AccessKeyID: accessKeyID, SecretAccessKey: secretKey}
|
2024-06-17 11:36:53 +00:00
|
|
|
|
|
|
|
reqData := RequestData{
|
|
|
|
Method: "GET",
|
|
|
|
Endpoint: "http://localhost:8084",
|
|
|
|
Bucket: "my-bucket",
|
|
|
|
Object: "@obj/name",
|
|
|
|
}
|
|
|
|
presignData := PresignData{
|
|
|
|
Service: "s3",
|
|
|
|
Region: "spb",
|
|
|
|
Lifetime: 10 * time.Minute,
|
|
|
|
SignTime: time.Now().UTC(),
|
|
|
|
}
|
|
|
|
|
2024-09-04 14:35:39 +00:00
|
|
|
req, err := PresignRequest(context.Background(), awsCreds, reqData, presignData)
|
2024-06-17 11:36:53 +00:00
|
|
|
if req == nil {
|
|
|
|
return fuzzFailExitCode
|
|
|
|
}
|
|
|
|
|
|
|
|
expBox := &accessbox.Box{
|
|
|
|
Gate: &accessbox.GateData{
|
|
|
|
SecretKey: secretKey,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := newTokensFrostfsMock()
|
|
|
|
mock.addBox(accessKeyAddr, expBox)
|
|
|
|
|
|
|
|
c := &Center{
|
|
|
|
cli: mock,
|
2024-09-16 09:04:52 +00:00
|
|
|
reg: NewRegexpMatcher(AuthorizationFieldRegexp),
|
2024-06-17 11:36:53 +00:00
|
|
|
postReg: NewRegexpMatcher(postPolicyCredentialRegexp),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _ = c.Authenticate(req)
|
|
|
|
|
|
|
|
return fuzzSuccessExitCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func FuzzAuthenticate(f *testing.F) {
|
|
|
|
f.Fuzz(func(t *testing.T, data []byte) {
|
|
|
|
DoFuzzAuthenticate(data)
|
|
|
|
})
|
|
|
|
}
|