Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for OpenSSL #3865

Merged
merged 8 commits into from Jan 16, 2017
Merged

API for OpenSSL #3865

merged 8 commits into from Jan 16, 2017

Conversation

bararchy
Copy link
Contributor

No description provided.

# # - https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet#Rule_-_Only_Support_Strong_Cryptographic_Ciphers
# # - https://cipherli.st/
# # - Full list is available at: https://wiki.openssl.org/index.php/Manual:Ciphers(1)#CIPHER_STRINGS
# context.ciphers = "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"
Copy link
Member

@jhass jhass Jan 10, 2017

Choose a reason for hiding this comment

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

I'm not sure about adding a valid value here, people should be forced to actually follow the links given rather than copy pasting whatever is here. Also it should be made clear that we do provide a sane enough default.

# context.certificate_chain = "/tmp/certificate.crt"
# # Those options are to enhance the security of the server by not using deprecated SSLv2 and SSLv3 protocols
# # It is also advised to disable Compression and enable only TLS1.2
# context.add_options(OpenSSL::SSL::Options::NO_SSLV2 | OpenSSL::SSL::Options::NO_SSLV3)
Copy link
Member

Choose a reason for hiding this comment

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

Same, those recommendations might get outdated and we do provide sane enough defaults. Or if we don't we should.

# context = OpenSSL::SSL::Context::Client.new
# context.ciphers = "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"
# context.add_options(OpenSSL::SSL::Options::NO_SSLV2 | OpenSSL::SSL::Options::NO_SSLV3)
# context.verify_mode = OpenSSL::SSL::VerifyMode::NONE
Copy link
Member

@jhass jhass Jan 10, 2017

Choose a reason for hiding this comment

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

I wouldn't even mention this option in a usage example. People should pay reasonable research effort into this, so they understand what they're doing with it.

- removed valid ciphers from code
- moved links to the upper part of the doc
@bararchy
Copy link
Contributor Author

@jhass , better ?

@ysbaddaden
Copy link
Contributor

I'll be more harsh: drop the security tuning examples completely (ciphers, options, verify mode), except for specifying the keys; document that we do our best to define good defaults (Mozilla Intermediate) in the stdlib with a link to the Mozilla wiki page for more details, along with encouragements to notify us / send a pull request if we get out-of-date, have ciphers enabled that shouldn't be, etc.

Note that we don't exactly follow the Mozilla Intermediate configuration, for example we don't configure the secp384r1 and secp521r1 curves. If someone knows how to enable/initialize them, please step in!

@bararchy
Copy link
Contributor Author

@ysbaddaden I just did , removed all security tuning.

@bararchy
Copy link
Contributor Author

@jhass and @ysbaddaden .
I added more info regarding the Crystal supplying the sane defaults, also that if any issues are found in the choices we made, an issue should be opened

  • I would encourage opening a crystal-security mailing list so that security issues could be notified secretly and remain unpublished until they are fixed.

# - Full list is available at: https://wiki.openssl.org/index.php/Manual:Ciphers(1)#CIPHER_STRINGS
#
# Do note that
# - Crystal do provide sane defaults for all Ciphers and protocols
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose:

Crystal does its best to provide sane configuration defaults (see Mozilla Intermediate).

# socket = TCPServer.new(5555) # Bind new TCPSocket to port 5555
# context = OpenSSL::SSL::Context::Server.new
# # Define which ciphers to use with OpenSSL
# context.ciphers = "VALID_CIPHER_STRING"
Copy link
Contributor

Choose a reason for hiding this comment

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

context.ciphers leftover.

# def client
# socket = TCPSocket.new("127.0.0.1", 5555)
# context = OpenSSL::SSL::Context::Client.new
# context.ciphers = "VALID_CIPHER_STRING"
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -1,5 +1,56 @@
require "./openssl/lib_ssl"

# ### Example
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe have a header? Something as basic as # OpenSSL integration

Maybe also have an introduction that says that:

  • TLS sockets need a context, potentially with keys (required for servers) and configuration.
  • TLS sockets will wrap the underlying TCP socket, and any further communication must happen through the OpenSSL::SSL::Socket only.

Then continue with:

  • the default configuration (sane defaults, uses Mozilla Intermediate, best effort, please contribute)
  • the server example —I'm not sure we should add an example about how to generate the certificates, one should buy a certificate instead;
  • the client example.

@bararchy
Copy link
Contributor Author

@ysbaddaden cool ?

@bararchy
Copy link
Contributor Author

@ysbaddaden @jhass
Is this ok from your end ? or more changes needed ?

# - Linked version of OpenSSL need to be checked for supporting specific protocols and ciphers
# - If any configurations or choices in Crystal regarding SSL settings and security are found to be lacking or need
# improvement please open an issue and let us know
# ### Server side
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a newline before and after the heading ###.

# end
# end
# ```
# ### Client side
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

# ssl_socket.write("Testing".to_slice)
# end
# ```

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove redundant newline.

@bararchy
Copy link
Contributor Author

@Sija , done.

@bararchy
Copy link
Contributor Author

@ysbaddaden @jhass @Sija

So ... are we done ? can this be merged ?

@ysbaddaden
Copy link
Contributor

Looks OK to me.

# socket = TCPServer.new(5555) # Bind new TCPSocket to port 5555
# context = OpenSSL::SSL::Context::Server.new
# context.private_key = "/path/to/private.key"
# context.certificate_chain = "/path/to/public.cert?"
Copy link
Contributor

Choose a reason for hiding this comment

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

is ? at the end of the path intentional?

#
# ### Server side
#
# ```crystal
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for crystal prefix here

#
# ### Client side
#
# ```crystal
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@Sija
Copy link
Contributor

Sija commented Jan 14, 2017

LGTM

@ysbaddaden
Copy link
Contributor

Build has failed on x86-linux. Restarted.

@ysbaddaden ysbaddaden merged commit 87317f2 into crystal-lang:master Jan 16, 2017
@spalladino spalladino added this to the Next milestone Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants