rho-tau-extensions 5.5.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (661) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +2 -0
  3. data/LICENSE +21 -0
  4. data/README.md +6 -0
  5. data/Rakefile +90 -0
  6. data/libs/crosswalk.rb +2 -0
  7. data/libs/crosswalk/crosswalk.rb +2 -0
  8. data/libs/crosswalk/ext.yml +21 -0
  9. data/libs/crosswalk/ext/Crosswalk.xml +27 -0
  10. data/libs/crosswalk/ext/build +19 -0
  11. data/libs/crosswalk/ext/build.bat +29 -0
  12. data/libs/crosswalk/ext/platform/android/AndroidManifest.xml +9 -0
  13. data/libs/crosswalk/ext/platform/android/Rakefile +141 -0
  14. data/libs/crosswalk/ext/platform/android/adds/lib/armeabi/libxwalkcore.so +0 -0
  15. data/libs/crosswalk/ext/platform/android/adds/lib/armeabi/libxwalkdummy.so +0 -0
  16. data/libs/crosswalk/ext/platform/android/adds/lib/x86/libxwalkcore.so +0 -0
  17. data/libs/crosswalk/ext/platform/android/adds/lib/x86/libxwalkdummy.so +0 -0
  18. data/libs/crosswalk/ext/platform/android/adds/lib/xwalk_core_library_java.jar +0 -0
  19. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/bubble.9.png +0 -0
  20. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/bubble_arrow_up.png +0 -0
  21. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/color_picker_advanced_select_handle.png +0 -0
  22. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/crosswalk.png +0 -0
  23. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/dropdown_popup_background_down.9.png +0 -0
  24. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/dropdown_popup_background_up.9.png +0 -0
  25. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/ic_menu_share_holo_light.png +0 -0
  26. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/ic_search.png +0 -0
  27. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/ic_warning.png +0 -0
  28. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/ondemand_overlay.9.png +0 -0
  29. data/libs/crosswalk/ext/platform/android/adds/res/drawable-hdpi/verify_checkmark.png +0 -0
  30. data/libs/crosswalk/ext/platform/android/adds/res/drawable-ldpi/crosswalk.png +0 -0
  31. data/libs/crosswalk/ext/platform/android/adds/res/drawable-mdpi/crosswalk.png +0 -0
  32. data/libs/crosswalk/ext/platform/android/adds/res/drawable-v21/button_borderless_compat.xml +10 -0
  33. data/libs/crosswalk/ext/platform/android/adds/res/drawable-v21/button_compat.xml +9 -0
  34. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/bubble.9.png +0 -0
  35. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/bubble_arrow_up.png +0 -0
  36. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/color_picker_advanced_select_handle.png +0 -0
  37. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/crosswalk.png +0 -0
  38. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/dropdown_popup_background_down.9.png +0 -0
  39. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/dropdown_popup_background_up.9.png +0 -0
  40. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/ic_menu_share_holo_light.png +0 -0
  41. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/ic_search.png +0 -0
  42. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/ic_warning.png +0 -0
  43. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/ondemand_overlay.9.png +0 -0
  44. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xhdpi/verify_checkmark.png +0 -0
  45. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxhdpi/ic_menu_share_holo_light.png +0 -0
  46. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxhdpi/ic_search.png +0 -0
  47. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxhdpi/ic_warning.png +0 -0
  48. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxhdpi/verify_checkmark.png +0 -0
  49. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxxhdpi/ic_menu_share_holo_light.png +0 -0
  50. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxxhdpi/ic_search.png +0 -0
  51. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxxhdpi/ic_warning.png +0 -0
  52. data/libs/crosswalk/ext/platform/android/adds/res/drawable-xxxhdpi/verify_checkmark.png +0 -0
  53. data/libs/crosswalk/ext/platform/android/adds/res/drawable/autofill_chip_inset.xml +15 -0
  54. data/libs/crosswalk/ext/platform/android/adds/res/drawable/bubble.9.png +0 -0
  55. data/libs/crosswalk/ext/platform/android/adds/res/drawable/bubble_arrow_up.png +0 -0
  56. data/libs/crosswalk/ext/platform/android/adds/res/drawable/button_compat_shape.xml +9 -0
  57. data/libs/crosswalk/ext/platform/android/adds/res/drawable/color_button_background.xml +36 -0
  58. data/libs/crosswalk/ext/platform/android/adds/res/drawable/color_picker_advanced_select_handle.png +0 -0
  59. data/libs/crosswalk/ext/platform/android/adds/res/drawable/color_picker_border.xml +12 -0
  60. data/libs/crosswalk/ext/platform/android/adds/res/drawable/dropdown_label_color.xml +11 -0
  61. data/libs/crosswalk/ext/platform/android/adds/res/drawable/dropdown_popup_background.xml +13 -0
  62. data/libs/crosswalk/ext/platform/android/adds/res/drawable/dropdown_popup_background_down.9.png +0 -0
  63. data/libs/crosswalk/ext/platform/android/adds/res/drawable/dropdown_popup_background_up.9.png +0 -0
  64. data/libs/crosswalk/ext/platform/android/adds/res/drawable/ic_menu_share_holo_light.png +0 -0
  65. data/libs/crosswalk/ext/platform/android/adds/res/drawable/ic_search.png +0 -0
  66. data/libs/crosswalk/ext/platform/android/adds/res/drawable/ic_warning.png +0 -0
  67. data/libs/crosswalk/ext/platform/android/adds/res/drawable/launchscreen_bg.xml +19 -0
  68. data/libs/crosswalk/ext/platform/android/adds/res/drawable/ondemand_overlay.9.png +0 -0
  69. data/libs/crosswalk/ext/platform/android/adds/res/drawable/verify_checkmark.png +0 -0
  70. data/libs/crosswalk/ext/platform/android/adds/res/layout-land/date_time_picker_dialog.xml +42 -0
  71. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/autofill_keyboard_accessory_item.xml +40 -0
  72. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/autofill_suggestion_item.xml +18 -0
  73. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/color_picker_advanced_component.xml +46 -0
  74. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/color_picker_dialog_content.xml +51 -0
  75. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/color_picker_dialog_title.xml +41 -0
  76. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/date_time_suggestion.xml +35 -0
  77. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/dropdown_item.xml +58 -0
  78. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/multi_field_time_picker_dialog.xml +122 -0
  79. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/two_field_date_picker.xml +38 -0
  80. data/libs/crosswalk/ext/platform/android/adds/res/layout-v17/validation_message_bubble.xml +72 -0
  81. data/libs/crosswalk/ext/platform/android/adds/res/layout/autofill_keyboard_accessory_icon.xml +13 -0
  82. data/libs/crosswalk/ext/platform/android/adds/res/layout/autofill_keyboard_accessory_item.xml +17 -0
  83. data/libs/crosswalk/ext/platform/android/adds/res/layout/autofill_suggestion_item.xml +7 -0
  84. data/libs/crosswalk/ext/platform/android/adds/res/layout/color_picker_advanced_component.xml +30 -0
  85. data/libs/crosswalk/ext/platform/android/adds/res/layout/color_picker_dialog_content.xml +36 -0
  86. data/libs/crosswalk/ext/platform/android/adds/res/layout/color_picker_dialog_title.xml +25 -0
  87. data/libs/crosswalk/ext/platform/android/adds/res/layout/date_time_picker_dialog.xml +42 -0
  88. data/libs/crosswalk/ext/platform/android/adds/res/layout/date_time_suggestion.xml +16 -0
  89. data/libs/crosswalk/ext/platform/android/adds/res/layout/dropdown_item.xml +34 -0
  90. data/libs/crosswalk/ext/platform/android/adds/res/layout/multi_field_time_picker_dialog.xml +50 -0
  91. data/libs/crosswalk/ext/platform/android/adds/res/layout/two_field_date_picker.xml +26 -0
  92. data/libs/crosswalk/ext/platform/android/adds/res/layout/validation_message_bubble.xml +47 -0
  93. data/libs/crosswalk/ext/platform/android/adds/res/menu/select_action_menu.xml +54 -0
  94. data/libs/crosswalk/ext/platform/android/adds/res/raw/contacts_api.js +206 -0
  95. data/libs/crosswalk/ext/platform/android/adds/res/raw/device_capabilities_api.js +231 -0
  96. data/libs/crosswalk/ext/platform/android/adds/res/raw/empty.wav +0 -0
  97. data/libs/crosswalk/ext/platform/android/adds/res/raw/icudtl.dat +0 -0
  98. data/libs/crosswalk/ext/platform/android/adds/res/raw/launch_screen_api.js +9 -0
  99. data/libs/crosswalk/ext/platform/android/adds/res/raw/messaging_api.js +359 -0
  100. data/libs/crosswalk/ext/platform/android/adds/res/raw/presentation_api.js +144 -0
  101. data/libs/crosswalk/ext/platform/android/adds/res/raw/wifidirect_api.js +227 -0
  102. data/libs/crosswalk/ext/platform/android/adds/res/raw/xwalk.pak +0 -0
  103. data/libs/crosswalk/ext/platform/android/adds/res/values-am/android_content_strings.xml +15 -0
  104. data/libs/crosswalk/ext/platform/android/adds/res/values-am/android_ui_strings.xml +47 -0
  105. data/libs/crosswalk/ext/platform/android/adds/res/values-ar/android_content_strings.xml +15 -0
  106. data/libs/crosswalk/ext/platform/android/adds/res/values-ar/android_ui_strings.xml +47 -0
  107. data/libs/crosswalk/ext/platform/android/adds/res/values-bg/android_content_strings.xml +15 -0
  108. data/libs/crosswalk/ext/platform/android/adds/res/values-bg/android_ui_strings.xml +47 -0
  109. data/libs/crosswalk/ext/platform/android/adds/res/values-ca/android_content_strings.xml +15 -0
  110. data/libs/crosswalk/ext/platform/android/adds/res/values-ca/android_ui_strings.xml +47 -0
  111. data/libs/crosswalk/ext/platform/android/adds/res/values-cs/android_content_strings.xml +15 -0
  112. data/libs/crosswalk/ext/platform/android/adds/res/values-cs/android_ui_strings.xml +47 -0
  113. data/libs/crosswalk/ext/platform/android/adds/res/values-da/android_content_strings.xml +15 -0
  114. data/libs/crosswalk/ext/platform/android/adds/res/values-da/android_ui_strings.xml +47 -0
  115. data/libs/crosswalk/ext/platform/android/adds/res/values-de/android_content_strings.xml +15 -0
  116. data/libs/crosswalk/ext/platform/android/adds/res/values-de/android_ui_strings.xml +47 -0
  117. data/libs/crosswalk/ext/platform/android/adds/res/values-el/android_content_strings.xml +15 -0
  118. data/libs/crosswalk/ext/platform/android/adds/res/values-el/android_ui_strings.xml +47 -0
  119. data/libs/crosswalk/ext/platform/android/adds/res/values-en-rGB/android_content_strings.xml +15 -0
  120. data/libs/crosswalk/ext/platform/android/adds/res/values-en-rGB/android_ui_strings.xml +47 -0
  121. data/libs/crosswalk/ext/platform/android/adds/res/values-es-rUS/android_content_strings.xml +15 -0
  122. data/libs/crosswalk/ext/platform/android/adds/res/values-es-rUS/android_ui_strings.xml +47 -0
  123. data/libs/crosswalk/ext/platform/android/adds/res/values-es/android_content_strings.xml +15 -0
  124. data/libs/crosswalk/ext/platform/android/adds/res/values-es/android_ui_strings.xml +47 -0
  125. data/libs/crosswalk/ext/platform/android/adds/res/values-fa/android_content_strings.xml +15 -0
  126. data/libs/crosswalk/ext/platform/android/adds/res/values-fa/android_ui_strings.xml +47 -0
  127. data/libs/crosswalk/ext/platform/android/adds/res/values-fi/android_content_strings.xml +15 -0
  128. data/libs/crosswalk/ext/platform/android/adds/res/values-fi/android_ui_strings.xml +47 -0
  129. data/libs/crosswalk/ext/platform/android/adds/res/values-fr/android_content_strings.xml +15 -0
  130. data/libs/crosswalk/ext/platform/android/adds/res/values-fr/android_ui_strings.xml +47 -0
  131. data/libs/crosswalk/ext/platform/android/adds/res/values-hi/android_content_strings.xml +15 -0
  132. data/libs/crosswalk/ext/platform/android/adds/res/values-hi/android_ui_strings.xml +47 -0
  133. data/libs/crosswalk/ext/platform/android/adds/res/values-hr/android_content_strings.xml +15 -0
  134. data/libs/crosswalk/ext/platform/android/adds/res/values-hr/android_ui_strings.xml +47 -0
  135. data/libs/crosswalk/ext/platform/android/adds/res/values-hu/android_content_strings.xml +15 -0
  136. data/libs/crosswalk/ext/platform/android/adds/res/values-hu/android_ui_strings.xml +47 -0
  137. data/libs/crosswalk/ext/platform/android/adds/res/values-in/android_content_strings.xml +15 -0
  138. data/libs/crosswalk/ext/platform/android/adds/res/values-in/android_ui_strings.xml +47 -0
  139. data/libs/crosswalk/ext/platform/android/adds/res/values-it/android_content_strings.xml +15 -0
  140. data/libs/crosswalk/ext/platform/android/adds/res/values-it/android_ui_strings.xml +47 -0
  141. data/libs/crosswalk/ext/platform/android/adds/res/values-iw/android_content_strings.xml +15 -0
  142. data/libs/crosswalk/ext/platform/android/adds/res/values-iw/android_ui_strings.xml +47 -0
  143. data/libs/crosswalk/ext/platform/android/adds/res/values-ja/android_content_strings.xml +15 -0
  144. data/libs/crosswalk/ext/platform/android/adds/res/values-ja/android_ui_strings.xml +47 -0
  145. data/libs/crosswalk/ext/platform/android/adds/res/values-ko/android_content_strings.xml +15 -0
  146. data/libs/crosswalk/ext/platform/android/adds/res/values-ko/android_ui_strings.xml +47 -0
  147. data/libs/crosswalk/ext/platform/android/adds/res/values-lt/android_content_strings.xml +15 -0
  148. data/libs/crosswalk/ext/platform/android/adds/res/values-lt/android_ui_strings.xml +47 -0
  149. data/libs/crosswalk/ext/platform/android/adds/res/values-lv/android_content_strings.xml +15 -0
  150. data/libs/crosswalk/ext/platform/android/adds/res/values-lv/android_ui_strings.xml +47 -0
  151. data/libs/crosswalk/ext/platform/android/adds/res/values-nb/android_content_strings.xml +15 -0
  152. data/libs/crosswalk/ext/platform/android/adds/res/values-nb/android_ui_strings.xml +47 -0
  153. data/libs/crosswalk/ext/platform/android/adds/res/values-nl/android_content_strings.xml +15 -0
  154. data/libs/crosswalk/ext/platform/android/adds/res/values-nl/android_ui_strings.xml +47 -0
  155. data/libs/crosswalk/ext/platform/android/adds/res/values-pl/android_content_strings.xml +15 -0
  156. data/libs/crosswalk/ext/platform/android/adds/res/values-pl/android_ui_strings.xml +47 -0
  157. data/libs/crosswalk/ext/platform/android/adds/res/values-pt-rBR/android_content_strings.xml +15 -0
  158. data/libs/crosswalk/ext/platform/android/adds/res/values-pt-rBR/android_ui_strings.xml +47 -0
  159. data/libs/crosswalk/ext/platform/android/adds/res/values-pt-rPT/android_content_strings.xml +15 -0
  160. data/libs/crosswalk/ext/platform/android/adds/res/values-pt-rPT/android_ui_strings.xml +47 -0
  161. data/libs/crosswalk/ext/platform/android/adds/res/values-ro/android_content_strings.xml +15 -0
  162. data/libs/crosswalk/ext/platform/android/adds/res/values-ro/android_ui_strings.xml +47 -0
  163. data/libs/crosswalk/ext/platform/android/adds/res/values-ru/android_content_strings.xml +15 -0
  164. data/libs/crosswalk/ext/platform/android/adds/res/values-ru/android_ui_strings.xml +47 -0
  165. data/libs/crosswalk/ext/platform/android/adds/res/values-sk/android_content_strings.xml +15 -0
  166. data/libs/crosswalk/ext/platform/android/adds/res/values-sk/android_ui_strings.xml +47 -0
  167. data/libs/crosswalk/ext/platform/android/adds/res/values-sl/android_content_strings.xml +15 -0
  168. data/libs/crosswalk/ext/platform/android/adds/res/values-sl/android_ui_strings.xml +47 -0
  169. data/libs/crosswalk/ext/platform/android/adds/res/values-sr/android_content_strings.xml +15 -0
  170. data/libs/crosswalk/ext/platform/android/adds/res/values-sr/android_ui_strings.xml +47 -0
  171. data/libs/crosswalk/ext/platform/android/adds/res/values-sv/android_content_strings.xml +15 -0
  172. data/libs/crosswalk/ext/platform/android/adds/res/values-sv/android_ui_strings.xml +47 -0
  173. data/libs/crosswalk/ext/platform/android/adds/res/values-sw/android_content_strings.xml +15 -0
  174. data/libs/crosswalk/ext/platform/android/adds/res/values-sw/android_ui_strings.xml +47 -0
  175. data/libs/crosswalk/ext/platform/android/adds/res/values-th/android_content_strings.xml +15 -0
  176. data/libs/crosswalk/ext/platform/android/adds/res/values-th/android_ui_strings.xml +47 -0
  177. data/libs/crosswalk/ext/platform/android/adds/res/values-tl/android_content_strings.xml +15 -0
  178. data/libs/crosswalk/ext/platform/android/adds/res/values-tl/android_ui_strings.xml +47 -0
  179. data/libs/crosswalk/ext/platform/android/adds/res/values-tr/android_content_strings.xml +15 -0
  180. data/libs/crosswalk/ext/platform/android/adds/res/values-tr/android_ui_strings.xml +47 -0
  181. data/libs/crosswalk/ext/platform/android/adds/res/values-uk/android_content_strings.xml +15 -0
  182. data/libs/crosswalk/ext/platform/android/adds/res/values-uk/android_ui_strings.xml +47 -0
  183. data/libs/crosswalk/ext/platform/android/adds/res/values-v14/theme.xml +16 -0
  184. data/libs/crosswalk/ext/platform/android/adds/res/values-v17/styles.xml +19 -0
  185. data/libs/crosswalk/ext/platform/android/adds/res/values-v17/ui_java_styles.xml +41 -0
  186. data/libs/crosswalk/ext/platform/android/adds/res/values-v21/styles.xml +14 -0
  187. data/libs/crosswalk/ext/platform/android/adds/res/values-v21/ui_java_styles.xml +14 -0
  188. data/libs/crosswalk/ext/platform/android/adds/res/values-vi/android_content_strings.xml +15 -0
  189. data/libs/crosswalk/ext/platform/android/adds/res/values-vi/android_ui_strings.xml +47 -0
  190. data/libs/crosswalk/ext/platform/android/adds/res/values-zh-rCN/android_content_strings.xml +15 -0
  191. data/libs/crosswalk/ext/platform/android/adds/res/values-zh-rCN/android_ui_strings.xml +47 -0
  192. data/libs/crosswalk/ext/platform/android/adds/res/values-zh-rTW/android_content_strings.xml +15 -0
  193. data/libs/crosswalk/ext/platform/android/adds/res/values-zh-rTW/android_ui_strings.xml +47 -0
  194. data/libs/crosswalk/ext/platform/android/adds/res/values/android_content_strings.xml +15 -0
  195. data/libs/crosswalk/ext/platform/android/adds/res/values/android_ui_strings.xml +47 -0
  196. data/libs/crosswalk/ext/platform/android/adds/res/values/android_xwalk_strings.xml +17 -0
  197. data/libs/crosswalk/ext/platform/android/adds/res/values/ui_java_attrs.xml +9 -0
  198. data/libs/crosswalk/ext/platform/android/adds/res/values/ui_java_dimens.xml +31 -0
  199. data/libs/crosswalk/ext/platform/android/adds/res/values/ui_java_strings.xml +16 -0
  200. data/libs/crosswalk/ext/platform/android/adds/res/values/ui_java_styles.xml +101 -0
  201. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_app_strings.xml +28 -0
  202. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_attrs.xml +11 -0
  203. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_colors.xml +13 -0
  204. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_core_internal_java_strings.xml +16 -0
  205. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_core_java_strings.xml +16 -0
  206. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_dimens.xml +11 -0
  207. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_resources_list.xml +7 -0
  208. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_styles.xml +40 -0
  209. data/libs/crosswalk/ext/platform/android/adds/res/values/xwalk_values.xml +10 -0
  210. data/libs/crosswalk/ext/platform/android/ext_java.files +14 -0
  211. data/libs/crosswalk/ext/platform/android/ext_native.files +7 -0
  212. data/libs/crosswalk/ext/platform/android/jni/Crosswalk_impl.cpp +61 -0
  213. data/libs/crosswalk/ext/platform/android/src/com/rho/crosswalk/Crosswalk.java +14 -0
  214. data/libs/crosswalk/ext/platform/android/src/com/rho/crosswalk/CrosswalkFactory.java +18 -0
  215. data/libs/crosswalk/ext/platform/android/src/com/rho/crosswalk/CrosswalkSingleton.java +24 -0
  216. data/libs/crosswalk/ext/platform/android/src/com/tautechnologies/tau/crosswalk/CrosswalkExtension.java +16 -0
  217. data/libs/crosswalk/ext/platform/android/src/com/tautechnologies/tau/crosswalk/RhodesListener.java +18 -0
  218. data/libs/crosswalk/ext/platform/android/src/com/tautechnologies/tau/crosswalk/TauXWResourceClient.java +182 -0
  219. data/libs/crosswalk/ext/platform/android/src/com/tautechnologies/tau/crosswalk/TauXWUIClient.java +125 -0
  220. data/libs/crosswalk/ext/platform/android/src/com/tautechnologies/tau/crosswalk/TauXWalkWebView.java +368 -0
  221. data/libs/crosswalk/ext/platform/iphone/Crosswalk.xcodeproj/project.pbxproj +368 -0
  222. data/libs/crosswalk/ext/platform/iphone/Crosswalk_Prefix.pch +7 -0
  223. data/libs/crosswalk/ext/platform/iphone/Rakefile +73 -0
  224. data/libs/crosswalk/ext/platform/iphone/impl/Crosswalk.h +14 -0
  225. data/libs/crosswalk/ext/platform/iphone/impl/Crosswalk.m +24 -0
  226. data/libs/crosswalk/ext/platform/iphone/impl/CrosswalkFactorySingleton.m +16 -0
  227. data/libs/crosswalk/ext/platform/iphone/impl/CrosswalkSetup.m +9 -0
  228. data/libs/crosswalk/ext/platform/iphone/impl/CrosswalkSingleton.h +17 -0
  229. data/libs/crosswalk/ext/platform/iphone/impl/CrosswalkSingleton.m +23 -0
  230. data/libs/crosswalk/ext/platform/iphone/impl/readme.txt +7 -0
  231. data/libs/crosswalk/ext/platform/qt/Crosswalk.pro +66 -0
  232. data/libs/crosswalk/ext/platform/qt/Rakefile +35 -0
  233. data/libs/crosswalk/ext/platform/qt/src/Crosswalk_impl.cpp +77 -0
  234. data/libs/crosswalk/ext/platform/wm/Crosswalk.sln +52 -0
  235. data/libs/crosswalk/ext/platform/wm/Crosswalk.vcproj +714 -0
  236. data/libs/crosswalk/ext/platform/wm/Crosswalk.vsprops +15 -0
  237. data/libs/crosswalk/ext/platform/wm/src/Crosswalk_impl.cpp +77 -0
  238. data/libs/crosswalk/ext/platform/wp8/Crosswalk.props +18 -0
  239. data/libs/crosswalk/ext/platform/wp8/Crosswalk.vcxproj +170 -0
  240. data/libs/crosswalk/ext/platform/wp8/Crosswalk.vcxproj.filters +50 -0
  241. data/libs/crosswalk/ext/platform/wp8/CrosswalkImpl.csproj +119 -0
  242. data/libs/crosswalk/ext/platform/wp8/CrosswalkImpl.props +8 -0
  243. data/libs/crosswalk/ext/platform/wp8/CrosswalkImpl.targets +7 -0
  244. data/libs/crosswalk/ext/platform/wp8/CrosswalkLib.props +18 -0
  245. data/libs/crosswalk/ext/platform/wp8/CrosswalkLib.vcxproj +185 -0
  246. data/libs/crosswalk/ext/platform/wp8/CrosswalkLib.vcxproj.filters +58 -0
  247. data/libs/crosswalk/ext/platform/wp8/src/Crosswalk_impl.cpp +76 -0
  248. data/libs/crosswalk/ext/platform/wp8/src/Crosswalk_impl.cs +69 -0
  249. data/libs/crosswalk/ext/platform/wp8/src/Properties/AssemblyInfo.cs +37 -0
  250. data/libs/enterprise-barcode/ext.yml +13 -0
  251. data/libs/enterprise-barcode/ext/barcode.xml +2144 -0
  252. data/libs/enterprise-barcode/ext/build +17 -0
  253. data/libs/enterprise-barcode/ext/build.bat +29 -0
  254. data/libs/enterprise-barcode/ext/platform/android/AndroidManifest.xml +31 -0
  255. data/libs/enterprise-barcode/ext/platform/android/ZXing_Info/AUTHORS +58 -0
  256. data/libs/enterprise-barcode/ext/platform/android/ZXing_Info/CHANGES +266 -0
  257. data/libs/enterprise-barcode/ext/platform/android/ZXing_Info/COPYING +201 -0
  258. data/libs/enterprise-barcode/ext/platform/android/ZXing_Info/README +11 -0
  259. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/drawable-hdpi/cancel_icon.png +0 -0
  260. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/drawable-hdpi/ok_icon.png +0 -0
  261. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/drawable-hdpi/retake_icon.png +0 -0
  262. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/drawable/cancel_icon.png +0 -0
  263. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/drawable/ok_icon.png +0 -0
  264. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/drawable/retake_icon.png +0 -0
  265. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/layout/capture.xml +122 -0
  266. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/raw/beep.ogg +0 -0
  267. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/values/attrs.xml +20 -0
  268. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/values/colors.xml +42 -0
  269. data/libs/enterprise-barcode/ext/platform/android/additional_files/res/values/ids.xml +31 -0
  270. data/libs/enterprise-barcode/ext/platform/android/adds/lib/armeabi/liballbarcode.a +0 -0
  271. data/libs/enterprise-barcode/ext/platform/android/adds/lib/x86/liballbarcode.a +0 -0
  272. data/libs/enterprise-barcode/ext/platform/android/allbarcode.jar +0 -0
  273. data/libs/enterprise-barcode/ext/platform/iphone/Barcode.xcodeproj/project.pbxproj +524 -0
  274. data/libs/enterprise-barcode/ext/platform/iphone/Barcode_Prefix.pch +7 -0
  275. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeCallbackHelper.h +27 -0
  276. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeCallbackHelper.mm +231 -0
  277. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewController.h +95 -0
  278. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewController.m +1017 -0
  279. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewFactory.h +7 -0
  280. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewFactory.mm +58 -0
  281. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewFactoryRegister.mm +18 -0
  282. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewManager.h +16 -0
  283. data/libs/enterprise-barcode/ext/platform/iphone/Classes/BarcodeViewManager.mm +32 -0
  284. data/libs/enterprise-barcode/ext/platform/iphone/Classes/ImageProvider.cpp +25 -0
  285. data/libs/enterprise-barcode/ext/platform/iphone/Classes/ImageProvider.h +15 -0
  286. data/libs/enterprise-barcode/ext/platform/iphone/Classes/ImageProvider.mm +159 -0
  287. data/libs/enterprise-barcode/ext/platform/iphone/Classes/barcode.m +123 -0
  288. data/libs/enterprise-barcode/ext/platform/iphone/Rakefile +69 -0
  289. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/COPYING +27 -0
  290. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarCameraSimulator.h +45 -0
  291. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarCaptureReader.h +111 -0
  292. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarHelpController.h +60 -0
  293. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarImage.h +69 -0
  294. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarImageScanner.h +51 -0
  295. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarReaderController.h +142 -0
  296. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarReaderView.h +135 -0
  297. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarReaderViewController.h +130 -0
  298. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarSDK.h +34 -0
  299. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarSymbol.h +71 -0
  300. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar.h +1497 -0
  301. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Decoder.h +202 -0
  302. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Exception.h +187 -0
  303. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Image.h +321 -0
  304. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/ImageScanner.h +130 -0
  305. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Processor.h +223 -0
  306. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Scanner.h +162 -0
  307. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Symbol.h +528 -0
  308. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Video.h +170 -0
  309. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Window.h +136 -0
  310. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/LICENSE +504 -0
  311. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/README +59 -0
  312. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Resources/zbar-back.png +0 -0
  313. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Resources/zbar-help.html +88 -0
  314. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Resources/zbar-helpicons.png +0 -0
  315. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/Resources/zbar-samples.png +0 -0
  316. data/libs/enterprise-barcode/ext/platform/iphone/ZBarSDK/libzbar.a +0 -0
  317. data/libs/enterprise-barcode/ext/platform/iphone/impl/Barcode.h +21 -0
  318. data/libs/enterprise-barcode/ext/platform/iphone/impl/Barcode.m +132 -0
  319. data/libs/enterprise-barcode/ext/platform/iphone/impl/BarcodeFactory.h +10 -0
  320. data/libs/enterprise-barcode/ext/platform/iphone/impl/BarcodeFactory.m +16 -0
  321. data/libs/enterprise-barcode/ext/platform/iphone/impl/BarcodeFactorySingleton.m +16 -0
  322. data/libs/enterprise-barcode/ext/platform/iphone/impl/BarcodeSetup.m +8 -0
  323. data/libs/enterprise-barcode/ext/platform/iphone/impl/BarcodeSingleton.h +17 -0
  324. data/libs/enterprise-barcode/ext/platform/iphone/impl/BarcodeSingleton.m +22 -0
  325. data/libs/enterprise-barcode/ext/platform/iphone/impl/readme.txt +7 -0
  326. data/libs/enterprise-barcode/ext/platform/wm/Barcode.sln +44 -0
  327. data/libs/enterprise-barcode/ext/platform/wm/Barcode.vcproj +836 -0
  328. data/libs/enterprise-barcode/ext/platform/wm/Barcode.vsprops +15 -0
  329. data/libs/enterprise-barcode/ext/platform/wm/readme.txt +0 -0
  330. data/libs/enterprise-barcode/ext/platform/wm/src/Barcode_impl.cpp +376 -0
  331. data/libs/enterprise-barcode/ext/platform/wm/src/DecodeNotifier.cpp +173 -0
  332. data/libs/enterprise-barcode/ext/platform/wm/src/DecodeNotifier.h +149 -0
  333. data/libs/enterprise-barcode/ext/platform/wm/src/EMDKInterfaceAbstraction.cpp +476 -0
  334. data/libs/enterprise-barcode/ext/platform/wm/src/GetDecoderProperties.cpp +1195 -0
  335. data/libs/enterprise-barcode/ext/platform/wm/src/GetScannerProperties.cpp +553 -0
  336. data/libs/enterprise-barcode/ext/platform/wm/src/KeyInjector.cpp +177 -0
  337. data/libs/enterprise-barcode/ext/platform/wm/src/KeyInjector.h +40 -0
  338. data/libs/enterprise-barcode/ext/platform/wm/src/NotificationLoader.cpp +76 -0
  339. data/libs/enterprise-barcode/ext/platform/wm/src/NotificationLoader.h +44 -0
  340. data/libs/enterprise-barcode/ext/platform/wm/src/RSM.cpp +1211 -0
  341. data/libs/enterprise-barcode/ext/platform/wm/src/Scanner.cpp +2609 -0
  342. data/libs/enterprise-barcode/ext/platform/wm/src/Scanner.h +1099 -0
  343. data/libs/enterprise-barcode/ext/platform/wm/src/ScannerDefines.h +322 -0
  344. data/libs/enterprise-barcode/ext/platform/wm/src/SetDecoderProperties.cpp +2106 -0
  345. data/libs/enterprise-barcode/ext/platform/wm/src/SetScannerProperties.cpp +1060 -0
  346. data/libs/enterprise-barcode/ext/platform/wm/src/Utilities.cpp +184 -0
  347. data/libs/enterprise-barcode/ext/platform/wp8/BarcodeImpl.csproj +119 -0
  348. data/libs/enterprise-barcode/ext/platform/wp8/BarcodeImpl.props +8 -0
  349. data/libs/enterprise-barcode/ext/platform/wp8/BarcodeImpl.targets +35 -0
  350. data/libs/enterprise-barcode/ext/platform/wp8/BarcodeLib.props +18 -0
  351. data/libs/enterprise-barcode/ext/platform/wp8/BarcodeLib.vcxproj +185 -0
  352. data/libs/enterprise-barcode/ext/platform/wp8/BarcodeLib.vcxproj.filters +58 -0
  353. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/Nokia.Graphics.Imaging.dll +0 -0
  354. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/Nokia.Graphics.Imaging.winmd +0 -0
  355. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/Nokia.Graphics.Imaging.xml +4813 -0
  356. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/Nokia.InteropServices.WindowsRuntime.dll +0 -0
  357. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/Nokia.InteropServices.WindowsRuntime.winmd +0 -0
  358. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/Nokia.InteropServices.WindowsRuntime.xml +41 -0
  359. data/libs/enterprise-barcode/ext/platform/wp8/lib/ARM/OpticalReaderLib.dll +0 -0
  360. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib.XML +68 -0
  361. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib.dll +0 -0
  362. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib/BarcodeReaderLib.csproj +120 -0
  363. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib/BarcodeReaderLib.sln +34 -0
  364. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib/CameraNavigatePage.xaml +32 -0
  365. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib/CameraNavigatePage.xaml.cs +235 -0
  366. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib/OpticalReaderTask.cs +182 -0
  367. data/libs/enterprise-barcode/ext/platform/wp8/lib/BarcodeReaderLib/Properties/AssemblyInfo.cs +37 -0
  368. data/libs/enterprise-barcode/ext/platform/wp8/lib/Nokia.Graphics.Imaging.Managed.dll +0 -0
  369. data/libs/enterprise-barcode/ext/platform/wp8/lib/Nokia.Graphics.Imaging.Managed.xml +341 -0
  370. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/Nokia.Graphics.Imaging.dll +0 -0
  371. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/Nokia.Graphics.Imaging.winmd +0 -0
  372. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/Nokia.Graphics.Imaging.xml +4813 -0
  373. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/Nokia.InteropServices.WindowsRuntime.dll +0 -0
  374. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/Nokia.InteropServices.WindowsRuntime.winmd +0 -0
  375. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/Nokia.InteropServices.WindowsRuntime.xml +41 -0
  376. data/libs/enterprise-barcode/ext/platform/wp8/lib/x86/OpticalReaderLib.dll +0 -0
  377. data/libs/enterprise-barcode/ext/platform/wp8/lib/zxing.wp8.0.XML +10324 -0
  378. data/libs/enterprise-barcode/ext/platform/wp8/lib/zxing.wp8.0.dll +0 -0
  379. data/libs/enterprise-barcode/ext/platform/wp8/src/Barcode_impl.cs +630 -0
  380. data/libs/enterprise-barcode/ext/platform/wp8/src/Properties/AssemblyInfo.cs +37 -0
  381. data/libs/enterprise-barcode/public/api/generated/Rho.Barcode.js +772 -0
  382. data/libs/ie/rhobrowser.dll +0 -0
  383. data/libs/nodejs.rb +2 -0
  384. data/libs/nodejs/ext.yml +25 -0
  385. data/libs/nodejs/ext/Nodejs.xml +37 -0
  386. data/libs/nodejs/ext/build +19 -0
  387. data/libs/nodejs/ext/build.bat +29 -0
  388. data/libs/nodejs/ext/platform/android/Rakefile +161 -0
  389. data/libs/nodejs/ext/platform/android/ext_native.files +8 -0
  390. data/libs/nodejs/ext/platform/android/jxCore/jx.h +134 -0
  391. data/libs/nodejs/ext/platform/android/jxCore/jx_result.h +221 -0
  392. data/libs/nodejs/ext/platform/android/jxCore/libcares_arm.a +0 -0
  393. data/libs/nodejs/ext/platform/android/jxCore/libcares_ia32.a +0 -0
  394. data/libs/nodejs/ext/platform/android/jxCore/libcares_x64.a +0 -0
  395. data/libs/nodejs/ext/platform/android/jxCore/libchrome_zlib_arm.a +0 -0
  396. data/libs/nodejs/ext/platform/android/jxCore/libchrome_zlib_ia32.a +0 -0
  397. data/libs/nodejs/ext/platform/android/jxCore/libchrome_zlib_x64.a +0 -0
  398. data/libs/nodejs/ext/platform/android/jxCore/libhttp_parser_arm.a +0 -0
  399. data/libs/nodejs/ext/platform/android/jxCore/libhttp_parser_ia32.a +0 -0
  400. data/libs/nodejs/ext/platform/android/jxCore/libhttp_parser_x64.a +0 -0
  401. data/libs/nodejs/ext/platform/android/jxCore/libjx_arm.a +0 -0
  402. data/libs/nodejs/ext/platform/android/jxCore/libjx_ia32.a +0 -0
  403. data/libs/nodejs/ext/platform/android/jxCore/libjx_x64.a +0 -0
  404. data/libs/nodejs/ext/platform/android/jxCore/libopenssl_arm.a +0 -0
  405. data/libs/nodejs/ext/platform/android/jxCore/libopenssl_ia32.a +0 -0
  406. data/libs/nodejs/ext/platform/android/jxCore/libopenssl_x64.a +0 -0
  407. data/libs/nodejs/ext/platform/android/jxCore/libsqlite3_arm.a +0 -0
  408. data/libs/nodejs/ext/platform/android/jxCore/libsqlite3_ia32.a +0 -0
  409. data/libs/nodejs/ext/platform/android/jxCore/libsqlite3_x64.a +0 -0
  410. data/libs/nodejs/ext/platform/android/jxCore/libuv_arm.a +0 -0
  411. data/libs/nodejs/ext/platform/android/jxCore/libuv_ia32.a +0 -0
  412. data/libs/nodejs/ext/platform/android/jxCore/libuv_x64.a +0 -0
  413. data/libs/nodejs/ext/platform/android/jxCore/libv8_base_arm.a +0 -0
  414. data/libs/nodejs/ext/platform/android/jxCore/libv8_base_ia32.a +0 -0
  415. data/libs/nodejs/ext/platform/android/jxCore/libv8_base_x64.a +0 -0
  416. data/libs/nodejs/ext/platform/android/jxCore/libv8_nosnapshot_arm.a +0 -0
  417. data/libs/nodejs/ext/platform/android/jxCore/libv8_nosnapshot_ia32.a +0 -0
  418. data/libs/nodejs/ext/platform/android/jxCore/libv8_nosnapshot_x64.a +0 -0
  419. data/libs/nodejs/ext/platform/iphone/Nodejs.xcodeproj/project.pbxproj +350 -0
  420. data/libs/nodejs/ext/platform/iphone/Nodejs_Prefix.pch +7 -0
  421. data/libs/nodejs/ext/platform/iphone/Rakefile +73 -0
  422. data/libs/nodejs/ext/platform/iphone/jxCore/jx.h +134 -0
  423. data/libs/nodejs/ext/platform/iphone/jxCore/jx_result.h +221 -0
  424. data/libs/nodejs/ext/platform/iphone/jxCore/libcares.a +0 -0
  425. data/libs/nodejs/ext/platform/iphone/jxCore/libchrome_zlib.a +0 -0
  426. data/libs/nodejs/ext/platform/iphone/jxCore/libhttp_parser.a +0 -0
  427. data/libs/nodejs/ext/platform/iphone/jxCore/libjx.a +0 -0
  428. data/libs/nodejs/ext/platform/iphone/jxCore/libmozjs.a +0 -0
  429. data/libs/nodejs/ext/platform/iphone/jxCore/libopenssl.a +0 -0
  430. data/libs/nodejs/ext/platform/iphone/jxCore/libsqlite3.a +0 -0
  431. data/libs/nodejs/ext/platform/iphone/jxCore/libuv.a +0 -0
  432. data/libs/nodejs/ext/shared/jxcore/jx.h +134 -0
  433. data/libs/nodejs/ext/shared/jxcore/jx_result.h +221 -0
  434. data/libs/nodejs/ext/shared/jxcoretau.cpp +454 -0
  435. data/libs/nodejs/ext/shared/jxcoretau.h +20 -0
  436. data/libs/nodejs/ext/shared/nodejs_impl.cpp +106 -0
  437. data/libs/nodejs/nodejs.rb +2 -0
  438. data/libs/openssl-edge.rb +2 -0
  439. data/libs/openssl-edge/ext.yml +4 -0
  440. data/libs/openssl-edge/ext/Rakefile +145 -0
  441. data/libs/openssl-edge/ext/android/Rakefile +107 -0
  442. data/libs/openssl-edge/ext/android/ext_native.files +32 -0
  443. data/libs/openssl-edge/ext/android/extconf.h +91 -0
  444. data/libs/openssl-edge/ext/build +12 -0
  445. data/libs/openssl-edge/ext/build.bat +5 -0
  446. data/libs/openssl-edge/ext/extconf.rb +141 -0
  447. data/libs/openssl-edge/ext/openssl.pro +109 -0
  448. data/libs/openssl-edge/ext/openssl.sln +52 -0
  449. data/libs/openssl-edge/ext/openssl.vcproj +1010 -0
  450. data/libs/openssl-edge/ext/openssl_missing.c +1163 -0
  451. data/libs/openssl-edge/ext/openssl_missing.h +537 -0
  452. data/libs/openssl-edge/ext/ossl.c +1203 -0
  453. data/libs/openssl-edge/ext/ossl.h +242 -0
  454. data/libs/openssl-edge/ext/ossl_asn1.c +2008 -0
  455. data/libs/openssl-edge/ext/ossl_asn1.h +66 -0
  456. data/libs/openssl-edge/ext/ossl_bio.c +118 -0
  457. data/libs/openssl-edge/ext/ossl_bio.h +19 -0
  458. data/libs/openssl-edge/ext/ossl_bn.c +1153 -0
  459. data/libs/openssl-edge/ext/ossl_bn.h +23 -0
  460. data/libs/openssl-edge/ext/ossl_cipher.c +1085 -0
  461. data/libs/openssl-edge/ext/ossl_cipher.h +20 -0
  462. data/libs/openssl-edge/ext/ossl_config.c +89 -0
  463. data/libs/openssl-edge/ext/ossl_config.h +19 -0
  464. data/libs/openssl-edge/ext/ossl_digest.c +453 -0
  465. data/libs/openssl-edge/ext/ossl_digest.h +20 -0
  466. data/libs/openssl-edge/ext/ossl_engine.c +580 -0
  467. data/libs/openssl-edge/ext/ossl_engine.h +19 -0
  468. data/libs/openssl-edge/ext/ossl_hmac.c +398 -0
  469. data/libs/openssl-edge/ext/ossl_hmac.h +18 -0
  470. data/libs/openssl-edge/ext/ossl_ns_spki.c +406 -0
  471. data/libs/openssl-edge/ext/ossl_ns_spki.h +19 -0
  472. data/libs/openssl-edge/ext/ossl_ocsp.c +2013 -0
  473. data/libs/openssl-edge/ext/ossl_ocsp.h +23 -0
  474. data/libs/openssl-edge/ext/ossl_pkcs12.c +261 -0
  475. data/libs/openssl-edge/ext/ossl_pkcs12.h +13 -0
  476. data/libs/openssl-edge/ext/ossl_pkcs5.c +180 -0
  477. data/libs/openssl-edge/ext/ossl_pkcs5.h +6 -0
  478. data/libs/openssl-edge/ext/ossl_pkcs7.c +1157 -0
  479. data/libs/openssl-edge/ext/ossl_pkcs7.h +20 -0
  480. data/libs/openssl-edge/ext/ossl_pkey.c +469 -0
  481. data/libs/openssl-edge/ext/ossl_pkey.h +245 -0
  482. data/libs/openssl-edge/ext/ossl_pkey_dh.c +650 -0
  483. data/libs/openssl-edge/ext/ossl_pkey_dsa.c +672 -0
  484. data/libs/openssl-edge/ext/ossl_pkey_ec.c +1806 -0
  485. data/libs/openssl-edge/ext/ossl_pkey_rsa.c +768 -0
  486. data/libs/openssl-edge/ext/ossl_rand.c +238 -0
  487. data/libs/openssl-edge/ext/ossl_rand.h +18 -0
  488. data/libs/openssl-edge/ext/ossl_ssl.c +2724 -0
  489. data/libs/openssl-edge/ext/ossl_ssl.h +41 -0
  490. data/libs/openssl-edge/ext/ossl_ssl_session.c +352 -0
  491. data/libs/openssl-edge/ext/ossl_version.h +15 -0
  492. data/libs/openssl-edge/ext/ossl_x509.c +186 -0
  493. data/libs/openssl-edge/ext/ossl_x509.h +119 -0
  494. data/libs/openssl-edge/ext/ossl_x509attr.c +328 -0
  495. data/libs/openssl-edge/ext/ossl_x509cert.c +863 -0
  496. data/libs/openssl-edge/ext/ossl_x509crl.c +565 -0
  497. data/libs/openssl-edge/ext/ossl_x509ext.c +480 -0
  498. data/libs/openssl-edge/ext/ossl_x509name.c +547 -0
  499. data/libs/openssl-edge/ext/ossl_x509req.c +492 -0
  500. data/libs/openssl-edge/ext/ossl_x509revoked.c +279 -0
  501. data/libs/openssl-edge/ext/ossl_x509store.c +846 -0
  502. data/libs/openssl-edge/ext/ruby_missing.h +32 -0
  503. data/libs/openssl-edge/openssl-edge.rb +2 -0
  504. data/libs/openssl-edge/openssl.rb +24 -0
  505. data/libs/openssl-edge/openssl/bn.rb +35 -0
  506. data/libs/openssl-edge/openssl/buffering.rb +341 -0
  507. data/libs/openssl-edge/openssl/cipher.rb +65 -0
  508. data/libs/openssl-edge/openssl/digest.rb +61 -0
  509. data/libs/openssl-edge/openssl/ssl-internal.rb +180 -0
  510. data/libs/openssl-edge/openssl/ssl.rb +1 -0
  511. data/libs/openssl-edge/openssl/x509-internal.rb +153 -0
  512. data/libs/openssl-edge/openssl/x509.rb +1 -0
  513. data/libs/openssl.so-edge.rb +2 -0
  514. data/libs/openssl.so-edge/ext.yml +8 -0
  515. data/libs/openssl.so-edge/ext/Rakefile +140 -0
  516. data/libs/openssl.so-edge/ext/android/armeabi/libcrypto.a +0 -0
  517. data/libs/openssl.so-edge/ext/android/armeabi/libssl.a +0 -0
  518. data/libs/openssl.so-edge/ext/android/x86/libcrypto.a +0 -0
  519. data/libs/openssl.so-edge/ext/android/x86/libssl.a +0 -0
  520. data/libs/openssl.so-edge/ext/build +12 -0
  521. data/libs/openssl.so-edge/ext/build.bat +1 -0
  522. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/dh/dh_locl.h +56 -0
  523. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/dsa/dsa_locl.h +76 -0
  524. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/evp/evp_locl.h +66 -0
  525. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/hmac/hmac_lcl.h +33 -0
  526. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/asn1_int.h +94 -0
  527. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/async.h +14 -0
  528. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/bn_conf.h +28 -0
  529. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/bn_dh.h +17 -0
  530. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/bn_int.h +82 -0
  531. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/bn_srp.h +32 -0
  532. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/chacha.h +49 -0
  533. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/cryptlib.h +81 -0
  534. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/cryptlib_int.h +31 -0
  535. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/dso_conf.h +16 -0
  536. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/engine.h +20 -0
  537. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/err_int.h +17 -0
  538. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/evp_int.h +382 -0
  539. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/md32_common.h +383 -0
  540. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/objects.h +12 -0
  541. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/poly1305.h +19 -0
  542. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/rand.h +20 -0
  543. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/include/internal/x509_int.h +267 -0
  544. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/ocsp/ocsp_lcl.h +216 -0
  545. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/rsa/rsa_locl.h +96 -0
  546. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/crypto/x509/x509_lcl.h +142 -0
  547. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/e_os.h +520 -0
  548. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/bio.h +26 -0
  549. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/comp.h +12 -0
  550. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/conf.h +32 -0
  551. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/constant_time_locl.h +185 -0
  552. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/dane.h +103 -0
  553. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/dso.h +216 -0
  554. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/err.h +15 -0
  555. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/numbers.h +68 -0
  556. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/o_dir.h +63 -0
  557. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/o_str.h +17 -0
  558. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/internal/thread_once.h +42 -0
  559. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/__DECC_INCLUDE_EPILOGUE.H +16 -0
  560. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/__DECC_INCLUDE_PROLOGUE.H +20 -0
  561. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/aes.h +92 -0
  562. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/asn1.h +1096 -0
  563. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/asn1_mac.h +10 -0
  564. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/asn1t.h +924 -0
  565. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/async.h +98 -0
  566. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/bio.h +854 -0
  567. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/blowfish.h +61 -0
  568. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/bn.h +575 -0
  569. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/buffer.h +76 -0
  570. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/camellia.h +83 -0
  571. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/cast.h +53 -0
  572. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/cmac.h +41 -0
  573. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/cms.h +512 -0
  574. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/comp.h +72 -0
  575. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/conf.h +216 -0
  576. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/conf_api.h +40 -0
  577. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/crypto.h +463 -0
  578. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ct.h +518 -0
  579. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/des.h +174 -0
  580. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/dh.h +343 -0
  581. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/dsa.h +282 -0
  582. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/dtls1.h +56 -0
  583. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/e_os2.h +311 -0
  584. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ebcdic.h +33 -0
  585. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ec.h +1581 -0
  586. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ecdh.h +10 -0
  587. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ecdsa.h +10 -0
  588. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/engine.h +842 -0
  589. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/err.h +259 -0
  590. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/evp.h +1586 -0
  591. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/hmac.h +49 -0
  592. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/idea.h +64 -0
  593. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/kdf.h +75 -0
  594. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/lhash.h +204 -0
  595. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/md2.h +44 -0
  596. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/md4.h +51 -0
  597. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/md5.h +50 -0
  598. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/mdc2.h +42 -0
  599. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/modes.h +203 -0
  600. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/obj_mac.h +4577 -0
  601. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/objects.h +1097 -0
  602. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ocsp.h +409 -0
  603. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/opensslconf.h +169 -0
  604. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/opensslconf.h.in +141 -0
  605. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/opensslv.h +105 -0
  606. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ossl_typ.h +190 -0
  607. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/pem.h +501 -0
  608. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/pem2.h +20 -0
  609. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/pkcs12.h +282 -0
  610. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/pkcs7.h +404 -0
  611. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/rand.h +89 -0
  612. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/rc2.h +51 -0
  613. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/rc4.h +36 -0
  614. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/rc5.h +63 -0
  615. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ripemd.h +47 -0
  616. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/rsa.h +588 -0
  617. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/safestack.h +164 -0
  618. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/seed.h +98 -0
  619. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/sha.h +119 -0
  620. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/srp.h +131 -0
  621. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/srtp.h +50 -0
  622. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ssl.h +2527 -0
  623. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ssl2.h +24 -0
  624. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ssl3.h +307 -0
  625. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/stack.h +78 -0
  626. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/symhacks.h +52 -0
  627. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/tls1.h +972 -0
  628. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ts.h +643 -0
  629. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/txt_db.h +57 -0
  630. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/ui.h +368 -0
  631. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/whrlpool.h +48 -0
  632. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/x509.h +1123 -0
  633. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/x509_vfy.h +539 -0
  634. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/openssl/x509v3.h +1005 -0
  635. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/ssl/packet_locl.h +555 -0
  636. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/ssl/record/record.h +240 -0
  637. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/ssl/record/record_locl.h +114 -0
  638. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/ssl/ssl_locl.h +2127 -0
  639. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/ssl/statem/statem.h +123 -0
  640. data/libs/openssl.so-edge/ext/openssl-1-1-0-stable/include/ssl/statem/statem_locl.h +124 -0
  641. data/libs/openssl.so-edge/openssl.so.rb +2 -0
  642. data/libs/webkit.rb +2 -0
  643. data/libs/webkit/ext.yml +4 -0
  644. data/libs/webkit/ext/build +12 -0
  645. data/libs/webkit/ext/build.bat +7 -0
  646. data/libs/webkit/ext/wm/Rakefile +61 -0
  647. data/libs/webkit/ext/wm/RhoMsgs.cpp +17 -0
  648. data/libs/webkit/ext/wm/RhoMsgs.h +14 -0
  649. data/libs/webkit/ext/wm/RhoWKBrowserEngine.cpp +736 -0
  650. data/libs/webkit/ext/wm/RhoWKBrowserEngine.h +105 -0
  651. data/libs/webkit/ext/wm/lib/npapi/rhobridge.dll +0 -0
  652. data/libs/webkit/ext/wm/lib/rhoengine_defs.h +80 -0
  653. data/libs/webkit/ext/wm/lib/rhowebkit.dll +0 -0
  654. data/libs/webkit/ext/wm/webkit.sln +36 -0
  655. data/libs/webkit/ext/wm/webkit.suo +0 -0
  656. data/libs/webkit/ext/wm/webkit.vcproj +800 -0
  657. data/libs/webkit/ext/wm/webkit.vsprops +20 -0
  658. data/libs/webkit/webkit.rb +2 -0
  659. data/rho-tau-extensions.gemspec +23 -0
  660. data/version +1 -0
  661. metadata +705 -0
@@ -0,0 +1,238 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ *
5
+ * All rights reserved.
6
+ *
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ VALUE mRandom;
13
+ VALUE eRandomError;
14
+
15
+ /*
16
+ * call-seq:
17
+ * seed(str) -> str
18
+ *
19
+ * ::seed is equivalent to ::add where +entropy+ is length of +str+.
20
+ */
21
+ static VALUE
22
+ ossl_rand_seed(VALUE self, VALUE str)
23
+ {
24
+ StringValue(str);
25
+ RAND_seed(RSTRING_PTR(str), RSTRING_LENINT(str));
26
+
27
+ return str;
28
+ }
29
+
30
+ /*
31
+ * call-seq:
32
+ * add(str, entropy) -> self
33
+ *
34
+ * Mixes the bytes from +str+ into the Pseudo Random Number Generator(PRNG)
35
+ * state.
36
+ *
37
+ * Thus, if the data from +str+ are unpredictable to an adversary, this
38
+ * increases the uncertainty about the state and makes the PRNG output less
39
+ * predictable.
40
+ *
41
+ * The +entropy+ argument is (the lower bound of) an estimate of how much
42
+ * randomness is contained in +str+, measured in bytes.
43
+ *
44
+ * === Example
45
+ *
46
+ * pid = $$
47
+ * now = Time.now
48
+ * ary = [now.to_i, now.nsec, 1000, pid]
49
+ * OpenSSL::Random.add(ary.join, 0.0)
50
+ * OpenSSL::Random.seed(ary.join)
51
+ */
52
+ static VALUE
53
+ ossl_rand_add(VALUE self, VALUE str, VALUE entropy)
54
+ {
55
+ StringValue(str);
56
+ RAND_add(RSTRING_PTR(str), RSTRING_LENINT(str), NUM2DBL(entropy));
57
+
58
+ return self;
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * load_random_file(filename) -> true
64
+ *
65
+ * Reads bytes from +filename+ and adds them to the PRNG.
66
+ */
67
+ static VALUE
68
+ ossl_rand_load_file(VALUE self, VALUE filename)
69
+ {
70
+ rb_check_safe_obj(filename);
71
+
72
+ if(!RAND_load_file(StringValueCStr(filename), -1)) {
73
+ ossl_raise(eRandomError, NULL);
74
+ }
75
+ return Qtrue;
76
+ }
77
+
78
+ /*
79
+ * call-seq:
80
+ * write_random_file(filename) -> true
81
+ *
82
+ * Writes a number of random generated bytes (currently 1024) to +filename+
83
+ * which can be used to initialize the PRNG by calling ::load_random_file in a
84
+ * later session.
85
+ */
86
+ static VALUE
87
+ ossl_rand_write_file(VALUE self, VALUE filename)
88
+ {
89
+ rb_check_safe_obj(filename);
90
+
91
+ if (RAND_write_file(StringValueCStr(filename)) == -1) {
92
+ ossl_raise(eRandomError, NULL);
93
+ }
94
+ return Qtrue;
95
+ }
96
+
97
+ /*
98
+ * call-seq:
99
+ * random_bytes(length) -> string
100
+ *
101
+ * Generates +string+ with +length+ number of cryptographically strong
102
+ * pseudo-random bytes.
103
+ *
104
+ * === Example
105
+ *
106
+ * OpenSSL::Random.random_bytes(12)
107
+ * #=> "..."
108
+ */
109
+ static VALUE
110
+ ossl_rand_bytes(VALUE self, VALUE len)
111
+ {
112
+ VALUE str;
113
+ int n = NUM2INT(len);
114
+ int ret;
115
+
116
+ str = rb_str_new(0, n);
117
+ ret = RAND_bytes((unsigned char *)RSTRING_PTR(str), n);
118
+ if (ret == 0) {
119
+ ossl_raise(eRandomError, "RAND_bytes");
120
+ } else if (ret == -1) {
121
+ ossl_raise(eRandomError, "RAND_bytes is not supported");
122
+ }
123
+
124
+ return str;
125
+ }
126
+
127
+ #if defined(HAVE_RAND_PSEUDO_BYTES)
128
+ /*
129
+ * call-seq:
130
+ * pseudo_bytes(length) -> string
131
+ *
132
+ * Generates +string+ with +length+ number of pseudo-random bytes.
133
+ *
134
+ * Pseudo-random byte sequences generated by ::pseudo_bytes will be unique if
135
+ * they are of sufficient length, but are not necessarily unpredictable.
136
+ *
137
+ * === Example
138
+ *
139
+ * OpenSSL::Random.pseudo_bytes(12)
140
+ * #=> "..."
141
+ */
142
+ static VALUE
143
+ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
144
+ {
145
+ VALUE str;
146
+ int n = NUM2INT(len);
147
+
148
+ str = rb_str_new(0, n);
149
+ if (RAND_pseudo_bytes((unsigned char *)RSTRING_PTR(str), n) < 1) {
150
+ ossl_raise(eRandomError, NULL);
151
+ }
152
+
153
+ return str;
154
+ }
155
+ #endif
156
+
157
+ #ifdef HAVE_RAND_EGD
158
+ /*
159
+ * call-seq:
160
+ * egd(filename) -> true
161
+ *
162
+ * Same as ::egd_bytes but queries 255 bytes by default.
163
+ */
164
+ static VALUE
165
+ ossl_rand_egd(VALUE self, VALUE filename)
166
+ {
167
+ rb_check_safe_obj(filename);
168
+
169
+ if (RAND_egd(StringValueCStr(filename)) == -1) {
170
+ ossl_raise(eRandomError, NULL);
171
+ }
172
+ return Qtrue;
173
+ }
174
+
175
+ /*
176
+ * call-seq:
177
+ * egd_bytes(filename, length) -> true
178
+ *
179
+ * Queries the entropy gathering daemon EGD on socket path given by +filename+.
180
+ *
181
+ * Fetches +length+ number of bytes and uses ::add to seed the OpenSSL built-in
182
+ * PRNG.
183
+ */
184
+ static VALUE
185
+ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
186
+ {
187
+ int n = NUM2INT(len);
188
+
189
+ rb_check_safe_obj(filename);
190
+
191
+ if (RAND_egd_bytes(StringValueCStr(filename), n) == -1) {
192
+ ossl_raise(eRandomError, NULL);
193
+ }
194
+ return Qtrue;
195
+ }
196
+ #endif /* HAVE_RAND_EGD */
197
+
198
+ /*
199
+ * call-seq:
200
+ * status? => true | false
201
+ *
202
+ * Return true if the PRNG has been seeded with enough data, false otherwise.
203
+ */
204
+ static VALUE
205
+ ossl_rand_status(VALUE self)
206
+ {
207
+ return RAND_status() ? Qtrue : Qfalse;
208
+ }
209
+
210
+ /*
211
+ * INIT
212
+ */
213
+ void
214
+ Init_ossl_rand(void)
215
+ {
216
+ #if 0
217
+ mOSSL = rb_define_module("OpenSSL");
218
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
219
+ #endif
220
+
221
+ mRandom = rb_define_module_under(mOSSL, "Random");
222
+
223
+ eRandomError = rb_define_class_under(mRandom, "RandomError", eOSSLError);
224
+
225
+ rb_define_module_function(mRandom, "seed", ossl_rand_seed, 1);
226
+ rb_define_module_function(mRandom, "random_add", ossl_rand_add, 2);
227
+ rb_define_module_function(mRandom, "load_random_file", ossl_rand_load_file, 1);
228
+ rb_define_module_function(mRandom, "write_random_file", ossl_rand_write_file, 1);
229
+ rb_define_module_function(mRandom, "random_bytes", ossl_rand_bytes, 1);
230
+ #if defined(HAVE_RAND_PSEUDO_BYTES)
231
+ rb_define_module_function(mRandom, "pseudo_bytes", ossl_rand_pseudo_bytes, 1);
232
+ #endif
233
+ #ifdef HAVE_RAND_EGD
234
+ rb_define_module_function(mRandom, "egd", ossl_rand_egd, 1);
235
+ rb_define_module_function(mRandom, "egd_bytes", ossl_rand_egd_bytes, 2);
236
+ #endif /* HAVE_RAND_EGD */
237
+ rb_define_module_function(mRandom, "status?", ossl_rand_status, 0);
238
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #if !defined(_OSSL_RAND_H_)
11
+ #define _OSSL_RAND_H_
12
+
13
+ extern VALUE mRandom;
14
+ extern VALUE eRandomError;
15
+
16
+ void Init_ossl_rand(void);
17
+
18
+ #endif /* _OSSL_RAND_H_ */
@@ -0,0 +1,2724 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2000-2002 GOTOU Yuuzou <gotoyuzo@notwork.org>
4
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
+ * Copyright (C) 2001-2007 Technorama Ltd. <oss-ruby@technorama.net>
6
+ * All rights reserved.
7
+ */
8
+ /*
9
+ * This program is licensed under the same licence as Ruby.
10
+ * (See the file 'LICENCE'.)
11
+ */
12
+ #include "ossl.h"
13
+
14
+ #if defined(HAVE_UNISTD_H)
15
+ # include <unistd.h> /* for read(), and write() */
16
+ #endif
17
+
18
+ #define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
19
+
20
+ #ifdef _WIN32
21
+ # define TO_SOCKET(s) _get_osfhandle(s)
22
+ #else
23
+ # define TO_SOCKET(s) (s)
24
+ #endif
25
+
26
+ #define GetSSLCTX(obj, ctx) do { \
27
+ TypedData_Get_Struct((obj), SSL_CTX, &ossl_sslctx_type, (ctx)); \
28
+ } while (0)
29
+
30
+ VALUE mSSL;
31
+ static VALUE mSSLExtConfig;
32
+ static VALUE eSSLError;
33
+ VALUE cSSLContext;
34
+ VALUE cSSLSocket;
35
+
36
+ static VALUE eSSLErrorWaitReadable;
37
+ static VALUE eSSLErrorWaitWritable;
38
+
39
+ static ID ID_callback_state;
40
+ static VALUE sym_exception, sym_wait_readable, sym_wait_writable;
41
+
42
+ static ID id_i_cert_store, id_i_ca_file, id_i_ca_path, id_i_verify_mode,
43
+ id_i_verify_depth, id_i_verify_callback, id_i_client_ca,
44
+ id_i_renegotiation_cb, id_i_cert, id_i_key, id_i_extra_chain_cert,
45
+ id_i_client_cert_cb, id_i_tmp_ecdh_callback, id_i_timeout,
46
+ id_i_session_id_context, id_i_session_get_cb, id_i_session_new_cb,
47
+ id_i_session_remove_cb, id_i_npn_select_cb, id_i_npn_protocols,
48
+ id_i_alpn_select_cb, id_i_alpn_protocols, id_i_servername_cb,
49
+ id_i_verify_hostname;
50
+ static ID id_i_io, id_i_context, id_i_hostname;
51
+
52
+ /*
53
+ * SSLContext class
54
+ */
55
+ static const struct {
56
+ const char *name;
57
+ SSL_METHOD *(*func)(void); /* FIXME: constify when dropping 0.9.8 */
58
+ int version;
59
+ } ossl_ssl_method_tab[] = {
60
+ #if defined(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)
61
+ #define OSSL_SSL_METHOD_ENTRY(name, version) \
62
+ { #name, (SSL_METHOD *(*)(void))TLS_method, version }, \
63
+ { #name"_server", (SSL_METHOD *(*)(void))TLS_server_method, version }, \
64
+ { #name"_client", (SSL_METHOD *(*)(void))TLS_client_method, version }
65
+ #else
66
+ #define OSSL_SSL_METHOD_ENTRY(name, version) \
67
+ { #name, (SSL_METHOD *(*)(void))name##_method, version }, \
68
+ { #name"_server", (SSL_METHOD *(*)(void))name##_server_method, version }, \
69
+ { #name"_client", (SSL_METHOD *(*)(void))name##_client_method, version }
70
+ #endif
71
+ #if defined(HAVE_SSLV2_METHOD)
72
+ OSSL_SSL_METHOD_ENTRY(SSLv2, SSL2_VERSION),
73
+ #endif
74
+ #if defined(HAVE_SSLV3_METHOD)
75
+ OSSL_SSL_METHOD_ENTRY(SSLv3, SSL3_VERSION),
76
+ #endif
77
+ OSSL_SSL_METHOD_ENTRY(TLSv1, TLS1_VERSION),
78
+ #if defined(HAVE_TLSV1_1_METHOD)
79
+ OSSL_SSL_METHOD_ENTRY(TLSv1_1, TLS1_1_VERSION),
80
+ #endif
81
+ #if defined(HAVE_TLSV1_2_METHOD)
82
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2, TLS1_2_VERSION),
83
+ #endif
84
+ OSSL_SSL_METHOD_ENTRY(SSLv23, 0),
85
+ #undef OSSL_SSL_METHOD_ENTRY
86
+ };
87
+
88
+ static int ossl_ssl_ex_vcb_idx;
89
+ static int ossl_ssl_ex_store_p;
90
+ static int ossl_ssl_ex_ptr_idx;
91
+
92
+ static void
93
+ ossl_sslctx_free(void *ptr)
94
+ {
95
+ SSL_CTX *ctx = ptr;
96
+ #if !defined(HAVE_X509_STORE_UP_REF)
97
+ if(ctx && SSL_CTX_get_ex_data(ctx, ossl_ssl_ex_store_p)== (void*)1)
98
+ ctx->cert_store = NULL;
99
+ #endif
100
+ SSL_CTX_free(ctx);
101
+ }
102
+
103
+ static const rb_data_type_t ossl_sslctx_type = {
104
+ "OpenSSL/SSL/CTX",
105
+ {
106
+ 0, ossl_sslctx_free,
107
+ },
108
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
109
+ };
110
+
111
+ static VALUE
112
+ ossl_sslctx_s_alloc(VALUE klass)
113
+ {
114
+ SSL_CTX *ctx;
115
+ long mode = SSL_MODE_ENABLE_PARTIAL_WRITE |
116
+ SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER;
117
+ VALUE obj;
118
+
119
+ #ifdef SSL_MODE_RELEASE_BUFFERS
120
+ mode |= SSL_MODE_RELEASE_BUFFERS;
121
+ #endif
122
+
123
+ obj = TypedData_Wrap_Struct(klass, &ossl_sslctx_type, 0);
124
+ ctx = SSL_CTX_new(SSLv23_method());
125
+ if (!ctx) {
126
+ ossl_raise(eSSLError, "SSL_CTX_new");
127
+ }
128
+ SSL_CTX_set_mode(ctx, mode);
129
+ RTYPEDDATA_DATA(obj) = ctx;
130
+ SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_ptr_idx, (void*)obj);
131
+
132
+ #if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
133
+ /* We use SSL_CTX_set1_curves_list() to specify the curve used in ECDH. It
134
+ * allows to specify multiple curve names and OpenSSL will select
135
+ * automatically from them. In OpenSSL 1.0.2, the automatic selection has to
136
+ * be enabled explicitly. But OpenSSL 1.1.0 removed the knob and it is
137
+ * always enabled. To uniform the behavior, we enable the automatic
138
+ * selection also in 1.0.2. Users can still disable ECDH by removing ECDH
139
+ * cipher suites by SSLContext#ciphers=. */
140
+ if (!SSL_CTX_set_ecdh_auto(ctx, 1))
141
+ ossl_raise(eSSLError, "SSL_CTX_set_ecdh_auto");
142
+ #endif
143
+
144
+ return obj;
145
+ }
146
+
147
+ /*
148
+ * call-seq:
149
+ * ctx.ssl_version = :TLSv1
150
+ * ctx.ssl_version = "SSLv23_client"
151
+ *
152
+ * Sets the SSL/TLS protocol version for the context. This forces connections to
153
+ * use only the specified protocol version.
154
+ *
155
+ * You can get a list of valid versions with OpenSSL::SSL::SSLContext::METHODS
156
+ */
157
+ static VALUE
158
+ ossl_sslctx_set_ssl_version(VALUE self, VALUE ssl_method)
159
+ {
160
+ SSL_CTX *ctx;
161
+ const char *s;
162
+ VALUE m = ssl_method;
163
+ int i;
164
+
165
+ GetSSLCTX(self, ctx);
166
+ if (RB_TYPE_P(ssl_method, T_SYMBOL))
167
+ //TAU
168
+ //m = rb_sym2str(ssl_method);
169
+ //s = StringValueCStr(m);
170
+ s = rb_id2name(SYM2ID(ssl_method));
171
+
172
+ for (i = 0; i < numberof(ossl_ssl_method_tab); i++) {
173
+ if (strcmp(ossl_ssl_method_tab[i].name, s) == 0) {
174
+ #if defined(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)
175
+ int version = ossl_ssl_method_tab[i].version;
176
+ #endif
177
+ SSL_METHOD *method = ossl_ssl_method_tab[i].func();
178
+
179
+ if (SSL_CTX_set_ssl_version(ctx, method) != 1)
180
+ ossl_raise(eSSLError, "SSL_CTX_set_ssl_version");
181
+
182
+ #if defined(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)
183
+ if (!SSL_CTX_set_min_proto_version(ctx, version))
184
+ ossl_raise(eSSLError, "SSL_CTX_set_min_proto_version");
185
+ if (!SSL_CTX_set_max_proto_version(ctx, version))
186
+ ossl_raise(eSSLError, "SSL_CTX_set_max_proto_version");
187
+ #endif
188
+ return ssl_method;
189
+ }
190
+ }
191
+
192
+ ossl_raise(rb_eArgError, "unknown SSL method `%"PRIsVALUE"'.", m);
193
+ }
194
+
195
+ static VALUE
196
+ ossl_call_client_cert_cb(VALUE obj)
197
+ {
198
+ VALUE ctx_obj, cb, ary, cert, key;
199
+
200
+ ctx_obj = rb_attr_get(obj, id_i_context);
201
+ cb = rb_attr_get(ctx_obj, id_i_client_cert_cb);
202
+ if (NIL_P(cb))
203
+ return Qnil;
204
+
205
+ ary = rb_funcall(cb, rb_intern("call"), 1, obj);
206
+ Check_Type(ary, T_ARRAY);
207
+ GetX509CertPtr(cert = rb_ary_entry(ary, 0));
208
+ GetPrivPKeyPtr(key = rb_ary_entry(ary, 1));
209
+
210
+ return rb_ary_new3(2, cert, key);
211
+ }
212
+
213
+ static int
214
+ ossl_client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
215
+ {
216
+ VALUE obj, ret;
217
+
218
+ obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
219
+ ret = rb_protect(ossl_call_client_cert_cb, obj, NULL);
220
+ if (NIL_P(ret))
221
+ return 0;
222
+
223
+ *x509 = DupX509CertPtr(RARRAY_AREF(ret, 0));
224
+ *pkey = DupPKeyPtr(RARRAY_AREF(ret, 1));
225
+
226
+ return 1;
227
+ }
228
+
229
+ #if !defined(OPENSSL_NO_DH)
230
+ static VALUE
231
+ ossl_call_tmp_dh_callback(VALUE args)
232
+ {
233
+ VALUE cb, dh;
234
+ EVP_PKEY *pkey;
235
+
236
+ cb = rb_funcall(rb_ary_entry(args, 0), rb_intern("tmp_dh_callback"), 0);
237
+
238
+ if (NIL_P(cb)) return Qfalse;
239
+ dh = rb_apply(cb, rb_intern("call"), args);
240
+ pkey = GetPKeyPtr(dh);
241
+ if (EVP_PKEY_base_id(pkey) != EVP_PKEY_DH) return Qfalse;
242
+
243
+ return dh;
244
+ }
245
+
246
+ static DH*
247
+ ossl_tmp_dh_callback(SSL *ssl, int is_export, int keylength)
248
+ {
249
+ VALUE args, dh, rb_ssl;
250
+
251
+ rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
252
+
253
+ args = rb_ary_new_from_args(3, rb_ssl, INT2NUM(is_export), INT2NUM(keylength));
254
+
255
+ dh = rb_protect(ossl_call_tmp_dh_callback, args, NULL);
256
+ if (!RTEST(dh)) return NULL;
257
+
258
+ return EVP_PKEY_get0_DH(GetPKeyPtr(dh));
259
+ }
260
+ #endif /* OPENSSL_NO_DH */
261
+
262
+ #if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
263
+ static VALUE
264
+ ossl_call_tmp_ecdh_callback(VALUE args)
265
+ {
266
+ VALUE cb, ecdh;
267
+ EVP_PKEY *pkey;
268
+
269
+ cb = rb_funcall(rb_ary_entry(args, 0), rb_intern("tmp_ecdh_callback"), 0);
270
+
271
+ if (NIL_P(cb)) return Qfalse;
272
+ ecdh = rb_apply(cb, rb_intern("call"), args);
273
+ pkey = GetPKeyPtr(ecdh);
274
+ if (EVP_PKEY_base_id(pkey) != EVP_PKEY_EC) return Qfalse;
275
+
276
+ return ecdh;
277
+ }
278
+
279
+ static EC_KEY*
280
+ ossl_tmp_ecdh_callback(SSL *ssl, int is_export, int keylength)
281
+ {
282
+ VALUE args, ecdh, rb_ssl;
283
+
284
+ rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
285
+
286
+ args = rb_ary_new_from_args(3, rb_ssl, INT2NUM(is_export), INT2NUM(keylength));
287
+
288
+ ecdh = rb_protect(ossl_call_tmp_ecdh_callback, args, NULL);
289
+ if (!RTEST(ecdh)) return NULL;
290
+
291
+ return EVP_PKEY_get0_EC_KEY(GetPKeyPtr(ecdh));
292
+ }
293
+ #endif
294
+
295
+ static VALUE
296
+ call_verify_certificate_identity(VALUE ctx_v)
297
+ {
298
+ X509_STORE_CTX *ctx = (X509_STORE_CTX *)ctx_v;
299
+ SSL *ssl;
300
+ VALUE ssl_obj, hostname, cert_obj;
301
+
302
+ ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
303
+ ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
304
+ hostname = rb_attr_get(ssl_obj, id_i_hostname);
305
+
306
+ if (!RTEST(hostname)) {
307
+ rb_warning("verify_hostname requires hostname to be set");
308
+ return Qtrue;
309
+ }
310
+
311
+ cert_obj = ossl_x509_new(X509_STORE_CTX_get_current_cert(ctx));
312
+ return rb_funcall(mSSL, rb_intern("verify_certificate_identity"), 2,
313
+ cert_obj, hostname);
314
+ }
315
+
316
+ static int
317
+ ossl_ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
318
+ {
319
+ VALUE cb, ssl_obj, sslctx_obj, verify_hostname, ret;
320
+ SSL *ssl;
321
+ int status;
322
+
323
+ ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
324
+ cb = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_vcb_idx);
325
+ ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
326
+ sslctx_obj = rb_attr_get(ssl_obj, id_i_context);
327
+ verify_hostname = rb_attr_get(sslctx_obj, id_i_verify_hostname);
328
+
329
+ if (preverify_ok && RTEST(verify_hostname) && !SSL_is_server(ssl) &&
330
+ !X509_STORE_CTX_get_error_depth(ctx)) {
331
+ ret = rb_protect(call_verify_certificate_identity, (VALUE)ctx, &status);
332
+ if (status) {
333
+ rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(status));
334
+ return 0;
335
+ }
336
+ preverify_ok = ret == Qtrue;
337
+ }
338
+
339
+ return ossl_verify_cb_call(cb, preverify_ok, ctx);
340
+ }
341
+
342
+ static VALUE
343
+ ossl_call_session_get_cb(VALUE ary)
344
+ {
345
+ VALUE ssl_obj, cb;
346
+
347
+ Check_Type(ary, T_ARRAY);
348
+ ssl_obj = rb_ary_entry(ary, 0);
349
+
350
+ cb = rb_funcall(ssl_obj, rb_intern("session_get_cb"), 0);
351
+ if (NIL_P(cb)) return Qnil;
352
+
353
+ return rb_funcall(cb, rb_intern("call"), 1, ary);
354
+ }
355
+
356
+ /* this method is currently only called for servers (in OpenSSL <= 0.9.8e) */
357
+ static SSL_SESSION *
358
+ #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
359
+ ossl_sslctx_session_get_cb(SSL *ssl, const unsigned char *buf, int len, int *copy)
360
+ #else
361
+ ossl_sslctx_session_get_cb(SSL *ssl, unsigned char *buf, int len, int *copy)
362
+ #endif
363
+ {
364
+ VALUE ary, ssl_obj, ret_obj;
365
+ SSL_SESSION *sess;
366
+ void *ptr;
367
+ int state = 0;
368
+
369
+ OSSL_Debug("SSL SESSION get callback entered");
370
+ if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
371
+ return NULL;
372
+ ssl_obj = (VALUE)ptr;
373
+ ary = rb_ary_new2(2);
374
+ rb_ary_push(ary, ssl_obj);
375
+ rb_ary_push(ary, rb_str_new((const char *)buf, len));
376
+
377
+ ret_obj = rb_protect(ossl_call_session_get_cb, ary, &state);
378
+ if (state) {
379
+ rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
380
+ return NULL;
381
+ }
382
+ if (!rb_obj_is_instance_of(ret_obj, cSSLSession))
383
+ return NULL;
384
+
385
+ SafeGetSSLSession(ret_obj, sess);
386
+ *copy = 1;
387
+
388
+ return sess;
389
+ }
390
+
391
+ static VALUE
392
+ ossl_call_session_new_cb(VALUE ary)
393
+ {
394
+ VALUE ssl_obj, cb;
395
+
396
+ Check_Type(ary, T_ARRAY);
397
+ ssl_obj = rb_ary_entry(ary, 0);
398
+
399
+ cb = rb_funcall(ssl_obj, rb_intern("session_new_cb"), 0);
400
+ if (NIL_P(cb)) return Qnil;
401
+
402
+ return rb_funcall(cb, rb_intern("call"), 1, ary);
403
+ }
404
+
405
+ /* return 1 normal. return 0 removes the session */
406
+ static int
407
+ ossl_sslctx_session_new_cb(SSL *ssl, SSL_SESSION *sess)
408
+ {
409
+ VALUE ary, ssl_obj, sess_obj;
410
+ void *ptr;
411
+ int state = 0;
412
+
413
+ OSSL_Debug("SSL SESSION new callback entered");
414
+
415
+ if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
416
+ return 1;
417
+ ssl_obj = (VALUE)ptr;
418
+ sess_obj = rb_obj_alloc(cSSLSession);
419
+ SSL_SESSION_up_ref(sess);
420
+ DATA_PTR(sess_obj) = sess;
421
+
422
+ ary = rb_ary_new2(2);
423
+ rb_ary_push(ary, ssl_obj);
424
+ rb_ary_push(ary, sess_obj);
425
+
426
+ rb_protect(ossl_call_session_new_cb, ary, &state);
427
+ if (state) {
428
+ rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
429
+ }
430
+
431
+ /*
432
+ * return 0 which means to OpenSSL that the session is still
433
+ * valid (since we created Ruby Session object) and was not freed by us
434
+ * with SSL_SESSION_free(). Call SSLContext#remove_session(sess) in
435
+ * session_get_cb block if you don't want OpenSSL to cache the session
436
+ * internally.
437
+ */
438
+ return 0;
439
+ }
440
+
441
+ static VALUE
442
+ ossl_call_session_remove_cb(VALUE ary)
443
+ {
444
+ VALUE sslctx_obj, cb;
445
+
446
+ Check_Type(ary, T_ARRAY);
447
+ sslctx_obj = rb_ary_entry(ary, 0);
448
+
449
+ cb = rb_attr_get(sslctx_obj, id_i_session_remove_cb);
450
+ if (NIL_P(cb)) return Qnil;
451
+
452
+ return rb_funcall(cb, rb_intern("call"), 1, ary);
453
+ }
454
+
455
+ static void
456
+ ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
457
+ {
458
+ VALUE ary, sslctx_obj, sess_obj;
459
+ void *ptr;
460
+ int state = 0;
461
+
462
+ OSSL_Debug("SSL SESSION remove callback entered");
463
+
464
+ if ((ptr = SSL_CTX_get_ex_data(ctx, ossl_ssl_ex_ptr_idx)) == NULL)
465
+ return;
466
+ sslctx_obj = (VALUE)ptr;
467
+ sess_obj = rb_obj_alloc(cSSLSession);
468
+ SSL_SESSION_up_ref(sess);
469
+ DATA_PTR(sess_obj) = sess;
470
+
471
+ ary = rb_ary_new2(2);
472
+ rb_ary_push(ary, sslctx_obj);
473
+ rb_ary_push(ary, sess_obj);
474
+
475
+ rb_protect(ossl_call_session_remove_cb, ary, &state);
476
+ if (state) {
477
+ /*
478
+ the SSL_CTX is frozen, nowhere to save state.
479
+ there is no common accessor method to check it either.
480
+ rb_ivar_set(sslctx_obj, ID_callback_state, INT2NUM(state));
481
+ */
482
+ }
483
+ }
484
+
485
+ static VALUE
486
+ ossl_sslctx_add_extra_chain_cert_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
487
+ {
488
+ X509 *x509;
489
+ SSL_CTX *ctx;
490
+
491
+ GetSSLCTX(arg, ctx);
492
+ x509 = DupX509CertPtr(i);
493
+ if(!SSL_CTX_add_extra_chain_cert(ctx, x509)){
494
+ ossl_raise(eSSLError, NULL);
495
+ }
496
+
497
+ return i;
498
+ }
499
+
500
+ static VALUE ossl_sslctx_setup(VALUE self);
501
+
502
+ #ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
503
+ static VALUE
504
+ ossl_call_servername_cb(VALUE ary)
505
+ {
506
+ VALUE ssl_obj, sslctx_obj, cb, ret_obj;
507
+
508
+ Check_Type(ary, T_ARRAY);
509
+ ssl_obj = rb_ary_entry(ary, 0);
510
+
511
+ sslctx_obj = rb_attr_get(ssl_obj, id_i_context);
512
+ cb = rb_attr_get(sslctx_obj, id_i_servername_cb);
513
+ if (NIL_P(cb)) return Qnil;
514
+
515
+ ret_obj = rb_funcall(cb, rb_intern("call"), 1, ary);
516
+ if (rb_obj_is_kind_of(ret_obj, cSSLContext)) {
517
+ SSL *ssl;
518
+ SSL_CTX *ctx2;
519
+
520
+ ossl_sslctx_setup(ret_obj);
521
+ GetSSL(ssl_obj, ssl);
522
+ GetSSLCTX(ret_obj, ctx2);
523
+ SSL_set_SSL_CTX(ssl, ctx2);
524
+ rb_ivar_set(ssl_obj, id_i_context, ret_obj);
525
+ } else if (!NIL_P(ret_obj)) {
526
+ ossl_raise(rb_eArgError, "servername_cb must return an "
527
+ "OpenSSL::SSL::SSLContext object or nil");
528
+ }
529
+
530
+ return ret_obj;
531
+ }
532
+
533
+ static int
534
+ ssl_servername_cb(SSL *ssl, int *ad, void *arg)
535
+ {
536
+ VALUE ary, ssl_obj;
537
+ void *ptr;
538
+ int state = 0;
539
+ const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
540
+
541
+ if (!servername)
542
+ return SSL_TLSEXT_ERR_OK;
543
+
544
+ if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
545
+ return SSL_TLSEXT_ERR_ALERT_FATAL;
546
+ ssl_obj = (VALUE)ptr;
547
+ ary = rb_ary_new2(2);
548
+ rb_ary_push(ary, ssl_obj);
549
+ rb_ary_push(ary, rb_str_new2(servername));
550
+
551
+ rb_protect(ossl_call_servername_cb, ary, &state);
552
+ if (state) {
553
+ rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
554
+ return SSL_TLSEXT_ERR_ALERT_FATAL;
555
+ }
556
+
557
+ return SSL_TLSEXT_ERR_OK;
558
+ }
559
+ #endif
560
+
561
+ static void
562
+ ssl_renegotiation_cb(const SSL *ssl)
563
+ {
564
+ VALUE ssl_obj, sslctx_obj, cb;
565
+ void *ptr;
566
+
567
+ if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
568
+ ossl_raise(eSSLError, "SSL object could not be retrieved");
569
+ ssl_obj = (VALUE)ptr;
570
+
571
+ sslctx_obj = rb_attr_get(ssl_obj, id_i_context);
572
+ cb = rb_attr_get(sslctx_obj, id_i_renegotiation_cb);
573
+ if (NIL_P(cb)) return;
574
+
575
+ (void) rb_funcall(cb, rb_intern("call"), 1, ssl_obj);
576
+ }
577
+
578
+ #if defined(HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB) || \
579
+ defined(HAVE_SSL_CTX_SET_ALPN_SELECT_CB)
580
+ static VALUE
581
+ ssl_npn_encode_protocol_i(VALUE cur, VALUE encoded)
582
+ {
583
+ int len = RSTRING_LENINT(cur);
584
+ char len_byte;
585
+ if (len < 1 || len > 255)
586
+ ossl_raise(eSSLError, "Advertised protocol must have length 1..255");
587
+ /* Encode the length byte */
588
+ len_byte = len;
589
+ rb_str_buf_cat(encoded, &len_byte, 1);
590
+ rb_str_buf_cat(encoded, RSTRING_PTR(cur), len);
591
+ return Qnil;
592
+ }
593
+
594
+ static VALUE
595
+ ssl_encode_npn_protocols(VALUE protocols)
596
+ {
597
+ VALUE encoded = rb_str_new(NULL, 0);
598
+ rb_iterate(rb_each, protocols, ssl_npn_encode_protocol_i, encoded);
599
+ return encoded;
600
+ }
601
+
602
+ struct npn_select_cb_common_args {
603
+ VALUE cb;
604
+ const unsigned char *in;
605
+ unsigned inlen;
606
+ };
607
+
608
+ static VALUE
609
+ npn_select_cb_common_i(VALUE tmp)
610
+ {
611
+ struct npn_select_cb_common_args *args = (void *)tmp;
612
+ const unsigned char *in = args->in, *in_end = in + args->inlen;
613
+ unsigned char l;
614
+ long len;
615
+ VALUE selected, protocols = rb_ary_new();
616
+
617
+ /* assume OpenSSL verifies this format */
618
+ /* The format is len_1|proto_1|...|len_n|proto_n */
619
+ while (in < in_end) {
620
+ l = *in++;
621
+ rb_ary_push(protocols, rb_str_new((const char *)in, l));
622
+ in += l;
623
+ }
624
+
625
+ selected = rb_funcall(args->cb, rb_intern("call"), 1, protocols);
626
+ StringValue(selected);
627
+ len = RSTRING_LEN(selected);
628
+ if (len < 1 || len >= 256) {
629
+ ossl_raise(eSSLError, "Selected protocol name must have length 1..255");
630
+ }
631
+
632
+ return selected;
633
+ }
634
+
635
+ static int
636
+ ssl_npn_select_cb_common(SSL *ssl, VALUE cb, const unsigned char **out,
637
+ unsigned char *outlen, const unsigned char *in,
638
+ unsigned int inlen)
639
+ {
640
+ VALUE selected;
641
+ int status;
642
+ struct npn_select_cb_common_args args = { cb, in, inlen };
643
+
644
+ selected = rb_protect(npn_select_cb_common_i, (VALUE)&args, &status);
645
+ if (status) {
646
+ VALUE ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
647
+
648
+ rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(status));
649
+ return SSL_TLSEXT_ERR_ALERT_FATAL;
650
+ }
651
+
652
+ *out = (unsigned char *)RSTRING_PTR(selected);
653
+ *outlen = (unsigned char)RSTRING_LEN(selected);
654
+
655
+ return SSL_TLSEXT_ERR_OK;
656
+ }
657
+ #endif
658
+
659
+ #ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
660
+ static int
661
+ ssl_npn_advertise_cb(SSL *ssl, const unsigned char **out, unsigned int *outlen,
662
+ void *arg)
663
+ {
664
+ VALUE protocols = (VALUE)arg;
665
+
666
+ *out = (const unsigned char *) RSTRING_PTR(protocols);
667
+ *outlen = RSTRING_LENINT(protocols);
668
+
669
+ return SSL_TLSEXT_ERR_OK;
670
+ }
671
+
672
+ static int
673
+ ssl_npn_select_cb(SSL *ssl, unsigned char **out, unsigned char *outlen,
674
+ const unsigned char *in, unsigned int inlen, void *arg)
675
+ {
676
+ VALUE sslctx_obj, cb;
677
+
678
+ sslctx_obj = (VALUE) arg;
679
+ cb = rb_attr_get(sslctx_obj, id_i_npn_select_cb);
680
+
681
+ return ssl_npn_select_cb_common(ssl, cb, (const unsigned char **)out,
682
+ outlen, in, inlen);
683
+ }
684
+ #endif
685
+
686
+ #ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
687
+ static int
688
+ ssl_alpn_select_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen,
689
+ const unsigned char *in, unsigned int inlen, void *arg)
690
+ {
691
+ VALUE sslctx_obj, cb;
692
+
693
+ sslctx_obj = (VALUE) arg;
694
+ cb = rb_attr_get(sslctx_obj, id_i_alpn_select_cb);
695
+
696
+ return ssl_npn_select_cb_common(ssl, cb, out, outlen, in, inlen);
697
+ }
698
+ #endif
699
+
700
+ /* This function may serve as the entry point to support further callbacks. */
701
+ static void
702
+ ssl_info_cb(const SSL *ssl, int where, int val)
703
+ {
704
+ int is_server = SSL_is_server((SSL *)ssl);
705
+
706
+ if (is_server && where & SSL_CB_HANDSHAKE_START) {
707
+ ssl_renegotiation_cb(ssl);
708
+ }
709
+ }
710
+
711
+ /*
712
+ * Gets various OpenSSL options.
713
+ */
714
+ static VALUE
715
+ ossl_sslctx_get_options(VALUE self)
716
+ {
717
+ SSL_CTX *ctx;
718
+ GetSSLCTX(self, ctx);
719
+ return LONG2NUM(SSL_CTX_get_options(ctx));
720
+ }
721
+
722
+ /*
723
+ * Sets various OpenSSL options.
724
+ */
725
+ static VALUE
726
+ ossl_sslctx_set_options(VALUE self, VALUE options)
727
+ {
728
+ SSL_CTX *ctx;
729
+
730
+ rb_check_frozen(self);
731
+ GetSSLCTX(self, ctx);
732
+
733
+ SSL_CTX_clear_options(ctx, SSL_CTX_get_options(ctx));
734
+
735
+ if (NIL_P(options)) {
736
+ SSL_CTX_set_options(ctx, SSL_OP_ALL);
737
+ } else {
738
+ SSL_CTX_set_options(ctx, NUM2LONG(options));
739
+ }
740
+
741
+ return self;
742
+ }
743
+
744
+ /*
745
+ * call-seq:
746
+ * ctx.setup => Qtrue # first time
747
+ * ctx.setup => nil # thereafter
748
+ *
749
+ * This method is called automatically when a new SSLSocket is created.
750
+ * However, it is not thread-safe and must be called before creating
751
+ * SSLSocket objects in a multi-threaded program.
752
+ */
753
+ static VALUE
754
+ ossl_sslctx_setup(VALUE self)
755
+ {
756
+ SSL_CTX *ctx;
757
+ X509 *cert = NULL, *client_ca = NULL;
758
+ EVP_PKEY *key = NULL;
759
+ char *ca_path = NULL, *ca_file = NULL;
760
+ int verify_mode;
761
+ long i;
762
+ VALUE val;
763
+
764
+ if(OBJ_FROZEN(self)) return Qnil;
765
+ GetSSLCTX(self, ctx);
766
+
767
+ #if !defined(OPENSSL_NO_DH)
768
+ SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
769
+ #endif
770
+
771
+ #if !defined(OPENSSL_NO_EC)
772
+ /* We added SSLContext#tmp_ecdh_callback= in Ruby 2.3.0,
773
+ * but SSL_CTX_set_tmp_ecdh_callback() was removed in OpenSSL 1.1.0. */
774
+ if (RTEST(rb_attr_get(self, id_i_tmp_ecdh_callback))) {
775
+ # if defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
776
+ rb_warn("#tmp_ecdh_callback= is deprecated; use #ecdh_curves= instead");
777
+ SSL_CTX_set_tmp_ecdh_callback(ctx, ossl_tmp_ecdh_callback);
778
+ # if defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
779
+ /* tmp_ecdh_callback and ecdh_auto conflict; OpenSSL ignores
780
+ * tmp_ecdh_callback. So disable ecdh_auto. */
781
+ if (!SSL_CTX_set_ecdh_auto(ctx, 0))
782
+ ossl_raise(eSSLError, "SSL_CTX_set_ecdh_auto");
783
+ # endif
784
+ # else
785
+ ossl_raise(eSSLError, "OpenSSL does not support tmp_ecdh_callback; "
786
+ "use #ecdh_curves= instead");
787
+ # endif
788
+ }
789
+ #endif /* OPENSSL_NO_EC */
790
+
791
+ val = rb_attr_get(self, id_i_cert_store);
792
+ if (!NIL_P(val)) {
793
+ X509_STORE *store = GetX509StorePtr(val); /* NO NEED TO DUP */
794
+ SSL_CTX_set_cert_store(ctx, store);
795
+ #if !defined(HAVE_X509_STORE_UP_REF)
796
+ /*
797
+ * WORKAROUND:
798
+ * X509_STORE can count references, but
799
+ * X509_STORE_free() doesn't care it.
800
+ * So we won't increment it but mark it by ex_data.
801
+ */
802
+ SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_store_p, (void *)1);
803
+ #else /* Fixed in OpenSSL 1.0.2; bff9ce4db38b (master), 5b4b9ce976fc (1.0.2) */
804
+ X509_STORE_up_ref(store);
805
+ #endif
806
+ }
807
+
808
+ val = rb_attr_get(self, id_i_extra_chain_cert);
809
+ if(!NIL_P(val)){
810
+ rb_block_call(val, rb_intern("each"), 0, 0, ossl_sslctx_add_extra_chain_cert_i, self);
811
+ }
812
+
813
+ /* private key may be bundled in certificate file. */
814
+ val = rb_attr_get(self, id_i_cert);
815
+ cert = NIL_P(val) ? NULL : GetX509CertPtr(val); /* NO DUP NEEDED */
816
+ val = rb_attr_get(self, id_i_key);
817
+ key = NIL_P(val) ? NULL : GetPrivPKeyPtr(val); /* NO DUP NEEDED */
818
+ if (cert && key) {
819
+ if (!SSL_CTX_use_certificate(ctx, cert)) {
820
+ /* Adds a ref => Safe to FREE */
821
+ ossl_raise(eSSLError, "SSL_CTX_use_certificate");
822
+ }
823
+ if (!SSL_CTX_use_PrivateKey(ctx, key)) {
824
+ /* Adds a ref => Safe to FREE */
825
+ ossl_raise(eSSLError, "SSL_CTX_use_PrivateKey");
826
+ }
827
+ if (!SSL_CTX_check_private_key(ctx)) {
828
+ ossl_raise(eSSLError, "SSL_CTX_check_private_key");
829
+ }
830
+ }
831
+
832
+ val = rb_attr_get(self, id_i_client_ca);
833
+ if(!NIL_P(val)){
834
+ if (RB_TYPE_P(val, T_ARRAY)) {
835
+ for(i = 0; i < RARRAY_LEN(val); i++){
836
+ client_ca = GetX509CertPtr(RARRAY_AREF(val, i));
837
+ if (!SSL_CTX_add_client_CA(ctx, client_ca)){
838
+ /* Copies X509_NAME => FREE it. */
839
+ ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
840
+ }
841
+ }
842
+ }
843
+ else{
844
+ client_ca = GetX509CertPtr(val); /* NO DUP NEEDED. */
845
+ if (!SSL_CTX_add_client_CA(ctx, client_ca)){
846
+ /* Copies X509_NAME => FREE it. */
847
+ ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
848
+ }
849
+ }
850
+ }
851
+
852
+ val = rb_attr_get(self, id_i_ca_file);
853
+ ca_file = NIL_P(val) ? NULL : StringValueCStr(val);
854
+ val = rb_attr_get(self, id_i_ca_path);
855
+ ca_path = NIL_P(val) ? NULL : StringValueCStr(val);
856
+ if(ca_file || ca_path){
857
+ if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
858
+ rb_warning("can't set verify locations");
859
+ }
860
+
861
+ val = rb_attr_get(self, id_i_verify_mode);
862
+ verify_mode = NIL_P(val) ? SSL_VERIFY_NONE : NUM2INT(val);
863
+ SSL_CTX_set_verify(ctx, verify_mode, ossl_ssl_verify_callback);
864
+ if (RTEST(rb_attr_get(self, id_i_client_cert_cb)))
865
+ SSL_CTX_set_client_cert_cb(ctx, ossl_client_cert_cb);
866
+
867
+ val = rb_attr_get(self, id_i_timeout);
868
+ if(!NIL_P(val)) SSL_CTX_set_timeout(ctx, NUM2LONG(val));
869
+
870
+ val = rb_attr_get(self, id_i_verify_depth);
871
+ if(!NIL_P(val)) SSL_CTX_set_verify_depth(ctx, NUM2INT(val));
872
+
873
+ #ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
874
+ val = rb_attr_get(self, id_i_npn_protocols);
875
+ if (!NIL_P(val)) {
876
+ VALUE encoded = ssl_encode_npn_protocols(val);
877
+ SSL_CTX_set_next_protos_advertised_cb(ctx, ssl_npn_advertise_cb, (void *)encoded);
878
+ OSSL_Debug("SSL NPN advertise callback added");
879
+ }
880
+ if (RTEST(rb_attr_get(self, id_i_npn_select_cb))) {
881
+ SSL_CTX_set_next_proto_select_cb(ctx, ssl_npn_select_cb, (void *) self);
882
+ OSSL_Debug("SSL NPN select callback added");
883
+ }
884
+ #endif
885
+
886
+ #ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
887
+ val = rb_attr_get(self, id_i_alpn_protocols);
888
+ if (!NIL_P(val)) {
889
+ VALUE rprotos = ssl_encode_npn_protocols(val);
890
+
891
+ /* returns 0 on success */
892
+ if (SSL_CTX_set_alpn_protos(ctx, (unsigned char *)RSTRING_PTR(rprotos),
893
+ RSTRING_LENINT(rprotos)))
894
+ ossl_raise(eSSLError, "SSL_CTX_set_alpn_protos");
895
+ OSSL_Debug("SSL ALPN values added");
896
+ }
897
+ if (RTEST(rb_attr_get(self, id_i_alpn_select_cb))) {
898
+ SSL_CTX_set_alpn_select_cb(ctx, ssl_alpn_select_cb, (void *) self);
899
+ OSSL_Debug("SSL ALPN select callback added");
900
+ }
901
+ #endif
902
+
903
+ rb_obj_freeze(self);
904
+
905
+ val = rb_attr_get(self, id_i_session_id_context);
906
+ if (!NIL_P(val)){
907
+ StringValue(val);
908
+ if (!SSL_CTX_set_session_id_context(ctx, (unsigned char *)RSTRING_PTR(val),
909
+ RSTRING_LENINT(val))){
910
+ ossl_raise(eSSLError, "SSL_CTX_set_session_id_context");
911
+ }
912
+ }
913
+
914
+ if (RTEST(rb_attr_get(self, id_i_session_get_cb))) {
915
+ SSL_CTX_sess_set_get_cb(ctx, ossl_sslctx_session_get_cb);
916
+ OSSL_Debug("SSL SESSION get callback added");
917
+ }
918
+ if (RTEST(rb_attr_get(self, id_i_session_new_cb))) {
919
+ SSL_CTX_sess_set_new_cb(ctx, ossl_sslctx_session_new_cb);
920
+ OSSL_Debug("SSL SESSION new callback added");
921
+ }
922
+ if (RTEST(rb_attr_get(self, id_i_session_remove_cb))) {
923
+ SSL_CTX_sess_set_remove_cb(ctx, ossl_sslctx_session_remove_cb);
924
+ OSSL_Debug("SSL SESSION remove callback added");
925
+ }
926
+
927
+ #ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
928
+ val = rb_attr_get(self, id_i_servername_cb);
929
+ if (!NIL_P(val)) {
930
+ SSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);
931
+ OSSL_Debug("SSL TLSEXT servername callback added");
932
+ }
933
+ #endif
934
+
935
+ return Qtrue;
936
+ }
937
+
938
+ static VALUE
939
+ ossl_ssl_cipher_to_ary(const SSL_CIPHER *cipher)
940
+ {
941
+ VALUE ary;
942
+ int bits, alg_bits;
943
+
944
+ ary = rb_ary_new2(4);
945
+ rb_ary_push(ary, rb_str_new2(SSL_CIPHER_get_name(cipher)));
946
+ rb_ary_push(ary, rb_str_new2(SSL_CIPHER_get_version(cipher)));
947
+ bits = SSL_CIPHER_get_bits(cipher, &alg_bits);
948
+ rb_ary_push(ary, INT2NUM(bits));
949
+ rb_ary_push(ary, INT2NUM(alg_bits));
950
+
951
+ return ary;
952
+ }
953
+
954
+ /*
955
+ * call-seq:
956
+ * ctx.ciphers => [[name, version, bits, alg_bits], ...]
957
+ *
958
+ * The list of cipher suites configured for this context.
959
+ */
960
+ static VALUE
961
+ ossl_sslctx_get_ciphers(VALUE self)
962
+ {
963
+ SSL_CTX *ctx;
964
+ STACK_OF(SSL_CIPHER) *ciphers;
965
+ const SSL_CIPHER *cipher;
966
+ VALUE ary;
967
+ int i, num;
968
+
969
+ GetSSLCTX(self, ctx);
970
+ if(!ctx){
971
+ rb_warning("SSL_CTX is not initialized.");
972
+ return Qnil;
973
+ }
974
+ ciphers = SSL_CTX_get_ciphers(ctx);
975
+
976
+ if (!ciphers)
977
+ return rb_ary_new();
978
+
979
+ num = sk_SSL_CIPHER_num(ciphers);
980
+ ary = rb_ary_new2(num);
981
+ for(i = 0; i < num; i++){
982
+ cipher = sk_SSL_CIPHER_value(ciphers, i);
983
+ rb_ary_push(ary, ossl_ssl_cipher_to_ary(cipher));
984
+ }
985
+ return ary;
986
+ }
987
+
988
+ /*
989
+ * call-seq:
990
+ * ctx.ciphers = "cipher1:cipher2:..."
991
+ * ctx.ciphers = [name, ...]
992
+ * ctx.ciphers = [[name, version, bits, alg_bits], ...]
993
+ *
994
+ * Sets the list of available cipher suites for this context. Note in a server
995
+ * context some ciphers require the appropriate certificates. For example, an
996
+ * RSA cipher suite can only be chosen when an RSA certificate is available.
997
+ */
998
+ static VALUE
999
+ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
1000
+ {
1001
+ SSL_CTX *ctx;
1002
+ VALUE str, elem;
1003
+ int i;
1004
+
1005
+ rb_check_frozen(self);
1006
+ if (NIL_P(v))
1007
+ return v;
1008
+ else if (RB_TYPE_P(v, T_ARRAY)) {
1009
+ str = rb_str_new(0, 0);
1010
+ for (i = 0; i < RARRAY_LEN(v); i++) {
1011
+ elem = rb_ary_entry(v, i);
1012
+ if (RB_TYPE_P(elem, T_ARRAY)) elem = rb_ary_entry(elem, 0);
1013
+ elem = rb_String(elem);
1014
+ rb_str_append(str, elem);
1015
+ if (i < RARRAY_LEN(v)-1) rb_str_cat2(str, ":");
1016
+ }
1017
+ } else {
1018
+ str = v;
1019
+ StringValue(str);
1020
+ }
1021
+
1022
+ GetSSLCTX(self, ctx);
1023
+ if(!ctx){
1024
+ ossl_raise(eSSLError, "SSL_CTX is not initialized.");
1025
+ return Qnil;
1026
+ }
1027
+ if (!SSL_CTX_set_cipher_list(ctx, StringValueCStr(str))) {
1028
+ ossl_raise(eSSLError, "SSL_CTX_set_cipher_list");
1029
+ }
1030
+
1031
+ return v;
1032
+ }
1033
+
1034
+ #if !defined(OPENSSL_NO_EC)
1035
+ /*
1036
+ * call-seq:
1037
+ * ctx.ecdh_curves = curve_list -> curve_list
1038
+ *
1039
+ * Sets the list of "supported elliptic curves" for this context.
1040
+ *
1041
+ * For a TLS client, the list is directly used in the Supported Elliptic Curves
1042
+ * Extension. For a server, the list is used by OpenSSL to determine the set of
1043
+ * shared curves. OpenSSL will pick the most appropriate one from it.
1044
+ *
1045
+ * Note that this works differently with old OpenSSL (<= 1.0.1). Only one curve
1046
+ * can be set, and this has no effect for TLS clients.
1047
+ *
1048
+ * === Example
1049
+ * ctx1 = OpenSSL::SSL::SSLContext.new
1050
+ * ctx1.ecdh_curves = "X25519:P-256:P-224"
1051
+ * svr = OpenSSL::SSL::SSLServer.new(tcp_svr, ctx1)
1052
+ * Thread.new { svr.accept }
1053
+ *
1054
+ * ctx2 = OpenSSL::SSL::SSLContext.new
1055
+ * ctx2.ecdh_curves = "P-256"
1056
+ * cli = OpenSSL::SSL::SSLSocket.new(tcp_sock, ctx2)
1057
+ * cli.connect
1058
+ *
1059
+ * p cli.tmp_key.group.curve_name
1060
+ * # => "prime256v1" (is an alias for NIST P-256)
1061
+ */
1062
+ static VALUE
1063
+ ossl_sslctx_set_ecdh_curves(VALUE self, VALUE arg)
1064
+ {
1065
+ SSL_CTX *ctx;
1066
+
1067
+ rb_check_frozen(self);
1068
+ GetSSLCTX(self, ctx);
1069
+ StringValueCStr(arg);
1070
+
1071
+ #if defined(HAVE_SSL_CTX_SET1_CURVES_LIST)
1072
+ if (!SSL_CTX_set1_curves_list(ctx, RSTRING_PTR(arg)))
1073
+ ossl_raise(eSSLError, NULL);
1074
+ #else
1075
+ /* OpenSSL does not have SSL_CTX_set1_curves_list()... Fallback to
1076
+ * SSL_CTX_set_tmp_ecdh(). So only the first curve is used. */
1077
+ {
1078
+ VALUE curve, splitted;
1079
+ EC_KEY *ec;
1080
+ int nid;
1081
+
1082
+ splitted = rb_str_split(arg, ":");
1083
+ if (!RARRAY_LEN(splitted))
1084
+ ossl_raise(eSSLError, "invalid input format");
1085
+ curve = RARRAY_AREF(splitted, 0);
1086
+ StringValueCStr(curve);
1087
+
1088
+ /* SSL_CTX_set1_curves_list() accepts NIST names */
1089
+ nid = EC_curve_nist2nid(RSTRING_PTR(curve));
1090
+ if (nid == NID_undef)
1091
+ nid = OBJ_txt2nid(RSTRING_PTR(curve));
1092
+ if (nid == NID_undef)
1093
+ ossl_raise(eSSLError, "unknown curve name");
1094
+
1095
+ ec = EC_KEY_new_by_curve_name(nid);
1096
+ if (!ec)
1097
+ ossl_raise(eSSLError, NULL);
1098
+ EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
1099
+ if (!SSL_CTX_set_tmp_ecdh(ctx, ec)) {
1100
+ EC_KEY_free(ec);
1101
+ ossl_raise(eSSLError, "SSL_CTX_set_tmp_ecdh");
1102
+ }
1103
+ EC_KEY_free(ec);
1104
+ # if defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
1105
+ /* tmp_ecdh and ecdh_auto conflict. tmp_ecdh is ignored when ecdh_auto
1106
+ * is enabled. So disable ecdh_auto. */
1107
+ if (!SSL_CTX_set_ecdh_auto(ctx, 0))
1108
+ ossl_raise(eSSLError, "SSL_CTX_set_ecdh_auto");
1109
+ # endif
1110
+ }
1111
+ #endif
1112
+
1113
+ return arg;
1114
+ }
1115
+ #else
1116
+ #define ossl_sslctx_set_ecdh_curves rb_f_notimplement
1117
+ #endif
1118
+
1119
+ /*
1120
+ * call-seq:
1121
+ * ctx.security_level -> Integer
1122
+ *
1123
+ * Returns the security level for the context.
1124
+ *
1125
+ * See also OpenSSL::SSL::SSLContext#security_level=.
1126
+ */
1127
+ static VALUE
1128
+ ossl_sslctx_get_security_level(VALUE self)
1129
+ {
1130
+ SSL_CTX *ctx;
1131
+
1132
+ GetSSLCTX(self, ctx);
1133
+
1134
+ #if defined(HAVE_SSL_CTX_GET_SECURITY_LEVEL)
1135
+ return INT2NUM(SSL_CTX_get_security_level(ctx));
1136
+ #else
1137
+ (void)ctx;
1138
+ return INT2FIX(0);
1139
+ #endif
1140
+ }
1141
+
1142
+ /*
1143
+ * call-seq:
1144
+ * ctx.security_level = integer
1145
+ *
1146
+ * Sets the security level for the context. OpenSSL limits parameters according
1147
+ * to the level. The "parameters" include: ciphersuites, curves, key sizes,
1148
+ * certificate signature algorithms, protocol version and so on. For example,
1149
+ * level 1 rejects parameters offering below 80 bits of security, such as
1150
+ * ciphersuites using MD5 for the MAC or RSA keys shorter than 1024 bits.
1151
+ *
1152
+ * Note that attempts to set such parameters with insufficient security are
1153
+ * also blocked. You need to lower the level first.
1154
+ *
1155
+ * This feature is not supported in OpenSSL < 1.1.0, and setting the level to
1156
+ * other than 0 will raise NotImplementedError. Level 0 means everything is
1157
+ * permitted, the same behavior as previous versions of OpenSSL.
1158
+ *
1159
+ * See the manpage of SSL_CTX_set_security_level(3) for details.
1160
+ */
1161
+ static VALUE
1162
+ ossl_sslctx_set_security_level(VALUE self, VALUE value)
1163
+ {
1164
+ SSL_CTX *ctx;
1165
+
1166
+ rb_check_frozen(self);
1167
+ GetSSLCTX(self, ctx);
1168
+
1169
+ #if defined(HAVE_SSL_CTX_GET_SECURITY_LEVEL)
1170
+ SSL_CTX_set_security_level(ctx, NUM2INT(value));
1171
+ #else
1172
+ (void)ctx;
1173
+ if (NUM2INT(value) != 0)
1174
+ ossl_raise(rb_eNotImpError, "setting security level to other than 0 is "
1175
+ "not supported in this version of OpenSSL");
1176
+ #endif
1177
+
1178
+ return value;
1179
+ }
1180
+
1181
+ /*
1182
+ * call-seq:
1183
+ * ctx.session_add(session) -> true | false
1184
+ *
1185
+ * Adds +session+ to the session cache.
1186
+ */
1187
+ static VALUE
1188
+ ossl_sslctx_session_add(VALUE self, VALUE arg)
1189
+ {
1190
+ SSL_CTX *ctx;
1191
+ SSL_SESSION *sess;
1192
+
1193
+ GetSSLCTX(self, ctx);
1194
+ SafeGetSSLSession(arg, sess);
1195
+
1196
+ return SSL_CTX_add_session(ctx, sess) == 1 ? Qtrue : Qfalse;
1197
+ }
1198
+
1199
+ /*
1200
+ * call-seq:
1201
+ * ctx.session_remove(session) -> true | false
1202
+ *
1203
+ * Removes +session+ from the session cache.
1204
+ */
1205
+ static VALUE
1206
+ ossl_sslctx_session_remove(VALUE self, VALUE arg)
1207
+ {
1208
+ SSL_CTX *ctx;
1209
+ SSL_SESSION *sess;
1210
+
1211
+ GetSSLCTX(self, ctx);
1212
+ SafeGetSSLSession(arg, sess);
1213
+
1214
+ return SSL_CTX_remove_session(ctx, sess) == 1 ? Qtrue : Qfalse;
1215
+ }
1216
+
1217
+ /*
1218
+ * call-seq:
1219
+ * ctx.session_cache_mode -> Integer
1220
+ *
1221
+ * The current session cache mode.
1222
+ */
1223
+ static VALUE
1224
+ ossl_sslctx_get_session_cache_mode(VALUE self)
1225
+ {
1226
+ SSL_CTX *ctx;
1227
+
1228
+ GetSSLCTX(self, ctx);
1229
+
1230
+ return LONG2NUM(SSL_CTX_get_session_cache_mode(ctx));
1231
+ }
1232
+
1233
+ /*
1234
+ * call-seq:
1235
+ * ctx.session_cache_mode=(integer) -> Integer
1236
+ *
1237
+ * Sets the SSL session cache mode. Bitwise-or together the desired
1238
+ * SESSION_CACHE_* constants to set. See SSL_CTX_set_session_cache_mode(3) for
1239
+ * details.
1240
+ */
1241
+ static VALUE
1242
+ ossl_sslctx_set_session_cache_mode(VALUE self, VALUE arg)
1243
+ {
1244
+ SSL_CTX *ctx;
1245
+
1246
+ GetSSLCTX(self, ctx);
1247
+
1248
+ SSL_CTX_set_session_cache_mode(ctx, NUM2LONG(arg));
1249
+
1250
+ return arg;
1251
+ }
1252
+
1253
+ /*
1254
+ * call-seq:
1255
+ * ctx.session_cache_size -> Integer
1256
+ *
1257
+ * Returns the current session cache size. Zero is used to represent an
1258
+ * unlimited cache size.
1259
+ */
1260
+ static VALUE
1261
+ ossl_sslctx_get_session_cache_size(VALUE self)
1262
+ {
1263
+ SSL_CTX *ctx;
1264
+
1265
+ GetSSLCTX(self, ctx);
1266
+
1267
+ return LONG2NUM(SSL_CTX_sess_get_cache_size(ctx));
1268
+ }
1269
+
1270
+ /*
1271
+ * call-seq:
1272
+ * ctx.session_cache_size=(integer) -> Integer
1273
+ *
1274
+ * Sets the session cache size. Returns the previously valid session cache
1275
+ * size. Zero is used to represent an unlimited session cache size.
1276
+ */
1277
+ static VALUE
1278
+ ossl_sslctx_set_session_cache_size(VALUE self, VALUE arg)
1279
+ {
1280
+ SSL_CTX *ctx;
1281
+
1282
+ GetSSLCTX(self, ctx);
1283
+
1284
+ SSL_CTX_sess_set_cache_size(ctx, NUM2LONG(arg));
1285
+
1286
+ return arg;
1287
+ }
1288
+
1289
+ /*
1290
+ * call-seq:
1291
+ * ctx.session_cache_stats -> Hash
1292
+ *
1293
+ * Returns a Hash containing the following keys:
1294
+ *
1295
+ * :accept:: Number of started SSL/TLS handshakes in server mode
1296
+ * :accept_good:: Number of established SSL/TLS sessions in server mode
1297
+ * :accept_renegotiate:: Number of start renegotiations in server mode
1298
+ * :cache_full:: Number of sessions that were removed due to cache overflow
1299
+ * :cache_hits:: Number of successfully reused connections
1300
+ * :cache_misses:: Number of sessions proposed by clients that were not found
1301
+ * in the cache
1302
+ * :cache_num:: Number of sessions in the internal session cache
1303
+ * :cb_hits:: Number of sessions retrieved from the external cache in server
1304
+ * mode
1305
+ * :connect:: Number of started SSL/TLS handshakes in client mode
1306
+ * :connect_good:: Number of established SSL/TLS sessions in client mode
1307
+ * :connect_renegotiate:: Number of start renegotiations in client mode
1308
+ * :timeouts:: Number of sessions proposed by clients that were found in the
1309
+ * cache but had expired due to timeouts
1310
+ */
1311
+ static VALUE
1312
+ ossl_sslctx_get_session_cache_stats(VALUE self)
1313
+ {
1314
+ SSL_CTX *ctx;
1315
+ VALUE hash;
1316
+
1317
+ GetSSLCTX(self, ctx);
1318
+
1319
+ hash = rb_hash_new();
1320
+ rb_hash_aset(hash, ID2SYM(rb_intern("cache_num")), LONG2NUM(SSL_CTX_sess_number(ctx)));
1321
+ rb_hash_aset(hash, ID2SYM(rb_intern("connect")), LONG2NUM(SSL_CTX_sess_connect(ctx)));
1322
+ rb_hash_aset(hash, ID2SYM(rb_intern("connect_good")), LONG2NUM(SSL_CTX_sess_connect_good(ctx)));
1323
+ rb_hash_aset(hash, ID2SYM(rb_intern("connect_renegotiate")), LONG2NUM(SSL_CTX_sess_connect_renegotiate(ctx)));
1324
+ rb_hash_aset(hash, ID2SYM(rb_intern("accept")), LONG2NUM(SSL_CTX_sess_accept(ctx)));
1325
+ rb_hash_aset(hash, ID2SYM(rb_intern("accept_good")), LONG2NUM(SSL_CTX_sess_accept_good(ctx)));
1326
+ rb_hash_aset(hash, ID2SYM(rb_intern("accept_renegotiate")), LONG2NUM(SSL_CTX_sess_accept_renegotiate(ctx)));
1327
+ rb_hash_aset(hash, ID2SYM(rb_intern("cache_hits")), LONG2NUM(SSL_CTX_sess_hits(ctx)));
1328
+ rb_hash_aset(hash, ID2SYM(rb_intern("cb_hits")), LONG2NUM(SSL_CTX_sess_cb_hits(ctx)));
1329
+ rb_hash_aset(hash, ID2SYM(rb_intern("cache_misses")), LONG2NUM(SSL_CTX_sess_misses(ctx)));
1330
+ rb_hash_aset(hash, ID2SYM(rb_intern("cache_full")), LONG2NUM(SSL_CTX_sess_cache_full(ctx)));
1331
+ rb_hash_aset(hash, ID2SYM(rb_intern("timeouts")), LONG2NUM(SSL_CTX_sess_timeouts(ctx)));
1332
+
1333
+ return hash;
1334
+ }
1335
+
1336
+
1337
+ /*
1338
+ * call-seq:
1339
+ * ctx.flush_sessions(time | nil) -> self
1340
+ *
1341
+ * Removes sessions in the internal cache that have expired at +time+.
1342
+ */
1343
+ static VALUE
1344
+ ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self)
1345
+ {
1346
+ VALUE arg1;
1347
+ SSL_CTX *ctx;
1348
+ time_t tm = 0;
1349
+
1350
+ rb_scan_args(argc, argv, "01", &arg1);
1351
+
1352
+ GetSSLCTX(self, ctx);
1353
+
1354
+ if (NIL_P(arg1)) {
1355
+ tm = time(0);
1356
+ } else if (rb_obj_is_instance_of(arg1, rb_cTime)) {
1357
+ tm = NUM2LONG(rb_funcall(arg1, rb_intern("to_i"), 0));
1358
+ } else {
1359
+ ossl_raise(rb_eArgError, "arg must be Time or nil");
1360
+ }
1361
+
1362
+ SSL_CTX_flush_sessions(ctx, (long)tm);
1363
+
1364
+ return self;
1365
+ }
1366
+
1367
+ /*
1368
+ * SSLSocket class
1369
+ */
1370
+ #ifndef OPENSSL_NO_SOCK
1371
+ static inline int
1372
+ ssl_started(SSL *ssl)
1373
+ {
1374
+ /* the FD is set in ossl_ssl_setup(), called by #connect or #accept */
1375
+ return SSL_get_fd(ssl) >= 0;
1376
+ }
1377
+
1378
+ static void
1379
+ ossl_ssl_shutdown(SSL *ssl)
1380
+ {
1381
+ int i;
1382
+
1383
+ /* 4 is from SSL_smart_shutdown() of mod_ssl.c (v2.2.19) */
1384
+ /* It says max 2x pending + 2x data = 4 */
1385
+ for (i = 0; i < 4; ++i) {
1386
+ /*
1387
+ * Ignore the case SSL_shutdown returns -1. Empty handshake_func
1388
+ * must not happen.
1389
+ */
1390
+ if (SSL_shutdown(ssl) != 0)
1391
+ break;
1392
+ }
1393
+ ossl_clear_error();
1394
+ }
1395
+
1396
+ static void
1397
+ ossl_ssl_free(void *ssl)
1398
+ {
1399
+ SSL_free(ssl);
1400
+ }
1401
+
1402
+ const rb_data_type_t ossl_ssl_type = {
1403
+ "OpenSSL/SSL",
1404
+ {
1405
+ 0, ossl_ssl_free,
1406
+ },
1407
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
1408
+ };
1409
+
1410
+ static VALUE
1411
+ ossl_ssl_s_alloc(VALUE klass)
1412
+ {
1413
+ return TypedData_Wrap_Struct(klass, &ossl_ssl_type, NULL);
1414
+ }
1415
+
1416
+ /*
1417
+ * call-seq:
1418
+ * SSLSocket.new(io) => aSSLSocket
1419
+ * SSLSocket.new(io, ctx) => aSSLSocket
1420
+ *
1421
+ * Creates a new SSL socket from +io+ which must be a real IO object (not an
1422
+ * IO-like object that responds to read/write).
1423
+ *
1424
+ * If +ctx+ is provided the SSL Sockets initial params will be taken from
1425
+ * the context.
1426
+ *
1427
+ * The OpenSSL::Buffering module provides additional IO methods.
1428
+ *
1429
+ * This method will freeze the SSLContext if one is provided;
1430
+ * however, session management is still allowed in the frozen SSLContext.
1431
+ */
1432
+ static VALUE
1433
+ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
1434
+ {
1435
+ VALUE io, v_ctx, verify_cb;
1436
+ SSL *ssl;
1437
+ SSL_CTX *ctx;
1438
+
1439
+ TypedData_Get_Struct(self, SSL, &ossl_ssl_type, ssl);
1440
+ if (ssl)
1441
+ ossl_raise(eSSLError, "SSL already initialized");
1442
+
1443
+ if (rb_scan_args(argc, argv, "11", &io, &v_ctx) == 1)
1444
+ v_ctx = rb_funcall(cSSLContext, rb_intern("new"), 0);
1445
+
1446
+ GetSSLCTX(v_ctx, ctx);
1447
+ rb_ivar_set(self, id_i_context, v_ctx);
1448
+ ossl_sslctx_setup(v_ctx);
1449
+
1450
+ if (rb_respond_to(io, rb_intern("nonblock=")))
1451
+ rb_funcall(io, rb_intern("nonblock="), 1, Qtrue);
1452
+ rb_ivar_set(self, id_i_io, io);
1453
+
1454
+ ssl = SSL_new(ctx);
1455
+ if (!ssl)
1456
+ ossl_raise(eSSLError, NULL);
1457
+ RTYPEDDATA_DATA(self) = ssl;
1458
+
1459
+ SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void *)self);
1460
+ SSL_set_info_callback(ssl, ssl_info_cb);
1461
+ verify_cb = rb_attr_get(v_ctx, id_i_verify_callback);
1462
+ SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)verify_cb);
1463
+
1464
+ rb_call_super(0, NULL);
1465
+
1466
+ return self;
1467
+ }
1468
+
1469
+ static VALUE
1470
+ ossl_ssl_setup(VALUE self)
1471
+ {
1472
+ VALUE io;
1473
+ SSL *ssl;
1474
+ rb_io_t *fptr;
1475
+
1476
+ GetSSL(self, ssl);
1477
+ if (ssl_started(ssl))
1478
+ return Qtrue;
1479
+
1480
+ io = rb_attr_get(self, id_i_io);
1481
+ GetOpenFile(io, fptr);
1482
+ rb_io_check_readable(fptr);
1483
+ rb_io_check_writable(fptr);
1484
+ SSL_set_fd(ssl, TO_SOCKET(FPTR_TO_FD(fptr)));
1485
+
1486
+ return Qtrue;
1487
+ }
1488
+
1489
+ #ifdef _WIN32
1490
+ #define ssl_get_error(ssl, ret) (errno = rb_w32_map_errno(WSAGetLastError()), SSL_get_error((ssl), (ret)))
1491
+ #else
1492
+ #define ssl_get_error(ssl, ret) SSL_get_error((ssl), (ret))
1493
+ #endif
1494
+
1495
+ static void
1496
+ write_would_block(int nonblock)
1497
+ {
1498
+ if (nonblock) {
1499
+ VALUE exc = ossl_exc_new(eSSLErrorWaitWritable, "write would block");
1500
+ rb_exc_raise(exc);
1501
+ }
1502
+ }
1503
+
1504
+ static void
1505
+ read_would_block(int nonblock)
1506
+ {
1507
+ if (nonblock) {
1508
+ VALUE exc = ossl_exc_new(eSSLErrorWaitReadable, "read would block");
1509
+ rb_exc_raise(exc);
1510
+ }
1511
+ }
1512
+
1513
+ static int
1514
+ no_exception_p(VALUE opts)
1515
+ {
1516
+ if (RB_TYPE_P(opts, T_HASH) &&
1517
+ rb_hash_lookup2(opts, sym_exception, Qundef) == Qfalse)
1518
+ return 1;
1519
+ return 0;
1520
+ }
1521
+
1522
+ static VALUE
1523
+ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
1524
+ {
1525
+ SSL *ssl;
1526
+ rb_io_t *fptr;
1527
+ int ret, ret2;
1528
+ VALUE cb_state;
1529
+ int nonblock = opts != Qfalse;
1530
+
1531
+ rb_ivar_set(self, ID_callback_state, Qnil);
1532
+
1533
+ GetSSL(self, ssl);
1534
+
1535
+ GetOpenFile(rb_attr_get(self, id_i_io), fptr);
1536
+ for(;;){
1537
+ ret = func(ssl);
1538
+
1539
+ cb_state = rb_attr_get(self, ID_callback_state);
1540
+ if (!NIL_P(cb_state)) {
1541
+ /* must cleanup OpenSSL error stack before re-raising */
1542
+ ossl_clear_error();
1543
+ rb_jump_tag(NUM2INT(cb_state));
1544
+ }
1545
+
1546
+ if (ret > 0)
1547
+ break;
1548
+
1549
+ switch((ret2 = ssl_get_error(ssl, ret))){
1550
+ case SSL_ERROR_WANT_WRITE:
1551
+ if (no_exception_p(opts)) { return sym_wait_writable; }
1552
+ write_would_block(nonblock);
1553
+ rb_io_wait_writable(FPTR_TO_FD(fptr));
1554
+ continue;
1555
+ case SSL_ERROR_WANT_READ:
1556
+ if (no_exception_p(opts)) { return sym_wait_readable; }
1557
+ read_would_block(nonblock);
1558
+ rb_io_wait_readable(FPTR_TO_FD(fptr));
1559
+ continue;
1560
+ case SSL_ERROR_SYSCALL:
1561
+ if (errno) rb_sys_fail(funcname);
1562
+ ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
1563
+ default:
1564
+ ossl_raise(eSSLError, "%s returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
1565
+ }
1566
+ }
1567
+
1568
+ return self;
1569
+ }
1570
+
1571
+ /*
1572
+ * call-seq:
1573
+ * ssl.connect => self
1574
+ *
1575
+ * Initiates an SSL/TLS handshake with a server. The handshake may be started
1576
+ * after unencrypted data has been sent over the socket.
1577
+ */
1578
+ static VALUE
1579
+ ossl_ssl_connect(VALUE self)
1580
+ {
1581
+ ossl_ssl_setup(self);
1582
+
1583
+ return ossl_start_ssl(self, SSL_connect, "SSL_connect", Qfalse);
1584
+ }
1585
+
1586
+ /*
1587
+ * call-seq:
1588
+ * ssl.connect_nonblock([options]) => self
1589
+ *
1590
+ * Initiates the SSL/TLS handshake as a client in non-blocking manner.
1591
+ *
1592
+ * # emulates blocking connect
1593
+ * begin
1594
+ * ssl.connect_nonblock
1595
+ * rescue IO::WaitReadable
1596
+ * IO.select([s2])
1597
+ * retry
1598
+ * rescue IO::WaitWritable
1599
+ * IO.select(nil, [s2])
1600
+ * retry
1601
+ * end
1602
+ *
1603
+ * By specifying `exception: false`, the options hash allows you to indicate
1604
+ * that connect_nonblock should not raise an IO::WaitReadable or
1605
+ * IO::WaitWritable exception, but return the symbol :wait_readable or
1606
+ * :wait_writable instead.
1607
+ */
1608
+ static VALUE
1609
+ ossl_ssl_connect_nonblock(int argc, VALUE *argv, VALUE self)
1610
+ {
1611
+ VALUE opts;
1612
+ rb_scan_args(argc, argv, "0:", &opts);
1613
+
1614
+ ossl_ssl_setup(self);
1615
+
1616
+ return ossl_start_ssl(self, SSL_connect, "SSL_connect", opts);
1617
+ }
1618
+
1619
+ /*
1620
+ * call-seq:
1621
+ * ssl.accept => self
1622
+ *
1623
+ * Waits for a SSL/TLS client to initiate a handshake. The handshake may be
1624
+ * started after unencrypted data has been sent over the socket.
1625
+ */
1626
+ static VALUE
1627
+ ossl_ssl_accept(VALUE self)
1628
+ {
1629
+ ossl_ssl_setup(self);
1630
+
1631
+ return ossl_start_ssl(self, SSL_accept, "SSL_accept", Qfalse);
1632
+ }
1633
+
1634
+ /*
1635
+ * call-seq:
1636
+ * ssl.accept_nonblock([options]) => self
1637
+ *
1638
+ * Initiates the SSL/TLS handshake as a server in non-blocking manner.
1639
+ *
1640
+ * # emulates blocking accept
1641
+ * begin
1642
+ * ssl.accept_nonblock
1643
+ * rescue IO::WaitReadable
1644
+ * IO.select([s2])
1645
+ * retry
1646
+ * rescue IO::WaitWritable
1647
+ * IO.select(nil, [s2])
1648
+ * retry
1649
+ * end
1650
+ *
1651
+ * By specifying `exception: false`, the options hash allows you to indicate
1652
+ * that accept_nonblock should not raise an IO::WaitReadable or
1653
+ * IO::WaitWritable exception, but return the symbol :wait_readable or
1654
+ * :wait_writable instead.
1655
+ */
1656
+ static VALUE
1657
+ ossl_ssl_accept_nonblock(int argc, VALUE *argv, VALUE self)
1658
+ {
1659
+ VALUE opts;
1660
+
1661
+ rb_scan_args(argc, argv, "0:", &opts);
1662
+ ossl_ssl_setup(self);
1663
+
1664
+ return ossl_start_ssl(self, SSL_accept, "SSL_accept", opts);
1665
+ }
1666
+
1667
+ static VALUE
1668
+ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1669
+ {
1670
+ SSL *ssl;
1671
+ int ilen, nread = 0;
1672
+ VALUE len, str;
1673
+ rb_io_t *fptr;
1674
+ VALUE io, opts = Qnil;
1675
+
1676
+ if (nonblock) {
1677
+ rb_scan_args(argc, argv, "11:", &len, &str, &opts);
1678
+ } else {
1679
+ rb_scan_args(argc, argv, "11", &len, &str);
1680
+ }
1681
+
1682
+ ilen = NUM2INT(len);
1683
+ if(NIL_P(str)) str = rb_str_new(0, ilen);
1684
+ else{
1685
+ StringValue(str);
1686
+ rb_str_modify(str);
1687
+ rb_str_resize(str, ilen);
1688
+ }
1689
+ if(ilen == 0) return str;
1690
+
1691
+ GetSSL(self, ssl);
1692
+ io = rb_attr_get(self, id_i_io);
1693
+ GetOpenFile(io, fptr);
1694
+ if (ssl_started(ssl)) {
1695
+ if(!nonblock && SSL_pending(ssl) <= 0)
1696
+ rb_thread_wait_fd(FPTR_TO_FD(fptr));
1697
+ for (;;){
1698
+ nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LENINT(str));
1699
+ switch(ssl_get_error(ssl, nread)){
1700
+ case SSL_ERROR_NONE:
1701
+ goto end;
1702
+ case SSL_ERROR_ZERO_RETURN:
1703
+ if (no_exception_p(opts)) { return Qnil; }
1704
+ rb_eof_error();
1705
+ case SSL_ERROR_WANT_WRITE:
1706
+ if (no_exception_p(opts)) { return sym_wait_writable; }
1707
+ write_would_block(nonblock);
1708
+ rb_io_wait_writable(FPTR_TO_FD(fptr));
1709
+ continue;
1710
+ case SSL_ERROR_WANT_READ:
1711
+ if (no_exception_p(opts)) { return sym_wait_readable; }
1712
+ read_would_block(nonblock);
1713
+ rb_io_wait_readable(FPTR_TO_FD(fptr));
1714
+ continue;
1715
+ case SSL_ERROR_SYSCALL:
1716
+ if(ERR_peek_error() == 0 && nread == 0) {
1717
+ if (no_exception_p(opts)) { return Qnil; }
1718
+ rb_eof_error();
1719
+ }
1720
+ rb_sys_fail(0);
1721
+ default:
1722
+ ossl_raise(eSSLError, "SSL_read");
1723
+ }
1724
+ }
1725
+ }
1726
+ else {
1727
+ ID meth = nonblock ? rb_intern("read_nonblock") : rb_intern("sysread");
1728
+
1729
+ rb_warning("SSL session is not started yet.");
1730
+ if (nonblock)
1731
+ return rb_funcall(io, meth, 3, len, str, opts);
1732
+ else
1733
+ return rb_funcall(io, meth, 2, len, str);
1734
+ }
1735
+
1736
+ end:
1737
+ rb_str_set_len(str, nread);
1738
+ OBJ_TAINT(str);
1739
+
1740
+ return str;
1741
+ }
1742
+
1743
+ /*
1744
+ * call-seq:
1745
+ * ssl.sysread(length) => string
1746
+ * ssl.sysread(length, buffer) => buffer
1747
+ *
1748
+ * Reads +length+ bytes from the SSL connection. If a pre-allocated +buffer+
1749
+ * is provided the data will be written into it.
1750
+ */
1751
+ static VALUE
1752
+ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
1753
+ {
1754
+ return ossl_ssl_read_internal(argc, argv, self, 0);
1755
+ }
1756
+
1757
+ /*
1758
+ * call-seq:
1759
+ * ssl.sysread_nonblock(length) => string
1760
+ * ssl.sysread_nonblock(length, buffer) => buffer
1761
+ * ssl.sysread_nonblock(length[, buffer [, opts]) => buffer
1762
+ *
1763
+ * A non-blocking version of #sysread. Raises an SSLError if reading would
1764
+ * block. If "exception: false" is passed, this method returns a symbol of
1765
+ * :wait_readable, :wait_writable, or nil, rather than raising an exception.
1766
+ *
1767
+ * Reads +length+ bytes from the SSL connection. If a pre-allocated +buffer+
1768
+ * is provided the data will be written into it.
1769
+ */
1770
+ static VALUE
1771
+ ossl_ssl_read_nonblock(int argc, VALUE *argv, VALUE self)
1772
+ {
1773
+ return ossl_ssl_read_internal(argc, argv, self, 1);
1774
+ }
1775
+
1776
+ static VALUE
1777
+ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
1778
+ {
1779
+ SSL *ssl;
1780
+ int nwrite = 0;
1781
+ rb_io_t *fptr;
1782
+ int nonblock = opts != Qfalse;
1783
+ VALUE io;
1784
+
1785
+ StringValue(str);
1786
+ GetSSL(self, ssl);
1787
+ io = rb_attr_get(self, id_i_io);
1788
+ GetOpenFile(io, fptr);
1789
+ if (ssl_started(ssl)) {
1790
+ for (;;){
1791
+ int num = RSTRING_LENINT(str);
1792
+
1793
+ /* SSL_write(3ssl) manpage states num == 0 is undefined */
1794
+ if (num == 0)
1795
+ goto end;
1796
+
1797
+ nwrite = SSL_write(ssl, RSTRING_PTR(str), num);
1798
+ switch(ssl_get_error(ssl, nwrite)){
1799
+ case SSL_ERROR_NONE:
1800
+ goto end;
1801
+ case SSL_ERROR_WANT_WRITE:
1802
+ if (no_exception_p(opts)) { return sym_wait_writable; }
1803
+ write_would_block(nonblock);
1804
+ rb_io_wait_writable(FPTR_TO_FD(fptr));
1805
+ continue;
1806
+ case SSL_ERROR_WANT_READ:
1807
+ if (no_exception_p(opts)) { return sym_wait_readable; }
1808
+ read_would_block(nonblock);
1809
+ rb_io_wait_readable(FPTR_TO_FD(fptr));
1810
+ continue;
1811
+ case SSL_ERROR_SYSCALL:
1812
+ if (errno) rb_sys_fail(0);
1813
+ default:
1814
+ ossl_raise(eSSLError, "SSL_write");
1815
+ }
1816
+ }
1817
+ }
1818
+ else {
1819
+ ID meth = nonblock ?
1820
+ rb_intern("write_nonblock") : rb_intern("syswrite");
1821
+
1822
+ rb_warning("SSL session is not started yet.");
1823
+ if (nonblock)
1824
+ return rb_funcall(io, meth, 2, str, opts);
1825
+ else
1826
+ return rb_funcall(io, meth, 1, str);
1827
+ }
1828
+
1829
+ end:
1830
+ return INT2NUM(nwrite);
1831
+ }
1832
+
1833
+ /*
1834
+ * call-seq:
1835
+ * ssl.syswrite(string) => Integer
1836
+ *
1837
+ * Writes +string+ to the SSL connection.
1838
+ */
1839
+ static VALUE
1840
+ ossl_ssl_write(VALUE self, VALUE str)
1841
+ {
1842
+ return ossl_ssl_write_internal(self, str, Qfalse);
1843
+ }
1844
+
1845
+ /*
1846
+ * call-seq:
1847
+ * ssl.syswrite_nonblock(string) => Integer
1848
+ *
1849
+ * Writes +string+ to the SSL connection in a non-blocking manner. Raises an
1850
+ * SSLError if writing would block.
1851
+ */
1852
+ static VALUE
1853
+ ossl_ssl_write_nonblock(int argc, VALUE *argv, VALUE self)
1854
+ {
1855
+ VALUE str, opts;
1856
+
1857
+ rb_scan_args(argc, argv, "1:", &str, &opts);
1858
+
1859
+ return ossl_ssl_write_internal(self, str, opts);
1860
+ }
1861
+
1862
+ /*
1863
+ * call-seq:
1864
+ * ssl.stop => nil
1865
+ *
1866
+ * Sends "close notify" to the peer and tries to shut down the SSL connection
1867
+ * gracefully.
1868
+ */
1869
+ static VALUE
1870
+ ossl_ssl_stop(VALUE self)
1871
+ {
1872
+ SSL *ssl;
1873
+
1874
+ GetSSL(self, ssl);
1875
+
1876
+ ossl_ssl_shutdown(ssl);
1877
+
1878
+ return Qnil;
1879
+ }
1880
+
1881
+ /*
1882
+ * call-seq:
1883
+ * ssl.cert => cert or nil
1884
+ *
1885
+ * The X509 certificate for this socket endpoint.
1886
+ */
1887
+ static VALUE
1888
+ ossl_ssl_get_cert(VALUE self)
1889
+ {
1890
+ SSL *ssl;
1891
+ X509 *cert = NULL;
1892
+
1893
+ GetSSL(self, ssl);
1894
+
1895
+ /*
1896
+ * Is this OpenSSL bug? Should add a ref?
1897
+ * TODO: Ask for.
1898
+ */
1899
+ cert = SSL_get_certificate(ssl); /* NO DUPs => DON'T FREE. */
1900
+
1901
+ if (!cert) {
1902
+ return Qnil;
1903
+ }
1904
+ return ossl_x509_new(cert);
1905
+ }
1906
+
1907
+ /*
1908
+ * call-seq:
1909
+ * ssl.peer_cert => cert or nil
1910
+ *
1911
+ * The X509 certificate for this socket's peer.
1912
+ */
1913
+ static VALUE
1914
+ ossl_ssl_get_peer_cert(VALUE self)
1915
+ {
1916
+ SSL *ssl;
1917
+ X509 *cert = NULL;
1918
+ VALUE obj;
1919
+
1920
+ GetSSL(self, ssl);
1921
+
1922
+ cert = SSL_get_peer_certificate(ssl); /* Adds a ref => Safe to FREE. */
1923
+
1924
+ if (!cert) {
1925
+ return Qnil;
1926
+ }
1927
+ obj = ossl_x509_new(cert);
1928
+ X509_free(cert);
1929
+
1930
+ return obj;
1931
+ }
1932
+
1933
+ /*
1934
+ * call-seq:
1935
+ * ssl.peer_cert_chain => [cert, ...] or nil
1936
+ *
1937
+ * The X509 certificate chain for this socket's peer.
1938
+ */
1939
+ static VALUE
1940
+ ossl_ssl_get_peer_cert_chain(VALUE self)
1941
+ {
1942
+ SSL *ssl;
1943
+ STACK_OF(X509) *chain;
1944
+ X509 *cert;
1945
+ VALUE ary;
1946
+ int i, num;
1947
+
1948
+ GetSSL(self, ssl);
1949
+
1950
+ chain = SSL_get_peer_cert_chain(ssl);
1951
+ if(!chain) return Qnil;
1952
+ num = sk_X509_num(chain);
1953
+ ary = rb_ary_new2(num);
1954
+ for (i = 0; i < num; i++){
1955
+ cert = sk_X509_value(chain, i);
1956
+ rb_ary_push(ary, ossl_x509_new(cert));
1957
+ }
1958
+
1959
+ return ary;
1960
+ }
1961
+
1962
+ /*
1963
+ * call-seq:
1964
+ * ssl.ssl_version => String
1965
+ *
1966
+ * Returns a String representing the SSL/TLS version that was negotiated
1967
+ * for the connection, for example "TLSv1.2".
1968
+ */
1969
+ static VALUE
1970
+ ossl_ssl_get_version(VALUE self)
1971
+ {
1972
+ SSL *ssl;
1973
+
1974
+ GetSSL(self, ssl);
1975
+
1976
+ return rb_str_new2(SSL_get_version(ssl));
1977
+ }
1978
+
1979
+ /*
1980
+ * call-seq:
1981
+ * ssl.cipher => [name, version, bits, alg_bits]
1982
+ *
1983
+ * The cipher being used for the current connection
1984
+ */
1985
+ static VALUE
1986
+ ossl_ssl_get_cipher(VALUE self)
1987
+ {
1988
+ SSL *ssl;
1989
+ SSL_CIPHER *cipher;
1990
+
1991
+ GetSSL(self, ssl);
1992
+
1993
+ cipher = (SSL_CIPHER *)SSL_get_current_cipher(ssl);
1994
+
1995
+ return ossl_ssl_cipher_to_ary(cipher);
1996
+ }
1997
+
1998
+ /*
1999
+ * call-seq:
2000
+ * ssl.state => string
2001
+ *
2002
+ * A description of the current connection state. This is for diagnostic
2003
+ * purposes only.
2004
+ */
2005
+ static VALUE
2006
+ ossl_ssl_get_state(VALUE self)
2007
+ {
2008
+ SSL *ssl;
2009
+ VALUE ret;
2010
+
2011
+ GetSSL(self, ssl);
2012
+
2013
+ ret = rb_str_new2(SSL_state_string(ssl));
2014
+ if (ruby_verbose) {
2015
+ rb_str_cat2(ret, ": ");
2016
+ rb_str_cat2(ret, SSL_state_string_long(ssl));
2017
+ }
2018
+ return ret;
2019
+ }
2020
+
2021
+ /*
2022
+ * call-seq:
2023
+ * ssl.pending => Integer
2024
+ *
2025
+ * The number of bytes that are immediately available for reading.
2026
+ */
2027
+ static VALUE
2028
+ ossl_ssl_pending(VALUE self)
2029
+ {
2030
+ SSL *ssl;
2031
+
2032
+ GetSSL(self, ssl);
2033
+
2034
+ return INT2NUM(SSL_pending(ssl));
2035
+ }
2036
+
2037
+ /*
2038
+ * call-seq:
2039
+ * ssl.session_reused? -> true | false
2040
+ *
2041
+ * Returns true if a reused session was negotiated during the handshake.
2042
+ */
2043
+ static VALUE
2044
+ ossl_ssl_session_reused(VALUE self)
2045
+ {
2046
+ SSL *ssl;
2047
+
2048
+ GetSSL(self, ssl);
2049
+
2050
+ return SSL_session_reused(ssl) ? Qtrue : Qfalse;
2051
+ }
2052
+
2053
+ /*
2054
+ * call-seq:
2055
+ * ssl.session = session -> session
2056
+ *
2057
+ * Sets the Session to be used when the connection is established.
2058
+ */
2059
+ static VALUE
2060
+ ossl_ssl_set_session(VALUE self, VALUE arg1)
2061
+ {
2062
+ SSL *ssl;
2063
+ SSL_SESSION *sess;
2064
+
2065
+ GetSSL(self, ssl);
2066
+ SafeGetSSLSession(arg1, sess);
2067
+
2068
+ if (SSL_set_session(ssl, sess) != 1)
2069
+ ossl_raise(eSSLError, "SSL_set_session");
2070
+
2071
+ return arg1;
2072
+ }
2073
+
2074
+ #ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
2075
+ /*
2076
+ * call-seq:
2077
+ * ssl.hostname = hostname -> hostname
2078
+ *
2079
+ * Sets the server hostname used for SNI. This needs to be set before
2080
+ * SSLSocket#connect.
2081
+ */
2082
+ static VALUE
2083
+ ossl_ssl_set_hostname(VALUE self, VALUE arg)
2084
+ {
2085
+ SSL *ssl;
2086
+ char *hostname = NULL;
2087
+
2088
+ GetSSL(self, ssl);
2089
+
2090
+ if (!NIL_P(arg))
2091
+ hostname = StringValueCStr(arg);
2092
+
2093
+ if (!SSL_set_tlsext_host_name(ssl, hostname))
2094
+ ossl_raise(eSSLError, NULL);
2095
+
2096
+ /* for SSLSocket#hostname */
2097
+ rb_ivar_set(self, id_i_hostname, arg);
2098
+
2099
+ return arg;
2100
+ }
2101
+ #endif
2102
+
2103
+ /*
2104
+ * call-seq:
2105
+ * ssl.verify_result => Integer
2106
+ *
2107
+ * Returns the result of the peer certificates verification. See verify(1)
2108
+ * for error values and descriptions.
2109
+ *
2110
+ * If no peer certificate was presented X509_V_OK is returned.
2111
+ */
2112
+ static VALUE
2113
+ ossl_ssl_get_verify_result(VALUE self)
2114
+ {
2115
+ SSL *ssl;
2116
+
2117
+ GetSSL(self, ssl);
2118
+
2119
+ return INT2NUM(SSL_get_verify_result(ssl));
2120
+ }
2121
+
2122
+ /*
2123
+ * call-seq:
2124
+ * ssl.client_ca => [x509name, ...]
2125
+ *
2126
+ * Returns the list of client CAs. Please note that in contrast to
2127
+ * SSLContext#client_ca= no array of X509::Certificate is returned but
2128
+ * X509::Name instances of the CA's subject distinguished name.
2129
+ *
2130
+ * In server mode, returns the list set by SSLContext#client_ca=.
2131
+ * In client mode, returns the list of client CAs sent from the server.
2132
+ */
2133
+ static VALUE
2134
+ ossl_ssl_get_client_ca_list(VALUE self)
2135
+ {
2136
+ SSL *ssl;
2137
+ STACK_OF(X509_NAME) *ca;
2138
+
2139
+ GetSSL(self, ssl);
2140
+
2141
+ ca = SSL_get_client_CA_list(ssl);
2142
+ return ossl_x509name_sk2ary(ca);
2143
+ }
2144
+
2145
+ # ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
2146
+ /*
2147
+ * call-seq:
2148
+ * ssl.npn_protocol => String | nil
2149
+ *
2150
+ * Returns the protocol string that was finally selected by the client
2151
+ * during the handshake.
2152
+ */
2153
+ static VALUE
2154
+ ossl_ssl_npn_protocol(VALUE self)
2155
+ {
2156
+ SSL *ssl;
2157
+ const unsigned char *out;
2158
+ unsigned int outlen;
2159
+
2160
+ GetSSL(self, ssl);
2161
+
2162
+ SSL_get0_next_proto_negotiated(ssl, &out, &outlen);
2163
+ if (!outlen)
2164
+ return Qnil;
2165
+ else
2166
+ return rb_str_new((const char *) out, outlen);
2167
+ }
2168
+ # endif
2169
+
2170
+ # ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
2171
+ /*
2172
+ * call-seq:
2173
+ * ssl.alpn_protocol => String | nil
2174
+ *
2175
+ * Returns the ALPN protocol string that was finally selected by the server
2176
+ * during the handshake.
2177
+ */
2178
+ static VALUE
2179
+ ossl_ssl_alpn_protocol(VALUE self)
2180
+ {
2181
+ SSL *ssl;
2182
+ const unsigned char *out;
2183
+ unsigned int outlen;
2184
+
2185
+ GetSSL(self, ssl);
2186
+
2187
+ SSL_get0_alpn_selected(ssl, &out, &outlen);
2188
+ if (!outlen)
2189
+ return Qnil;
2190
+ else
2191
+ return rb_str_new((const char *) out, outlen);
2192
+ }
2193
+ # endif
2194
+
2195
+ # ifdef HAVE_SSL_GET_SERVER_TMP_KEY
2196
+ /*
2197
+ * call-seq:
2198
+ * ssl.tmp_key => PKey or nil
2199
+ *
2200
+ * Returns the ephemeral key used in case of forward secrecy cipher.
2201
+ */
2202
+ static VALUE
2203
+ ossl_ssl_tmp_key(VALUE self)
2204
+ {
2205
+ SSL *ssl;
2206
+ EVP_PKEY *key;
2207
+
2208
+ GetSSL(self, ssl);
2209
+ if (!SSL_get_server_tmp_key(ssl, &key))
2210
+ return Qnil;
2211
+ return ossl_pkey_new(key);
2212
+ }
2213
+ # endif /* defined(HAVE_SSL_GET_SERVER_TMP_KEY) */
2214
+ #endif /* !defined(OPENSSL_NO_SOCK) */
2215
+
2216
+ #undef rb_intern
2217
+ #define rb_intern(s) rb_intern_const(s)
2218
+ void
2219
+ Init_ossl_ssl(void)
2220
+ {
2221
+ int i;
2222
+ VALUE ary;
2223
+
2224
+ #if 0
2225
+ mOSSL = rb_define_module("OpenSSL");
2226
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
2227
+ rb_mWaitReadable = rb_define_module_under(rb_cIO, "WaitReadable");
2228
+ rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
2229
+ #endif
2230
+
2231
+ ID_callback_state = rb_intern("callback_state");
2232
+
2233
+ ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_vcb_idx",0,0,0);
2234
+ ossl_ssl_ex_store_p = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_store_p",0,0,0);
2235
+ ossl_ssl_ex_ptr_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_ptr_idx",0,0,0);
2236
+
2237
+ /* Document-module: OpenSSL::SSL
2238
+ *
2239
+ * Use SSLContext to set up the parameters for a TLS (former SSL)
2240
+ * connection. Both client and server TLS connections are supported,
2241
+ * SSLSocket and SSLServer may be used in conjunction with an instance
2242
+ * of SSLContext to set up connections.
2243
+ */
2244
+ mSSL = rb_define_module_under(mOSSL, "SSL");
2245
+
2246
+ /* Document-module: OpenSSL::ExtConfig
2247
+ *
2248
+ * This module contains configuration information about the SSL extension,
2249
+ * for example if socket support is enabled, or the host name TLS extension
2250
+ * is enabled. Constants in this module will always be defined, but contain
2251
+ * `true` or `false` values depending on the configuration of your OpenSSL
2252
+ * installation.
2253
+ */
2254
+ mSSLExtConfig = rb_define_module_under(mOSSL, "ExtConfig");
2255
+
2256
+ /* Document-class: OpenSSL::SSL::SSLError
2257
+ *
2258
+ * Generic error class raised by SSLSocket and SSLContext.
2259
+ */
2260
+ eSSLError = rb_define_class_under(mSSL, "SSLError", eOSSLError);
2261
+ eSSLErrorWaitReadable = rb_define_class_under(mSSL, "SSLErrorWaitReadable", eSSLError);
2262
+ rb_include_module(eSSLErrorWaitReadable, rb_mWaitReadable);
2263
+ eSSLErrorWaitWritable = rb_define_class_under(mSSL, "SSLErrorWaitWritable", eSSLError);
2264
+ rb_include_module(eSSLErrorWaitWritable, rb_mWaitWritable);
2265
+
2266
+ Init_ossl_ssl_session();
2267
+
2268
+ /* Document-class: OpenSSL::SSL::SSLContext
2269
+ *
2270
+ * An SSLContext is used to set various options regarding certificates,
2271
+ * algorithms, verification, session caching, etc. The SSLContext is
2272
+ * used to create an SSLSocket.
2273
+ *
2274
+ * All attributes must be set before creating an SSLSocket as the
2275
+ * SSLContext will be frozen afterward.
2276
+ */
2277
+ cSSLContext = rb_define_class_under(mSSL, "SSLContext", rb_cObject);
2278
+ rb_define_alloc_func(cSSLContext, ossl_sslctx_s_alloc);
2279
+ rb_undef_method(cSSLContext, "initialize_copy");
2280
+
2281
+ /*
2282
+ * Context certificate
2283
+ */
2284
+ rb_attr(cSSLContext, rb_intern("cert"), 1, 1, Qfalse);
2285
+
2286
+ /*
2287
+ * Context private key
2288
+ */
2289
+ rb_attr(cSSLContext, rb_intern("key"), 1, 1, Qfalse);
2290
+
2291
+ /*
2292
+ * A certificate or Array of certificates that will be sent to the client.
2293
+ */
2294
+ rb_attr(cSSLContext, rb_intern("client_ca"), 1, 1, Qfalse);
2295
+
2296
+ /*
2297
+ * The path to a file containing a PEM-format CA certificate
2298
+ */
2299
+ rb_attr(cSSLContext, rb_intern("ca_file"), 1, 1, Qfalse);
2300
+
2301
+ /*
2302
+ * The path to a directory containing CA certificates in PEM format.
2303
+ *
2304
+ * Files are looked up by subject's X509 name's hash value.
2305
+ */
2306
+ rb_attr(cSSLContext, rb_intern("ca_path"), 1, 1, Qfalse);
2307
+
2308
+ /*
2309
+ * Maximum session lifetime in seconds.
2310
+ */
2311
+ rb_attr(cSSLContext, rb_intern("timeout"), 1, 1, Qfalse);
2312
+
2313
+ /*
2314
+ * Session verification mode.
2315
+ *
2316
+ * Valid modes are VERIFY_NONE, VERIFY_PEER, VERIFY_CLIENT_ONCE,
2317
+ * VERIFY_FAIL_IF_NO_PEER_CERT and defined on OpenSSL::SSL
2318
+ *
2319
+ * The default mode is VERIFY_NONE, which does not perform any verification
2320
+ * at all.
2321
+ *
2322
+ * See SSL_CTX_set_verify(3) for details.
2323
+ */
2324
+ rb_attr(cSSLContext, rb_intern("verify_mode"), 1, 1, Qfalse);
2325
+
2326
+ /*
2327
+ * Number of CA certificates to walk when verifying a certificate chain.
2328
+ */
2329
+ rb_attr(cSSLContext, rb_intern("verify_depth"), 1, 1, Qfalse);
2330
+
2331
+ /*
2332
+ * A callback for additional certificate verification. The callback is
2333
+ * invoked for each certificate in the chain.
2334
+ *
2335
+ * The callback is invoked with two values. +preverify_ok+ indicates
2336
+ * indicates if the verification was passed (true) or not (false).
2337
+ * +store_context+ is an OpenSSL::X509::StoreContext containing the
2338
+ * context used for certificate verification.
2339
+ *
2340
+ * If the callback returns false, the chain verification is immediately
2341
+ * stopped and a bad_certificate alert is then sent.
2342
+ */
2343
+ rb_attr(cSSLContext, rb_intern("verify_callback"), 1, 1, Qfalse);
2344
+
2345
+ /*
2346
+ * Whether to check the server certificate is valid for the hostname.
2347
+ *
2348
+ * In order to make this work, verify_mode must be set to VERIFY_PEER and
2349
+ * the server hostname must be given by OpenSSL::SSL::SSLSocket#hostname=.
2350
+ */
2351
+ rb_attr(cSSLContext, rb_intern("verify_hostname"), 1, 1, Qfalse);
2352
+
2353
+ /*
2354
+ * An OpenSSL::X509::Store used for certificate verification.
2355
+ */
2356
+ rb_attr(cSSLContext, rb_intern("cert_store"), 1, 1, Qfalse);
2357
+
2358
+ /*
2359
+ * An Array of extra X509 certificates to be added to the certificate
2360
+ * chain.
2361
+ */
2362
+ rb_attr(cSSLContext, rb_intern("extra_chain_cert"), 1, 1, Qfalse);
2363
+
2364
+ /*
2365
+ * A callback invoked when a client certificate is requested by a server
2366
+ * and no certificate has been set.
2367
+ *
2368
+ * The callback is invoked with a Session and must return an Array
2369
+ * containing an OpenSSL::X509::Certificate and an OpenSSL::PKey. If any
2370
+ * other value is returned the handshake is suspended.
2371
+ */
2372
+ rb_attr(cSSLContext, rb_intern("client_cert_cb"), 1, 1, Qfalse);
2373
+
2374
+ #if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
2375
+ /*
2376
+ * A callback invoked when ECDH parameters are required.
2377
+ *
2378
+ * The callback is invoked with the Session for the key exchange, an
2379
+ * flag indicating the use of an export cipher and the keylength
2380
+ * required.
2381
+ *
2382
+ * The callback is deprecated. This does not work with recent versions of
2383
+ * OpenSSL. Use OpenSSL::SSL::SSLContext#ecdh_curves= instead.
2384
+ */
2385
+ rb_attr(cSSLContext, rb_intern("tmp_ecdh_callback"), 1, 1, Qfalse);
2386
+ #endif
2387
+
2388
+ /*
2389
+ * Sets the context in which a session can be reused. This allows
2390
+ * sessions for multiple applications to be distinguished, for example, by
2391
+ * name.
2392
+ */
2393
+ rb_attr(cSSLContext, rb_intern("session_id_context"), 1, 1, Qfalse);
2394
+
2395
+ /*
2396
+ * A callback invoked on a server when a session is proposed by the client
2397
+ * but the session could not be found in the server's internal cache.
2398
+ *
2399
+ * The callback is invoked with the SSLSocket and session id. The
2400
+ * callback may return a Session from an external cache.
2401
+ */
2402
+ rb_attr(cSSLContext, rb_intern("session_get_cb"), 1, 1, Qfalse);
2403
+
2404
+ /*
2405
+ * A callback invoked when a new session was negotiated.
2406
+ *
2407
+ * The callback is invoked with an SSLSocket. If false is returned the
2408
+ * session will be removed from the internal cache.
2409
+ */
2410
+ rb_attr(cSSLContext, rb_intern("session_new_cb"), 1, 1, Qfalse);
2411
+
2412
+ /*
2413
+ * A callback invoked when a session is removed from the internal cache.
2414
+ *
2415
+ * The callback is invoked with an SSLContext and a Session.
2416
+ */
2417
+ rb_attr(cSSLContext, rb_intern("session_remove_cb"), 1, 1, Qfalse);
2418
+
2419
+ #ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
2420
+ rb_define_const(mSSLExtConfig, "HAVE_TLSEXT_HOST_NAME", Qtrue);
2421
+ #else
2422
+ rb_define_const(mSSLExtConfig, "HAVE_TLSEXT_HOST_NAME", Qfalse);
2423
+ #endif
2424
+
2425
+ #ifdef TLS_DH_anon_WITH_AES_256_GCM_SHA384
2426
+ rb_define_const(mSSLExtConfig, "TLS_DH_anon_WITH_AES_256_GCM_SHA384", Qtrue);
2427
+ #else
2428
+ rb_define_const(mSSLExtConfig, "TLS_DH_anon_WITH_AES_256_GCM_SHA384", Qfalse);
2429
+ #endif
2430
+
2431
+ /*
2432
+ * A callback invoked whenever a new handshake is initiated. May be used
2433
+ * to disable renegotiation entirely.
2434
+ *
2435
+ * The callback is invoked with the active SSLSocket. The callback's
2436
+ * return value is irrelevant, normal return indicates "approval" of the
2437
+ * renegotiation and will continue the process. To forbid renegotiation
2438
+ * and to cancel the process, an Error may be raised within the callback.
2439
+ *
2440
+ * === Disable client renegotiation
2441
+ *
2442
+ * When running a server, it is often desirable to disable client
2443
+ * renegotiation entirely. You may use a callback as follows to implement
2444
+ * this feature:
2445
+ *
2446
+ * num_handshakes = 0
2447
+ * ctx.renegotiation_cb = lambda do |ssl|
2448
+ * num_handshakes += 1
2449
+ * raise RuntimeError.new("Client renegotiation disabled") if num_handshakes > 1
2450
+ * end
2451
+ */
2452
+ rb_attr(cSSLContext, rb_intern("renegotiation_cb"), 1, 1, Qfalse);
2453
+ #ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
2454
+ /*
2455
+ * An Enumerable of Strings. Each String represents a protocol to be
2456
+ * advertised as the list of supported protocols for Next Protocol
2457
+ * Negotiation. Supported in OpenSSL 1.0.1 and higher. Has no effect
2458
+ * on the client side. If not set explicitly, the NPN extension will
2459
+ * not be sent by the server in the handshake.
2460
+ *
2461
+ * === Example
2462
+ *
2463
+ * ctx.npn_protocols = ["http/1.1", "spdy/2"]
2464
+ */
2465
+ rb_attr(cSSLContext, rb_intern("npn_protocols"), 1, 1, Qfalse);
2466
+ /*
2467
+ * A callback invoked on the client side when the client needs to select
2468
+ * a protocol from the list sent by the server. Supported in OpenSSL 1.0.1
2469
+ * and higher. The client MUST select a protocol of those advertised by
2470
+ * the server. If none is acceptable, raising an error in the callback
2471
+ * will cause the handshake to fail. Not setting this callback explicitly
2472
+ * means not supporting the NPN extension on the client - any protocols
2473
+ * advertised by the server will be ignored.
2474
+ *
2475
+ * === Example
2476
+ *
2477
+ * ctx.npn_select_cb = lambda do |protocols|
2478
+ * # inspect the protocols and select one
2479
+ * protocols.first
2480
+ * end
2481
+ */
2482
+ rb_attr(cSSLContext, rb_intern("npn_select_cb"), 1, 1, Qfalse);
2483
+ #endif
2484
+
2485
+ #ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
2486
+ /*
2487
+ * An Enumerable of Strings. Each String represents a protocol to be
2488
+ * advertised as the list of supported protocols for Application-Layer
2489
+ * Protocol Negotiation. Supported in OpenSSL 1.0.2 and higher. Has no
2490
+ * effect on the server side. If not set explicitly, the ALPN extension will
2491
+ * not be included in the handshake.
2492
+ *
2493
+ * === Example
2494
+ *
2495
+ * ctx.alpn_protocols = ["http/1.1", "spdy/2", "h2"]
2496
+ */
2497
+ rb_attr(cSSLContext, rb_intern("alpn_protocols"), 1, 1, Qfalse);
2498
+ /*
2499
+ * A callback invoked on the server side when the server needs to select
2500
+ * a protocol from the list sent by the client. Supported in OpenSSL 1.0.2
2501
+ * and higher. The callback must return a protocol of those advertised by
2502
+ * the client. If none is acceptable, raising an error in the callback
2503
+ * will cause the handshake to fail. Not setting this callback explicitly
2504
+ * means not supporting the ALPN extension on the server - any protocols
2505
+ * advertised by the client will be ignored.
2506
+ *
2507
+ * === Example
2508
+ *
2509
+ * ctx.alpn_select_cb = lambda do |protocols|
2510
+ * # inspect the protocols and select one
2511
+ * protocols.first
2512
+ * end
2513
+ */
2514
+ rb_attr(cSSLContext, rb_intern("alpn_select_cb"), 1, 1, Qfalse);
2515
+ #endif
2516
+
2517
+ rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
2518
+ rb_define_alias(cSSLContext, "ssl_timeout=", "timeout=");
2519
+ rb_define_method(cSSLContext, "ssl_version=", ossl_sslctx_set_ssl_version, 1);
2520
+ rb_define_method(cSSLContext, "ciphers", ossl_sslctx_get_ciphers, 0);
2521
+ rb_define_method(cSSLContext, "ciphers=", ossl_sslctx_set_ciphers, 1);
2522
+ rb_define_method(cSSLContext, "ecdh_curves=", ossl_sslctx_set_ecdh_curves, 1);
2523
+ rb_define_method(cSSLContext, "security_level", ossl_sslctx_get_security_level, 0);
2524
+ rb_define_method(cSSLContext, "security_level=", ossl_sslctx_set_security_level, 1);
2525
+
2526
+ rb_define_method(cSSLContext, "setup", ossl_sslctx_setup, 0);
2527
+
2528
+ /*
2529
+ * No session caching for client or server
2530
+ */
2531
+ rb_define_const(cSSLContext, "SESSION_CACHE_OFF", LONG2NUM(SSL_SESS_CACHE_OFF));
2532
+
2533
+ /*
2534
+ * Client sessions are added to the session cache
2535
+ */
2536
+ rb_define_const(cSSLContext, "SESSION_CACHE_CLIENT", LONG2NUM(SSL_SESS_CACHE_CLIENT)); /* doesn't actually do anything in 0.9.8e */
2537
+
2538
+ /*
2539
+ * Server sessions are added to the session cache
2540
+ */
2541
+ rb_define_const(cSSLContext, "SESSION_CACHE_SERVER", LONG2NUM(SSL_SESS_CACHE_SERVER));
2542
+
2543
+ /*
2544
+ * Both client and server sessions are added to the session cache
2545
+ */
2546
+ rb_define_const(cSSLContext, "SESSION_CACHE_BOTH", LONG2NUM(SSL_SESS_CACHE_BOTH)); /* no different than CACHE_SERVER in 0.9.8e */
2547
+
2548
+ /*
2549
+ * Normally the session cache is checked for expired sessions every 255
2550
+ * connections. Since this may lead to a delay that cannot be controlled,
2551
+ * the automatic flushing may be disabled and #flush_sessions can be
2552
+ * called explicitly.
2553
+ */
2554
+ rb_define_const(cSSLContext, "SESSION_CACHE_NO_AUTO_CLEAR", LONG2NUM(SSL_SESS_CACHE_NO_AUTO_CLEAR));
2555
+
2556
+ /*
2557
+ * Always perform external lookups of sessions even if they are in the
2558
+ * internal cache.
2559
+ *
2560
+ * This flag has no effect on clients
2561
+ */
2562
+ rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_LOOKUP", LONG2NUM(SSL_SESS_CACHE_NO_INTERNAL_LOOKUP));
2563
+
2564
+ /*
2565
+ * Never automatically store sessions in the internal store.
2566
+ */
2567
+ rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_STORE", LONG2NUM(SSL_SESS_CACHE_NO_INTERNAL_STORE));
2568
+
2569
+ /*
2570
+ * Enables both SESSION_CACHE_NO_INTERNAL_LOOKUP and
2571
+ * SESSION_CACHE_NO_INTERNAL_STORE.
2572
+ */
2573
+ rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL", LONG2NUM(SSL_SESS_CACHE_NO_INTERNAL));
2574
+
2575
+ rb_define_method(cSSLContext, "session_add", ossl_sslctx_session_add, 1);
2576
+ rb_define_method(cSSLContext, "session_remove", ossl_sslctx_session_remove, 1);
2577
+ rb_define_method(cSSLContext, "session_cache_mode", ossl_sslctx_get_session_cache_mode, 0);
2578
+ rb_define_method(cSSLContext, "session_cache_mode=", ossl_sslctx_set_session_cache_mode, 1);
2579
+ rb_define_method(cSSLContext, "session_cache_size", ossl_sslctx_get_session_cache_size, 0);
2580
+ rb_define_method(cSSLContext, "session_cache_size=", ossl_sslctx_set_session_cache_size, 1);
2581
+ rb_define_method(cSSLContext, "session_cache_stats", ossl_sslctx_get_session_cache_stats, 0);
2582
+ rb_define_method(cSSLContext, "flush_sessions", ossl_sslctx_flush_sessions, -1);
2583
+ rb_define_method(cSSLContext, "options", ossl_sslctx_get_options, 0);
2584
+ rb_define_method(cSSLContext, "options=", ossl_sslctx_set_options, 1);
2585
+
2586
+ ary = rb_ary_new2(numberof(ossl_ssl_method_tab));
2587
+ for (i = 0; i < numberof(ossl_ssl_method_tab); i++) {
2588
+ rb_ary_push(ary, ID2SYM(rb_intern(ossl_ssl_method_tab[i].name)));
2589
+ }
2590
+ rb_obj_freeze(ary);
2591
+ /* The list of available SSL/TLS methods */
2592
+ rb_define_const(cSSLContext, "METHODS", ary);
2593
+
2594
+ /*
2595
+ * Document-class: OpenSSL::SSL::SSLSocket
2596
+ */
2597
+ cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
2598
+ #ifdef OPENSSL_NO_SOCK
2599
+ rb_define_const(mSSLExtConfig, "OPENSSL_NO_SOCK", Qtrue);
2600
+ rb_define_method(cSSLSocket, "initialize", rb_f_notimplement, -1);
2601
+ #else
2602
+ rb_define_const(mSSLExtConfig, "OPENSSL_NO_SOCK", Qfalse);
2603
+ rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
2604
+ rb_define_method(cSSLSocket, "initialize", ossl_ssl_initialize, -1);
2605
+ rb_undef_method(cSSLSocket, "initialize_copy");
2606
+ rb_define_method(cSSLSocket, "connect", ossl_ssl_connect, 0);
2607
+ rb_define_method(cSSLSocket, "connect_nonblock", ossl_ssl_connect_nonblock, -1);
2608
+ rb_define_method(cSSLSocket, "accept", ossl_ssl_accept, 0);
2609
+ rb_define_method(cSSLSocket, "accept_nonblock", ossl_ssl_accept_nonblock, -1);
2610
+ rb_define_method(cSSLSocket, "sysread", ossl_ssl_read, -1);
2611
+ rb_define_private_method(cSSLSocket, "sysread_nonblock", ossl_ssl_read_nonblock, -1);
2612
+ rb_define_method(cSSLSocket, "syswrite", ossl_ssl_write, 1);
2613
+ rb_define_private_method(cSSLSocket, "syswrite_nonblock", ossl_ssl_write_nonblock, -1);
2614
+ rb_define_private_method(cSSLSocket, "stop", ossl_ssl_stop, 0);
2615
+ rb_define_method(cSSLSocket, "cert", ossl_ssl_get_cert, 0);
2616
+ rb_define_method(cSSLSocket, "peer_cert", ossl_ssl_get_peer_cert, 0);
2617
+ rb_define_method(cSSLSocket, "peer_cert_chain", ossl_ssl_get_peer_cert_chain, 0);
2618
+ rb_define_method(cSSLSocket, "ssl_version", ossl_ssl_get_version, 0);
2619
+ rb_define_method(cSSLSocket, "cipher", ossl_ssl_get_cipher, 0);
2620
+ rb_define_method(cSSLSocket, "state", ossl_ssl_get_state, 0);
2621
+ rb_define_method(cSSLSocket, "pending", ossl_ssl_pending, 0);
2622
+ rb_define_method(cSSLSocket, "session_reused?", ossl_ssl_session_reused, 0);
2623
+ /* implementation of OpenSSL::SSL::SSLSocket#session is in lib/openssl/ssl.rb */
2624
+ rb_define_method(cSSLSocket, "session=", ossl_ssl_set_session, 1);
2625
+ rb_define_method(cSSLSocket, "verify_result", ossl_ssl_get_verify_result, 0);
2626
+ rb_define_method(cSSLSocket, "client_ca", ossl_ssl_get_client_ca_list, 0);
2627
+ #ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
2628
+ /* #hostname is defined in lib/openssl/ssl.rb */
2629
+ rb_define_method(cSSLSocket, "hostname=", ossl_ssl_set_hostname, 1);
2630
+ #endif
2631
+ # ifdef HAVE_SSL_GET_SERVER_TMP_KEY
2632
+ rb_define_method(cSSLSocket, "tmp_key", ossl_ssl_tmp_key, 0);
2633
+ # endif
2634
+ # ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
2635
+ rb_define_method(cSSLSocket, "alpn_protocol", ossl_ssl_alpn_protocol, 0);
2636
+ # endif
2637
+ # ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
2638
+ rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
2639
+ # endif
2640
+ #endif
2641
+
2642
+ #define ossl_ssl_def_const(x) rb_define_const(mSSL, #x, LONG2NUM(SSL_##x))
2643
+
2644
+ ossl_ssl_def_const(VERIFY_NONE);
2645
+ ossl_ssl_def_const(VERIFY_PEER);
2646
+ ossl_ssl_def_const(VERIFY_FAIL_IF_NO_PEER_CERT);
2647
+ ossl_ssl_def_const(VERIFY_CLIENT_ONCE);
2648
+ /* Introduce constants included in OP_ALL. These constants are mostly for
2649
+ * unset some bits in OP_ALL such as;
2650
+ * ctx.options = OP_ALL & ~OP_DONT_INSERT_EMPTY_FRAGMENTS
2651
+ */
2652
+ ossl_ssl_def_const(OP_MICROSOFT_SESS_ID_BUG);
2653
+ ossl_ssl_def_const(OP_NETSCAPE_CHALLENGE_BUG);
2654
+ ossl_ssl_def_const(OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG);
2655
+ ossl_ssl_def_const(OP_SSLREF2_REUSE_CERT_TYPE_BUG);
2656
+ ossl_ssl_def_const(OP_MICROSOFT_BIG_SSLV3_BUFFER);
2657
+ ossl_ssl_def_const(OP_MSIE_SSLV2_RSA_PADDING);
2658
+ ossl_ssl_def_const(OP_SSLEAY_080_CLIENT_DH_BUG);
2659
+ ossl_ssl_def_const(OP_TLS_D5_BUG);
2660
+ ossl_ssl_def_const(OP_TLS_BLOCK_PADDING_BUG);
2661
+ ossl_ssl_def_const(OP_DONT_INSERT_EMPTY_FRAGMENTS);
2662
+ ossl_ssl_def_const(OP_ALL);
2663
+ ossl_ssl_def_const(OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
2664
+ ossl_ssl_def_const(OP_SINGLE_ECDH_USE);
2665
+ ossl_ssl_def_const(OP_SINGLE_DH_USE);
2666
+ ossl_ssl_def_const(OP_EPHEMERAL_RSA);
2667
+ ossl_ssl_def_const(OP_CIPHER_SERVER_PREFERENCE);
2668
+ ossl_ssl_def_const(OP_TLS_ROLLBACK_BUG);
2669
+ ossl_ssl_def_const(OP_NO_SSLv2);
2670
+ ossl_ssl_def_const(OP_NO_SSLv3);
2671
+ ossl_ssl_def_const(OP_NO_TLSv1);
2672
+ #if defined(SSL_OP_NO_TLSv1_1)
2673
+ ossl_ssl_def_const(OP_NO_TLSv1_1);
2674
+ #endif
2675
+ #if defined(SSL_OP_NO_TLSv1_2)
2676
+ ossl_ssl_def_const(OP_NO_TLSv1_2);
2677
+ #endif
2678
+ #if defined(SSL_OP_NO_TICKET)
2679
+ ossl_ssl_def_const(OP_NO_TICKET);
2680
+ #endif
2681
+ #if defined(SSL_OP_NO_COMPRESSION)
2682
+ ossl_ssl_def_const(OP_NO_COMPRESSION);
2683
+ #endif
2684
+ ossl_ssl_def_const(OP_PKCS1_CHECK_1);
2685
+ ossl_ssl_def_const(OP_PKCS1_CHECK_2);
2686
+ ossl_ssl_def_const(OP_NETSCAPE_CA_DN_BUG);
2687
+ ossl_ssl_def_const(OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
2688
+
2689
+ sym_exception = ID2SYM(rb_intern("exception"));
2690
+ sym_wait_readable = ID2SYM(rb_intern("wait_readable"));
2691
+ sym_wait_writable = ID2SYM(rb_intern("wait_writable"));
2692
+
2693
+ #define DefIVarID(name) do \
2694
+ id_i_##name = rb_intern("@"#name); while (0)
2695
+
2696
+ DefIVarID(cert_store);
2697
+ DefIVarID(ca_file);
2698
+ DefIVarID(ca_path);
2699
+ DefIVarID(verify_mode);
2700
+ DefIVarID(verify_depth);
2701
+ DefIVarID(verify_callback);
2702
+ DefIVarID(client_ca);
2703
+ DefIVarID(renegotiation_cb);
2704
+ DefIVarID(cert);
2705
+ DefIVarID(key);
2706
+ DefIVarID(extra_chain_cert);
2707
+ DefIVarID(client_cert_cb);
2708
+ DefIVarID(tmp_ecdh_callback);
2709
+ DefIVarID(timeout);
2710
+ DefIVarID(session_id_context);
2711
+ DefIVarID(session_get_cb);
2712
+ DefIVarID(session_new_cb);
2713
+ DefIVarID(session_remove_cb);
2714
+ DefIVarID(npn_select_cb);
2715
+ DefIVarID(npn_protocols);
2716
+ DefIVarID(alpn_protocols);
2717
+ DefIVarID(alpn_select_cb);
2718
+ DefIVarID(servername_cb);
2719
+ DefIVarID(verify_hostname);
2720
+
2721
+ DefIVarID(io);
2722
+ DefIVarID(context);
2723
+ DefIVarID(hostname);
2724
+ }