Skip to content

Commit 6e68525

Browse files
author
Nicolas Beguier
committed
CASSH v1.4.0: Admin can force signature
1 parent 51e797c commit 6e68525

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cassh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ if sys.version_info < (3, 0):
3131
# Debug
3232
# from pdb import set_trace as st
3333

34+
VERSION = '%(prog)s 1.4.0'
35+
3436
def read_conf(conf_path):
3537
"""
3638
Read CASSH configuration file and return metadata.
@@ -176,14 +178,19 @@ class CASSH(object):
176178
exit(1)
177179
print(req.text)
178180

179-
def sign(self, do_write_on_disk, uid=None):
181+
def sign(self, do_write_on_disk, uid=None, force=False):
180182
"""
181183
Sign a public key.
182184
"""
183185
pubkey = open('%s.pub' % self.key_path, 'rb')
184186
try:
185-
req = self.session.post(self.url + '/client' + \
186-
self.auth_url(prefix='?username=%s' % self.name), data=pubkey, verify=False)
187+
if force:
188+
req = self.session.post(self.url + '/client' + \
189+
self.auth_url(prefix='?username=%s&admin_force=true' % self.name), \
190+
data=pubkey, verify=False)
191+
else:
192+
req = self.session.post(self.url + '/client' + \
193+
self.auth_url(prefix='?username=%s' % self.name), data=pubkey, verify=False)
187194
except ConnectionError:
188195
print('Connection error : %s' % self.url)
189196
exit(1)
@@ -255,7 +262,7 @@ if __name__ == '__main__':
255262

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

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

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

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

0 commit comments

Comments
 (0)