Introduction - Andrew.cmu.edu

Download Report

Transcript Introduction - Andrew.cmu.edu

Applied Cryptography
Introduction
95-804 Applied Crypto
Master of Information System
Management
1
Course Web Site
 http://www.andrew.cmu.edu/~mm6
Course Text
“Professional Java Security” Garms & Somerfield
95-804 Applied Crypto
Master of Information System
Management
2
Selected Course Topics(1)
Java Extensible Security Architecture
Java Authentication and Authorization Services (JAAS)
Java Cryptography Architecture(JCA)
Java Cryptography Extensions (JCE)
Java Certification Path API (CertPath)
Java Secure Socket Extensions (JSSE)
Java Security Management Tools
Java Keystore
Keytool
Policytool
Jarsigner
Cryptographic protocols
Voting
SSL
95-804 Applied Crypto
KerberosMaster of Information System
Management
3
Selected Course Topics(2)
Web Services Security and Identity Management
Web Service Security - Standards and Technologies
XML Signature
XML Encryption
XML Key Management System (XKMS)
OASIS Web Service Security (WS-Security)
WS-I Basic Security Profile
Security Assertion Markup Language (SAML)
Extensible Access Control Markup Language (XACML)
.Net Crypto API’s
95-804 Applied Crypto
Master of Information System
Management
4
Structure of the Course
• Lectures / class participation
• Demonstrations
• Homework (programming)
• Several quizzes (low score
dropped)
• Final examination
95-804 Applied Crypto
Master of Information System
Management
5
Readings
• Readings from the required text
are assigned for each lecture -read them in advance
• Readings from the web also
assigned
• For this week read JAAS pages 244
through 258 from Garms and
Somerfield & “All That JAAS” from
JavaWorld
95-804 Applied Crypto
Master of Information System
Management
6
Grading
• Homework/Programming (3-6)
• Quizzes (3)
40%
30%
• Final Exam
30%
95-804 Applied Crypto
Master of Information System
Management
7
Traditional Java Platform
Security
• Each loaded class is verified by the
bytecode verifier.
• The origin of the class (its IP address) is
identified.
• If the code is signed its signature is
checked.
• A set of permissions is assigned based
on the JVM security policy.
• Activities of this class are allowed if
permissions have been granted.
• Protecting
users from bad code.
95-804 Applied Crypto
Master of Information System
Management
8
Today’s Topic
• Java Authentication and
Authorization Service (JAAS)
• Identification - who are you?
• Authentication - can you prove it?
• Authorization - here is what you
may do.
• Protecting the system from bad
users.
95-804 Applied Crypto
Master of Information System
Management
9
JAAS is a Java
implementation
of PAM (Pluggable
Authentication
Module)
framework
developed for
Sun’s Solaris OS.
JAAS
Applications
Login Context
JAAS features a
provider architecture so
that different JAAS-based
authentication and
authorization modules
may be plugged in.
It’s “pluggable” because
we can swap in different
modules by changing
configuration files.
Login Module
Kerberos
Password
Login
95-804 Applied Crypto
Master of Information System
Management
Smart Card
Biometrics
10
JAAS
Typically
1.
2.
Privilege granting
software creates a
LoginContext object
Optionally, it passes a
CallBackHandler to the
LoginContext for
gathering or
processing
authentication data.
Kerberos
Applications
Login Context
3. It calls the
LoginContext’s
logIn method
4. If success then
it uses the returned
Subject to perform
privileged actions
Login Module
Smart Card
95-804 Applied Crypto
Master of Information System
Management
Web
Service
Biometrics
11
JAAS Login Configuration
SomeAppName is provided
File
to the LoginContext from
Applications
A login configuration file:
Login Context
SomeAppName {
loginModuleClassPath required;
anotherLoginModuleClassPath required;
}
Login Module
Kerberos
Module
Smart Card
Module
95-804 Applied Crypto
Master of Information System
Management
the Application.
The LoginContext looks
in the login configuration
file to determine what
login module(s) to use.
It finds the configuration
file by examining
java.security.auth.login.config
system property
Biometrics
Module
12
JAAS Login Modules
Login Module
Depending upon which
login module(s) are
selected several sources
may be present and
accessed for authentication
data. That is, the O.S. may
be queried to get the users
ID or group. The user might
be queried for an ID and
password. Hardware may
be queried for biometric
data, and so on…
Smart Card
Biometrics
Applications
Login Context
Kerberos
95-804 Applied Crypto
Master of Information System
Management
13
JAAS O.S Login Module
Login Module
In the case of O.S.
verification, the login
module (for O.S.
verification)
would make queries on the
O.S. to determine who
is running this application.
Several Principals will
normally be returned. For
example, user ID and
group ID would each
act as a Principal.
Smart Card
SolarisLoginModule
Applications
Login Context
Kerberos
95-804 Applied Crypto
Master of Information System
Management
Solaris
14
JAAS ID and Password
Challenge
Applications
Login Context
In the case of user
verification, the login
module (for user
verification)
would challenge the user
by making a call on a
callback method provided
by the application.
Login Module
Kerberos
Smart Card
95-804 Applied Crypto
Master of Information System
Management
Biometrics
15
A smart card can be used
to hold a user’s public
key certificate. Or, the
certificate may be looked
up in an LDAP directory.
The login module
needs a CA public
key to verify that the
user’s public key is
associated with the
user.
JAAS & Smart
Cards
Applications
Login Context
Login Module
Kerberos
Module
In the case of smart card
verification, the login
module (for smart cards)
would challenge the smart
card with a random
challenge. The card
encrypts the challenge with
its on-board private key.
The login module
checks the signature
and if it’s valid a
Principal is added to the
Subject.
Smart Card
Module
95-804 Applied Crypto
Master of Information System
Management
Biometrics
Module
Card
16
JAAS
Control Flow
LoginContext lc = new LoginContext(…)
lc.login();
// if all OK
// do some
// privileged
// actions
LoginContext
login()
95-804 Applied Crypto
Master of Information System
Management
LoginModule0
init
login
commit
abort
logout
LoginModule1
init
login
commit
abort
logout
LoginModule2
init
login
commit
abort
logout
17
Callbacks (1)
Control Flow
May involve
callback handling
CallbackHandler
handle()
LoginContext lc = new LoginContext(..)
lc.login();
// if all OK
// do some
// privileged
// actions
LoginModule0
init
login
commit
abort
logout
LoginContext
login()
95-804 Applied Crypto
Master of Information System
Management
LoginModule1
init
login
commit
abort
logout
LoginModule2
init
login
commit
abort
logout
18
Callbacks (2)
CallBackHandler
LoginModule0
init
login
commit
abort
logout
handle()
• The callback handler allows the authentication module to gather
necessary authentication information from the user or system.
• A console application, for example, may use the handle method
to contain interaction code.
• A web application may read data from an HTML form and make that
data available to the Callback handler object. The LoginModule
will still query the handler for the authentication data.
95-804 Applied Crypto
Master of Information System
Management
19
Callbacks (3)
CallBackHandler
LoginModule0
init
login
commit
abort
logout
handle()
The communication with the handle method
is done with Callback objects.
95-804 Applied Crypto
Master of Information System
Management
20
Subjects, Principals and
Credentials
• The Subject class represents an authenticated
entity.
• A Subject instance may represent a device,
web service, user or administrator.
• A Subject object contains:
An array of Principals (ID’s, SS#’s, URL’s)
Public credentials (user id’s or public keys)
Private credentials (user passwords or
private keys)
95-804 Applied Crypto
Master of Information System
Management
21
The Commit
Control Flow
If all logins go well call commit
on each module.
LoginModule0
login
commit
assign
principals and
credentials
LoginContext lc = new LoginContext(..)
lc.login();
// if all OK
// do some
// privileged
// actions
LoginContext
login()
95-804 Applied Crypto
Master of Information System
Management
LoginModule2
login
commit
assign
principals
and
credentials
22
LoginModule Initialization
Control Flow
The login method calls initialize
on each module.
LoginContext lc = new LoginContext(..)
lc.login();
// if all OK
// do some
// privileged
// actions
LoginContext
login()
95-804 Applied Crypto
Master of Information System
Management
LoginModule0
initialize
Parameters are
Subject
Callbackhandler
SharedState Map
Options Map
Options are name value
pairs found in the
configuration file. These
may be database
params.
23
LoginModule login
Control Flow
The login method calls initialize
on each module.
LoginContext lc = new LoginContext(..)
lc.login();
// if all OK
// do some
// privileged
// actions
LoginContext
login()
95-804 Applied Crypto
Master of Information System
Management
LoginModule0
login
Might use a
callback for user
input and a
database
to compare ID’s
24
Example From G & S
•
•
•
•
•
JAASSampleAPP.java
UserNamePasswordCallbackHandler.java
PrincipalImpl.java
PasswordLoginModule.java
Jaas.config
95-804 Applied Crypto
Master of Information System
Management
25
JAASSampleApp.java
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
public class JAASSampleApp {
public static void main(String args[]) throws Exception{
if(args.length != 2) {
95-804 Applied Crypto
Master of Information System
System.err.println("Usage:
java JAASSampleApp
Management
26
// The callback handler could be written to prompt the user
// and read the data from the console. In this case, we are
// providing the callbackhandler with the data in its
// constructor. It will provide that data to the module
// when the module calls the handle method.
LoginContext loginContext = new LoginContext("Sample",
new UserNamePasswordCallbackHandler(username,
password));
loginContext.login();
// Now we are logged in, so we can get the current Subject
Subject subject = loginContext.getSubject();
// Display the Subject
95-804 Applied Crypto
System.out.println(subject);
Master of Information System
Management
27
UserNamePasswordCallbackHandler.java
import javax.security.auth.*;
import javax.security.auth.callback.*;
/*
* CallbackHandler that handles usernames and passwords.
* A CallbackHandler must implement the handle method.
*/
public class UserNamePasswordCallbackHandler
implements CallbackHandler {
private String mUsername;
private char[] mPassword;
95-804 Applied Crypto
Master of Information System
Management
28
// As an alternative, the handler might interact with
// a user to collect the data. Here, we provide it to
// the constructor.
public UserNamePasswordCallbackHandler(String userName, char[]
password) {
mUsername = userName;
mPassword = password;
}
/**
* Handle each callback. We support only NameCallbacks and
* PasswordCallbacks.
*/
95-804 Applied Crypto
Master of Information System
Management
29
public void handle(Callback[] callbacks) throws
UnsupportedCallbackException {
// Step through the callbacks
for(int i = 0; i < callbacks.length; i++) {
Callback callback = callbacks[i];
95-804 Applied Crypto
Master of Information System
Management
30
// handle the callback based on its type
if(callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(mUsername);
}
else if(callback instanceof PasswordCallback) {
PasswordCallback passwordCallback =
(PasswordCallback) callback;
passwordCallback.setPassword(mPassword);
}
else {
throw new UnsupportedCallbackException
(callback, "Unsupported callback type");
}
}
}
}
95-804 Applied Crypto
Master of Information System
Management
31
PrincipalImpl.java
import java.io.Serializable;
import java.security.Principal;
public class PrincipalImpl implements Principal,
Serializable {
private String mName;
public PrincipalImpl(String name) {
mName = name;
}
95-804 Applied Crypto
Master of Information System
Management
32
public boolean equals(Object obj) {
if(!(obj instanceof PrincipalImpl)) {
return false;
}
PrincipalImpl other = (PrincipalImpl) obj;
if(mName.equals(other.getName())) {
return true;
}
return false;
}
public String getName() {
return mName;
}
public int hashCode() {
return mName.hashCode();
}
public String toString() {
return getName();
}
95-804 Applied Crypto
}
Master of Information System
Management
33
PasswordLoginModule.java
import java.io.IOException;
import java.security.Principal;
import java.util.Map;
import
import
import
import
import
import
import
import
import
javax.security.auth.Subject;
javax.security.auth.callback.Callback;
javax.security.auth.callback.CallbackHandler;
javax.security.auth.callback.NameCallback;
javax.security.auth.callback.PasswordCallback;
javax.security.auth.callback.UnsupportedCallbackException;
javax.security.auth.login.FailedLoginException;
javax.security.auth.login.LoginException;
javax.security.auth.spi.LoginModule;
95-804 Applied Crypto
Master of Information System
Management
34
public class PasswordLoginModule implements LoginModule {
private Subject mSubject;
private CallbackHandler mCallbackHandler;
private boolean mLoginSucceeded = false;
private boolean mCommitSucceeded = false;
private String mUserName;
private char[] mPassword;
private Principal mPrincipal;
95-804 Applied Crypto
Master of Information System
Management
35
private void clearPassword() {
if(mPassword == null) {
return;
}
for(int i = 0; i < mPassword.length; i++) {
mPassword[i] = ' ';
}
mPassword = null;
}
95-804 Applied Crypto
Master of Information System
Management
36
// Called by LoginContext object provided by JAAS
public void initialize(Subject subject, CallbackHandler callbackHandler,
Map sharedState, Map options) {
mSubject = subject;
mCallbackHandler = callbackHandler;
mLoginSucceeded = false;
mCommitSucceeded = false;
mUserName = null;
clearPassword();
}
95-804 Applied Crypto
Master of Information System
Management
37
// Called by the LoginContext's login method.
public boolean login() throws LoginException {
if(mCallbackHandler == null) {
throw new LoginException("No callback handler defined")
}
// Create two callbacks, one for the user name and
// one for the password.
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username");
callbacks[1] = new PasswordCallback("Password",false);
95-804 Applied Crypto
Master of Information System
Management
38
try {
// Call the callback handler to fill out information
mCallbackHandler.handle(callbacks);
mUserName = ((NameCallback)callbacks[0]).getName();
char[] tempPassword = ((PasswordCallback)
callbacks[1]).getPassword();
mPassword = new char[tempPassword.length];
System.arraycopy(tempPassword,0, mPassword,
0, tempPassword.length);
((PasswordCallback)callbacks[1]).clearPassword();
}
catch(IOException ioe) {
throw new LoginException(ioe.toString());
}
catch(UnsupportedCallbackException uce) {
throw new LoginException(uce.toString());
}
95-804 Applied Crypto
Master of Information System
Management
39
// Now we need to check for the validity of the username and password.
// If we were using a database or a file, we could check against that
// resource.
if( "testuser".equals(mUserName) &&
mPassword.length == 9 &&
mPassword[0] == 's' &&
mPassword[1] == 'a' &&
mPassword[2] == 's' &&
mPassword[3] == 'q' &&
mPassword[4] == 'u' &&
mPassword[5] == 'a' &&
mPassword[6] == 't' &&
mPassword[7] == 'c' &&
mPassword[8] == 'h' ) {
95-804 Applied Crypto
Master of Information System
Management
40
// user name and password are correct
mLoginSucceeded = true;
return true;
} else {
// Authentication failed. Clean up state and
// throw execption.
mLoginSucceeded = false;
mUserName = null;
clearPassword();
throw new
FailedLoginException("Incorrect password");
}
}
95-804 Applied Crypto
Master of Information System
Management
41
public boolean commit() throws LoginException {
if(mLoginSucceeded == false) {
return false;
}
// Login succeeded so create a Principal and add it
// to the Subject.
mPrincipal = new PrincipalImpl(mUserName);
if(!(mSubject.getPrincipals().contains(mPrincipal))) {
mSubject.getPrincipals().add(mPrincipal);
}
95-804 Applied Crypto
Master of Information System
Management
42
// If we wanted our Subject to contain our credentials,
// now would be the time to add them. We don't need to
// do that for this simple example however.
// Clear out the username and password.
mUserName = null;
clearPassword();
mCommitSucceeded = true;
return true;
}
95-804 Applied Crypto
Master of Information System
Management
43
// Called by LoginContext if overall login failed
public boolean abort() throws LoginException {
// if login failed, return false
if(mLoginSucceeded == false) {
return false;
}
else if (mLoginSucceeded == true
&& mCommitSucceeded == false) {
// Our login succeeded, but others failed
mLoginSucceeded = false;
mUserName = null;
clearPassword();
mPrincipal = null;
} else {
// We committed, but someone else failed.
logout();
}
return true;
}
95-804 Applied Crypto
Master of Information System
Management
44
/**
* Logout the user.
*/
public boolean logout() throws LoginException {
// Need to remove the principal from the Subject.
mSubject.getPrincipals().remove(mPrincipal);
mLoginSucceeded = false;
mCommitSucceeded = false;
mUserName = null;
clearPassword();
mPrincipal = null;
return true;
}
}
95-804 Applied Crypto
Master of Information System
Management
45