xamfia
پنج شنبه 01 بهمن 1388, 12:09 عصر
چندی است بنا بر نیاز شرکتمان و نیز علاقه شخصی مشغول کار بر روی برقراری امنیت در وب سرویس ها و نیز WCF می باشم.
بحث برقراری امنیت در سرویس ها امروزه یکی از مهمترین چالش های مهندسان نرم افزار در زمینه SOA میباشد.من نیز بد ندیدم به دلیل کمی منابع فارسی در این زمینه این تاپیک را ایجاد کنم تا مهندسان و برنامه نویسان علاقمند داشته هایشان را یکجا کنند.
مهمترین موضوعاتی که در این تاپیک در مورد آن بحث خواهد شد:
Webservice Security Fundamentals
WCF security
Message Security
Transport Security
Webservice Reliable
WebService Authentication
WebService Authorization
Issue Token & STS
SSL & Certificate & X.509
دوستان عزیز سعی کنند مباحث و سواالت خود را در این قالب مطرح کنند و از طرح مسائل دیگر پیرامون وب سرویس به دیگر تاپیک های مربوط مراجعه کنند.
xamfia
پنج شنبه 01 بهمن 1388, 12:33 عصر
در ابتدا یک مروری کلی و اجمالی روی برخی از این مباحث میکنم
وب سرویس ها تقریبا در 4 حالت مختلف با یکدیگر تعامل میکنند:
1.تعاملات درون سازمانی (Intranet Web service)
2.تعاملات بین سازمانی (Internet business-to-business)
3.وب سوریس های عمومی (Public Web service)
4.تکنولوژی های ترکیبی (Multiple Internet Web services)
1.معماری کربروس(Kerberos) بیشتر برای برقراری امنیت در یک دامین خاص استفاده میشود و در نتیجه کاربردش بیشتر زمانی است که ما قصد داریم سرویس هایمان را در یک دامین مشخص امن کنیم.
2.گواهینامه های امنیتی(Certificate) راه حلی هستند برای ایجاد یک بستر امن در B2B.بطوری که شما میتوانید سرویس هایتان را با شرکای خارجی در رابطه قرار دهید و آنها را با X.509 امن کنید.
یک نمونه X.509
Certificate:
Data:
Version: 1 (0x0)
Serial Number: 7829 (0x1e95)
Signature Algorithm: md5WithRSAEncryption
Issuer: C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc,
OU=Certification Services Division,
CN=Thawte Server CA/emailAddress=server-certs@thawte.com
Validity
Not Before: Jul 9 16:04:02 1998 GMT
Not After : Jul 9 16:04:02 1999 GMT
Subject: C=US, ST=Maryland, L=Pasadena, O=Brent Baccala,
OU=FreeSoft, CN=www.freesoft.org/emailAddress=baccala@freesoft.org
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:b4:31:98:0a:c4:bc:62:c1:88:aa:dc:b0:c8:bb:
33:35:19:d5:0c:64:b9:3d:41:b2:96:fc:f3:31:e1:
66:36:d0:8e:56:12:44:ba:75:eb:e8:1c:9c:5b:66:
70:33:52:14:c9:ec:4f:91:51:70:39:de:53:85:17:
16:94:6e:ee:f4:d5:6f:d5:ca:b3:47:5e:1b:0c:7b:
c5:cc:2b:6b:c1:90:c3:16:31:0d:bf:7a:c7:47:77:
8f:a0:21:c7:4c:d0:16:65:00:c1:0f:d7:b8:80:e3:
d2:75:6b:c1:ea:9e:5c:5c:ea:7d:c1:a1:10:bc:b8:
e8:35:1c:9e:27:52:7e:41:8f
Exponent: 65537 (0x10001)
Signature Algorithm: md5WithRSAEncryption
93:5f:8f:5f:c5:af:bf:0a:ab:a5:6d:fb:24:5f:b6:59:5d :9d:
92:2e:4a:1b:8b:ac:7d:99:17:5d:cd:19:f6:ad:ef:63:2f :92:
ab:2f:4b:cf:0a:13:90:ee:2c:0e:43:03:be:f6:ea:8e:9c :67:
d0:a2:40:03:f7:ef:6a:15:09:79:a9:46:ed:b7:16:1b:41 :72:
0d:19:aa:ad:dd:9a:df:ab:97:50:65:f5:5e:85:a6:ef:19 :d1:
5a:de:9d:ea:63:cd:cb:cc:6d:5d:01:85:b5:6d:c8:f3:d9 :f7:
8f:0e:fc:ba:1f:34:e9:96:6e:6c:cf:f2:ef:9b:bf:de:b5 :22:
68:9f
3.Tokenها یا همان شناسه های امنیتی با یک سری الگوریتم های مشخص و با استفاده از یک سری داده های مشخص مثل نام کاربری،رمز عبور،یک کلید عمومی... ایجاد میشود و نباید به راحتی قابل حدس یا رمزگشایی باشد.
4.تکنولوژی های ترکیبی بهترین پیش آمد برای سازمان هایی است که معماری نامتقارنی دارند یا قصد دارند با سازمان های نامتقارن تعامل کنند.
در برقراری امنیت در وب سرویس ها چند گره اساسی وجود دارد که هر کدام باید به صورت جداگانه باز شود.
1.اعتبارسنجی(Authentication)
تشخیص هویت کاربران،که مطمئن باشیم کاربر نامعتبری از سرویس های ما بهره نمیبرد.
برای اینکار ما نیاز به یک سیستم مدیریت اعضا داریم و همچنین نیاز به فرایندی که کاربری بدون اعبارسنجی وارو نشود و نیز Ticket او در طول فرایند حفظ و به موقع منقرض شود.
در WCF، Authentication تقریبا به این شکل است:
Transport Security Mode Authentication Options
None. When using this option, the WCF service does not authenticate the callers. This is not the recommended option from a security perspective – avoid using this option wherever possible.
Basic. This option is available with the HTTP protocol only. The client is authenticated using the username and password against Active Directory. The client credentials are transported using the Base64 encode string, which is literally likea clear string and therefore is not the most secure option. The service is authenticated by the SSL certificate used for secure communication.
NTLM. This option is available with the HTTP protocol only. The client is authenticated using a challenge-response scheme against Windows accounts. The NTLM option is well suited for a workgroup environment. NTLM authentication is more secure than either Digest or Basic authentication. The service is authenticated using the Windows credentials of the process identity or using an SSL certificate if you are using the HTTP protocol.
Windows. The Windows option tells the WCF service to use Kerberos when in a domain, or NTLM when deployed in a workgroup environment. This option uses a Windows token presented by the caller to authenticate against Active Directory. This is the most secure option compared to Basic, Digest, or NTLM authentication. The service is authenticated using the Windows credentials of the process identity or an SSL certificate if you are using the HTTP protocol.
Certificate. When using this option, the caller presents an X.509 client certificate that the WCF service either validates with peer trust or trusts based on the issuer of the certificate. This option should be used when Windows authentication is not possible, as in the case of business-to-business (B2B) scenarios. The service is authenticated with the service certificate or by using an SSL certificate if you are using the HTTP protocol.
Message Security Mode Authentication Options
None. When using this option, the WCF service does not authenticate the callers. This is not the recommended option from a security perspective – avoid using this option wherever possible.
Windows. When using this option, the WCF service uses Kerberos when in a domain, or NTLM when deployed in a workgroup environment. This option uses the Windows token presented by the caller in order to authenticate against the Active Directory. The service is authenticated using the Windows credentials of the process identity.
Username. When using this option, the caller provides the username and password to the service. The service can authenticate against Windows, use membership providers such as SqlMembershipProvider, or use a custom validator to validate against the custom store. You should choose this option only when Windows authentication is not possible. The service is authenticated with a service certificate.
Certificate. When using this option, the caller presents an X.509 client certificate; the WCF service looks up the certificate information on the host side and either validates it (peer trust) or trusts the issuer (chain trust) of the client certificate. This option should be used when Windows authentication is not possible, or in B2B scenarios. Service is authenticated with a service certificate.
Issue token. When using this option, the client and service depend on a secure token service (STS) to issue tokens that the client and service trusts. Microsoft Windows CardSpace™ is a typical example of an STS.
2.اعمال سطح دسترسی(Authorization)
اعمال دسترسی و محدودیت برای کاربران خاص با توجه به Role تعریف شده.
در WCF داریم:
Authorization in WCF
WCF supports the following three basic authorization approaches:
Role-based. Access to WCF operations is secured based on the role membership of the caller. The role store can be Windows groups, ASP.NET roles, or a custom role store.
Identity-based. WCF supports an Identity Model feature, which is an extension to role-based authorization. Identity Model enables you to manage claims and policies to authorize clients. With this approach, you can verify claims contained within the authenticated users’ credentials.
Resource-based. Individual resources are secured using Windows access control lists (ACLs). The WCF service impersonates the caller prior to accessing resources, which allows the operating system to perform standard access checks. All resource access is performed using the original caller’s security context.
Role-based Authorization
WCF provides the following options for role-based authorization:
Windows groups. If your WCF services and clients are deployed in the same Windows domain, you can use Windows groups for authorization.
ASP.NET roles. Use ASP.NET roles if you have fine-grained roles requirements, or if the users cannot be mapped to Windows domain accounts. This option uses the Role Manager feature and provides three different role providers based on the role store:
SqlRoleProvider. If your role information is stored in a Microsoft SQL Server® database, consider using the SqlRoleProvider for role=basedauthorization.
WindowsTokenRoleProvider. If your roles are Window groups, and you want to leverage the Role Manager feature as a consistent way to check the role membership of your users, regardless of the underlying data store, consider using the WindowsTokenRoleProvider for role-basedauthorization.
AuthorizationStoreRoleProvider. If your role information is stored using the AzMan policy store in an XML file, in Active Directory, or in Active Directory Application Mode (ADAM), consider using the AuthorizationStoreRoleProvider for role-based authorization.
Custom Roles. If your role information is stored in a custom store such as a SQL Server database, create a custom authorization policy to authorize your users.
Note: It is recommended that you implement a custom role provider, using the Role Manager feature, for your custom role store rather than using the custom roles option.
3.امن سازی پیام ها(Message security)
این رمز نگاری میتواند متقارن باشد:
و یا اینکه نامتقارن(با استفاده از دو کلید عمومی و خصوصی):
رمز کردن پیغام های ارسالی میتوند توافقی باشد به طوری که فقط شریک مورد نظر قادر به رمز گشایی آن باشد:
راه دیگر امن سازی پیام ها بهره بردن از کانال های ارتباطی امن(Transport security) میباشد.در این تکنیک از SSL یا همان پروتکل HTTPS برای داشتن یک کانال امن استفاده میشود.
mhaeri
پنج شنبه 15 بهمن 1388, 13:37 عصر
با سلام و تشکر
لطفا این مباحث رو با ذکر مثال و مراجع بع همراه مثال ادامه بدین
ممنون
xamfia
چهارشنبه 12 اسفند 1388, 09:24 صبح
یه بلاگ فوق العاده که میتونه تقریبا تمام چالش های امنیتی شما در زمینه WCF را برطرف کند.
http://www.codeplex.com/WCFSecurity
xamfia
چهارشنبه 12 اسفند 1388, 10:01 صبح
در ادامه لینک قبلی در زمینه ایجاد کانال ارتباطی امن بین سرور و کلاینت چه در بحث WCFو چه webservice میتوانید از مثال زیر در IIS استفاده کنید
http://www.codeproject.com/KB/server-management/SSL_IIS.aspx
(http://www.codeproject.com/KB/server-management/SSL_IIS.aspx)
alimahdavi675
سه شنبه 07 اردیبهشت 1389, 09:19 صبح
با سلام اتفاقا من هم در شركتي كار مي كنم كه دنبال منابعي براي اينكه چگونه امنيت وب سرويس را بيشتر كنيم مي گشت واقعا از تايپكي كه گذاشتيد ممنونم
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.