You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
4.7 KiB

  1. From 14a6994ae89f54218c2c509c7e68323b7a9a2cbf Mon Sep 17 00:00:00 2001
  2. From: "djm@openbsd.org" <djm@openbsd.org>
  3. Date: Thu, 13 Sep 2018 05:06:51 +0000
  4. Subject: [PATCH 3/5] upstream: use only openssl-1.1.x API here too
  5. OpenBSD-Regress-ID: ae877064597c349954b1b443769723563cecbc8f
  6. ---
  7. regress/unittests/sshkey/test_sshkey.c | 104 +++++++++++++++++++++------------
  8. 1 file changed, 67 insertions(+), 37 deletions(-)
  9. diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c
  10. index 72367bde..a32d2884 100644
  11. --- a/regress/unittests/sshkey/test_sshkey.c
  12. +++ b/regress/unittests/sshkey/test_sshkey.c
  13. @@ -1,4 +1,5 @@
  14. /* $OpenBSD: test_sshkey.c,v 1.14 2018/07/13 02:13:19 djm Exp $ */
  15. +/* Incorporates changes from 1.16 */
  16. /*
  17. * Regress test for sshkey.h key management API
  18. *
  19. @@ -173,6 +174,61 @@ get_private(const char *n)
  20. return ret;
  21. }
  22. +static const BIGNUM *
  23. +rsa_n(struct sshkey *k)
  24. +{
  25. + const BIGNUM *n = NULL;
  26. +
  27. + ASSERT_PTR_NE(k, NULL);
  28. + ASSERT_PTR_NE(k->rsa, NULL);
  29. + RSA_get0_key(k->rsa, &n, NULL, NULL);
  30. + return n;
  31. +}
  32. +
  33. +static const BIGNUM *
  34. +rsa_e(struct sshkey *k)
  35. +{
  36. + const BIGNUM *e = NULL;
  37. +
  38. + ASSERT_PTR_NE(k, NULL);
  39. + ASSERT_PTR_NE(k->rsa, NULL);
  40. + RSA_get0_key(k->rsa, NULL, &e, NULL);
  41. + return e;
  42. +}
  43. +
  44. +static const BIGNUM *
  45. +rsa_p(struct sshkey *k)
  46. +{
  47. + const BIGNUM *p = NULL;
  48. +
  49. + ASSERT_PTR_NE(k, NULL);
  50. + ASSERT_PTR_NE(k->rsa, NULL);
  51. + RSA_get0_factors(k->rsa, &p, NULL);
  52. + return p;
  53. +}
  54. +
  55. +static const BIGNUM *
  56. +dsa_g(struct sshkey *k)
  57. +{
  58. + const BIGNUM *g = NULL;
  59. +
  60. + ASSERT_PTR_NE(k, NULL);
  61. + ASSERT_PTR_NE(k->dsa, NULL);
  62. + DSA_get0_pqg(k->dsa, NULL, NULL, &g);
  63. + return g;
  64. +}
  65. +
  66. +static const BIGNUM *
  67. +dsa_priv_key(struct sshkey *k)
  68. +{
  69. + const BIGNUM *priv_key = NULL;
  70. +
  71. + ASSERT_PTR_NE(k, NULL);
  72. + ASSERT_PTR_NE(k->dsa, NULL);
  73. + DSA_get0_key(k->dsa, NULL, &priv_key);
  74. + return priv_key;
  75. +}
  76. +
  77. void
  78. sshkey_tests(void)
  79. {
  80. @@ -197,9 +253,6 @@ sshkey_tests(void)
  81. k1 = sshkey_new(KEY_RSA);
  82. ASSERT_PTR_NE(k1, NULL);
  83. ASSERT_PTR_NE(k1->rsa, NULL);
  84. - ASSERT_PTR_NE(k1->rsa->n, NULL);
  85. - ASSERT_PTR_NE(k1->rsa->e, NULL);
  86. - ASSERT_PTR_EQ(k1->rsa->p, NULL);
  87. sshkey_free(k1);
  88. TEST_DONE();
  89. @@ -207,8 +260,6 @@ sshkey_tests(void)
  90. k1 = sshkey_new(KEY_DSA);
  91. ASSERT_PTR_NE(k1, NULL);
  92. ASSERT_PTR_NE(k1->dsa, NULL);
  93. - ASSERT_PTR_NE(k1->dsa->g, NULL);
  94. - ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
  95. sshkey_free(k1);
  96. TEST_DONE();
  97. @@ -230,27 +281,6 @@ sshkey_tests(void)
  98. sshkey_free(k1);
  99. TEST_DONE();
  100. - TEST_START("new_private KEY_RSA");
  101. - k1 = sshkey_new_private(KEY_RSA);
  102. - ASSERT_PTR_NE(k1, NULL);
  103. - ASSERT_PTR_NE(k1->rsa, NULL);
  104. - ASSERT_PTR_NE(k1->rsa->n, NULL);
  105. - ASSERT_PTR_NE(k1->rsa->e, NULL);
  106. - ASSERT_PTR_NE(k1->rsa->p, NULL);
  107. - ASSERT_INT_EQ(sshkey_add_private(k1), 0);
  108. - sshkey_free(k1);
  109. - TEST_DONE();
  110. -
  111. - TEST_START("new_private KEY_DSA");
  112. - k1 = sshkey_new_private(KEY_DSA);
  113. - ASSERT_PTR_NE(k1, NULL);
  114. - ASSERT_PTR_NE(k1->dsa, NULL);
  115. - ASSERT_PTR_NE(k1->dsa->g, NULL);
  116. - ASSERT_PTR_NE(k1->dsa->priv_key, NULL);
  117. - ASSERT_INT_EQ(sshkey_add_private(k1), 0);
  118. - sshkey_free(k1);
  119. - TEST_DONE();
  120. -
  121. TEST_START("generate KEY_RSA too small modulus");
  122. ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 128, &k1),
  123. SSH_ERR_KEY_LENGTH);
  124. @@ -285,18 +315,18 @@ sshkey_tests(void)
  125. ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &kr), 0);
  126. ASSERT_PTR_NE(kr, NULL);
  127. ASSERT_PTR_NE(kr->rsa, NULL);
  128. - ASSERT_PTR_NE(kr->rsa->n, NULL);
  129. - ASSERT_PTR_NE(kr->rsa->e, NULL);
  130. - ASSERT_PTR_NE(kr->rsa->p, NULL);
  131. - ASSERT_INT_EQ(BN_num_bits(kr->rsa->n), 1024);
  132. + ASSERT_PTR_NE(rsa_n(kr), NULL);
  133. + ASSERT_PTR_NE(rsa_e(kr), NULL);
  134. + ASSERT_PTR_NE(rsa_p(kr), NULL);
  135. + ASSERT_INT_EQ(BN_num_bits(rsa_n(kr)), 1024);
  136. TEST_DONE();
  137. TEST_START("generate KEY_DSA");
  138. ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0);
  139. ASSERT_PTR_NE(kd, NULL);
  140. ASSERT_PTR_NE(kd->dsa, NULL);
  141. - ASSERT_PTR_NE(kd->dsa->g, NULL);
  142. - ASSERT_PTR_NE(kd->dsa->priv_key, NULL);
  143. + ASSERT_PTR_NE(dsa_g(kd), NULL);
  144. + ASSERT_PTR_NE(dsa_priv_key(kd), NULL);
  145. TEST_DONE();
  146. #ifdef OPENSSL_HAS_ECC
  147. @@ -323,9 +353,9 @@ sshkey_tests(void)
  148. ASSERT_PTR_NE(kr, k1);
  149. ASSERT_INT_EQ(k1->type, KEY_RSA);
  150. ASSERT_PTR_NE(k1->rsa, NULL);
  151. - ASSERT_PTR_NE(k1->rsa->n, NULL);
  152. - ASSERT_PTR_NE(k1->rsa->e, NULL);
  153. - ASSERT_PTR_EQ(k1->rsa->p, NULL);
  154. + ASSERT_PTR_NE(rsa_n(k1), NULL);
  155. + ASSERT_PTR_NE(rsa_e(k1), NULL);
  156. + ASSERT_PTR_EQ(rsa_p(k1), NULL);
  157. TEST_DONE();
  158. TEST_START("equal KEY_RSA/demoted KEY_RSA");
  159. @@ -339,8 +369,8 @@ sshkey_tests(void)
  160. ASSERT_PTR_NE(kd, k1);
  161. ASSERT_INT_EQ(k1->type, KEY_DSA);
  162. ASSERT_PTR_NE(k1->dsa, NULL);
  163. - ASSERT_PTR_NE(k1->dsa->g, NULL);
  164. - ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
  165. + ASSERT_PTR_NE(dsa_g(k1), NULL);
  166. + ASSERT_PTR_EQ(dsa_priv_key(k1), NULL);
  167. TEST_DONE();
  168. TEST_START("equal KEY_DSA/demoted KEY_DSA");
  169. --
  170. 2.16.4