# Usage of naive Socket class to create SSL Socket

## Overview

* **Rule ID**: `java_lang_socket_init`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-319

## Description

Using the naive Socket class to create SSL sockets compromises security. Directly creating SSL sockets with `new Socket()` lacks the advanced security features provided by `SSLSocketFactory`. `SSLSocketFactory` is designed with SSL/TLS protocols in mind, offering encryption, hostname verification, and trust manager configuration, making it a more secure option for creating SSL sockets.

## Remediation Guidelines

* **Avoid** using `java.net.Socket` to directly create SSL sockets due to its limited security capabilities.
* **Use** SSLSocketFactory to create SSL sockets, ensuring the use of SSL/TLS protocols and other security enhancements.

  ```java
  SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
  SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, true);

  ```

## References

* [**OWASP Transport Layer Security Cheat Sheet**](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html)
* [**CWE-319: Cleartext Transmission of Sensitive Information**](https://cwe.mitre.org/data/definitions/319.html)
* [**OWASP Top 10: A02:2021 - Cryptographic Failures**](https://owasp.org/Top10/A02_2021-Cryptographic_Failures/)

## Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our [**SAST TOOL**](https://scopy.sec1.io/login)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sec1.io/user-docs/4-sast/2-java/usage-of-naive-socket-class-to-create-ssl-socket.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
