Securely Managing Public/Private Keys for Cloud Services
Introduction
In our daily lives, there are many services with which we have to use authentication in order to get access; be it personal services like our cloud email solutions, a social gathering service, business socializing websites, or enterprise services needed to do our jobs. Enterprises most often have to have access to the following services:
- Domain name service: it's where all the records for their domains are kept and managed. An attacker having accessed the domain name service can change all their domain records to point to his own malicious website in order to disrupt the enterprise service and possibly even attack all of the visitors of the service.
- Dedicated servers: A company usually has many dedicated services in different data centers around the word. A hacker, having gained access to a dedicated server, can disrupt the service running on that server; obtain all user credentials from login requests coming over the network or something entirely different, like installing a backdoor into the system.
- Source code hosting: Software companies often use source code hosting in order to save repositories for various projects online. This greatly simplifies the development and maintenance of source code repositories, but allows an attacker possibly to gain access and steal the source code of an application or a system.
- A website: A company can easily set up a website by using various platforms that already do most of the work for us. However, if the website allows user authentication, it should be run over TLS in order for a secure session to be established prior to entering the credentials.
All of the above services can be installed and maintained in an company's internal network and by company administrators, but there are cloud service providers offering the same kind of services for free or possibly for small subscription fee. In any case, users of the services have to access those services regularly in order to do their jobs. There are many ways a user can access the services, but in order to be most secure public/private keys are used to obtain access to the service.
Learn Cloud Security
Public/Private keys
To access various cloud-based services securely, we can use public-key cryptography, which uses two separate but corresponding keys –the public and private key. The public key can be publicly disclosed and is used for encrypting the message, while the private key must be kept private and is used to decrypt the message. The public-key cryptography is used in various protocols and infrastructure applications, like when connecting to a TLS-enabled website, connect to a dedicated server through SSH, access the source code repository at hosting provider, etc. Whenever we use git to push/pull source code changes from the repository or using ssh to connect to the remote server, we're using the public/private key-pairs. Therefore, it's safe to conclude that public/private keys are extensively used and they have to be properly protected to achieve the utmost security.
The public/private key pair can be generated by a tool ssh-keygen, which is part of the openssh package in Linux. In Windows, we can generate the keys by using the Putty client, which also includes the Puttygen utility used for generating the keys.
Let's generate a simple public/private key by using the ssh-keygen command below and using the -f option, which specifies the filename of the key file.
[plain]
# ssh-keygen -f mykey
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in mykey.
Your public key has been saved in mykey.pub.
The key fingerprint is:
86:79:43:6a:c2:ab:34:2b:bf:7f:e1:63:5f:83:a4:42 user@server
The key's randomart image is:
+---[RSA 4096]----+
| |
| |
| . |
| . = |
| E = S |
| . +.= o |
| o o.... o |
|.. + .= . . |
| o=o.o o. |
+-----------------+
The ssh-keygen command generated two files, the private key mykey and the public key mykey.pub, which has the .pub extension. The public key can be seen below and is defined of several fields [1]:
- Key format: specifies how the format of the key, where the following options are available: ssh-dss, ssh-rsa, pgp-sign-rsa and pgp-sign-dss.
- Encoded Data: a base64-encoded public key.
- Additional information: usually specifies the user and server identifier about where the key was generated.
[plain]
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1Qrhb8G6e4QayTBXShd5PCUvlKmmWVarYd1lV0TZTw47C5yFC+pj/NsH/EZM7vI9LvFZ0vj8WRy1k7KmHzXZcThr6e9VzsU42YOtTAys8SXlZ8Bac/B97K3g3KspQWCv0Yd1HQMTWZ8hELHPL+6J0nhXazxQM2DgivREri8jjzLqLw+T7twwNzBCwS6kjuRYBiuHSjLYdV+EIv+a6DU1s14YlQHYuo6icic4OFouXurol4pphO+7bzlYrw/o5XA2Umt4q5tFEEogy7n+NaYyq8/+QRehR1awlQz74NMqklbmzhgHpVBMxKFpUxBKR0d8KZVxcKD4QlGlylhM1Xl8RkrQl3SQOscVv9TNYIPvxXGvxderXszsnogShARoKAix3vAXCkJO0DOgFgAX5mVyT1Eq2AR5YDoP/E2O61m716EC0J/j3hbNnNzOh63nIucF2n6w3C32dAxF6xKVlrzkvkWCH7m6sd7xtVx0KzsYXYGEdbBSMtsMCDc1n3XQdCKO05oWNd2SplpM8m8bybDR+JU6LGsgCBwGoHG7HQIvpf/OYZo9NIyli2pXYOEKoanQW3H2QRqiqPEKde5HMp4aHjGu0Kl9f6VyQC0w5dCB+7rDahfdh0e6PvVA8rCYYyXqQTbyT7mJs3v5DE5/tnjJ9bFcmqsV6wN4LDPlra7oOlw== user@server
The private key mykey, which doesn't have an extension, can be seen below and follows the ASN.1 syntax notation.
[plain]
-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAtUK4W/BunuEGskwV0oXeTwlL5SppllWq2HdZVdE2U8OOwuch
QvqY/zbB/xGTO7yPS7xWdL4/FkctZOyph812XE4a+nvVc7FONmDrUwMrPEl5WfAW
nPwfeyt4NyrKUFgr9GHdR0DE1mfIRCxzy/uidJ4V2s8UDNg4Ir0RK4vI48y6i8Pk
+7cMDcwQsEupI7kWAYrh0oy2HVfhCL/mug1NbNeGJUB2LqOonInODhaLl7q6JeKa
YTvu285WK8P6OVwNlJreKubRRBKIMu5/jWmMqvP/kEXoUdWsJUM++DTKpJW5s4YB
6VQTMShaVMQSkdHfCmVcXCg+EJRpcpYTNV5fEZK0Jd0kDrHFb/UzWCD78Vxr8XXq
17M7J6IEoQEaCgIsd7wFwpCTtAzoBYAF+Zlck9RKtgEeWA6D/xNjutZu9ehAtCf4
94WzZzczoet5yLnBdp+sNwt9nQMResSlZa85L5Fgh+5urHe8bVcdCs7GF2BhHWwU
jLbDAg3NZ910HQijtOaFjXdkqZaTPJvG8mw0fiVOixrIAgcBqBxux0CL6X/zmGaP
TSMpYtqV2DhCqGp0Ftx9kEaoqjxCnXuRzKeGh4xrtCpfX+lckAtMOXQgfu6w2oX3
YdHuj71QPKwmGMl6kE28k+5ibN7+QxOf7Z4yfWxXJqrFesDeCwz5a2u6DpcCAwEA
AQKCAgAVaO0Xxv15/MBqvPvy4ucQVNvHFMxl+nZ0nRxLO6v8FuQ890oBfFIoCxK9
Cxll++69FmDr5zDSc9PT0PRxWv55Bqy/G3Np9+5yE96X7o7jzxXrXqV9I3ageND5
Sy+cb925PvoBGZBmdtm727hNxso4lhekwcLvhXaT+9sUVq2C4sLCEYBxjvx4gLsT
58vxsUH9Kqdj1EUKkD+/ZdNd9IZJredlbQjIl4IqA0j4dwdEA8VLBkoP5CFhiyy4
fKyIq+vaurQ1QxBCxyGZSnx8epQn+SwdoXRA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XIe66XSQV7Cs5RzJqaStrVnFcWpB/Vp2nIYc/iT/aXA=
-----END RSA PRIVATE KEY-----
Password Protected Keys
We've said that public keys can and usually have to be shared with the public in order for the other users to be able to encrypt the messages with your public key. After the messages are sent to you, you can decrypt them with your corresponding private key without providing any additional information. If an attacker is able to compromise your machine and get access to the private key, he will also be able to decrypt all the messages that were encrypted with the corresponding public key.
In most penetration tests or vulnerability assessments, we've come across numerous private/public keys. A penetration test is an attack on computer system or network in order to gain access to internal system and its data. After the reconnaissance phase, we've scanned the network for open ports in which we found a number of publicly available web applications. Despite certain security precautions used by some of the applications, we've been able to upload a shell on the server in order to be able to run arbitrary commands under the application or web server user. That gave us access to the actual file system, where we could search for interesting files; since we had the permissions of the web application, some directories were not browsable, so we couldn't look inside. Despite that, we obtained certain private keys from /etc/ssh/, which didn't have correct permissions. Normally, the files should be owned by root:root and have 600 permissions only to allow user root to access them. Since that wasn't so in our case, the private keys were obtainable, and later we've figured out, they were actually used to access some other internal systems over SSH protocol. We were able to compromise the second server by using the private keys obtained on the first server.
I hope this emphasizes the importance of actually encrypting the private keys with an additional password. If that were the case on the server previously mentioned, we wouldn't be able to compromise the second server because we would only have access to an encrypted private key. We could, however, bruteforce the password of the private key, but such operation is quite slow and normally fails, because a person encrypting the private key knows enough about security not to use a weak password that could easily get cracked. Additionally, the ssh-keygen itself will reject a weak password as we can see below, where we used a password "test" that doesn't contain the minimum allowable number of characters.
[plain]
# ssh-keygen -f mykey -b 4096
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
key_save_private: passphrase is too short (minimum four characters)
Saving the key failed: mykey.
Nevertheless, the password verification isn't good enough, since we can choose a password "test123" that will easily be accepted by the ssh-keygen tool.
[plain]
# ssh-keygen -f mykey2 -b 4096
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in mykey.
Your public key has been saved in mykey.pub.
The key fingerprint is:
00:dc:18:e2:31:87:1e:be:d5:6a:16:2a:67:d4:81:55 server@host
The key's randomart image is:
+---[RSA 4096]----+
| +===E |
| .+=+.. |
| o.o o. |
| + + .. |
| . + o S |
|. = + |
| + o |
| |
| |
+-----------------+
We have to choose a strong password when creating a private key in order to store the key in encrypted form on the hard drive. Any program that wishes to use the private key must provide the password that was chosen when generating the key. An encrypted version of a key can be seen below.
[plain]
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
Q5NJXbEmvu/BFhE65KPdxQXyxTFK0uMKloSR5/XcBMggDnMpowy27amjAH77sz5U
4BDx73SENtca7EmB5f2gaHBOdA48kzYNFs0JMamwnTY1jQyLFIxrwWjtT5sR660L
MXO4vwgxUlSfOg7gQgKp7finJUR7zq4CPVDvWmHAtDk6SwtfNW1DsVS1F1+hwK+2
6JpfAYD8Tmvj3D86kKnlB5U+kc0VCV+mzdvliG+y9Q5lj9Fbbx718mtXUg09WBdW
YJLglWVWj4SYFWjg9Wa2XTm3oZDJ7nStvjFUO7Nz0kX+LTJ7uUHrMoXWrUtsKEtJ
B5XV6dO/opa7Le1W9EZ72ixmLY/4p6dVJNDMJx3GzEqtFQ179OpDjIGaFKy28KHy
Btb4sJu5TiB48es+cSM+Pgpp3D2mmV4EESN5mBUkTK0F287U+Tu/zuptmnKlgIhA
u68Mb5xmU1ZMAx6c9vLMnlLnWLfLhEjDsH6ml6rbxK7o/b20Z3L7kn3vAUdnNbuc
NVCotr+PMW4Dpl97j4SLCTL3Qs1XmEatvKE630cq72EBhG1tlqYULJYnSy5+mKdE
n7pSXjtCSKEalfRjRneJgX3fi82qQVZ8QALviSGK+LFIbJpHhwsIt3JpfRp3qEXe
HAU4WpfQQDRnunnPHY/NUdpR4H7lXNbURqkyelj2ASh+pbQK90x5QlPeSWqyI79Z
oL611E7KXJCpyRkwbd/FPCi554sTdMT6AkrMQWj6+/xyBwhHhJr6DiSEVoWZjL1p
F+fNwxyvMwlqsisOwwhUQiUNGQ49tKBoy1H8IovrhOhx6HxrFf5LmIU5fq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LA9Ew1wt7l5jYcHbq3
8JwtY21bic4ILBVKYI4x0SlEzGX/5M+YxQnBBV1zunn8QEui7Sx5v0JBY/Rnx766
b2unDFukFHgyUUSYvchO+zmMIBuUgCDkoed5+PY6XcZUqhrXfTf/wf2PndSi741q
2w3oMjFPEeWeuWUpTvaDDA2kkn8UhQtafJomu9BCGzeOL7KKkZc45SAhtcFrpwYr
-----END RSA PRIVATE KEY-----
Key Strength
When passing the -b option to ssh-keygen, we can specify the number of bits in the key that will be created. Normally the following sizes are supported: 1024, 2048, 4096, etc. To generate an asymmetric RSA key, two prime numbers are selected and their product is calculated. The strength of the asymmetric encryption lies in the fact that it's very easy to calculate the product of two randomly chosen prime numbers, but it's fairly difficult to determine which of the two prime numbers were used if we know only their product. If an attacker can determine the two prime numbers somehow, he can calculate the private RSA key and break the cryptography.
An attacker can break the RSA by bruteforcing all the keys of certain size, but every number of certain size isn't a RSA key, because it isn't a product of two prime numbers. Therefore, even if the size of the key is quite larger than when using a symmetric key, there are actually less possibilities, which we have to bruteforce. If a product is a number of 2048 bits in size, then both prime numbers are around 1024 bits in size. A 128-bit symmetric key provides the same strength and therefore security as a 3248-bit asymmetric key [2].
Therefore, it's advisable that we choose a 4096-bit asymmetric key length when generating the keys that will be used for authentication. We can do that by using the command below.
[plain]
# ssh-keygen -f mykey2 -b 4096
An example private key consisting of 1024 bits can be seen below:
[plain]
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDN7tW5GRy5wNHrAEOpko80fd6zrABqVQFsAQaqi0h8TgNScfX0
ynSzrBlqTEenHp6QUAS45OJ1gNDAxGlbX+pLVX+je2sr7aTrGrCeYxVhms0vln8x
8Nrfk2Axh1B0UHrPRx+TXg3rZcfq/3U1A8k9DUb4jsoBHdNHhiyBZRUZwQIDAQAB
AoGAYrkOqG/Lf5laiShVR6PFF0sISmY4xMD/r4FGatfe5giYOxv652FvVPs6K+Vp
rEpXhaN2wBSqI96fNOpz/6QZsyroe95UkXOPYp7iwEiTjQYp5/ixdfmiMBOnBwDX
/UDA9KJCEK6uGXzeB+t+iwLhECbV9oTYPHGI8fff/2slCwkCQQD5BiQ0BVy1Cfi3
SgICwcV7/MJW+cK6Ur/5T2OXgSa74WIEAx2l07ChebwrHoBpTXLFxTgpqmkySf0x
2ipUvEY7AkEA07OrQZe19e4OlC5YnxGtiyUeNKwmMj6Uh5vwC9Cv/QIzh8t1iMhE
fOYGuleZAIfsLThGwI5qKWLVvQKK3FuUMwJBANaEu9s0Y1Bxbpg2YNUPJ5hPfPp/
3Ye0kTurcBerYjqnRVA/fuLDIX146OgcNnKADUbhRihebJCtvDedwKmOJtECQQC+
tVYLSr3Sg9eCSZXwBh7OAGwLiyEFljZ7S1CddCt1wqvlIrYIuFBqK1XYO91LCycJ
PW8PO7wK+EwPbuDkzWLdAkEA4bx5fINl3NWLBvievrBDTXyZo6whxrB5tZK9Po8G
Lxm/OrMACYuyUcTMkgYhE12DFCQ61VXJbU7F3u5GY5LTdw==
-----END RSA PRIVATE KEY-----
An example private key consisting of 1024 bits can be seen below:
[plain]
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAqkzWjlcyEC31pMRU6BnnzbyFGXm1uFx8vGrh/1bUImmJvuO8
s0Pg2vgt7iiLsOFyabaHR0kxanwDAjxG9Q0E+GkB02HL393TX8eVey0P75YbQMtL
kHOCNCq8XL4BJSd6ML0PcSu1VYhCXLojnnCznjwX8IqHAmtd+qLSTsFmDsi2+QUq
+REuy/nxs+0PxSJNszPcBYSlB3Kp9/uCC/EOKJXkkMsaNewqEd3epvGhevs/5/3Z
Eu+f7d6F5QzCNVtcYHPY7mON+o9pEWCVfiH/0ILfcw4oF052E9VQ0Ks+zLVmv+b5
6ZzpuDy4m1b+rQ78+EH+zIW7HChuRuvxRMoFbQIDAQABAoIBAQCOz2zFZN24r7Hl
ADdrg/3di4/aMzRubDC2GLN4Wqn+SZ6Xk4b0laGEPsbVhu7N3+EAQW7kGr7z2xby
0vV2HfrjDbvY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Fu7yBRZGJvmUYgiu4yFlFIgqzSoef8rMAjY
FM0oX88NeiKMjnEM4klMR+L8zjcvcg2ek5qwrbtfqyR4ld2EphOVRw==
-----END RSA PRIVATE KEY-----
An example private key consisting of 4096 bits can be seen below:
[plain]
-----BEGIN RSA PRIVATE KEY-----
MIIJKgIBAAKCAgEAs97b02xeA+uwL+JKi1cSs+7HjlZAw6fi5SwQZhipILjHlCuU
LDxOa//YgxK+XId9YkIos8wrMh1VwewsHT3XlpxFLL3sVZuTYM2Tngb0/6kCW7zp
DQb8FZCIy9dn7BhL4Klym5ltyCaf7OgktyfE/vGV7+cqcrVF84lb3ZZ2wq7v3mq7
dKd+RCQ/RlfeVIzmluCZDIAZbPtHBwtW2dI53PPD8gmZm88Sg9hmxLwogxx6atrW
FOYYiOjnM4ceRVhfp55xF1O71fN42L/pdW41LtnTzFWmCAqJOpQjpV3ZqYd30Xnn
6XLDQ3zTerblCmzaK/N6QEiswD1QVrbLJ1qr67QREBlEHoAtbdQ5hiWNUPWb3FGZ
FrdL34e6aKoWJ++QUbCY+t9YjsQNN+b876VhYmEjpXccPN17BoaMkhE+xspmnCIE
VallHH17bo//QptJMYZsI4H1fWSmYY2eUs8doUYcQJSRqcpG8KlQHXLwCmP2NsSH
uEf3Vur2neOAT9e98CpMX9tEj3eMQaVxI+CfUadx91Xp+4BBadki0zS25mkHwMYu
bav8qUyuR/KQqIyiM802CuJPR8ZTGT6RUrPNklF7HqDjU4p1Ga0gzIqYOuZwSHYj
cTINs5ywkNOWCUKZrdpcquB0AIWVDXZu0z0gx40S+zOcw85DRnrKhEODdMUCAwEA
AQKCAgBrnfwyTBUYDWzVyXPGWKt1AnldHRgUuB8V9L4/B6QxUrz+VvCJYu+cyG+X
RKCmpd4L6v+FS7PQgSKtKwvd1wFlOExfD6cWNUYBVh5rH0h4qnshvi5FwBcVI+vk
4hVoecT0Pw22MR8w8IMg8Gf/OYkw7AREjC+mf/TBWD6hnoOhyZ70mTFdA1WVmYZO
JQZ92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BePSk/6T0d7H
hKk8ckEJtDhYAjFTnjn3ttfcid2CL2G2inN7Yh9wN1wuG4qR+dHfvxqOPI59aidz
cuX8EZFXIphNYEDF+DL2dGgMlwoH6j+Ja3o3dwibm5QNef5m3pXIqEYa9Oau5A==
-----END RSA PRIVATE KEY-----
We can see the size of the private key actually increases when specifying different key sizes. By using a larger key size, we're actually increasing the number of possibilities, which also increases the bruteforce time.
Reducing the Login Time
Whenever we start to use public/private keys, we may soon be annoyed by having to provide the password for the private keys all the time. In order to solve that issue, we can use ssh-agent, which is a daemon, whose sole purpose is to cache our decrypted private keys in memory for the duration of the session. The ssh command can communicate with the ssh-agent to provide the private keys, so the user doesn't need to repeatedly provide the password.
Two environmental variables SSH_AUTH_SOCK and SSH_AGENT_PID are used in the shell in order to tell programs the settings of the ssh-agent process. Once the ssh-agent is started and the environmental variables are applied to the current shell, we can use ssh-add to add a private key to the cache.
[plain]
# ssh-add mykey
Identity added: mykey (rsa w/o comment)
Then we can list the keys by using the "ssh-add -l" command as presented below.
[plain]
# ssh-add -l
4096 39:ca:ec:af:b8:9f:79:7d:27:83:5f:fc:e1:2a:72:fd rsa w/o comment (RSA)
Afterwards, we can easily ssh to the cloud server by using the cached version of private key without providing the password. This gives us the best possible security, since all the keys stored on the filesystem are encrypted, but a cached copy of a private key is stored by ssh-agent for the duration of the session.
[plain]
# ssh -i mykey user@host
Backing Up Keys
When having a number of private/public key pairs that we rely on, we have to have a secure backup solution. Failing to do so can result in being locked out of a cloud service or disable a way to decrypt the already encrypted files. The result of losing the private/public key pairs can be devastating, which is why we have to ensure we have a proper backup in place.
We can also use private/public keys as part of our backup solution as was described by this article. In the article, private/public keys are created and used by the bacula daemon in order to backup an encrypted version of files to the remote location. A part of the files can also be the private/public keys we created eariler.
Conclusion
The use of public/private keys has mushroomed, and is now being used by a number of protocols and applications. The primary reason for that is improving security, since keys provide a much better security than a password that was chosen by a user. Therefore, the importance of public/private keys is becoming more and more important and is being used to authentication to various cloud-based services.
In order to provide cloud services, we have to ensure we're properly protecting our public/private keys, which can give an attacker keys to the kingdom. We've looked at various ways of how further to protect the keys in order to make the attacker's job much more difficult. We have to keep in mind that an attacker having gained a private key can possibly log in to various cloud systems or decrypt possibly leaked encrypted data.
Learn Cloud Security
References
[1] The Secure Shell (SSH) Transport Layer Protocol, https://tools.ietf.org/html/rfc4253#section-6.6.
[2] Why some cryptographic keys are much smaller than others, https://blog.cloudflare.com/why-are-some-keys-small/.