summaryrefslogtreecommitdiff
path: root/patches/gnutls/22_functional_s2k_with_GNU_dummy.diff
blob: 2d7e35d37082e9481963aad703fdebe08d78b3d3 (plain)
  1. diff -ruN gnutls26-2.4.1.orig/lib/opencdk/opencdk.h gnutls26-2.4.1/lib/opencdk/opencdk.h
  2. --- gnutls26-2.4.1.orig/lib/opencdk/opencdk.h 2008-06-30 16:45:51.000000000 -0400
  3. +++ gnutls26-2.4.1/lib/opencdk/opencdk.h 2008-08-21 19:23:44.000000000 -0400
  4. @@ -214,7 +214,11 @@
  5. enum cdk_s2k_type_t {
  6. CDK_S2K_SIMPLE = 0,
  7. CDK_S2K_SALTED = 1,
  8. - CDK_S2K_ITERSALTED = 3
  9. + CDK_S2K_ITERSALTED = 3,
  10. + CDK_S2K_GNU_EXT = 101
  11. + /* GNU S2K extensions: refer to DETAILS from GnuPG:
  12. + http://cvs.gnupg.org/cgi-bin/viewcvs.cgi/trunk/doc/DETAILS?root=GnuPG
  13. + */
  14. };
  15. diff -ruN gnutls26-2.4.1.orig/lib/opencdk/read-packet.c gnutls26-2.4.1/lib/opencdk/read-packet.c
  16. --- gnutls26-2.4.1.orig/lib/opencdk/read-packet.c 2008-06-30 16:45:51.000000000 -0400
  17. +++ gnutls26-2.4.1/lib/opencdk/read-packet.c 2008-08-21 19:30:09.000000000 -0400
  18. @@ -78,10 +78,35 @@
  19. }
  20. -static int
  21. +/* read about S2K at http://tools.ietf.org/html/rfc4880#section-3.7.1 */
  22. +static cdk_error_t
  23. read_s2k (cdk_stream_t inp, cdk_s2k_t s2k)
  24. {
  25. - return CDK_Not_Implemented;
  26. + size_t nread;
  27. +
  28. + s2k->mode = cdk_stream_getc (inp);
  29. + s2k->hash_algo = cdk_stream_getc (inp);
  30. + if (s2k->mode == CDK_S2K_SIMPLE)
  31. + return 0;
  32. + else if (s2k->mode == CDK_S2K_SALTED || s2k->mode == CDK_S2K_ITERSALTED)
  33. + {
  34. + if (stream_read (inp, s2k->salt, DIM (s2k->salt), &nread))
  35. + return CDK_Inv_Packet;
  36. + if (nread != DIM (s2k->salt))
  37. + return CDK_Inv_Packet;
  38. +
  39. + if (s2k->mode == CDK_S2K_ITERSALTED)
  40. + s2k->count = cdk_stream_getc (inp);
  41. + }
  42. + else if (s2k->mode == CDK_S2K_GNU_EXT)
  43. + {
  44. + /* GNU extensions to the S2K : read DETAILS from gnupg */
  45. + return 0;
  46. + }
  47. + else
  48. + return CDK_Not_Implemented;
  49. +
  50. + return 0;
  51. }
  52. @@ -194,6 +219,7 @@
  53. static cdk_error_t
  54. read_symkey_enc (cdk_stream_t inp, size_t pktlen, cdk_pkt_symkey_enc_t ske)
  55. {
  56. + cdk_error_t ret;
  57. cdk_s2k_t s2k;
  58. size_t minlen;
  59. size_t nread, nleft;
  60. @@ -213,7 +239,9 @@
  61. return CDK_Out_Of_Core;
  62. ske->cipher_algo = cdk_stream_getc (inp);
  63. - s2k->mode = cdk_stream_getc (inp);
  64. + ret = read_s2k(inp, s2k);
  65. + if (ret != 0)
  66. + return ret;
  67. switch (s2k->mode)
  68. {
  69. case CDK_S2K_SIMPLE : minlen = 0; break;
  70. @@ -225,18 +253,6 @@
  71. return CDK_Inv_Packet;
  72. }
  73. - s2k->hash_algo = cdk_stream_getc (inp);
  74. - if (s2k->mode == CDK_S2K_SALTED || s2k->mode == CDK_S2K_ITERSALTED)
  75. - {
  76. - if (stream_read (inp, s2k->salt, DIM (s2k->salt), &nread))
  77. - return CDK_Inv_Packet;
  78. - if (nread != DIM (s2k->salt))
  79. - return CDK_Inv_Packet;
  80. -
  81. - if (s2k->mode == CDK_S2K_ITERSALTED)
  82. - s2k->count = cdk_stream_getc (inp);
  83. - }
  84. -
  85. ske->seskeylen = pktlen - 4 - minlen;
  86. /* We check if there is an encrypted session key and if it fits into
  87. the buffer. The maximal key length is 256-bit. */
  88. @@ -421,14 +437,19 @@
  89. rc = read_s2k (inp, sk->protect.s2k);
  90. if (rc)
  91. return rc;
  92. - sk->protect.ivlen = gcry_cipher_get_algo_blklen (sk->protect.algo);
  93. - if (!sk->protect.ivlen)
  94. - return CDK_Inv_Packet;
  95. - rc = stream_read (inp, sk->protect.iv, sk->protect.ivlen, &nread);
  96. - if (rc)
  97. - return rc;
  98. - if (nread != sk->protect.ivlen)
  99. - return CDK_Inv_Packet;
  100. + /* refer to --export-secret-subkeys in gpg(1) */
  101. + if (sk->protect.s2k->mode == CDK_S2K_GNU_EXT)
  102. + sk->protect.ivlen = 0;
  103. + else {
  104. + sk->protect.ivlen = gcry_cipher_get_algo_blklen (sk->protect.algo);
  105. + if (!sk->protect.ivlen)
  106. + return CDK_Inv_Packet;
  107. + rc = stream_read (inp, sk->protect.iv, sk->protect.ivlen, &nread);
  108. + if (rc)
  109. + return rc;
  110. + if (nread != sk->protect.ivlen)
  111. + return CDK_Inv_Packet;
  112. + }
  113. }
  114. else
  115. sk->protect.algo = sk->s2k_usage;
  116. @@ -476,6 +497,22 @@
  117. return CDK_Out_Of_Core;
  118. if (stream_read (inp, sk->encdata, sk->enclen, &nread))
  119. return CDK_Inv_Packet;
  120. + /* Handle the GNU S2K extensions we know (just gnu-dummy right now): */
  121. + if (sk->protect.s2k->mode == CDK_S2K_GNU_EXT) {
  122. + unsigned char gnumode;
  123. + if ((sk->enclen < strlen("GNU") + 1) ||
  124. + (0 != memcmp("GNU", sk->encdata, strlen("GNU"))))
  125. + return CDK_Inv_Packet;
  126. + gnumode = sk->encdata[strlen("GNU")];
  127. + /* we only handle gnu-dummy (mode 1).
  128. + mode 2 should refer to external smart cards.
  129. + */
  130. + if (gnumode != 1)
  131. + return CDK_Inv_Packet;
  132. + /* gnu-dummy should have no more data */
  133. + if (sk->enclen != strlen("GNU") + 1)
  134. + return CDK_Inv_Packet;
  135. + }
  136. nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo);
  137. if (!nskey)
  138. return CDK_Inv_Algo;