def makePrivateKeyString_lsh(obj, passphrase): if passphrase: raise BadKeyError("cannot encrypt to lsh format") keyType = objectType(obj) if keyType == 'ssh-rsa': p,q=obj.p,obj.q if p > q: (p,q)=(q,p) return sexpy.pack([['private-key', ['rsa-pkcs1', ['n', common.MP(obj.n)[4:]], ['e', common.MP(obj.e)[4:]], ['d', common.MP(obj.d)[4:]], ['p', common.MP(q)[4:]], ['q', common.MP(p)[4:]], ['a', common.MP(obj.d%(q-1))[4:]], ['b', common.MP(obj.d%(p-1))[4:]], ['c', common.MP(Util.number.inverse(p, q))[4:]]]]]) elif keyType == 'ssh-dss': return sexpy.pack([['private-key', ['dsa', ['p', common.MP(obj.p)[4:]], ['q', common.MP(obj.q)[4:]], ['g', common.MP(obj.g)[4:]], ['y', common.MP(obj.y)[4:]], ['x', common.MP(obj.x)[4:]]]]]) else: raise BadKeyError('bad keyType %s' % keyType)
def makePrivateKeyString_lsh(obj, passphrase): if passphrase: raise BadKeyError("cannot encrypt to lsh format") keyType = objectType(obj) if keyType == 'ssh-rsa': p, q = obj.p, obj.q if p > q: (p, q) = (q, p) return sexpy.pack([[ 'private-key', [ 'rsa-pkcs1', ['n', common.MP(obj.n)[4:]], ['e', common.MP(obj.e)[4:]], ['d', common.MP(obj.d)[4:]], ['p', common.MP(q)[4:]], ['q', common.MP(p)[4:]], ['a', common.MP(obj.d % (q - 1))[4:]], ['b', common.MP(obj.d % (p - 1))[4:]], ['c', common.MP(Util.number.inverse(p, q))[4:]] ] ]]) elif keyType == 'ssh-dss': return sexpy.pack([[ 'private-key', [ 'dsa', ['p', common.MP(obj.p)[4:]], ['q', common.MP(obj.q)[4:]], ['g', common.MP(obj.g)[4:]], ['y', common.MP(obj.y)[4:]], ['x', common.MP(obj.x)[4:]] ] ]]) else: raise BadKeyError('bad keyType %s' % keyType)
def makePublicKeyString_lsh(obj): keyType = objectType(obj) if keyType == 'ssh-rsa': keyData = sexpy.pack([['public-key', ['rsa-pkcs1-sha1', ['n', common.MP(obj.n)[4:]], ['e', common.MP(obj.e)[4:]]]]]) elif keyType == 'ssh-dss': keyData = sexpy.pack([['public-key', ['dsa', ['p', common.MP(obj.p)[4:]], ['q', common.MP(obj.q)[4:]], ['g', common.MP(obj.g)[4:]], ['y', common.MP(obj.y)[4:]]]]]) else: raise BadKeyError('bad keyType %s' % keyType) return '{' + base64.encodestring(keyData).replace('\n','') + '}'
def makePrivateKeyString_lsh(obj, passphrase): #assert not passphrase keyType = objectType(obj) if keyType == 'ssh-rsa': return sexpy.pack([['private-key', ['rsa-pkcs1', ['n', common.MP(obj.n)[4:]], ['e', common.MP(obj.e)[4:]], ['d', common.MP(obj.d)[4:]], ['p', common.MP(obj.p)[4:]], ['q', common.MP(obj.q)[4:]], ['a', common.MP(obj.d%(obj.p-1))[4:]], ['b', common.MP(obj.d%(obj.q-1))[4:]], ['c', common.MP(Util.number.inverse(obj.q, obj.p))[4:]]]]]) elif keyType == 'ssh-dss': return sexpy.pack([['private-key', ['dsa', ['p', common.MP(obj.p)[4:]], ['q', common.MP(obj.q)[4:]], ['g', common.MP(obj.g)[4:]], ['y', common.MP(obj.y)[4:]], ['x', common.MP(obj.x)[4:]]]]]) else: raise BadKeyError('bad keyType %s' % keyType)
def makePublicKeyString_lsh(obj): keyType = objectType(obj) if keyType == 'ssh-rsa': keyData = sexpy.pack([[ 'public-key', [ 'rsa-pkcs1-sha1', ['n', common.MP(obj.n)[4:]], ['e', common.MP(obj.e)[4:]] ] ]]) elif keyType == 'ssh-dss': keyData = sexpy.pack([[ 'public-key', [ 'dsa', ['p', common.MP(obj.p)[4:]], ['q', common.MP(obj.q)[4:]], ['g', common.MP(obj.g)[4:]], ['y', common.MP(obj.y)[4:]] ] ]]) else: raise BadKeyError('bad keyType %s' % keyType) return '{' + base64.encodestring(keyData).replace('\n', '') + '}'