Author Topic: TlsLib4Pascal  (Read 4125 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 19978
  • Pointless static linking author
Re: TlsLib4Pascal
« Reply #30 on: September 04, 2026, 09:26:53 am »
Fresh install of the lot: fixed!
Everybody should use it.
« Last Edit: September 04, 2026, 10:52:21 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

Antek

  • New Member
  • *
  • Posts: 34
Re: TlsLib4Pascal
« Reply #31 on: September 17, 2026, 09:22:09 pm »
I just tested this lib within pixie htmlviewer example.
 TlsLibFclNetTls is used, inspired by thaddys example.
Great, big thanks!

Antek

  • New Member
  • *
  • Posts: 34
Re: TlsLib4Pascal
« Reply #32 on: September 17, 2026, 09:48:51 pm »
I changed my FTP client to use your library instead of OpenSSL and it works really nice!

Now it would be great to have SSH libraries in Pascal and FTP/SFTP/FTPS would work with no DLLs!

Yes,Yes I vote for SSH libs  :)

Xor-el

  • Sr. Member
  • ****
  • Posts: 438
Re: TlsLib4Pascal
« Reply #33 on: September 17, 2026, 10:24:54 pm »
I just tested this lib within pixie htmlviewer example.
 TlsLibFclNetTls is used, inspired by thaddys example.
Great, big thanks!

Glad to hear it worked for you! Thanks for testing and reporting back. Really appreciate it!

Xor-el

  • Sr. Member
  • ****
  • Posts: 438
Re: TlsLib4Pascal
« Reply #34 on: October 31, 2026, 09:15:48 pm »
TlsLib4Pascal v1.1 is out

A big update to the TLS 1.2/1.3 library for Free Pascal and Delphi.

Highlights
  • Encrypted Client Hello (RFC 9849) for TLS 1.3
  • TlsLib.Compliance: FIPS 140-3 and CNSA 1.0 policies; attests the Windows CNG module
  • OS-native crypto, opt-in: Windows CNG
  • OS-native live revocation, opt-in, on Windows and Apple, for clients and servers including mutual TLS
  • Host trust anchors: add your own root certificates (such as a private CA), and optionally a distrust list, to the system roots or use them instead, on every platform
  • Post-quantum hybrid key exchange with SecP256r1MLKEM768 (P-256 + ML-KEM), and an always-on check that certificate chains use acceptable signature algorithms and key sizes
  • TLS 1.2 pre-shared keys (ECDHE_PSK)
  • mORMot, Synapse, Indy and fcl-net adapters now read the host's PKCS#12 and in-memory certificate properties where it has them, and honour host cipher lists
  • Handshake failures report the specific reason, with the error origin and the peer's raw alert byte
  • Several certificate-trust and resumption fixes, name constraints enforced on every OS trust back end

New packages: TlsLib.Net, TlsLib.Crypto.System and TlsLib.Compliance.

Full release notes: https://github.com/Xor-el/TlsLib4Pascal/releases/tag/v1.1
Repository: https://github.com/Xor-el/TlsLib4Pascal

Feedback and bug reports are welcome.

dbannon

  • Hero Member
  • *****
  • Posts: 3927
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TlsLib4Pascal
« Reply #35 on: October 31, 2026, 11:57:49 pm »
Xor-el, even with my limited knowledge, I think this is a marvelous project. But every time I see it mentioned, I wonder what it is. 'T' for type, 'is' or 'ls', 'Lib4Pascal ? SansSerif fonts don't help that much.

I think if you called it TLSLib4Pascal, same spelling, different capitalization, it would be a lot clearer ?

Hope you don't mind ....

Davo

Lazarus 4, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Xor-el

  • Sr. Member
  • ****
  • Posts: 438
Re: TlsLib4Pascal
« Reply #36 on: November 01, 2026, 10:20:07 am »
Xor-el, even with my limited knowledge, I think this is a marvelous project. But every time I see it mentioned, I wonder what it is. 'T' for type, 'is' or 'ls', 'Lib4Pascal ? SansSerif fonts don't help that much.

I think if you called it TLSLib4Pascal, same spelling, different capitalization, it would be a lot clearer ?

Hope you don't mind ....

Davo

Hi Davo, thanks, and no offense taken. Fair point on the sans serif fonts, the "l" does look like an "I" there.
I'm sticking with the name though, it matches my other libs (HashLib4Pascal, CryptoLib4Pascal and so on). Think of it as Tls the word, not TLS the acronym. Glad you like the project.

Hobbit00

  • Jr. Member
  • **
  • Posts: 70
Re: TlsLib4Pascal
« Reply #37 on: November 01, 2026, 12:00:27 pm »
@Xor-el
I normally use other forum to interact with you, but that is temporary down.

Without adding "SecP256r1MLKEM768" to the group this is te result of scan of my Server (SNI), that is what I want:

Quote
# TLS 1.3 (suites in server-preferred order)
TLS_AES_256_GCM_SHA384 (0x1302)   X25519MLKEM768 (eq. 3072 bits RSA)   FS    256
TLS_CHACHA20_POLY1305_SHA256 (0x1303)   X25519MLKEM768 (eq. 3072 bits RSA)   FS    256
TLS_AES_128_GCM_SHA256 (0x1301)   X25519MLKEM768 (eq. 3072 bits RSA)   FS    128

Adding SecP256r1MLKEM768 this is the result:

Quote
# TLS 1.3 (we could not determine if the server has a preference)
TLS_AES_256_GCM_SHA384 (0x1302)   ECDH x25519 (eq. 3072 bits RSA)   FS    256

Group is composed by:

"TNamedGroupCatalog.X25519MlKem768, TNamedGroupCatalog.MlKem768, TNamedGroupCatalog.X25519, TNamedGroupCatalog.Secp521r1, TNamedGroupCatalog.Secp384r1, TNamedGroupCatalog.Secp256r1"

ChiperList is:

"TCipherSuites13.Aes256GcmSha384, TCipherSuites13.ChaCha20Poly1305Sha256, TCipherSuites13.Aes128GcmSha256
       ,TCipherSuites12.EcdheEcdsaAes256GcmSha384, TCipherSuites12.EcdheEcdsaAes128GcmSha256
       ,TCipherSuites12.EcdheEcdsaChaCha20Poly1305Sha256, TCipherSuites12.EcdheRsaAes256GcmSha384
       ,TCipherSuites12.EcdheRsaChaCha20Poly1305Sha256, TCipherSuites12.EcdheRsaAes128GcmSha256"

It's normal that there is no server preferences list when use the new "SecP256r1MLKEM768"  ?

Some connections (old devices) cannot occours adding the new "SecP256r1MLKEM768" (but that never minds).

I report here only TLS1.3 status, the TLS1.2 doesn't change.

Xor-el

  • Sr. Member
  • ****
  • Posts: 438
Re: TlsLib4Pascal
« Reply #38 on: November 01, 2026, 01:39:43 pm »
@Hobbit00 thanks for the detailed report and for trying the new group.

I tried to reproduce this with a TlsLib server (Compatible preset) using the group and cipher lists you posted, with the new group inserted at several positions, and so far I don't see a failure. The likeliest explanation is where the new group sits in the list.

How the server picks a group
The server walks its own list, in order, and takes the first group the client says it supports. It does not look at which group the client already sent a key share for. If the client sent no key share for the chosen group, the server sends a HelloRetryRequest (HRR), which is one extra round trip, and the client sends a second ClientHello. Suite preference is not affected.

What I saw (OpenSSL 3.6.1 and TlsLib's own client against a loopback TlsLib server, about 80 handshakes)
  • With SecP256r1MLKEM768 after X25519MlKem768 (second, middle or last), every client that offers X25519MLKEM768 or only classical groups behaved exactly as without the group: same group, same suite, same HRR or no HRR. The one difference is that a client offering only SecP256r1MLKEM768 now connects, where before it got handshake_failure.
  • With SecP256r1MLKEM768 first in the list, any client that merely lists it in supported_groups is moved onto it. If that client had sent its key share for X25519MLKEM768 or x25519, the server now answers with an HRR. The handshake still completes.
  • Classical-only clients (x25519, P-256, P-384, and TLS 1.2) got identical results with and without the group.
  • Offering a single suite, or the suites in reversed order, gave the same answers in every variant. The reversed-order probe still got the server's first choice, TLS_AES_256_GCM_SHA384.

Your questions
  • I don't think the loss of "server preference" comes from the server's suite choice. If SecP256r1MLKEM768 sits first in your list, my best guess is that the scanner advertises it, gets an HRR for it, and cannot finish that handshake, so only a classical probe works. That fits the single "ECDH x25519" line you got. This part is a guess, because I don't have your scanner here.
  • For the old devices I could not reproduce a failure. If a particular device really fails, I would need a capture to look at.

What to try
Put the new group right after X25519MLKEM768, which is where the library's own defaults put it. This is your list with the group inserted second, the order I tested as "second":
Code: Pascal  [Select][+][-]
  1. TNamedGroupCatalog.X25519MlKem768, TNamedGroupCatalog.SecP256r1MlKem768,
  2. TNamedGroupCatalog.MlKem768, TNamedGroupCatalog.X25519, TNamedGroupCatalog.Secp521r1,
  3. TNamedGroupCatalog.Secp384r1, TNamedGroupCatalog.Secp256r1
  4.  

What would settle it
Could you tell me:
  • where in your list you inserted SecP256r1MlKem768,
  • which scanner you used (name and version),
  • what the scanner's ClientHello contains (the groups it lists and the key share it sends)?
For the last one, if you already set a credential through a resolver, or can use one, this logs it. Adjust the unit names to your project:
Code: Pascal  [Select][+][-]
  1. uses SysUtils, TlpITlsCredentialResolver, TlpTlsCredential;
  2.  
  3. type
  4.   TLogResolver = class(TInterfacedObject, ITlsServerCredentialResolver)
  5.   public
  6.     Cred: TTlsCredential; // your existing server credential
  7.     function TryResolve(const AClientHello: TTlsClientHelloInfo;
  8.       out ACredential: TTlsCredential): Boolean;
  9.   end;
  10.  
  11. function TLogResolver.TryResolve(const AClientHello: TTlsClientHelloInfo;
  12.   out ACredential: TTlsCredential): Boolean;
  13. var
  14.   LI: Integer;
  15.   LGroups, LSuites: string;
  16. begin
  17.   LGroups := '';
  18.   for LI := 0 to High(AClientHello.SupportedGroups) do
  19.     LGroups := LGroups + '0x' + IntToHex(AClientHello.SupportedGroups[LI], 4) + ' ';
  20.   LSuites := '';
  21.   for LI := 0 to High(AClientHello.CipherSuites) do
  22.     LSuites := LSuites + '0x' + IntToHex(AClientHello.CipherSuites[LI], 4) + ' ';
  23.   Writeln('ClientHello groups: ', LGroups);
  24.   Writeln('ClientHello suites: ', LSuites);
  25.   ACredential := Cred;
  26.   Result := True;
  27. end;
  28.  
  29. // ... Builder.WithCredentialResolver(LResolver as ITlsServerCredentialResolver);
  30.  
Group 0x11EC is X25519MLKEM768, 0x11EB is SecP256r1MLKEM768, 0x001D is x25519 and 0x0017 is secp256r1. A line is printed once per ClientHello, so if the server sent an HRR you will see a second line from the same scan.

If you have OpenSSL 3.5 or newer, you can try the same probes yourself against your server:
Code: [Select]
openssl s_client -connect host:443 -tls1_3 -groups X25519MLKEM768:SecP256r1MLKEM768:X25519
openssl s_client -connect host:443 -tls1_3 -groups "*X25519:X25519MLKEM768:SecP256r1MLKEM768"
openssl s_client -connect host:443 -tls1_3 -groups SecP256r1MLKEM768
The second one sends a key share for x25519 only, which is the case that triggers an HRR when the hybrid is first in your list. The output shows the negotiated group.

Hobbit00

  • Jr. Member
  • **
  • Posts: 70
Re: TlsLib4Pascal
« Reply #39 on: November 01, 2026, 02:46:08 pm »
@Xor-el
Thanks for your quickly response.

I'm out now, what I can respond immediately is that I added the new "Sec..." group at he beginning of the list (the first).

This evening / tomorrow morning I will give you all informations and comparisons about.

The scanner is SSLLabs (https://www.ssllabs.com/ssltest/)

Xor-el

  • Sr. Member
  • ****
  • Posts: 438
Re: TlsLib4Pascal
« Reply #40 on: November 01, 2026, 06:19:27 pm »
@Xor-el
Thanks for your quickly response.

I'm out now, what I can respond immediately is that I added the new "Sec..." group at he beginning of the list (the first).

This evening / tomorrow morning I will give you all informations and comparisons about.

The scanner is SSLLabs (https://www.ssllabs.com/ssltest/)

@Hobbit00 thanks for the details, that was the missing piece. I found the cause, and it is not in TlsLib.

What is happening
SSL Labs sends a broken key share for SecP256r1MLKEM768. The share is built in the wrong order: the ML-KEM key comes first and the P-256 point last, while RFC 10024 section 4.1 says the P-256 point comes first. When your server prefers that group (it is first in your list), TlsLib picks it, sees the malformed share and rejects it, as any correct server would. SSL Labs' TLS 1.3 probes that need that share then fail, and only the classical ones get through. That is why your report dropped to one suite with "ECDH x25519" and no preference.

OpenSSL does exactly the same thing. I scanned an OpenSSL 3.6.1 server with SecP256r1MLKEM768 first and its own suite order, and got the same result: one suite, x25519, no preference. With X25519MLKEM768 first, both OpenSSL and TlsLib give a complete report with three suites and X25519MLKEM768.

I have reported the bug to SSL Labs: https://github.com/ssllabs/ssllabs-scan/issues/1026

What to do
Nothing is wrong with your server or with TlsLib. The reordering below is only a workaround for the SSL Labs bug, until they fix it. Keep SecP256r1MLKEM768 in the list, but put it after X25519MlKem768:
Code: Pascal  [Select][+][-]
  1. TNamedGroupCatalog.X25519MlKem768, TNamedGroupCatalog.SecP256r1MlKem768,
  2. TNamedGroupCatalog.MlKem768, TNamedGroupCatalog.X25519, TNamedGroupCatalog.Secp521r1,
  3. TNamedGroupCatalog.Secp384r1, TNamedGroupCatalog.Secp256r1
  4.  
Then the server prefers X25519MLKEM768, SSL Labs' bad share is never used, and the scan is complete again. Clients that send a correct share, like OpenSSL, work with the group in either position.

If you want to verify it with OpenSSL
You need OpenSSL 3.5 or newer and a host that SSL Labs can scan on port 443. This server puts SecP256r1MLKEM768 first:
Code: [Select]
openssl s_server -accept 443 -cert c.pem -key k.pem -serverpref -www \
  -groups "SecP256r1MLKEM768/X25519MLKEM768/MLKEM768/X25519/secp521r1/secp384r1/secp256r1"
Two details matter:
  • The / gives each group its own priority level, so the first group wins whenever the client lists it.
  • The -serverpref makes OpenSSL use its own suite order, like TlsLib. Without it OpenSSL follows the client's order and SSL Labs shows three suites (all x25519, still no preference) instead of one.
Scan it, then start it again with X25519MLKEM768 first:
Code: [Select]
openssl s_server -accept 443 -cert c.pem -key k.pem -serverpref -www \
  -groups "X25519MLKEM768/SecP256r1MLKEM768/MLKEM768/X25519/secp521r1/secp384r1/secp256r1"
and the scan comes back complete.

Hobbit00

  • Jr. Member
  • **
  • Posts: 70
Re: TlsLib4Pascal
« Reply #41 on: November 01, 2026, 06:48:31 pm »
I used now another scan and as you said the server works right  :D

Thanks for your support.

Xor-el

  • Sr. Member
  • ****
  • Posts: 438
Re: TlsLib4Pascal
« Reply #42 on: November 01, 2026, 06:57:11 pm »
I used now another scan and as you said the server works right  :D

Thanks for your support.

@Hobbit00 great, glad it works.

 

TinyPortal © 2005-2018