SSD Quiz 5

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/60

encourage image

There's no tags or description

Looks like no tags are added yet.

61 Terms

1
New cards

What is the main goal of cryptography?

To give the sender and receiver security like a secret pipe that only the two of them can use.

2
New cards

What is a random number generator and why does it matter?

It makes numbers that cannot be predicted better than by chance (P = 1/N). Random numbers are used as keys, so guessable numbers mean guessable keys.

3
New cards

Which Java class makes secure random numbers?

SecureRandom

4
New cards

What is symmetric encryption?

The same secret key encrypts and decrypts the data. Keeping the key private is critical. Example: AES.

5
New cards

What is asymmetric encryption?

A public/private key pair. Data encrypted with one key is decrypted with the other. Examples: RSA, DSA.

6
New cards

What does the Cipher class do and what does it protect?

Encrypts and decrypts data. Protects confidentiality.

7
New cards

What is a hash function?

Compresses input of any length into a short fixed-length output. Used to detect modification (integrity). Example: SHA-256.

8
New cards

Which Java class computes a hash?

MessageDigest

9
New cards

What is a MAC (Message Authentication Code)?

A digest computed with a secret key. Only someone with the key can verify the integrity of the data. Example: HmacSHA256.

10
New cards

Why is a plain hash not enough to stop an attacker?

The attacker can change the message and recompute the hash because it uses no secret. Without the key they cannot produce a valid MAC (soldiers example: 5K changed to 1K).

11
New cards

What is a digital signature?

Only the private key holder can create it; anyone with the public key can verify authenticity and integrity. Example: SHA256withDSA (Signature class).

12
New cards

What is a certificate?

A digital ID that contains a public key. A certificate chain links it to a trusted CA.

13
New cards

Where are keys and certificates stored in Java?

In a keystore (JKS, JCEKS, PKCS12).

14
New cards

Match the JCA classes to their jobs

SecureRandom = random numbers; Cipher = encrypt/decrypt; MessageDigest = hash; Mac = keyed hash; Signature = sign and verify.

15
New cards

What are the RSA steps?

1) N = p x q 2) m = (p-1)(q-1) 3) pick E with gcd(E, m) = 1 4) find D with E x D = 1 mod m 5) encrypt c = s^E mod N 6) decrypt s = c^D mod N

16
New cards

RSA exercise: p = 17, q = 19, E = 191, s = 25. Find N, m, D, c.

N = 323, m = 288, D = 95 (191 x 95 = 1 + 63 x 288), c = 25^191 mod 323 = 321. Check: 321^95 mod 323 = 25.

17
New cards

RSA slide example: p = 23, q = 29, E = 487. Find N, m, D.

N = 667, m = 616, D = 191. 25 encrypts to 169; 169 decrypts back to 25.

18
New cards

How does the SSL/TLS handshake (RSA suite) create the session key?

1) Server sends its certificate (public key) 2) Client verifies it with its TrustManager 3) Client makes random bytes with SecureRandom and encrypts them with the server's public key 4) Server decrypts with its private key 5) Both derive the symmetric key.

19
New cards

Name three common crypto errors

Insecure cryptosystems (DES, MD5); incorrect configurations; short keys; unsigned certificates; not verifying certificates.

20
New cards

Why not use the same key for a set of products?

If one key leaks, every product is compromised. Each product needs its own key.

21
New cards

What is wrong with srand(time(NULL)) then rand() to make a password?

rand() is not cryptographic and the seed is the time, which an attacker can guess, so the password is predictable. (Quiz 1 Q3)

22
New cards

Where should private keys not be stored?

In open locations like /tmp. Store them in a secure location.

23
New cards

What is taint analysis?

Tracks untrusted input from a source (e.g., request.getParameter) to a sink (e.g., executeQuery). Detects SQL injection.

24
New cards

Can taint analysis detect crypto API misuse? Why?

No. No untrusted input flows anywhere; the bug is how the crypto API is used (wrong algorithm, weak key, wrong call order).

25
New cards

What is wrong with Cipher.getInstance("DES/ECB/PKCS5Padding")?

DES has a short key and is breakable. ECB encrypts identical blocks identically, leaking patterns. Use AES with GCM.

26
New cards

What is wrong with Cipher.getInstance("AES") with no mode?

It defaults to ECB mode. Specify the mode, e.g., AES/GCM.

27
New cards

What is wrong with getRandomKey(192, 1873)?

The fixed seed 1873 makes the key predictable, effectively hardcoded.

28
New cards

What is wrong with the KeyDeriv code where algorithm = ""?

The algorithm is empty, so key derivation is undefined and cannot be verified. Set a strong algorithm explicitly.

29
New cards

Type vs typestate

Type: the set of operations ever permitted on an object. Typestate: the subset permitted in a particular context (state).

30
New cards

Typestate of a variable

Uninitialized -assign-> Initialized -read/update-> Initialized -finalize-> done

31
New cards

Typestate of KeyGenerator

0 -getInstance-> 1 -init-> 2 -generateKey-> 3, plus 1 -generateKey-> 3 (init is optional).

32
New cards

What is CrySL?

A language for writing rules that specify correct use of crypto APIs; a tool checks code against the rules.

33
New cards

Six parts of a CrySL rule

OBJECTS (variables), EVENTS (method calls), ORDER (allowed call sequence), CONSTRAINTS (allowed values), REQUIRES (predicates needed from other objects), ENSURES (predicate this object provides).

34
New cards

CrySL ORDER rule for KeyGenerator

GetInstance, Init?, GenKey (? means Init is optional)

35
New cards

Allowed AES key sizes in the CrySL rule

128, 192, 256

36
New cards

CrySL exercise: getInstance("AES"), init(64), generateKey(). Do ORDER and CONSTRAINTS hold?

ORDER holds. CONSTRAINTS fail: 64 is not in {128, 192, 256}. CrySL reports a misuse.

37
New cards

How do REQUIRES and ENSURES work together?

KeyGenerator ENSURES generatedKey; Cipher REQUIRES generatedKey, then ENSURES encrypted. A chain of promises across composed objects.

38
New cards

Allowed algorithms in the CrySL MessageDigest rule

SHA-256, SHA-384, SHA-512 (not MD5)

39
New cards

Limitation of static analysis for crypto misuse

isPrime(66) is always false so MD5 is never used, but the tool cannot evaluate it and reports MD5 anyway: a false positive.

40
New cards

Tools that detect crypto API misuse

Coverity, CrySL, CryptoGuard, SpotBugs

41
New cards

Study result on 2,324 Java projects

Only 642 used crypto securely; 1,682 were buggy.

42
New cards

What is an API?

Application Programming Interface: lets third-party systems use a system's capabilities.

43
New cards

Two API security issues and their fixes

Secure communication: SSL/TLS. Authorization: OAuth 2.0 (authorization code or client credentials).

44
New cards

What happens if an API uses plain http?

Anyone on the network can read or modify the data (e.g., name, card type, billing address).

45
New cards

What does curl -k do and why is it risky?

Skips certificate verification, so a man-in-the-middle can impersonate the server. Fix: --cacert ca.crt.

46
New cards

Why did curl reject certificate name foo for localhost?

The certificate subject name (CN) must match the host name.

47
New cards

What is mutual TLS?

Both server and client present certificates. Setting: server.ssl.client-auth: need.

48
New cards

Why use a token instead of giving an app your password?

Credentials give full, lasting access; a token is time-bounded and limited.

49
New cards

Four OAuth 2.0 roles

Resource owner (owns data), resource server (hosts data), client (app wanting access), authorization server (issues tokens).

50
New cards

Four OAuth 2.0 grant types

Client credentials; resource owner password; implicit; authorization code.

51
New cards

Which grant types are obsolete and why?

Password: the client sees the user's password. Implicit: no verification of client identity; token exposed in the URL.

52
New cards

When to use client credentials grant?

When the client owns the resources.

53
New cards

When to use authorization code grant?

When a user allows a client to use the user's resources.

54
New cards

Steps of the authorization code flow

1) Client redirects user to /authorize 2) User consents; server returns a code 3) Client sends code + client secret to /token 4) Server returns access token.

55
New cards

Three ways to send an access token

Authorization header (Bearer, best); query parameter; form body.

56
New cards

ApolloAuto: protect HD map updates

Vendor digitally signs maps; car verifies with vendor public key (integrity + authenticity).

57
New cards

ApolloAuto: stop fake CANBus commands

Add a MAC (HmacSHA256) with a per-vehicle secret key; spoofed messages fail the check.

58
New cards

ApolloAuto: keep car data private in transit

Use TLS, ideally mutual TLS.

59
New cards

ApolloAuto: phone app reading car status uses which grant?

Authorization code (user delegates access).

60
New cards

ApolloAuto: why a unique key per car?

One leaked key compromises only one car, not the whole fleet.

61
New cards