WEBVTT

00:00.000 --> 00:04.280
Our next speaker is Guy.

00:04.280 --> 00:07.280
I'm not gonna try to pronounce his last name.

00:07.760 --> 00:09.420
He told me not to do that.

00:09.420 --> 00:10.120
Okay.

00:11.000 --> 00:15.360
He's B-Sides Tel Aviv chairman and CTF lead.

00:15.360 --> 00:20.760
Also a public speaker and recipient of the Cisco Black Belt Security Ninja.

00:20.760 --> 00:21.900
That's nice.

00:22.060 --> 00:26.420
With nearly 20 years of experience in cyber security industry.

00:26.860 --> 00:29.800
Currently providing security services.

00:29.800 --> 00:35.800
Focusing on OS, hardening, crypto, AI and reverse engineering.

00:35.820 --> 00:40.680
And he's going to talk about crypto failures and how to avoid them.

00:40.680 --> 00:43.120
Give him a round of applause please.

00:47.370 --> 00:49.250
Thank you very much.

00:49.250 --> 00:51.110
Can you hear me in the back?

00:51.110 --> 00:53.830
Because I tend to walk about so I'll take the mic.

00:53.830 --> 00:55.790
But if not I'll just speak very loudly.

00:56.790 --> 00:57.270
Okay.

00:57.270 --> 01:00.250
So welcome to my talk about crypto failures.

01:00.250 --> 01:02.810
Before I begin I just want to say one thing.

01:02.810 --> 01:06.970
I'm not dissing anyone who's actually developing and using crypto libraries.

01:06.970 --> 01:12.350
But I do want to point out several failures that I have seen happen over and over again.

01:12.350 --> 01:19.730
And try to give you those patterns and some tools and some ideas of what to do when you encounter such issues or such things.

01:19.730 --> 01:28.370
But I also wanted to make this talk let's say entertaining and show you a couple of well at least for me and probably for others pretty funny failures.

01:28.370 --> 01:30.950
Some of them of very large extent.

01:31.250 --> 01:34.070
So said so.

01:34.070 --> 01:34.710
Okay.

01:40.500 --> 01:41.700
This should work.

01:41.800 --> 01:42.180
Okay.

01:42.180 --> 01:50.640
So as I was so kindly introduced I'm besides Tel Aviv chairman I also do the CTF.

01:50.720 --> 01:55.500
I invite you all to come to us to sunny Tel Aviv in June for a pretty nice conference.

01:57.820 --> 02:00.800
I'm here and I've been here for quite a while .

02:00.800 --> 02:03.560
I've seen a couple of different things in different areas.

02:03.560 --> 02:04.960
I've managed a cryptographer.

02:04.960 --> 02:06.280
I manage developers.

02:06.280 --> 02:07.640
I manage reverse engineers.

02:07.640 --> 02:11.280
And some patterns tend to emerge again and again.

02:11.520 --> 02:13.480
So I want to focus on that.

02:13.480 --> 02:18.980
The first thing and probably the most important thing is crypto is math and that kind of scares a lot of people.

02:19.100 --> 02:29.680
And I'll try to give you like a first introduction to what cryptography actually is without going into the math because obviously most people don't really care.

02:29.680 --> 02:40.280
But more than that I want you to give to get like a very at least fundamental understanding of what you should expect and when you don't see that it should light a red flag.

02:40.280 --> 02:42.100
So I'll give you a couple of examples.

02:42.540 --> 02:50.540
So you probably are already familiar with the CIA confidentiality integrity and availability concepts from other perspectives.

02:50.540 --> 02:52.580
This is also true for cryptography.

02:52.680 --> 02:57.200
So when we're saying confidentiality and talking about cryptography, it means we want to keep things secret.

02:57.200 --> 03:05.540
We want to have some sort of method, some sort of idea or function that if we know the secret, then we will know what this payload contains.

03:05.540 --> 03:09.980
And if no one else knows that secret, nobody else can know what this secret contains.

03:10.120 --> 03:11.420
Identity comes to the same thing.

03:11.420 --> 03:18.700
We want to make sure that if someone sends us the message, we can verify that we got the message from that person or that system and not from someone else.

03:18.860 --> 03:20.300
Phishing comes to mind.

03:20.720 --> 03:22.340
The third one is authenticity.

03:22.340 --> 03:25.800
Can we trust that nobody touched that message or modified that message?

03:25.800 --> 03:32.420
Did we actually get the same message that the sender sent us or was somebody messing around with it along the way?

03:33.560 --> 03:37.540
This is kind of a personal point for me, but I'm not ashamed to mention it.

03:37.540 --> 03:43.760
One of the teams I led when I was at Cisco was in charge of an area called supply chain security.

03:44.040 --> 03:51.260
So I was the very happy owner of that specific area of responsibility when Snowden releases documents.

03:51.620 --> 03:59.560
If you remember the nice image of NSA intercepting Cisco equipment and doing supply chain attacks, that was fun.

04:00.060 --> 04:03.420
And my point is, is that authenticity is important.

04:03.420 --> 04:14.980
When you're dealing with a product, with a vendor, with a library, you want to make sure that what you're getting is what actually the developer or the system actually intended you to receive.

04:14.980 --> 04:28.600
If you remember the NPM dependency issue, I don't remember, about a year ago more or less, somebody decided that he doesn't like the left line string to maintain that anymore, he kind of dropped that, everything broke.

04:29.220 --> 04:39.460
Somebody put some malicious code or stuff like that into the dependencies of NPM and now everybody got the same kind of libraries along the way.

04:39.460 --> 04:40.800
This is something you need to think about.

04:40.800 --> 04:42.380
It's something you need to be aware of.

04:42.380 --> 04:43.540
So it's an issue.

04:44.860 --> 04:49.340
Usually when people talk about cryptography, they kind of think that everything is the same.

04:49.340 --> 04:50.300
And it's not the same.

04:50.300 --> 04:58.540
When we're talking about hashes, for example, one of the common things that I hear is that I've encrypted with SHA-1 or encrypted with SHA-512.

04:59.240 --> 05:00.080
Well, not.

05:00.080 --> 05:01.840
You did not encrypt the SHA.

05:01.840 --> 05:05.540
A hash function has only one job.

05:05.540 --> 05:10.540
Taking lots and lots of information, boiling it down and getting a very short piece of information.

05:10.540 --> 05:12.500
But that's also true for checksums.

05:12.600 --> 05:17.740
So if you write CRC32 or something similar, you get the same concept.

05:17.740 --> 05:22.920
You process a lot of information, you get some validating code at the end.

05:22.940 --> 05:28.860
However, CRC32 and SHA and other constructs are not the same.

05:28.860 --> 05:33.960
Because cryptographic hashes, which is a specific type of hashes, try to give you a guarantee.

05:34.020 --> 05:40.280
They try to give you that if you change one bit in the input, you'll get a dramatically different output.

05:40.280 --> 05:42.360
More than 50% of it should be different.

05:42.380 --> 05:45.500
And if it's not the case, this is a very bad function to use.

05:45.500 --> 05:49.540
Because that means that an attacker can now use that to find collisions.

05:49.540 --> 05:53.240
Collisions meaning find a different message that will give him the same output.

05:53.400 --> 05:55.680
So short story.

05:55.900 --> 06:01.680
MD5, for those of you who are familiar with it, used to be a very common hashing algorithm way back when.

06:01.820 --> 06:15.040
And a couple of years ago in Black Hat, if I remember correctly, I don't remember her name, but a researcher from China, if I remember correctly, showed a way to find collisions in MD5.

06:15.040 --> 06:23.100
And what happened, immediately you can actually generate whatever you want to get the same kind of MD5 hash on it.

06:23.100 --> 06:31.920
Which means that now it's open for attackers to use MD5 to modify inputs or select their own inputs.

06:31.920 --> 06:34.080
And you will still think it's the same thing.

06:34.100 --> 06:50.040
It's paramount or analogous into some developer writing a library and giving you an affirmation that this is my library, I wrote it, here's my MD5 signature, and then someone else uses MD5 to give you some malicious piece of code and you will not be able to tell the difference.

06:50.500 --> 06:54.600
So just as an example, what does it look like in real life?

06:54.680 --> 07:03.300
So if we take a function, SHA1 in this example, the quick run forks, blah, blah, blah, will give an output, 2FD, blah, blah, ending in B12.

07:04.080 --> 07:05.720
Let's change one character.

07:05.720 --> 07:08.120
I change the D to a C.

07:08.120 --> 07:10.860
And you can see that the output is dramatically different.

07:10.860 --> 07:14.740
So that's the purpose of a cryptographic hash function.

07:14.740 --> 07:18.560
So if you change just one thing, it will be dramatically different.

07:18.560 --> 07:22.860
It will be very difficult to find two different sources that get the same output.

07:23.240 --> 07:24.420
Why is this important?

07:24.420 --> 07:29.020
It used to be very, very difficult to attack SHA1, two to the power of 80.

07:29.020 --> 07:31.260
That means it's a lot of compute.

07:31.400 --> 07:38.760
However, with recent advances, last year, or sorry, this year, early this year, this was reduced to the power of 68.

07:38.820 --> 07:41.140
Well, that sounds pretty tough yet, right?

07:41.140 --> 07:46.280
So if you go and spend like 100K in Amazon, you can crack SHA1.

07:46.920 --> 08:02.700
And that means that if you have, you're using Git and you're counting in Git to make sure that the commits have the right hashes and don't have like two people committing the same thing or a malicious person committing something and you get the same kind of commit,

08:02.700 --> 08:06.640
well, that's not true anymore for a SHA1 attacker with lots of money.

08:06.840 --> 08:10.420
But it might be even true in the future for other advances.

08:10.420 --> 08:15.740
So I'm not really worried about Git because that's like not a really viable attack surface.

08:15.740 --> 08:25.200
But Git had discussions to move away from SHA1 to SHA256 or SHA512 and that's probably the most common recommendation right now, don't use SHA1 anymore.

08:26.460 --> 08:36.520
Symmetric function, something you're probably more familiar with, which is a cryptographic function that given a key, you can use it on a piece of information and then it will be hidden.

08:36.520 --> 08:39.600
Use the same key again, you get the information right back.

08:39.740 --> 08:49.080
So example, take AS, AS is the currently known best practice to use for encrypting symmetric information.

08:49.180 --> 08:55.800
So I just like, it's pseudocode, but like Python notation, padded it with 21 zeros, get something.

08:55.800 --> 08:58.640
Change a bit, get something dramatically different.

08:58.820 --> 09:00.000
Why is this important?

09:00.000 --> 09:13.920
It's important because if the cryptographic function produces an output that has some sort of information in it, it doesn't look like random noise, it means that I can go ahead and break this algorithm.

09:13.920 --> 09:15.300
I'll give you an example.

09:15.520 --> 09:24.180
One of my friends, he's a master thesis, was to break an algorithm called WEP, might have heard of it for Wi-Fi.

09:24.180 --> 09:32.820
And the reason it was broken was because when you used the algorithmic function called RC4, RC4 wasn't stable.

09:32.820 --> 09:37.340
The first 1,000 or 2,000 bits coming out of RC4 had a bias.

09:37.340 --> 09:43.440
So you can guess with good certainty what was the key that produced that output if you recorded that output.

09:43.440 --> 09:49.720
So once you did that, you just record some information out of the air and now you know the key for that WEP encryption.

09:49.720 --> 09:50.880
But that's pretty bad.

09:50.880 --> 09:54.660
You want something to be very, very stable, very, very good.

09:55.000 --> 10:00.560
So AES is currently the standard and it's a good standard and you could be very happy using it.

10:00.560 --> 10:06.020
And there are other cryptographic algorithms out there to supplement it when the time comes.

10:07.320 --> 10:13.860
Asymmetric cryptography, I'm not going to go into a lot of length here, but that's what you probably all know from private public keys.

10:14.060 --> 10:30.960
Basically what they mean is that if you have a pair of public and private keys, you can give everybody your public key, they can encrypt the message with the public key that you gave away, but because you're the only one who has a private key, you're the only one who is able to decrypt that message.

10:31.080 --> 10:33.680
So hand wavingly, this is the way that works.

10:33.820 --> 10:39.000
And this is something that a lot of our internet, our data communication is based on.

10:40.980 --> 10:50.540
There was a presentation , I don't know if you've seen the Twitter storm about it, I think it was, I'm not sure if it was yesterday or two days ago, in Black Hat by a company called Time AI.

10:50.800 --> 11:01.840
They do 5D encryption with quasi prime numbers and lots of other, they enhance their cryptographic functions with music and emotions.

11:01.880 --> 11:05.040
And it was like, I could not believe that this was a Black Hat talk.

11:05.640 --> 11:11.780
So choosing like vetted, known, good algorithms is what you should do.

11:11.780 --> 11:13.560
You should not invent your own algorithms.

11:13.580 --> 11:17.720
And I'll come back to that message in a moment with some examples.

11:18.600 --> 11:20.400
So what is a signature ?

11:20.400 --> 11:30.660
A signature is having some private key and using that in order to provide a proof to everyone that a piece of code or a piece of message is something that you actually guarantee came from you.

11:30.660 --> 11:31.880
So how does that work?

11:31.880 --> 11:40.860
So I'll take my message, could be my library or something similar, and I'll calculate or compute the hash of that message using the SHA-1 or something similar from before.

11:41.340 --> 11:43.360
Then I'll provide a signature.

11:43.360 --> 11:49.880
A signature is just taking a public private key algorithm, using my private key, I'll encrypt the hash.

11:50.060 --> 11:53.300
Now I have an encrypted hash that was encrypted with my private key.

11:53.300 --> 11:58.480
So I'm not giving anyone my private key, but I know that it's, I can assure someone that it's mine.

11:58.480 --> 12:00.540
How can I ensure someone that it's mine?

12:00.700 --> 12:03.860
I give everybody my public key and I give them the message.

12:03.860 --> 12:08.420
They will compute their own version of the hash because they do it by themselves, they don't trust me anymore.

12:09.380 --> 12:12.320
And they decrypt the message using the public key.

12:12.460 --> 12:22.280
Now if they got the same key, the same hash, that means that I am the owner of the private key, of the public key, and therefore this message came from me.

12:23.260 --> 12:24.300
Sorry.

12:24.620 --> 12:33.000
So the whole concept of signature is based on the idea that I can share something publicly, I can keep something private, not tell that to anyone.

12:33.000 --> 12:40.500
But using that information, I can also convince you of my identity as a holder of that private key.

12:40.940 --> 12:41.560
Okay.

12:42.380 --> 12:48.020
One of the things and probably the last tenets for this very short introduction is the idea of randomness.

12:48.500 --> 12:53.300
Almost everything that we do in cryptography is somehow centered about randomness.

12:53.300 --> 12:57.740
So if we don't have a very strong randomness source, everything breaks.

12:57.740 --> 12:59.320
And I'll give some examples of that.

12:59.320 --> 13:02.480
So usually when we talk about randomness, we talk about two different things.

13:02.480 --> 13:06.520
The first one is called the TRNG or true random number generator.

13:06.520 --> 13:09.780
And the other is called PRNG, absurd random number generator.

13:09.780 --> 13:13.780
The big difference between the two is that the PRNG is a function.

13:13.780 --> 13:18.460
If I'll give it a known starting point, it will always get to the same result.

13:18.520 --> 13:22.760
Change the starting point, you'll get a different result, but it's derived in deterministic fashion.

13:23.440 --> 13:25.960
TRNG, I have no idea what's not going to happen.

13:25.960 --> 13:31.360
So it's just like measuring neutrons from the air or like measuring electromagnetic interference.

13:31.400 --> 13:34.940
It might be zero, it might be one, I have no idea what's going to happen.

13:34.940 --> 13:39.080
So a good TRNG will give me bits with a probability of 50%.

13:39.080 --> 13:41.080
I don't know what it would be.

13:41.080 --> 13:47.300
If it was something like, let's say 49%, I would be able to break that random number generator.

13:47.300 --> 13:49.600
So we need something that's very, very stable.

13:50.340 --> 13:52.200
So how do you use that?

13:52.200 --> 14:00.440
You take a PRNG and you provide it with an input that's come from a real world entropy source, something that's actually truly random.

14:01.320 --> 14:04.360
So what happens when it isn't random?

14:04.380 --> 14:07.240
Sometimes people misuse random numbers.

14:07.240 --> 14:10.660
For example, when they're writing code and they need to use nonces.

14:10.660 --> 14:13.200
Everybody are familiar with what's a nonce?

14:13.980 --> 14:17.500
Okay, so a nonce should be just a random number.

14:17.500 --> 14:22.440
It shouldn't be constant, it shouldn't be hardcoded into your code, until it is.

14:22.440 --> 14:24.900
And when it is, funny things happen.

14:24.900 --> 14:26.300
So I'll give you an example.

14:28.220 --> 14:31.240
Probably heard of Bitcoin, once or twice, maybe.

14:31.540 --> 14:36.100
So Bitcoins is actually a cryptographic operation.

14:36.400 --> 14:37.800
So what are coins?

14:37.800 --> 14:46.040
Coins are actually going and trying to find inputs that given a hash function will provide a pre-known output.

14:46.220 --> 14:54.000
So that's the difficult problem, not because it's mathematically hard, but because it's very difficult to find those inputs.

14:54.000 --> 14:54.780
So what do you do?

14:54.780 --> 14:59.060
You try a lot of different attempts, found one, you earn the coin.

14:59.060 --> 15:01.240
Now you are an owner of a single Bitcoin.

15:01.300 --> 15:10.500
This is exponentially harder as time goes by, which means you have to invest more time, more resources, more CPU power in order to actually mine those Bitcoins.

15:10.500 --> 15:12.920
But the basic principle still holds.

15:13.200 --> 15:16.720
Wallets, or your Bitcoin wallets, are just identities.

15:16.740 --> 15:19.860
They are something that represent your private and public keys.

15:20.340 --> 15:28.920
And transactions are actually just saying, I'll take this piece of money and I'll give it to that private key or that holder of that private key, and this is a transaction.

15:28.920 --> 15:34.060
Just shifting money or shifting coins or pieces of coins from one source to another.

15:34.740 --> 15:37.540
And I should have clicked like 20 minutes ago.

15:39.040 --> 15:44.240
An important thing to note, if you lose your private key, you lost your money.

15:44.240 --> 15:48.020
Because your coins are held by your private key.

15:48.020 --> 15:52.600
If you don't have access to your private key anymore, you don't have access to your coins.

15:52.600 --> 15:55.720
Something to keep in mind when you're playing around with Bitcoin.

15:56.280 --> 16:00.000
So the last thing I want to talk about is called elliptic curve cryptography.

16:00.000 --> 16:08.240
If you're familiar with RSA, basically the same thing, much cheaper to execute, much less compute power, same guarantees for security.

16:09.020 --> 16:15.040
Bitcoin is using these elliptic curve cryptography operations in order to move money about.

16:15.040 --> 16:18.100
So that's the basic algorithms behind Bitcoin.

16:18.360 --> 16:22.440
So this is a screenshot from a Bitcoin transfer.

16:22.440 --> 16:32.380
So what you can actually see is that this value here, this is the address of the source, which is actually the hash of my public key.

16:32.680 --> 16:43.740
And I'm moving money, 7.179 blah blah Bitcoins, into two different addresses, and the addresses are just the hashes of the public keys of the recipients.

16:44.040 --> 16:45.400
This is everything that there is to it.

16:45.400 --> 16:50.380
This is the entire Bitcoin idea in a slide.

16:51.460 --> 16:54.120
So how would you go about attacking this?

16:54.260 --> 17:01.560
So I will not going to bore you with the mathematical details behind this, but I'll try to direct your attention to a couple of things.

17:02.420 --> 17:15.460
The transaction actually happens when I, as an owner of a Bitcoin, will sign over a portion of that coin into a new address, to a new private key, or sorry, to a new hash of a public key.

17:15.640 --> 17:19.720
In order to do that, I have to work with a couple of components.

17:19.720 --> 17:28.160
The hash of the message, K, which is random, R, which is the multiplication operation under elliptic curves, and the signature.

17:28.220 --> 17:31.740
And the way to calculate the signature is outlined in the formula in the bottom.

17:31.980 --> 17:41.260
So there's something here which should stick out like a sore thumb to everyone who looks at it, which is, maybe I can show my hair.

17:42.460 --> 17:44.300
K should be random.

17:44.700 --> 17:51.580
And sometimes when implementers are reading the spec, they say, okay, K should be random, so I'll select a random number.

17:53.340 --> 17:55.880
So what happens when K isn't random?

17:56.060 --> 17:57.820
Assume that K isn't random.

17:58.040 --> 18:07.840
If I can go over on the block, look at all the blockchain, all the Bitcoin transactions, and find two different transactions that share the same random number.

18:07.840 --> 18:11.360
Suddenly, this is a problem in sixth grade algebra.

18:11.360 --> 18:18.920
Because if I know the value for K, I can just move about the equation, isolate K, and solve for everything else.

18:18.920 --> 18:21.560
And I solve and I solve, and finally I have D.

18:21.560 --> 18:23.300
Now I have the private key.

18:23.300 --> 18:30.200
Because in elliptic curve operations, when you're not using random numbers, everything breaks.

18:30.400 --> 18:33.000
So it's a tenet of using elliptic curves.

18:33.300 --> 18:36.100
So you say, okay, this is like nonsense.

18:36.100 --> 18:38.300
Who wouldn't use random numbers in the real world?

18:38.300 --> 18:40.000
This never happens.

18:40.420 --> 18:42.900
And the answer is, well, of course it does.

18:43.040 --> 18:50.220
So this is a screenshot from many, many years ago, 2013, when somebody noticed that people are stealing money from wallets.

18:50.540 --> 18:52.560
And how did this attack happen?

18:52.560 --> 19:07.260
Because someone else was probably a bit brighter noticed that people are using bad wallets or bad wallet software, where the developers for that piece of software for that wallet didn't realize that they need to generate a new K for every transaction.

19:07.540 --> 19:18.960
So what they've done is just searched the transaction logs for two different transactions using the same random number, extracted the private key, and stole all of their bitcoins.

19:18.960 --> 19:20.560
This was in the entire attack.

19:21.320 --> 19:26.520
So, you know, that's kind of if somebody wants to mess with bitcoins, like they had it coming.

19:26.520 --> 19:28.760
I have no problems with that.

19:28.760 --> 19:34.920
But you say, this shouldn't happen in, like, real world applications, like big sized interesting stuff.

19:35.520 --> 19:38.540
So how does that look like in the real world?

19:38.540 --> 19:51.480
When you generate a random number, what you should probably be doing is something like open slash dev slash random and pull a number of bytes out of it, maybe 30, I don't know, just throw in a number there.

19:51.840 --> 19:54.940
But you should do this for every time that you need a random number.

19:54.940 --> 19:57.720
Because when you don't, you get something like this.

19:58.680 --> 20:03.960
You choose the random number very securely, once, and hard code it.

20:04.160 --> 20:07.520
Which is like analogous to saying, what's my random number?

20:07.520 --> 20:08.300
Four.

20:08.700 --> 20:11.140
It was chosen by a fair dice roll.

20:14.060 --> 20:15.660
I'll skip this.

20:17.780 --> 20:18.440
Okay.

20:18.440 --> 20:21.320
We'll come back to the point of the randomness in a moment.

20:21.320 --> 20:26.500
I want to show you a piece of code and ask everyone, can everybody see the problem with this piece of code?

20:27.120 --> 20:28.180
Any hands?

20:28.940 --> 20:30.700
It was pretty famous for a while.

20:31.380 --> 20:31.620
Okay.

20:31.620 --> 20:32.780
We have one person.

20:33.160 --> 20:34.040
Two persons.

20:34.040 --> 20:34.680
Excellent.

20:34.680 --> 20:36.260
So I'll highlight it for everyone.

20:36.720 --> 20:44.520
So this piece of code is actually the verification code for X509 certificates on iOS.

20:44.660 --> 20:46.200
Or it used to be.

20:46.460 --> 20:52.660
And what this means is when you're doing a TLS transaction, somebody needs to check the certificate.

20:52.820 --> 20:54.280
How do you check the certificate?

20:54.280 --> 20:56.080
Just the same way that we talked previously.

20:56.080 --> 21:00.200
Just check the public keys, find out the hashes, compare them, check them.

21:00.200 --> 21:06.880
And the way that the code is written is that if there's an error, some check didn't pass, go to fail.

21:07.580 --> 21:10.740
But what happens here is you have a double line.

21:11.320 --> 21:13.980
So the first line is in the scope of that if.

21:13.980 --> 21:16.360
The second line isn't in the scope of anything.

21:16.400 --> 21:20.400
So anything written after that never executes.

21:20.740 --> 21:21.020
Okay?

21:21.020 --> 21:24.360
Whenever you go into that point, you immediately go to fail.

21:24.680 --> 21:26.720
So how is that interesting for an attacker?

21:26.780 --> 21:38.320
If you specially craft your certificate that you would pass each and every check up to that point, even though your certificate is invalid, you will still pass the test.

21:38.640 --> 21:42.280
Because nobody tests for like everything, you just test up to that point.

21:42.640 --> 21:55.060
And that meant that attackers could create certificates for, I don't know, for example, iOS apps that are invalid and malicious but have like certificates which are bad but pass the verification process.

21:55.840 --> 22:00.740
So special attention needs to be given to these kinds of cases.

22:02.700 --> 22:04.280
Am I missing a slide?

22:04.280 --> 22:05.380
Let me check.

22:08.040 --> 22:08.940
Yeah.

22:09.380 --> 22:21.120
I should have said something here and I skipped it, so let me circle back for a second.

22:21.120 --> 22:26.240
So Sony, you might have heard of them, have a device or had a device called the PlayStation 3.

22:26.420 --> 22:31.020
And the PlayStation 3 was pretty awesome, everybody liked playing with it, but they couldn't really copy the games.

22:31.080 --> 22:31.440
Why?

22:31.440 --> 22:35.560
Because of the digital rights management protection on the games.

22:35.960 --> 22:48.620
But what Sony didn't really take into account or their developers didn't think about very thoroughly is that when they signed the games, they signed them with elliptic curves but they chose a single random value and it was hard-coded.

22:48.720 --> 23:09.300
So when the guys at Overflow found this out, they understood, okay, I can just take two different games, compare the signatures, find the random values that they used, derive the private key and now I can sign whatever game that I want for Sony because I have the private keys because they didn't use random values.

23:09.300 --> 23:18.540
So this was a very big thing for a while because those hard-coded numbers were hard-coded into the PlayStation 3 hardware device itself, the firmware.

23:18.740 --> 23:28.060
And they couldn't really update this, they couldn't circumvent this, they just lost a lot of money because someone made a mistake about assuming something about random numbers.

23:28.280 --> 23:31.200
Sorry, I completely missed my point here .

23:34.040 --> 23:40.680
Circling back to Bitcoin, everybody remember this screen from two and a half years ago, something like that?

23:41.520 --> 23:57.940
So attackers behind WannaCry built, I don't know, let's call it a GUI or something that will give you some information, how can you get the keys in order to get back all your files that they encrypted, just send me some money to this Bitcoin address.

23:58.500 --> 24:02.440
And they were supposed to send you back the keys and everybody would be very happy.

24:02.860 --> 24:04.280
So a couple of things happened.

24:04.280 --> 24:06.920
The first one was that obviously they never sent the keys.

24:06.960 --> 24:13.260
The second one was that the WannaCry attack was stopped pretty much in the middle because of a different operation.

24:13.260 --> 24:27.520
They had like a failsafe so they could stop the propagation of the malware from going everywhere because, that's like a different story, but the malware would check if a specific domain name was registered.

24:27.520 --> 24:29.900
If it was registered, it would stop the work.

24:30.840 --> 24:36.460
So while that domain name was not registered, it would continue to propagate.

24:36.660 --> 24:49.820
So one of the security researchers would just finish, if you're following up on the news, just finish his trial, find that out from reverse engineering the software, he registered that domain, he paid like, I don't know, $5 for it and stopped WannaCry.

24:50.180 --> 24:53.700
So that was the first thing that was really not very smart about WannaCry.

24:53.700 --> 24:59.580
The second thing was that they kind of missed the point of using Bitcoin.

24:59.580 --> 25:03.960
Bitcoin is a confidential service, but it's not an anonymous service.

25:03.960 --> 25:09.040
It means that everybody can be the owner of Bitcoins and their identity is protected.

25:09.040 --> 25:15.060
You don't have to tell anyone your identity, but everything you do is always logged, is always recorded.

25:15.060 --> 25:19.620
It's part of the very mechanism of how transactions on the blockchains work.

25:19.620 --> 25:30.800
And that means that if I'm a malicious attacker, and I'm asking people to send money over to my wallet, everything is traceable, everything is accountable, and it's part of the design of the system.

25:30.800 --> 25:34.160
And if I want to cash out, now I have a problem .

25:34.320 --> 25:42.420
Because if I try to cash out, somebody can just okay, now you linked that identity with this real world credit card.

25:43.020 --> 25:59.740
So they had money stuck there, they had about $70,000 if I remember correctly, they had it stuck there for a couple of months until they thought about a solution , which was just doing cash exchanges in Macau or something like that, to go over there, pull out the money very fast and disappear.

25:59.980 --> 26:06.420
But while they were doing this, they really couldn't touch the funds, because whatever you do with the funds, it's always traceable.

26:08.060 --> 26:08.940
Okay.

26:09.240 --> 26:11.380
So how does this look in the real world?

26:11.380 --> 26:12.360
New example.

26:12.900 --> 26:17.140
Who uses BitLocker, or at least heard of it enough to understand the term?

26:17.860 --> 26:18.800
I don't believe you.

26:18.800 --> 26:20.360
Who has Windows laptops?

26:21.660 --> 26:23.480
Really, everybody runs Linux?

26:23.920 --> 26:25.960
Wow, cool.

26:25.960 --> 26:27.740
I'm really proud of you guys.

26:29.400 --> 26:38.300
So BitLocker is, I wouldn't call it a protocol, but it's like a feature where your hard drive will self encrypt everything.

26:38.300 --> 26:45.320
So if somebody steals the hard drive and connects it to a new computer, he can't read the data that's on that device.

26:45.380 --> 26:47.420
That's a description of that feature.

26:47.420 --> 26:55.140
What really happens is that when you connect it to the operating system, the operating system is something like this.

26:55.740 --> 27:01.620
Are you a hard drive or SSD or whatever that supports hardware encryption?

27:01.620 --> 27:05.660
And the BitLocker supported device says, yes, of course I know encryption.

27:05.660 --> 27:07.360
Let's use my encryption.

27:07.600 --> 27:13.920
So if you have a hardware supported encryption on your hard drive, it will use the hardware version.

27:13.920 --> 27:18.720
If you don't have support, then Windows will simulate that support in software.

27:19.240 --> 27:20.840
What's the problem with that?

27:20.840 --> 27:25.000
The problem with that is the very premise that hardware is actually better than software.

27:25.000 --> 27:28.380
Because the way that the hardware developers did that was mumble about.

27:29.080 --> 27:30.420
What they did.

27:32.260 --> 27:40.160
They had a password that's used by your BIOS in order to encrypt or decrypt information from your hard drive, and they had a key.

27:40.220 --> 27:43.000
But there is no relationship between the password and the key.

27:43.000 --> 27:46.740
So you can type any password that you want, the key will still be fixed.

27:46.740 --> 27:50.180
It will be orthogonal to the password that you used.

27:50.180 --> 27:52.780
So they didn't tie together in any way.

27:53.500 --> 27:57.280
Second thing is, they used the same key to encrypt the entire drive.

27:57.280 --> 28:00.240
All of the different partition, all of the different blocks and sections.

28:00.240 --> 28:07.360
Which means that I have lots and lots of different blocks of encrypted data that I can compare against that are all using the same key.

28:07.460 --> 28:13.040
Which means that if you had a bad implementation, you just made my life easier as an attacker.

28:14.020 --> 28:17.220
And the last thing is, they didn't really use random keys.

28:17.640 --> 28:23.180
I'm just dissing here, but think of it as an equivalent of a 12 character password where it's all ones.

28:23.680 --> 28:24.000
Okay?

28:24.000 --> 28:26.020
So they didn't randomize the password.

28:26.060 --> 28:34.120
So you had the same password for all blocks on your hard drive, which didn't have any correspondence with a password for your BIOS or anything else.

28:34.120 --> 28:37.840
So you couldn't customize it, it didn't tie into anything from the real world.

28:37.840 --> 28:47.320
And that meant that, I'll skip that, and that meant that all of those drives were very, very weak from a cryptographic perspective.

28:47.320 --> 28:50.100
It's almost trivial to break them.

28:50.160 --> 28:56.140
However, the operating system by default will choose the hardware encryption over the software encryption.

28:56.140 --> 29:12.700
And that means that any laptop that you probably have or had for the past year or older than that, didn't really have the security guarantees that you thought it had by using the BitLocker and similar properties, similar features.

29:13.620 --> 29:17.340
Here's just, I don't know, I just found it like an extremely funny example.

29:17.340 --> 29:21.720
Somebody on Stack Exchange asked for an algorithm to encrypt your password.

29:21.720 --> 29:23.760
I know you can't read it, so I'll enlarge it.

29:24.160 --> 29:35.500
So the method that he was suggesting to do was to take a Base64 encoding of your password and then reverse it, apply Base64, and now you have an encryption.

29:35.720 --> 29:42.060
So the amount of things that are wrong with that sentence are that... I don't know, he summarized this much better than me.

29:42.060 --> 29:50.920
The first thing is that Base64 is a bad choice because it enlarges the space requirement to store the same kind of information.

29:50.920 --> 29:56.380
The second thing is obviously this has nothing to do with cryptography, it's just encoding the same information in a different way.

29:56.940 --> 30:02.800
Reversing the encoding does nothing for security, just means that I have to reverse it again.

30:03.140 --> 30:19.820
And the basic thing is that this was an entire thread on Stack Exchange, should I use MD5 to encrypt my files and encrypt my passwords, where one, MD5 is not an encryption algorithm, and two, it has nothing to do with it, it's broken, use something else.

30:19.820 --> 30:26.140
And this guy came along and suggested to use this amazing piece of code that he wrote in order to protect everybody's password.

30:26.500 --> 30:29.200
So be careful of where you get your advice.

30:30.680 --> 30:34.920
I'm not dissing Stack Exchange, I'm just saying you should vet information that you receive.

30:35.820 --> 30:38.020
I think it's my last example.

30:38.160 --> 30:50.980
I do want to explain the concept and what I find problematic with it, but the basic idea is that it is actually a good piece of software, it just had its own limitation.

30:51.240 --> 31:04.340
So what this guy, he wrote a piece of software called Crypt Hook, and the problem he was trying to solve is that you have information on server A, and you want to communicate with server B, but you don't have the facilities to encrypt the information,

31:04.340 --> 31:06.880
you can't change the software that's running on the servers.

31:07.080 --> 31:15.240
So what he said, okay, I'll hook the system calls, and every network packet that transfers from server A to server B, I will encrypt it myself.

31:15.700 --> 31:24.160
So I will, like, create an out-of-bed encrypted channel between the two servers that has nothing to do with the software running on them.

31:24.160 --> 31:29.160
It will still transparently use the network stack, and I will encrypt the network stack.

31:29.640 --> 31:34.660
Out of the box, it's not like a bad idea, this really solves a real problem where you can't touch the software.

31:34.720 --> 31:38.320
On the other hand, the choices that he's made, made it very, very weak.

31:38.620 --> 31:47.880
So he chose to use GCM, which nobody should really care what it means, to do authentication, but he encrypted everything with a fixed key.

31:48.140 --> 31:51.440
So every packet was encrypted with the same key.

31:51.900 --> 31:59.060
Not only was that every packet was encrypted with the same key, there was no difference between the packets, so everything was encrypted exactly the same way.

31:59.440 --> 32:06.280
So it was absolutely easy for an attacker to capture a packet and replay it, send it again over the network.

32:06.280 --> 32:18.980
So if you had a packet that says, transfer $1,000 to my account, you can just capture that packet and replay it again and again and again, because no one would know, because there's no such information inside the packet to stop that.

32:19.020 --> 32:21.580
Also, you can change the order of the messages.

32:22.080 --> 32:31.100
You can do whatever you want with it, like dropping some of the messages, because his encryption scheme didn't think about those kinds of edge cases or use cases.

32:31.300 --> 32:46.080
But also, it meant that if I broke the key once, because it was fixed, it was hard-coded, that meant that I now had the key to every communication that would ever happen with this piece of software, which is tentative to just reading the source code because the key was there.

32:47.720 --> 32:50.480
So the question is, is everything on fire?

32:50.480 --> 32:51.780
Is everything bad?

32:52.280 --> 32:58.080
So obviously the answer to that is no, not everything is on fire, not everything is bad.

32:58.080 --> 33:05.460
But you should really pay special consideration whenever you're touching something related to crypto.

33:05.780 --> 33:07.460
Crypto is hard.

33:07.460 --> 33:19.980
There are experts, usually PhDs, that spend years and years of their lives researching crypto problems and crypto properties in order to make sure that whatever they're doing is very, very safe.

33:20.200 --> 33:25.720
You're not going to outperform them, you're not going to outsmart them, and you probably shouldn't be trying.

33:26.040 --> 33:27.640
Never roll your own crypto.

33:27.640 --> 33:30.780
Use best practices, use what's already out there.

33:30.780 --> 33:32.820
In my next slide, I'll give some recommendation.

33:32.820 --> 33:40.240
But also, you have a special use case, you have some problem that's unique and you don't know if the current tooling is able to solve that.

33:40.280 --> 33:42.960
Well, ask around, ask an expert.

33:43.060 --> 33:47.460
I can recommend two, let's say, expert advice channels that you can use.

33:47.460 --> 33:52.280
The first one is using Reddit, the crypto subreddit, but also the crypto stack exchange.

33:52.280 --> 34:04.920
Both are wonderful resources to consult with real world experts that can help you understand your problem and the right kind of tooling, the right kind of algorithms that you can use to solve that unique problem.

34:05.100 --> 34:08.060
More than that, you can always pay consultants.

34:08.140 --> 34:11.040
I'm a consultant, I'm getting paid to give advice, that's fine.

34:11.040 --> 34:14.920
There are experts that you can talk to on Twitter, anywhere else, you will get advice.

34:14.920 --> 34:18.680
People are nice, basically, most of the time.

34:18.680 --> 34:26.400
You can also pay a crypto review firm to go and look over your crypto code to make sure you haven't done something horrible like what happened to Sony.

34:26.420 --> 34:37.420
You don't want to be in that position where you wrote your own crypto or your team wrote some crypto because you thought you would be really solving something and you just horribly broke the entire security premise of your product.

34:39.320 --> 34:41.220
So what's my advice to you?

34:41.220 --> 34:45.520
That's probably the slide you should copy or photograph or just listen very carefully.

34:45.520 --> 34:50.940
The first one is that make sure that you're using the right libraries for you.

34:51.360 --> 34:54.420
Personally, I never recommend OpenSSL.

34:54.500 --> 35:04.060
Who has experience using OpenSSL APIs or implementing OpenSSL code in their own ID or in their own product?

35:04.060 --> 35:05.940
Anyone using OpenSSL?

35:06.020 --> 35:07.700
How sorry are you?

35:08.920 --> 35:11.580
Have you tried anything else?

35:12.080 --> 35:13.520
Not really.

35:13.520 --> 35:31.980
So at least my opinion of OpenSSL, it's a big, large, bloated piece of software that tries to do everything and most of the time doesn't do them the most efficient or the most proper way and it gives you... I used to have a boss that told me that C is a wonderful language.

35:31.980 --> 35:34.640
It gives you every tool possible to slit your own throat.

35:35.440 --> 35:37.680
So in a sense, OpenSSL is the same way.

35:37.680 --> 35:39.120
They support everything.

35:39.120 --> 35:50.000
Every legacy algorithm, every parameter ever conceived for anything and if you will misuse this or configure it wrongly or use the wrong parameters, you won't even know that you broke your crypto.

35:50.380 --> 35:54.100
So my first recommendation for you is just use something simpler.

35:54.500 --> 35:56.100
And you know, the world has advanced.

35:56.100 --> 35:58.420
There are lots of very good libraries out there.

35:58.540 --> 36:03.560
Archimedecommon, BoringSSL, the Golang crypto stack is excellent.

36:04.280 --> 36:06.200
NACL is also very, very good.

36:06.200 --> 36:07.720
NSS is very good.

36:08.980 --> 36:15.560
I do want to say that all of the libraries I mentioned here are good and I recommend them myself.

36:15.560 --> 36:17.260
Sometimes they have issues.

36:17.300 --> 36:18.400
They have bugs.

36:18.400 --> 36:20.460
They have patches that you need.

36:20.580 --> 36:22.060
And this is actually a good thing.

36:22.060 --> 36:24.300
Because that means that somebody is maintaining this.

36:24.300 --> 36:28.400
Somebody is actually looking if there are any issues and somebody is trying to fix them.

36:28.400 --> 36:35.820
So whenever such a thing exists, take that into your consideration, into your dependency stack and make sure that your own code is up to date.

36:36.620 --> 36:39.140
Never trust people that roll their own crypto.

36:39.400 --> 36:42.260
There are lots of like, oh, yeah, we have a student.

36:42.260 --> 36:43.440
He's really brilliant.

36:43.440 --> 36:45.660
We ask him to write our crypto stack.

36:45.820 --> 36:47.380
That's not a good idea.

36:47.380 --> 36:48.840
Even if he is brilliant.

36:48.900 --> 36:49.920
Use best practices.

36:49.920 --> 36:51.280
Use what's already out there.

36:51.280 --> 36:52.480
Just use it correctly.

36:52.480 --> 36:56.160
You have a much easier time, much better time overall.

36:56.720 --> 37:00.340
The last thing is that... sorry.

37:00.660 --> 37:08.160
The last thing that I want to mention about that is that not every feature that exists in crypto is actually something that you need.

37:08.240 --> 37:12.600
So cryptography has a lot of building blocks that are used in many, many different ways.

37:12.660 --> 37:14.940
Some of them are very esoteric.

37:14.960 --> 37:17.340
Some of them are like the mainline use cases.

37:17.820 --> 37:20.560
90% of the time, you need the mainline use case.

37:20.560 --> 37:21.600
It's already described.

37:21.600 --> 37:22.320
It's already known.

37:22.320 --> 37:23.360
Just use that.

37:23.360 --> 37:24.420
Don't invent anything.

37:24.420 --> 37:27.380
Don't try to like, oh, that's a nice looking piece of technology.

37:27.380 --> 37:29.520
Just like, let's use that instead.

37:29.540 --> 37:34.580
You need to think about it and you probably need some cryptographer to let you know if you did this correctly or not.

37:35.560 --> 37:37.100
So what you can do.

37:37.400 --> 37:38.900
Update your libraries.

37:39.120 --> 37:46.800
I've seen so many customers, so many people who use OpenSSL and like version 1.01 or something like that.

37:46.980 --> 37:49.020
And it's not updated at all.

37:49.020 --> 37:55.100
Because it's hard to update and they're afraid it will break something.

37:55.100 --> 37:58.040
And with OpenSSL, that's very cumbersome anyway.

37:58.480 --> 38:00.280
So make your life easier.

38:00.380 --> 38:04.500
Make sure that you have thought of how are you going to update this?

38:04.500 --> 38:06.800
How are you going to fix this when the time comes?

38:07.380 --> 38:11.560
If you want to become an expert, my recommendation to you is to start small.

38:11.580 --> 38:16.100
Go to trainings, to workshops, hear talks, go over YouTube, read a book.

38:16.160 --> 38:19.480
You can become an expert on cryptography without knowing math.

38:19.480 --> 38:22.580
You don't need a math degree in order to better understand crypto.

38:22.580 --> 38:26.200
You probably need a math degree or even a math PhD to invent crypto.

38:26.200 --> 38:27.280
But not to use it.

38:27.280 --> 38:29.400
To use it properly, study.

38:29.400 --> 38:30.920
Like everything else that we do.

38:30.920 --> 38:31.380
Study.

38:31.380 --> 38:34.480
This is a domain of knowledge that you can use, you can learn.

38:34.480 --> 38:35.360
It's not scary.

38:35.360 --> 38:37.620
It's not something that you should be afraid of.

38:37.940 --> 38:45.720
Down the line, you probably want to either outsource or hire the right people to look at cryptography very closely.

38:45.720 --> 38:50.920
But if you're not inventing cryptography, just use something that someone else already did.

38:50.920 --> 38:54.940
It will make your life easier and probably get better security out of it.

38:55.520 --> 38:58.460
With that, I would thank you very much.

39:05.970 --> 39:08.910
I'll be happy to take questions now in a moment.

39:08.910 --> 39:12.010
And if not, I'll be also outside later to take more questions.

39:12.010 --> 39:12.530
Yes, sir?

39:16.310 --> 39:18.910
That depends on what your desktop is.

39:18.910 --> 39:22.850
If you're on Linux or on your own Windows or you're on Chrome OS or differently.

39:22.850 --> 39:29.190
But I would trust with a mild degree of assault attached to it.

39:29.190 --> 39:32.010
But I would trust the operating system to hold secrets.

39:32.890 --> 39:34.790
They're usually pretty good.

39:34.830 --> 39:37.090
Depending on how much trust you need for that secret.

39:37.090 --> 39:44.210
If I have a desktop application, usually that means I have my own laptop or storing my own bank accounts or something like that, that's secure enough.

39:44.210 --> 39:50.730
If I have a production server hosting secrets for my 100,000 customers, that's a different question.

39:50.730 --> 39:53.270
There I would use an HSM or something similar.

39:54.130 --> 39:56.450
HSM is a hardware security module.

39:56.450 --> 40:01.690
That's actually a piece of hardware that holds secrets and lets you do cryptographic operations without revealing those secrets.

40:01.810 --> 40:03.610
So we can talk about that later.

40:03.610 --> 40:04.270
Yes?

40:07.920 --> 40:08.800
Yeah?

40:28.570 --> 40:30.410
I fully agree.

40:30.410 --> 40:31.190
I'll repeat that.

40:31.190 --> 40:38.050
The Capital One issue hand wavingly was not actually an encryption issue, it was a permission issue.

40:38.090 --> 40:48.950
So if you give someone permissions or you commit to GitHub your keys, then you actually give everybody permission to use your keys to do whatever they want to do.

40:49.030 --> 40:52.630
So the cryptography is still very strong but you haven't protected your keys.

40:52.630 --> 40:54.430
So in a sense that's what happened with Capital One.

40:54.430 --> 40:58.790
Both for roles and permissions for the access list they used for attacking.

41:13.540 --> 41:19.420
Well, here's where you actually need an expert to come and help you and look at your own specific use case.

41:19.420 --> 41:25.540
But if you encrypted your entire database but you kept the key in a script by that database, then you haven't really done anything.

41:25.540 --> 41:33.720
But if you encrypted your entire database and the key comes from a different component which checks your permissions and stuff like that, then you already have a different security model.

41:33.820 --> 41:41.580
So this is actually a more complex question to answer and not necessarily relevant for client side encryption depending on what you're trying to solve.

41:42.340 --> 41:44.000
Okay, more questions please.

41:45.400 --> 41:46.480
Be brave.

41:47.780 --> 41:48.520
Go on.

41:49.260 --> 41:49.700
Going to the next one.

41:49.720 --> 41:52.400
Thank you very much.

