Пример #1
0
 def testI01EncryptPublicElGamalDES3ZIP(self):
     """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity, & ZIP"""
     key_d = read_test_file(['pgpfiles', 'key', 'DSAELG3.pub.gpg'])
     keypkt = list_pkts(key_d)[3]  # ElGamal encrypting key
     d = "My secret message."
     # literal data packet
     litbody = create_LiteralDataBody(data=d,
                                      modified=0,
                                      format='b',
                                      filename='outfile')
     litpkt = create_Packet(PKT_LITERAL, litbody._d)
     # compressed data packet
     compbody = create_CompressedDataBody(COMP_ZIP, litpkt.rawstr())
     comppkt = create_Packet(PKT_COMPRESSED, compbody._d)
     # session key
     key = gen_random(_keysize(SYM_DES3))
     sespkt = encrypt_public_session(keypkt, key, SYM_DES3)
     # encrypted data
     encpkt = encrypt_integrity(SYM_DES3, key, comppkt.rawstr())
     # decryption
     seckey_d = read_test_file(
         ['pgpfiles', 'key', 'DSAELG3.sec.nopass.gpg'])
     seckeypkt = list_pkts(seckey_d)[2]
     clrtxt = decrypt(encpkt, None, sespkt, seckeypkt)
     # got compressed
     comppkt_out = list_pkts(clrtxt)[0]
     # got literal
     litpkt_out = list_pkts(comppkt_out.body.data)[0]
     self.assertEqual(d, litpkt_out.body.data)
     self.assertEqual('outfile', litpkt_out.body.filename)
     self.assertEqual(0, litpkt_out.body.modified)
     self.assertEqual('b', litpkt_out.body.format)
Пример #2
0
 def testI01EncryptPublicElGamalDES3ZIP(self):
     """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity, & ZIP"""
     key_d = read_test_file(['pgpfiles','key','DSAELG3.pub.gpg'])
     keypkt = list_pkts(key_d)[3] # ElGamal encrypting key
     d = "My secret message."
     # literal data packet
     litbody = create_LiteralDataBody(data=d, modified=0, format='b',
                                          filename='outfile')
     litpkt = create_Packet(PKT_LITERAL, litbody._d)
     # compressed data packet
     compbody = create_CompressedDataBody(COMP_ZIP, litpkt.rawstr())
     comppkt = create_Packet(PKT_COMPRESSED, compbody._d)
     # session key
     key = gen_random(_keysize(SYM_DES3))
     sespkt = encrypt_public_session(keypkt, key, SYM_DES3)
     # encrypted data
     encpkt = encrypt_integrity(SYM_DES3, key, comppkt.rawstr())
     # decryption
     seckey_d = read_test_file(['pgpfiles','key','DSAELG3.sec.nopass.gpg'])
     seckeypkt = list_pkts(seckey_d)[2]
     clrtxt = decrypt(encpkt, None, sespkt, seckeypkt)
     # got compressed
     comppkt_out = list_pkts(clrtxt)[0]
     # got literal
     litpkt_out = list_pkts(comppkt_out.body.data)[0]
     self.assertEqual(d, litpkt_out.body.data)
     self.assertEqual('outfile', litpkt_out.body.filename)
     self.assertEqual(0, litpkt_out.body.modified)
     self.assertEqual('b', litpkt_out.body.format)
Пример #3
0
 def testH03EncryptSymmetric(self):
     """crypto.cipher: encrypt()/decrypt() AES256 (symmetric) w/ integrity"""
     alg = SYM_AES256
     msg = "My secret message."
     passphrase = 'test'
     sespkt = encrypt_symmetric_session(alg)
     key = string2key(sespkt.body.s2k, alg, passphrase)
     encpkt = encrypt_integrity(alg, key, msg)
     clrtxt = decrypt(encpkt, passphrase, sespkt)
     self.assertEqual(msg, clrtxt)
Пример #4
0
 def testG05Decrypt5(self):
     """crypto.cipher: decrypt() symmetric (CAST) compressed"""
     enc_d = read_test_file(['pgpfiles','enc','sym.cast.cleartext.txt.gpg'])
     clr_d = read_test_file(['pgpfiles','cleartext.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     passphrase = 'test'
     msg_d = decrypt(encpkt, passphrase, sespkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #5
0
 def testH03EncryptSymmetric(self):
     """crypto.cipher: encrypt()/decrypt() AES256 (symmetric) w/ integrity"""
     alg = SYM_AES256
     msg = "My secret message."
     passphrase = 'test'
     sespkt = encrypt_symmetric_session(alg)
     key = string2key(sespkt.body.s2k, alg, passphrase)
     encpkt = encrypt_integrity(alg, key, msg)
     clrtxt = decrypt(encpkt, passphrase, sespkt)
     self.assertEqual(msg, clrtxt)
Пример #6
0
 def testG05Decrypt5(self):
     """crypto.cipher: decrypt() symmetric (CAST) compressed"""
     enc_d = read_test_file(
         ['pgpfiles', 'enc', 'sym.cast.cleartext.txt.gpg'])
     clr_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     passphrase = 'test'
     msg_d = decrypt(encpkt, passphrase, sespkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #7
0
 def testH01EncryptPublicElGamalDES3(self):
     """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity"""
     key_d = read_test_file(['pgpfiles','key','DSAELG3.pub.gpg'])
     keypkt = list_pkts(key_d)[3] # ElGamal encrypting key
     msg = "My secret message."
     key = gen_random(_keysize(SYM_DES3))
     sespkt = encrypt_public_session(keypkt, key, SYM_DES3)
     encpkt = encrypt_integrity(SYM_DES3, key, msg)
     seckey_d = read_test_file(['pgpfiles','key','DSAELG3.sec.nopass.gpg'])
     seckeypkt = list_pkts(seckey_d)[2]
     clrtxt = decrypt(encpkt, None, sespkt, seckeypkt)
     self.assertEqual(msg, clrtxt)
Пример #8
0
 def testH01EncryptPublicElGamalDES3(self):
     """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity"""
     key_d = read_test_file(['pgpfiles', 'key', 'DSAELG3.pub.gpg'])
     keypkt = list_pkts(key_d)[3]  # ElGamal encrypting key
     msg = "My secret message."
     key = gen_random(_keysize(SYM_DES3))
     sespkt = encrypt_public_session(keypkt, key, SYM_DES3)
     encpkt = encrypt_integrity(SYM_DES3, key, msg)
     seckey_d = read_test_file(
         ['pgpfiles', 'key', 'DSAELG3.sec.nopass.gpg'])
     seckeypkt = list_pkts(seckey_d)[2]
     clrtxt = decrypt(encpkt, None, sespkt, seckeypkt)
     self.assertEqual(msg, clrtxt)
Пример #9
0
 def testG03Decrypt3(self):
     """crypto.cipher: decrypt() v3 public (RSA nopass) 3DES compressed"""
     enc_d = read_test_file(['pgpfiles', 'enc', 'pub.pgp653rsa.clrtxt.gpg'])
     key_d = read_test_file(['pgpfiles', 'key', 'pgp653rsa.sec.nopass.gpg'])
     clr_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     passphrase = 'test'
     sespkt, encpkt = list_pkts(enc_d)
     keypkt = list_pkts(key_d)[0]
     msg_d = decrypt(encpkt, passphrase, sespkt, keypkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #10
0
 def testG03Decrypt3(self):
     """crypto.cipher: decrypt() v3 public (RSA nopass) 3DES compressed"""
     enc_d = read_test_file(['pgpfiles','enc','pub.pgp653rsa.clrtxt.gpg'])
     key_d = read_test_file(['pgpfiles','key','pgp653rsa.sec.nopass.gpg'])
     clr_d = read_test_file(['pgpfiles','cleartext.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     passphrase = 'test'
     sespkt, encpkt = list_pkts(enc_d)
     keypkt = list_pkts(key_d)[0]
     msg_d = decrypt(encpkt, passphrase, sespkt, keypkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #11
0
 def testH02EncryptPublicRSAAES256(self):
     """crypto.cipher: encrypt()/decrypt() RSA, AES256 w/ integrity"""
     key_d = read_test_file(['pgpfiles', 'key', 'RSA1.pub.gpg'])
     keypkt = list_pkts(key_d)[0]  # use RSA for encrypting
     alg = SYM_AES256
     msg = "My secret message."
     passphrase = 'test'
     key = gen_random(_keysize(alg))
     sespkt = encrypt_public_session(keypkt, key, alg)
     encpkt = encrypt_integrity(alg, key, msg)
     seckey_d = read_test_file(['pgpfiles', 'key', 'RSA1.sec.gpg'])
     seckeypkt = list_pkts(seckey_d)[0]
     clrtxt = decrypt(encpkt, passphrase, sespkt, seckeypkt)
     self.assertEqual(msg, clrtxt)
Пример #12
0
 def testG01Decrypt1(self):
     """crypto.cipher: decrypt() v4 public (ElGamal) MDC CAST5 compressed"""
     # This message is known to have a compressed packet containing a literal
     # packet containing the text from cleartext.txt.
     enc_d = read_test_file(['pgpfiles', 'enc', 'pub.elg.cast.clrtxt.gpg'])
     key_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.gpg'])
     clr_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     keypkt = list_pkts(key_d)[3]  # first encryption subkey (known)
     passphrase = 'test'
     msg_d = decrypt(encpkt, passphrase, sespkt, keypkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #13
0
 def testH02EncryptPublicRSAAES256(self):
     """crypto.cipher: encrypt()/decrypt() RSA, AES256 w/ integrity"""
     key_d = read_test_file(['pgpfiles','key','RSA1.pub.gpg'])
     keypkt = list_pkts(key_d)[0] # use RSA for encrypting
     alg = SYM_AES256
     msg = "My secret message."
     passphrase = 'test'
     key = gen_random(_keysize(alg))
     sespkt = encrypt_public_session(keypkt, key, alg)
     encpkt = encrypt_integrity(alg, key, msg)
     seckey_d = read_test_file(['pgpfiles','key','RSA1.sec.gpg'])
     seckeypkt = list_pkts(seckey_d)[0]
     clrtxt = decrypt(encpkt, passphrase, sespkt, seckeypkt)
     self.assertEqual(msg, clrtxt)
Пример #14
0
 def testG02Decrypt2(self):
     """crypto.cipher: decrypt() v4 public (ElGamal) MDC AES256 compressed"""
     # This message is known to have a compressed packet containing a literal
     # packet containing the text from cleartext.txt.
     enc_d = read_test_file(['pgpfiles','enc','pub.elg.aes256.clrtxt.gpg'])
     key_d = read_test_file(['pgpfiles','key','DSAELG1.sec.gpg'])
     clr_d = read_test_file(['pgpfiles','cleartext.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     keypkt = list_pkts(key_d)[3] # first encryption subkey (known)
     passphrase = 'test'
     msg_d = decrypt(encpkt, passphrase, sespkt, keypkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #15
0
 def testG04Decrypt4(self):
     """crypto.cipher: decrypt() v3 public (RSA) 3DES compressed"""
     prefix = ['pgpfiles','interop','pgp6.5.3','RSA1']
     enc_d = read_test_file(prefix+['encrypted.cleartext.notepad.pgp6.5.3.RSA1.pgp'])
     key_d = read_test_file(prefix+['key.pgp6.5.3.RSA1.sec.asc'])
     clr_d = read_test_file(prefix+['cleartext.notepad.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     passphrase = 'test'
     # first (totally detached) armored block has [secret key pkt, uid pkt]
     arms = list_armored(key_d)
     keypkt = list_pkts(arms[0].data)[0]
     msg_d = decrypt(encpkt, passphrase, sespkt, keypkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)
Пример #16
0
 def testG04Decrypt4(self):
     """crypto.cipher: decrypt() v3 public (RSA) 3DES compressed"""
     prefix = ['pgpfiles', 'interop', 'pgp6.5.3', 'RSA1']
     enc_d = read_test_file(
         prefix + ['encrypted.cleartext.notepad.pgp6.5.3.RSA1.pgp'])
     key_d = read_test_file(prefix + ['key.pgp6.5.3.RSA1.sec.asc'])
     clr_d = read_test_file(prefix + ['cleartext.notepad.txt'])
     sespkt, encpkt = list_pkts(enc_d)
     passphrase = 'test'
     # first (totally detached) armored block has [secret key pkt, uid pkt]
     arms = list_armored(key_d)
     keypkt = list_pkts(arms[0].data)[0]
     msg_d = decrypt(encpkt, passphrase, sespkt, keypkt)
     compmsg = list_msgs(list_pkts(msg_d))[0]
     litpkt = list_pkts(compmsg.compressed.body.data)[0]
     self.assertEqual(clr_d, litpkt.body.data)