Building Secure ASP.NET Applications phần 1 docx

61 409 0
Building Secure ASP.NET Applications phần 1 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Building Secure ASP.NET Applications Authentication, Authorization, and Secure Communication Web Server Database Server IIS SQL Server Clients ASP.NET IIS ASP.NET Authentication, Authorization and Secure Communication Enterprise Services (COM+) Web Services IIS ASP.NET .NET Remoting Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft, MS-DOS, Windows, Active Directory, C#, Visual Basic, Visual Studio, and Win32 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. © 2002 Microsoft Corporation. All rights reserved. Version 1.0 The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Contents About This Book xxi Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Applies To . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi What This Guide is About . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Who Should Read This Guide? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii What You Must Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Feedback and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii The Team That Brought You This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Contributors and Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv At a Glance xxvii Chapter 1 – Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Chapter 2 – Security Model for ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . xxvii Chapter 3 – Authentication and Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Chapter 4 – Secure Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix Chapter 5 – Intranet Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx Chapter 6 – Extranet Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxii Chapter 7 – Internet Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii Chapter 8 – ASP.NET Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiv Chapter 9 – Enterprise Services Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxv Chapter 10 – Web Services Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxvii Chapter 11 – .NET Remoting Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxviii Chapter 12 – Data Access Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxix Chapter 13 – Troubleshooting Security Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xl Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xl Chapter 1 Introduction 1 The Connected Landscape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 What Are the Goals of This Guide? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 How You Should Read This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Organization of the Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Part I, Security Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Part II, Application Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Part III, Securing the Tiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Part IV, Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Key Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Contentsiv Chapter 2 Security Model for ASP.NET Applications 9 .NET Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Logical Tiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Physical Deployment Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Implementation Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Enterprise Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 .NET Remoting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 ADO.NET and SQL Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Internet Protocol Security (IPSec) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Secure Sockets Layer (SSL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Security Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Security Across the Tiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Gatekeepers and Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Identities and Principals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 WindowsPrincipal and WindowsIdentity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 GenericPrincipal and Associated Identity Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 24 ASP.NET and HttpContext.User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Remoting and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Chapter 3 Authentication and Authorization 29 Designing an Authentication and Authorization Strategy . . . . . . . . . . . . . . . . . . . . . . . 30 Identify Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Choose an Authorization Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Choose the Identities Used for Resource Access . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Consider Identity Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Choose an Authentication Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Decide How to Flow Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Authorization Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Role Based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Resource Based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Resource Access Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 The Trusted Subsystem Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 The Impersonation / Delegation Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Choosing a Resource Access Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Flowing Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Application vs. Operating System Identity Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Impersonation and Delegation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Contents v Role-Based Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 .NET Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Enterprise Services (COM+) Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 SQL Server User Defined Database Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 SQL Server Application Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 .NET Roles versus Enterprise Services (COM+) Roles . . . . . . . . . . . . . . . . . . . . . . . 45 Using .NET Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Choosing an Authentication Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Internet Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Intranet / Extranet Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Authentication Mechanism Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Chapter 4 Secure Communication 55 Know What to Secure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 SSL/TLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Using SSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 IPSec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Using IPSec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 RPC Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Using RPC Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Point to Point Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Browser to Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Web Server to Remote Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Application Server to Database Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Choosing Between IPSec and SSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Farming and Load Balancing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Chapter 5 Intranet Security 65 ASP.NET to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Related Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Contentsvi ASP.NET to Enterprise Services to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 ASP.NET to Web Services to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 ASP.NET to Remoting to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Flowing the Original Caller to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 ASP.NET to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 ASP.NET to Enterprise Services to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Chapter 6 Extranet Security 103 Exposing a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Exposing a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Scenario Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Contents vii Chapter 7 Internet Security 119 ASP.NET to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Related Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 ASP.NET to Remote Enterprise Services to SQL Server . . . . . . . . . . . . . . . . . . . . . . . 127 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Secure the Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 The Result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Security Configuration Steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Related Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Chapter 8 ASP.NET Security 137 ASP.NET Security Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Gatekeepers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Authentication and Authorization Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Available Authorization Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Windows Authentication with Impersonation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Windows Authentication without Impersonation . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Windows Authentication Using a Fixed Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Passport Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Configuring Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Configure IIS Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Configure ASP.NET Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Secure Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Secure Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Programming Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 An Authorization Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Creating a Custom IPrincipal class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Windows Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Development Steps for Forms Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Forms Implementation Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Hosting Multiple Applications Using Forms Authentication . . . . . . . . . . . . . . . . . . 168 Cookieless Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Contentsviii Passport Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Custom Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Process Identity for ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Use a Least Privileged Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Avoid Running as SYSTEM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Using the Default ASPNET Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Impersonation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Impersonation and Local Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Impersonation and Remote Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Impersonation and Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Accessing System Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Accessing the Event Log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Accessing the Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Accessing COM Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Apartment Model Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Accessing Network Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Using the ASP.NET Process Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Using a Serviced Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Using the Anonymous Internet User Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Using LogonUser and Impersonating a Specific Windows Identity . . . . . . . . . . . . . 182 Using the Original Caller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Accessing Files on a UNC File Share . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Accessing Non-Windows Network Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Secure Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Storing Secrets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Options for Storing Secrets in ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Consider Storing Secrets in Files on Separate Logical Volumes . . . . . . . . . . . . . . . 186 Securing Session and View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Securing View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Securing Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Securing SQL Session State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Web Farm Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Session State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 DPAPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Using Forms Authentication in a Web Farm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 The <machineKey> Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Chapter 9 Enterprise Services Security 195 Security Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 Gatekeepers and Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Use Server Applications for Increased Security . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Security for Server and Library Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 Code Access Security Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 Contents ix Configuring Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Configuring a Server Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Configuring an ASP.NET Client Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Configuring Impersonation Levels for an Enterprise Services Application . . . . . . . . 208 Programming Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Programmatic Role-Based Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Identifying Callers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Choosing a Process Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Never Run as the Interactive User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Use a Least-Privileged Custom Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Accessing Network Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Using the Original Caller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Using the Current Process Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Using a Specific Service Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Flowing the Original Caller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Calling CoImpersonateClient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 RPC Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Building Serviced Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 DLL Locking Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 QueryInterface Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 DCOM and Firewalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Calling Serviced Components from ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Caller’s Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Use Windows Authentication and Impersonation Within the Web-based Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Configure Authentication and Impersonation within Machine.config . . . . . . . . . . . . 218 Configuring Interface Proxies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Security Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Enterprise Services (COM+) Roles and .NET Roles . . . . . . . . . . . . . . . . . . . . . . . . 222 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Impersonation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Chapter 10 Web Services Security 227 Web Service Security Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Platform/Transport Level (Point-to-Point) Security . . . . . . . . . . . . . . . . . . . . . . . . . 228 Application Level Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Message Level (End-to-End) Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Platform/Transport Security Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 Gatekeepers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Contentsx Authentication and Authorization Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Windows Authentication with Impersonation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Windows Authentication without Impersonation . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Windows Authentication Using a Fixed Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Configuring Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Configure IIS Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Configure ASP .NET Settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Secure Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Disable HTTP-GET, HTTP-POST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Secure Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Passing Credentials for Authentication to Web Services . . . . . . . . . . . . . . . . . . . . . . 240 Specifying Client Credentials for Windows Authentication . . . . . . . . . . . . . . . . . . . 241 Calling Web Services from Non-Windows Clients . . . . . . . . . . . . . . . . . . . . . . . . . 243 Proxy Server Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Flowing the Original Caller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Default Credentials with Kerberos Delegation . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Explicit Credentials with Basic or Forms Authentication . . . . . . . . . . . . . . . . . . . . 247 Trusted Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Flowing the Caller’s Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Configuration Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Accessing System Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 Accessing Network Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 Accessing COM Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 Using Client Certificates with Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 Authenticating Web Browser Clients with Certificates . . . . . . . . . . . . . . . . . . . . . . 254 Using the Trusted Subsystem Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Secure Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Transport Level Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Message Level Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Chapter 11 .NET Remoting Security 261 .NET Remoting Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Remoting Sinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Anatomy of a Request When Hosting in ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . 264 ASP.NET and the HTTP Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 .NET Remoting Gatekeepers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Hosting in ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Hosting in a Windows Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Using File Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Authentication and Authorization Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 [...]... Windows 2000 Hubs xix 517 517 518 518 518 518 518 519 519 519 519 519 519 519 520 520 520 520 5 21 5 21 5 21 5 21 522 522 522 522 522 522 522 523 523 523 523 523 523 523 523 524 524 524 524 524 525 525 xx Contents How Does It Work? IIS and ASP NET Processing ... Storing Database Connection Strings Securely The Options Using DPAPI Using Web.config and Machine.config 293 293 295 295 297 297 303 305 306 306 310 310 310 311 311 312 312 313 314 314 314 319 xii Contents Using UDL Files ... References 415 415 416 417 417 418 418 419 420 420 4 21 422 424 424 427 428 xvi Contents How To: Create an Encryption Library Requirements Summary 1 Create a C# Class Library 2 Create a... 5 41 542 542 543 543 543 544 547 NET Web Application Security 549 Glossary 5 51 About This Book Summary This guide presents a practical, scenario driven approach to designing and building secure ASP.NET applications for Windows 2000 and version 1. 0 of the NET Framework It focuses on the key elements of authentication, authorization and secure communication within and across... Read an Encrypted Connection String from Web.Config References 409 409 410 410 410 412 413 414 How To: Use DPAPI (User Store) from ASP.NET with Enterprise Services Notes Why Use Enterprise Services? Why Use... for those clients) q Secure communication (to ensure that messages remain private and are not altered by unauthorized parties) Building Secure ASP.NET Applications Why authentication, authorization, and secure communication? Security is a broad topic Research has shown that early design of authentication and authorization eliminates a high percentage of application vulnerabilities Secure communication... to learn how to: q Apply secure communication techniques throughout the various tiers of your application q Choose between SSL and IPSec q Configure secure communication q Use RPC encryption The chapter addresses the need to provide secure communication channels between your application’s various physical tiers as shown in Figure 3 on the next page xxx Building Secure ASP.NET Applications Application... Developer Support Engineer, Product Support and Services (PSS) xxiv Building Secure ASP.NET Applications Contributors and Reviewers Many thanks to the following contributors and reviewers: q Thanks to external reviewers – Keith Brown (DevelopMentor) for review and feedback on the ASP.NET chapter, Andy Eunson for providing scenarios on middleware applications, John Langley (KANA Software) for bringing J2EE... Server IIS Secure Communication (SSL / IPSec) xxii ASP.NET ASP.NET IIS ASP.NET Web Services Enterprise Services (COM+) Authorization NTFS Perms IP Restrictions IIS ASP.NET NET Remoting Authentication Windows Forms Passport None (Custom) Authorization URL Auth File Auth NET Roles Enterprise Services Authentication RPC Authorization COM+ Roles NTFS Perms SQL Server SQL Server Database Server Figure 1 NET... Security configuration for ASP.NET to remote Enterprise Services to SQL Server Read this chapter to learn how to: q Use Forms authentication with a SQL Server credential database q Avoid storing passwords in the credential database q Authorize Internet users with URL Authorization and NET roles xxxiv Building Secure ASP.NET Applications q q q q Use Windows authentication from an ASP.NET Web application . Building Secure ASP. NET Applications Authentication, Authorization, and Secure Communication Web Server Database Server IIS SQL Server Clients ASP. NET IIS ASP. NET Authentication,. . . . . 11 7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 7 Contents vii Chapter 7 Internet Security 11 9 ASP. NET to SQL. . . . . . . . . . . . 13 6 Chapter 8 ASP. NET Security 13 7 ASP. NET Security Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 7 Gatekeepers . . .

Ngày đăng: 12/08/2014, 09:21

Từ khóa liên quan

Mục lục

  • Front Cover

  • Contents

    • About This Book

      • Summary

      • Applies To

      • What This Guide is About

      • Who Should Read This Guide?

      • What You Must Know

      • Feedback and Support

      • The Team That Brought You This Guide

        • Contributors and Reviewers

        • At a Glance

          • Chapter 1 - Introduction

          • Chapter 2 - Security Model for ASP.NET Applications

          • Chapter 3 - Authentication and Authorization

          • Chapter 4 - Secure Communication

          • Chapter 5 - Intranet Security

          • Chapter 6 - Extranet Security

          • Chapter 7 - Internet Security

          • Chapter 8 - ASP.NET Security

          • Chapter 9 - Enterprise Services Security

          • Chapter 10 - Web Services Security

          • Chapter 11 - .NET Remoting Security

          • Chapter 12 - Data Access Security

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan