Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.

Commit b325d4d

Browse files
authored
Merge pull request #5 from klyonrad/feature/ssl-security-in-http-helper
Enable SSL certificate check in http helper
2 parents 6ed394b + c0a7c40 commit b325d4d

10 files changed

Lines changed: 105 additions & 7 deletions

File tree

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AllCops:
2+
TargetRubyVersion: 2.2
23
Exclude:
34
- 'tmp/**/*'
45
- 'spec/fixtures/application/htdocs/stylesheets/**/config.rb'

Berksfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ GRAPH
1818
mysql (~> 6.1)
1919
mysql2_chef_gem (~> 1.0)
2020
php (~> 1.9)
21+
ssl_certificate (~> 1.12.0)
2122
iis (4.1.7)
2223
windows (>= 1.34.6)
2324
mariadb (0.3.1)
@@ -49,6 +50,7 @@ GRAPH
4950
windows (>= 1.2.2)
5051
smf (2.2.8)
5152
rbac (>= 1.0.1)
53+
ssl_certificate (1.12.0)
5254
windows (1.40.0)
5355
chef_handler (>= 0.0.0)
5456
xml (2.0.0)

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [Unreleased]: https://github.com/dkdeploy/dkdeploy-php/compare/master...develop
6+
7+
### Added
8+
9+
- `:ssl_verify_mode` for server properties, which takes SSL verify_mode constants (`OpenSSL::SSL::VERIFY_NONE`)
10+
11+
### Changed
12+
13+
- `Dkdeploy::Php::Helpers::Http::http_get_with_redirect` gets arguments as options hash now
14+
15+
### Fixed
16+
17+
- remove SSL certificate bypassing in http helper #5
18+
19+
520
## [7.0.0] - 2016-07-01
621
### Summary
722

823
- first public release
924

10-
[Unreleased]: https://github.com/dkdeploy/dkdeploy-php/compare/master...develop
25+
1126
[7.0.0]: https://github.com/dkdeploy/dkdeploy-php/releases/tag/v7.0.0

config/vm/cookbooks/dkdeploy-php/metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
depends 'apache2', '~> 3.2'
1111
depends 'php', '~> 1.9'
1212
depends 'apt', '~> 3.0'
13+
depends 'ssl_certificate', '~> 1.12.0'

config/vm/cookbooks/dkdeploy-php/recipes/default.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@
5656
# Apache
5757
include_recipe 'apache2'
5858
include_recipe 'apache2::mod_php5'
59+
include_recipe 'apache2::mod_ssl'
5960

6061
# install apache2-utils. It is needed for the assets:add_htpasswd task
6162
package 'apache2-utils' do
6263
action :install
6364
end
6465

66+
ssl_key_path = '/var/www/dkdeploy.key'
67+
ssl_cert_path = '/var/www/dkdeploy.pem'
68+
6569
web_app 'dkdeploy-php.dev' do
6670
server_name 'dkdeploy-php.dev'
6771
server_aliases ['second-dkdeploy-php.dev']
6872
docroot '/var/www/dkdeploy/current/'
73+
key_path ssl_key_path
74+
cert_path ssl_cert_path
6975
template 'web_app.conf.erb'
7076
end
7177

@@ -75,3 +81,13 @@
7581
mode '0770'
7682
action :create
7783
end
84+
85+
ssl_certificate 'dkdeploy-php.dev' do
86+
key_path ssl_key_path
87+
key_mode 00755
88+
cert_path ssl_cert_path
89+
domain 'dkdeploy-php.dev'
90+
organization 'dkdeploy'
91+
email 'offical@example.com'
92+
notifies :restart, 'service[apache2]'
93+
end

config/vm/cookbooks/dkdeploy-php/templates/default/web_app.conf.erb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,38 @@
2626
php_admin_value realpath_cache_ttl 0
2727
php_admin_value realpath_cache_size 0k
2828
</VirtualHost>
29+
30+
<VirtualHost *:443>
31+
ServerName <%= @params[:server_name] %>
32+
ServerAlias <%= @params[:server_aliases].join(' ') %>
33+
DocumentRoot <%= @params[:docroot] %>
34+
RewriteEngine On
35+
36+
<Directory <%= @params[:docroot] %>>
37+
Options FollowSymLinks
38+
AllowOverride None
39+
Require all granted
40+
</Directory>
41+
42+
<Directory />
43+
Options FollowSymLinks
44+
AllowOverride None
45+
</Directory>
46+
47+
<IfModule mod_ssl.c>
48+
SSLEngine on
49+
SSLCertificateFile <%= @params[:cert_path] %>
50+
SSLCertificateKeyFile <%= @params[:key_path] %>
51+
</IfModule>
52+
53+
LogLevel info
54+
ErrorLog <%= node[:apache][:log_dir] %>/<%= @params[:name] %>-error.log
55+
CustomLog <%= node[:apache][:log_dir] %>/<%= @params[:name] %>-access.log combined
56+
57+
RewriteEngine On
58+
LogLevel info rewrite:trace2 alias:debug
59+
60+
# Deactivate php realpath cache
61+
php_admin_value realpath_cache_ttl 0
62+
php_admin_value realpath_cache_size 0k
63+
</VirtualHost>

features/php.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@ Feature: Test tasks for namespace 'php'
4242
And I extend the development capistrano configuration from the fixture file server_with_faulty_domain_configuration.rb
4343
When I run `cap dev php:clear_opcache`
4444
Then the exit status should not be 0
45+
46+
Scenario: Clear APC via HTTPS
47+
Given a directory named "temp"
48+
And I extend the development capistrano configuration from the fixture file server_with_ssl.rb
49+
And I inject the root SSL certificate
50+
When I run `cap dev php:clear_apc_cache`
51+
Then the exit status should be 0
52+
And the output should contain "200 - OK"
53+
54+
Scenario: Clear APC via HTTPS and failing SSL certificate
55+
Given a directory named "temp"
56+
And I extend the development capistrano configuration from the fixture file server_with_ssl.rb
57+
When I run `cap dev php:clear_apc_cache`
58+
Then the exit status should not be 0
59+
And the output should contain "certificate verify failed"

features/support/step_definitions/steps.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'erb'
22
require 'ostruct'
33

4+
include Dkdeploy::TestEnvironment::Constants # to get access to test_app_path method
45
# Creates an empty doctrine migration with a given migration version and basic content
56
#
67
# @yieldparam migration_version [String] the 14 digits migration number
@@ -13,3 +14,13 @@ def context_object.binding_for_erb
1314
empty_doctrine_migration_template = ERB.new File.read(empty_doctrine_migration_template_path)
1415
write_file file_path, empty_doctrine_migration_template.result(context_object.binding_for_erb)
1516
end
17+
18+
Given(/^I set relative to current path the environment variable "(.*)" to "(.*)"/) do |variable, value|
19+
set_environment_variable(variable.to_s, test_app_path + value.to_s)
20+
end
21+
22+
# injects the self-signed certificate into environment variables to simulate a valid certificate
23+
Given('I inject the root SSL certificate') do
24+
steps 'When I run `cap dev utils:download_file[../../../dkdeploy.pem]`
25+
Given I set relative to current path the environment variable "SSL_CERT_FILE" to "/temp/dkdeploy.dkdeploy-php.dev.pem"'
26+
end

lib/dkdeploy/php/helpers/http.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ def call_file_on_server(filename, server)
1818
web_server_port = domain_scheme == 'https' ? 443 : 80
1919
# Use server configuration, if exists
2020
web_server_port = server.fetch(:web_server_port) if server.properties.respond_to?(:web_server_port)
21+
ssl_verify_mode = server.properties.respond_to?(:ssl_verify_mode) ? server.fetch(:ssl_verify_mode) : OpenSSL::SSL::VERIFY_PEER
2122

2223
url = URI.parse("#{domain_scheme}://#{domain}").merge("/#{filename}")
2324
url.port = web_server_port
2425
info "Call URL #{url}"
2526

26-
http_get_with_redirect url
27+
http_get_with_redirect url: url, verify_mode: ssl_verify_mode
2728
end
2829

2930
# Sends a get request that handles redirects
3031
#
3132
# @param url [URI]
3233
# @param limit [Integer] defines how many redirects are allowed
34+
# @param verify_mode [OpenSSL::SSL::verify_mode] ssl verify mode, setting to VERIFY_NONE disables certificate check
3335
# @return [NET::HTTPResponse]
34-
def http_get_with_redirect(url, limit = 5)
36+
def http_get_with_redirect(url:, limit: 5, verify_mode: OpenSSL::SSL::VERIFY_PEER)
3537
limit = Integer(limit)
3638
raise ArgumentError, 'limit cannot be negative' if limit < 0
3739
raise 'too many HTTP redirects' if limit.zero?
@@ -41,16 +43,15 @@ def http_get_with_redirect(url, limit = 5)
4143
http.read_timeout = fetch :http_read_timeout
4244
if url.scheme == 'https'
4345
http.use_ssl = true
44-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
46+
http.verify_mode = verify_mode
4547
end
4648
request = Net::HTTP::Get.new(url.path) # build request
47-
# call url
48-
response = http.request(request)
49+
response = http.request(request) # call url
4950
if response.is_a? Net::HTTPRedirection
5051
# Does not handle multiple redirects. Code/idea from http://stackoverflow.com/a/7210600/1796645
5152
location = URI.parse(response.header['location'])
5253
info "redirected to #{location}"
53-
response = http_get_with_redirect(location, limit - 1)
54+
response = http_get_with_redirect(url: location, limit: limit - 1, verify_mode: verify_mode)
5455
end
5556
response
5657
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server 'dkdeploy-php.dev', roles: %w(web app backend), primary: true, domain_scheme: 'https'

0 commit comments

Comments
 (0)