JAVA NÂNG CAO
(Advanced Java)
Java security
Outline
● Components of Java
● Java security models
● Main components of the Java security
architecture
– class loaders
– bytecode verification
– the Security Manager
● DSA authentication algorithm
● RSA encryption algorithm
2
Components of Java
● the development environment
– development lifecycle
– Java language features
– class files and bytecode
● the execution environment
– the Java Virtual Machine (JVM)
● interfaces and architectures
– e.g., Java beans, RMI, JDBC, etc
3
Development lifecycle
4
Java language features
● object-oriented
● multi-threaded
● strongly typed
● exception handling
● very similar to C/C++, but cleaner and simpler
– no more struct and union
– no more (stand alone) functions
– no more multiple inheritance
– no more operator overloading
– no more pointers
● garbage collection
– objects no longer in use are removed automatically
5
Class files
● contain
6
The Java Virtual Machine (JVM)
●
7
The Java Virtual Machine (JVM)
●
8
The Java Virtual Machine (JVM)
●
9
The Java Virtual Machine (JVM)
●
10
The Java Virtual Machine (JVM)
●
11
The Java Virtual Machine (JVM)
●
12
Java security models
● the need for Java security
● the sandbox (Java 1.0)
● the concept of trusted code (Java 1.1)
● fine grained access control (Java 2)
13
The need for Java security
● code mobility can be useful (though not
indispensable)
– may reduce bandwidth requirements
– improve functionality of web services
● but downloaded executable content is dangerous
14
The sandbox
15
The concept of trusted code
16
Fine grained access control
17
The three pillars of Java security
● the Security Manager
● class loaders
● the bytecode verifier
18
The Security Manager
19
The Security Manager
20
Class loaders
21
Class loading process
22
Class loading task delegation
23
Bytecode verifier
24
DSA authentication algorithm
● To understand digital signatures, we need to understand
the concept of public encryption
● Public encryption is based on two concepts: public key and
private key
● The public key can be known to everyone
● The private key is known only to the person who holds it
● These two keys have a mathematical relationship with each
other, but it is impossible to find the other key from one key
● We will learn how to use the DSA algorithm to generate
public - private key pairs and how to use them to
authenticate information.
25
DSA authentication algorithm
● The sender creates a public-private key pair using DSA
algorithm
KeyPairGenerator keygen = [Link]("DSA");
[Link](512, new SecureRandom());
KeyPair keys = [Link]();
● The public key is sent to the receiver
PublicKey pubkey = [Link](); //Gởi cho người nhận
● The sender uses the private key to authenticate the message
PrivateKey privkey = [Link]();
Signature signalg = [Link]("DSA");
[Link](privkey);
String message = "Mua thu vang hoa cuc"; //Gởi cho người nhận
[Link]([Link]());
byte[] signature = [Link](); //Tạo chữ ký số gởi cho người nhận
26
DSA authentication algorithm
● The message is sent to the receiver
● The receiver uses the public key to check authentication on
the message
● If the authentication is OK, it ensures the sender is correct
and the message content has not been changed
Signature verifyalg = [Link]("DSA");
[Link](pubkey);
[Link]([Link]());
if()
[Link]("Not ");
[Link]("Signed with private key");
27
DSA authentication algorithm
28
RSA encryption algorithm
● The public - private key pair is also used to encrypt and
decrypt information
● The process of using the RSA algorithm to generate public -
private key pairs and use them includes the following steps:
● The receiver of the information uses the RSA algorithm to
generate a public - private key pair
● The receiver sends the public key to the sender
● The sender uses the public key to encrypt the information to
be sent
● The receiver uses the private key to decrypt the received
message and display it
29
RSA encryption algorithm
● The receiver creates a public-private key pair using RSA
algorithm
KeyPairGenerator kpg = [Link]("RSA");
[Link](2048, new SecureRandom());
KeyPair kp = [Link](); //Người nhận tạo cặp khóa
● The public key is sent to the sender
PublicKey pubKey = [Link]();
● The sender uses the public key to encrypt the message
String msg = "Mua thu vang hoa cuc";
Cipher c = [Link]("RSA");
[Link](Cipher.ENCRYPT_MODE, pubKey);
byte encryptOut[] = [Link]([Link]());
//[Link].Base64
String strEncrypt = new String([Link]().encode(encryptOut));
30
RSA encryption algorithm
● The encrypted message is sent to the receiver
● The receiver uses the private key to decrypt the
encrypted message
Cipher c = [Link]("RSA");
PrivateKey priKey = [Link]();
[Link](Cipher.DECRYPT_MODE, priKey);
byte decryptOut[] = [Link]([Link]().decode(strEncrypt));
● Displays the decrypted message
[Link](“Result: " + new String(decryptOut));
31
RSA encryption algorithm
32
33
Thank you!