|
|
@ -17,7 +17,6 @@ |
|
|
|
package cmd |
|
|
|
package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/base64" |
|
|
|
|
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"reflect" |
|
|
|
"reflect" |
|
|
@ -52,6 +51,13 @@ func isString(val interface{}) bool { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ContentLengthRange - policy content-length-range field.
|
|
|
|
|
|
|
|
type contentLengthRange struct { |
|
|
|
|
|
|
|
Min int |
|
|
|
|
|
|
|
Max int |
|
|
|
|
|
|
|
Valid bool // If content-length-range was part of policy
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// PostPolicyForm provides strict static type conversion and validation for Amazon S3's POST policy JSON string.
|
|
|
|
// PostPolicyForm provides strict static type conversion and validation for Amazon S3's POST policy JSON string.
|
|
|
|
type PostPolicyForm struct { |
|
|
|
type PostPolicyForm struct { |
|
|
|
Expiration time.Time // Expiration date and time of the POST policy.
|
|
|
|
Expiration time.Time // Expiration date and time of the POST policy.
|
|
|
@ -60,10 +66,7 @@ type PostPolicyForm struct { |
|
|
|
Operator string |
|
|
|
Operator string |
|
|
|
Value string |
|
|
|
Value string |
|
|
|
} |
|
|
|
} |
|
|
|
ContentLengthRange struct { |
|
|
|
ContentLengthRange contentLengthRange |
|
|
|
Min int |
|
|
|
|
|
|
|
Max int |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -133,13 +136,7 @@ func parsePostPolicyFormV4(policy string) (PostPolicyForm, error) { |
|
|
|
Value: value, |
|
|
|
Value: value, |
|
|
|
} |
|
|
|
} |
|
|
|
case "content-length-range": |
|
|
|
case "content-length-range": |
|
|
|
parsedPolicy.Conditions.ContentLengthRange = struct { |
|
|
|
parsedPolicy.Conditions.ContentLengthRange = contentLengthRange{toInteger(condt[1]), toInteger(condt[2]), true} |
|
|
|
Min int |
|
|
|
|
|
|
|
Max int |
|
|
|
|
|
|
|
}{ |
|
|
|
|
|
|
|
Min: toInteger(condt[1]), |
|
|
|
|
|
|
|
Max: toInteger(condt[2]), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
// Condition should be valid.
|
|
|
|
// Condition should be valid.
|
|
|
|
return parsedPolicy, fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.", reflect.TypeOf(condt).String(), condt) |
|
|
|
return parsedPolicy, fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.", reflect.TypeOf(condt).String(), condt) |
|
|
@ -152,16 +149,7 @@ func parsePostPolicyFormV4(policy string) (PostPolicyForm, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// checkPostPolicy - apply policy conditions and validate input values.
|
|
|
|
// checkPostPolicy - apply policy conditions and validate input values.
|
|
|
|
func checkPostPolicy(formValues map[string]string) APIErrorCode { |
|
|
|
func checkPostPolicy(formValues map[string]string, postPolicyForm PostPolicyForm) APIErrorCode { |
|
|
|
/// Decoding policy
|
|
|
|
|
|
|
|
policyBytes, err := base64.StdEncoding.DecodeString(formValues["Policy"]) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return ErrMalformedPOSTRequest |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
postPolicyForm, err := parsePostPolicyFormV4(string(policyBytes)) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return ErrMalformedPOSTRequest |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !postPolicyForm.Expiration.After(time.Now().UTC()) { |
|
|
|
if !postPolicyForm.Expiration.After(time.Now().UTC()) { |
|
|
|
return ErrPolicyAlreadyExpired |
|
|
|
return ErrPolicyAlreadyExpired |
|
|
|
} |
|
|
|
} |
|
|
|