Configure authentication

  • Authenticating users

    • IIS authentication

      • Anonymous
      • ASP.net impersonation
      • Basic

        transmit username/password between client/server in Base64 encoded but not encrypted.
      • Digest

        username/password are encrypted
      • Forms

        1: without using built-in windows security system

        2: use FormsAuthentication.SetAuthCookie to make authentication token available for the rest of the session.
      • Windows

        supported only in microsoft browser

        use NTLM/Kerberos

        straightforward and easy to implement, especially on intranet.
      • ASP.net impersonation authentication

        independent of authentication mode configured in Web.config file
    • System.Security.Principal.IPrincipal / System.Security.Principal.IIdentity

    • WindowsIdentity/WindowsPrincipal
    • FormsIdentity/GenericPrincipal
    • GenericIdentity/GenericPrinciapl

    use AuthorizeAttribute to enforce authentication

    • Form authentication + SimpleMembership + WebSecurity

      Windows authentication

      • use Active directory to manage users
      • all users are members of your domain
      • require users to use IE or Microsoft browser

        Form authentication
      • use standard ASP.net membership provider db schema or your own

        Custom authentication
      • create a custom provider by implementing IIdentity or IPrincipal to interact with underlying authentication mechanism
  • Manage user session by cookies

FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
userName,
DateTime.Now,
DateTime.Now.AddDays(90),
createPersistentCookie, // a Boolean indicating whether a cookie
// should be created on the user's machine
String.Join(";",rolesArr) //user's roles
);
// add cookie to response stream
string encTicket = FormsAuthentication.Encrypt(authTicket);
System.Web.HttpCookie authCookie = new System.Web.HttpCookie(FormsAuthentication.
FormsCookieName, encTicket);
System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
  • Configuring membership providers

    • use SimpleMembershipProvider/WebSecurity helper classes
  • Creating custom membership providers

    • ActiveDirectoryProvider for app use windows authentication
    • SqlMembershipProvider for form authentication

Configure and apply authorization

  • create roles
  • configure roles

    configure a SQL membership role provider in Web.config file

    use InitializeDatabaseConnection(...) for SimpleMembershipProvider with SimpleRole.
  • Authorizing roles programmatically
    • applying Authorize attribute
    • check in code via followings

      *RoleProvider.GetRolesForUser, RoleProvider.IsUserInRole, HttpContext.User.IsInRole

      *WebSecurity.RequireRoles(...)
  • creating custom role providers
  • Implementing WCF service authorization

Design and implement claims-based authentication across federated identity stores

  • Implementing federated authentication by using Windows Azure Access Control Service (ACS)

    ACS features includes:

    • integrates with Windows Identity Foundation (WIF)
    • support well-known identity providers such as Facebook, Microsoft account, Yahoo and Google
    • support Active Directory Federation Services (ADFS) 2.0
    • support OAuth 2.0, WS-Trust and WS-Federation protocols
    • support various token formats, include JSON Web Token (JWT), Security Assertion Markup Language (SAML) and Simple Web Token (SWT)
    • provides a web-based management portal

  • Creating a custom security token by using WIF
  • Handling token formats for SAML and SWT tokens

Manage data integrity

  • encryption terminology

    • Encryption: DES, AES
    • Hashing: MD5, SHA
    • Salting
  • Applying encryption to application data

    • Symmetric: AES, DES, RC2, Rijindael, TripleDES
    • Asymmetric: DSA, ECDiffieHellman, ECDsa, RSA
using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
{
// assumes that the key and initialization vectors are already configured
CryptoStream crypoStream = new CryptoStream(myManagedStream, rijndaelManaged.
CreateEncryptor(),CryptoStreamMode.Write);
}; using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
{
// assumes that the key and initialization vectors are already configured
CryptoStream crypoStream = new CryptoStream(myManagedStream, rijndaelManaged.
CreateDecryptor(),CryptoStreamMode.Read);
};
  • Applying encryption to the configuraion sections of an application

    • DPAPIProtectedConfigurationProvider
    • RsaProtectedConfigurationProvider: allow export/import of the keys used for encryption/decryption
    • use aspnet_regiis to encrypt/decrypt sections of the Web.confg file.
  • Signing application data to prevent tampering

// create the hash code of the text to sign
SHA1 sha = SHA1.Create();
byte[] hashcode = sha.ComputeHash(TextToConvert);
// use the CreateSignature method to sign the data
DSA dsa = DSA.Create();
byte[] signature = dsa.CreateSignature(hashcode); // create the hash code of the text to verify
SHA1 sha = SHA1.Create();
byte[] hashcode = sha.ComputeHash(TextToVerify);
// use the VerifySignature method to verify the DSA signature
DSA dsa = DSA.Create();
bool isSignatureValid = dsa.VerifySignature(hashcode, signature);

Implement a secure site with ASP.NET

  • Securing communication by applying SSL/TLS certificates

    setup site with certificate and https

  • Salt and hash passwords for storage

  • Using HTML encoding to prevent cross-site scripting attacks (AntiXSS Library)

    • use @Html.Encode()
    • encode the data before saving to db
    • use AntiXSS library from NuGet
  • Implementing deferred validation and handle unvalidated requests

  • Preventing SQL injection attacks by parameterizing queries

  • Preventing cross-site request forgeries (XSRFs)

[RequireSession]
[AcceptVerbs(HttpVerbs.Post)]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(string username, string password, string remember, string deviceToken, string apid)
{
}
@using (Html.BeginForm("Login", "Authorize"))
{
@Html.AntiForgeryToken();
}

internally cookie is used for XSRF validation.

Chapter 5: Design and implement security的更多相关文章

  1. Chapter 2: Design the user experience

    Apply the user interface design for a web application 介绍了Css的常用属性和html5的新element,以及Htmlhelper的简单方法,如 ...

  2. Chapter 1: Design the application architecture

    1.1 Plan the application layers 提到了repository pattern,SoC(Separation of Concern), 进而提及MVC,Action/Act ...

  3. Chapter 7. Design and Performance

    本章将对MPEG4及H.264的实现细节进行讲解和比对. Motion Estimation 衡量运动估计的好坏有三种函数(第228页):MSE,MAE和SAE,其中由于SAE运算速度最快所以采用的最 ...

  4. MapReduce Design Patterns(chapter 1)(一)

    Chapter 1.Design Patterns and MapReduce MapReduce 是一种运行于成百上千台机器上的处理数据的框架,目前被google,Hadoop等多家公司或社区广泛使 ...

  5. (转)MapReduce Design Patterns(chapter 1)(一)

    翻译的是这本书: Chapter 1.Design Patterns and MapReduce MapReduce 是一种运行于成百上千台机器上的处理数据的框架,目前被google,Hadoop等多 ...

  6. Page Security

    参见开发文档 Overview This document describes how to build applications that grant selected access to indi ...

  7. Chapter 6 — Improving ASP.NET Performance

    https://msdn.microsoft.com/en-us/library/ff647787.aspx Retired Content This content is outdated and ...

  8. Quality in the Test Automation Review Process and Design Review Template

    About this document Prerequisite knowledge/experience: Software Testing, Test Automation Applicable ...

  9. Security Software Engineer

    Security Software Engineer Are you excited to be part of the VR revolution and work on cutting edge ...

随机推荐

  1. 将word文件快速转换成表格的技巧

    最近烦心事还真是很多,世界买家网最近就遇到了很多烦心事. 从www.buyerinfo.biz网站中的数据导出为csv格式的文件,我导出了buyer的数据,那怎么把它制作成表格呢? 找了下,发现还是比 ...

  2. Cordova+ionic 开发hybird App --- 开发环境搭建

    Cordova 开发hybird App 开发环境搭建 一.一些基础概念: Ant : 简单说来可以这么理解,如果你用记事本写JAVA程序,然后在cmd里输入javac命令编译它,但是有一天你发现每次 ...

  3. SpellTime

    如果你的应用程序允许用户输入文本,或者它结合了任何基于文本的处理,那么我们有一款你一直寻找的产品.Spell Time 允许你把个拼写检查器整合到你的产品中.该产品携带了完整的源码.Spell Tim ...

  4. JPA使用入门

    JPA能干什么?我在前面一遍文章<初步了解JPA>基本描述了.不过你不需要点击回去再看.这里简单的再提一下JPA的功能,就是:(1)实现“对象-关系”映射:(2)对象持久化到数据库:(3) ...

  5. 自定义 placeholder 文本颜色

    原文  http://zhuyujia.github.io/2016/01/custom-placeholder-text-color.html Css: ::-webkit-input-placeh ...

  6. php大力力 [048节] php一点支付开发资料,很散

    https://beecloud.cn/activity/jsbutton/?index=4&t=1441261629019 https://beecloud.cn/download/ php ...

  7. grunt安装与配置

    安装 CLI npm install -g grunt-cli//全局安装 npm init //初始化package.json npm init   命令会创建一个基本的package.json文件 ...

  8. 子级与父级的margin合并的问题

    子级加上了margin以后,发现其父级也移动了相应的margin值.外边距合并.换成padding;在父级上加overflow:hidden;

  9. BackTrack5-r3任务栏显示网络图标及自定义DNS

    任务栏显示网络连接图标:安装NM工具,在BT终端中执行:apt-get install network-manager按y继续执行,显示:ldconfig deferred processing no ...

  10. wordpress模板学习之导航目录

    wordpress的导航目录分为三个部分,一开启,二配置:三使用 开启在functions.php,这个注册会保存在全局变量中,接下来在菜单配置中会看到 register_nav_menu( 'pri ...