Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SharedKeyCredential #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
Expand Down Expand Up @@ -119,25 +118,34 @@ private String buildStringToSign(URL requestURL, String httpMethod, Map<String,
contentLength = contentLength.equals("0") ? "" : contentLength;

// If the x-ms-header exists ignore the Date header
String dateHeader = (headers.containsKey("x-ms-date")) ? "" : headers.getOrDefault("Date", "");
String dateHeader = (headers.containsKey("x-ms-date")) ? "" : getStandardHeaderValue(headers,"Date");

return String.join("\n",
httpMethod,
headers.getOrDefault("Content-Encoding", ""),
headers.getOrDefault("Content-Language", ""),
getStandardHeaderValue(headers,"Content-Encoding"),
getStandardHeaderValue(headers,"Content-Language"),
contentLength,
headers.getOrDefault("Content-MD5", ""),
headers.getOrDefault("Content-Type", ""),
getStandardHeaderValue(headers,"Content-MD5"),
getStandardHeaderValue(headers,"Content-Type"),
dateHeader,
headers.getOrDefault("If-Modified-Since", ""),
headers.getOrDefault("If-Match", ""),
headers.getOrDefault("If-None-Match", ""),
headers.getOrDefault("If-Unmodified-Since", ""),
headers.getOrDefault("Range", ""),
getStandardHeaderValue(headers,"If-Modified-Since"),
getStandardHeaderValue(headers,"If-Match"),
getStandardHeaderValue(headers, "If-None-Match"),
getStandardHeaderValue(headers,"If-Unmodified-Since"),
getStandardHeaderValue(headers, "Range"),
getAdditionalXmsHeaders(headers),
getCanonicalizedResource(requestURL));
}

/*
* Returns an empty string if the header value is null or empty.
*/
private String getStandardHeaderValue(Map<String, String> headers, String headerName) {
final String headerValue = headers.get(headerName);

return headerValue == null ? "" : headerValue;
}

private String getAdditionalXmsHeaders(Map<String, String> headers) {
// Add only headers that begin with 'x-ms-'
final List<String> xmsHeaderNameArray = headers.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import com.azure.storage.blob.models.AccessTier
import com.azure.storage.blob.models.ArchiveStatus
import com.azure.storage.blob.models.BlobHTTPHeaders
import com.azure.storage.blob.models.BlobItem
import com.azure.storage.blob.models.BlobType
import com.azure.storage.blob.models.CopyStatusType
import com.azure.storage.blob.models.LeaseAccessConditions
import com.azure.storage.blob.models.LeaseDurationType
import com.azure.storage.blob.models.LeaseStateType
import com.azure.storage.blob.models.LeaseStatusType
import com.azure.storage.blob.models.ModifiedAccessConditions
import com.azure.storage.blob.models.PublicAccessType
import com.azure.storage.blob.models.SyncCopyStatusType
Expand Down