public static async Task <bool> IsAuthorizedAsync(IHttpRequestWrapper request) { bool retval = false; var requestUriParts = request.UriParts; var requestOperation = StorageOperations.GetBlobOperation(request.HttpMethod, requestUriParts, request.QueryParameters, request.Headers); if (request.HttpMethod == HttpMethod.Options.ToString()) { return(true); } switch (requestOperation) { case StorageOperationTypes.GetContainerProperties: case StorageOperationTypes.GetContainerMetadata: case StorageOperationTypes.ListBlobs: retval = await GetContainerPublicAccessAsync(requestUriParts.Container) == BlobContainerPublicAccessType.Container; break; case StorageOperationTypes.GetBlob: case StorageOperationTypes.GetBlobProperties: case StorageOperationTypes.GetBlobMetadata: case StorageOperationTypes.GetBlockList: retval = await GetContainerPublicAccessAsync(requestUriParts.Container) != BlobContainerPublicAccessType.Off; break; } return(retval); }
public async Task <HttpResponseMessage> PutBlobComp(string container, string blob, string comp) { var requestWrapper = DashHttpRequestWrapper.Create(this.Request); var operation = StorageOperations.GetBlobOperation(requestWrapper); switch (operation) { case StorageOperationTypes.SetBlobProperties: case StorageOperationTypes.SetBlobMetadata: case StorageOperationTypes.LeaseBlob: case StorageOperationTypes.SnapshotBlob: case StorageOperationTypes.PutPage: return(await BasicBlobHandler(container, blob, requestWrapper, operation)); case StorageOperationTypes.PutBlock: case StorageOperationTypes.PutBlockList: return(await PutBlobHandler(container, blob, requestWrapper, operation)); case StorageOperationTypes.AbortCopyBlob: /// Abort Copy Blob - http://msdn.microsoft.com/en-us/library/azure/jj159098.aspx return(ProcessResultResponse(await BlobHandler.AbortCopyBlobAsync( requestWrapper, container, blob, requestWrapper.QueryParameters.Value <string>("copyid")))); default: return(this.CreateResponse(HttpStatusCode.BadRequest, requestWrapper.Headers)); } }
public static void SaveOperation(StorageOperations storageOperation, int operationID, int invoiceID) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { string s1 = "OperationID, Date, Receiver, Sender, InvoiceID"; cnn.Execute("insert into StorageInformation(" + s1 + ")values(" + operationID.ToString() + "," + "\'" + storageOperation.Date + "\'" + "," + "\'" + storageOperation.Receiver + "\'" + "," + "\'" + storageOperation.Sender + "\'" + "," + invoiceID.ToString() + ")"); } }
public async Task <HttpResponseMessage> GetBlobComp(string container, string blob, string comp, string snapshot = null) { var requestWrapper = DashHttpRequestWrapper.Create(this.Request); var operation = StorageOperations.GetBlobOperation(requestWrapper); switch (operation) { case StorageOperationTypes.GetBlobMetadata: case StorageOperationTypes.GetBlockList: case StorageOperationTypes.GetPageRanges: return(await BasicBlobHandler(container, blob, requestWrapper, operation)); default: return(this.CreateResponse(HttpStatusCode.BadRequest, requestWrapper.Headers)); } }
public AzureStorageTableOperations(StorageOperations operation) { try { var connStr = System.Configuration.ConfigurationManager.AppSettings["StorageConStr"].ToString(); storageAccount = CloudStorageAccount.Parse(connStr); tableClient = storageAccount.CreateCloudTableClient(); if (operation == StorageOperations.Logging) { tableName = AppConstant.StorageTableLogs; CloudTable table = tableClient.GetTableReference(tableName); table.CreateIfNotExists(); } } catch (Exception ex) { //LogHelper.AddLog(new LogEntity(Constants.PARTITION_ERRORLOG, "SYSTEM", ApplicationModules.COMMON_STORAGEDAL, ex.Message, ex.StackTrace)); } }
public async Task <HttpResponseMessage> PutBlob(string container, string blob) { var requestWrapper = DashHttpRequestWrapper.Create(this.Request); var operation = StorageOperations.GetBlobOperation(requestWrapper); switch (operation) { case StorageOperationTypes.CopyBlob: /// Copy Blob - https://msdn.microsoft.com/en-us/library/azure/dd894037.aspx return(ProcessResultResponse(await BlobHandler.CopyBlobAsync(requestWrapper, container, blob, requestWrapper.Headers.Value <string>("x-ms-copy-source")))); case StorageOperationTypes.PutBlob: /// Put Blob - http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx return(await PutBlobHandler(container, blob, requestWrapper, operation)); default: System.Diagnostics.Debug.Assert(false); return(this.CreateResponse(HttpStatusCode.BadRequest, requestWrapper.Headers)); } }
public static async Task <bool> IsAuthorizedAsync(IHttpRequestWrapper request, RequestHeaders headers, RequestQueryParameters queryParams, bool ignoreRequestAge) { var requestUriParts = request.UriParts; var resourceType = queryParams.Value <string>(ParamResourceType, String.Empty).ToLowerInvariant(); DateTimeOffset?start = queryParams.Value(ParamStartTime, DateTimeOffset.UtcNow); DateTimeOffset?expiry = queryParams.Value(ParamExpiryTime, DateTimeOffset.MinValue); if (expiry == DateTimeOffset.MinValue) { expiry = null; } SharedAccessBlobPermissions permissions = SharedAccessBlobPolicy.PermissionsFromString(queryParams.Value(ParamPermissions, String.Empty)); // Determine validity of the structure first if (requestUriParts.IsAccountRequest) { // SAS keys are not valid for account operations return(false); } else if (requestUriParts.IsContainerRequest && resourceType != "c") { return(false); } else if (requestUriParts.IsBlobRequest && resourceType.IndexOfAny(new [] { 'c', 'b' }) == -1) { return(false); } var storedPolicyId = queryParams.Value <string>(ParamStoredPolicy); if (!String.IsNullOrWhiteSpace(storedPolicyId)) { // Validate that we're not duplicating values for both stored access policy & url var storedPolicy = await GetStoredPolicyForContainer(requestUriParts.Container, storedPolicyId); if (storedPolicy == null) { return(false); } if (storedPolicy.SharedAccessStartTime.HasValue) { start = storedPolicy.SharedAccessStartTime; } if (storedPolicy.SharedAccessExpiryTime.HasValue) { if (expiry.HasValue) { return(false); } expiry = storedPolicy.SharedAccessExpiryTime; } if (queryParams.Contains(ParamPermissions)) { return(false); } permissions = storedPolicy.Permissions; } if (!expiry.HasValue || permissions == SharedAccessBlobPermissions.None) { return(false); } else if (!ignoreRequestAge && (start.Value > DateTimeOffset.UtcNow || expiry.Value < DateTimeOffset.UtcNow)) { return(false); } // Verify the assigned permissions line up with the requested operation StorageOperationTypes requestOperation = StorageOperations.GetBlobOperation(request); switch (requestOperation) { case StorageOperationTypes.GetBlob: case StorageOperationTypes.GetBlobMetadata: case StorageOperationTypes.GetBlobProperties: case StorageOperationTypes.GetBlockList: case StorageOperationTypes.GetPageRanges: if (!permissions.IsFlagSet(SharedAccessBlobPermissions.Read)) { return(false); } break; case StorageOperationTypes.AbortCopyBlob: case StorageOperationTypes.CopyBlob: case StorageOperationTypes.LeaseBlob: case StorageOperationTypes.PutBlob: case StorageOperationTypes.PutBlock: case StorageOperationTypes.PutBlockList: case StorageOperationTypes.PutPage: case StorageOperationTypes.SetBlobMetadata: case StorageOperationTypes.SetBlobProperties: case StorageOperationTypes.SnapshotBlob: if (!permissions.IsFlagSet(SharedAccessBlobPermissions.Write)) { return(false); } break; case StorageOperationTypes.DeleteBlob: if (!permissions.IsFlagSet(SharedAccessBlobPermissions.Delete)) { return(false); } break; case StorageOperationTypes.ListBlobs: if (!permissions.IsFlagSet(SharedAccessBlobPermissions.List)) { return(false); } break; default: // All other operations are not supported by SAS uris return(false); } DateTimeOffset sasVersion = queryParams.Value(ParamVersion, StorageServiceVersions.Version_2009_09_19); Func <string> stringToSignFactory = null; Func <string> baseStringToSign = () => String.Format("{0}\n{1}\n{2}\n{3}\n{4}", queryParams.Value <string>(ParamPermissions), queryParams.Value <string>(ParamStartTime), queryParams.Value <string>(ParamExpiryTime), GetCanonicalizedResource(requestUriParts, resourceType), queryParams.Value <string>(ParamStoredPolicy)); Func <string> v2012_02_12StringToSign = () => String.Format("{0}\n{1}", baseStringToSign(), queryParams.Value <string>(ParamVersion)); if (sasVersion < StorageServiceVersions.Version_2012_02_12) { stringToSignFactory = baseStringToSign; } else if (sasVersion == StorageServiceVersions.Version_2012_02_12) { stringToSignFactory = v2012_02_12StringToSign; } else { stringToSignFactory = () => String.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}", v2012_02_12StringToSign(), queryParams.Value <string>(ParamCacheControl), queryParams.Value <string>(ParamContentDisposition), queryParams.Value <string>(ParamContentEncoding), queryParams.Value <string>(ParamContentLang), queryParams.Value <string>(ParamContentType)); } string signature = queryParams.Value <string>(ParamSignature); var usingPrimaryKey = new[] { true, false }; int matchIndex = Array.FindIndex(usingPrimaryKey, usePrimaryKey => VerifySignature(signature, usePrimaryKey, stringToSignFactory)); if (matchIndex != -1) { // We can't sign the redirection response when the request uses a SAS key - preserve the matching key, however request.AuthenticationScheme = String.Empty; request.AuthenticationKey = usingPrimaryKey[matchIndex] ? SharedKeySignature.PrimaryAccountKey : SharedKeySignature.SecondaryAccountKey; return(true); } return(false); }
StorageOperationTypes GetStorageOperation(string method, string uri, IEnumerable <Tuple <string, string> > headers = null) { return(StorageOperations.GetBlobOperation(new MockHttpRequestWrapper(method, uri, headers))); }