Beispiel #1
0
	def execute( self, args ):
		keys = self.root.gpg.keyDB().findKeys( args.recipients )

		havePrivate = False
		for key in keys:
			if key.type == 'sec':
				havePrivate = True

		if not havePrivate:
			print( "At least one key provided should have a private key available, otherwise you will not be able to decrypt the passwords. Aborting.")
			sys.exit()

		pathUri = uri.join( args.path )

		print( self.repository._path( pathUri ))

		if self.repository.exists(pathUri ):
			if not self.repository.isDir(  pathUri ):
				print( "'%s' is not a directory!" % (pathUri ) )
				sys.exit( 1 )
			#else: #if os.path.islink( realPath ):
			#	print( "'%s' is a symlink!" % ( pathUri ) )
			#	sys.exit( 1 )
		else:
			os.makedirs( realPath )

		keyIds = []
		for key in keys:
			keyIds += [ key.keyid ]

		# Double-check that this isn't a no-op
		gpgIdPath = uri.join( pathUri, '.gpg-id' )
		gpgIdFile = self.repository.write( gpgIdPath )
		#gpgIdPath = os.path.join( args.path, '.gpg-id' )

		for keyId in keyIds:
			gpgIdFile.write( (keyId + '\n').encode() )
		gpgIdFile.commit()

		self.repository.notifyAdd( gpgIdPath, 'Set GPG id to %s' % ( ', '.join( keyIds ) ) )
		print( "Password store initialized for %s" % ( ', '.join( keyIds ) ) )

		print( 'Re-encrypting entries as necessary...' )
		container = self.root.findEntry( args.path )
		signature = container.signingKey()
		print( 'signingKey is %s' % ( signature ) )
		def reencryptCallback( entry, level ):
			try:
				if isinstance( entry, PasswordEntry ):
					print( 'Re-encrypting ' + entry.name, end='', flush=True )
					if entry.reencrypt( signature ):
						print( ' done' )
					else:
						print( ' not needed' )
			except RuntimeError as e:
				print( ' failure' )
				print( 'Failed to encrypt file %s' % ( e ) )

		container.walk( reencryptCallback )
Beispiel #2
0
    def findEntry(self, path):
        childPath = uri.join(self.path, path)

        if self.repository.isDir(childPath):
            return Container(childPath, self.repository, self.gpg)
        else:
            return PasswordEntry(childPath, self.repository, self.gpg)
Beispiel #3
0
	def findEntry( self, path ):
		childPath = uri.join( self.path, path )

		if self.repository.isDir( childPath ):
			return Container( childPath, self.repository, self.gpg )
		else:
			return PasswordEntry( childPath, self.repository, self.gpg )
Beispiel #4
0
    def __init__(self, path='/', *args):
        super().__init__(path, *args)

        if not self.repository.isDir(self.path):
            raise RuntimeError('%s: is not a valid container' % (self.path))

        self.gpgIdPath = uri.join(self.path, '.gpg-id')
        self._recipients = None
Beispiel #5
0
	def __init__( self, path = '/', *args ):
		super().__init__( path, *args )

		if not self.repository.isDir( self.path ):
			raise RuntimeError( '%s: is not a valid container' % ( self.path ) )

		self.gpgIdPath = uri.join( self.path, '.gpg-id' )
		self._recipients = None
Beispiel #6
0
    def children(self):
        fullPath = self.repository._path(self.path)
        items = os.listdir(fullPath)

        childList = []
        for item in items:
            if item.startswith('.'): continue
            fullURI = uri.join(self.path, item)
            if self.repository.isDir(fullURI):
                childList.append(Container(item, self))
            elif item.endswith('.gpg'):
                childList.append(PasswordEntry(item, self))

        return childList
Beispiel #7
0
	def children( self ):
		fullPath = self.repository._path( self.path )
		items = os.listdir( fullPath )

		childList = []
		for item in items:
			if item.startswith( '.' ): continue
			fullURI = uri.join( self.path, item )
			if self.repository.isDir( fullURI ):
				childList.append( Container( item, self ) )
			elif item.endswith( '.gpg' ):
				childList.append( PasswordEntry( item, self ) )

		return childList
Beispiel #8
0
    def __init__(self, path, *args):
        parent = None
        for arg in args:
            if isinstance(arg, Entry):
                parent = arg
                self.repository = arg.repository
                self.gpg = arg.gpg
            elif isinstance(arg, Repository):
                self.repository = arg
            elif isinstance(arg, ExtendedGPG):
                self.gpg = arg

        if parent is not None:
            self.path = uri.join(parent.path, path)
        else:
            self.path = path

        self.name = path
Beispiel #9
0
	def __init__( self, path, *args ):
		parent = None
		for arg in args:
			if isinstance( arg, Entry ):
				parent = arg
				self.repository = arg.repository
				self.gpg = arg.gpg
			elif isinstance( arg, Repository ):
				self.repository = arg
			elif isinstance( arg, ExtendedGPG ):
				self.gpg = arg
		
		if parent is not None:
			self.path = uri.join( parent.path, path )
		else:
			self.path = path

		self.name = path
Beispiel #10
0
    def execute(self, args):
        keys = self.root.gpg.keyDB().findKeys(args.recipients)

        havePrivate = False
        for key in keys:
            if key.type == 'sec':
                havePrivate = True

        if not havePrivate:
            print(
                "At least one key provided should have a private key available, otherwise you will not be able to decrypt the passwords. Aborting."
            )
            sys.exit()

        pathUri = uri.join(args.path)

        print(self.repository._path(pathUri))

        if self.repository.exists(pathUri):
            if not self.repository.isDir(pathUri):
                print("'%s' is not a directory!" % (pathUri))
                sys.exit(1)
            #else: #if os.path.islink( realPath ):
            #	print( "'%s' is a symlink!" % ( pathUri ) )
            #	sys.exit( 1 )
        else:
            os.makedirs(realPath)

        keyIds = []
        for key in keys:
            keyIds += [key.keyid]

        # Double-check that this isn't a no-op
        gpgIdPath = uri.join(pathUri, '.gpg-id')
        gpgIdFile = self.repository.write(gpgIdPath)
        #gpgIdPath = os.path.join( args.path, '.gpg-id' )

        for keyId in keyIds:
            gpgIdFile.write((keyId + '\n').encode())
        gpgIdFile.commit()

        self.repository.notifyAdd(gpgIdPath,
                                  'Set GPG id to %s' % (', '.join(keyIds)))
        print("Password store initialized for %s" % (', '.join(keyIds)))

        print('Re-encrypting entries as necessary...')
        container = self.root.findEntry(args.path)
        signature = container.signingKey()
        print('signingKey is %s' % (signature))

        def reencryptCallback(entry, level):
            try:
                if isinstance(entry, PasswordEntry):
                    print('Re-encrypting ' + entry.name, end='', flush=True)
                    if entry.reencrypt(signature):
                        print(' done')
                    else:
                        print(' not needed')
            except RuntimeError as e:
                print(' failure')
                print('Failed to encrypt file %s' % (e))

        container.walk(reencryptCallback)