[Applause]
so hello as you said my name is
Benedicta and I'm a full-stack
JavaScript developer from Oslo Norway
I'm so still Europe and today I'm gonna
share with you what I learned so far
about encryption and that more
importantly key management when it comes
to encryption on my quest to figuring
out how to make a privacy first period
period tracker or menstrual cycle cycle
tracker it depends on the but where do
you use and I hope I can help lower the
bar when it comes to encryption so that
maybe you also will use encryption in
your next side project and maybe later
at work but first we'll have some story
time for years and years I've been able
to keep consumer Benedicta away from
developer Benedicta consumer Benedicta
has been using apps and services like
most regular users you know I have
nothing to hide and if I did like I just
don't have the time but then to care
about it but then this winter the first
kind of major leak that health apps and
especially menstrual cycle trackers were
leaking data to Facebook through
facebook analytics and later just a
couple of weeks ago a new report came
out where their attention sharing that
data with other people some companies
selling it and some using it for reach
research which is a good cause but it's
still something we need to know about as
a consumer when we make choices so
Benedicta a developer abandoned exciting
consumer benedict's i had to have a
little talk because right after this
leak came out my period tracker clue
which is one of the nicer ones sent me
this email and it says that only a few
people have access to the tools we use
to look into the databases and that
that's the point where consumer
Benedicta realized you know what
developer Bendix has always known and
that's this data is just there in plain
text I mean it's
in the database and somebody needs to
have access to that database and it
could be any of you it could be me could
my in my friend from University and with
some types of data that could just be
you know very awkward conversations or
not like trying to pretend that I
haven't seen the data so for me kind of
hit home more personally when I started
thinking about that scenario then kind
of like the big data scenario so in the
back of my mind I've always felt like
these apps have been very invasive
they're very detailed they don't care
about only when my period is it's like
how much and for how long and like all
these kinds of weird questions and my
friend who's been single for months
she's tired of getting the question
every day is like have you had sex like
you know yet and like there's been like
this thing in the back of my mind is
like why are they so invasive and I've
realized of course it's because they're
going to use this data for something
else so they need a certain kind of
detailed level so my idea of making so
in the back of my mind I've always
wanted to make a less invasive and less
detailed app that would fit fit my cycle
better and I thought if I'm ever gonna
make this I need to learn how to shield
myself from my users data I want to be
one of those can't be evil apps I don't
want to be the one don't be evil so I
sat down and I did what any sane
developer would do is that I made the
proposal that got me on the stage today
saying stating I'm gonna learn what I
need to learn to make a privacy first
app so that's what I did and also while
I was like any old the same developer do
as well while I was procrastinating
finishing these slides I actually took a
stab at making the app so it's called
pal and I launched it on product and
it's a very minimal version and on the
same day that new leak came out so you
know could think that I actually had an
agreement with these journalists because
it was just hours after I released Palin
on product hunt and this
support and attention has been really
it's blown my mind like people are
really interested they really want such
an app so I've decided to just keep
focusing on actually making the app and
we'll try to launch on March 8th 2020
and for those who you don't know what
that day is it's the International
Women's Day so I'm happy to say it seems
like privacy is becoming more mainstream
and people are getting interested in
knowing where their data is going and
also maybe having a say in where it's
going before I go into encryption I just
need to thank Jeffrey Jeffrey from
1password
it was really hard trying to find
information on this topic from a webapp
perspective there's a lot of more
theoretical knowledge but the only real
real content I found on how the full
flow of a web application goes it's it's
this security white paper by Jeffrey who
works at 1password
which is a great app so if you want to
look into it more after my talk which is
very introductory you should try to read
this white paper and I'm a noob I just
learned this and I'm gonna try to
explain how to use encryption algorithms
I will not go into how they actually
work and you will should not try to make
your own encryption that is something
that will take about 20 years to be able
to do if you're gonna do it on the state
secret level yeah you first need your
PhD and then about 15 years of
experience and then you're allowed to
make a ssin so that's not for us
mmm and I will not go through all the
attack vectors I will look more into how
would you actually do it because that's
what I found lacking so I'm actually I
have a master of computer science and I
remember talks about in Christian but I
feel like I know way way too new too
little about it and I'm still as I said
in all of the people making encryption
algorithms but we're gonna go and look
at how to use them and especially key
management as I realized using algorithm
using the encryption algorithms are
fairly easy but what to do about all the
keys we're gonna get into so this is a
basic encryption algorithm or encryption
flow you have your plaintext and you
have a key and then you encrypt it and
what comes out is called cipher or
ciphertext and then to get your
plaintext back your reverse t3 order
Commission your decryption algorithm one
of the things that I spent an
embarrassing long amount of time to
figure out this what is this key it's
usually just drawn that's a key the same
way I did and I was like this key it's
you know this sort of magical thing but
it turns out it's a very long sequence
of characters and but you use different
algorithms to make them for specific
generate them for specific algorithms
but basically they're just real long
random strings of characters and it
turns out that random long random
strings of character is really important
in encryption and so they even have a
word for it called entropy and because
if you have something that's easy to
guess then the whole thing would fall
apart then you would just guess the key
or guess the password and encryption
would fall apart and if you now you know
very obvious crypt developers if you're
thinking math.random right now then that
is not a true random algorithm that's
something called a pseudo-random they
gives you pseudo random values but what
we need is crypto cryptographically
strong random values therefore showing a
code example and we're going to look at
the net analogy that's often used in the
crypto world a way to think about
encryption is how we secure our
belongings by locking them in to our
house only somebody with the correct key
can unlock the door and get a hold of
your belongings the big difference
though is we look something inside well
with the cripton we actually transform
your belongings so the furniture would
no longer be there it would be something
different but we're still going to use
this analogy because it's used a lot and
it's easier than like transforming
things into different as substance
matter so luckily for us the browsers
now come with dead crypto API embedded
so we don't have to do any crypto stuff
ourselves as we should not do and the
first thing we need to do is make that
key that we saw in our Krypton algorithm
and before we can make the key we need
to decide on what encryption algorithm
to use and from what I've gathered this
is the algorithm we want the advanced
encryption standard with geleris counter
mode so we start by generating a key for
that algorithm and here we say that we
want the length to be 256 256 but it
could just as well be 128 and Jeff
Jeffery from one password has a long
blog post about it not really being that
it's not that much more secure with the
250 bit encryption as it's called as a
128 bit encryption it's like going from
infinity to infinity he says but but for
the users they they liked the sound of
256 over 128 it just sounds more secure
it sounds better so I found that also in
security there's a lot of usability
issues and it's not only like the hard
science that they might want you to
believe in you read most of their
literature so we have the key and now
we're going to encrypt our little note
and as some people might notice we're
not allowed to work on strings we have
to make buf buffers which I find quite
annoying because that's not something I
usually do in my day to day work so as
we as we saw on the diagram we input the
key and the note and out we get a cipher
and but there's another thing here in
addition it's called it's in a celeste
installation in init vector because
and to counter against something called
cipher attacks that I don't totally
understand we need a different random
value as well but we could save that
together with our ciphertext because it
does not have to be secret so we and we
generated here with that cryptographic
safe random value generator so it has to
be a unique for every piece of data you
encrypt but it doesn't have but it
doesn't have to be secret and to get our
note back we decrypt decrypt using the
same installation vector key vector the
key and we have our cipher test text we
get the buffer back and then we make it
into our string again so that was basic
encryption we generated the key the red
key we encrypted our data and then we
decrypted our data again so I was very
pleased with myself when I got this far
in my exploration but I quickly realized
that there's a lot more more to it I was
a lot closer to those two circles than
the owl so I'm going to try not to walk
you through how we generate keys and
when we use what key to hopefully make
you better equipped to read they've read
content around encryption
we're gonna start start by just assuming
everything is in your client your mobile
phone or your or your laptop and it's
easy peasy we just save our ciphertext
to the local storage but where do we
keep the key so this is our first
encounter with key management if we
stored the key together with our
ciphertext then you know there wouldn't
have been much point in encrypting at
all so let's go back to our house and in
this scenario we're we're gonna look at
a way to do this so it's a little bit of
a stretching so we would probably not do
this with houses in real life but just
bear with me so in this scenario we're
looking at where we'd actually just like
hide the key next to the house some
people would do that for convenience
maybe it would be under
the flowerpot on the veranda or like a
secret spot under the stairs something
like that it's convenient but it's not
really recommended because anybody could
get in your house if they found the key
so therefore you decide to get one of
those key boxes that are more popular
now especially with Airbnb where you pop
your key into key box and then you set a
code on the keyed box and in this way
you can access only you can access the
key with something you remember not
something that's stored anywhere so for
to do this we can implement we can do
this in our code as well we can import
key by from a password and with this
function called import key and we want
to use the password-based key derivation
function to we ask the user for their
password and then we transform the
password in turkey by using this
function and then again we have to
encode our strings and using that
password key we can derive a key and as
the name implies it's really good at
making keys from passwords but since
user selected passwords are often easier
to guess than something we generated
randomly we also need a truly random key
and we add that and we call it the salt
so this function derived key is
determined amidst deterministic meaning
that as long as he prided with the same
salt on the same password the output
will be the same so we can generate it
again and/or derive it again and again
and in our case so far we would have to
save that salt together with our cipher
text so it doesn't provide the password
provides us with some extra security but
the salt is not giving us much extra
right now but later on we will see how
the salt can shine so let's go back to
our house there we only had a key luck
with the passcode on it
so we need to get one of those
that has a code and a regular luck I
don't think those exist yet that's what
we're getting and then we take that salt
or that key for the regular lock and we
put that one under the flowerpot so to
get in we need to find the key that
we've hidden very secretly under the
flowerpot and we need to remember our
code then we can get our house key and
we can get into our house so that um
yeah so that was this is our basic
encryption and as you can see the
encryption stays the same but we're now
deriving the key instead of generating
the key so let's move over to cloud
storage so there could be a case where a
menstrual cycle tracker app could just
store everything locally but consumer
Benedicta has gotten some fancy habits
and she likes her data in the cloud so
she can get access from multiple clients
and also backup so we'll keep going on
our encryption and key journey will
start by what goes where
so we'll put our ciphertext in the cloud
we'll keep our salt on the client and
then everything else is kept in memory
the password kept in you know our own
human memory and then everything else in
the clients memory and this looks like
this for the user in one password when
you're gonna move between devices this
is where our salt shines because you
can't if you pick up a new device you
will need the password but you also need
the salt so you need access to your
other device to get that salt and you
need to manually transfer it so this
gives us some added benefit instead of
just hiding it in the player of
flowerpot next to the house and one
password calls it the secret key and
they also give us a QR code so it's
easier to set up on a new mobile device
by just taking a photo they also really
want you to print this out and put it
somewhere safe and they have a little
field where you can write in the
password that you're supposed to only
remem
in your mind and the reason for this is
that in these kind of privacy first
focused apps if you forget your password
then they can't give you any account
recovery because they don't know your
password and they don't have access to
your content anymore so you really need
the users to remember that password or
print but their secret key and their
password out and put it in a safe or
some or somewhere because you cannot
give their content back to them if they
forget so it's a very interesting from a
user standpoint we need to help our
users to get new mental models about
where data is stored and how it's stored
because a lot of people are very used to
just hitting the recovery or I've forgot
my password link a nice thing with this
setup is that something that sounds
really fancy or at least for me sound
very fancy and to end encryption
something that's people say whenever
they talk about cloud and it's not as
hard as it sounds or special as it
sounds it just means that all encryption
and decryption happens on the client and
you know that's what we're already doing
so we have intent encryption down
without much extra effort or with no
extra effort effort again you might say
you know what the sharing have to do
with a period tracker app and over these
last weeks of making it up and started
talking about menstrual cycles I've
talked talked more to more about cycles
with my friends and and other random
people then I think I have in my
lifetime combined and this ID that I've
had and that we've had at home where I
want I maybe want to share some of my
data with my significant others there
are parts of the days in the cycle where
I don't really want to communicate
that's a regular human I just want my
have to do it for me and other people
some people think it's it's a horrible
horrible idea and other people love it
so we're gonna go with the people who
loves it and we're also going to share
some of our data so to share data we
need some different encryption
floo and it's called a async encryption
because I'm I always have a problem
saying a is asynchronous encryption and
in this type of async encryption and
there's a different key for encryption
and decryption so see we have the orange
key old old school looking key there on
the left and the purple on the right you
could switch these up and use the other
one for encryption and the first one for
decryption and and this this was really
hard for me to understand in the
beginning because they're usually taught
and they labeled public and private so I
thought it was always the public that
had to encrypt on the private that had
to decrypt or the other way around but
you can switch these up and they have
different use cases but for our use case
this is the one we want we want to
encrypt with the public key which is
something that you can freely share and
then we want to decrypt with the private
key so let's go back to our houses
you know hatton you now have a neighbor
and the neighbor has very complementary
tools to use you want to be able to
share your tools with your neighbor and
she wants to share her tools with you
which is really nice as a nice
neighborhood yeah but you don't want to
always have to be at home when she comes
over and you want some way to coordinate
the sharing and you could just give you
know give give it to her in the physical
world but this is a special case well
anyway so you put your you can put all
of your tools and she can put all of her
tools in your respective sheds but how
are you supposed to be able to give her
the key if you're not kind of if you
don't have time to meet her and meet her
imperfect person and one way to do that
is that all your other neighbors have
lockable mailboxes so you can take your
shed a copy of her shed key and then you
can drop it in her mailbox and she will
be the only one able to unlock that and
get the key to your shed and the same
the other way around she could take a
copy of her shed key and drop it into
your public mailbox and then you will be
the only one able to
open it with the key to your mailbox but
then if you have a key again so you have
the key to the mailbox and what should
you do with this well we'll put it into
that key box again that has a code and
then it has to lock and then you put
that key under your flower button and to
generate these async keys you can use
this algorithm I won't go much further
into that they will look at the flow so
for sharing data you'll take your plain
text and you'll let's see no there's
something wrong yeah no yes sir
ah you'll take you'll first generate a
key like we did all the way in the
beginning and you'll encrypt the data
with that and you get your ciphertext
but then you take your generated key and
you encrypt that with the other person's
public key and you get an encrypted
generated key and you can share both of
those and put it in the cloud and then
to decrypt the other person will take
their private key decrypt encrypted
generated key get the generated key and
then decrypt the ciphertext to plaintext
so as you can see with all these keys we
got a really stay sharp
to not mess it up but where you know
that private key can't just be laying
around so this is what we do with our
private keys we encrypted with the
derived key and then we can decrypt it
again so if you then look at the whole
flow if I want to decrypt something
shared with me I first have to get my
derived key decrypt my encrypted private
key then I use my private creek to
decrypt my encrypted generated key I get
my generated key and I can finally
decrypt my text and I get my plaintext
back and this is actually what we
usually do also with things we only want
to share with ourselves we do the same
flow so that it will be the equal
process so then you just use your
public-key when encrypted and then you
do this whole song and dance to get your
content back so intent ocation I kind of
just skipped the whole authentication
part as you might have noticed we just
put things on the cloud and without
knowing who anyone was and the reason
for that that it it becomes more
problematic than in a normal web app
since we use our password to generate
keys we don't really the password
becomes much more sensitive than in a
regular app so we don't want to send the
password even if it's hashed back and
forth between the server to log in and I
haven't been able and one password
called this they've solved this using
something called secure remote password
where you never send the password over
you just do a lot of really cool math on
both sides and you're able to say like
we both know the same secret but you
don't send the password back and forth
but I've not been able to find any
services that gives us this because all
the regular back-end as a service
providers and auth providers they do
regular authentication flow
I found one random package on node which
you know I can't just jump jump and use
that without knowing anything more about
it
one password has open source to go
implementation if you want to try to
host your own and secure patent remote
password solution but for pow I find
something else it's called block stack
it's a fairly seems to be fairly a new
framework for creating decentralized
apps so they have authentication on you
know the blockchain which is very
popular word to say these days but I
find it to be able to use this for POW
is a very practical example of when it's
needed and they're they do a similar
thing where you intend to authenticate
without sending the password over any
wires they also help you with encryption
so if you're just going to do simple
encryption it's much easier you don't
have to work with buffer so you can just
encrypt strings like you know normal
JavaScript developers would like so
check that out if you want to if you
just want to do some fun side projects
so we're to the main question is it
possible so for my use case it's
definitely possible because we can
encrypt and I have made a version of the
app but I think what is more important
is that more of us especially in the
developers start using encryption and
really taking privacy first to help our
users and educate our users to know when
they share and how that whole flow works
when you do encrypted apps and there
will always be a trust issue because I
could of course do things in the brows
or in addition to encrypting and just
sending off the data if I wanted to and
that's one of the things side projects
and indie developers I think it comes in
our favor is that it's maybe easier to
get the trust and you start with your
friends than it is for the bigger
company corporation so maybe we we might
have a competitive advantage as in the
developers if you take privacy seriously
so my I would like everybody to just go
out and start making your own private
apps and if you want to copy whatever
I've made feel free to do that and let
me know how it goes if you want to see
the slides or codes or a code or
anything you can go to add this address
it's gonna leave it up there for a while
and please come talk to me in the in the
lunch break if you have any questions
and that was all thank you
and I also
oh she got lost yeah and also just want
to thank Lilian who made all of the the
beaded illustrations
[Applause]