Proper Use of Cryptography Never write your own crypto functions if - - PowerPoint PPT Presentation

proper use of cryptography
SMART_READER_LITE
LIVE PREVIEW

Proper Use of Cryptography Never write your own crypto functions if - - PowerPoint PPT Presentation

Proper Use of Cryptography Never write your own crypto functions if you have any choice Another favorite piece of advice from industry Never, ever, design your own encryption algorithm Unless thats your area of expertise


slide-1
SLIDE 1

Lecture 14 Page 1 CS 236 Online

Proper Use of Cryptography

  • Never write your own crypto functions if you have

any choice – Another favorite piece of advice from industry

  • Never, ever, design your own encryption

algorithm – Unless that’s your area of expertise

  • Generally, rely on tried and true stuff

– Both algorithms and implementations

slide-2
SLIDE 2

Lecture 14 Page 2 CS 236 Online

Proper Use of Crypto

  • Even with good crypto algorithms (and

code), problems are possible

  • Proper use of crypto is quite subtle
  • Bugs possible in:

– Choice of keys – Key management – Application of cryptographic ops

slide-3
SLIDE 3

Lecture 14 Page 3 CS 236 Online

An Example

  • An application where RSA was used to

distribute a triple-DES key

  • Seemed to work fine
  • Someone noticed that part of the RSA

key exchange was always the same – That’s odd . . .

slide-4
SLIDE 4

Lecture 14 Page 4 CS 236 Online

What Was Happening?

  • Bad parameters were handed to the RSA

encryption code

  • It failed and returned an error
  • Which wasn’t checked for

– Since it “couldn’t fail”

  • As a result, RSA encryption wasn’t applied

at all

  • The session key was sent in plaintext . . .
slide-5
SLIDE 5

Lecture 14 Page 5 CS 236 Online

Another Example

  • Many pieces of malware use cryptography
  • RC4 is a frequent choice of cipher

– Seems easy and fast

  • So the hackers implement it themselves
  • Which often gives the defenders advantages
  • Because the hackers screw it up
  • Being evil doesn’t necessarily make you

smart

slide-6
SLIDE 6

Lecture 14 Page 6 CS 236 Online

Trust Management

  • Don’t trust anything you don’t need to
  • Don’t trust other programs
  • Don’t trust other components of your

program

  • Don’t trust users
  • Don’t trust the data users provide you
slide-7
SLIDE 7

Lecture 14 Page 7 CS 236 Online

Trust

  • Some trust required to get most jobs done
  • But determine how much you must trust the
  • ther

– Don’t trust things you can independently verify

  • Limit the scope of your trust

– Compartmentalization helps

  • Be careful who you trust
slide-8
SLIDE 8

Lecture 14 Page 8 CS 236 Online

Two Important Lessons

  • 1. Many security problems arise

because of unverified assumptions – You think someone is going to do something he actually isn’t

  • 2. Trusting someone doesn’t just mean

trusting their honesty – It means trusting their caution, too

slide-9
SLIDE 9

Lecture 14 Page 9 CS 236 Online

Input Verification

  • Never assume users followed any rules

in providing you input

  • They can provide you with anything
  • Unless you check it, assume they’ve

given you garbage – Or worse

  • Just because the last input was good

doesn’t mean the next one will be

slide-10
SLIDE 10

Lecture 14 Page 10 CS 236 Online

Treat Input as Hostile

  • If it comes from outside your control

and reasonable area of trust

  • Probably even if it doesn’t
  • There may be code paths you haven’t

considered

  • New code paths might be added
  • Input might come from new sources
slide-11
SLIDE 11

Lecture 14 Page 11 CS 236 Online

For Example

  • Shopping cart exploits
  • Web shopping carts sometimes

handled as a cookie delivered to the user

  • Some of these weren’t encrypted
  • So users could alter them
  • The shopping cart cookie included the

price of the goods . . .

slide-12
SLIDE 12

Lecture 14 Page 12 CS 236 Online

What Was the Problem?

  • The system trusted the shopping cart cookie when

it was returned – When there was no reason to trust it

  • Either encrypt the cookie

– Making the input more trusted – Can you see any problem with this approach?

  • Or scan the input before taking action on it

– To find refrigerators being sold for 3 cents

slide-13
SLIDE 13

Lecture 14 Page 13 CS 236 Online

Variable Synchronization

  • Often, two or more program variables

have related values

  • Common example is a pointer to a

buffer and a length variable

  • Are the two variables always

synchronized?

  • If not, bad input can cause trouble
slide-14
SLIDE 14

Lecture 14 Page 14 CS 236 Online

An Example

  • From Apache web server
  • cdata is a pointer to a buffer
  • len is an integer containing the

length of that buffer

  • Programmer wanted to get rid of

leading and trailing white spaces

slide-15
SLIDE 15

Lecture 14 Page 15 CS 236 Online

The Problematic Code

while (apr_isspace(*cdata)) ++cdata; while (len-- >0 && apr_isspace(cdata[len])) continue; cdata[len+1] = ‘/0’;

  • len is not decremented when leading white spaces are

removed

  • So trailing white space removal can overwrite end of buffer

with nulls

  • May or may not be serious security problem, depending on

what’s stored in overwritten area