1 00:00:00,000 --> 00:00:02,900 All right. Next up, please give a warm welcome to Scott 2 00:00:02,900 --> 00:00:06,100 Arsazewski. He's going to be giving a talk called, No Way 3 00:00:06,100 --> 00:00:09,360 Jose, Designing Cryptography Features for Mere Mortals. 4 00:00:09,560 --> 00:00:10,280 Welcome, Scott. 5 00:00:16,960 --> 00:00:20,680 Hey, thanks for having me here. As she said, my name is Scott 6 00:00:20,680 --> 00:00:24,120 Arsazewski. You might know of me from some of my open source 7 00:00:24,120 --> 00:00:28,460 projects online through Paragon Initiative Enterprises. You can 8 00:00:28,460 --> 00:00:32,340 blame me for getting Lipsodium into PHP 7.2 and for rewriting 9 00:00:32,340 --> 00:00:37,580 it in PHP. My Twitter handle is CypherCoder with PHP in it and 10 00:00:37,580 --> 00:00:41,360 sometimes I live up to that name, which kind of goes into the 11 00:00:41,360 --> 00:00:46,560 whole point why we're here today. Everybody in security 12 00:00:46,560 --> 00:00:50,040 knows that you should not roll your own crypto, right? That's 13 00:00:50,040 --> 00:00:54,380 common knowledge. It's actually repeated a lot on the Internet 14 00:00:54,380 --> 00:00:58,440 and everyone knows it. It's common wisdom. So, I'm going to 15 00:00:58,460 --> 00:01:01,840 talk about this. There's good reasons for it. If you follow the 16 00:01:01,840 --> 00:01:04,440 work of Bruce Schneier, you know that amateurs produce amateur 17 00:01:04,440 --> 00:01:07,860 cryptography. It's very difficult to get right. You might 18 00:01:07,860 --> 00:01:10,060 think it's secure and find out you have a timing side channel. 19 00:01:11,980 --> 00:01:14,480 Even people who have been experts in the field for years 20 00:01:14,480 --> 00:01:21,640 make mistakes. And the problem is that the buck usually stops 21 00:01:21,640 --> 00:01:27,960 there. Developers are told, don't build your own. But that's 22 00:01:27,960 --> 00:01:34,000 it. They're just told not to. So, when people say, okay, well 23 00:01:34,000 --> 00:01:37,180 instead of rolling my own, what should I do, they're often told 24 00:01:37,180 --> 00:01:42,060 something like this. And I copied that from my friends at 25 00:01:42,060 --> 00:01:49,880 Latakora. So, most developers work, they do line of business 26 00:01:49,880 --> 00:01:52,740 software development of some form, CRUD apps, moving data 27 00:01:52,740 --> 00:01:55,340 from point A to point B. Sometimes they do really cool 28 00:01:55,340 --> 00:01:57,940 stuff with machine learning, but usually if they need to increase 29 00:01:57,960 --> 00:02:01,720 encryption, it's to protect data they're storing. So, they have 30 00:02:01,720 --> 00:02:06,500 business goals. So, they just need to solve problems. And they 31 00:02:06,500 --> 00:02:09,500 need easy to use tools that will just solve the problem and get 32 00:02:09,500 --> 00:02:13,040 out of their way without, you know, exposing them to you have 33 00:02:13,040 --> 00:02:15,420 to select this particular configuration for it to be 34 00:02:15,420 --> 00:02:17,900 secure and you have all these options to, you know, research 35 00:02:17,900 --> 00:02:24,260 and learn about. And let's take a look at one really egregious 36 00:02:24,260 --> 00:02:27,900 example of this. It's called Jose, the JavaScript object. 37 00:02:27,960 --> 00:02:31,160 Signing an encryption standard. Some of you might be familiar 38 00:02:31,160 --> 00:02:36,720 with it. It's a family of standards with several RFCs. 39 00:02:40,780 --> 00:02:45,080 Most of them relate to authenticated tokens either 40 00:02:45,080 --> 00:02:47,180 signed using public key cryptography or secret key 41 00:02:47,180 --> 00:02:49,880 cryptography or they're encrypted. People use them for 42 00:02:49,880 --> 00:02:53,260 all sorts of things. They're supposed to be used for short 43 00:02:53,260 --> 00:02:56,780 lived claims. Like if you have a third party download server and 44 00:02:56,780 --> 00:02:57,940 you want to say, yes, this is what I want to do, I'm going to 45 00:02:57,960 --> 00:03:00,740 do this. To do that, they can download this file once. That's 46 00:03:00,740 --> 00:03:04,600 the envisioned use case. People abuse them for like stateless 47 00:03:04,600 --> 00:03:06,960 session and all that and it was never really designed for that 48 00:03:06,960 --> 00:03:12,680 use case in mind. So, if you look at the RFC, you can see a 49 00:03:12,680 --> 00:03:16,280 lot of text that explains pretty much what I just said. The 50 00:03:16,280 --> 00:03:21,380 important thing is that a JWT, pronounced jot, uses either 51 00:03:21,380 --> 00:03:26,520 encryption or signature algorithm. So, consequently, if 52 00:03:26,520 --> 00:03:27,940 there's a JWS or JWT is a JOT, it's a JOT. It's a JWT. So, if 53 00:03:27,940 --> 00:03:34,420 JWE vulnerability, it probably applies to your JWT library. And there's implementations of 54 00:03:34,420 --> 00:03:38,700 JSON Web Tokens in pretty much every language. Most developers use them whether they realize 55 00:03:38,700 --> 00:03:44,240 them or not. And here's what they look like. You have a header, you have the message, and 56 00:03:44,240 --> 00:03:50,740 then you have your signature. Now let's take a look at the JSON Web signatures real quick. You 57 00:03:50,740 --> 00:03:57,220 have this thing called an ALG header, which was the red in the slides up here. That tells you 58 00:03:57,220 --> 00:04:03,160 what algorithm you're using and what type it is. There's different options. You have HS256, 59 00:04:03,340 --> 00:04:14,140 you know, HMAC SHA256. You have RS256, RSA with PKCS1V1.5 and SHA256. And you, of course, 60 00:04:14,160 --> 00:04:23,940 have none. This is the textbook bad API design mistake. It's mixing symmetric and 61 00:04:23,940 --> 00:04:25,680 asymmetric cryptography in the same context. 62 00:04:28,520 --> 00:04:32,060 And unfortunately, attackers are the ones who provide the tokens, which contains all this 63 00:04:32,060 --> 00:04:39,160 metadata. So they can choose the header. And so, you know, this sounds dangerous. It is. It 64 00:04:39,160 --> 00:04:43,720 actually gets worse than that. Because in the RFC that defines JSON Web Tokens, it says the 65 00:04:43,720 --> 00:04:48,040 header parameter must be present and must be understood and processed by implementations. And 66 00:04:48,040 --> 00:04:53,700 if you've ever worked with software developers, you'll know that that means obeyed. Right? They 67 00:04:53,700 --> 00:04:57,200 don't parse standards the same way that people that write them do. They say you can't use this. 68 00:04:57,200 --> 00:05:02,100 It must be processed and understood. That means we have to adhere to whatever the token says. And 69 00:05:02,100 --> 00:05:08,000 this has led to vulnerabilities that we've probably all heard of before in JSON Web Token 70 00:05:08,000 --> 00:05:14,680 libraries. JSON Web Encryption is not much better. Look at these key encryption options. 71 00:05:15,760 --> 00:05:24,240 Right? This is for encrypting a key to later on encrypt the token body. Now, if you noticed, we 72 00:05:24,240 --> 00:05:30,220 have three asymmetric ones and one symmetric key option. This was clearly not the result of 73 00:05:30,220 --> 00:05:36,740 careful designing of use cases. This was a design by committee of trying to solve the 99% problem 74 00:05:36,740 --> 00:05:44,680 rather than the 50% problem at day one. Furthermore, the ECDHES, which is Liptic Curve Diffie 75 00:05:44,680 --> 00:05:53,760 Hellman encryption, something like that, the way they specified it in the Jose standards opened the 76 00:05:54,240 --> 00:05:58,780 valid curve attacks, which allow an attacker to keep feeding you tokens and then steal your 77 00:05:58,780 --> 00:06:08,440 private key. The way that, the reason why this is the case is that they say it must specify the 78 00:06:08,440 --> 00:06:14,140 X and Y coordinate of your public key point. What it should have done is either only specified 79 00:06:14,140 --> 00:06:21,360 one of the coordinates and, you know, a signing bit or make point validation an explicit part of 80 00:06:24,240 --> 00:06:24,920 what's showing up on the bin. The way it says, I don't need a password. But if I did it first, 81 00:06:24,920 --> 00:06:27,020 the code is a bit out of the game. So that's some of the problems built into the Jose standards. 82 00:06:28,440 --> 00:06:34,760 There's a more general problem. So they say, okay, let's give developers options. My friend 83 00:06:34,760 --> 00:06:39,520 Taylor Hornby wrote a blog post about this, where he called that reasoning by lego. And, you 84 00:06:39,520 --> 00:06:45,600 see a lot of this in the internet. Especially early 90s and early 2000s crypto designs. Like 85 00:06:45,600 --> 00:06:52,240 people who do MAC and encrypt. Not MAC then encrypt or encrypt then MAC. People say, well we 86 00:06:52,240 --> 00:06:55,740 have a secure MAC function and we have a secure encryption function, this should be secure. 87 00:06:56,100 --> 00:07:00,720 But it's not the two pieces that make the protocol secure. It's also how it's joined 88 00:07:00,720 --> 00:07:09,300 together. So to put this in layman's terms that a developer would understand. You're 89 00:07:09,300 --> 00:07:14,240 building a brick wall, right? But instead of putting bricks and laying mortar and putting 90 00:07:14,240 --> 00:07:19,340 more bricks and more mortar, instead you have this mesh with empty space of just mortar in 91 00:07:19,340 --> 00:07:25,260 place. And you're supposed to slide the bricks you prefer into place. You know, the 92 00:07:25,260 --> 00:07:30,700 architects who designed this brick wall insist that it gives you more flexibility. Would you 93 00:07:30,700 --> 00:07:35,680 trust that wall to hold up the roof? That's how cryptography libraries and standards have 94 00:07:35,680 --> 00:07:42,700 been built historically. TLS is no exception, although 1.3 is a heck of an improvement. So 95 00:07:43,520 --> 00:07:48,420 Tupone or JotTupone? There are a lot of ways for the standards to go wrong. We've seen some 96 00:07:48,420 --> 00:07:49,320 of them in CVS. There are a lot of ways for the standards to go wrong. We've seen some of them 97 00:07:49,320 --> 00:07:54,220 in VE's over the past three years. We'll probably see even more. There's a lot of RFCs that I 98 00:07:54,220 --> 00:08:00,880 haven't even had time to delve into, the specify weird cipher modes. And then there's 99 00:08:00,880 --> 00:08:04,960 implementation security risks and user error. Somebody could just say, okay, I'm going to 100 00:08:04,960 --> 00:08:10,020 make the, you know, JSON web token key their user name. And then I'll use that for HMAC 101 00:08:10,020 --> 00:08:14,420 validation. That would be a user error. And then implementation specific would be a library 102 00:08:14,420 --> 00:08:19,300 that, like, has a timing attack vulnerability and the, you know, MAC validator. And then 103 00:08:19,300 --> 00:08:24,460 that would be a user error. Whenever I would raise these criticisms of the standard to the 104 00:08:24,460 --> 00:08:31,760 people who design and advocate for Jose libraries, or Jose, their response was always, well, you 105 00:08:31,760 --> 00:08:35,360 should use one of these libraries. You should use this one. We've vetted this one. Don't use 106 00:08:35,360 --> 00:08:40,500 the other one. That doesn't really solve the problem. It shifts the blame from the badly 107 00:08:40,500 --> 00:08:45,060 designed standard onto the library's developers and their users, the people who are trying to 108 00:08:45,060 --> 00:08:49,280 choose a library. And if we want to build a library that's not going to work, we're going to 109 00:08:49,300 --> 00:08:55,920 build secure systems. This is an anti-pattern. That bears emphasizing. And there's an entire 110 00:08:55,920 --> 00:09:01,020 series of anti-patterns at play here. So the people who design standards say let's give users 111 00:09:01,020 --> 00:09:04,420 lots of choices. In case one of them turns out not to be a good one, then we can just 112 00:09:04,420 --> 00:09:11,800 deprecate that down the line. Which never happens. You still see systems using RC4 today. Their 113 00:09:11,800 --> 00:09:18,760 advocates will blame the implementation rather than the standard. Security experts will say, well, 114 00:09:19,700 --> 00:09:27,060 don't use this standard. Don't use JWT. And then developers roll their own crypto because 115 00:09:27,060 --> 00:09:31,820 they're not given an alternative. And this is what happened with JSON Web Tokens and the other 116 00:09:31,820 --> 00:09:37,300 half of my talk that I wanted to go into. So can you really blame developers for rolling their 117 00:09:37,300 --> 00:09:44,520 own crypto when they're not given a viable alternative to bad designs? I say no. If our goal 118 00:09:44,520 --> 00:09:48,620 is to stop badly written cryptography from being put out in the world, which means 119 00:09:48,760 --> 00:09:54,060 having non-experts design it, we need to design a better standard that's easy to use 120 00:09:54,060 --> 00:10:01,880 securely. And hard to use insecurely. With that in mind, I designed POSETO, Platform 121 00:10:01,880 --> 00:10:09,320 Agnostic Security Tokens. You can see how it's pronounced there. When I set out on this, I had a 122 00:10:09,320 --> 00:10:14,600 few design goals in mind. I wanted to minimize run time negotiation. That's where you would 123 00:10:14,600 --> 00:10:18,740 say, okay, you have these ciphers you can choose from, now pick from this list. I want to minimize the 124 00:10:18,760 --> 00:10:20,580 wanted that to be completely trimmed down as much as 125 00:10:20,580 --> 00:10:25,780 possible. I wanted versions tokens, built in versioning so 126 00:10:25,780 --> 00:10:29,040 that way if you have version 1 and version 2 of the standard 127 00:10:30,300 --> 00:10:33,480 and then version 1 becomes critically insecure to where you 128 00:10:33,480 --> 00:10:36,180 don't want to run it anymore and version 2 is implicated because 129 00:10:36,180 --> 00:10:39,580 of some new attack, you can design version 3 and then 130 00:10:39,580 --> 00:10:42,380 migrate everyone on to that. Like let's say a practical 131 00:10:42,380 --> 00:10:45,280 quantum computer comes out and that breaks all of elliptic 132 00:10:45,280 --> 00:10:50,060 curve cryptography. So each version has its own one true 133 00:10:50,060 --> 00:10:54,100 cyber suite. You don't have a lot of options. It's either, I'll 134 00:10:54,100 --> 00:10:56,860 go into what the options are. You're using version 1 or 135 00:10:56,860 --> 00:11:01,660 version 2 or version 3. Less knobs and levers for people to 136 00:11:01,660 --> 00:11:06,040 play with and get wrong. And that's pretty much it. That's 137 00:11:06,040 --> 00:11:09,240 the main design philosophy I took that was different from the 138 00:11:09,240 --> 00:11:14,920 pose standards. So since I showed you a, you know, JSON 139 00:11:14,920 --> 00:11:18,360 Web Token, this is what the structure of a POSETO looks like. 140 00:11:19,000 --> 00:11:22,120 You have a version. Pretty obvious from everything I've 141 00:11:22,120 --> 00:11:26,420 said. You have a purpose. They're called local and public. 142 00:11:27,020 --> 00:11:31,440 And the difference is not subtle. Local is symmetric key 143 00:11:31,440 --> 00:11:34,940 authenticated encryption. Public is just a digital signature 144 00:11:34,940 --> 00:11:41,260 using RSA for version 1 or ed 255 19 for version 2. And you 145 00:11:41,260 --> 00:11:44,900 have an optional footer. The reason for an optional footer 146 00:11:44,920 --> 00:11:49,100 is because some people want to do key rotation. So they would 147 00:11:49,100 --> 00:11:53,020 want an unencrypted part of a local token. They could store 148 00:11:53,020 --> 00:11:55,540 like a key identifier that references a specific public key 149 00:11:55,540 --> 00:12:02,040 or a specific secret key. Everything is base 64 URL 150 00:12:02,040 --> 00:12:05,620 encoded as in defined in the RFC and joined by period 151 00:12:05,620 --> 00:12:11,820 characters just like JSON Web Tokens are. So the version 152 00:12:11,820 --> 00:12:14,900 defines the cyber suite. The purpose tells you that the 153 00:12:14,920 --> 00:12:17,820 user is a user. It tells you what it's doing. And the footer 154 00:12:17,820 --> 00:12:22,920 is optional for key rotation schemes. Envision use cases is 155 00:12:22,920 --> 00:12:26,220 pretty much the same use case that JSON Web Tokens is supposed 156 00:12:26,220 --> 00:12:30,400 to be solving. Short lived one time third party access tokens. 157 00:12:31,040 --> 00:12:33,280 That was all it was designed for. They threw all this 158 00:12:33,280 --> 00:12:38,360 complexity and machinery on top of it for solving every use case 159 00:12:38,360 --> 00:12:42,420 with one tool. And more specifically I want to 160 00:12:42,420 --> 00:12:44,780 eventually integrate this into something like open ID connect 161 00:12:44,920 --> 00:12:51,800 so people can use this instead of JSON Web Tokens for OAuth. So 162 00:12:51,800 --> 00:12:56,080 as I said there's two versions defined in the initial run. There 163 00:12:56,080 --> 00:12:58,620 might be future ones when quantum computers become a more 164 00:12:58,620 --> 00:13:02,760 you know imminent threat. Compatibility mode uses open SSL 165 00:13:02,760 --> 00:13:06,640 like the ciphers that almost everybody is familiar with. RSA 166 00:13:06,640 --> 00:13:13,680 AES uses SHA2. Specifically it uses AES 256 encounter mode. 167 00:13:14,620 --> 00:13:19,180 HMAC SHA384 and encrypt thin MAC. And then uses HKDF to split 168 00:13:19,180 --> 00:13:23,940 the keys. I use SHA384 just as a standard hash function. There's 169 00:13:23,940 --> 00:13:26,460 no reason 256 wouldn't have worked or 512 wouldn't have 170 00:13:26,460 --> 00:13:32,460 worked. But there are a lot of people who will look at it. One 171 00:13:32,460 --> 00:13:35,600 subtle decision made somewhere in one standard and reapply it 172 00:13:35,600 --> 00:13:39,960 everywhere. So if I went with SHA256 developers would assume 173 00:13:39,960 --> 00:13:43,380 that SHA256 was secure. Never mind that there's length 174 00:13:43,380 --> 00:13:43,660 extension. I'm not going to go into that. I'm just going to 175 00:13:43,680 --> 00:13:46,380 talk about extension attacks and what not if they decide to build 176 00:13:46,380 --> 00:13:51,220 their own MAC protocol with that. And then public key 177 00:13:51,840 --> 00:13:56,220 signatures. If you've worked with RSA you'll probably be 178 00:13:56,220 --> 00:14:00,180 relieved that PKCS1V1.5 is not here. Instead you get the 179 00:14:00,180 --> 00:14:03,400 probabilistic signature scheme. The secure RSA signature scheme 180 00:14:03,900 --> 00:14:10,280 with a hard coded set of parameters. And then you have 181 00:14:10,280 --> 00:14:12,720 the recommended version. This is the one I actually want people to 182 00:14:12,720 --> 00:14:16,900 use. But they might not have libsodium which is what I'm using 183 00:14:16,900 --> 00:14:21,460 as a basis for this. Specifically it uses the extended notch, 184 00:14:21,580 --> 00:14:27,660 extended nonce cha cha 20 poly 1305 AAD mode. And then it 185 00:14:27,660 --> 00:14:33,540 uses ED25519 for signatures. So let's look at one. So in this 186 00:14:33,540 --> 00:14:40,060 example the payload is foo and the footer is bar. This is a 187 00:14:40,060 --> 00:14:42,700 local token. It's color coded. I don't know if you've seen it. 188 00:14:42,700 --> 00:14:46,060 It seems to show up pretty well on the slide. You can see that 189 00:14:46,060 --> 00:14:49,680 you have the version, the purpose, a payload and then a 190 00:14:49,680 --> 00:14:53,820 footer at the end. And here's the key that actually generated 191 00:14:53,820 --> 00:14:57,320 this if anybody wanted to download one of the many 192 00:14:57,320 --> 00:15:02,020 libraries that implement Paseto and play with it at home. And 193 00:15:02,020 --> 00:15:08,300 here's a public payload. You can see that the string changed 194 00:15:08,300 --> 00:15:10,960 from local to public and it's a little bit longer because it's a 195 00:15:10,960 --> 00:15:12,680 digital signature. But you see the 196 00:15:12,700 --> 00:15:15,740 first four letters of the yellow. That will not change 197 00:15:15,740 --> 00:15:20,100 because that's actually plain text. And then if you look at it 198 00:15:20,480 --> 00:15:24,240 oh yeah here's the keys. Without a footer it just looks like 199 00:15:24,240 --> 00:15:30,580 this. And if you go back and forth quickly you'll see that 200 00:15:30,580 --> 00:15:32,800 the first four letters of the yellow did not change because 201 00:15:32,800 --> 00:15:37,520 that's bar in base 64 URL. That's what they look like. 202 00:15:37,680 --> 00:15:40,720 That's what developers will see. They don't really need to know 203 00:15:40,720 --> 00:15:42,680 all of the internals. But can you see that the first four 204 00:15:42,700 --> 00:15:44,680 letters of the yellow are the same? I'm going to go into them a 205 00:15:44,680 --> 00:15:50,920 little bit. So for all versions, there's a couple rules that I 206 00:15:50,920 --> 00:15:54,660 wrote into this proposed standard that will eventually 207 00:15:55,960 --> 00:16:00,920 hopefully be taken seriously by the IETF and accepted as an 208 00:16:00,920 --> 00:16:03,620 RFC. I have a first draft submitted to them, got some 209 00:16:03,620 --> 00:16:06,880 feedback. I'm working on the second one right now. The first 210 00:16:06,880 --> 00:16:12,280 rule for randomness is to use U random specifically or more 211 00:16:12,280 --> 00:16:12,680 broadly as a random. You can use whatever you want to use. You 212 00:16:12,700 --> 00:16:15,720 the operating systems cryptographically secure random 213 00:16:15,720 --> 00:16:18,620 number generator. You're not allowed to use a linear 214 00:16:18,620 --> 00:16:22,180 congruent generator or a MRCIN twister or any other insecure 215 00:16:22,180 --> 00:16:27,700 user space design. That's a standard rule. If you're doing 216 00:16:27,700 --> 00:16:31,860 that, you're deviating from the standard and you shouldn't do 217 00:16:31,860 --> 00:16:40,280 that. No NCCA2 insecure public key cryptography. Specifically I 218 00:16:40,280 --> 00:16:44,560 would call out this padding mode for RSA. It will never be 219 00:16:44,560 --> 00:16:47,220 allowed. If anybody suggests it, the answer is going to be no, 220 00:16:47,260 --> 00:16:50,820 closed, won't fix, works as intended. And the reason is 221 00:16:50,820 --> 00:16:54,580 because, I hope I'm pronouncing his name right, Bleichenbacher 222 00:16:55,120 --> 00:16:58,120 had that 1998 padding Oracle attack that's still relevant 20 223 00:16:58,120 --> 00:17:01,100 years later. It's old enough to drink. I think it's high time we 224 00:17:01,100 --> 00:17:03,860 stopped building that padding mode into new protocols and 225 00:17:03,860 --> 00:17:07,800 designs. And Robot just won a pony award at Black Hat, so 226 00:17:07,800 --> 00:17:10,260 you know, congratulations to Robot. 227 00:17:10,280 --> 00:17:16,540 And finally, when possible, do everything in constant time. 228 00:17:17,080 --> 00:17:20,980 This includes Base64 URL encoding. I will post these 229 00:17:20,980 --> 00:17:23,720 slides online afterwards. That actually links to a PHP library 230 00:17:24,180 --> 00:17:29,560 that implements Base64 encoding without any cache timing side 231 00:17:29,560 --> 00:17:34,980 channels. So another thing that's built into the standard 232 00:17:34,980 --> 00:17:38,240 is what's called pre-authentication encoding. This 233 00:17:38,240 --> 00:17:40,260 isn't really an immediate security concern, but it's 234 00:17:40,280 --> 00:17:44,580 a class of attacks based on how you feed data into your message 235 00:17:44,580 --> 00:17:49,460 authentication code called canonicalization attacks. So 236 00:17:49,460 --> 00:17:52,500 basically this is just a proactive measure to ensure that 237 00:17:52,500 --> 00:17:58,480 every message doesn't create collisions from having 238 00:17:58,480 --> 00:18:02,820 multi-part messages. So you can't just, you know, append a 239 00:18:02,820 --> 00:18:05,560 bunch of data and have it match a signature that has a footer 240 00:18:05,560 --> 00:18:08,660 that originally didn't have a footer so you can forge it. Or 241 00:18:08,660 --> 00:18:10,260 anything weird like that. So basically this is just a 242 00:18:10,280 --> 00:18:13,360 pre-authentication. So what we do here is we prefix it, we 243 00:18:13,360 --> 00:18:18,300 take the number of pieces and we turn it into a string, you know, 244 00:18:18,320 --> 00:18:20,900 binary packed string representation of that number 245 00:18:21,380 --> 00:18:25,440 in little Indian as 64-bit. And then for each piece we do the 246 00:18:25,440 --> 00:18:28,100 same exact thing. We prefix it with the length in the same 247 00:18:28,100 --> 00:18:32,500 encoding format and then we put the string. This might sound a 248 00:18:32,500 --> 00:18:35,760 little weird. I'll get to what it does in just a second. So 249 00:18:36,820 --> 00:18:40,260 when a posse is being encrypted, you're going to have a string 250 00:18:40,280 --> 00:18:40,560 that is the same length as the header. So this is a very 251 00:18:40,560 --> 00:18:41,440 powerful way to do it. So instead of just feeding the cipher 252 00:18:41,440 --> 00:18:44,660 text into the message authentication code, you know, 253 00:18:44,680 --> 00:18:48,520 HMAC, it actually does the pre-authentication encoding and 254 00:18:48,520 --> 00:18:52,260 takes that output of all those pieces and then uses the HMAC 255 00:18:52,260 --> 00:18:56,520 of that. So this will authenticate not only the header 256 00:18:56,520 --> 00:18:59,940 V1.local, it will also authenticate the nonce which is 257 00:18:59,940 --> 00:19:02,440 generated randomly, the ciphertext and the optional 258 00:19:02,440 --> 00:19:07,500 footer. The same thing happens with the RSA signature. It 259 00:19:07,500 --> 00:19:10,260 covers the header, message and optional footer. So this will be 260 00:19:11,060 --> 00:19:14,580 just an empty string followed by 8 null bytes if you didn't 261 00:19:14,580 --> 00:19:19,900 specify one. For version 2, subtle difference between how 262 00:19:20,880 --> 00:19:24,700 the crypto AEAD interface works. It already authenticates the 263 00:19:24,700 --> 00:19:27,840 ciphertext. You can specify your additional data. So it 264 00:19:27,840 --> 00:19:31,300 just packs together the header, the nonce and the footer for 265 00:19:31,760 --> 00:19:36,420 version 2. And that's because libsodium and other 266 00:19:36,420 --> 00:19:38,880 implementations of the same protocol already authenticate 267 00:19:38,880 --> 00:19:40,260 the ciphertext. This is just a simple way to do it. So we'll 268 00:19:40,280 --> 00:19:45,160 just use the additional data. And then add 25519 is exactly 269 00:19:45,160 --> 00:19:49,620 what you'd expect if you looked at the RSA slide previously. So 270 00:19:49,620 --> 00:19:53,960 let's compare the two real quick. JSON Web Tokens has a lot 271 00:19:53,960 --> 00:19:58,120 of options, including unauthenticated options. It 272 00:19:58,120 --> 00:20:01,320 promotes reasoning by Lego which, you know, you have two 273 00:20:01,320 --> 00:20:03,160 pieces that doesn't necessarily mean they're secure if they're 274 00:20:03,160 --> 00:20:06,860 not glued together properly or in the right order. And it's 275 00:20:06,860 --> 00:20:10,080 often abused for stateless tokens. That's something that 276 00:20:10,280 --> 00:20:12,380 people will criticize JSON Web Tokens for and they don't 277 00:20:12,380 --> 00:20:14,960 really look further because that's what most developers are 278 00:20:14,960 --> 00:20:19,920 doing. You have two options. You have version and 279 00:20:19,920 --> 00:20:24,160 purpose. Everything's authenticated and your local 280 00:20:24,160 --> 00:20:26,580 tokens are always encrypted so you don't accidentally leak 281 00:20:26,580 --> 00:20:29,820 sensitive information for a local system. It does it's job 282 00:20:29,820 --> 00:20:32,500 and it gets out of the way. People can still abuse this for 283 00:20:32,500 --> 00:20:36,520 stateless tokens, but it doesn't have the built-in habit in the 284 00:20:36,520 --> 00:20:39,460 community yet. And I've been actively discouraging it when 285 00:20:39,460 --> 00:20:40,260 people ask if they can use it. I've been actively discouraging it 286 00:20:40,280 --> 00:20:41,940 when people ask if they can use it this way. So hopefully that 287 00:20:41,940 --> 00:20:46,500 won't be a re-immersion issue. If it is, of course, that's what 288 00:20:46,500 --> 00:20:48,380 the security industry is here for is to tell them not to do 289 00:20:48,380 --> 00:20:51,540 that. If you'd like to learn more about the standard I'm 290 00:20:51,540 --> 00:20:55,460 trying to build, you can go to poseto.io or github.com slash 291 00:20:55,460 --> 00:20:59,000 Paragon IE slash poseto and you can look and see the RFC draft 292 00:20:59,000 --> 00:21:02,420 is being written and marked down. You can look at the reference 293 00:21:02,420 --> 00:21:06,260 implementation and PHP. If you look at the first URL, there's 294 00:21:06,260 --> 00:21:10,180 like implementations in about 11 other languages. That number is 295 00:21:10,180 --> 00:21:12,660 going to go up when I get home because I have a couple to review 296 00:21:12,660 --> 00:21:18,740 when I get back. So that's just an example. A very important one 297 00:21:18,740 --> 00:21:25,700 in my opinion, but there's a more general topic here. It's 298 00:21:25,700 --> 00:21:30,400 about designing cryptography for humans. Using the examples that I 299 00:21:30,400 --> 00:21:34,540 just gave you, if we want developers to build secure 300 00:21:34,540 --> 00:21:37,600 software and we give them crypto building blocks that are 301 00:21:37,600 --> 00:21:40,160 actually secure, that won't fail them. If we want developers to 302 00:21:40,160 --> 00:21:40,180 build secure software and we give them crypto building blocks 303 00:21:40,180 --> 00:21:41,400 that are actually secure, that won't fail them. But in order to do 304 00:21:41,400 --> 00:21:44,000 that, we have to know how to design cryptography for humans to 305 00:21:44,000 --> 00:21:47,000 use safely. You know, mere mortals, humans, developers, 306 00:21:47,240 --> 00:21:51,940 whatever noun you want to use there. So you should have an 307 00:21:51,940 --> 00:21:55,100 opinionated interface. This should be your API for any 308 00:21:55,100 --> 00:21:58,580 encryption library. You have your message, your key, and an 309 00:21:58,580 --> 00:22:01,140 optional data to include in the authentication tag. Your 310 00:22:01,140 --> 00:22:04,240 decryption should be exactly the same. You shouldn't have to 311 00:22:04,240 --> 00:22:07,480 specify a mode. You shouldn't have to even know what a nonce 312 00:22:07,480 --> 00:22:10,140 is, let alone the subtle difference between a nonce and a 313 00:22:10,160 --> 00:22:14,000 initialization vector. Which, does anybody here not know the 314 00:22:14,000 --> 00:22:17,400 difference between a nonce and an initialization vector, aka IV? 315 00:22:22,620 --> 00:22:28,420 Okay. So you should have hard coded version protocols, which 316 00:22:28,420 --> 00:22:31,620 means that, like Poseto, you have version 1 and version 2. 317 00:22:31,800 --> 00:22:35,880 You don't have version 1 in ECB mode and version 1 in CBC mode 318 00:22:35,880 --> 00:22:39,740 and version 1 in counter mode. You just have version 1. And they 319 00:22:39,740 --> 00:22:42,000 should be vetted by cryptographers. If you're not a 320 00:22:42,000 --> 00:22:44,860 cryptographer and you want to design one, you should hire one 321 00:22:44,860 --> 00:22:48,280 to audit your design, like give you protocol review, give you 322 00:22:48,280 --> 00:22:52,340 recommendations, etcetera. And if a vulnerability is ever 323 00:22:52,340 --> 00:22:55,220 found in the current version, a new one should be published with 324 00:22:55,220 --> 00:22:57,940 a better hard coded cipher suite instead of giving people options. 325 00:22:58,600 --> 00:23:01,900 Because if you give developers options, a lot of them are going 326 00:23:01,900 --> 00:23:04,160 to choose poorly and that's how we end up in the situation we're 327 00:23:04,160 --> 00:23:09,640 in today. This is different from what a lot of other people will 328 00:23:09,640 --> 00:23:09,720 understand, and so let's talk about the product to be any way to 329 00:23:09,720 --> 00:23:13,340 believe in. When you're designing cryptography libraries 330 00:23:13,340 --> 00:23:17,480 and you're working with keys, don't just accept binary strings 331 00:23:18,040 --> 00:23:23,500 or byte arrays. Encapsulate them in an object, specifically a 332 00:23:23,500 --> 00:23:26,080 typed object. If you have a signing secret key, you know, 333 00:23:26,100 --> 00:23:28,960 for asymmetric cryptography, that should be distinct from 334 00:23:28,960 --> 00:23:32,140 your symmetric secret key. Even if they're the same bit length, 335 00:23:32,300 --> 00:23:35,100 even if you generate them from the same randomness device, you 336 00:23:35,100 --> 00:23:39,120 want to keep a little bit of type safety there. That also 337 00:23:39,120 --> 00:23:41,420 discourages them from using their passwords as their key, 338 00:23:41,660 --> 00:23:44,260 which if you've worked with PHP developers, you know that 339 00:23:44,260 --> 00:23:49,300 problem is more commonplace than we even want to get into. And 340 00:23:49,300 --> 00:23:55,980 there's an additional benefit here. I'm not really at liberty 341 00:23:55,980 --> 00:24:00,940 to go into how often this one turns up in my work, but it's a 342 00:24:00,940 --> 00:24:06,980 lot. Stack traces and uncaught exceptions and error codes 343 00:24:06,980 --> 00:24:09,100 ending up in automated bug reports. That's a lot of 344 00:24:13,340 --> 00:24:13,720 stuff. So I'm going to talk a little bit about stack traces. 345 00:24:13,720 --> 00:24:13,740 Stack traces is a tool that's been around for a long time. 346 00:24:13,740 --> 00:24:16,120 that's been around for years and years and years. So when you 347 00:24:16,120 --> 00:24:19,280 go in and you look at their bug tracker, you can just grep for 348 00:24:19,280 --> 00:24:21,640 password and you can find a lot of their users' real passwords 349 00:24:24,220 --> 00:24:26,140 because they're being passed around as strings and the 350 00:24:26,140 --> 00:24:28,400 programming languages that people work with don't assume 351 00:24:28,400 --> 00:24:30,420 it's sensitive. It just goes, oh, it's a string. I'm going to 352 00:24:30,420 --> 00:24:33,200 include it in the stack trace to be helpful. So if you 353 00:24:33,200 --> 00:24:35,780 encapsulate it in an object, you can actually hide it from stack 354 00:24:35,780 --> 00:24:39,100 traces easily. My friend Taylor, who is a big fan of Stack Traces, 355 00:24:39,100 --> 00:24:42,680 who coined the phrase reasoning by Lego, actually wrote a PHP 356 00:24:42,680 --> 00:24:46,120 library. You've probably heard of it as defuse slash PHP 357 00:24:46,120 --> 00:24:50,400 encryption. And that was one of the main departures from the 358 00:24:50,400 --> 00:24:57,200 norm that went to that design. Always logically separate 359 00:24:57,200 --> 00:25:00,880 symmetric from asymmetric cryptography. So that way, you 360 00:25:00,880 --> 00:25:03,240 know, people don't try to use RSA to encrypt something that 361 00:25:03,240 --> 00:25:07,960 doesn't need to be, doesn't need the overhead or complexity of 362 00:25:07,960 --> 00:25:09,080 asymmetric cryptography. So I'm going to talk a little bit about 363 00:25:09,100 --> 00:25:10,360 that in just a second. So if you're storing it in a database 364 00:25:10,360 --> 00:25:13,480 and your application that's writing it needs to be able to 365 00:25:13,480 --> 00:25:19,920 read it, you don't need RSA. Just use AES. Java and their 366 00:25:19,920 --> 00:25:23,060 built-in cipher is the probably most egregious example of 367 00:25:23,060 --> 00:25:30,820 violating this rule. Failure emotes. So when PHP 7 was being 368 00:25:30,820 --> 00:25:34,180 discussed and they were adding a new cryptographically secure 369 00:25:34,180 --> 00:25:38,240 random number generator API to be consistent regardless of OS and 370 00:25:39,100 --> 00:25:43,880 all that, the original run would return false if it couldn't 371 00:25:43,880 --> 00:25:47,360 generate random numbers securely. Which PHP is a weakly typed 372 00:25:47,360 --> 00:25:52,720 language. A lot of people would say, you know, set this letter of 373 00:25:52,720 --> 00:25:56,100 a password to an index of an array based on the random int 374 00:25:56,100 --> 00:25:58,760 that was just generated. So if you have a random integer and 375 00:25:58,760 --> 00:26:01,260 it's set to false, it's going to return a zero, you're not only 376 00:26:01,260 --> 00:26:03,240 going to end up with passwords that will look like the letter A 377 00:26:03,240 --> 00:26:09,080 repeating ten times. So the, you know, the, you know, the 378 00:26:09,100 --> 00:26:13,760 best thing for any, to do for designing some, a library for 379 00:26:13,760 --> 00:26:16,520 developers to use is to throw exceptions or whatever 380 00:26:16,520 --> 00:26:19,780 equivalent error handling mechanism the programming 381 00:26:19,780 --> 00:26:25,320 language allows. This way if they catch the exception, they 382 00:26:25,320 --> 00:26:28,280 can fail gracefully. They can have their pretty error page, 383 00:26:28,520 --> 00:26:31,300 they can silently encrypt and email a report to the developer 384 00:26:31,300 --> 00:26:33,960 saying, hey, this broke and it shouldn't have, you know, this 385 00:26:33,960 --> 00:26:37,580 is a high alert, fix it now. Or they can just log into a bug 386 00:26:37,580 --> 00:26:39,080 tracker. What's the point of doing that? You know, it's just a 387 00:26:39,100 --> 00:26:42,800 matter of whatever they want to do. If you fail closed in a way 388 00:26:42,800 --> 00:26:45,280 that doesn't allow them to catch the exception, like if you just 389 00:26:45,280 --> 00:26:49,520 have a fatal error, developers won't use the new API. An 390 00:26:49,520 --> 00:26:53,680 unpredictable, you know, white page or a failure scares 391 00:26:53,680 --> 00:26:55,680 developers. It's like, okay, well, this is going to crash. 392 00:26:55,840 --> 00:26:58,020 It's going to make my system unstable. I'm going to get the 393 00:26:58,020 --> 00:27:00,860 call at 2 in the morning to fix something that, you know, is a 394 00:27:00,860 --> 00:27:04,800 random error. And that just makes them nervous. They won't 395 00:27:04,800 --> 00:27:07,500 want to use it. And they'll go back to using rand and mt rand 396 00:27:07,500 --> 00:27:09,080 forever. So, you know, it's, you know, it's, you know, it's a 397 00:27:09,100 --> 00:27:11,060 lot of work. And then, you know, the exception being the 398 00:27:11,060 --> 00:27:13,800 middle ground between the two. And you don't want to fail open 399 00:27:14,280 --> 00:27:17,660 like the first example did. Eventually that was ironed out 400 00:27:17,660 --> 00:27:26,440 and when 7.0 launched, PHP does the right thing. Okay. So just 401 00:27:26,440 --> 00:27:30,060 a quick recap. Or actually, this is the recap. The blame 402 00:27:30,060 --> 00:27:33,420 game doesn't solve insecurity. Telling developers don't use 403 00:27:33,420 --> 00:27:37,940 JDUT like many security experts did last year and not giving 404 00:27:37,940 --> 00:27:39,080 them something viable to fix. That's not going to solve 405 00:27:39,100 --> 00:27:43,220 any security issues. They'll just keep using it out of spite 406 00:27:43,220 --> 00:27:45,720 and they're going to stop listening to you. Or they're 407 00:27:45,720 --> 00:27:49,040 going to invent their own. Or they're just going to say screw 408 00:27:49,040 --> 00:27:51,060 it, let's not even sign anything. Let's just store a 409 00:27:51,060 --> 00:27:55,460 token that's completely plain text. If you don't give them an 410 00:27:55,460 --> 00:27:58,100 option that's better, they're going to probably choose a 411 00:27:58,100 --> 00:28:04,000 poorer one because that's all the options they have. The only 412 00:28:04,000 --> 00:28:05,860 way to really prevent people from designing their own 413 00:28:05,860 --> 00:28:08,620 cryptography and, you know, implementing it and publishing 414 00:28:08,620 --> 00:28:12,500 it in a way that, you know, I'm talking about amateur designs 415 00:28:12,500 --> 00:28:15,500 here, is to give them something that already solves their problem 416 00:28:15,500 --> 00:28:18,000 for them that's easy enough to use to where they won't have the 417 00:28:18,000 --> 00:28:21,900 incentive to get creative. This won't stop arrogant people from 418 00:28:21,900 --> 00:28:24,200 thinking that they're smarter than the people who built, you 419 00:28:24,200 --> 00:28:27,920 know, invented AES, et cetera, because, well, we're not going 420 00:28:27,920 --> 00:28:29,580 to get through to arrogant people anyway. They think they 421 00:28:29,580 --> 00:28:34,400 know better. Your API should always be simple to understand. 422 00:28:36,000 --> 00:28:38,600 Whenever I talk about crypto documentation, I say every API 423 00:28:38,620 --> 00:28:45,460 asterisk is a disaster risk. I strongly believe in preferring 424 00:28:45,460 --> 00:28:50,500 version protocols over cipher agility. And error prone 425 00:28:50,500 --> 00:28:54,240 standards should be deprecated in favor of safer ones for 426 00:28:54,240 --> 00:28:58,820 developers to use. At that point, do I have any questions? 427 00:29:01,960 --> 00:29:03,860 All right. Let's give it up for Scott. 428 00:29:08,620 --> 00:29:08,860 Thank you.