高度安全性的应用程式系统实作.ppt

上传人:本田雅阁 文档编号:3163642 上传时间:2019-07-18 格式:PPT 页数:60 大小:2.41MB
返回 下载 相关 举报
高度安全性的应用程式系统实作.ppt_第1页
第1页 / 共60页
高度安全性的应用程式系统实作.ppt_第2页
第2页 / 共60页
高度安全性的应用程式系统实作.ppt_第3页
第3页 / 共60页
高度安全性的应用程式系统实作.ppt_第4页
第4页 / 共60页
高度安全性的应用程式系统实作.ppt_第5页
第5页 / 共60页
点击查看更多>>
资源描述

《高度安全性的应用程式系统实作.ppt》由会员分享,可在线阅读,更多相关《高度安全性的应用程式系统实作.ppt(60页珍藏版)》请在三一文库上搜索。

1、高度安全性的應用程式系統實作,台灣微軟公司 研發處開發工具部 產品規劃經理 何銘哲,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentication) .NET 的程式碼存取安全性 ASP.NET 中的驗證考量 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,範例實作架構簡介,範例實作架構 那裡要驗證?,Intranet,Internet,Web Form,Authentication,Smart Client,APP Serve

2、r,SQL Server,Web Server,ASP.NET Code Access Security,範例實作架構 何時需要授權?,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentication) .NET 的程式碼存取安全性 ASP.NET 中的驗證考量 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,範例實作架構 程式碼存取安全性,什麼是程式碼存取安全性,控制程式碼要對保護資源存取或是執行特定作業的安全機制 由 CLR

3、的安全性系統查核來檢查呼叫堆疊中每個呼叫端授與的使用權限和要求的使用權限 (Stack Walk) 禁止低度受信任的程式碼呼叫高度受信任的程式碼進而使用它來執行未經授權的動作 可使用 Demand 及 Assert 來實作程式碼存取安全性語法,什麼是舉證 (Evidence)?,舉證 (Evidence) 是由應用程式組件的識別項及其出處資訊組成 .NET Framework 安全系統會根據舉證項目來設定其權限,什麼是安全性原則 (Policy)?,安全性原則控制程式碼存取資源的使用權限 (permission) 依據程式碼的 identity 及來源來決定可存取的項目有那些 (Evidenc

4、e based!) 程式碼的 identity 及來源由舉證項目所組成 安全性原則將各類型的舉證對應到不同的使用權限集合 (permission set) Nothing Execution Internet LocalIntranet Everything FullTrust Custom-defined,什麼是程式碼群組?,Cond: All Code PSet: Nothing,Cond: Site = A PSet: All Printer Access,Cond: Publisher=Microsoft PSet: Read:C:Microsoft,Cond: Zone=Intern

5、et PSet: Internet,Cond: Zone=MyComputer PSet: Execution,Cond: SN Key=25 98 PSet: Read:C:Adatum,Cond: SN Key = 9F AD Simple Name = Microsoft Money PSet: Read:C:Money,Cond: SN Key = 9F AD Simple Name = Microsoft.App PSet: Write:C:Microsoft,A hierarchy of code groups,Permission Grant,Evidence,Publisher

6、 = Microsoft Zone= Internet SNKey = 9F AD,Read C:Microsoft Read C:Money Write: C:Microsoft Internet,Publisher = Adatum Site = A SN Key=25 98,Execution Read:C:Adatum All Printer Access,什麼是安全性原則等級?,安全性原則可被使用在不同的層級上 來控制存取資料的權限: 企業 (Enterprise) 電腦 (Machine) 使用者 (User) Application domain 每一個原則層級中都含有一些程式碼

7、群組、使用權限集合,以及原則組件清,當超過一個安全性原則生效時: Permission grant is the intersection of permissions allowed at each policy level The least common permission set is applied Example:,判斷多個安全性原則等級,1. 使用 .NET Framework 組態工具修改安全性原則設定,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentication) .NET 的程式碼存取安全性 ASP.NET 中的驗證考量

8、 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,範例實作架構 ASP.NET 的驗證,Windows 驗證,Client Computer,/ web.config file ,Forms 驗證,/ web.config file ,Anonymous,Passport 驗證,/ web.config file ,Anonymous,P,如何使用 Forms-Based 驗證,Configure IIS to use Anonymous access Set forms-ba

9、sed authentication in Web.config Set up authorization Create a logon page,1,2,3,4,設定 web.config,/ Web.config file ,如何建立 Logon 網頁,Import the System.Web.Security namespace Create a logon page that verifies and checks the credentials of a user and redirects if valid Read user credentials from a cookie

10、User.Identity.Name returns the value saved by FormsAuthentication.RedirectFromLoginPage,If (bValidCredentials) FormsAuthentication.RedirectFromLoginPage _ (strUserName, False) End If,2. 在 ASP.NET 中使用 Windows based 以及 Forms based 驗證,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentication) .NET 的程式碼存

11、取安全性 ASP.NET 中的驗證考量 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,Intranet,Internet,Web Form,SQL Server,APP Server,Web Server,Smart Client,Windows Integrated Role-based security Authorization Manager,Authorization,範例實作架構 授權 -角色架構安全性,什麼是角色架構(Role-Based)安全性?,什麼是 Id

12、entity?,Identity 物件封裝有關使用者或驗證過的實體的資訊 Identity 在 .NET Framework 中可分為三大類: Windows Generic Custom Identity 類別均實作了 IIdentity interface Name (使用者名稱或 Windows 帳戶名稱) IsAuthenticated AuthenticationType (所支援的登入通訊協定),什麼是 Principal?,Principal 則是結合了 identity 及此 Identity 的角色 (Role) 所執行的安全性內容. .NET角色架構安全性支援了三種類型的p

13、rincipals : Windows principal Generic principal Custom principal All principal類別均實作了 IPrincipal interface,如何使用 WindowsIdentity 及 WindowsPrincipal 物件,/ Single validation WindowsIdentity myIdentity = WindowsIdentity.GetCurrent(); WindowsPrincipal myPrincipal = new WindowsPrincipal(myIdentity); / Repea

14、ted validation / 呼叫 AppDomain.SetPrincipalPolicy 方法 / 並將新的 PrincipalPolicy 列舉型別值傳遞給它 AppDomain.CurrentDomain.SetPrincipalPolicy( PrincipalPolicy.WindowsPrincipal); /使用 CurrentPrincipal 擷取目前 Windows 的當事人 WindowsPrincipal myPrincipal = (WindowsPrincipal) System.Threading.Thread.CurrentPrincipal;,如何使用

15、GenericIdentity及GenericPrincipal 物件,可用 GenericIdentity 及 GenericPrincipal 來建立獨立存在於 Windows之外的授權配置:,/ Create a generic identity GenericIdentity myIdentity = new GenericIdentity(“User1“); / Create a generic principal String myStringArray = “Manager“, “Teller“; GenericPrincipal myPrincipal = new Generi

16、cPrincipal(myIdentity, myStringArray); / Attach the generic principal to the thread System.Threading.Thread.CurrentPrincipal = myPrincipal;,檢查 Identity 以及群組的授權,/ Check identity / Assume a valid Principal is in myPrincipal if (String.Compare(myPrincipal.Identity.Name, “DOMAINFred“, true)=0) / Permit

17、access to some code / Check role membership / Assume a valid Principal is in myPrincipal if (myPrincipal.IsInRole(“BUILTINAdministrators“) / Permit access to some code ,3. 使用 Windows 及 Generic 物件來檢查 Role-Based 的授權,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentication) .NET 的程式碼存取安全性 ASP.NET 中的驗證考

18、量 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,範例實作架構 授權 -授權管理員,授權管理員的概念,操作 (Operation) Low-level application work-unit expressed in code Procedure, function, method, LDAP or SQL query 工作 (Task) High-level application work-unit expressed in the UI Submit report,

19、 Approve report, Delete report 角色 (Role) Set of Tasks that correspond to a persons job description Defines the generic permissions needed to do that job 商業規則 (Biz Rule) Script to adjust Role-based permissions at runtime 領域 (Scope) Set of resources where Role permissoins apply 應用程式群組 (Application gro

20、up) Application manages membership; Static or LDAP query,授權管理員,AuthorizationStore,Application,Scope (Roles, Tasks, Groups),ClientContext,ApplicationGroup,AccessCheck,Static, Query,Operation,Task,Role,ApplicationGroup,BizRule,AD,XML,Web Expense Application,Role=Tasks, Task=Operations,Database Operati

21、on,Web Operation,Directory Operation,Payment System Operation,角色定義, 指派及領域,Submitter,Administrator,Approver: QueryGroup_D1Mgrs Administrator: Jane, Lizzy,Approver: ADGroup_D2Mgrs Administrator: Jane, Charlie,Submitter: Everyone,Scope: Dept 01,Scope: Dept 02,Role Definitions,Approver,Dept 01 Role Assi

22、gnments:,Dept 02 Role Assignments:,Web Expense Role Assignments:,Scope: App,Web Expense Application,開發模式 Trusted Subsystem,Authorization Policy Store,Action performed in server context on behalf of client Audits generated at front and back end,Client Request,Server verifies access against authorizat

23、ion policy in separate store,Response,AzMan APP,4. 如何使用 Authorization Manager 進行角色架構的授權檢查,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentication) .NET 的程式碼存取安全性 ASP.NET 中的驗證考量 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,範例實作架構 何時需要加密?,什麼是加密?,可使用加密的目的 機密性 - 避免

24、使用者的識別 (Identity) 或資料被讀取 資料完整性 - 避免資料被變更 驗證 - 確保資料是來自特定的一方 加密編譯的方式有 私密金鑰加密 (對稱加密 Symmetric Cryptography) 公開金鑰 (Public key) 加密 (非對稱加密Asymmetric Cryptography) 數位簽章 密碼編譯雜湊 System.Security.Cryptography 命名空間,什麼是私密金鑰加密 (對稱加密)?,用來安全的傳送資料 仰賴私密金鑰secret key來逹到安全性 如何安全的交換私密金鑰?,什麼是公開金鑰加密 (非對稱加密)?,用來安全的傳送資料 仰賴一對

25、相關的金鑰加密: 公開金鑰 (public key) 及私密金鑰 (private key),使用 SHA1 來編譯雜湊,Private Sub HashText(ByVal TextToHash As String) / Create New Crypto Service Provider Object SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); / Convert the original string to array of Bytes byte bytValue = System.Text.Enco

26、ding.UTF8.GetBytes(Value); / Compute the Hash, returns an array of Bytes byte bytHash = mhash.ComputeHash(bytValue); / Note: It is always a good idea to clear the hash variable / once you are done with it. mhash.Clear(); / Return a base 64 encoded string of the Hash value Debug.WriteLine(Convert.ToB

27、ase64String(bytHash); End Sub,加入 Salt 到雜湊中,The problem : Hash algorithms will hash the same data to exactly the same value The solution : Add a unique value to each data before hashing it. It is called a “salt“ value. How to generate Salt : Create a random string of digits using the .NET Fw class RN

28、GCryptoServiceProvider. RNG stands for Random Number Generator.,使用 RNG 來產生 salt,Creates an array of bytes that is 8 bytes long. It use GetBytes() of RNGCryptoServiceProvider class to fill in the array of bytes with the generated random set of characters.,private string CreateSalt() byte bytSalt = ne

29、w byte8; RNGCryptoServiceProvider rng; rng = new RNGCryptoServiceProvider(); rng.GetBytes(bytSalt); return Convert.ToBase64String(bytSalt); ,該用那種加密方法?,Symmetric, or secret key, algorithms Extremely fast, but potential to be broken Well suited for encrypting large streams of data Asymmetric, or publi

30、c key, algorithms not that fas, but are much harder to break. Not suited to large amounts of data (performance). Hash Used when you do not wish to ever recover the original value One-way operatio. Use for small amounts of data, like a password,如何產生金鑰和初始化向量,.NET Framework 所提供的對稱加密類別需要金鑰和新的初始化向量 (Init

31、ialization Vector-IV) 來加密和解密資料 對稱密碼編譯類別建構函式會自動建立新的金鑰和 IV 或是呼叫 GenerateKey() 及 GenerateIV() 來建立新的金鑰和 IV,private SymmetricAlgorithm mCSP = new DESCryptoServiceProvider(); / Generate Key and IV mCSP.GenerateKey(); mCSP.GenerateIV(); / Convert to string for display string strKey = Convert.ToBase64String

32、(mCSP.Key); string strIV = Convert.ToBase64String(mCSP.IV);,File Format,如何將資料加密?,private string EncryptString(string Value) ICryptoTransform ct; / To call the CreateEncryptor for all algorithms byte byt; /CreateEncryptor will return encryptor object. ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV); /co

33、nvert string into an bytes array for cryptographic algorithms byt = Encoding.UTF8.GetBytes(Value); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); /write the encrypted data into the memory stream /ensure all the

34、data has been written into the MemoryStream object cs.FlushFinalBlock(); cs.Close(); return Convert.ToBase64String(ms.ToArray(); ,如何將資料解密?,private string DecryptString(string Value) ICryptoTransform ct; byte byt; ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV); byt = Convert.FromBase64String(Value); Me

35、moryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); / Decrypt data cs.FlushFinalBlock(); cs.Close(); return Encoding.UTF8.GetString(ms.ToArray(); ,5. 使用 Cryptography,今日議程,範例實作架構簡介 .NET Framework 安全機制範例實作 驗證 (Authentica

36、tion) .NET 的程式碼存取安全性 ASP.NET 中的驗證考量 授權 (Authorization ) 角色架構安全性 授權管理員 加密 (Cryptography) Web 應用程式安全機制範例實作 Web應用程式的安全性考量,什麼是 Open Hack?,In 2002, eWeek sponsored its fourth OpenHack challenge. The OpenHack team built an ASP.NET Web application using Microsoft Windows 2000 Advanced Server, Internet Info

37、rmation Services (IIS) 5.0, Microsoft SQL Server 2000, and the .NET Framework. It successfully withstood more than 82,500 attempted attacks.,6. Open Hack 範例,Do More With Less, 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1