L10 SecurityProgramming
L10 SecurityProgramming
L10 SecurityProgramming
Outlines
Major security issues (Authentication and SSL)
Types of security programming
Declarative and program security
Declarative security
Using BASIC authentication
Using Form-based authentication
Authentication
Collect user ID information from end users (logging in)
usually by means of browser dialog / interface
user ID information normally refers to username and password
Source: www.verisign.com/ssl/ssl-information-center/how-ssl-security-works/index.html
Web Application Security
A Sample Certificate
This is a certificate issued by Ace CA:
Data
Version: v1 (0x0)
Serial Number: 1 (0x1)
Signature Algorithm: PKCS #1 MD5 With RSA Encryption
Issuer: OU=Ace Certificate Authority, O=Ace Ltd, C=US
Validity: Not Before: Fri Nov 15 00:24:11 1996
Not After: Sat Nov 15 00:24:11 1997
Subject: CN=Jane Doe, O=Ace Industry, C=US
Subject Public Key Info:
Algorithm: PKCS #1 RSA Encryption
Public Key: 00:d0:e5:60:7c:82:19:14:cf:38: F7:5b:f7:35:4e:14:41:2b:ec:24:
33:73:be:06:aa:3d:8b:dc:0d:06: 35:10:92:25:da:8c:c3:ba:b3:d7:
lf:1d:5a:50:6f:9a:86:53:15:f2: 53:63:54:40:88:a2:3f:53:11:ec: 68:fa:e1:f2:57
Public Exponent: 65537 (0x10001)
Signature
Algorithm: PKCS #1 MD5 With RSA Encryption
Signature:
12:f6:55:19:3a:76:d4:56:87:a6: 39:65:f2:66:f7:06:f8:10:de:cd:
1f:2d:89:33:90:3d:a7:e3:ec:27: ac:e1:c0:29:c4:5a:69:17:51:dc:
1e:0c:c6:5f:eb:dc:53:55:77:01: 83:8f:4a:ab:41:46:02:d7:c8:9a: fe:7a:91:5c
Browser connects to SSL port 443 on the web server, and Hello msg
exchange btn browser & server on key-exchange, encrypt alg, etc
Web server sends back its SSL certificate. Web browser decides if it wants
to trust the web servers SSL certificate
Web Browser
Web browser and web server both calculate a session key by agreed
key-generation method
Web browser and web server negotiate an encryption cipher
Web Server
CA Root Certificate
Web browser needs the root certificate of the CA that issued the SSL
certificate to the web-server to verify if the web server is trustable.
If the browser does not have/trust the CA root certificate, most web
browsers will warn you
10
11
12
Declarative Security
None of the individual servlets or JSP pages needs any security conscious
code. You only need to do some configurations (on file web.xml) and
the security is automatically handled by the system.
To prevent unauthorized access
Use the Web application deployment descriptor (web.xml) to declare that
certain URLs need protection.
The server automatically prompts users for username and password upon
requests for access to restricted resources, performs verification, and
keeps track of users who have previously been authenticated.
13
Program Security
Servlets and JSP pages manage (or partially) their own security. All
security (authentication, access control, etc) is done by user programs.
To prevent unauthorized access
Each servlet or JSP page must either authenticate the user or verify that
the user has been authenticated previously.
14
15
BASIC Authentication
By using declarative security, all you need
to do is to put the protected data in a
directory and declare the directory as
protected in <url-pattern> in web.xml (for
restricted servlet, also declare it in <urlpattern>)
The server will pop up a standard
authentication window asking for username
& passwd upon users requests to access
restricted resources (specified directory or
files).
Web Application Security
16
17
<web-app >
<security-constraint></security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>BASIC Authentication Example</realm-name>
</login-config>
< /web-app>
18
19
<web-app >
<security-constraint></security-constraint>
<security-role>
<role-name>sprole</role-name>
<role-name>admin</role-name>
<role-name>user</role-name>
</security-role>
</web-app>
Web Application Security
20
<security-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Web Application Security
21
Disadvantages
- No customization is allowed (e.g. no
user defined GUI or login pages)
- Can only get username and
password by default
22
Form-based Authentication
Web server collects user identification information via a
customized login page, e.g.
23
24
25
26
27
Form-based
28
29
30
31
if (request.isUserInRole(admin")) {
out.println("<H3>Administrator</H3>");
out.println("Median pay for corporate administrator:");
out.println("<UL>");
out.println(" <LI><B>2004:</B> $500,000.");
out.println(" <LI><B>2005:</B> $600,000.");
out.println("</UL>");
}
Web Application Security
32
33
Disadvantages
Much harder to write programs and maintain
Every resource has to use programmed access control
You can build reusable infrastructure (e.g., servlets that inherit from
certain class or custom JSP tags), but it is still a lot of work
34
35
36
37
38
Summary
Declarative security
Requires security configuration and no programming required.
BASIC authentication
Use standard login dialog box.
Form-based authentication
User customized login page.
Combined security
Use isUserRole or getRemoteUser for access control depending on
who accesses resource
Still rely on server for authentication
39