Skip to content

Commit

Permalink
Showing 3 changed files with 27 additions and 15 deletions.
26 changes: 13 additions & 13 deletions spec/std/openssl/ssl/context_spec.cr
Original file line number Diff line number Diff line change
@@ -4,21 +4,21 @@ require "openssl"
describe OpenSSL::SSL::Context do
it "new for client" do
ssl_context = OpenSSL::SSL::Context::Client.new
ssl_context.options.should eq(OpenSSL::SSL::Options.flags(
ssl_context.options.should eq(OpenSSL::SSL.options_flags(
ALL, NO_SSLV2, NO_SSLV3, NO_SESSION_RESUMPTION_ON_RENEGOTIATION, SINGLE_ECDH_USE, SINGLE_DH_USE
))
ssl_context.modes.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.modes.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.verify_mode.should eq(OpenSSL::SSL::VerifyMode::PEER)

OpenSSL::SSL::Context::Client.new(LibSSL.tlsv1_method)
end

it "new for server" do
ssl_context = OpenSSL::SSL::Context::Server.new
ssl_context.options.should eq(OpenSSL::SSL::Options.flags(
ssl_context.options.should eq(OpenSSL::SSL.options_flags(
ALL, NO_SSLV2, NO_SSLV3, NO_SESSION_RESUMPTION_ON_RENEGOTIATION, SINGLE_ECDH_USE, SINGLE_DH_USE, CIPHER_SERVER_PREFERENCE
))
ssl_context.modes.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.modes.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.verify_mode.should eq(OpenSSL::SSL::VerifyMode::NONE)

OpenSSL::SSL::Context::Server.new(LibSSL.tlsv1_method)
@@ -81,39 +81,39 @@ describe OpenSSL::SSL::Context do
ssl_context = OpenSSL::SSL::Context::Client.new
ssl_context.remove_options(ssl_context.options) # reset
ssl_context.add_options(OpenSSL::SSL::Options::ALL).should eq(OpenSSL::SSL::Options::ALL)
ssl_context.add_options(OpenSSL::SSL::Options.flags(NO_SSLV2, NO_SSLV3))
.should eq(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2, NO_SSLV3))
ssl_context.add_options(OpenSSL::SSL.options_flags(NO_SSLV2, NO_SSLV3))
.should eq(OpenSSL::SSL.options_flags(ALL, NO_SSLV2, NO_SSLV3))
end

it "removes options" do
ssl_context = OpenSSL::SSL::Context::Client.insecure
ssl_context.add_options(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))
ssl_context.add_options(OpenSSL::SSL.options_flags(ALL, NO_SSLV2))
ssl_context.remove_options(OpenSSL::SSL::Options::ALL).should eq(OpenSSL::SSL::Options::NO_SSLV2)
end

it "returns options" do
ssl_context = OpenSSL::SSL::Context::Client.insecure
ssl_context.add_options(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))
ssl_context.options.should eq(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))
ssl_context.add_options(OpenSSL::SSL.options_flags(ALL, NO_SSLV2))
ssl_context.options.should eq(OpenSSL::SSL.options_flags(ALL, NO_SSLV2))
end

it "adds modes" do
ssl_context = OpenSSL::SSL::Context::Client.insecure
ssl_context.add_modes(OpenSSL::SSL::Modes::AUTO_RETRY).should eq(OpenSSL::SSL::Modes::AUTO_RETRY)
ssl_context.add_modes(OpenSSL::SSL::Modes::RELEASE_BUFFERS)
.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
end

it "removes modes" do
ssl_context = OpenSSL::SSL::Context::Client.insecure
ssl_context.add_modes(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.add_modes(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.remove_modes(OpenSSL::SSL::Modes::AUTO_RETRY).should eq(OpenSSL::SSL::Modes::RELEASE_BUFFERS)
end

it "returns modes" do
ssl_context = OpenSSL::SSL::Context::Client.insecure
ssl_context.add_modes(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.modes.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.add_modes(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
ssl_context.modes.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
end

it "sets the verify mode" do
12 changes: 12 additions & 0 deletions src/openssl/openssl.cr
Original file line number Diff line number Diff line change
@@ -31,6 +31,18 @@ module OpenSSL
alias X509VerifyFlags = LibCrypto::X509VerifyFlags
{% end %}

# TODO: remove these after 0.18.0

# :nodoc:
macro options_flags(*flags)
LibSSL::Options.flags({{*flags}})
end

# :nodoc:
macro modes_flags(*flags)
LibSSL::Modes.flags({{*flags}})
end

class Error < OpenSSL::Error
getter error : ErrorType

4 changes: 2 additions & 2 deletions src/openssl/ssl/context.cr
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ abstract class OpenSSL::SSL::Context

set_default_verify_paths

add_options(OpenSSL::SSL::Options.flags(
add_options(OpenSSL::SSL.options_flags(
ALL,
NO_SSLV2,
NO_SSLV3,
@@ -129,7 +129,7 @@ abstract class OpenSSL::SSL::Context
SINGLE_DH_USE
))

add_modes(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
add_modes(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))

self.ciphers = CIPHERS

4 comments on commit f029d2e

@asterite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhass In general I try to keep the current specs compiling without a new compiler. Otherwise someone who wants to contribute to just the standard library can't do bin/crystal spec/std_spec.cr, he would need to compile a compiler but that takes a bit more effort.

@jhass
Copy link
Member

@jhass jhass commented on f029d2e Jun 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we flip compiling the specs and the compiler on Travis? Or rather std_spec -> crystal -> compiler_specs

@asterite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhass we were just talking with @bcardiff about that. Sounds good :-)

@asterite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though some cast messages are broken right now, those about cast messages. We can use {% if Crystal::VERSION == 0.18.0 %} for those, though we'd have to tell travis to set that somehow...

Please sign in to comment.