@annadata/capacitor-mqtt-quic 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (656) hide show
  1. package/AnnadataCapacitorMqttQuic.podspec +2 -1
  2. package/README.md +121 -12
  3. package/android/NGTCP2_BUILD_INSTRUCTIONS.md +65 -44
  4. package/android/build-openssl.sh +1 -1
  5. package/android/install/nghttp3-android/arm64-v8a/include/nghttp3/nghttp3.h +3295 -0
  6. package/android/install/nghttp3-android/arm64-v8a/include/nghttp3/version.h +46 -0
  7. package/android/install/nghttp3-android/arm64-v8a/lib/cmake/nghttp3/nghttp3Config.cmake +3 -0
  8. package/android/install/nghttp3-android/arm64-v8a/lib/cmake/nghttp3/nghttp3ConfigVersion.cmake +65 -0
  9. package/android/install/nghttp3-android/arm64-v8a/lib/cmake/nghttp3/nghttp3Targets-release.cmake +29 -0
  10. package/android/install/nghttp3-android/arm64-v8a/lib/cmake/nghttp3/nghttp3Targets.cmake +114 -0
  11. package/android/install/nghttp3-android/arm64-v8a/lib/libnghttp3.a +0 -0
  12. package/android/install/nghttp3-android/arm64-v8a/lib/libnghttp3.so +0 -0
  13. package/android/install/nghttp3-android/arm64-v8a/lib/pkgconfig/libnghttp3.pc +34 -0
  14. package/android/install/nghttp3-android/arm64-v8a/share/doc/nghttp3/README.rst +75 -0
  15. package/android/install/nghttp3-android/armeabi-v7a/include/nghttp3/nghttp3.h +3295 -0
  16. package/android/install/nghttp3-android/armeabi-v7a/include/nghttp3/version.h +46 -0
  17. package/android/install/nghttp3-android/armeabi-v7a/lib/cmake/nghttp3/nghttp3Config.cmake +3 -0
  18. package/android/install/nghttp3-android/armeabi-v7a/lib/cmake/nghttp3/nghttp3ConfigVersion.cmake +65 -0
  19. package/android/install/nghttp3-android/armeabi-v7a/lib/cmake/nghttp3/nghttp3Targets-release.cmake +29 -0
  20. package/android/install/nghttp3-android/armeabi-v7a/lib/cmake/nghttp3/nghttp3Targets.cmake +114 -0
  21. package/android/install/nghttp3-android/armeabi-v7a/lib/libnghttp3.a +0 -0
  22. package/android/install/nghttp3-android/armeabi-v7a/lib/libnghttp3.so +0 -0
  23. package/android/install/nghttp3-android/armeabi-v7a/lib/pkgconfig/libnghttp3.pc +34 -0
  24. package/android/install/nghttp3-android/armeabi-v7a/share/doc/nghttp3/README.rst +75 -0
  25. package/android/install/nghttp3-android/x86_64/include/nghttp3/nghttp3.h +3295 -0
  26. package/android/install/nghttp3-android/x86_64/include/nghttp3/version.h +46 -0
  27. package/android/install/nghttp3-android/x86_64/lib/cmake/nghttp3/nghttp3Config.cmake +3 -0
  28. package/android/install/nghttp3-android/x86_64/lib/cmake/nghttp3/nghttp3ConfigVersion.cmake +65 -0
  29. package/android/install/nghttp3-android/x86_64/lib/cmake/nghttp3/nghttp3Targets-release.cmake +29 -0
  30. package/android/install/nghttp3-android/x86_64/lib/cmake/nghttp3/nghttp3Targets.cmake +114 -0
  31. package/android/install/nghttp3-android/x86_64/lib/libnghttp3.a +0 -0
  32. package/android/install/nghttp3-android/x86_64/lib/libnghttp3.so +0 -0
  33. package/android/install/nghttp3-android/x86_64/lib/pkgconfig/libnghttp3.pc +34 -0
  34. package/android/install/nghttp3-android/x86_64/share/doc/nghttp3/README.rst +75 -0
  35. package/android/install/ngtcp2-android/arm64-v8a/include/ngtcp2/ngtcp2.h +6254 -0
  36. package/android/install/ngtcp2-android/arm64-v8a/include/ngtcp2/ngtcp2_crypto.h +1037 -0
  37. package/android/install/ngtcp2-android/arm64-v8a/include/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  38. package/android/install/ngtcp2-android/arm64-v8a/include/ngtcp2/version.h +51 -0
  39. package/android/install/ngtcp2-android/arm64-v8a/lib/cmake/ngtcp2/ngtcp2Config.cmake +6 -0
  40. package/android/install/ngtcp2-android/arm64-v8a/lib/cmake/ngtcp2/ngtcp2ConfigVersion.cmake +65 -0
  41. package/android/install/ngtcp2-android/arm64-v8a/lib/cmake/ngtcp2/ngtcp2Targets-release.cmake +29 -0
  42. package/android/install/ngtcp2-android/arm64-v8a/lib/cmake/ngtcp2/ngtcp2Targets.cmake +114 -0
  43. package/android/install/ngtcp2-android/arm64-v8a/lib/libngtcp2.a +0 -0
  44. package/android/install/ngtcp2-android/arm64-v8a/lib/libngtcp2.so +0 -0
  45. package/android/install/ngtcp2-android/arm64-v8a/lib/libngtcp2_crypto_wolfssl.a +0 -0
  46. package/android/install/ngtcp2-android/arm64-v8a/lib/libngtcp2_crypto_wolfssl.so +0 -0
  47. package/android/install/ngtcp2-android/arm64-v8a/lib/pkgconfig/libngtcp2.pc +33 -0
  48. package/android/install/ngtcp2-android/arm64-v8a/lib/pkgconfig/libngtcp2_crypto_wolfssl.pc +34 -0
  49. package/android/install/ngtcp2-android/arm64-v8a/share/doc/ngtcp2/README.rst +385 -0
  50. package/android/install/ngtcp2-android/armeabi-v7a/include/ngtcp2/ngtcp2.h +6254 -0
  51. package/android/install/ngtcp2-android/armeabi-v7a/include/ngtcp2/ngtcp2_crypto.h +1037 -0
  52. package/android/install/ngtcp2-android/armeabi-v7a/include/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  53. package/android/install/ngtcp2-android/armeabi-v7a/include/ngtcp2/version.h +51 -0
  54. package/android/install/ngtcp2-android/armeabi-v7a/lib/cmake/ngtcp2/ngtcp2Config.cmake +6 -0
  55. package/android/install/ngtcp2-android/armeabi-v7a/lib/cmake/ngtcp2/ngtcp2ConfigVersion.cmake +65 -0
  56. package/android/install/ngtcp2-android/armeabi-v7a/lib/cmake/ngtcp2/ngtcp2Targets-release.cmake +29 -0
  57. package/android/install/ngtcp2-android/armeabi-v7a/lib/cmake/ngtcp2/ngtcp2Targets.cmake +114 -0
  58. package/android/install/ngtcp2-android/armeabi-v7a/lib/libngtcp2.a +0 -0
  59. package/android/install/ngtcp2-android/armeabi-v7a/lib/libngtcp2.so +0 -0
  60. package/android/install/ngtcp2-android/armeabi-v7a/lib/libngtcp2_crypto_wolfssl.a +0 -0
  61. package/android/install/ngtcp2-android/armeabi-v7a/lib/libngtcp2_crypto_wolfssl.so +0 -0
  62. package/android/install/ngtcp2-android/armeabi-v7a/lib/pkgconfig/libngtcp2.pc +33 -0
  63. package/android/install/ngtcp2-android/armeabi-v7a/lib/pkgconfig/libngtcp2_crypto_wolfssl.pc +34 -0
  64. package/android/install/ngtcp2-android/armeabi-v7a/share/doc/ngtcp2/README.rst +385 -0
  65. package/android/install/ngtcp2-android/x86_64/include/ngtcp2/ngtcp2.h +6254 -0
  66. package/android/install/ngtcp2-android/x86_64/include/ngtcp2/ngtcp2_crypto.h +1037 -0
  67. package/android/install/ngtcp2-android/x86_64/include/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  68. package/android/install/ngtcp2-android/x86_64/include/ngtcp2/version.h +51 -0
  69. package/android/install/ngtcp2-android/x86_64/lib/cmake/ngtcp2/ngtcp2Config.cmake +6 -0
  70. package/android/install/ngtcp2-android/x86_64/lib/cmake/ngtcp2/ngtcp2ConfigVersion.cmake +65 -0
  71. package/android/install/ngtcp2-android/x86_64/lib/cmake/ngtcp2/ngtcp2Targets-release.cmake +29 -0
  72. package/android/install/ngtcp2-android/x86_64/lib/cmake/ngtcp2/ngtcp2Targets.cmake +114 -0
  73. package/android/install/ngtcp2-android/x86_64/lib/libngtcp2.a +0 -0
  74. package/android/install/ngtcp2-android/x86_64/lib/libngtcp2.so +0 -0
  75. package/android/install/ngtcp2-android/x86_64/lib/libngtcp2_crypto_wolfssl.a +0 -0
  76. package/android/install/ngtcp2-android/x86_64/lib/libngtcp2_crypto_wolfssl.so +0 -0
  77. package/android/install/ngtcp2-android/x86_64/lib/pkgconfig/libngtcp2.pc +33 -0
  78. package/android/install/ngtcp2-android/x86_64/lib/pkgconfig/libngtcp2_crypto_wolfssl.pc +34 -0
  79. package/android/install/ngtcp2-android/x86_64/share/doc/ngtcp2/README.rst +385 -0
  80. package/android/install/wolfssl-android/arm64-v8a/bin/wolfssl-config +117 -0
  81. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/callbacks.h +93 -0
  82. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/certs_test.h +7073 -0
  83. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/certs_test_sm.h +2913 -0
  84. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/crl.h +58 -0
  85. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/error-ssl.h +280 -0
  86. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/ocsp.h +191 -0
  87. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/aes.h +117 -0
  88. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/asn1.h +315 -0
  89. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/asn1t.h +30 -0
  90. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/bio.h +237 -0
  91. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/bn.h +332 -0
  92. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/buffer.h +57 -0
  93. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/camellia.h +27 -0
  94. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/cmac.h +66 -0
  95. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/cms.h +26 -0
  96. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/compat_types.h +70 -0
  97. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/conf.h +117 -0
  98. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/crypto.h +171 -0
  99. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/des.h +124 -0
  100. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/dh.h +144 -0
  101. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/dsa.h +164 -0
  102. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ec.h +525 -0
  103. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ec25519.h +46 -0
  104. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ec448.h +46 -0
  105. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ecdh.h +49 -0
  106. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ecdsa.h +87 -0
  107. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ed25519.h +49 -0
  108. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ed448.h +49 -0
  109. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/engine.h +9 -0
  110. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/err.h +84 -0
  111. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/evp.h +1540 -0
  112. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/fips_rand.h +125 -0
  113. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/hmac.h +98 -0
  114. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/kdf.h +45 -0
  115. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/lhash.h +64 -0
  116. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/md4.h +66 -0
  117. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/md5.h +108 -0
  118. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/modes.h +45 -0
  119. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/obj_mac.h +92 -0
  120. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/objects.h +86 -0
  121. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ocsp.h +108 -0
  122. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/opensslconf.h +8 -0
  123. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/opensslv.h +78 -0
  124. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ossl_typ.h +32 -0
  125. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/pem.h +301 -0
  126. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/pkcs12.h +57 -0
  127. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/pkcs7.h +110 -0
  128. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/rand.h +38 -0
  129. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/rc4.h +64 -0
  130. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ripemd.h +58 -0
  131. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/rsa.h +291 -0
  132. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/safestack.h +40 -0
  133. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/sha.h +331 -0
  134. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/sha3.h +158 -0
  135. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/srp.h +33 -0
  136. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ssl.h +1923 -0
  137. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ssl23.h +1 -0
  138. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/stack.h +61 -0
  139. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/tls1.h +64 -0
  140. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/txt_db.h +60 -0
  141. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/ui.h +2 -0
  142. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/x509.h +227 -0
  143. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/x509_vfy.h +50 -0
  144. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/openssl/x509v3.h +237 -0
  145. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/options.h +273 -0
  146. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/quic.h +310 -0
  147. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/sniffer.h +359 -0
  148. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/sniffer_error.h +151 -0
  149. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/ssl.h +6300 -0
  150. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/test.h +4989 -0
  151. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/version.h +40 -0
  152. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/aes.h +1074 -0
  153. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/arc4.h +69 -0
  154. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ascon.h +109 -0
  155. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/asn.h +2855 -0
  156. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/asn_public.h +1009 -0
  157. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/blake2-impl.h +155 -0
  158. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/blake2-int.h +174 -0
  159. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/blake2.h +108 -0
  160. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/camellia.h +116 -0
  161. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/chacha.h +133 -0
  162. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/chacha20_poly1305.h +157 -0
  163. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/cmac.h +168 -0
  164. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/coding.h +107 -0
  165. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/compress.h +60 -0
  166. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/cpuid.h +153 -0
  167. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/cryptocb.h +770 -0
  168. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/curve25519.h +225 -0
  169. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/curve448.h +151 -0
  170. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/des3.h +167 -0
  171. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/dh.h +210 -0
  172. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/dilithium.h +1051 -0
  173. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/dsa.h +121 -0
  174. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ecc.h +1074 -0
  175. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/eccsi.h +176 -0
  176. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ed25519.h +239 -0
  177. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ed448.h +214 -0
  178. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/error-crypt.h +368 -0
  179. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ext_lms.h +62 -0
  180. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ext_mlkem.h +74 -0
  181. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ext_xmss.h +53 -0
  182. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/falcon.h +180 -0
  183. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/fe_448.h +122 -0
  184. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/fe_operations.h +189 -0
  185. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/fips_test.h +131 -0
  186. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ge_448.h +84 -0
  187. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ge_operations.h +134 -0
  188. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/hash.h +296 -0
  189. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/hmac.h +231 -0
  190. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/hpke.h +145 -0
  191. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/integer.h +449 -0
  192. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/kdf.h +199 -0
  193. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/lms.h +202 -0
  194. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/logging.h +588 -0
  195. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/md2.h +83 -0
  196. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/md4.h +77 -0
  197. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/md5.h +141 -0
  198. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/mem_track.h +968 -0
  199. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/memory.h +545 -0
  200. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/misc.h +214 -0
  201. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/mlkem.h +377 -0
  202. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/mpi_class.h +1021 -0
  203. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/mpi_superclass.h +96 -0
  204. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/oid_sum.h +1907 -0
  205. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/pkcs12.h +79 -0
  206. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/pkcs7.h +578 -0
  207. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/poly1305.h +207 -0
  208. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/pwdbased.h +81 -0
  209. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/random.h +300 -0
  210. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/rc2.h +68 -0
  211. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/ripemd.h +67 -0
  212. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/rsa.h +494 -0
  213. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sakke.h +228 -0
  214. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/settings.h +4762 -0
  215. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sha.h +237 -0
  216. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sha256.h +360 -0
  217. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sha3.h +274 -0
  218. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sha512.h +372 -0
  219. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/signature.h +87 -0
  220. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/siphash.h +101 -0
  221. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sm2.h +27 -0
  222. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sm3.h +27 -0
  223. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sm4.h +27 -0
  224. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sp_int.h +1396 -0
  225. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/sphincs.h +167 -0
  226. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/srp.h +313 -0
  227. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/tfm.h +941 -0
  228. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/types.h +2383 -0
  229. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/visibility.h +97 -0
  230. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wc_encrypt.h +126 -0
  231. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wc_lms.h +506 -0
  232. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wc_mlkem.h +370 -0
  233. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wc_port.h +1764 -0
  234. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wc_xmss.h +285 -0
  235. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wolfevent.h +120 -0
  236. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/wolfmath.h +175 -0
  237. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfcrypt/xmss.h +203 -0
  238. package/android/install/wolfssl-android/arm64-v8a/include/wolfssl/wolfio.h +1035 -0
  239. package/android/install/wolfssl-android/arm64-v8a/lib/libwolfssl.a +0 -0
  240. package/android/install/wolfssl-android/arm64-v8a/lib/libwolfssl.la +41 -0
  241. package/android/install/wolfssl-android/arm64-v8a/lib/pkgconfig/wolfssl.pc +11 -0
  242. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/QUIC.md +117 -0
  243. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/README.txt +8 -0
  244. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/async_client.c +245 -0
  245. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/async_server.c +331 -0
  246. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/client.c +4885 -0
  247. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/echoclient.c +341 -0
  248. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/echoserver.c +498 -0
  249. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/sctp-client-dtls.c +135 -0
  250. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/sctp-client.c +78 -0
  251. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/sctp-server-dtls.c +134 -0
  252. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/sctp-server.c +83 -0
  253. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/server.c +4124 -0
  254. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/example/tls_bench.c +2357 -0
  255. package/android/install/wolfssl-android/arm64-v8a/share/doc/wolfssl/taoCert.txt +176 -0
  256. package/android/install/wolfssl-android/armeabi-v7a/bin/wolfssl-config +117 -0
  257. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/callbacks.h +93 -0
  258. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/certs_test.h +7073 -0
  259. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/certs_test_sm.h +2913 -0
  260. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/crl.h +58 -0
  261. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/error-ssl.h +280 -0
  262. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/ocsp.h +191 -0
  263. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/aes.h +117 -0
  264. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/asn1.h +315 -0
  265. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/asn1t.h +30 -0
  266. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/bio.h +237 -0
  267. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/bn.h +332 -0
  268. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/buffer.h +57 -0
  269. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/camellia.h +27 -0
  270. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/cmac.h +66 -0
  271. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/cms.h +26 -0
  272. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/compat_types.h +70 -0
  273. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/conf.h +117 -0
  274. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/crypto.h +171 -0
  275. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/des.h +124 -0
  276. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/dh.h +144 -0
  277. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/dsa.h +164 -0
  278. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ec.h +525 -0
  279. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ec25519.h +46 -0
  280. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ec448.h +46 -0
  281. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ecdh.h +49 -0
  282. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ecdsa.h +87 -0
  283. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ed25519.h +49 -0
  284. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ed448.h +49 -0
  285. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/engine.h +9 -0
  286. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/err.h +84 -0
  287. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/evp.h +1540 -0
  288. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/fips_rand.h +125 -0
  289. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/hmac.h +98 -0
  290. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/kdf.h +45 -0
  291. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/lhash.h +64 -0
  292. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/md4.h +66 -0
  293. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/md5.h +108 -0
  294. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/modes.h +45 -0
  295. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/obj_mac.h +92 -0
  296. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/objects.h +86 -0
  297. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ocsp.h +108 -0
  298. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/opensslconf.h +8 -0
  299. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/opensslv.h +78 -0
  300. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ossl_typ.h +32 -0
  301. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/pem.h +301 -0
  302. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/pkcs12.h +57 -0
  303. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/pkcs7.h +110 -0
  304. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/rand.h +38 -0
  305. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/rc4.h +64 -0
  306. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ripemd.h +58 -0
  307. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/rsa.h +291 -0
  308. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/safestack.h +40 -0
  309. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/sha.h +331 -0
  310. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/sha3.h +158 -0
  311. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/srp.h +33 -0
  312. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ssl.h +1923 -0
  313. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ssl23.h +1 -0
  314. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/stack.h +61 -0
  315. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/tls1.h +64 -0
  316. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/txt_db.h +60 -0
  317. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/ui.h +2 -0
  318. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/x509.h +227 -0
  319. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/x509_vfy.h +50 -0
  320. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/openssl/x509v3.h +237 -0
  321. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/options.h +261 -0
  322. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/quic.h +310 -0
  323. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/sniffer.h +359 -0
  324. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/sniffer_error.h +151 -0
  325. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/ssl.h +6300 -0
  326. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/test.h +4989 -0
  327. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/version.h +40 -0
  328. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/aes.h +1074 -0
  329. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/arc4.h +69 -0
  330. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ascon.h +109 -0
  331. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/asn.h +2855 -0
  332. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/asn_public.h +1009 -0
  333. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/blake2-impl.h +155 -0
  334. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/blake2-int.h +174 -0
  335. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/blake2.h +108 -0
  336. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/camellia.h +116 -0
  337. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/chacha.h +133 -0
  338. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/chacha20_poly1305.h +157 -0
  339. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/cmac.h +168 -0
  340. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/coding.h +107 -0
  341. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/compress.h +60 -0
  342. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/cpuid.h +153 -0
  343. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/cryptocb.h +770 -0
  344. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/curve25519.h +225 -0
  345. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/curve448.h +151 -0
  346. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/des3.h +167 -0
  347. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/dh.h +210 -0
  348. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/dilithium.h +1051 -0
  349. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/dsa.h +121 -0
  350. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ecc.h +1074 -0
  351. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/eccsi.h +176 -0
  352. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ed25519.h +239 -0
  353. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ed448.h +214 -0
  354. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/error-crypt.h +368 -0
  355. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ext_lms.h +62 -0
  356. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ext_mlkem.h +74 -0
  357. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ext_xmss.h +53 -0
  358. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/falcon.h +180 -0
  359. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/fe_448.h +122 -0
  360. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/fe_operations.h +189 -0
  361. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/fips_test.h +131 -0
  362. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ge_448.h +84 -0
  363. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ge_operations.h +134 -0
  364. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/hash.h +296 -0
  365. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/hmac.h +231 -0
  366. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/hpke.h +145 -0
  367. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/integer.h +449 -0
  368. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/kdf.h +199 -0
  369. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/lms.h +202 -0
  370. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/logging.h +588 -0
  371. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/md2.h +83 -0
  372. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/md4.h +77 -0
  373. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/md5.h +141 -0
  374. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/mem_track.h +968 -0
  375. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/memory.h +545 -0
  376. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/misc.h +214 -0
  377. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/mlkem.h +377 -0
  378. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/mpi_class.h +1021 -0
  379. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/mpi_superclass.h +96 -0
  380. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/oid_sum.h +1907 -0
  381. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/pkcs12.h +79 -0
  382. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/pkcs7.h +578 -0
  383. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/poly1305.h +207 -0
  384. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/pwdbased.h +81 -0
  385. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/random.h +300 -0
  386. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/rc2.h +68 -0
  387. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/ripemd.h +67 -0
  388. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/rsa.h +494 -0
  389. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sakke.h +228 -0
  390. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/settings.h +4762 -0
  391. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sha.h +237 -0
  392. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sha256.h +360 -0
  393. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sha3.h +274 -0
  394. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sha512.h +372 -0
  395. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/signature.h +87 -0
  396. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/siphash.h +101 -0
  397. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sm2.h +27 -0
  398. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sm3.h +27 -0
  399. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sm4.h +27 -0
  400. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sp_int.h +1396 -0
  401. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/sphincs.h +167 -0
  402. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/srp.h +313 -0
  403. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/tfm.h +941 -0
  404. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/types.h +2383 -0
  405. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/visibility.h +97 -0
  406. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wc_encrypt.h +126 -0
  407. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wc_lms.h +506 -0
  408. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wc_mlkem.h +370 -0
  409. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wc_port.h +1764 -0
  410. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wc_xmss.h +285 -0
  411. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wolfevent.h +120 -0
  412. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/wolfmath.h +175 -0
  413. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfcrypt/xmss.h +203 -0
  414. package/android/install/wolfssl-android/armeabi-v7a/include/wolfssl/wolfio.h +1035 -0
  415. package/android/install/wolfssl-android/armeabi-v7a/lib/libwolfssl.a +0 -0
  416. package/android/install/wolfssl-android/armeabi-v7a/lib/libwolfssl.la +41 -0
  417. package/android/install/wolfssl-android/armeabi-v7a/lib/pkgconfig/wolfssl.pc +11 -0
  418. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/QUIC.md +117 -0
  419. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/README.txt +8 -0
  420. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/async_client.c +245 -0
  421. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/async_server.c +331 -0
  422. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/client.c +4885 -0
  423. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/echoclient.c +341 -0
  424. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/echoserver.c +498 -0
  425. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/sctp-client-dtls.c +135 -0
  426. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/sctp-client.c +78 -0
  427. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/sctp-server-dtls.c +134 -0
  428. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/sctp-server.c +83 -0
  429. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/server.c +4124 -0
  430. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/example/tls_bench.c +2357 -0
  431. package/android/install/wolfssl-android/armeabi-v7a/share/doc/wolfssl/taoCert.txt +176 -0
  432. package/android/install/wolfssl-android/x86_64/bin/wolfssl-config +117 -0
  433. package/android/install/wolfssl-android/x86_64/include/wolfssl/callbacks.h +93 -0
  434. package/android/install/wolfssl-android/x86_64/include/wolfssl/certs_test.h +7073 -0
  435. package/android/install/wolfssl-android/x86_64/include/wolfssl/certs_test_sm.h +2913 -0
  436. package/android/install/wolfssl-android/x86_64/include/wolfssl/crl.h +58 -0
  437. package/android/install/wolfssl-android/x86_64/include/wolfssl/error-ssl.h +280 -0
  438. package/android/install/wolfssl-android/x86_64/include/wolfssl/ocsp.h +191 -0
  439. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/aes.h +117 -0
  440. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/asn1.h +315 -0
  441. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/asn1t.h +30 -0
  442. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/bio.h +237 -0
  443. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/bn.h +332 -0
  444. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/buffer.h +57 -0
  445. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/camellia.h +27 -0
  446. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/cmac.h +66 -0
  447. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/cms.h +26 -0
  448. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/compat_types.h +70 -0
  449. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/conf.h +117 -0
  450. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/crypto.h +171 -0
  451. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/des.h +124 -0
  452. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/dh.h +144 -0
  453. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/dsa.h +164 -0
  454. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ec.h +525 -0
  455. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ec25519.h +46 -0
  456. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ec448.h +46 -0
  457. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ecdh.h +49 -0
  458. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ecdsa.h +87 -0
  459. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ed25519.h +49 -0
  460. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ed448.h +49 -0
  461. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/engine.h +9 -0
  462. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/err.h +84 -0
  463. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/evp.h +1540 -0
  464. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/fips_rand.h +125 -0
  465. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/hmac.h +98 -0
  466. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/kdf.h +45 -0
  467. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/lhash.h +64 -0
  468. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/md4.h +66 -0
  469. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/md5.h +108 -0
  470. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/modes.h +45 -0
  471. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/obj_mac.h +92 -0
  472. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/objects.h +86 -0
  473. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ocsp.h +108 -0
  474. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/opensslconf.h +8 -0
  475. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/opensslv.h +78 -0
  476. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ossl_typ.h +32 -0
  477. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/pem.h +301 -0
  478. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/pkcs12.h +57 -0
  479. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/pkcs7.h +110 -0
  480. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/rand.h +38 -0
  481. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/rc4.h +64 -0
  482. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ripemd.h +58 -0
  483. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/rsa.h +291 -0
  484. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/safestack.h +40 -0
  485. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/sha.h +331 -0
  486. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/sha3.h +158 -0
  487. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/srp.h +33 -0
  488. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ssl.h +1923 -0
  489. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ssl23.h +1 -0
  490. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/stack.h +61 -0
  491. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/tls1.h +64 -0
  492. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/txt_db.h +60 -0
  493. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/ui.h +2 -0
  494. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/x509.h +227 -0
  495. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/x509_vfy.h +50 -0
  496. package/android/install/wolfssl-android/x86_64/include/wolfssl/openssl/x509v3.h +237 -0
  497. package/android/install/wolfssl-android/x86_64/include/wolfssl/options.h +273 -0
  498. package/android/install/wolfssl-android/x86_64/include/wolfssl/quic.h +310 -0
  499. package/android/install/wolfssl-android/x86_64/include/wolfssl/sniffer.h +359 -0
  500. package/android/install/wolfssl-android/x86_64/include/wolfssl/sniffer_error.h +151 -0
  501. package/android/install/wolfssl-android/x86_64/include/wolfssl/ssl.h +6300 -0
  502. package/android/install/wolfssl-android/x86_64/include/wolfssl/test.h +4989 -0
  503. package/android/install/wolfssl-android/x86_64/include/wolfssl/version.h +40 -0
  504. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/aes.h +1074 -0
  505. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/arc4.h +69 -0
  506. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ascon.h +109 -0
  507. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/asn.h +2855 -0
  508. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/asn_public.h +1009 -0
  509. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/blake2-impl.h +155 -0
  510. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/blake2-int.h +174 -0
  511. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/blake2.h +108 -0
  512. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/camellia.h +116 -0
  513. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/chacha.h +133 -0
  514. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/chacha20_poly1305.h +157 -0
  515. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/cmac.h +168 -0
  516. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/coding.h +107 -0
  517. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/compress.h +60 -0
  518. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/cpuid.h +153 -0
  519. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/cryptocb.h +770 -0
  520. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/curve25519.h +225 -0
  521. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/curve448.h +151 -0
  522. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/des3.h +167 -0
  523. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/dh.h +210 -0
  524. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/dilithium.h +1051 -0
  525. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/dsa.h +121 -0
  526. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ecc.h +1074 -0
  527. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/eccsi.h +176 -0
  528. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ed25519.h +239 -0
  529. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ed448.h +214 -0
  530. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/error-crypt.h +368 -0
  531. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ext_lms.h +62 -0
  532. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ext_mlkem.h +74 -0
  533. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ext_xmss.h +53 -0
  534. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/falcon.h +180 -0
  535. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/fe_448.h +122 -0
  536. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/fe_operations.h +189 -0
  537. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/fips_test.h +131 -0
  538. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ge_448.h +84 -0
  539. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ge_operations.h +134 -0
  540. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/hash.h +296 -0
  541. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/hmac.h +231 -0
  542. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/hpke.h +145 -0
  543. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/integer.h +449 -0
  544. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/kdf.h +199 -0
  545. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/lms.h +202 -0
  546. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/logging.h +588 -0
  547. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/md2.h +83 -0
  548. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/md4.h +77 -0
  549. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/md5.h +141 -0
  550. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/mem_track.h +968 -0
  551. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/memory.h +545 -0
  552. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/misc.h +214 -0
  553. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/mlkem.h +377 -0
  554. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/mpi_class.h +1021 -0
  555. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/mpi_superclass.h +96 -0
  556. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/oid_sum.h +1907 -0
  557. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/pkcs12.h +79 -0
  558. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/pkcs7.h +578 -0
  559. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/poly1305.h +207 -0
  560. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/pwdbased.h +81 -0
  561. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/random.h +300 -0
  562. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/rc2.h +68 -0
  563. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/ripemd.h +67 -0
  564. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/rsa.h +494 -0
  565. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sakke.h +228 -0
  566. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/settings.h +4762 -0
  567. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sha.h +237 -0
  568. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sha256.h +360 -0
  569. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sha3.h +274 -0
  570. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sha512.h +372 -0
  571. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/signature.h +87 -0
  572. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/siphash.h +101 -0
  573. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sm2.h +27 -0
  574. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sm3.h +27 -0
  575. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sm4.h +27 -0
  576. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sp_int.h +1396 -0
  577. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/sphincs.h +167 -0
  578. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/srp.h +313 -0
  579. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/tfm.h +941 -0
  580. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/types.h +2383 -0
  581. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/visibility.h +97 -0
  582. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wc_encrypt.h +126 -0
  583. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wc_lms.h +506 -0
  584. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wc_mlkem.h +370 -0
  585. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wc_port.h +1764 -0
  586. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wc_xmss.h +285 -0
  587. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wolfevent.h +120 -0
  588. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/wolfmath.h +175 -0
  589. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfcrypt/xmss.h +203 -0
  590. package/android/install/wolfssl-android/x86_64/include/wolfssl/wolfio.h +1035 -0
  591. package/android/install/wolfssl-android/x86_64/lib/libwolfssl.a +0 -0
  592. package/android/install/wolfssl-android/x86_64/lib/libwolfssl.la +41 -0
  593. package/android/install/wolfssl-android/x86_64/lib/pkgconfig/wolfssl.pc +11 -0
  594. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/QUIC.md +117 -0
  595. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/README.txt +8 -0
  596. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/async_client.c +245 -0
  597. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/async_server.c +331 -0
  598. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/client.c +4885 -0
  599. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/echoclient.c +341 -0
  600. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/echoserver.c +498 -0
  601. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/sctp-client-dtls.c +135 -0
  602. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/sctp-client.c +78 -0
  603. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/sctp-server-dtls.c +134 -0
  604. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/sctp-server.c +83 -0
  605. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/server.c +4124 -0
  606. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/example/tls_bench.c +2357 -0
  607. package/android/install/wolfssl-android/x86_64/share/doc/wolfssl/taoCert.txt +176 -0
  608. package/android/src/main/cpp/CMakeLists.txt +19 -27
  609. package/android/src/main/cpp/ngtcp2_jni.cpp +30 -36
  610. package/android/src/main/kotlin/ai/annadata/mqttquic/MqttQuicPlugin.kt +15 -0
  611. package/android/src/main/kotlin/ai/annadata/mqttquic/client/MQTTClient.kt +6 -2
  612. package/build-native.sh +397 -0
  613. package/deps-versions.sh +25 -0
  614. package/dist/esm/definitions.d.ts +20 -0
  615. package/dist/esm/definitions.d.ts.map +1 -1
  616. package/dist/esm/web.d.ts +26 -3
  617. package/dist/esm/web.d.ts.map +1 -1
  618. package/dist/esm/web.js +230 -10
  619. package/dist/esm/web.js.map +1 -1
  620. package/dist/plugin.cjs.js +11363 -13
  621. package/dist/plugin.cjs.js.map +1 -1
  622. package/dist/plugin.js +11364 -14
  623. package/dist/plugin.js.map +1 -1
  624. package/docs/ARCHITECTURAL_ANALYSIS.md +710 -0
  625. package/docs/CAPACITOR_MQTT_QUIC_PRODUCTION_PLUGIN.md +190 -0
  626. package/docs/CAPACITOR_VERSION_SUPPORT.md +65 -0
  627. package/docs/IMPLEMENTATION_SUMMARY.md +246 -0
  628. package/docs/MQTT5_CLIENT_COMPLIANCE.md +48 -0
  629. package/docs/MQTT5_IMPLEMENTATION_COMPLETE.md +178 -0
  630. package/docs/MQTT_VERSION_ANALYSIS.md +233 -0
  631. package/docs/NGTCP2_IMPLEMENTATION_STATUS.md +214 -0
  632. package/docs/NGTCP2_INTEGRATION_PLAN.md +597 -0
  633. package/docs/P0_P1_CHANGELOG.md +79 -0
  634. package/docs/PRODUCTION_PUBLISH_STEPS.md +161 -0
  635. package/docs/PROJECT_OVERVIEW.md +193 -0
  636. package/ios/.swiftpm/xcode/xcuserdata/annadata.xcuserdatad/xcschemes/xcschememanagement.plist +1 -1
  637. package/ios/NGTCP2_BUILD_INSTRUCTIONS.md +12 -0
  638. package/ios/Sources/MqttQuicPlugin/MqttQuicPlugin.swift +6 -0
  639. package/ios/Sources/MqttQuicPlugin/QUIC/NGTCP2Bridge.mm +6 -0
  640. package/ios/build-openssl.sh +1 -1
  641. package/ios/libs/MqttQuicLibs.xcframework/Info.plist +44 -0
  642. package/ios/libs/MqttQuicLibs.xcframework/ios-arm64/libmqttquic_native_device.a +0 -0
  643. package/ios/libs/MqttQuicLibs.xcframework/ios-arm64_x86_64-simulator/libmqttquic_native_simulator.a +0 -0
  644. package/ios/libs/libnghttp3.a +0 -0
  645. package/ios/libs/libngtcp2.a +0 -0
  646. package/ios/libs/libngtcp2_crypto_wolfssl.a +0 -0
  647. package/ios/libs/libwolfssl.a +0 -0
  648. package/ios/libs-simulator/libnghttp3.a +0 -0
  649. package/ios/libs-simulator/libngtcp2.a +0 -0
  650. package/ios/libs-simulator/libngtcp2_crypto_wolfssl.a +0 -0
  651. package/ios/libs-simulator/libwolfssl.a +0 -0
  652. package/ios/libs-simulator-x86_64/libnghttp3.a +0 -0
  653. package/ios/libs-simulator-x86_64/libngtcp2.a +0 -0
  654. package/ios/libs-simulator-x86_64/libngtcp2_crypto_wolfssl.a +0 -0
  655. package/ios/libs-simulator-x86_64/libwolfssl.a +0 -0
  656. package/package.json +22 -9
@@ -0,0 +1,4989 @@
1
+ /* test.h
2
+ *
3
+ * Copyright (C) 2006-2025 wolfSSL Inc.
4
+ *
5
+ * This file is part of wolfSSL.
6
+ *
7
+ * wolfSSL is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * wolfSSL is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20
+ */
21
+ /*!
22
+ \file ../wolfssl/test.h
23
+ \brief Header file containing test inline functions
24
+ */
25
+
26
+ /* Testing functions */
27
+
28
+ #ifndef wolfSSL_TEST_H
29
+ #define wolfSSL_TEST_H
30
+
31
+ #include <wolfssl/wolfcrypt/settings.h>
32
+
33
+ #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
34
+ #if defined(OPENSSL_EXTRA) && defined(OPENSSL_COEXIST)
35
+ #error "Example apps built with OPENSSL_EXTRA can't also be built with OPENSSL_COEXIST."
36
+ #endif
37
+
38
+ #include <wolfssl/wolfcrypt/wc_port.h>
39
+
40
+ #ifdef FUSION_RTOS
41
+ #include <fclstdio.h>
42
+ #include <fclstdlib.h>
43
+ #else
44
+ #include <stdio.h>
45
+ #include <stdlib.h>
46
+ #endif
47
+ #include <assert.h>
48
+ #include <ctype.h>
49
+ #ifdef HAVE_ERRNO_H
50
+ #include <errno.h>
51
+ #endif
52
+ #include <wolfssl/wolfcrypt/types.h>
53
+ #include <wolfssl/error-ssl.h>
54
+ #include <wolfssl/wolfcrypt/random.h>
55
+ #include <wolfssl/wolfcrypt/mem_track.h>
56
+ #include <wolfssl/wolfio.h>
57
+ #include <wolfssl/wolfcrypt/asn.h>
58
+
59
+ #ifdef ATOMIC_USER
60
+ #include <wolfssl/wolfcrypt/aes.h>
61
+ #include <wolfssl/wolfcrypt/arc4.h>
62
+ #include <wolfssl/wolfcrypt/hmac.h>
63
+ #endif
64
+ #ifdef HAVE_PK_CALLBACKS
65
+ #ifndef NO_RSA
66
+ #include <wolfssl/wolfcrypt/rsa.h>
67
+ #endif
68
+ #ifdef HAVE_ECC
69
+ #include <wolfssl/wolfcrypt/ecc.h>
70
+ #endif /* HAVE_ECC */
71
+ #ifndef NO_DH
72
+ #include <wolfssl/wolfcrypt/dh.h>
73
+ #endif /* !NO_DH */
74
+ #ifdef HAVE_ED25519
75
+ #include <wolfssl/wolfcrypt/ed25519.h>
76
+ #endif /* HAVE_ED25519 */
77
+ #ifdef HAVE_CURVE25519
78
+ #include <wolfssl/wolfcrypt/curve25519.h>
79
+ #endif /* HAVE_ECC */
80
+ #ifdef HAVE_ED448
81
+ #include <wolfssl/wolfcrypt/ed448.h>
82
+ #endif /* HAVE_ED448 */
83
+ #ifdef HAVE_CURVE448
84
+ #include <wolfssl/wolfcrypt/curve448.h>
85
+ #endif /* HAVE_ECC */
86
+ #endif /*HAVE_PK_CALLBACKS */
87
+
88
+ #ifdef __WATCOMC__
89
+ #define SNPRINTF snprintf
90
+ #if defined(__NT__)
91
+ #include <winsock2.h>
92
+ #include <ws2tcpip.h>
93
+ #include <process.h>
94
+ #ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
95
+ #include <wspiapi.h>
96
+ #endif
97
+ #define SOCKET_T SOCKET
98
+ #define XSLEEP_MS(t) Sleep(t)
99
+ #elif defined(__OS2__)
100
+ #include <netdb.h>
101
+ #include <sys/ioctl.h>
102
+ #include <tcpustd.h>
103
+ #define SOCKET_T int
104
+ #elif defined(__UNIX__)
105
+ #include <string.h>
106
+ #include <netdb.h>
107
+ #include <netinet/tcp.h>
108
+ #ifndef WOLFSSL_NDS
109
+ #include <sys/ioctl.h>
110
+ #endif
111
+ #include <time.h>
112
+ #include <sys/time.h>
113
+ #ifdef HAVE_PTHREAD
114
+ #include <pthread.h>
115
+ #endif
116
+ #define SOCKET_T int
117
+ #ifndef SO_NOSIGPIPE
118
+ #include <signal.h> /* ignore SIGPIPE */
119
+ #endif
120
+
121
+ #define XSLEEP_MS(m) \
122
+ { \
123
+ struct timespec req = { (m)/1000, ((m) % 1000) * 1000 }; \
124
+ nanosleep( &req, NULL ); \
125
+ }
126
+ #endif
127
+ #elif defined(USE_WINDOWS_API)
128
+ #include <winsock2.h>
129
+ #include <ws2tcpip.h>
130
+ #include <process.h>
131
+ #ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
132
+ #include <wspiapi.h>
133
+ #endif
134
+ #define SOCKET_T SOCKET
135
+ #define SNPRINTF _snprintf
136
+ #define XSLEEP_MS(t) Sleep(t)
137
+ #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
138
+ #include <string.h>
139
+ #include "rl_net.h"
140
+ #define SOCKET_T int
141
+ typedef int socklen_t ;
142
+ #define inet_addr wolfSSL_inet_addr
143
+ static unsigned long wolfSSL_inet_addr(const char *cp)
144
+ {
145
+ unsigned int a[4] ; unsigned long ret ;
146
+ sscanf(cp, "%u.%u.%u.%u", &a[0], &a[1], &a[2], &a[3]) ;
147
+ ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ;
148
+ return(ret) ;
149
+ }
150
+ #if defined(HAVE_KEIL_RTX)
151
+ #define XSLEEP_MS(t) os_dly_wait(t)
152
+ #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
153
+ #define XSLEEP_MS(t) osDelay(t)
154
+ #endif
155
+ #elif defined(WOLFSSL_TIRTOS)
156
+ #include <string.h>
157
+ #include <netdb.h>
158
+ #if !defined(__ti__) /* conflicts with sys/socket.h */
159
+ #include <sys/types.h>
160
+ #endif
161
+ #include <arpa/inet.h>
162
+ #include <sys/socket.h>
163
+ #include <ti/sysbios/knl/Task.h>
164
+ struct hostent {
165
+ char *h_name; /* official name of host */
166
+ char **h_aliases; /* alias list */
167
+ int h_addrtype; /* host address type */
168
+ int h_length; /* length of address */
169
+ char **h_addr_list; /* list of addresses from name server */
170
+ };
171
+ #define SOCKET_T int
172
+ #define XSLEEP_MS(t) Task_sleep(t/1000)
173
+ #elif defined(WOLFSSL_VXWORKS)
174
+ #include <hostLib.h>
175
+ #include <sockLib.h>
176
+ #include <arpa/inet.h>
177
+ #include <string.h>
178
+ #include <selectLib.h>
179
+ #include <sys/types.h>
180
+ #include <netinet/in.h>
181
+ #include <fcntl.h>
182
+ #ifdef WOLFSSL_VXWORKS_6_x
183
+ #include <time.h>
184
+ #else
185
+ #include <sys/time.h>
186
+ #endif
187
+ #include <netdb.h>
188
+ #include <pthread.h>
189
+ #define SOCKET_T int
190
+ #elif defined(WOLFSSL_ZEPHYR)
191
+ #include <version.h>
192
+ #include <string.h>
193
+ #include <sys/types.h>
194
+ #if KERNEL_VERSION_NUMBER >= 0x30100
195
+ #include <zephyr/net/socket.h>
196
+ #ifdef CONFIG_POSIX_API
197
+ #include <zephyr/posix/poll.h>
198
+ #include <zephyr/posix/netdb.h>
199
+ #include <zephyr/posix/sys/socket.h>
200
+ #include <zephyr/posix/sys/select.h>
201
+ #endif
202
+ #else
203
+ #include <net/socket.h>
204
+ #ifdef CONFIG_POSIX_API
205
+ #include <posix/poll.h>
206
+ #include <posix/netdb.h>
207
+ #include <posix/sys/socket.h>
208
+ #include <posix/sys/select.h>
209
+ #endif
210
+ #endif
211
+ #define SOCKET_T int
212
+ #define SOL_SOCKET 1
213
+ #define WOLFSSL_USE_GETADDRINFO
214
+
215
+ static unsigned long inet_addr(const char *cp)
216
+ {
217
+ unsigned int a[4]; unsigned long ret;
218
+ int i, j;
219
+ for (i=0, j=0; i<4; i++) {
220
+ a[i] = 0;
221
+ while (cp[j] != '.' && cp[j] != '\0') {
222
+ a[i] *= 10;
223
+ a[i] += cp[j] - '0';
224
+ j++;
225
+ }
226
+ }
227
+ ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ;
228
+ return(ret) ;
229
+ }
230
+ #elif defined(NETOS)
231
+ #include <string.h>
232
+ #include <sys/types.h>
233
+ struct hostent {
234
+ char* h_name; /* official name of host */
235
+ char** h_aliases; /* alias list */
236
+ int h_addrtype; /* host address type */
237
+ int h_length; /* length of address */
238
+ char** h_addr_list; /* list of addresses from the name server */
239
+ };
240
+ #elif defined(ARDUINO)
241
+ /* TODO, define board-specific */
242
+ #else
243
+ #include <string.h>
244
+ #include <sys/types.h>
245
+ #ifndef WOLFSSL_LEANPSK
246
+ #include <unistd.h>
247
+ #include <netdb.h>
248
+ #include <netinet/in.h>
249
+ #include <netinet/tcp.h>
250
+ #include <arpa/inet.h>
251
+ #ifndef WOLFSSL_NDS
252
+ #include <sys/ioctl.h>
253
+ #endif
254
+ #include <sys/time.h>
255
+ #include <sys/socket.h>
256
+ #ifdef HAVE_PTHREAD
257
+ #include <pthread.h>
258
+ #endif
259
+ #include <fcntl.h>
260
+ #ifdef TEST_IPV6
261
+ #include <netdb.h>
262
+ #endif
263
+ #endif
264
+ #ifdef FREESCALE_MQX
265
+ typedef int socklen_t ;
266
+ #endif
267
+ #define SOCKET_T int
268
+ #ifndef SO_NOSIGPIPE
269
+ #include <signal.h> /* ignore SIGPIPE */
270
+ #endif
271
+ #define SNPRINTF snprintf
272
+
273
+ #define XSELECT_WAIT(x,y) do { \
274
+ struct timeval tv = {((x) + ((y) / 1000000)),((y) % 1000000)}; \
275
+ if ((select(0, NULL, NULL, NULL, &tv) < 0) && (errno != EINTR)) \
276
+ err_sys("select for XSELECT_WAIT failed."); \
277
+ } while (0)
278
+ #define XSLEEP_US(u) XSELECT_WAIT(0,u)
279
+ #define XSLEEP_MS(m) XSELECT_WAIT(0,(m)*1000)
280
+ #endif /* USE_WINDOWS_API */
281
+
282
+ #ifndef XSLEEP_MS
283
+ #define XSLEEP_MS(t) sleep(t/1000)
284
+ #endif
285
+
286
+ #ifdef WOLFSSL_ASYNC_CRYPT
287
+ #include <wolfssl/wolfcrypt/async.h>
288
+ #endif
289
+ #ifdef HAVE_CAVIUM
290
+ #include <wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h>
291
+ #endif
292
+ #ifdef _MSC_VER
293
+ /* disable conversion warning */
294
+ /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
295
+ #pragma warning(disable:4244 4996)
296
+ #endif
297
+
298
+ #ifndef WOLFSSL_CIPHER_LIST_MAX_SIZE
299
+ #define WOLFSSL_CIPHER_LIST_MAX_SIZE 4096
300
+ #endif
301
+ /* Buffer for benchmark tests */
302
+ #ifndef TEST_BUFFER_SIZE
303
+ #define TEST_BUFFER_SIZE 16384
304
+ #endif
305
+
306
+ #ifndef WOLFSSL_HAVE_MIN
307
+ #define WOLFSSL_HAVE_MIN
308
+ #ifdef NO_INLINE
309
+ #define min no_inline_min
310
+ #endif
311
+ static WC_INLINE word32 min(word32 a, word32 b)
312
+ {
313
+ return a > b ? b : a;
314
+ }
315
+ #endif /* WOLFSSL_HAVE_MIN */
316
+
317
+ /* Socket Handling */
318
+ #ifndef WOLFSSL_SOCKET_INVALID
319
+ #ifdef USE_WINDOWS_API
320
+ #define WOLFSSL_SOCKET_INVALID ((SOCKET_T)INVALID_SOCKET)
321
+ #elif defined(WOLFSSL_TIRTOS)
322
+ #define WOLFSSL_SOCKET_INVALID ((SOCKET_T)-1)
323
+ #else
324
+ #define WOLFSSL_SOCKET_INVALID (SOCKET_T)(-1)
325
+ #endif
326
+ #endif /* WOLFSSL_SOCKET_INVALID */
327
+
328
+ #ifndef WOLFSSL_SOCKET_IS_INVALID
329
+ #if defined(USE_WINDOWS_API) || defined(WOLFSSL_TIRTOS)
330
+ #define WOLFSSL_SOCKET_IS_INVALID(s) ((SOCKET_T)(s) == WOLFSSL_SOCKET_INVALID)
331
+ #else
332
+ #define WOLFSSL_SOCKET_IS_INVALID(s) ((SOCKET_T)(s) < WOLFSSL_SOCKET_INVALID)
333
+ #endif
334
+ #endif /* WOLFSSL_SOCKET_IS_INVALID */
335
+
336
+ #if defined(__MACH__) || defined(USE_WINDOWS_API)
337
+ #ifndef _SOCKLEN_T
338
+ typedef int socklen_t;
339
+ #endif
340
+ #endif
341
+
342
+
343
+ /* HPUX doesn't use socklent_t for third parameter to accept, unless
344
+ _XOPEN_SOURCE_EXTENDED is defined */
345
+ #if !defined(__hpux__) && !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_IAR_ARM)\
346
+ && !defined(WOLFSSL_ROWLEY_ARM) && !defined(WOLFSSL_KEIL_TCP_NET)
347
+ typedef socklen_t* ACCEPT_THIRD_T;
348
+ #else
349
+ #if defined _XOPEN_SOURCE_EXTENDED
350
+ typedef socklen_t* ACCEPT_THIRD_T;
351
+ #else
352
+ typedef int* ACCEPT_THIRD_T;
353
+ #endif
354
+ #endif
355
+
356
+
357
+ #if defined(DEBUG_PK_CB) || defined(TEST_PK_PRIVKEY) || defined(TEST_PK_PSK)
358
+ #define WOLFSSL_PKMSG(...) printf(__VA_ARGS__)
359
+ #else
360
+ #define WOLFSSL_PKMSG(...) WC_DO_NOTHING
361
+ #endif
362
+
363
+
364
+ #ifndef MY_EX_USAGE
365
+ #define MY_EX_USAGE 2
366
+ #endif
367
+
368
+ #ifndef EXIT_FAILURE
369
+ #define EXIT_FAILURE 1
370
+ #endif
371
+
372
+ #if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR)
373
+ #ifndef EXIT_SUCCESS
374
+ #define EXIT_SUCCESS 0
375
+ #endif
376
+ #define XEXIT(rc) return rc
377
+ #define XEXIT_T(rc) return (THREAD_RETURN)rc
378
+ #else
379
+ #define XEXIT(rc) exit((int)(rc))
380
+ #define XEXIT_T(rc) exit((int)(rc))
381
+ #endif
382
+
383
+ static WC_INLINE
384
+ #if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR)
385
+ THREAD_RETURN
386
+ #else
387
+ WC_NORETURN void
388
+ #endif
389
+ err_sys(const char* msg)
390
+ {
391
+ #if !defined(__GNUC__)
392
+ /* scan-build (which pretends to be gnuc) can get confused and think the
393
+ * msg pointer can be null even when hardcoded and then it won't exit,
394
+ * making null pointer checks above the err_sys() call useless.
395
+ * We could just always exit() but some compilers will complain about no
396
+ * possible return, with gcc we know the attribute to handle that with
397
+ * WC_NORETURN. */
398
+ if (msg)
399
+ #endif
400
+ {
401
+ fprintf(stderr, "wolfSSL error: %s\n", msg);
402
+ }
403
+ XEXIT_T(EXIT_FAILURE);
404
+ }
405
+
406
+ static WC_INLINE
407
+ #if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR)
408
+ THREAD_RETURN
409
+ #else
410
+ WC_NORETURN void
411
+ #endif
412
+ err_sys_with_errno(const char* msg)
413
+ {
414
+ #if !defined(__GNUC__)
415
+ /* scan-build (which pretends to be gnuc) can get confused and think the
416
+ * msg pointer can be null even when hardcoded and then it won't exit,
417
+ * making null pointer checks above the err_sys() call useless.
418
+ * We could just always exit() but some compilers will complain about no
419
+ * possible return, with gcc we know the attribute to handle that with
420
+ * WC_NORETURN. */
421
+ if (msg)
422
+ #endif
423
+ {
424
+ #if defined(HAVE_STRING_H) && defined(HAVE_ERRNO_H)
425
+ fprintf(stderr, "wolfSSL error: %s: %s\n", msg, strerror(errno));
426
+ #else
427
+ fprintf(stderr, "wolfSSL error: %s\n", msg);
428
+ #endif
429
+ }
430
+ XEXIT_T(EXIT_FAILURE);
431
+ }
432
+
433
+ #define LIBCALL_CHECK_RET(...) do { \
434
+ int _libcall_ret = (__VA_ARGS__); \
435
+ if (_libcall_ret < 0) { \
436
+ fprintf(stderr, "%s L%d error %d for \"%s\"\n", \
437
+ __FILE__, __LINE__, errno, #__VA_ARGS__); \
438
+ err_sys("library/system call failed"); \
439
+ } \
440
+ } while(0)
441
+
442
+ #define THREAD_CHECK_RET(...) do { \
443
+ int _thread_ret = (__VA_ARGS__); \
444
+ if (_thread_ret != 0) { \
445
+ errno = _thread_ret; \
446
+ fprintf(stderr, "%s L%d error %d for \"%s\"\n", \
447
+ __FILE__, __LINE__, _thread_ret, #__VA_ARGS__); \
448
+ err_sys("thread call failed"); \
449
+ } \
450
+ } while(0)
451
+
452
+
453
+ #ifndef WOLFSSL_NO_TLS12
454
+ #define SERVER_DEFAULT_VERSION 3
455
+ #else
456
+ #define SERVER_DEFAULT_VERSION 4
457
+ #endif
458
+ #define SERVER_DTLS_DEFAULT_VERSION (-2)
459
+ #define SERVER_INVALID_VERSION (-99)
460
+ #define SERVER_DOWNGRADE_VERSION (-98)
461
+ #ifndef WOLFSSL_NO_TLS12
462
+ #define CLIENT_DEFAULT_VERSION 3
463
+ #else
464
+ #define CLIENT_DEFAULT_VERSION 4
465
+ #endif
466
+ #define CLIENT_DTLS_DEFAULT_VERSION (-2)
467
+ #define CLIENT_INVALID_VERSION (-99)
468
+ #define CLIENT_DOWNGRADE_VERSION (-98)
469
+ #define EITHER_DOWNGRADE_VERSION (-97)
470
+ #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH)
471
+ #define DEFAULT_MIN_DHKEY_BITS 2048
472
+ #define DEFAULT_MAX_DHKEY_BITS 3072
473
+ #else
474
+ #define DEFAULT_MIN_DHKEY_BITS 1024
475
+ #define DEFAULT_MAX_DHKEY_BITS 2048
476
+ #endif
477
+ #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH)
478
+ #define DEFAULT_MIN_RSAKEY_BITS 2048
479
+ #else
480
+ #ifndef DEFAULT_MIN_RSAKEY_BITS
481
+ #define DEFAULT_MIN_RSAKEY_BITS 1024
482
+ #endif
483
+ #endif
484
+ #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_MAX_STRENGTH)
485
+ #define DEFAULT_MIN_ECCKEY_BITS 256
486
+ #else
487
+ #ifndef DEFAULT_MIN_ECCKEY_BITS
488
+ #define DEFAULT_MIN_ECCKEY_BITS 224
489
+ #endif
490
+ #endif
491
+
492
+ #ifndef DEFAULT_TIMEOUT_SEC
493
+ #define DEFAULT_TIMEOUT_SEC 2
494
+ #endif
495
+
496
+ /* all certs relative to wolfSSL home directory now */
497
+ #if defined(WOLFSSL_NO_CURRDIR) || defined(WOLFSSL_MDK_SHELL)
498
+ #ifdef WOLFSSL_PEM_TO_DER
499
+ #define caCertFile "certs/ca-cert.pem"
500
+ #define eccCertFile "certs/server-ecc.pem"
501
+ #define eccKeyFile "certs/ecc-key.pem"
502
+ #define eccKeyPubFile "certs/ecc-keyPub.pem"
503
+ #define eccRsaCertFile "certs/server-ecc-rsa.pem"
504
+ #define svrCertFile "certs/server-cert.pem"
505
+ #define svrKeyFile "certs/server-key.pem"
506
+ #define svrKeyPubFile "certs/server-keyPub.pem"
507
+ #define cliCertFile "certs/client-cert.pem"
508
+ #define cliCertDerFile "certs/client-cert.der"
509
+ #define cliCertFileExt "certs/client-cert-ext.pem"
510
+ #define cliCertDerFileExt "certs/client-cert-ext.der"
511
+ #define cliKeyFile "certs/client-key.pem"
512
+ #define cliKeyPubFile "certs/client-keyPub.pem"
513
+ #define dhParamFile "certs/dh2048.pem"
514
+ #define cliEccKeyFile "certs/ecc-client-key.pem"
515
+ #define cliEccKeyPubFile "certs/ecc-client-keyPub.pem"
516
+ #define cliEccCertFile "certs/client-ecc-cert.pem"
517
+ #define caEccCertFile "certs/ca-ecc-cert.pem"
518
+ #define crlPemDir "certs/crl"
519
+ #define edCertFile "certs/ed25519/server-ed25519-cert.pem"
520
+ #define edKeyFile "certs/ed25519/server-ed25519-priv.pem"
521
+ #define edKeyPubFile "certs/ed25519/server-ed25519-key.pem"
522
+ #define cliEdCertFile "certs/ed25519/client-ed25519.pem"
523
+ #define cliEdKeyFile "certs/ed25519/client-ed25519-priv.pem"
524
+ #define cliEdKeyPubFile "certs/ed25519/client-ed25519-key.pem"
525
+ #define caEdCertFile "certs/ed25519/ca-ed25519.pem"
526
+ #define ed448CertFile "certs/ed448/server-ed448-cert.pem"
527
+ #define ed448KeyFile "certs/ed448/server-ed448-priv.pem"
528
+ #define cliEd448CertFile "certs/ed448/client-ed448.pem"
529
+ #define cliEd448KeyFile "certs/ed448/client-ed448-priv.pem"
530
+ #define caEd448CertFile "certs/ed448/ca-ed448.pem"
531
+ #define noIssuerCertFile "certs/empty-issuer-cert.pem"
532
+ #else
533
+ #define caCertFile "certs/ca-cert.der"
534
+ #define eccCertFile "certs/server-ecc.der"
535
+ #define eccKeyFile "certs/ecc-key.der"
536
+ #define eccKeyPubFile "certs/ecc-keyPub.der"
537
+ #define eccRsaCertFile "certs/server-ecc-rsa.der"
538
+ #define svrCertFile "certs/server-cert.der"
539
+ #define svrKeyFile "certs/server-key.der"
540
+ #define svrKeyPubFile "certs/server-keyPub.der"
541
+ #define cliCertFile "certs/client-cert.der"
542
+ #define cliCertDerFile "certs/client-cert.der"
543
+ #define cliCertFileExt "certs/client-cert-ext.der"
544
+ #define cliCertDerFileExt "certs/client-cert-ext.der"
545
+ #define cliKeyFile "certs/client-key.der"
546
+ #define cliKeyPubFile "certs/client-keyPub.der"
547
+ #define dhParamFile "certs/dh2048.der"
548
+ #define cliEccKeyFile "certs/ecc-client-key.der"
549
+ #define cliEccKeyPubFile "certs/ecc-client-keyPub.der"
550
+ #define cliEccCertFile "certs/client-ecc-cert.der"
551
+ #define caEccCertFile "certs/ca-ecc-cert.der"
552
+ #define crlPemDir "certs/crl"
553
+ #define edCertFile "certs/ed25519/server-ed25519-cert.der"
554
+ #define edKeyFile "certs/ed25519/server-ed25519-priv.der"
555
+ #define edKeyPubFile "certs/ed25519/server-ed25519-key.der"
556
+ #define cliEdCertFile "certs/ed25519/client-ed25519.der"
557
+ #define cliEdKeyFile "certs/ed25519/client-ed25519-priv.der"
558
+ #define cliEdKeyPubFile "certs/ed25519/client-ed25519-key.der"
559
+ #define caEdCertFile "certs/ed25519/ca-ed25519.der"
560
+ #define ed448CertFile "certs/ed448/server-ed448-cert.der"
561
+ #define ed448KeyFile "certs/ed448/server-ed448-priv.der"
562
+ #define cliEd448CertFile "certs/ed448/client-ed448.der"
563
+ #define cliEd448KeyFile "certs/ed448/client-ed448-priv.der"
564
+ #define caEd448CertFile "certs/ed448/ca-ed448.der"
565
+ #define noIssuerCertFile "certs/empty-issuer-cert.der"
566
+ #endif
567
+ #define caCertFolder "certs/"
568
+ #ifdef HAVE_WNR
569
+ /* Whitewood netRandom default config file */
570
+ #define wnrConfig "wnr-example.conf"
571
+ #endif
572
+ #elif defined(NETOS) && defined(HAVE_FIPS)
573
+ /* These defines specify the file system volume and root directory used by
574
+ * the FTP server used in the only supported NETOS FIPS solution (at this
575
+ * time), these can be tailored in the event a future FIPS solution is added
576
+ * for an alternate NETOS use-case */
577
+ #define FS_VOLUME1 "FLASH0"
578
+ #define FS_VOLUME1_DIR FS_VOLUME1 "/"
579
+ #define caCertFile FS_VOLUME1_DIR "certs/ca-cert.pem"
580
+ #define eccCertFile FS_VOLUME1_DIR "certs/server-ecc.pem"
581
+ #define eccKeyFile FS_VOLUME1_DIR "certs/ecc-key.pem"
582
+ #define svrCertFile FS_VOLUME1_DIR "certs/server-cert.pem"
583
+ #define svrKeyFile FS_VOLUME1_DIR "certs/server-key.pem"
584
+ #define cliCertFile FS_VOLUME1_DIR "certs/client-cert.pem"
585
+ #define cliKeyFile FS_VOLUME1_DIR "certs/client-key.pem"
586
+ #define ntruCertFile FS_VOLUME1_DIR "certs/ntru-cert.pem"
587
+ #define ntruKeyFile FS_VOLUME1_DIR "certs/ntru-key.raw"
588
+ #define dhParamFile FS_VOLUME1_DIR "certs/dh2048.pem"
589
+ #define cliEccKeyFile FS_VOLUME1_DIR "certs/ecc-client-key.pem"
590
+ #define cliEccCertFile FS_VOLUME1_DIR "certs/client-ecc-cert.pem"
591
+ #define caEccCertFile FS_VOLUME1_DIR "certs/ca-ecc-cert/pem"
592
+ #define crlPemDir FS_VOLUME1_DIR "certs/crl"
593
+ #ifdef HAVE_WNR
594
+ /* Whitewood netRandom default config file */
595
+ #define wnrConfig "wnr-example.conf"
596
+ #endif
597
+ #else
598
+ #ifdef WOLFSSL_PEM_TO_DER
599
+ #define caCertFile "./certs/ca-cert.pem"
600
+ #define eccCertFile "./certs/server-ecc.pem"
601
+ #define eccKeyFile "./certs/ecc-key.pem"
602
+ #define eccKeyPubFile "./certs/ecc-keyPub.pem"
603
+ #define eccRsaCertFile "./certs/server-ecc-rsa.pem"
604
+ #define svrCertFile "./certs/server-cert.pem"
605
+ #define svrKeyFile "./certs/server-key.pem"
606
+ #define svrKeyPubFile "./certs/server-keyPub.pem"
607
+ #define cliCertFile "./certs/client-cert.pem"
608
+ #define cliCertDerFile "./certs/client-cert.der"
609
+ #define cliCertFileExt "./certs/client-cert-ext.pem"
610
+ #define cliCertDerFileExt "./certs/client-cert-ext.der"
611
+ #define cliKeyFile "./certs/client-key.pem"
612
+ #define cliKeyPubFile "./certs/client-keyPub.pem"
613
+ #define dhParamFile "./certs/dh2048.pem"
614
+ #define cliEccKeyFile "./certs/ecc-client-key.pem"
615
+ #define cliEccKeyPubFile "./certs/ecc-client-keyPub.pem"
616
+ #define cliEccCertFile "./certs/client-ecc-cert.pem"
617
+ #define caEccCertFile "./certs/ca-ecc-cert.pem"
618
+ #define crlPemDir "./certs/crl"
619
+ #define edCertFile "./certs/ed25519/server-ed25519-cert.pem"
620
+ #define edKeyFile "./certs/ed25519/server-ed25519-priv.pem"
621
+ #define edKeyPubFile "./certs/ed25519/server-ed25519-key.pem"
622
+ #define cliEdCertFile "./certs/ed25519/client-ed25519.pem"
623
+ #define cliEdKeyFile "./certs/ed25519/client-ed25519-priv.pem"
624
+ #define cliEdKeyPubFile "./certs/ed25519/client-ed25519-key.pem"
625
+ #define caEdCertFile "./certs/ed25519/ca-ed25519.pem"
626
+ #define ed448CertFile "./certs/ed448/server-ed448-cert.pem"
627
+ #define ed448KeyFile "./certs/ed448/server-ed448-priv.pem"
628
+ #define cliEd448CertFile "./certs/ed448/client-ed448.pem"
629
+ #define cliEd448KeyFile "./certs/ed448/client-ed448-priv.pem"
630
+ #define caEd448CertFile "./certs/ed448/ca-ed448.pem"
631
+ #define noIssuerCertFile "./certs/empty-issuer-cert.pem"
632
+ #else
633
+ #define caCertFile "./certs/ca-cert.der"
634
+ #define eccCertFile "./certs/server-ecc.der"
635
+ #define eccKeyFile "./certs/ecc-key.der"
636
+ #define eccKeyPubFile "./certs/ecc-keyPub.der"
637
+ #define eccRsaCertFile "./certs/server-ecc-rsa.der"
638
+ #define svrCertFile "./certs/server-cert.der"
639
+ #define svrKeyFile "./certs/server-key.der"
640
+ #define svrKeyPubFile "./certs/server-keyPub.der"
641
+ #define cliCertFile "./certs/client-cert.der"
642
+ #define cliCertDerFile "./certs/client-cert.der"
643
+ #define cliCertFileExt "./certs/client-cert-ext.der"
644
+ #define cliCertDerFileExt "./certs/client-cert-ext.der"
645
+ #define cliKeyFile "./certs/client-key.der"
646
+ #define cliKeyPubFile "./certs/client-keyPub.der"
647
+ #define dhParamFile "./certs/dh2048.der"
648
+ #define cliEccKeyFile "./certs/ecc-client-key.der"
649
+ #define cliEccKeyPubFile "./certs/ecc-client-keyPub.der"
650
+ #define cliEccCertFile "./certs/client-ecc-cert.der"
651
+ #define caEccCertFile "./certs/ca-ecc-cert.der"
652
+ #define crlPemDir "./certs/crl"
653
+ #define edCertFile "./certs/ed25519/server-ed25519-cert.der"
654
+ #define edKeyFile "./certs/ed25519/server-ed25519-priv.der"
655
+ #define edKeyPubFile "./certs/ed25519/server-ed25519-key.der"
656
+ #define cliEdCertFile "./certs/ed25519/client-ed25519.der"
657
+ #define cliEdKeyFile "./certs/ed25519/client-ed25519-priv.der"
658
+ #define cliEdKeyPubFile "./certs/ed25519/client-ed25519-key.der"
659
+ #define caEdCertFile "./certs/ed25519/ca-ed25519.der"
660
+ #define ed448CertFile "./certs/ed448/server-ed448-cert.der"
661
+ #define ed448KeyFile "./certs/ed448/server-ed448-priv.der"
662
+ #define cliEd448CertFile "./certs/ed448/client-ed448.der"
663
+ #define cliEd448KeyFile "./certs/ed448/client-ed448-priv.der"
664
+ #define caEd448CertFile "./certs/ed448/ca-ed448.der"
665
+ #define noIssuerCertFile "./certs/empty-issuer-cert.der"
666
+ #endif
667
+ #define caCertFolder "./certs/"
668
+ #ifdef HAVE_WNR
669
+ /* Whitewood netRandom default config file */
670
+ #define wnrConfig "./wnr-example.conf"
671
+ #endif
672
+ #endif
673
+
674
+ #ifdef WOLFSSL_PEM_TO_DER
675
+ #define CERT_FILETYPE WOLFSSL_FILETYPE_PEM
676
+ #else
677
+ #define CERT_FILETYPE WOLFSSL_FILETYPE_ASN1
678
+ #endif
679
+
680
+ #ifdef TEST_IPV6
681
+ typedef struct sockaddr_in6 SOCKADDR_IN_T;
682
+ #define AF_INET_V AF_INET6
683
+ #else
684
+ typedef struct sockaddr_in SOCKADDR_IN_T;
685
+ #define AF_INET_V AF_INET
686
+ #endif
687
+
688
+ typedef struct tcp_ready {
689
+ word16 ready; /* predicate */
690
+ word16 port;
691
+ char* srfName; /* server ready file name */
692
+ #ifndef SINGLE_THREADED
693
+ #ifdef WOLFSSL_COND
694
+ wolfSSL_Mutex mutex;
695
+ COND_TYPE cond;
696
+ #else /* No signaling available, rely only on the mutex */
697
+ wolfSSL_Mutex mutex;
698
+ #endif
699
+ #endif
700
+ } tcp_ready;
701
+
702
+ static WC_INLINE void InitTcpReady(tcp_ready* ready)
703
+ {
704
+ ready->ready = 0;
705
+ ready->port = 0;
706
+ ready->srfName = NULL;
707
+
708
+ #ifndef SINGLE_THREADED
709
+ THREAD_CHECK_RET(wc_InitMutex(&ready->mutex));
710
+ #ifdef WOLFSSL_COND
711
+ THREAD_CHECK_RET(wolfSSL_CondInit(&ready->cond));
712
+ #endif
713
+ #endif
714
+ }
715
+
716
+ #ifdef NETOS
717
+ struct hostent* gethostbyname(const char* name);
718
+ #endif
719
+
720
+ static WC_INLINE void FreeTcpReady(tcp_ready* ready)
721
+ {
722
+ #ifndef SINGLE_THREADED
723
+ THREAD_CHECK_RET(wc_FreeMutex(&ready->mutex));
724
+ #ifdef WOLFSSL_COND
725
+ THREAD_CHECK_RET(wolfSSL_CondFree(&ready->cond));
726
+ #endif
727
+ #else
728
+ (void)ready;
729
+ #endif
730
+ }
731
+
732
+ typedef WOLFSSL_METHOD* (*method_provider)(void);
733
+ typedef void (*ctx_callback)(WOLFSSL_CTX* ctx);
734
+ typedef void (*ssl_callback)(WOLFSSL* ssl);
735
+
736
+ typedef struct callback_functions {
737
+ method_provider method;
738
+ ctx_callback ctx_ready;
739
+ ssl_callback ssl_ready;
740
+ ssl_callback on_result;
741
+ ssl_callback on_cleanup;
742
+ WOLFSSL_CTX* ctx;
743
+ const char* caPemFile;
744
+ const char* certPemFile;
745
+ const char* keyPemFile;
746
+ const char* crlPemFile;
747
+ #ifdef WOLFSSL_STATIC_MEMORY
748
+ byte* mem;
749
+ word32 memSz;
750
+ wolfSSL_method_func method_ex;
751
+ #endif
752
+ int devId;
753
+ int return_code;
754
+ int last_err;
755
+ unsigned char isSharedCtx:1;
756
+ unsigned char loadToSSL:1;
757
+ unsigned char ticNoInit:1;
758
+ unsigned char doUdp:1;
759
+ } callback_functions;
760
+
761
+ #if defined(WOLFSSL_SRTP) && defined(WOLFSSL_COND)
762
+ typedef struct srtp_test_helper {
763
+ wolfSSL_Mutex mutex;
764
+ COND_TYPE cond;
765
+ uint8_t* server_srtp_ekm;
766
+ size_t server_srtp_ekm_size;
767
+ } srtp_test_helper;
768
+ #endif /* WOLFSSL_SRTP WOLFSSL_COND */
769
+
770
+ typedef struct func_args {
771
+ int argc;
772
+ char** argv;
773
+ int return_code;
774
+ tcp_ready* signal;
775
+ callback_functions *callbacks;
776
+ #if defined(WOLFSSL_SRTP) && defined(WOLFSSL_COND)
777
+ srtp_test_helper* srtp_helper;
778
+ #endif
779
+ } func_args;
780
+
781
+ #ifdef NETOS
782
+ int dc_log_printf(char* format, ...);
783
+ #undef printf
784
+ #define printf dc_log_printf
785
+ #endif
786
+
787
+ void wait_tcp_ready(func_args* args);
788
+
789
+ #ifndef SINGLE_THREADED
790
+ void start_thread(THREAD_CB fun, func_args* args, THREAD_TYPE* thread);
791
+ void join_thread(THREAD_TYPE thread);
792
+ #endif
793
+
794
+ typedef int (*cbType)(WOLFSSL_CTX *ctx, WOLFSSL *ssl);
795
+
796
+ void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
797
+ callback_functions* server_cb, cbType client_on_handshake);
798
+ void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
799
+ callback_functions* server_cb);
800
+
801
+
802
+ #if defined(__MACH__) || defined(__FreeBSD__)
803
+ int link_file(const char* in, const char* out);
804
+ #define STAGE_FILE(x,y) link_file((x),(y))
805
+ #else
806
+ #define STAGE_FILE(x,y) copy_file((x),(y))
807
+ #endif
808
+
809
+ void signal_ready(tcp_ready* ready);
810
+
811
+ /* wolfSSL */
812
+ #ifndef TEST_IPV6
813
+ static const char* const wolfSSLIP = "127.0.0.1";
814
+ #else
815
+ static const char* const wolfSSLIP = "::1";
816
+ #endif
817
+ static const word16 wolfSSLPort = 11111;
818
+
819
+
820
+ extern int myoptind;
821
+ extern char* myoptarg;
822
+
823
+ #if defined(WOLFSSL_SRTP) && defined(WOLFSSL_COND)
824
+
825
+ static WC_INLINE void srtp_helper_init(srtp_test_helper *srtp)
826
+ {
827
+ srtp->server_srtp_ekm_size = 0;
828
+ srtp->server_srtp_ekm = NULL;
829
+
830
+ THREAD_CHECK_RET(wc_InitMutex(&srtp->mutex));
831
+ THREAD_CHECK_RET(wolfSSL_CondInit(&srtp->cond));
832
+ }
833
+
834
+ /**
835
+ * strp_helper_get_ekm() - get exported key material of other peer
836
+ * @srtp: srtp_test_helper struct shared with other peer [in]
837
+ * @ekm: where to store the shared buffer pointer [out]
838
+ * @size: size of the shared buffer returned [out]
839
+ *
840
+ * This function wait that the other peer calls strp_helper_set_ekm() and then
841
+ * store the buffer pointer/size in @ekm and @size.
842
+ */
843
+ static WC_INLINE void srtp_helper_get_ekm(srtp_test_helper *srtp,
844
+ uint8_t **ekm, size_t *size)
845
+ {
846
+ THREAD_CHECK_RET(wolfSSL_CondStart(&srtp->cond));
847
+ if (srtp->server_srtp_ekm == NULL) {
848
+ THREAD_CHECK_RET(wolfSSL_CondWait(&srtp->cond));
849
+ }
850
+ *ekm = srtp->server_srtp_ekm;
851
+ *size = srtp->server_srtp_ekm_size;
852
+
853
+ /* reset */
854
+ srtp->server_srtp_ekm = NULL;
855
+ srtp->server_srtp_ekm_size = 0;
856
+ THREAD_CHECK_RET(wolfSSL_CondEnd(&srtp->cond));
857
+ }
858
+
859
+ /**
860
+ * strp_helper_set_ekm() - set exported key material of other peer
861
+ * @srtp: srtp_test_helper struct shared with other peer [in]
862
+ * @ekm: pointer to the shared buffer [in]
863
+ * @size: size of the shared buffer [in]
864
+ *
865
+ * This function set the @ekm and wakes up a peer waiting in
866
+ * srtp_helper_get_ekm().
867
+ *
868
+ * used in client_srtp_test()/server_srtp_test()
869
+ */
870
+ static WC_INLINE void srtp_helper_set_ekm(srtp_test_helper *srtp,
871
+ uint8_t *ekm, size_t size)
872
+ {
873
+ THREAD_CHECK_RET(wolfSSL_CondStart(&srtp->cond));
874
+ srtp->server_srtp_ekm_size = size;
875
+ srtp->server_srtp_ekm = ekm;
876
+ THREAD_CHECK_RET(wolfSSL_CondSignal(&srtp->cond));
877
+ THREAD_CHECK_RET(wolfSSL_CondEnd(&srtp->cond));
878
+ }
879
+
880
+ static WC_INLINE void srtp_helper_free(srtp_test_helper *srtp)
881
+ {
882
+ THREAD_CHECK_RET(wc_FreeMutex(&srtp->mutex));
883
+ THREAD_CHECK_RET(wolfSSL_CondFree(&srtp->cond));
884
+ }
885
+
886
+ #endif /* WOLFSSL_SRTP && WOLFSSL_COND */
887
+
888
+
889
+ /**
890
+ *
891
+ * @param argc Number of argv strings
892
+ * @param argv Array of string arguments
893
+ * @param optstring String containing the supported alphanumeric arguments.
894
+ * A ':' following a character means that it requires a
895
+ * value in myoptarg to be set. A ';' means that the
896
+ * myoptarg is optional. myoptarg is set to "" if not
897
+ * present.
898
+ * @return Option letter in argument
899
+ */
900
+ static WC_INLINE int mygetopt(int argc, char** argv, const char* optstring)
901
+ {
902
+ static char* next = NULL;
903
+
904
+ char c;
905
+ char* cp;
906
+
907
+ /* Added sanity check because scan-build complains argv[myoptind] access
908
+ * results in a null pointer dereference. */
909
+ if (argv == NULL) {
910
+ myoptarg = NULL;
911
+ return -1;
912
+ }
913
+
914
+ if (myoptind == 0)
915
+ next = NULL; /* we're starting new/over */
916
+
917
+ if (next == NULL || *next == '\0') {
918
+ if (myoptind == 0)
919
+ myoptind++;
920
+
921
+ if (myoptind >= argc || argv[myoptind] == NULL ||
922
+ argv[myoptind][0] != '-' || argv[myoptind][1] == '\0') {
923
+ myoptarg = NULL;
924
+ if (myoptind < argc)
925
+ myoptarg = argv[myoptind];
926
+
927
+ return -1;
928
+ }
929
+
930
+ if (strcmp(argv[myoptind], "--") == 0) {
931
+ myoptind++;
932
+ myoptarg = NULL;
933
+
934
+ if (myoptind < argc)
935
+ myoptarg = argv[myoptind];
936
+
937
+ return -1;
938
+ }
939
+
940
+ next = argv[myoptind];
941
+ next++; /* skip - */
942
+ myoptind++;
943
+ }
944
+
945
+ c = *next++;
946
+ /* The C++ strchr can return a different value */
947
+ cp = (char*)strchr(optstring, c);
948
+
949
+ if (cp == NULL || c == ':' || c == ';')
950
+ return '?';
951
+
952
+ cp++;
953
+
954
+ if (*cp == ':') {
955
+ if (*next != '\0') {
956
+ myoptarg = next;
957
+ next = NULL;
958
+ }
959
+ else if (myoptind < argc) {
960
+ myoptarg = argv[myoptind];
961
+ myoptind++;
962
+ }
963
+ else
964
+ return '?';
965
+ }
966
+ else if (*cp == ';') {
967
+ myoptarg = (char*)"";
968
+ if (*next != '\0') {
969
+ myoptarg = next;
970
+ next = NULL;
971
+ }
972
+ else if (myoptind < argc) {
973
+ /* Check if next argument is not a parameter argument */
974
+ if (argv[myoptind] && argv[myoptind][0] != '-') {
975
+ myoptarg = argv[myoptind];
976
+ myoptind++;
977
+ }
978
+ }
979
+ }
980
+
981
+ return c;
982
+ }
983
+
984
+ struct mygetopt_long_config {
985
+ const char *name;
986
+ int takes_arg; /* 0=no arg, 1=required arg, 2=optional arg */
987
+ int value;
988
+ };
989
+
990
+ /**
991
+ *
992
+ * @param argc Number of argv strings
993
+ * @param argv Array of string arguments
994
+ * @param optstring String containing the supported alphanumeric arguments.
995
+ * A ':' following a character means that it requires a
996
+ * value in myoptarg to be set. A ';' means that the
997
+ * myoptarg is optional. myoptarg is set to "" if not
998
+ * present.
999
+ * @return Option letter in argument
1000
+ */
1001
+ static WC_INLINE int mygetopt_long(int argc, char** argv, const char* optstring,
1002
+ const struct mygetopt_long_config *longopts, int *longindex)
1003
+ {
1004
+ static char* next = NULL;
1005
+
1006
+ int c;
1007
+ char* cp;
1008
+
1009
+ /* Added sanity check because scan-build complains argv[myoptind] access
1010
+ * results in a null pointer dereference. */
1011
+ if (argv == NULL) {
1012
+ myoptarg = NULL;
1013
+ return -1;
1014
+ }
1015
+
1016
+ if (myoptind == 0)
1017
+ next = NULL; /* we're starting new/over */
1018
+
1019
+ if (next == NULL || *next == '\0') {
1020
+ if (myoptind == 0)
1021
+ myoptind++;
1022
+
1023
+ if (myoptind >= argc || argv[myoptind] == NULL ||
1024
+ argv[myoptind][0] != '-' || argv[myoptind][1] == '\0') {
1025
+ myoptarg = NULL;
1026
+ if (myoptind < argc)
1027
+ myoptarg = argv[myoptind];
1028
+
1029
+ return -1;
1030
+ }
1031
+
1032
+ if (strcmp(argv[myoptind], "--") == 0) {
1033
+ myoptind++;
1034
+ myoptarg = NULL;
1035
+
1036
+ if (myoptind < argc)
1037
+ myoptarg = argv[myoptind];
1038
+
1039
+ return -1;
1040
+ }
1041
+
1042
+ if (strncmp(argv[myoptind], "--", 2) == 0) {
1043
+ const struct mygetopt_long_config *i;
1044
+ c = -1;
1045
+ myoptarg = NULL;
1046
+ for (i = longopts; i->name; ++i) {
1047
+ if (! strcmp(argv[myoptind] + 2, i->name)) {
1048
+ c = i->value;
1049
+ myoptind++;
1050
+ if (longindex)
1051
+ *longindex = (int)((size_t)(i - longopts) / sizeof i[0]);
1052
+ if (i->takes_arg) {
1053
+ if (myoptind < argc) {
1054
+ if (i->takes_arg == 1 || argv[myoptind][0] != '-') {
1055
+ myoptarg = argv[myoptind];
1056
+ myoptind++;
1057
+ }
1058
+ } else if (i->takes_arg != 2) {
1059
+ return -1;
1060
+ }
1061
+ }
1062
+ break;
1063
+ }
1064
+ }
1065
+
1066
+ return c;
1067
+ }
1068
+
1069
+ next = argv[myoptind];
1070
+ next++; /* skip - */
1071
+ myoptind++;
1072
+ }
1073
+
1074
+ c = (int)(unsigned char)*next++;
1075
+ /* The C++ strchr can return a different value */
1076
+ cp = (char*)strchr(optstring, c);
1077
+
1078
+ if (cp == NULL || c == ':' || c == ';')
1079
+ return '?';
1080
+
1081
+ cp++;
1082
+
1083
+ if (*cp == ':') {
1084
+ if (*next != '\0') {
1085
+ myoptarg = next;
1086
+ next = NULL;
1087
+ }
1088
+ else if (myoptind < argc) {
1089
+ myoptarg = argv[myoptind];
1090
+ myoptind++;
1091
+ }
1092
+ else
1093
+ return '?';
1094
+ }
1095
+ else if (*cp == ';') {
1096
+ myoptarg = (char*)"";
1097
+ if (*next != '\0') {
1098
+ myoptarg = next;
1099
+ next = NULL;
1100
+ }
1101
+ else if (myoptind < argc) {
1102
+ /* Check if next argument is not a parameter argument */
1103
+ if (argv[myoptind] && argv[myoptind][0] != '-') {
1104
+ myoptarg = argv[myoptind];
1105
+ myoptind++;
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ return c;
1111
+ }
1112
+
1113
+
1114
+ #ifdef WOLFSSL_ENCRYPTED_KEYS
1115
+
1116
+ static WC_INLINE int PasswordCallBack(char* passwd, int sz, int rw, void* userdata)
1117
+ {
1118
+ (void)rw;
1119
+ (void)userdata;
1120
+ if (userdata != NULL) {
1121
+ strncpy(passwd, (char*)userdata, (size_t) sz);
1122
+ return (int)XSTRLEN((char*)userdata);
1123
+ }
1124
+ else {
1125
+ strncpy(passwd, "yassl123", (size_t) sz);
1126
+ return 8;
1127
+ }
1128
+ }
1129
+
1130
+ #endif
1131
+
1132
+ static const char* client_showpeer_msg[][9] = {
1133
+ /* English */
1134
+ {
1135
+ "SSL version is",
1136
+ "SSL cipher suite is",
1137
+ "SSL signature algorithm is",
1138
+ "SSL curve name is",
1139
+ "SSL DH size is",
1140
+ "SSL reused session",
1141
+ "Alternate cert chain used",
1142
+ "peer's cert info:",
1143
+ NULL
1144
+ },
1145
+ #ifndef NO_MULTIBYTE_PRINT
1146
+ /* Japanese */
1147
+ {
1148
+ "SSL バージョンは",
1149
+ "SSL 暗号スイートは",
1150
+ "SSL signature algorithm is",
1151
+ "SSL 曲線名は",
1152
+ "SSL DH サイズは",
1153
+ "SSL 再利用セッション",
1154
+ "代替証明チェーンを使用",
1155
+ "相手方証明書情報",
1156
+ NULL
1157
+ },
1158
+ #endif
1159
+ };
1160
+
1161
+ #if defined(KEEP_PEER_CERT) || defined(KEEP_OUR_CERT) || defined(SESSION_CERTS)
1162
+ static const char* client_showx509_msg[][5] = {
1163
+ /* English */
1164
+ {
1165
+ "issuer",
1166
+ "subject",
1167
+ "altname",
1168
+ "serial number",
1169
+ NULL
1170
+ },
1171
+ #ifndef NO_MULTIBYTE_PRINT
1172
+ /* Japanese */
1173
+ {
1174
+ "発行者",
1175
+ "サブジェクト",
1176
+ "代替名",
1177
+ "シリアル番号",
1178
+ NULL
1179
+ },
1180
+ #endif
1181
+ };
1182
+
1183
+ /* lng_index is to specify the language for displaying message. */
1184
+ /* 0:English, 1:Japanese */
1185
+ static WC_INLINE void ShowX509Ex(WOLFSSL_X509* x509, const char* hdr,
1186
+ int lng_index)
1187
+ {
1188
+ char* altName;
1189
+ char* issuer;
1190
+ char* subject;
1191
+ byte serial[32];
1192
+ int ret;
1193
+ int sz = sizeof(serial);
1194
+ const char** words = client_showx509_msg[lng_index];
1195
+
1196
+ if (x509 == NULL) {
1197
+ fprintf(stderr, "%s No Cert\n", hdr);
1198
+ return;
1199
+ }
1200
+
1201
+ issuer = wolfSSL_X509_NAME_oneline(
1202
+ wolfSSL_X509_get_issuer_name(x509), 0, 0);
1203
+ subject = wolfSSL_X509_NAME_oneline(
1204
+ wolfSSL_X509_get_subject_name(x509), 0, 0);
1205
+
1206
+ printf("%s\n %s : %s\n %s: %s\n", hdr, words[0], issuer, words[1], subject);
1207
+
1208
+ while ( (altName = wolfSSL_X509_get_next_altname(x509)) != NULL)
1209
+ printf(" %s = %s\n", words[2], altName);
1210
+
1211
+ ret = wolfSSL_X509_get_serial_number(x509, serial, &sz);
1212
+ if (ret == WOLFSSL_SUCCESS) {
1213
+ int i;
1214
+ int strLen;
1215
+ char serialMsg[80];
1216
+
1217
+ /* testsuite has multiple threads writing to stdout, get output
1218
+ * message ready to write once */
1219
+ strLen = XSNPRINTF(serialMsg, sizeof(serialMsg), " %s", words[3]);
1220
+ for (i = 0; i < sz; i++)
1221
+ strLen = XSNPRINTF(serialMsg + strLen,
1222
+ sizeof(serialMsg) - (size_t)strLen, ":%02x ", serial[i]);
1223
+ printf("%s\n", serialMsg);
1224
+ }
1225
+
1226
+ XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
1227
+ XFREE(issuer, 0, DYNAMIC_TYPE_OPENSSL);
1228
+
1229
+ #if defined(SHOW_CERTS) && defined(OPENSSL_EXTRA)
1230
+ {
1231
+ WOLFSSL_BIO* bio;
1232
+ char buf[WC_ASN_NAME_MAX];
1233
+ int textSz;
1234
+
1235
+ /* print out domain component if certificate has it */
1236
+ textSz = wolfSSL_X509_NAME_get_text_by_NID(
1237
+ wolfSSL_X509_get_subject_name(x509), NID_domainComponent,
1238
+ buf, sizeof(buf));
1239
+ if (textSz > 0) {
1240
+ printf("Domain Component = %s\n", buf);
1241
+ }
1242
+
1243
+ bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
1244
+ if (bio != NULL) {
1245
+ wolfSSL_BIO_set_fp(bio, stdout, BIO_NOCLOSE);
1246
+ wolfSSL_X509_print(bio, x509);
1247
+ wolfSSL_BIO_free(bio);
1248
+ }
1249
+ }
1250
+ #endif /* SHOW_CERTS && OPENSSL_EXTRA */
1251
+ }
1252
+ /* original ShowX509 to maintain compatibility */
1253
+ static WC_INLINE void ShowX509(WOLFSSL_X509* x509, const char* hdr)
1254
+ {
1255
+ ShowX509Ex(x509, hdr, 0);
1256
+ }
1257
+
1258
+ #endif /* KEEP_PEER_CERT || KEEP_OUR_CERT || SESSION_CERTS */
1259
+
1260
+ #if defined(SHOW_CERTS) && defined(SESSION_CERTS) && \
1261
+ (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
1262
+ static WC_INLINE void ShowX509Chain(WOLFSSL_X509_CHAIN* chain, int count,
1263
+ const char* hdr)
1264
+ {
1265
+ int i;
1266
+ int length;
1267
+ unsigned char certPem[3072];
1268
+ WOLFSSL_X509* chainX509;
1269
+
1270
+ for (i = 0; i < count; i++) {
1271
+ wolfSSL_get_chain_cert_pem(chain, i, certPem, sizeof(certPem), &length);
1272
+ certPem[length] = 0;
1273
+ printf("\n%s: %d has length %d data = \n%s\n", hdr, i, length, certPem);
1274
+
1275
+ chainX509 = wolfSSL_get_chain_X509(chain, i);
1276
+ if (chainX509)
1277
+ ShowX509(chainX509, hdr);
1278
+ else
1279
+ fprintf(stderr, "get_chain_X509 failed\n");
1280
+ wolfSSL_FreeX509(chainX509);
1281
+ }
1282
+ }
1283
+ #endif /* SHOW_CERTS && SESSION_CERTS */
1284
+
1285
+ /* lng_index is to specify the language for displaying message. */
1286
+ /* 0:English, 1:Japanese */
1287
+ static WC_INLINE void showPeerEx(WOLFSSL* ssl, int lng_index)
1288
+ {
1289
+ WOLFSSL_CIPHER* cipher;
1290
+ const char** words = client_showpeer_msg[lng_index];
1291
+
1292
+ #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) || \
1293
+ !defined(NO_DH)
1294
+ const char *name;
1295
+ #endif
1296
+ #ifndef NO_DH
1297
+ int bits;
1298
+ #endif
1299
+ #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
1300
+ int nid;
1301
+ #endif
1302
+ #ifdef KEEP_PEER_CERT
1303
+ WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
1304
+ if (peer)
1305
+ ShowX509Ex(peer, words[6], lng_index);
1306
+ else
1307
+ fprintf(stderr, "peer has no cert!\n");
1308
+ wolfSSL_FreeX509(peer);
1309
+ #endif
1310
+ #if defined(SHOW_CERTS) && defined(KEEP_OUR_CERT) && \
1311
+ (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
1312
+ ShowX509(wolfSSL_get_certificate(ssl), "our cert info:");
1313
+ printf("Peer verify result = %ld\n", wolfSSL_get_verify_result(ssl));
1314
+ #endif /* SHOW_CERTS && KEEP_OUR_CERT */
1315
+ printf("%s %s\n", words[0], wolfSSL_get_version(ssl));
1316
+
1317
+ cipher = wolfSSL_get_current_cipher(ssl);
1318
+ printf("%s %s\n", words[1], wolfSSL_CIPHER_get_name(cipher));
1319
+ #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
1320
+ if (wolfSSL_get_signature_nid(ssl, &nid) == WOLFSSL_SUCCESS) {
1321
+ printf("%s %s\n", words[2], OBJ_nid2sn(nid));
1322
+ }
1323
+ #endif
1324
+ #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) || \
1325
+ !defined(NO_DH)
1326
+ if ((name = wolfSSL_get_curve_name(ssl)) != NULL)
1327
+ printf("%s %s\n", words[3], name);
1328
+ #endif
1329
+ #ifndef NO_DH
1330
+ else if ((bits = wolfSSL_GetDhKey_Sz(ssl)) > 0)
1331
+ printf("%s %d bits\n", words[4], bits);
1332
+ #endif
1333
+ if (wolfSSL_session_reused(ssl))
1334
+ printf("%s\n", words[5]);
1335
+ #ifdef WOLFSSL_ALT_CERT_CHAINS
1336
+ if (wolfSSL_is_peer_alt_cert_chain(ssl))
1337
+ printf("%s\n", words[6]);
1338
+ #endif
1339
+
1340
+ #if defined(SHOW_CERTS) && defined(SESSION_CERTS) && \
1341
+ (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
1342
+ {
1343
+ WOLFSSL_X509_CHAIN* chain;
1344
+
1345
+ chain = wolfSSL_get_peer_chain(ssl);
1346
+ ShowX509Chain(chain, wolfSSL_get_chain_count(chain), "session cert");
1347
+
1348
+ #ifdef WOLFSSL_ALT_CERT_CHAINS
1349
+ if (wolfSSL_is_peer_alt_cert_chain(ssl)) {
1350
+ chain = wolfSSL_get_peer_alt_chain(ssl);
1351
+ ShowX509Chain(chain, wolfSSL_get_chain_count(chain), "alt cert");
1352
+ }
1353
+ #endif
1354
+ }
1355
+ #endif /* SHOW_CERTS && SESSION_CERTS */
1356
+ (void)ssl;
1357
+ }
1358
+ /* original showPeer to maintain compatibility */
1359
+ static WC_INLINE void showPeer(WOLFSSL* ssl)
1360
+ {
1361
+ showPeerEx(ssl, 0);
1362
+ }
1363
+
1364
+ static WC_INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer,
1365
+ word16 port, int udp, int sctp)
1366
+ {
1367
+ int useLookup = 0;
1368
+ (void)useLookup;
1369
+ (void)udp;
1370
+ (void)sctp;
1371
+
1372
+ if (addr == NULL) {
1373
+ err_sys("invalid argument to build_addr, addr is NULL");
1374
+ return;
1375
+ }
1376
+
1377
+ XMEMSET(addr, 0, sizeof(SOCKADDR_IN_T));
1378
+
1379
+ #ifndef TEST_IPV6
1380
+ /* peer could be in human readable form */
1381
+ if ( ((size_t)peer != INADDR_ANY) && isalpha((unsigned char)peer[0])) {
1382
+ #if !defined(WOLFSSL_USE_GETADDRINFO)
1383
+ #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
1384
+ int err;
1385
+ struct hostent* entry = gethostbyname(peer, &err);
1386
+ #elif defined(WOLFSSL_TIRTOS)
1387
+ struct hostent* entry = (struct hostent*)DNSGetHostByName(peer);
1388
+ #elif defined(WOLFSSL_VXWORKS)
1389
+ struct hostent* entry = (struct hostent*)hostGetByName((char*)peer);
1390
+ #else
1391
+ struct hostent* entry = gethostbyname(peer);
1392
+ #endif
1393
+
1394
+ if (entry) {
1395
+ XMEMCPY(&addr->sin_addr.s_addr, entry->h_addr_list[0],
1396
+ (size_t) entry->h_length);
1397
+ useLookup = 1;
1398
+ }
1399
+ #else
1400
+ struct zsock_addrinfo hints, *addrInfo;
1401
+ char portStr[6];
1402
+ XSNPRINTF(portStr, sizeof(portStr), "%d", port);
1403
+ XMEMSET(&hints, 0, sizeof(hints));
1404
+ hints.ai_family = AF_UNSPEC;
1405
+ hints.ai_socktype = udp ? SOCK_DGRAM : SOCK_STREAM;
1406
+ hints.ai_protocol = udp ? IPPROTO_UDP : IPPROTO_TCP;
1407
+ if (getaddrinfo((char*)peer, portStr, &hints, &addrInfo) == 0) {
1408
+ XMEMCPY(addr, addrInfo->ai_addr, sizeof(*addr));
1409
+ useLookup = 1;
1410
+ }
1411
+ #endif
1412
+ else
1413
+ err_sys("no entry for host");
1414
+ }
1415
+ #endif
1416
+
1417
+
1418
+ #ifndef TEST_IPV6
1419
+ #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
1420
+ addr->sin_family = PF_INET;
1421
+ #else
1422
+ addr->sin_family = AF_INET_V;
1423
+ #endif
1424
+ addr->sin_port = XHTONS(port);
1425
+ if ((size_t)peer == INADDR_ANY)
1426
+ addr->sin_addr.s_addr = INADDR_ANY;
1427
+ else {
1428
+ if (!useLookup)
1429
+ addr->sin_addr.s_addr = inet_addr(peer);
1430
+ }
1431
+ #else
1432
+ addr->sin6_family = AF_INET_V;
1433
+ addr->sin6_port = XHTONS(port);
1434
+ if ((size_t)peer == INADDR_ANY) {
1435
+ addr->sin6_addr = in6addr_any;
1436
+ }
1437
+ else {
1438
+ #if defined(HAVE_GETADDRINFO)
1439
+ struct addrinfo hints;
1440
+ struct addrinfo* answer = NULL;
1441
+ int ret;
1442
+ char strPort[80];
1443
+
1444
+ XMEMSET(&hints, 0, sizeof(hints));
1445
+
1446
+ hints.ai_family = AF_INET_V;
1447
+ if (udp) {
1448
+ hints.ai_socktype = SOCK_DGRAM;
1449
+ hints.ai_protocol = IPPROTO_UDP;
1450
+ }
1451
+ #ifdef WOLFSSL_SCTP
1452
+ else if (sctp) {
1453
+ hints.ai_socktype = SOCK_STREAM;
1454
+ hints.ai_protocol = IPPROTO_SCTP;
1455
+ }
1456
+ #endif
1457
+ else {
1458
+ hints.ai_socktype = SOCK_STREAM;
1459
+ hints.ai_protocol = IPPROTO_TCP;
1460
+ }
1461
+
1462
+ (void)SNPRINTF(strPort, sizeof(strPort), "%d", port);
1463
+ strPort[79] = '\0';
1464
+
1465
+ ret = getaddrinfo(peer, strPort, &hints, &answer);
1466
+ if (ret < 0 || answer == NULL)
1467
+ err_sys("getaddrinfo failed");
1468
+
1469
+ XMEMCPY(addr, answer->ai_addr, answer->ai_addrlen);
1470
+ freeaddrinfo(answer);
1471
+ #else
1472
+ printf("no ipv6 getaddrinfo, loopback only tests/examples\n");
1473
+ addr->sin6_addr = in6addr_loopback;
1474
+ #endif
1475
+ }
1476
+ #endif
1477
+ }
1478
+
1479
+
1480
+ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp)
1481
+ {
1482
+ (void)sctp;
1483
+
1484
+ if (udp)
1485
+ *sockfd = socket(AF_INET_V, SOCK_DGRAM, IPPROTO_UDP);
1486
+ #ifdef WOLFSSL_SCTP
1487
+ else if (sctp)
1488
+ *sockfd = socket(AF_INET_V, SOCK_STREAM, IPPROTO_SCTP);
1489
+ #endif
1490
+ else
1491
+ *sockfd = socket(AF_INET_V, SOCK_STREAM, IPPROTO_TCP);
1492
+
1493
+ if(WOLFSSL_SOCKET_IS_INVALID(*sockfd)) {
1494
+ err_sys_with_errno("socket failed\n");
1495
+ }
1496
+
1497
+ #if !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && !defined(__OS2__)
1498
+ #ifdef SO_NOSIGPIPE
1499
+ {
1500
+ int on = 1;
1501
+ socklen_t len = sizeof(on);
1502
+ int res = setsockopt(*sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, len);
1503
+ if (res < 0)
1504
+ err_sys_with_errno("setsockopt SO_NOSIGPIPE failed\n");
1505
+ }
1506
+ #elif defined(WOLFSSL_MDK_ARM) || defined (WOLFSSL_TIRTOS) ||\
1507
+ defined(WOLFSSL_KEIL_TCP_NET) || defined(WOLFSSL_ZEPHYR)
1508
+ /* nothing to define */
1509
+ #elif defined(NETOS)
1510
+ /* TODO: signal(SIGPIPE, SIG_IGN); */
1511
+ #else /* no S_NOSIGPIPE */
1512
+ signal(SIGPIPE, SIG_IGN);
1513
+ #endif /* S_NOSIGPIPE */
1514
+
1515
+ #if defined(TCP_NODELAY)
1516
+ if (!udp && !sctp)
1517
+ {
1518
+ int on = 1;
1519
+ socklen_t len = sizeof(on);
1520
+ int res = setsockopt(*sockfd, IPPROTO_TCP, TCP_NODELAY, &on, len);
1521
+ if (res < 0)
1522
+ err_sys_with_errno("setsockopt TCP_NODELAY failed\n");
1523
+ }
1524
+ #endif
1525
+ #endif /* !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && ... */
1526
+ }
1527
+
1528
+ #if defined(WOLFSSL_WOLFSENTRY_HOOKS) && defined(WOLFSENTRY_H)
1529
+
1530
+ #include <wolfsentry/wolfssl_test.h>
1531
+
1532
+ #else /* !WOLFSSL_WOLFSENTRY_HOOKS */
1533
+
1534
+ static WC_INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port,
1535
+ int udp, int sctp, WOLFSSL* ssl)
1536
+ {
1537
+ SOCKADDR_IN_T addr;
1538
+ fprintf(stderr, "connecting to %s:%d\n", ip, port);
1539
+ build_addr(&addr, ip, port, udp, sctp);
1540
+ if (udp) {
1541
+ wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
1542
+ }
1543
+ tcp_socket(sockfd, udp, sctp);
1544
+
1545
+ if (!udp) {
1546
+ if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) {
1547
+ perror("connect");
1548
+ err_sys_with_errno("tcp connect failed");
1549
+ }
1550
+ }
1551
+ }
1552
+
1553
+ #endif /* WOLFSSL_WOLFSENTRY_HOOKS */
1554
+
1555
+
1556
+ static WC_INLINE void udp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
1557
+ {
1558
+ SOCKADDR_IN_T addr;
1559
+ build_addr(&addr, ip, port, 1, 0);
1560
+ if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
1561
+ err_sys_with_errno("udp connect failed");
1562
+ }
1563
+
1564
+
1565
+ enum {
1566
+ TEST_SELECT_FAIL,
1567
+ TEST_TIMEOUT,
1568
+ TEST_RECV_READY,
1569
+ TEST_SEND_READY,
1570
+ TEST_ERROR_READY
1571
+ };
1572
+
1573
+
1574
+ #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && \
1575
+ !defined(WOLFSSL_TIRTOS)
1576
+ static WC_INLINE int tcp_select_ex(SOCKET_T socketfd, int to_sec, int rx)
1577
+ {
1578
+ fd_set fds, errfds;
1579
+ fd_set* recvfds = NULL;
1580
+ fd_set* sendfds = NULL;
1581
+ SOCKET_T nfds = socketfd + 1;
1582
+ #if !defined(__INTEGRITY) && !defined(__WATCOMC__)
1583
+ struct timeval timeout = {(to_sec > 0) ? to_sec : 0, 0};
1584
+ #else
1585
+ struct timeval timeout;
1586
+ #endif
1587
+ int result;
1588
+
1589
+ FD_ZERO(&fds);
1590
+ FD_SET(socketfd, &fds);
1591
+ FD_ZERO(&errfds);
1592
+ FD_SET(socketfd, &errfds);
1593
+
1594
+ if (rx)
1595
+ recvfds = &fds;
1596
+ else
1597
+ sendfds = &fds;
1598
+
1599
+ #if defined(__INTEGRITY) || defined(__WATCOMC__)
1600
+ timeout.tv_sec = (long long)(to_sec > 0) ? to_sec : 0;
1601
+ timeout.tv_usec = 0;
1602
+ #endif
1603
+ result = select(nfds, recvfds, sendfds, &errfds, &timeout);
1604
+
1605
+ if (result == 0)
1606
+ return TEST_TIMEOUT;
1607
+ else if (result > 0) {
1608
+ if (FD_ISSET(socketfd, &fds)) {
1609
+ if (rx)
1610
+ return TEST_RECV_READY;
1611
+ else
1612
+ return TEST_SEND_READY;
1613
+ }
1614
+ else if(FD_ISSET(socketfd, &errfds))
1615
+ return TEST_ERROR_READY;
1616
+ }
1617
+
1618
+ return TEST_SELECT_FAIL;
1619
+ }
1620
+
1621
+ static WC_INLINE int tcp_select(SOCKET_T socketfd, int to_sec)
1622
+ {
1623
+ return tcp_select_ex(socketfd, to_sec, 1);
1624
+ }
1625
+
1626
+ static WC_INLINE int tcp_select_tx(SOCKET_T socketfd, int to_sec)
1627
+ {
1628
+ return tcp_select_ex(socketfd, to_sec, 0);
1629
+ }
1630
+
1631
+ #elif defined(WOLFSSL_TIRTOS) || defined(WOLFSSL_KEIL_TCP_NET)
1632
+ static WC_INLINE int tcp_select(SOCKET_T socketfd, int to_sec)
1633
+ {
1634
+ return TEST_RECV_READY;
1635
+ }
1636
+ static WC_INLINE int tcp_select_tx(SOCKET_T socketfd, int to_sec)
1637
+ {
1638
+ return TEST_SEND_READY;
1639
+ }
1640
+ #endif /* !WOLFSSL_MDK_ARM */
1641
+
1642
+
1643
+ static WC_INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr,
1644
+ int udp, int sctp)
1645
+ {
1646
+ SOCKADDR_IN_T addr;
1647
+
1648
+ /* don't use INADDR_ANY by default, firewall may block, make user switch
1649
+ on */
1650
+ build_addr(&addr, (useAnyAddr ? (const char*)INADDR_ANY : wolfSSLIP),
1651
+ *port, udp, sctp);
1652
+ tcp_socket(sockfd, udp, sctp);
1653
+
1654
+ #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_ARM)\
1655
+ && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_ZEPHYR)
1656
+ {
1657
+ int res, on = 1;
1658
+ socklen_t len = sizeof(on);
1659
+ res = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &on, len);
1660
+ if (res < 0)
1661
+ err_sys_with_errno("setsockopt SO_REUSEADDR failed\n");
1662
+ }
1663
+ #ifdef SO_REUSEPORT
1664
+ {
1665
+ int res, on = 1;
1666
+ socklen_t len = sizeof(on);
1667
+ res = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEPORT, &on, len);
1668
+ if (res < 0)
1669
+ err_sys_with_errno("setsockopt SO_REUSEPORT failed\n");
1670
+ }
1671
+ #endif
1672
+ #endif
1673
+
1674
+ if (bind(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
1675
+ err_sys_with_errno("tcp bind failed");
1676
+ if (!udp) {
1677
+ #ifdef WOLFSSL_KEIL_TCP_NET
1678
+ #define SOCK_LISTEN_MAX_QUEUE 1
1679
+ #else
1680
+ #define SOCK_LISTEN_MAX_QUEUE 5
1681
+ #endif
1682
+ if (listen(*sockfd, SOCK_LISTEN_MAX_QUEUE) != 0)
1683
+ err_sys_with_errno("tcp listen failed");
1684
+ }
1685
+ #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) \
1686
+ && !defined(WOLFSSL_ZEPHYR)
1687
+ if (*port == 0) {
1688
+ socklen_t len = sizeof(addr);
1689
+ if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) {
1690
+ #ifndef TEST_IPV6
1691
+ *port = XNTOHS(addr.sin_port);
1692
+ #else
1693
+ *port = XNTOHS(addr.sin6_port);
1694
+ #endif
1695
+ }
1696
+ }
1697
+ #endif
1698
+ fprintf(stderr, "listening on port %d\n", *port);
1699
+ }
1700
+
1701
+
1702
+ #if 0
1703
+ static WC_INLINE int udp_read_connect(SOCKET_T sockfd)
1704
+ {
1705
+ SOCKADDR_IN_T cliaddr;
1706
+ byte b[1500];
1707
+ int n;
1708
+ socklen_t len = sizeof(cliaddr);
1709
+
1710
+ n = (int)recvfrom(sockfd, (char*)b, sizeof(b), MSG_PEEK,
1711
+ (struct sockaddr*)&cliaddr, &len);
1712
+ if (n > 0) {
1713
+ if (connect(sockfd, (const struct sockaddr*)&cliaddr,
1714
+ sizeof(cliaddr)) != 0)
1715
+ err_sys("udp connect failed");
1716
+ }
1717
+ else
1718
+ err_sys("recvfrom failed");
1719
+
1720
+ return sockfd;
1721
+ }
1722
+ #endif
1723
+
1724
+ static WC_INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
1725
+ int useAnyAddr, word16 port, func_args* args)
1726
+ {
1727
+ SOCKADDR_IN_T addr;
1728
+
1729
+ (void)args;
1730
+ build_addr(&addr, (useAnyAddr ? (const char*)INADDR_ANY : wolfSSLIP),
1731
+ port, 1, 0);
1732
+ tcp_socket(sockfd, 1, 0);
1733
+
1734
+
1735
+ #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_ARM) \
1736
+ && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_ZEPHYR)
1737
+ {
1738
+ int res, on = 1;
1739
+ socklen_t len = sizeof(on);
1740
+ res = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &on, len);
1741
+ if (res < 0)
1742
+ err_sys_with_errno("setsockopt SO_REUSEADDR failed\n");
1743
+ }
1744
+ #ifdef SO_REUSEPORT
1745
+ {
1746
+ int res, on = 1;
1747
+ socklen_t len = sizeof(on);
1748
+ res = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEPORT, &on, len);
1749
+ if (res < 0)
1750
+ err_sys_with_errno("setsockopt SO_REUSEPORT failed\n");
1751
+ }
1752
+ #endif
1753
+ #endif
1754
+
1755
+ if (bind(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0)
1756
+ err_sys_with_errno("tcp bind failed");
1757
+
1758
+ #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) && \
1759
+ !defined(SINGLE_THREADED)
1760
+ if (port == 0) {
1761
+ socklen_t len = sizeof(addr);
1762
+ if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) {
1763
+ #ifndef TEST_IPV6
1764
+ port = XNTOHS(addr.sin_port);
1765
+ #else
1766
+ port = XNTOHS(addr.sin6_port);
1767
+ #endif
1768
+ }
1769
+ }
1770
+ #else
1771
+ (void)port;
1772
+ #endif
1773
+
1774
+ if (args != NULL && args->signal != NULL) {
1775
+ #ifndef SINGLE_THREADED
1776
+ tcp_ready* ready = args->signal;
1777
+ #ifdef WOLFSSL_COND
1778
+ THREAD_CHECK_RET(wolfSSL_CondStart(&ready->cond));
1779
+ #endif
1780
+ ready->ready = 1;
1781
+ ready->port = port;
1782
+ #ifdef WOLFSSL_COND
1783
+ /* signal ready to accept data */
1784
+ THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond));
1785
+ THREAD_CHECK_RET(wolfSSL_CondEnd(&ready->cond));
1786
+ #endif
1787
+ #endif /* !SINGLE_THREADED */
1788
+ }
1789
+ else {
1790
+ fprintf(stderr, "args or args->signal was NULL. Not setting ready info.");
1791
+ }
1792
+
1793
+ *clientfd = *sockfd;
1794
+ }
1795
+
1796
+ static WC_INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
1797
+ func_args* args, word16 port, int useAnyAddr,
1798
+ int udp, int sctp, int ready_file, int do_listen,
1799
+ SOCKADDR_IN_T *client_addr, socklen_t *client_len)
1800
+ {
1801
+ tcp_ready* ready = NULL;
1802
+
1803
+ (void) ready; /* Account for case when "ready" is not used */
1804
+
1805
+ if (udp) {
1806
+ udp_accept(sockfd, clientfd, useAnyAddr, port, args);
1807
+ return;
1808
+ }
1809
+
1810
+ if(do_listen) {
1811
+ tcp_listen(sockfd, &port, useAnyAddr, udp, sctp);
1812
+
1813
+ #ifndef SINGLE_THREADED
1814
+ /* signal ready to tcp_accept */
1815
+ if (args)
1816
+ ready = args->signal;
1817
+ if (ready) {
1818
+ #ifdef WOLFSSL_COND
1819
+ THREAD_CHECK_RET(wolfSSL_CondStart(&ready->cond));
1820
+ #endif
1821
+ ready->ready = 1;
1822
+ ready->port = port;
1823
+ #ifdef WOLFSSL_COND
1824
+ THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond));
1825
+ THREAD_CHECK_RET(wolfSSL_CondEnd(&ready->cond));
1826
+ #endif
1827
+ }
1828
+ #endif /* !SINGLE_THREADED */
1829
+
1830
+ if (ready_file) {
1831
+ #if (!defined(NO_FILESYSTEM) || defined(FORCE_BUFFER_TEST)) && \
1832
+ !defined(NETOS)
1833
+ XFILE srf = (XFILE)NULL;
1834
+ if (args)
1835
+ ready = args->signal;
1836
+
1837
+ if (ready) {
1838
+ srf = XFOPEN(ready->srfName, "w");
1839
+
1840
+ if (srf) {
1841
+ /* let's write port sever is listening on to ready file
1842
+ external monitor can then do ephemeral ports by passing
1843
+ -p 0 to server on supported platforms with -R ready_file
1844
+ client can then wait for existence of ready_file and see
1845
+ which port the server is listening on. */
1846
+ LIBCALL_CHECK_RET(fprintf(srf, "%d\n", (int)port));
1847
+ fclose(srf);
1848
+ }
1849
+ }
1850
+ #endif
1851
+ }
1852
+ }
1853
+
1854
+ *clientfd = accept(*sockfd, (struct sockaddr*)client_addr,
1855
+ (ACCEPT_THIRD_T)client_len);
1856
+ if(WOLFSSL_SOCKET_IS_INVALID(*clientfd)) {
1857
+ err_sys_with_errno("tcp accept failed");
1858
+ }
1859
+ }
1860
+
1861
+
1862
+ static WC_INLINE void tcp_set_nonblocking(SOCKET_T* sockfd)
1863
+ {
1864
+ #if defined(USE_WINDOWS_API) || defined(EBSNET)
1865
+ unsigned long blocking = 1;
1866
+ int ret = ioctlsocket(*sockfd, FIONBIO, &blocking);
1867
+ if (ret == SOCKET_ERROR)
1868
+ err_sys_with_errno("ioctlsocket failed");
1869
+ #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) \
1870
+ || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
1871
+ || defined(WOLFSSL_ZEPHYR)
1872
+ /* non blocking not supported, for now */
1873
+ #elif defined(__WATCOMC__) && defined(__OS2__)
1874
+ int blocking = 1;
1875
+ if (ioctl(*sockfd, FIONBIO, &blocking) == -1)
1876
+ err_sys_with_errno("ioctl failed");
1877
+ #else
1878
+ int flags = fcntl(*sockfd, F_GETFL, 0);
1879
+ if (flags < 0)
1880
+ err_sys_with_errno("fcntl get failed");
1881
+ flags = fcntl(*sockfd, F_SETFL, flags | O_NONBLOCK);
1882
+ if (flags < 0)
1883
+ err_sys_with_errno("fcntl set failed");
1884
+ #endif
1885
+ }
1886
+
1887
+ static WC_INLINE void tcp_set_blocking(SOCKET_T* sockfd)
1888
+ {
1889
+ #ifdef USE_WINDOWS_API
1890
+ unsigned long blocking = 0;
1891
+ int ret = ioctlsocket(*sockfd, FIONBIO, &blocking);
1892
+ if (ret == SOCKET_ERROR)
1893
+ err_sys_with_errno("ioctlsocket failed");
1894
+ #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) \
1895
+ || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
1896
+ || defined(WOLFSSL_ZEPHYR)
1897
+ /* non blocking not supported, for now */
1898
+ #elif defined(__WATCOMC__) && defined(__OS2__)
1899
+ int blocking = 0;
1900
+ if (ioctl(*sockfd, FIONBIO, &blocking) == -1)
1901
+ err_sys_with_errno("ioctl failed");
1902
+ #else
1903
+ int flags = fcntl(*sockfd, F_GETFL, 0);
1904
+ if (flags < 0)
1905
+ err_sys_with_errno("fcntl get failed");
1906
+ flags = fcntl(*sockfd, F_SETFL, flags & (~O_NONBLOCK));
1907
+ if (flags < 0)
1908
+ err_sys_with_errno("fcntl set failed");
1909
+ #endif
1910
+ }
1911
+
1912
+ #ifndef NO_PSK
1913
+
1914
+ /* identity is OpenSSL testing default for openssl s_client, keep same */
1915
+ static const char* kIdentityStr = "Client_identity";
1916
+
1917
+ static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
1918
+ char* identity, unsigned int id_max_len, unsigned char* key,
1919
+ unsigned int key_max_len)
1920
+ {
1921
+ unsigned int ret;
1922
+
1923
+ (void)ssl;
1924
+ (void)hint;
1925
+ (void)key_max_len;
1926
+
1927
+ /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
1928
+ XSTRNCPY(identity, kIdentityStr, id_max_len);
1929
+
1930
+ if (wolfSSL_GetVersion(ssl) != WOLFSSL_TLSV1_3 &&
1931
+ wolfSSL_GetVersion(ssl) != WOLFSSL_DTLSV1_3) {
1932
+ /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using
1933
+ * unsigned binary */
1934
+ key[0] = 0x1a;
1935
+ key[1] = 0x2b;
1936
+ key[2] = 0x3c;
1937
+ key[3] = 0x4d;
1938
+
1939
+ ret = 4; /* length of key in octets or 0 for error */
1940
+ }
1941
+ else {
1942
+ int i;
1943
+ int b = 0x01;
1944
+
1945
+ for (i = 0; i < 32; i++, b += 0x22) {
1946
+ if (b >= 0x100)
1947
+ b = 0x01;
1948
+ key[i] = (unsigned char) b;
1949
+ }
1950
+
1951
+ ret = 32; /* length of key in octets or 0 for error */
1952
+ }
1953
+
1954
+ #if defined(HAVE_PK_CALLBACKS) && defined(TEST_PK_PSK)
1955
+ WOLFSSL_PKMSG("PSK Client using HW (Len %u, Hint %s)\n", ret, hint);
1956
+ ret = (unsigned int)USE_HW_PSK;
1957
+ #endif
1958
+
1959
+ return ret;
1960
+ }
1961
+
1962
+
1963
+ static WC_INLINE unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
1964
+ unsigned char* key, unsigned int key_max_len)
1965
+ {
1966
+ unsigned int ret;
1967
+
1968
+ (void)ssl;
1969
+ (void)key_max_len;
1970
+
1971
+ /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
1972
+ if (XSTRCMP(identity, kIdentityStr) != 0)
1973
+ return 0;
1974
+
1975
+ if (wolfSSL_GetVersion(ssl) != WOLFSSL_TLSV1_3 &&
1976
+ wolfSSL_GetVersion(ssl) != WOLFSSL_DTLSV1_3) {
1977
+ /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using
1978
+ * unsigned binary */
1979
+ key[0] = 0x1a;
1980
+ key[1] = 0x2b;
1981
+ key[2] = 0x3c;
1982
+ key[3] = 0x4d;
1983
+
1984
+ ret = 4; /* length of key in octets or 0 for error */
1985
+ }
1986
+ else {
1987
+ int i;
1988
+ int b = 0x01;
1989
+
1990
+ for (i = 0; i < 32; i++, b += 0x22) {
1991
+ if (b >= 0x100)
1992
+ b = 0x01;
1993
+ key[i] = (unsigned char) b;
1994
+ }
1995
+
1996
+ ret = 32; /* length of key in octets or 0 for error */
1997
+ }
1998
+ #if defined(HAVE_PK_CALLBACKS) && defined(TEST_PK_PSK)
1999
+ WOLFSSL_PKMSG("PSK Server using HW (Len %u, Hint %s)\n", ret, identity);
2000
+ ret = (unsigned int)USE_HW_PSK;
2001
+ #endif
2002
+
2003
+ return ret;
2004
+ }
2005
+
2006
+ #ifdef WOLFSSL_TLS13
2007
+ static WC_INLINE unsigned int my_psk_client_tls13_cb(WOLFSSL* ssl,
2008
+ const char* hint, char* identity, unsigned int id_max_len,
2009
+ unsigned char* key, unsigned int key_max_len, const char** ciphersuite)
2010
+ {
2011
+ unsigned int ret;
2012
+ int i;
2013
+ int b = 0x01;
2014
+ const char* userCipher = (const char*)wolfSSL_get_psk_callback_ctx(ssl);
2015
+
2016
+ (void)ssl;
2017
+ (void)hint;
2018
+ (void)key_max_len;
2019
+
2020
+ /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
2021
+ XSTRNCPY(identity, kIdentityStr, id_max_len);
2022
+
2023
+ for (i = 0; i < 32; i++, b += 0x22) {
2024
+ if (b >= 0x100)
2025
+ b = 0x01;
2026
+ key[i] = (unsigned char) b;
2027
+ }
2028
+
2029
+ #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
2030
+ *ciphersuite = userCipher ? userCipher : "TLS13-AES256-GCM-SHA384";
2031
+ #else
2032
+ *ciphersuite = userCipher ? userCipher : "TLS13-AES128-GCM-SHA256";
2033
+ #endif
2034
+
2035
+ ret = 32; /* length of key in octets or 0 for error */
2036
+
2037
+ #if defined(HAVE_PK_CALLBACKS) && defined(TEST_PK_PSK)
2038
+ WOLFSSL_PKMSG("PSK Client TLS 1.3 using HW (Len %u, Hint %s)\n", ret, hint);
2039
+ ret = (unsigned int)USE_HW_PSK;
2040
+ #endif
2041
+
2042
+ return ret;
2043
+ }
2044
+
2045
+
2046
+ static WC_INLINE unsigned int my_psk_server_tls13_cb(WOLFSSL* ssl,
2047
+ const char* identity, unsigned char* key, unsigned int key_max_len,
2048
+ const char** ciphersuite)
2049
+ {
2050
+ unsigned int ret;
2051
+ int i;
2052
+ int b = 0x01;
2053
+ size_t kIdLen = XSTRLEN(kIdentityStr);
2054
+ const char* userCipher = (const char*)wolfSSL_get_psk_callback_ctx(ssl);
2055
+
2056
+ (void)ssl;
2057
+ (void)key_max_len;
2058
+
2059
+ /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
2060
+ if (XSTRNCMP(identity, kIdentityStr, kIdLen) != 0)
2061
+ return 0;
2062
+ if (identity[kIdLen] != '\0') {
2063
+ userCipher = wolfSSL_get_cipher_name_by_hash(ssl, identity + kIdLen);
2064
+ }
2065
+
2066
+ for (i = 0; i < 32; i++, b += 0x22) {
2067
+ if (b >= 0x100)
2068
+ b = 0x01;
2069
+ key[i] = (unsigned char) b;
2070
+ }
2071
+
2072
+ #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
2073
+ *ciphersuite = userCipher ? userCipher : "TLS13-AES256-GCM-SHA384";
2074
+ #else
2075
+ *ciphersuite = userCipher ? userCipher : "TLS13-AES128-GCM-SHA256";
2076
+ #endif
2077
+
2078
+ ret = 32; /* length of key in octets or 0 for error */
2079
+
2080
+ #if defined(HAVE_PK_CALLBACKS) && defined(TEST_PK_PSK)
2081
+ WOLFSSL_PKMSG("PSK Server TLS 1.3 using HW (Len %u, Hint %s)\n",
2082
+ ret, identity);
2083
+ ret = (unsigned int)USE_HW_PSK;
2084
+ #endif
2085
+
2086
+ return ret;
2087
+ }
2088
+ #endif
2089
+
2090
+ #ifdef OPENSSL_EXTRA
2091
+ static WC_INLINE int my_psk_use_session_cb(WOLFSSL* ssl,
2092
+ const WOLFSSL_EVP_MD* md, const unsigned char **id,
2093
+ size_t* idlen, WOLFSSL_SESSION **sess)
2094
+ {
2095
+ #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
2096
+ static unsigned char local_psk[32];
2097
+ int i;
2098
+ WOLFSSL_SESSION* lsess;
2099
+ char buf[256];
2100
+ const char* cipher_id = "TLS13-AES128-GCM-SHA256";
2101
+ const SSL_CIPHER* cipher = NULL;
2102
+ STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
2103
+ int numCiphers = 0;
2104
+ (void)ssl;
2105
+ (void)md;
2106
+
2107
+ printf("use psk session callback \n");
2108
+
2109
+ lsess = SSL_SESSION_new();
2110
+ if (lsess == NULL) {
2111
+ return 0;
2112
+ }
2113
+ supportedCiphers = SSL_get_ciphers(ssl);
2114
+ numCiphers = sk_num(supportedCiphers);
2115
+
2116
+ for (i = 0; i < numCiphers; ++i) {
2117
+ XMEMSET(buf, 0, sizeof(buf));
2118
+
2119
+ if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
2120
+ SSL_CIPHER_description(cipher, buf, sizeof(buf));
2121
+ }
2122
+
2123
+ if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
2124
+ break;
2125
+ }
2126
+ }
2127
+
2128
+ if (i != numCiphers) {
2129
+ int b = 0x01;
2130
+ SSL_SESSION_set_cipher(lsess, cipher);
2131
+ for (i = 0; i < 32; i++, b += 0x22) {
2132
+ if (b >= 0x100)
2133
+ b = 0x01;
2134
+ local_psk[i] = (unsigned char) b;
2135
+ }
2136
+
2137
+ *id = local_psk;
2138
+ *idlen = 32;
2139
+ *sess = lsess;
2140
+
2141
+ return 1;
2142
+ }
2143
+ else {
2144
+ *id = NULL;
2145
+ *idlen = 0;
2146
+ *sess = NULL;
2147
+ SSL_SESSION_free(lsess);
2148
+ return 0;
2149
+ }
2150
+ #else
2151
+ (void)ssl;
2152
+ (void)md;
2153
+ (void)id;
2154
+ (void)idlen;
2155
+ (void)sess;
2156
+
2157
+ return 0;
2158
+ #endif
2159
+ }
2160
+ #endif /* OPENSSL_EXTRA */
2161
+
2162
+ static WC_INLINE unsigned int my_psk_client_cs_cb(WOLFSSL* ssl,
2163
+ const char* hint, char* identity, unsigned int id_max_len,
2164
+ unsigned char* key, unsigned int key_max_len, const char* ciphersuite)
2165
+ {
2166
+ int i;
2167
+ int b = 0x01;
2168
+
2169
+ (void)ssl;
2170
+ (void)hint;
2171
+ (void)key_max_len;
2172
+
2173
+ #ifdef WOLFSSL_PSK_MULTI_ID_PER_CS
2174
+ /* Multiple calls for each cipher suite. First identity byte indicates the
2175
+ * number of identities seen so far for cipher suite. */
2176
+ if (identity[0] != 0) {
2177
+ return 0;
2178
+ }
2179
+ #endif
2180
+
2181
+ /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
2182
+ XSTRNCPY(identity, kIdentityStr, id_max_len);
2183
+ XSTRNCAT(identity, ciphersuite + XSTRLEN(ciphersuite) - 6, id_max_len);
2184
+
2185
+ for (i = 0; i < 32; i++, b += 0x22) {
2186
+ if (b >= 0x100)
2187
+ b = 0x01;
2188
+ key[i] = (unsigned char) b;
2189
+ }
2190
+
2191
+ return 32; /* length of key in octets or 0 for error */
2192
+ }
2193
+
2194
+ #endif /* !NO_PSK */
2195
+
2196
+
2197
+ #if defined(WOLFSSL_USER_CURRTIME)
2198
+ extern double current_time(int reset);
2199
+
2200
+ #elif defined(USE_WINDOWS_API)
2201
+
2202
+ #define WIN32_LEAN_AND_MEAN
2203
+ #define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
2204
+ #include <windows.h>
2205
+ #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
2206
+
2207
+ static WC_INLINE double current_time(int reset)
2208
+ {
2209
+ static int init = 0;
2210
+ static LARGE_INTEGER freq;
2211
+
2212
+ LARGE_INTEGER count;
2213
+
2214
+ if (!init) {
2215
+ QueryPerformanceFrequency(&freq);
2216
+ init = 1;
2217
+ }
2218
+
2219
+ QueryPerformanceCounter(&count);
2220
+
2221
+ (void)reset;
2222
+ return (double)count.QuadPart / freq.QuadPart;
2223
+ }
2224
+
2225
+ #elif defined(WOLFSSL_TIRTOS)
2226
+ extern double current_time();
2227
+ #elif defined(WOLFSSL_ZEPHYR)
2228
+ extern double current_time();
2229
+ #else
2230
+
2231
+ #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_CHIBIOS)
2232
+ #ifndef NETOS
2233
+ #include <sys/time.h>
2234
+ #endif
2235
+
2236
+ static WC_INLINE double current_time(int reset)
2237
+ {
2238
+ struct timeval tv;
2239
+ if (gettimeofday(&tv, NULL) < 0)
2240
+ err_sys_with_errno("gettimeofday");
2241
+ (void)reset;
2242
+
2243
+ return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
2244
+ }
2245
+ #else
2246
+ extern double current_time(int reset);
2247
+ #endif
2248
+ #endif /* USE_WINDOWS_API */
2249
+
2250
+ #ifdef WOLFSSL_CALLBACKS
2251
+ /* only for debug use! */
2252
+ static WC_INLINE void msgDebugCb(int write_p, int version, int content_type,
2253
+ const void *buf, size_t len, WOLFSSL *ssl, void *arg)
2254
+ {
2255
+ size_t z;
2256
+ byte* pt;
2257
+
2258
+ printf("Version %02X, content type = %d\n", version, content_type);
2259
+ printf("%s ", (write_p)? "WRITING" : "READING");
2260
+ pt = (byte*)buf;
2261
+ printf("DATA [%zu]: ", len);
2262
+ for (z = 0; z < len; z++)
2263
+ printf("%02X", pt[z]);
2264
+ printf("\n");
2265
+
2266
+ (void)arg;
2267
+ (void)ssl;
2268
+ }
2269
+ #endif /* WOLFSSL_CALLBACKS */
2270
+
2271
+ #if defined(HAVE_OCSP) && defined(WOLFSSL_NONBLOCK_OCSP)
2272
+ static WC_INLINE int OCSPIOCb(void* ioCtx, const char* url, int urlSz,
2273
+ unsigned char* request, int requestSz, unsigned char** response)
2274
+ {
2275
+ #ifdef TEST_NONBLOCK_CERTS
2276
+ static int ioCbCnt = 0;
2277
+ #endif
2278
+
2279
+ (void)ioCtx;
2280
+ (void)url;
2281
+ (void)urlSz;
2282
+ (void)request;
2283
+ (void)requestSz;
2284
+ (void)response;
2285
+
2286
+ #ifdef TEST_NONBLOCK_CERTS
2287
+ if (ioCbCnt) {
2288
+ ioCbCnt = 0;
2289
+ return EmbedOcspLookup(ioCtx, url, urlSz, request, requestSz, response);
2290
+ }
2291
+ else {
2292
+ ioCbCnt = 1;
2293
+ return WOLFSSL_CBIO_ERR_WANT_READ;
2294
+ }
2295
+ #else
2296
+ return EmbedOcspLookup(ioCtx, url, urlSz, request, requestSz, response);
2297
+ #endif
2298
+ }
2299
+
2300
+ static WC_INLINE void OCSPRespFreeCb(void* ioCtx, unsigned char* response)
2301
+ {
2302
+ EmbedOcspRespFree(ioCtx, response);
2303
+ }
2304
+ #endif
2305
+
2306
+ #if !defined(NO_CERTS)
2307
+ #if !defined(NO_FILESYSTEM) || \
2308
+ (defined(NO_FILESYSTEM) && defined(FORCE_BUFFER_TEST)) && \
2309
+ !defined(NETOS)
2310
+
2311
+ /* reads file size, allocates buffer, reads into buffer, returns buffer */
2312
+ static WC_INLINE int load_file(const char* fname, byte** buf, size_t* bufLen)
2313
+ {
2314
+ int ret;
2315
+ long int fileSz;
2316
+ XFILE lFile;
2317
+
2318
+ if (fname == NULL || buf == NULL || bufLen == NULL)
2319
+ return BAD_FUNC_ARG;
2320
+
2321
+ /* set defaults */
2322
+ *buf = NULL;
2323
+ *bufLen = 0;
2324
+
2325
+ /* open file (read-only binary) */
2326
+ lFile = XFOPEN(fname, "rb");
2327
+ if (!lFile) {
2328
+ fprintf(stderr, "Error loading %s\n", fname);
2329
+ return BAD_PATH_ERROR;
2330
+ }
2331
+
2332
+ LIBCALL_CHECK_RET(XFSEEK(lFile, 0, XSEEK_END));
2333
+ fileSz = (int)ftell(lFile);
2334
+ LIBCALL_CHECK_RET(XFSEEK(lFile, 0, XSEEK_SET));
2335
+ if (fileSz > 0) {
2336
+ *bufLen = (size_t)fileSz;
2337
+ *buf = (byte*)malloc(*bufLen);
2338
+ if (*buf == NULL) {
2339
+ ret = MEMORY_E;
2340
+ fprintf(stderr,
2341
+ "Error allocating %lu bytes\n", (unsigned long)*bufLen);
2342
+ }
2343
+ else {
2344
+ size_t readLen = fread(*buf, *bufLen, 1, lFile);
2345
+
2346
+ /* check response code */
2347
+ ret = (readLen > 0) ? 0 : -1;
2348
+ }
2349
+ }
2350
+ else {
2351
+ ret = BUFFER_E;
2352
+ }
2353
+ fclose(lFile);
2354
+
2355
+ return ret;
2356
+ }
2357
+
2358
+ enum {
2359
+ WOLFSSL_CA = 1,
2360
+ WOLFSSL_CERT = 2,
2361
+ WOLFSSL_KEY = 3,
2362
+ WOLFSSL_CERT_CHAIN = 4,
2363
+ };
2364
+
2365
+ static WC_INLINE void load_buffer(WOLFSSL_CTX* ctx, const char* fname, int type)
2366
+ {
2367
+ int format = WOLFSSL_FILETYPE_PEM;
2368
+ byte* buff = NULL;
2369
+ size_t sz = 0;
2370
+
2371
+ if (load_file(fname, &buff, &sz) != 0) {
2372
+ err_sys("can't open file for buffer load "
2373
+ "Please run from wolfSSL home directory if not");
2374
+ }
2375
+
2376
+ /* determine format */
2377
+ if (strstr(fname, ".der"))
2378
+ format = WOLFSSL_FILETYPE_ASN1;
2379
+
2380
+ if (type == WOLFSSL_CA) {
2381
+ if (wolfSSL_CTX_load_verify_buffer(ctx, buff, (long)sz, format)
2382
+ != WOLFSSL_SUCCESS)
2383
+ err_sys("can't load buffer ca file");
2384
+ }
2385
+ else if (type == WOLFSSL_CERT) {
2386
+ if (wolfSSL_CTX_use_certificate_buffer(ctx, buff, (long)sz,
2387
+ format) != WOLFSSL_SUCCESS)
2388
+ err_sys("can't load buffer cert file");
2389
+ }
2390
+ else if (type == WOLFSSL_KEY) {
2391
+ if (wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, (long)sz,
2392
+ format) != WOLFSSL_SUCCESS)
2393
+ err_sys("can't load buffer key file");
2394
+ }
2395
+ else if (type == WOLFSSL_CERT_CHAIN) {
2396
+ if (wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buff,
2397
+ (long)sz, format) != WOLFSSL_SUCCESS)
2398
+ err_sys("can't load cert chain buffer");
2399
+ }
2400
+
2401
+ if (buff)
2402
+ free(buff);
2403
+ }
2404
+
2405
+ static WC_INLINE void load_ssl_buffer(WOLFSSL* ssl, const char* fname, int type)
2406
+ {
2407
+ int format = WOLFSSL_FILETYPE_PEM;
2408
+ byte* buff = NULL;
2409
+ size_t sz = 0;
2410
+
2411
+ if (load_file(fname, &buff, &sz) != 0) {
2412
+ err_sys("can't open file for buffer load "
2413
+ "Please run from wolfSSL home directory if not");
2414
+ }
2415
+
2416
+ /* determine format */
2417
+ if (strstr(fname, ".der"))
2418
+ format = WOLFSSL_FILETYPE_ASN1;
2419
+
2420
+ if (type == WOLFSSL_CA) {
2421
+ /* verify certs (CA's) use the shared ctx->cm (WOLFSSL_CERT_MANAGER) */
2422
+ WOLFSSL_CTX* ctx = wolfSSL_get_SSL_CTX(ssl);
2423
+ if (wolfSSL_CTX_load_verify_buffer(ctx, buff, (long)sz, format)
2424
+ != WOLFSSL_SUCCESS)
2425
+ err_sys("can't load buffer ca file");
2426
+ }
2427
+ else if (type == WOLFSSL_CERT) {
2428
+ if (wolfSSL_use_certificate_buffer(ssl, buff, (long)sz,
2429
+ format) != WOLFSSL_SUCCESS)
2430
+ err_sys("can't load buffer cert file");
2431
+ }
2432
+ else if (type == WOLFSSL_KEY) {
2433
+ if (wolfSSL_use_PrivateKey_buffer(ssl, buff, (long)sz,
2434
+ format) != WOLFSSL_SUCCESS)
2435
+ err_sys("can't load buffer key file");
2436
+ }
2437
+ else if (type == WOLFSSL_CERT_CHAIN) {
2438
+ if (wolfSSL_use_certificate_chain_buffer_format(ssl, buff,
2439
+ (long)sz, format) != WOLFSSL_SUCCESS)
2440
+ err_sys("can't load cert chain buffer");
2441
+ }
2442
+
2443
+ if (buff)
2444
+ free(buff);
2445
+ }
2446
+
2447
+ #ifdef TEST_PK_PRIVKEY
2448
+ static WC_INLINE int load_key_file(const char* fname, byte** derBuf, word32* derLen)
2449
+ {
2450
+ int ret;
2451
+ byte* buf = NULL;
2452
+ size_t bufLen;
2453
+
2454
+ ret = load_file(fname, &buf, &bufLen);
2455
+ if (ret != 0)
2456
+ return ret;
2457
+
2458
+ *derBuf = (byte*)malloc(bufLen);
2459
+ if (*derBuf == NULL) {
2460
+ free(buf);
2461
+ return MEMORY_E;
2462
+ }
2463
+
2464
+ ret = wc_KeyPemToDer(buf, (word32)bufLen, *derBuf, (word32)bufLen, NULL);
2465
+ if (ret < 0) {
2466
+ free(buf);
2467
+ free(*derBuf);
2468
+ return ret;
2469
+ }
2470
+ *derLen = ret;
2471
+ free(buf);
2472
+
2473
+ return 0;
2474
+ }
2475
+ #endif /* TEST_PK_PRIVKEY */
2476
+
2477
+ #endif /* !NO_FILESYSTEM || (NO_FILESYSTEM && FORCE_BUFFER_TEST) */
2478
+ #endif /* !NO_CERTS */
2479
+
2480
+ enum {
2481
+ VERIFY_OVERRIDE_ERROR,
2482
+ VERIFY_FORCE_FAIL,
2483
+ VERIFY_USE_PREVERIFY,
2484
+ VERIFY_OVERRIDE_DATE_ERR,
2485
+ };
2486
+ static THREAD_LS_T int myVerifyAction = VERIFY_OVERRIDE_ERROR;
2487
+
2488
+ /* The verify callback is called for every certificate only when
2489
+ * --enable-opensslextra is defined because it sets WOLFSSL_ALWAYS_VERIFY_CB and
2490
+ * WOLFSSL_VERIFY_CB_ALL_CERTS.
2491
+ * Normal cases of the verify callback only occur on certificate failures when the
2492
+ * wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, myVerify); is called
2493
+ */
2494
+
2495
+ static WC_INLINE int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store)
2496
+ {
2497
+ char err_buffer[WOLFSSL_MAX_ERROR_SZ];
2498
+ int err;
2499
+ #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
2500
+ WOLFSSL_X509* peer;
2501
+ #endif
2502
+ #if defined(OPENSSL_EXTRA) && defined(SHOW_CERTS) && !defined(NO_FILESYSTEM)
2503
+ WOLFSSL_BIO* bio = NULL;
2504
+ WOLFSSL_STACK* sk = NULL;
2505
+ X509* x509 = NULL;
2506
+ #endif
2507
+
2508
+ /* Verify Callback Arguments:
2509
+ * preverify: 1=Verify Okay, 0=Failure
2510
+ * store->error: Failure error code (0 indicates no failure)
2511
+ * store->current_cert: Current WOLFSSL_X509 object (only with OPENSSL_EXTRA)
2512
+ * store->error_depth: Current Index
2513
+ * store->domain: Subject CN as string (null term)
2514
+ * store->totalCerts: Number of certs presented by peer
2515
+ * store->certs[i]: A `WOLFSSL_BUFFER_INFO` with plain DER for each cert
2516
+ * store->store: WOLFSSL_X509_STORE with CA cert chain
2517
+ * store->store->cm: WOLFSSL_CERT_MANAGER
2518
+ * store->ex_data: The WOLFSSL object pointer
2519
+ * store->discardSessionCerts: When set to non-zero value session certs
2520
+ will be discarded (only with SESSION_CERTS)
2521
+ */
2522
+
2523
+ #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
2524
+ defined(WOLFSSL_EXTRA)
2525
+ err = wolfSSL_X509_STORE_CTX_get_error(store);
2526
+ #else
2527
+ err = store->error;
2528
+ #endif
2529
+
2530
+ fprintf(stderr, "In verification callback, error = %d, %s\n", err,
2531
+ wolfSSL_ERR_error_string((unsigned long) err, err_buffer));
2532
+ #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
2533
+ peer = wolfSSL_X509_STORE_CTX_get_current_cert(store);
2534
+ if (peer) {
2535
+ char* issuer = wolfSSL_X509_NAME_oneline(
2536
+ wolfSSL_X509_get_issuer_name(peer), 0, 0);
2537
+ char* subject = wolfSSL_X509_NAME_oneline(
2538
+ wolfSSL_X509_get_subject_name(peer), 0, 0);
2539
+ printf("\tPeer's cert info:\n issuer : %s\n subject: %s\n",
2540
+ issuer ? issuer : "[none]",
2541
+ subject ? subject : "[none]");
2542
+ #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
2543
+ if (issuer != NULL && subject != NULL) {
2544
+ /* preverify needs to be self-signer error for Qt compat.
2545
+ * Should be ASN_SELF_SIGNED_E */
2546
+ if (XSTRCMP(issuer, subject) == 0 && preverify == ASN_NO_SIGNER_E)
2547
+ return 0;
2548
+ }
2549
+ #endif
2550
+
2551
+ XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
2552
+ XFREE(issuer, 0, DYNAMIC_TYPE_OPENSSL);
2553
+ #if defined(OPENSSL_EXTRA) && defined(SHOW_CERTS) && !defined(NO_FILESYSTEM)
2554
+ /* avoid printing duplicate certs */
2555
+ if (store->depth == 1) {
2556
+ int i;
2557
+ /* retrieve x509 certs and display them on stdout */
2558
+ sk = wolfSSL_X509_STORE_GetCerts(store);
2559
+
2560
+ for (i = 0; i < wolfSSL_sk_X509_num(sk); i++) {
2561
+ x509 = wolfSSL_sk_X509_value(sk, i);
2562
+ bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
2563
+ if (bio != NULL) {
2564
+ wolfSSL_BIO_set_fp(bio, stdout, BIO_NOCLOSE);
2565
+ wolfSSL_X509_print(bio, x509);
2566
+ wolfSSL_BIO_free(bio);
2567
+ }
2568
+ }
2569
+ wolfSSL_sk_X509_pop_free(sk, NULL);
2570
+ }
2571
+ #endif
2572
+ }
2573
+ else
2574
+ fprintf(stderr, "\tPeer has no cert!\n");
2575
+ #else
2576
+ printf("\tPeer certs: %d\n", store->totalCerts);
2577
+ #ifdef SHOW_CERTS
2578
+ { int i;
2579
+ for (i=0; i<store->totalCerts; i++) {
2580
+ WOLFSSL_BUFFER_INFO* cert = &store->certs[i];
2581
+ printf("\t\tCert %d: Ptr %p, Len %u\n", i, cert->buffer, cert->length);
2582
+ }
2583
+ }
2584
+ #endif /* SHOW_CERTS */
2585
+ #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
2586
+
2587
+ printf("\tSubject's domain name at %d is %s\n", store->error_depth, store->domain);
2588
+
2589
+ /* Testing forced fail case by return zero */
2590
+ if (myVerifyAction == VERIFY_FORCE_FAIL) {
2591
+ return 0; /* test failure case */
2592
+ }
2593
+
2594
+ if (myVerifyAction == VERIFY_OVERRIDE_DATE_ERR &&
2595
+ (store->error == ASN_BEFORE_DATE_E || store->error == ASN_AFTER_DATE_E)) {
2596
+ printf("Overriding cert date error as example for bad clock testing\n");
2597
+ return 1;
2598
+ }
2599
+
2600
+ /* If error indicate we are overriding it for testing purposes */
2601
+ if (store->error != 0 && myVerifyAction == VERIFY_OVERRIDE_ERROR) {
2602
+ printf("\tAllowing failed certificate check, testing only "
2603
+ "(shouldn't do this in production)\n");
2604
+ }
2605
+
2606
+ /* A non-zero return code indicates failure override */
2607
+ return (myVerifyAction == VERIFY_OVERRIDE_ERROR) ? 1 : preverify;
2608
+ }
2609
+
2610
+
2611
+ #ifdef HAVE_EXT_CACHE
2612
+
2613
+ static WC_INLINE WOLFSSL_SESSION* mySessGetCb(WOLFSSL* ssl,
2614
+ const unsigned char* id, int id_len, int* copy)
2615
+ {
2616
+ (void)ssl;
2617
+ (void)id;
2618
+ (void)id_len;
2619
+ (void)copy;
2620
+
2621
+ /* using internal cache, this is for testing only */
2622
+ return NULL;
2623
+ }
2624
+
2625
+ static WC_INLINE int mySessNewCb(WOLFSSL* ssl, WOLFSSL_SESSION* session)
2626
+ {
2627
+ (void)ssl;
2628
+ (void)session;
2629
+
2630
+ /* using internal cache, this is for testing only */
2631
+ return 0;
2632
+ }
2633
+
2634
+ static WC_INLINE void mySessRemCb(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* session)
2635
+ {
2636
+ (void)ctx;
2637
+ (void)session;
2638
+
2639
+ /* using internal cache, this is for testing only */
2640
+ }
2641
+
2642
+ #endif /* HAVE_EXT_CACHE */
2643
+
2644
+
2645
+ #ifdef HAVE_CRL
2646
+
2647
+ static WC_INLINE void CRL_CallBack(const char* url)
2648
+ {
2649
+ printf("CRL callback url = %s\n", url);
2650
+ }
2651
+
2652
+ #endif
2653
+
2654
+ #ifndef NO_DH
2655
+ #if defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)
2656
+ /* dh2048 p */
2657
+ static const unsigned char test_dh_p[] =
2658
+ {
2659
+ 0xD3, 0xB2, 0x99, 0x84, 0x5C, 0x0A, 0x4C, 0xE7, 0x37, 0xCC, 0xFC, 0x18,
2660
+ 0x37, 0x01, 0x2F, 0x5D, 0xC1, 0x4C, 0xF4, 0x5C, 0xC9, 0x82, 0x8D, 0xB7,
2661
+ 0xF3, 0xD4, 0xA9, 0x8A, 0x9D, 0x34, 0xD7, 0x76, 0x57, 0xE5, 0xE5, 0xC3,
2662
+ 0xE5, 0x16, 0x85, 0xCA, 0x4D, 0xD6, 0x5B, 0xC1, 0xF8, 0xCF, 0x89, 0x26,
2663
+ 0xD0, 0x38, 0x8A, 0xEE, 0xF3, 0xCD, 0x33, 0xE5, 0x56, 0xBB, 0x90, 0x83,
2664
+ 0x9F, 0x97, 0x8E, 0x71, 0xFB, 0x27, 0xE4, 0x35, 0x15, 0x45, 0x86, 0x09,
2665
+ 0x71, 0xA8, 0x9A, 0xB9, 0x3E, 0x0F, 0x51, 0x8A, 0xC2, 0x75, 0x51, 0x23,
2666
+ 0x12, 0xFB, 0x94, 0x31, 0x44, 0xBF, 0xCE, 0xF6, 0xED, 0xA6, 0x3A, 0xB7,
2667
+ 0x92, 0xCE, 0x16, 0xA9, 0x14, 0xB3, 0x88, 0xB7, 0x13, 0x81, 0x71, 0x83,
2668
+ 0x88, 0xCD, 0xB1, 0xA2, 0x37, 0xE1, 0x59, 0x5C, 0xD0, 0xDC, 0xCA, 0x82,
2669
+ 0x87, 0xFA, 0x43, 0x44, 0xDD, 0x78, 0x3F, 0xCA, 0x27, 0x7E, 0xE1, 0x6B,
2670
+ 0x93, 0x19, 0x7C, 0xD9, 0xA6, 0x96, 0x47, 0x0D, 0x12, 0xC1, 0x13, 0xD7,
2671
+ 0xB9, 0x0A, 0x40, 0xD9, 0x1F, 0xFF, 0xB8, 0xB4, 0x00, 0xC8, 0xAA, 0x5E,
2672
+ 0xD2, 0x66, 0x4A, 0x05, 0x8E, 0x9E, 0xF5, 0x34, 0xE7, 0xD7, 0x09, 0x7B,
2673
+ 0x15, 0x49, 0x1D, 0x76, 0x31, 0xD6, 0x71, 0xEC, 0x13, 0x4E, 0x89, 0x8C,
2674
+ 0x09, 0x22, 0xD8, 0xE7, 0xA3, 0xE9, 0x7D, 0x21, 0x51, 0x26, 0x6E, 0x9F,
2675
+ 0x30, 0x8A, 0xBB, 0xBC, 0x74, 0xC1, 0xC3, 0x27, 0x6A, 0xCE, 0xA3, 0x12,
2676
+ 0x60, 0x68, 0x01, 0xD2, 0x34, 0x07, 0x80, 0xCC, 0x2D, 0x7F, 0x5C, 0xAE,
2677
+ 0xA2, 0x97, 0x40, 0xC8, 0x3C, 0xAC, 0xDB, 0x6F, 0xFE, 0x6C, 0x6D, 0xD2,
2678
+ 0x06, 0x1C, 0x43, 0xA2, 0xB2, 0x2B, 0x82, 0xB7, 0xD0, 0xAB, 0x3F, 0x2C,
2679
+ 0xE7, 0x9C, 0x19, 0x16, 0xD1, 0x5E, 0x26, 0x86, 0xC7, 0x92, 0xF9, 0x16,
2680
+ 0x0B, 0xFA, 0x66, 0x83
2681
+ };
2682
+
2683
+ /* dh2048 g */
2684
+ static const unsigned char test_dh_g[] =
2685
+ {
2686
+ 0x02,
2687
+ };
2688
+ #else
2689
+ /* dh1024 p */
2690
+ static const unsigned char test_dh_p[] =
2691
+ {
2692
+ 0xE6, 0x96, 0x9D, 0x3D, 0x49, 0x5B, 0xE3, 0x2C, 0x7C, 0xF1, 0x80, 0xC3,
2693
+ 0xBD, 0xD4, 0x79, 0x8E, 0x91, 0xB7, 0x81, 0x82, 0x51, 0xBB, 0x05, 0x5E,
2694
+ 0x2A, 0x20, 0x64, 0x90, 0x4A, 0x79, 0xA7, 0x70, 0xFA, 0x15, 0xA2, 0x59,
2695
+ 0xCB, 0xD5, 0x23, 0xA6, 0xA6, 0xEF, 0x09, 0xC4, 0x30, 0x48, 0xD5, 0xA2,
2696
+ 0x2F, 0x97, 0x1F, 0x3C, 0x20, 0x12, 0x9B, 0x48, 0x00, 0x0E, 0x6E, 0xDD,
2697
+ 0x06, 0x1C, 0xBC, 0x05, 0x3E, 0x37, 0x1D, 0x79, 0x4E, 0x53, 0x27, 0xDF,
2698
+ 0x61, 0x1E, 0xBB, 0xBE, 0x1B, 0xAC, 0x9B, 0x5C, 0x60, 0x44, 0xCF, 0x02,
2699
+ 0x3D, 0x76, 0xE0, 0x5E, 0xEA, 0x9B, 0xAD, 0x99, 0x1B, 0x13, 0xA6, 0x3C,
2700
+ 0x97, 0x4E, 0x9E, 0xF1, 0x83, 0x9E, 0xB5, 0xDB, 0x12, 0x51, 0x36, 0xF7,
2701
+ 0x26, 0x2E, 0x56, 0xA8, 0x87, 0x15, 0x38, 0xDF, 0xD8, 0x23, 0xC6, 0x50,
2702
+ 0x50, 0x85, 0xE2, 0x1F, 0x0D, 0xD5, 0xC8, 0x6B,
2703
+ };
2704
+
2705
+ /* dh1024 g */
2706
+ static const unsigned char test_dh_g[] =
2707
+ {
2708
+ 0x02,
2709
+ };
2710
+ #endif
2711
+
2712
+ static WC_INLINE void SetDH(WOLFSSL* ssl)
2713
+ {
2714
+ wolfSSL_SetTmpDH(ssl, test_dh_p, sizeof(test_dh_p), test_dh_g,
2715
+ sizeof(test_dh_g));
2716
+ }
2717
+
2718
+ static WC_INLINE void SetDHCtx(WOLFSSL_CTX* ctx)
2719
+ {
2720
+ wolfSSL_CTX_SetTmpDH(ctx, test_dh_p, sizeof(test_dh_p), test_dh_g,
2721
+ sizeof(test_dh_g));
2722
+ }
2723
+ #endif /* NO_DH */
2724
+
2725
+ #ifndef NO_CERTS
2726
+
2727
+ static WC_INLINE void CaCb(unsigned char* der, int sz, int type)
2728
+ {
2729
+ (void)der;
2730
+ printf("Got CA cache add callback, derSz = %d, type = %d\n", sz, type);
2731
+ }
2732
+
2733
+ #endif /* !NO_CERTS */
2734
+
2735
+
2736
+ /* Wolf Root Directory Helper */
2737
+ /* KEIL-RL File System does not support relative directory */
2738
+ #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOLFSSL_TIRTOS)
2739
+ /* Maximum depth to search for WolfSSL root */
2740
+ #define MAX_WOLF_ROOT_DEPTH 5
2741
+
2742
+ static WC_INLINE int ChangeToWolfRoot(void)
2743
+ {
2744
+ #if (!defined(NO_FILESYSTEM) || defined(FORCE_BUFFER_TEST)) && \
2745
+ !defined(NETOS)
2746
+ int depth;
2747
+ for(depth = 0; depth <= MAX_WOLF_ROOT_DEPTH; depth++) {
2748
+ int res;
2749
+ XFILE keyFile = XFOPEN(dhParamFile, "rb");
2750
+ if (keyFile != NULL) {
2751
+ fclose(keyFile);
2752
+ return depth;
2753
+ }
2754
+ #ifdef USE_WINDOWS_API
2755
+ res = SetCurrentDirectoryA("..\\");
2756
+ #elif defined(NETOS)
2757
+ return 0;
2758
+ #else
2759
+ res = chdir("../");
2760
+ #endif
2761
+ if (res < 0) {
2762
+ printf("chdir to ../ failed!\n");
2763
+ break;
2764
+ }
2765
+ }
2766
+
2767
+ err_sys("wolf root not found");
2768
+ return -1;
2769
+ #else
2770
+ return 0;
2771
+ #endif
2772
+ }
2773
+ #endif /* !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOLFSSL_TIRTOS) */
2774
+
2775
+
2776
+ #if defined(ATOMIC_USER) && !defined(WOLFSSL_AEAD_ONLY)
2777
+
2778
+ /* Atomic Encrypt Context example */
2779
+ typedef struct AtomicEncCtx {
2780
+ int keySetup; /* have we done key setup yet */
2781
+ Aes aes; /* for aes example */
2782
+ } AtomicEncCtx;
2783
+
2784
+
2785
+ /* Atomic Decrypt Context example */
2786
+ typedef struct AtomicDecCtx {
2787
+ int keySetup; /* have we done key setup yet */
2788
+ Aes aes; /* for aes example */
2789
+ } AtomicDecCtx;
2790
+
2791
+ #if !defined(NO_HMAC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
2792
+ static WC_INLINE int myMacEncryptCb(WOLFSSL* ssl, unsigned char* macOut,
2793
+ const unsigned char* macIn, unsigned int macInSz, int macContent,
2794
+ int macVerify, unsigned char* encOut, const unsigned char* encIn,
2795
+ unsigned int encSz, void* ctx)
2796
+ {
2797
+ int ret;
2798
+ Hmac hmac;
2799
+ byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2800
+ AtomicEncCtx* encCtx = (AtomicEncCtx*)ctx;
2801
+ const char* tlsStr = "TLS";
2802
+
2803
+ /* example supports (d)tls aes */
2804
+ if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2805
+ printf("myMacEncryptCb not using AES\n");
2806
+ return -1;
2807
+ }
2808
+
2809
+ if (strstr(wolfSSL_get_version(ssl), tlsStr) == NULL) {
2810
+ printf("myMacEncryptCb not using (D)TLS\n");
2811
+ return -1;
2812
+ }
2813
+
2814
+ /* hmac, not needed if aead mode */
2815
+ wolfSSL_SetTlsHmacInner(ssl, myInner, macInSz, macContent, macVerify);
2816
+
2817
+ ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
2818
+ if (ret != 0)
2819
+ return ret;
2820
+ ret = wc_HmacSetKey(&hmac, wolfSSL_GetHmacType(ssl),
2821
+ wolfSSL_GetMacSecret(ssl, macVerify), (word32) wolfSSL_GetHmacSize(ssl));
2822
+ if (ret != 0)
2823
+ return ret;
2824
+ ret = wc_HmacUpdate(&hmac, myInner, sizeof(myInner));
2825
+ if (ret != 0)
2826
+ return ret;
2827
+ ret = wc_HmacUpdate(&hmac, macIn, macInSz);
2828
+ if (ret != 0)
2829
+ return ret;
2830
+ ret = wc_HmacFinal(&hmac, macOut);
2831
+ if (ret != 0)
2832
+ return ret;
2833
+
2834
+
2835
+ /* encrypt setup on first time */
2836
+ if (encCtx->keySetup == 0) {
2837
+ int keyLen = wolfSSL_GetKeySize(ssl);
2838
+ const byte* key;
2839
+ const byte* iv;
2840
+
2841
+ if (wolfSSL_GetSide(ssl) == WOLFSSL_CLIENT_END) {
2842
+ key = wolfSSL_GetClientWriteKey(ssl);
2843
+ iv = wolfSSL_GetClientWriteIV(ssl);
2844
+ }
2845
+ else {
2846
+ key = wolfSSL_GetServerWriteKey(ssl);
2847
+ iv = wolfSSL_GetServerWriteIV(ssl);
2848
+ }
2849
+
2850
+ ret = wc_AesInit(&encCtx->aes, NULL, INVALID_DEVID);
2851
+ if (ret != 0) {
2852
+ fprintf(stderr, "AesInit failed in myMacEncryptCb\n");
2853
+ return ret;
2854
+ }
2855
+ ret = wc_AesSetKey(&encCtx->aes, key, (word32) keyLen, iv, AES_ENCRYPTION);
2856
+ if (ret != 0) {
2857
+ fprintf(stderr, "AesSetKey failed in myMacEncryptCb\n");
2858
+ return ret;
2859
+ }
2860
+ encCtx->keySetup = 1;
2861
+ }
2862
+
2863
+ /* encrypt */
2864
+ return wc_AesCbcEncrypt(&encCtx->aes, encOut, encIn, encSz);
2865
+ }
2866
+
2867
+ static WC_INLINE int myDecryptVerifyCb(WOLFSSL* ssl,
2868
+ unsigned char* decOut, const unsigned char* decIn,
2869
+ unsigned int decSz, int macContent, int macVerify,
2870
+ unsigned int* padSz, void* ctx)
2871
+ {
2872
+ AtomicDecCtx* decCtx = (AtomicDecCtx*)ctx;
2873
+ int ret = 0;
2874
+ unsigned int macInSz = 0;
2875
+ int ivExtra = 0;
2876
+ int digestSz = wolfSSL_GetHmacSize(ssl);
2877
+ unsigned int pad = 0;
2878
+ unsigned int padByte = 0;
2879
+ Hmac hmac;
2880
+ byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2881
+ byte verify[WC_MAX_DIGEST_SIZE];
2882
+ const char* tlsStr = "TLS";
2883
+
2884
+ /* example supports (d)tls aes */
2885
+ if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2886
+ printf("myMacEncryptCb not using AES\n");
2887
+ return -1;
2888
+ }
2889
+
2890
+ if (strstr(wolfSSL_get_version(ssl), tlsStr) == NULL) {
2891
+ printf("myMacEncryptCb not using (D)TLS\n");
2892
+ return -1;
2893
+ }
2894
+
2895
+ /*decrypt */
2896
+ if (decCtx->keySetup == 0) {
2897
+ int keyLen = wolfSSL_GetKeySize(ssl);
2898
+ const byte* key;
2899
+ const byte* iv;
2900
+
2901
+ /* decrypt is from other side (peer) */
2902
+ if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
2903
+ key = wolfSSL_GetClientWriteKey(ssl);
2904
+ iv = wolfSSL_GetClientWriteIV(ssl);
2905
+ }
2906
+ else {
2907
+ key = wolfSSL_GetServerWriteKey(ssl);
2908
+ iv = wolfSSL_GetServerWriteIV(ssl);
2909
+ }
2910
+
2911
+ ret = wc_AesInit(&decCtx->aes, NULL, INVALID_DEVID);
2912
+ if (ret != 0) {
2913
+ fprintf(stderr, "AesInit failed in myDecryptVerifyCb\n");
2914
+ return ret;
2915
+ }
2916
+ ret = wc_AesSetKey(&decCtx->aes, key, (word32) keyLen, iv, AES_DECRYPTION);
2917
+ if (ret != 0) {
2918
+ fprintf(stderr, "AesSetKey failed in myDecryptVerifyCb\n");
2919
+ return ret;
2920
+ }
2921
+ decCtx->keySetup = 1;
2922
+ }
2923
+
2924
+ /* decrypt */
2925
+ ret = wc_AesCbcDecrypt(&decCtx->aes, decOut, decIn, decSz);
2926
+ if (ret != 0)
2927
+ return ret;
2928
+
2929
+ if (wolfSSL_GetCipherType(ssl) == WOLFSSL_AEAD_TYPE) {
2930
+ *padSz = (unsigned int)wolfSSL_GetAeadMacSize(ssl);
2931
+ return 0; /* hmac, not needed if aead mode */
2932
+ }
2933
+
2934
+ if (wolfSSL_GetCipherType(ssl) == WOLFSSL_BLOCK_TYPE) {
2935
+ pad = *(decOut + decSz - 1);
2936
+ padByte = 1;
2937
+ if (wolfSSL_IsTLSv1_1(ssl))
2938
+ ivExtra = wolfSSL_GetCipherBlockSize(ssl);
2939
+ }
2940
+
2941
+ *padSz = (unsigned int)wolfSSL_GetHmacSize(ssl) + pad + padByte;
2942
+ macInSz = decSz - (unsigned int)ivExtra - (unsigned int)digestSz - pad - padByte;
2943
+
2944
+ wolfSSL_SetTlsHmacInner(ssl, myInner, macInSz, macContent, macVerify);
2945
+
2946
+ ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
2947
+ if (ret != 0)
2948
+ return ret;
2949
+ ret = wc_HmacSetKey(&hmac, wolfSSL_GetHmacType(ssl),
2950
+ wolfSSL_GetMacSecret(ssl, macVerify), (unsigned int) digestSz);
2951
+ if (ret != 0)
2952
+ return ret;
2953
+ ret = wc_HmacUpdate(&hmac, myInner, sizeof(myInner));
2954
+ if (ret != 0)
2955
+ return ret;
2956
+ ret = wc_HmacUpdate(&hmac, decOut + ivExtra, macInSz);
2957
+ if (ret != 0)
2958
+ return ret;
2959
+ ret = wc_HmacFinal(&hmac, verify);
2960
+ if (ret != 0)
2961
+ return ret;
2962
+
2963
+ if (XMEMCMP(verify, decOut + decSz - digestSz - pad - padByte,
2964
+ (size_t) digestSz) != 0) {
2965
+ printf("myDecryptVerify verify failed\n");
2966
+ return -1;
2967
+ }
2968
+
2969
+ return ret;
2970
+ }
2971
+
2972
+ #ifdef HAVE_ENCRYPT_THEN_MAC
2973
+
2974
+ static WC_INLINE int myEncryptMacCb(WOLFSSL* ssl, unsigned char* macOut,
2975
+ int content, int macVerify, unsigned char* encOut,
2976
+ const unsigned char* encIn, unsigned int encSz, void* ctx)
2977
+ {
2978
+ int ret;
2979
+ Hmac hmac;
2980
+ AtomicEncCtx* encCtx = (AtomicEncCtx*)ctx;
2981
+ byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
2982
+ const char* tlsStr = "TLS";
2983
+
2984
+ /* example supports (d)tls aes */
2985
+ if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
2986
+ printf("myMacEncryptCb not using AES\n");
2987
+ return -1;
2988
+ }
2989
+
2990
+ if (strstr(wolfSSL_get_version(ssl), tlsStr) == NULL) {
2991
+ printf("myMacEncryptCb not using (D)TLS\n");
2992
+ return -1;
2993
+ }
2994
+
2995
+ /* encrypt setup on first time */
2996
+ if (encCtx->keySetup == 0) {
2997
+ int keyLen = wolfSSL_GetKeySize(ssl);
2998
+ const byte* key;
2999
+ const byte* iv;
3000
+
3001
+ if (wolfSSL_GetSide(ssl) == WOLFSSL_CLIENT_END) {
3002
+ key = wolfSSL_GetClientWriteKey(ssl);
3003
+ iv = wolfSSL_GetClientWriteIV(ssl);
3004
+ }
3005
+ else {
3006
+ key = wolfSSL_GetServerWriteKey(ssl);
3007
+ iv = wolfSSL_GetServerWriteIV(ssl);
3008
+ }
3009
+
3010
+ ret = wc_AesInit(&encCtx->aes, NULL, INVALID_DEVID);
3011
+ if (ret != 0) {
3012
+ fprintf(stderr, "AesInit failed in myMacEncryptCb\n");
3013
+ return ret;
3014
+ }
3015
+ ret = wc_AesSetKey(&encCtx->aes, key, (word32) keyLen, iv, AES_ENCRYPTION);
3016
+ if (ret != 0) {
3017
+ fprintf(stderr, "AesSetKey failed in myMacEncryptCb\n");
3018
+ return ret;
3019
+ }
3020
+ encCtx->keySetup = 1;
3021
+ }
3022
+
3023
+ /* encrypt */
3024
+ ret = wc_AesCbcEncrypt(&encCtx->aes, encOut, encIn, encSz);
3025
+ if (ret != 0)
3026
+ return ret;
3027
+
3028
+ /* Reconstruct record header. */
3029
+ wolfSSL_SetTlsHmacInner(ssl, myInner, encSz, content, macVerify);
3030
+
3031
+ ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
3032
+ if (ret != 0)
3033
+ return ret;
3034
+ ret = wc_HmacSetKey(&hmac, wolfSSL_GetHmacType(ssl),
3035
+ wolfSSL_GetMacSecret(ssl, macVerify), (word32) wolfSSL_GetHmacSize(ssl));
3036
+ if (ret != 0)
3037
+ return ret;
3038
+ ret = wc_HmacUpdate(&hmac, myInner, sizeof(myInner));
3039
+ if (ret != 0)
3040
+ return ret;
3041
+ ret = wc_HmacUpdate(&hmac, encOut, encSz);
3042
+ if (ret != 0)
3043
+ return ret;
3044
+ return wc_HmacFinal(&hmac, macOut);
3045
+ }
3046
+
3047
+
3048
+ static WC_INLINE int myVerifyDecryptCb(WOLFSSL* ssl,
3049
+ unsigned char* decOut, const unsigned char* decIn,
3050
+ unsigned int decSz, int content, int macVerify,
3051
+ unsigned int* padSz, void* ctx)
3052
+ {
3053
+ AtomicDecCtx* decCtx = (AtomicDecCtx*)ctx;
3054
+ int ret = 0;
3055
+ int digestSz = wolfSSL_GetHmacSize(ssl);
3056
+ Hmac hmac;
3057
+ byte myInner[WOLFSSL_TLS_HMAC_INNER_SZ];
3058
+ byte verify[WC_MAX_DIGEST_SIZE];
3059
+ const char* tlsStr = "TLS";
3060
+
3061
+ /* example supports (d)tls aes */
3062
+ if (wolfSSL_GetBulkCipher(ssl) != wolfssl_aes) {
3063
+ printf("myMacEncryptCb not using AES\n");
3064
+ return -1;
3065
+ }
3066
+
3067
+ if (strstr(wolfSSL_get_version(ssl), tlsStr) == NULL) {
3068
+ printf("myMacEncryptCb not using (D)TLS\n");
3069
+ return -1;
3070
+ }
3071
+
3072
+ /* Reconstruct record header. */
3073
+ wolfSSL_SetTlsHmacInner(ssl, myInner, decSz, content, macVerify);
3074
+
3075
+ ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
3076
+ if (ret != 0)
3077
+ return ret;
3078
+ ret = wc_HmacSetKey(&hmac, wolfSSL_GetHmacType(ssl),
3079
+ wolfSSL_GetMacSecret(ssl, macVerify), (word32) digestSz);
3080
+ if (ret != 0)
3081
+ return ret;
3082
+ ret = wc_HmacUpdate(&hmac, myInner, sizeof(myInner));
3083
+ if (ret != 0)
3084
+ return ret;
3085
+ ret = wc_HmacUpdate(&hmac, decIn, decSz);
3086
+ if (ret != 0)
3087
+ return ret;
3088
+ ret = wc_HmacFinal(&hmac, verify);
3089
+ if (ret != 0)
3090
+ return ret;
3091
+
3092
+ if (XMEMCMP(verify, decOut + decSz, (size_t) digestSz) != 0) {
3093
+ printf("myDecryptVerify verify failed\n");
3094
+ return -1;
3095
+ }
3096
+
3097
+ /* decrypt */
3098
+ if (decCtx->keySetup == 0) {
3099
+ int keyLen = wolfSSL_GetKeySize(ssl);
3100
+ const byte* key;
3101
+ const byte* iv;
3102
+
3103
+ /* decrypt is from other side (peer) */
3104
+ if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
3105
+ key = wolfSSL_GetClientWriteKey(ssl);
3106
+ iv = wolfSSL_GetClientWriteIV(ssl);
3107
+ }
3108
+ else {
3109
+ key = wolfSSL_GetServerWriteKey(ssl);
3110
+ iv = wolfSSL_GetServerWriteIV(ssl);
3111
+ }
3112
+
3113
+ ret = wc_AesInit(&decCtx->aes, NULL, INVALID_DEVID);
3114
+ if (ret != 0) {
3115
+ fprintf(stderr, "AesInit failed in myDecryptVerifyCb\n");
3116
+ return ret;
3117
+ }
3118
+ ret = wc_AesSetKey(&decCtx->aes, key, (word32) keyLen, iv, AES_DECRYPTION);
3119
+ if (ret != 0) {
3120
+ fprintf(stderr, "AesSetKey failed in myDecryptVerifyCb\n");
3121
+ return ret;
3122
+ }
3123
+ decCtx->keySetup = 1;
3124
+ }
3125
+
3126
+ /* decrypt */
3127
+ ret = wc_AesCbcDecrypt(&decCtx->aes, decOut, decIn, decSz);
3128
+ if (ret != 0)
3129
+ return ret;
3130
+
3131
+ *padSz = *(decOut + decSz - 1) + 1;
3132
+
3133
+ return 0;
3134
+ }
3135
+
3136
+ #endif /* HAVE_ENCRYPT_THEN_MAC */
3137
+ #endif /* !NO_HMAC && !NO_AES && HAVE_AES_CBC */
3138
+
3139
+
3140
+ static WC_INLINE void SetupAtomicUser(WOLFSSL_CTX* ctx, WOLFSSL* ssl)
3141
+ {
3142
+ #if !defined(NO_HMAC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
3143
+ AtomicEncCtx* encCtx;
3144
+ AtomicDecCtx* decCtx;
3145
+
3146
+ encCtx = (AtomicEncCtx*)malloc(sizeof(AtomicEncCtx));
3147
+ if (encCtx == NULL)
3148
+ err_sys_with_errno("AtomicEncCtx malloc failed");
3149
+ XMEMSET(encCtx, 0, sizeof(AtomicEncCtx));
3150
+
3151
+ decCtx = (AtomicDecCtx*)malloc(sizeof(AtomicDecCtx));
3152
+ if (decCtx == NULL) {
3153
+ free(encCtx);
3154
+ err_sys_with_errno("AtomicDecCtx malloc failed");
3155
+ }
3156
+ XMEMSET(decCtx, 0, sizeof(AtomicDecCtx));
3157
+
3158
+ wolfSSL_CTX_SetMacEncryptCb(ctx, myMacEncryptCb);
3159
+ wolfSSL_SetMacEncryptCtx(ssl, encCtx);
3160
+
3161
+ wolfSSL_CTX_SetDecryptVerifyCb(ctx, myDecryptVerifyCb);
3162
+ wolfSSL_SetDecryptVerifyCtx(ssl, decCtx);
3163
+
3164
+ #ifdef HAVE_ENCRYPT_THEN_MAC
3165
+ wolfSSL_CTX_SetEncryptMacCb(ctx, myEncryptMacCb);
3166
+ wolfSSL_SetEncryptMacCtx(ssl, encCtx);
3167
+
3168
+ wolfSSL_CTX_SetVerifyDecryptCb(ctx, myVerifyDecryptCb);
3169
+ wolfSSL_SetVerifyDecryptCtx(ssl, decCtx);
3170
+ #endif
3171
+ #else
3172
+ (void)ctx;
3173
+ (void)ssl;
3174
+ #endif
3175
+ }
3176
+
3177
+
3178
+ static WC_INLINE void FreeAtomicUser(WOLFSSL* ssl)
3179
+ {
3180
+ AtomicEncCtx* encCtx = (AtomicEncCtx*)wolfSSL_GetMacEncryptCtx(ssl);
3181
+ AtomicDecCtx* decCtx = (AtomicDecCtx*)wolfSSL_GetDecryptVerifyCtx(ssl);
3182
+
3183
+ /* Encrypt-Then-MAC callbacks use same contexts. */
3184
+
3185
+ if (encCtx != NULL) {
3186
+ if (encCtx->keySetup == 1)
3187
+ wc_AesFree(&encCtx->aes);
3188
+ free(encCtx);
3189
+ }
3190
+ if (decCtx != NULL) {
3191
+ if (decCtx->keySetup == 1)
3192
+ wc_AesFree(&decCtx->aes);
3193
+ free(decCtx);
3194
+ }
3195
+ }
3196
+
3197
+ #endif /* ATOMIC_USER */
3198
+
3199
+ #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
3200
+ static WC_INLINE int wolfSSL_PrintStats(WOLFSSL_MEM_STATS* stats)
3201
+ {
3202
+ word16 i;
3203
+
3204
+ if (stats == NULL) {
3205
+ return 0;
3206
+ }
3207
+
3208
+ /* print to stderr so is on the same pipe as DEBUG_WOLFSSL */
3209
+ fprintf(stderr, "Total mallocs = %d\n", stats->totalAlloc);
3210
+ fprintf(stderr, "Total frees = %d\n", stats->totalFr);
3211
+ fprintf(stderr, "Current mallocs = %d\n", stats->curAlloc);
3212
+ fprintf(stderr, "Available IO = %d\n", stats->avaIO);
3213
+ fprintf(stderr, "Max con. handshakes = %d\n", stats->maxHa);
3214
+ fprintf(stderr, "Max con. IO = %d\n", stats->maxIO);
3215
+ fprintf(stderr, "State of memory blocks: size : available \n");
3216
+ for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
3217
+ fprintf(stderr, " : %d\t : %d\n", stats->blockSz[i],
3218
+ stats->avaBlock[i]);
3219
+ }
3220
+
3221
+ return 1;
3222
+ }
3223
+
3224
+ static WC_INLINE int wolfSSL_PrintStatsConn(WOLFSSL_MEM_CONN_STATS* stats)
3225
+ {
3226
+ if (stats == NULL) {
3227
+ return 0;
3228
+ }
3229
+
3230
+ fprintf(stderr, "peak connection memory = %d\n", stats->peakMem);
3231
+ fprintf(stderr, "current memory in use = %d\n", stats->curMem);
3232
+ fprintf(stderr, "peak connection allocs = %d\n", stats->peakAlloc);
3233
+ fprintf(stderr, "current connection allocs = %d\n",stats->curAlloc);
3234
+ fprintf(stderr, "total connection allocs = %d\n", stats->totalAlloc);
3235
+ fprintf(stderr, "total connection frees = %d\n\n", stats->totalFr);
3236
+
3237
+ return 1;
3238
+ }
3239
+ #endif /* WOLFSSL_STATIC_MEMORY */
3240
+
3241
+ #ifdef HAVE_PK_CALLBACKS
3242
+
3243
+ typedef struct PkCbInfo {
3244
+ const char* ourKey;
3245
+ #ifdef TEST_PK_PRIVKEY
3246
+ union {
3247
+ #ifdef HAVE_ECC
3248
+ /* only ECC PK callback with TLS v1.2 needs this */
3249
+ ecc_key ecc;
3250
+ #endif
3251
+ } keyGen;
3252
+ int hasKeyGen;
3253
+ #endif
3254
+ } PkCbInfo;
3255
+
3256
+ #ifdef HAVE_ECC
3257
+
3258
+ static WC_INLINE int myEccKeyGen(WOLFSSL* ssl, ecc_key* key, word32 keySz,
3259
+ int ecc_curve, void* ctx)
3260
+ {
3261
+ int ret;
3262
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3263
+ ecc_key* new_key;
3264
+
3265
+ #ifdef TEST_PK_PRIVKEY
3266
+ new_key = cbInfo ? &cbInfo->keyGen.ecc : key;
3267
+ #else
3268
+ new_key = key;
3269
+ #endif
3270
+
3271
+ (void)ssl;
3272
+ (void)cbInfo;
3273
+
3274
+ WOLFSSL_PKMSG("PK ECC KeyGen: keySz %u, Curve ID %d\n", keySz, ecc_curve);
3275
+
3276
+ ret = wc_ecc_init(new_key);
3277
+ if (ret == 0) {
3278
+ WC_RNG *rng = wolfSSL_GetRNG(ssl);
3279
+
3280
+ /* create new key */
3281
+ ret = wc_ecc_make_key_ex(rng, (int) keySz, new_key, ecc_curve);
3282
+
3283
+ #ifdef TEST_PK_PRIVKEY
3284
+ if (ret == 0 && new_key != key) {
3285
+ byte qx[MAX_ECC_BYTES], qy[MAX_ECC_BYTES];
3286
+ word32 qxLen = sizeof(qx), qyLen = sizeof(qy);
3287
+
3288
+ /* extract public portion from new key into `key` arg */
3289
+ ret = wc_ecc_export_public_raw(new_key, qx, &qxLen, qy, &qyLen);
3290
+ if (ret == 0) {
3291
+ /* load public portion only into key */
3292
+ ret = wc_ecc_import_unsigned(key, qx, qy, NULL, ecc_curve);
3293
+ }
3294
+ (void)qxLen;
3295
+ (void)qyLen;
3296
+ }
3297
+ if (ret == 0 && cbInfo != NULL) {
3298
+ cbInfo->hasKeyGen = 1;
3299
+ }
3300
+ #endif
3301
+ }
3302
+
3303
+ WOLFSSL_PKMSG("PK ECC KeyGen: ret %d\n", ret);
3304
+
3305
+ return ret;
3306
+ }
3307
+
3308
+ static WC_INLINE int myEccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
3309
+ byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx)
3310
+ {
3311
+ int ret;
3312
+ word32 idx = 0;
3313
+ ecc_key myKey;
3314
+ byte* keyBuf = (byte*)key;
3315
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3316
+
3317
+ (void)ssl;
3318
+ (void)cbInfo;
3319
+
3320
+ WOLFSSL_PKMSG("PK ECC Sign: inSz %u, keySz %u\n", inSz, keySz);
3321
+
3322
+ #ifdef TEST_PK_PRIVKEY
3323
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3324
+ if (ret != 0)
3325
+ return ret;
3326
+ #endif
3327
+
3328
+ ret = wc_ecc_init(&myKey);
3329
+ if (ret == 0) {
3330
+ ret = wc_EccPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
3331
+ if (ret == 0) {
3332
+ WC_RNG *rng = wolfSSL_GetRNG(ssl);
3333
+
3334
+ WOLFSSL_PKMSG("PK ECC Sign: Curve ID %d\n", myKey.dp->id);
3335
+ ret = wc_ecc_sign_hash(in, inSz, out, outSz, rng, &myKey);
3336
+ }
3337
+ wc_ecc_free(&myKey);
3338
+ }
3339
+
3340
+ #ifdef TEST_PK_PRIVKEY
3341
+ free(keyBuf);
3342
+ #endif
3343
+
3344
+ WOLFSSL_PKMSG("PK ECC Sign: ret %d outSz %u\n", ret, *outSz);
3345
+
3346
+ return ret;
3347
+ }
3348
+
3349
+
3350
+ static WC_INLINE int myEccVerify(WOLFSSL* ssl, const byte* sig, word32 sigSz,
3351
+ const byte* hash, word32 hashSz, const byte* key, word32 keySz,
3352
+ int* result, void* ctx)
3353
+ {
3354
+ int ret;
3355
+ word32 idx = 0;
3356
+ ecc_key myKey;
3357
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3358
+
3359
+ (void)ssl;
3360
+ (void)cbInfo;
3361
+
3362
+ WOLFSSL_PKMSG("PK ECC Verify: sigSz %u, hashSz %u, keySz %u\n", sigSz, hashSz, keySz);
3363
+
3364
+ ret = wc_ecc_init(&myKey);
3365
+ if (ret == 0) {
3366
+ ret = wc_EccPublicKeyDecode(key, &idx, &myKey, keySz);
3367
+ if (ret == 0)
3368
+ ret = wc_ecc_verify_hash(sig, sigSz, hash, hashSz, result, &myKey);
3369
+ wc_ecc_free(&myKey);
3370
+ }
3371
+
3372
+ WOLFSSL_PKMSG("PK ECC Verify: ret %d, result %d\n", ret, *result);
3373
+
3374
+ return ret;
3375
+ }
3376
+
3377
+ static WC_INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey,
3378
+ unsigned char* pubKeyDer, unsigned int* pubKeySz,
3379
+ unsigned char* out, unsigned int* outlen,
3380
+ int side, void* ctx)
3381
+ {
3382
+ int ret;
3383
+ ecc_key* privKey = NULL;
3384
+ ecc_key* pubKey = NULL;
3385
+ ecc_key tmpKey;
3386
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3387
+
3388
+ (void)ssl;
3389
+ (void)cbInfo;
3390
+
3391
+ WOLFSSL_PKMSG("PK ECC PMS: Side %s, Peer Curve %d\n",
3392
+ side == WOLFSSL_CLIENT_END ? "client" : "server", otherKey->dp->id);
3393
+
3394
+ ret = wc_ecc_init(&tmpKey);
3395
+ if (ret != 0) {
3396
+ return ret;
3397
+ }
3398
+
3399
+ /* for client: create and export public key */
3400
+ if (side == WOLFSSL_CLIENT_END) {
3401
+ #ifdef TEST_PK_PRIVKEY
3402
+ privKey = cbInfo ? &cbInfo->keyGen.ecc : &tmpKey;
3403
+ #else
3404
+ privKey = &tmpKey;
3405
+ #endif
3406
+ pubKey = otherKey;
3407
+
3408
+ /* TLS v1.2 and older we must generate a key here for the client only.
3409
+ * TLS v1.3 calls key gen early with key share */
3410
+ if (wolfSSL_GetVersion(ssl) < WOLFSSL_TLSV1_3) {
3411
+ ret = myEccKeyGen(ssl, privKey, 0, otherKey->dp->id, ctx);
3412
+ if (ret == 0) {
3413
+ ret = wc_ecc_export_x963(privKey, pubKeyDer, pubKeySz);
3414
+ }
3415
+ }
3416
+ }
3417
+
3418
+ /* for server: import public key */
3419
+ else if (side == WOLFSSL_SERVER_END) {
3420
+ #ifdef TEST_PK_PRIVKEY
3421
+ privKey = cbInfo ? &cbInfo->keyGen.ecc : otherKey;
3422
+ #else
3423
+ privKey = otherKey;
3424
+ #endif
3425
+ pubKey = &tmpKey;
3426
+
3427
+ ret = wc_ecc_import_x963_ex(pubKeyDer, *pubKeySz, pubKey,
3428
+ otherKey->dp->id);
3429
+ }
3430
+ else {
3431
+ ret = BAD_FUNC_ARG;
3432
+ }
3433
+
3434
+ if (privKey == NULL || pubKey == NULL) {
3435
+ ret = BAD_FUNC_ARG;
3436
+ }
3437
+
3438
+ #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
3439
+ (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
3440
+ !defined(HAVE_SELFTEST)
3441
+ if (ret == 0) {
3442
+ ret = wc_ecc_set_rng(privKey, wolfSSL_GetRNG(ssl));
3443
+ }
3444
+ #endif
3445
+
3446
+ /* generate shared secret and return it */
3447
+ if (ret == 0) {
3448
+ ret = wc_ecc_shared_secret(privKey, pubKey, out, outlen);
3449
+
3450
+ #ifdef WOLFSSL_ASYNC_CRYPT
3451
+ if (ret == WC_PENDING_E) {
3452
+ ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
3453
+ }
3454
+ #endif
3455
+ }
3456
+
3457
+ #ifdef TEST_PK_PRIVKEY
3458
+ if (cbInfo && cbInfo->hasKeyGen) {
3459
+ wc_ecc_free(&cbInfo->keyGen.ecc);
3460
+ cbInfo->hasKeyGen = 0;
3461
+ }
3462
+ #endif
3463
+
3464
+ wc_ecc_free(&tmpKey);
3465
+
3466
+ WOLFSSL_PKMSG("PK ECC PMS: ret %d, PubKeySz %u, OutLen %u\n", ret, *pubKeySz, *outlen);
3467
+
3468
+ return ret;
3469
+ }
3470
+
3471
+ #endif /* HAVE_ECC */
3472
+
3473
+ #if defined(HAVE_HKDF) && !defined(NO_HMAC)
3474
+ static WC_INLINE int myHkdfExtract(byte* prk, const byte* salt, word32 saltLen,
3475
+ byte* ikm, word32 ikmLen, int digest, void* ctx)
3476
+ {
3477
+ int ret;
3478
+ word32 len = 0;
3479
+
3480
+ switch (digest) {
3481
+ #ifndef NO_SHA256
3482
+ case WC_SHA256:
3483
+ len = WC_SHA256_DIGEST_SIZE;
3484
+ break;
3485
+ #endif
3486
+
3487
+ #ifdef WOLFSSL_SHA384
3488
+ case WC_SHA384:
3489
+ len = WC_SHA384_DIGEST_SIZE;
3490
+ break;
3491
+ #endif
3492
+
3493
+ #ifdef WOLFSSL_TLS13_SHA512
3494
+ case WC_SHA512:
3495
+ len = WC_SHA512_DIGEST_SIZE;
3496
+ break;
3497
+ #endif
3498
+ default:
3499
+ return BAD_FUNC_ARG;
3500
+ }
3501
+
3502
+ /* When length is 0 then use zeroed data of digest length. */
3503
+ if (ikmLen == 0) {
3504
+ ikmLen = len;
3505
+ XMEMSET(ikm, 0, len);
3506
+ }
3507
+
3508
+ (void)ctx;
3509
+ ret = wc_HKDF_Extract(digest, salt, saltLen, ikm, ikmLen, prk);
3510
+ WOLFSSL_PKMSG("PK HKDF Extract: ret %d saltLen %d ikmLen %d\n", ret, saltLen,
3511
+ ikmLen);
3512
+ return ret;
3513
+ }
3514
+ #endif /* HAVE_HKDF && !NO_HMAC */
3515
+
3516
+ #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
3517
+ #ifdef HAVE_ED25519_SIGN
3518
+ static WC_INLINE int myEd25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
3519
+ byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx)
3520
+ {
3521
+ int ret;
3522
+ word32 idx = 0;
3523
+ ed25519_key myKey;
3524
+ byte* keyBuf = (byte*)key;
3525
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3526
+
3527
+ (void)ssl;
3528
+ (void)cbInfo;
3529
+
3530
+ WOLFSSL_PKMSG("PK 25519 Sign: inSz %d, keySz %d\n", inSz, keySz);
3531
+
3532
+ #ifdef TEST_PK_PRIVKEY
3533
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3534
+ if (ret != 0)
3535
+ return ret;
3536
+ #endif
3537
+
3538
+ ret = wc_ed25519_init(&myKey);
3539
+ if (ret == 0) {
3540
+ ret = wc_Ed25519PrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
3541
+ if (ret == 0) {
3542
+ ret = wc_ed25519_make_public(&myKey, myKey.p, ED25519_PUB_KEY_SIZE);
3543
+ }
3544
+ if (ret == 0) {
3545
+ myKey.pubKeySet = 1;
3546
+ ret = wc_ed25519_sign_msg(in, inSz, out, outSz, &myKey);
3547
+ }
3548
+ wc_ed25519_free(&myKey);
3549
+ }
3550
+
3551
+ #ifdef TEST_PK_PRIVKEY
3552
+ free(keyBuf);
3553
+ #endif
3554
+
3555
+ WOLFSSL_PKMSG("PK 25519 Sign: ret %d, outSz %d\n", ret, *outSz);
3556
+
3557
+ return ret;
3558
+ }
3559
+ #endif /* HAVE_ED25519_SIGN */
3560
+
3561
+
3562
+ #ifdef HAVE_ED25519_VERIFY
3563
+ static WC_INLINE int myEd25519Verify(WOLFSSL* ssl, const byte* sig, word32 sigSz,
3564
+ const byte* msg, word32 msgSz, const byte* key, word32 keySz,
3565
+ int* result, void* ctx)
3566
+ {
3567
+ int ret;
3568
+ ed25519_key myKey;
3569
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3570
+
3571
+ (void)ssl;
3572
+ (void)cbInfo;
3573
+
3574
+ WOLFSSL_PKMSG("PK 25519 Verify: sigSz %d, msgSz %d, keySz %d\n", sigSz, msgSz, keySz);
3575
+
3576
+ ret = wc_ed25519_init(&myKey);
3577
+ if (ret == 0) {
3578
+ ret = wc_ed25519_import_public(key, keySz, &myKey);
3579
+ if (ret == 0) {
3580
+ ret = wc_ed25519_verify_msg(sig, sigSz, msg, msgSz, result, &myKey);
3581
+ }
3582
+ wc_ed25519_free(&myKey);
3583
+ }
3584
+
3585
+ WOLFSSL_PKMSG("PK 25519 Verify: ret %d, result %d\n", ret, *result);
3586
+
3587
+ return ret;
3588
+ }
3589
+ #endif /* HAVE_ED25519_VERIFY */
3590
+ #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_IMPORT */
3591
+
3592
+ #ifdef HAVE_CURVE25519
3593
+ static WC_INLINE int myX25519KeyGen(WOLFSSL* ssl, curve25519_key* key,
3594
+ unsigned int keySz, void* ctx)
3595
+ {
3596
+ int ret;
3597
+ WC_RNG rng;
3598
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3599
+
3600
+ (void)ssl;
3601
+ (void)cbInfo;
3602
+
3603
+ WOLFSSL_PKMSG("PK 25519 KeyGen: keySz %u\n", keySz);
3604
+
3605
+ ret = wc_InitRng(&rng);
3606
+ if (ret != 0)
3607
+ return ret;
3608
+
3609
+ ret = wc_curve25519_make_key(&rng, (int) keySz, key);
3610
+
3611
+ wc_FreeRng(&rng);
3612
+
3613
+ WOLFSSL_PKMSG("PK 25519 KeyGen: ret %d\n", ret);
3614
+
3615
+ return ret;
3616
+ }
3617
+
3618
+ static WC_INLINE int myX25519SharedSecret(WOLFSSL* ssl, curve25519_key* otherKey,
3619
+ unsigned char* pubKeyDer, unsigned int* pubKeySz,
3620
+ unsigned char* out, unsigned int* outlen,
3621
+ int side, void* ctx)
3622
+ {
3623
+ int ret;
3624
+ curve25519_key* privKey = NULL;
3625
+ curve25519_key* pubKey = NULL;
3626
+ curve25519_key tmpKey;
3627
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3628
+
3629
+ (void)ssl;
3630
+ (void)cbInfo;
3631
+
3632
+ WOLFSSL_PKMSG("PK 25519 PMS: side %s\n",
3633
+ side == WOLFSSL_CLIENT_END ? "client" : "server");
3634
+
3635
+ ret = wc_curve25519_init(&tmpKey);
3636
+ if (ret != 0) {
3637
+ return ret;
3638
+ }
3639
+
3640
+ /* for client: create and export public key */
3641
+ if (side == WOLFSSL_CLIENT_END) {
3642
+ WC_RNG rng;
3643
+
3644
+ privKey = &tmpKey;
3645
+ pubKey = otherKey;
3646
+
3647
+ ret = wc_InitRng(&rng);
3648
+ if (ret == 0) {
3649
+ ret = wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, privKey);
3650
+ if (ret == 0) {
3651
+ ret = wc_curve25519_export_public_ex(privKey, pubKeyDer,
3652
+ pubKeySz, EC25519_LITTLE_ENDIAN);
3653
+ }
3654
+ wc_FreeRng(&rng);
3655
+ }
3656
+ }
3657
+
3658
+ /* for server: import public key */
3659
+ else if (side == WOLFSSL_SERVER_END) {
3660
+ privKey = otherKey;
3661
+ pubKey = &tmpKey;
3662
+
3663
+ ret = wc_curve25519_import_public_ex(pubKeyDer, *pubKeySz, pubKey,
3664
+ EC25519_LITTLE_ENDIAN);
3665
+ }
3666
+ else {
3667
+ ret = BAD_FUNC_ARG;
3668
+ }
3669
+
3670
+ /* generate shared secret and return it */
3671
+ if (ret == 0) {
3672
+ ret = wc_curve25519_shared_secret_ex(privKey, pubKey, out, outlen,
3673
+ EC25519_LITTLE_ENDIAN);
3674
+ }
3675
+
3676
+ wc_curve25519_free(&tmpKey);
3677
+
3678
+ WOLFSSL_PKMSG("PK 25519 PMS: ret %d, pubKeySz %u, outLen %u\n",
3679
+ ret, *pubKeySz, *outlen);
3680
+
3681
+ return ret;
3682
+ }
3683
+ #endif /* HAVE_CURVE25519 */
3684
+
3685
+ #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
3686
+ #ifdef HAVE_ED448_SIGN
3687
+ static WC_INLINE int myEd448Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
3688
+ byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx)
3689
+ {
3690
+ int ret;
3691
+ word32 idx = 0;
3692
+ ed448_key myKey;
3693
+ byte* keyBuf = (byte*)key;
3694
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3695
+
3696
+ (void)ssl;
3697
+ (void)cbInfo;
3698
+
3699
+ WOLFSSL_PKMSG("PK 448 Sign: inSz %u, keySz %u\n", inSz, keySz);
3700
+
3701
+ #ifdef TEST_PK_PRIVKEY
3702
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3703
+ if (ret != 0)
3704
+ return ret;
3705
+ #endif
3706
+
3707
+ ret = wc_ed448_init(&myKey);
3708
+ if (ret == 0) {
3709
+ ret = wc_Ed448PrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
3710
+ if (ret == 0) {
3711
+ ret = wc_ed448_make_public(&myKey, myKey.p, ED448_PUB_KEY_SIZE);
3712
+ }
3713
+ if (ret == 0) {
3714
+ myKey.pubKeySet = 1;
3715
+ ret = wc_ed448_sign_msg(in, inSz, out, outSz, &myKey, NULL, 0);
3716
+ }
3717
+ wc_ed448_free(&myKey);
3718
+ }
3719
+
3720
+ #ifdef TEST_PK_PRIVKEY
3721
+ free(keyBuf);
3722
+ #endif
3723
+
3724
+ WOLFSSL_PKMSG("PK 448 Sign: ret %d, outSz %u\n", ret, *outSz);
3725
+
3726
+ return ret;
3727
+ }
3728
+ #endif /* HAVE_ED448_SIGN */
3729
+
3730
+
3731
+ #ifdef HAVE_ED448_VERIFY
3732
+ static WC_INLINE int myEd448Verify(WOLFSSL* ssl, const byte* sig, word32 sigSz,
3733
+ const byte* msg, word32 msgSz, const byte* key, word32 keySz,
3734
+ int* result, void* ctx)
3735
+ {
3736
+ int ret;
3737
+ ed448_key myKey;
3738
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3739
+
3740
+ (void)ssl;
3741
+ (void)cbInfo;
3742
+
3743
+ WOLFSSL_PKMSG("PK 448 Verify: sigSz %u, msgSz %u, keySz %u\n", sigSz, msgSz,
3744
+ keySz);
3745
+
3746
+ ret = wc_ed448_init(&myKey);
3747
+ if (ret == 0) {
3748
+ ret = wc_ed448_import_public(key, keySz, &myKey);
3749
+ if (ret == 0) {
3750
+ ret = wc_ed448_verify_msg(sig, sigSz, msg, msgSz, result, &myKey,
3751
+ NULL, 0);
3752
+ }
3753
+ wc_ed448_free(&myKey);
3754
+ }
3755
+
3756
+ WOLFSSL_PKMSG("PK 448 Verify: ret %d, result %d\n", ret, *result);
3757
+
3758
+ return ret;
3759
+ }
3760
+ #endif /* HAVE_ED448_VERIFY */
3761
+ #endif /* HAVE_ED448 && HAVE_ED448_KEY_IMPORT */
3762
+
3763
+ #ifdef HAVE_CURVE448
3764
+ static WC_INLINE int myX448KeyGen(WOLFSSL* ssl, curve448_key* key,
3765
+ unsigned int keySz, void* ctx)
3766
+ {
3767
+ int ret;
3768
+ WC_RNG rng;
3769
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3770
+
3771
+ (void)ssl;
3772
+ (void)cbInfo;
3773
+
3774
+ WOLFSSL_PKMSG("PK 448 KeyGen: keySz %u\n", keySz);
3775
+
3776
+ ret = wc_InitRng(&rng);
3777
+ if (ret != 0)
3778
+ return ret;
3779
+
3780
+ ret = wc_curve448_make_key(&rng, (int) keySz, key);
3781
+
3782
+ wc_FreeRng(&rng);
3783
+
3784
+ WOLFSSL_PKMSG("PK 448 KeyGen: ret %d\n", ret);
3785
+
3786
+ return ret;
3787
+ }
3788
+
3789
+ static WC_INLINE int myX448SharedSecret(WOLFSSL* ssl, curve448_key* otherKey,
3790
+ unsigned char* pubKeyDer, unsigned int* pubKeySz,
3791
+ unsigned char* out, unsigned int* outlen,
3792
+ int side, void* ctx)
3793
+ {
3794
+ int ret;
3795
+ curve448_key* privKey = NULL;
3796
+ curve448_key* pubKey = NULL;
3797
+ curve448_key tmpKey;
3798
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3799
+
3800
+ (void)ssl;
3801
+ (void)cbInfo;
3802
+
3803
+ WOLFSSL_PKMSG("PK 448 PMS: side %s\n",
3804
+ side == WOLFSSL_CLIENT_END ? "client" : "server");
3805
+
3806
+ ret = wc_curve448_init(&tmpKey);
3807
+ if (ret != 0) {
3808
+ return ret;
3809
+ }
3810
+
3811
+ /* for client: create and export public key */
3812
+ if (side == WOLFSSL_CLIENT_END) {
3813
+ WC_RNG rng;
3814
+
3815
+ privKey = &tmpKey;
3816
+ pubKey = otherKey;
3817
+
3818
+ ret = wc_InitRng(&rng);
3819
+ if (ret == 0) {
3820
+ ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, privKey);
3821
+ if (ret == 0) {
3822
+ ret = wc_curve448_export_public_ex(privKey, pubKeyDer,
3823
+ pubKeySz, EC448_LITTLE_ENDIAN);
3824
+ }
3825
+ wc_FreeRng(&rng);
3826
+ }
3827
+ }
3828
+
3829
+ /* for server: import public key */
3830
+ else if (side == WOLFSSL_SERVER_END) {
3831
+ privKey = otherKey;
3832
+ pubKey = &tmpKey;
3833
+
3834
+ ret = wc_curve448_import_public_ex(pubKeyDer, *pubKeySz, pubKey,
3835
+ EC448_LITTLE_ENDIAN);
3836
+ }
3837
+ else {
3838
+ ret = BAD_FUNC_ARG;
3839
+ }
3840
+
3841
+ /* generate shared secret and return it */
3842
+ if (ret == 0) {
3843
+ ret = wc_curve448_shared_secret_ex(privKey, pubKey, out, outlen,
3844
+ EC448_LITTLE_ENDIAN);
3845
+ }
3846
+
3847
+ wc_curve448_free(&tmpKey);
3848
+
3849
+ WOLFSSL_PKMSG("PK 448 PMS: ret %d, pubKeySz %u, outLen %u\n",
3850
+ ret, *pubKeySz, *outlen);
3851
+
3852
+ return ret;
3853
+ }
3854
+ #endif /* HAVE_CURVE448 */
3855
+
3856
+ #ifndef NO_DH
3857
+ static WC_INLINE int myDhCallback(WOLFSSL* ssl, struct DhKey* key,
3858
+ const unsigned char* priv, unsigned int privSz,
3859
+ const unsigned char* pubKeyDer, unsigned int pubKeySz,
3860
+ unsigned char* out, unsigned int* outlen,
3861
+ void* ctx)
3862
+ {
3863
+ int ret;
3864
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3865
+
3866
+ (void)ssl;
3867
+ (void)cbInfo;
3868
+
3869
+ /* return 0 on success */
3870
+ ret = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
3871
+
3872
+ WOLFSSL_PKMSG("PK ED Agree: ret %d, privSz %u, pubKeySz %u, outlen %u\n",
3873
+ ret, privSz, pubKeySz, *outlen);
3874
+
3875
+ return ret;
3876
+ }
3877
+
3878
+ #endif /* !NO_DH */
3879
+
3880
+ #ifndef NO_RSA
3881
+
3882
+ static WC_INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
3883
+ byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx)
3884
+ {
3885
+ WC_RNG rng;
3886
+ int ret;
3887
+ word32 idx = 0;
3888
+ RsaKey myKey;
3889
+ byte* keyBuf = (byte*)key;
3890
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3891
+
3892
+ (void)ssl;
3893
+ (void)cbInfo;
3894
+
3895
+ WOLFSSL_PKMSG("PK RSA Sign: inSz %u, keySz %u\n", inSz, keySz);
3896
+
3897
+ #ifdef TEST_PK_PRIVKEY
3898
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3899
+ if (ret != 0)
3900
+ return ret;
3901
+ #endif
3902
+
3903
+ ret = wc_InitRng(&rng);
3904
+ if (ret != 0)
3905
+ return ret;
3906
+
3907
+ ret = wc_InitRsaKey(&myKey, NULL);
3908
+ if (ret == 0) {
3909
+ ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
3910
+ if (ret == 0)
3911
+ ret = wc_RsaSSL_Sign(in, inSz, out, *outSz, &myKey, &rng);
3912
+ if (ret > 0) { /* save and convert to 0 success */
3913
+ *outSz = (word32) ret;
3914
+ ret = 0;
3915
+ }
3916
+ wc_FreeRsaKey(&myKey);
3917
+ }
3918
+ wc_FreeRng(&rng);
3919
+
3920
+ #ifdef TEST_PK_PRIVKEY
3921
+ free(keyBuf);
3922
+ #endif
3923
+
3924
+ WOLFSSL_PKMSG("PK RSA Sign: ret %d, outSz %u\n", ret, *outSz);
3925
+
3926
+ return ret;
3927
+ }
3928
+
3929
+
3930
+ static WC_INLINE int myRsaVerify(WOLFSSL* ssl, byte* sig, word32 sigSz,
3931
+ byte** out, const byte* key, word32 keySz, void* ctx)
3932
+ {
3933
+ int ret;
3934
+ word32 idx = 0;
3935
+ RsaKey myKey;
3936
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3937
+
3938
+ (void)ssl;
3939
+ (void)cbInfo;
3940
+
3941
+ WOLFSSL_PKMSG("PK RSA Verify: sigSz %u, keySz %u\n", sigSz, keySz);
3942
+
3943
+ ret = wc_InitRsaKey(&myKey, NULL);
3944
+ if (ret == 0) {
3945
+ ret = wc_RsaPublicKeyDecode(key, &idx, &myKey, keySz);
3946
+ if (ret == 0)
3947
+ ret = wc_RsaSSL_VerifyInline(sig, sigSz, out, &myKey);
3948
+ wc_FreeRsaKey(&myKey);
3949
+ }
3950
+
3951
+ WOLFSSL_PKMSG("PK RSA Verify: ret %d\n", ret);
3952
+
3953
+ return ret;
3954
+ }
3955
+
3956
+ static WC_INLINE int myRsaSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz,
3957
+ byte** out, const byte* key, word32 keySz, void* ctx)
3958
+ {
3959
+ int ret;
3960
+ word32 idx = 0;
3961
+ RsaKey myKey;
3962
+ byte* keyBuf = (byte*)key;
3963
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
3964
+
3965
+ (void)ssl;
3966
+ (void)cbInfo;
3967
+
3968
+ WOLFSSL_PKMSG("PK RSA SignCheck: sigSz %u, keySz %u\n", sigSz, keySz);
3969
+
3970
+ #ifdef TEST_PK_PRIVKEY
3971
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
3972
+ if (ret != 0)
3973
+ return ret;
3974
+ #endif
3975
+
3976
+ ret = wc_InitRsaKey(&myKey, NULL);
3977
+ if (ret == 0) {
3978
+ ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
3979
+ if (ret == 0)
3980
+ ret = wc_RsaSSL_VerifyInline(sig, sigSz, out, &myKey);
3981
+ wc_FreeRsaKey(&myKey);
3982
+ }
3983
+ #ifdef TEST_PK_PRIVKEY
3984
+ free(keyBuf);
3985
+ #endif
3986
+
3987
+ WOLFSSL_PKMSG("PK RSA SignCheck: ret %d\n", ret);
3988
+
3989
+ return ret;
3990
+ }
3991
+
3992
+ #ifdef WC_RSA_PSS
3993
+ static WC_INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz,
3994
+ byte* out, word32* outSz, int hash, int mgf, const byte* key,
3995
+ word32 keySz, void* ctx)
3996
+ {
3997
+ enum wc_HashType hashType = WC_HASH_TYPE_NONE;
3998
+ WC_RNG rng;
3999
+ int ret = 0;
4000
+ word32 idx = 0;
4001
+ RsaKey myKey;
4002
+ byte* inBuf = (byte*)in;
4003
+ word32 inBufSz = inSz;
4004
+ byte* keyBuf = (byte*)key;
4005
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4006
+
4007
+ (void)ssl;
4008
+ (void)cbInfo;
4009
+
4010
+ WOLFSSL_PKMSG("PK RSA PSS Sign: inSz %u, hash %d, mgf %d, keySz %u\n",
4011
+ inSz, hash, mgf, keySz);
4012
+
4013
+ #ifdef TEST_PK_PRIVKEY
4014
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
4015
+ if (ret != 0)
4016
+ return ret;
4017
+ #endif
4018
+
4019
+ switch (hash) {
4020
+ #ifndef NO_SHA256
4021
+ case SHA256h:
4022
+ hashType = WC_HASH_TYPE_SHA256;
4023
+ break;
4024
+ #endif
4025
+ #ifdef WOLFSSL_SHA384
4026
+ case SHA384h:
4027
+ hashType = WC_HASH_TYPE_SHA384;
4028
+ break;
4029
+ #endif
4030
+ #ifdef WOLFSSL_SHA512
4031
+ case SHA512h:
4032
+ hashType = WC_HASH_TYPE_SHA512;
4033
+ break;
4034
+ #endif
4035
+ }
4036
+
4037
+ ret = wc_InitRng(&rng);
4038
+ if (ret != 0)
4039
+ return ret;
4040
+
4041
+ #ifdef TLS13_RSA_PSS_SIGN_CB_NO_PREHASH
4042
+ /* With this defined, RSA-PSS sign callback when used from TLS 1.3
4043
+ * does not hash data before giving to this callback. User must
4044
+ * compute hash themselves. */
4045
+ if (wolfSSL_GetVersion(ssl) == WOLFSSL_TLSV1_3) {
4046
+ inBufSz = wc_HashGetDigestSize(hashType);
4047
+ inBuf = (byte*)XMALLOC(inBufSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4048
+ if (inBuf == NULL) {
4049
+ ret = MEMORY_E;
4050
+ }
4051
+ if (ret == 0) {
4052
+ ret = wc_Hash(hashType, in, inSz, inBuf, inBufSz);
4053
+ }
4054
+ }
4055
+ #endif
4056
+
4057
+ if (ret == 0) {
4058
+ ret = wc_InitRsaKey(&myKey, NULL);
4059
+ }
4060
+ if (ret == 0) {
4061
+ ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
4062
+ if (ret == 0) {
4063
+ ret = wc_RsaPSS_Sign(inBuf, inBufSz, out, *outSz, hashType, mgf,
4064
+ &myKey, &rng);
4065
+ }
4066
+ if (ret > 0) { /* save and convert to 0 success */
4067
+ *outSz = (word32) ret;
4068
+ ret = 0;
4069
+ }
4070
+ #ifdef TLS13_RSA_PSS_SIGN_CB_NO_PREHASH
4071
+ if ((inBuf != NULL) && (wolfSSL_GetVersion(ssl) == WOLFSSL_TLSV1_3)) {
4072
+ XFREE(inBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4073
+ }
4074
+ #endif
4075
+ wc_FreeRsaKey(&myKey);
4076
+ }
4077
+ wc_FreeRng(&rng);
4078
+
4079
+ #ifdef TEST_PK_PRIVKEY
4080
+ free(keyBuf);
4081
+ #endif
4082
+
4083
+ WOLFSSL_PKMSG("PK RSA PSS Sign: ret %d, outSz %u\n", ret, *outSz);
4084
+
4085
+ return ret;
4086
+ }
4087
+
4088
+
4089
+ static WC_INLINE int myRsaPssVerify(WOLFSSL* ssl, byte* sig, word32 sigSz,
4090
+ byte** out, int hash, int mgf, const byte* key, word32 keySz, void* ctx)
4091
+ {
4092
+ int ret;
4093
+ word32 idx = 0;
4094
+ RsaKey myKey;
4095
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4096
+ enum wc_HashType hashType = WC_HASH_TYPE_NONE;
4097
+
4098
+ (void)ssl;
4099
+ (void)cbInfo;
4100
+
4101
+ WOLFSSL_PKMSG("PK RSA PSS Verify: sigSz %u, hash %d, mgf %d, keySz %u\n",
4102
+ sigSz, hash, mgf, keySz);
4103
+
4104
+ switch (hash) {
4105
+ #ifndef NO_SHA256
4106
+ case SHA256h:
4107
+ hashType = WC_HASH_TYPE_SHA256;
4108
+ break;
4109
+ #endif
4110
+ #ifdef WOLFSSL_SHA384
4111
+ case SHA384h:
4112
+ hashType = WC_HASH_TYPE_SHA384;
4113
+ break;
4114
+ #endif
4115
+ #ifdef WOLFSSL_SHA512
4116
+ case SHA512h:
4117
+ hashType = WC_HASH_TYPE_SHA512;
4118
+ break;
4119
+ #endif
4120
+ }
4121
+
4122
+ ret = wc_InitRsaKey(&myKey, NULL);
4123
+ if (ret == 0) {
4124
+ ret = wc_RsaPublicKeyDecode(key, &idx, &myKey, keySz);
4125
+ if (ret == 0) {
4126
+ ret = wc_RsaPSS_VerifyInline(sig, sigSz, out, hashType, mgf,
4127
+ &myKey);
4128
+ }
4129
+ wc_FreeRsaKey(&myKey);
4130
+ }
4131
+
4132
+ WOLFSSL_PKMSG("PK RSA PSS Verify: ret %d\n", ret);
4133
+
4134
+ return ret;
4135
+ }
4136
+
4137
+ static WC_INLINE int myRsaPssSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz,
4138
+ byte** out, int hash, int mgf, const byte* key, word32 keySz, void* ctx)
4139
+ {
4140
+ int ret;
4141
+ word32 idx = 0;
4142
+ RsaKey myKey;
4143
+ byte* keyBuf = (byte*)key;
4144
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4145
+ enum wc_HashType hashType = WC_HASH_TYPE_NONE;
4146
+
4147
+ (void)ssl;
4148
+ (void)cbInfo;
4149
+
4150
+ WOLFSSL_PKMSG("PK RSA PSS SignCheck: sigSz %u, hash %d, mgf %d, keySz %u\n",
4151
+ sigSz, hash, mgf, keySz);
4152
+
4153
+ #ifdef TEST_PK_PRIVKEY
4154
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
4155
+ if (ret != 0)
4156
+ return ret;
4157
+ #endif
4158
+
4159
+ switch (hash) {
4160
+ #ifndef NO_SHA256
4161
+ case SHA256h:
4162
+ hashType = WC_HASH_TYPE_SHA256;
4163
+ break;
4164
+ #endif
4165
+ #ifdef WOLFSSL_SHA384
4166
+ case SHA384h:
4167
+ hashType = WC_HASH_TYPE_SHA384;
4168
+ break;
4169
+ #endif
4170
+ #ifdef WOLFSSL_SHA512
4171
+ case SHA512h:
4172
+ hashType = WC_HASH_TYPE_SHA512;
4173
+ break;
4174
+ #endif
4175
+ }
4176
+
4177
+ ret = wc_InitRsaKey(&myKey, NULL);
4178
+ if (ret == 0) {
4179
+ ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
4180
+ if (ret == 0) {
4181
+ ret = wc_RsaPSS_VerifyInline(sig, sigSz, out, hashType, mgf,
4182
+ &myKey);
4183
+ }
4184
+ wc_FreeRsaKey(&myKey);
4185
+ }
4186
+
4187
+ #ifdef TEST_PK_PRIVKEY
4188
+ free(keyBuf);
4189
+ #endif
4190
+
4191
+ WOLFSSL_PKMSG("PK RSA PSS SignCheck: ret %d\n", ret);
4192
+
4193
+ return ret;
4194
+ }
4195
+ #endif
4196
+
4197
+
4198
+ static WC_INLINE int myRsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz,
4199
+ byte* out, word32* outSz, const byte* key,
4200
+ word32 keySz, void* ctx)
4201
+ {
4202
+ int ret;
4203
+ word32 idx = 0;
4204
+ RsaKey myKey;
4205
+ WC_RNG rng;
4206
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4207
+
4208
+ (void)ssl;
4209
+ (void)cbInfo;
4210
+
4211
+ WOLFSSL_PKMSG("PK RSA Enc: inSz %u, keySz %u\n", inSz, keySz);
4212
+
4213
+ ret = wc_InitRng(&rng);
4214
+ if (ret != 0)
4215
+ return ret;
4216
+
4217
+ ret = wc_InitRsaKey(&myKey, NULL);
4218
+ if (ret == 0) {
4219
+ ret = wc_RsaPublicKeyDecode(key, &idx, &myKey, keySz);
4220
+ if (ret == 0) {
4221
+ ret = wc_RsaPublicEncrypt(in, inSz, out, *outSz, &myKey, &rng);
4222
+ if (ret > 0) {
4223
+ *outSz = (word32) ret;
4224
+ ret = 0; /* reset to success */
4225
+ }
4226
+ }
4227
+ wc_FreeRsaKey(&myKey);
4228
+ }
4229
+ wc_FreeRng(&rng);
4230
+
4231
+ WOLFSSL_PKMSG("PK RSA Enc: ret %d, outSz %u\n", ret, *outSz);
4232
+
4233
+ return ret;
4234
+ }
4235
+
4236
+ static WC_INLINE int myRsaDec(WOLFSSL* ssl, byte* in, word32 inSz,
4237
+ byte** out,
4238
+ const byte* key, word32 keySz, void* ctx)
4239
+ {
4240
+ int ret;
4241
+ word32 idx = 0;
4242
+ RsaKey myKey;
4243
+ byte* keyBuf = (byte*)key;
4244
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4245
+
4246
+ (void)ssl;
4247
+ (void)cbInfo;
4248
+
4249
+ WOLFSSL_PKMSG("PK RSA Dec: inSz %u, keySz %u\n", inSz, keySz);
4250
+
4251
+ #ifdef TEST_PK_PRIVKEY
4252
+ ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
4253
+ if (ret != 0)
4254
+ return ret;
4255
+ #endif
4256
+
4257
+ ret = wc_InitRsaKey(&myKey, NULL);
4258
+ if (ret == 0) {
4259
+ ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
4260
+ if (ret == 0) {
4261
+ #ifdef WC_RSA_BLINDING
4262
+ ret = wc_RsaSetRNG(&myKey, wolfSSL_GetRNG(ssl));
4263
+ if (ret != 0) {
4264
+ wc_FreeRsaKey(&myKey);
4265
+ return ret;
4266
+ }
4267
+ #endif
4268
+ ret = wc_RsaPrivateDecryptInline(in, inSz, out, &myKey);
4269
+ }
4270
+ wc_FreeRsaKey(&myKey);
4271
+ }
4272
+
4273
+ #ifdef TEST_PK_PRIVKEY
4274
+ free(keyBuf);
4275
+ #endif
4276
+
4277
+ WOLFSSL_PKMSG("PK RSA Dec: ret %d\n", ret);
4278
+
4279
+ return ret;
4280
+ }
4281
+
4282
+ #endif /* NO_RSA */
4283
+
4284
+ static WC_INLINE int myGenMaster(WOLFSSL* ssl, void* ctx)
4285
+ {
4286
+ int ret;
4287
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4288
+
4289
+ (void)ssl;
4290
+ (void)cbInfo;
4291
+
4292
+ WOLFSSL_PKMSG("Gen Master");
4293
+ /* fall through to original routine */
4294
+ ret = PROTOCOLCB_UNAVAILABLE;
4295
+ WOLFSSL_PKMSG("Gen Master: ret %d\n", ret);
4296
+
4297
+ return ret;
4298
+ }
4299
+
4300
+ static WC_INLINE int myGenExtMaster(WOLFSSL* ssl, byte* hash, word32 hashSz,
4301
+ void* ctx)
4302
+ {
4303
+ int ret;
4304
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4305
+
4306
+ (void)ssl;
4307
+ (void)cbInfo;
4308
+ (void)hash;
4309
+ (void)hashSz;
4310
+
4311
+ WOLFSSL_PKMSG("Gen Extended Master");
4312
+ /* fall through to original routine */
4313
+ ret = PROTOCOLCB_UNAVAILABLE;
4314
+ WOLFSSL_PKMSG("Gen Extended Master: ret %d\n", ret);
4315
+
4316
+ return ret;
4317
+ }
4318
+
4319
+ static WC_INLINE int myGenPreMaster(WOLFSSL* ssl, byte *premaster,
4320
+ word32 preSz, void* ctx)
4321
+ {
4322
+ int ret;
4323
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4324
+
4325
+ (void) ssl;
4326
+ (void) cbInfo;
4327
+ (void) premaster;
4328
+ (void) preSz;
4329
+
4330
+ WOLFSSL_PKMSG("Gen Pre-Master Cb");
4331
+ /* fall through to original routine */
4332
+ ret = PROTOCOLCB_UNAVAILABLE;
4333
+ WOLFSSL_PKMSG("Gen Pre-Master Cb: ret %d\n", ret);
4334
+
4335
+ return ret;
4336
+ }
4337
+
4338
+ static WC_INLINE int myGenSessionKey(WOLFSSL* ssl, void* ctx)
4339
+ {
4340
+ int ret;
4341
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4342
+
4343
+ (void)ssl;
4344
+ (void)cbInfo;
4345
+
4346
+ WOLFSSL_PKMSG("Gen Master Cb");
4347
+ /* fall through to original routine */
4348
+ ret = PROTOCOLCB_UNAVAILABLE;
4349
+ WOLFSSL_PKMSG("Gen Master Cb: ret %d\n", ret);
4350
+
4351
+ return ret;
4352
+ }
4353
+
4354
+ static WC_INLINE int mySetEncryptKeys(WOLFSSL* ssl, void* ctx)
4355
+ {
4356
+ int ret;
4357
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4358
+
4359
+ (void)ssl;
4360
+ (void)cbInfo;
4361
+
4362
+ WOLFSSL_PKMSG("Set Encrypt Keys Cb");
4363
+ /* fall through to original routine */
4364
+ ret = PROTOCOLCB_UNAVAILABLE;
4365
+ WOLFSSL_PKMSG("Set Encrypt Keys Cb: ret %d\n", ret);
4366
+
4367
+ return ret;
4368
+ }
4369
+
4370
+ #if !defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_AEAD_ONLY)
4371
+ static WC_INLINE int myVerifyMac(WOLFSSL *ssl, const byte* message,
4372
+ word32 messageSz, word32 macSz, word32 content, void* ctx)
4373
+ {
4374
+ int ret;
4375
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4376
+
4377
+ (void)ssl;
4378
+ (void)message;
4379
+ (void)messageSz;
4380
+ (void)macSz;
4381
+ (void)content;
4382
+ (void)cbInfo;
4383
+
4384
+ WOLFSSL_PKMSG("Verify Mac Cb");
4385
+ /* fall through to original routine */
4386
+ ret = PROTOCOLCB_UNAVAILABLE;
4387
+ WOLFSSL_PKMSG("Verify Mac Cb: ret %d\n", ret);
4388
+
4389
+ return ret;
4390
+ }
4391
+ #endif
4392
+
4393
+ static WC_INLINE int myTlsFinished(WOLFSSL* ssl,
4394
+ const byte *side,
4395
+ const byte *handshake_hash, word32 hashSz,
4396
+ byte *hashes, void* ctx)
4397
+ {
4398
+ int ret;
4399
+ PkCbInfo* cbInfo = (PkCbInfo*)ctx;
4400
+
4401
+ (void)ssl;
4402
+ (void)cbInfo;
4403
+ (void)side;
4404
+ (void)handshake_hash;
4405
+ (void)hashSz;
4406
+ (void)hashes;
4407
+
4408
+ WOLFSSL_PKMSG("Tls Finished Cb");
4409
+ /* fall through to original routine */
4410
+ ret = PROTOCOLCB_UNAVAILABLE;
4411
+ WOLFSSL_PKMSG("Tls Finished Cb: ret %d\n", ret);
4412
+
4413
+ return ret;
4414
+ }
4415
+
4416
+ static WC_INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx)
4417
+ {
4418
+ (void)ctx;
4419
+
4420
+ #ifdef HAVE_ECC
4421
+ wolfSSL_CTX_SetEccKeyGenCb(ctx, myEccKeyGen);
4422
+ wolfSSL_CTX_SetEccSignCb(ctx, myEccSign);
4423
+ wolfSSL_CTX_SetEccVerifyCb(ctx, myEccVerify);
4424
+ wolfSSL_CTX_SetEccSharedSecretCb(ctx, myEccSharedSecret);
4425
+ #endif /* HAVE_ECC */
4426
+ #if defined(HAVE_HKDF) && !defined(NO_HMAC)
4427
+ wolfSSL_CTX_SetHKDFExtractCb(ctx, myHkdfExtract);
4428
+ #endif /* HAVE_HKDF && !NO_HMAC */
4429
+ #ifndef NO_DH
4430
+ wolfSSL_CTX_SetDhAgreeCb(ctx, myDhCallback);
4431
+ #endif
4432
+ #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
4433
+ #ifdef HAVE_ED25519_SIGN
4434
+ wolfSSL_CTX_SetEd25519SignCb(ctx, myEd25519Sign);
4435
+ #endif
4436
+ #ifdef HAVE_ED25519_VERIFY
4437
+ wolfSSL_CTX_SetEd25519VerifyCb(ctx, myEd25519Verify);
4438
+ #endif
4439
+ #endif
4440
+ #ifdef HAVE_CURVE25519
4441
+ wolfSSL_CTX_SetX25519KeyGenCb(ctx, myX25519KeyGen);
4442
+ wolfSSL_CTX_SetX25519SharedSecretCb(ctx, myX25519SharedSecret);
4443
+ #endif
4444
+ #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
4445
+ #if defined(HAVE_ED448_SIGN)
4446
+ wolfSSL_CTX_SetEd448SignCb(ctx, myEd448Sign);
4447
+ #endif
4448
+ #if defined(HAVE_ED448_VERIFY)
4449
+ wolfSSL_CTX_SetEd448VerifyCb(ctx, myEd448Verify);
4450
+ #endif
4451
+ #endif
4452
+ #ifdef HAVE_CURVE448
4453
+ wolfSSL_CTX_SetX448KeyGenCb(ctx, myX448KeyGen);
4454
+ wolfSSL_CTX_SetX448SharedSecretCb(ctx, myX448SharedSecret);
4455
+ #endif
4456
+ #ifndef NO_RSA
4457
+ wolfSSL_CTX_SetRsaSignCb(ctx, myRsaSign);
4458
+ wolfSSL_CTX_SetRsaVerifyCb(ctx, myRsaVerify);
4459
+ wolfSSL_CTX_SetRsaSignCheckCb(ctx, myRsaSignCheck);
4460
+ #ifdef WC_RSA_PSS
4461
+ wolfSSL_CTX_SetRsaPssSignCb(ctx, myRsaPssSign);
4462
+ wolfSSL_CTX_SetRsaPssVerifyCb(ctx, myRsaPssVerify);
4463
+ wolfSSL_CTX_SetRsaPssSignCheckCb(ctx, myRsaPssSignCheck);
4464
+ #endif
4465
+ wolfSSL_CTX_SetRsaEncCb(ctx, myRsaEnc);
4466
+ wolfSSL_CTX_SetRsaDecCb(ctx, myRsaDec);
4467
+ #endif /* NO_RSA */
4468
+
4469
+ #ifndef NO_CERTS
4470
+ wolfSSL_CTX_SetGenMasterSecretCb(ctx, myGenMaster);
4471
+ wolfSSL_CTX_SetGenExtMasterSecretCb(ctx, myGenExtMaster);
4472
+ wolfSSL_CTX_SetGenPreMasterCb(ctx, myGenPreMaster);
4473
+ wolfSSL_CTX_SetGenSessionKeyCb(ctx, myGenSessionKey);
4474
+ wolfSSL_CTX_SetEncryptKeysCb(ctx, mySetEncryptKeys);
4475
+
4476
+ #if !defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_AEAD_ONLY)
4477
+ wolfSSL_CTX_SetVerifyMacCb(ctx, myVerifyMac);
4478
+ #endif
4479
+
4480
+ wolfSSL_CTX_SetTlsFinishedCb(ctx, myTlsFinished);
4481
+ #endif /* NO_CERTS */
4482
+ }
4483
+
4484
+ static WC_INLINE void SetupPkCallbackContexts(WOLFSSL* ssl, void* myCtx)
4485
+ {
4486
+ #ifdef HAVE_ECC
4487
+ wolfSSL_SetEccKeyGenCtx(ssl, myCtx);
4488
+ wolfSSL_SetEccSignCtx(ssl, myCtx);
4489
+ wolfSSL_SetEccVerifyCtx(ssl, myCtx);
4490
+ wolfSSL_SetEccSharedSecretCtx(ssl, myCtx);
4491
+ #endif /* HAVE_ECC */
4492
+ #ifdef HAVE_HKDF
4493
+ wolfSSL_SetHKDFExtractCtx(ssl, myCtx);
4494
+ #endif /* HAVE_HKDF */
4495
+ #ifndef NO_DH
4496
+ wolfSSL_SetDhAgreeCtx(ssl, myCtx);
4497
+ #endif
4498
+ #ifdef HAVE_ED25519
4499
+ wolfSSL_SetEd25519SignCtx(ssl, myCtx);
4500
+ wolfSSL_SetEd25519VerifyCtx(ssl, myCtx);
4501
+ #endif
4502
+ #ifdef HAVE_CURVE25519
4503
+ wolfSSL_SetX25519KeyGenCtx(ssl, myCtx);
4504
+ wolfSSL_SetX25519SharedSecretCtx(ssl, myCtx);
4505
+ #endif
4506
+ #ifdef HAVE_ED448
4507
+ wolfSSL_SetEd448SignCtx(ssl, myCtx);
4508
+ wolfSSL_SetEd448VerifyCtx(ssl, myCtx);
4509
+ #endif
4510
+ #ifdef HAVE_CURVE448
4511
+ wolfSSL_SetX448KeyGenCtx(ssl, myCtx);
4512
+ wolfSSL_SetX448SharedSecretCtx(ssl, myCtx);
4513
+ #endif
4514
+ #ifndef NO_RSA
4515
+ wolfSSL_SetRsaSignCtx(ssl, myCtx);
4516
+ wolfSSL_SetRsaVerifyCtx(ssl, myCtx);
4517
+ #ifdef WC_RSA_PSS
4518
+ wolfSSL_SetRsaPssSignCtx(ssl, myCtx);
4519
+ wolfSSL_SetRsaPssVerifyCtx(ssl, myCtx);
4520
+ #endif
4521
+ wolfSSL_SetRsaEncCtx(ssl, myCtx);
4522
+ wolfSSL_SetRsaDecCtx(ssl, myCtx);
4523
+ #endif /* NO_RSA */
4524
+
4525
+ #ifndef NO_CERTS
4526
+ wolfSSL_SetGenMasterSecretCtx(ssl, myCtx);
4527
+ wolfSSL_SetGenExtMasterSecretCtx(ssl, myCtx);
4528
+ wolfSSL_SetGenPreMasterCtx(ssl, myCtx);
4529
+ wolfSSL_SetGenSessionKeyCtx(ssl, myCtx);
4530
+ wolfSSL_SetEncryptKeysCtx(ssl, myCtx);
4531
+
4532
+ #if !defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_AEAD_ONLY)
4533
+ wolfSSL_SetVerifyMacCtx(ssl, myCtx);
4534
+ #endif
4535
+
4536
+ wolfSSL_SetTlsFinishedCtx(ssl, myCtx);
4537
+ #endif
4538
+ }
4539
+
4540
+ #endif /* HAVE_PK_CALLBACKS */
4541
+
4542
+ #ifdef USE_WOLFSSL_IO
4543
+ static WC_INLINE int SimulateWantWriteIOSendCb(WOLFSSL *ssl, char *buf, int sz, void *ctx)
4544
+ {
4545
+ static int wantWriteFlag = 1;
4546
+
4547
+ int sd = *(int*)ctx;
4548
+
4549
+ (void)ssl;
4550
+
4551
+ if (!wantWriteFlag)
4552
+ {
4553
+ int sent;
4554
+ wantWriteFlag = 1;
4555
+
4556
+ sent = wolfIO_Send(sd, buf, sz, 0);
4557
+ if (sent < 0) {
4558
+ int err = errno;
4559
+
4560
+ if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
4561
+ return WOLFSSL_CBIO_ERR_WANT_WRITE;
4562
+ }
4563
+ else if (err == SOCKET_ECONNRESET) {
4564
+ return WOLFSSL_CBIO_ERR_CONN_RST;
4565
+ }
4566
+ else if (err == SOCKET_EINTR) {
4567
+ return WOLFSSL_CBIO_ERR_ISR;
4568
+ }
4569
+ else if (err == SOCKET_EPIPE) {
4570
+ return WOLFSSL_CBIO_ERR_CONN_CLOSE;
4571
+ }
4572
+ else {
4573
+ return WOLFSSL_CBIO_ERR_GENERAL;
4574
+ }
4575
+ }
4576
+
4577
+ return sent;
4578
+ }
4579
+ else
4580
+ {
4581
+ wantWriteFlag = 0;
4582
+ return WOLFSSL_CBIO_ERR_WANT_WRITE;
4583
+ }
4584
+ }
4585
+ #endif /* USE_WOLFSSL_IO */
4586
+
4587
+ #if defined(__hpux__) || defined(__MINGW32__) || defined (WOLFSSL_TIRTOS) \
4588
+ || defined(_MSC_VER) || defined(__WATCOMC__)
4589
+
4590
+ /* HP/UX doesn't have strsep, needed by test/suites.c */
4591
+ static WC_INLINE char* strsep(char **stringp, const char *delim)
4592
+ {
4593
+ char* start;
4594
+ char* end;
4595
+
4596
+ start = *stringp;
4597
+ if (start == NULL)
4598
+ return NULL;
4599
+
4600
+ if ((end = strpbrk(start, delim))) {
4601
+ *end++ = '\0';
4602
+ *stringp = end;
4603
+ } else {
4604
+ *stringp = NULL;
4605
+ }
4606
+
4607
+ return start;
4608
+ }
4609
+
4610
+ #endif /* __hpux__ and others */
4611
+
4612
+ /* Create unique filename, len is length of tempfn name, assuming
4613
+ len does not include null terminating character,
4614
+ num is number of characters in tempfn name to randomize */
4615
+ static WC_INLINE const char* mymktemp(char *tempfn, int len, int num)
4616
+ {
4617
+ int x, size;
4618
+ static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4619
+ "abcdefghijklmnopqrstuvwxyz";
4620
+ WC_RNG rng;
4621
+ byte out = 0;
4622
+
4623
+ if (tempfn == NULL || len < 1 || num < 1 || len <= num) {
4624
+ fprintf(stderr, "Bad input\n");
4625
+ return NULL;
4626
+ }
4627
+
4628
+ size = len - 1;
4629
+
4630
+ if (wc_InitRng(&rng) != 0) {
4631
+ fprintf(stderr, "InitRng failed\n");
4632
+ return NULL;
4633
+ }
4634
+
4635
+ for (x = size; x > size - num; x--) {
4636
+ if (wc_RNG_GenerateBlock(&rng,(byte*)&out, sizeof(out)) != 0) {
4637
+ fprintf(stderr, "RNG_GenerateBlock failed\n");
4638
+ return NULL;
4639
+ }
4640
+ tempfn[x] = alphanum[out % (sizeof(alphanum) - 1)];
4641
+ }
4642
+ tempfn[len] = '\0';
4643
+
4644
+ wc_FreeRng(&rng);
4645
+ (void)rng; /* for WC_NO_RNG case */
4646
+
4647
+ return tempfn;
4648
+ }
4649
+
4650
+
4651
+
4652
+ #if defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
4653
+ ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || \
4654
+ defined(HAVE_AESGCM))
4655
+
4656
+ #define HAVE_TEST_SESSION_TICKET
4657
+
4658
+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4659
+ #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
4660
+ #define WOLFSSL_TICKET_KEY_SZ CHACHA20_POLY1305_AEAD_KEYSIZE
4661
+ #elif defined(HAVE_AESGCM)
4662
+ #include <wolfssl/wolfcrypt/aes.h>
4663
+ #include <wolfssl/wolfcrypt/wc_encrypt.h> /* AES IV sizes in FIPS mode */
4664
+ #define WOLFSSL_TICKET_KEY_SZ AES_256_KEY_SIZE
4665
+ #endif
4666
+
4667
+ typedef struct key_ctx {
4668
+ byte name[WOLFSSL_TICKET_NAME_SZ]; /* name for this context */
4669
+ byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
4670
+ } key_ctx;
4671
+
4672
+ static THREAD_LS_T key_ctx myKey_ctx;
4673
+ static THREAD_LS_T WC_RNG myKey_rng;
4674
+
4675
+ static WC_INLINE int TicketInit(void)
4676
+ {
4677
+ int ret = wc_InitRng(&myKey_rng);
4678
+ if (ret == 0) {
4679
+ ret = wc_RNG_GenerateBlock(&myKey_rng, myKey_ctx.key,
4680
+ sizeof(myKey_ctx.key));
4681
+ }
4682
+ if (ret == 0) {
4683
+ ret = wc_RNG_GenerateBlock(&myKey_rng, myKey_ctx.name,
4684
+ sizeof(myKey_ctx.name));
4685
+ }
4686
+ return ret;
4687
+ }
4688
+
4689
+ static WC_INLINE void TicketCleanup(void)
4690
+ {
4691
+ wc_FreeRng(&myKey_rng);
4692
+ }
4693
+
4694
+ typedef enum MyTicketState {
4695
+ MY_TICKET_STATE_NONE,
4696
+ MY_TICKET_STATE_INIT,
4697
+ MY_TICKET_STATE_RNG,
4698
+ MY_TICKET_STATE_CIPHER_SETUP,
4699
+ MY_TICKET_STATE_CIPHER,
4700
+ MY_TICKET_STATE_FINAL
4701
+ } MyTicketState;
4702
+ typedef struct MyTicketCtx {
4703
+ MyTicketState state;
4704
+ byte aad[WOLFSSL_TICKET_NAME_SZ + WOLFSSL_TICKET_IV_SZ + 2];
4705
+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4706
+ /* chahca20/poly1305 */
4707
+ #elif defined(HAVE_AESGCM)
4708
+ Aes aes;
4709
+ #endif
4710
+ } MyTicketCtx;
4711
+
4712
+ static WC_INLINE int myTicketEncCb(WOLFSSL* ssl,
4713
+ byte key_name[WOLFSSL_TICKET_NAME_SZ],
4714
+ byte iv[WOLFSSL_TICKET_IV_SZ],
4715
+ byte mac[WOLFSSL_TICKET_MAC_SZ],
4716
+ int enc, byte* ticket, int inLen, int* outLen,
4717
+ void* userCtx)
4718
+ {
4719
+ int ret = 0;
4720
+ MyTicketCtx tickCtx_lcl;
4721
+ MyTicketCtx* tickCtx = (MyTicketCtx*)userCtx;
4722
+
4723
+ (void)ssl;
4724
+
4725
+ if (tickCtx == NULL) {
4726
+ /* for test cases where userCtx is not set use local stack for context */
4727
+ XMEMSET(&tickCtx_lcl, 0, sizeof(tickCtx_lcl));
4728
+ tickCtx = &tickCtx_lcl;
4729
+ }
4730
+
4731
+ switch (tickCtx->state) {
4732
+ case MY_TICKET_STATE_NONE:
4733
+ case MY_TICKET_STATE_INIT:
4734
+ {
4735
+ /* encrypt */
4736
+ if (enc) {
4737
+ XMEMCPY(key_name, myKey_ctx.name, WOLFSSL_TICKET_NAME_SZ);
4738
+ }
4739
+ else {
4740
+ /* see if we know this key */
4741
+ if (XMEMCMP(key_name, myKey_ctx.name, WOLFSSL_TICKET_NAME_SZ) != 0) {
4742
+ printf("client presented unknown ticket key name %s\n", key_name);
4743
+ return WOLFSSL_TICKET_RET_FATAL;
4744
+ }
4745
+ }
4746
+ tickCtx->state = MY_TICKET_STATE_RNG;
4747
+ }
4748
+ FALL_THROUGH;
4749
+ case MY_TICKET_STATE_RNG:
4750
+ {
4751
+ if (enc) {
4752
+ ret = wc_RNG_GenerateBlock(&myKey_rng, iv, WOLFSSL_TICKET_IV_SZ);
4753
+ if (ret != 0)
4754
+ break;
4755
+ }
4756
+ tickCtx->state = MY_TICKET_STATE_CIPHER_SETUP;
4757
+ }
4758
+ FALL_THROUGH;
4759
+ case MY_TICKET_STATE_CIPHER_SETUP:
4760
+ {
4761
+ byte* tmp = tickCtx->aad;
4762
+ word16 sLen = XHTONS(inLen);
4763
+
4764
+ /* build aad from key name, iv, and length */
4765
+ XMEMCPY(tmp, key_name, WOLFSSL_TICKET_NAME_SZ);
4766
+ tmp += WOLFSSL_TICKET_NAME_SZ;
4767
+ XMEMCPY(tmp, iv, WOLFSSL_TICKET_IV_SZ);
4768
+ tmp += WOLFSSL_TICKET_IV_SZ;
4769
+ XMEMCPY(tmp, &sLen, sizeof(sLen));
4770
+
4771
+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4772
+ #elif defined(HAVE_AESGCM)
4773
+ ret = wc_AesInit(&tickCtx->aes, NULL, INVALID_DEVID);
4774
+ if (ret == 0) {
4775
+ ret = wc_AesGcmSetKey(&tickCtx->aes, myKey_ctx.key,
4776
+ sizeof(myKey_ctx.key));
4777
+ }
4778
+ if (ret != 0)
4779
+ break;
4780
+ #endif
4781
+ tickCtx->state = MY_TICKET_STATE_CIPHER;
4782
+ }
4783
+ FALL_THROUGH;
4784
+ case MY_TICKET_STATE_CIPHER:
4785
+ {
4786
+ int aadSz = (int)sizeof(tickCtx->aad);
4787
+
4788
+ /* encrypt */
4789
+ if (enc) {
4790
+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4791
+ ret = wc_ChaCha20Poly1305_Encrypt(myKey_ctx.key, iv,
4792
+ tickCtx->aad, aadSz,
4793
+ ticket, inLen,
4794
+ ticket,
4795
+ mac);
4796
+ #elif defined(HAVE_AESGCM)
4797
+ ret = wc_AesGcmEncrypt(&tickCtx->aes, ticket, ticket, inLen,
4798
+ iv, GCM_NONCE_MID_SZ, mac, WC_AES_BLOCK_SIZE,
4799
+ tickCtx->aad, aadSz);
4800
+ #endif
4801
+ }
4802
+ /* decrypt */
4803
+ else {
4804
+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4805
+ ret = wc_ChaCha20Poly1305_Decrypt(myKey_ctx.key, iv,
4806
+ tickCtx->aad, aadSz,
4807
+ ticket, inLen,
4808
+ mac,
4809
+ ticket);
4810
+ #elif defined(HAVE_AESGCM)
4811
+ ret = wc_AesGcmDecrypt(&tickCtx->aes, ticket, ticket, inLen,
4812
+ iv, GCM_NONCE_MID_SZ, mac, WC_AES_BLOCK_SIZE,
4813
+ tickCtx->aad, aadSz);
4814
+ #endif
4815
+ }
4816
+ if (ret != 0) {
4817
+ break;
4818
+ }
4819
+ tickCtx->state = MY_TICKET_STATE_FINAL;
4820
+ }
4821
+ FALL_THROUGH;
4822
+ case MY_TICKET_STATE_FINAL:
4823
+ *outLen = inLen; /* no padding in this mode */
4824
+ break;
4825
+ } /* switch */
4826
+
4827
+ #ifdef WOLFSSL_ASYNC_CRYPT
4828
+ if (ret == WC_PENDING_E) {
4829
+ return ret;
4830
+ }
4831
+ #endif
4832
+
4833
+ /* cleanup */
4834
+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4835
+ #elif defined(HAVE_AESGCM)
4836
+ wc_AesFree(&tickCtx->aes);
4837
+ #endif
4838
+
4839
+ /* reset context */
4840
+ XMEMSET(tickCtx, 0, sizeof(MyTicketCtx));
4841
+
4842
+ return (ret == 0) ? WOLFSSL_TICKET_RET_OK : WOLFSSL_TICKET_RET_REJECT;
4843
+ }
4844
+
4845
+ #endif /* HAVE_SESSION_TICKET && ((HAVE_CHACHA && HAVE_POLY1305) || HAVE_AESGCM) */
4846
+
4847
+
4848
+ static WC_INLINE word16 GetRandomPort(void)
4849
+ {
4850
+ word16 port = 0;
4851
+
4852
+ /* Generate random port for testing */
4853
+ WC_RNG rng;
4854
+ if (wc_InitRng(&rng) == 0) {
4855
+ if (wc_RNG_GenerateBlock(&rng, (byte*)&port, sizeof(port)) == 0) {
4856
+ port |= 0xC000; /* Make sure its in the 49152 - 65535 range */
4857
+ }
4858
+ wc_FreeRng(&rng);
4859
+ }
4860
+ (void)rng; /* for WC_NO_RNG case */
4861
+ return port;
4862
+ }
4863
+
4864
+ #ifdef WOLFSSL_EARLY_DATA
4865
+ static WC_INLINE void EarlyDataStatus(WOLFSSL* ssl)
4866
+ {
4867
+ int earlyData_status;
4868
+ #ifdef OPENSSL_EXTRA
4869
+ earlyData_status = SSL_get_early_data_status(ssl);
4870
+ #else
4871
+ earlyData_status = wolfSSL_get_early_data_status(ssl);
4872
+ #endif
4873
+ if (earlyData_status < 0) return;
4874
+
4875
+ printf("Early Data was ");
4876
+
4877
+ switch(earlyData_status) {
4878
+ case WOLFSSL_EARLY_DATA_NOT_SENT:
4879
+ printf("not sent.\n");
4880
+ break;
4881
+ case WOLFSSL_EARLY_DATA_REJECTED:
4882
+ printf("rejected.\n");
4883
+ break;
4884
+ case WOLFSSL_EARLY_DATA_ACCEPTED:
4885
+ printf("accepted\n");
4886
+ break;
4887
+ default:
4888
+ printf("unknown...\n");
4889
+ }
4890
+ }
4891
+ #endif /* WOLFSSL_EARLY_DATA */
4892
+
4893
+ #if defined(HAVE_SESSION_TICKET) || defined (WOLFSSL_DTLS13)
4894
+ static WC_INLINE int process_handshake_messages(WOLFSSL* ssl, int blocking,
4895
+ int* zero_return)
4896
+ {
4897
+ char foo[1];
4898
+ int ret = 0;
4899
+ int dtls;
4900
+
4901
+ if (zero_return == NULL || ssl == NULL)
4902
+ return -1;
4903
+
4904
+ dtls = wolfSSL_dtls(ssl);
4905
+ (void)dtls;
4906
+ *zero_return = 0;
4907
+
4908
+ if (!blocking) {
4909
+ int timeout = DEFAULT_TIMEOUT_SEC;
4910
+
4911
+ #ifdef WOLFSSL_DTLS
4912
+ if (dtls) {
4913
+ timeout = wolfSSL_dtls_get_current_timeout(ssl);
4914
+
4915
+ #ifdef WOLFSSL_DTLS13
4916
+ if (timeout > 4 && wolfSSL_dtls13_use_quick_timeout(ssl))
4917
+ timeout /= 4;
4918
+ #endif /* WOLFSSL_DTLS13 */
4919
+ }
4920
+ #endif /* WOLFSSL_DTLS */
4921
+
4922
+ ret = tcp_select(wolfSSL_get_fd(ssl), timeout);
4923
+ if (ret == TEST_ERROR_READY) {
4924
+ err_sys("tcp_select error");
4925
+ return -1;
4926
+ }
4927
+
4928
+ if (ret == TEST_TIMEOUT) {
4929
+ #ifdef WOLFSSL_DTLS
4930
+ if (dtls) {
4931
+ ret = wolfSSL_dtls_got_timeout(ssl);
4932
+ if (ret != WOLFSSL_SUCCESS && !wolfSSL_want_write(ssl) &&
4933
+ !wolfSSL_want_read(ssl)) {
4934
+ err_sys("got timeout error");
4935
+ return -1;
4936
+ }
4937
+ }
4938
+ #endif /* WOLFSSL_DTLS */
4939
+ /* do the peek to detect if the peer closed the connection*/
4940
+ }
4941
+ }
4942
+
4943
+ ret = wolfSSL_peek(ssl, foo, 0);
4944
+ if (ret < 0 && !wolfSSL_want_read(ssl) && !wolfSSL_want_write(ssl)) {
4945
+ ret = wolfSSL_get_error(ssl, ret);
4946
+ if (ret == WOLFSSL_ERROR_ZERO_RETURN)
4947
+ *zero_return = 1;
4948
+ return -1;
4949
+ }
4950
+
4951
+ return 0;
4952
+ }
4953
+ #endif /* HAVE_SESSION_TICKET || WOLFSSL_DTLS13 */
4954
+
4955
+ static WC_INLINE void printBuffer(const byte *buf, int size)
4956
+ {
4957
+ int i;
4958
+ for (i = 0; i < size; i++)
4959
+ printf("%x", buf[i]);
4960
+ }
4961
+
4962
+ #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
4963
+ defined(DEBUG_UNIT_TEST_CERTS)
4964
+ void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName);
4965
+ void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName);
4966
+ #endif
4967
+
4968
+ #define DTLS_CID_BUFFER_SIZE 256
4969
+
4970
+ static WC_MAYBE_UNUSED void *mymemmem(const void *haystack, size_t haystacklen,
4971
+ const void *needle, size_t needlelen)
4972
+ {
4973
+ size_t i, j;
4974
+ const char* h = (const char*)haystack;
4975
+ const char* n = (const char*)needle;
4976
+ if (needlelen > haystacklen)
4977
+ return NULL;
4978
+ for (i = 0; i <= haystacklen - needlelen; i++) {
4979
+ for (j = 0; j < needlelen; j++) {
4980
+ if (h[i + j] != n[j])
4981
+ break;
4982
+ }
4983
+ if (j == needlelen)
4984
+ return (void*)(h + i);
4985
+ }
4986
+ return NULL;
4987
+ }
4988
+
4989
+ #endif /* wolfSSL_TEST_H */