Skip to content

Commit 8e03632

Browse files
author
lukpueh
authored
Merge pull request #264 from lukpueh/fix-gpg-dsa-test
Change DSA test key format + adopt test code
2 parents a7308f0 + 15028a4 commit 8e03632

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

requirements-pinned.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cffi==1.14.1 # via cryptography, pynacl
22
colorama==0.4.3
3-
cryptography==2.9.2
3+
cryptography==3.0
44
enum34==1.1.6 ; python_version < "3" # via cryptography
55
ipaddress==1.0.23 ; python_version < "3" # via cryptography
66
pycparser==2.20 # via cffi
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MIIDRjCCAjkGByqGSM44BAEwggIsAoIBAQD8oyds14wg48c64jmGdARgOfXZD0Hj
3+
7em8mflAANFFaTUiZx+6SB0i4KmzHmldGY2l5i9P+0213GQHbQ8tfQPOlT/HhGpt
4+
ThehC/Hc0XFn96/3YbWfohgOf80spSfAPFDHhmW1U5vytFZIttI/MfN5meantOCH
5+
bdrX7Hg7jux+H7FHM+dLawsQXL3Fp96OCUZX8hRs5Doxd1gcsCKk4s5meKM2Slbg
6+
IJBVmm39gdkco7fGr9T8/Gb9iDOdIXBiRi9Rxckdbsz6+zIGW+aOa5Hsg3xZpRuu
7+
vsoccP04kcm7tn99kg+RU/xNLKA/iKJ7cN8WhHCfma0YcHGJsBVEGyv7AiEAhHee
8+
6uAjjXqaAwpjm/AaD571F6XZUFmcGaTlT7vyMhkCggEAf3JSrhgkuvK+X8j0MaGX
9+
hoOjjUoizCvNwBzNH17uR6lkqldjmmGM+xsQcHtNCf8RpEjoO6cBI1c/LUmlmfUx
10+
OnRGPluzyj1hcqAPArAQZc4xJQHheX97V+YGlHxEvYOf3o1DJp8ft0r2zt9Nt/q/
11+
CyNX7QnVY4Gsdp71qK8bRFDgyItk7hyrn63rMbe+Yge34XAIozp2E4MfcKEj1ZJ5
12+
3LwiOPRu6qgJd5W3gF8bg37zuOgHFk4Yb66fo/9RAhMJa/VAQOrFRaaltHyRDmz3
13+
4wbh9Gcj8UsCzZ4LD/KlbDsmBIaUMasyY9Yb9QaL7jbIgMe/LHRtyuXQ17L/8kTv
14+
QwOCAQUAAoIBAC3VCyKSRBREWB+aC32Nf4i1c/xFH15yB8MkaUIywi4XG1CPaEKu
15+
m6vFb+TlhqIghhiLSCe3q6jHv/SkrJqoDINUILGvukq08bHA74lEN5A6n0xW6+8D
16+
eASpmSXJoVO4oWwVYvKXdVrqog+gKrMqpTZuBStrqpqTQ1bU9fwhh4UBjdErLI5t
17+
YF0q+zbLBqnM7Z6h9fgnmNY13iZO8OtZWQxKSy/fI2mjb5VhSATHqllmupWXQEui
18+
0saIGVkRLeUt5LbU8eLIpZ3arbCKWayDNBGPFaoBWT6FECSQXqbYhMOlRa9v3QPI
19+
0rVNodNecQ73WitHdbt4xQso0eL7SEFtyUE=
20+
-----END PUBLIC KEY-----

tests/test_gpg.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -655,31 +655,31 @@ def tearDownClass(self):
655655
def test_export_pubkey(self):
656656
""" export a public key and make sure the parameters are the right ones:
657657
658-
since there's very little we can do to check rsa key parameters are right
659-
we pre-exported the public key to an ssh key, which we can load with
660-
cryptography for the sake of comparison """
658+
since there's very little we can do to check key parameters are right
659+
we pre-exported the public key to an x.509 SubjectPublicKeyInfo key,
660+
which we can load with cryptography for the sake of comparison """
661661

662662
# export our gpg key, using our functions
663663
key_data = export_pubkey(self.default_keyid, homedir=self.gnupg_home)
664664
our_exported_key = dsa_create_pubkey(key_data)
665665

666-
# load the equivalent ssh key, and make sure that we get the same RSA key
667-
# parameters
668-
ssh_key_basename = "{}.ssh".format(self.default_keyid)
669-
ssh_key_path = os.path.join(self.gnupg_home, ssh_key_basename)
670-
with open(ssh_key_path, "rb") as fp:
666+
# load same key, pre-exported with 3rd-party tooling
667+
pem_key_basename = "{}.pem".format(self.default_keyid)
668+
pem_key_path = os.path.join(self.gnupg_home, pem_key_basename)
669+
with open(pem_key_path, "rb") as fp:
671670
keydata = fp.read()
672671

673-
ssh_key = serialization.load_ssh_public_key(keydata,
672+
pem_key = serialization.load_pem_public_key(keydata,
674673
backends.default_backend())
675674

676-
self.assertEqual(ssh_key.public_numbers().y,
675+
# make sure keys match
676+
self.assertEqual(pem_key.public_numbers().y,
677677
our_exported_key.public_numbers().y)
678-
self.assertEqual(ssh_key.public_numbers().parameter_numbers.g,
678+
self.assertEqual(pem_key.public_numbers().parameter_numbers.g,
679679
our_exported_key.public_numbers().parameter_numbers.g)
680-
self.assertEqual(ssh_key.public_numbers().parameter_numbers.q,
680+
self.assertEqual(pem_key.public_numbers().parameter_numbers.q,
681681
our_exported_key.public_numbers().parameter_numbers.q)
682-
self.assertEqual(ssh_key.public_numbers().parameter_numbers.p,
682+
self.assertEqual(pem_key.public_numbers().parameter_numbers.p,
683683
our_exported_key.public_numbers().parameter_numbers.p)
684684

685685
def test_gpg_sign_and_verify_object_with_default_key(self):

0 commit comments

Comments
 (0)