Exemplo n.º 1
0
    def test_ECDSA(self):
        publicKey, privateKey = ECGenerator().generateECKeyPair()
        data = bytearray([0, 1, 2, 3])
        badData = bytearray([0, 1, 2, 4])

        signature = privateKey.sign(data)
        assert (publicKey.verify(data, signature))
        assert (not publicKey.verify(badData, signature))
Exemplo n.º 2
0
    def test_ECDSA(self):
        publicKey, privateKey = ECGenerator().generateECKeyPair()
        data = bytearray([0,1,2,3])
        badData = bytearray([0,1,2,4])

        signature = privateKey.getSignature(data)
        assert(publicKey.verify(data, signature))
        assert(not publicKey.verify(badData, signature))
Exemplo n.º 3
0
    def execute(self):
        password = self._getPasswordWithPrompt()
        public_key, private_key = ECGenerator.generateECKeyPair()
        keyFile  = TackKeyFile.create(public_key, private_key, password)
        self.outputFile.write(self.addPemComments(keyFile.serializeAsPem()))

        if self.isVerbose():
            self.writeCryptoVersion()
            sys.stderr.write(str(keyFile))
Exemplo n.º 4
0
 def createRandom(cls, password):
     tackKeyFile = cls()
     tackKeyFile.password = password
     tackKeyFile.version = 1
     tackKeyFile.iter_count = 8192
     tackKeyFile.salt = bytearray(os.urandom(16))
     tackKeyFile.public_key, tackKeyFile.private_key = ECGenerator(
     ).generateECKeyPair()
     tackKeyFile.ciphertext, tackKeyFile.mac = tackKeyFile._encryptKey(
         password, tackKeyFile.salt, tackKeyFile.iter_count,
         tackKeyFile.public_key, tackKeyFile.private_key)
     return tackKeyFile
Exemplo n.º 5
0
 def test_KeyFile(self):
     s = """
 -----BEGIN TACK PRIVATE KEY-----
 AQAAIAAjOxiOdpiMo5qWidXwBTqJHxW5X1zRDBOA4ldqqFuKOSh6JJdrbXk1WsMN
 X/gyaVuHMBhC/g/rjtu/EnmIHoUuT9348iXeeROaLVRPdNqwr+5KEfjtTY7uXA6Q
 mhRUn+XmDePKRucRHYkcQaFPnzglrQ120Dh6aXD4PbtJMWajJtzTMvtEo9pNZhoM
 QTNZNoM=
 -----END TACK PRIVATE KEY-----"""
     publicKey = a2b_hex("87301842fe0feb8edbbf1279881e852e"
                         "4fddf8f225de79139a2d544f74dab0af"
                         "ee4a11f8ed4d8eee5c0e909a14549fe5"
                         "e60de3ca46e7111d891c41a14f9f3825")
     privateKey = a2b_hex("fc815de8b1de13a436e9cd69742cbf2c"
                          "d4c1c9bb33e023401d9291cf2781b754")
     kf = TackKeyFile.createFromPem(s, "asdf")
     assert(kf.getPublicKey().getRawKey() == publicKey)
     assert(kf.getPrivateKey().getRawKey() == privateKey)
     kf2 = TackKeyFile.createFromPem(kf.serializeAsPem(), "asdf")
     assert(kf2.getPublicKey().getRawKey() == publicKey)
     assert(kf2.getPrivateKey().getRawKey() == privateKey)
     public_key, private_key = ECGenerator.generateECKeyPair()
     kf3  = TackKeyFile.create(public_key, private_key, "123")
     kf4 = TackKeyFile.createFromPem(kf3.serializeAsPem(), "123")
     assert(kf3.getPublicKey().getRawKey() == kf4.getPublicKey().getRawKey())
Exemplo n.º 6
0
 def execute(self):
     password = self._getPasswordWithPrompt()
     public_key, private_key = ECGenerator.generateECKeyPair()
     keyFile  = TackKeyFile.create(public_key, private_key, password)
     self.outputFile.write(self.addPemComments(keyFile.serializeAsPem()))
     self.printVerbose(str(keyFile))
Exemplo n.º 7
0
 def execute(self):
     password = self._getPasswordWithPrompt()
     public_key, private_key = ECGenerator.generateECKeyPair()
     keyFile = TackKeyFile.create(public_key, private_key, password)
     self.outputFile.write(self.addPemComments(keyFile.serializeAsPem()))
     self.printVerbose(str(keyFile))