1d4afb5ceSopenharmony_ci# lws minimal example for X509
2d4afb5ceSopenharmony_ci
3d4afb5ceSopenharmony_ciThe example shows how to:
4d4afb5ceSopenharmony_ci
5d4afb5ceSopenharmony_ci - confirm one PEM cert or chain (-c) was signed by a trusted PEM cert (-t)
6d4afb5ceSopenharmony_ci - convert a certificate public key to JWK
7d4afb5ceSopenharmony_ci - convert a certificate public key and its private key PEM to a private JWK
8d4afb5ceSopenharmony_ci
9d4afb5ceSopenharmony_ciThe examples work for EC and RSA certs and on mbedtls and OpenSSL the same.
10d4afb5ceSopenharmony_ci
11d4afb5ceSopenharmony_ciNotice the logging is on stderr, and only the JWK is output on stdout.
12d4afb5ceSopenharmony_ci
13d4afb5ceSopenharmony_ci## build
14d4afb5ceSopenharmony_ci
15d4afb5ceSopenharmony_ci```
16d4afb5ceSopenharmony_ci $ cmake . && make
17d4afb5ceSopenharmony_ci```
18d4afb5ceSopenharmony_ci
19d4afb5ceSopenharmony_ci## usage
20d4afb5ceSopenharmony_ci
21d4afb5ceSopenharmony_ciCommandline option|Meaning
22d4afb5ceSopenharmony_ci---|---
23d4afb5ceSopenharmony_ci-d <loglevel>|Debug verbosity in decimal, eg, -d15
24d4afb5ceSopenharmony_ci-c <PEM certificate path>|Required PEM Certificate(s) to operate on... may be multiple concatednated PEM
25d4afb5ceSopenharmony_ci-t <PEM certificate path>|Single PEM trusted certificate
26d4afb5ceSopenharmony_ci-p <PEM private key path>|Optional private key matching certificate given in -c.  If given, only the private JWK is printed to stdout
27d4afb5ceSopenharmony_ci
28d4afb5ceSopenharmony_ciExample for confirming trust relationship.  Notice the PEM in -c must contain not only
29d4afb5ceSopenharmony_cithe final certificate but also the certificates for any intermediate CAs.
30d4afb5ceSopenharmony_ci
31d4afb5ceSopenharmony_ci```
32d4afb5ceSopenharmony_ci $ ./lws-crypto-x509 -c ec-cert.pem -t ca-cert.pem
33d4afb5ceSopenharmony_ci[2019/01/02 20:31:13:2031] USER: LWS X509 api example
34d4afb5ceSopenharmony_ci[2019/01/02 20:31:13:2032] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off
35d4afb5ceSopenharmony_ci[2019/01/02 20:31:13:2043] NOTICE: main: certs loaded OK
36d4afb5ceSopenharmony_ci[2019/01/02 20:31:13:2043] NOTICE: main: verified OK  <<<<======
37d4afb5ceSopenharmony_ci[2019/01/02 20:31:13:2045] NOTICE: Cert Public JWK
38d4afb5ceSopenharmony_ci{"crv":"P-521","kty":"EC","x":"_uRNBbIbm0zhk8v6ujvQX9924264ZkqJhit0qamAoCegzuJbLf434kN7_aFEt6u-QWUu6-N1R8t6OlvrLo2jrNY","y":"AU-29XpNyB7e5e3s5t0ylzGEnF601A8A7Tx8m8xxngARZX_bn22itGJ3Y57BTcclPMoG80KjWAMnRVtrKqrD_aGD"}
39d4afb5ceSopenharmony_ci
40d4afb5ceSopenharmony_ci[2019/01/02 20:31:13:2045] NOTICE: main: OK
41d4afb5ceSopenharmony_ci```
42d4afb5ceSopenharmony_ci
43d4afb5ceSopenharmony_ciExample creating JWKs for public and public + private cert + PEM keys:
44d4afb5ceSopenharmony_ci
45d4afb5ceSopenharmony_ci```
46d4afb5ceSopenharmony_ci $ ./lws-crypto-x509 -c ec-cert.pem -p ec-key.pem
47d4afb5ceSopenharmony_ci[2019/01/02 20:14:43:4966] USER: LWS X509 api example
48d4afb5ceSopenharmony_ci[2019/01/02 20:14:43:5225] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off
49d4afb5ceSopenharmony_ci[2019/01/02 20:14:43:5707] NOTICE: lws_x509_public_to_jwk: EC key
50d4afb5ceSopenharmony_ci[2019/01/02 20:24:59:9514] USER: LWS X509 api example
51d4afb5ceSopenharmony_ci[2019/01/02 20:24:59:9741] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off
52d4afb5ceSopenharmony_ci[2019/01/02 20:25:00:1261] NOTICE: lws_x509_public_to_jwk: key type 408 "id-ecPublicKey"
53d4afb5ceSopenharmony_ci[2019/01/02 20:25:00:1269] NOTICE: lws_x509_public_to_jwk: EC key
54d4afb5ceSopenharmony_ci[2019/01/02 20:25:00:2097] NOTICE: Cert + Key Private JWK
55d4afb5ceSopenharmony_ci{"crv":"P-521","d":"AU3iQSKfPskMTW4ZncrYLhipUYzLYty2XhemTQ_nSuUB1vB76jHmOYUTRXFBLkVCW8cQYyMa5dMa3Bvv-cdvH0IB","kty":"EC","x":"_uRNBbIbm0zhk8v6ujvQX9924264ZkqJhit0qamAoCegzuJbLf434kN7_aFEt6u-QWUu6-N1R8t6OlvrLo2jrNY","y":"AU-29XpNyB7e5e3s5t0ylzGEnF601A8A7Tx8m8xxngARZX_bn22itGJ3Y57BTcclPMoG80KjWAMnRVtrKqrD_aGD"}
56d4afb5ceSopenharmony_ci
57d4afb5ceSopenharmony_ci[2019/01/02 20:25:00:2207] NOTICE: main: OK
58d4afb5ceSopenharmony_ci```
59d4afb5ceSopenharmony_ci
60