Skip to content

Commit

Permalink
Add all keytypes support (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikdoof authored Oct 1, 2020
1 parent 56e82bc commit ac7833b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

## Configuration

`mkuser` uses the OS defined configuration for the `useradd` command. On a Redhat derrived system this will be in `/etc/login.defs`. No configuration for the user is held by any `mkuser` file.
`mkuser` uses the OS defined configuration for the `useradd` command. On a Redhat derived system this will be in `/etc/login.defs`. No configuration for the user is held by any `mkuser` file.

The email template must be located at `/etc/mkuser/welcome_email.tmpl` and it uses Python's string Template format. Further details on the synax can be found within the [Python documentation](https://docs.python.org/3/library/string.html#template-strings).
The email template must be located at `/etc/mkuser/welcome_email.tmpl` and it uses Python's string Template format. Further details on the syntax can be found within the [Python documentation](https://docs.python.org/3/library/string.html#template-strings).

## Usage

Expand Down
29 changes: 19 additions & 10 deletions mkuser
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,32 @@ import yaml


__author__ = 'Andrew Williams <[email protected]>'
__version__ = '1.1.0'
__version__ = '1.1.1'

VALID_SSH_KEYTYPES = [
'[email protected]',
'ecdsa-sha2-nistp256',
'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp521',
'[email protected]',
'ssh-ed25519',
'ssh-rsa',
]


def validate_sshkey(keystring):
""" Validates that SSH pubkey string is valid """
# do we have 3 fields?
fields = len(keystring.split(' '))
if fields < 2 or fields > 3:
if fields < 2:
return 'Incorrect number of fields (%d)' % fields

if fields == 2:
keytype, pubkey = keystring.split(' ')
if fields == 3:
keytype, pubkey, _ = keystring.split(' ')
else:
fsplit = keystring.split(' ')
keytype = fsplit[0]
pubkey = fsplit[1]

# Check it is a valid type
if not keytype in ['ssh-rsa', 'ssh-ed25519']:
if not keytype in VALID_SSH_KEYTYPES:
return 'Invalid keytype'

# Decode the key data from Base64
Expand All @@ -52,7 +61,6 @@ def validate_sshkey(keystring):
# Keytype is encoded and must match
if not data[4:4+str_len].decode('ascii') == keytype:
return 'Embedded keytype does not match declared keytype (%s vs %s)' % (data[4:4+str_len].decode('ascii'), keytype)

return True


Expand Down Expand Up @@ -181,5 +189,6 @@ def main():
for address in (args.email, user.pw_name):
send_welcome_mail(address, mail_data)


if __name__ == '__main__':
main()
main()

0 comments on commit ac7833b

Please sign in to comment.