watobo 0.9.19 → 0.9.20
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +104 -0
- data/bin/nfq_server.rb +8 -20
- data/bin/watobo_gui.rb +8 -20
- data/config/forwarding_proxy.yml +2 -2
- data/lib/watobo.rb +12 -22
- data/lib/watobo/adapters.rb +12 -24
- data/lib/watobo/adapters/data_store.rb +76 -66
- data/lib/watobo/adapters/file/file_store.rb +295 -307
- data/lib/watobo/adapters/session_store.rb +13 -25
- data/lib/watobo/ca.rb +9 -21
- data/lib/watobo/config.rb +205 -217
- data/lib/watobo/constants.rb +8 -20
- data/lib/watobo/core.rb +11 -23
- data/lib/watobo/core/active_check.rb +11 -21
- data/lib/watobo/core/active_checks.rb +57 -69
- data/lib/watobo/core/ca.rb +388 -398
- data/lib/watobo/core/cert_store.rb +42 -54
- data/lib/watobo/core/chat.rb +100 -112
- data/lib/watobo/core/chats.rb +271 -275
- data/lib/watobo/core/client_cert_store.rb +33 -45
- data/lib/watobo/core/conversation.rb +56 -68
- data/lib/watobo/core/cookie.rb +31 -43
- data/lib/watobo/core/finding.rb +74 -86
- data/lib/watobo/core/findings.rb +113 -125
- data/lib/watobo/core/forwarding_proxy.rb +44 -35
- data/lib/watobo/core/fuzz_gen.rb +8 -20
- data/lib/watobo/core/intercept_carver.rb +176 -188
- data/lib/watobo/core/intercept_filter.rb +243 -255
- data/lib/watobo/core/interceptor.rb +106 -118
- data/lib/watobo/core/min_class.rb +12 -24
- data/lib/watobo/core/netfilter_queue.rb +178 -190
- data/lib/watobo/core/ott_cache.rb +152 -148
- data/lib/watobo/core/parameter.rb +53 -58
- data/lib/watobo/core/passive_check.rb +8 -20
- data/lib/watobo/core/passive_checks.rb +56 -68
- data/lib/watobo/core/passive_scanner.rb +54 -66
- data/lib/watobo/core/plugin.rb +19 -31
- data/lib/watobo/core/project.rb +8 -20
- data/lib/watobo/core/proxy.rb +51 -63
- data/lib/watobo/core/request.rb +128 -120
- data/lib/watobo/core/response.rb +59 -61
- data/lib/watobo/core/scanner.rb +8 -20
- data/lib/watobo/core/scanner3.rb +413 -425
- data/lib/watobo/core/scope.rb +91 -103
- data/lib/watobo/core/session.rb +109 -87
- data/lib/watobo/core/sid_cache.rb +106 -118
- data/lib/watobo/core/subscriber.rb +33 -45
- data/lib/watobo/defaults.rb +29 -41
- data/lib/watobo/external/diff/lcs.rb +8 -20
- data/lib/watobo/external/diff/lcs/array.rb +8 -20
- data/lib/watobo/external/diff/lcs/block.rb +8 -20
- data/lib/watobo/external/diff/lcs/callbacks.rb +8 -20
- data/lib/watobo/external/diff/lcs/change.rb +8 -20
- data/lib/watobo/external/diff/lcs/hunk.rb +8 -20
- data/lib/watobo/external/diff/lcs/ldiff.rb +8 -20
- data/lib/watobo/external/diff/lcs/string.rb +8 -20
- data/lib/watobo/externals.rb +14 -26
- data/lib/watobo/framework.rb +12 -24
- data/lib/watobo/framework/create_project.rb +68 -80
- data/lib/watobo/framework/init.rb +8 -20
- data/lib/watobo/framework/init_modules.rb +8 -20
- data/lib/watobo/framework/license_text.rb +36 -48
- data/lib/watobo/framework/load_chat.rb +21 -33
- data/lib/watobo/gui.rb +121 -133
- data/lib/watobo/gui/about_watobo.rb +8 -20
- data/lib/watobo/gui/browser_preview.rb +8 -20
- data/lib/watobo/gui/certificate_dialog.rb +8 -20
- data/lib/watobo/gui/chat_diff.rb +11 -21
- data/lib/watobo/gui/chatviewer_frame.rb +10 -22
- data/lib/watobo/gui/checkboxtree.rb +8 -20
- data/lib/watobo/gui/checks_policy_frame.rb +8 -20
- data/lib/watobo/gui/client_cert_dialog.rb +10 -21
- data/lib/watobo/gui/confirm_scan_dialog.rb +8 -20
- data/lib/watobo/gui/conversation_table.rb +54 -44
- data/lib/watobo/gui/conversation_table_ctrl.rb +215 -227
- data/lib/watobo/gui/conversation_table_ctrl2.rb +385 -393
- data/lib/watobo/gui/csrf_token_dialog.rb +11 -25
- data/lib/watobo/gui/custom_viewer.rb +357 -369
- data/lib/watobo/gui/dashboard.rb +8 -20
- data/lib/watobo/gui/define_scope_frame.rb +8 -20
- data/lib/watobo/gui/differ_frame.rb +223 -235
- data/lib/watobo/gui/edit_comment.rb +8 -20
- data/lib/watobo/gui/edit_scope_dialog.rb +8 -20
- data/lib/watobo/gui/export_dialog.rb +114 -0
- data/lib/watobo/gui/finding_info.rb +9 -21
- data/lib/watobo/gui/findings_tree.rb +8 -20
- data/lib/watobo/gui/full_scan_dialog.rb +8 -20
- data/lib/watobo/gui/fuzzer_gui.rb +8 -20
- data/lib/watobo/gui/goto_url_dialog.rb +78 -90
- data/lib/watobo/gui/hex_viewer.rb +25 -27
- data/lib/watobo/gui/html_viewer.rb +295 -307
- data/lib/watobo/gui/intercept_filter_dialog.rb +196 -208
- data/lib/watobo/gui/interceptor_gui.rb +1046 -1041
- data/lib/watobo/gui/interceptor_settings_dialog.rb +8 -20
- data/lib/watobo/gui/list_box.rb +109 -121
- data/lib/watobo/gui/log_file_viewer.rb +40 -52
- data/lib/watobo/gui/log_viewer.rb +87 -99
- data/lib/watobo/gui/login_wizzard.rb +8 -20
- data/lib/watobo/gui/main_window.rb +34 -33
- data/lib/watobo/gui/manual_request_editor.rb +25 -35
- data/lib/watobo/gui/master_pw_dialog.rb +8 -20
- data/lib/watobo/gui/mixins/gui_settings.rb +37 -49
- data/lib/watobo/gui/page_tree.rb +225 -237
- data/lib/watobo/gui/password_policy_dialog.rb +8 -20
- data/lib/watobo/gui/plugin_board.rb +8 -20
- data/lib/watobo/gui/preferences_dialog.rb +8 -20
- data/lib/watobo/gui/progress_window.rb +8 -20
- data/lib/watobo/gui/project_wizzard.rb +8 -20
- data/lib/watobo/gui/proxy_dialog.rb +117 -85
- data/lib/watobo/gui/quick_scan_dialog.rb +8 -20
- data/lib/watobo/gui/request_builder_frame.rb +125 -122
- data/lib/watobo/gui/request_editor.rb +53 -28
- data/lib/watobo/gui/rewrite_filters_dialog.rb +402 -414
- data/lib/watobo/gui/rewrite_rules_dialog.rb +380 -392
- data/lib/watobo/gui/save_chat_dialog.rb +148 -160
- data/lib/watobo/gui/scanner_settings_dialog.rb +8 -20
- data/lib/watobo/gui/select_chat_dialog.rb +8 -20
- data/lib/watobo/gui/session_management_dialog.rb +8 -20
- data/lib/watobo/gui/sites_tree.rb +118 -22
- data/lib/watobo/gui/status_bar.rb +8 -20
- data/lib/watobo/gui/table_editor.rb +76 -53
- data/lib/watobo/gui/tagless_viewer.rb +10 -21
- data/lib/watobo/gui/templates/plugin.rb +8 -20
- data/lib/watobo/gui/templates/plugin2.rb +99 -111
- data/lib/watobo/gui/templates/plugin_base.rb +152 -164
- data/lib/watobo/gui/text_viewer.rb +8 -20
- data/lib/watobo/gui/transcoder_window.rb +15 -22
- data/lib/watobo/gui/utils/gui_utils.rb +8 -20
- data/lib/watobo/gui/utils/init_icons.rb +94 -106
- data/lib/watobo/gui/utils/load_icons.rb +41 -53
- data/lib/watobo/gui/utils/load_plugins.rb +118 -130
- data/lib/watobo/gui/utils/master_password.rb +76 -88
- data/lib/watobo/gui/utils/save_default_settings.rb +121 -133
- data/lib/watobo/gui/utils/save_project_settings.rb +8 -20
- data/lib/watobo/gui/utils/save_proxy_settings.rb +53 -21
- data/lib/watobo/gui/utils/save_scanner_settings.rb +26 -38
- data/lib/watobo/gui/utils/session_history.rb +120 -132
- data/lib/watobo/gui/workspace_dialog.rb +8 -20
- data/lib/watobo/gui/www_auth_dialog.rb +8 -20
- data/lib/watobo/gui/xml_viewer_frame.rb +8 -20
- data/lib/watobo/http.rb +12 -23
- data/lib/watobo/http/cookies/cookies.rb +63 -70
- data/lib/watobo/http/data/data.rb +56 -64
- data/lib/watobo/http/data/json.rb +51 -0
- data/lib/watobo/http/url/url.rb +46 -58
- data/lib/watobo/http/xml/xml.rb +129 -141
- data/lib/watobo/interceptor.rb +11 -23
- data/lib/watobo/interceptor/proxy.rb +624 -625
- data/lib/watobo/interceptor/transparent.rb +22 -34
- data/lib/watobo/mixins.rb +18 -30
- data/lib/watobo/mixins/check_info.rb +35 -47
- data/lib/watobo/mixins/httpparser.rb +42 -35
- data/lib/watobo/mixins/request_parser.rb +8 -20
- data/lib/watobo/mixins/shapers.rb +484 -477
- data/lib/watobo/mixins/transcoders.rb +8 -20
- data/lib/watobo/parser.rb +9 -21
- data/lib/watobo/parser/html.rb +91 -103
- data/lib/watobo/sockets.rb +11 -23
- data/lib/watobo/sockets/agent.rb +836 -848
- data/lib/watobo/sockets/client_socket.rb +283 -277
- data/lib/watobo/sockets/connection.rb +409 -421
- data/lib/watobo/sockets/http_socket.rb +16 -23
- data/lib/watobo/sockets/ntlm_auth.rb +137 -149
- data/lib/watobo/utils.rb +18 -30
- data/lib/watobo/utils/check_regex.rb +8 -20
- data/lib/watobo/utils/copy_object.rb +8 -20
- data/lib/watobo/utils/crypto.rb +8 -20
- data/lib/watobo/utils/expand_range.rb +31 -43
- data/lib/watobo/utils/export_xml.rb +108 -0
- data/lib/watobo/utils/file_management.rb +8 -20
- data/lib/watobo/utils/hexprint.rb +17 -29
- data/lib/watobo/utils/load_chat.rb +8 -20
- data/lib/watobo/utils/load_icon.rb +8 -20
- data/lib/watobo/{external/ntlm → utils}/ntlm.rb +874 -796
- data/lib/watobo/utils/print_debug.rb +20 -32
- data/lib/watobo/utils/response_builder.rb +98 -110
- data/lib/watobo/utils/response_hash.rb +9 -20
- data/lib/watobo/utils/secure_eval.rb +10 -22
- data/lib/watobo/utils/strings.rb +18 -30
- data/lib/watobo/utils/text2request.rb +12 -20
- data/lib/watobo/utils/url.rb +31 -43
- data/lib/watobo/utils/utf16.rb +22 -0
- data/modules/active/Apache/mod_status.rb +9 -0
- data/modules/active/Apache/multiview.rb +161 -0
- data/modules/active/Flash/crossdomain.rb +9 -0
- data/modules/active/directories/dirwalker.rb +8 -20
- data/modules/active/discovery/fileextensions.rb +10 -22
- data/modules/active/discovery/http_methods.rb +8 -20
- data/modules/active/domino/domino_db.rb +8 -20
- data/modules/active/dotNET/custom_errors.rb +110 -122
- data/modules/active/dotNET/dotnet_files.rb +98 -110
- data/modules/active/fileinclusion/lfi_simple.rb +8 -20
- data/modules/active/jboss/jboss_basic.rb +8 -20
- data/modules/active/sap/business_objects.rb +63 -0
- data/modules/active/sap/its_commands.rb +8 -20
- data/modules/active/sap/its_service_parameter.rb +8 -20
- data/modules/active/sap/its_services.rb +8 -20
- data/modules/active/sap/its_xss.rb +8 -20
- data/modules/active/shell_shock/shell_shock.rb +149 -0
- data/modules/active/siebel/siebel_apps.rb +168 -180
- data/modules/active/sqlinjection/sql_boolean.rb +9 -21
- data/modules/active/sqlinjection/sqli_error.rb +10 -22
- data/modules/active/sqlinjection/sqli_timing.rb +228 -240
- data/modules/active/struts2/default_handler_ognl.rb +114 -126
- data/modules/active/struts2/include_params_ognl.rb +113 -125
- data/modules/active/xml/xml_xxe.rb +122 -127
- data/modules/active/xss/xss_ng.rb +223 -234
- data/modules/active/xss/xss_simple.rb +8 -20
- data/modules/passive/ajax.rb +76 -84
- data/modules/passive/autocomplete.rb +64 -76
- data/modules/passive/cookie_options.rb +8 -20
- data/modules/passive/cookie_xss.rb +9 -21
- data/modules/passive/detect_code.rb +9 -21
- data/modules/passive/detect_fileupload.rb +11 -22
- data/modules/passive/detect_infrastructure.rb +23 -35
- data/modules/passive/detect_one_time_tokens.rb +8 -20
- data/modules/passive/dirindexing.rb +9 -21
- data/modules/passive/disclosure_domino.rb +66 -79
- data/modules/passive/disclosure_emails.rb +9 -21
- data/modules/passive/disclosure_ipaddr.rb +15 -23
- data/modules/passive/filename_as_parameter.rb +8 -20
- data/modules/passive/form_spotter.rb +15 -21
- data/modules/passive/hidden_fields.rb +64 -70
- data/modules/passive/hotspots.rb +13 -22
- data/modules/passive/in_script_parameter.rb +15 -24
- data/modules/passive/multiple_server_headers.rb +8 -20
- data/modules/passive/possible_login.rb +12 -23
- data/modules/passive/redirect_url.rb +10 -22
- data/modules/passive/redirectionz.rb +9 -21
- data/modules/passive/sap-headers.rb +64 -76
- data/modules/passive/xss_dom.rb +10 -21
- data/plugins/catalog/catalog.rb +17 -23
- data/plugins/crawler/crawler.rb +12 -24
- data/plugins/crawler/gui.rb +13 -25
- data/plugins/crawler/gui/auth_frame.rb +278 -290
- data/plugins/crawler/gui/crawler_gui.rb +302 -320
- data/plugins/crawler/gui/general_settings_frame.rb +104 -116
- data/plugins/crawler/gui/hooks_frame.rb +88 -100
- data/plugins/crawler/gui/scope_frame.rb +58 -70
- data/plugins/crawler/gui/settings_tabbook.rb +46 -58
- data/plugins/crawler/gui/status_frame.rb +67 -78
- data/plugins/crawler/lib/bags.rb +26 -38
- data/plugins/crawler/lib/constants.rb +19 -31
- data/plugins/crawler/lib/engine.rb +505 -508
- data/plugins/crawler/lib/grabber.rb +77 -87
- data/plugins/crawler/lib/status.rb +82 -0
- data/plugins/crawler/lib/uri_mp.rb +20 -32
- data/plugins/filefinder/dbs/siebel_paths.txt +1118 -0
- data/plugins/filefinder/dbs/subs-big.lst +31986 -0
- data/plugins/filefinder/filefinder.rb +13 -23
- data/plugins/sqlmap/bin/test.rb +86 -98
- data/plugins/sqlmap/gui.rb +12 -24
- data/plugins/sqlmap/gui/main.rb +226 -238
- data/plugins/sqlmap/gui/options_frame.rb +105 -117
- data/plugins/sqlmap/lib/sqlmap_ctrl.rb +103 -115
- data/plugins/sqlmap/sqlmap.rb +10 -22
- data/plugins/sslchecker/cli/sslchecker_cli.rb +8 -20
- data/plugins/sslchecker/gui/cipher_table.rb +252 -264
- data/plugins/sslchecker/gui/gui.rb +267 -276
- data/plugins/sslchecker/gui/sslchecker.rb +12 -24
- data/plugins/sslchecker/lib/check.rb +172 -80
- data/plugins/wshell/gui/main.rb +115 -127
- data/plugins/wshell/lib/core.rb +85 -97
- data/plugins/wshell/wshell.rb +19 -31
- metadata +14 -6
- data/.yardopts +0 -24
data/lib/watobo/constants.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
|
-
|
1
|
+
#.
|
2
2
|
# constants.rb
|
3
|
-
|
4
|
-
# Copyright
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation version 2 of the License.
|
12
|
-
#
|
13
|
-
# WATOBO is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with WATOBO; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
# .
|
3
|
+
#.
|
4
|
+
# Copyright 2014 by siberas, http://www.siberas.de
|
5
|
+
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
6
|
+
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
7
|
+
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
8
|
+
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
9
|
+
|
22
10
|
$debug_project = false
|
23
11
|
$debug_active_check = false
|
24
12
|
$debug_scanner = false
|
data/lib/watobo/core.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
|
-
|
1
|
+
#.
|
2
2
|
# core.rb
|
3
|
-
|
4
|
-
# Copyright
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# WATOBO is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with WATOBO; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
# .
|
22
|
-
%w( subscriber client_cert_store sid_cache ott_cache parameter conversation chat findings chats active_checks passive_checks scope passive_scanner scanner3 finding project scanner proxy session fuzz_gen interceptor passive_check active_check cookie request response intercept_filter intercept_carver plugin forwarding_proxy cert_store netfilter_queue ).each do |lib|
|
23
|
-
require File.join( "watobo", "core", lib)
|
24
|
-
end
|
3
|
+
#.
|
4
|
+
# Copyright 2014 by siberas, http://www.siberas.de
|
5
|
+
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
6
|
+
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
7
|
+
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
8
|
+
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
9
|
+
|
10
|
+
%w( subscriber client_cert_store sid_cache ott_cache parameter conversation chat findings chats active_checks passive_checks scope passive_scanner scanner3 finding project scanner proxy session fuzz_gen interceptor passive_check active_check cookie request response intercept_filter intercept_carver plugin forwarding_proxy cert_store netfilter_queue ).each do |lib|
|
11
|
+
require File.join( "watobo", "core", lib)
|
12
|
+
end
|
@@ -1,24 +1,12 @@
|
|
1
|
-
|
1
|
+
#.
|
2
2
|
# active_check.rb
|
3
|
-
|
4
|
-
# Copyright
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation version 2 of the License.
|
12
|
-
#
|
13
|
-
# WATOBO is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with WATOBO; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
# .
|
3
|
+
#.
|
4
|
+
# Copyright 2014 by siberas, http://www.siberas.de
|
5
|
+
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
6
|
+
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
7
|
+
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
8
|
+
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
9
|
+
|
22
10
|
# @private
|
23
11
|
module Watobo#:nodoc: all
|
24
12
|
class ActiveCheck < Watobo::Session # Base Class for Passive Checks
|
@@ -93,7 +81,9 @@ module Watobo#:nodoc: all
|
|
93
81
|
id_string = (Time.now.to_i + rand(10000)).to_s
|
94
82
|
end
|
95
83
|
#
|
96
|
-
new_details
|
84
|
+
unless new_details.has_key? :fid
|
85
|
+
new_details[:fid] = Digest::MD5.hexdigest(id_string)
|
86
|
+
end
|
97
87
|
|
98
88
|
puts new_details[:fid] if $DEBUG
|
99
89
|
|
@@ -1,73 +1,61 @@
|
|
1
|
-
|
1
|
+
#.
|
2
2
|
# active_checks.rb
|
3
|
-
|
4
|
-
# Copyright
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# WATOBO is free software; you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation version 2 of the License.
|
12
|
-
#
|
13
|
-
# WATOBO is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with WATOBO; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
# .
|
22
|
-
# @private
|
23
|
-
module Watobo#:nodoc: all
|
24
|
-
class ActiveModules
|
25
|
-
@checks = []
|
26
|
-
def self.each(&block)
|
27
|
-
if block_given?
|
28
|
-
@checks.map{|c| yield c }
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.to_a
|
34
|
-
@checks
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.length
|
38
|
-
@checks.length
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.init
|
42
|
-
@checks = []
|
43
|
-
active_path = Watobo.active_module_path
|
44
|
-
Dir["#{active_path}/**"].each do |group|
|
45
|
-
if File.ftype(group) == "directory"
|
46
|
-
Dir["#{group}/*.rb"].each do |mod_file|
|
47
|
-
begin
|
48
|
-
# module_file = File.join(active_path, group, modules)
|
49
|
-
mod = File.basename(mod_file)
|
50
|
-
group_name = File.basename(group)# notify(:logger, LOG_DEBUG, "loading module: #{module_file}")
|
51
|
-
|
52
|
-
require mod_file
|
53
|
-
|
54
|
-
group_class = group_name.slice(0..0).upcase + group_name.slice(1..-1).downcase
|
55
|
-
#
|
56
|
-
module_class = mod.slice(0..0).upcase + mod.slice(1..-1).downcase
|
57
|
-
module_class.sub!(".rb","")
|
3
|
+
#.
|
4
|
+
# Copyright 2014 by siberas, http://www.siberas.de
|
5
|
+
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
6
|
+
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
7
|
+
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
8
|
+
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
58
9
|
|
10
|
+
# @private
|
11
|
+
module Watobo#:nodoc: all
|
12
|
+
class ActiveModules
|
13
|
+
@checks = []
|
14
|
+
def self.each(&block)
|
15
|
+
if block_given?
|
16
|
+
@checks.map{|c| yield c }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.to_a
|
22
|
+
@checks
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.length
|
26
|
+
@checks.length
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.init
|
30
|
+
@checks = []
|
31
|
+
active_path = Watobo.active_module_path
|
32
|
+
Dir["#{active_path}/**"].each do |group|
|
33
|
+
if File.ftype(group) == "directory"
|
34
|
+
Dir["#{group}/*.rb"].each do |mod_file|
|
35
|
+
begin
|
36
|
+
# module_file = File.join(active_path, group, modules)
|
37
|
+
mod = File.basename(mod_file)
|
38
|
+
group_name = File.basename(group)# notify(:logger, LOG_DEBUG, "loading module: #{module_file}")
|
39
|
+
|
40
|
+
require mod_file
|
41
|
+
|
42
|
+
group_class = group_name.slice(0..0).upcase + group_name.slice(1..-1).downcase
|
43
|
+
#
|
44
|
+
module_class = mod.slice(0..0).upcase + mod.slice(1..-1).downcase
|
45
|
+
module_class.sub!(".rb","")
|
46
|
+
|
59
47
|
ac = Watobo::Modules::Active.const_get(group_class).const_get(module_class)
|
60
|
-
print "."
|
61
|
-
|
62
|
-
@checks << ac
|
63
|
-
rescue => bang
|
64
|
-
puts bang
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
@checks
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
48
|
+
print "."
|
49
|
+
|
50
|
+
@checks << ac
|
51
|
+
rescue => bang
|
52
|
+
puts bang
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@checks
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
73
61
|
end
|
data/lib/watobo/core/ca.rb
CHANGED
@@ -1,31 +1,19 @@
|
|
1
|
-
|
1
|
+
#.
|
2
2
|
# ca.rb
|
3
|
-
|
4
|
-
# Copyright
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation version 2 of the License.
|
12
|
-
#
|
13
|
-
# WATOBO is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with WATOBO; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
# .
|
3
|
+
#.
|
4
|
+
# Copyright 2014 by siberas, http://www.siberas.de
|
5
|
+
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
6
|
+
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
7
|
+
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
8
|
+
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
9
|
+
|
22
10
|
# @private
|
23
|
-
module Watobo#:nodoc: all
|
24
|
-
module CA
|
25
|
-
@cadir = File.join(Watobo.working_directory, "CA")
|
26
|
-
@crl_dir= File.join(@cadir, "crl")
|
27
|
-
@hostname = %x('hostname').strip
|
28
|
-
@hostname = "watobo" if @hostname.empty?
|
11
|
+
module Watobo#:nodoc: all
|
12
|
+
module CA
|
13
|
+
@cadir = File.join(Watobo.working_directory, "CA")
|
14
|
+
@crl_dir= File.join(@cadir, "crl")
|
15
|
+
@hostname = %x('hostname').strip
|
16
|
+
@hostname = "watobo" if @hostname.empty?
|
29
17
|
@domain = "#{@hostname}.watobo.local"
|
30
18
|
|
31
19
|
def self.dh_key
|
@@ -40,381 +28,383 @@ module Watobo#:nodoc: all
|
|
40
28
|
end
|
41
29
|
OpenSSL::PKey::DH.new(File.read(dh_filename))
|
42
30
|
end
|
43
|
-
|
44
|
-
def self.ca_ready?
|
45
|
-
return false unless File.exists? @ca_config[:CA_dir]
|
46
|
-
return false unless File.exists? @ca_config[:private_dir]
|
47
|
-
return false unless File.exists? @ca_config[:fake_certs_dir]
|
48
|
-
return false unless File.exists? @ca_config[:crl_dir]
|
49
|
-
return false unless File.exists? @ca_config[:csr_dir]
|
50
|
-
return true
|
51
|
-
end
|
52
|
-
|
53
|
-
# return 0
|
54
|
-
@ca_config = {
|
55
|
-
:CA_dir => @cadir,
|
56
|
-
# need a password here .... mmmhhhhh ...,
|
57
|
-
:password => "watobo",
|
58
|
-
|
59
|
-
:keypair_file => File.join(@cadir, "private/cakeypair.pem"),
|
60
|
-
:cert_file => File.join(@cadir, "cacert.pem"),
|
61
|
-
:serial_file => File.join(@cadir, "serial"),
|
62
|
-
:fake_certs_dir => File.join(@cadir, "fake_certs"),
|
63
|
-
:new_keypair_dir => File.join(@cadir, "private/keypair_backup"),
|
64
|
-
:csr_dir => File.join(@cadir, "csr"),
|
65
|
-
:crl_dir => File.join(@cadir, 'crl'),
|
66
|
-
:private_dir => File.join(@cadir, 'private'), #, 0700
|
67
|
-
|
68
|
-
:ca_cert_days => 5 * 365, # five years
|
69
|
-
:ca_rsa_key_length => 2048,
|
70
|
-
|
71
|
-
:cert_days => 365, # one year
|
72
|
-
:cert_key_length_min => 1024,
|
73
|
-
:cert_key_length_max => 2048,
|
74
|
-
|
75
|
-
:crl_file => File.join(@crl_dir, "#{@hostname}.crl"),
|
76
|
-
:crl_pem_file => File.join(@crl_dir, "#{@hostname}.pem"),
|
77
|
-
:crl_days => 14,
|
78
|
-
:name => [
|
79
|
-
['C', 'DE', OpenSSL::ASN1::PRINTABLESTRING],
|
31
|
+
|
32
|
+
def self.ca_ready?
|
33
|
+
return false unless File.exists? @ca_config[:CA_dir]
|
34
|
+
return false unless File.exists? @ca_config[:private_dir]
|
35
|
+
return false unless File.exists? @ca_config[:fake_certs_dir]
|
36
|
+
return false unless File.exists? @ca_config[:crl_dir]
|
37
|
+
return false unless File.exists? @ca_config[:csr_dir]
|
38
|
+
return true
|
39
|
+
end
|
40
|
+
|
41
|
+
# return 0
|
42
|
+
@ca_config = {
|
43
|
+
:CA_dir => @cadir,
|
44
|
+
# need a password here .... mmmhhhhh ...,
|
45
|
+
:password => "watobo",
|
46
|
+
|
47
|
+
:keypair_file => File.join(@cadir, "private/cakeypair.pem"),
|
48
|
+
:cert_file => File.join(@cadir, "cacert.pem"),
|
49
|
+
:serial_file => File.join(@cadir, "serial"),
|
50
|
+
:fake_certs_dir => File.join(@cadir, "fake_certs"),
|
51
|
+
:new_keypair_dir => File.join(@cadir, "private/keypair_backup"),
|
52
|
+
:csr_dir => File.join(@cadir, "csr"),
|
53
|
+
:crl_dir => File.join(@cadir, 'crl'),
|
54
|
+
:private_dir => File.join(@cadir, 'private'), #, 0700
|
55
|
+
|
56
|
+
:ca_cert_days => 5 * 365, # five years
|
57
|
+
:ca_rsa_key_length => 2048,
|
58
|
+
|
59
|
+
:cert_days => 365, # one year
|
60
|
+
:cert_key_length_min => 1024,
|
61
|
+
:cert_key_length_max => 2048,
|
62
|
+
|
63
|
+
:crl_file => File.join(@crl_dir, "#{@hostname}.crl"),
|
64
|
+
:crl_pem_file => File.join(@crl_dir, "#{@hostname}.pem"),
|
65
|
+
:crl_days => 14,
|
66
|
+
:name => [
|
67
|
+
['C', 'DE', OpenSSL::ASN1::PRINTABLESTRING],
|
80
68
|
#['O', @domain, OpenSSL::ASN1::UTF8STRING],
|
81
|
-
['O', "WATOBO", OpenSSL::ASN1::UTF8STRING],
|
69
|
+
['O', "WATOBO", OpenSSL::ASN1::UTF8STRING],
|
82
70
|
# ['OU', @hostname, OpenSSL::ASN1::UTF8STRING],
|
83
|
-
['OU', "WATOBO CA", OpenSSL::ASN1::UTF8STRING]
|
84
|
-
]
|
85
|
-
}
|
86
|
-
|
87
|
-
unless Watobo::CA.ca_ready? then
|
88
|
-
Dir.mkdir(@ca_config[:CA_dir])
|
89
|
-
Dir.mkdir @ca_config[:private_dir]
|
90
|
-
Dir.mkdir @ca_config[:fake_certs_dir]
|
91
|
-
Dir.mkdir @ca_config[:crl_dir]
|
92
|
-
Dir.mkdir @ca_config[:csr_dir]
|
93
|
-
|
94
|
-
File.open @ca_config[:serial_file], 'w' do |f| f << '1' end
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
cert.
|
108
|
-
cert.
|
109
|
-
cert.
|
110
|
-
cert.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
ef
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
ef.create_extension("
|
120
|
-
ef.create_extension("
|
121
|
-
ef.create_extension("
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
fh.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
71
|
+
['OU', "WATOBO CA", OpenSSL::ASN1::UTF8STRING]
|
72
|
+
]
|
73
|
+
}
|
74
|
+
|
75
|
+
unless Watobo::CA.ca_ready? then
|
76
|
+
Dir.mkdir(@ca_config[:CA_dir])
|
77
|
+
Dir.mkdir @ca_config[:private_dir]
|
78
|
+
Dir.mkdir @ca_config[:fake_certs_dir]
|
79
|
+
Dir.mkdir @ca_config[:crl_dir]
|
80
|
+
Dir.mkdir @ca_config[:csr_dir]
|
81
|
+
|
82
|
+
#File.open @ca_config[:serial_file], 'w' do |f| f << '1' end
|
83
|
+
File.open @ca_config[:serial_file], 'w' do |f| f << "#{Time.now.to_i.to_s(16)}" end
|
84
|
+
|
85
|
+
#print "Generating CA keypair ..."
|
86
|
+
#puts " - rsa_key_length: " + @ca_config[:ca_rsa_key_length].to_s
|
87
|
+
keypair = OpenSSL::PKey::RSA.new(@ca_config[:ca_rsa_key_length])
|
88
|
+
#puts "done!"
|
89
|
+
|
90
|
+
#print "Create Certificate ..."
|
91
|
+
cert = OpenSSL::X509::Certificate.new
|
92
|
+
#puts "done!"
|
93
|
+
name = @ca_config[:name].dup << ['CN', 'Watobo']
|
94
|
+
|
95
|
+
cert.subject = cert.issuer = OpenSSL::X509::Name.new(name)
|
96
|
+
cert.not_before = Time.now - 24 * 60 * 60
|
97
|
+
cert.not_after = Time.now + @ca_config[:ca_cert_days] * 24 * 60 * 60
|
98
|
+
cert.public_key = keypair.public_key
|
99
|
+
# cert.serial = 0x0
|
100
|
+
cert.serial = Time.now.to_i
|
101
|
+
cert.version = 2 # X509v3
|
102
|
+
# puts "Init ExtensionFactory ..."
|
103
|
+
ef = OpenSSL::X509::ExtensionFactory.new
|
104
|
+
ef.subject_certificate = cert
|
105
|
+
ef.issuer_certificate = cert
|
106
|
+
cert.extensions = [
|
107
|
+
ef.create_extension("basicConstraints","CA:TRUE", true),
|
108
|
+
# ef.create_extension("nsComment","Ruby/OpenSSL Generated Certificate"),
|
109
|
+
ef.create_extension("nsComment","WATOBO CA"),
|
110
|
+
ef.create_extension("subjectKeyIdentifier", "hash"),
|
111
|
+
ef.create_extension("keyUsage", "cRLSign,keyCertSign", true),
|
112
|
+
]
|
113
|
+
cert.add_extension ef.create_extension("authorityKeyIdentifier",
|
114
|
+
"keyid:always,issuer:always")
|
115
|
+
# puts "Sign Certificate ..."
|
116
|
+
cert.sign keypair, OpenSSL::Digest::SHA1.new
|
117
|
+
|
118
|
+
cb = proc do @ca_config[:password] end
|
119
|
+
keypair_export = keypair.export OpenSSL::Cipher::DES.new(:EDE3, :CBC),
|
120
|
+
&cb
|
121
|
+
|
122
|
+
#puts "Writing keypair to #{@ca_config[:keypair_file]}"
|
123
|
+
begin
|
124
|
+
fh = File.open(@ca_config[:keypair_file], "w+")
|
125
|
+
|
126
|
+
fh.puts keypair_export
|
127
|
+
fh.close
|
128
|
+
rescue => bang
|
129
|
+
puts "! Could not write keypair"
|
130
|
+
puts bang
|
131
|
+
end
|
132
|
+
|
133
|
+
#puts "Writing cert to #{@ca_config[:cert_file]}"
|
134
|
+
File.open @ca_config[:cert_file], "w", 0644 do |f|
|
135
|
+
f << cert.to_pem
|
136
|
+
end
|
137
|
+
|
148
138
|
puts "Done generating certificate for #{cert.subject}"
|
149
139
|
puts ">> create DH key ..."
|
150
|
-
dh_key
|
151
|
-
else
|
152
|
-
#puts "Open Cert File ..."
|
153
|
-
raw = File.read @ca_config[:cert_file] # DER- or PEM-encoded
|
154
|
-
cert = OpenSSL::X509::Certificate.new raw
|
155
|
-
# puts cert
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
def self.create_cert(cert_config)
|
160
|
-
# puts " ... keypair ..."
|
161
|
-
cert_keypair = create_key(cert_config)
|
162
|
-
# puts "... csr ..."
|
163
|
-
cert_csr = create_csr(cert_config, cert_keypair)
|
164
|
-
# puts "... signing ..."
|
165
|
-
signed_cert = sign_cert(cert_config, cert_keypair, cert_csr)
|
166
|
-
return signed_cert, cert_keypair
|
167
|
-
end
|
168
|
-
|
169
|
-
##
|
170
|
-
# Creates a new RSA key from +cert_config+.
|
171
|
-
|
172
|
-
def self.create_key(cert_config)
|
173
|
-
#passwd_cb = nil
|
174
|
-
target = cert_config[:hostname] || cert_config[:user]
|
175
|
-
# puts target
|
176
|
-
dest = @ca_config[:fake_certs_dir]
|
177
|
-
# puts dest
|
178
|
-
keypair_file = File.join(dest, (target + "_keypair.pem"))
|
179
|
-
keypair_file.gsub!(/\*/,"_")
|
180
|
-
|
181
|
-
return keypair_file if File.exist? keypair_file
|
182
|
-
|
183
|
-
#puts "create_key: #{keypair_file}"
|
184
|
-
begin
|
185
|
-
Dir.mkdir dest #, 0700
|
186
|
-
rescue Errno::EEXIST
|
187
|
-
# puts "directory exists"
|
188
|
-
end
|
189
|
-
|
190
|
-
if not File.exists?(keypair_file) then
|
191
|
-
#puts "Generating RSA keypair" if $DEBUG
|
192
|
-
keypair = OpenSSL::PKey::RSA.new 1024
|
193
|
-
# puts keypair.to_pem.class
|
194
|
-
|
195
|
-
if cert_config[:password].nil? then
|
196
|
-
# puts "no password for cert"
|
197
|
-
# puts "Writing keypair to #{keypair_file}" if $DEBUG
|
198
|
-
begin
|
199
|
-
dummy = keypair.to_pem.split("\n")
|
200
|
-
dummy.each do |line|
|
201
|
-
line.strip!
|
202
|
-
end
|
203
|
-
fh = File.open( keypair_file, "wb" )
|
204
|
-
fh.write dummy.join("\n")
|
205
|
-
fh.close
|
206
|
-
rescue => bang
|
207
|
-
puts "! Could not write keypair"
|
208
|
-
puts bang
|
209
|
-
puts bang.backtrace
|
210
|
-
end
|
211
|
-
else
|
212
|
-
# passwd_cb = proc do cert_config[:password] end
|
213
|
-
keypair_export = keypair.export OpenSSL::Cipher::DES.new(:EDE3, :CBC), cert_config[:password]
|
214
|
-
|
215
|
-
# puts "Writing keypair to #{keypair_file}" if $DEBUG
|
216
|
-
#File.open keypair_file, "w" do |f|
|
217
|
-
# f << keypair_export
|
218
|
-
#end
|
219
|
-
begin
|
220
|
-
fh = File.open( keypair_file, "w" )
|
221
|
-
fh.puts keypair_export
|
222
|
-
fh.close
|
223
|
-
rescue => bang
|
224
|
-
|
225
|
-
puts "! Could not write keypair"
|
226
|
-
puts bang
|
227
|
-
puts bang.backtrace
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
231
|
-
end
|
232
|
-
return keypair_file
|
233
|
-
end
|
234
|
-
|
235
|
-
##
|
236
|
-
# Signs the certificate described in +cert_config+ and
|
237
|
-
# +csr_file+, saving it to +cert_file+.
|
238
|
-
|
239
|
-
def self.sign_cert(cert_config, cert_file, csr_file)
|
240
|
-
|
241
|
-
target = cert_config[:hostname] || cert_config[:user]
|
242
|
-
dest = @ca_config[:fake_certs_dir]
|
243
|
-
cert_file = File.join dest, "#{target}_cert.pem"
|
244
|
-
cert_file.gsub!(/\*/,"_")
|
245
|
-
return cert_file if File.exist? cert_file
|
246
|
-
|
247
|
-
csr = OpenSSL::X509::Request.new File.read(csr_file)
|
248
|
-
|
249
|
-
raise "CSR sign verification failed." unless csr.verify csr.public_key
|
250
|
-
|
251
|
-
if csr.public_key.n.num_bits < @ca_config[:cert_key_length_min] then
|
252
|
-
raise "Key length too short"
|
253
|
-
end
|
254
|
-
|
255
|
-
if csr.public_key.n.num_bits > @ca_config[:cert_key_length_max] then
|
256
|
-
raise "Key length too long"
|
257
|
-
end
|
258
|
-
|
259
|
-
if csr.subject.to_a[0, @ca_config[:name].size] != @ca_config[:name] then
|
260
|
-
raise "DN does not match"
|
261
|
-
end
|
262
|
-
|
263
|
-
# Only checks signature here. You must verify CSR according to your
|
264
|
-
# CP/CPS.
|
265
|
-
|
266
|
-
# CA setup
|
267
|
-
|
268
|
-
puts "Reading CA cert from #{@ca_config[:cert_file]}" if $DEBUG
|
269
|
-
ca = OpenSSL::X509::Certificate.new File.read(@ca_config[:cert_file])
|
270
|
-
|
271
|
-
puts "Reading CA keypair from #{@ca_config[:keypair_file]}" if $DEBUG
|
272
|
-
ca_keypair = OpenSSL::PKey::RSA.new File.read(@ca_config[:keypair_file]),
|
273
|
-
@ca_config[:password]
|
274
|
-
|
275
|
-
serial = File.read(@ca_config[:serial_file]).chomp.hex
|
276
|
-
File.open @ca_config[:serial_file], "w" do |f|
|
277
|
-
f << "%04X" % (serial + 1)
|
278
|
-
end
|
279
|
-
|
280
|
-
puts "Generating cert" if $DEBUG
|
281
|
-
|
282
|
-
cert = OpenSSL::X509::Certificate.new
|
283
|
-
from = Time.now
|
284
|
-
cert.subject = csr.subject
|
285
|
-
cert.issuer = ca.subject
|
286
|
-
cert.not_before = from
|
287
|
-
cert.not_after = from + @ca_config[:cert_days] * 24 * 60 * 60
|
288
|
-
cert.public_key = csr.public_key
|
289
|
-
cert.serial = serial
|
290
|
-
cert.version = 2 # X509v3
|
291
|
-
|
292
|
-
basic_constraint = nil
|
293
|
-
key_usage = []
|
294
|
-
ext_key_usage = []
|
295
|
-
|
296
|
-
case cert_config[:type]
|
297
|
-
when "ca" then
|
298
|
-
basic_constraint = "CA:TRUE"
|
299
|
-
key_usage << "cRLSign" << "keyCertSign"
|
300
|
-
when "terminalsubca" then
|
301
|
-
basic_constraint = "CA:TRUE,pathlen:0"
|
302
|
-
key_usage << "cRLSign" << "keyCertSign"
|
303
|
-
when "server" then
|
304
|
-
basic_constraint = "CA:FALSE"
|
305
|
-
key_usage << "digitalSignature" << "keyEncipherment"
|
306
|
-
ext_key_usage << "serverAuth"
|
307
|
-
when "ocsp" then
|
308
|
-
basic_constraint = "CA:FALSE"
|
309
|
-
key_usage << "nonRepudiation" << "digitalSignature"
|
310
|
-
ext_key_usage << "serverAuth" << "OCSPSigning"
|
311
|
-
when "client" then
|
312
|
-
basic_constraint = "CA:FALSE"
|
313
|
-
key_usage << "nonRepudiation" << "digitalSignature" << "keyEncipherment"
|
314
|
-
ext_key_usage << "clientAuth" << "emailProtection"
|
315
|
-
else
|
316
|
-
raise "unknonw cert type \"#{cert_config[:type]}\""
|
317
|
-
end
|
318
|
-
|
319
|
-
ef = OpenSSL::X509::ExtensionFactory.new
|
320
|
-
ef.subject_certificate = cert
|
321
|
-
ef.issuer_certificate = ca
|
322
|
-
ex = []
|
323
|
-
ex << ef.create_extension("basicConstraints", basic_constraint, true)
|
324
|
-
ex << ef.create_extension("nsComment",
|
325
|
-
"Ruby/OpenSSL Generated Certificate")
|
326
|
-
ex << ef.create_extension("subjectKeyIdentifier", "hash")
|
327
|
-
#ex << ef.create_extension("nsCertType", "client,email")
|
328
|
-
unless key_usage.empty? then
|
329
|
-
ex << ef.create_extension("keyUsage", key_usage.join(","))
|
330
|
-
end
|
331
|
-
#ex << ef.create_extension("authorityKeyIdentifier",
|
332
|
-
# "keyid:always,issuer:always")
|
333
|
-
#ex << ef.create_extension("authorityKeyIdentifier", "keyid:always")
|
334
|
-
unless ext_key_usage.empty? then
|
335
|
-
ex << ef.create_extension("extendedKeyUsage", ext_key_usage.join(","))
|
336
|
-
end
|
337
|
-
|
338
|
-
if @ca_config[:cdp_location] then
|
339
|
-
ex << ef.create_extension("crlDistributionPoints",
|
340
|
-
@ca_config[:cdp_location])
|
341
|
-
end
|
342
|
-
|
343
|
-
if @ca_config[:ocsp_location] then
|
344
|
-
ex << ef.create_extension("authorityInfoAccess",
|
345
|
-
"OCSP;" << @ca_config[:ocsp_location])
|
346
|
-
end
|
347
|
-
# cert.extensions = ex
|
348
|
-
cert.sign ca_keypair, OpenSSL::Digest::SHA1.new
|
349
|
-
|
350
|
-
# backup_cert_file = @ca_config[:backup_certs_dir] + "/cert_#{cert.serial}.pem"
|
351
|
-
# puts "Writing backup cert to #{backup_cert_file}" if $DEBUG
|
352
|
-
# File.open backup_cert_file, "w", 0644 do |f|
|
353
|
-
# f << cert.to_pem
|
354
|
-
# end
|
355
|
-
|
356
|
-
# Write cert
|
357
|
-
puts "Writing cert to #{cert_file}"
|
358
|
-
File.open cert_file, "w", 0644 do |f|
|
359
|
-
f << cert.to_pem
|
360
|
-
end
|
361
|
-
|
362
|
-
return cert_file
|
363
|
-
end
|
364
|
-
|
365
|
-
##
|
366
|
-
# Creates a new Certificate Signing Request for the keypair in
|
367
|
-
# +keypair_file+, generating and saving new keypair if nil.
|
368
|
-
|
369
|
-
def self.create_csr(cert_config, keypair_file = nil)
|
370
|
-
keypair = nil
|
371
|
-
target = cert_config[:hostname] || cert_config[:user]
|
372
|
-
dest = @ca_config[:csr_dir]
|
373
|
-
csr_file = File.join dest, "csr_#{target}.pem"
|
374
|
-
csr_file.gsub!(/\*/,"_")
|
375
|
-
|
376
|
-
return csr_file if File.exist? csr_file
|
377
|
-
|
378
|
-
name = @ca_config[:name].dup
|
379
|
-
case cert_config[:type]
|
380
|
-
when 'server' then
|
381
|
-
# name << ['OU', 'Watobo CA']
|
140
|
+
dh_key
|
141
|
+
else
|
142
|
+
#puts "Open Cert File ..."
|
143
|
+
raw = File.read @ca_config[:cert_file] # DER- or PEM-encoded
|
144
|
+
cert = OpenSSL::X509::Certificate.new raw
|
145
|
+
# puts cert
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.create_cert(cert_config)
|
150
|
+
# puts " ... keypair ..."
|
151
|
+
cert_keypair = create_key(cert_config)
|
152
|
+
# puts "... csr ..."
|
153
|
+
cert_csr = create_csr(cert_config, cert_keypair)
|
154
|
+
# puts "... signing ..."
|
155
|
+
signed_cert = sign_cert(cert_config, cert_keypair, cert_csr)
|
156
|
+
return signed_cert, cert_keypair
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# Creates a new RSA key from +cert_config+.
|
161
|
+
|
162
|
+
def self.create_key(cert_config)
|
163
|
+
#passwd_cb = nil
|
164
|
+
target = cert_config[:hostname] || cert_config[:user]
|
165
|
+
# puts target
|
166
|
+
dest = @ca_config[:fake_certs_dir]
|
167
|
+
# puts dest
|
168
|
+
keypair_file = File.join(dest, (target + "_keypair.pem"))
|
169
|
+
keypair_file.gsub!(/\*/,"_")
|
170
|
+
|
171
|
+
return keypair_file if File.exist? keypair_file
|
172
|
+
|
173
|
+
#puts "create_key: #{keypair_file}"
|
174
|
+
begin
|
175
|
+
Dir.mkdir dest #, 0700
|
176
|
+
rescue Errno::EEXIST
|
177
|
+
# puts "directory exists"
|
178
|
+
end
|
179
|
+
|
180
|
+
if not File.exists?(keypair_file) then
|
181
|
+
#puts "Generating RSA keypair" if $DEBUG
|
182
|
+
keypair = OpenSSL::PKey::RSA.new 1024
|
183
|
+
# puts keypair.to_pem.class
|
184
|
+
|
185
|
+
if cert_config[:password].nil? then
|
186
|
+
# puts "no password for cert"
|
187
|
+
# puts "Writing keypair to #{keypair_file}" if $DEBUG
|
188
|
+
begin
|
189
|
+
dummy = keypair.to_pem.split("\n")
|
190
|
+
dummy.each do |line|
|
191
|
+
line.strip!
|
192
|
+
end
|
193
|
+
fh = File.open( keypair_file, "wb" )
|
194
|
+
fh.write dummy.join("\n")
|
195
|
+
fh.close
|
196
|
+
rescue => bang
|
197
|
+
puts "! Could not write keypair"
|
198
|
+
puts bang
|
199
|
+
puts bang.backtrace
|
200
|
+
end
|
201
|
+
else
|
202
|
+
# passwd_cb = proc do cert_config[:password] end
|
203
|
+
keypair_export = keypair.export OpenSSL::Cipher::DES.new(:EDE3, :CBC), cert_config[:password]
|
204
|
+
|
205
|
+
# puts "Writing keypair to #{keypair_file}" if $DEBUG
|
206
|
+
#File.open keypair_file, "w" do |f|
|
207
|
+
# f << keypair_export
|
208
|
+
#end
|
209
|
+
begin
|
210
|
+
fh = File.open( keypair_file, "w" )
|
211
|
+
fh.puts keypair_export
|
212
|
+
fh.close
|
213
|
+
rescue => bang
|
214
|
+
|
215
|
+
puts "! Could not write keypair"
|
216
|
+
puts bang
|
217
|
+
puts bang.backtrace
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
end
|
222
|
+
return keypair_file
|
223
|
+
end
|
224
|
+
|
225
|
+
##
|
226
|
+
# Signs the certificate described in +cert_config+ and
|
227
|
+
# +csr_file+, saving it to +cert_file+.
|
228
|
+
|
229
|
+
def self.sign_cert(cert_config, cert_file, csr_file)
|
230
|
+
|
231
|
+
target = cert_config[:hostname] || cert_config[:user]
|
232
|
+
dest = @ca_config[:fake_certs_dir]
|
233
|
+
cert_file = File.join dest, "#{target}_cert.pem"
|
234
|
+
cert_file.gsub!(/\*/,"_")
|
235
|
+
return cert_file if File.exist? cert_file
|
236
|
+
|
237
|
+
csr = OpenSSL::X509::Request.new File.read(csr_file)
|
238
|
+
|
239
|
+
raise "CSR sign verification failed." unless csr.verify csr.public_key
|
240
|
+
|
241
|
+
if csr.public_key.n.num_bits < @ca_config[:cert_key_length_min] then
|
242
|
+
raise "Key length too short"
|
243
|
+
end
|
244
|
+
|
245
|
+
if csr.public_key.n.num_bits > @ca_config[:cert_key_length_max] then
|
246
|
+
raise "Key length too long"
|
247
|
+
end
|
248
|
+
|
249
|
+
if csr.subject.to_a[0, @ca_config[:name].size] != @ca_config[:name] then
|
250
|
+
raise "DN does not match"
|
251
|
+
end
|
252
|
+
|
253
|
+
# Only checks signature here. You must verify CSR according to your
|
254
|
+
# CP/CPS.
|
255
|
+
|
256
|
+
# CA setup
|
257
|
+
|
258
|
+
puts "Reading CA cert from #{@ca_config[:cert_file]}" if $DEBUG
|
259
|
+
ca = OpenSSL::X509::Certificate.new File.read(@ca_config[:cert_file])
|
260
|
+
|
261
|
+
puts "Reading CA keypair from #{@ca_config[:keypair_file]}" if $DEBUG
|
262
|
+
ca_keypair = OpenSSL::PKey::RSA.new File.read(@ca_config[:keypair_file]),
|
263
|
+
@ca_config[:password]
|
264
|
+
|
265
|
+
serial = File.read(@ca_config[:serial_file]).chomp.hex
|
266
|
+
File.open @ca_config[:serial_file], "w" do |f|
|
267
|
+
f << "%04X" % (serial + 1)
|
268
|
+
end
|
269
|
+
|
270
|
+
puts "Generating cert" if $DEBUG
|
271
|
+
|
272
|
+
cert = OpenSSL::X509::Certificate.new
|
273
|
+
from = Time.now
|
274
|
+
cert.subject = csr.subject
|
275
|
+
cert.issuer = ca.subject
|
276
|
+
cert.not_before = from
|
277
|
+
cert.not_after = from + @ca_config[:cert_days] * 24 * 60 * 60
|
278
|
+
cert.public_key = csr.public_key
|
279
|
+
cert.serial = serial
|
280
|
+
cert.version = 2 # X509v3
|
281
|
+
|
282
|
+
basic_constraint = nil
|
283
|
+
key_usage = []
|
284
|
+
ext_key_usage = []
|
285
|
+
|
286
|
+
case cert_config[:type]
|
287
|
+
when "ca" then
|
288
|
+
basic_constraint = "CA:TRUE"
|
289
|
+
key_usage << "cRLSign" << "keyCertSign"
|
290
|
+
when "terminalsubca" then
|
291
|
+
basic_constraint = "CA:TRUE,pathlen:0"
|
292
|
+
key_usage << "cRLSign" << "keyCertSign"
|
293
|
+
when "server" then
|
294
|
+
basic_constraint = "CA:FALSE"
|
295
|
+
key_usage << "digitalSignature" << "keyEncipherment"
|
296
|
+
ext_key_usage << "serverAuth"
|
297
|
+
when "ocsp" then
|
298
|
+
basic_constraint = "CA:FALSE"
|
299
|
+
key_usage << "nonRepudiation" << "digitalSignature"
|
300
|
+
ext_key_usage << "serverAuth" << "OCSPSigning"
|
301
|
+
when "client" then
|
302
|
+
basic_constraint = "CA:FALSE"
|
303
|
+
key_usage << "nonRepudiation" << "digitalSignature" << "keyEncipherment"
|
304
|
+
ext_key_usage << "clientAuth" << "emailProtection"
|
305
|
+
else
|
306
|
+
raise "unknonw cert type \"#{cert_config[:type]}\""
|
307
|
+
end
|
308
|
+
|
309
|
+
ef = OpenSSL::X509::ExtensionFactory.new
|
310
|
+
ef.subject_certificate = cert
|
311
|
+
ef.issuer_certificate = ca
|
312
|
+
ex = []
|
313
|
+
ex << ef.create_extension("basicConstraints", basic_constraint, true)
|
314
|
+
ex << ef.create_extension("nsComment",
|
315
|
+
"Ruby/OpenSSL Generated Certificate")
|
316
|
+
ex << ef.create_extension("subjectKeyIdentifier", "hash")
|
317
|
+
#ex << ef.create_extension("nsCertType", "client,email")
|
318
|
+
unless key_usage.empty? then
|
319
|
+
ex << ef.create_extension("keyUsage", key_usage.join(","))
|
320
|
+
end
|
321
|
+
#ex << ef.create_extension("authorityKeyIdentifier",
|
322
|
+
# "keyid:always,issuer:always")
|
323
|
+
#ex << ef.create_extension("authorityKeyIdentifier", "keyid:always")
|
324
|
+
unless ext_key_usage.empty? then
|
325
|
+
ex << ef.create_extension("extendedKeyUsage", ext_key_usage.join(","))
|
326
|
+
end
|
327
|
+
|
328
|
+
if @ca_config[:cdp_location] then
|
329
|
+
ex << ef.create_extension("crlDistributionPoints",
|
330
|
+
@ca_config[:cdp_location])
|
331
|
+
end
|
332
|
+
|
333
|
+
if @ca_config[:ocsp_location] then
|
334
|
+
ex << ef.create_extension("authorityInfoAccess",
|
335
|
+
"OCSP;" << @ca_config[:ocsp_location])
|
336
|
+
end
|
337
|
+
# cert.extensions = ex
|
338
|
+
cert.sign ca_keypair, OpenSSL::Digest::SHA1.new
|
339
|
+
|
340
|
+
# backup_cert_file = @ca_config[:backup_certs_dir] + "/cert_#{cert.serial}.pem"
|
341
|
+
# puts "Writing backup cert to #{backup_cert_file}" if $DEBUG
|
342
|
+
# File.open backup_cert_file, "w", 0644 do |f|
|
343
|
+
# f << cert.to_pem
|
344
|
+
# end
|
345
|
+
|
346
|
+
# Write cert
|
347
|
+
puts "Writing cert to #{cert_file}"
|
348
|
+
File.open cert_file, "w", 0644 do |f|
|
349
|
+
f << cert.to_pem
|
350
|
+
end
|
351
|
+
|
352
|
+
return cert_file
|
353
|
+
end
|
354
|
+
|
355
|
+
##
|
356
|
+
# Creates a new Certificate Signing Request for the keypair in
|
357
|
+
# +keypair_file+, generating and saving new keypair if nil.
|
358
|
+
|
359
|
+
def self.create_csr(cert_config, keypair_file = nil)
|
360
|
+
keypair = nil
|
361
|
+
target = cert_config[:hostname] || cert_config[:user]
|
362
|
+
dest = @ca_config[:csr_dir]
|
363
|
+
csr_file = File.join dest, "csr_#{target}.pem"
|
364
|
+
csr_file.gsub!(/\*/,"_")
|
365
|
+
|
366
|
+
return csr_file if File.exist? csr_file
|
367
|
+
|
368
|
+
name = @ca_config[:name].dup
|
369
|
+
case cert_config[:type]
|
370
|
+
when 'server' then
|
371
|
+
# name << ['OU', 'Watobo CA']
|
382
372
|
name << ['CN', cert_config[:hostname]]
|
383
|
-
#name << ['CN', "WATOBO"]
|
384
|
-
when 'client' then
|
385
|
-
name << ['CN', cert_config[:user]]
|
386
|
-
name << ['emailAddress', cert_config[:email]]
|
387
|
-
end
|
388
|
-
#puts "Create Certificate Signing Request ..."
|
389
|
-
# puts "Keypair File: " + keypair_file
|
390
|
-
# puts name
|
391
|
-
name = OpenSSL::X509::Name.new(name)
|
392
|
-
# puts "- - -"
|
393
|
-
|
394
|
-
if File.exists? keypair_file then
|
395
|
-
# puts "Get Keypair from file #{keypair_file}"
|
396
|
-
keypair = OpenSSL::PKey::RSA.new(File.read(keypair_file), cert_config[:password])
|
397
|
-
else
|
398
|
-
# puts "Create Certificate KeyPair ..."
|
399
|
-
keypair = create_key(cert_config)
|
400
|
-
end
|
401
|
-
|
402
|
-
# puts "Generating CSR for #{name}" if $DEBUG
|
403
|
-
|
404
|
-
req = OpenSSL::X509::Request.new
|
405
|
-
req.version = 0
|
406
|
-
req.subject = name
|
407
|
-
req.public_key = keypair.public_key
|
408
|
-
req.sign keypair, OpenSSL::Digest::MD5.new
|
409
|
-
|
410
|
-
# puts "Writing CSR to #{csr_file}" if $DEBUG
|
411
|
-
File.open csr_file, "w" do |f|
|
412
|
-
f << req.to_pem
|
413
|
-
end
|
414
|
-
|
415
|
-
return csr_file
|
416
|
-
end
|
417
|
-
|
418
|
-
|
419
|
-
end
|
373
|
+
#name << ['CN', "WATOBO"]
|
374
|
+
when 'client' then
|
375
|
+
name << ['CN', cert_config[:user]]
|
376
|
+
name << ['emailAddress', cert_config[:email]]
|
377
|
+
end
|
378
|
+
#puts "Create Certificate Signing Request ..."
|
379
|
+
# puts "Keypair File: " + keypair_file
|
380
|
+
# puts name
|
381
|
+
name = OpenSSL::X509::Name.new(name)
|
382
|
+
# puts "- - -"
|
383
|
+
|
384
|
+
if File.exists? keypair_file then
|
385
|
+
# puts "Get Keypair from file #{keypair_file}"
|
386
|
+
keypair = OpenSSL::PKey::RSA.new(File.read(keypair_file), cert_config[:password])
|
387
|
+
else
|
388
|
+
# puts "Create Certificate KeyPair ..."
|
389
|
+
keypair = create_key(cert_config)
|
390
|
+
end
|
391
|
+
|
392
|
+
# puts "Generating CSR for #{name}" if $DEBUG
|
393
|
+
|
394
|
+
req = OpenSSL::X509::Request.new
|
395
|
+
req.version = 0
|
396
|
+
req.subject = name
|
397
|
+
req.public_key = keypair.public_key
|
398
|
+
req.sign keypair, OpenSSL::Digest::MD5.new
|
399
|
+
|
400
|
+
# puts "Writing CSR to #{csr_file}" if $DEBUG
|
401
|
+
File.open csr_file, "w" do |f|
|
402
|
+
f << req.to_pem
|
403
|
+
end
|
404
|
+
|
405
|
+
return csr_file
|
406
|
+
end
|
407
|
+
|
408
|
+
|
409
|
+
end
|
420
410
|
end
|