Java Security & Error prevention Flashcards

1
Q

Druhy utoku (6)

A

DOS - denial of service
Code injection
Code corruption
Deserialization
Sensitive data leaks
Directory traversal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Java Security Descriptor - jmeno, co muze obsahovat(3), sample location + obsah

A

java.security
security policy files, cert keystore files, general settings

policy.url.1=file:${java.home}/conf/security/java.policy
policy.url.2=file:/someDir/java.policy

$JAVA_HOME/conf/security

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Java Security Policy Descriptor - jmeno, syntax:
povol pripojeni k localhost:7777
povol cteni a zapis do souboru abc.txt
pro kod z /lib.jar, pokud ma podpis “John and Joe”

A

grant codeBase “file:/lib.jar” signed “John and Joe” {
permission java.net.SocketPermission “localhost:7777”, “connect”;
permission java.io.FilePermission “abc.txt”, “read,write”;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Vytvor povoleni pro poslech localhost:7777, programatically
Zjisti, jestli mas povoleni
Co se stane, pokud ne?

A

SocketPermission sp = new SocketPermission(“localhost:7777”, “listen”);
AccessController.checkPermission(sp);
vyhodi se AccessControlException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Directory traversal - metody obrany (2)

A

path.normalize()
path.toRealPath(LinkOption)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Privilegovany kod - co to je
Syntax

A

pristup se nekontroluje, je proste povolen

AccessController.doPrivileged(new PrivilegedAction<T>() {
public T run() { ... }
})</T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Utok pri deserializaci - obrana

A

deserializuji jen trusted data
validace objektu po deserializaci

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DOS - obrana (5)

A

validace vstupu
omezeni pristupu ke kritickym zdrojum
vzdy po sobe uzavirej zdroje
timeouty dlouheho zpracovani
sledovani velikosti filu/streamu/narustu pozadavku

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Povoleni spusteni souboru file.exe, programaticcally - vytvor a checkni

A

FilePermission fp = new FilePermission(“file.exe”, “execute”);
try { AccessController.checkPermission(fp); } catch (AccessControlPermission e) { … }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Metoda pro numericke plus, ktere je citlive na preteceni
Jak se pozna preteceni?

A

Math.addExact(Integer.MAX, 1)
vyhodi se ArtithmeticException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Jak poznam, ze cislo je po operaci konecne?

A

Math.isInfinite(1/Integer.MAX)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Check, jestli je Double fakt ok po parsovani

A

!Math.isNaN(myDouble)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Osetreni, jestli Wrapper obsahuje cislo, tedy neni null

A

Optional<Double> o = ...
if (o.isPresent) Double d = o.get();</Double>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

SQL injection - osetreni, pokud nemuzu pouzit prepared statement nebo prepared callable

A

enquoteLiteral(param)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Scramble dat - hexadecimalni vystup - syntax pro SHA-256

A

MessageDigest md = MessageDigest.getInstance(“SHA-256”);
byte[] digest = md.digest(message.getBytes);
BigInteger hash = BigInteger.valueOf(digest).toString(16);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Sifrovani - ziskani klice a sifrovatka pro AES
pkg

A

SecretKey key = KeyGenerator.getInstance(“AES”).generateKey();
Cipher cipher = Cipher.getInstance(“AES/GCM/NoPadding”);

17
Q

Sifrovani - mam sifrovatko, jak zasifruji “password” do byte[]?

A

cipher.init(Cipher.ENCRYPT_MODE, key);
cipher.doFinal(“password”.getBytes());

18
Q

Sifrovani - mam sifrovatko, jak rozsifruji byte[] password?

A

cipher.init(Cipher.DECRYPT_MODE, key);
cipher.doFinal(password);