コード例 #1
0
 def testE02SignTextKeyID(self):
     "sign_str()/verify_str() text (0x01) using key ID"
     lit_d = read_test_file(['pgpfiles','cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc'])
     signed = sign_str(0x01, seckey_d, target=lit_d,
                       use_key=(None, '0CFC2B6DCC079DF3'),
                       passphrase='test')
     verified = verify_str(signed, pubkey_d)
     self.assertEqual(lit_d, list_pkts(verified)[0].body.data)
コード例 #2
0
 def testE01SignBinaryAsMsgViaUID(self):
     "sign_str()/verify_str() binary (0x00) using user ID"
     lit_d = read_test_file(['pgpfiles','cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc'])
     signed = sign_str(0x00, seckey_d, target=lit_d,
                       use_userid=(None,'Tester'),
                       passphrase='test')
     verified = verify_str(signed, pubkey_d)
     self.assertEqual(lit_d, list_pkts(verified)[0].body.data)
コード例 #3
0
 def testE02SignTextKeyID(self):
     "sign_str()/verify_str() text (0x01) using key ID"
     lit_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc'])
     signed = sign_str(0x01,
                       seckey_d,
                       target=lit_d,
                       use_key=(None, '0CFC2B6DCC079DF3'),
                       passphrase='test')
     verified = verify_str(signed, pubkey_d)
     self.assertEqual(lit_d, list_pkts(verified)[0].body.data)
コード例 #4
0
 def testE01SignBinaryAsMsgViaUID(self):
     "sign_str()/verify_str() binary (0x00) using user ID"
     lit_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc'])
     signed = sign_str(0x00,
                       seckey_d,
                       target=lit_d,
                       use_userid=(None, 'Tester'),
                       passphrase='test')
     verified = verify_str(signed, pubkey_d)
     self.assertEqual(lit_d, list_pkts(verified)[0].body.data)
コード例 #5
0
 def testE08SignSubkeyBadSigner(self):
     "sign_str() subkey direct (0x1F) target not found"
     seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc'])
     try:
         sigpkt = sign_str(0x1F, seckey_d, target=pubkey_d,
                           use_key=(None, "0CFC2B6DCC079xxx"), # munged
                           target_key=(None,"CB7D6980A1F2BEF6"),
                           passphrase='test')
     except PGPError: # signing key is specified so it must be used
         pass
     else:
         self.fail()
コード例 #6
0
 def testE03SignDetached(self):
     "sign_str()/verify_str() detached binary (0x00) using key ID"
     lit_d = read_test_file(['pgpfiles','cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc'])
     sigtype = 0x01
     keyid_d = "0CFC2B6DCC079DF3"
     passphrase = "test"
     sigpkt = sign_str(0x01, seckey_d, target=lit_d,
                       use_key=(None, '0CFC2B6DCC079DF3'),
                       passphrase='test',
                       detach=True)
     verified = verify_str(sigpkt, pubkey_d, detached=lit_d)
     self.assertEqual(lit_d, verified)
コード例 #7
0
 def testE05SignBinaryAsStringUsingUID(self):
     "sign_str()/verify_str() check literal data options"
     lit_d = read_test_file(['pgpfiles','cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc'])
     signed = sign_str(0x00, seckey_d, target=lit_d,
                       use_userid=(None,'Tester'),
                       passphrase='test',
                       lit_filename='testfilename',
                       lit_modified=100)
     verified = verify_str(signed, pubkey_d) # verified strips sigs..
     literal_body = list_as_signed(verified)[0].literals[0].body
     self.assertEqual('b', literal_body.format)
     self.assertEqual(lit_d, literal_body.data)
     self.assertEqual('testfilename', literal_body.filename)
     self.assertEqual(100, literal_body.modified)
コード例 #8
0
 def testE08SignSubkeyBadSigner(self):
     "sign_str() subkey direct (0x1F) target not found"
     seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc'])
     try:
         sigpkt = sign_str(
             0x1F,
             seckey_d,
             target=pubkey_d,
             use_key=(None, "0CFC2B6DCC079xxx"),  # munged
             target_key=(None, "CB7D6980A1F2BEF6"),
             passphrase='test')
     except PGPError:  # signing key is specified so it must be used
         pass
     else:
         self.fail()
コード例 #9
0
 def testE03SignDetached(self):
     "sign_str()/verify_str() detached binary (0x00) using key ID"
     lit_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc'])
     sigtype = 0x01
     keyid_d = "0CFC2B6DCC079DF3"
     passphrase = "test"
     sigpkt = sign_str(0x01,
                       seckey_d,
                       target=lit_d,
                       use_key=(None, '0CFC2B6DCC079DF3'),
                       passphrase='test',
                       detach=True)
     verified = verify_str(sigpkt, pubkey_d, detached=lit_d)
     self.assertEqual(lit_d, verified)
コード例 #10
0
 def testE04SignSubkey(self):
     "sign_str()/verify_str() subkey direct (0x1F) w/ lots of subpackets"
     seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc'])
     keyid = "0CFC2B6DCC079DF3"
     opts = {
         'use_key': (None, keyid),
         'passphrase': "test",
         'target': pubkey_d,
         'target_key': (None, "CB7D6980A1F2BEF6"),
         'sig_signerid': keyid,
         'sig_created': 100,
         'sig_expires': 4294967295,
         'sig_keyexpires': 4294967200,
         'sig_revoker':
         (0x80, 1, "AB06532F70BD5CD68978D0181AC964878A17BAC6"),
         #'sig_note':"n1@test::v1 ,, n2@test:: v2,,n3@test:: v3 ",
         'sig_note': [("n1@test", "v1"), ("n2@test", "v2"),
                      ("n3@test", "v3")],
         'sig_policyurl': "http://policy.com"
     }
     #keymsg = sign_str(0x1F, seckey_d, **opts)
     signed = sign_str(0x1F, seckey_d, **opts)
     keymsg = list_as_signed(signed)[0]
     sigpkt = keymsg._b_subkeys['CB7D6980A1F2BEF6'].local_direct[0]
     # the subpkt order is determined by their order of appendage in
     # sign_str() which isn't important, it's just convenient for testing
     h = sigpkt.body.hashed_subpkts
     [signerid, created, sig_exp, key_exp, n1, n2, n3, url, revoker] = h
     self.assertEqual((0x10, keyid), (signerid.type, signerid.value))
     self.assertEqual((0x02, 100), (created.type, created.value))
     self.assertEqual((0x03, 4294967295), (sig_exp.type, sig_exp.value))
     self.assertEqual((0x09, 4294967200), (key_exp.type, key_exp.value))
     self.assertEqual((0x14, "n1@test", "v1"),
                      (n1.type, n1.value[1], n1.value[2]))
     self.assertEqual((0x14, "n2@test", "v2"),
                      (n2.type, n2.value[1], n2.value[2]))
     self.assertEqual((0x14, "n3@test", "v3"),
                      (n3.type, n3.value[1], n3.value[2]))
     self.assertEqual((0x1A, "http://policy.com"), (url.type, url.value))
     self.assertEqual(
         (0x0C, (128, 1, "AB06532F70BD5CD68978D0181AC964878A17BAC6")),
         (revoker.type, revoker.value))
     # verify new sig (everything in signed is verified against pubkey_d)
     verified = verify_str(signed, pubkey_d)
     self.assertEqual(verified, signed)
コード例 #11
0
 def testE05SignBinaryAsStringUsingUID(self):
     "sign_str()/verify_str() check literal data options"
     lit_d = read_test_file(['pgpfiles', 'cleartext.txt'])
     seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc'])
     signed = sign_str(0x00,
                       seckey_d,
                       target=lit_d,
                       use_userid=(None, 'Tester'),
                       passphrase='test',
                       lit_filename='testfilename',
                       lit_modified=100)
     verified = verify_str(signed, pubkey_d)  # verified strips sigs..
     literal_body = list_as_signed(verified)[0].literals[0].body
     self.assertEqual('b', literal_body.format)
     self.assertEqual(lit_d, literal_body.data)
     self.assertEqual('testfilename', literal_body.filename)
     self.assertEqual(100, literal_body.modified)
コード例 #12
0
 def testE04SignSubkey(self):
     "sign_str()/verify_str() subkey direct (0x1F) w/ lots of subpackets"
     seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc'])
     pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc'])
     keyid = "0CFC2B6DCC079DF3"
     opts = {'use_key':(None, keyid),
             'passphrase':"test",
             'target':pubkey_d,
             'target_key':(None,"CB7D6980A1F2BEF6"),
             'sig_signerid':keyid,
             'sig_created':100,
             'sig_expires':4294967295,
             'sig_keyexpires':4294967200,
             'sig_revoker':(0x80,1,"AB06532F70BD5CD68978D0181AC964878A17BAC6"),
             #'sig_note':"n1@test::v1 ,, n2@test:: v2,,n3@test:: v3 ",
             'sig_note':[("n1@test","v1"),("n2@test","v2"),("n3@test","v3")],
             'sig_policyurl':"http://policy.com"}
     #keymsg = sign_str(0x1F, seckey_d, **opts)
     signed = sign_str(0x1F, seckey_d, **opts)
     keymsg = list_as_signed(signed)[0]
     sigpkt = keymsg._b_subkeys['CB7D6980A1F2BEF6'].local_direct[0]
     # the subpkt order is determined by their order of appendage in
     # sign_str() which isn't important, it's just convenient for testing
     h = sigpkt.body.hashed_subpkts 
     [signerid, created, sig_exp, key_exp, n1, n2, n3, url, revoker] = h
     self.assertEqual((0x10, keyid), (signerid.type, signerid.value))
     self.assertEqual((0x02, 100), (created.type, created.value))
     self.assertEqual((0x03, 4294967295), (sig_exp.type, sig_exp.value))
     self.assertEqual((0x09, 4294967200), (key_exp.type, key_exp.value))
     self.assertEqual((0x14, "n1@test", "v1"), (n1.type, n1.value[1], n1.value[2]))
     self.assertEqual((0x14, "n2@test", "v2"), (n2.type, n2.value[1], n2.value[2]))
     self.assertEqual((0x14, "n3@test", "v3"), (n3.type, n3.value[1], n3.value[2]))
     self.assertEqual((0x1A, "http://policy.com"), (url.type, url.value))
     self.assertEqual((0x0C, (128, 1, "AB06532F70BD5CD68978D0181AC964878A17BAC6")), (revoker.type, revoker.value))
     # verify new sig (everything in signed is verified against pubkey_d)
     verified = verify_str(signed, pubkey_d)
     self.assertEqual(verified, signed)