Skip to content

Commit

Permalink
CASSH v1.4.0: Admin can force signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Beguier committed Nov 21, 2017
1 parent 51e797c commit 6e68525
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cassh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ if sys.version_info < (3, 0):
# Debug
# from pdb import set_trace as st

VERSION = '%(prog)s 1.4.0'

def read_conf(conf_path):
"""
Read CASSH configuration file and return metadata.
Expand Down Expand Up @@ -176,14 +178,19 @@ class CASSH(object):
exit(1)
print(req.text)

def sign(self, do_write_on_disk, uid=None):
def sign(self, do_write_on_disk, uid=None, force=False):
"""
Sign a public key.
"""
pubkey = open('%s.pub' % self.key_path, 'rb')
try:
req = self.session.post(self.url + '/client' + \
self.auth_url(prefix='?username=%s' % self.name), data=pubkey, verify=False)
if force:
req = self.session.post(self.url + '/client' + \
self.auth_url(prefix='?username=%s&admin_force=true' % self.name), \
data=pubkey, verify=False)
else:
req = self.session.post(self.url + '/client' + \
self.auth_url(prefix='?username=%s' % self.name), data=pubkey, verify=False)
except ConnectionError:
print('Connection error : %s' % self.url)
exit(1)
Expand Down Expand Up @@ -255,7 +262,7 @@ if __name__ == '__main__':

SUBPARSERS = PARSER.add_subparsers(help='commands')

PARSER.add_argument('--version', action='version', version='%(prog)s 1.3.0')
PARSER.add_argument('--version', action='version', version=VERSION)

# ADMIN Arguments
ADMIN_PARSER = SUBPARSERS.add_parser('admin',\
Expand All @@ -274,6 +281,8 @@ if __name__ == '__main__':
SIGN_PARSER = SUBPARSERS.add_parser('sign', help='Sign its key by remote ssh ca server.')
SIGN_PARSER.add_argument('-d', '--display-only', action='store_true',\
help='Display key in shell only.')
SIGN_PARSER.add_argument('-f', '--force', action='store_true',\
help='Admin can force signature if server enable it.')
SIGN_PARSER.add_argument('-u', '--uid', action='store',\
help='Force UID in key ownership.')

Expand All @@ -299,7 +308,7 @@ if __name__ == '__main__':
print('[user]')
print('# name : it\'s the user you will use to log in every server')
print('name = user')
print('# key_path : This key path won\'t be use to log in, a copy will be made for the certificate.')
print('# key_path : This key path won\'t be use to log in, a copy will be made.')
print('# We assume that `${key_path}` exists and `${key_path}.pub` too.')
print('# WARNING: Never delete these keys')
print('key_path = ~/.ssh/id_rsa')
Expand All @@ -323,7 +332,7 @@ if __name__ == '__main__':
if sys.argv[1] == 'add':
LBC.add()
elif sys.argv[1] == 'sign':
LBC.sign(not ARGS.display_only, uid=ARGS.uid)
LBC.sign(not ARGS.display_only, uid=ARGS.uid, force=ARGS.force)
elif sys.argv[1] == 'status':
LBC.status()
elif sys.argv[1] == 'ca':
Expand Down

0 comments on commit 6e68525

Please sign in to comment.