SlideShare a Scribd company logo
Java Security Architecture
Demystified
Martin Toshev,
BGOUG, 13.06.2015
Who am I
Software engineer @ EPAM Bulgaria
BG JUG governance board member (http://jug.bg)
OpenJDK contributor
Agenda
• Evolution of the Java security model
• Outside the sandbox - APIs for secure coding
• Designing and coding with security in mind
Evolution of the Java security
model
Evolution of the
Java security model
• Traditionally - companies protect they assets
using strict physical and network access policies
• Tools such as anti-virus software, firewalls,
IPS/IDS systems facilitate this approach
Evolution of the
Java security model
• With the introduction of various technologies for
loading and executing code on the client machine
from the browser (such as Applets) - a new range
of concerns emerge related to client security –
this is when the Java security sandbox starts to
evolve …
Evolution of the
Java security model
• The goal of the Java security sandbox is to allow
untrusted code from applets to be executed in a
trusted environment such as the user's browser
Evolution of the
Java security model
• JDK 1.0 (when it all started …) – the original
sandbox model was introduced
Applet
(untrusted)
System code
(trusted)
JVM
Browser
http://javaday.bg/demoapplet
Evolution of the
Java security model
• Code executed by the JVM is divided in two
domains – trusted and untrusted
• Strict restriction are applied by default on the
security model of applets such as denial to
read/write data from disk, connect to the
network and so on
Evolution of the
Java security model
• JDK 1.1 (gaining trust …) – applet signing
introduced
Applet
(untrusted)
System code
(trusted)
JVM
Browser
http://javaday.bg/demoapplet
Signed Applet
(trusted)
http://javaday.bg/trustedapplet
Evolution of the
Java security model
• Trusted local code and untrusted remote code
from applets restricted to a predefined set of
operations OR signed applet code that is trusted
Evolution of the
Java security model
• Steps needed to sign and run an applet:
– Compile the applet
– Create a JAR file for the applet
– Generate a pair of public/private keys
– Sign the applet JAR with the private key
– Export a certificate for the public key
– Import the Certificate as a Trusted Certificate
– Create the policy file
– Load and run the applet
Evolution of the
Java security model
• JDK 1.2 (gaining more trust …) – fine-grained
access control
Applet
System code
JVM
Browser
http://javaday.bg/demoapplet
grant codeBase http://javaday.bg/demoapplet {
permission java.io.FilePermissions “C:Windows” “delete”
}
security.policy
SecurityManager.checkPermission(…)
AccessController.checkPermission(…)
Evolution of the
Java security model
• Since the security model is code-centric -
additional access control decisions are specified
in a security policy
• No more notion of trusted and untrusted code
Evolution of the
Java security model
• The notion of protection domain introduced –
determined by the security policy
• Two types of protection domains – system and
application
Evolution of the
Java security model
• The protection domain is set during classloading
and contains the code source and the list of
permissions for the class
applet.getClass().getProtectionDomain();
Evolution of the
Java security model
• One permission can imply another permission
java.io.FilePermissions “C:Windows” “delete”
implies
java.io.FilePermissions “C:Windowssystem32” “delete”
Evolution of the
Java security model
• One code source can imply another code source
codeBase http://javaday.bg/
implies
codeBase http://javaday.bg/demoapplet
Evolution of the
Java security model
• Since an execution thread may pass through
classes loaded by different classloaders (and
hence – have different protection domains) the
following rule of thumb applies:
The permission set of an execution thread is considered
to be the intersection of the permissions of all protection
domains traversed by the execution thread
Evolution of the
Java security model
• JDK 1.3, 1,4 (what about entities running the
code … ?) – JAAS
Applet
System code
JVM
Browser
http://javaday.bg/demoapplet
grant principal javax.security.auth.x500.X500Principal "cn=Tom"
{ permission java.io.FilePermissions “C:Windows” “delete” }
security.policy
Evolution of the
Java security model
• JAAS (Java Authentication and Authorization
Service) extends the security model with role-
based permissions
• The protection domain of a class now may
contain not only the code source and the
permissions but a list of principals
Evolution of the
Java security model
• The authentication component of JAAS is
independent of the security sandbox in Java and
hence is typically used in more wider context
(such as j2ee app servers)
• The authorization component is the one that
extends the Java security policy
Evolution of the
Java security model
• Core classes of JAAS:
– javax.security.auth.Subject - an authenticated subject
– java.security.Principal - identifying characteristic of a subject
– javax.security.auth.spi.LoginModule - interface for
implementors of login (PAM) modules
– javax.security.auth.login.LoginContext - creates objects used
for authentication
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
1) upon system startup a security policy is set and a
security manager is installed
Policy.setPolicy(…)
System.setSecurityManager(…)
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
2) during classloading (e.g. of a remote applet) bytecode
verification is done and the protection domain is set
for the current classloader (along with the code
source, the set of permissions and the set of JAAS
principals)
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
3) when system code is invoked from the remote code
the SecurityManager is used to check against the
intersection of protection domains based on the chain
of threads and their call stacks
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
SocketPermission permission = new
SocketPermission("javaday.bg:8000-
9000","connect,accept");
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(permission);
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
4) application code can also do permission checking
against remote code using a SecurityManager or an
AccessController
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
SocketPermission permission = new
SocketPermission("javaday.bg:8000-9000",
"connect,accept");
AccessController.checkPermission(permission)
Evolution of the
Java security model
• Up to JDK 1.4 the following is a typical flow for
permission checking:
5) application code can also do permission checking with
all permissions of the calling domain or a particular
JAAS subject
AccessController.doPrivileged(…)
Subject.doAs(…)
Subject.doAsPrivileged(…)
Evolution of the
Java security model
• The security model defined by
java.lang.SecurityManager is customizable
• For example: Oracle JVM uses a custom
SecurityManager with additional permission
classes where the code source is a database
schema (containing e.g. Java stored procedures)
Evolution of the
Java security model
• JDK 1.5, 1.6 (enhancing the model …) – new
additions to the sandbox model (e.g. LDAP
support for JAAS)
Evolution of the
Java security model
• JDK 1.7, 1.8 (further enhancing the model …) –
enhancements to the sandbox model (e.g.
AccessController.doPrivileged() for checking
against a subset of permissions)
Evolution of the
Java security model
• JDK 1.9 and beyond … (applying the model to
modules …)
application module
system
module 1
JVM
Browser
http://javaday.bg/appmodule
security.policy
system
module 2
Evolution of the
Java security model
• By modules we understand modules in JDK as
defined by project Jigsaw
• Modules must conform to the same security
model as applets – moreover each module is
loaded by a different classloader – hence classes
in different modules must have different
protection domains
Evolution of the
Java security model
• Modularization of the JDK system classes
allows further to define fine-grained access
control permissions for classes in the system
domain
• This is not currently allowed due to the
monolithic nature of the JDK
Outside the sandbox - APIs for
secure coding
Outside the sandbox - APIs for secure
coding
• The security sandbox defines a strict model for
execution of remote code in the JVM
• The other side of the coin are the security APIs
that provide utilities for implementing the
different aspects of application security …
Outside the sandbox - APIs for secure
coding
• The additional set of APIs includes:
– JCA (Java Cryptography Architecture)
– PKI (Public Key Infrastructure) utilities
– JSSE (Java Secure Socket Extension)
– Java GSS API (Java Generic Security Services)
– Java SASL API (Java Simple Authentication and Security
Layer)
Outside the sandbox - APIs for secure
coding
• JCA provides utilities for:
– creating digital signatures
– creating message digests
– using cryptographic ciphers (symetric/asymetric,
block/stream)
– using different other types of cryptographic services and
algorithms
Outside the sandbox - APIs for secure
coding
• JCA has a pluggable architecture
• JCA is independent from particular cryptographic
algorithms
• JCA continues to evolve (especially by providing
stronger cryptographic algorithms)
Outside the sandbox - APIs for secure
coding
• PKI utilities provide means for working with:
– certificates
– certificate revocation lists (CRL)
– OCSP (Online Certificate Status Protocol)
– key stores and trust stores (also based on the PKCS -
public-key cryptography standards)
Outside the sandbox - APIs for secure
coding
• PKI certificate revocation check (revision):
• PKI utilities continue to evolve (especially in
providing more support for managing certificates
and keys)
certificate
authorityrevocation
checking
OCSP
CRL
certificate
certificate
Outside the sandbox - APIs for secure
coding
• JSSE provides an implementation of the TSL/SSL
sockets for working with remote communication
• JSSE continues to evolve (especially in the
support for additional features such as Server
Name Identication)
Outside the sandbox - APIs for secure
coding
• Java GSS API provides an alternative of JSSE
for secure communication
• Java GSS API is a framework for providing
token-based security services that is
independent of the underlying protocols
Outside the sandbox - APIs for secure
coding
• Java GSS API can be used along with JAAS for
authentication purposes
• Java GSS API continues to evolve (especially in
the support for Kerberos authentication)
Outside the sandbox - APIs for secure
coding
• Java SASL defines a protocol for exchange of
authentication data
• Java SASL is a framework where external
providers give concrete semantics to the
authentication data being exchanged
Outside the sandbox - APIs for secure
coding
• Java SASL continues to evolve (especially with
support for additional and enhanced
properties for exchanging authentication data)
Designing and coding with
security in mind
Designing and coding
with security in mind
• First of all - follow programing guidelines and
best practices - most are not bound to the Java
programming language (input validation, error
handling, type safety, access modifiers, resource
cleanup, prepared SQL queries and whatever you
can think of …)
Designing and coding
with security in mind
• Respect the SecurityManager - design libraries so
that they work in environments with installed
SecurityManager
• Example: GSON library does not respect the
SecurityManager and cannot be used without additional
reflective permissions in some scenarios
Designing and coding
with security in mind
• Grant minimal permissions to code that requires
them - the principle of "least privilege"
• Copy-pasting, of course, increases the risk of
security flows (if the copied code is flawed)
Designing and coding
with security in mind
• Sanitize exception messages from sensitive
information - often this results in an unintended
exposal of exploitable information
• Let alone exception stacktraces … in many cases
they convey a wealth of information about the
system
Thank you
References
• Java Security Overview (white paper)
http://www.oracle.com/technetwork/java/js-white-paper-
149932.pdf
• Java SE Platform Security Architecture Spec
http://docs.oracle.com/javase/7/docs/technotes/guides/sec
urity/spec/security-spec.doc.html
• Inside Java 2 Platform Security, 2nd edition
http://www.amazon.com/Inside-Java%C2%BF-Platform-
Security-Implementation/dp/0201787911
References
• Java Security, 2nd edition, Scott Oaks
http://shop.oreilly.com/product/9780596001575.do
• Securing Java, Gary McGraw, Ed Felden
http://www.securingjava.com
• Secure Coding Guidelines for Java SE
http://www.oracle.com/technetwork/java/seccodeguide
-139067.html#0
References
• Java 2 Network Security
http://www.amazon.com/JAVA-Network-Security-2nd-
Edition/dp/0130155926
• Java Security Documentation
http://docs.oracle.com/javase/8/docs/technotes/guides/
security/index.html
References
• Core Java Security: Class Loaders, Security
Managers and Encryption
http://www.informit.com/articles/article.aspx?p=118796
7
• Overview of Java Security Models
http://docs.oracle.com/cd/E12839_01/core.1111/e1004
3/introjps.htm#CHDCEJGH

More Related Content

PPTX
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
PPTX
Security Аrchitecture of Тhe Java Platform
PPT
Java security
PPTX
Deep dive into Java security architecture
PPTX
Martin Toshev - Java Security Architecture - Codemotion Rome 2019
PDF
Asec r01-resting-on-your-laurels-will-get-you-pwned
PDF
Unsafe Deserialization Attacks In Java and A New Approach To Protect The JVM ...
PDF
Spring Framework - Spring Security
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Аrchitecture of Тhe Java Platform
Java security
Deep dive into Java security architecture
Martin Toshev - Java Security Architecture - Codemotion Rome 2019
Asec r01-resting-on-your-laurels-will-get-you-pwned
Unsafe Deserialization Attacks In Java and A New Approach To Protect The JVM ...
Spring Framework - Spring Security

What's hot (20)

PPT
Creating Secure Applications
PDF
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
PDF
Spring security 2017
PDF
SecDevOps - The Operationalisation of Security
PDF
Javacro 2014 Spring Security 3 Speech
PPTX
Access Control Pitfalls v2
PDF
State of Solr Security 2016: Presented by Ishan Chattopadhyaya, Lucidworks
PDF
Java EE Security API - JSR375: Getting Started
PPTX
[OWASP Poland Day] Application frameworks' vulnerabilities
PPTX
[Wroclaw #2] Web Application Security Headers
PPTX
Windows Azure Security Features And Functionality
ODP
Dos and Don'ts of Android Application Security (Security Professional Perspec...
PDF
Securing Search Data in the Cloud
PDF
BlackHat Arsenal 2014 - C-SCAD : Assessing Security Flaws in C-SCAD WebX Clie...
PDF
UKC - Feb 2013 - Analyzing the security of Windows 7 and Linux for cloud comp...
PDF
[OWASP Poland Day] Web App Security Architectures
PDF
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
PPTX
Spring Security
PPTX
Advance java session 19
PDF
Persistant Cookies and LDAP Injection
Creating Secure Applications
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Spring security 2017
SecDevOps - The Operationalisation of Security
Javacro 2014 Spring Security 3 Speech
Access Control Pitfalls v2
State of Solr Security 2016: Presented by Ishan Chattopadhyaya, Lucidworks
Java EE Security API - JSR375: Getting Started
[OWASP Poland Day] Application frameworks' vulnerabilities
[Wroclaw #2] Web Application Security Headers
Windows Azure Security Features And Functionality
Dos and Don'ts of Android Application Security (Security Professional Perspec...
Securing Search Data in the Cloud
BlackHat Arsenal 2014 - C-SCAD : Assessing Security Flaws in C-SCAD WebX Clie...
UKC - Feb 2013 - Analyzing the security of Windows 7 and Linux for cloud comp...
[OWASP Poland Day] Web App Security Architectures
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
Spring Security
Advance java session 19
Persistant Cookies and LDAP Injection
Ad

Viewers also liked (20)

PPTX
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
PDF
Java security in the real world (Ryan Sciampacone)
PPTX
Writing Stored Procedures with Oracle Database 12c
PPTX
Writing Stored Procedures in Oracle RDBMS
PPTX
Writing Java Stored Procedures in Oracle 12c
PPTX
Modular Java
PPTX
RxJS vs RxJava: Intro
PPTX
Spring RabbitMQ
PDF
KDB database (EPAM tech talks, Sofia, April, 2015)
PDF
Java Security Manager Reloaded - Devoxx 2014
PPTX
Rest with Java EE 6 , Security , Backbone.js
PPTX
Security Architecture of the Java platform
PDF
Eclipse plug in development
PPTX
JVM++: The Graal VM
PPTX
Spring Security
PPTX
Spring Security 3
PDF
The Present Future of OAuth
PPT
Security via Java
PPTX
The RabbitMQ Message Broker
PPTX
Oracle Database 12c Attack Vectors
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Java security in the real world (Ryan Sciampacone)
Writing Stored Procedures with Oracle Database 12c
Writing Stored Procedures in Oracle RDBMS
Writing Java Stored Procedures in Oracle 12c
Modular Java
RxJS vs RxJava: Intro
Spring RabbitMQ
KDB database (EPAM tech talks, Sofia, April, 2015)
Java Security Manager Reloaded - Devoxx 2014
Rest with Java EE 6 , Security , Backbone.js
Security Architecture of the Java platform
Eclipse plug in development
JVM++: The Graal VM
Spring Security
Spring Security 3
The Present Future of OAuth
Security via Java
The RabbitMQ Message Broker
Oracle Database 12c Attack Vectors
Ad

Similar to Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015) (20)

PDF
Javantura v4 - Security architecture of the Java platform - Martin Toshev
ODP
Tollas Ferenc - Java security
PDF
Java Platform Security Architecture
PPT
Chapter three Java_security.ppt
PPT
Java Security
PDF
Advanced Java
PDF
Security in Java
PPT
Sandboxing (Distributed computing)
PPTX
From java to android a security analysis
PPT
java-card20232024999999999999999999999999999999999999999999999999999999999999...
PPTX
Practical security In a modular world
PDF
Secure JEE Architecture and Programming 101
PPTX
How java is better than other languages according to history and uses.
PPTX
Networking and Security in Java
PDF
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
PPTX
Voxxed Days Athens - Securing the JVM - Neither for fun nor for profit, but d...
PPTX
Code Europe PL - Securing the JVM: Neither for fun nor for profit, but do you...
PDF
Secure Computing With Java
PPTX
Javantura - Securing the JVM
PDF
Java Platform Standard Edition Security Developers Guide 17th Edition Oracle
Javantura v4 - Security architecture of the Java platform - Martin Toshev
Tollas Ferenc - Java security
Java Platform Security Architecture
Chapter three Java_security.ppt
Java Security
Advanced Java
Security in Java
Sandboxing (Distributed computing)
From java to android a security analysis
java-card20232024999999999999999999999999999999999999999999999999999999999999...
Practical security In a modular world
Secure JEE Architecture and Programming 101
How java is better than other languages according to history and uses.
Networking and Security in Java
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Voxxed Days Athens - Securing the JVM - Neither for fun nor for profit, but d...
Code Europe PL - Securing the JVM: Neither for fun nor for profit, but do you...
Secure Computing With Java
Javantura - Securing the JVM
Java Platform Standard Edition Security Developers Guide 17th Edition Oracle

More from Martin Toshev (11)

PPTX
Building highly scalable data pipelines with Apache Spark
PPTX
Big data processing with Apache Spark and Oracle Database
PPT
Jdk 10 sneak peek
PPT
Semantic Technology In Oracle Database 12c
PPT
Java 9 Security Enhancements in Practice
PPTX
Java 9 sneak peek
PPTX
Spring RabbitMQ
PDF
Concurrency Utilities in Java 8
PPTX
java2days 2014: Attacking JavaEE Application Servers
PPTX
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
PPTX
New Features in JDK 8
Building highly scalable data pipelines with Apache Spark
Big data processing with Apache Spark and Oracle Database
Jdk 10 sneak peek
Semantic Technology In Oracle Database 12c
Java 9 Security Enhancements in Practice
Java 9 sneak peek
Spring RabbitMQ
Concurrency Utilities in Java 8
java2days 2014: Attacking JavaEE Application Servers
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
New Features in JDK 8

Recently uploaded (20)

PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Well-logging-methods_new................
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Artificial Intelligence
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
Project quality management in manufacturing
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Geodesy 1.pptx...............................................
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
III.4.1.2_The_Space_Environment.p pdffdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
bas. eng. economics group 4 presentation 1.pptx
Well-logging-methods_new................
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Artificial Intelligence
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
573137875-Attendance-Management-System-original
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Project quality management in manufacturing
737-MAX_SRG.pdf student reference guides
Geodesy 1.pptx...............................................

Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)

  • 2. Who am I Software engineer @ EPAM Bulgaria BG JUG governance board member (http://jug.bg) OpenJDK contributor
  • 3. Agenda • Evolution of the Java security model • Outside the sandbox - APIs for secure coding • Designing and coding with security in mind
  • 4. Evolution of the Java security model
  • 5. Evolution of the Java security model • Traditionally - companies protect they assets using strict physical and network access policies • Tools such as anti-virus software, firewalls, IPS/IDS systems facilitate this approach
  • 6. Evolution of the Java security model • With the introduction of various technologies for loading and executing code on the client machine from the browser (such as Applets) - a new range of concerns emerge related to client security – this is when the Java security sandbox starts to evolve …
  • 7. Evolution of the Java security model • The goal of the Java security sandbox is to allow untrusted code from applets to be executed in a trusted environment such as the user's browser
  • 8. Evolution of the Java security model • JDK 1.0 (when it all started …) – the original sandbox model was introduced Applet (untrusted) System code (trusted) JVM Browser http://javaday.bg/demoapplet
  • 9. Evolution of the Java security model • Code executed by the JVM is divided in two domains – trusted and untrusted • Strict restriction are applied by default on the security model of applets such as denial to read/write data from disk, connect to the network and so on
  • 10. Evolution of the Java security model • JDK 1.1 (gaining trust …) – applet signing introduced Applet (untrusted) System code (trusted) JVM Browser http://javaday.bg/demoapplet Signed Applet (trusted) http://javaday.bg/trustedapplet
  • 11. Evolution of the Java security model • Trusted local code and untrusted remote code from applets restricted to a predefined set of operations OR signed applet code that is trusted
  • 12. Evolution of the Java security model • Steps needed to sign and run an applet: – Compile the applet – Create a JAR file for the applet – Generate a pair of public/private keys – Sign the applet JAR with the private key – Export a certificate for the public key – Import the Certificate as a Trusted Certificate – Create the policy file – Load and run the applet
  • 13. Evolution of the Java security model • JDK 1.2 (gaining more trust …) – fine-grained access control Applet System code JVM Browser http://javaday.bg/demoapplet grant codeBase http://javaday.bg/demoapplet { permission java.io.FilePermissions “C:Windows” “delete” } security.policy SecurityManager.checkPermission(…) AccessController.checkPermission(…)
  • 14. Evolution of the Java security model • Since the security model is code-centric - additional access control decisions are specified in a security policy • No more notion of trusted and untrusted code
  • 15. Evolution of the Java security model • The notion of protection domain introduced – determined by the security policy • Two types of protection domains – system and application
  • 16. Evolution of the Java security model • The protection domain is set during classloading and contains the code source and the list of permissions for the class applet.getClass().getProtectionDomain();
  • 17. Evolution of the Java security model • One permission can imply another permission java.io.FilePermissions “C:Windows” “delete” implies java.io.FilePermissions “C:Windowssystem32” “delete”
  • 18. Evolution of the Java security model • One code source can imply another code source codeBase http://javaday.bg/ implies codeBase http://javaday.bg/demoapplet
  • 19. Evolution of the Java security model • Since an execution thread may pass through classes loaded by different classloaders (and hence – have different protection domains) the following rule of thumb applies: The permission set of an execution thread is considered to be the intersection of the permissions of all protection domains traversed by the execution thread
  • 20. Evolution of the Java security model • JDK 1.3, 1,4 (what about entities running the code … ?) – JAAS Applet System code JVM Browser http://javaday.bg/demoapplet grant principal javax.security.auth.x500.X500Principal "cn=Tom" { permission java.io.FilePermissions “C:Windows” “delete” } security.policy
  • 21. Evolution of the Java security model • JAAS (Java Authentication and Authorization Service) extends the security model with role- based permissions • The protection domain of a class now may contain not only the code source and the permissions but a list of principals
  • 22. Evolution of the Java security model • The authentication component of JAAS is independent of the security sandbox in Java and hence is typically used in more wider context (such as j2ee app servers) • The authorization component is the one that extends the Java security policy
  • 23. Evolution of the Java security model • Core classes of JAAS: – javax.security.auth.Subject - an authenticated subject – java.security.Principal - identifying characteristic of a subject – javax.security.auth.spi.LoginModule - interface for implementors of login (PAM) modules – javax.security.auth.login.LoginContext - creates objects used for authentication
  • 24. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: 1) upon system startup a security policy is set and a security manager is installed Policy.setPolicy(…) System.setSecurityManager(…)
  • 25. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: 2) during classloading (e.g. of a remote applet) bytecode verification is done and the protection domain is set for the current classloader (along with the code source, the set of permissions and the set of JAAS principals)
  • 26. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: 3) when system code is invoked from the remote code the SecurityManager is used to check against the intersection of protection domains based on the chain of threads and their call stacks
  • 27. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: SocketPermission permission = new SocketPermission("javaday.bg:8000- 9000","connect,accept"); SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission(permission);
  • 28. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: 4) application code can also do permission checking against remote code using a SecurityManager or an AccessController
  • 29. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: SocketPermission permission = new SocketPermission("javaday.bg:8000-9000", "connect,accept"); AccessController.checkPermission(permission)
  • 30. Evolution of the Java security model • Up to JDK 1.4 the following is a typical flow for permission checking: 5) application code can also do permission checking with all permissions of the calling domain or a particular JAAS subject AccessController.doPrivileged(…) Subject.doAs(…) Subject.doAsPrivileged(…)
  • 31. Evolution of the Java security model • The security model defined by java.lang.SecurityManager is customizable • For example: Oracle JVM uses a custom SecurityManager with additional permission classes where the code source is a database schema (containing e.g. Java stored procedures)
  • 32. Evolution of the Java security model • JDK 1.5, 1.6 (enhancing the model …) – new additions to the sandbox model (e.g. LDAP support for JAAS)
  • 33. Evolution of the Java security model • JDK 1.7, 1.8 (further enhancing the model …) – enhancements to the sandbox model (e.g. AccessController.doPrivileged() for checking against a subset of permissions)
  • 34. Evolution of the Java security model • JDK 1.9 and beyond … (applying the model to modules …) application module system module 1 JVM Browser http://javaday.bg/appmodule security.policy system module 2
  • 35. Evolution of the Java security model • By modules we understand modules in JDK as defined by project Jigsaw • Modules must conform to the same security model as applets – moreover each module is loaded by a different classloader – hence classes in different modules must have different protection domains
  • 36. Evolution of the Java security model • Modularization of the JDK system classes allows further to define fine-grained access control permissions for classes in the system domain • This is not currently allowed due to the monolithic nature of the JDK
  • 37. Outside the sandbox - APIs for secure coding
  • 38. Outside the sandbox - APIs for secure coding • The security sandbox defines a strict model for execution of remote code in the JVM • The other side of the coin are the security APIs that provide utilities for implementing the different aspects of application security …
  • 39. Outside the sandbox - APIs for secure coding • The additional set of APIs includes: – JCA (Java Cryptography Architecture) – PKI (Public Key Infrastructure) utilities – JSSE (Java Secure Socket Extension) – Java GSS API (Java Generic Security Services) – Java SASL API (Java Simple Authentication and Security Layer)
  • 40. Outside the sandbox - APIs for secure coding • JCA provides utilities for: – creating digital signatures – creating message digests – using cryptographic ciphers (symetric/asymetric, block/stream) – using different other types of cryptographic services and algorithms
  • 41. Outside the sandbox - APIs for secure coding • JCA has a pluggable architecture • JCA is independent from particular cryptographic algorithms • JCA continues to evolve (especially by providing stronger cryptographic algorithms)
  • 42. Outside the sandbox - APIs for secure coding • PKI utilities provide means for working with: – certificates – certificate revocation lists (CRL) – OCSP (Online Certificate Status Protocol) – key stores and trust stores (also based on the PKCS - public-key cryptography standards)
  • 43. Outside the sandbox - APIs for secure coding • PKI certificate revocation check (revision): • PKI utilities continue to evolve (especially in providing more support for managing certificates and keys) certificate authorityrevocation checking OCSP CRL certificate certificate
  • 44. Outside the sandbox - APIs for secure coding • JSSE provides an implementation of the TSL/SSL sockets for working with remote communication • JSSE continues to evolve (especially in the support for additional features such as Server Name Identication)
  • 45. Outside the sandbox - APIs for secure coding • Java GSS API provides an alternative of JSSE for secure communication • Java GSS API is a framework for providing token-based security services that is independent of the underlying protocols
  • 46. Outside the sandbox - APIs for secure coding • Java GSS API can be used along with JAAS for authentication purposes • Java GSS API continues to evolve (especially in the support for Kerberos authentication)
  • 47. Outside the sandbox - APIs for secure coding • Java SASL defines a protocol for exchange of authentication data • Java SASL is a framework where external providers give concrete semantics to the authentication data being exchanged
  • 48. Outside the sandbox - APIs for secure coding • Java SASL continues to evolve (especially with support for additional and enhanced properties for exchanging authentication data)
  • 49. Designing and coding with security in mind
  • 50. Designing and coding with security in mind • First of all - follow programing guidelines and best practices - most are not bound to the Java programming language (input validation, error handling, type safety, access modifiers, resource cleanup, prepared SQL queries and whatever you can think of …)
  • 51. Designing and coding with security in mind • Respect the SecurityManager - design libraries so that they work in environments with installed SecurityManager • Example: GSON library does not respect the SecurityManager and cannot be used without additional reflective permissions in some scenarios
  • 52. Designing and coding with security in mind • Grant minimal permissions to code that requires them - the principle of "least privilege" • Copy-pasting, of course, increases the risk of security flows (if the copied code is flawed)
  • 53. Designing and coding with security in mind • Sanitize exception messages from sensitive information - often this results in an unintended exposal of exploitable information • Let alone exception stacktraces … in many cases they convey a wealth of information about the system
  • 55. References • Java Security Overview (white paper) http://www.oracle.com/technetwork/java/js-white-paper- 149932.pdf • Java SE Platform Security Architecture Spec http://docs.oracle.com/javase/7/docs/technotes/guides/sec urity/spec/security-spec.doc.html • Inside Java 2 Platform Security, 2nd edition http://www.amazon.com/Inside-Java%C2%BF-Platform- Security-Implementation/dp/0201787911
  • 56. References • Java Security, 2nd edition, Scott Oaks http://shop.oreilly.com/product/9780596001575.do • Securing Java, Gary McGraw, Ed Felden http://www.securingjava.com • Secure Coding Guidelines for Java SE http://www.oracle.com/technetwork/java/seccodeguide -139067.html#0
  • 57. References • Java 2 Network Security http://www.amazon.com/JAVA-Network-Security-2nd- Edition/dp/0130155926 • Java Security Documentation http://docs.oracle.com/javase/8/docs/technotes/guides/ security/index.html
  • 58. References • Core Java Security: Class Loaders, Security Managers and Encryption http://www.informit.com/articles/article.aspx?p=118796 7 • Overview of Java Security Models http://docs.oracle.com/cd/E12839_01/core.1111/e1004 3/introjps.htm#CHDCEJGH

Editor's Notes

  • #16: The code source on the other hand contains the URL location, the list of signers and the list of certificates
  • #17: The code source on the other hand contains the URL location, the list of signers and the list of certificates
  • #18: The code source on the other hand contains the URL location, the list of signers and the list of certificates
  • #19: The code source on the other hand contains the URL location, the list of signers and the list of certificates
  • #20: The code source on the other hand contains the URL location, the list of signers and the list of certificates
  • #21: A typical scenario – in a single multiuser operating system we may have multiple users accessing the same applet from the browser – we may want to define permissions based on the currently logged-in user by providing integration with e.g. Kerberos (in case of a Windows OS)
  • #27: An AccessControlContext keeps the list of protection domains for the current thread
  • #28: An AccessControlContext keeps the list of protection domains for the current thread
  • #29: There are two main differences in using a SecurityManager and an AccessController: The SecurityManager needs to be installed while AccessController only provides static methods The SecurityManager can be customized while AccessController provides additional algorithms that can be used over the default security model
  • #30: There are two main differences in using a SecurityManager and an AccessController: The SecurityManager needs to be installed while AccessController only provides static methods The SecurityManager can be customized while AccessController provides additional algorithms that can be used over the default security model
  • #31: Calling code with a different JAAS subject is similar to the Unix setuid utility