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

Fix SSL 2 version constant to 0x0002 #1694

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Conversation

droe
Copy link

@droe droe commented Jan 19, 2025

SSL 2 uses a version field of 0x0002, not 0x0200. This is confirmed not only in the original Netscape spec [1] and RFC draft of the time [2], but also in major implementations such as OpenSSL [3] and Wireshark [4].

[1] https://www-archive.mozilla.org/projects/security/pki/nss/ssl/draft02.html
[2] https://datatracker.ietf.org/doc/html/draft-hickman-netscape-ssl-00
[3] https://github.com/openssl/openssl/blob/OpenSSL_0_9_6m/ssl/ssl2.h#L66-L71
[4] https://github.com/wireshark/wireshark/blob/release-4.4/epan/dissectors/packet-tls-utils.h#L266-L277

@droe droe requested a review from seladb as a code owner January 19, 2025 16:19
@tigercosmos
Copy link
Collaborator

It's just bytes order. PCPP here is using host order, and other libraries that you posted are using network order.

@droe
Copy link
Author

droe commented Jan 19, 2025

If it was byte order, as you suggest, then the constants for SSL 3 and TLS would be wrong.

SSL 2 uses a version field of 0x0002, not 0x0200.  This is confirmed not
only in the original Netscape spec [1] and RFC draft of the time [2],
but also in major implementations such as OpenSSL [3] and Wireshark [4].

[1] https://www-archive.mozilla.org/projects/security/pki/nss/ssl/draft02.html
[2] https://datatracker.ietf.org/doc/html/draft-hickman-netscape-ssl-00
[3] https://github.com/openssl/openssl/blob/OpenSSL_0_9_6m/ssl/ssl2.h#L66-L71
[4] https://github.com/wireshark/wireshark/blob/release-4.4/epan/dissectors/packet-tls-utils.h#L266-L277
@droe
Copy link
Author

droe commented Jan 19, 2025

I missed code in Packet++/src/SSLCommon.cpp that used 0x200 in the first attempt, second attempt also addresses that.

@Dimi1010 Dimi1010 changed the base branch from master to dev January 19, 2025 18:12
@Dimi1010
Copy link
Collaborator

Dimi1010 commented Jan 19, 2025

Closing and reopening to run CI after base branch change.

@Dimi1010 Dimi1010 closed this Jan 19, 2025
@Dimi1010 Dimi1010 reopened this Jan 19, 2025
Copy link

codecov bot commented Jan 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.11%. Comparing base (bc5c08d) to head (426070b).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1694      +/-   ##
==========================================
- Coverage   83.15%   83.11%   -0.05%     
==========================================
  Files         277      277              
  Lines       48185    48205      +20     
  Branches    10165    10192      +27     
==========================================
- Hits        40067    40064       -3     
- Misses       7237     7244       +7     
- Partials      881      897      +16     
Flag Coverage Δ
alpine320 75.11% <100.00%> (-0.05%) ⬇️
fedora40 75.15% <100.00%> (-0.01%) ⬇️
macos-13 80.62% <100.00%> (-0.03%) ⬇️
macos-14 80.62% <100.00%> (-0.03%) ⬇️
macos-15 80.59% <100.00%> (-0.03%) ⬇️
mingw32 70.83% <100.00%> (-0.09%) ⬇️
mingw64 70.79% <100.00%> (-0.09%) ⬇️
npcap 85.17% <100.00%> (-0.14%) ⬇️
rhel94 74.99% <100.00%> (-0.06%) ⬇️
ubuntu2004 58.57% <100.00%> (-0.03%) ⬇️
ubuntu2004-zstd 58.68% <100.00%> (-0.03%) ⬇️
ubuntu2204 74.90% <100.00%> (-0.03%) ⬇️
ubuntu2204-icpx 61.46% <100.00%> (+0.08%) ⬆️
ubuntu2404 75.15% <100.00%> (-0.04%) ⬇️
unittest 83.11% <100.00%> (-0.05%) ⬇️
windows-2019 85.26% <100.00%> (-0.07%) ⬇️
windows-2022 85.30% <100.00%> (-0.06%) ⬇️
winpcap 85.27% <100.00%> (-0.05%) ⬇️
xdp 50.53% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tigercosmos
Copy link
Collaborator

@droe So is this still an issue?

@droe
Copy link
Author

droe commented Jan 20, 2025

Yes, certainly. Code point 0x0200 is wrong, 0x0002 as proposed in this PR is correct.

@tigercosmos
Copy link
Collaborator

@droe In Wireshark the values are:

#define SSLV2_VERSION           0x0002 /* not in record layer, SSL_CLIENT_SERVER from
                                          http://www-archive.mozilla.org/projects/security/pki/nss/ssl/draft02.html */
#define SSLV3_VERSION          0x300
#define TLSV1_VERSION          0x301

And in PCPP, the current (master) values are:

			/** SSL 2.0 */
			SSL2 = 0x0200,
			/** SSL 3.0 */
			SSL3 = 0x0300,
			/** TLS 1.0 */
			TLS1_0 = 0x0301,

According to the byte order, I think SSL2 should be 0x0020, not 0x0002?

@droe
Copy link
Author

droe commented Jan 20, 2025

It should be 0x0002 for SSL 2. This is not a byte order problem (and you're swapping nibbles, not bytes).

@tigercosmos
Copy link
Collaborator

I meant: major is 0x00, minor is 0x02. If you swap the bytes, 0x02 can be 0x2.

@droe
Copy link
Author

droe commented Jan 20, 2025

Not sure I understand what you're saying, uint8_t 0x02 and 0x2 are the same thing. You are running the version uint16_t from the wire through be16toh() at deserialization time, so the code ends up seeing SSLVersion 0x0002 in host byte order for the SSL 2 version bytes 00 02 on the wire.

@@ -117,7 +117,7 @@ namespace pcpp
enum SSLVersionEnum
{
/** SSL 2.0 */
SSL2 = 0x0200,
SSL2 = 0x0002,
Copy link
Owner

Choose a reason for hiding this comment

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

I wouldn't change the byte order here because it'll be different from the rest of the values in this enum

Copy link
Collaborator

Choose a reason for hiding this comment

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

@seladb Actually I think 0x0200 is wrong, and it should be 0x0020 based on other enum value byte order.

Copy link
Owner

Choose a reason for hiding this comment

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

Do you happen to have a SSLv2 pcap that we can use in tests? If so, it'd be great to add a test for it!

When I wrote this code I couldn't find a pcap file...

Copy link
Author

@droe droe Jan 23, 2025

Choose a reason for hiding this comment

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

https://github.com/Lekensteyn/wireshark-notes/blob/master/ssl3/sslv2.pcapng

I don't think you currently support SSL 2 record format or SSL 2 compatible SSL 3 handshakes (as per RFC 6101 Appendix E); if you or a user of PCPP were to support the latter, you will have to handle either "0x00 0x02" or "0x03 0x00" / "0x03 0x01" / ... in the handshake version field. Therefore I do believe the best and most correct and useful value for the constant in the enum would be 0x0002. (Also note that SSL 2.0 is called "SSL 0.2" in the old Netscape spec.)

Copy link
Owner

Choose a reason for hiding this comment

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

That's great, thanks! Would you consider adding a test with a single SSLv2 packet from this file?

Copy link
Author

Choose a reason for hiding this comment

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

Fair request, I'll look into it.

Copy link
Author

Choose a reason for hiding this comment

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

SSL2RecordSSL2ClientHelloTest      : PASSED
SSL2RecordTLS1ClientHelloTest      : PASSED

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.

4 participants