Skip to content

Commit aec8196

Browse files
committed
Merge pull request gitlabhq#62 from knu/use_cert_store
Add ca_file/ca_path configuration options.
2 parents 5519420 + 932238e commit aec8196

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

config.yml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ gitlab_url: "http://localhost/"
77
http_settings:
88
# user: someone
99
# password: somepass
10+
# ca_file: /etc/ssl/cert.pem
11+
# ca_path: /etc/pki/tls/certs
1012
self_signed_cert: false
1113

1214
# Repositories path

lib/gitlab_net.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ def host
4242
def get(url)
4343
url = URI.parse(url)
4444
http = Net::HTTP.new(url.host, url.port)
45-
http.use_ssl = (url.scheme == 'https')
4645

47-
if config.http_settings['self_signed_cert'] && http.use_ssl?
48-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
46+
if URI::HTTPS === url
47+
http.use_ssl = true
48+
http.cert_store = cert_store
49+
50+
if config.http_settings['self_signed_cert']
51+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52+
end
4953
end
5054

5155
request = Net::HTTP::Get.new(url.request_uri)
@@ -55,4 +59,18 @@ def get(url)
5559

5660
http.start {|http| http.request(request) }
5761
end
62+
63+
def cert_store
64+
@cert_store ||= OpenSSL::X509::Store.new.tap { |store|
65+
store.set_default_paths
66+
67+
if ca_file = config.http_settings['ca_file']
68+
store.add_file(ca_file)
69+
end
70+
71+
if ca_path = config.http_settings['ca_path']
72+
store.add_path(ca_path)
73+
end
74+
}
75+
end
5876
end

0 commit comments

Comments
 (0)