Slide 1

Slide 1 text

Braulio Martinez Software Engineer brauliomlm brauliomartinezlm [email protected]

Slide 2

Slide 2 text

Your Software Partner. Your Ally.

Slide 3

Slide 3 text

Go Passwordless with WebAuthn in Ruby

Slide 4

Slide 4 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 5

Slide 5 text

Authentication Factors

Slide 6

Slide 6 text

Knowledge factors ○ Password ○ PIN K

Slide 7

Slide 7 text

Possession factors ○ Bank card ○ USB physical key P

Slide 8

Slide 8 text

Inherent factors ○ Fingerprint scan ○ Voice recognition ○ Face recognition ○ Typing pattern I

Slide 9

Slide 9 text

ATM authentication Factors: ○ Bank card - Possession ○ 4-digit PIN - Knowledge

Slide 10

Slide 10 text

WhatsApp’s authentication Factors: ○ Phone number ownership - Possession ■ Proved by typing a code received via SMS ○ [Optional] 6-digit PIN - Knowledge

Slide 11

Slide 11 text

Passwords ○ Prone to phishing, brute force, etc ○ All users compromised if hackers access a DB or a server ○ Repetition across systems ○ Bad UX

Slide 12

Slide 12 text

81% of all hacking related breaches were a consequence of stolen passwords https://tinyurl.com/eumfschr

Slide 13

Slide 13 text

Most used second factors ○ One Time Password (OTP) via SMS ○ Time based OTP or TOTP via Google Authenticator

Slide 14

Slide 14 text

Only 28% of users use some kind of second authentication factor https://tinyurl.com/mpk979xz

Slide 15

Slide 15 text

89% of organizations suffered at least one phishing attack in the course of 2022 with an average cost of $2.19M https://blog.hypr.com/press-releases/hypr-the-leader-in-phishing- resistant-mfa-raises-25m

Slide 16

Slide 16 text

Phishing & Replay Attack Example

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 20

Slide 20 text

What is WebAuthn?

Slide 21

Slide 21 text

WebAuthn (Web Authentication) is a standard that defines a set of rules for APIs to enable users to strongly register and authenticate on web applications using public key based cryptography.

Slide 22

Slide 22 text

Who created it?

Slide 23

Slide 23 text

+

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

What was the standardization process?

Slide 26

Slide 26 text

May, 2016 W3C First Public Working Draft

Slide 27

Slide 27 text

March, 2019 W3C Recommendation, Standard Level 1

Slide 28

Slide 28 text

April, 2021 W3C Recommendation, Standard Level 2

Slide 29

Slide 29 text

March, 2023 W3C Editor’s Draft, Standard Level 3

Slide 30

Slide 30 text

Where do people collaborate on the standard?

Slide 31

Slide 31 text

https://github.com/w3c/webauthn/issues

Slide 32

Slide 32 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 33

Slide 33 text

WebAuthn

Slide 34

Slide 34 text

What does it provide?

Slide 35

Slide 35 text

Possession factor

Slide 36

Slide 36 text

USB dongle

Slide 37

Slide 37 text

Phone

Slide 38

Slide 38 text

WebAuthn Spec

Slide 39

Slide 39 text

The WebAuthn Spec ○ WebAuthn Credential ○ 3 entities ○ 2 user flows

Slide 40

Slide 40 text

WebAuthn Credential

Slide 41

Slide 41 text

1. Strong

Slide 42

Slide 42 text

2. Scoped

Slide 43

Slide 43 text

Digital Signatures

Slide 44

Slide 44 text

The Entities ○ Authenticator ○ Client ○ Relying Party

Slide 45

Slide 45 text

The Entities ○ Authenticator => User Device ■ Creating and holding credentials securely, signing ○ Client => Web Browser ○ Relying Party => Web App

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

The User Flows ○ Registration (of a credential) ○ Authentication (of a credential)

Slide 48

Slide 48 text

Registration

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Authentication

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Behind the scenes

Slide 53

Slide 53 text

Registration

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

🔑 🔐

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Authentication

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

📜

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

v(📜, 🔑) = ✅

Slide 73

Slide 73 text

v(origin) = ✅

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

The Code

Slide 76

Slide 76 text

cedarcode/webauthn-ruby

Slide 77

Slide 77 text

# Gemfile gem "webauthn" # config/initializers/webauthn.rb WebAuthn.configure do |config| config.origin = "https://your-app.com" end

Slide 78

Slide 78 text

Registration

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

# app/views/registrations/new.html.erb <%= form_with url: registration_path, ... do |form| %> <%= form.text_field :username %> <%= form.text_field :nickname %> <%= form.submit ‘Sign Up’ %> <% end %>

Slide 81

Slide 81 text

# app/controllers/credentials_controller.rb def create user = User.new(...) options = WebAuthn::Credential.options_for_create(...) if user.valid? session[:current_registration] = { challenge: options.challenge, ... } respond_to do |format| format.json { render json: options } end end end

Slide 82

Slide 82 text

# app/javascript/credentials.js navigator.credentials.create({ publicKey: { … } })

Slide 83

Slide 83 text

# app/javascript/credentials.js navigator.credentials.create({ publicKey: { … } })

Slide 84

Slide 84 text

# app/javascript/credentials.js navigator.credentials.create({ publicKey: { … } }). then(function(credential) { registerCredentialWithServer(credential); });

Slide 85

Slide 85 text

# app/javascript/credentials.js navigator.credentials.create({ publicKey: { … } }). then(function(credential) { registerCredentialWithServer(credential); });

Slide 86

Slide 86 text

# app/controllers/credentials_controller.rb def register credential = WebAuthn::Credential.from_create(params[:credential]) credential.verify(…) end

Slide 87

Slide 87 text

# app/controllers/credentials_controller.rb def register credential = WebAuthn::Credential.from_create(params[:credential]) credential.verify(…) current_user.webauthn_credentials.create!( webauthn_id: credential.id, public_key: credential.public_key ) end

Slide 88

Slide 88 text

# app/controllers/credentials_controller.rb def register credential = WebAuthn::Credential.from_create(params[:credential]) credential.verify(…) current_user.webauthn_credentials.create!( webauthn_id: credential.id, public_key: credential.public_key ) # return success end

Slide 89

Slide 89 text

Authentication

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

# app/views/sessions/new.html.erb <%= form_with url: session_path, ... do |form| %> <%= form.text_field :username %> <%= form.submit ‘Sign In’ %> <% end %>

Slide 92

Slide 92 text

# app/controllers/sessions_controller.rb def create user = User.find_by(...) if user options = WebAuthn::Credential.options_for_get( allow: user.credentials.pluck(:external_id), ... ) session[:current_authentication] = { challenge: options.challenge, ... } respond_to do |format| format.json { render json: options } end end end

Slide 93

Slide 93 text

# app/javascript/credentials.js navigator.credentials.get({ publicKey: { allowedCredentials: [{ id: registeredCredId, … }] } })

Slide 94

Slide 94 text

# app/javascript/credentials.js navigator.credentials.get({ publicKey: { allowedCredentials: [{ id: registeredCredId, … }] } })

Slide 95

Slide 95 text

# app/javascript/credentials.js navigator.credentials.get({ publicKey: { allowedCredentials: [{ id: registeredCredId, … }] } }).then(function(credential) { authenticateCredentialWithServer(credential); });

Slide 96

Slide 96 text

# app/javascript/credentials.js navigator.credentials.get({ publicKey: { allowedCredentials: [{ id: registeredCredId, … }] } }).then(function(credential) { authenticateCredentialWithServer(credential); });

Slide 97

Slide 97 text

# app/controllers/credentials_controller.rb def authenticate credential = WebAuthn::Credential.from_get(params[:credential]) credential.verify(…, public_key: registered_credential.public_key) end

Slide 98

Slide 98 text

# app/controllers/credentials_controller.rb def authenticate credential = WebAuthn::Credential.from_get(params[:credential]) registered_credential = current_user .webauthn_credentials .find_by(webauthn_id: credential.id) credential.verify(…, public_key: registered_credential.public_key) end

Slide 99

Slide 99 text

# app/controllers/credentials_controller.rb def authenticate credential = WebAuthn::Credential.from_get(params[:credential]) registered_credential = current_user .webauthn_credentials .find_by(webauthn_id: credential.id) credential.verify(…, public_key: registered_credential.public_key) # return success end

Slide 100

Slide 100 text

WebAuthn as a 2nd Factor 1st: Password - Knowledge 2nd: WebAuthn Credential - Possession

Slide 101

Slide 101 text

Optional: Local User Verification

Slide 102

Slide 102 text

Inherence

Slide 103

Slide 103 text

Knowledge

Slide 104

Slide 104 text

navigator.credentials.get({ publicKey: { …, “userVerification”: “required” }});

Slide 105

Slide 105 text

WebAuthn as a 2nd & 3rd Factor 1st: Password - Knowledge 2nd: WebAuthn Credential - Possession 3rd: WebAuthn User Verification - Knowledge or Inherence

Slide 106

Slide 106 text

WebAuthn as a 2nd & 3rd Factor 1st: Password - Knowledge 2nd: WebAuthn Credential - Possession 3rd: WebAuthn User Verification - Knowledge or Inherence

Slide 107

Slide 107 text

WebAuthn as 1st & 2nd factor 1st: WebAuthn Credential - Possession 2nd: WebAuthn User Verification - Knowledge or Inherence

Slide 108

Slide 108 text

Password-less 🙉

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

Wins! ✅ No brute force ✅ No sensitive data (secrets) in the Server ✅ No phishing ✅ No man-in-the-middle attacks

Slide 111

Slide 111 text

Challenges 🚧 Device loss recovery UX 🚧 Portability across devices

Slide 112

Slide 112 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 113

Slide 113 text

How can we solve this for mass adoption?

Slide 114

Slide 114 text

Passkeys https://tinyurl.com/2m4h6yeh

Slide 115

Slide 115 text

Multi device WebAuthn Credential

Slide 116

Slide 116 text

Passkeys Features (many WIP) ● Browser Autofill UI ● Cross device authentication authenticators ● Cross device authentication client ● Device Public Key (DPK)

Slide 117

Slide 117 text

Are multi device Passkeys as secure as device bound Passkeys?

Slide 118

Slide 118 text

Registration

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

Authentication

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

Password-less

Slide 123

Slide 123 text

WebAuthn Platform/Browser Support (Oct 2019)

Slide 124

Slide 124 text

Disclaimer: a few of these browsers/platforms might still be using legacy U2F to talk to authenticators WebAuthn Platform/Browser Support (April 2023) iOS Android Windows macOS Linux Chrome Edge Safari - - - Firefox Brave

Slide 125

Slide 125 text

Passkeys Support *credits to https://passkeys.dev/device-support/

Slide 126

Slide 126 text

September 2018 18F/Login.gov https://fidoalliance.org/u-s-general-services-administrations-rollout-of-fido2-on-login-gov/

Slide 127

Slide 127 text

April 2019 Google Accounts http://tiny.cc/z776vz

Slide 128

Slide 128 text

June 2019 Shopify http://tiny.cc/5876vz https://shopify.engineering/supporting-passkeys-in-shop-authentication-flows (March 2023)

Slide 129

Slide 129 text

August 2019 Github https://github.blog/2019-08-21-github-supports-webauthn-for-security-keys/

Slide 130

Slide 130 text

December 2019 Basecamp https://m.signalvnoise.com/basecamp-now-supports-security-keys-for-two-factor-authentication-thanks-to-webauthn/

Slide 131

Slide 131 text

September 2020 GitLab https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26692

Slide 132

Slide 132 text

November 2020 AWS SSO https://aws.amazon.com/blogs/aws/multi-factor-authentication-with-webauthn-for-aws-sso/

Slide 133

Slide 133 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 134

Slide 134 text

How to migrate my app to use WebAuthn?

Slide 135

Slide 135 text

https://github.com/cedarcode/webauthn-rails-demo-app webauthn.cedarcode.com ○ Blank sheet app ○ Rails & Stimulus.js ○ Fully passwordless - WebAuthn only

Slide 136

Slide 136 text

https://github.com/cedarcode/webauthn-2fa-rails-demo webauthn-2fa.cedarcode.com ○ Blank sheet app ○ Rails & Stimulus.js ○ WebAuthn as 2nd factor

Slide 137

Slide 137 text

https://github.com/rubygems/rubygems.org/pull/2865 Rubygems.org ○ Real life application ○ Only 2FA ○ Clearance based authentication

Slide 138

Slide 138 text

https://github.com/mastodon/mastodon/pull/14466 Mastodon ○ Real life application ○ Only 2FA ○ Devise based authentication

Slide 139

Slide 139 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 140

Slide 140 text

○ webauthn-ruby v3.X.X ■ Maintenance and staying on edge on dependencies ■ Evolving as well as the standard keeps changing ○ webauthn + devise, keep pushing as a second factor ○ Passkeys

Slide 141

Slide 141 text

Thanks to webauthn-ruby contributors! ○ @grzuy - Gonzalo Rodriguez (former Cedarcode) ○ @bdewater - Bart @Thatch (former Shopify) ○ @santiagorodriguez96 - Santiago Rodriguez @Cedarcode ○ @sorah - Sorah Fukumori @Cookpad ○ @lgarron - Lucas Garron @Github ○ @padulafacundo - Facundo Padula (former Cerdacode)

Slide 142

Slide 142 text

Motivation Context The Workings Adoption Take the step Future Resources

Slide 143

Slide 143 text

○ https://webauthn.io ○ https://github.com/cedarcode/webauthn-ruby ○ https://fidoalliance.org/fido2-2/fido2-web-authentication-webauthn/ ○ https://www.yubico.com/services-with-yubikey/webauthn ○ https://www.w3.org/TR/webauthn

Slide 144

Slide 144 text

Thanks!

Slide 145

Slide 145 text

Q&A WebAuthn Demo

Slide 146

Slide 146 text

Braulio Martinez Software Engineer brauliomlm brauliomartinezlm [email protected] WebAuthn Demo