@@ -100,22 +100,34 @@ def readbyte
100
100
101
101
def create_context ( options )
102
102
context = OpenSSL ::SSL ::SSLContext . new
103
- if options [ :ssl_cert ]
104
- context . cert = OpenSSL ::X509 ::Certificate . new ( File . open ( options [ :ssl_cert ] ) )
105
- end
106
- if options [ :ssl_key ]
107
- if options [ :ssl_key_pass_phrase ]
108
- context . key = OpenSSL ::PKey ::RSA . new ( File . open ( options [ :ssl_key ] ) ,
109
- options [ :ssl_key_pass_phrase ] )
110
- else
111
- context . key = OpenSSL ::PKey ::RSA . new ( File . open ( options [ :ssl_key ] ) )
112
- end
103
+ set_cert ( context , options ) if options [ :ssl_cert ]
104
+ set_key ( context , options ) if options [ :ssl_key ]
105
+ set_cert_verification ( context , options ) unless options [ :ssl_verify ] == false
106
+ context
107
+ end
108
+
109
+ def set_cert ( context , options )
110
+ context . cert = OpenSSL ::X509 ::Certificate . new ( File . open ( options [ :ssl_cert ] ) )
111
+ end
112
+
113
+ def set_key ( context , options )
114
+ if options [ :ssl_key_pass_phrase ]
115
+ context . key = OpenSSL ::PKey ::RSA . new ( File . open ( options [ :ssl_key ] ) ,
116
+ options [ :ssl_key_pass_phrase ] )
117
+ else
118
+ context . key = OpenSSL ::PKey ::RSA . new ( File . open ( options [ :ssl_key ] ) )
113
119
end
114
- if options [ :ssl_verify ] || options [ :ssl_ca_cert ]
115
- context . ca_file = options [ :ssl_ca_cert ]
116
- context . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
120
+ end
121
+
122
+ def set_cert_verification ( context , options )
123
+ context . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
124
+ cert_store = OpenSSL ::X509 ::Store . new
125
+ if options [ :ssl_ca_cert ]
126
+ cert_store . add_file ( options [ :ssl_ca_cert ] )
127
+ else
128
+ cert_store . set_default_paths
117
129
end
118
- context
130
+ context . cert_store = cert_store
119
131
end
120
132
121
133
def verify_certificate! ( socket )
0 commit comments