Documentation ¶
Overview ¶
This file implements helper functions to validate AWS Signature Version '4' authorization header.
This package provides comprehensive helpers for following signature types. - Based on Authorization header. - Based on Query parameters. - Based on Form POST policy.
Index ¶
- Constants
- func AESDecrypt(cryptData, key []byte) ([]byte, error)
- func AESDecryptHexStringToOrigin(hexStr string, key []byte) (string, error)
- func AESEncrypt(data, key []byte) ([]byte, error)
- func AESEncryptToHexString(data, key []byte) (string, error)
- func Format(s string) string
- func GenMinimalPart() []byte
- func GenTestObjectUrl(sc *S3Client) string
- func GenTestSpecialCharaterObjectUrl(sc *S3Client) string
- func HTTPRequestToGetObject(url string) (status int, val []byte, err error)
- func HTTPRequestToGetObjectWithReferer(url string, refererUrl string) (status int, val []byte, err error)
- func HTTPRequestToGetObjectWithSpecialIP(url string, ipAddress string) (status int, val []byte, err error)
- func RandBytes(ln int) []byte
- func TransferToS3AccessControlPolicy(policy *datatype.AccessControlPolicy) (s3policy *s3.AccessControlPolicy)
- type AccessPolicyGroup
- type HTTPRequestToGetObjectType
- type PostObjectInput
- type S3Client
- func (s3client *S3Client) AbortMultiPartUpload(bucketName, key, uploadId string) (err error)
- func (s3client *S3Client) AppendObject(bucketName, key, value string, position int64) (nextPos int64, err error)
- func (s3client *S3Client) ChangeObjectStorageClass(bucketName, key string, storageClass string) (err error)
- func (sc *S3Client) CleanEnv()
- func (s3client *S3Client) CompleteMultiPartUpload(bucketName, key, uploadId string, completed *s3.CompletedMultipartUpload) (err error)
- func (s3client *S3Client) CreateMultiPartUpload(bucketName, key, storageClass string) (uploadId string, err error)
- func (s3client *S3Client) DeleteBucket(bucketName string) (err error)
- func (s3client *S3Client) DeleteBucketPolicy(bucketName string) (err error)
- func (s3client *S3Client) DeleteBucketWebsite(bucketName string) (err error)
- func (s3client *S3Client) DeleteObject(bucketName, key string) (err error)
- func (s3client *S3Client) GetBucketAcl(bucketName string) (ret string, err error)
- func (s3client *S3Client) GetBucketPolicy(bucketName string) (policy string, err error)
- func (s3client *S3Client) GetBucketWebsite(bucketName string) (conf string, err error)
- func (s3client *S3Client) GetEncryptObjectWithSSEC(bucketName, key string) (value string, err error)
- func (s3client *S3Client) GetEncryptObjectWithSSES3(bucketName, key string) (value string, err error)
- func (s3client *S3Client) GetObject(bucketName, key string) (value string, err error)
- func (s3client *S3Client) GetObjectAcl(bucketName, objName string) (ret string, err error)
- func (s3client *S3Client) GetObjectOutPut(bucketName, key string) (out *s3.GetObjectOutput, err error)
- func (s3client *S3Client) GetObjectPreSigned(bucketName, key string, expire time.Duration) (url string, err error)
- func (s3client *S3Client) HeadBucket(bucketName string) (err error)
- func (s3client *S3Client) HeadObject(bucketName, key string) (err error)
- func (s3client *S3Client) MakeBucket(bucketName string) (err error)
- func (s3Client *S3Client) PostObject(pbi *PostObjectInput) error
- func (s3client *S3Client) PutBucketAcl(bucketName string, acl string) (err error)
- func (s3client *S3Client) PutBucketAclWithXml(bucketName string, acl *s3.AccessControlPolicy) (err error)
- func (s3client *S3Client) PutBucketPolicy(bucketName, policy string) (err error)
- func (s3client *S3Client) PutBucketWebsite(bucketName, index, error string) (err error)
- func (s3client *S3Client) PutBucketWebsiteWithConf(bucketName string, conf *s3.WebsiteConfiguration) (err error)
- func (s3client *S3Client) PutEncryptObjectWithSSEC(bucketName, key, value string) (err error)
- func (s3client *S3Client) PutEncryptObjectWithSSES3(bucketName, key, value string) (err error)
- func (s3client *S3Client) PutObject(bucketName, key, value string) (err error)
- func (s3client *S3Client) PutObjectAcl(bucketName, objName string, acl string) (err error)
- func (s3client *S3Client) PutObjectAclWithXml(bucketName, objName string, acl *s3.AccessControlPolicy) (err error)
- func (s3client *S3Client) PutObjectPreSignedWithSpecifiedBody(bucketName, key, value string, expire time.Duration) (url string, err error)
- func (s3client *S3Client) PutObjectPreSignedWithoutSpecifiedBody(bucketName, key, value string, expire time.Duration) (url string, err error)
- func (s3client *S3Client) PutObjectWithStorageClass(bucketName, key, value string, storageClass string) (err error)
- func (sc *S3Client) TestAnonymousAccessResult(policyGroup AccessPolicyGroup, resultCode int) (err error)
- func (sc *S3Client) TestAnonymousAccessResultWithPolicyCondition(policyGroup AccessPolicyGroup, resultCode int, requestCondition string, ...) (err error)
- func (s3client *S3Client) UploadPart(bucketName, key string, value []byte, uploadId string, partNumber int64) (etag string, err error)
Constants ¶
View Source
const ( // BucketCannedACLPrivate is a BucketCannedACL enum value BucketCannedACLPrivate = "private" // BucketCannedACLPublicRead is a BucketCannedACL enum value BucketCannedACLPublicRead = "public-read" // BucketCannedACLPublicReadWrite is a BucketCannedACL enum value BucketCannedACLPublicReadWrite = "public-read-write" // BucketCannedACLAuthenticatedRead is a BucketCannedACL enum value BucketCannedACLAuthenticatedRead = "authenticated-read" // ObjectCannedACLPrivate is a ObjectCannedACL enum value ObjectCannedACLPrivate = "private" // ObjectCannedACLPublicRead is a ObjectCannedACL enum value ObjectCannedACLPublicRead = "public-read" // ObjectCannedACLPublicReadWrite is a ObjectCannedACL enum value ObjectCannedACLPublicReadWrite = "public-read-write" // ObjectCannedACLAuthenticatedRead is a ObjectCannedACL enum value ObjectCannedACLAuthenticatedRead = "authenticated-read" // ObjectCannedACLAwsExecRead is a ObjectCannedACL enum value ObjectCannedACLAwsExecRead = "aws-exec-read" // ObjectCannedACLBucketOwnerRead is a ObjectCannedACL enum value ObjectCannedACLBucketOwnerRead = "bucket-owner-read" // ObjectCannedACLBucketOwnerFullControl is a ObjectCannedACL enum value ObjectCannedACLBucketOwnerFullControl = "bucket-owner-full-control" )
View Source
const ( Endpoint = "s3.test.com:8080" EndpointInternal = "s3-internal.test.com:8080" AccessKey = "hehehehe" SecretKey = "hehehehe" Region = "RegionHeHe" TEST_BUCKET = "mybucket" TEST_KEY = "testput" TEST_KEY_SPECIAL = "testputspecial:!@$%^&*()_+=-;?><| " TEST_VALUE = "valueput" TEST_ILLEGALREFERER = "http://www.thief.com/" TEST_LEGALREFERER = "http://www.genltemen.com/" TEST_COMMONREFERER = "http://www.common.com/" )
View Source
const ( GetObjectPolicy_1 = `{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": {"AWS":["*"]}, "Action": ["s3:GetObject"], "Resource": [ "arn:aws:s3:::` + TEST_BUCKET + `/*" ] }] }` GetObjectPolicy_2 = `{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": {"AWS":["*"]}, "Action": ["s3:GetObject"], "Resource": [ "arn:aws:s3:::` + TEST_BUCKET + `/test/*" ] }] }` SetBucketPolicyAllowStringLike = `{ "Version": "2012-10-17", "Id": "http referer policy example", "Statement": [ { "Sid": "Allow get requests referred by url test1", "Effect":"Allow", "Principal": { "AWS":"*" }, "Action":["s3:GetObject"], "Resource":[ "arn:aws:s3:::` + TEST_BUCKET + `", "arn:aws:s3:::` + TEST_BUCKET + `/*" ], "Condition": {"StringLike":{"aws:Referer":["http://www.genltemen.com/*","http://genltemen.com/*"]}} } ] }` SetBucketPolicyAllowStringNotLike = `{ "Version": "2012-10-17", "Id": "http referer policy example", "Statement": [ { "Sid": "Allow get requests referred by url test2", "Effect":"Allow", "Principal": { "AWS":"*" }, "Action":["s3:GetObject"], "Resource":[ "arn:aws:s3:::` + TEST_BUCKET + `", "arn:aws:s3:::` + TEST_BUCKET + `/*" ], "Condition": {"StringNotLike":{"aws:Referer":["http://www.thief.com/*","http://thief.com/*"]}} } ] }` SetBucketPolicyDenyStringLike = `{ "Version": "2012-10-17", "Id": "http referer policy example", "Statement": [ { "Sid": "Deny get requests referred by url test3", "Effect":"Deny", "Principal": { "AWS":"*" }, "Action":["s3:GetObject"], "Resource":[ "arn:aws:s3:::` + TEST_BUCKET + `", "arn:aws:s3:::` + TEST_BUCKET + `/*" ], "Condition": {"StringLike":{"aws:Referer":["http://www.thief.com/*","http://thief.com/*"]}} } ] }` SetBucketPolicyDenyStringNotLike = `{ "Version": "2012-10-17", "Id": "http referer policy example", "Statement": [ { "Sid": "Deny get requests referred by url test3", "Effect":"Deny", "Principal": { "AWS":"*" }, "Action":["s3:GetObject"], "Resource":[ "arn:aws:s3:::` + TEST_BUCKET + `", "arn:aws:s3:::` + TEST_BUCKET + `/*" ], "Condition": {"StringNotLike":{"aws:Referer":["http://www.genltemen.com/*","http://genltemen.com/*"]}} } ] }` SetBucketPolicyAllowIPAddress = `{ "Id":"PolicyId2", "Version":"2012-10-17", "Statement":[ { "Sid":"AllowIPmix", "Effect":"Allow", "Principal":"*", "Action":"s3:GetObject", "Resource":"arn:aws:s3:::` + TEST_BUCKET + `/*", "Condition": { "IpAddress": { "aws:SourceIp": "10.0.12.0/24" } } } ] }` SetBucketPolicyAllowNotIPAddress = `{ "Id":"PolicyId2", "Version":"2012-10-17", "Statement":[ { "Sid":"AllowIPmix", "Effect":"Allow", "Principal":"*", "Action":"s3:GetObject", "Resource":"arn:aws:s3:::` + TEST_BUCKET + `/*", "Condition": { "NotIpAddress": { "aws:SourceIp": "10.0.11.0/24" } } } ] }` SetBucketPolicyDenyIPAddress = `{ "Id":"PolicyId2", "Version":"2012-10-17", "Statement":[ { "Sid":"DenyIPmix", "Effect":"Deny", "Principal":"*", "Action":"s3:GetObject", "Resource":"arn:aws:s3:::` + TEST_BUCKET + `/*", "Condition": { "IpAddress": { "aws:SourceIp": "10.0.11.0/24" } } } ] }` SetBucketPolicyDenyNotIPAddress = `{ "Id":"PolicyId2", "Version":"2012-10-17", "Statement":[ { "Sid":"DenyIPmix", "Effect":"Deny", "Principal":"*", "Action":"s3:GetObject", "Resource":"arn:aws:s3:::` + TEST_BUCKET + `/*", "Condition": { "NotIpAddress": { "aws:SourceIp": "10.0.12.0/24" } } } ] }` )
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
func AESEncrypt ¶
func AESEncryptToHexString ¶
func GenTestObjectUrl ¶
func HTTPRequestToGetObject ¶
func TransferToS3AccessControlPolicy ¶
func TransferToS3AccessControlPolicy(policy *datatype.AccessControlPolicy) (s3policy *s3.AccessControlPolicy)
Types ¶
type AccessPolicyGroup ¶
type PostObjectInput ¶
type S3Client ¶
func NewS3Internal ¶
func NewS3Internal() *S3Client
func NewS3WithoutMD5 ¶
func NewS3WithoutMD5() *S3Client
func (*S3Client) AbortMultiPartUpload ¶
func (*S3Client) AppendObject ¶
func (*S3Client) ChangeObjectStorageClass ¶
func (*S3Client) CompleteMultiPartUpload ¶
func (s3client *S3Client) CompleteMultiPartUpload(bucketName, key, uploadId string, completed *s3.CompletedMultipartUpload) (err error)
func (*S3Client) CreateMultiPartUpload ¶
func (*S3Client) DeleteBucket ¶
func (*S3Client) DeleteBucketPolicy ¶
func (*S3Client) DeleteBucketWebsite ¶
func (*S3Client) DeleteObject ¶
func (*S3Client) GetBucketAcl ¶
func (*S3Client) GetBucketPolicy ¶
func (*S3Client) GetBucketWebsite ¶
func (*S3Client) GetEncryptObjectWithSSEC ¶
func (*S3Client) GetEncryptObjectWithSSES3 ¶
func (*S3Client) GetObjectAcl ¶
func (*S3Client) GetObjectOutPut ¶
func (s3client *S3Client) GetObjectOutPut(bucketName, key string) (out *s3.GetObjectOutput, err error)
func (*S3Client) GetObjectPreSigned ¶
func (*S3Client) HeadBucket ¶
func (*S3Client) HeadObject ¶
func (*S3Client) MakeBucket ¶
func (*S3Client) PostObject ¶
func (s3Client *S3Client) PostObject(pbi *PostObjectInput) error
func (*S3Client) PutBucketAcl ¶
func (*S3Client) PutBucketAclWithXml ¶
func (s3client *S3Client) PutBucketAclWithXml(bucketName string, acl *s3.AccessControlPolicy) (err error)
func (*S3Client) PutBucketPolicy ¶
func (*S3Client) PutBucketWebsite ¶
func (*S3Client) PutBucketWebsiteWithConf ¶
func (s3client *S3Client) PutBucketWebsiteWithConf(bucketName string, conf *s3.WebsiteConfiguration) (err error)
func (*S3Client) PutEncryptObjectWithSSEC ¶
func (*S3Client) PutEncryptObjectWithSSES3 ¶
func (*S3Client) PutObjectAcl ¶
func (*S3Client) PutObjectAclWithXml ¶
func (s3client *S3Client) PutObjectAclWithXml(bucketName, objName string, acl *s3.AccessControlPolicy) (err error)
func (*S3Client) PutObjectPreSignedWithSpecifiedBody ¶
func (*S3Client) PutObjectPreSignedWithoutSpecifiedBody ¶
func (*S3Client) PutObjectWithStorageClass ¶
func (*S3Client) TestAnonymousAccessResult ¶
func (sc *S3Client) TestAnonymousAccessResult(policyGroup AccessPolicyGroup, resultCode int) (err error)
func (*S3Client) TestAnonymousAccessResultWithPolicyCondition ¶
func (sc *S3Client) TestAnonymousAccessResultWithPolicyCondition(policyGroup AccessPolicyGroup, resultCode int, requestCondition string, HTTPRequestToGetObject HTTPRequestToGetObjectType) (err error)
Click to show internal directories.
Click to hide internal directories.