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