Skip to content

Commit

Permalink
Merge pull request #42 from CloudBreadPaPa/master
Browse files Browse the repository at this point in the history
Adding encryption feature to CloudBread v2
  • Loading branch information
CloudBreadPaPa committed Mar 25, 2016
2 parents 392f99e + 1064505 commit d5ba085
Show file tree
Hide file tree
Showing 78 changed files with 3,250 additions and 1,769 deletions.
37 changes: 36 additions & 1 deletion CBLoggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@ public static bool RunLog(CBLoggers message)
message.memberID = ""; /// in case of non-member triggered job
}

/// critical error case, save in ATS CloudBreadErrorLog
if (message.Level.ToUpper() == "ERROR")
{
try
{
/// Save error log on Azure Table Storage
{
/// Azure Table Storage connection retry policy
var tableStorageRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10);
CloudStorageAccount storageAccountT = CloudStorageAccount.Parse(globalVal.StorageConnectionString);
CloudTableClient tableClient = storageAccountT.CreateCloudTableClient();
tableClient.DefaultRequestOptions.RetryPolicy = tableStorageRetryPolicy;
CloudTable table = tableClient.GetTableReference("CloudBreadErrorLog");
CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString());
Message.jobID = message.jobID;
Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
Message.Thread = message.Thread;
Message.Level = message.Level;
Message.Logger = message.Logger;
Message.Message = message.Message;
Message.Exception = message.Exception;
TableOperation insertOperation = TableOperation.Insert(Message);
table.Execute(insertOperation);
}
}
catch (Exception)
{
/// Catch fail to log on database. Most case database connection or login fail issue.
throw;
}
}
}
else
{
/// Regarding to web.config logger settting, save logs on specific storage
try
{
switch (globalVal.CloudBreadLoggerSetting)
Expand Down Expand Up @@ -116,7 +151,7 @@ public static bool RunLog(CBLoggers message)
CloudTableClient tableClient = storageAccountT.CreateCloudTableClient();
tableClient.DefaultRequestOptions.RetryPolicy = tableStorageRetryPolicy;
CloudTable table = tableClient.GetTableReference("CloudBreadLog");
CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString()); //memberid를 파티션키로 쓴다.
CBATSMessageEntity Message = new CBATSMessageEntity(message.memberID, Guid.NewGuid().ToString());
Message.jobID = message.jobID;
Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
//Message.Date = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
Expand Down
36 changes: 36 additions & 0 deletions CloudBread.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,43 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\AddMemberItemPurchase.cs" />
<Compile Include="Models\AddUseMemberItem.cs" />
<Compile Include="Models\ComInsMemberItemPurchase.cs" />
<Compile Include="Models\ComSelCoupon.cs" />
<Compile Include="Models\ComSelGiftDepository.cs" />
<Compile Include="Models\ComSelItemList1.cs" />
<Compile Include="Models\ComSelMember.cs" />
<Compile Include="Models\ComSelMemberGameInfoes.cs" />
<Compile Include="Models\ComSelMemberGameInfoStages.cs" />
<Compile Include="Models\ComSelMemberItem.cs" />
<Compile Include="Models\ComSelMemberItemPurchase.cs" />
<Compile Include="Models\ComUdtGiftDepository.cs" />
<Compile Include="Models\COMUdtMember.cs" />
<Compile Include="Models\ComUdtMemberGameInfoes.cs" />
<Compile Include="Models\ComUdtMemberGameInfoStages.cs" />
<Compile Include="Models\ComUdtMemberItem.cs" />
<Compile Include="Models\ComUdtMemberItemPurchase.cs" />
<Compile Include="Models\EncryptedData.cs" />
<Compile Include="Models\InsRegMember.cs" />
<Compile Include="Models\MobileServiceContext.cs" />
<Compile Include="Models\RowcountResult.cs" />
<Compile Include="Models\SelGameEvents.cs" />
<Compile Include="Models\SelGiftItemToMe.cs" />
<Compile Include="Models\SelItem1.cs" />
<Compile Include="Models\SelItemListAll.cs" />
<Compile Include="Models\SelLoginIDDupeCheck.cs" />
<Compile Include="Models\SelLoginInfo.cs" />
<Compile Include="Models\SelMemberGameInfoStages.cs" />
<Compile Include="Models\SelMemberItems.cs" />
<Compile Include="Models\SelNotices.cs" />
<Compile Include="Models\SelSendEmailToMember.cs" />
<Compile Include="Models\UdtCouponMember.cs" />
<Compile Include="Models\UdtGameEventMemberToItem.cs" />
<Compile Include="Models\UdtMemberGameInfoStage.cs" />
<Compile Include="Models\UdtMoveGift.cs" />
<Compile Include="Models\UdtReturnItem.cs" />
<Compile Include="Models\UdtSendGift.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Startup.cs" />
</ItemGroup>
Expand Down
121 changes: 39 additions & 82 deletions Controllers/CBAddMemberItemPurchaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,102 +33,42 @@
using System.Security.Claims;
using Microsoft.Practices.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using CloudBread.Models;

namespace CloudBread.Controllers
{
[MobileAppController]
public class CBAddMemberItemPurchaseController : ApiController
{

public class InputParams
public HttpResponseMessage Post(AddMemberItemPurchaseInputParams p)
{
public string InsertORUpdate { get; set; }
public string MemberItemID_MemberItems { get; set; }
public string MemberID_MemberItems { get; set; }
public string ItemListID_MemberItems { get; set; }
public string ItemCount_MemberItems { get; set; }
public string ItemStatus_MemberItems { get; set; }
public string sCol1_MemberItems { get; set; }
public string sCol2_MemberItems { get; set; }
public string sCol3_MemberItems { get; set; }
public string sCol4_MemberItems { get; set; }
public string sCol5_MemberItems { get; set; }
public string sCol6_MemberItems { get; set; }
public string sCol7_MemberItems { get; set; }
public string sCol8_MemberItems { get; set; }
public string sCol9_MemberItems { get; set; }
public string sCol10_MemberItems { get; set; }
public string MemberID_MemberItemPurchases { get; set; }
public string ItemListID_MemberItemPurchases { get; set; }
public string PurchaseQuantity_MemberItemPurchases { get; set; }
public string PurchasePrice_MemberItemPurchases { get; set; }
public string PGinfo1_MemberItemPurchases { get; set; }
public string PGinfo2_MemberItemPurchases { get; set; }
public string PGinfo3_MemberItemPurchases { get; set; }
public string PGinfo4_MemberItemPurchases { get; set; }
public string PGinfo5_MemberItemPurchases { get; set; }
public string PurchaseDeviceID_MemberItemPurchases { get; set; }
public string PurchaseDeviceIPAddress_MemberItemPurchases { get; set; }
public string PurchaseDeviceMACAddress_MemberItemPurchases { get; set; }
public string PurchaseDT_MemberItemPurchases { get; set; }
public string PurchaseCancelYN_MemberItemPurchases { get; set; }
public string PurchaseCancelDT_MemberItemPurchases { get; set; }
public string PurchaseCancelingStatus_MemberItemPurchases { get; set; }
public string PurchaseCancelReturnedAmount_MemberItemPurchases { get; set; }
public string PurchaseCancelDeviceID_MemberItemPurchases { get; set; }
public string PurchaseCancelDeviceIPAddress_MemberItemPurchases { get; set; }
public string PurchaseCancelDeviceMACAddress_MemberItemPurchases { get; set; }
public string sCol1_MemberItemPurchases { get; set; }
public string sCol2_MemberItemPurchases { get; set; }
public string sCol3_MemberItemPurchases { get; set; }
public string sCol4_MemberItemPurchases { get; set; }
public string sCol5_MemberItemPurchases { get; set; }
public string sCol6_MemberItemPurchases { get; set; }
public string sCol7_MemberItemPurchases { get; set; }
public string sCol8_MemberItemPurchases { get; set; }
public string sCol9_MemberItemPurchases { get; set; }
public string sCol10_MemberItemPurchases { get; set; }
public string MemberID_MemberGameInfoes { get; set; }
public string Level_MemberGameInfoes { get; set; }
public string Exps_MemberGameInfoes { get; set; }
public string Points_MemberGameInfoes { get; set; }
public string UserSTAT1_MemberGameInfoes { get; set; }
public string UserSTAT2_MemberGameInfoes { get; set; }
public string UserSTAT3_MemberGameInfoes { get; set; }
public string UserSTAT4_MemberGameInfoes { get; set; }
public string UserSTAT5_MemberGameInfoes { get; set; }
public string UserSTAT6_MemberGameInfoes { get; set; }
public string UserSTAT7_MemberGameInfoes { get; set; }
public string UserSTAT8_MemberGameInfoes { get; set; }
public string UserSTAT9_MemberGameInfoes { get; set; }
public string UserSTAT10_MemberGameInfoes { get; set; }
public string sCol1_MemberGameInfoes { get; set; }
public string sCol2_MemberGameInfoes { get; set; }
public string sCol3_MemberGameInfoes { get; set; }
public string sCol4_MemberGameInfoes { get; set; }
public string sCol5_MemberGameInfoes { get; set; }
public string sCol6_MemberGameInfoes { get; set; }
public string sCol7_MemberGameInfoes { get; set; }
public string sCol8_MemberGameInfoes { get; set; }
public string sCol9_MemberGameInfoes { get; set; }
public string sCol10_MemberGameInfoes { get; set; }


}
// try decrypt data
if (!string.IsNullOrEmpty(p.token) && globalVal.CloudBreadCryptSetting == "AES256")
{
try
{
string decrypted = Crypto.AES_decrypt(p.token, globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
p = JsonConvert.DeserializeObject<AddMemberItemPurchaseInputParams>(decrypted);

public string Post(InputParams p)
{
string result = "";
}
catch (Exception ex)
{
ex = (Exception)Activator.CreateInstance(ex.GetType(), "Decrypt Error", ex);
throw ex;
}
}

// Get the sid or memberID of the current user.
var claimsPrincipal = this.User as ClaimsPrincipal;
string sid = CBAuth.getMemberID(p.MemberID_MemberGameInfoes, claimsPrincipal);
string sid = CBAuth.getMemberID(p.MemberID_MemberGameInfoes, this.User as ClaimsPrincipal);
p.MemberID_MemberGameInfoes = sid;
p.MemberID_MemberItemPurchases = sid;
p.MemberID_MemberItems = sid;

Logging.CBLoggers logMessage = new Logging.CBLoggers();
string jsonParam = JsonConvert.SerializeObject(p);
RowcountResult rowCountResult = new RowcountResult();
HttpResponseMessage response = new HttpResponseMessage();
EncryptedData encryptedResult = new EncryptedData();

try
{
Expand Down Expand Up @@ -223,7 +163,7 @@ public string Post(InputParams p)
{
while (dreader.Read())
{
result = dreader[0].ToString();
rowCountResult.result = dreader[0].ToString();
}
dreader.Close();
}
Expand All @@ -236,7 +176,24 @@ public string Post(InputParams p)
logMessage.Message = jsonParam;
Logging.RunLog(logMessage);

return result;
/// Encrypt the result response
if (globalVal.CloudBreadCryptSetting == "AES256")
{
try
{
encryptedResult.token = Crypto.AES_encrypt(JsonConvert.SerializeObject(rowCountResult), globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
response = Request.CreateResponse(HttpStatusCode.OK, encryptedResult);
return response;
}
catch (Exception ex)
{
ex = (Exception)Activator.CreateInstance(ex.GetType(), "Encrypt Error", ex);
throw ex;
}
}

response = Request.CreateResponse(HttpStatusCode.OK, rowCountResult);
return response;
}

}
Expand Down
94 changes: 40 additions & 54 deletions Controllers/CBAddUseMemberItemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,71 +33,42 @@
using System.Security.Claims;
using Microsoft.Practices.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using CloudBread.Models;

namespace CloudBread.Controllers
{
[MobileAppController]
public class CBAddUseMemberItemController : ApiController
{

public class InputParams
{
public string InsertORUpdateORDelete;
public string MemberItemID_MemberItem;
public string MemberID_MemberItem;
public string ItemListID_MemberItem;
public string ItemCount_MemberItem;
public string ItemStatus_MemberItem;
public string sCol1_MemberItem;
public string sCol2_MemberItem;
public string sCol3_MemberItem;
public string sCol4_MemberItem;
public string sCol5_MemberItem;
public string sCol6_MemberItem;
public string sCol7_MemberItem;
public string sCol8_MemberItem;
public string sCol9_MemberItem;
public string sCol10_MemberItem;
public string MemberID_MemberGameInfoes;
public string Level_MemberGameInfoes;
public string Exps_MemberGameInfoes;
public string Points_MemberGameInfoes;
public string UserSTAT1_MemberGameInfoes;
public string UserSTAT2_MemberGameInfoes;
public string UserSTAT3_MemberGameInfoes;
public string UserSTAT4_MemberGameInfoes;
public string UserSTAT5_MemberGameInfoes;
public string UserSTAT6_MemberGameInfoes;
public string UserSTAT7_MemberGameInfoes;
public string UserSTAT8_MemberGameInfoes;
public string UserSTAT9_MemberGameInfoes;
public string UserSTAT10_MemberGameInfoes;
public string sCol1_MemberGameInfoes;
public string sCol2_MemberGameInfoes;
public string sCol3_MemberGameInfoes;
public string sCol4_MemberGameInfoes;
public string sCol5_MemberGameInfoes;
public string sCol6_MemberGameInfoes;
public string sCol7_MemberGameInfoes;
public string sCol8_MemberGameInfoes;
public string sCol9_MemberGameInfoes;
public string sCol10_MemberGameInfoes;
}

public string Post(InputParams p)
public HttpResponseMessage Post(AddUseMemberItemInputParams p)
{

string result = "";
// try decrypt data
if (!string.IsNullOrEmpty(p.token) && globalVal.CloudBreadCryptSetting == "AES256")
{
try
{
string decrypted = Crypto.AES_decrypt(p.token, globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
p = JsonConvert.DeserializeObject<AddUseMemberItemInputParams>(decrypted);
}
catch (Exception ex)
{
ex = (Exception)Activator.CreateInstance(ex.GetType(), "Decrypt Error", ex);
throw ex;
}
}

// Get the sid or memberID of the current user.
var claimsPrincipal = this.User as ClaimsPrincipal;
string sid = CBAuth.getMemberID(p.MemberID_MemberGameInfoes, claimsPrincipal);
string sid = CBAuth.getMemberID(p.MemberID_MemberGameInfoes, this.User as ClaimsPrincipal);
p.MemberID_MemberGameInfoes = sid;
p.MemberID_MemberItem = sid;

Logging.CBLoggers logMessage = new Logging.CBLoggers();
string jsonParam = JsonConvert.SerializeObject(p);

HttpResponseMessage response = new HttpResponseMessage();
EncryptedData encryptedResult = new EncryptedData();
RowcountResult rowcountResult = new RowcountResult();

try
{
// start task log
Expand Down Expand Up @@ -160,7 +131,7 @@ public string Post(InputParams p)
{
while (dreader.Read())
{
result = dreader[0].ToString();
rowcountResult.result = dreader[0].ToString();
}
dreader.Close();
}
Expand All @@ -173,9 +144,25 @@ public string Post(InputParams p)
logMessage.Message = jsonParam;
Logging.RunLog(logMessage);

return result;
}
/// Encrypt the result response
if (globalVal.CloudBreadCryptSetting == "AES256")
{
try
{
encryptedResult.token = Crypto.AES_encrypt(JsonConvert.SerializeObject(rowcountResult), globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
response = Request.CreateResponse(HttpStatusCode.OK, encryptedResult);
return response;
}
catch (Exception ex)
{
ex = (Exception)Activator.CreateInstance(ex.GetType(), "Encrypt Error", ex);
throw ex;
}
}

response = Request.CreateResponse(HttpStatusCode.OK, rowcountResult);
return response;
}
}
}

Expand All @@ -192,6 +179,5 @@ public string Post(InputParams p)
throw;
}
}

}
}
Loading

0 comments on commit d5ba085

Please sign in to comment.