|
|
|
@ -53,6 +53,12 @@ var signKeyList = []string{"acl", "uploads", "location", "cors", |
|
|
|
|
"metaQuery", "resourceGroup", "rtc", "x-oss-async-process", "responseHeader", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
timeFormatV4 = "20060102T150405Z" |
|
|
|
|
shortTimeFormatV4 = "20060102" |
|
|
|
|
signingAlgorithmV4 = "OSS4-HMAC-SHA256" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// init initializes Conn
|
|
|
|
|
func (conn *Conn) init(config *Config, urlMaker *urlMaker, client *http.Client) error { |
|
|
|
|
if client == nil { |
|
|
|
@ -338,7 +344,15 @@ func (conn Conn) doRequest(ctx context.Context, method string, uri *url.URL, can |
|
|
|
|
req.Header.Set(HttpHeaderOssContentSha256, DefaultContentSha256) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
akIf := conn.config.GetCredentials() |
|
|
|
|
var akIf Credentials |
|
|
|
|
if providerE, ok := conn.config.CredentialsProvider.(CredentialsProviderE); ok { |
|
|
|
|
if akIf, err = providerE.GetCredentialsE(); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
akIf = conn.config.GetCredentials() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if akIf.GetSecurityToken() != "" { |
|
|
|
|
req.Header.Set(HTTPHeaderOssSecurityToken, akIf.GetSecurityToken()) |
|
|
|
|
} |
|
|
|
@ -349,7 +363,7 @@ func (conn Conn) doRequest(ctx context.Context, method string, uri *url.URL, can |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
conn.signHeader(req, canonicalizedResource) |
|
|
|
|
conn.signHeader(req, canonicalizedResource, akIf) |
|
|
|
|
|
|
|
|
|
// Transfer started
|
|
|
|
|
event := newProgressEvent(TransferStartedEvent, 0, req.ContentLength, 0) |
|
|
|
@ -381,10 +395,15 @@ func (conn Conn) doRequest(ctx context.Context, method string, uri *url.URL, can |
|
|
|
|
return conn.handleResponse(resp, crc) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (conn Conn) signURL(method HTTPMethod, bucketName, objectName string, expiration int64, params map[string]interface{}, headers map[string]string) string { |
|
|
|
|
akIf := conn.config.GetCredentials() |
|
|
|
|
if akIf.GetSecurityToken() != "" { |
|
|
|
|
params[HTTPParamSecurityToken] = akIf.GetSecurityToken() |
|
|
|
|
func (conn Conn) signURL(method HTTPMethod, bucketName, objectName string, expiration int64, params map[string]interface{}, headers map[string]string) (string, error) { |
|
|
|
|
var akIf Credentials |
|
|
|
|
var err error |
|
|
|
|
if providerE, ok := conn.config.CredentialsProvider.(CredentialsProviderE); ok { |
|
|
|
|
if akIf, err = providerE.GetCredentialsE(); err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
akIf = conn.config.GetCredentials() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m := strings.ToUpper(string(method)) |
|
|
|
@ -399,38 +418,74 @@ func (conn Conn) signURL(method HTTPMethod, bucketName, objectName string, expir |
|
|
|
|
req.Header.Set("Proxy-Authorization", basic) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
req.Header.Set(HTTPHeaderDate, strconv.FormatInt(expiration, 10)) |
|
|
|
|
req.Header.Set(HTTPHeaderUserAgent, conn.config.UserAgent) |
|
|
|
|
if conn.config.AuthVersion == AuthV4 { |
|
|
|
|
if akIf.GetSecurityToken() != "" { |
|
|
|
|
params[HTTPParamOssSecurityToken] = akIf.GetSecurityToken() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if headers != nil { |
|
|
|
|
for k, v := range headers { |
|
|
|
|
req.Header.Set(k, v) |
|
|
|
|
if headers != nil { |
|
|
|
|
for k, v := range headers { |
|
|
|
|
req.Header.Set(k, v) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if conn.config.AuthVersion == AuthV2 { |
|
|
|
|
params[HTTPParamSignatureVersion] = "OSS2" |
|
|
|
|
params[HTTPParamExpiresV2] = strconv.FormatInt(expiration, 10) |
|
|
|
|
params[HTTPParamAccessKeyIDV2] = conn.config.AccessKeyID |
|
|
|
|
now := time.Now().UTC() |
|
|
|
|
expires := expiration - now.Unix() |
|
|
|
|
product := conn.config.GetSignProduct() |
|
|
|
|
region := conn.config.GetSignRegion() |
|
|
|
|
strDay := now.Format(shortTimeFormatV4) |
|
|
|
|
additionalList, _ := conn.getAdditionalHeaderKeys(req) |
|
|
|
|
|
|
|
|
|
params[HTTPParamSignatureVersion] = signingAlgorithmV4 |
|
|
|
|
params[HTTPParamCredential] = fmt.Sprintf("%s/%s/%s/%s/aliyun_v4_request", akIf.GetAccessKeyID(), strDay, region, product) |
|
|
|
|
params[HTTPParamDate] = now.Format(timeFormatV4) |
|
|
|
|
params[HTTPParamExpiresV2] = strconv.FormatInt(expires, 10) |
|
|
|
|
if len(additionalList) > 0 { |
|
|
|
|
params[HTTPParamAdditionalHeadersV2] = strings.Join(additionalList, ";") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
subResource := conn.getSubResource(params) |
|
|
|
|
canonicalizedResource := conn.getResource(bucketName, objectName, subResource) |
|
|
|
|
signedStr := conn.getSignedStr(req, canonicalizedResource, akIf.GetAccessKeySecret()) |
|
|
|
|
subResource := conn.getSubResource(params) |
|
|
|
|
canonicalizedResource := conn.getResourceV4(bucketName, objectName, subResource) |
|
|
|
|
authorizationStr := conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret(), &now) |
|
|
|
|
params[HTTPParamSignatureV2] = authorizationStr |
|
|
|
|
} else { |
|
|
|
|
if akIf.GetSecurityToken() != "" { |
|
|
|
|
params[HTTPParamSecurityToken] = akIf.GetSecurityToken() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if conn.config.AuthVersion == AuthV1 { |
|
|
|
|
params[HTTPParamExpires] = strconv.FormatInt(expiration, 10) |
|
|
|
|
params[HTTPParamAccessKeyID] = akIf.GetAccessKeyID() |
|
|
|
|
params[HTTPParamSignature] = signedStr |
|
|
|
|
} else if conn.config.AuthVersion == AuthV2 { |
|
|
|
|
params[HTTPParamSignatureV2] = signedStr |
|
|
|
|
req.Header.Set(HTTPHeaderDate, strconv.FormatInt(expiration, 10)) |
|
|
|
|
|
|
|
|
|
if headers != nil { |
|
|
|
|
for k, v := range headers { |
|
|
|
|
req.Header.Set(k, v) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if conn.config.AuthVersion == AuthV2 { |
|
|
|
|
params[HTTPParamSignatureVersion] = "OSS2" |
|
|
|
|
params[HTTPParamExpiresV2] = strconv.FormatInt(expiration, 10) |
|
|
|
|
params[HTTPParamAccessKeyIDV2] = conn.config.AccessKeyID |
|
|
|
|
additionalList, _ := conn.getAdditionalHeaderKeys(req) |
|
|
|
|
if len(additionalList) > 0 { |
|
|
|
|
params[HTTPParamAdditionalHeadersV2] = strings.Join(additionalList, ";") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
subResource := conn.getSubResource(params) |
|
|
|
|
canonicalizedResource := conn.getResource(bucketName, objectName, subResource) |
|
|
|
|
signedStr := conn.getSignedStr(req, canonicalizedResource, akIf.GetAccessKeySecret()) |
|
|
|
|
|
|
|
|
|
if conn.config.AuthVersion == AuthV1 { |
|
|
|
|
params[HTTPParamExpires] = strconv.FormatInt(expiration, 10) |
|
|
|
|
params[HTTPParamAccessKeyID] = akIf.GetAccessKeyID() |
|
|
|
|
params[HTTPParamSignature] = signedStr |
|
|
|
|
} else if conn.config.AuthVersion == AuthV2 { |
|
|
|
|
params[HTTPParamSignatureV2] = signedStr |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
urlParams := conn.getURLParams(params) |
|
|
|
|
return conn.url.getSignURL(bucketName, objectName, urlParams) |
|
|
|
|
return conn.url.getSignURL(bucketName, objectName, urlParams), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (conn Conn) signRtmpURL(bucketName, channelName, playlistName string, expiration int64) string { |
|
|
|
|