All right. Next up, please give a warm welcome to Scott Arsazewski. He's going to be giving a talk called, No Way Jose, Designing Cryptography Features for Mere Mortals. Welcome, Scott. Hey, thanks for having me here. As she said, my name is Scott Arsazewski. You might know of me from some of my open source projects online through Paragon Initiative Enterprises. You can blame me for getting Lipsodium into PHP 7.2 and for rewriting it in PHP. My Twitter handle is CypherCoder with PHP in it and sometimes I live up to that name, which kind of goes into the whole point why we're here today. Everybody in security knows that you should not roll your own crypto, right? That's common knowledge. It's actually repeated a lot on the Internet and everyone knows it. It's common wisdom. So, I'm going to talk about this. There's good reasons for it. If you follow the work of Bruce Schneier, you know that amateurs produce amateur cryptography. It's very difficult to get right. You might think it's secure and find out you have a timing side channel. Even people who have been experts in the field for years make mistakes. And the problem is that the buck usually stops there. Developers are told, don't build your own. But that's it. They're just told not to. So, when people say, okay, well instead of rolling my own, what should I do, they're often told something like this. And I copied that from my friends at Latakora. So, most developers work, they do line of business software development of some form, CRUD apps, moving data from point A to point B. Sometimes they do really cool stuff with machine learning, but usually if they need to increase encryption, it's to protect data they're storing. So, they have business goals. So, they just need to solve problems. And they need easy to use tools that will just solve the problem and get out of their way without, you know, exposing them to you have to select this particular configuration for it to be secure and you have all these options to, you know, research and learn about. And let's take a look at one really egregious example of this. It's called Jose, the JavaScript object. Signing an encryption standard. Some of you might be familiar with it. It's a family of standards with several RFCs. Most of them relate to authenticated tokens either signed using public key cryptography or secret key cryptography or they're encrypted. People use them for all sorts of things. They're supposed to be used for short lived claims. Like if you have a third party download server and you want to say, yes, this is what I want to do, I'm going to do this. To do that, they can download this file once. That's the envisioned use case. People abuse them for like stateless session and all that and it was never really designed for that use case in mind. So, if you look at the RFC, you can see a lot of text that explains pretty much what I just said. The important thing is that a JWT, pronounced jot, uses either encryption or signature algorithm. So, consequently, if there's a JWS or JWT is a JOT, it's a JOT. It's a JWT. So, if JWE vulnerability, it probably applies to your JWT library. And there's implementations of JSON Web Tokens in pretty much every language. Most developers use them whether they realize them or not. And here's what they look like. You have a header, you have the message, and then you have your signature. Now let's take a look at the JSON Web signatures real quick. You have this thing called an ALG header, which was the red in the slides up here. That tells you what algorithm you're using and what type it is. There's different options. You have HS256, you know, HMAC SHA256. You have RS256, RSA with PKCS1V1.5 and SHA256. And you, of course, have none. This is the textbook bad API design mistake. It's mixing symmetric and asymmetric cryptography in the same context. And unfortunately, attackers are the ones who provide the tokens, which contains all this metadata. So they can choose the header. And so, you know, this sounds dangerous. It is. It actually gets worse than that. Because in the RFC that defines JSON Web Tokens, it says the header parameter must be present and must be understood and processed by implementations. And if you've ever worked with software developers, you'll know that that means obeyed. Right? They don't parse standards the same way that people that write them do. They say you can't use this. It must be processed and understood. That means we have to adhere to whatever the token says. And this has led to vulnerabilities that we've probably all heard of before in JSON Web Token libraries. JSON Web Encryption is not much better. Look at these key encryption options. Right? This is for encrypting a key to later on encrypt the token body. Now, if you noticed, we have three asymmetric ones and one symmetric key option. This was clearly not the result of careful designing of use cases. This was a design by committee of trying to solve the 99% problem rather than the 50% problem at day one. Furthermore, the ECDHES, which is Liptic Curve Diffie Hellman encryption, something like that, the way they specified it in the Jose standards opened the valid curve attacks, which allow an attacker to keep feeding you tokens and then steal your private key. The way that, the reason why this is the case is that they say it must specify the X and Y coordinate of your public key point. What it should have done is either only specified one of the coordinates and, you know, a signing bit or make point validation an explicit part of what's showing up on the bin. The way it says, I don't need a password. But if I did it first, the code is a bit out of the game. So that's some of the problems built into the Jose standards. There's a more general problem. So they say, okay, let's give developers options. My friend Taylor Hornby wrote a blog post about this, where he called that reasoning by lego. And, you see a lot of this in the internet. Especially early 90s and early 2000s crypto designs. Like people who do MAC and encrypt. Not MAC then encrypt or encrypt then MAC. People say, well we have a secure MAC function and we have a secure encryption function, this should be secure. But it's not the two pieces that make the protocol secure. It's also how it's joined together. So to put this in layman's terms that a developer would understand. You're building a brick wall, right? But instead of putting bricks and laying mortar and putting more bricks and more mortar, instead you have this mesh with empty space of just mortar in place. And you're supposed to slide the bricks you prefer into place. You know, the architects who designed this brick wall insist that it gives you more flexibility. Would you trust that wall to hold up the roof? That's how cryptography libraries and standards have been built historically. TLS is no exception, although 1.3 is a heck of an improvement. So Tupone or JotTupone? There are a lot of ways for the standards to go wrong. We've seen some of them in CVS. There are a lot of ways for the standards to go wrong. We've seen some of them in VE's over the past three years. We'll probably see even more. There's a lot of RFCs that I haven't even had time to delve into, the specify weird cipher modes. And then there's implementation security risks and user error. Somebody could just say, okay, I'm going to make the, you know, JSON web token key their user name. And then I'll use that for HMAC validation. That would be a user error. And then implementation specific would be a library that, like, has a timing attack vulnerability and the, you know, MAC validator. And then that would be a user error. Whenever I would raise these criticisms of the standard to the people who design and advocate for Jose libraries, or Jose, their response was always, well, you should use one of these libraries. You should use this one. We've vetted this one. Don't use the other one. That doesn't really solve the problem. It shifts the blame from the badly designed standard onto the library's developers and their users, the people who are trying to choose a library. And if we want to build a library that's not going to work, we're going to build secure systems. This is an anti-pattern. That bears emphasizing. And there's an entire series of anti-patterns at play here. So the people who design standards say let's give users lots of choices. In case one of them turns out not to be a good one, then we can just deprecate that down the line. Which never happens. You still see systems using RC4 today. Their advocates will blame the implementation rather than the standard. Security experts will say, well, don't use this standard. Don't use JWT. And then developers roll their own crypto because they're not given an alternative. And this is what happened with JSON Web Tokens and the other half of my talk that I wanted to go into. So can you really blame developers for rolling their own crypto when they're not given a viable alternative to bad designs? I say no. If our goal is to stop badly written cryptography from being put out in the world, which means having non-experts design it, we need to design a better standard that's easy to use securely. And hard to use insecurely. With that in mind, I designed POSETO, Platform Agnostic Security Tokens. You can see how it's pronounced there. When I set out on this, I had a few design goals in mind. I wanted to minimize run time negotiation. That's where you would say, okay, you have these ciphers you can choose from, now pick from this list. I want to minimize the wanted that to be completely trimmed down as much as possible. I wanted versions tokens, built in versioning so that way if you have version 1 and version 2 of the standard and then version 1 becomes critically insecure to where you don't want to run it anymore and version 2 is implicated because of some new attack, you can design version 3 and then migrate everyone on to that. Like let's say a practical quantum computer comes out and that breaks all of elliptic curve cryptography. So each version has its own one true cyber suite. You don't have a lot of options. It's either, I'll go into what the options are. You're using version 1 or version 2 or version 3. Less knobs and levers for people to play with and get wrong. And that's pretty much it. That's the main design philosophy I took that was different from the pose standards. So since I showed you a, you know, JSON Web Token, this is what the structure of a POSETO looks like. You have a version. Pretty obvious from everything I've said. You have a purpose. They're called local and public. And the difference is not subtle. Local is symmetric key authenticated encryption. Public is just a digital signature using RSA for version 1 or ed 255 19 for version 2. And you have an optional footer. The reason for an optional footer is because some people want to do key rotation. So they would want an unencrypted part of a local token. They could store like a key identifier that references a specific public key or a specific secret key. Everything is base 64 URL encoded as in defined in the RFC and joined by period characters just like JSON Web Tokens are. So the version defines the cyber suite. The purpose tells you that the user is a user. It tells you what it's doing. And the footer is optional for key rotation schemes. Envision use cases is pretty much the same use case that JSON Web Tokens is supposed to be solving. Short lived one time third party access tokens. That was all it was designed for. They threw all this complexity and machinery on top of it for solving every use case with one tool. And more specifically I want to eventually integrate this into something like open ID connect so people can use this instead of JSON Web Tokens for OAuth. So as I said there's two versions defined in the initial run. There might be future ones when quantum computers become a more you know imminent threat. Compatibility mode uses open SSL like the ciphers that almost everybody is familiar with. RSA AES uses SHA2. Specifically it uses AES 256 encounter mode. HMAC SHA384 and encrypt thin MAC. And then uses HKDF to split the keys. I use SHA384 just as a standard hash function. There's no reason 256 wouldn't have worked or 512 wouldn't have worked. But there are a lot of people who will look at it. One subtle decision made somewhere in one standard and reapply it everywhere. So if I went with SHA256 developers would assume that SHA256 was secure. Never mind that there's length extension. I'm not going to go into that. I'm just going to talk about extension attacks and what not if they decide to build their own MAC protocol with that. And then public key signatures. If you've worked with RSA you'll probably be relieved that PKCS1V1.5 is not here. Instead you get the probabilistic signature scheme. The secure RSA signature scheme with a hard coded set of parameters. And then you have the recommended version. This is the one I actually want people to use. But they might not have libsodium which is what I'm using as a basis for this. Specifically it uses the extended notch, extended nonce cha cha 20 poly 1305 AAD mode. And then it uses ED25519 for signatures. So let's look at one. So in this example the payload is foo and the footer is bar. This is a local token. It's color coded. I don't know if you've seen it. It seems to show up pretty well on the slide. You can see that you have the version, the purpose, a payload and then a footer at the end. And here's the key that actually generated this if anybody wanted to download one of the many libraries that implement Paseto and play with it at home. And here's a public payload. You can see that the string changed from local to public and it's a little bit longer because it's a digital signature. But you see the first four letters of the yellow. That will not change because that's actually plain text. And then if you look at it oh yeah here's the keys. Without a footer it just looks like this. And if you go back and forth quickly you'll see that the first four letters of the yellow did not change because that's bar in base 64 URL. That's what they look like. That's what developers will see. They don't really need to know all of the internals. But can you see that the first four letters of the yellow are the same? I'm going to go into them a little bit. So for all versions, there's a couple rules that I wrote into this proposed standard that will eventually hopefully be taken seriously by the IETF and accepted as an RFC. I have a first draft submitted to them, got some feedback. I'm working on the second one right now. The first rule for randomness is to use U random specifically or more broadly as a random. You can use whatever you want to use. You the operating systems cryptographically secure random number generator. You're not allowed to use a linear congruent generator or a MRCIN twister or any other insecure user space design. That's a standard rule. If you're doing that, you're deviating from the standard and you shouldn't do that. No NCCA2 insecure public key cryptography. Specifically I would call out this padding mode for RSA. It will never be allowed. If anybody suggests it, the answer is going to be no, closed, won't fix, works as intended. And the reason is because, I hope I'm pronouncing his name right, Bleichenbacher had that 1998 padding Oracle attack that's still relevant 20 years later. It's old enough to drink. I think it's high time we stopped building that padding mode into new protocols and designs. And Robot just won a pony award at Black Hat, so you know, congratulations to Robot. And finally, when possible, do everything in constant time. This includes Base64 URL encoding. I will post these slides online afterwards. That actually links to a PHP library that implements Base64 encoding without any cache timing side channels. So another thing that's built into the standard is what's called pre-authentication encoding. This isn't really an immediate security concern, but it's a class of attacks based on how you feed data into your message authentication code called canonicalization attacks. So basically this is just a proactive measure to ensure that every message doesn't create collisions from having multi-part messages. So you can't just, you know, append a bunch of data and have it match a signature that has a footer that originally didn't have a footer so you can forge it. Or anything weird like that. So basically this is just a pre-authentication. So what we do here is we prefix it, we take the number of pieces and we turn it into a string, you know, binary packed string representation of that number in little Indian as 64-bit. And then for each piece we do the same exact thing. We prefix it with the length in the same encoding format and then we put the string. This might sound a little weird. I'll get to what it does in just a second. So when a posse is being encrypted, you're going to have a string that is the same length as the header. So this is a very powerful way to do it. So instead of just feeding the cipher text into the message authentication code, you know, HMAC, it actually does the pre-authentication encoding and takes that output of all those pieces and then uses the HMAC of that. So this will authenticate not only the header V1.local, it will also authenticate the nonce which is generated randomly, the ciphertext and the optional footer. The same thing happens with the RSA signature. It covers the header, message and optional footer. So this will be just an empty string followed by 8 null bytes if you didn't specify one. For version 2, subtle difference between how the crypto AEAD interface works. It already authenticates the ciphertext. You can specify your additional data. So it just packs together the header, the nonce and the footer for version 2. And that's because libsodium and other implementations of the same protocol already authenticate the ciphertext. This is just a simple way to do it. So we'll just use the additional data. And then add 25519 is exactly what you'd expect if you looked at the RSA slide previously. So let's compare the two real quick. JSON Web Tokens has a lot of options, including unauthenticated options. It promotes reasoning by Lego which, you know, you have two pieces that doesn't necessarily mean they're secure if they're not glued together properly or in the right order. And it's often abused for stateless tokens. That's something that people will criticize JSON Web Tokens for and they don't really look further because that's what most developers are doing. You have two options. You have version and purpose. Everything's authenticated and your local tokens are always encrypted so you don't accidentally leak sensitive information for a local system. It does it's job and it gets out of the way. People can still abuse this for stateless tokens, but it doesn't have the built-in habit in the community yet. And I've been actively discouraging it when people ask if they can use it. I've been actively discouraging it when people ask if they can use it this way. So hopefully that won't be a re-immersion issue. If it is, of course, that's what the security industry is here for is to tell them not to do that. If you'd like to learn more about the standard I'm trying to build, you can go to poseto.io or github.com slash Paragon IE slash poseto and you can look and see the RFC draft is being written and marked down. You can look at the reference implementation and PHP. If you look at the first URL, there's like implementations in about 11 other languages. That number is going to go up when I get home because I have a couple to review when I get back. So that's just an example. A very important one in my opinion, but there's a more general topic here. It's about designing cryptography for humans. Using the examples that I just gave you, if we want developers to build secure software and we give them crypto building blocks that are actually secure, that won't fail them. If we want developers to build secure software and we give them crypto building blocks that are actually secure, that won't fail them. But in order to do that, we have to know how to design cryptography for humans to use safely. You know, mere mortals, humans, developers, whatever noun you want to use there. So you should have an opinionated interface. This should be your API for any encryption library. You have your message, your key, and an optional data to include in the authentication tag. Your decryption should be exactly the same. You shouldn't have to specify a mode. You shouldn't have to even know what a nonce is, let alone the subtle difference between a nonce and a initialization vector. Which, does anybody here not know the difference between a nonce and an initialization vector, aka IV? Okay. So you should have hard coded version protocols, which means that, like Poseto, you have version 1 and version 2. You don't have version 1 in ECB mode and version 1 in CBC mode and version 1 in counter mode. You just have version 1. And they should be vetted by cryptographers. If you're not a cryptographer and you want to design one, you should hire one to audit your design, like give you protocol review, give you recommendations, etcetera. And if a vulnerability is ever found in the current version, a new one should be published with a better hard coded cipher suite instead of giving people options. Because if you give developers options, a lot of them are going to choose poorly and that's how we end up in the situation we're in today. This is different from what a lot of other people will understand, and so let's talk about the product to be any way to believe in. When you're designing cryptography libraries and you're working with keys, don't just accept binary strings or byte arrays. Encapsulate them in an object, specifically a typed object. If you have a signing secret key, you know, for asymmetric cryptography, that should be distinct from your symmetric secret key. Even if they're the same bit length, even if you generate them from the same randomness device, you want to keep a little bit of type safety there. That also discourages them from using their passwords as their key, which if you've worked with PHP developers, you know that problem is more commonplace than we even want to get into. And there's an additional benefit here. I'm not really at liberty to go into how often this one turns up in my work, but it's a lot. Stack traces and uncaught exceptions and error codes ending up in automated bug reports. That's a lot of stuff. So I'm going to talk a little bit about stack traces. Stack traces is a tool that's been around for a long time. that's been around for years and years and years. So when you go in and you look at their bug tracker, you can just grep for password and you can find a lot of their users' real passwords because they're being passed around as strings and the programming languages that people work with don't assume it's sensitive. It just goes, oh, it's a string. I'm going to include it in the stack trace to be helpful. So if you encapsulate it in an object, you can actually hide it from stack traces easily. My friend Taylor, who is a big fan of Stack Traces, who coined the phrase reasoning by Lego, actually wrote a PHP library. You've probably heard of it as defuse slash PHP encryption. And that was one of the main departures from the norm that went to that design. Always logically separate symmetric from asymmetric cryptography. So that way, you know, people don't try to use RSA to encrypt something that doesn't need to be, doesn't need the overhead or complexity of asymmetric cryptography. So I'm going to talk a little bit about that in just a second. So if you're storing it in a database and your application that's writing it needs to be able to read it, you don't need RSA. Just use AES. Java and their built-in cipher is the probably most egregious example of violating this rule. Failure emotes. So when PHP 7 was being discussed and they were adding a new cryptographically secure random number generator API to be consistent regardless of OS and all that, the original run would return false if it couldn't generate random numbers securely. Which PHP is a weakly typed language. A lot of people would say, you know, set this letter of a password to an index of an array based on the random int that was just generated. So if you have a random integer and it's set to false, it's going to return a zero, you're not only going to end up with passwords that will look like the letter A repeating ten times. So the, you know, the, you know, the best thing for any, to do for designing some, a library for developers to use is to throw exceptions or whatever equivalent error handling mechanism the programming language allows. This way if they catch the exception, they can fail gracefully. They can have their pretty error page, they can silently encrypt and email a report to the developer saying, hey, this broke and it shouldn't have, you know, this is a high alert, fix it now. Or they can just log into a bug tracker. What's the point of doing that? You know, it's just a matter of whatever they want to do. If you fail closed in a way that doesn't allow them to catch the exception, like if you just have a fatal error, developers won't use the new API. An unpredictable, you know, white page or a failure scares developers. It's like, okay, well, this is going to crash. It's going to make my system unstable. I'm going to get the call at 2 in the morning to fix something that, you know, is a random error. And that just makes them nervous. They won't want to use it. And they'll go back to using rand and mt rand forever. So, you know, it's, you know, it's, you know, it's a lot of work. And then, you know, the exception being the middle ground between the two. And you don't want to fail open like the first example did. Eventually that was ironed out and when 7.0 launched, PHP does the right thing. Okay. So just a quick recap. Or actually, this is the recap. The blame game doesn't solve insecurity. Telling developers don't use JDUT like many security experts did last year and not giving them something viable to fix. That's not going to solve any security issues. They'll just keep using it out of spite and they're going to stop listening to you. Or they're going to invent their own. Or they're just going to say screw it, let's not even sign anything. Let's just store a token that's completely plain text. If you don't give them an option that's better, they're going to probably choose a poorer one because that's all the options they have. The only way to really prevent people from designing their own cryptography and, you know, implementing it and publishing it in a way that, you know, I'm talking about amateur designs here, is to give them something that already solves their problem for them that's easy enough to use to where they won't have the incentive to get creative. This won't stop arrogant people from thinking that they're smarter than the people who built, you know, invented AES, et cetera, because, well, we're not going to get through to arrogant people anyway. They think they know better. Your API should always be simple to understand. Whenever I talk about crypto documentation, I say every API asterisk is a disaster risk. I strongly believe in preferring version protocols over cipher agility. And error prone standards should be deprecated in favor of safer ones for developers to use. At that point, do I have any questions? All right. Let's give it up for Scott. Thank you.