Sunteți pe pagina 1din 6

Java vs. .

Net Security: Comparative study


Vishan Singh1 Dr. Dharminder Kumar2
Department of Computer Science and Engineering
Guru Jambheshwer University of Science & Technology
Hisar (Haryana)-125001
1
vishansingh139@gmail.com
2
dr_dk_kumar_02@yahoo.com

Abstract collection of standard classes which must be present


Now a days many systems execute untrusted on any supported platform. Standard classes for file
programs (developed in either Java or .Net) in virtual and network I/O, graphical user interfaces and
machines (VMs) to limit their access to system advanced topics like encryption or database access
resources. Java is developed by Sun and .Net by allow many programs to run without bundled
Microsoft for this purpose. Both platforms share libraries.
many design and implementation properties, but The Java environment is called Java Runtime
there are key differences between Java and .NET that Environment (JRE), the .NET counterpart is Common
have an impact on their security. There are a lot of Language Runtime (CLR). Figure 1 shows the
papers that have been presented for comparing these conceptual architecture common to both
two technologies. The intention of this paper is to environments. The class loader is used to read byte
discuss Java and .Net at a high level from a security code from disk or other sources. The code is then
perspective, examining the tools and methodologies immediately checked for validity by the code verifier.
the platforms use to provide secure development and During runtime, the access controller ensures that
deployment environments. resources are protected. Byte code is called managed
code in .NET, to distinguish it from native code
Keywords: code safety, code access security, which executes directly on the CPU. The roles of
cryptography, communication, configuration, code those components are explained later.
protection, user authentication, user access security,
JAAS, IIS .

1. Introduction
Java and .NET are both platforms for
executing untrusted programs with security
restrictions. There can be many types of risks while
using these programs such as these programs can be
Malevolent, Intrusive, faked etc [1] .
Java is both a programming language and a
runtime environment. What C# is for .NET is the Java
language for the Java runtime environment. When
Java is mentioned here, think about the environment.
Both .NET and Java programs could be written in
different languages. While for the .NET platform,
compilers for many languages exist, for Java only few Figure 1. Virtual Machine
compilers for other languages exist1. A reason The VM interprets the code and executes the
why .NET has more compilers for different languages program2. The most direct consequence is that
might be the Common Type System (CTS), which Java / .NET programs are not platform specific. On
defines the standard types needed in a .NET language, whatever architecture the VM has been ported, any
and the precise specification of interoperation of program can be executed. While Java has been ported
programs with the Virtual Machine (VM). to about every platform from Mainframe to the more
Both Java and .NET programs are executed powerful PDA’s, .NET is only available for windows
by a Virtual Machine (VM) which emulates a well systems. To make matters worse, it is highly
specified platform. The source code is compiled into depending on other Microsoft products like the
so-called byte code for Java respectively into the Internet Information Server (IIS).
Microsoft Intermediate Language (MS-IL) for .NET. Many research works have been done on
The runtime environment consists of the VM and a this topic in the recent years. Nathanael Paul and

1
David Evans [1] does there work on this topic types. This makes the verification process in java
concentrating on code safety and polices used in both more complex.
platforms. David Buchmann [2] had worked on 2.2 Code access security:
permission management, language security and byte Code-access permissions represent
code language. Ger Mulcahy [16] has compared the authorization to access a protected resource or
architecture and cryptographic support of Java and perform a dangerous operation, and form a foundation
.Net. Eduardo B. Fernadez, Michael Thomsen, and of CAS. They have to be explicitly requested from the
Minjie H. Fernandez [9] have also compared the caller either by the system or by application code, and
architectures of Java and .Net in their paper. Denis their presence or absence determines the appropriate
Piliptchouk [10, 11, 12, 13] have given a series of course of action.
papers on java and .Net security. Permissions: Code-access permissions represent
authorization to access a protected resource or
2. Summary of work: perform a dangerous operation, and form a foundation
of CAS. They have to be explicitly requested from the
2.1 Low level code safety: caller either by the system or by application code, and
Low-level code safety comprises the their presence or absence determines the appropriate
properties of code that make it type, memory, and course of action. Both Java and .NET supply an
control-flow safe. Without these properties, sample choice of permissions for a variety of system
applications could circumvent nearly all high-level operations. The runtime systems carry out appropriate
security mechanisms. Type safety ensures that objects checks when a resource is accessed or an operation is
of a given type will be used in a way that is requested. .NET defines a richer selection here,
appropriate for that type [1] . Memory safety ensures providing permissions for role-based checks [13] and
that a program cannot access memory outside of evidence-based checks. Also, some of its permissions
properly allocated objects. Buffer overflow attacks reflect close binding between the .NET platform and
violate memory safety by overwriting other data by the underlying Windows OS (EventLogPermission,
writing beyond the allocated storage. Control safety RegistryPermission) [12]. These bindings of the
ensures that all jumps are to valid addresses. Without permissions of .Net with the windows OS is a weak
control safety, a program could jump directly to point for it.
system code fragments or injected code, thereby Polices: Code Access Security is evidence-based.
bypassing security checks. Each application carries some evidence about its
In both environments, the respective VM origin: location, signer, etc. This evidence can be
starts out with bytecode, which it verifies and discovered either by examining the application itself,
executes. The bytecode format is well known and can or by a trusted entity: a class loader or a trusted
be easily checked for potential violations, either at host(for further details see reference [12] ). A policy,
loading or at execution time. Some of the checks maintained by a system administrator, groups
include stack integrity, overflow and underflow, applications based on their evidence, and assigns
validity of bytecode structure, parameters' types and appropriate permissions to each group of applications.
values, proper object initialization before usage, Evidence for the .NET platform consists of various
assignment semantics, array bounds, type assembly properties [15].
conversions, and accessibility policies. Both Java and For Java, two types of code evidence are
CLS languages possess memory- (or type-) safety accepted by the JVM -- codebase (URL, either web or
property; that is, applications written in those local), from where it is accessed, and signer
languages are verifiably safe, if they do not use unsafe (effectively, the publisher of the code). Both
constructs (like calling into unmanaged code). After evidences are optional: if omitted, all code is implied.
studying deeply the verification process in both Policy links together permissions and evidence by
environments we found that JVM does not verify assigning proper rights to code, grouped by similar
local code by default. On the other hand, JVM always criteria [14].
preserves the bytecode stack for runtime checks, Policy-based security causes problems for
while .NET relies on a combination of static analysis applets. It's unlikely that a web site's users will be
and injection of verification code at runtime. editing their policy files before accessing a site. Java
Now if the instruction sets of both languages does not allow runtime modification to the policy, so
is compared then one main difference between the the code writers (especially applets) simply cannot
instruction sets is that JVML has separate versions of obtain the required execution permissions. IE and
instructions for each type, whereas .NET uses a single Netscape have incompatible (with Sun's JVM, too!)
instruction to perform the same operation on different approaches to handling applet security. JavaSoft's
Java plug-in is supposed to solve this problem by

2
providing a common JRE, instead of the browser- Now for running the unsafe code a sandbox
provided VM. If the applet code needs to step outside is used for both java and .Net. The .NET sandbox is
of the sandbox, the policy file has to be edited called application domain. It is fixed when the
anyway, unless it is an RSA-signed applet. Those program is started. Additional assemblies are loaded
applets will either be given full trust (with user's only loaded from the same application domain, so the
blessing, or course), or if policy has an entry for the initial policy can always be used. To use code from
signer, it will be used [14]. other domains, .NET remoting has to be used. The
Policy in .NET has a much more Java protection domain is dynamic. For each access,
sophisticated structure than in Java, and it also works the currently valid protection domain is determined.
with many more types of evidences. Java defines very As long as the same class loader loaded them, classes
flexible approach to adding and overriding default can use other classes directly. Only between different
policies -- something that .NET lacks completely class loaders, RMI is needed. While the Java
[12]. approach is more flexible, it is also more complicated.
This results in a speed penalty and may lead to
2.3 Language Security: implementation errors, opening security holes in the
The programming languages provide sandbox.
important security features. Most important are the Both Java with the Java Native Interface
public / protected / private and final modifiers for (JNI) and .NET with Platform Invoke (PInvoke)
fields and methods. A class can contain sensitive data allow the execution of code running directly on the
that might not be accessed by other classes. For processor. This is important for projects to integrate
example, think of an applet requiring a valid credit with existing libraries not written in a language
card number before processing. To save the state, a supported by the VM. But the VM can not verify
private field has Paid is set to true. If the protection what that code does. It gives up control to the native
would not be enforced, you could write code to set the code which can do whatever it wants, allowing for all
field to true. If “final” would not be enforced at the security issues discussed above to be violated.
runtime, you could overwrite some important method. Because of this, access to native libraries should not
Now we discuss the problems with pointers be granted to untrusted code. The JNI is not often
used in the code. A pointer is just the address of a used. The C# language however makes it simple to
memory cell. It can be used to read or write to mangle safe code with none-safe sections, by just
arbitrary cells. Other than spying on private data and specifying the PInvoke keyword. The .NET
destroying data, a malicious program with direct framework uses the term “unmanaged code” for such
access to memory can make the CPU execute native code, to emphasize that the VM has no control
uncontrolled code by writing it at the appropriate over it(for more details see reference [2]).
location.
Neither Java nor normal .NET code can 2.4 Security Configuration:
therefore use pointers and operate directly on the Configuration on both platforms is handled
memory. This way, the Virtual Machine (VM) can through XML or plain-text files, which can be
avoid that a process could gain access to memory modified in any text editor, or through the supplied
sections other than its own. In C, arrays are just tools. However, the platforms differ significantly in
pointer to a memory segment. In C# and Java, arrays how they handle configuration hierarchies.
contain a mandatory boundary check for any access. In the .NET world, Mscorcfg.msc and
The VM tests if casts are possible and throws Caspol.exe can be used to modify all aspects of
an exception on any illegal cast attempt. The VM security configuration. On the other hand, Caspol.exe
must prevent stack corruption too, as this again could provides a number of command-line options,
provide access to protected areas like private member appropriate for use in scripts and batch routines.
fields of other classes. Local variables may not be Here's how it would be used to add full trust to an
used uninitialized, member variables are always assembly: caspol -af MyApp.exe.
initialized to zero. Java platform provides a single GUI-based
To enforce as much of those requirements tool, policytool.exe for setting code- and Principal-
and language features, the byte code verifier is used. based security policies. This tool works with arbitrary
When a VM loads code, it is first passed through the policy files (as long as they are in the proper format),
verifier to check the security properties and any code as opposed to .NET, where names and locations of the
violating them is rejected. Such verified code which configuration files are fixed (see Reference [10]).
executes under the control of the VM is called J2SE does provide significant runtime
“managed code” in .NET [2] . flexibility by using a number of command-line
application parameters, which allow the caller, on a

3
per-application basis, to set keyfiles, trust policy, and
extend the security policy. By allowing command-line 2.6 Secure Communication:
JVM parameters, Java provides a significantly more Data has to be exchanged over the network,
flexible and configurable environment, without which is termed as communication. In both java
conflicts among multiple JVM installations. and .Net there are various mechanisms for this. In this
part we will discuss on these mechanisms.
2.5 Cryptography: During transmission, data can be protected
Once an application steps out of the bounds on three levels: hardware, platform, and application.
of a single-computer box, its external communication These can be used independently, or combined for
is immediately exposed to a multitude of outside better results. In all cases, there is some kind of
observers with various intentions, their interests cryptographic protection applied to the data prior to
ranging from employers scanning the list of web sites communication, but the amount of required
an employee visits to business spies looking for a application code and its complexity increases, with
company's "know-how." In order to protect sensitive application-level solution being the most involved.
data while it is en route, applications invoke different While wire-level protocols (IPSec, for instance) may
methods, most often with some kind of cryptographic be implemented at the hardware level for speed and
protection applied to the data before transmitting it. efficiency, they are not discussed in this article in
Cryptography in .NET is based to a large order to keep the primary focus on the platforms
extent on the Windows CryptoAPI (CAPI) service, themselves.
with some extensions. Many algorithms are In case of .Net all the security while
implemented as managed wrappers on top of CAPI, communication depends mainly on the IIS, Non-IIS
and the key management system is based on CAPI applications have no means for protecting there data
key containers. However, .NET's Cryptography on route. The Java platform offers Java Secure Socket
service is more than just a managed wrapper -- it Extensions (JSSE) as a platform-level service for
extends the CAPI in a number of ways. First, it is securing TCP/IP-based communication in vanilla
highly configurable and allows adding custom J2SE applications, and J2EE's servlet specifications
algorithm implementations in the machine.config file. declare options for configuring SSL protection and
Second, .NET uses a stream-based model, where all refusing unprotected connection attempts.
cryptographic transformations (except for asymmetric So after studying a lot on this it is found that
algorithms) are always performed on streams. Third, besides IIS, .NET does not offer any standard means
the defaults for all algorithms are configured to the for communication protection at the platform level,
strongest and safest settings (subject to Windows OS while Java has a complete solution in this space. On
encryption settings, though), so the default objects the other hand at the application level The .NET
that the user receives are most secure from what his platform stays very current with the latest
Windows encryption settings allow [11]. developments in web services security, while their
The Java platform's cryptography support support in Java is not standardized and is limited to
has two parts to it: Java Cryptography Architecture offerings from individual vendors.
(JCA) and Java Cryptography Extension (JCE), which Now after studying deeply over
were separated (due to US export restrictions) to gain communication security provided by both platforms it
exportability for the Java platform. All cryptography is concluded that Java fares much better by providing
functions, which are subject to export laws, have been a choice of both platform and application-level
moved to JCE. A number of industry standard solutions, it clearly lags behind .NET. When it comes
cryptographic algorithms(Symmetric, Asymmetric, to support for web services security, here, Java
Hashes, Signatures, PBE) and stream /block ciphers developers would have to turn to independent vendors
are available for both platforms. with default for the desired features.
installations. There are quite a few independent Java
vendors who offer even better selection than Sun's 2.7 Code protection:
defaults. The possibility of the reverse engineering of
Both java and .Net provides good distributed bytecodes needs to be taken into account
configurability. In the coding of .Net if the name of when planning the security aspects of an application,
the algorithm is not given then it takes it by default. because bytecode formats are well-documented for
On the other hand in java provides name as well as both Java and .NET (see also GotDotNet), so any
additional algorithm details as default. Defaults for hardcoded data or algorithms may be easily restored
algorithm names are a convenient feature in .NET. with readily obtainable decompiling tools. While
Java, on the other hand, allows specifying additional there is no ideal way around this issue, short of
algorithm details besides the name. shipping encrypted code and providing just-in-time

4
decryption, an average perpetrator's task may be made solution (for instance, biometric readers), which is
harder by using so called obfuscators; i.e., tools that outside of the scope of this paper.
intentionally scramble bytecodes by using .NET includes a web solution for the server
unintelligible names and moving entry points around. side: ASP.NET, which is coupled with IIS for
Finally, OS-level protection mechanisms need to be processing HTTP requests (for details see reference
utilized, along with the platform ones, in order to [13]). The Java platform defines two solutions for
ensure good protection of the stored data [12]. user authentication to the servers: JAAS and servlets.
At first we discuss certificate management as Although EJB does not have its own authentication
a mechanism for both java and .Net platforms. First of facilities [14]. Java servlets is the Java platform's
all, certificates need to be created and stored, and then HTTP-oriented server layer, which performs HTTP
accessed from the applications. Both platforms supply processing functions similar to those of the ASP.NET
tools to issue certificate requests, as well as APIs for layer [14]. Correspondingly, the servlet's security
accessing the stored certificates. model is intended specifically to handle the
.NET, as usual, heavily relies on Windows requirements of web applications. JAAS may be used
certificate stores to deal with certificates — they are to add authentication and authorization to any Java-
used to store X509 certificates and certificate chains based application (executable, bean, applet, etc) [14].
of trusted signers. There are a number of tools In both systems, a principle and his identity (or
included with the .NET SDK to help accessing those identities) are established as a result of the
stores, manage certificates, and sign assemblies using authentication process, which serve to represent the
those certificates. user in the application during his further requests.
The Java platform implements RFC 3280 in Now in case of web services .NET delegates
the Certification Path API, which is supplied in the all types of user authentication (except for forms) to
default "SUN" provider. This API, however, allows IIS, and barely consumes the results. J2EE requires
read-only — retrieving, accessing attributes, etc. — support for all standard authentication mechanisms
access to certificates, because they are considered to from the compliant servers. .NET provides good
be immutable entities in Java. Classes implementing support for impersonation on Windows-only
Certification Path API, belong to the JCA framework networks, but delegation across the Internet is not
and can be found in the java.security.cert package possible. Java can do application-level impersonation
(See Reference [12]). Becoming a Certificate and is capable of supporting delegation across the
authority is problematic but not impossible for java. Internet.
One can either purchase a commercial library, or Finally it is concluded that .NET suffers
build his or her own CA using sun.security.x509 from tight integration with IIS, without which it is not
classes, although they only work with JKS keystores. really capable of performing authentication. In terms
However, the latter solution is neither portable nor of access control, it does provide a convenient
documented. There are also a number of open source mechanism that meshes nicely with its CAS features.
libraries that allow you to deal with certificate
management, including CA functionality. 2.9 User access security:
Java provides a solid API for dealing with Once a distinguished principle has been
certificates. .NET programmers have to turn to identified as a result of the authentication step and
unmanaged CAPI functions to access certificates, attached to the call context (usually associated with
unless they use WSE, which adds a lot of useful threads), it can be used in determining resource access
functionality. rights. In role-based systems, application code may
operate not only with specific principals, but also with
2.8 User Authentication: their abstract roles, which results in a more flexible
The process of authentication starts right system configuration. So after establishing a
after identification by collecting caller credentials, principle, the server goes through an additional step
confirming the identity claim, and securely of mapping it to the possible application roles. .NET
communicating them to the server. Those credentials has a very convenient, permission-based user access
(possibly several types of them, so it's called multi- system. However, it can only restrict the total
factor authentication) are matched against the permission set for an assembly, never extend it. JAAS
registered account information and a positive or makes use of dynamic policies in Java to extend a
negative answer is returned regarding the claimed granted permission set with user-specific permissions.
identity. To do this work, application developers can For extended access checks, both systems
either utilize standard platform facilities, as described provide an adequate level of declarative support. Java,
below, or roll out some custom authentication in addition to the standard authentication types, offers
the powerful JAAS mechanism as its primary vehicle

5
for adding authentication and Principal-based .NET. University of Fribourg, Switzerland,
authorization to Java applications, which adds a lot of Department of Informatics, Software
flexibility to the design choices. Engineering Group, May, 2003.
http://diuf.unifr.ch/softeng/
3. Conclusion: [3] Frank Yellin. Low Level Security in Java. 4th
Java and .Net are two comparable platforms, International WWW Conference, December
very similar to each other. In this paper we have tried 1995.
to compare .Net and Java platforms and to find out [4] David Evans and Andrew Twyman. Policy-
differences between them with regards to security. Directed Code Safety. IEEE Symposium on
In case of code containment both platforms Security and Privacy. May 1999.
have pretty strong offerings, with .NET having [5] Sun Microsystems. Permissions in the Java 2
slightly more choices and being more straightforward SDK. http://java.sun.com/j2se/1.4.2/docs/guide/
to use. security/permissions.html
CAS features in .NET are significantly better [6] .NET Framework Developer’s Guide.
than the ones Java can offer, with a single exception Permissions.
-- flexibility. Java, as it is often the case, offers ease http://msdn.microsoft.com/library/
and configurability in policy handling that .NET default.asp?url=/library/en-
cannot match. us/cpguide/html/cpconpermissions.asp
In Java language security features as [7] Microsoft Corporation. Technology Overview.
discussed above are more secure then .net, on the http://msdn.microsoft.com/netframework/
other hand .Net provides more functionality then java. previous/v1.0/overview/default.aspx
In case of security configuration java offers a [8] Scott Oaks. Java Security 2nd Edition.
lot of advantages then .Net discussed above. O’Reilly, 2001.
Both platforms come out pretty even in [9] Eduardo B. Fernadez, Michael Thomsen, and
terms of cryptographic features, although Java has a Minjie H. Fernandez, Comparing the
more complicated solution due to the obsolete US Security architectures of Sun ONE and
export restrictions. Microsoft .NET. Department of Computer
In case of communication protection -- while Science and Engineering,
Java fares much better by providing a choice of both Florida Atlantic University.
platform and application-level solutions, it clearly [10] Denis Piliptchouk. Java vs .NET Security, Part
lags behind .NET when it comes to support for web 1 Security Configuration and Code
services security. Containment. Nov, 2003.
While code protection came out more or less [11] Denis Piliptchouk. Java vs .NET Security, Part
even, CAS features in .NET are significantly better 2: Cryptography and
than the ones Java can offer, with a single exception Communication. Dec. 2003.
-- flexibility. [12] Denis Piliptchouk. Java vs .NET Security, Part
We now come to the point of user 3: Code Protection and Code Access
authentication .NET suffer from tight integration with Security (CAS). Jan., 2004.
IIS, without which it is not really capable of [13] Denis Piliptchouk. Java vs .NET Security, Part
performing authentication. In terms of access control, 4: User Authentication and
it does provide a convenient mechanism that meshes Authorization. Feb 2004.
nicely with its CAS features. [14] J2EE Security, for servlets, EJBs and web
At last we come to the point of user access services, Pankaj Kumar, Pearson Education.
security Java, in addition to the standard [15] .Net Framework Security, Brian A. Lamacchia,
authentication types, offers the powerful JAAS Sebastion, Mathew Lyons, Rudi Martin,
mechanism as its primary vehicle for adding Kevin T Price, Pearson Education(Asia).
authentication and Principle-based authorization to [16] Ger Mulcahy, J2EE and .Net security. Feb
Java applications, which adds a lot of flexibility to the 2002.
design choices.

4. References:
[1] Nathanael Paul, David Evans. Comparing
Java and .NET Security. University of
Virginia, Department of Computer
Science. [nate, evans]@cs.virginia.ed
[2] David Buchmann. Basic Security: Java vs.

S-ar putea să vă placă și