dknewkey with ed25519 insecure chmod call / race condition
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dkimpy |
Fix Released
|
Medium
|
Scott Kitterman | ||
1.0 |
Fix Released
|
Medium
|
Scott Kitterman | ||
1.1 |
Fix Released
|
Medium
|
Scott Kitterman |
Bug Description
When generating an ed25519 key with dknewkey a race condition occurs with the file permission.
The problem is in this code:
```
priv_key = skg.generate()
with open(private_
if os.name == 'posix':
return(
```
The chmod is only called after the key is written to the file.
This could be exploited on a multiuser system if keys are generated according to a known scheme. You can test this with fpracer, a proof of concept for such vulnerabilities:
https:/
With an unprivileged user account run:
```
./fpracer /etc/dkim/
```
With the root account run:
```
mkdir /etc/dkim
cd /etc/dkim
dknewkey --ktype ed25519 example.com
```
To avoid such races it is necessary to already create the file with secure permissions. This can be done for example via os.umask. I have attached a patch.
Changed in dkimpy: | |
assignee: | nobody → Scott Kitterman (kitterman) |
Changed in dkimpy: | |
status: | Confirmed → Fix Released |
information type: | Private Security → Public Security |
Thanks. I agree this is an issue, but I don't think it's super urgent as it takes local access and knowing what the file name will be, in addition to knowing when. I'm going to give it a week and see if any other bugs pop up and then do a release to fix this and anything else.