-: IPSec or IP Security. 2 2
In this lesson, we're going to talk all about IPSec. 3 3
Now, IPSec is a secure network protocol suite 4 4
that provides authentication and encryption of data packets 5 5
to create a secure encrypted communication path 6 6
between two computers over internet protocol network. 7 7
IPSec is the most popular protocol in use today 8 8
for the creation operation of VPNs 9 9
or virtual private networks. 10 10
IPSec provides confidentiality, integrity, 11 11
authentication, and anti-replay 12 12
when using a VPN connection 13 13
for both site-to-site and client-to-site VPNs. 14 14
IPSec provides confidentiality by using data encryption. 15 15
It's also going to provide integrity 16 16
by ensuring that data was not modified in transit 17 17
by checking that it's hashed before transmission 18 18
and upon receipt, match. 19 19
Authentication is going to be provided 20 20
by having each party verify 21 21
that they are who they claim to be. 22 22
And IPSec is also going to provide you 23 23
with anti-replay by checking the sequence numbers 24 24
on all the packets prior to transmission. 25 25
This prevents the transmission of duplicate packets, 26 26
and it prevents an attacker from being able to capture 27 27
and resend packets later as part of an attack. 28 28
Before we go too deep into IPSec, 29 29
let's take a big picture view of how IPSec works. 30 30
There are five main steps in the process 31 31
of establishing and using a secure VPN tunnel 32 32
when you're using IPSec. 33 33
First, there is a request to start a key exchange. 34 34
Second, IKE Phase one is going to authenticate the parties 35 35
and establish a secure channel for negotiation. 36 36
Third, IKE Phase two is going to negotiate 37 37
the security association parameters 38 38
and fully establish the secure tunnel. 39 39
Fourth, we're going to have data transfer, 40 40
and this is going to allow data transfer 41 41
between the two parties over the secure tunnel to occur 42 42
using the IPSec parameters and keys 43 43
stored from the security associations 44 44
that were negotiated back in step three. 45 45
Fifth, IPSec tunnel termination is going to occur. 46 46
And this happens when the security associations 47 47
are terminated through either mutual agreement 48 48
and deletion or due to timing out of the tunnel 49 49
due to one party becoming non-responsive. 50 50
All right, those are our five main steps, 51 51
but it's important for us to fully understand 52 52
how all of this works in our networks 53 53
so that we can better troubleshoot these IPSec tunnels 54 54
if we ever have a problem with their not working properly. 55 55
Now, the first step is pretty self-explanatory here. 56 56
We need to request to start a key exchange. 57 57
This can be done by your devices automatically 58 58
if you're using a site-to-site VPN, 59 59
or it can be initiated by a software client 60 60
on your laptop, if you're going to be using 61 61
a client-to-site method. 62 62
Either way, the request to initiate a VPN connection 63 63
is going to occur, and then we can move to our second step, 64 64
the IKE Phase one. 65 65
Now, during IKE Phase one, 66 66
the IPSec peers have their identities authenticated 67 67
and encrypted for protection. 68 68
Then there's going to be a negotiation that occurs 69 69
to create a matching IKE SA 70 70
or internet key exchange security association 71 71
between the two IPSec peers 72 72
to protect the key exchange that's about to occur. 73 73
Next, the IPSec peers are going to perform 74 74
an authenticated Diffie-Hellman key exchange 75 75
so that both IPSec peers 76 76
will have a copy of the same shared secret key, 77 77
and that way they can use that to establish 78 78
and secure an IKE Phase two tunnel. 79 79
The internet key exchange or IKE Phase one 80 80
can use one of two modes to conduct this process. 81 81
We can use either main mode or aggressive mode. 82 82
Now, when we're using main mode, 83 83
it's going to conduct three 2-way exchanges 84 84
between the peers. 85 85
This goes from the initiator to the receiver. 86 86
Now, the first exchange between the IPSec peers 87 87
is to agree upon which algorithms and hashes 88 88
are going to be used to secure the IKE communications 89 89
throughout this process. 90 90
The second exchange that they're going to do 91 91
is going to be between the peers, 92 92
using a Diffie-Hellman key exchange 93 93
to generate the shared secret key material 94 94
that's going to be used to create 95 95
these shared secret keys 96 96
that we can then send to the other party 97 97
by sending assigned random number, 98 98
and that way the two parties 99 99
can prove their identities. 100 100
Then we're going to have a third exchange 101 101
between the IPSec peers. 102 102
And this occurs where each side can verify 103 103
the identity of the other side 104 104
by looking at encrypted form 105 105
of the other peer's IP address. 106 106
Now, by the time these three exchanges are finished, 107 107
both peers have received matching IKE security associations 108 108
or IKE SAs. 109 109
These can now be used for ISAKMP exchanges 110 110
between the IPSec peers 111 111
moving forward throughout the rest of the process. 112 112
These security associations are going to contain 113 113
the authentication methods used by the peers, 114 114
the encryption and hash algorithms used, 115 115
the Diffie-Hellman groups used, 116 116
the expiration of the IKE SA, 117 117
and the shared secret values for the encryption algorithms. 118 118
Basically these IKE SAs have everything 119 119
that both peers need in order to make and maintain 120 120
their IPSec tunnels. 121 121
Now, the second mode you can use 122 122
is known as aggressive mode, 123 123
and this has fewer exchanges than the main mode. 124 124
So instead of having three, 125 125
we're going to have less. 126 126
This results in fewer packets 127 127
and a faster initial connection 128 128
than using main mode. 129 129
Now, in aggressive mode, almost everything needed 130 130
for the proposed security associations 131 131
is going to be sent by the initiator at first. 132 132
This includes the Diffie-Hellman public key, 133 133
the signed random number, and an identity packet. 134 134
Then it's going to be received 135 135
and the receiver is going to send everything back at once. 136 136
So the initiator only needs to confirm the exchange 137 137
to finish the association. 138 138
This is why it's considered more aggressive 139 139
because one side is saying, 140 140
"Here's all the things I want to use," 141 141
and the second side can say, 142 142
"Okay, I'll go along with that." 143 143
Now, this is concerned less secure than main mode, 144 144
but again, it's a lot faster than using main mode 145 145
'cause we don't have to go through these three passes 146 146
and three exchanges. 147 147
Now, once you have the IKE security associations 148 148
and they've been received 149 149
by either using main mode or aggressive mode, 150 150
we can move into step three of our process. 151 151
This is the IKE Phase two portion 152 152
of our tunnel establishment. 153 153
Now the purpose of IKE Phase two is to negotiate 154 154
IPSec security associations 155 155
to set up the IPSec tunnel. 156 156
IKE Phase two is used to negotiate 157 157
the IPSec security association parameters 158 158
that are protected by the existing IKE SA 159 159
that we created in phase one. 160 160
This allows us to establish IPSec security associations 161 161
to periodically renegotiate security associations we need, 162 162
to maintain that security, and to perform 163 163
additional Diffie-Hellman key exchanges 164 164
if we need to. 165 165
During IKE Phase two, 166 166
we can accomplish this by using quick mode. 167 167
Now, quick mode can only occur after IKE 168 168
has already been estabished 169 169
in that secure tunnel during Phase one, 170 170
using either main or aggressive modes. 171 171
Using quick mode, 172 172
we can negotiate a shared IPSec policy, 173 173
and we can also drive shared secret key materials 174 174
using the IPSec security algorithms. 175 175
And then we can use that to establish 176 176
our IPSec SAs. 177 177
Now as discussed in phase one, 178 178
each essay has a limited lifespan 179 179
and it will then expire. 180 180
Now with quick mode, 181 181
we can negotiate a replacement SA 182 182
before the expiration occurs. 183 183
And this lets us maintain that VPN tunnel 184 184
for longer periods of time 185 185
without worrying that the attacker 186 186
could crack our security associations 187 187
and enter that tunnel. 188 188
Now, the fourth step of this process 189 189
is to conduct our data transfer 190 190
with those newly established encrypted IPSec tunnels. 191 191
This is done by using IPSec SAs 192 192
that were created in IKE Phase two. 193 193
Now, these packets are going to be encrypted by the sender, 194 194
and they're going to be decrypted by the receiver, 195 195
and this makes sure everything is kept 196 196
confidential and secure. 197 197
Now, our fifth and final step of this process 198 198
is to terminate the tunnel. 199 199
This occurs whenever the IPSec SAs 200 200
are deleted by mutual agreement by both peers, 201 201
or if the SAs reach their lifetime expiration 202 202
and simply time out without being replaced. 203 203
When this happens, we need to go and create 204 204
a new phase one and phase two key exchange 205 205
if we want to re-establish that tunnel 206 206
and conduct more data transfers. 207 207
Now, you may or may not understand 208 208
the basics of asymmetric cryptography yet, 209 209
so let me take a quick detour 210 210
and explain how this whole key exchange thing works. 211 211
You may have noticed I kept saying the words 212 212
Diffie-Hellman. 213 213
I kept talking about a Diffie-Hellman exchange. 214 214
Well, Diffie and Hellman are basically names 215 215
of two computer scientists who came up 216 216
with this really brilliant way 217 217
for two systems that don't know each other 218 218
to be able to exchange a secret key and trust each other. 219 219
This process is known as the Diffie-Hellman key exchange 220 220
named after them. 221 221
So at IKE Phase one, there's an initial tunnel 222 222
created between the two peers. 223 223
And they're going to begin to exchange some information 224 224
to create those IKE SAs or security associations, 225 225
and then authenticate each other. 226 226
Now, in a Diffie-Hellman key exchange, 227 227
the two clients, in this case PC1 and PC2, 228 228
are going to create their own private key. 229 229
And I'm labeling this PRI for private. 230 230
From that key, they can use a mathematical algorithm 231 231
to calculate a corresponding public key, 232 232
and then they can hand that public key 233 233
to the other PC to create a key exchange. 234 234
Now, PC2 has a private key called PC2 PRI, 235 235
and they have a public key for PC1 called PC1 PUB. 236 236
PC1 has its private key, PC1 PRI, 237 237
and a public key for PC2 called PC2 PUB. 238 238
Now at this point, 239 239
each side is going to calculate a shared secret 240 240
using the Diffie-Hellman protocol. 241 241
By using their private key 242 242
and the other person's public key 243 243
in this mathematical algorithm, 244 244
they get a Diffie-Hellman shared key, 245 245
which is going to be the same on both sides. 246 246
And now they both have the same shared secret. 247 247
They can now create a tunnel with it. 248 248
At this point, they both agreed to the encryption 249 249
and the integrity methods, 250 250
and they're going to establish the IKE Phase two tunnel 251 251
using that Diffie-Hellman key. 252 252
At this point, they are going to use 253 253
the IPSec tunnel created, 254 254
and that becomes known as a phase two key 255 255
that's going to create this IPSec tunnel 256 256
and secure it. 257 257
Once they have this phase two key in use, 258 258
they now have encryption and integrity intact 259 259
for this tunnel and it becomes a tunnel 260 260
inside of a tunnel. 261 261
And now we have a secure method 262 262
to communicate between the two peers. 263 263
Now, I know that was a lot, 264 264
so let me break it down again into just five steps 265 265
and show you what it looks like in the real world. 266 266
First, I have PC1. 267 267
And they want to send traffic to PC2. 268 268
When they do this, router one is going to create 269 269
an initiation of an IPSec tunnel. 270 270
Second, we're going to see router one and router two, 271 271
and they start negotiating the security associations 272 272
to form the IPSec IKE Phase one tunnel. 273 273
This is also known as our ISAKMP tunnel. 274 274
Now, in step three, 275 275
the IKE Phase two is going to create this tunnel 276 276
inside of the tunnel when it's negotiated and set up. 277 277
Now, once that tunnel is established, 278 278
we can begin to conduct data transfer in step four, 279 279
and the information starts flowing 280 280
between PC1 and PC2 securely. 281 281
When they're all done with that, 282 282
we reach step five, and the tunnel is going to be torn down, 283 283
and the IPSec security associations 284 284
are going to be deleted. 285 285
Now, if you wanted to be able to create another VPN, 286 286
you can do that by starting this whole process over 287 287
from the beginning and going through those five steps again. 288 288
All right, at this point, 289 289
we've covered the tunnel establishments 290 290
a few different times in a few different ways, 291 291
so hopefully it's beginning to make some sense. 292 292
The reason I cover this so many times 293 293
in so many different ways is this is an area 294 294
that a lot of people struggle with. 295 295
Now, to allow the data transfer to happen, 296 296
there are two methods that we can use. 297 297
These are known as transport mode 298 298
or tunneling mode. 299 299
Now, transport mode is going to use 300 300
the packet's original IP header, 301 301
and it's used for client-to-site VPNs. 302 302
This approach works really well 303 303
if you have problems increasing your packet size 304 304
because you may end up hitting 305 305
a maximum transmission unit size 306 306
or MTU inside your network. 307 307
Remember, by default, the MTU 308 308
or maximum transmission unit size 309 309
is set at 1500 bytes in most networks. 310 310
If you go over 1500 bytes, 311 311
the packet will become fragmented 312 312
and this can cause issues with your VPN's functionality. 313 313
If you're using a client-to-site VPN, 314 314
I highly recommend you use transport mode 315 315
as your IPSec method, 316 316
because it doesn't add additional padding 317 317
to your packet and doesn't increase its size. 318 318
Now, on the other hand, 319 319
if you're setting up a site-to-site VPN, 320 320
like having a regional office 321 321
connecting back to a main office, 322 322
then I would use tunneling mode. 323 323
Now, tunneling mode is used to encapsulate 324 324
the entire packet and put another header on top of it. 325 325
This is going to increase the size of that packet 326 326
and it could go over your MTU. 327 327
Now, think about it this way. 328 328
Let's say you had an envelope 329 329
and you put it inside another envelope 330 330
and then wrote an address on it. 331 331
You readdressed it and then you shipped it to somebody else. 332 332
This new header is going to have a new source 333 333
and destination of the VPN terminating devices 334 334
at the different site that it wants to go to. 335 335
When it gets to the other site, 336 336
the VPN concentrator is going to remove 337 337
that outer envelope 338 338
or that header inside of a network packet, 339 339
decrypt the content, 340 340
and then route it across their private local area network, 341 341
just as if it was coming 342 342
from an internally connected client. 343 343
When using tunneling mode 344 344
you're encapsulating the entire packet 345 345
into a new packet. 346 346
So this is going to increase 347 347
the size of your overall packet. 348 348
And it could go above that MTU default size 349 349
of 1500 bytes. 350 350
If you're going to be using a site-to-site VPN, 351 351
you may need to allow jumbo frames, 352 352
which is any frame above the MTU size of 1500 bytes. 353 353
This way it'll be properly supported. 354 354
Normally the best way to configure your devices 355 355
would be to drop your maximum MTU size 356 356
on your inner router 357 357
to something like 1400 bytes, 358 358
and then connect it to the VPN. 359 359
This way there's enough room to add the extra encapsulation 360 360
and the new packet header before transmitting it out 361 361
over the public internet inside your VPN tunnel. 362 362
If you control the entire network, 363 363
you could actually raise your MTU size up 364 364
to a maximum of 9,000 bytes if you wanted to, 365 365
but this should only be done on your own local area networks 366 366
because 9,000 byte packets will have trouble 367 367
traversing the internet. 368 368
Now remember, transport mode 369 369
is normally going to be used for client-to-site VPNs 370 370
and tunneling mode is normally going to be used 371 371
for site-to-site VPNs. 372 372
The final thing we need to discuss in this lesson 373 373
is the concept of an authentication header or AH 374 374
and an encapsulating security payload or ESP 375 375
within your IPSec protocol. 376 376
Now, the AH or authentication header 377 377
is used to provide connectionless data integrity 378 378
and data origin authentication for IP datagrams, 379 379
and it provides protection against replay attacks. 380 380
Be aware though, 381 381
that the authentication header does not provide 382 382
any kind of confidentiality of the data itself. 383 383
Instead, the authentication header 384 384
contains a cryptographic hash of the data, 385 385
and this acts as identification information 386 386
to provide the integrity between the sender 387 387
and the receiver of each packet being transmitted. 388 388
Now, the encapsulating security payload 389 389
or ESP is used to provide authentication, 390 390
integrity, replay protection, 391 391
and confidentiality of the data. 392 392
By using ESP within IPSec, 393 393
you can rewrite the payload of the packet 394 394
inside of an encrypted format. 395 395
Now, with ESP, we're only protecting 396 396
the confidentiality of the payload 397 397
contained within the packet, 398 398
not the headers themselves. 399 399
So if you're using transport mode, 400 400
such as in a client-to-site VPN, 401 401
you can use the authentication header 402 402
to provide integrity for your TCP header. 403 403
And then you can add the ESP, 404 404
encapsulating security payload, 405 405
to encrypt the TCP header and the data in the payload. 406 406
But this does not encrypt the end-to-end header, 407 407
so people outside your organization 408 408
can see where the data's coming from 409 409
and where it's going to. 410 410
If you're using the tunneling mode, 411 411
such as in a site-to-site VPN, 412 412
you can instead use both the authentication header 413 413
and the encapsulating security payload 414 414
to provide integrity and encryption of that payload, 415 415
including the end-to-end header. 416 416
In this case, a new IP header is going to be added 417 417
to the front of the packet to cover the hops 418 418
to the other end of the secure connection. 419 419
This means that nobody on the internet 420 420
can see the source or destination of the traffic 421 421
within the organization's internal networks 422 422
on either side of this VPN connection.