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

Implement HTTPS Support with SSL/TLS and HTTP to HTTPS Redirection #15

Merged
merged 4 commits into from
Oct 9, 2024

Conversation

Guhapriya01
Copy link
Collaborator

@Guhapriya01 Guhapriya01 commented Oct 7, 2024

This pull request implements HTTPS and SSL/TLS support for the Java HTTP server and introduces HTTP to HTTPS redirection.

Changes Made:

  • SSL/TLS Support:

    • Generated a self-signed SSL certificate using keytool for development and testing.
    • Integrated the SSL certificate using JSSE to enable HTTPS.
    • Configured the server to load the generated keystore and use the SSL certificate for encrypted communication on port 8043.
  • HTTP to HTTPS Redirection:

    • Implemented logic to listen for HTTP requests on port 8080.
    • Redirected HTTP requests to the corresponding HTTPS URL with a 301 status code.

Output:

To verify the implementation, you can test the following commands:

  1. HTTP to HTTPS Redirection:

    curl -i http://localhost:8080

    Response:

    HTTP/1.1 301 Moved Permanently
    Location: https://172.25.224.1:8043/
    Connection: close
    
  2. Accessing the HTTPS Server:

    curl -ik https://localhost:8043

    Response:

    HTTP/1.1 200 OK
    Content-Length: 109
    
    <html><head><title>Simple Java HTTPS Server</title></head><body>This page was served using Java</body></html>
    

Steps to Create a Self-Signed Certificate:

  1. Open Command Prompt and navigate to the directory where you want to create your keystore.
  2. Generate the Self-Signed Certificate:
    Use the following command to create a keystore and generate a self-signed SSL certificate:
    keytool -genkeypair -alias myserver -keyalg RSA -keysize 2048 -keystore keystore.jks -validity 365
    • You will be prompted to enter information for the certificate. Fill in the required details such as your name, organization, and location.
  3. Enter a Password for the keystore when prompted. Remember this password as it will be used in the server configuration.
  4. The keystore.jks file will be created in the current directory. This file contains the self-signed certificate.

In the ssl-config.json file, replace the keystore path with the path where you created the file, and use the same password for both the keystore and key password.

Related issues : #7

Please review the changes and let me know if any modifications are needed!

@Guhapriya01 Guhapriya01 marked this pull request as ready for review October 7, 2024 07:15
Copy link
Owner

@ajaynegi45 ajaynegi45 left a comment

Choose a reason for hiding this comment

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

Hi @Guhapriya01,

Thank you for your prompt work on this issue. I appreciate your dedication to the project.

I have reviewed your work, and I need some changes.

  • resolve these conflicts.
This branch has conflicts that must be resolved
to resolve conflicts before continuing.
Conflicting files
src/main/java/com/httpserver/HttpServerApplication.java
src/main/java/com/httpserver/config/Configuration.java
src/main/java/com/httpserver/config/ConfigurationManager.java
src/main/java/com/httpserver/core/HttpConnectionWorkerThread.java
src/main/java/com/httpserver/core/ServerListenerThread.java

Once again, thank you for your contribution! ❤️

@Guhapriya01
Copy link
Collaborator Author

Thank you so much @ajaynegi45 for reviewing my work and for your kind words!

I will resolve the conflicts and make the necessary changes to ensure everything works smoothly. I'll get back to you as soon as it's done.

@ajaynegi45
Copy link
Owner

Thank you so much @ajaynegi45 for reviewing my work and for your kind words!

I will resolve the conflicts and make the necessary changes to ensure everything works smoothly. I'll get back to you as soon as it's done.

Just fetch update from the upstream main branch

@Guhapriya01
Copy link
Collaborator Author

Hi @ajaynegi45,

I’ve committed the changes and resolved the conflicts. Let me know if you need anything else!

@Guhapriya01 Guhapriya01 requested a review from ajaynegi45 October 9, 2024 07:28
Copy link
Owner

@ajaynegi45 ajaynegi45 left a comment

Choose a reason for hiding this comment

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

Hi @Guhapriya01,

Thank you for your prompt work on this issue. I appreciate your dedication to the project.

I have reviewed your work, and I'm pleased to inform you that I have merged your pull request. Your changes looks fantastic, and it aligns perfectly with the project's design and usability goals. Great job!

If you have any more contributions or if there's anything else you'd like to work on in the future, please don't hesitate to let us know. Your efforts are valuable to the project's success.

Once again, thank you for your contribution! ❤️

@Guhapriya01
Copy link
Collaborator Author

Thank you @ajaynegi45! 😊 I'm glad the changes worked well. Looking forward to contributing more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants