summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/Fingerprint.py
blob: aff8d42bf8eae51dd40ae03b508811c8b9357b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''Fingerprint mode for bcfg2-admin'''

import Bcfg2.tlslite.api
import Bcfg2.Server.Admin

class Fingerprint(Bcfg2.Server.Admin.Mode):
    '''Produce server key fingerprint'''
    __shorthelp__ = 'bcfg2-admin fingerprint'
    __longhelp__ = __shorthelp__ + '\n\tPrint the server certificate fingerprint'
    
    def __init__(self, cfile):
	Bcfg2.Server.Admin.Mode.__init__(self, cfile)	

    def __call__(self, args):
        Bcfg2.Server.Admin.Mode.__call__(self, args)
        print self.getFingerprint()

    def getFingerprint(self):
        '''calculate key fingerprint'''
        keypath = self.cfp.get('communication', 'key')
        x509 = Bcfg2.tlslite.api.X509()
        x509.parse(open(keypath).read())
        return x509.getFingerprint()