start	end	text
0	8680	Our next speaker is Guy. I'm not gonna try to pronounce his last name. He told me not to do
8680	16980	that. Okay. He's B-Sides Tel Aviv chairman and CTF lead. Also a public speaker and
16980	24020	recipient of the Cisco Black Belt Security Ninja. That's nice. With nearly 20 years of
24020	31620	experience in cyber security industry. Currently providing security services. Focusing on OS,
31620	39100	hardening, crypto, AI and reverse engineering. And he's going to talk about crypto failures and
39100	43120	how to avoid them. Give him a round of applause please.
47370	53350	Thank you very much. Can you hear me in the back? Because I tend to walk about so I'll take the
53350	60250	mic. But if not I'll just speak very loudly. Okay. So welcome to my talk about crypto failures.
60250	65590	Before I begin I just want to say one thing. I'm not dissing anyone who's actually developing and
65590	71490	using crypto libraries. But I do want to point out several failures that I have seen happen over and
71490	76250	over again. And try to give you those patterns and some tools and some ideas of what to do when you
76810	82250	encounter such issues or such things. But I also wanted to make this talk let's say entertaining
82250	88510	and show you a couple of well at least for me and probably for others pretty funny failures. Some
88510	104420	of them of very large extent. So said so. Okay. This should work. Okay. So as I was so kindly
104420	112460	introduced I'm besides Tel Aviv chairman I also do the CTF. I invite you all to come to us to
112460	120720	sunny Tel Aviv in June for a pretty nice conference. I'm here and I've been here for quite a
120720	125280	while. I've seen a couple of different things in different areas. I've managed a cryptographer. I
125280	131800	manage developers. I manage reverse engineers. And some patterns tend to emerge again and again.
131800	136600	So I want to focus on that. The first thing and probably the most important thing is crypto is
136600	142440	math and that kind of scares a lot of people. And I'll try to give you like a first introduction
143060	148740	to what cryptography actually is without going into the math because obviously most people don't
148740	154200	really care. But more than that I want you to give to get like a very at least fundamental
154200	160400	understanding of what you should expect and when you don't see that it should light a red flag. So
160400	165760	I'll give you a couple of examples. So you probably are already familiar with the CIA
165760	171580	confidentiality integrity and availability concepts from other perspectives. This is also true for
171580	175740	cryptography. So when we're saying confidentiality and talking about cryptography, it means we
175740	180820	want to keep things secret. We want to have some sort of method, some sort of idea or function
181340	186820	that if we know the secret, then we will know what this payload contains. And if no one else knows
186820	191560	that secret, nobody else can know what this secret contains. Identity comes to the same thing. We
191560	195420	want to make sure that if someone sends us the message, we can verify that we got the message
195420	201140	from that person or that system and not from someone else. Phishing comes to mind. The third
201140	205860	one is authenticity. Can we trust that nobody touched that message or modified that message? Did
205860	211280	we actually get the same message that the sender sent us or was somebody messing around with it
211280	217840	along the way? This is kind of a personal point for me, but I'm not ashamed to mention it. One of
217840	224640	the teams I led when I was at Cisco was in charge of an area called supply chain security. So I
224640	230360	was the very happy owner of that specific area of responsibility when Snowden releases
230360	236020	documents. If you remember the nice image of NSA intercepting Cisco equipment and doing supply
236020	243900	chain attacks, that was fun. And my point is, is that authenticity is important. When you're
243900	248680	dealing with a product, with a vendor, with a library, you want to make sure that what you're
248680	255320	getting is what actually the developer or the system actually intended you to receive. If you
255320	261240	remember the NPM dependency issue, I don't remember, about a year ago more or less,
261240	266740	somebody decided that he doesn't like the left line string to maintain that anymore, he kind of
266740	274720	dropped that, everything broke. Somebody put some malicious code or stuff like that into the
274720	279740	dependencies of NPM and now everybody got the same kind of libraries along the way. This is
279740	283540	something you need to think about. It's something you need to be aware of. So it's an issue.
284860	289340	Usually when people talk about cryptography, they kind of think that everything is the same.
289340	293980	And it's not the same. When we're talking about hashes, for example, one of the common things
293980	300520	that I hear is that I've encrypted with SHA-1 or encrypted with SHA-512. Well, not. You did
300520	307660	not encrypt the SHA. A hash function has only one job. Taking lots and lots of information,
307660	311580	boiling it down and getting a very short piece of information. But that's also true for
311580	319460	checksums. So if you write CRC32 or something similar, you get the same concept. You process a
319460	328080	lot of information, you get some validating code at the end. However, CRC32 and SHA and other
328080	332920	constructs are not the same. Because cryptographic hashes, which is a specific type of hashes,
332920	338140	try to give you a guarantee. They try to give you that if you change one bit in the input, you'll
338140	343000	get a dramatically different output. More than 50% of it should be different. And if it's not
343000	348140	the case, this is a very bad function to use. Because that means that an attacker can now use
348140	352480	that to find collisions. Collisions meaning find a different message that will give him the same
352480	358680	output. So short story. MD5, for those of you who are familiar with it, used to be a very common
359220	364280	hashing algorithm way back when. And a couple of years ago in Black Hat, if I remember
364280	372120	correctly, I don't remember her name, but a researcher from China, if I remember correctly,
372120	378200	showed a way to find collisions in MD5. And what happened, immediately you can actually
378200	385280	generate whatever you want to get the same kind of MD5 hash on it. Which means that now it's
385280	392660	open for attackers to use MD5 to modify inputs or select their own inputs. And you will still
392660	398360	think it's the same thing. It's paramount or analogous into some developer writing a library
398840	404000	and giving you an affirmation that this is my library, I wrote it, here's my MD5 signature,
404000	408640	and then someone else uses MD5 to give you some malicious piece of code and you will not be
408640	414840	able to tell the difference. So just as an example, what does it look like in real life? So
414840	419960	if we take a function, SHA1 in this example, the quick run forks, blah, blah, blah, will give an
419960	428240	output, 2FD, blah, blah, ending in B12. Let's change one character. I change the D to a C. And
428240	433540	you can see that the output is dramatically different. So that's the purpose of a
433540	438700	cryptographic hash function. So if you change just one thing, it will be dramatically different.
438700	444420	It will be very difficult to find two different sources that get the same output. Why is this
444420	449340	important? It used to be very, very difficult to attack SHA1, two to the power of 80. That
449340	455220	means it's a lot of compute. However, with recent advances, last year, or sorry, this year,
455220	460400	early this year, this was reduced to the power of 68. Well, that sounds pretty tough yet,
460400	467900	right? So if you go and spend like 100K in Amazon, you can crack SHA1. And that means that if
467900	474880	you have, you're using Git and you're counting in Git to make sure that the commits have the
474880	479200	right hashes and don't have like two people committing the same thing or a malicious person
479200	485180	committing something and you get the same kind of commit, well, that's not true anymore for a
485180	490640	SHA1 attacker with lots of money. But it might be even true in the future for other advances. So
490640	497280	I'm not really worried about Git because that's like not a really viable attack surface. But Git
497280	503320	had discussions to move away from SHA1 to SHA256 or SHA512 and that's probably the most common
503320	508100	recommendation right now, don't use SHA1 anymore. Symmetric function, something you're probably
508100	513860	more familiar with, which is a cryptographic function that given a key, you can use it on a
513860	518780	piece of information and then it will be hidden. Use the same key again, you get the information
518780	528000	right back. So example, take AS, AS is the currently known best practice to use for encrypting
528000	532820	symmetric information. So I just like, it's pseudocode, but like Python notation, padded it
532820	539320	with 21 zeros, get something. Change a bit, get something dramatically different. Why is this
539320	546440	important? It's important because if the cryptographic function produces an output that has
546440	551080	some sort of information in it, it doesn't look like random noise, it means that I can go ahead
551080	558820	and break this algorithm. I'll give you an example. One of my friends, he's a master thesis,
558820	564880	was to break an algorithm called WEP, might have heard of it for Wi-Fi. And the reason it was
564880	572920	broken was because when you used the algorithmic function called RC4, RC4 wasn't stable. The
572920	579140	first 1,000 or 2,000 bits coming out of RC4 had a bias. So you can guess with good certainty
579140	584560	what was the key that produced that output if you recorded that output. So once you did that,
584560	589720	you just record some information out of the air and now you know the key for that WEP encryption.
589720	595880	But that's pretty bad. You want something to be very, very stable, very, very good. So AES is
595880	600760	currently the standard and it's a good standard and you could be very happy using it. And there
600760	607760	are other cryptographic algorithms out there to supplement it when the time comes. Asymmetric
607760	612080	cryptography, I'm not going to go into a lot of length here, but that's what you probably all know
612080	617160	from private public keys. Basically what they mean is that if you have a pair of public and
617160	624280	private keys, you can give everybody your public key, they can encrypt the message with the public
624280	628840	key that you gave away, but because you're the only one who has a private key, you're the only
628840	634220	one who is able to decrypt that message. So hand wavingly, this is the way that works. And this is
634220	642380	something that a lot of our internet, our data communication is based on. There was a
642380	645740	presentation, I don't know if you've seen the Twitter storm about it, I think it was, I'm not
645740	652460	sure if it was yesterday or two days ago, in Black Hat by a company called Time AI. They do 5D
652860	659460	encryption with quasi prime numbers and lots of other, they enhance their cryptographic functions
659460	665660	with music and emotions. And it was like, I could not believe that this was a Black Hat talk. So
666340	672960	choosing like vetted, known, good algorithms is what you should do. You should not invent your
672960	680060	own algorithms. And I'll come back to that message in a moment with some examples. So what is a
680060	685720	signature? A signature is having some private key and using that in order to provide a proof to
685720	690020	everyone that a piece of code or a piece of message is something that you actually guarantee came
690020	694980	from you. So how does that work? So I'll take my message, could be my library or something similar,
694980	700100	and I'll calculate or compute the hash of that message using the SHA-1 or something similar from
700100	706760	before. Then I'll provide a signature. A signature is just taking a public private key algorithm,
706760	712220	using my private key, I'll encrypt the hash. Now I have an encrypted hash that was encrypted with
712220	717440	my private key. So I'm not giving anyone my private key, but I know that it's, I can assure
717440	722800	someone that it's mine. How can I ensure someone that it's mine? I give everybody my public key and
722800	726700	I give them the message. They will compute their own version of the hash because they do it by
726700	732860	themselves, they don't trust me anymore. And they decrypt the message using the public key. Now if
732860	738940	they got the same key, the same hash, that means that I am the owner of the private key, of the
738940	746760	public key, and therefore this message came from me. Sorry. So the whole concept of signature is
746760	752120	based on the idea that I can share something publicly, I can keep something private, not tell
752120	759160	that to anyone. But using that information, I can also convince you of my identity as a holder of
759160	765480	that private key. Okay. One of the things and probably the last tenets for this very short
765480	771240	introduction is the idea of randomness. Almost everything that we do in cryptography is somehow
771240	777740	centered about randomness. So if we don't have a very strong randomness source, everything breaks.
777740	781640	And I'll give some examples of that. So usually when we talk about randomness, we talk about two
781640	787120	different things. The first one is called the TRNG or true random number generator. And the other is
787120	793060	called PRNG, absurd random number generator. The big difference between the two is that the PRNG is
793160	798920	a function. If I'll give it a known starting point, it will always get to the same result. Change the
798920	804280	starting point, you'll get a different result, but it's derived in deterministic fashion. TRNG, I
804280	809220	have no idea what's not going to happen. So it's just like measuring neutrons from the air or like
809220	814120	measuring electromagnetic interference. It might be zero, it might be one, I have no idea what's
814120	820540	going to happen. So a good TRNG will give me bits with a probability of 50%. I don't know what it
820540	826400	would be. If it was something like, let's say 49%, I would be able to break that random number
826400	834080	generator. So we need something that's very, very stable. So how do you use that? You take a PRNG and
834080	839260	you provide it with an input that's come from a real world entropy source, something that's actually
839260	847360	truly random. So what happens when it isn't random? Sometimes people misuse random numbers. For
847360	852320	example, when they're writing code and they need to use nonces. Everybody are familiar with what's
852420	859160	a nonce? Okay, so a nonce should be just a random number. It shouldn't be constant, it shouldn't be
859160	865440	hardcoded into your code, until it is. And when it is, funny things happen. So I'll give you an
865440	873840	example. Probably heard of Bitcoin, once or twice, maybe. So Bitcoins is actually a
873840	881660	cryptographic operation. So what are coins? Coins are actually going and trying to find inputs that
881660	888780	given a hash function will provide a pre-known output. So that's the difficult problem, not
888780	894360	because it's mathematically hard, but because it's very difficult to find those inputs. So what do
894360	900180	you do? You try a lot of different attempts, found one, you earn the coin. Now you are an owner of a
900180	906000	single Bitcoin. This is exponentially harder as time goes by, which means you have to invest more
906000	911360	time, more resources, more CPU power in order to actually mine those Bitcoins. But the basic
911360	917380	principle still holds. Wallets, or your Bitcoin wallets, are just identities. They are something
917380	923040	that represent your private and public keys. And transactions are actually just saying, I'll take
923040	928140	this piece of money and I'll give it to that private key or that holder of that private key, and this
928140	933240	is a transaction. Just shifting money or shifting coins or pieces of coins from one source to
933240	942120	another. And I should have clicked like 20 minutes ago. An important thing to note, if you lose your
942120	948600	private key, you lost your money. Because your coins are held by your private key. If you don't
948600	953400	have access to your private key anymore, you don't have access to your coins. Something to keep in
953400	958660	mind when you're playing around with Bitcoin. So the last thing I want to talk about is called
958660	964640	elliptic curve cryptography. If you're familiar with RSA, basically the same thing, much cheaper to
964640	972060	execute, much less compute power, same guarantees for security. Bitcoin is using these elliptic
972060	977840	curve cryptography operations in order to move money about. So that's the basic algorithms behind
977840	984340	Bitcoin. So this is a screenshot from a Bitcoin transfer. So what you can actually see is that
984340	993060	this value here, this is the address of the source, which is actually the hash of my public key. And
993060	1000320	I'm moving money, 7.179 blah blah Bitcoins, into two different addresses, and the addresses are
1000320	1005400	just the hashes of the public keys of the recipients. This is everything that there is to it.
1005400	1015180	This is the entire Bitcoin idea in a slide. So how would you go about attacking this? So I will not
1015180	1020220	going to bore you with the mathematical details behind this, but I'll try to direct your attention
1020220	1028600	to a couple of things. The transaction actually happens when I, as an owner of a Bitcoin, will sign
1028600	1034600	over a portion of that coin into a new address, to a new private key, or sorry, to a new hash of a
1034600	1040320	public key. In order to do that, I have to work with a couple of components. The hash of the
1040320	1047240	message, K, which is random, R, which is the multiplication operation under elliptic curves, and
1047240	1051740	the signature. And the way to calculate the signature is outlined in the formula in the bottom.
1051980	1056780	So there's something here which should stick out like a sore thumb to everyone who looks at it,
1056780	1067120	which is, maybe I can show my hair. K should be random. And sometimes when implementers are
1067120	1074020	reading the spec, they say, okay, K should be random, so I'll select a random number. So what
1074020	1080200	happens when K isn't random? Assume that K isn't random. If I can go over on the block, look at all
1080200	1086480	the blockchain, all the Bitcoin transactions, and find two different transactions that share the
1086480	1092200	same random number. Suddenly, this is a problem in sixth grade algebra. Because if I know the
1092200	1099300	value for K, I can just move about the equation, isolate K, and solve for everything else. And I
1099300	1104980	solve and I solve, and finally I have D. Now I have the private key. Because in elliptic curve
1104980	1111940	operations, when you're not using random numbers, everything breaks. So it's a tenet of using
1111940	1117840	elliptic curves. So you say, okay, this is like nonsense. Who wouldn't use random numbers in the
1117840	1124080	real world? This never happens. And the answer is, well, of course it does. So this is a
1124080	1129220	screenshot from many, many years ago, 2013, when somebody noticed that people are stealing money
1129220	1135440	from wallets. And how did this attack happen? Because someone else was probably a bit brighter
1135440	1141060	noticed that people are using bad wallets or bad wallet software, where the developers for that
1141060	1146240	piece of software for that wallet didn't realize that they need to generate a new K for every
1146240	1152960	transaction. So what they've done is just searched the transaction logs for two different
1152960	1158140	transactions using the same random number, extracted the private key, and stole all of their
1158140	1164500	bitcoins. This was in the entire attack. So, you know, that's kind of if somebody wants to mess
1164500	1169900	with bitcoins, like they had it coming. I have no problems with that. But you say, this shouldn't
1169900	1176700	happen in, like, real world applications, like big sized interesting stuff. So how does that
1176700	1182000	look like in the real world? When you generate a random number, what you should probably be
1182000	1188800	doing is something like open slash dev slash random and pull a number of bytes out of it, maybe
1188800	1193840	30, I don't know, just throw in a number there. But you should do this for every time that you
1193840	1199600	need a random number. Because when you don't, you get something like this. You choose the
1199600	1206680	random number very securely, once, and hard code it. Which is like analogous to saying, what's
1206680	1219140	my random number? Four. It was chosen by a fair dice roll. I'll skip this. Okay. We'll come back
1219140	1223580	to the point of the randomness in a moment. I want to show you a piece of code and ask
1223580	1229440	everyone, can everybody see the problem with this piece of code? Any hands? It was pretty
1229440	1235540	famous for a while. Okay. We have one person. Two persons. Excellent. So I'll highlight it for
1235540	1243640	everyone. So this piece of code is actually the verification code for X509 certificates on
1243640	1251040	iOS. Or it used to be. And what this means is when you're doing a TLS transaction, somebody
1251040	1255220	needs to check the certificate. How do you check the certificate? Just the same way that we
1255220	1260340	talked previously. Just check the public keys, find out the hashes, compare them, check them. And
1260340	1266160	the way that the code is written is that if there's an error, some check didn't pass, go to
1266160	1273280	fail. But what happens here is you have a double line. So the first line is in the scope of that
1273280	1279320	if. The second line isn't in the scope of anything. So anything written after that never
1279320	1285200	executes. Okay? Whenever you go into that point, you immediately go to fail. So how is that
1285200	1291740	interesting for an attacker? If you specially craft your certificate that you would pass each
1291740	1297320	and every check up to that point, even though your certificate is invalid, you will still pass
1297320	1303060	the test. Because nobody tests for like everything, you just test up to that point. And that
1303060	1308940	meant that attackers could create certificates for, I don't know, for example, iOS apps that are
1308940	1313960	invalid and malicious but have like certificates which are bad but pass the verification
1313960	1324420	process. So special attention needs to be given to these kinds of cases. Am I missing a slide? Let
1324420	1338600	me check. Yeah. I should have said something here and I skipped it, so let me circle back for a
1340640	1344720	second. So Sony, you might have heard of them, have a device or had a device called the
1344720	1349280	PlayStation 3. And the PlayStation 3 was pretty awesome, everybody liked playing with it, but
1349280	1354540	they couldn't really copy the games. Why? Because of the digital rights management protection
1354540	1359600	on the games. But what Sony didn't really take into account or their developers didn't think
1359600	1364620	about very thoroughly is that when they signed the games, they signed them with elliptic curves
1364620	1371800	but they chose a single random value and it was hard-coded. So when the guys at Overflow found
1371800	1378260	this out, they understood, okay, I can just take two different games, compare the signatures,
1378260	1383380	find the random values that they used, derive the private key and now I can sign whatever game
1383380	1389480	that I want for Sony because I have the private keys because they didn't use random values. So
1389480	1394260	this was a very big thing for a while because those hard-coded numbers were hard-coded
1394260	1400060	into the PlayStation 3 hardware device itself, the firmware. And they couldn't really update
1400060	1405580	this, they couldn't circumvent this, they just lost a lot of money because someone made a
1405580	1410660	mistake about assuming something about random numbers. Sorry, I completely missed my point
1410660	1419740	here. Circling back to Bitcoin, everybody remember this screen from two and a half years ago,
1419740	1428740	something like that? So attackers behind WannaCry built, I don't know, let's call it a GUI or
1428740	1433720	something that will give you some information, how can you get the keys in order to get back all
1433720	1439240	your files that they encrypted, just send me some money to this Bitcoin address. And they were
1439240	1443860	supposed to send you back the keys and everybody would be very happy. So a couple of things
1443860	1448200	happened. The first one was that obviously they never sent the keys. The second one was that the
1448200	1453340	WannaCry attack was stopped pretty much in the middle because of a different operation. They
1453340	1459900	had like a failsafe so they could stop the propagation of the malware from going everywhere
1459900	1466500	because, that's like a different story, but the malware would check if a specific domain name
1466500	1473940	was registered. If it was registered, it would stop the work. So while that domain name was not
1473940	1478580	registered, it would continue to propagate. So one of the security researchers would just
1478580	1484020	finish, if you're following up on the news, just finish his trial, find that out from reverse
1484020	1488760	engineering the software, he registered that domain, he paid like, I don't know, $5 for it and
1488760	1493880	stopped WannaCry. So that was the first thing that was really not very smart about WannaCry. The
1493880	1501080	second thing was that they kind of missed the point of using Bitcoin. Bitcoin is a confidential
1501080	1506700	service, but it's not an anonymous service. It means that everybody can be the owner of
1506700	1511440	Bitcoins and their identity is protected. You don't have to tell anyone your identity, but
1511440	1517020	everything you do is always logged, is always recorded. It's part of the very mechanism of how
1517020	1523400	transactions on the blockchains work. And that means that if I'm a malicious attacker, and I'm
1523400	1528180	asking people to send money over to my wallet, everything is traceable, everything is
1528180	1533920	accountable, and it's part of the design of the system. And if I want to cash out, now I have a
1533920	1540360	problem. Because if I try to cash out, somebody can just okay, now you linked that identity with
1540360	1547220	this real world credit card. So they had money stuck there, they had about $70,000 if I
1547220	1552080	remember correctly, they had it stuck there for a couple of months until they thought about a
1552080	1557780	solution, which was just doing cash exchanges in Macau or something like that, to go over there,
1557780	1562440	pull out the money very fast and disappear. But while they were doing this, they really couldn't
1562440	1569640	touch the funds, because whatever you do with the funds, it's always traceable. Okay. So how
1569640	1575800	does this look in the real world? New example. Who uses BitLocker, or at least heard of it enough
1575800	1582700	to understand the term? I don't believe you. Who has Windows laptops? Really, everybody runs
1582700	1593740	Linux? Wow, cool. I'm really proud of you guys. So BitLocker is, I wouldn't call it a protocol,
1593740	1599420	but it's like a feature where your hard drive will self encrypt everything. So if somebody steals
1600100	1605320	the hard drive and connects it to a new computer, he can't read the data that's on that device.
1605380	1611080	That's a description of that feature. What really happens is that when you connect it to the
1611080	1618680	operating system, the operating system is something like this. Are you a hard drive or SSD or
1618680	1624580	whatever that supports hardware encryption? And the BitLocker supported device says, yes, of
1624580	1630840	course I know encryption. Let's use my encryption. So if you have a hardware supported encryption
1630840	1636240	on your hard drive, it will use the hardware version. If you don't have support, then Windows
1636240	1641740	will simulate that support in software. What's the problem with that? The problem with that is
1641740	1646220	the very premise that hardware is actually better than software. Because the way that the hardware
1646220	1655140	developers did that was mumble about. What they did. They had a password that's used by your
1655140	1660460	BIOS in order to encrypt or decrypt information from your hard drive, and they had a key. But
1660460	1664380	there is no relationship between the password and the key. So you can type any password that you
1664380	1670320	want, the key will still be fixed. It will be orthogonal to the password that you used. So
1670320	1676860	they didn't tie together in any way. Second thing is, they used the same key to encrypt the entire
1676860	1680900	drive. All of the different partition, all of the different blocks and sections. Which means
1680900	1685820	that I have lots and lots of different blocks of encrypted data that I can compare against that are
1685820	1691560	all using the same key. Which means that if you had a bad implementation, you just made my life
1691560	1697940	easier as an attacker. And the last thing is, they didn't really use random keys. I'm just
1697940	1703180	dissing here, but think of it as an equivalent of a 12 character password where it's all ones.
1703680	1708980	Okay? So they didn't randomize the password. So you had the same password for all blocks on
1708980	1713440	your hard drive, which didn't have any correspondence with a password for your BIOS or
1713440	1717840	anything else. So you couldn't customize it, it didn't tie into anything from the real world.
1717840	1725220	And that meant that, I'll skip that, and that meant that all of those drives were very, very
1725220	1731120	weak from a cryptographic perspective. It's almost trivial to break them. However, the
1731120	1736140	operating system by default will choose the hardware encryption over the software encryption.
1736140	1741820	And that means that any laptop that you probably have or had for the past year or older than
1741820	1748680	that, didn't really have the security guarantees that you thought it had by using the
1748680	1755820	BitLocker and similar properties, similar features. Here's just, I don't know, I just found it
1755820	1760940	like an extremely funny example. Somebody on Stack Exchange asked for an algorithm to encrypt
1760940	1765240	your password. I know you can't read it, so I'll enlarge it. So the method that he was
1765240	1772900	suggesting to do was to take a Base64 encoding of your password and then reverse it, apply
1772900	1777560	Base64, and now you have an encryption. So the amount of things that are wrong with that
1777560	1782700	sentence are that... I don't know, he summarized this much better than me. The first thing is
1782700	1789920	that Base64 is a bad choice because it enlarges the space requirement to store the same kind
1789920	1793920	of information. The second thing is obviously this has nothing to do with cryptography, it's
1793920	1799860	just encoding the same information in a different way. Reversing the encoding does nothing for
1799860	1805360	security, just means that I have to reverse it again. And the basic thing is that this
1805360	1812420	was an entire thread on Stack Exchange, should I use MD5 to encrypt my files and encrypt
1812420	1817780	my passwords, where one, MD5 is not an encryption algorithm, and two, it has nothing to do with
1817780	1822740	it, it's broken, use something else. And this guy came along and suggested to use this amazing
1822740	1827740	piece of code that he wrote in order to protect everybody's password. So be careful of where
1827740	1833880	you get your advice. I'm not dissing Stack Exchange, I'm just saying you should vet information
1833880	1842940	that you receive. I think it's my last example. I do want to explain the concept and what
1842940	1848720	I find problematic with it, but the basic idea is that it is actually a good piece of
1848720	1853340	software, it just had its own limitation. So what this guy, he wrote a piece of software
1853340	1858320	called Crypt Hook, and the problem he was trying to solve is that you have information
1858320	1863060	on server A, and you want to communicate with server B, but you don't have the facilities
1863060	1866880	to encrypt the information, you can't change the software that's running on the servers.
1867080	1871860	So what he said, okay, I'll hook the system calls, and every network packet that transfers
1871860	1878140	from server A to server B, I will encrypt it myself. So I will, like, create an out-of-bed
1878140	1883700	encrypted channel between the two servers that has nothing to do with the software running
1883700	1888420	on them. It will still transparently use the network stack, and I will encrypt the network
1888420	1893140	stack. Out of the box, it's not like a bad idea, this really solves a real problem where
1893140	1897180	you can't touch the software. On the other hand, the choices that he's made, made it
1897180	1904440	very, very weak. So he chose to use GCM, which nobody should really care what it means, to
1904440	1909740	do authentication, but he encrypted everything with a fixed key. So every packet was encrypted
1909740	1915120	with the same key. Not only was that every packet was encrypted with the same key, there
1915120	1918380	was no difference between the packets, so everything was encrypted exactly the same
1918380	1924980	way. So it was absolutely easy for an attacker to capture a packet and replay it, send it
1924980	1930320	again over the network. So if you had a packet that says, transfer $1,000 to my account,
1930320	1934420	you can just capture that packet and replay it again and again and again, because no
1934420	1939680	one would know, because there's no such information inside the packet to stop that. Also, you
1939680	1944760	can change the order of the messages. You can do whatever you want with it, like dropping
1944760	1949580	some of the messages, because his encryption scheme didn't think about those kinds of edge
1949580	1955500	cases or use cases. But also, it meant that if I broke the key once, because it was fixed,
1955500	1959840	it was hard-coded, that meant that I now had the key to every communication that would
1959840	1964560	ever happen with this piece of software, which is tentative to just reading the source
1964560	1971780	code because the key was there. So the question is, is everything on fire? Is everything bad?
1972280	1978080	So obviously the answer to that is no, not everything is on fire, not everything is bad.
1978080	1984460	But you should really pay special consideration whenever you're touching something related
1984460	1991560	to crypto. Crypto is hard. There are experts, usually PhDs, that spend years and years of
1991560	1997000	their lives researching crypto problems and crypto properties in order to make sure that
1997000	2002280	whatever they're doing is very, very safe. You're not going to outperform them, you're
2002280	2007640	not going to outsmart them, and you probably shouldn't be trying. Never roll your own crypto.
2007640	2012820	Use best practices, use what's already out there. In my next slide, I'll give some recommendation.
2012820	2017680	But also, you have a special use case, you have some problem that's unique and you don't
2017680	2023480	know if the current tooling is able to solve that. Well, ask around, ask an expert. I can
2023480	2028740	recommend two, let's say, expert advice channels that you can use. The first one is using Reddit,
2028740	2033640	the crypto subreddit, but also the crypto stack exchange. Both are wonderful resources
2033640	2039120	to consult with real world experts that can help you understand your problem and the right
2039120	2044920	kind of tooling, the right kind of algorithms that you can use to solve that unique problem.
2045100	2049740	More than that, you can always pay consultants. I'm a consultant, I'm getting paid to give
2049740	2054120	advice, that's fine. There are experts that you can talk to on Twitter, anywhere else,
2054120	2059960	you will get advice. People are nice, basically, most of the time. You can also pay a crypto
2059960	2064100	review firm to go and look over your crypto code to make sure you haven't done something
2064100	2069060	horrible like what happened to Sony. You don't want to be in that position where you wrote
2069060	2072960	your own crypto or your team wrote some crypto because you thought you would be really solving
2072960	2077420	something and you just horribly broke the entire security premise of your product.
2079320	2084080	So what's my advice to you? That's probably the slide you should copy or photograph or
2084080	2089560	just listen very carefully. The first one is that make sure that you're using the right
2089560	2098300	libraries for you. Personally, I never recommend OpenSSL. Who has experience using OpenSSL
2098300	2104600	APIs or implementing OpenSSL code in their own ID or in their own product? Anyone using
2104600	2114880	OpenSSL? How sorry are you? Have you tried anything else? Not really. So at least my
2114880	2121820	opinion of OpenSSL, it's a big, large, bloated piece of software that tries to do everything
2121820	2127900	and most of the time doesn't do them the most efficient or the most proper way and it gives
2127900	2132400	you... I used to have a boss that told me that C is a wonderful language. It gives you
2132400	2137860	every tool possible to slit your own throat. So in a sense, OpenSSL is the same way. They
2137860	2142460	support everything. Every legacy algorithm, every parameter ever conceived for anything
2142460	2147880	and if you will misuse this or configure it wrongly or use the wrong parameters, you won't
2147880	2152920	even know that you broke your crypto. So my first recommendation for you is just use
2152920	2157160	something simpler. And you know, the world has advanced. There are lots of very good
2157160	2164760	libraries out there. Archimedecommon, BoringSSL, the Golang crypto stack is excellent. NACL
2164760	2172800	is also very, very good. NSS is very good. I do want to say that all of the libraries
2172800	2177440	I mentioned here are good and I recommend them myself. Sometimes they have issues. They
2177440	2182180	have bugs. They have patches that you need. And this is actually a good thing. Because
2182180	2186140	that means that somebody is maintaining this. Somebody is actually looking if there are
2186140	2190800	any issues and somebody is trying to fix them. So whenever such a thing exists, take that
2190800	2194940	into your consideration, into your dependency stack and make sure that your own code is
2194940	2201020	up to date. Never trust people that roll their own crypto. There are lots of like, oh, yeah,
2201020	2206160	we have a student. He's really brilliant. We ask him to write our crypto stack. That's
2206160	2211060	not a good idea. Even if he is brilliant. Use best practices. Use what's already out
2211060	2216160	there. Just use it correctly. You have a much easier time, much better time overall.
2216720	2222940	The last thing is that... sorry. The last thing that I want to mention about that is
2222940	2229020	that not every feature that exists in crypto is actually something that you need. So cryptography
2229020	2233240	has a lot of building blocks that are used in many, many different ways. Some of them
2233240	2239100	are very esoteric. Some of them are like the mainline use cases. 90% of the time,
2239100	2243360	you need the mainline use case. It's already described. It's already known. Just use that.
2243360	2247380	Don't invent anything. Don't try to like, oh, that's a nice looking piece of technology.
2247380	2251420	Just like, let's use that instead. You need to think about it and you probably need some
2251420	2254580	cryptographer to let you know if you did this correctly or not.
2255560	2261680	So what you can do. Update your libraries. I've seen so many customers, so many people
2261680	2269160	who use OpenSSL and like version 1.01 or something like that. And it's not updated at all. Because
2271260	2276300	it's hard to update and they're afraid it will break something. And with OpenSSL, that's
2276300	2282580	very cumbersome anyway. So make your life easier. Make sure that you have thought of
2282580	2286800	how are you going to update this? How are you going to fix this when the time comes?
2287380	2292440	If you want to become an expert, my recommendation to you is to start small. Go to trainings,
2292440	2297960	to workshops, hear talks, go over YouTube, read a book. You can become an expert on cryptography
2297960	2302580	without knowing math. You don't need a math degree in order to better understand crypto.
2302580	2306920	You probably need a math degree or even a math PhD to invent crypto. But not to use
2306920	2312520	it. To use it properly, study. Like everything else that we do. Study. This is a domain of
2312520	2316300	knowledge that you can use, you can learn. It's not scary. It's not something that you
2316300	2322600	should be afraid of. Down the line, you probably want to either outsource or hire the right
2322600	2328260	people to look at cryptography very closely. But if you're not inventing cryptography,
2328260	2332680	just use something that someone else already did. It will make your life easier and probably
2332680	2346810	get better security out of it. With that, I would thank you very much. I'll be happy
2346810	2351470	to take questions now in a moment. And if not, I'll be also outside later to take more
2351470	2359810	questions. Yes, sir? That depends on what your desktop is. If you're on Linux or on
2359810	2366730	your own Windows or you're on Chrome OS or differently. But I would trust with a mild
2366730	2372010	degree of assault attached to it. But I would trust the operating system to hold secrets.
2372890	2377310	They're usually pretty good. Depending on how much trust you need for that secret. If
2377310	2381810	I have a desktop application, usually that means I have my own laptop or storing my own
2381810	2385770	bank accounts or something like that, that's secure enough. If I have a production server
2385770	2391290	hosting secrets for my 100,000 customers, that's a different question. There I would
2391290	2397090	use an HSM or something similar. HSM is a hardware security module. That's actually a
2397090	2400670	piece of hardware that holds secrets and lets you do cryptographic operations without
2400670	2408800	revealing those secrets. So we can talk about that later. Yes? Yeah?
2428570	2435530	I fully agree. I'll repeat that. The Capital One issue hand wavingly was not actually an
2435530	2440490	encryption issue, it was a permission issue. So if you give someone permissions or you
2440490	2447130	commit to GitHub your keys, then you actually give everybody permission to use your keys to
2447130	2451310	do whatever they want to do. So the cryptography is still very strong but you haven't
2451310	2455070	protected your keys. So in a sense that's what happened with Capital One. Both for roles
2455070	2475620	and permissions for the access list they used for attacking. Well, here's where you
2475620	2479720	actually need an expert to come and help you and look at your own specific use case. But if
2479720	2484100	you encrypted your entire database but you kept the key in a script by that database, then
2484100	2487620	you haven't really done anything. But if you encrypted your entire database and the key
2487620	2491800	comes from a different component which checks your permissions and stuff like that, then you
2491800	2496960	already have a different security model. So this is actually a more complex question to
2496960	2500500	answer and not necessarily relevant for client side encryption depending on what you're
2500500	2509700	trying to solve. Okay, more questions please. Be brave. Go on. Going to the next one.
2509720	2512400	Thank you very much.
