Closed ruhuang2001 closed 1 month ago
I try to use pipy debug mode show this output
$ ./pipy ../../certs/server/main.js --log-level=debug
2024-10-18 10:20:26.442 [DBG] [worker 0x7f6b78006690] ++
2024-10-18 10:20:26.442 [DBG] [module 0x7f6b78077f10] ++ index = 0
2024-10-18 10:20:26.443 [DBG] [context 0x7f6b78071e60] ++ id = 1
2024-10-18 10:20:26.451 [DBG] [context 0x7f6b78071e60] -- id = 1
2024-10-18 10:20:26.452 [INF] [config]
2024-10-18 10:20:26.452 [INF] [config] Module /main.js
2024-10-18 10:20:26.452 [INF] [config] ===============
2024-10-18 10:20:26.452 [INF] [config]
2024-10-18 10:20:26.452 [INF] [config] [Listen on 443 at 0.0.0.0]
2024-10-18 10:20:26.452 [INF] [config] ----->|
2024-10-18 10:20:26.452 [INF] [config] |
2024-10-18 10:20:26.452 [INF] [config] acceptTLS
2024-10-18 10:20:26.452 [INF] [config] |
2024-10-18 10:20:26.452 [INF] [config] |--> []
2024-10-18 10:20:26.452 [INF] [config] replaceMessage -->|
2024-10-18 10:20:26.452 [INF] [config] |
2024-10-18 10:20:26.452 [INF] [config] <-----------------------------|
2024-10-18 10:20:26.452 [INF] [config]
2024-10-18 10:20:26.452 [DBG] [pipeline] create layout: Pipeline at line 39
2024-10-18 10:20:26.452 [DBG] [pipeline] create layout: [0.0.0.0]:443
2024-10-18 10:20:26.452 [DBG] [inbound 0x7f6b78121010] ++
2024-10-18 10:20:26.452 [INF] [listener] Listening on TCP port 443 at 0.0.0.0
2024-10-18 10:20:26.452 [DBG] [thread] Thread 0 started
2024-10-18 10:20:44.116 [DBG] [inbound] [127.0.0.1]:36132 -> [127.0.0.1]:443 connection accepted
2024-10-18 10:20:44.116 [DBG] [context 0x7f6b78071e60] ++ id = 2
2024-10-18 10:20:44.116 [DBG] [pipeline] ++ [0.0.0.0]:443, active = 1, pooled = 0, context = 2
2024-10-18 10:20:44.116 [DBG] [inbound 0x7f6b78131640] ++
2024-10-18 10:20:44.116 [DBG] [listener] [accept] thread 0 port [0.0.0.0]:443 state: [open] local 1/-1 global 1/-1
T+0 tcp >>>> recv 58
2024-10-18 10:20:44.117 [DBG] [pipeline] ++ Pipeline at line 39, active = 1, pooled = 0, context = 2
2024-10-18 10:20:44.118 [WRN] [tls] handshake failed (error = 1)
2024-10-18 10:20:44.118 [WRN] [tls] error:0A0000C1:SSL routines::no shared cipher
2024-10-18 10:20:44.118 [DBG] [inbound] [127.0.0.1]:36132 -> [127.0.0.1]:443 socket shutdown
T+1.81ms tcp >>>> recv 7
2024-10-18 10:20:44.118 [WRN] [tls] handshake failed (error = 5)
2024-10-18 10:20:44.119 [DBG] [inbound] [127.0.0.1]:36132 -> [127.0.0.1]:443 EOF from peer
2024-10-18 10:20:44.119 [DBG] [inbound] [127.0.0.1]:36132 -> [127.0.0.1]:443 socket closed
2024-10-18 10:20:44.119 [DBG] [listener] [finish] thread 0 port [0.0.0.0]:443 state: [open] local 0/-1 global 0/-1
2024-10-18 10:20:44.119 [DBG] [inbound 0x7f6b78121010] --
2024-10-18 10:20:44.119 [DBG] [pipeline] -- Pipeline at line 39, active = 0, pooled = 1
2024-10-18 10:20:44.119 [DBG] [context 0x7f6b78071e60] -- id = 2
2024-10-18 10:20:44.119 [DBG] [pipeline] -- [0.0.0.0]:443, active = 0, pooled = 1
$ /opt/tongsuo/bin/tongsuo s_client -connect localhost:443 -cipher ECC-SM2-SM4-CBC-SM3 -enable_ntls -ntls -trace
CONNECTED(00000003)
Sent Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 53
ClientHello, Length=49
client_version=0x101 (NTLS)
Random:
gmt_unix_time=0x40F1DE70
random_bytes (len=28): 5AA50B0D17187D55C4B4CA589A311819E2FBF7B1910253A3CFE1684D
session_id (len=0):
cipher_suites (len=4)
{0xE0, 0x13} ECC_SM4_CBC_SM3
{0x00, 0xFF} TLS_EMPTY_RENEGOTIATION_INFO_SCSV
compression_methods (len=1)
No Compression (0x00)
extensions, length = 4
extension_type=session_ticket(35), length=0
Sent Record
Header:
Version = NTLS (0x101)
Content Type = Alert (21)
Length = 2
Level=fatal(2), description=decode error(50)
40A762DF7B7F0000:error:0A000126:SSL routines:ssl3_read_n:unexpected eof while reading:ssl/record/rec_layer_s3.c:306:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 65 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : NTLSv1.1
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1729218044
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
QUIC: no
---
@ruhuang2001 please help to share the pipy version you are using.
pipy -v
ok, by the way wsl ubuntu version is 22.04
$ ./pipy -v
Version : 1.5.1
Commit : 71e490e084cf887aeb0010cbe430a384e6effb67
Commit Date : Sun, 13 Oct 2024 11:07:36 +0800
Host : Linux-5.15.153.1-microsoft-standard-WSL2 x86_64
Tongsuo : Tongsuo 8.5.0-dev
Builtin GUI : No
Builtin Codebases: No
Codebase to work with NTLS is located under macro PIPY_USE_NTLS
in file tls.cpp
would appreciate if you can help to review and contribute changes (if required).
I tried to reproduce that but seems I'm getting different results than you
PS:
openssl
istongsuo
❯ apps/openssl s_client -connect localhost:8443 -enable_ntls -ntls -trace
CONNECTED(00000005)
Sent Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 67
ClientHello, Length=63
client_version=0x101 (NTLS)
Random:
gmt_unix_time=0x91999F19
random_bytes (len=28): B817A5FD20B4849DA017AEC62D96C139F818D613B45F596088EC62A2
session_id (len=0):
cipher_suites (len=18)
{0xE0, 0x53} ECC_SM4_GCM_SM3
{0xE0, 0x51} ECDHE_SM4_GCM_SM3
{0xE0, 0x5A} RSA_SM4_GCM_SHA256
{0xE0, 0x59} RSA_SM4_GCM_SM3
{0xE0, 0x13} ECC_SM4_CBC_SM3
{0xE0, 0x11} ECDHE_SM4_CBC_SM3
{0xE0, 0x1C} RSA_SM4_CBC_SHA256
{0xE0, 0x19} RSA_SM4_CBC_SM3
{0x00, 0xFF} TLS_EMPTY_RENEGOTIATION_INFO_SCSV
compression_methods (len=1)
No Compression (0x00)
extensions, length = 4
extension_type=session_ticket(35), length=0
Received Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 48
ServerHello, Length=44
server_version=0x101 (NTLS)
Random:
gmt_unix_time=0x95817C1F
random_bytes (len=28): E37767885A75F34E42A101478E9A6827BB812F0D87D20AFCF69DCA6B
session_id (len=0):
cipher_suite {0xE0, 0x53} ECC_SM4_GCM_SM3
compression_method: No Compression (0x00)
extensions, length = 4
extension_type=session_ticket(35), length=0
Can't use SSL_get_servername
Received Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 1006
Certificate, Length=1002
certificate_list, length=999
ASN.1Cert, length=498
------details-----
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
71:b2:93:95:ce:be:08:da:07:82:59:84:93:ec:66:f9:62:2a:65:c0
Signature Algorithm: SM2-with-SM3
Issuer: C = AA, ST = BB, O = CC, OU = DD, CN = sub ca
Validity
Not Before: Feb 22 02:30:14 2023 GMT
Not After : Jan 29 02:30:14 2123 GMT
Subject: C = AA, ST = BB, O = CC, OU = DD, CN = server sign
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:05:bf:fa:ee:c4:06:c8:f3:f5:80:a6:e3:9c:52:
84:76:c0:df:2b:61:06:5d:4a:74:f4:76:af:0f:b6:
68:90:f8:96:ac:c4:b2:1d:8b:03:6d:13:f1:7b:d4:
d3:82:34:90:8b:ed:b7:7f:8e:3e:ae:87:06:54:fc:
6f:a8:04:8d:0c
ASN1 OID: SM2
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
Digital Signature, Non Repudiation
X509v3 Subject Key Identifier:
7D:EE:06:A9:1D:A3:02:2F:93:FF:CF:EE:7E:54:B6:7A:55:F5:34:7A
X509v3 Authority Key Identifier:
AC:61:EB:22:80:62:59:08:3E:96:C8:D1:7F:CE:74:5C:02:AF:3C:99
Signature Algorithm: SM2-with-SM3
Signature Value:
30:46:02:21:00:b3:5b:fe:99:fd:df:c8:25:44:eb:3b:4a:3c:
9c:2c:4d:95:ee:91:d0:09:11:08:a5:05:85:6f:73:6c:84:65:
37:02:21:00:96:71:83:88:2c:d9:c5:76:40:5d:fb:a0:7b:3a:
f5:30:fe:32:44:5b:aa:5e:18:6f:8e:fe:8c:b7:fc:7f:6e:3b
-----BEGIN CERTIFICATE-----
MIIB7jCCAZOgAwIBAgIUcbKTlc6+CNoHglmEk+xm+WIqZcAwCgYIKoEcz1UBg3Uw
RTELMAkGA1UEBhMCQUExCzAJBgNVBAgMAkJCMQswCQYDVQQKDAJDQzELMAkGA1UE
CwwCREQxDzANBgNVBAMMBnN1YiBjYTAgFw0yMzAyMjIwMjMwMTRaGA8yMTIzMDEy
OTAyMzAxNFowSjELMAkGA1UEBhMCQUExCzAJBgNVBAgMAkJCMQswCQYDVQQKDAJD
QzELMAkGA1UECwwCREQxFDASBgNVBAMMC3NlcnZlciBzaWduMFkwEwYHKoZIzj0C
AQYIKoEcz1UBgi0DQgAEBb/67sQGyPP1gKbjnFKEdsDfK2EGXUp09HavD7ZokPiW
rMSyHYsDbRPxe9TTgjSQi+23f44+rocGVPxvqASNDKNaMFgwCQYDVR0TBAIwADAL
BgNVHQ8EBAMCBsAwHQYDVR0OBBYEFH3uBqkdowIvk//P7n5UtnpV9TR6MB8GA1Ud
IwQYMBaAFKxh6yKAYlkIPpbI0X/OdFwCrzyZMAoGCCqBHM9VAYN1A0kAMEYCIQCz
W/6Z/d/IJUTrO0o8nCxNle6R0AkRCKUFhW9zbIRlNwIhAJZxg4gs2cV2QF37oHs6
9TD+MkRbql4Yb47+jLf8f247
-----END CERTIFICATE-----
------------------
ASN.1Cert, length=495
------details-----
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
68:d8:92:e9:63:ac:a0:45:62:0e:79:9d:6f:c3:1d:93:74:33:e5:7c
Signature Algorithm: SM2-with-SM3
Issuer: C = AA, ST = BB, O = CC, OU = DD, CN = sub ca
Validity
Not Before: Feb 22 02:30:14 2023 GMT
Not After : Jan 29 02:30:14 2123 GMT
Subject: C = AA, ST = BB, O = CC, OU = DD, CN = server enc
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:7d:be:a5:45:43:45:81:72:bd:3b:68:8e:50:9c:
2d:f5:45:86:ac:e0:0b:58:ec:94:14:99:f9:4a:50:
a5:8c:67:5d:6f:9a:da:ff:08:9e:81:37:a7:63:43:
ac:d2:f3:5c:a3:0a:8a:5c:cf:81:b7:cd:ce:52:66:
a0:16:b9:e3:64
ASN1 OID: SM2
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
Key Encipherment, Data Encipherment, Key Agreement
X509v3 Subject Key Identifier:
67:A5:AD:D5:94:76:E0:5A:9C:5E:56:B8:86:0F:F1:3B:28:EE:EC:54
X509v3 Authority Key Identifier:
AC:61:EB:22:80:62:59:08:3E:96:C8:D1:7F:CE:74:5C:02:AF:3C:99
Signature Algorithm: SM2-with-SM3
Signature Value:
30:44:02:20:47:59:35:79:c4:ad:ec:8d:b7:df:98:c4:aa:e1:
66:1c:11:39:a5:ef:12:93:f2:2a:3a:a4:12:d0:9b:ec:d6:e6:
02:20:6e:57:30:1d:17:79:46:95:6f:d3:9c:b5:ac:60:39:02:
cd:17:c7:51:7e:d8:94:1e:cc:98:5e:a7:db:69:58:c8
-----BEGIN CERTIFICATE-----
MIIB6zCCAZKgAwIBAgIUaNiS6WOsoEViDnmdb8Mdk3Qz5XwwCgYIKoEcz1UBg3Uw
RTELMAkGA1UEBhMCQUExCzAJBgNVBAgMAkJCMQswCQYDVQQKDAJDQzELMAkGA1UE
CwwCREQxDzANBgNVBAMMBnN1YiBjYTAgFw0yMzAyMjIwMjMwMTRaGA8yMTIzMDEy
OTAyMzAxNFowSTELMAkGA1UEBhMCQUExCzAJBgNVBAgMAkJCMQswCQYDVQQKDAJD
QzELMAkGA1UECwwCREQxEzARBgNVBAMMCnNlcnZlciBlbmMwWTATBgcqhkjOPQIB
BggqgRzPVQGCLQNCAAR9vqVFQ0WBcr07aI5QnC31RYas4AtY7JQUmflKUKWMZ11v
mtr/CJ6BN6djQ6zS81yjCopcz4G3zc5SZqAWueNko1owWDAJBgNVHRMEAjAAMAsG
A1UdDwQEAwIDODAdBgNVHQ4EFgQUZ6Wt1ZR24FqcXla4hg/xOyju7FQwHwYDVR0j
BBgwFoAUrGHrIoBiWQg+lsjRf850XAKvPJkwCgYIKoEcz1UBg3UDRwAwRAIgR1k1
ecSt7I2335jEquFmHBE5pe8Sk/IqOqQS0Jvs1uYCIG5XMB0XeUaVb9OctaxgOQLN
F8dRftiUHsyYXqfbaVjI
-----END CERTIFICATE-----
------------------
depth=0 C = AA, ST = BB, O = CC, OU = DD, CN = server enc
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = AA, ST = BB, O = CC, OU = DD, CN = server enc
verify error:num=21:unable to verify the first certificate
verify return:1
depth=0 C = AA, ST = BB, O = CC, OU = DD, CN = server enc
verify return:1
depth=0 C = AA, ST = BB, O = CC, OU = DD, CN = server sign
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = AA, ST = BB, O = CC, OU = DD, CN = server sign
verify error:num=21:unable to verify the first certificate
verify return:1
depth=0 C = AA, ST = BB, O = CC, OU = DD, CN = server sign
verify return:1
Received Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 78
ServerKeyExchange, Length=74
KeyExchangeAlgorithm=SM2
Signature (len=72): 3046022100E0D20EBA5713FEB1217306CB7BEB26D0AF61E49E73C30679A94D47B5F622F231022100B621E47B130D7380978C62DECA1BD6B6A6DF3157A5A13FFFA18C242E5932529D
Received Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 4
ServerHelloDone, Length=0
Sent Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 162
ClientKeyExchange, Length=158
KeyExchangeAlgorithm=SM2
EncryptedPreMasterSecret (len=156): 30819902210096F70B37084138F772A6DEEFF763812A258DA51FFDF1B12AEB0DA58722827F7102200260B229420CADAF5350A0CD98EFC26ED088E0B642EC72E49A32AC69BD3AF75B04205D0EC8FAD05137A4F8B1E8027839DE81DCEC2163483247DD8CAF6BABECF4324D0430A9BE9DFCD1045C1828B6B204230B88FDEBA6F4C5EDF23D803E9C0F41D571AEE0FBE0F89F366C668CD353FC15044070DB
Sent Record
Header:
Version = NTLS (0x101)
Content Type = ChangeCipherSpec (20)
Length = 1
change_cipher_spec (1)
Sent Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 40
Finished, Length=12
verify_data (len=12): 65CA08B0E10E5E98CDF2CF42
Received Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 170
NewSessionTicket, Length=166
ticket_lifetime_hint=7200
ticket (len=160): 2671CE7987205F49BD589E578F145551351159B72032E167292C1E44F1FE6D7A6887BB1FCCAC2E81430E72EE5FDE9A336D3953912DF52CF87BFAB1BC69323B5003436A27122CD68547A7BCE60C1ACA43FD1CE9DD5B34E880597533919D24A0F0CFD331464514E516E9A8ADD21354E68A0BAF9693CAC74BE6C8ED8021F6CC802A11CEB105D18B9B049F05B5275E24C9DAA0FF7608FC39DB2D08BF25A0AADA94FB
Received Record
Header:
Version = NTLS (0x101)
Content Type = ChangeCipherSpec (20)
Length = 1
Received Record
Header:
Version = NTLS (0x101)
Content Type = Handshake (22)
Length = 40
Finished, Length=12
verify_data (len=12): 1CCEC571471DDBD1BE6CB1AF
---
Certificate chain
0 s:C = AA, ST = BB, O = CC, OU = DD, CN = server sign
i:C = AA, ST = BB, O = CC, OU = DD, CN = sub ca
a:PKEY: id-ecPublicKey, 256 (bit); sigalg: SM2-SM3
v:NotBefore: Feb 22 02:30:14 2023 GMT; NotAfter: Jan 29 02:30:14 2123 GMT
1 s:C = AA, ST = BB, O = CC, OU = DD, CN = server enc
i:C = AA, ST = BB, O = CC, OU = DD, CN = sub ca
a:PKEY: id-ecPublicKey, 256 (bit); sigalg: SM2-SM3
v:NotBefore: Feb 22 02:30:14 2023 GMT; NotAfter: Jan 29 02:30:14 2123 GMT
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIB7jCCAZOgAwIBAgIUcbKTlc6+CNoHglmEk+xm+WIqZcAwCgYIKoEcz1UBg3Uw
RTELMAkGA1UEBhMCQUExCzAJBgNVBAgMAkJCMQswCQYDVQQKDAJDQzELMAkGA1UE
CwwCREQxDzANBgNVBAMMBnN1YiBjYTAgFw0yMzAyMjIwMjMwMTRaGA8yMTIzMDEy
OTAyMzAxNFowSjELMAkGA1UEBhMCQUExCzAJBgNVBAgMAkJCMQswCQYDVQQKDAJD
QzELMAkGA1UECwwCREQxFDASBgNVBAMMC3NlcnZlciBzaWduMFkwEwYHKoZIzj0C
AQYIKoEcz1UBgi0DQgAEBb/67sQGyPP1gKbjnFKEdsDfK2EGXUp09HavD7ZokPiW
rMSyHYsDbRPxe9TTgjSQi+23f44+rocGVPxvqASNDKNaMFgwCQYDVR0TBAIwADAL
BgNVHQ8EBAMCBsAwHQYDVR0OBBYEFH3uBqkdowIvk//P7n5UtnpV9TR6MB8GA1Ud
IwQYMBaAFKxh6yKAYlkIPpbI0X/OdFwCrzyZMAoGCCqBHM9VAYN1A0kAMEYCIQCz
W/6Z/d/IJUTrO0o8nCxNle6R0AkRCKUFhW9zbIRlNwIhAJZxg4gs2cV2QF37oHs6
9TD+MkRbql4Yb47+jLf8f247
-----END CERTIFICATE-----
subject=C = AA, ST = BB, O = CC, OU = DD, CN = server sign
issuer=C = AA, ST = BB, O = CC, OU = DD, CN = sub ca
---
No client certificate CA names sent
Peer signing digest: SM3
Peer signature type: SM2
---
SSL handshake has read 1382 bytes and written 290 bytes
Verification error: unable to verify the first certificate
---
New, NTLSv1.1, Cipher is ECC-SM2-SM4-GCM-SM3
Server public key is 256 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : NTLSv1.1
Cipher : ECC-SM2-SM4-GCM-SM3
Session-ID: CA3136135E78560955CF4D4208A5B52F815F63B85123BA82131239A702ADEE66
Session-ID-ctx:
Master-Key: AA050F946E4E9D65DEB8D32ACB252715B83FF5BA2B25018065C6ECF6B34905C92BAD15AF73FE072DC5481EA7E43FFF74
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 26 71 ce 79 87 20 5f 49-bd 58 9e 57 8f 14 55 51 &q.y. _I.X.W..UQ
0010 - 35 11 59 b7 20 32 e1 67-29 2c 1e 44 f1 fe 6d 7a 5.Y. 2.g),.D..mz
0020 - 68 87 bb 1f cc ac 2e 81-43 0e 72 ee 5f de 9a 33 h.......C.r._..3
0030 - 6d 39 53 91 2d f5 2c f8-7b fa b1 bc 69 32 3b 50 m9S.-.,.{...i2;P
0040 - 03 43 6a 27 12 2c d6 85-47 a7 bc e6 0c 1a ca 43 .Cj'.,..G......C
0050 - fd 1c e9 dd 5b 34 e8 80-59 75 33 91 9d 24 a0 f0 ....[4..Yu3..$..
0060 - cf d3 31 46 45 14 e5 16-e9 a8 ad d2 13 54 e6 8a ..1FE........T..
0070 - 0b af 96 93 ca c7 4b e6-c8 ed 80 21 f6 cc 80 2a ......K....!...*
0080 - 11 ce b1 05 d1 8b 9b 04-9f 05 b5 27 5e 24 c9 da ...........'^$..
0090 - a0 ff 76 08 fc 39 db 2d-08 bf 25 a0 aa da 94 fb ..v..9.-..%.....
Start Time: 1729220594
Timeout : 7200 (sec)
Verify return code: 21 (unable to verify the first certificate)
Extended master secret: no
QUIC: no
---
and here is excerpt from sample i've used
and here is excerpt from sample i've used
I am a newcomer to cryptography.
I noticed that it seems like you're passing six arguments (cert
, key
, certSign
, certEnc
, keySign
, keyEnc
) to it. Could it be that my failure is due to the fact that I only passing four arguments (certSign
, certEnc
, keySign
, keyEnc
) to it like #192 ? I referenced the Tongsuo documentation to generate the file as follows:
I tried to reproduce that but seems I'm getting different results than you
PS:
openssl
istongsuo
❯ apps/openssl s_client -connect localhost:8443 -enable_ntls -ntls -trace CONNECTED(00000005) Sent Record Header: Version = NTLS (0x101) Content Type = Handshake (22) Length = 67 ClientHello, Length=63 ······················· No client certificate CA names sent Peer signing digest: SM3 Peer signature type: SM2 --- SSL handshake has read 1382 bytes and written 290 bytes Verification error: unable to verify the first certificate --- New, NTLSv1.1, Cipher is ECC-SM2-SM4-GCM-SM3 Server public key is 256 bit Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session: Protocol : NTLSv1.1 Cipher : ECC-SM2-SM4-GCM-SM3 Session-ID: CA3136135E78560955CF4D4208A5B52F815F63B85123BA82131239A702ADEE66 Session-ID-ctx: Master-Key: AA050F946E4E9D65DEB8D32ACB252715B83FF5BA2B25018065C6ECF6B34905C92BAD15AF73FE072DC5481EA7E43FFF74 PSK identity: None PSK identity hint: None SRP username: None TLS session ticket lifetime hint: 7200 (seconds) TLS session ticket: 0000 - 26 71 ce 79 87 20 5f 49-bd 58 9e 57 8f 14 55 51 &q.y. _I.X.W..UQ 0010 - 35 11 59 b7 20 32 e1 67-29 2c 1e 44 f1 fe 6d 7a 5.Y. 2.g),.D..mz 0020 - 68 87 bb 1f cc ac 2e 81-43 0e 72 ee 5f de 9a 33 h.......C.r._..3 0030 - 6d 39 53 91 2d f5 2c f8-7b fa b1 bc 69 32 3b 50 m9S.-.,.{...i2;P 0040 - 03 43 6a 27 12 2c d6 85-47 a7 bc e6 0c 1a ca 43 .Cj'.,..G......C 0050 - fd 1c e9 dd 5b 34 e8 80-59 75 33 91 9d 24 a0 f0 ....[4..Yu3..$.. 0060 - cf d3 31 46 45 14 e5 16-e9 a8 ad d2 13 54 e6 8a ..1FE........T.. 0070 - 0b af 96 93 ca c7 4b e6-c8 ed 80 21 f6 cc 80 2a ......K....!...* 0080 - 11 ce b1 05 d1 8b 9b 04-9f 05 b5 27 5e 24 c9 da ...........'^$.. 0090 - a0 ff 76 08 fc 39 db 2d-08 bf 25 a0 aa da 94 fb ..v..9.-..%..... Start Time: 1729220594 Timeout : 7200 (sec) Verify return code: 21 (unable to verify the first certificate) Extended master secret: no QUIC: no ---
you used the same main.js
for testing, right?
you used the same main.js for testing, right?
I used modified sample, but below is your provided sample script (with some minor tweaks)
var certSign = new crypto.Certificate(pipy.load('ntls/server_sign.crt'));
var keySign = new crypto.PrivateKey(pipy.load('ntls/server_sign.key'));
var certEnc = new crypto.Certificate(pipy.load('ntls/server_enc.crt'));
var keyEnc = new crypto.PrivateKey(pipy.load('ntls/server_enc.key'));
var cert = new crypto.Certificate(pipy.load("secret/server-cert.pem"));
var key = new crypto.PrivateKey(pipy.load("secret/server-key.pem"));
pipy()
.listen(443)
.acceptTLS({
ntls: true,
certificate: {
cert,
key,
certSign,
certEnc,
keySign,
keyEnc
},
ciphers: 'ECC-SM2-SM4-CBC-SM3',
})
.to(
$ => $.replaceMessage(
new Message({
status: 200,
headers: {
'Content-Type': 'text/html'
},
body: `<h1>TLS handshake successful with SM2! Welcome to the server.</h1>`
})
)
);
The error might be caused by this :
I noticed that it seems like you're passing six arguments (cert, key, certSign, certEnc, keySign, keyEnc) to it. Could it be that my failure is due to the fact that I only passing four arguments (certSign, certEnc, keySign, keyEnc) to it like https://github.com/flomesh-io/pipy/issues/192 ?
After adding cert
and key
auguments , it success recognize.
I used modified sample, but below is your provided sample script (with some minor tweaks)
var cert = new crypto.Certificate(pipy.load("secret/server-cert.pem")); var key = new crypto.PrivateKey(pipy.load("secret/server-key.pem")); ··· .acceptTLS({ ntls: true, certificate: { cert, key, certSign, certEnc, keySign, keyEnc }, ciphers: 'ECC-SM2-SM4-CBC-SM3', })
Thanks a lot!
Glad it helped. Feel free to close this issue
I am testing Pipy's support for the SM2 and wrote a simple file
main.js
based on the reply in #192.Opened a new terminal to test establishing an NTLS secure connection with the local server on port 443, but it seems unable to recognize its cipher.
Refer to Tongsuo Docs , I tested the
server.c
file with the Tongsuo-generated key certificates, and the results were successful as documented.Testing Process
![image](https://github.com/user-attachments/assets/731b2289-54d0-48f6-96ec-a800a47ed888) ```c // server.c #includeI noticed that this time the cipher was successfully recognized.
Based on this, I have a few questions:
main.js
?Thank you very much!