예제 #1
0
    def _decryptWithMyPrivateKey(self, message):
        from algorithmcontroller import getAlgorithmController

        rsa = getAlgorithmController().getAlgorithm("rsa")
        rsa.setKeyPair(self._privateKey)

        return rsa.decrypt(message)
예제 #2
0
파일: testg4ds.py 프로젝트: kichkasch/ioids
def testSecurityController():
    from algorithmcontroller import getAlgorithmController
    print getAlgorithmController().getAvailableAlgorithms()
    print getAlgorithmController().getOpenAlgorithms()
    algRsa = getAlgorithmController().getAlgorithm("rsa")
    privatekey = algRsa.createKeyPair(512)
    algRsa.setKeyPair(privatekey)
    pubkeystr = algRsa.getPublicKey()
    
    message = "hello world"
    cipher = algRsa.encrypt(message, pubkeystr)
    print cipher
    sig = algRsa.signMessage(message)
    print "Signature: ", sig
    
    plain = algRsa.decrypt(cipher)
    print plain
    print "Verified? ", algRsa.validate(plain, sig, pubkeystr)
예제 #3
0
 def validate(self, message, signature, key, algorithm):
     """
     Verifies, whether the given signature corrosponds with the given message.
     
     @return: Indicates, whether message and signature belong togehter.
     @rtype: C{Boolean}
     """
     algorithm = getAlgorithmController().getAlgorithm(algorithm)
     return algorithm.validate(message, signature, key)
예제 #4
0
 def signMessage(self, message, algorithm): 
     """
     Provides a signature for the given message.
     
     Key is not need here since the private key stored for this algorithm will be used.
     
     @return: The signature
     @rtype: C{String}
     """
     algorithm = getAlgorithmController().getAlgorithm(algorithm)
     signature = algorithm.signMessage(message)
     return signature
예제 #5
0
    def _createAuthenticationToken(self):
        """
        We simply use RSA here.
        """
        from algorithmcontroller import getAlgorithmController

        rsa = getAlgorithmController().getAlgorithm("rsa")
        rsa.setKeyPair(self._privateKey)

        import random

        plain = ""
        for i in range(0, 100):
            plain += chr(random.randint(0, 127))

        signature = rsa.signMessage(plain)

        return plain, signature
예제 #6
0
 def encrypt(self, message, key, algorithm):
     """
     Encrypts the message using the the given key and algorithm.
     
     The corresponding algorithm is loaded using the name and the messages together with
     the key is passed to the encryption method in there.
     
     @param message: Plain text to be encrypted
     @type message: C{String}
     @param key: Key to be used for encryption
     @type key: C{String}
     @param algorithm: Name of the algorithm to be used for encryption
     @type algorithm: C{String}
     @return: Return value of the corresponding encrypt function within the implementation for the algorithm - cipher text
     @rtype: C{String}
     """
     algorithm = getAlgorithmController().getAlgorithm(algorithm)
     cipher = algorithm.encrypt(message, key)
     return cipher
예제 #7
0
 def decrypt(self, message, algorithm):
     """
     Decrypts the message using the the given key and algorithm.
     
     The corresponding algorithm is loaded using the name and the messages together with
     the key is passed to the decryption method in there.
     
     Key is not need here since the private key stored for this algorithm will be used.
     
     @param message: Cipher text to be decrypted
     @type message: C{String}
     @param algorithm: Name of the algorithm to be used for decryption
     @type algorithm: C{String}
     @return: Return value of the corresponding decrypt function within the implementation for the algorithm - plain text
     @rtype: C{String}
     """
     algorithm = getAlgorithmController().getAlgorithm(algorithm)
     plain = algorithm.decrypt(message)
     return plain
예제 #8
0
파일: install.py 프로젝트: kichkasch/ioids
def installOneKey(algId, i, localMemberId):
    """
    Install key for one algorithm
    """
    from algorithmcontroller import getAlgorithmController
    from securitymanager import getAlgorithmManager
    algName = getAlgorithmManager().getAlgorithm(algId).getName()
    _printAction (i, "Personal Credential for algorithm '" + algName + "'")
    algImplementation = getAlgorithmController().getAlgorithm(algName)
    privateKey = algImplementation.createKeyPair()
    publicKey = algImplementation.getPublicKey(privateKey)
    from securitymanager import PersonalCredential
    credential = PersonalCredential(None, algName + " key pair", algId, privateKey, publicKey, "")
    from securitymanager import getPersonalCredentialManager
    getPersonalCredentialManager().addPersonalCredential(credential)
    _finishActionLine()
    
    _printAction (i, "Public Credential for algorithm '" + algName + "'")
    from securitymanager import Credential
    from securitymanager import getCredentialManager
    credential = Credential(None, algId, "", publicKey, localMemberId)
    getCredentialManager().addCredential(credential)
    _finishActionLine()
예제 #9
0
파일: install.py 프로젝트: kichkasch/ioids
def installAlgorithms(i, localMemberId):
    """
    Put all algorithms into the database.
    
    @return: list of algorithm ids.
    @rtype: C{List} of C{String}
    """
    _printAction (i, "Initialise algorithms", 1)
    from algorithmcontroller import getAlgorithmController
    from securitymanager import getAlgorithmManager
    from securitymanager import Algorithm
    
    allOpen = getAlgorithmController().getOpenAlgorithms()
    returnList = []
    for algName in allOpen:
        _printAction (i +1, "Algorithm '" + algName)
##        alg = Algorithm(None, algName)
##        getAlgorithmManager().addAlgorithm(alg)
        alg = getAlgorithmManager().getAlgorithmByNameAndInsert(algName)
        returnList.append(alg.getId())
        _finishActionLine()
    _printAction (i, "Finished algorithms")
    _finishActionLine()
    return returnList
예제 #10
0
파일: g4ds.py 프로젝트: kichkasch/ioids
        self.loadConfigurations()        # initialise with their private keys from the personal credential manager
##        _finishActionLine()        

        _printAction(1, "Start G4DS logging")
        from g4dslogging import getDefaultLogger
        try:
            getDefaultLogger()
            _finishActionLine()
        except G4dsException, msg:
            _finishActionLine(SUCESS_NEG)
            _printAction(2, str(msg))
            _finishActionLine(SUCESS_NEG)
            
        _printAction(1, "Loading Keys")
        from algorithmcontroller import getAlgorithmController
        getAlgorithmController().loadKeys()        # initialise with their private keys from the personal credential manager
        _finishActionLine()        

        _printAction(1, "Start up protocols and listeners")
        from protocolcontroller import getProtocolController
        import socket 
        try:
            getProtocolController()                     # start listening on all endpoints
            _finishActionLine()
        except socket.error, msg:
            _finishActionLine(SUCESS_NEG)
            _printAction(2, str(msg))
            _finishActionLine(SUCESS_NEG)            
            
        _printAction(1, "Load up permission policies into memory")
        from authorisationcontroller import getAuthorisationController