cjson
.github
workflows CI.yml ci-fuzz.yml
CONTRIBUTING.md
fuzzing
inputs test1 test10 test11 test2 test3 test3.bu test3.uf test3.uu test4 test5 test6 test7 test8 test9
.gitignore CMakeLists.txt afl-prepare-linux.sh afl.c afl.sh cjson_read_fuzzer.c fuzz_main.c json.dict ossfuzz.sh
library_config cJSONConfig.cmake.in cJSONConfigVersion.cmake.in libcjson.pc.in libcjson_utils.pc.in uninstall.cmake
tests
inputs test1 test1.expected test10 test10.expected test11 test11.expected test2 test2.expected test3 test3.expected test4 test4.expected test5 test5.expected test6 test7 test7.expected test8 test8.expected test9 test9.expected
json-patch-tests .editorconfig .gitignore .npmignore README.md cjson-utils-tests.json package.json spec_tests.json tests.json
unity
auto colour_prompt.rb colour_reporter.rb generate_config.yml generate_module.rb generate_test_runner.rb parse_output.rb stylize_as_junit.rb test_file_filter.rb type_sanitizer.rb unity_test_summary.py unity_test_summary.rb unity_to_junit.py
docs ThrowTheSwitchCodingStandard.md UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf UnityAssertionsReference.md UnityConfigurationGuide.md UnityGettingStartedGuide.md UnityHelperScriptsGuide.md license.txt
examples
example_1
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
makefile readme.txt
example_2
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
makefile readme.txt
example_3
helper UnityHelper.c UnityHelper.h
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
rakefile.rb rakefile_helper.rb readme.txt target_gcc_32.yml
unity_config.h
extras
eclipse error_parsers.txt
fixture
src unity_fixture.c unity_fixture.h unity_fixture_internals.h unity_fixture_malloc_overrides.h
rakefile.rb rakefile_helper.rb readme.txt
release build.info version.info
src unity.c unity.h unity_internals.h
.gitattributes .gitignore .travis.yml README.md
CMakeLists.txt cjson_add.c common.h compare_tests.c json_patch_tests.c minify_tests.c misc_tests.c misc_utils_tests.c old_utils_tests.c parse_array.c parse_examples.c parse_hex4.c parse_number.c parse_object.c parse_string.c parse_value.c parse_with_opts.c print_array.c print_number.c print_object.c print_string.c print_value.c readme_examples.c unity_setup.c
.editorconfig .gitattributes .gitignore .travis.yml CHANGELOG.md CMakeLists.txt CONTRIBUTORS.md LICENSE Makefile README.md SECURITY.md appveyor.yml cJSON.c cJSON.h cJSON_Utils.c cJSON_Utils.h test.c valgrind.supp
curl
.circleci config.yml
.github
ISSUE_TEMPLATE bug_report.yml config.yml docs.yml
scripts cleancmd.pl cmp-config.pl cmp-pkg-config.sh codespell-ignore.words codespell.sh distfiles.sh pyspelling.words pyspelling.yaml randcurl.pl requirements-docs.txt requirements-proselint.txt requirements.txt shellcheck-ci.sh shellcheck.sh spellcheck.curl trimmarkdownheader.pl typos.sh typos.toml verify-examples.pl verify-synopsis.pl yamlcheck.sh yamlcheck.yaml
workflows appveyor-status.yml checkdocs.yml checksrc.yml checkurls.yml codeql.yml configure-vs-cmake.yml curl-for-win.yml distcheck.yml fuzz.yml http3-linux.yml label.yml linux-old.yml linux.yml macos.yml non-native.yml windows.yml
CODEOWNERS CONTRIBUTING.md FUNDING.yml dependabot.yml labeler.yml lock.yml stale.yml
CMake CurlSymbolHiding.cmake CurlTests.c FindBrotli.cmake FindCares.cmake FindGSS.cmake FindGnuTLS.cmake FindLDAP.cmake FindLibbacktrace.cmake FindLibgsasl.cmake FindLibidn2.cmake FindLibpsl.cmake FindLibssh.cmake FindLibssh2.cmake FindLibuv.cmake FindMbedTLS.cmake FindNGHTTP2.cmake FindNGHTTP3.cmake FindNGTCP2.cmake FindNettle.cmake FindQuiche.cmake FindRustls.cmake FindWolfSSL.cmake FindZstd.cmake Macros.cmake OtherTests.cmake PickyWarnings.cmake Utilities.cmake cmake_uninstall.in.cmake curl-config.in.cmake unix-cache.cmake win32-cache.cmake
LICENSES BSD-4-Clause-UC.txt ISC.txt curl.txt
docs
cmdline-opts .gitignore CMakeLists.txt MANPAGE.md Makefile.am Makefile.inc _AUTHORS.md _BUGS.md _DESCRIPTION.md _ENVIRONMENT.md _EXITCODES.md _FILES.md _GLOBBING.md _NAME.md _OPTIONS.md _OUTPUT.md _PROGRESS.md _PROTOCOLS.md _PROXYPREFIX.md _SEEALSO.md _SYNOPSIS.md _URL.md _VARIABLES.md _VERSION.md _WWW.md abstract-unix-socket.md alt-svc.md anyauth.md append.md aws-sigv4.md basic.md ca-native.md cacert.md capath.md cert-status.md cert-type.md cert.md ciphers.md compressed-ssh.md compressed.md config.md connect-timeout.md connect-to.md continue-at.md cookie-jar.md cookie.md create-dirs.md create-file-mode.md crlf.md crlfile.md curves.md data-ascii.md data-binary.md data-raw.md data-urlencode.md data.md delegation.md digest.md disable-eprt.md disable-epsv.md disable.md disallow-username-in-url.md dns-interface.md dns-ipv4-addr.md dns-ipv6-addr.md dns-servers.md doh-cert-status.md doh-insecure.md doh-url.md dump-ca-embed.md dump-header.md ech.md egd-file.md engine.md etag-compare.md etag-save.md expect100-timeout.md fail-early.md fail-with-body.md fail.md false-start.md follow.md form-escape.md form-string.md form.md ftp-account.md ftp-alternative-to-user.md ftp-create-dirs.md ftp-method.md ftp-pasv.md ftp-port.md ftp-pret.md ftp-skip-pasv-ip.md ftp-ssl-ccc-mode.md ftp-ssl-ccc.md ftp-ssl-control.md get.md globoff.md happy-eyeballs-timeout-ms.md haproxy-clientip.md haproxy-protocol.md head.md header.md help.md hostpubmd5.md hostpubsha256.md hsts.md http0.9.md http1.0.md http1.1.md http2-prior-knowledge.md http2.md http3-only.md http3.md ignore-content-length.md insecure.md interface.md ip-tos.md ipfs-gateway.md ipv4.md ipv6.md json.md junk-session-cookies.md keepalive-cnt.md keepalive-time.md key-type.md key.md knownhosts.md krb.md libcurl.md limit-rate.md list-only.md local-port.md location-trusted.md location.md login-options.md mail-auth.md mail-from.md mail-rcpt-allowfails.md mail-rcpt.md mainpage.idx manual.md max-filesize.md max-redirs.md max-time.md metalink.md mptcp.md negotiate.md netrc-file.md netrc-optional.md netrc.md next.md no-alpn.md no-buffer.md no-clobber.md no-keepalive.md no-npn.md no-progress-meter.md no-sessionid.md noproxy.md ntlm-wb.md ntlm.md oauth2-bearer.md out-null.md output-dir.md output.md parallel-immediate.md parallel-max-host.md parallel-max.md parallel.md pass.md path-as-is.md pinnedpubkey.md post301.md post302.md post303.md preproxy.md progress-bar.md proto-default.md proto-redir.md proto.md proxy-anyauth.md proxy-basic.md proxy-ca-native.md proxy-cacert.md proxy-capath.md proxy-cert-type.md proxy-cert.md proxy-ciphers.md proxy-crlfile.md proxy-digest.md proxy-header.md proxy-http2.md proxy-insecure.md proxy-key-type.md proxy-key.md proxy-negotiate.md proxy-ntlm.md proxy-pass.md proxy-pinnedpubkey.md proxy-service-name.md proxy-ssl-allow-beast.md proxy-ssl-auto-client-cert.md proxy-tls13-ciphers.md proxy-tlsauthtype.md proxy-tlspassword.md proxy-tlsuser.md proxy-tlsv1.md proxy-user.md proxy.md proxy1.0.md proxytunnel.md pubkey.md quote.md random-file.md range.md rate.md raw.md referer.md remote-header-name.md remote-name-all.md remote-name.md remote-time.md remove-on-error.md request-target.md request.md resolve.md retry-all-errors.md retry-connrefused.md retry-delay.md retry-max-time.md retry.md sasl-authzid.md sasl-ir.md service-name.md show-error.md show-headers.md sigalgs.md silent.md skip-existing.md socks4.md socks4a.md socks5-basic.md socks5-gssapi-nec.md socks5-gssapi-service.md socks5-gssapi.md socks5-hostname.md socks5.md speed-limit.md speed-time.md ssl-allow-beast.md ssl-auto-client-cert.md ssl-no-revoke.md ssl-reqd.md ssl-revoke-best-effort.md ssl-sessions.md ssl.md sslv2.md sslv3.md stderr.md styled-output.md suppress-connect-headers.md tcp-fastopen.md tcp-nodelay.md telnet-option.md tftp-blksize.md tftp-no-options.md time-cond.md tls-earlydata.md tls-max.md tls13-ciphers.md tlsauthtype.md tlspassword.md tlsuser.md tlsv1.0.md tlsv1.1.md tlsv1.2.md tlsv1.3.md tlsv1.md tr-encoding.md trace-ascii.md trace-config.md trace-ids.md trace-time.md trace.md unix-socket.md upload-file.md upload-flags.md url-query.md url.md use-ascii.md user-agent.md user.md variable.md verbose.md version.md vlan-priority.md write-out.md xattr.md
examples .checksrc .gitignore 10-at-a-time.c CMakeLists.txt Makefile.am Makefile.example Makefile.inc README.md adddocsref.pl address-scope.c altsvc.c anyauthput.c block_ip.c cacertinmem.c certinfo.c chkspeed.c connect-to.c cookie_interface.c crawler.c debug.c default-scheme.c ephiperfifo.c evhiperfifo.c externalsocket.c fileupload.c ftp-delete.c ftp-wildcard.c ftpget.c ftpgetinfo.c ftpgetresp.c ftpsget.c ftpupload.c ftpuploadfrommem.c ftpuploadresume.c getinfo.c getinmemory.c getredirect.c getreferrer.c ghiper.c headerapi.c hiperfifo.c hsts-preload.c htmltidy.c htmltitle.cpp http-options.c http-post.c http2-download.c http2-pushinmemory.c http2-serverpush.c http2-upload.c http3-present.c http3.c httpcustomheader.c httpput-postfields.c httpput.c https.c imap-append.c imap-authzid.c imap-copy.c imap-create.c imap-delete.c imap-examine.c imap-fetch.c imap-list.c imap-lsub.c imap-multi.c imap-noop.c imap-search.c imap-ssl.c imap-store.c imap-tls.c interface.c ipv6.c keepalive.c localport.c log_failed_transfers.c maxconnects.c multi-app.c multi-debugcallback.c multi-double.c multi-event.c multi-formadd.c multi-legacy.c multi-post.c multi-single.c multi-uv.c netrc.c parseurl.c persistent.c pop3-authzid.c pop3-dele.c pop3-list.c pop3-multi.c pop3-noop.c pop3-retr.c pop3-ssl.c pop3-stat.c pop3-tls.c pop3-top.c pop3-uidl.c post-callback.c postinmemory.c postit2-formadd.c postit2.c progressfunc.c protofeats.c range.c resolve.c rtsp-options.c sendrecv.c sepheaders.c sessioninfo.c sftpget.c sftpuploadresume.c shared-connection-cache.c simple.c simplepost.c simplessl.c smooth-gtk-thread.c smtp-authzid.c smtp-expn.c smtp-mail.c smtp-mime.c smtp-multi.c smtp-ssl.c smtp-tls.c smtp-vrfy.c sslbackend.c synctime.c threaded.c unixsocket.c url2file.c urlapi.c usercertinmem.c version-check.pl websocket-cb.c websocket-updown.c websocket.c xmlstream.c
internals BUFQ.md BUFREF.md CHECKSRC.md CLIENT-READERS.md CLIENT-WRITERS.md CODE_STYLE.md CONNECTION-FILTERS.md CREDENTIALS.md CURLX.md DYNBUF.md HASH.md LLIST.md MID.md MQTT.md MULTI-EV.md NEW-PROTOCOL.md PEERS.md PORTING.md RATELIMITS.md README.md SCORECARD.md SPLAY.md STRPARSE.md THRDPOOL-AND-QUEUE.md TIME-KEEPING.md TLS-SESSIONS.md UINT_SETS.md WEBSOCKET.md
libcurl
opts CMakeLists.txt CURLINFO_ACTIVESOCKET.md CURLINFO_APPCONNECT_TIME.md CURLINFO_APPCONNECT_TIME_T.md CURLINFO_CAINFO.md CURLINFO_CAPATH.md CURLINFO_CERTINFO.md CURLINFO_CONDITION_UNMET.md CURLINFO_CONNECT_TIME.md CURLINFO_CONNECT_TIME_T.md CURLINFO_CONN_ID.md CURLINFO_CONTENT_LENGTH_DOWNLOAD.md CURLINFO_CONTENT_LENGTH_DOWNLOAD_T.md CURLINFO_CONTENT_LENGTH_UPLOAD.md CURLINFO_CONTENT_LENGTH_UPLOAD_T.md CURLINFO_CONTENT_TYPE.md CURLINFO_COOKIELIST.md CURLINFO_EARLYDATA_SENT_T.md CURLINFO_EFFECTIVE_METHOD.md CURLINFO_EFFECTIVE_URL.md CURLINFO_FILETIME.md CURLINFO_FILETIME_T.md CURLINFO_FTP_ENTRY_PATH.md CURLINFO_HEADER_SIZE.md CURLINFO_HTTPAUTH_AVAIL.md CURLINFO_HTTPAUTH_USED.md CURLINFO_HTTP_CONNECTCODE.md CURLINFO_HTTP_VERSION.md CURLINFO_LASTSOCKET.md CURLINFO_LOCAL_IP.md CURLINFO_LOCAL_PORT.md CURLINFO_NAMELOOKUP_TIME.md CURLINFO_NAMELOOKUP_TIME_T.md CURLINFO_NUM_CONNECTS.md CURLINFO_OS_ERRNO.md CURLINFO_POSTTRANSFER_TIME_T.md CURLINFO_PRETRANSFER_TIME.md CURLINFO_PRETRANSFER_TIME_T.md CURLINFO_PRIMARY_IP.md CURLINFO_PRIMARY_PORT.md CURLINFO_PRIVATE.md CURLINFO_PROTOCOL.md CURLINFO_PROXYAUTH_AVAIL.md CURLINFO_PROXYAUTH_USED.md CURLINFO_PROXY_ERROR.md CURLINFO_PROXY_SSL_VERIFYRESULT.md CURLINFO_QUEUE_TIME_T.md CURLINFO_REDIRECT_COUNT.md CURLINFO_REDIRECT_TIME.md CURLINFO_REDIRECT_TIME_T.md CURLINFO_REDIRECT_URL.md CURLINFO_REFERER.md CURLINFO_REQUEST_SIZE.md CURLINFO_RESPONSE_CODE.md CURLINFO_RETRY_AFTER.md CURLINFO_RTSP_CLIENT_CSEQ.md CURLINFO_RTSP_CSEQ_RECV.md CURLINFO_RTSP_SERVER_CSEQ.md CURLINFO_RTSP_SESSION_ID.md CURLINFO_SCHEME.md CURLINFO_SIZE_DELIVERED.md CURLINFO_SIZE_DOWNLOAD.md CURLINFO_SIZE_DOWNLOAD_T.md CURLINFO_SIZE_UPLOAD.md CURLINFO_SIZE_UPLOAD_T.md CURLINFO_SPEED_DOWNLOAD.md CURLINFO_SPEED_DOWNLOAD_T.md CURLINFO_SPEED_UPLOAD.md CURLINFO_SPEED_UPLOAD_T.md CURLINFO_SSL_ENGINES.md CURLINFO_SSL_VERIFYRESULT.md CURLINFO_STARTTRANSFER_TIME.md CURLINFO_STARTTRANSFER_TIME_T.md CURLINFO_TLS_SESSION.md CURLINFO_TLS_SSL_PTR.md CURLINFO_TOTAL_TIME.md CURLINFO_TOTAL_TIME_T.md CURLINFO_USED_PROXY.md CURLINFO_XFER_ID.md CURLMINFO_XFERS_ADDED.md CURLMINFO_XFERS_CURRENT.md CURLMINFO_XFERS_DONE.md CURLMINFO_XFERS_PENDING.md CURLMINFO_XFERS_RUNNING.md CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE.md CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE.md CURLMOPT_MAXCONNECTS.md CURLMOPT_MAX_CONCURRENT_STREAMS.md CURLMOPT_MAX_HOST_CONNECTIONS.md CURLMOPT_MAX_PIPELINE_LENGTH.md CURLMOPT_MAX_TOTAL_CONNECTIONS.md CURLMOPT_NETWORK_CHANGED.md CURLMOPT_NOTIFYDATA.md CURLMOPT_NOTIFYFUNCTION.md CURLMOPT_PIPELINING.md CURLMOPT_PIPELINING_SERVER_BL.md CURLMOPT_PIPELINING_SITE_BL.md CURLMOPT_PUSHDATA.md CURLMOPT_PUSHFUNCTION.md CURLMOPT_QUICK_EXIT.md CURLMOPT_RESOLVE_THREADS_MAX.md CURLMOPT_SOCKETDATA.md CURLMOPT_SOCKETFUNCTION.md CURLMOPT_TIMERDATA.md CURLMOPT_TIMERFUNCTION.md CURLOPT_ABSTRACT_UNIX_SOCKET.md CURLOPT_ACCEPTTIMEOUT_MS.md CURLOPT_ACCEPT_ENCODING.md CURLOPT_ADDRESS_SCOPE.md CURLOPT_ALTSVC.md CURLOPT_ALTSVC_CTRL.md CURLOPT_APPEND.md CURLOPT_AUTOREFERER.md CURLOPT_AWS_SIGV4.md CURLOPT_BUFFERSIZE.md CURLOPT_CAINFO.md CURLOPT_CAINFO_BLOB.md CURLOPT_CAPATH.md CURLOPT_CA_CACHE_TIMEOUT.md CURLOPT_CERTINFO.md CURLOPT_CHUNK_BGN_FUNCTION.md CURLOPT_CHUNK_DATA.md CURLOPT_CHUNK_END_FUNCTION.md CURLOPT_CLOSESOCKETDATA.md CURLOPT_CLOSESOCKETFUNCTION.md CURLOPT_CONNECTTIMEOUT.md CURLOPT_CONNECTTIMEOUT_MS.md CURLOPT_CONNECT_ONLY.md CURLOPT_CONNECT_TO.md CURLOPT_CONV_FROM_NETWORK_FUNCTION.md CURLOPT_CONV_FROM_UTF8_FUNCTION.md CURLOPT_CONV_TO_NETWORK_FUNCTION.md CURLOPT_COOKIE.md CURLOPT_COOKIEFILE.md CURLOPT_COOKIEJAR.md CURLOPT_COOKIELIST.md CURLOPT_COOKIESESSION.md CURLOPT_COPYPOSTFIELDS.md CURLOPT_CRLF.md CURLOPT_CRLFILE.md CURLOPT_CURLU.md CURLOPT_CUSTOMREQUEST.md CURLOPT_DEBUGDATA.md CURLOPT_DEBUGFUNCTION.md CURLOPT_DEFAULT_PROTOCOL.md CURLOPT_DIRLISTONLY.md CURLOPT_DISALLOW_USERNAME_IN_URL.md CURLOPT_DNS_CACHE_TIMEOUT.md CURLOPT_DNS_INTERFACE.md CURLOPT_DNS_LOCAL_IP4.md CURLOPT_DNS_LOCAL_IP6.md CURLOPT_DNS_SERVERS.md CURLOPT_DNS_SHUFFLE_ADDRESSES.md CURLOPT_DNS_USE_GLOBAL_CACHE.md CURLOPT_DOH_SSL_VERIFYHOST.md CURLOPT_DOH_SSL_VERIFYPEER.md CURLOPT_DOH_SSL_VERIFYSTATUS.md CURLOPT_DOH_URL.md CURLOPT_ECH.md CURLOPT_EGDSOCKET.md CURLOPT_ERRORBUFFER.md CURLOPT_EXPECT_100_TIMEOUT_MS.md CURLOPT_FAILONERROR.md CURLOPT_FILETIME.md CURLOPT_FNMATCH_DATA.md CURLOPT_FNMATCH_FUNCTION.md CURLOPT_FOLLOWLOCATION.md CURLOPT_FORBID_REUSE.md CURLOPT_FRESH_CONNECT.md CURLOPT_FTPPORT.md CURLOPT_FTPSSLAUTH.md CURLOPT_FTP_ACCOUNT.md CURLOPT_FTP_ALTERNATIVE_TO_USER.md CURLOPT_FTP_CREATE_MISSING_DIRS.md CURLOPT_FTP_FILEMETHOD.md CURLOPT_FTP_SKIP_PASV_IP.md CURLOPT_FTP_SSL_CCC.md CURLOPT_FTP_USE_EPRT.md CURLOPT_FTP_USE_EPSV.md CURLOPT_FTP_USE_PRET.md CURLOPT_GSSAPI_DELEGATION.md CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.md CURLOPT_HAPROXYPROTOCOL.md CURLOPT_HAPROXY_CLIENT_IP.md CURLOPT_HEADER.md CURLOPT_HEADERDATA.md CURLOPT_HEADERFUNCTION.md CURLOPT_HEADEROPT.md CURLOPT_HSTS.md CURLOPT_HSTSREADDATA.md CURLOPT_HSTSREADFUNCTION.md CURLOPT_HSTSWRITEDATA.md CURLOPT_HSTSWRITEFUNCTION.md CURLOPT_HSTS_CTRL.md CURLOPT_HTTP09_ALLOWED.md CURLOPT_HTTP200ALIASES.md CURLOPT_HTTPAUTH.md CURLOPT_HTTPGET.md CURLOPT_HTTPHEADER.md CURLOPT_HTTPPOST.md CURLOPT_HTTPPROXYTUNNEL.md CURLOPT_HTTP_CONTENT_DECODING.md CURLOPT_HTTP_TRANSFER_DECODING.md CURLOPT_HTTP_VERSION.md CURLOPT_IGNORE_CONTENT_LENGTH.md CURLOPT_INFILESIZE.md CURLOPT_INFILESIZE_LARGE.md CURLOPT_INTERFACE.md CURLOPT_INTERLEAVEDATA.md CURLOPT_INTERLEAVEFUNCTION.md CURLOPT_IOCTLDATA.md CURLOPT_IOCTLFUNCTION.md CURLOPT_IPRESOLVE.md CURLOPT_ISSUERCERT.md CURLOPT_ISSUERCERT_BLOB.md CURLOPT_KEEP_SENDING_ON_ERROR.md CURLOPT_KEYPASSWD.md CURLOPT_KRBLEVEL.md CURLOPT_LOCALPORT.md CURLOPT_LOCALPORTRANGE.md CURLOPT_LOGIN_OPTIONS.md CURLOPT_LOW_SPEED_LIMIT.md CURLOPT_LOW_SPEED_TIME.md CURLOPT_MAIL_AUTH.md CURLOPT_MAIL_FROM.md CURLOPT_MAIL_RCPT.md CURLOPT_MAIL_RCPT_ALLOWFAILS.md CURLOPT_MAXAGE_CONN.md CURLOPT_MAXCONNECTS.md CURLOPT_MAXFILESIZE.md CURLOPT_MAXFILESIZE_LARGE.md CURLOPT_MAXLIFETIME_CONN.md CURLOPT_MAXREDIRS.md CURLOPT_MAX_RECV_SPEED_LARGE.md CURLOPT_MAX_SEND_SPEED_LARGE.md CURLOPT_MIMEPOST.md CURLOPT_MIME_OPTIONS.md CURLOPT_NETRC.md CURLOPT_NETRC_FILE.md CURLOPT_NEW_DIRECTORY_PERMS.md CURLOPT_NEW_FILE_PERMS.md CURLOPT_NOBODY.md CURLOPT_NOPROGRESS.md CURLOPT_NOPROXY.md CURLOPT_NOSIGNAL.md CURLOPT_OPENSOCKETDATA.md CURLOPT_OPENSOCKETFUNCTION.md CURLOPT_PASSWORD.md CURLOPT_PATH_AS_IS.md CURLOPT_PINNEDPUBLICKEY.md CURLOPT_PIPEWAIT.md CURLOPT_PORT.md CURLOPT_POST.md CURLOPT_POSTFIELDS.md CURLOPT_POSTFIELDSIZE.md CURLOPT_POSTFIELDSIZE_LARGE.md CURLOPT_POSTQUOTE.md CURLOPT_POSTREDIR.md CURLOPT_PREQUOTE.md CURLOPT_PREREQDATA.md CURLOPT_PREREQFUNCTION.md CURLOPT_PRE_PROXY.md CURLOPT_PRIVATE.md CURLOPT_PROGRESSDATA.md CURLOPT_PROGRESSFUNCTION.md CURLOPT_PROTOCOLS.md CURLOPT_PROTOCOLS_STR.md CURLOPT_PROXY.md CURLOPT_PROXYAUTH.md CURLOPT_PROXYHEADER.md CURLOPT_PROXYPASSWORD.md CURLOPT_PROXYPORT.md CURLOPT_PROXYTYPE.md CURLOPT_PROXYUSERNAME.md CURLOPT_PROXYUSERPWD.md CURLOPT_PROXY_CAINFO.md CURLOPT_PROXY_CAINFO_BLOB.md CURLOPT_PROXY_CAPATH.md CURLOPT_PROXY_CRLFILE.md CURLOPT_PROXY_ISSUERCERT.md CURLOPT_PROXY_ISSUERCERT_BLOB.md CURLOPT_PROXY_KEYPASSWD.md CURLOPT_PROXY_PINNEDPUBLICKEY.md CURLOPT_PROXY_SERVICE_NAME.md CURLOPT_PROXY_SSLCERT.md CURLOPT_PROXY_SSLCERTTYPE.md CURLOPT_PROXY_SSLCERT_BLOB.md CURLOPT_PROXY_SSLKEY.md CURLOPT_PROXY_SSLKEYTYPE.md CURLOPT_PROXY_SSLKEY_BLOB.md CURLOPT_PROXY_SSLVERSION.md CURLOPT_PROXY_SSL_CIPHER_LIST.md CURLOPT_PROXY_SSL_OPTIONS.md CURLOPT_PROXY_SSL_VERIFYHOST.md CURLOPT_PROXY_SSL_VERIFYPEER.md CURLOPT_PROXY_TLS13_CIPHERS.md CURLOPT_PROXY_TLSAUTH_PASSWORD.md CURLOPT_PROXY_TLSAUTH_TYPE.md CURLOPT_PROXY_TLSAUTH_USERNAME.md CURLOPT_PROXY_TRANSFER_MODE.md CURLOPT_PUT.md CURLOPT_QUICK_EXIT.md CURLOPT_QUOTE.md CURLOPT_RANDOM_FILE.md CURLOPT_RANGE.md CURLOPT_READDATA.md CURLOPT_READFUNCTION.md CURLOPT_REDIR_PROTOCOLS.md CURLOPT_REDIR_PROTOCOLS_STR.md CURLOPT_REFERER.md CURLOPT_REQUEST_TARGET.md CURLOPT_RESOLVE.md CURLOPT_RESOLVER_START_DATA.md CURLOPT_RESOLVER_START_FUNCTION.md CURLOPT_RESUME_FROM.md CURLOPT_RESUME_FROM_LARGE.md CURLOPT_RTSP_CLIENT_CSEQ.md CURLOPT_RTSP_REQUEST.md CURLOPT_RTSP_SERVER_CSEQ.md CURLOPT_RTSP_SESSION_ID.md CURLOPT_RTSP_STREAM_URI.md CURLOPT_RTSP_TRANSPORT.md CURLOPT_SASL_AUTHZID.md CURLOPT_SASL_IR.md CURLOPT_SEEKDATA.md CURLOPT_SEEKFUNCTION.md CURLOPT_SERVER_RESPONSE_TIMEOUT.md CURLOPT_SERVER_RESPONSE_TIMEOUT_MS.md CURLOPT_SERVICE_NAME.md CURLOPT_SHARE.md CURLOPT_SOCKOPTDATA.md CURLOPT_SOCKOPTFUNCTION.md CURLOPT_SOCKS5_AUTH.md CURLOPT_SOCKS5_GSSAPI_NEC.md CURLOPT_SOCKS5_GSSAPI_SERVICE.md CURLOPT_SSH_AUTH_TYPES.md CURLOPT_SSH_COMPRESSION.md CURLOPT_SSH_HOSTKEYDATA.md CURLOPT_SSH_HOSTKEYFUNCTION.md CURLOPT_SSH_HOST_PUBLIC_KEY_MD5.md CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256.md CURLOPT_SSH_KEYDATA.md CURLOPT_SSH_KEYFUNCTION.md CURLOPT_SSH_KNOWNHOSTS.md CURLOPT_SSH_PRIVATE_KEYFILE.md CURLOPT_SSH_PUBLIC_KEYFILE.md CURLOPT_SSLCERT.md CURLOPT_SSLCERTTYPE.md CURLOPT_SSLCERT_BLOB.md CURLOPT_SSLENGINE.md CURLOPT_SSLENGINE_DEFAULT.md CURLOPT_SSLKEY.md CURLOPT_SSLKEYTYPE.md CURLOPT_SSLKEY_BLOB.md CURLOPT_SSLVERSION.md CURLOPT_SSL_CIPHER_LIST.md CURLOPT_SSL_CTX_DATA.md CURLOPT_SSL_CTX_FUNCTION.md CURLOPT_SSL_EC_CURVES.md CURLOPT_SSL_ENABLE_ALPN.md CURLOPT_SSL_ENABLE_NPN.md CURLOPT_SSL_FALSESTART.md CURLOPT_SSL_OPTIONS.md CURLOPT_SSL_SESSIONID_CACHE.md CURLOPT_SSL_SIGNATURE_ALGORITHMS.md CURLOPT_SSL_VERIFYHOST.md CURLOPT_SSL_VERIFYPEER.md CURLOPT_SSL_VERIFYSTATUS.md CURLOPT_STDERR.md CURLOPT_STREAM_DEPENDS.md CURLOPT_STREAM_DEPENDS_E.md CURLOPT_STREAM_WEIGHT.md CURLOPT_SUPPRESS_CONNECT_HEADERS.md CURLOPT_TCP_FASTOPEN.md CURLOPT_TCP_KEEPALIVE.md CURLOPT_TCP_KEEPCNT.md CURLOPT_TCP_KEEPIDLE.md CURLOPT_TCP_KEEPINTVL.md CURLOPT_TCP_NODELAY.md CURLOPT_TELNETOPTIONS.md CURLOPT_TFTP_BLKSIZE.md CURLOPT_TFTP_NO_OPTIONS.md CURLOPT_TIMECONDITION.md CURLOPT_TIMEOUT.md CURLOPT_TIMEOUT_MS.md CURLOPT_TIMEVALUE.md CURLOPT_TIMEVALUE_LARGE.md CURLOPT_TLS13_CIPHERS.md CURLOPT_TLSAUTH_PASSWORD.md CURLOPT_TLSAUTH_TYPE.md CURLOPT_TLSAUTH_USERNAME.md CURLOPT_TRAILERDATA.md CURLOPT_TRAILERFUNCTION.md CURLOPT_TRANSFERTEXT.md CURLOPT_TRANSFER_ENCODING.md CURLOPT_UNIX_SOCKET_PATH.md CURLOPT_UNRESTRICTED_AUTH.md CURLOPT_UPKEEP_INTERVAL_MS.md CURLOPT_UPLOAD.md CURLOPT_UPLOAD_BUFFERSIZE.md CURLOPT_UPLOAD_FLAGS.md CURLOPT_URL.md CURLOPT_USERAGENT.md CURLOPT_USERNAME.md CURLOPT_USERPWD.md CURLOPT_USE_SSL.md CURLOPT_VERBOSE.md CURLOPT_WILDCARDMATCH.md CURLOPT_WRITEDATA.md CURLOPT_WRITEFUNCTION.md CURLOPT_WS_OPTIONS.md CURLOPT_XFERINFODATA.md CURLOPT_XFERINFOFUNCTION.md CURLOPT_XOAUTH2_BEARER.md CURLSHOPT_LOCKFUNC.md CURLSHOPT_SHARE.md CURLSHOPT_UNLOCKFUNC.md CURLSHOPT_UNSHARE.md CURLSHOPT_USERDATA.md Makefile.am Makefile.inc
.gitignore ABI.md CMakeLists.txt Makefile.am Makefile.inc curl_easy_cleanup.md curl_easy_duphandle.md curl_easy_escape.md curl_easy_getinfo.md curl_easy_header.md curl_easy_init.md curl_easy_nextheader.md curl_easy_option_by_id.md curl_easy_option_by_name.md curl_easy_option_next.md curl_easy_pause.md curl_easy_perform.md curl_easy_recv.md curl_easy_reset.md curl_easy_send.md curl_easy_setopt.md curl_easy_ssls_export.md curl_easy_ssls_import.md curl_easy_strerror.md curl_easy_unescape.md curl_easy_upkeep.md curl_escape.md curl_formadd.md curl_formfree.md curl_formget.md curl_free.md curl_getdate.md curl_getenv.md curl_global_cleanup.md curl_global_init.md curl_global_init_mem.md curl_global_sslset.md curl_global_trace.md curl_mime_addpart.md curl_mime_data.md curl_mime_data_cb.md curl_mime_encoder.md curl_mime_filedata.md curl_mime_filename.md curl_mime_free.md curl_mime_headers.md curl_mime_init.md curl_mime_name.md curl_mime_subparts.md curl_mime_type.md curl_mprintf.md curl_multi_add_handle.md curl_multi_assign.md curl_multi_cleanup.md curl_multi_fdset.md curl_multi_get_handles.md curl_multi_get_offt.md curl_multi_info_read.md curl_multi_init.md curl_multi_notify_disable.md curl_multi_notify_enable.md curl_multi_perform.md curl_multi_poll.md curl_multi_remove_handle.md curl_multi_setopt.md curl_multi_socket.md curl_multi_socket_action.md curl_multi_socket_all.md curl_multi_strerror.md curl_multi_timeout.md curl_multi_wait.md curl_multi_waitfds.md curl_multi_wakeup.md curl_pushheader_byname.md curl_pushheader_bynum.md curl_share_cleanup.md curl_share_init.md curl_share_setopt.md curl_share_strerror.md curl_slist_append.md curl_slist_free_all.md curl_strequal.md curl_strnequal.md curl_unescape.md curl_url.md curl_url_cleanup.md curl_url_dup.md curl_url_get.md curl_url_set.md curl_url_strerror.md curl_version.md curl_version_info.md curl_ws_meta.md curl_ws_recv.md curl_ws_send.md curl_ws_start_frame.md libcurl-easy.md libcurl-env-dbg.md libcurl-env.md libcurl-errors.md libcurl-multi.md libcurl-security.md libcurl-share.md libcurl-thread.md libcurl-tutorial.md libcurl-url.md libcurl-ws.md libcurl.m4 libcurl.md mksymbolsmanpage.pl symbols-in-versions symbols.pl
tests CI.md FILEFORMAT.md HTTP.md TEST-SUITE.md
.gitignore ALTSVC.md BINDINGS.md BUG-BOUNTY.md BUGS.md CIPHERS-TLS12.md CIPHERS.md CMakeLists.txt CODE_OF_CONDUCT.md CODE_REVIEW.md CONTRIBUTE.md CURL-DISABLE.md CURLDOWN.md DEPRECATE.md DISTROS.md EARLY-RELEASE.md ECH.md EXPERIMENTAL.md FAQ.md FEATURES.md GOVERNANCE.md HELP-US.md HISTORY.md HSTS.md HTTP-COOKIES.md HTTP3.md HTTPSRR.md INFRASTRUCTURE.md INSTALL-CMAKE.md INSTALL.md INTERNALS.md IPFS.md KNOWN_BUGS.md KNOWN_RISKS.md MAIL-ETIQUETTE.md MANUAL.md Makefile.am README.md RELEASE-PROCEDURE.md ROADMAP.md RUSTLS.md SECURITY-ADVISORY.md SPONSORS.md SSL-PROBLEMS.md SSLCERTS.md THANKS THANKS-filter TODO.md TheArtOfHttpScripting.md URL-SYNTAX.md VERIFY.md VERSIONS.md VULN-DISCLOSURE-POLICY.md curl-config.md mk-ca-bundle.md options-in-versions runtests.md testcurl.md wcurl.md
include
curl Makefile.am curl.h curlver.h easy.h header.h mprintf.h multi.h options.h stdcheaders.h system.h typecheck-gcc.h urlapi.h websockets.h
Makefile.am README.md
lib
curlx base64.c base64.h basename.c basename.h dynbuf.c dynbuf.h fopen.c fopen.h inet_ntop.c inet_ntop.h inet_pton.c inet_pton.h multibyte.c multibyte.h nonblock.c nonblock.h snprintf.c snprintf.h strcopy.c strcopy.h strdup.c strdup.h strerr.c strerr.h strparse.c strparse.h timediff.c timediff.h timeval.c timeval.h version_win32.c version_win32.h wait.c wait.h warnless.c warnless.h winapi.c winapi.h
vauth cleartext.c cram.c digest.c digest.h digest_sspi.c gsasl.c krb5_gssapi.c krb5_sspi.c ntlm.c ntlm_sspi.c oauth2.c spnego_gssapi.c spnego_sspi.c vauth.c vauth.h
vquic curl_ngtcp2.c curl_ngtcp2.h curl_quiche.c curl_quiche.h vquic-tls.c vquic-tls.h vquic.c vquic.h vquic_int.h
vssh libssh.c libssh2.c ssh.h vssh.c vssh.h
vtls apple.c apple.h cipher_suite.c cipher_suite.h gtls.c gtls.h hostcheck.c hostcheck.h keylog.c keylog.h mbedtls.c mbedtls.h openssl.c openssl.h rustls.c rustls.h schannel.c schannel.h schannel_int.h schannel_verify.c vtls.c vtls.h vtls_int.h vtls_scache.c vtls_scache.h vtls_spack.c vtls_spack.h wolfssl.c wolfssl.h x509asn1.c x509asn1.h
.gitignore CMakeLists.txt Makefile.am Makefile.inc Makefile.soname altsvc.c altsvc.h amigaos.c amigaos.h arpa_telnet.h asyn-ares.c asyn-base.c asyn-thrdd.c asyn.h bufq.c bufq.h bufref.c bufref.h cf-dns.c cf-dns.h cf-h1-proxy.c cf-h1-proxy.h cf-h2-proxy.c cf-h2-proxy.h cf-haproxy.c cf-haproxy.h cf-https-connect.c cf-https-connect.h cf-ip-happy.c cf-ip-happy.h cf-socket.c cf-socket.h cfilters.c cfilters.h config-mac.h config-os400.h config-riscos.h config-win32.h conncache.c conncache.h connect.c connect.h content_encoding.c content_encoding.h cookie.c cookie.h creds.c creds.h cshutdn.c cshutdn.h curl_addrinfo.c curl_addrinfo.h curl_config-cmake.h.in curl_ctype.h curl_endian.c curl_endian.h curl_fnmatch.c curl_fnmatch.h curl_fopen.c curl_fopen.h curl_get_line.c curl_get_line.h curl_gethostname.c curl_gethostname.h curl_gssapi.c curl_gssapi.h curl_hmac.h curl_ldap.h curl_md4.h curl_md5.h curl_memrchr.c curl_memrchr.h curl_ntlm_core.c curl_ntlm_core.h curl_printf.h curl_range.c curl_range.h curl_sasl.c curl_sasl.h curl_setup.h curl_sha256.h curl_sha512_256.c curl_sha512_256.h curl_share.c curl_share.h curl_sspi.c curl_sspi.h curl_threads.c curl_threads.h curl_trc.c curl_trc.h cw-out.c cw-out.h cw-pause.c cw-pause.h dict.c dict.h dllmain.c dnscache.c dnscache.h doh.c doh.h dynhds.c dynhds.h easy.c easy_lock.h easygetopt.c easyif.h easyoptions.c easyoptions.h escape.c escape.h fake_addrinfo.c fake_addrinfo.h file.c file.h fileinfo.c fileinfo.h formdata.c formdata.h ftp-int.h ftp.c ftp.h ftplistparser.c ftplistparser.h functypes.h getenv.c getinfo.c getinfo.h gopher.c gopher.h hash.c hash.h headers.c headers.h hmac.c hostip.c hostip.h hostip4.c hostip6.c hsts.c hsts.h http.c http.h http1.c http1.h http2.c http2.h http_aws_sigv4.c http_aws_sigv4.h http_chunks.c http_chunks.h http_digest.c http_digest.h http_negotiate.c http_negotiate.h http_ntlm.c http_ntlm.h http_proxy.c http_proxy.h httpsrr.c httpsrr.h idn.c idn.h if2ip.c if2ip.h imap.c imap.h ldap.c libcurl.def libcurl.rc libcurl.vers.in llist.c llist.h macos.c macos.h md4.c md5.c memdebug.c mime.c mime.h mprintf.c mqtt.c mqtt.h multi.c multi_ev.c multi_ev.h multi_ntfy.c multi_ntfy.h multihandle.h multiif.h netrc.c netrc.h noproxy.c noproxy.h openldap.c optiontable.pl parsedate.c parsedate.h peer.c peer.h pingpong.c pingpong.h pop3.c pop3.h progress.c progress.h protocol.c protocol.h psl.c psl.h rand.c rand.h ratelimit.c ratelimit.h request.c request.h rtsp.c rtsp.h select.c select.h sendf.c sendf.h setopt.c setopt.h setup-os400.h setup-vms.h setup-win32.h sha256.c sigpipe.h slist.c slist.h smb.c smb.h smtp.c smtp.h sockaddr.h socketpair.c socketpair.h socks.c socks.h socks_gssapi.c socks_sspi.c splay.c splay.h strcase.c strcase.h strequal.c strerror.c strerror.h system_win32.c system_win32.h telnet.c telnet.h tftp.c tftp.h thrdpool.c thrdpool.h thrdqueue.c thrdqueue.h transfer.c transfer.h uint-bset.c uint-bset.h uint-hash.c uint-hash.h uint-spbset.c uint-spbset.h uint-table.c uint-table.h url.c url.h urlapi-int.h urlapi.c urldata.h version.c ws.c ws.h
m4 .gitignore curl-amissl.m4 curl-apple-sectrust.m4 curl-compilers.m4 curl-confopts.m4 curl-functions.m4 curl-gnutls.m4 curl-mbedtls.m4 curl-openssl.m4 curl-override.m4 curl-reentrant.m4 curl-rustls.m4 curl-schannel.m4 curl-sysconfig.m4 curl-wolfssl.m4 xc-am-iface.m4 xc-cc-check.m4 xc-lt-iface.m4 xc-val-flgs.m4 zz40-xc-ovr.m4 zz50-xc-ovr.m4
projects
OS400
rpg-examples HEADERAPI HTTPPOST INMEMORY SIMPLE1 SIMPLE2 SMTPSRCMBR
.checksrc README.OS400 ccsidcurl.c ccsidcurl.h config400.default curl.cmd curl.inc.in curlcl.c curlmain.c initscript.sh make-docs.sh make-include.sh make-lib.sh make-src.sh make-tests.sh makefile.sh os400sys.c os400sys.h
Windows
tmpl .gitattributes README.txt curl-all.sln curl.sln curl.vcxproj curl.vcxproj.filters libcurl.sln libcurl.vcxproj libcurl.vcxproj.filters
.gitignore README.md generate.bat
vms Makefile.am backup_gnv_curl_src.com build_curl-config_script.com build_gnv_curl.com build_gnv_curl_pcsi_desc.com build_gnv_curl_pcsi_text.com build_gnv_curl_release_notes.com build_libcurl_pc.com build_vms.com clean_gnv_curl.com compare_curl_source.com config_h.com curl_crtl_init.c curl_gnv_build_steps.txt curl_release_note_start.txt curl_startup.com curlmsg.h curlmsg.msg curlmsg.sdl curlmsg_vms.h generate_config_vms_h_curl.com generate_vax_transfer.com gnv_conftest.c_first gnv_curl_configure.sh gnv_libcurl_symbols.opt gnv_link_curl.com macro32_exactcase.patch make_gnv_curl_install.sh make_pcsi_curl_kit_name.com pcsi_gnv_curl_file_list.txt pcsi_product_gnv_curl.com readme report_openssl_version.c setup_gnv_curl_build.com stage_curl_install.com vms_eco_level.h
Makefile.am README.md
scripts .checksrc CMakeLists.txt Makefile.am badwords badwords-all badwords.txt cd2cd cd2nroff cdall checksrc-all.pl checksrc.pl cmakelint.sh completion.pl contributors.sh contrithanks.sh coverage.sh delta dmaketgz extract-unit-protos firefox-db2pem.sh installcheck.sh maketgz managen mdlinkcheck mk-ca-bundle.pl mk-unity.pl nroff2cd perlcheck.sh pythonlint.sh randdisable release-notes.pl release-tools.sh schemetable.c singleuse.pl spacecheck.pl top-complexity top-length verify-release wcurl
src
toolx tool_time.c tool_time.h
.checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc config2setopts.c config2setopts.h curl.rc curlinfo.c mk-file-embed.pl mkhelp.pl slist_wc.c slist_wc.h terminal.c terminal.h tool_cb_dbg.c tool_cb_dbg.h tool_cb_hdr.c tool_cb_hdr.h tool_cb_prg.c tool_cb_prg.h tool_cb_rea.c tool_cb_rea.h tool_cb_see.c tool_cb_see.h tool_cb_soc.c tool_cb_soc.h tool_cb_wrt.c tool_cb_wrt.h tool_cfgable.c tool_cfgable.h tool_dirhie.c tool_dirhie.h tool_doswin.c tool_doswin.h tool_easysrc.c tool_easysrc.h tool_filetime.c tool_filetime.h tool_findfile.c tool_findfile.h tool_formparse.c tool_formparse.h tool_getparam.c tool_getparam.h tool_getpass.c tool_getpass.h tool_help.c tool_help.h tool_helpers.c tool_helpers.h tool_hugehelp.h tool_ipfs.c tool_ipfs.h tool_libinfo.c tool_libinfo.h tool_listhelp.c tool_main.c tool_main.h tool_msgs.c tool_msgs.h tool_operate.c tool_operate.h tool_operhlp.c tool_operhlp.h tool_paramhlp.c tool_paramhlp.h tool_parsecfg.c tool_parsecfg.h tool_progress.c tool_progress.h tool_sdecls.h tool_setopt.c tool_setopt.h tool_setup.h tool_ssls.c tool_ssls.h tool_stderr.c tool_stderr.h tool_urlglob.c tool_urlglob.h tool_util.c tool_util.h tool_version.h tool_vms.c tool_vms.h tool_writeout.c tool_writeout.h tool_writeout_json.c tool_writeout_json.h tool_xattr.c tool_xattr.h var.c var.h
tests
certs .gitignore CMakeLists.txt Makefile.am Makefile.inc genserv.pl srp-verifier-conf srp-verifier-db test-ca.cnf test-ca.prm test-client-cert.prm test-client-eku-only.prm test-localhost-san-first.prm test-localhost-san-last.prm test-localhost.nn.prm test-localhost.prm test-localhost0h.prm
cmake CMakeLists.txt test.c test.cpp test.sh
data .gitignore DISABLED Makefile.am data-xml1 data1400.c data1401.c data1402.c data1403.c data1404.c data1405.c data1406.c data1407.c data1420.c data1461.txt data1463.txt data1465.c data1481.c data1705-1.md data1705-2.md data1705-3.md data1705-4.md data1705-stdout.1 data1706-1.md data1706-2.md data1706-3.md data1706-4.md data1706-stdout.txt data320.html test1 test10 test100 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 test1008 test1009 test101 test1010 test1011 test1012 test1013 test1014 test1015 test1016 test1017 test1018 test1019 test102 test1020 test1021 test1022 test1023 test1024 test1025 test1026 test1027 test1028 test1029 test103 test1030 test1031 test1032 test1033 test1034 test1035 test1036 test1037 test1038 test1039 test104 test1040 test1041 test1042 test1043 test1044 test1045 test1046 test1047 test1048 test1049 test105 test1050 test1051 test1052 test1053 test1054 test1055 test1056 test1057 test1058 test1059 test106 test1060 test1061 test1062 test1063 test1064 test1065 test1066 test1067 test1068 test1069 test107 test1070 test1071 test1072 test1073 test1074 test1075 test1076 test1077 test1078 test1079 test108 test1080 test1081 test1082 test1083 test1084 test1085 test1086 test1087 test1088 test1089 test109 test1090 test1091 test1092 test1093 test1094 test1095 test1096 test1097 test1098 test1099 test11 test110 test1100 test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 test1109 test111 test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117 test1118 test1119 test112 test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 test1128 test1129 test113 test1130 test1131 test1132 test1133 test1134 test1135 test1136 test1137 test1138 test1139 test114 test1140 test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 test1149 test115 test1150 test1151 test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 test116 test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1167 test1168 test1169 test117 test1170 test1171 test1172 test1173 test1174 test1175 test1176 test1177 test1178 test1179 test118 test1180 test1181 test1182 test1183 test1184 test1185 test1186 test1187 test1188 test1189 test119 test1190 test1191 test1192 test1193 test1194 test1195 test1196 test1197 test1198 test1199 test12 test120 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 test1208 test1209 test121 test1210 test1211 test1212 test1213 test1214 test1215 test1216 test1217 test1218 test1219 test122 test1220 test1221 test1222 test1223 test1224 test1225 test1226 test1227 test1228 test1229 test123 test1230 test1231 test1232 test1233 test1234 test1235 test1236 test1237 test1238 test1239 test124 test1240 test1241 test1242 test1243 test1244 test1245 test1246 test1247 test1248 test1249 test125 test1250 test1251 test1252 test1253 test1254 test1255 test1256 test1257 test1258 test1259 test126 test1260 test1261 test1262 test1263 test1264 test1265 test1266 test1267 test1268 test1269 test127 test1270 test1271 test1272 test1273 test1274 test1275 test1276 test1277 test1278 test1279 test128 test1280 test1281 test1282 test1283 test1284 test1285 test1286 test1287 test1288 test1289 test129 test1290 test1291 test1292 test1293 test1294 test1295 test1296 test1297 test1298 test1299 test13 test130 test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 test1308 test1309 test131 test1310 test1311 test1312 test1313 test1314 test1315 test1316 test1317 test1318 test1319 test132 test1320 test1321 test1322 test1323 test1324 test1325 test1326 test1327 test1328 test1329 test133 test1330 test1331 test1332 test1333 test1334 test1335 test1336 test1337 test1338 test1339 test134 test1340 test1341 test1342 test1343 test1344 test1345 test1346 test1347 test1348 test1349 test135 test1350 test1351 test1352 test1353 test1354 test1355 test1356 test1357 test1358 test1359 test136 test1360 test1361 test1362 test1363 test1364 test1365 test1366 test1367 test1368 test1369 test137 test1370 test1371 test1372 test1373 test1374 test1375 test1376 test1377 test1378 test1379 test138 test1380 test1381 test1382 test1383 test1384 test1385 test1386 test1387 test1388 test1389 test139 test1390 test1391 test1392 test1393 test1394 test1395 test1396 test1397 test1398 test1399 test14 test140 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 test1408 test1409 test141 test1410 test1411 test1412 test1413 test1414 test1415 test1416 test1417 test1418 test1419 test142 test1420 test1421 test1422 test1423 test1424 test1425 test1426 test1427 test1428 test1429 test143 test1430 test1431 test1432 test1433 test1434 test1435 test1436 test1437 test1438 test1439 test144 test1440 test1441 test1442 test1443 test1444 test1445 test1446 test1447 test1448 test1449 test145 test1450 test1451 test1452 test1453 test1454 test1455 test1456 test1457 test1458 test1459 test146 test1460 test1461 test1462 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test147 test1470 test1471 test1472 test1473 test1474 test1475 test1476 test1477 test1478 test1479 test148 test1480 test1481 test1482 test1483 test1484 test1485 test1486 test1487 test1488 test1489 test149 test1490 test1491 test1492 test1493 test1494 test1495 test1496 test1497 test1498 test1499 test15 test150 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 test1508 test1509 test151 test1510 test1511 test1512 test1513 test1514 test1515 test1516 test1517 test1518 test1519 test152 test1520 test1521 test1522 test1523 test1524 test1525 test1526 test1527 test1528 test1529 test153 test1530 test1531 test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 test154 test1540 test1541 test1542 test1543 test1544 test1545 test1546 test1547 test1548 test1549 test155 test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 test1558 test1559 test156 test1560 test1561 test1562 test1563 test1564 test1565 test1566 test1567 test1568 test1569 test157 test1570 test1571 test1572 test1573 test1574 test1575 test1576 test1577 test1578 test1579 test158 test1580 test1581 test1582 test1583 test1584 test1585 test1586 test1587 test1588 test1589 test159 test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 test1598 test1599 test16 test160 test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 test1608 test1609 test161 test1610 test1611 test1612 test1613 test1614 test1615 test1616 test1617 test1618 test1619 test162 test1620 test1621 test1622 test1623 test1624 test1625 test1626 test1627 test1628 test1629 test163 test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 test1638 test1639 test164 test1640 test1641 test1642 test1643 test1644 test1645 test165 test1650 test1651 test1652 test1653 test1654 test1655 test1656 test1657 test1658 test1659 test166 test1660 test1661 test1662 test1663 test1664 test1665 test1666 test1667 test1668 test1669 test167 test1670 test1671 test1672 test1673 test1674 test1675 test1676 test168 test1680 test1681 test1682 test1683 test1684 test1685 test169 test17 test170 test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 test1708 test1709 test171 test1710 test1711 test1712 test1713 test1714 test1715 test172 test1720 test1721 test173 test174 test175 test176 test177 test178 test179 test18 test180 test1800 test1801 test1802 test181 test182 test183 test184 test1847 test1848 test1849 test185 test1850 test1851 test186 test187 test188 test189 test19 test190 test1900 test1901 test1902 test1903 test1904 test1905 test1906 test1907 test1908 test1909 test191 test1910 test1911 test1912 test1913 test1914 test1915 test1916 test1917 test1918 test1919 test192 test1920 test1921 test193 test1933 test1934 test1935 test1936 test1937 test1938 test1939 test194 test1940 test1941 test1942 test1943 test1944 test1945 test1946 test1947 test1948 test195 test1955 test1956 test1957 test1958 test1959 test196 test1960 test1964 test1965 test1966 test197 test1970 test1971 test1972 test1973 test1974 test1975 test1976 test1977 test1978 test1979 test198 test1980 test1981 test1982 test1983 test1984 test199 test2 test20 test200 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 test2008 test2009 test201 test2010 test2011 test2012 test2013 test2014 test202 test2023 test2024 test2025 test2026 test2027 test2028 test2029 test203 test2030 test2031 test2032 test2033 test2034 test2035 test2037 test2038 test2039 test204 test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 test2048 test2049 test205 test2050 test2051 test2052 test2053 test2054 test2055 test2056 test2057 test2058 test2059 test206 test2060 test2061 test2062 test2063 test2064 test2065 test2066 test2067 test2068 test2069 test207 test2070 test2071 test2072 test2073 test2074 test2075 test2076 test2077 test2078 test2079 test208 test2080 test2081 test2082 test2083 test2084 test2085 test2086 test2087 test2088 test2089 test209 test2090 test2091 test2092 test21 test210 test2100 test2101 test2102 test2103 test2104 test211 test212 test213 test214 test215 test216 test217 test218 test219 test22 test220 test2200 test2201 test2202 test2203 test2204 test2205 test2206 test2207 test221 test222 test223 test224 test225 test226 test227 test228 test229 test23 test230 test2300 test2301 test2302 test2303 test2304 test2306 test2307 test2308 test2309 test231 test232 test233 test234 test235 test236 test237 test238 test239 test24 test240 test2400 test2401 test2402 test2403 test2404 test2405 test2406 test2407 test2408 test2409 test241 test2410 test2411 test242 test243 test244 test245 test246 test247 test248 test249 test25 test250 test2500 test2501 test2502 test2503 test2504 test2505 test2506 test251 test252 test253 test254 test255 test256 test257 test258 test259 test26 test260 test2600 test2601 test2602 test2603 test2604 test2605 test261 test262 test263 test264 test265 test266 test267 test268 test269 test27 test270 test2700 test2701 test2702 test2703 test2704 test2705 test2706 test2707 test2708 test2709 test271 test2710 test2711 test2712 test2713 test2714 test2715 test2716 test2717 test2718 test2719 test272 test2720 test2721 test2722 test2723 test273 test274 test275 test276 test277 test278 test279 test28 test280 test281 test282 test283 test284 test285 test286 test287 test288 test289 test29 test290 test291 test292 test293 test294 test295 test296 test297 test298 test299 test3 test30 test300 test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 test3008 test3009 test301 test3010 test3011 test3012 test3013 test3014 test3015 test3016 test3017 test3018 test3019 test302 test3020 test3021 test3022 test3023 test3024 test3025 test3026 test3027 test3028 test3029 test303 test3030 test3031 test3032 test3033 test3034 test3035 test3036 test304 test305 test306 test307 test308 test309 test31 test310 test3100 test3101 test3102 test3103 test3104 test3105 test3106 test311 test312 test313 test314 test315 test316 test317 test318 test319 test32 test320 test3200 test3201 test3202 test3203 test3204 test3205 test3206 test3207 test3208 test3209 test321 test3210 test3211 test3212 test3213 test3214 test3215 test3216 test3217 test3218 test3219 test322 test3220 test323 test324 test325 test326 test327 test328 test329 test33 test330 test3300 test3301 test3302 test331 test332 test333 test334 test335 test336 test337 test338 test339 test34 test340 test341 test342 test343 test344 test345 test346 test347 test348 test349 test35 test350 test351 test352 test353 test354 test355 test356 test357 test358 test359 test36 test360 test361 test362 test363 test364 test365 test366 test367 test368 test369 test37 test370 test371 test372 test373 test374 test375 test376 test378 test379 test38 test380 test381 test383 test384 test385 test386 test387 test388 test389 test39 test390 test391 test392 test393 test394 test395 test396 test397 test398 test399 test4 test40 test400 test4000 test4001 test401 test402 test403 test404 test405 test406 test407 test408 test409 test41 test410 test411 test412 test413 test414 test415 test416 test417 test418 test419 test42 test420 test421 test422 test423 test424 test425 test426 test427 test428 test429 test43 test430 test431 test432 test433 test434 test435 test436 test437 test438 test439 test44 test440 test441 test442 test443 test444 test445 test446 test447 test448 test449 test45 test450 test451 test452 test453 test454 test455 test456 test457 test458 test459 test46 test460 test461 test462 test463 test467 test468 test469 test47 test470 test471 test472 test473 test474 test475 test476 test477 test478 test479 test48 test480 test481 test482 test483 test484 test485 test486 test487 test488 test489 test49 test490 test491 test492 test493 test494 test495 test496 test497 test498 test499 test5 test50 test500 test501 test502 test503 test504 test505 test506 test507 test508 test509 test51 test510 test511 test512 test513 test514 test515 test516 test517 test518 test519 test52 test520 test521 test522 test523 test524 test525 test526 test527 test528 test529 test53 test530 test531 test532 test533 test534 test535 test536 test537 test538 test539 test54 test540 test541 test542 test543 test544 test545 test546 test547 test548 test549 test55 test550 test551 test552 test553 test554 test555 test556 test557 test558 test559 test56 test560 test561 test562 test563 test564 test565 test566 test567 test568 test569 test57 test570 test571 test572 test573 test574 test575 test576 test577 test578 test579 test58 test580 test581 test582 test583 test584 test585 test586 test587 test588 test589 test59 test590 test591 test592 test593 test594 test595 test596 test597 test598 test599 test6 test60 test600 test601 test602 test603 test604 test605 test606 test607 test608 test609 test61 test610 test611 test612 test613 test614 test615 test616 test617 test618 test619 test62 test620 test621 test622 test623 test624 test625 test626 test627 test628 test629 test63 test630 test631 test632 test633 test634 test635 test636 test637 test638 test639 test64 test640 test641 test642 test643 test644 test645 test646 test647 test648 test649 test65 test650 test651 test652 test653 test654 test655 test656 test658 test659 test66 test660 test661 test662 test663 test664 test665 test666 test667 test668 test669 test67 test670 test671 test672 test673 test674 test675 test676 test677 test678 test679 test68 test680 test681 test682 test683 test684 test685 test686 test687 test688 test689 test69 test690 test691 test692 test693 test694 test695 test696 test697 test698 test699 test7 test70 test700 test701 test702 test703 test704 test705 test706 test707 test708 test709 test71 test710 test711 test712 test713 test714 test715 test716 test717 test718 test719 test72 test720 test721 test722 test723 test724 test725 test726 test727 test728 test729 test73 test730 test731 test732 test733 test734 test735 test736 test737 test738 test739 test74 test740 test741 test742 test743 test744 test745 test746 test747 test748 test749 test75 test750 test751 test752 test753 test754 test755 test756 test757 test758 test759 test76 test760 test761 test762 test763 test764 test765 test766 test767 test768 test769 test77 test770 test771 test772 test773 test774 test775 test776 test777 test778 test779 test78 test780 test781 test782 test783 test784 test785 test786 test787 test788 test789 test79 test790 test791 test792 test793 test794 test795 test796 test797 test798 test799 test8 test80 test800 test801 test802 test803 test804 test805 test806 test807 test808 test809 test81 test810 test811 test812 test813 test814 test815 test816 test817 test818 test819 test82 test820 test821 test822 test823 test824 test825 test826 test827 test828 test829 test83 test830 test831 test832 test833 test834 test835 test836 test837 test838 test839 test84 test840 test841 test842 test843 test844 test845 test846 test847 test848 test849 test85 test850 test851 test852 test853 test854 test855 test856 test857 test858 test859 test86 test860 test861 test862 test863 test864 test865 test866 test867 test868 test869 test87 test870 test871 test872 test873 test874 test875 test876 test877 test878 test879 test88 test880 test881 test882 test883 test884 test885 test886 test887 test888 test889 test89 test890 test891 test892 test893 test894 test895 test896 test897 test898 test899 test9 test90 test900 test901 test902 test903 test904 test905 test906 test907 test908 test909 test91 test910 test911 test912 test913 test914 test915 test916 test917 test918 test919 test92 test920 test921 test922 test923 test924 test925 test926 test927 test928 test929 test93 test930 test931 test932 test933 test934 test935 test936 test937 test938 test939 test94 test940 test941 test942 test943 test944 test945 test946 test947 test948 test949 test95 test950 test951 test952 test953 test954 test955 test956 test957 test958 test959 test96 test960 test961 test962 test963 test964 test965 test966 test967 test968 test969 test97 test970 test971 test972 test973 test974 test975 test976 test977 test978 test979 test98 test980 test981 test982 test983 test984 test985 test986 test987 test988 test989 test99 test990 test991 test992 test993 test994 test995 test996 test997 test998 test999
http
testenv
mod_curltest .gitignore mod_curltest.c
__init__.py caddy.py certs.py client.py curl.py dante.py dnsd.py env.py httpd.py nghttpx.py ports.py sshd.py vsftpd.py ws_echo_server.py
.gitignore CMakeLists.txt Makefile.am config.ini.in conftest.py requirements.txt scorecard.py test_01_basic.py test_02_download.py test_03_goaway.py test_04_stuttered.py test_05_errors.py test_06_eyeballs.py test_07_upload.py test_08_caddy.py test_09_push.py test_10_proxy.py test_11_unix.py test_12_reuse.py test_13_proxy_auth.py test_14_auth.py test_15_tracing.py test_16_info.py test_17_ssl_use.py test_18_methods.py test_19_shutdown.py test_20_websockets.py test_21_resolve.py test_22_httpsrr.py test_30_vsftpd.py test_31_vsftpds.py test_32_ftps_vsftpd.py test_40_socks.py test_50_scp.py test_51_sftp.py
libtest .gitignore CMakeLists.txt Makefile.am Makefile.inc cli_ftp_upload.c cli_h2_pausing.c cli_h2_serverpush.c cli_h2_upgrade_extreme.c cli_hx_download.c cli_hx_upload.c cli_tls_session_reuse.c cli_upload_pausing.c cli_ws_data.c cli_ws_pingpong.c first.c first.h lib1156.c lib1301.c lib1308.c lib1485.c lib1500.c lib1501.c lib1502.c lib1506.c lib1507.c lib1508.c lib1509.c lib1510.c lib1511.c lib1512.c lib1513.c lib1514.c lib1515.c lib1517.c lib1518.c lib1520.c lib1522.c lib1523.c lib1525.c lib1526.c lib1527.c lib1528.c lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c lib1536.c lib1537.c lib1538.c lib1540.c lib1541.c lib1542.c lib1545.c lib1549.c lib1550.c lib1551.c lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c lib1559.c lib1560.c lib1564.c lib1565.c lib1567.c lib1568.c lib1569.c lib1571.c lib1576.c lib1582.c lib1587.c lib1588.c lib1589.c lib1591.c lib1592.c lib1593.c lib1594.c lib1597.c lib1598.c lib1599.c lib1662.c lib1900.c lib1901.c lib1902.c lib1903.c lib1905.c lib1906.c lib1907.c lib1908.c lib1910.c lib1911.c lib1912.c lib1913.c lib1915.c lib1916.c lib1918.c lib1919.c lib1920.c lib1921.c lib1933.c lib1934.c lib1935.c lib1936.c lib1937.c lib1938.c lib1939.c lib1940.c lib1945.c lib1947.c lib1948.c lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c lib1964.c lib1965.c lib1970.c lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c lib2023.c lib2032.c lib2082.c lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c lib2402.c lib2404.c lib2405.c lib2502.c lib2504.c lib2505.c lib2506.c lib2700.c lib3010.c lib3025.c lib3026.c lib3027.c lib3033.c lib3034.c lib3100.c lib3101.c lib3102.c lib3103.c lib3104.c lib3105.c lib3207.c lib3208.c lib500.c lib501.c lib502.c lib503.c lib504.c lib505.c lib506.c lib507.c lib508.c lib509.c lib510.c lib511.c lib512.c lib513.c lib514.c lib515.c lib516.c lib517.c lib518.c lib519.c lib520.c lib521.c lib523.c lib524.c lib525.c lib526.c lib530.c lib533.c lib536.c lib537.c lib539.c lib540.c lib541.c lib542.c lib543.c lib544.c lib547.c lib549.c lib552.c lib553.c lib554.c lib555.c lib556.c lib557.c lib558.c lib559.c lib560.c lib562.c lib564.c lib566.c lib567.c lib568.c lib569.c lib570.c lib571.c lib572.c lib573.c lib574.c lib575.c lib576.c lib578.c lib579.c lib582.c lib583.c lib586.c lib589.c lib590.c lib591.c lib597.c lib598.c lib599.c lib643.c lib650.c lib651.c lib652.c lib653.c lib654.c lib655.c lib658.c lib659.c lib661.c lib666.c lib667.c lib668.c lib670.c lib674.c lib676.c lib677.c lib678.c lib694.c lib695.c lib751.c lib753.c lib757.c lib758.c lib766.c memptr.c mk-lib1521.pl test1013.pl test1022.pl test307.pl test610.pl test613.pl testtrace.c testtrace.h testutil.c testutil.h unitcheck.h
server .checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc dnsd.c first.c first.h getpart.c mqttd.c resolve.c rtspd.c sockfilt.c socksd.c sws.c tftpd.c util.c
tunit .gitignore CMakeLists.txt Makefile.am Makefile.inc README.md tool1394.c tool1604.c tool1621.c tool1622.c tool1623.c tool1720.c
unit .gitignore CMakeLists.txt Makefile.am Makefile.inc README.md unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c unit1307.c unit1309.c unit1323.c unit1330.c unit1395.c unit1396.c unit1397.c unit1398.c unit1399.c unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c unit1615.c unit1616.c unit1620.c unit1625.c unit1626.c unit1627.c unit1636.c unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c unit1666.c unit1667.c unit1668.c unit1669.c unit1674.c unit1675.c unit1676.c unit1979.c unit1980.c unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c unit2605.c unit3200.c unit3205.c unit3211.c unit3212.c unit3213.c unit3214.c unit3216.c unit3219.c unit3300.c unit3301.c unit3302.c
.gitignore CMakeLists.txt Makefile.am allversions.pm appveyor.pm azure.pm config.in configurehelp.pm.in devtest.pl dictserver.py directories.pm ech_combos.py ech_tests.sh ftpserver.pl getpart.pm globalconfig.pm http-server.pl http2-server.pl http3-server.pl memanalyze.pl memanalyzer.pm negtelnetserver.py nghttpx.conf pathhelp.pm processhelp.pm requirements.txt rtspserver.pl runner.pm runtests.pl secureserver.pl serverhelp.pm servers.pm smbserver.py sshhelp.pm sshserver.pl test1119.pl test1135.pl test1139.pl test1140.pl test1165.pl test1167.pl test1173.pl test1175.pl test1177.pl test1222.pl test1275.pl test1276.pl test1477.pl test1486.pl test1488.pl test1544.pl test1707.pl test745.pl test971.pl testcurl.pl testutil.pm tftpserver.pl util.py valgrind.pm valgrind.supp
.clang-tidy.yml .dir-locals.el .editorconfig .git-blame-ignore-revs .gitattributes .gitignore .mailmap CHANGES.md CMakeLists.txt COPYING Dockerfile GIT-INFO.md Makefile.am README README.md RELEASE-NOTES REUSE.toml SECURITY.md acinclude.m4 appveyor.sh appveyor.yml configure.ac curl-config.in libcurl.pc.in renovate.json
examples .env config.ini crypto_test.lua env_test.lua fs_example.lua http_server.lua https_test.lua ini_example.lua json.lua log.lua path_fs_example.lua process_example.lua request_download.lua request_test.lua run_all.lua sqlite_example.lua sqlite_http_template.lua stash_test.lua template_test.lua timer.lua websocket.lua
iniparser
.github
ISSUE_TEMPLATE config.yml
workflows disable-pull-requests.yml trigger-gitlab-ci.yml
cmake JoinPaths.cmake config.cmake.in pc.in
example iniexample.c iniwrite.c parse.c twisted-errors.ini twisted-genhuge.py twisted-ofkey.ini twisted-ofval.ini twisted.ini
src dictionary.c dictionary.h iniparser.c iniparser.h
test
ressources
bad_ini ends_well.ini twisted-errors.ini twisted-ofkey.ini twisted-ofval.ini
good_ini empty.ini spaced.ini spaced2.ini twisted.ini
gruezi.ini old.ini quotes.ini utf8.ini
CMakeLists.txt test_dictionary.c test_iniparser.c unity-config.yml unity_config.h
.cmake-format.py .gitignore .gitlab-ci.yml .gitmessage .travis.yml AUTHORS CMakeLists.txt FAQ-en.md FAQ-zhcn.md INSTALL LICENSE README.md compile_commands.json
jinjac
example CMakeLists.txt example.c
jinjac_test_app CMakeLists.txt jinjac_test_app.c
libjinjac
include jinjac.h
src CMakeLists.txt ast.c ast.h block_statement.c block_statement.h buffer.c buffer.h buildin.c buildin.h common.h convert.c convert.h flex_decl.h jfunction.c jfunction.h jinja_expression.l jinja_expression.y jinjac_parse.c jinjac_parse.h jinjac_stream.c jinjac_stream.h jlist.c jlist.h jobject.c jobject.h parameter.c parameter.h str_obj.c str_obj.h trace.c trace.h
CMakeLists.txt
test .gitignore CMakeLists.txt autotest.rb test_01.expected test_01.jinja test_01b.expected test_01b.jinja test_01c.expected test_01c.jinja test_01d.expected test_01d.jinja test_02.expected test_02.jinja test_03.expected test_03.jinja test_04.expected test_04.jinja test_05.expected test_05.jinja test_06.expected test_06.jinja test_07.expected test_07.jinja test_08.expected test_08.jinja test_08b.expected test_08b.jinja test_09.expected test_09.jinja test_10.expected test_10.jinja test_11.expected test_11.jinja test_12.expected test_12.jinja test_13.expected test_13.jinja test_14.expected test_14.jinja test_15.expected test_15.jinja test_16.expected test_16.jinja test_17.expected test_17.jinja test_18.expected test_18.jinja test_18b.expected test_18b.jinja test_18c.expected test_18c.jinja test_19.expected test_19.jinja test_19b.expected test_19b.jinja test_19c.expected test_19c.jinja test_19d.expected test_19d.jinja test_19e.expected test_19e.jinja test_19f.expected test_19f.jinja test_20.expected test_20.jinja test_21.expected test_21.jinja test_22.expected test_22.jinja test_22a.expected test_22a.jinja test_22b.expected test_22b.jinja test_23.expected test_23.jinja test_24.expected test_24.jinja
.gitignore CMakeLists.txt LICENSE.txt README.md build_coverage.sh build_debug.sh build_release.sh cppcheck_analysis.sh
libev Changes LICENSE Makefile Makefile.am Makefile.in README Symbols.ev Symbols.event aclocal.m4 autogen.sh compile config.guess config.h config.h.in config.status config.sub configure configure.ac depcomp ev++.h ev.3 ev.c ev.h ev.pod ev_epoll.c ev_kqueue.c ev_poll.c ev_port.c ev_select.c ev_vars.h ev_win32.c ev_wrap.h event.c event.h install-sh libev.m4 libtool ltmain.sh missing mkinstalldirs stamp-h1
luajit
doc
img contact.png
bluequad-print.css bluequad.css contact.html ext_buffer.html ext_c_api.html ext_ffi.html ext_ffi_api.html ext_ffi_semantics.html ext_ffi_tutorial.html ext_jit.html ext_profiler.html extensions.html install.html luajit.html running.html
dynasm dasm_arm.h dasm_arm.lua dasm_arm64.h dasm_arm64.lua dasm_mips.h dasm_mips.lua dasm_mips64.lua dasm_ppc.h dasm_ppc.lua dasm_proto.h dasm_x64.lua dasm_x86.h dasm_x86.lua dynasm.lua
etc luajit.1 luajit.pc
src
host .gitignore README buildvm.c buildvm.h buildvm_asm.c buildvm_fold.c buildvm_lib.c buildvm_libbc.h buildvm_peobj.c genlibbc.lua genminilua.lua genversion.lua minilua.c
jit .gitignore bc.lua bcsave.lua dis_arm.lua dis_arm64.lua dis_arm64be.lua dis_mips.lua dis_mips64.lua dis_mips64el.lua dis_mips64r6.lua dis_mips64r6el.lua dis_mipsel.lua dis_ppc.lua dis_x64.lua dis_x86.lua dump.lua p.lua v.lua zone.lua
.gitignore Makefile Makefile.dep lauxlib.h lib_aux.c lib_base.c lib_bit.c lib_buffer.c lib_debug.c lib_ffi.c lib_init.c lib_io.c lib_jit.c lib_math.c lib_os.c lib_package.c lib_string.c lib_table.c lj_alloc.c lj_alloc.h lj_api.c lj_arch.h lj_asm.c lj_asm.h lj_asm_arm.h lj_asm_arm64.h lj_asm_mips.h lj_asm_ppc.h lj_asm_x86.h lj_assert.c lj_bc.c lj_bc.h lj_bcdump.h lj_bcread.c lj_bcwrite.c lj_buf.c lj_buf.h lj_carith.c lj_carith.h lj_ccall.c lj_ccall.h lj_ccallback.c lj_ccallback.h lj_cconv.c lj_cconv.h lj_cdata.c lj_cdata.h lj_char.c lj_char.h lj_clib.c lj_clib.h lj_cparse.c lj_cparse.h lj_crecord.c lj_crecord.h lj_ctype.c lj_ctype.h lj_debug.c lj_debug.h lj_def.h lj_dispatch.c lj_dispatch.h lj_emit_arm.h lj_emit_arm64.h lj_emit_mips.h lj_emit_ppc.h lj_emit_x86.h lj_err.c lj_err.h lj_errmsg.h lj_ff.h lj_ffrecord.c lj_ffrecord.h lj_frame.h lj_func.c lj_func.h lj_gc.c lj_gc.h lj_gdbjit.c lj_gdbjit.h lj_ir.c lj_ir.h lj_ircall.h lj_iropt.h lj_jit.h lj_lex.c lj_lex.h lj_lib.c lj_lib.h lj_load.c lj_mcode.c lj_mcode.h lj_meta.c lj_meta.h lj_obj.c lj_obj.h lj_opt_dce.c lj_opt_fold.c lj_opt_loop.c lj_opt_mem.c lj_opt_narrow.c lj_opt_sink.c lj_opt_split.c lj_parse.c lj_parse.h lj_prng.c lj_prng.h lj_profile.c lj_profile.h lj_record.c lj_record.h lj_serialize.c lj_serialize.h lj_snap.c lj_snap.h lj_state.c lj_state.h lj_str.c lj_str.h lj_strfmt.c lj_strfmt.h lj_strfmt_num.c lj_strscan.c lj_strscan.h lj_tab.c lj_tab.h lj_target.h lj_target_arm.h lj_target_arm64.h lj_target_mips.h lj_target_ppc.h lj_target_x86.h lj_trace.c lj_trace.h lj_traceerr.h lj_udata.c lj_udata.h lj_vm.h lj_vmevent.c lj_vmevent.h lj_vmmath.c ljamalg.c lua.h lua.hpp luaconf.h luajit.c luajit_rolling.h lualib.h msvcbuild.bat nxbuild.bat ps4build.bat ps5build.bat psvitabuild.bat vm_arm.dasc vm_arm64.dasc vm_mips.dasc vm_mips64.dasc vm_ppc.dasc vm_x64.dasc vm_x86.dasc xb1build.bat xedkbuild.bat
.gitattributes .gitignore .relver COPYRIGHT Makefile README
sqlite shell.c sqlite3.c sqlite3.h sqlite3ext.h
wolfssl
.github
ISSUE_TEMPLATE bug_report.yaml other.yaml
actions
install-apt-deps action.yml
scripts
zephyr-4.x external_libc.conf zephyr-test.sh
openssl-ech.sh tls-anvil-test.sh
workflows
disabled haproxy.yml hitch.yml hostap.yml
hostap-files
configs
07c9f183ea744ac04585fb6dd10220c75a5e2e74 hostapd.config tests wpa_supplicant.config
b607d2723e927a3446d89aed813f1aa6068186bb hostapd.config tests wpa_supplicant.config
hostap_2_10 extra.patch hostapd.config tests wpa_supplicant.config
Makefile README dbus-wpa_supplicant.conf
ada.yml arduino.yml async-examples.yml async.yml atecc608-sim.yml bind.yml cmake-autoconf.yml cmake.yml codespell.yml coverity-scan-fixes.yml cryptocb-only.yml curl.yml cyrus-sasl.yml disable-pk-algs.yml docker-Espressif.yml docker-OpenWrt.yml emnet-nonblock.yml fil-c.yml freertos-mem-track.yml gencertbuf.yml grpc.yml haproxy.yml hostap-vm.yml intelasm-c-fallback.yml ipmitool.yml jwt-cpp.yml krb5.yml libspdm.yml libssh2.yml libvncserver.yml linuxkm.yml macos-apple-native-cert-validation.yml mbedtls.sh mbedtls.yml membrowse-comment.yml membrowse-onboard.yml membrowse-report.yml memcached.sh memcached.yml mono.yml mosquitto.yml msmtp.yml msys2.yml multi-arch.yml multi-compiler.yml net-snmp.yml nginx.yml no-malloc.yml no-tls.yml nss.sh nss.yml ntp.yml ocsp.yml openldap.yml openssh.yml openssl-ech.yml opensslcoexist.yml openvpn.yml os-check.yml packaging.yml pam-ipmi.yml pq-all.yml pr-commit-check.yml psk.yml puf.yml python.yml rng-tools.yml rust-wrapper.yml se050-sim.yml smallStackSize.yml socat.yml softhsm.yml sssd.yml stm32-sim.yml stsafe-a120-sim.yml stunnel.yml symbol-prefixes.yml threadx.yml tls-anvil.yml trackmemory.yml watcomc.yml win-csharp-test.yml wolfCrypt-Wconversion.yml wolfboot-integration.yml wolfsm.yml xcode.yml zephyr-4.x.yml zephyr.yml
PULL_REQUEST_TEMPLATE.md SECURITY.md membrowse-targets.json
Docker
OpenWrt Dockerfile README.md runTests.sh
packaging
debian Dockerfile
fedora Dockerfile
wolfCLU Dockerfile README.md
yocto Dockerfile buildAndPush.sh
Dockerfile Dockerfile.cross-compiler README.md buildAndPush.sh include.am run.sh
IDE
ARDUINO
sketches
wolfssl_client README.md
wolfssl_server README.md
wolfssl_version README.md
README.md
Arduino_README_prepend.md README.md include.am keywords.txt library.properties.template wolfssl-arduino.cpp wolfssl-arduino.sh wolfssl.h
AURIX Cpu0_Main.c README.md include.am user_settings.h wolf_main.c
Android Android.bp README.md include.am user_settings.h
CRYPTOCELL README.md include.am main.c user_settings.h
CSBENCH include.am user_settings.h
ECLIPSE
DEOS
deos_wolfssl .options
README.md deos_malloc.c include.am tls_wolfssl.c tls_wolfssl.h user_settings.h
MICRIUM README.md client_wolfssl.c client_wolfssl.h include.am server_wolfssl.c server_wolfssl.h user_settings.h wolfsslRunTests.c
RTTHREAD README.md include.am user_settings.h wolfssl_test.c
SIFIVE README.md include.am
Espressif
ESP-IDF
examples
template
VisualGDB wolfssl_template_IDF_v5.1_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266
wolfssl_benchmark
VisualGDB wolfssl_benchmark_IDF_v4.4_ESP32.sln wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32.sln wolfssl_benchmark_IDF_v5_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32C3.sln wolfssl_benchmark_IDF_v5_ESP32C3.vgdbproj wolfssl_benchmark_IDF_v5_ESP32S3.sln wolfssl_benchmark_IDF_v5_ESP32S3.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266
wolfssl_client
VisualGDB README.md wolfssl_client_IDF_v5_ESP32.sln wolfssl_client_IDF_v5_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include client-tls.h main.h time_helper.h wifi_connect.h
CMakeLists.txt Kconfig.projbuild client-tls.c component.mk main.c time_helper.c wifi_connect.c
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_client_ESP8266.vgdbproj
wolfssl_server
VisualGDB README.md wolfssl_server_IDF_v5_ESP32.sln wolfssl_server_IDF_v5_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h server-tls.h time_helper.h wifi_connect.h
CMakeLists.txt Kconfig.projbuild component.mk main.c server-tls.c time_helper.c wifi_connect.c
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_server_ESP8266.vgdbproj
wolfssl_test
VisualGDB wolfssl_test-IDF_v5_ESP32.sln wolfssl_test-IDF_v5_ESP32.vgdbproj wolfssl_test-IDF_v5_ESP32C3.sln wolfssl_test-IDF_v5_ESP32C3.vgdbproj wolfssl_test-IDF_v5_ESP32C6.sln wolfssl_test-IDF_v5_ESP32C6.vgdbproj wolfssl_test_IDF_v5_ESP32S3.sln wolfssl_test_IDF_v5_ESP32S3.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32 sdkconfig.defaults.esp32c3 sdkconfig.defaults.esp32c6 sdkconfig.defaults.esp32h2 sdkconfig.defaults.esp32s2 sdkconfig.defaults.esp32s3 sdkconfig.defaults.esp8266 testAll.sh testMonitor.sh wolfssl_test_ESP8266.sln wolfssl_test_ESP8266.vgdbproj
wolfssl_test_idf
VisualGDB VisualGDB_wolfssl_test_idf.sln VisualGDB_wolfssl_test_idf.vgdbproj
main CMakeLists.txt Kconfig.projbuild component.mk main.c main_wip.c.ex time_helper.c time_helper.h
CMakeLists.txt Kconfig.projbuild README.md component.mk sdkconfig.defaults
README.md
libs CMakeLists.txt README.md component.mk tigard.cfg
test CMakeLists.txt README.md component.mk test_wolfssl.c
README.md README_32se.md UPDATE.md compileAllExamples.sh dummy_config_h dummy_test_paths.h setup.sh setup_win.bat user_settings.h
README.md include.am
GCC-ARM
Header user_settings.h
Source armtarget.c benchmark_main.c test_main.c tls_client.c tls_server.c wolf_main.c
Makefile Makefile.bench Makefile.client Makefile.common Makefile.server Makefile.static Makefile.test README.md include.am linker.ld linker_fips.ld
Gaisler-BCC README.md include.am
HEXAGON
DSP Makefile wolfssl_dsp.idl
Makefile README.md build.sh ecc-verify-benchmark.c ecc-verify.c include.am user_settings.h
HEXIWEAR
wolfSSL_HW .cwGeneratedFileSetLog user_settings.h
IAR-EWARM
Projects
benchmark benchmark-main.c current_time.c wolfCrypt-benchmark.ewd wolfCrypt-benchmark.ewp
common minimum-startup.c wolfssl.icf
lib wolfSSL-Lib.ewd wolfSSL-Lib.ewp
test test-main.c wolfCrypt-test.ewd wolfCrypt-test.ewp
user_settings.h wolfssl.eww
embOS
SAMV71_XULT
embOS_SAMV71_XULT_Linker_Script samv71q21_wolfssl.icf
embOS_SAMV71_XULT_user_settings user_settings.h user_settings_simple_example.h user_settings_verbose_example.h
embOS_wolfcrypt_benchmark_SAMV71_XULT
Application runBenchmarks.c
README_wolfcrypt_benchmark wolfcrypt_benchmark.ewd wolfcrypt_benchmark.ewp
embOS_wolfcrypt_lib_SAMV71_XULT README_wolfcrypt_lib wolfcrypt_lib.ewd wolfcrypt_lib.ewp
embOS_wolfcrypt_test_SAMV71_XULT
Application runWolfcryptTests.c
README_wolfcrypt_test wolfcrypt_test.ewd wolfcrypt_test.ewp
README_SAMV71
custom_port
custom_port_Linker_Script samv71q21_wolfssl.icf
custom_port_user_settings user_settings.h
wolfcrypt_benchmark_custom_port
Application runBenchmarks.c
wolfcrypt_test_custom_port
Application runWolfcryptTests.c
README_custom_port
extract_trial_here README_extract_trial_here
README
.gitignore README
IAR-MSP430 Makefile README.md include.am main.c user_settings.h
INTIME-RTOS Makefile README.md include.am libwolfssl.c libwolfssl.vcxproj user_settings.h wolfExamples.c wolfExamples.h wolfExamples.sln wolfExamples.vcxproj wolfssl-lib.sln wolfssl-lib.vcxproj
Infineon README.md include.am user_settings.h
KDS
config user_settings.h
include.am
LINUX-SGX README.md build.sh clean.sh include.am sgx_t_static.mk
LPCXPRESSO
lib_wolfssl lpc_18xx_port.c user_settings.h
wolf_example
src lpc_18xx_startup.c wolfssl_example.c
readme.txt
README.md
M68K
benchmark Makefile main.cpp
testwolfcrypt Makefile main.cpp
Makefile README.md include.am user_settings.h
MCUEXPRESSO
RT1170 fsl_caam_c.patch fsl_caam_h.patch user_settings.h
benchmark
source run_benchmark.c
wolfssl liblinks.xml
README.md include.am user_settings.h wolfcrypt_test.c
MDK-ARM
LPC43xx time-LCP43xx.c
MDK-ARM
wolfSSL Retarget.c cert_data.c cert_data.h config-BARE-METAL.h config-FS.h config-RTX-TCP-FS.h config-WOLFLIB.h main.c shell.c time-CortexM3-4.c time-dummy.c wolfssl_MDK_ARM.c wolfssl_MDK_ARM.h
STM32F2xx_StdPeriph_Lib time-STM32F2xx.c
MDK5-ARM
Conf user_settings.h
Inc wolfssl_MDK_ARM.h
Projects
CryptBenchmark Abstract.txt CryptBenchmark.sct CryptBenchmark.uvoptx CryptBenchmark.uvprojx main.c
CryptTest Abstract.txt CryptTest.sct CryptTest.uvoptx CryptTest.uvprojx main.c
EchoClient Abstract.txt EchoClient.uvoptx EchoClient.uvprojx main.c wolfssl-link.sct
EchoServer Abstract.txt EchoServer.uvoptx EchoServer.uvprojx main.c wolfssl-link.sct
SimpleClient Abstract.txt SimpleClient.uvoptx SimpleClient.uvprojx main.c wolfssl-link.sct
SimpleServer Abstract.txt SimpleServer.uvoptx SimpleServer.uvprojx main.c wolfssl-link.sct
wolfSSL-Full Abstract.txt main.c shell.c time-CortexM3-4.c wolfsslFull.uvoptx wolfsslFull.uvprojx
wolfSSL-Lib Abstract.txt wolfSSL-Lib.uvoptx wolfSSL-Lib.uvprojx
Src ssl-dummy.c
README.md include.am
MPLABX16
wolfcrypt_test.X
nbproject
private configurations.xml private.xml
configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
README.md include.am main.c user_settings.h
MQX Makefile README-jp.md README.md client-tls.c include.am server-tls.c user_config.h user_settings.h
MSVS-2019-AZSPHERE
client client.c client.h
server server.c server.h
shared util.h
wolfssl_new_azsphere
HardwareDefinitions
avnet_mt3620_sk
inc
hw template_appliance.h
template_appliance.json
mt3620_rdb
inc
hw template_appliance.h
template_appliance.json
seeed_mt3620_mdb
inc
hw template_appliance.h
template_appliance.json
.gitignore CMakeLists.txt CMakeSettings.json app_manifest.json applibs_versions.h launch.vs.json main.c
README.md include.am user_settings.h
MYSQL CMakeLists_wolfCrypt.txt CMakeLists_wolfSSL.txt do.sh
NDS README.md
NETOS Makefile.wolfcrypt.inc README.md include.am user_settings.h user_settings.h-cert2425 user_settings.h-cert3389 wolfssl_netos_custom.c
OPENSTM32 README.md
PlatformIO
examples
wolfssl_benchmark
include README main.h
lib README
src CMakeLists.txt main.c
test README
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_benchmark.code-workspace
wolfssl_test
include README main.h
lib README
src CMakeLists.txt main.c
test README
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_test.code-workspace
README.md wolfssl_platformio.code-workspace
README.md include.am
QNX
CAAM-DRIVER Makefile
example-client Makefile client-tls.c
example-cmac Makefile cmac-test.c
example-server Makefile server-tls.c
testwolfcrypt Makefile
wolfssl Makefile user_settings.h
README.md include.am
RISCV
SIFIVE-HIFIVE1 Makefile README.md include.am main.c user_settings.h
SIFIVE-UNLEASHED README.md include.am
include.am
ROWLEY-CROSSWORKS-ARM Kinetis_FlashPlacement.xml README.md arm_startup.c benchmark_main.c hw.h include.am kinetis_hw.c retarget.c test_main.c user_settings.h wolfssl.hzp wolfssl_ltc.hzp
Renesas
cs+
Projects
common strings.h unistd.h user_settings.h wolfssl_dummy.c
t4_demo README_en.txt README_jp.txt t4_demo.mtpj wolf_client.c wolf_demo.h wolf_main.c wolf_server.c
test test.mtpj test_main.c
wolfssl_lib wolfssl_lib.mtpj
README include.am
e2studio
DK-S7G2
benchmark-template
src app_entry.c
example_server-template
src app_entry.c
wolfcrypttest-template
src app_entry.c
wolfssl-template-project configuration.xml
README.md include.am user_settings.h
Projects
common strings.h unistd.h user_settings.h wolfssl_dummy.c
test
src key_data.c key_data.h test_main.c wolf_client.c wolf_server.c wolfssl_demo.h
tools generate_rsa_keypair.sh genhexbuf.pl rsa_pss_sign.sh
wolfssl
src .gitkeep
wolfcrypt
src .gitkeep
README include.am
RA6M3
benchmark-wolfcrypt
common .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
client-wolfssl
common
src .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl_thread_entry.h
common
ra6m3g README.md
src freertos_tcp_port.c
user_settings.h util.h
server-wolfssl
common
src .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl_thread_entry.h
test-wolfcrypt
common .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl
src .gitkeep
wolfcrypt .gitkeep
README.md README_APRA6M_en.md README_APRA6M_jp.md include.am
RA6M3G README.md
RA6M4
common user_settings.h wolfssl_demo.h
test
key_data key_data.h key_data_sce.c
src
SEGGER_RTT myprint.c
common .gitignore
test_main.c wolf_client.c wolfssl_sce_unit_test.c
test_RA6M4Debug.launch
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
README.md include.am
RX65N
GR-ROSE
common strings.h unistd.h user_settings.h wolfssl_dummy.c
smc smc.scfg
test
src key_data.c key_data.h test_main.c wolf_client.c wolf_server.c wolfssl_demo.h
test.rcpc test_HardwareDebug.launch
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
wolfssl wolfssl.rcpc
README_EN.md README_JP.md include.am
RSK
resource section.esi
wolfssl wolfssl.rcpc
wolfssl_demo key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h
InstructionManualForExample_RSK+RX65N-2MB_EN.pdf InstructionManualForExample_RSK+RX65N-2MB_JP.pdf README_EN.md README_JP.md include.am
RX72N
EnvisionKit
Simple
common sectioninfo.esi wolfssl_dummy.c
test
src
client simple_tcp_client.c simple_tls_tsip_client.c
server simple_tcp_server.c simple_tls_server.c
test_main.c wolfssl_simple_demo.h
test.rcpc test.scfg test_HardwareDebug.launch
wolfssl wolfssl.rcpc
README_EN.md README_JP.md
resource section.esi
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
wolfssl wolfssl.rcpc
wolfssl_demo key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h wolfssl_tsip_unit_test.c
InstructionManualForExample_RX72N_EnvisonKit_EN.pdf InstructionManualForExample_RX72N_EnvisonKit_JP.pdf README_EN.md README_JP.md include.am
RZN2L
common user_settings.h wolfssl_demo.h
test
src
serial_io app_print.c
test wolf_client.c wolf_server.c wolfssl_rsip_unit_test.c
wolfCrypt .gitignore
wolfSSL .gitignore
local_system_init.c rzn2l_tst_thread_entry.c wolfssl_dummy.c
README.md include.am
SK-S7G2
common user_settings.h
wolfssl_lib configuration.xml
.gitignore README.md include.am
STARCORE README.txt include.am starcore_test.c user_settings.h
STM32Cube README.md STM32_Benchmarks.md default_conf.ftl include.am main.c wolfssl_example.c wolfssl_example.h
SimplicityStudio README.md include.am test_wolf.c user_settings.h
TRUESTUDIO
wolfssl user_settings.h
README include.am
VS-ARM README.md include.am user_settings.h wolfssl.sln wolfssl.vcxproj
VS-AZURE-SPHERE
client app_manifest.json client.c client.h client.vcxproj
server app_manifest.json server.c server.h server.vcxproj
shared util.h
wolfcrypt_test app_manifest.json wolfcrypt_test.vcxproj
README.md include.am user_settings.h wolfssl.sln wolfssl.vcxproj
VisualDSP include.am user_settings.h wolf_tasks.c
WICED-STUDIO README include.am user_settings.h
WIN README.txt include.am test.vcxproj user_settings.h user_settings_dtls.h wolfssl-fips.sln wolfssl-fips.vcxproj
WIN-SGX ReadMe.txt include.am wolfSSL_SGX.edl wolfSSL_SGX.sln wolfSSL_SGX.vcxproj
WIN-SRTP-KDF-140-3 README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxproj
WIN10 README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxproj
WINCE README.md include.am user_settings.h user_settings.h.140-2-deprecated
WORKBENCH README.md include.am
XCODE
Benchmark
wolfBench
Assets.xcassets
AppIcon.appiconset Contents.json
Base.lproj LaunchScreen.storyboard Main.storyboard
AppDelegate.h AppDelegate.m Info.plist ViewController.h ViewController.m main.m
wolfBench.xcodeproj project.pbxproj
include.am
wolfssl-FIPS.xcodeproj project.pbxproj
wolfssl.xcodeproj project.pbxproj
wolfssl_testsuite.xcodeproj project.pbxproj
README.md build-for-i386.sh include.am user_settings.h
XCODE-FIPSv2
macOS-C++
Intel user_settings.h
M1 user_settings.h
include.am user_settings.h
XCODE-FIPSv5 README include.am user_settings.h
XCODE-FIPSv6 README include.am user_settings.h
XilinxSDK
2018_2 lscript.ld
2019_2
wolfCrypt_example
src lscript.ld
wolfCrypt_example_system wolfCrypt_example_system.sprj
2022_1
wolfCrypt_FreeRTOS_example wolfCrypt_FreeRTOS_example.prj
wolfCrypt_FreeRTOS_example_system wolfCrypt_FreeRTOS_example_system.sprj
wolfCrypt_example wolfCrypt_example.prj
wolfCrypt_example_system wolfCrypt_example_system.sprj
.gitignore
README.md bench.sh combine.sh eclipse_formatter_profile.xml graph.sh include.am user_settings.h wolfssl_example.c
apple-universal
wolfssl-multiplatform
wolfssl-multiplatform
Assets.xcassets
AccentColor.colorset Contents.json
AppIcon.appiconset Contents.json
Contents.json
ContentView.swift simple_client_example.c simple_client_example.h wolfssl-multiplatform-Bridging-Header.h wolfssl_multiplatform.entitlements wolfssl_multiplatformApp.swift wolfssl_test_driver.c wolfssl_test_driver.h
wolfssl-multiplatform.xcodeproj project.pbxproj
.gitignore README.md build-wolfssl-framework.sh include.am
iotsafe Makefile README.md ca-cert.c devices.c devices.h include.am main.c memory-tls.c startup.c target.ld user_settings.h
iotsafe-raspberrypi Makefile README.md client-tls13.c include.am main.c
mynewt README.md apps.wolfcrypttest.pkg.yml crypto.wolfssl.pkg.yml crypto.wolfssl.syscfg.yml include.am setup.sh
zephyr README.md include.am
include.am
RTOS
nuttx
wolfssl .gitignore Kconfig Make.defs Makefile README.md setup-wolfssl.sh user_settings.h
include.am
bsdkm Makefile README.md bsdkm_wc_port.h include.am wolfkmod.c wolfkmod_aes.c x86_vecreg.c
certs
1024 ca-cert.der ca-cert.pem ca-key.der ca-key.pem client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der dh1024.der dh1024.pem dsa-pub-1024.pem dsa1024.der dsa1024.pem include.am rsa1024.der server-cert.der server-cert.pem server-key.der server-key.pem
3072 client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der include.am
4096 client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der include.am
acert
rsa_pss acert.pem acert_ietf.pem acert_ietf_pubkey.pem acert_pubkey.pem
acert.pem acert_ietf.pem acert_ietf_pubkey.pem acert_pubkey.pem include.am
aia ca-issuers-cert.pem multi-aia-cert.pem overflow-aia-cert.pem
crl
extra-crls ca-int-cert-revoked.pem claim-root.pem crl_critical_entry.pem crlnum_57oct.pem crlnum_64oct.pem general-server-crl.pem large_crlnum.pem large_crlnum2.pem
hash_der 0fdb2da4.r0
hash_pem 0fdb2da4.r0
bad_time_fmt.pem ca-int-ecc.pem ca-int.pem ca-int2-ecc.pem ca-int2.pem caEcc384Crl.pem caEccCrl.der caEccCrl.pem cliCrl.pem client-int-ecc.pem client-int.pem crl.der crl.pem crl.revoked crl2.der crl2.pem crl_reason.pem crl_rsapss.pem eccCliCRL.pem eccSrvCRL.pem gencrls.sh include.am server-goodaltCrl.pem server-goodaltwildCrl.pem server-goodcnCrl.pem server-goodcnwildCrl.pem server-int-ecc.pem server-int.pem wolfssl.cnf
dilithium bench_dilithium_level2_key.der bench_dilithium_level3_key.der bench_dilithium_level5_key.der include.am
ecc bp256r1-key.der bp256r1-key.pem ca-secp256k1-cert.pem ca-secp256k1-key.pem client-bp256r1-cert.der client-bp256r1-cert.pem client-secp256k1-cert.der client-secp256k1-cert.pem genecc.sh include.am secp256k1-key.der secp256k1-key.pem secp256k1-param.pem secp256k1-privkey.der secp256k1-privkey.pem server-bp256r1-cert.der server-bp256r1-cert.pem server-secp256k1-cert.der server-secp256k1-cert.pem server2-secp256k1-cert.der server2-secp256k1-cert.pem wolfssl.cnf wolfssl_384.cnf
ed25519 ca-ed25519-key.der ca-ed25519-key.pem ca-ed25519-priv.der ca-ed25519-priv.pem ca-ed25519.der ca-ed25519.pem client-ed25519-key.der client-ed25519-key.pem client-ed25519-priv.der client-ed25519-priv.pem client-ed25519.der client-ed25519.pem eddsa-ed25519.der eddsa-ed25519.pem gen-ed25519-certs.sh gen-ed25519-keys.sh gen-ed25519.sh include.am root-ed25519-key.der root-ed25519-key.pem root-ed25519-priv.der root-ed25519-priv.pem root-ed25519.der root-ed25519.pem server-ed25519-cert.pem server-ed25519-key.der server-ed25519-key.pem server-ed25519-priv.der server-ed25519-priv.pem server-ed25519.der server-ed25519.pem
ed448 ca-ed448-key.der ca-ed448-key.pem ca-ed448-priv.der ca-ed448-priv.pem ca-ed448.der ca-ed448.pem client-ed448-key.der client-ed448-key.pem client-ed448-priv.der client-ed448-priv.pem client-ed448.der client-ed448.pem gen-ed448-certs.sh gen-ed448-keys.sh include.am root-ed448-key.der root-ed448-key.pem root-ed448-priv.der root-ed448-priv.pem root-ed448.der root-ed448.pem server-ed448-cert.pem server-ed448-key.der server-ed448-key.pem server-ed448-priv.der server-ed448-priv.pem server-ed448.der server-ed448.pem
external DigiCertGlobalRootCA.pem README.txt ca-digicert-ev.pem ca-globalsign-root.pem ca-google-root.pem ca_collection.pem include.am
falcon bench_falcon_level1_key.der bench_falcon_level5_key.der include.am
intermediate
ca_false_intermediate gentestcert.sh int_ca.key server.key test_ca.key test_ca.pem test_int_not_cacert.pem test_sign_bynoca_srv.pem wolfssl_base.conf wolfssl_srv.conf
ca-ecc-bad-aki.der ca-ecc-bad-aki.pem ca-int-cert.der ca-int-cert.pem ca-int-ecc-cert.der ca-int-ecc-cert.pem ca-int-ecc-key.der ca-int-ecc-key.pem ca-int-key.der ca-int-key.pem ca-int2-cert.der ca-int2-cert.pem ca-int2-ecc-cert.der ca-int2-ecc-cert.pem ca-int2-ecc-key.der ca-int2-ecc-key.pem ca-int2-key.der ca-int2-key.pem client-chain-alt-ecc.pem client-chain-alt.pem client-chain-ecc.der client-chain-ecc.pem client-chain.der client-chain.pem client-int-cert.der client-int-cert.pem client-int-ecc-cert.der client-int-ecc-cert.pem genintcerts.sh include.am server-chain-alt-ecc.pem server-chain-alt.pem server-chain-ecc.der server-chain-ecc.pem server-chain-short.pem server-chain.der server-chain.pem server-int-cert.der server-int-cert.pem server-int-ecc-cert.der server-int-ecc-cert.pem
lms bc_hss_L2_H5_W8_root.der bc_hss_L3_H5_W4_root.der bc_lms_chain_ca.der bc_lms_chain_leaf.der bc_lms_native_bc_root.der bc_lms_sha256_h10_w8_root.der bc_lms_sha256_h5_w4_root.der include.am
mldsa README.txt include.am mldsa44-cert.der mldsa44-cert.pem mldsa44-key.pem mldsa44_bare-priv.der mldsa44_bare-seed.der mldsa44_oqskeypair.der mldsa44_priv-only.der mldsa44_pub-spki.der mldsa44_seed-only.der mldsa44_seed-priv.der mldsa65-cert.der mldsa65-cert.pem mldsa65-key.pem mldsa65_bare-priv.der mldsa65_bare-seed.der mldsa65_oqskeypair.der mldsa65_priv-only.der mldsa65_pub-spki.der mldsa65_seed-only.der mldsa65_seed-priv.der mldsa87-cert.der mldsa87-cert.pem mldsa87-key.pem mldsa87_bare-priv.der mldsa87_bare-seed.der mldsa87_oqskeypair.der mldsa87_priv-only.der mldsa87_pub-spki.der mldsa87_seed-only.der mldsa87_seed-priv.der
ocsp imposter-root-ca-cert.der imposter-root-ca-cert.pem imposter-root-ca-key.der imposter-root-ca-key.pem include.am index-ca-and-intermediate-cas.txt index-ca-and-intermediate-cas.txt.attr index-intermediate1-ca-issued-certs.txt index-intermediate1-ca-issued-certs.txt.attr index-intermediate2-ca-issued-certs.txt index-intermediate2-ca-issued-certs.txt.attr index-intermediate3-ca-issued-certs.txt index-intermediate3-ca-issued-certs.txt.attr intermediate1-ca-cert.der intermediate1-ca-cert.pem intermediate1-ca-key.der intermediate1-ca-key.pem intermediate2-ca-cert.der intermediate2-ca-cert.pem intermediate2-ca-key.der intermediate2-ca-key.pem intermediate3-ca-cert.der intermediate3-ca-cert.pem intermediate3-ca-key.der intermediate3-ca-key.pem ocsp-responder-cert.der ocsp-responder-cert.pem ocsp-responder-key.der ocsp-responder-key.pem openssl.cnf renewcerts-for-test.sh renewcerts.sh root-ca-cert.der root-ca-cert.pem root-ca-crl.pem root-ca-key.der root-ca-key.pem server1-cert.der server1-cert.pem server1-chain-noroot.pem server1-key.der server1-key.pem server2-cert.der server2-cert.pem server2-key.der server2-key.pem server3-cert.der server3-cert.pem server3-key.der server3-key.pem server4-cert.der server4-cert.pem server4-key.der server4-key.pem server5-cert.der server5-cert.pem server5-key.der server5-key.pem test-leaf-response.der test-multi-response.der test-response-nointern.der test-response-rsapss.der test-response.der
p521 ca-p521-key.der ca-p521-key.pem ca-p521-priv.der ca-p521-priv.pem ca-p521.der ca-p521.pem client-p521-key.der client-p521-key.pem client-p521-priv.der client-p521-priv.pem client-p521.der client-p521.pem gen-p521-certs.sh gen-p521-keys.sh include.am root-p521-key.der root-p521-key.pem root-p521-priv.der root-p521-priv.pem root-p521.der root-p521.pem server-p521-cert.pem server-p521-key.der server-p521-key.pem server-p521-priv.der server-p521-priv.pem server-p521.der server-p521.pem
renewcerts wolfssl.cnf
rpk client-cert-rpk.der client-ecc-cert-rpk.der include.am server-cert-rpk.der server-ecc-cert-rpk.der
rsapss ca-3072-rsapss-key.der ca-3072-rsapss-key.pem ca-3072-rsapss-priv.der ca-3072-rsapss-priv.pem ca-3072-rsapss.der ca-3072-rsapss.pem ca-rsapss-key.der ca-rsapss-key.pem ca-rsapss-priv.der ca-rsapss-priv.pem ca-rsapss.der ca-rsapss.pem client-3072-rsapss-key.der client-3072-rsapss-key.pem client-3072-rsapss-priv.der client-3072-rsapss-priv.pem client-3072-rsapss.der client-3072-rsapss.pem client-rsapss-key.der client-rsapss-key.pem client-rsapss-priv.der client-rsapss-priv.pem client-rsapss.der client-rsapss.pem gen-rsapss-keys.sh include.am renew-rsapss-certs.sh root-3072-rsapss-key.der root-3072-rsapss-key.pem root-3072-rsapss-priv.der root-3072-rsapss-priv.pem root-3072-rsapss.der root-3072-rsapss.pem root-rsapss-key.der root-rsapss-key.pem root-rsapss-priv.der root-rsapss-priv.pem root-rsapss.der root-rsapss.pem server-3072-rsapss-cert.pem server-3072-rsapss-key.der server-3072-rsapss-key.pem server-3072-rsapss-priv.der server-3072-rsapss-priv.pem server-3072-rsapss.der server-3072-rsapss.pem server-mix-rsapss-cert.pem server-rsapss-cert.pem server-rsapss-key.der server-rsapss-key.pem server-rsapss-priv.der server-rsapss-priv.pem server-rsapss.der server-rsapss.pem
sia timestamping-sia-cert.pem
slhdsa bench_slhdsa_sha2_128f_key.der bench_slhdsa_sha2_128s_key.der bench_slhdsa_sha2_192f_key.der bench_slhdsa_sha2_192s_key.der bench_slhdsa_sha2_256f_key.der bench_slhdsa_sha2_256s_key.der bench_slhdsa_shake128f_key.der bench_slhdsa_shake128s_key.der bench_slhdsa_shake192f_key.der bench_slhdsa_shake192s_key.der bench_slhdsa_shake256f_key.der bench_slhdsa_shake256s_key.der client-mldsa44-priv.pem client-mldsa44-sha2.der client-mldsa44-sha2.pem client-mldsa44-shake.der client-mldsa44-shake.pem gen-slhdsa-mldsa-certs.sh include.am root-slhdsa-sha2-128s-priv.der root-slhdsa-sha2-128s-priv.pem root-slhdsa-sha2-128s.der root-slhdsa-sha2-128s.pem root-slhdsa-shake-128s-priv.der root-slhdsa-shake-128s-priv.pem root-slhdsa-shake-128s.der root-slhdsa-shake-128s.pem server-mldsa44-priv.pem server-mldsa44-sha2.der server-mldsa44-sha2.pem server-mldsa44-shake.der server-mldsa44-shake.pem
sm2 ca-sm2-key.der ca-sm2-key.pem ca-sm2-priv.der ca-sm2-priv.pem ca-sm2.der ca-sm2.pem client-sm2-key.der client-sm2-key.pem client-sm2-priv.der client-sm2-priv.pem client-sm2.der client-sm2.pem fix_sm2_spki.py gen-sm2-certs.sh gen-sm2-keys.sh include.am root-sm2-key.der root-sm2-key.pem root-sm2-priv.der root-sm2-priv.pem root-sm2.der root-sm2.pem self-sm2-cert.pem self-sm2-key.pem self-sm2-priv.pem server-sm2-cert.der server-sm2-cert.pem server-sm2-key.der server-sm2-key.pem server-sm2-priv.der server-sm2-priv.pem server-sm2.der server-sm2.pem
statickeys dh-ffdhe2048-params.pem dh-ffdhe2048-pub.der dh-ffdhe2048-pub.pem dh-ffdhe2048.der dh-ffdhe2048.pem ecc-secp256r1.der ecc-secp256r1.pem gen-static.sh include.am x25519-pub.der x25519-pub.pem x25519.der x25519.pem
test
expired expired-ca.der expired-ca.pem expired-cert.der expired-cert.pem
catalog.txt cert-bad-neg-int.der cert-bad-oid.der cert-bad-utf8.der cert-ext-ia.cfg cert-ext-ia.der cert-ext-ia.pem cert-ext-joi.cfg cert-ext-joi.der cert-ext-joi.pem cert-ext-mnc.der cert-ext-multiple.cfg cert-ext-multiple.der cert-ext-multiple.pem cert-ext-nc-combined.der cert-ext-nc-combined.pem cert-ext-nc.cfg cert-ext-nc.der cert-ext-nc.pem cert-ext-ncdns.der cert-ext-ncdns.pem cert-ext-ncip.der cert-ext-ncip.pem cert-ext-ncmixed.der cert-ext-ncmulti.der cert-ext-ncmulti.pem cert-ext-ncrid.der cert-ext-ncrid.pem cert-ext-nct.cfg cert-ext-nct.der cert-ext-nct.pem cert-ext-ndir-exc.cfg cert-ext-ndir-exc.der cert-ext-ndir-exc.pem cert-ext-ndir.cfg cert-ext-ndir.der cert-ext-ndir.pem cert-ext-ns.der cert-over-max-altnames.cfg cert-over-max-altnames.der cert-over-max-altnames.pem cert-over-max-nc.cfg cert-over-max-nc.der cert-over-max-nc.pem client-ecc-cert-ski.hex cn-ip-literal.der cn-ip-wildcard.der crit-cert.pem crit-key.pem dh1024.der dh1024.pem dh512.der dh512.pem digsigku.pem encrypteddata.msg gen-badsig.sh gen-ext-certs.sh gen-testcerts.sh include.am kari-keyid-cms.msg ktri-keyid-cms.msg ossl-trusted-cert.pem server-badaltname.der server-badaltname.pem server-badaltnull.der server-badaltnull.pem server-badcn.der server-badcn.pem server-badcnnull.der server-badcnnull.pem server-cert-ecc-badsig.der server-cert-ecc-badsig.pem server-cert-rsa-badsig.der server-cert-rsa-badsig.pem server-duplicate-policy.pem server-garbage.der server-garbage.pem server-goodalt.der server-goodalt.pem server-goodaltwild.der server-goodaltwild.pem server-goodcn.der server-goodcn.pem server-goodcnwild.der server-goodcnwild.pem server-localhost.der server-localhost.pem smime-test-canon.p7s smime-test-multipart-badsig.p7s smime-test-multipart.p7s smime-test.p7s
test-pathlen assemble-chains.sh chainA-ICA1-key.pem chainA-ICA1-pathlen0.pem chainA-assembled.pem chainA-entity-key.pem chainA-entity.pem chainB-ICA1-key.pem chainB-ICA1-pathlen0.pem chainB-ICA2-key.pem chainB-ICA2-pathlen1.pem chainB-assembled.pem chainB-entity-key.pem chainB-entity.pem chainC-ICA1-key.pem chainC-ICA1-pathlen1.pem chainC-assembled.pem chainC-entity-key.pem chainC-entity.pem chainD-ICA1-key.pem chainD-ICA1-pathlen127.pem chainD-assembled.pem chainD-entity-key.pem chainD-entity.pem chainE-ICA1-key.pem chainE-ICA1-pathlen128.pem chainE-assembled.pem chainE-entity-key.pem chainE-entity.pem chainF-ICA1-key.pem chainF-ICA1-pathlen1.pem chainF-ICA2-key.pem chainF-ICA2-pathlen0.pem chainF-assembled.pem chainF-entity-key.pem chainF-entity.pem chainG-ICA1-key.pem chainG-ICA1-pathlen0.pem chainG-ICA2-key.pem chainG-ICA2-pathlen1.pem chainG-ICA3-key.pem chainG-ICA3-pathlen99.pem chainG-ICA4-key.pem chainG-ICA4-pathlen5.pem chainG-ICA5-key.pem chainG-ICA5-pathlen20.pem chainG-ICA6-key.pem chainG-ICA6-pathlen10.pem chainG-ICA7-key.pem chainG-ICA7-pathlen100.pem chainG-assembled.pem chainG-entity-key.pem chainG-entity.pem chainH-ICA1-key.pem chainH-ICA1-pathlen0.pem chainH-ICA2-key.pem chainH-ICA2-pathlen2.pem chainH-ICA3-key.pem chainH-ICA3-pathlen2.pem chainH-ICA4-key.pem chainH-ICA4-pathlen2.pem chainH-assembled.pem chainH-entity-key.pem chainH-entity.pem chainI-ICA1-key.pem chainI-ICA1-no_pathlen.pem chainI-ICA2-key.pem chainI-ICA2-no_pathlen.pem chainI-ICA3-key.pem chainI-ICA3-pathlen2.pem chainI-assembled.pem chainI-entity-key.pem chainI-entity.pem chainJ-ICA1-key.pem chainJ-ICA1-no_pathlen.pem chainJ-ICA2-key.pem chainJ-ICA2-no_pathlen.pem chainJ-ICA3-key.pem chainJ-ICA3-no_pathlen.pem chainJ-ICA4-key.pem chainJ-ICA4-pathlen2.pem chainJ-assembled.pem chainJ-entity-key.pem chainJ-entity.pem include.am refreshkeys.sh
test-serial0 ee_normal.pem ee_serial0.pem generate_certs.sh include.am intermediate_serial0.pem root_serial0.pem root_serial0_key.pem selfsigned_nonca_serial0.pem
xmss bc_xmss_chain_ca.der bc_xmss_chain_leaf.der bc_xmss_sha2_10_256_root.der bc_xmss_sha2_16_256_root.der bc_xmssmt_sha2_20_2_256_root.der bc_xmssmt_sha2_20_4_256_root.der bc_xmssmt_sha2_40_8_256_root.der include.am
ca-cert-chain.der ca-cert.der ca-cert.pem ca-ecc-cert.der ca-ecc-cert.pem ca-ecc-key.der ca-ecc-key.pem ca-ecc384-cert.der ca-ecc384-cert.pem ca-ecc384-key.der ca-ecc384-key.pem ca-key-pkcs8-attribute.der ca-key.der ca-key.pem check_dates.sh client-absolute-urn.pem client-ca-cert.der client-ca-cert.pem client-ca.pem client-cert-ext.der client-cert-ext.pem client-cert.der client-cert.pem client-crl-dist.der client-crl-dist.pem client-ecc-ca-cert.der client-ecc-ca-cert.pem client-ecc-cert.der client-ecc-cert.pem client-ecc384-cert.der client-ecc384-cert.pem client-ecc384-key.der client-ecc384-key.pem client-key.der client-key.pem client-keyEnc.pem client-keyPub.der client-keyPub.pem client-relative-uri.pem client-uri-cert.pem csr.attr.der csr.dsa.der csr.dsa.pem csr.ext.der csr.signed.der dh-priv-2048.der dh-priv-2048.pem dh-pub-2048.der dh-pub-2048.pem dh-pubkey-2048.der dh2048.der dh2048.pem dh3072.der dh3072.pem dh4096.der dh4096.pem dsa-pubkey-2048.der dsa2048.der dsa2048.pem dsa3072.der dsaparams.der dsaparams.pem ecc-client-key.der ecc-client-key.pem ecc-client-keyPub.der ecc-client-keyPub.pem ecc-key-comp.pem ecc-keyPkcs8.der ecc-keyPkcs8.pem ecc-keyPkcs8Enc.der ecc-keyPkcs8Enc.pem ecc-keyPub.der ecc-keyPub.pem ecc-params.der ecc-params.pem ecc-privOnlyCert.pem ecc-privOnlyKey.pem ecc-privkey.der ecc-privkey.pem ecc-privkeyPkcs8.der ecc-privkeyPkcs8.pem ecc-rsa-server.p12 empty-issuer-cert.pem entity-no-ca-bool-cert.pem entity-no-ca-bool-key.pem fpki-cert.der fpki-certpol-cert.der gen_revoked.sh include.am renewcerts.sh rid-cert.der rsa-pub-2048.pem rsa2048.der rsa3072.der server-cert-chain.der server-cert.der server-cert.pem server-ecc-comp.der server-ecc-comp.pem server-ecc-rsa.der server-ecc-rsa.pem server-ecc-self.der server-ecc-self.pem server-ecc.der server-ecc.pem server-ecc384-cert.der server-ecc384-cert.pem server-ecc384-key.der server-ecc384-key.pem server-key.der server-key.pem server-keyEnc.pem server-keyPkcs8.der server-keyPkcs8.pem server-keyPkcs8Enc.der server-keyPkcs8Enc.pem server-keyPkcs8Enc12.pem server-keyPkcs8Enc2.pem server-keyPub.der server-keyPub.pem server-revoked-cert.pem server-revoked-key.pem taoCert.txt test-ber-exp02-05-2022.p7b test-degenerate.p7b test-multiple-recipients.p7b test-servercert-rc2.p12 test-servercert.p12 test-stream-dec.p7b test-stream-sign.p7b wolfssl-website-ca.pem x942dh2048.der x942dh2048.pem
cmake
consumer CMakeLists.txt README.md main.c
modules FindARIA.cmake FindOQS.cmake
Config.cmake.in README.md config.in functions.cmake include.am options.h.in wolfssl-config-version.cmake.in wolfssl-targets.cmake.in
debian
source format
changelog.in control.in copyright include.am libwolfssl-dev.install libwolfssl.install rules.in
doc
dox_comments
header_files aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h puf.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wc_she.h wc_slhdsa.h wolfio.h
header_files-ja aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wolfio.h
formats
html
html_changes
search search.css search.js
customdoxygen.css doxygen.css menu.js menudata.js tabs.css
Doxyfile footer.html header.html mainpage.dox
pdf Doxyfile header.tex
images wolfssl_logo.png
QUIC.md README.txt README_DOXYGEN check_api.sh generate_documentation.sh include.am
examples
asn1 asn1.c dumpasn1.cfg gen_oid_names.rb include.am oid_names.h
async Makefile README.md async_client.c async_server.c async_tls.c async_tls.h include.am user_settings.h
benchmark include.am tls_bench.c tls_bench.h
client client.c client.h client.sln client.vcproj client.vcxproj include.am
configs README.md include.am user_settings_EBSnet.h user_settings_all.h user_settings_arduino.h user_settings_baremetal.h user_settings_ca.h user_settings_curve25519nonblock.h user_settings_dtls13.h user_settings_eccnonblock.h user_settings_espressif.h user_settings_fipsv2.h user_settings_fipsv5.h user_settings_min_ecc.h user_settings_openssl_compat.h user_settings_pkcs7.h user_settings_platformio.h user_settings_pq.h user_settings_rsa_only.h user_settings_stm32.h user_settings_template.h user_settings_tls12.h user_settings_tls13.h user_settings_wolfboot_keytools.h user_settings_wolfssh.h user_settings_wolftpm.h
crypto_policies
default wolfssl.txt
future wolfssl.txt
legacy wolfssl.txt
echoclient echoclient.c echoclient.h echoclient.sln echoclient.vcproj echoclient.vcxproj include.am quit
echoserver echoserver.c echoserver.h echoserver.sln echoserver.vcproj echoserver.vcxproj include.am
ocsp_responder include.am ocsp_responder.c ocsp_responder.h
pem include.am pem.c
sctp include.am sctp-client-dtls.c sctp-client.c sctp-server-dtls.c sctp-server.c
server include.am server.c server.h server.sln server.vcproj server.vcxproj
README.md include.am
linuxkm
patches
5.10.17 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v10v17.patch
5.10.236 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v10v236.patch
5.14.0-570.58.1.el9_6 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v14-570v58v1-el9_6.patch
5.15 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v15.patch
5.17 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v17.patch
5.17-ubuntu-jammy-tegra WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v17-ubuntu-jammy-tegra.patch
6.1.73 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v1v73.patch
6.12 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v12.patch
6.15 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v15.patch
7.0 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-7v0.patch
regen-patches.sh
Kbuild Makefile README.md get_thread_size.c include.am linuxkm-fips-hash-wrapper.sh linuxkm-fips-hash.c linuxkm_memory.c linuxkm_memory.h linuxkm_wc_port.h lkcapi_aes_glue.c lkcapi_dh_glue.c lkcapi_ecdh_glue.c lkcapi_ecdsa_glue.c lkcapi_glue.c lkcapi_rsa_glue.c lkcapi_sha_glue.c module_exports.c.template module_hooks.c pie_redirect_table.c wolfcrypt.lds x86_vector_register_glue.c
m4 ax_add_am_macro.m4 ax_am_jobserver.m4 ax_am_macros.m4 ax_append_compile_flags.m4 ax_append_flag.m4 ax_append_link_flags.m4 ax_append_to_file.m4 ax_atomic.m4 ax_bsdkm.m4 ax_check_compile_flag.m4 ax_check_link_flag.m4 ax_compiler_version.m4 ax_count_cpus.m4 ax_create_generic_config.m4 ax_debug.m4 ax_file_escapes.m4 ax_harden_compiler_flags.m4 ax_linuxkm.m4 ax_print_to_file.m4 ax_pthread.m4 ax_require_defined.m4 ax_tls.m4 ax_vcs_checkout.m4 hexversion.m4 lib_socket_nsl.m4 visibility.m4
mcapi
wolfcrypt_mcapi.X
nbproject configurations.xml include.am project.xml
Makefile
wolfcrypt_test.X
nbproject configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
zlib.X
nbproject configurations.xml include.am project.xml
Makefile
PIC32MZ-serial.h README crypto.c crypto.h include.am mcapi_test.c user_settings.h
mplabx
wolfcrypt_benchmark.X
nbproject configurations.xml include.am project.xml
Makefile
wolfcrypt_test.X
nbproject configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
PIC32MZ-serial.h README benchmark_main.c include.am test_main.c user_settings.h
mqx
util_lib
Sources include.am util.c util.h
wolfcrypt_benchmark
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
ReferencedRSESystems.xml wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch
wolfcrypt_test
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
ReferencedRSESystems.xml wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch
wolfssl include.am
wolfssl_client
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
ReferencedRSESystems.xml wolfssl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch
README
rpm include.am spec.in
scripts
bench bench_functions.sh
aria-cmake-build-test.sh asn1_oid_sum.pl benchmark.test benchmark_compare.sh cleanup_testfiles.sh crl-gen-openssl.test crl-revoked.test dertoc.pl dtls.test dtlscid.test external.test google.test include.am makedistsmall.sh memtest.sh ocsp-responder-openssl-interop.test ocsp-stapling-with-ca-as-responder.test ocsp-stapling-with-wolfssl-responder.test ocsp-stapling.test ocsp-stapling2.test ocsp-stapling_tls13multi.test ocsp.test openssl.test openssl_srtp.test pem.test ping.test pkcallbacks.test psk.test resume.test rsapss.test sniffer-gen.sh sniffer-ipv6.pcap sniffer-static-rsa.pcap sniffer-testsuite.test sniffer-tls12-keylog.out sniffer-tls12-keylog.pcap sniffer-tls12-keylog.sslkeylog sniffer-tls13-dh-resume.pcap sniffer-tls13-dh.pcap sniffer-tls13-ecc-resume.pcap sniffer-tls13-ecc.pcap sniffer-tls13-hrr.pcap sniffer-tls13-keylog.out sniffer-tls13-keylog.pcap sniffer-tls13-keylog.sslkeylog sniffer-tls13-x25519-resume.pcap sniffer-tls13-x25519.pcap stm32l4-v4_0_1_build.sh tls13.test trusted_peer.test unit.test.in user_settings_asm.sh
src bio.c conf.c crl.c dtls.c dtls13.c include.am internal.c keys.c ocsp.c pk.c pk_ec.c pk_rsa.c quic.c sniffer.c ssl.c ssl_api_cert.c ssl_api_crl_ocsp.c ssl_api_pk.c ssl_asn1.c ssl_bn.c ssl_certman.c ssl_crypto.c ssl_ech.c ssl_load.c ssl_misc.c ssl_p7p12.c ssl_sess.c ssl_sk.c tls.c tls13.c wolfio.c x509.c x509_str.c
sslSniffer
sslSnifferTest README_WIN.md include.am snifftest.c sslSniffTest.vcproj sslSniffTest.vcxproj
README.md sslSniffer.vcproj sslSniffer.vcxproj
support gen-debug-trace-error-codes.sh include.am wolfssl.pc.in
tests
api api.h api_decl.h create_ocsp_test_blobs.py include.am test_aes.c test_aes.h test_arc4.c test_arc4.h test_ascon.c test_ascon.h test_ascon_kats.h test_asn.c test_asn.h test_blake2.c test_blake2.h test_camellia.c test_camellia.h test_certman.c test_certman.h test_chacha.c test_chacha.h test_chacha20_poly1305.c test_chacha20_poly1305.h test_cmac.c test_cmac.h test_curve25519.c test_curve25519.h test_curve448.c test_curve448.h test_des3.c test_des3.h test_dh.c test_dh.h test_digest.h test_dsa.c test_dsa.h test_dtls.c test_dtls.h test_ecc.c test_ecc.h test_ed25519.c test_ed25519.h test_ed448.c test_ed448.h test_evp.c test_evp.h test_evp_cipher.c test_evp_cipher.h test_evp_digest.c test_evp_digest.h test_evp_pkey.c test_evp_pkey.h test_hash.c test_hash.h test_hmac.c test_hmac.h test_md2.c test_md2.h test_md4.c test_md4.h test_md5.c test_md5.h test_mldsa.c test_mldsa.h test_mlkem.c test_mlkem.h test_ocsp.c test_ocsp.h test_ocsp_test_blobs.h test_ossl_asn1.c test_ossl_asn1.h test_ossl_bio.c test_ossl_bio.h test_ossl_bn.c test_ossl_bn.h test_ossl_cipher.c test_ossl_cipher.h test_ossl_dgst.c test_ossl_dgst.h test_ossl_dh.c test_ossl_dh.h test_ossl_dsa.c test_ossl_dsa.h test_ossl_ec.c test_ossl_ec.h test_ossl_ecx.c test_ossl_ecx.h test_ossl_mac.c test_ossl_mac.h test_ossl_obj.c test_ossl_obj.h test_ossl_p7p12.c test_ossl_p7p12.h test_ossl_pem.c test_ossl_pem.h test_ossl_rand.c test_ossl_rand.h test_ossl_rsa.c test_ossl_rsa.h test_ossl_sk.c test_ossl_sk.h test_ossl_x509.c test_ossl_x509.h test_ossl_x509_acert.c test_ossl_x509_acert.h test_ossl_x509_crypto.c test_ossl_x509_crypto.h test_ossl_x509_ext.c test_ossl_x509_ext.h test_ossl_x509_info.c test_ossl_x509_info.h test_ossl_x509_io.c test_ossl_x509_io.h test_ossl_x509_lu.c test_ossl_x509_lu.h test_ossl_x509_name.c test_ossl_x509_name.h test_ossl_x509_pk.c test_ossl_x509_pk.h test_ossl_x509_str.c test_ossl_x509_str.h test_ossl_x509_vp.c test_ossl_x509_vp.h test_pkcs12.c test_pkcs12.h test_pkcs7.c test_pkcs7.h test_poly1305.c test_poly1305.h test_random.c test_random.h test_rc2.c test_rc2.h test_ripemd.c test_ripemd.h test_rsa.c test_rsa.h test_sha.c test_sha.h test_sha256.c test_sha256.h test_sha3.c test_sha3.h test_sha512.c test_sha512.h test_she.c test_she.h test_signature.c test_signature.h test_slhdsa.c test_slhdsa.h test_sm2.c test_sm2.h test_sm3.c test_sm3.h test_sm4.c test_sm4.h test_tls.c test_tls.h test_tls13.c test_tls13.h test_tls_ext.c test_tls_ext.h test_wc_encrypt.c test_wc_encrypt.h test_wolfmath.c test_wolfmath.h test_x509.c test_x509.h
emnet
IP IP.h
Makefile emnet_nonblock_test.c emnet_shim.c
freertos-mem-track-repro FreeRTOS.h repro.c run.sh semphr.h task.h user_settings.h
swdev .gitignore Makefile README.md swdev.c swdev.h swdev_loader.c swdev_loader.h user_settings.h
CONF_FILES_README.md NCONF_test.cnf README TXT_DB.txt api.c include.am quic.c srp.c suites.c test-altchains.conf test-chains.conf test-dhprime.conf test-dtls-downgrade.conf test-dtls-fails-cipher.conf test-dtls-fails.conf test-dtls-group.conf test-dtls-mtu.conf test-dtls-reneg-client.conf test-dtls-reneg-server.conf test-dtls-resume.conf test-dtls-sha2.conf test-dtls-srtp-fails.conf test-dtls-srtp.conf test-dtls.conf test-dtls13-cid.conf test-dtls13-downgrade-fails.conf test-dtls13-downgrade.conf test-dtls13-pq-hybrid-extra-frag.conf test-dtls13-pq-hybrid-extra.conf test-dtls13-pq-hybrid-frag.conf test-dtls13-pq-standalone-frag.conf test-dtls13-pq-standalone.conf test-dtls13-psk.conf test-dtls13.conf test-ecc-cust-curves.conf test-ed25519.conf test-ed448.conf test-enckeys.conf test-fails.conf test-maxfrag-dtls.conf test-maxfrag.conf test-p521.conf test-psk-no-id-sha2.conf test-psk-no-id.conf test-psk.conf test-rsapss.conf test-sctp-sha2.conf test-sctp.conf test-sha2.conf test-sig.conf test-sm2.conf test-tls-downgrade.conf test-tls13-down.conf test-tls13-ecc.conf test-tls13-pq-hybrid-extra.conf test-tls13-pq-hybrid.conf test-tls13-pq-standalone.conf test-tls13-psk-certs.conf test-tls13-psk.conf test-tls13-slhdsa-fail.conf test-tls13-slhdsa-sha2.conf test-tls13-slhdsa-shake.conf test-tls13.conf test-trustpeer.conf test.conf unit.c unit.h utils.c utils.h w64wrapper.c
testsuite include.am testsuite.c testsuite.sln testsuite.vcproj testsuite.vcxproj utils.c utils.h
tirtos
packages
ti
net
wolfssl
tests
EK_TM4C1294XL
wolfcrypt
benchmark TM4C1294NC.icf benchmark.cfg main.c package.bld.hide package.xdc
test TM4C1294NC.icf main.c package.bld.hide package.xdc test.cfg
package.bld package.xdc package.xs
.gitignore README include.am products.mak wolfssl.bld wolfssl.mak
wolfcrypt
benchmark README.md benchmark-VS2022.sln benchmark-VS2022.vcxproj benchmark-VS2022.vcxproj.user benchmark.c benchmark.h benchmark.sln benchmark.vcproj benchmark.vcxproj include.am
src
port
Espressif
esp_crt_bundle README.md cacrt_all.pem cacrt_deprecated.pem cacrt_local.pem esp_crt_bundle.c gen_crt_bundle.py pio_install_cryptography.py
README.md esp32_aes.c esp32_mp.c esp32_sha.c esp32_util.c esp_sdk_mem_lib.c esp_sdk_time_lib.c esp_sdk_wifi_lib.c
Renesas README.md renesas_common.c renesas_fspsm_aes.c renesas_fspsm_rsa.c renesas_fspsm_sha.c renesas_fspsm_util.c renesas_rx64_hw_sha.c renesas_rx64_hw_util.c renesas_tsip_aes.c renesas_tsip_rsa.c renesas_tsip_sha.c renesas_tsip_util.c
af_alg afalg_aes.c afalg_hash.c wc_afalg.c
aria aria-crypt.c aria-cryptocb.c
arm armv8-32-aes-asm.S armv8-32-aes-asm_c.c armv8-32-chacha-asm.S armv8-32-chacha-asm_c.c armv8-32-curve25519.S armv8-32-curve25519_c.c armv8-32-mlkem-asm.S armv8-32-mlkem-asm_c.c armv8-32-poly1305-asm.S armv8-32-poly1305-asm_c.c armv8-32-sha256-asm.S armv8-32-sha256-asm_c.c armv8-32-sha3-asm.S armv8-32-sha3-asm_c.c armv8-32-sha512-asm.S armv8-32-sha512-asm_c.c armv8-aes-asm.S armv8-aes-asm_c.c armv8-aes.c armv8-chacha-asm.S armv8-chacha-asm_c.c armv8-curve25519.S armv8-curve25519_c.c armv8-mlkem-asm.S armv8-mlkem-asm_c.c armv8-poly1305-asm.S armv8-poly1305-asm_c.c armv8-sha256-asm.S armv8-sha256-asm_c.c armv8-sha256.c armv8-sha3-asm.S armv8-sha3-asm_c.c armv8-sha512-asm.S armv8-sha512-asm_c.c armv8-sha512.c cryptoCell.c cryptoCellHash.c thumb2-aes-asm.S thumb2-aes-asm_c.c thumb2-chacha-asm.S thumb2-chacha-asm_c.c thumb2-curve25519.S thumb2-curve25519_c.c thumb2-mlkem-asm.S thumb2-mlkem-asm_c.c thumb2-poly1305-asm.S thumb2-poly1305-asm_c.c thumb2-sha256-asm.S thumb2-sha256-asm_c.c thumb2-sha3-asm.S thumb2-sha3-asm_c.c thumb2-sha512-asm.S thumb2-sha512-asm_c.c
atmel README.md atmel.c
autosar README.md cryif.c crypto.c csm.c include.am test.c
caam README.md caam_aes.c caam_doc.pdf caam_driver.c caam_error.c caam_integrity.c caam_qnx.c caam_sha.c wolfcaam_aes.c wolfcaam_cmac.c wolfcaam_ecdsa.c wolfcaam_fsl_nxp.c wolfcaam_hash.c wolfcaam_hmac.c wolfcaam_init.c wolfcaam_qnx.c wolfcaam_rsa.c wolfcaam_seco.c wolfcaam_x25519.c
cavium README.md README_Octeon.md cavium_nitrox.c cavium_octeon_sync.c
cuda README.md aes-cuda.cu
cypress README.md psoc6_crypto.c
devcrypto README.md devcrypto_aes.c devcrypto_ecdsa.c devcrypto_hash.c devcrypto_hmac.c devcrypto_rsa.c devcrypto_x25519.c wc_devcrypto.c
intel README.md quickassist.c quickassist_mem.c quickassist_sync.c
iotsafe iotsafe.c
kcapi README.md kcapi_aes.c kcapi_dh.c kcapi_ecc.c kcapi_hash.c kcapi_hmac.c kcapi_rsa.c
liboqs liboqs.c
maxim README.md max3266x.c maxq10xx.c
mynewt mynewt_port.c
nxp README.md README_SE050.md casper_port.c dcp_port.c hashcrypt_port.c ksdk_port.c se050_port.c
pic32 pic32mz-crypt.c
ppc32 ppc32-sha256-asm.S ppc32-sha256-asm_c.c ppc32-sha256-asm_cr.c
psa README.md psa.c psa_aes.c psa_hash.c psa_pkcbs.c
riscv riscv-64-aes.c riscv-64-chacha.c riscv-64-poly1305.c riscv-64-sha256.c riscv-64-sha3.c riscv-64-sha512.c
rpi_pico README.md pico.c
silabs README.md silabs_aes.c silabs_ecc.c silabs_hash.c silabs_random.c
st README.md STM32MP13.md STM32MP25.md stm32.c stsafe.c
ti ti-aes.c ti-ccm.c ti-des3.c ti-hash.c
tropicsquare README.md tropic01.c
xilinx xil-aesgcm.c xil-sha3.c xil-versal-glue.c xil-versal-trng.c
nrf51.c
ASN_TEMPLATE.md aes.c aes_asm.S aes_asm.asm aes_gcm_asm.S aes_gcm_asm.asm aes_gcm_x86_asm.S aes_xts_asm.S aes_xts_asm.asm arc4.c ascon.c asm.c asn.c asn_orig.c async.c blake2b.c blake2s.c camellia.c chacha.c chacha20_poly1305.c chacha_asm.S chacha_asm.asm cmac.c coding.c compress.c cpuid.c cryptocb.c curve25519.c curve448.c des3.c dh.c dilithium.c dsa.c ecc.c ecc_fp.c eccsi.c ed25519.c ed448.c error.c evp.c evp_pk.c falcon.c fe_448.c fe_low_mem.c fe_operations.c fe_x25519_128.h fe_x25519_asm.S fp_mont_small.i fp_mul_comba_12.i fp_mul_comba_17.i fp_mul_comba_20.i fp_mul_comba_24.i fp_mul_comba_28.i fp_mul_comba_3.i fp_mul_comba_32.i fp_mul_comba_4.i fp_mul_comba_48.i fp_mul_comba_6.i fp_mul_comba_64.i fp_mul_comba_7.i fp_mul_comba_8.i fp_mul_comba_9.i fp_mul_comba_small_set.i fp_sqr_comba_12.i fp_sqr_comba_17.i fp_sqr_comba_20.i fp_sqr_comba_24.i fp_sqr_comba_28.i fp_sqr_comba_3.i fp_sqr_comba_32.i fp_sqr_comba_4.i fp_sqr_comba_48.i fp_sqr_comba_6.i fp_sqr_comba_64.i fp_sqr_comba_7.i fp_sqr_comba_8.i fp_sqr_comba_9.i fp_sqr_comba_small_set.i ge_448.c ge_low_mem.c ge_operations.c hash.c hmac.c hpke.c include.am integer.c kdf.c logging.c md2.c md4.c md5.c memory.c misc.c pkcs12.c pkcs7.c poly1305.c poly1305_asm.S poly1305_asm.asm puf.c pwdbased.c random.c rc2.c ripemd.c rng_bank.c rsa.c sakke.c sha.c sha256.c sha256_asm.S sha3.c sha3_asm.S sha512.c sha512_asm.S signature.c siphash.c sm2.c sm3.c sm3_asm.S sm4.c sp_arm32.c sp_arm64.c sp_armthumb.c sp_c32.c sp_c64.c sp_cortexm.c sp_dsp32.c sp_int.c sp_sm2_arm32.c sp_sm2_arm64.c sp_sm2_armthumb.c sp_sm2_c32.c sp_sm2_c64.c sp_sm2_cortexm.c sp_sm2_x86_64.c sp_sm2_x86_64_asm.S sp_x86_64.c sp_x86_64_asm.S sp_x86_64_asm.asm srp.c tfm.c wc_dsp.c wc_encrypt.c wc_lms.c wc_lms_impl.c wc_mldsa_asm.S wc_mlkem.c wc_mlkem_asm.S wc_mlkem_poly.c wc_pkcs11.c wc_port.c wc_she.c wc_slhdsa.c wc_xmss.c wc_xmss_impl.c wolfentropy.c wolfevent.c wolfmath.c
test README.md include.am test-VS2022.sln test-VS2022.vcxproj test-VS2022.vcxproj.user test.c test.h test.sln test.vcproj test_paths.h.in
wolfssl
openssl aes.h asn1.h asn1t.h bio.h bn.h buffer.h camellia.h cmac.h cms.h compat_types.h conf.h crypto.h des.h dh.h dsa.h ec.h ec25519.h ec448.h ecdh.h ecdsa.h ed25519.h ed448.h engine.h err.h evp.h fips_rand.h hmac.h include.am kdf.h lhash.h md4.h md5.h modes.h obj_mac.h objects.h ocsp.h opensslconf.h opensslv.h ossl_typ.h pem.h pkcs12.h pkcs7.h rand.h rc4.h ripemd.h rsa.h safestack.h sha.h sha3.h srp.h ssl.h ssl23.h stack.h tls1.h txt_db.h ui.h x509.h x509_vfy.h x509v3.h
wolfcrypt
port
Espressif esp-sdk-lib.h esp32-crypt.h esp_crt_bundle.h
Renesas renesas-fspsm-crypt.h renesas-fspsm-types.h renesas-rx64-hw-crypt.h renesas-tsip-crypt.h renesas_cmn.h renesas_fspsm_internal.h renesas_sync.h renesas_tsip_internal.h renesas_tsip_types.h
af_alg afalg_hash.h wc_afalg.h
aria aria-crypt.h aria-cryptocb.h
arm cryptoCell.h
atmel atmel.h
autosar CryIf.h Crypto.h Csm.h StandardTypes.h
caam caam_driver.h caam_error.h caam_qnx.h wolfcaam.h wolfcaam_aes.h wolfcaam_cmac.h wolfcaam_ecdsa.h wolfcaam_fsl_nxp.h wolfcaam_hash.h wolfcaam_qnx.h wolfcaam_rsa.h wolfcaam_seco.h wolfcaam_sha.h wolfcaam_x25519.h
cavium cavium_nitrox.h cavium_octeon_sync.h
cypress psoc6_crypto.h
devcrypto wc_devcrypto.h
intel quickassist.h quickassist_mem.h quickassist_sync.h
iotsafe iotsafe.h
kcapi kcapi_dh.h kcapi_ecc.h kcapi_hash.h kcapi_hmac.h kcapi_rsa.h wc_kcapi.h
liboqs liboqs.h
maxim max3266x-cryptocb.h max3266x.h maxq10xx.h
nxp casper_port.h dcp_port.h hashcrypt_port.h ksdk_port.h se050_port.h
pic32 pic32mz-crypt.h
psa psa.h
riscv riscv-64-asm.h
rpi_pico pico.h
silabs silabs_aes.h silabs_ecc.h silabs_hash.h silabs_random.h
st stm32.h stsafe.h
ti ti-ccm.h ti-hash.h
tropicsquare tropic01.h
xilinx xil-sha3.h xil-versal-glue.h xil-versal-trng.h
nrf51.h
aes.h arc4.h ascon.h asn.h asn_public.h async.h blake2-impl.h blake2-int.h blake2.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cpuid.h cryptocb.h curve25519.h curve448.h des3.h dh.h dilithium.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h falcon.h fe_448.h fe_operations.h fips_test.h ge_448.h ge_operations.h hash.h hmac.h hpke.h include.am integer.h kdf.h libwolfssl_sources.h libwolfssl_sources_asm.h logging.h md2.h md4.h md5.h mem_track.h memory.h misc.h mpi_class.h mpi_superclass.h oid_sum.h pkcs11.h pkcs12.h pkcs7.h poly1305.h puf.h pwdbased.h random.h rc2.h ripemd.h rng_bank.h rsa.h sakke.h selftest.h settings.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h sm2.h sm3.h sm4.h sp.h sp_int.h srp.h tfm.h types.h visibility.h wc_encrypt.h wc_lms.h wc_mlkem.h wc_pkcs11.h wc_port.h wc_she.h wc_slhdsa.h wc_xmss.h wolfentropy.h wolfevent.h wolfmath.h
callbacks.h certs_test.h certs_test_sm.h crl.h error-ssl.h include.am internal.h ocsp.h options.h.in quic.h sniffer.h sniffer_error.h sniffer_error.rc ssl.h test.h version.h version.h.in wolfio.h
wrapper
Ada
examples
src aes_verify_main.adb rsa_verify_main.adb sha256_main.adb spark_sockets.adb spark_sockets.ads spark_terminal.adb spark_terminal.ads tls_client.adb tls_client.ads tls_client_main.adb tls_server.adb tls_server.ads tls_server_main.adb
.gitignore alire.toml examples.gpr
tests
src
support test_support.adb test_support.ads tests_root_suite.adb tests_root_suite.ads
aes_bindings_tests.adb aes_bindings_tests.ads rsa_verify_bindings_tests.adb rsa_verify_bindings_tests.ads sha256_bindings_tests.adb sha256_bindings_tests.ads tests.adb
.gitignore README.md alire.toml tests.gpr valgrind.supp
.gitignore README.md ada_binding.c alire.toml default.gpr include.am restricted.adc user_settings.h wolfssl-full_runtime.adb wolfssl-full_runtime.ads wolfssl.adb wolfssl.ads wolfssl.gpr
CSharp
wolfCrypt-Test
Properties AssemblyInfo.cs
App.config wolfCrypt-Test.cs wolfCrypt-Test.csproj
wolfSSL-DTLS-PSK-Server
Properties AssemblyInfo.cs
App.config wolfSSL-DTLS-PSK-Server.cs wolfSSL-DTLS-PSK-Server.csproj
wolfSSL-DTLS-Server
Properties AssemblyInfo.cs
App.config wolfSSL-DTLS-Server.cs wolfSSL-DTLS-Server.csproj
wolfSSL-Example-IOCallbacks
Properties AssemblyInfo.cs
App.config wolfSSL-Example-IOCallbacks.cs wolfSSL-Example-IOCallbacks.csproj
wolfSSL-TLS-Client
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-Client.cs wolfSSL-TLS-Client.csproj
wolfSSL-TLS-PSK-Client
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-PSK-Client.cs wolfSSL-TLS-PSK-Client.csproj
wolfSSL-TLS-PSK-Server
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-PSK-Server.cs wolfSSL-TLS-PSK-Server.csproj
wolfSSL-TLS-Server
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-Server.cs wolfSSL-TLS-Server.csproj
wolfSSL-TLS-ServerThreaded
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-ServerThreaded.cs wolfSSL-TLS-ServerThreaded.csproj
wolfSSL_CSharp
Properties AssemblyInfo.cs Resources.Designer.cs Resources.resx
X509.cs wolfCrypt.cs wolfSSL.cs wolfSSL_CSharp.csproj
README.md include.am user_settings.h wolfSSL_CSharp.sln wolfssl.vcxproj
python README.md
rust
wolfssl-wolfcrypt
src aes.rs blake2.rs chacha20_poly1305.rs cmac.rs cmac_mac.rs curve25519.rs dh.rs dilithium.rs ecc.rs ecdsa.rs ed25519.rs ed448.rs fips.rs hkdf.rs hmac.rs hmac_mac.rs kdf.rs lib.rs lms.rs mlkem.rs mlkem_kem.rs pbkdf2_password_hash.rs prf.rs random.rs rsa.rs rsa_pkcs1v15.rs sha.rs sha_digest.rs sys.rs
tests
common mod.rs
test_aes.rs test_blake2.rs test_chacha20_poly1305.rs test_cmac.rs test_cmac_mac.rs test_curve25519.rs test_dh.rs test_dilithium.rs test_ecc.rs test_ecdsa.rs test_ed25519.rs test_ed448.rs test_hkdf.rs test_hmac.rs test_hmac_mac.rs test_kdf.rs test_lms.rs test_mlkem.rs test_mlkem_kem.rs test_pbkdf2_password_hash.rs test_prf.rs test_random.rs test_rsa.rs test_rsa_pkcs1v15.rs test_sha.rs test_sha_digest.rs test_wolfcrypt.rs
CHANGELOG.md Cargo.lock Cargo.toml Makefile README.md build.rs headers.h
Makefile README.md include.am
include.am
zephyr
samples
wolfssl_benchmark
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
CMakeLists.txt README install_test.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_test
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
CMakeLists.txt README install_test.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_tls_sock
boards native_sim.conf
src tls_sock.c
CMakeLists.txt README install_sample.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_tls_thread
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
src tls_threaded.c
CMakeLists.txt README install_sample.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl options.h
CMakeLists.txt Kconfig Kconfig.tls-generic README.md include.am module.yml user_settings-no-malloc.h user_settings.h zephyr_init.c
.codespellexcludelines .cyignore .editorconfig .gitignore .wolfssl_known_macro_extras AUTHORS CMakeLists.txt CMakePresets.json CMakeSettings.json COPYING ChangeLog.md INSTALL LICENSING LPCExpresso.cproject LPCExpresso.project Makefile.am README README-async.md README.md SCRIPTS-LIST SECURITY-POLICY.md SECURITY-REPORT-TEMPLATE.md Vagrantfile autogen.sh commit-tests.sh configure.ac fips-check.sh fips-hash.sh gencertbuf.pl input pull_to_vagrant.sh quit resource.h stamp-h.in valgrind-bash.supp valgrind-error.sh wnr-example.conf wolfssl-VS2022.vcxproj wolfssl.rc wolfssl.vcproj wolfssl.vcxproj wolfssl64.sln
.clangd .gitignore DOCS.md Makefile README.md assert.c core.c crypto.c env.c fs.c http.c ini.c json.c log.c luna.h main.c makext.mk path.c process.c request.c sqlite.c stash.c template.c util.c
wolfssl/src/ssl_load.c raw
   1/* ssl_load.c
   2 *
   3 * Copyright (C) 2006-2026 wolfSSL Inc.
   4 *
   5 * This file is part of wolfSSL.
   6 *
   7 * wolfSSL is free software; you can redistribute it and/or modify
   8 * it under the terms of the GNU General Public License as published by
   9 * the Free Software Foundation; either version 3 of the License, or
  10 * (at your option) any later version.
  11 *
  12 * wolfSSL is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 * GNU General Public License for more details.
  16 *
  17 * You should have received a copy of the GNU General Public License
  18 * along with this program; if not, write to the Free Software
  19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20 */
  21
  22#include <wolfssl/wolfcrypt/libwolfssl_sources.h>
  23
  24/*
  25 * WOLFSSL_SYS_CA_CERTS
  26 *     Enables ability to load system CA certs from the OS via
  27 *     wolfSSL_CTX_load_system_CA_certs.
  28 */
  29
  30#ifdef WOLFSSL_SYS_CA_CERTS
  31/* Will be turned off automatically when NO_FILESYSTEM is defined
  32 * for non Mac/Windows systems */
  33
  34#ifdef _WIN32
  35    #define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
  36    #include <windows.h>
  37    #include <wincrypt.h>
  38    #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
  39
  40    /* mingw gcc does not support pragma comment, and the
  41     * linking with crypt32 is handled in configure.ac */
  42    #if !defined(__MINGW32__) && !defined(__MINGW64__)
  43        #pragma comment(lib, "crypt32")
  44    #endif
  45#endif
  46
  47#if defined(__APPLE__)
  48#if defined(HAVE_SECURITY_SECTRUSTSETTINGS_H)
  49#include <Security/SecTrustSettings.h>
  50#endif /* HAVE_SECURITY_SECTRUSTSETTINGS_H */
  51#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
  52#include <CoreFoundation/CoreFoundation.h>
  53#endif /* WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION */
  54#endif /* __APPLE__ */
  55
  56#endif /* WOLFSSL_SYS_CA_CERTS */
  57
  58#if !defined(WOLFSSL_SSL_LOAD_INCLUDED)
  59    #ifndef WOLFSSL_IGNORE_FILE_WARN
  60        #warning ssl_load.c does not need to be compiled separately from ssl.c
  61    #endif
  62#else
  63
  64#include <wolfssl/wolfcrypt/logging.h>
  65
  66#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  67    /* PSK field of context when it exists. */
  68    #define CTX_HAVE_PSK(ctx)   (ctx)->havePSK
  69    /* PSK field of ssl when it exists. */
  70    #define SSL_HAVE_PSK(ssl)   (ssl)->options.havePSK
  71#else
  72    /* Have PSK value when no field. */
  73    #define CTX_HAVE_PSK(ctx)   0
  74    /* Have PSK value when no field. */
  75    #define SSL_HAVE_PSK(ssl)   0
  76#endif
  77#ifdef NO_RSA
  78    /* Boolean for RSA available. */
  79    #define WOLFSSL_HAVE_RSA    0
  80#else
  81    /* Boolean for RSA available. */
  82    #define WOLFSSL_HAVE_RSA    1
  83#endif
  84#ifndef NO_CERTS
  85    /* Private key size from ssl. */
  86    #define SSL_KEY_SZ(ssl)     (ssl)->buffers.keySz
  87#else
  88    /* Private key size not available. */
  89    #define SSL_KEY_SZ(ssl)     0
  90#endif
  91#ifdef HAVE_ANON
  92    /* Anonymous ciphersuite allowed field in context. */
  93    #define CTX_USE_ANON(ctx)   (ctx)->useAnon
  94#else
  95    /* Anonymous ciphersuite allowed field not in context. */
  96    #define CTX_USE_ANON(ctx)   0
  97#endif
  98
  99#ifdef HAVE_PK_CALLBACKS
 100    #define WOLFSSL_IS_PRIV_PK_SET(ctx, ssl)                            \
 101        wolfSSL_CTX_IsPrivatePkSet(((ssl) == NULL) ? (ctx) : (ssl)->ctx)
 102#else
 103    #define WOLFSSL_IS_PRIV_PK_SET(ctx, ssl)    0
 104#endif
 105
 106/* Get the heap from the context or the ssl depending on which is available. */
 107#define WOLFSSL_HEAP(ctx, ssl)                                              \
 108    (((ctx) != NULL) ? (ctx)->heap : (((ssl) != NULL) ? (ssl)->heap : NULL))
 109
 110
 111#ifndef NO_CERTS
 112
 113/* Get DER encoding from data in a buffer as a DerBuffer.
 114 *
 115 * @param [in]      buff    Buffer containing data.
 116 * @param [in]      len     Length of data in buffer.
 117 * @param [in]      format  Format of data:
 118 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
 119 * @param [in]      type    Type of data:
 120 *                            CERT_TYPE, CA_TYPE, TRUSTED_PEER_TYPE,
 121 *                            PRIVATEKEY_TYPE or ALT_PRIVATEKEY_TYPE.
 122 * @param [in, out] info    Info for encryption.
 123 * @param [in]      heap    Dynamic memory allocation hint.
 124 * @param [out]     der     Holds DER encoded data.
 125 * @param [out]     algId   Algorithm identifier for private keys.
 126 * @return  0 on success.
 127 * @return  NOT_COMPILED_IN when format is PEM and PEM not supported.
 128 * @return  ASN_PARSE_E when format is ASN.1 and invalid DER encoding.
 129 * @return  MEMORY_E when dynamic memory allocation fails.
 130 */
 131static int DataToDerBuffer(const unsigned char* buff, word32 len, int format,
 132    int type, EncryptedInfo* info, void* heap, DerBuffer** der, int* algId)
 133{
 134    int ret;
 135
 136    info->consumed = 0;
 137
 138    /* Data in buffer has PEM format - extract DER data. */
 139    if (format == WOLFSSL_FILETYPE_PEM) {
 140    #ifdef WOLFSSL_PEM_TO_DER
 141        ret = PemToDer(buff, (long)(len), type, der, heap, info, algId);
 142        if (ret != 0) {
 143            FreeDer(der);
 144        }
 145    #else
 146        (void)algId;
 147        ret = NOT_COMPILED_IN;
 148    #endif
 149    }
 150    /* Data in buffer is ASN.1 format - get first SEQ or OCT into der. */
 151    else {
 152        /* Get length of SEQ including header. */
 153        if ((info->consumed = wolfssl_der_length(buff, (int)len)) > 0) {
 154            ret = 0;
 155        }
 156        else {
 157            ret = ASN_PARSE_E;
 158        }
 159
 160        if (info->consumed > (int)len) {
 161            ret = ASN_PARSE_E;
 162        }
 163        if (ret == 0) {
 164            ret = AllocCopyDer(der, buff, (word32)info->consumed, type, heap);
 165        }
 166    }
 167
 168    return ret;
 169}
 170
 171/* Process a user's certificate.
 172 *
 173 * Puts the 3-byte length before certificate data as required for TLS.
 174 * CA certificates are added to the certificate manager.
 175 *
 176 * @param [in]      cm           Certificate manager.
 177 * @param [in, out] pDer         DER encoded data.
 178 * @param [in]      type         Type of data. Valid values:
 179 *                                 CERT_TYPE, CA_TYPE or TRUSTED_PEER_TYPE.
 180 * @param [in]      verify       How to verify certificate.
 181 * @param [out]     chainBuffer  Buffer to hold chain of certificates.
 182 * @param [in, out] pIdx         On in, current index into chainBuffer.
 183 *                               On out, index after certificate added.
 184 * @param [in]      bufferSz     Size of buffer in bytes.
 185 * @return  0 on success.
 186 * @return  BUFFER_E if chain buffer not big enough to hold certificate.
 187 */
 188static int ProcessUserCert(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer,
 189    int type, int verify, byte* chainBuffer, word32* pIdx, word32 bufferSz)
 190{
 191    int ret = 0;
 192    word32 idx = *pIdx;
 193    DerBuffer* der = *pDer;
 194
 195    /* Check there is space for certificate in chainBuffer. */
 196    if ((ret == 0) && ((idx + der->length + CERT_HEADER_SZ) > bufferSz)) {
 197        WOLFSSL_MSG("   Cert Chain bigger than buffer. "
 198                    "Consider increasing MAX_CHAIN_DEPTH");
 199        ret = BUFFER_E;
 200    }
 201    if (ret == 0) {
 202        /* 3-byte length. */
 203        c32to24(der->length, &chainBuffer[idx]);
 204        idx += CERT_HEADER_SZ;
 205        /* Add complete DER encoded certificate. */
 206        XMEMCPY(&chainBuffer[idx], der->buffer, der->length);
 207        idx += der->length;
 208
 209        if (type == CA_TYPE) {
 210            /* Add CA to certificate manager */
 211            ret = AddCA(cm, pDer, WOLFSSL_USER_CA, verify);
 212            if (ret == 1) {
 213                ret = 0;
 214            }
 215        }
 216    }
 217
 218    /* Update the index into chainBuffer. */
 219    *pIdx = idx;
 220    return ret;
 221}
 222
 223/* Store the certificate chain buffer aganst WOLFSSL_CTX or WOLFSSL object.
 224 *
 225 * @param [in, out] ctx          SSL context object.
 226 * @param [in, out] ssl          SSL object.
 227 * @param [in]      chainBuffer  Buffer containing chain of certificates.
 228 * @param [in]      len          Length, in bytes, of data in buffer.
 229 * @param [in]      cnt          Number of certificates in chain.
 230 * @param [in]      type         Type of data. Valid values:
 231 *                                 CERT_TYPE, CA_TYPE or CHAIN_CERT_TYPE.
 232 * @param [in]      heap         Dynamic memory allocation hint.
 233 * @return  0 on success.
 234 * @return  MEMORY_E when dynamic memory allocation fails.
 235 */
 236static int ProcessUserChainRetain(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 237    const byte* chainBuffer, word32 len, int cnt, int type, void* heap)
 238{
 239    int ret = 0;
 240
 241    (void)cnt;
 242
 243    /* Store in SSL object if available. */
 244    if (ssl != NULL) {
 245        /* Dispose of old chain if not reference to context's. */
 246        if (ssl->buffers.weOwnCertChain) {
 247            FreeDer(&ssl->buffers.certChain);
 248        }
 249        /* Allocate and copy the buffer into SSL object. */
 250        ret = AllocCopyDer(&ssl->buffers.certChain, chainBuffer, len, type,
 251            heap);
 252        ssl->buffers.weOwnCertChain = (ret == 0);
 253        /* Update count of certificates in chain. */
 254        ssl->buffers.certChainCnt = cnt;
 255    }
 256    /* Store in SSL context object if available. */
 257    else if (ctx != NULL) {
 258        /* Dispose of old chain and allocate and copy in new chain. */
 259        FreeDer(&ctx->certChain);
 260        /* Allocate and copy the buffer into SSL context object. */
 261        ret = AllocCopyDer(&ctx->certChain, chainBuffer, len, type, heap);
 262        /* Update count of certificates in chain. */
 263        ctx->certChainCnt = cnt;
 264    }
 265
 266    return ret;
 267}
 268
 269/* Process user cert chain to pass during the TLS handshake.
 270 *
 271 * If not a certificate type then data is ignored.
 272 *
 273 * @param [in, out] ctx     SSL context object.
 274 * @param [in, out] ssl     SSL object.
 275 * @param [in]      buff    Buffer holding certificates.
 276 * @param [in]      sz      Length of data in buffer.
 277 * @param [in]      format  Format of the certificate:
 278 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1
 279 * @param [in]      type    Type of certificate:
 280 *                            CA_TYPE, CERT_TYPE or CHAIN_CERT_TYPE
 281 * @param [out]     used    Number of bytes from buff used.
 282 * @param [in, out] info    Encryption information.
 283 * @param [in]      verify  How to verify certificate.
 284 * @return  0 on success.
 285 * @return  BAD_FUNC_ARG when type is CA_TYPE and ctx is NULL.
 286 * @return  MEMORY_E when dynamic memory allocation fails.
 287 */
 288static int ProcessUserChain(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 289    const unsigned char* buff, long sz, int format, int type, long* used,
 290    EncryptedInfo* info, int verify)
 291{
 292    int ret = 0;
 293    void* heap = WOLFSSL_HEAP(ctx, ssl);
 294
 295    WOLFSSL_ENTER("ProcessUserChain");
 296
 297    /* Check we haven't consumed all the data. */
 298    if (info->consumed >= sz) {
 299        WOLFSSL_MSG("Already consumed data");
 300    }
 301    else {
 302    #ifndef WOLFSSL_SMALL_STACK
 303        byte stackBuffer[FILE_BUFFER_SIZE];
 304    #endif
 305        StaticBuffer chain;
 306        long   consumed = info->consumed;
 307        word32 idx = 0;
 308        int    gotOne = 0;
 309        int    cnt = 0;
 310        /* Calculate max possible size, including max headers */
 311        long   maxSz = (sz - consumed) + (CERT_HEADER_SZ * MAX_CHAIN_DEPTH);
 312
 313        /* Setup buffer to hold chain. */
 314    #ifdef WOLFSSL_SMALL_STACK
 315        static_buffer_init(&chain);
 316    #else
 317        static_buffer_init(&chain, stackBuffer, FILE_BUFFER_SIZE);
 318    #endif
 319        /* Make buffer big enough to support maximum size. */
 320        ret = static_buffer_set_size(&chain, (word32)maxSz, heap,
 321            DYNAMIC_TYPE_FILE);
 322
 323        WOLFSSL_MSG("Processing Cert Chain");
 324        /* Keep parsing certificates will data available. */
 325        while ((ret == 0) && (consumed < sz)) {
 326            DerBuffer* part = NULL;
 327
 328            /* Get a certificate as DER. */
 329            ret = DataToDerBuffer(buff + consumed, (word32)(sz - consumed),
 330                format, type, info, heap, &part, NULL);
 331            if (ret == 0) {
 332                /* Process the user certificate. */
 333                ret = ProcessUserCert(ctx->cm, &part, type, verify,
 334                   chain.buffer, &idx, (word32)maxSz);
 335            }
 336            /* PEM may have trailing data that can be ignored. */
 337            if ((ret == WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)) && gotOne) {
 338                WOLFSSL_MSG("We got one good cert, so stuff at end ok");
 339                ret = 0;
 340                break;
 341            }
 342            /* Certificate data handled. */
 343            FreeDer(&part);
 344
 345            if (ret == 0) {
 346                /* Update consumed length. */
 347                consumed += info->consumed;
 348                WOLFSSL_MSG("   Consumed another Cert in Chain");
 349                /* Update whether we got a user certificate. */
 350                gotOne |= (type != CA_TYPE);
 351                /* Update count of certificates added to chain. */
 352                cnt++;
 353            }
 354        }
 355        if (used != NULL) {
 356            /* Return the total consumed length. */
 357            *used = consumed;
 358        }
 359
 360        /* Check whether there is data in the chain buffer. */
 361        if ((ret == 0) && (idx > 0)) {
 362            /* Put the chain buffer against the SSL or SSL context object. */
 363            ret = ProcessUserChainRetain(ctx, ssl, chain.buffer, idx, cnt, type,
 364                heap);
 365        }
 366
 367        /* Dispose of chain buffer. */
 368        static_buffer_free(&chain, heap, DYNAMIC_TYPE_FILE);
 369    }
 370
 371    WOLFSSL_LEAVE("ProcessUserChain", ret);
 372    return ret;
 373}
 374
 375#ifndef NO_RSA
 376#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
 377    (HAVE_FIPS_VERSION > 2))
 378/* See if DER data is an RSA private key.
 379 *
 380 * Checks size meets minimum RSA key size.
 381 * This implementation uses less dynamic memory.
 382 *
 383 * @param [in, out] ctx        SSL context object.
 384 * @param [in, out] ssl        SSL object.
 385 * @param [in]      der        DER encoding.
 386 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 387 * @param [in]      devId      Device identifier.
 388 * @param [out]     keyType    Type of key.
 389 * @param [out]     keySize    Size of key.
 390 * @return  0 on success or not an RSA key and format unknown.
 391 * @return  RSA_KEY_SIZE_E when key size doesn't meet minimum required.
 392 */
 393static int ProcessBufferTryDecodeRsa(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 394    DerBuffer* der, int* keyFormat, int devId, byte* keyType, int* keySize)
 395{
 396    int ret;
 397    word32 idx;
 398    int keySz = 0;
 399
 400    (void)devId;
 401
 402    /* Validate we have an RSA private key and get key size. */
 403    idx = 0;
 404    ret = wc_RsaPrivateKeyValidate(der->buffer, &idx, &keySz, der->length);
 405#ifdef WOLF_PRIVATE_KEY_ID
 406    /* If that didn't work then maybe a public key if device ID or callback. */
 407    if ((ret != 0) && ((devId != INVALID_DEVID) ||
 408            WOLFSSL_IS_PRIV_PK_SET(ctx, ssl))) {
 409        word32 nSz;
 410
 411        /* Decode as an RSA public key. */
 412        idx = 0;
 413        ret = wc_RsaPublicKeyDecode_ex(der->buffer, &idx, der->length, NULL,
 414            &nSz, NULL, NULL);
 415        if (ret == 0) {
 416            keySz = (int)nSz;
 417        }
 418    }
 419#endif
 420    if (ret == 0) {
 421        /* Get the minimum RSA key size from SSL or SSL context object. */
 422        int minRsaSz = ssl ? ssl->options.minRsaKeySz : ctx->minRsaKeySz;
 423
 424        /* Format, type and size are known. */
 425        *keyFormat = RSAk;
 426        *keyType = rsa_sa_algo;
 427        *keySize = keySz;
 428
 429        /* Check that the size of the RSA key is enough. */
 430        if (keySz < minRsaSz) {
 431            WOLFSSL_MSG("Private Key size too small");
 432            ret = RSA_KEY_SIZE_E;
 433        }
 434         /* No static ECC key possible. */
 435        if ((ssl != NULL) && (ssl->options.side == WOLFSSL_SERVER_END)) {
 436             ssl->options.haveStaticECC = 0;
 437        }
 438    }
 439    /* Not an RSA key but check whether we know what it is. */
 440    else if (*keyFormat == 0) {
 441        WOLFSSL_MSG("Not an RSA key");
 442        /* Format unknown so keep trying. */
 443        ret = 0;
 444    }
 445
 446    return ret;
 447}
 448#else
 449/* See if DER data is an RSA private key.
 450 *
 451 * Checks size meets minimum RSA key size.
 452 * This implementation uses more dynamic memory but supports older FIPS.
 453 *
 454 * @param [in, out] ctx        SSL context object.
 455 * @param [in, out] ssl        SSL object.
 456 * @param [in]      der        DER encoding.
 457 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 458 * @param [in]      heap       Dynamic memory allocation hint.
 459 * @param [in]      devId      Device identifier.
 460 * @param [out]     keyType    Type of key.
 461 * @param [out]     keySize    Size of key.
 462 * @return  0 on success or not an RSA key and format unknown.
 463 * @return  RSA_KEY_SIZE_E when key size doesn't meet minimum required.
 464 */
 465static int ProcessBufferTryDecodeRsa(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 466    DerBuffer* der, int* keyFormat, void* heap, int devId, byte* keyType,
 467    int* keySize)
 468{
 469    int ret;
 470    word32 idx;
 471    /* make sure RSA key can be used */
 472    WC_DECLARE_VAR(key, RsaKey, 1, 0);
 473
 474    /* Allocate an RSA key to parse into so we can get size. */
 475    WC_ALLOC_VAR_EX(key, RsaKey, 1, heap, DYNAMIC_TYPE_RSA,
 476        return MEMORY_E);
 477
 478    /* Initialize the RSA key. */
 479    ret = wc_InitRsaKey_ex(key, heap, devId);
 480    if (ret == 0) {
 481        /* Check we have an RSA private key. */
 482        idx = 0;
 483        ret = wc_RsaPrivateKeyDecode(der->buffer, &idx, key, der->length);
 484    #ifdef WOLF_PRIVATE_KEY_ID
 485        /* If that didn't work then maybe a public key if device ID or callback.
 486         */
 487        if ((ret != 0) && ((devId != INVALID_DEVID) ||
 488                WOLFSSL_IS_PRIV_PK_SET(ctx, ssl))) {
 489            /* If that didn't work then maybe a public key if device ID or
 490             * callback. */
 491            idx = 0;
 492            ret = wc_RsaPublicKeyDecode(der->buffer, &idx, key, der->length);
 493        }
 494    #endif
 495        if (ret == 0) {
 496            /* Get the minimum RSA key size from SSL or SSL context object. */
 497            int minRsaSz = ssl ? ssl->options.minRsaKeySz : ctx->minRsaKeySz;
 498            int keySz = wc_RsaEncryptSize((RsaKey*)key);
 499
 500            /* Format is known. */
 501            *keyFormat = RSAk;
 502            *keyType = rsa_sa_algo;
 503            *keySize = keySz;
 504
 505            /* Check that the size of the RSA key is enough. */
 506            if (keySz < minRsaSz) {
 507                WOLFSSL_MSG("Private Key size too small");
 508                ret = RSA_KEY_SIZE_E;
 509            }
 510            /* No static ECC key possible. */
 511            if ((ssl != NULL) && (ssl->options.side == WOLFSSL_SERVER_END)) {
 512                 ssl->options.haveStaticECC = 0;
 513            }
 514        }
 515        /* Not an RSA key but check whether we know what it is. */
 516        else if (*keyFormat == 0) {
 517            WOLFSSL_MSG("Not an RSA key");
 518            /* Format unknown so keep trying. */
 519            ret = 0;
 520        }
 521
 522        /* Free dynamically allocated data in key. */
 523        wc_FreeRsaKey(key);
 524    }
 525
 526    WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_RSA);
 527
 528    return ret;
 529}
 530#endif
 531#endif /* !NO_RSA */
 532
 533#ifdef HAVE_ECC
 534/* See if DER data is an ECC private key.
 535 *
 536 * Checks size meets minimum ECC key size.
 537 *
 538 * @param [in, out] ctx        SSL context object.
 539 * @param [in, out] ssl        SSL object.
 540 * @param [in]      der        DER encoding.
 541 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 542 * @param [in]      heap       Dynamic memory allocation hint.
 543 * @param [in]      devId      Device identifier.
 544 * @param [out]     keyType    Type of key.
 545 * @param [out]     keySize    Size of key.
 546 * @return  0 on success or not an ECC key and format unknown.
 547 * @return  ECC_KEY_SIZE_E when ECC key size doesn't meet minimum required.
 548 */
 549static int ProcessBufferTryDecodeEcc(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 550    DerBuffer* der, int* keyFormat, void* heap, int devId, byte* keyType,
 551    int* keySize)
 552{
 553    int ret = 0;
 554    word32 idx;
 555    /* make sure ECC key can be used */
 556    WC_DECLARE_VAR(key, ecc_key, 1, 0);
 557
 558    /* Allocate an ECC key to parse into. */
 559    WC_ALLOC_VAR_EX(key, ecc_key, 1, heap, DYNAMIC_TYPE_ECC,
 560        return MEMORY_E);
 561
 562    /* Initialize ECC key. */
 563    if (wc_ecc_init_ex(key, heap, devId) == 0) {
 564        /* Decode as an ECC private key. */
 565        idx = 0;
 566        ret = wc_EccPrivateKeyDecode(der->buffer, &idx, key, der->length);
 567    #ifdef WOLF_PRIVATE_KEY_ID
 568        /* If that didn't work then maybe a public key if device ID or callback.
 569         */
 570        if ((ret != 0) && ((devId != INVALID_DEVID) ||
 571                WOLFSSL_IS_PRIV_PK_SET(ctx, ssl))) {
 572            /* Decode as an ECC public key. */
 573            idx = 0;
 574            ret = wc_EccPublicKeyDecode(der->buffer, &idx, key, der->length);
 575        }
 576    #endif
 577    #ifdef WOLFSSL_SM2
 578        if (*keyFormat == SM2k) {
 579            ret = wc_ecc_set_curve(key, WOLFSSL_SM2_KEY_BITS / 8,
 580                ECC_SM2P256V1);
 581        }
 582    #endif
 583        if (ret == 0) {
 584            /* Get the minimum ECC key size from SSL or SSL context object. */
 585            int minKeySz = ssl ? ssl->options.minEccKeySz : ctx->minEccKeySz;
 586            int keySz = wc_ecc_size(key);
 587
 588            /* Format is known. */
 589            *keyFormat = ECDSAk;
 590        #ifdef WOLFSSL_SM2
 591            if (key->dp->id == ECC_SM2P256V1) {
 592                *keyType = sm2_sa_algo;
 593            }
 594            else
 595        #endif
 596            {
 597                *keyType = ecc_dsa_sa_algo;
 598            }
 599            *keySize = keySz;
 600
 601            /* Check that the size of the ECC key is enough. */
 602            if (keySz < minKeySz) {
 603                WOLFSSL_MSG("ECC private key too small");
 604                ret = ECC_KEY_SIZE_E;
 605            }
 606            /* Static ECC key possible. */
 607            if (ssl) {
 608                ssl->options.haveStaticECC = 1;
 609            }
 610            else {
 611                ctx->haveStaticECC = 1;
 612            }
 613        }
 614        /* Not an ECC key but check whether we know what it is. */
 615        else if (*keyFormat == 0) {
 616            WOLFSSL_MSG("Not an ECC key");
 617            /* Format unknown so keep trying. */
 618            ret = 0;
 619        }
 620
 621        /* Free dynamically allocated data in key. */
 622        wc_ecc_free(key);
 623    }
 624
 625    WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_ECC);
 626    return ret;
 627}
 628#endif /* HAVE_ECC */
 629
 630#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
 631/* See if DER data is an Ed25519 private key.
 632 *
 633 * Checks size meets minimum ECC key size.
 634 *
 635 * @param [in, out] ctx        SSL context object.
 636 * @param [in, out] ssl        SSL object.
 637 * @param [in]      der        DER encoding.
 638 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 639 * @param [in]      heap       Dynamic memory allocation hint.
 640 * @param [in]      devId      Device identifier.
 641 * @param [out]     keyType    Type of key.
 642 * @param [out]     keySize    Size of key.
 643 * @return  0 on success or not an Ed25519 key and format unknown.
 644 * @return  ECC_KEY_SIZE_E when key size doesn't meet minimum required.
 645 */
 646static int ProcessBufferTryDecodeEd25519(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 647    DerBuffer* der, int* keyFormat, void* heap, int devId, byte* keyType,
 648    int* keySize)
 649{
 650    int ret;
 651    word32 idx;
 652    /* make sure Ed25519 key can be used */
 653    WC_DECLARE_VAR(key, ed25519_key, 1, 0);
 654
 655    /* Allocate an Ed25519 key to parse into. */
 656    WC_ALLOC_VAR_EX(key, ed25519_key, 1, heap, DYNAMIC_TYPE_ED25519,
 657        return MEMORY_E);
 658
 659    /* Initialize Ed25519 key. */
 660    ret = wc_ed25519_init_ex(key, heap, devId);
 661    if (ret == 0) {
 662        /* Decode as an Ed25519 private key. */
 663        idx = 0;
 664        ret = wc_Ed25519PrivateKeyDecode(der->buffer, &idx, key, der->length);
 665    #ifdef WOLF_PRIVATE_KEY_ID
 666        /* If that didn't work then maybe a public key if device ID or callback.
 667         */
 668        if ((ret != 0) && ((devId != INVALID_DEVID) ||
 669                WOLFSSL_IS_PRIV_PK_SET(ctx, ssl))) {
 670            /* Decode as an Ed25519 public key. */
 671            idx = 0;
 672            ret = wc_Ed25519PublicKeyDecode(der->buffer, &idx, key,
 673                der->length);
 674        }
 675    #endif
 676        if (ret == 0) {
 677            /* Get the minimum ECC key size from SSL or SSL context object. */
 678            int minKeySz = ssl ? ssl->options.minEccKeySz : ctx->minEccKeySz;
 679
 680            /* Format is known. */
 681            *keyFormat = ED25519k;
 682            *keyType = ed25519_sa_algo;
 683            *keySize = ED25519_KEY_SIZE;
 684
 685            /* Check that the size of the ECC key is enough. */
 686            if (ED25519_KEY_SIZE < minKeySz) {
 687                WOLFSSL_MSG("ED25519 private key too small");
 688                ret = ECC_KEY_SIZE_E;
 689            }
 690            if (ssl != NULL) {
 691#if !defined(WOLFSSL_NO_CLIENT_AUTH) && !defined(NO_ED25519_CLIENT_AUTH)
 692                /* Ed25519 requires caching enabled for tracking message
 693                 * hash used in EdDSA_Update for signing */
 694                ssl->options.cacheMessages = 1;
 695#endif
 696            }
 697        }
 698        /* Not an Ed25519 key but check whether we know what it is. */
 699        else if (*keyFormat == 0) {
 700            WOLFSSL_MSG("Not an Ed25519 key");
 701            /* Format unknown so keep trying. */
 702            ret = 0;
 703        }
 704
 705        /* Free dynamically allocated data in key. */
 706        wc_ed25519_free(key);
 707    }
 708
 709    WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_ED25519);
 710    return ret;
 711}
 712#endif /* HAVE_ED25519 && HAVE_ED25519_KEY_IMPORT */
 713
 714#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
 715/* See if DER data is an Ed448 private key.
 716 *
 717 * Checks size meets minimum ECC key size.
 718 *
 719 * @param [in, out] ctx        SSL context object.
 720 * @param [in, out] ssl        SSL object.
 721 * @param [in]      der        DER encoding.
 722 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 723 * @param [in]      heap       Dynamic memory allocation hint.
 724 * @param [in]      devId      Device identifier.
 725 * @param [out]     keyType    Type of key.
 726 * @param [out]     keySize    Size of key.
 727 * @return  0 on success or not an Ed448 key and format unknown.
 728 * @return  ECC_KEY_SIZE_E when key size doesn't meet minimum required.
 729 */
 730static int ProcessBufferTryDecodeEd448(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 731    DerBuffer* der, int* keyFormat, void* heap, int devId, byte* keyType,
 732    int* keySize)
 733{
 734    int ret;
 735    word32 idx;
 736    /* make sure Ed448 key can be used */
 737    WC_DECLARE_VAR(key, ed448_key, 1, 0);
 738
 739    /* Allocate an Ed448 key to parse into. */
 740    WC_ALLOC_VAR_EX(key, ed448_key, 1, heap, DYNAMIC_TYPE_ED448,
 741        return MEMORY_E);
 742
 743    /* Initialize Ed448 key. */
 744    ret = wc_ed448_init_ex(key, heap, devId);
 745    if (ret == 0) {
 746        /* Decode as an Ed448 private key. */
 747        idx = 0;
 748        ret = wc_Ed448PrivateKeyDecode(der->buffer, &idx, key, der->length);
 749    #ifdef WOLF_PRIVATE_KEY_ID
 750        /* If that didn't work then maybe a public key if device ID or callback.
 751         */
 752        if ((ret != 0) && ((devId != INVALID_DEVID) ||
 753                WOLFSSL_IS_PRIV_PK_SET(ctx, ssl))) {
 754            /* Decode as an Ed448 public key. */
 755            idx = 0;
 756            ret = wc_Ed448PublicKeyDecode(der->buffer, &idx, key, der->length);
 757        }
 758    #endif
 759        if (ret == 0) {
 760            /* Get the minimum ECC key size from SSL or SSL context object. */
 761            int minKeySz = ssl ? ssl->options.minEccKeySz : ctx->minEccKeySz;
 762
 763            /* Format is known. */
 764            *keyFormat = ED448k;
 765            *keyType = ed448_sa_algo;
 766            *keySize = ED448_KEY_SIZE;
 767
 768            /* Check that the size of the ECC key is enough. */
 769            if (ED448_KEY_SIZE < minKeySz) {
 770                WOLFSSL_MSG("ED448 private key too small");
 771                ret = ECC_KEY_SIZE_E;
 772            }
 773        #if !defined(WOLFSSL_NO_CLIENT_AUTH) && !defined(NO_ED448_CLIENT_AUTH)
 774            if (ssl != NULL) {
 775                /* Ed448 requires caching enabled for tracking message
 776                 * hash used in EdDSA_Update for signing */
 777                ssl->options.cacheMessages = 1;
 778            }
 779        #endif
 780        }
 781        /* Not an Ed448 key but check whether we know what it is. */
 782        else if (*keyFormat == 0) {
 783            WOLFSSL_MSG("Not an Ed448 key");
 784            /* Format unknown so keep trying. */
 785            ret = 0;
 786        }
 787
 788        /* Free dynamically allocated data in key. */
 789        wc_ed448_free(key);
 790    }
 791
 792    WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_ED448);
 793    return ret;
 794}
 795#endif /* HAVE_ED448 && HAVE_ED448_KEY_IMPORT */
 796
 797#if defined(HAVE_FALCON)
 798/* See if DER data is an Falcon private key.
 799 *
 800 * Checks size meets minimum Falcon key size.
 801 *
 802 * @param [in, out] ctx        SSL context object.
 803 * @param [in, out] ssl        SSL object.
 804 * @param [in]      der        DER encoding.
 805 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 806 * @param [in]      heap       Dynamic memory allocation hint.
 807 * @param [in]      devId      Device identifier.
 808 * @param [out]     keyType    Type of key.
 809 * @param [out]     keySize    Size of key.
 810 * @return  0 on success or not an Falcon key and format unknown.
 811 * @return  FALCON_KEY_SIZE_E when key size doesn't meet minimum required.
 812 */
 813static int ProcessBufferTryDecodeFalcon(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 814    DerBuffer* der, int* keyFormat, void* heap, byte* keyType, int* keySize)
 815{
 816    int ret;
 817    falcon_key* key;
 818
 819    /* Allocate a Falcon key to parse into. */
 820    key = (falcon_key*)XMALLOC(sizeof(falcon_key), heap, DYNAMIC_TYPE_FALCON);
 821    if (key == NULL) {
 822        return MEMORY_E;
 823    }
 824
 825    /* Initialize Falcon key. */
 826    ret = wc_falcon_init(key);
 827    if (ret == 0) {
 828        byte level = 0;
 829        word32 idx;
 830
 831        if (*keyFormat == FALCON_LEVEL1k) {
 832            level = 1;
 833        }
 834        else if (*keyFormat == FALCON_LEVEL5k) {
 835            level = 5;
 836        }
 837
 838        if (level != 0) {
 839            /* Caller told us the level via the OID sum. */
 840            ret = wc_falcon_set_level(key, level);
 841            if (ret == 0) {
 842                idx = 0;
 843                ret = wc_Falcon_PrivateKeyDecode(der->buffer, &idx, key,
 844                                                  der->length);
 845            }
 846        }
 847        else if (*keyFormat == 0) {
 848            /* Key format unknown. Try both levels; the expected OID inside
 849             * wc_Falcon_PrivateKeyDecode rejects non-matching DER. Re-init
 850             * between attempts so a partial first decode can't leave stale
 851             * bytes in key->k / key->p. */
 852            idx = 0;
 853            if (wc_falcon_set_level(key, 1) == 0 &&
 854                wc_Falcon_PrivateKeyDecode(der->buffer, &idx, key,
 855                                           der->length) == 0) {
 856                level = 1;
 857            }
 858            else {
 859                wc_falcon_free(key);
 860                if (wc_falcon_init(key) != 0) {
 861                    XFREE(key, heap, DYNAMIC_TYPE_FALCON);
 862                    return MEMORY_E;
 863                }
 864                idx = 0;
 865                if (wc_falcon_set_level(key, 5) == 0 &&
 866                    wc_Falcon_PrivateKeyDecode(der->buffer, &idx, key,
 867                                               der->length) == 0) {
 868                    level = 5;
 869                }
 870            }
 871            if (level == 0) {
 872                /* Not a Falcon key; let caller try another algorithm. */
 873                WOLFSSL_MSG("Not a Falcon key");
 874                wc_falcon_free(key);
 875                XFREE(key, heap, DYNAMIC_TYPE_FALCON);
 876                return 0;
 877            }
 878            ret = 0;
 879        }
 880        else {
 881            wc_falcon_free(key);
 882            ret = ALGO_ID_E;
 883        }
 884    }
 885
 886    if (ret == 0) {
 887        /* Get the minimum Falcon key size from SSL or SSL context object. */
 888        int minKeySz = ssl ? ssl->options.minFalconKeySz :
 889                             ctx->minFalconKeySz;
 890
 891        if (key->level == 1) {
 892            *keyFormat = FALCON_LEVEL1k;
 893            *keyType = falcon_level1_sa_algo;
 894            *keySize = FALCON_LEVEL1_KEY_SIZE;
 895        }
 896        else {
 897            *keyFormat = FALCON_LEVEL5k;
 898            *keyType = falcon_level5_sa_algo;
 899            *keySize = FALCON_LEVEL5_KEY_SIZE;
 900        }
 901
 902        /* Check that the size of the Falcon key is enough. */
 903        if (*keySize < minKeySz) {
 904            WOLFSSL_MSG("Falcon private key too small");
 905            ret = FALCON_KEY_SIZE_E;
 906        }
 907
 908        wc_falcon_free(key);
 909    }
 910    else if ((ret == WC_NO_ERR_TRACE(ALGO_ID_E)) && (*keyFormat == 0)) {
 911        WOLFSSL_MSG("Not a Falcon key");
 912        /* Format unknown so keep trying. */
 913        ret = 0;
 914    }
 915
 916    /* Dispose of allocated key. */
 917    XFREE(key, heap, DYNAMIC_TYPE_FALCON);
 918    return ret;
 919}
 920#endif
 921
 922#if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \
 923    !defined(WOLFSSL_DILITHIUM_NO_ASN1)
 924/* See if DER data is an Dilithium private key.
 925 *
 926 * Checks size meets minimum Falcon key size.
 927 *
 928 * @param [in, out] ctx        SSL context object.
 929 * @param [in, out] ssl        SSL object.
 930 * @param [in]      der        DER encoding.
 931 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
 932 * @param [in]      heap       Dynamic memory allocation hint.
 933 * @param [in]      devId      Device identifier.
 934 * @param [out]     keyType    Type of key.
 935 * @param [out]     keySize    Size of key.
 936 * @return  0 on success or not a Dilithium key and format unknown.
 937 * @return  DILITHIUM_KEY_SIZE_E when key size doesn't meet minimum required.
 938 */
 939static int ProcessBufferTryDecodeDilithium(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
 940    DerBuffer* der, int* keyFormat, void* heap, byte* keyType, int* keySize)
 941{
 942    int ret;
 943    word32 idx;
 944    dilithium_key* key;
 945    int keyFormatTemp = 0;
 946    int keyTypeTemp = 0;
 947    int keySizeTemp = 0;
 948
 949    /* Allocate a Dilithium key to parse into. */
 950    key = (dilithium_key*)XMALLOC(sizeof(dilithium_key), heap,
 951        DYNAMIC_TYPE_DILITHIUM);
 952    if (key == NULL) {
 953        return MEMORY_E;
 954    }
 955
 956    /* Initialize Dilithium key. */
 957    ret = wc_dilithium_init(key);
 958    if (ret == 0) {
 959        /* Decode as a Dilithium private key. The FIPS wrapper for
 960         * wc_dilithium_import_private gates on the per-thread
 961         * privateKeyReadEnable flag, which is unset by default in any
 962         * thread that hasn't called PRIVATE_KEY_UNLOCK(). Without the
 963         * bracket, loading a Dilithium/ML-DSA private key from a
 964         * worker thread fails with FIPS_PRIVATE_KEY_LOCKED_E. */
 965        idx = 0;
 966        PRIVATE_KEY_UNLOCK();
 967        ret = wc_Dilithium_PrivateKeyDecode(der->buffer, &idx, key,
 968            der->length);
 969        PRIVATE_KEY_LOCK();
 970        if (ret == 0) {
 971            ret = dilithium_get_oid_sum(key, &keyFormatTemp);
 972            if (ret == 0) {
 973                /* Format is known. */
 974                #if defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT)
 975                if (keyFormatTemp == DILITHIUM_LEVEL2k) {
 976                    keyTypeTemp = dilithium_level2_sa_algo;
 977                    keySizeTemp = DILITHIUM_LEVEL2_KEY_SIZE;
 978                }
 979                else if (keyFormatTemp == DILITHIUM_LEVEL3k) {
 980                    keyTypeTemp = dilithium_level3_sa_algo;
 981                    keySizeTemp = DILITHIUM_LEVEL3_KEY_SIZE;
 982                }
 983                else if (keyFormatTemp == DILITHIUM_LEVEL5k) {
 984                    keyTypeTemp = dilithium_level5_sa_algo;
 985                    keySizeTemp = DILITHIUM_LEVEL5_KEY_SIZE;
 986                }
 987                else
 988                #endif /* WOLFSSL_DILITHIUM_FIPS204_DRAFT */
 989                if (keyFormatTemp == ML_DSA_LEVEL2k) {
 990                    keyTypeTemp = dilithium_level2_sa_algo;
 991                    keySizeTemp = ML_DSA_LEVEL2_KEY_SIZE;
 992                }
 993                else if (keyFormatTemp == ML_DSA_LEVEL3k) {
 994                    keyTypeTemp = dilithium_level3_sa_algo;
 995                    keySizeTemp = ML_DSA_LEVEL3_KEY_SIZE;
 996                }
 997                else if (keyFormatTemp == ML_DSA_LEVEL5k) {
 998                    keyTypeTemp = dilithium_level5_sa_algo;
 999                    keySizeTemp = ML_DSA_LEVEL5_KEY_SIZE;
1000                }
1001                else {
1002                    ret = ALGO_ID_E;
1003                }
1004            }
1005
1006            if (ret == 0) {
1007                /* Get the minimum Dilithium key size from SSL or SSL context
1008                 * object. */
1009                int minKeySz = ssl ? ssl->options.minDilithiumKeySz :
1010                                     ctx->minDilithiumKeySz;
1011
1012                /* Check that the size of the Dilithium key is enough. */
1013                if (keySizeTemp < minKeySz) {
1014                    WOLFSSL_MSG("Dilithium private key too small");
1015                    ret = DILITHIUM_KEY_SIZE_E;
1016                }
1017            }
1018
1019            if (ret == 0) {
1020                *keyFormat = keyFormatTemp;
1021                *keyType = keyTypeTemp;
1022                *keySize = keySizeTemp;
1023            }
1024        }
1025        else if (*keyFormat == 0) {
1026            WOLFSSL_MSG("Not a Dilithium key");
1027            /* Unknown format wasn't dilithium, so keep trying other formats. */
1028            ret = 0;
1029        }
1030
1031        /* Free dynamically allocated data in key. */
1032        wc_dilithium_free(key);
1033    }
1034
1035    /* Dispose of allocated key. */
1036    XFREE(key, heap, DYNAMIC_TYPE_DILITHIUM);
1037    return ret;
1038}
1039#endif /* HAVE_DILITHIUM */
1040
1041/* Try to decode DER data is a known private key.
1042 *
1043 * Checks size meets minimum for key type.
1044 *
1045 * @param [in, out] ctx        SSL context object.
1046 * @param [in, out] ssl        SSL object.
1047 * @param [in]      der        DER encoding.
1048 * @param [in, out] keyFormat  On in, expected format. 0 means unknown.
1049 * @param [in]      heap       Dynamic memory allocation hint.
1050 * @param [out]     type       Type of key:
1051 *                               PRIVATEKEY_TYPE or ALT_PRIVATEKEY_TYPE.
1052 * @return  0 on success.
1053 * @return  BAD_FUNC_ARG when der or keyFormat is NULL.
1054 * @return  BAD_FUNC_ARG when ctx and ssl are NULL.
1055 * @return  WOLFSSL_BAD_FILE when unable to identify the key format.
1056 */
1057static int ProcessBufferTryDecode(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1058    DerBuffer* der, int* keyFormat, void* heap, int type)
1059{
1060    int ret = 0;
1061    int devId = wolfSSL_CTX_GetDevId(ctx, ssl);
1062    byte* keyType = NULL;
1063    int* keySz = NULL;
1064    int matchAnyKey = 0;
1065
1066    (void)heap;
1067    (void)devId;
1068    (void)type;
1069
1070    /* Validate parameters. */
1071    if ((der == NULL) || (keyFormat == NULL)) {
1072        ret = BAD_FUNC_ARG;
1073    }
1074    /* Must have an SSL context or SSL object to use. */
1075    if ((ret == 0) && (ctx == NULL) && (ssl == NULL)) {
1076        ret = BAD_FUNC_ARG;
1077    }
1078
1079    if (ret == 0) {
1080        /* Determine where to put key type and size in SSL or context object. */
1081    #ifdef WOLFSSL_DUAL_ALG_CERTS
1082        if (type == ALT_PRIVATEKEY_TYPE) {
1083            if (ssl != NULL) {
1084                keyType = &ssl->buffers.altKeyType;
1085                keySz = &ssl->buffers.altKeySz;
1086            }
1087            else {
1088                keyType = &ctx->altPrivateKeyType;
1089                keySz = &ctx->altPrivateKeySz;
1090            }
1091        }
1092        else
1093    #endif
1094        /* Type is PRIVATEKEY_TYPE. */
1095        if (ssl != NULL) {
1096            keyType = &ssl->buffers.keyType;
1097            keySz = &ssl->buffers.keySz;
1098        }
1099        else {
1100            keyType = &ctx->privateKeyType;
1101            keySz = &ctx->privateKeySz;
1102        }
1103    }
1104
1105#ifndef NO_RSA
1106    /* Try RSA if key format is RSA or yet unknown. */
1107    if ((ret == 0) && ((*keyFormat == 0) || (*keyFormat == RSAk))) {
1108#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
1109    (HAVE_FIPS_VERSION > 2))
1110        ret = ProcessBufferTryDecodeRsa(ctx, ssl, der, keyFormat, devId,
1111            keyType, keySz);
1112#else
1113        ret = ProcessBufferTryDecodeRsa(ctx, ssl, der, keyFormat, heap, devId,
1114            keyType, keySz);
1115#endif
1116        matchAnyKey = 1;
1117    }
1118#ifdef WC_RSA_PSS
1119    if((ret == 0) && (*keyFormat == RSAPSSk)) {
1120        /* Require logic to verify that the der is RSAPSSk
1121         * (when *keyFormat == RSAPSSK), and to detect that the der is RSAPSSk
1122         * (when *keyFormat == 0). */
1123        matchAnyKey = 1;
1124    }
1125#endif /* WC_RSA_PSS */
1126#endif /* NO_RSA */
1127#ifdef HAVE_ECC
1128    /* Try ECC if key format is ECDSA or SM2, or yet unknown. */
1129    if ((ret == 0) && ((*keyFormat == 0) || (*keyFormat == ECDSAk)
1130    #ifdef WOLFSSL_SM2
1131        || (*keyFormat == SM2k)
1132    #endif
1133        )) {
1134        ret = ProcessBufferTryDecodeEcc(ctx, ssl, der, keyFormat, heap, devId,
1135            keyType, keySz);
1136        matchAnyKey = 1;
1137    }
1138#endif /* HAVE_ECC */
1139#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
1140    /* Try Ed25519 if key format is Ed25519 or yet unknown. */
1141    if ((ret == 0) && ((*keyFormat == 0 || *keyFormat == ED25519k))) {
1142        ret = ProcessBufferTryDecodeEd25519(ctx, ssl, der, keyFormat, heap,
1143            devId, keyType, keySz);
1144        matchAnyKey = 1;
1145    }
1146#endif /* HAVE_ED25519 && HAVE_ED25519_KEY_IMPORT */
1147#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
1148    /* Try Ed448 if key format is Ed448 or yet unknown. */
1149    if ((ret == 0) && ((*keyFormat == 0 || *keyFormat == ED448k))) {
1150        ret = ProcessBufferTryDecodeEd448(ctx, ssl, der, keyFormat, heap, devId,
1151            keyType, keySz);
1152        matchAnyKey = 1;
1153    }
1154#endif /* HAVE_ED448 && HAVE_ED448_KEY_IMPORT */
1155#if defined(HAVE_FALCON)
1156    /* Try Falcon if key format is Falcon level 1k or 5k or yet unknown. */
1157    if ((ret == 0) && ((*keyFormat == 0) || (*keyFormat == FALCON_LEVEL1k) ||
1158            (*keyFormat == FALCON_LEVEL5k))) {
1159        ret = ProcessBufferTryDecodeFalcon(ctx, ssl, der, keyFormat, heap,
1160            keyType, keySz);
1161        matchAnyKey = 1;
1162    }
1163#endif /* HAVE_FALCON */
1164#if defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \
1165    !defined(WOLFSSL_DILITHIUM_NO_ASN1)
1166    /* Try Falcon if key format is Dilithium level 2k, 3k or 5k or yet unknown.
1167     */
1168    if ((ret == 0) &&
1169        ((*keyFormat == 0) ||
1170        (*keyFormat == ML_DSA_LEVEL2k) ||
1171        (*keyFormat == ML_DSA_LEVEL3k) ||
1172        (*keyFormat == ML_DSA_LEVEL5k)
1173    #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
1174     || (*keyFormat == DILITHIUM_LEVEL2k)
1175     || (*keyFormat == DILITHIUM_LEVEL3k)
1176     || (*keyFormat == DILITHIUM_LEVEL5k)
1177    #endif
1178        )) {
1179        ret = ProcessBufferTryDecodeDilithium(ctx, ssl, der, keyFormat, heap,
1180            keyType, keySz);
1181        matchAnyKey = 1;
1182    }
1183#endif /* HAVE_DILITHIUM */
1184
1185    /* Check we know the format. */
1186    if ((ret == 0) &&
1187        ((*keyFormat == 0) || ((*keyFormat != 0) && (matchAnyKey == 0)))) {
1188        WOLFSSL_MSG("Not a supported key type");
1189        /* Not supported key format. */
1190        ret = WOLFSSL_BAD_FILE;
1191    }
1192
1193    return ret;
1194}
1195
1196#if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_PWDBASED)
1197/* Decrypt PKCS#8 private key.
1198 *
1199 * @param [in] info   Encryption information.
1200 * @param [in] der    DER encoded data.
1201 * @param [in] heap   Dynamic memory allocation hint.
1202 * @return  0 on success.
1203 * @return  MEMORY_E when dynamic memory allocation fails.
1204 */
1205static int ProcessBufferPrivPkcs8Dec(EncryptedInfo* info, DerBuffer* der,
1206    void* heap)
1207{
1208    int ret = 0;
1209    word32 algId;
1210    int   passwordSz = NAME_SZ;
1211    WC_DECLARE_VAR(password, char, NAME_SZ, 0);
1212
1213    (void)heap;
1214#ifdef WOLFSSL_SMALL_STACK
1215    /* Allocate memory for password. */
1216    password = (char*)XMALLOC(passwordSz, heap, DYNAMIC_TYPE_STRING);
1217    if (password == NULL) {
1218        ret = MEMORY_E;
1219    }
1220#endif
1221
1222    if (ret == 0) {
1223        /* Get password. */
1224        ret = info->passwd_cb(password, passwordSz, PEM_PASS_READ,
1225            info->passwd_userdata);
1226    }
1227    if (ret >= 0) {
1228        /* Returned value is password size. */
1229        passwordSz = ret;
1230    #ifdef WOLFSSL_CHECK_MEM_ZERO
1231        wc_MemZero_Add("ProcessBuffer password", password, passwordSz);
1232    #endif
1233
1234        /* Decrypt PKCS#8 private key inline and get algorithm id. */
1235        ret = ToTraditionalEnc(der->buffer, der->length, password, passwordSz,
1236            &algId);
1237    }
1238    if (ret >= 0) {
1239        /* Zero out encrypted data not overwritten. */
1240        ForceZero(der->buffer + ret, der->length - (word32)ret);
1241        /* Set decrypted data length. */
1242        der->length = (word32)ret;
1243    }
1244
1245#ifdef WOLFSSL_SMALL_STACK
1246    if (password != NULL)
1247#endif
1248    {
1249        /* Ensure password is zeroized. */
1250        ForceZero(password, (word32)passwordSz);
1251    }
1252#ifdef WOLFSSL_SMALL_STACK
1253    /* Dispose of password memory. */
1254    XFREE(password, heap, DYNAMIC_TYPE_STRING);
1255#elif defined(WOLFSSL_CHECK_MEM_ZERO)
1256    wc_MemZero_Check(password, NAME_SZ);
1257#endif
1258    return ret;
1259}
1260#endif /* WOLFSSL_ENCRYPTED_KEYS && !NO_PWDBASED */
1261
1262/* Put the DER into the SSL or SSL context object.
1263 *
1264 * Precondition: ctx or ssl is not NULL.
1265 * Precondition: Must be a private key type.
1266 *
1267 * @param [in, out] ctx  SSL context object.
1268 * @param [in, out] ssl  SSL object.
1269 * @param [in]      der  DER encoding.
1270 * @return  0 on success.
1271 */
1272static int ProcessBufferPrivKeyHandleDer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1273    DerBuffer** der, int type)
1274{
1275    int ret = 0;
1276
1277    (void)type;
1278
1279#ifdef WOLFSSL_DUAL_ALG_CERTS
1280    if (type == ALT_PRIVATEKEY_TYPE) {
1281        /* Put in alternate private key fields of objects. */
1282        if (ssl != NULL) {
1283            /* Dispose of previous key if not context's. */
1284            if (ssl->buffers.weOwnAltKey) {
1285                FreeDer(&ssl->buffers.altKey);
1286            #ifdef WOLFSSL_BLIND_PRIVATE_KEY
1287                FreeDer(&ssl->buffers.altKeyMask);
1288            #endif
1289            }
1290            ssl->buffers.altKeyId = 0;
1291            ssl->buffers.altKeyLabel = 0;
1292            ssl->buffers.altKeyDevId = INVALID_DEVID;
1293            /* Store key by reference and own it. */
1294            ssl->buffers.altKey = *der;
1295        #ifdef WOLFSSL_CHECK_MEM_ZERO
1296            wc_MemZero_Add("SSL Buffers key", (*der)->buffer, (*der)->length);
1297        #endif
1298            ssl->buffers.weOwnAltKey = 1;
1299        }
1300        else if (ctx != NULL) {
1301            /* Dispose of previous key. */
1302            FreeDer(&ctx->altPrivateKey);
1303            ctx->altPrivateKeyId = 0;
1304            ctx->altPrivateKeyLabel = 0;
1305            ctx->altPrivateKeyDevId = INVALID_DEVID;
1306            /* Store key by reference. */
1307            ctx->altPrivateKey = *der;
1308        #ifdef WOLFSSL_CHECK_MEM_ZERO
1309            wc_MemZero_Add("CTX private key", (*der)->buffer, (*der)->length);
1310        #endif
1311        }
1312    }
1313    else
1314#endif /* WOLFSSL_DUAL_ALG_CERTS */
1315    if (ssl != NULL) {
1316        /* Dispose of previous key if not context's. */
1317        if (ssl->buffers.weOwnKey) {
1318            FreeDer(&ssl->buffers.key);
1319        #ifdef WOLFSSL_BLIND_PRIVATE_KEY
1320            FreeDer(&ssl->buffers.keyMask);
1321        #endif
1322        }
1323        ssl->buffers.keyId = 0;
1324        ssl->buffers.keyLabel = 0;
1325        ssl->buffers.keyDevId = INVALID_DEVID;
1326        /* Store key by reference and own it. */
1327        ssl->buffers.key = *der;
1328    #ifdef WOLFSSL_CHECK_MEM_ZERO
1329        wc_MemZero_Add("SSL Buffers key", (*der)->buffer, (*der)->length);
1330    #endif
1331        ssl->buffers.weOwnKey = 1;
1332    }
1333    else if (ctx != NULL) {
1334        /* Dispose of previous key. */
1335        FreeDer(&ctx->privateKey);
1336        ctx->privateKeyId = 0;
1337        ctx->privateKeyLabel = 0;
1338        ctx->privateKeyDevId = INVALID_DEVID;
1339        /* Store key by reference. */
1340        ctx->privateKey = *der;
1341    #ifdef WOLFSSL_CHECK_MEM_ZERO
1342        wc_MemZero_Add("CTX private key", (*der)->buffer, (*der)->length);
1343    #endif
1344    }
1345
1346    return ret;
1347}
1348
1349/* Decode private key.
1350 *
1351 * Precondition: ctx or ssl is not NULL.
1352 * Precondition: Must be a private key type.
1353 *
1354 * @param [in, out] ctx     SSL context object.
1355 * @param [in, out] ssl     SSL object.
1356 * @param [in]      der     DER encoding.
1357 * @param [in]      format  Original format of data.
1358 * @param [in]      info    Encryption information.
1359 * @param [in]      heap    Dynamic memory allocation hint.
1360 * @param [in]      type    Type of data:
1361 *                            PRIVATEKEY_TYPE or ALT_PRIVATEKEY_TYPE.
1362 * @param [in]      algId   Algorithm id of key.
1363 * @return  0 on success.
1364 * @return  WOLFSSL_BAD_FILE when not able to decode.
1365 */
1366static int ProcessBufferPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1367    DerBuffer* der, int format, EncryptedInfo* info, void* heap, int type,
1368    int algId)
1369{
1370    int ret;
1371
1372    (void)info;
1373    (void)format;
1374
1375    /* Put the data into the SSL or SSL context object. */
1376    ret = ProcessBufferPrivKeyHandleDer(ctx, ssl, &der, type);
1377    if (ret == 0) {
1378        /* Try to decode the DER data. */
1379        ret = ProcessBufferTryDecode(ctx, ssl, der, &algId, heap, type);
1380    }
1381
1382#if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_PWDBASED)
1383    /* If private key type PKCS8 header wasn't already removed (algId == 0). */
1384    if (((ret != 0) || (algId == 0)) && (format != WOLFSSL_FILETYPE_PEM) &&
1385            (info->passwd_cb != NULL) && (algId == 0)) {
1386        /* Try to decrypt DER data as a PKCS#8 private key. */
1387        ret = ProcessBufferPrivPkcs8Dec(info, der, heap);
1388        if (ret >= 0) {
1389            /* Try to decode decrypted data.  */
1390            ret = ProcessBufferTryDecode(ctx, ssl, der, &algId, heap, type);
1391        }
1392    }
1393#endif /* WOLFSSL_ENCRYPTED_KEYS && !NO_PWDBASED */
1394
1395#ifdef WOLFSSL_BLIND_PRIVATE_KEY
1396    {
1397        int blindRet = 0;
1398#ifdef WOLFSSL_DUAL_ALG_CERTS
1399        if (type == ALT_PRIVATEKEY_TYPE) {
1400            if (ssl != NULL) {
1401                blindRet = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.altKey,
1402                    &ssl->buffers.altKeyMask);
1403            }
1404            else {
1405                blindRet = wolfssl_priv_der_blind(NULL, ctx->altPrivateKey,
1406                    &ctx->altPrivateKeyMask);
1407            }
1408        }
1409        else
1410#endif
1411        if (ssl != NULL) {
1412            blindRet = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.key,
1413                &ssl->buffers.keyMask);
1414        }
1415        else {
1416            blindRet = wolfssl_priv_der_blind(NULL, ctx->privateKey,
1417                &ctx->privateKeyMask);
1418        }
1419        if (ret == 0 && blindRet != 0)
1420            ret = blindRet;
1421    }
1422#endif
1423
1424    /* Check if we were able to determine algorithm id. */
1425    if ((ret == 0) && (algId == 0)) {
1426    #ifdef OPENSSL_EXTRA
1427        /* Decryption password is probably wrong. */
1428        if (info->passwd_cb) {
1429            WOLFSSL_EVPerr(0, -WOLFSSL_EVP_R_BAD_DECRYPT_E);
1430        }
1431    #endif
1432        WOLFSSL_ERROR(WOLFSSL_BAD_FILE);
1433        /* Unable to decode DER data. */
1434        ret = WOLFSSL_BAD_FILE;
1435    }
1436
1437    return ret;
1438}
1439
1440/* Use the key OID to determine have options.
1441 *
1442 * @param [in, out] ctx     SSL context object.
1443 * @param [in, out] ssl     SSL object.
1444 * @param [in]      keyOID  OID for public/private key.
1445 */
1446static void wolfssl_set_have_from_key_oid(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1447    int keyOID)
1448{
1449    /* Set which private key algorithm available based on key OID. */
1450    switch (keyOID) {
1451        case ECDSAk:
1452    #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
1453        case SM2k:
1454    #endif
1455    #ifdef HAVE_ED25519
1456        case ED25519k:
1457    #endif
1458    #ifdef HAVE_ED448
1459        case ED448k:
1460    #endif
1461            if (ssl != NULL) {
1462                ssl->options.haveECC = 1;
1463            }
1464            else {
1465                ctx->haveECC = 1;
1466            }
1467            break;
1468    #ifndef NO_RSA
1469        case RSAk:
1470        #ifdef WC_RSA_PSS
1471        case RSAPSSk:
1472        #endif
1473            if (ssl != NULL) {
1474                ssl->options.haveRSA = 1;
1475            }
1476            else {
1477                ctx->haveRSA = 1;
1478            }
1479            break;
1480    #endif
1481    #ifdef HAVE_FALCON
1482        case FALCON_LEVEL1k:
1483        case FALCON_LEVEL5k:
1484            if (ssl != NULL) {
1485                ssl->options.haveFalconSig = 1;
1486            }
1487            else {
1488                ctx->haveFalconSig = 1;
1489            }
1490            break;
1491    #endif /* HAVE_FALCON */
1492    #ifdef HAVE_DILITHIUM
1493        case ML_DSA_LEVEL2k:
1494        case ML_DSA_LEVEL3k:
1495        case ML_DSA_LEVEL5k:
1496        #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
1497        case DILITHIUM_LEVEL2k:
1498        case DILITHIUM_LEVEL3k:
1499        case DILITHIUM_LEVEL5k:
1500        #endif
1501            if (ssl != NULL) {
1502                ssl->options.haveDilithiumSig = 1;
1503            }
1504            else {
1505                ctx->haveDilithiumSig = 1;
1506            }
1507            break;
1508    #endif /* HAVE_DILITHIUM */
1509        default:
1510            WOLFSSL_MSG("Cert key not supported");
1511            break;
1512        }
1513}
1514
1515/* Set which private key algorithm we have against SSL or SSL context object.
1516 *
1517 * Precondition: ctx or ssl is not NULL.
1518 *
1519 * @param [in, out] ctx     SSL context object.
1520 * @param [in, out] ssl     SSL object.
1521 * @param [in]      cert    Decode certificate.
1522 */
1523static void ProcessBufferCertSetHave(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1524    DecodedCert* cert)
1525{
1526    if (ssl != NULL) {
1527        /* Reset signatures we have in SSL. */
1528        ssl->options.haveECDSAsig = 0;
1529        ssl->options.haveFalconSig = 0;
1530        ssl->options.haveDilithiumSig = 0;
1531    }
1532
1533    /* Set which signature we have based on the type in the cert. */
1534    switch (cert->signatureOID) {
1535        case CTC_SHAwECDSA:
1536        case CTC_SHA256wECDSA:
1537        case CTC_SHA384wECDSA:
1538        case CTC_SHA512wECDSA:
1539    #ifdef HAVE_ED25519
1540        case CTC_ED25519:
1541    #endif
1542    #ifdef HAVE_ED448
1543        case CTC_ED448:
1544    #endif
1545    #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
1546        case CTC_SM3wSM2:
1547    #endif
1548            WOLFSSL_MSG("ECDSA/ED25519/ED448 cert signature");
1549            if (ssl) {
1550                ssl->options.haveECDSAsig = 1;
1551            }
1552            else if (ctx) {
1553                ctx->haveECDSAsig = 1;
1554            }
1555            break;
1556    #ifdef HAVE_FALCON
1557        case CTC_FALCON_LEVEL1:
1558        case CTC_FALCON_LEVEL5:
1559            WOLFSSL_MSG("Falcon cert signature");
1560            if (ssl) {
1561                ssl->options.haveFalconSig = 1;
1562            }
1563            else if (ctx) {
1564                ctx->haveFalconSig = 1;
1565            }
1566            break;
1567    #endif
1568    #ifdef HAVE_DILITHIUM
1569        case CTC_ML_DSA_LEVEL2:
1570        case CTC_ML_DSA_LEVEL3:
1571        case CTC_ML_DSA_LEVEL5:
1572        #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
1573        case CTC_DILITHIUM_LEVEL2:
1574        case CTC_DILITHIUM_LEVEL3:
1575        case CTC_DILITHIUM_LEVEL5:
1576        #endif /* WOLFSSL_DILITHIUM_FIPS204_DRAFT */
1577            WOLFSSL_MSG("Dilithium cert signature");
1578            if (ssl) {
1579                ssl->options.haveDilithiumSig = 1;
1580            }
1581            else if (ctx) {
1582                ctx->haveDilithiumSig = 1;
1583            }
1584            break;
1585    #endif
1586        default:
1587            WOLFSSL_MSG("Cert signature not supported");
1588            break;
1589    }
1590
1591#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448) || \
1592    defined(HAVE_FALCON) || defined(HAVE_DILITHIUM) || !defined(NO_RSA)
1593    #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
1594    /* Set the private key curve OID. */
1595    if (ssl != NULL) {
1596        ssl->pkCurveOID = cert->pkCurveOID;
1597    }
1598    else if (ctx) {
1599        ctx->pkCurveOID = cert->pkCurveOID;
1600    }
1601    #endif
1602#ifndef WC_STRICT_SIG
1603    if ((ctx != NULL) || (ssl != NULL)) {
1604        wolfssl_set_have_from_key_oid(ctx, ssl, (int)cert->keyOID);
1605    }
1606#else
1607    /* Set whether ECC is available based on signature available. */
1608    if (ssl != NULL) {
1609        ssl->options.haveECC = ssl->options.haveECDSAsig;
1610    }
1611    else if (ctx) {
1612        ctx->haveECC = ctx->haveECDSAsig;
1613    }
1614#endif /* !WC_STRICT_SIG */
1615#endif
1616}
1617
1618/* Check key size is valid.
1619 *
1620 * Precondition: ctx or ssl is not NULL.
1621 *
1622 * @param [in] min    Minimum key size.
1623 * @param [in] max    Maximum key size.
1624 * @param [in] keySz  Key size.
1625 * @param [in] err    Error value to return when key size is invalid.
1626 * @return  0 on success.
1627 * @return  err when verifying and min is less than 0 or key size is invalid.
1628 */
1629#define CHECK_KEY_SZ(min, max, keySz, err)                                     \
1630    (((min) < 0) || ((keySz) < (min)) || ((keySz) > (max))) ? (err) : 0
1631
1632/* Check public key in certificate.
1633 *
1634 * @param [in, out] ctx   SSL context object.
1635 * @param [in, out] ssl   SSL object.
1636 * @param [in]      cert  Certificate object.
1637 * @return  0 on success.
1638 * @return  Non-zero when an error occurred.
1639 */
1640static int ProcessBufferCertPublicKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1641    DecodedCert* cert, int checkKeySz)
1642{
1643    int ret = 0;
1644    byte keyType = 0;
1645    int keySz = 0;
1646#ifndef NO_RSA
1647    word32 idx;
1648#endif
1649    if (ctx == NULL && ssl == NULL) {
1650        return BAD_FUNC_ARG;
1651    }
1652
1653    /* Get key size and check unless not verifying. */
1654    switch (cert->keyOID) {
1655#ifndef NO_RSA
1656    #ifdef WC_RSA_PSS
1657        case RSAPSSk:
1658    #endif
1659        case RSAk:
1660            keyType = rsa_sa_algo;
1661            /* Determine RSA key size by parsing public key */
1662            idx = 0;
1663            ret = wc_RsaPublicKeyDecode_ex(cert->publicKey, &idx,
1664                cert->pubKeySize, NULL, (word32*)&keySz, NULL, NULL);
1665            if ((ret == 0) && checkKeySz) {
1666                ret = CHECK_KEY_SZ(ssl ? ssl->options.minRsaKeySz :
1667                    ctx->minRsaKeySz, RSA_MAX_SIZE / 8, keySz, RSA_KEY_SIZE_E);
1668            }
1669    #ifdef WC_RSA_PSS
1670            if (ssl) {
1671                ssl->useRsaPss = cert->keyOID == RSAPSSk;
1672            }
1673            if (ctx) {
1674                ctx->useRsaPss = cert->keyOID == RSAPSSk;
1675            }
1676    #endif
1677            break;
1678#endif /* !NO_RSA */
1679    #ifdef HAVE_ECC
1680        case ECDSAk:
1681            keyType = ecc_dsa_sa_algo;
1682            /* Determine ECC key size based on curve */
1683        #ifdef WOLFSSL_CUSTOM_CURVES
1684            if ((cert->pkCurveOID == 0) && (cert->pkCurveSize != 0)) {
1685                keySz = cert->pkCurveSize;
1686            }
1687            else
1688        #endif
1689            {
1690                keySz = wc_ecc_get_curve_size_from_id(wc_ecc_get_oid(
1691                    cert->pkCurveOID, NULL, NULL));
1692            }
1693
1694            if (checkKeySz) {
1695                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1696                     ctx->minEccKeySz, (MAX_ECC_BITS + 7) / 8, keySz,
1697                     ECC_KEY_SIZE_E);
1698            }
1699            break;
1700    #endif /* HAVE_ECC */
1701    #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
1702        case SM2k:
1703            keyType = sm2_sa_algo;
1704            /* Determine ECC key size based on curve */
1705            keySz = WOLFSSL_SM2_KEY_BITS / 8;
1706            if (checkKeySz) {
1707                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1708                    ctx->minEccKeySz, (MAX_ECC_BITS + 7) / 8, keySz,
1709                    ECC_KEY_SIZE_E);
1710            }
1711            break;
1712    #endif /* WOLFSSL_SM2 && WOLFSSL_SM3 */
1713    #ifdef HAVE_ED25519
1714        case ED25519k:
1715            keyType = ed25519_sa_algo;
1716            /* ED25519 is fixed key size */
1717            keySz = ED25519_KEY_SIZE;
1718            if (checkKeySz) {
1719                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1720                    ctx->minEccKeySz, ED25519_KEY_SIZE, keySz, ECC_KEY_SIZE_E);
1721            }
1722            break;
1723    #endif /* HAVE_ED25519 */
1724    #ifdef HAVE_ED448
1725        case ED448k:
1726            keyType = ed448_sa_algo;
1727            /* ED448 is fixed key size */
1728            keySz = ED448_KEY_SIZE;
1729            if (checkKeySz) {
1730                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1731                    ctx->minEccKeySz, ED448_KEY_SIZE, keySz, ECC_KEY_SIZE_E);
1732            }
1733            break;
1734    #endif /* HAVE_ED448 */
1735    #if defined(HAVE_FALCON)
1736        case FALCON_LEVEL1k:
1737            keyType = falcon_level1_sa_algo;
1738            /* Falcon is fixed key size */
1739            keySz = FALCON_LEVEL1_KEY_SIZE;
1740            if (checkKeySz) {
1741                ret = CHECK_KEY_SZ(ssl ? ssl->options.minFalconKeySz :
1742                    ctx->minFalconKeySz, FALCON_MAX_KEY_SIZE, keySz,
1743                    FALCON_KEY_SIZE_E);
1744            }
1745            break;
1746        case FALCON_LEVEL5k:
1747            keyType = falcon_level5_sa_algo;
1748            /* Falcon is fixed key size */
1749            keySz = FALCON_LEVEL5_KEY_SIZE;
1750            if (checkKeySz) {
1751                ret = CHECK_KEY_SZ(ssl ? ssl->options.minFalconKeySz :
1752                    ctx->minFalconKeySz, FALCON_MAX_KEY_SIZE, keySz,
1753                    FALCON_KEY_SIZE_E);
1754            }
1755            break;
1756    #endif /* HAVE_FALCON */
1757    #if defined(HAVE_DILITHIUM)
1758        #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
1759        case DILITHIUM_LEVEL2k:
1760            keyType = dilithium_level2_sa_algo;
1761            /* Dilithium is fixed key size */
1762            keySz = DILITHIUM_LEVEL2_KEY_SIZE;
1763            if (checkKeySz) {
1764                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1765                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1766                    DILITHIUM_KEY_SIZE_E);
1767            }
1768            break;
1769        case DILITHIUM_LEVEL3k:
1770            keyType = dilithium_level3_sa_algo;
1771            /* Dilithium is fixed key size */
1772            keySz = DILITHIUM_LEVEL3_KEY_SIZE;
1773            if (checkKeySz) {
1774                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1775                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1776                    DILITHIUM_KEY_SIZE_E);
1777            }
1778            break;
1779        case DILITHIUM_LEVEL5k:
1780            keyType = dilithium_level5_sa_algo;
1781            /* Dilithium is fixed key size */
1782            keySz = DILITHIUM_LEVEL5_KEY_SIZE;
1783            if (checkKeySz) {
1784                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1785                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1786                    DILITHIUM_KEY_SIZE_E);
1787            }
1788            break;
1789        #endif /* WOLFSSL_DILITHIUM_FIPS204_DRAFT */
1790        case ML_DSA_LEVEL2k:
1791            keyType = dilithium_level2_sa_algo;
1792            /* Dilithium is fixed key size */
1793            keySz = ML_DSA_LEVEL2_KEY_SIZE;
1794            if (checkKeySz) {
1795                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1796                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1797                    DILITHIUM_KEY_SIZE_E);
1798            }
1799            break;
1800        case ML_DSA_LEVEL3k:
1801            keyType = dilithium_level3_sa_algo;
1802            /* Dilithium is fixed key size */
1803            keySz = ML_DSA_LEVEL3_KEY_SIZE;
1804            if (checkKeySz) {
1805                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1806                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1807                    DILITHIUM_KEY_SIZE_E);
1808            }
1809            break;
1810        case ML_DSA_LEVEL5k:
1811            keyType = dilithium_level5_sa_algo;
1812            /* Dilithium is fixed key size */
1813            keySz = ML_DSA_LEVEL5_KEY_SIZE;
1814            if (checkKeySz) {
1815                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1816                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1817                    DILITHIUM_KEY_SIZE_E);
1818            }
1819            break;
1820    #endif /* HAVE_DILITHIUM */
1821
1822        default:
1823            WOLFSSL_MSG("No key size check done on public key in certificate");
1824            break;
1825    }
1826
1827    /* Store the type and key size as there may not be a private key set. */
1828    if (ssl != NULL) {
1829        ssl->buffers.keyType = keyType;
1830        ssl->buffers.keySz = keySz;
1831    }
1832    else {
1833        ctx->privateKeyType = keyType;
1834        ctx->privateKeySz = keySz;
1835    }
1836
1837    return ret;
1838}
1839
1840#ifdef WOLFSSL_DUAL_ALG_CERTS
1841static int ProcessBufferCertAltPublicKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1842    DecodedCert* cert, int checkKeySz)
1843{
1844    int ret = 0;
1845    void* heap = WOLFSSL_HEAP(ctx, ssl);
1846    byte keyType = 0;
1847    int keySz = 0;
1848#ifndef NO_RSA
1849    word32 idx;
1850#endif
1851
1852    /* Check alternative key size of cert. */
1853    switch (cert->sapkiOID) {
1854        /* No OID set. */
1855        case 0:
1856            if (cert->sapkiLen != 0) {
1857                /* Have the alternative key data but no OID. */
1858                ret = NOT_COMPILED_IN;
1859            }
1860            break;
1861
1862#ifndef NO_RSA
1863    #ifdef WC_RSA_PSS
1864        case RSAPSSk:
1865    #endif
1866        case RSAk:
1867            keyType = rsa_sa_algo;
1868            /* Determine RSA key size by parsing public key */
1869            idx = 0;
1870            ret = wc_RsaPublicKeyDecode_ex(cert->sapkiDer, &idx,
1871                cert->sapkiLen, NULL, (word32*)&keySz, NULL, NULL);
1872            if ((ret == 0) && checkKeySz) {
1873                ret = CHECK_KEY_SZ(ssl ? ssl->options.minRsaKeySz :
1874                    ctx->minRsaKeySz, RSA_MAX_SIZE / 8, keySz, RSA_KEY_SIZE_E);
1875            }
1876            break;
1877#endif /* !NO_RSA */
1878    #ifdef HAVE_ECC
1879        case ECDSAk:
1880        {
1881            WC_DECLARE_VAR(temp_key, ecc_key, 1, 0);
1882            keyType = ecc_dsa_sa_algo;
1883
1884            WC_ALLOC_VAR_EX(temp_key, ecc_key, 1, heap, DYNAMIC_TYPE_ECC,
1885                ret=MEMORY_E);
1886
1887            /* Determine ECC key size. We have to decode the sapki for
1888             * that. */
1889            if (ret == 0) {
1890                ret = wc_ecc_init_ex(temp_key, heap, INVALID_DEVID);
1891                if (ret == 0) {
1892                    idx = 0;
1893                    ret = wc_EccPublicKeyDecode(cert->sapkiDer, &idx, temp_key,
1894                        cert->sapkiLen);
1895                    if (ret == 0) {
1896                        keySz = wc_ecc_size(temp_key);
1897                    }
1898                    wc_ecc_free(temp_key);
1899                }
1900            }
1901            WC_FREE_VAR_EX(temp_key, heap, DYNAMIC_TYPE_ECC);
1902
1903            if ((ret == 0) && checkKeySz) {
1904                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1905                     ctx->minEccKeySz, (MAX_ECC_BITS + 7) / 8, keySz,
1906                     ECC_KEY_SIZE_E);
1907            }
1908            break;
1909        }
1910    #endif /* HAVE_ECC */
1911    #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
1912        case SM2k:
1913            keyType = sm2_sa_algo;
1914            /* Determine ECC key size based on curve */
1915            keySz = WOLFSSL_SM2_KEY_BITS / 8;
1916            if (checkKeySz) {
1917                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1918                    ctx->minEccKeySz, (MAX_ECC_BITS + 7) / 8, keySz,
1919                    ECC_KEY_SIZE_E);
1920            }
1921            break;
1922    #endif /* WOLFSSL_SM2 && WOLFSSL_SM3 */
1923    #ifdef HAVE_ED25519
1924        case ED25519k:
1925            keyType = ed25519_sa_algo;
1926            /* ED25519 is fixed key size */
1927            keySz = ED25519_KEY_SIZE;
1928            if (checkKeySz) {
1929                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1930                    ctx->minEccKeySz, ED25519_KEY_SIZE, keySz, ECC_KEY_SIZE_E);
1931            }
1932            break;
1933    #endif /* HAVE_ED25519 */
1934    #ifdef HAVE_ED448
1935        case ED448k:
1936            keyType = ed448_sa_algo;
1937            /* ED448 is fixed key size */
1938            keySz = ED448_KEY_SIZE;
1939            if (checkKeySz) {
1940                ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
1941                    ctx->minEccKeySz, ED448_KEY_SIZE, keySz, ECC_KEY_SIZE_E);
1942            }
1943            break;
1944    #endif /* HAVE_ED448 */
1945    #if defined(HAVE_FALCON)
1946        case FALCON_LEVEL1k:
1947            keyType = falcon_level1_sa_algo;
1948            /* Falcon is fixed key size */
1949            keySz = FALCON_LEVEL1_KEY_SIZE;
1950            if (checkKeySz) {
1951                ret = CHECK_KEY_SZ(ssl ? ssl->options.minFalconKeySz :
1952                    ctx->minFalconKeySz, FALCON_MAX_KEY_SIZE, keySz,
1953                    FALCON_KEY_SIZE_E);
1954            }
1955            break;
1956        case FALCON_LEVEL5k:
1957            keyType = falcon_level5_sa_algo;
1958            /* Falcon is fixed key size */
1959            keySz = FALCON_LEVEL5_KEY_SIZE;
1960            if (checkKeySz) {
1961                ret = CHECK_KEY_SZ(ssl ? ssl->options.minFalconKeySz :
1962                    ctx->minFalconKeySz, FALCON_MAX_KEY_SIZE, keySz,
1963                    FALCON_KEY_SIZE_E);
1964            }
1965            break;
1966    #endif /* HAVE_FALCON */
1967    #if defined(HAVE_DILITHIUM)
1968        #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
1969        case DILITHIUM_LEVEL2k:
1970            keyType = dilithium_level2_sa_algo;
1971            /* Dilithium is fixed key size */
1972            keySz = DILITHIUM_LEVEL2_KEY_SIZE;
1973            if (checkKeySz) {
1974                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1975                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1976                    DILITHIUM_KEY_SIZE_E);
1977            }
1978            break;
1979        case DILITHIUM_LEVEL3k:
1980            keyType = dilithium_level3_sa_algo;
1981            /* Dilithium is fixed key size */
1982            keySz = DILITHIUM_LEVEL3_KEY_SIZE;
1983            if (checkKeySz) {
1984                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1985                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1986                    DILITHIUM_KEY_SIZE_E);
1987            }
1988            break;
1989        case DILITHIUM_LEVEL5k:
1990            keyType = dilithium_level5_sa_algo;
1991            /* Dilithium is fixed key size */
1992            keySz = DILITHIUM_LEVEL5_KEY_SIZE;
1993            if (checkKeySz) {
1994                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
1995                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
1996                    DILITHIUM_KEY_SIZE_E);
1997            }
1998            break;
1999        #endif /* WOLFSSL_DILITHIUM_FIPS204_DRAFT */
2000        case ML_DSA_LEVEL2k:
2001            keyType = dilithium_level2_sa_algo;
2002            /* Dilithium is fixed key size */
2003            keySz = ML_DSA_LEVEL2_KEY_SIZE;
2004            if (checkKeySz) {
2005                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
2006                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
2007                    DILITHIUM_KEY_SIZE_E);
2008            }
2009            break;
2010        case ML_DSA_LEVEL3k:
2011            keyType = dilithium_level3_sa_algo;
2012            /* Dilithium is fixed key size */
2013            keySz = ML_DSA_LEVEL3_KEY_SIZE;
2014            if (checkKeySz) {
2015                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
2016                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
2017                    DILITHIUM_KEY_SIZE_E);
2018            }
2019            break;
2020        case ML_DSA_LEVEL5k:
2021            keyType = dilithium_level5_sa_algo;
2022            /* Dilithium is fixed key size */
2023            keySz = ML_DSA_LEVEL5_KEY_SIZE;
2024            if (checkKeySz) {
2025                ret = CHECK_KEY_SZ(ssl ? ssl->options.minDilithiumKeySz :
2026                    ctx->minDilithiumKeySz, DILITHIUM_MAX_KEY_SIZE, keySz,
2027                    DILITHIUM_KEY_SIZE_E);
2028            }
2029            break;
2030    #endif /* HAVE_DILITHIUM */
2031
2032        default:
2033            /* In this case, there was an OID that we didn't recognize.
2034             * This is an error. Use not compiled in because likely the
2035             * given algorithm was not enabled. */
2036            ret = NOT_COMPILED_IN;
2037            WOLFSSL_MSG("No alt key size check done on certificate");
2038            break;
2039    }
2040
2041    if (ssl != NULL) {
2042        ssl->buffers.altKeyType = (byte)keyType;
2043        ssl->buffers.altKeySz = keySz;
2044    }
2045    else if (ctx != NULL) {
2046        ctx->altPrivateKeyType = (byte)keyType;
2047        ctx->altPrivateKeySz = keySz;
2048    }
2049
2050    return ret;
2051}
2052#endif /* WOLFSSL_DUAL_ALG_CERTS */
2053
2054/* Parse the certificate and pull out information for TLS handshake.
2055 *
2056 * @param [in, out] ctx   SSL context object.
2057 * @param [in, out] ssl   SSL object.
2058 * @param [in]      der   DER encoded X509 certificate.
2059 * @return  0 on success.
2060 * @return  MEMORY_E when dynamic memory allocation fails.
2061 * @return  WOLFSSL_BAD_FILE when decoding certificate fails.
2062 */
2063static int ProcessBufferCert(WOLFSSL_CTX* ctx, WOLFSSL* ssl, DerBuffer* der)
2064{
2065    int ret = 0;
2066    void* heap = WOLFSSL_HEAP(ctx, ssl);
2067#if defined(HAVE_RPK)
2068    RpkState* rpkState = ssl ? &ssl->options.rpkState : &ctx->rpkState;
2069#endif
2070    WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
2071
2072    /* Allocate memory for certificate to be decoded into. */
2073    WC_ALLOC_VAR_EX(cert, DecodedCert, 1, heap, DYNAMIC_TYPE_DCERT,
2074        ret=MEMORY_E);
2075    if (WC_VAR_OK(cert))
2076    {
2077        /* Get device id from SSL context or SSL object. */
2078        int devId = wolfSSL_CTX_GetDevId(ctx, ssl);
2079
2080        WOLFSSL_MSG("Checking cert signature type");
2081        /* Initialize certificate object. */
2082        InitDecodedCert_ex(cert, der->buffer, der->length, heap, devId);
2083
2084        /* Decode up to and including public key. */
2085        if (DecodeToKey(cert, 0) < 0) {
2086            WOLFSSL_MSG("Decode to key failed");
2087            ret = WOLFSSL_BAD_FILE;
2088        }
2089        if (ret == 0) {
2090            int checkKeySz = 1;
2091
2092        #if defined(HAVE_RPK)
2093            /* Store whether the crtificate is a raw public key. */
2094            rpkState->isRPKLoaded = cert->isRPK;
2095        #endif /* HAVE_RPK */
2096
2097            /* Set which private key algorithm we have. */
2098            ProcessBufferCertSetHave(ctx, ssl, cert);
2099
2100            /* Don't check if verification is disabled for SSL. */
2101            if ((ssl != NULL) && ssl->options.verifyNone) {
2102                checkKeySz = 0;
2103            }
2104            /* Don't check if no SSL object verification is disabled for SSL
2105             * context. */
2106            else if ((ssl == NULL) && (ctx != NULL) && ctx->verifyNone) {
2107                checkKeySz = 0;
2108            }
2109
2110            /* Check public key size. */
2111            ret = ProcessBufferCertPublicKey(ctx, ssl, cert, checkKeySz);
2112        #ifdef WOLFSSL_DUAL_ALG_CERTS
2113            if (ret == 0) {
2114                ret = ProcessBufferCertAltPublicKey(ctx, ssl, cert, checkKeySz);
2115            }
2116        #endif
2117        }
2118    }
2119
2120    /* Dispose of dynamic memory in certificate object. */
2121    FreeDecodedCert(cert);
2122    WC_FREE_VAR_EX(cert, heap, DYNAMIC_TYPE_DCERT);
2123    return ret;
2124}
2125
2126/* Handle storing the DER encoding of the certificate.
2127 *
2128 * Do not free der outside of this function.
2129 *
2130 * @param [in, out] ctx     SSL context object.
2131 * @param [in, out] ssl     SSL object.
2132 * @param [in]      der     DER encoded certificate.
2133 * @param [in]      type    Type of data:
2134 *                            CERT_TYPE, CA_TYPE or TRUSTED_PEER_TYPE.
2135 * @param [in]      verify  What verification to do.
2136 * @return  0 on success.
2137 * @return  BAD_FUNC_ARG when type is CA_TYPE and ctx is NULL.
2138 * @return  WOLFSSL_BAD_CERTTYPE when data type is not supported.
2139 */
2140static int ProcessBufferCertHandleDer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
2141    DerBuffer* der, int type, int verify)
2142{
2143    int ret = 0;
2144
2145    /* CA certificate to verify with. */
2146    if (type == CA_TYPE) {
2147#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
2148        /* TEST ONLY CODE:
2149         * Store the DER encoding of the CA certificate so we can append it to
2150         * the list of trusted CA certificates if the subsequent call to AddCA
2151         * is successful */
2152        word32 derLen;
2153        byte* derBuf;
2154        if (ctx->doAppleNativeCertValidationFlag == 1) {
2155            WOLFSSL_MSG("ANCV Test: copy DER CA cert");
2156            derLen = der->length;
2157            derBuf = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2158            if (derBuf == NULL) {
2159                return MEMORY_E;
2160            }
2161            XMEMCPY(derBuf, der->buffer, derLen);
2162        }
2163        else {
2164            (void)derLen;
2165            (void)derBuf;
2166        }
2167#endif
2168        /* verify CA unless user set to no verify */
2169        ret = AddCA(ctx->cm, &der, WOLFSSL_USER_CA, verify);
2170
2171#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
2172        /* TEST ONLY CODE:
2173         * Append the DER encoded CA certificate to the list of trusted CA
2174         * certificates so we can inject them at verification time */
2175        if (ret == 1 && ctx->doAppleNativeCertValidationFlag == 1) {
2176            WOLFSSL_MSG("ANCV Test: Appending CA to cert list");
2177            ret = wolfSSL_TestAppleNativeCertValidation_AppendCA(ctx, derBuf,
2178                (int)derLen);
2179            if (ret == WOLFSSL_SUCCESS) {
2180                WOLFSSL_MSG("ANCV Test: Clearing CA table");
2181                /* Clear the CA table so we can ensure they won't be used for
2182                 * verification */
2183                ret = wolfSSL_CertManagerUnloadCAs(ctx->cm);
2184                if (ret == WOLFSSL_SUCCESS) {
2185                    ret = 0;
2186                }
2187            }
2188            XFREE(derBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2189        }
2190#endif /* !WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION */
2191
2192        if (ret == 1) {
2193            ret = 0;
2194        }
2195    }
2196#ifdef WOLFSSL_TRUST_PEER_CERT
2197    /* Trusted certificate to verify peer with. */
2198    else if (type == TRUSTED_PEER_TYPE) {
2199        WOLFSSL_CERT_MANAGER* cm;
2200
2201        /* Get certificate manager to add certificate to. */
2202        if (ctx != NULL) {
2203            cm = ctx->cm;
2204        }
2205        else {
2206            SSL_CM_WARNING(ssl);
2207            cm = SSL_CM(ssl);
2208        }
2209        /* Add certificate as a trusted peer. */
2210        ret = AddTrustedPeer(cm, &der, verify);
2211        if (ret != 1) {
2212            WOLFSSL_MSG("Error adding trusted peer");
2213        }
2214    }
2215#endif /* WOLFSSL_TRUST_PEER_CERT */
2216    /* Leaf certificate - our certificate. */
2217    else if (type == CERT_TYPE) {
2218        if (ssl != NULL) {
2219            /* Free previous certificate if we own it. */
2220            if (ssl->buffers.weOwnCert) {
2221                FreeDer(&ssl->buffers.certificate);
2222            #ifdef KEEP_OUR_CERT
2223                /* Dispose of X509 version of certificate. */
2224                wolfSSL_X509_free(ssl->ourCert);
2225                ssl->ourCert = NULL;
2226            #endif
2227            }
2228            /* Store certificate as ours. */
2229            ssl->buffers.certificate = der;
2230        #ifdef KEEP_OUR_CERT
2231            ssl->keepCert = 1; /* hold cert for ssl lifetime */
2232        #endif
2233            /* We have to free the certificate buffer. */
2234            ssl->buffers.weOwnCert = 1;
2235            /* ourCert is created on demand. */
2236        }
2237        else if (ctx != NULL) {
2238            /* Free previous certificate. */
2239            FreeDer(&ctx->certificate); /* Make sure previous is free'd */
2240        #ifdef KEEP_OUR_CERT
2241            /* Dispose of X509 version of certificate if we own it. */
2242            if (ctx->ownOurCert) {
2243                wolfSSL_X509_free(ctx->ourCert);
2244            }
2245            ctx->ourCert = NULL;
2246        #endif
2247            /* Store certificate as ours. */
2248            ctx->certificate = der;
2249            /* ourCert is created on demand. */
2250        }
2251    }
2252    else {
2253        /* Dispose of DER buffer. */
2254        FreeDer(&der);
2255        /* Not a certificate type supported. */
2256        ret = WOLFSSL_BAD_CERTTYPE;
2257    }
2258
2259    return ret;
2260}
2261
2262/* Process certificate based on type.
2263 *
2264 * @param [in, out] ctx     SSL context object.
2265 * @param [in, out] ssl     SSL object.
2266 * @param [in]      buff    Buffer holding original data.
2267 * @param [in]      sz      Size of data in buffer.
2268 * @param [in]      der     DER encoding of certificate.
2269 * @param [in]      format  Format of data.
2270 * @param [in]      type    Type of data:
2271 *                            CERT_TYPE, CA_TYPE or TRUSTED_PEER_TYPE.
2272 * @param [in]      verify  What verification to do.
2273 * @return  0 on success.
2274 * @return  WOLFSSL_FATAL_ERROR on failure.
2275 */
2276static int ProcessBufferCertTypes(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
2277    const unsigned char* buff, long sz, DerBuffer* der, int format, int type,
2278    int verify)
2279{
2280    int ret;
2281
2282    (void)buff;
2283    (void)sz;
2284    (void)format;
2285
2286    ret = ProcessBufferCertHandleDer(ctx, ssl, der, type, verify);
2287    if ((ret == 0) && (type == CERT_TYPE)) {
2288        /* Process leaf certificate. */
2289        ret = ProcessBufferCert(ctx, ssl, der);
2290    }
2291#if !defined(NO_WOLFSSL_CM_VERIFY) && (!defined(NO_WOLFSSL_CLIENT) || \
2292    !defined(WOLFSSL_NO_CLIENT_AUTH))
2293    /* Hand bad CA or user certificate to callback. */
2294    if ((ret < 0) && ((type == CA_TYPE) || (type == CERT_TYPE))) {
2295        /* Check for verification callback that may override error. */
2296        if ((ctx != NULL) && (ctx->cm != NULL) &&
2297                (ctx->cm->verifyCallback != NULL)) {
2298            /* Verify and use callback. */
2299            ret = CM_VerifyBuffer_ex(ctx->cm, buff, sz, format, ret);
2300            /* Convert error. */
2301            if (ret == 0) {
2302                ret = WOLFSSL_FATAL_ERROR;
2303            }
2304            if (ret == 1) {
2305                ret = 0;
2306            }
2307        }
2308    }
2309#endif /* NO_WOLFSSL_CM_VERIFY */
2310
2311    return ret;
2312}
2313
2314/* Reset the cipher suites based on updated private key or certificate.
2315 *
2316 * @param [in, out] ctx     SSL context object.
2317 * @param [in, out] ssl     SSL object.
2318 * @param [in]      type    Type of certificate.
2319 * @return  0 on success.
2320 * @return  WOLFSSL_FATAL_ERROR when allocation fails.
2321 */
2322static int ProcessBufferResetSuites(WOLFSSL_CTX* ctx, WOLFSSL* ssl, int type)
2323{
2324    int ret = 0;
2325
2326    /* Reset suites of SSL object. */
2327    if (ssl != NULL) {
2328        if (ssl->options.side == WOLFSSL_SERVER_END) {
2329            /* Allocate memory for suites. */
2330            if (AllocateSuites(ssl) != 0) {
2331                ret = WOLFSSL_FATAL_ERROR;
2332            }
2333            else {
2334                /* Determine cipher suites based on what we have. */
2335                InitSuites(ssl->suites, ssl->version, ssl->buffers.keySz,
2336                    WOLFSSL_HAVE_RSA, SSL_HAVE_PSK(ssl), ssl->options.haveDH,
2337                    ssl->options.haveECDSAsig, ssl->options.haveECC, TRUE,
2338                    ssl->options.haveStaticECC,
2339                    ssl->options.useAnon, TRUE,
2340                    TRUE, TRUE, TRUE, ssl->options.side);
2341            }
2342        }
2343    }
2344    /* Reset suites of SSL context object. */
2345    else if ((type == CERT_TYPE) && (ctx->method->side == WOLFSSL_SERVER_END)) {
2346        /* Allocate memory for suites. */
2347        if (AllocateCtxSuites(ctx) != 0) {
2348            ret = WOLFSSL_FATAL_ERROR;
2349        }
2350        else {
2351            /* Determine cipher suites based on what we have. */
2352            InitSuites(ctx->suites, ctx->method->version, ctx->privateKeySz,
2353                WOLFSSL_HAVE_RSA, CTX_HAVE_PSK(ctx), ctx->haveDH,
2354                ctx->haveECDSAsig, ctx->haveECC, TRUE, ctx->haveStaticECC,
2355                CTX_USE_ANON(ctx),
2356                TRUE, TRUE, TRUE, TRUE, ctx->method->side);
2357        }
2358    }
2359
2360    return ret;
2361}
2362
2363#ifndef WOLFSSL_DUAL_ALG_CERTS
2364    /* Determine whether the type is for a private key. */
2365    #define IS_PRIVKEY_TYPE(type) ((type) == PRIVATEKEY_TYPE)
2366#else
2367    /* Determine whether the type is for a private key. */
2368    #define IS_PRIVKEY_TYPE(type) (((type) == PRIVATEKEY_TYPE) ||   \
2369                                   ((type) == ALT_PRIVATEKEY_TYPE))
2370#endif
2371
2372/* Process a buffer of data.
2373 *
2374 * Data type is a private key or a certificate.
2375 * The format can be ASN.1 (DER) or PEM.
2376 *
2377 * @param [in, out] ctx        SSL context object.
2378 * @param [in]      buff       Buffer holding data.
2379 * @param [in]      sz         Size of data in buffer.
2380 * @param [in]      format     Format of data:
2381 *                               WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
2382 * @param [in]      type       Type of data:
2383 *                               CERT_TYPE, CA_TYPE, TRUSTED_PEER_TYPE,
2384 *                               PRIVATEKEY_TYPE or ALT_PRIVATEKEY_TYPE.
2385 * @param [in, out] ssl        SSL object.
2386 * @param [out]     used       Number of bytes consumed.
2387 * @param [in[      userChain  Whether this certificate is for user's chain.
2388 * @param [in]      verify     How to verify certificate.
2389 * @param [in]      source_name Associated filename or other source ID.
2390 * @return  1 on success.
2391 * @return  Less than 1 on failure.
2392 */
2393int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff, long sz,
2394    int format, int type, WOLFSSL* ssl, long* used, int userChain, int verify,
2395    const char *source_name)
2396{
2397    DerBuffer*    der = NULL;
2398    int           ret = 0;
2399    void*         heap = WOLFSSL_HEAP(ctx, ssl);
2400    WC_DECLARE_VAR(info, EncryptedInfo, 1, 0);
2401    int           algId = 0;
2402#ifdef WOLFSSL_DEBUG_CERTIFICATE_LOADS
2403    long usedAtStart = used ? *used : 0L;
2404#else
2405    (void)source_name;
2406#endif
2407
2408    WOLFSSL_ENTER("ProcessBuffer");
2409
2410    /* Check data format is supported. */
2411    if ((format != WOLFSSL_FILETYPE_ASN1) && (format != WOLFSSL_FILETYPE_PEM)) {
2412        ret = WOLFSSL_BAD_FILETYPE;
2413    }
2414    /* Need an object to store certificate into. */
2415    if ((ret == 0) && (ctx == NULL) && (ssl == NULL)) {
2416        ret = BAD_FUNC_ARG;
2417    }
2418    /* CA certificates go into the SSL context object. */
2419    if ((ret == 0) && (ctx == NULL) && (type == CA_TYPE)) {
2420        ret = BAD_FUNC_ARG;
2421    }
2422    /* This API does not handle CHAIN_CERT_TYPE */
2423    if ((ret == 0) && (type == CHAIN_CERT_TYPE)) {
2424        ret = BAD_FUNC_ARG;
2425    }
2426
2427#ifdef WOLFSSL_SMALL_STACK
2428    if (ret == 0) {
2429        /* Allocate memory for encryption information. */
2430        info = (EncryptedInfo*)XMALLOC(sizeof(EncryptedInfo), heap,
2431            DYNAMIC_TYPE_ENCRYPTEDINFO);
2432        if (info == NULL) {
2433            ret = MEMORY_E;
2434        }
2435    }
2436#endif
2437    if (ret == 0) {
2438        /* Initialize encryption information. */
2439        XMEMSET(info, 0, sizeof(EncryptedInfo));
2440    #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_PWDBASED)
2441        if (ctx != NULL) {
2442            info->passwd_cb       = ctx->passwd_cb;
2443            info->passwd_userdata = ctx->passwd_userdata;
2444        }
2445    #endif
2446
2447        /* Get the DER data for a private key or certificate. */
2448        ret = DataToDerBuffer(buff, (word32)sz, format, type, info, heap, &der,
2449            &algId);
2450        if (used != NULL) {
2451            /* Update to amount used/consumed. */
2452            *used = info->consumed;
2453        }
2454    #ifdef WOLFSSL_SMALL_STACK
2455        if (ret != 0) {
2456             /* Info no longer needed as loading failed. */
2457             XFREE(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
2458        }
2459    #endif
2460    }
2461
2462    if ((ret == 0) && IS_PRIVKEY_TYPE(type)) {
2463        /* Process the private key. */
2464        ret = ProcessBufferPrivateKey(ctx, ssl, der, format, info, heap, type,
2465            algId);
2466        WC_FREE_VAR_EX(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
2467    }
2468    else if (ret == 0) {
2469        /* Processing a certificate. */
2470        if (userChain) {
2471            /* Take original buffer and add to user chain to send in TLS
2472             * handshake. */
2473            ret = ProcessUserChain(ctx, ssl, buff, sz, format, type, used, info,
2474                verify);
2475            /* Additional chain is optional */
2476            if (ret == WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)) {
2477                unsigned long pemErr = 0;
2478                CLEAR_ASN_NO_PEM_HEADER_ERROR(pemErr);
2479                ret = 0;
2480            }
2481#ifdef WOLFSSL_DEBUG_CERTIFICATE_LOADS
2482            if (ret < 0) {
2483#ifdef NO_ERROR_STRINGS
2484                WOLFSSL_DEBUG_PRINTF(
2485                    "ERROR: ProcessUserChain: certificate from %s at offset %ld"
2486                    " rejected with code %d\n",
2487                    source_name, usedAtStart, ret);
2488#else
2489                WOLFSSL_DEBUG_PRINTF(
2490                    "ERROR: ProcessUserChain: certificate from %s at offset %ld"
2491                    " rejected with code %d: %s\n",
2492                    source_name, usedAtStart, ret,
2493                    wolfSSL_ERR_reason_error_string(ret));
2494#endif
2495            }
2496#endif /* WOLFSSL_DEBUG_CERTIFICATE_LOADS */
2497        }
2498
2499        WC_FREE_VAR_EX(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
2500
2501        if (ret == 0) {
2502            /* Process the different types of certificates. */
2503            ret = ProcessBufferCertTypes(ctx, ssl, buff, sz, der, format, type,
2504                verify);
2505#ifdef WOLFSSL_DEBUG_CERTIFICATE_LOADS
2506            if (ret < 0) {
2507#ifdef NO_ERROR_STRINGS
2508                WOLFSSL_DEBUG_PRINTF(
2509                    "ERROR: ProcessBufferCertTypes: certificate from %s at"
2510                    " offset %ld rejected with code %d\n",
2511                    source_name, usedAtStart, ret);
2512#else
2513                WOLFSSL_DEBUG_PRINTF(
2514                    "ERROR: ProcessBufferCertTypes: certificate from %s at"
2515                    " offset %ld rejected with code %d: %s\n",
2516                    source_name, usedAtStart, ret,
2517                    wolfSSL_ERR_reason_error_string(ret));
2518#endif
2519            }
2520#endif /* WOLFSSL_DEBUG_CERTIFICATE_LOADS */
2521        }
2522        else {
2523            FreeDer(&der);
2524        }
2525    }
2526
2527    /* Reset suites if this is a private key or user certificate. */
2528    if ((ret == 0) && ((type == PRIVATEKEY_TYPE) || (type == CERT_TYPE))) {
2529        ret = ProcessBufferResetSuites(ctx, ssl, type);
2530    }
2531
2532    /* Convert return code. */
2533    if (ret == 0) {
2534        ret = 1;
2535    }
2536    else if (ret == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) {
2537        ret = 0;
2538    }
2539    WOLFSSL_LEAVE("ProcessBuffer", ret);
2540    return ret;
2541}
2542
2543#if defined(WOLFSSL_WPAS) && defined(HAVE_CRL)
2544/* Try to parse data as a PEM CRL.
2545 *
2546 * @param [in]  ctx       SSL context object.
2547 * @param [in]  buff      Buffer containing potential CRL in PEM format.
2548 * @param [in]  sz        Amount of data in buffer remaining.
2549 * @param [out] consumed  Number of bytes in buffer was the CRL.
2550 * @return  0 on success.
2551 */
2552static int ProcessChainBufferCRL(WOLFSSL_CTX* ctx, const unsigned char* buff,
2553    long sz, long* consumed)
2554{
2555    int           ret;
2556    DerBuffer*    der = NULL;
2557    EncryptedInfo info;
2558
2559    WOLFSSL_MSG("Trying a CRL");
2560    ret = PemToDer(buff, sz, CRL_TYPE, &der, NULL, &info, NULL);
2561    if (ret == 0) {
2562        WOLFSSL_MSG("   Processed a CRL");
2563        wolfSSL_CertManagerLoadCRLBuffer(ctx->cm, der->buffer, der->length,
2564            WOLFSSL_FILETYPE_ASN1);
2565        FreeDer(&der);
2566        *consumed = info.consumed;
2567    }
2568
2569    return ret;
2570}
2571#endif
2572
2573/* Process all chain certificates (and CRLs) in the PEM data.
2574 *
2575 * @param [in, out] ctx     SSL context object.
2576 * @param [in, out] ssl     SSL object.
2577 * @param [in]      buff    Buffer containing PEM data.
2578 * @param [in]      sz      Size of data in buffer.
2579 * @param [in]      type    Type of data.
2580 * @param [in]      verify  How to verify certificate.
2581 * @param [in]      source_name   Associated filename or other source ID.
2582 * @return  1 on success.
2583 * @return  0 on failure.
2584 * @return  MEMORY_E when dynamic memory allocation fails.
2585 */
2586static int ProcessChainBuffer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
2587    const unsigned char* buff, long sz, int type, int verify,
2588    const char *source_name)
2589{
2590    int  ret    = 0;
2591    long used   = 0;
2592    int  gotOne = 0;
2593
2594    WOLFSSL_MSG("Processing CA PEM file");
2595    /* Keep processing file while no errors and data to parse. */
2596    while ((ret >= 0) && (used < sz)) {
2597        long consumed = used;
2598
2599        /* Process the buffer. */
2600        ret = ProcessBuffer(ctx, buff + used, sz - used, WOLFSSL_FILETYPE_PEM,
2601            type, ssl, &consumed, 0, verify, source_name);
2602        /* Memory allocation failure is fatal. */
2603        if (ret == WC_NO_ERR_TRACE(MEMORY_E)) {
2604            gotOne = 0;
2605        }
2606        /* Other error parsing. */
2607        else if (ret < 0) {
2608#if defined(WOLFSSL_WPAS) && defined(HAVE_CRL)
2609            /* Try parsing a CRL. */
2610            if (ProcessChainBufferCRL(ctx, buff + used, sz - used,
2611                    &consumed) == 0) {
2612                ret = 0;
2613            }
2614            else
2615#endif
2616            /* Check whether we made progress. */
2617            if (consumed > 0) {
2618                WOLFSSL_ERROR(ret);
2619                WOLFSSL_MSG("CA Parse failed, with progress in file.");
2620                WOLFSSL_MSG("Search for other certs in file");
2621                /* Check if we have more data to parse to recover. */
2622                if (used + consumed < sz) {
2623                    ret = 0;
2624                }
2625            }
2626            else {
2627                /* No progress in parsing being made - stop here. */
2628                WOLFSSL_MSG("CA Parse failed, no progress in file.");
2629                WOLFSSL_MSG("Do not continue search for other certs in file");
2630            }
2631        }
2632        else {
2633            /* Got a certificate out. */
2634            WOLFSSL_MSG("   Processed a CA");
2635            gotOne = 1;
2636        }
2637        /* Update used count. */
2638        used += consumed;
2639    }
2640
2641    /* May have other unparsable data but did we get a certificate? */
2642    if (gotOne) {
2643        WOLFSSL_MSG("Processed at least one valid CA. Other stuff OK");
2644        ret = 1;
2645    }
2646    return ret;
2647}
2648
2649
2650/* Get verify settings for AddCA from SSL context. */
2651#define GET_VERIFY_SETTING_CTX(ctx) \
2652    ((ctx) && (ctx)->verifyNone ? NO_VERIFY : VERIFY)
2653/* Get verify settings for AddCA from SSL. */
2654#define GET_VERIFY_SETTING_SSL(ssl) \
2655    ((ssl)->options.verifyNone ? NO_VERIFY : VERIFY)
2656
2657#ifndef NO_FILESYSTEM
2658
2659/* Process data from a file as private keys, CRL or certificates.
2660 *
2661 * @param [in, out] ctx        SSL context object.
2662 * @param [in]      fname      Name of file to read.
2663 * @param [in]      format     Format of data:
2664 *                               WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
2665 * @param [in]      type       Type of data:
2666 *                               CERT_TYPE, CA_TYPE, TRUSTED_PEER_TYPE,
2667 *                               PRIVATEKEY_TYPE or ALT_PRIVATEKEY_TYPE.
2668 * @param [in, out] ssl        SSL object.
2669 * @param [in]      userChain  Whether file contains chain of certificates.
2670 * @param [in, out] crl        CRL object to load data into.
2671 * @param [in]      verify     How to verify certificates.
2672 * @return  1 on success.
2673 * @return  WOLFSSL_BAD_FILE when reading the file fails.
2674 * @return  WOLFSSL_BAD_CERTTYPE when unable to detect certificate type.
2675 */
2676int ProcessFile(WOLFSSL_CTX* ctx, const char* fname, int format, int type,
2677    WOLFSSL* ssl, int userChain, WOLFSSL_CRL* crl, int verify)
2678{
2679    int    ret = 0;
2680#ifndef WOLFSSL_SMALL_STACK
2681    byte   stackBuffer[FILE_BUFFER_SIZE];
2682#endif
2683    StaticBuffer content;
2684    long   sz = 0;
2685    void*  heap = WOLFSSL_HEAP(ctx, ssl);
2686
2687    (void)crl;
2688    (void)heap;
2689
2690#ifdef WOLFSSL_SMALL_STACK
2691    static_buffer_init(&content);
2692#else
2693    static_buffer_init(&content, stackBuffer, FILE_BUFFER_SIZE);
2694#endif
2695
2696    /* Read file into static buffer. */
2697    ret = wolfssl_read_file_static(fname, &content, heap, DYNAMIC_TYPE_FILE,
2698        &sz);
2699    if ((ret == 0) && (type == DETECT_CERT_TYPE) &&
2700            (format != WOLFSSL_FILETYPE_PEM)) {
2701        WOLFSSL_MSG_CERT_LOG("Cannot detect certificate type when not PEM");
2702        ret = WOLFSSL_BAD_CERTTYPE;
2703    }
2704    /* Try to detect type by parsing cert header and footer. */
2705    if ((ret == 0) && (type == DETECT_CERT_TYPE)) {
2706#if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
2707        const char* header = NULL;
2708        const char* footer = NULL;
2709#ifdef HAVE_CRL
2710        WOLFSSL_MSG_CERT("Detecting cert type... (including CRL_TYPE)");
2711#else
2712        WOLFSSL_MSG_CERT("Detecting cert type... (HAVE_CRL not defined)");
2713#endif
2714
2715        /* Look for CA header and footer - same as CERT_TYPE. */
2716        if (wc_PemGetHeaderFooter(CA_TYPE, &header, &footer) == 0 &&
2717                (XSTRNSTR((char*)content.buffer, header, sz) != NULL)) {
2718            type = CA_TYPE;
2719            WOLFSSL_MSG_CERT_LOG_EX("Detected cert type CA_TYPE = %d:", type);
2720        }
2721#ifdef HAVE_CRL
2722        /* Look for CRL header and footer. */
2723        else if (wc_PemGetHeaderFooter(CRL_TYPE, &header, &footer) == 0 &&
2724                (XSTRNSTR((char*)content.buffer, header, sz) != NULL)) {
2725            type = CRL_TYPE;
2726            WOLFSSL_MSG_CERT_LOG_EX("Detected cert type CRL_TYPE = %d:", type);
2727        }
2728#endif
2729        /* Look for cert header and footer - same as CA_TYPE. */
2730        else if (wc_PemGetHeaderFooter(CERT_TYPE, &header, &footer) == 0 &&
2731                (XSTRNSTR((char*)content.buffer, header, sz) !=
2732                    NULL)) {
2733            type = CERT_TYPE;
2734            WOLFSSL_MSG_CERT_LOG_EX("Detected cert type CERT_TYPE = %d:", type);
2735        }
2736        else
2737#endif /* !NO_CODING && !WOLFSSL_NO_PEM */
2738        {
2739            /* Not a header that we support. */
2740            WOLFSSL_MSG_CERT_LOG("Failed to detect certificate type");
2741#ifdef WOLFSSL_DEBUG_CERTIFICATE_LOADS
2742            WOLFSSL_DEBUG_PRINTF(
2743                "ERROR: ProcessFile: Failed to detect certificate type"
2744                " of \"%s\"\n",
2745                fname);
2746#endif
2747            ret = WOLFSSL_BAD_CERTTYPE;
2748        }
2749    } /* (ret == 0) && (type == DETECT_CERT_TYPE) */
2750
2751    if (ret == 0) {
2752        /* When CA or trusted peer and PEM - process as a chain buffer. */
2753        if (((type == CA_TYPE) || (type == TRUSTED_PEER_TYPE)) &&
2754                (format == WOLFSSL_FILETYPE_PEM)) {
2755            WOLFSSL_MSG_CERT("Processing cert chain buffer...");
2756            ret = ProcessChainBuffer(ctx, ssl, content.buffer, sz, type,
2757                verify, fname);
2758        }
2759#ifdef HAVE_CRL
2760        else if (type == CRL_TYPE) {
2761            WOLFSSL_MSG_CERT("Loading CRL...");
2762            ret = BufferLoadCRL(crl, content.buffer, sz, format, verify);
2763        }
2764#endif
2765#ifdef WOLFSSL_DUAL_ALG_CERTS
2766        else if (type == PRIVATEKEY_TYPE) {
2767            /* When support for dual algorithm certificates is enabled, the
2768             * private key file may contain both the primary and the
2769             * alternative private key. Hence, we have to parse both of them.
2770             */
2771            long consumed = 0;
2772
2773            ret = ProcessBuffer(ctx, content.buffer, sz, format, type, ssl,
2774                &consumed, userChain, verify, fname);
2775            if ((ret == 1) && (consumed < sz)) {
2776                ret = ProcessBuffer(ctx, content.buffer + consumed,
2777                    sz - consumed, format, ALT_PRIVATEKEY_TYPE, ssl, NULL, 0,
2778                    verify, fname);
2779            }
2780        }
2781#endif
2782        else {
2783            /* Load all other certificate types. */
2784            ret = ProcessBuffer(ctx, content.buffer, sz, format, type, ssl,
2785                NULL, userChain, verify, fname);
2786        }
2787    }
2788
2789    /* Dispose of dynamically allocated data. */
2790    static_buffer_free(&content, heap, DYNAMIC_TYPE_FILE);
2791    return ret;
2792}
2793
2794#ifndef NO_WOLFSSL_DIR
2795/* Load file when filename is in the path.
2796 *
2797 * @param [in, out] ctx           SSL context object.
2798 * @param [in]      name          Name of file.
2799 * @param [in]      verify        How to verify a certificate.
2800 * @param [in]      flags         Flags representing options for loading.
2801 * @param [in, out] failCount     Number of files that failed to load.
2802 * @param [in, out] successCount  Number of files successfully loaded.
2803 * @return  1 on success.
2804 * @return  Not 1 when loading PEM certificate failed.
2805 */
2806static int wolfssl_ctx_load_path_file(WOLFSSL_CTX* ctx, const char* name,
2807    int verify, int flags, int* failCount, int* successCount)
2808{
2809    int ret;
2810
2811    /* Attempt to load file as a CA. */
2812    ret = ProcessFile(ctx, name, WOLFSSL_FILETYPE_PEM, CA_TYPE, NULL, 0, NULL,
2813        verify);
2814    if (ret != 1) {
2815        /* When ignoring errors or loading PEM only and no PEM. don't fail. */
2816        if ((flags & WOLFSSL_LOAD_FLAG_IGNORE_ERR) ||
2817                ((flags & WOLFSSL_LOAD_FLAG_PEM_CA_ONLY) &&
2818                 (ret == WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)))) {
2819            unsigned long err = 0;
2820            CLEAR_ASN_NO_PEM_HEADER_ERROR(err);
2821        #if defined(WOLFSSL_QT)
2822            ret = 1;
2823        #endif
2824        }
2825        else {
2826            WOLFSSL_ERROR(ret);
2827            WOLFSSL_MSG("Load CA file failed, continuing");
2828            /* Add to fail count. */
2829            (*failCount)++;
2830        }
2831    }
2832    else {
2833    #if defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS)
2834        /* Try loading as a trusted peer certificate. */
2835        ret = wolfSSL_CTX_trust_peer_cert(ctx, name, WOLFSSL_FILETYPE_PEM);
2836        if (ret != 1) {
2837            WOLFSSL_MSG("wolfSSL_CTX_trust_peer_cert error. "
2838                        "Ignoring this error.");
2839        }
2840    #endif
2841        /* Add to success count. */
2842        (*successCount)++;
2843    }
2844
2845    return ret;
2846}
2847
2848/* Load PEM formatted CA files from a path.
2849 *
2850 * @param [in, out] ctx           SSL context object.
2851 * @param [in]      path          Path to directory to read.
2852 * @param [in]      flags         Flags representing options for loading.
2853 * @param [in]      verify        How to verify a certificate.
2854 * @param [in]      successCount  Number of files successfully loaded.
2855 * @return  1 on success.
2856 * @return  0 on failure.
2857 * @return  MEMORY_E when dynamic memory allocation fails.
2858 */
2859static int wolfssl_ctx_load_path(WOLFSSL_CTX* ctx, const char* path,
2860    word32 flags, int verify, int successCount)
2861{
2862    int ret = 1;
2863    char* name = NULL;
2864    int fileRet;
2865    int failCount = 0;
2866    WC_DECLARE_VAR(readCtx, ReadDirCtx, 1, 0);
2867
2868    /* Allocate memory for directory reading context. */
2869    WC_ALLOC_VAR_EX(readCtx, ReadDirCtx, 1, ctx->heap, DYNAMIC_TYPE_DIRCTX,
2870        ret=MEMORY_E);
2871
2872    if (ret == 1) {
2873        /* Get name of first file in path. */
2874        fileRet = wc_ReadDirFirst(readCtx, path, &name);
2875        /* While getting filename doesn't fail and name returned, process file.
2876         */
2877        while ((fileRet == 0) && (name != NULL)) {
2878            WOLFSSL_MSG(name);
2879            /* Load file. */
2880            ret = wolfssl_ctx_load_path_file(ctx, name, verify, (int)flags,
2881                &failCount, &successCount);
2882            /* Get next filename. */
2883            fileRet = wc_ReadDirNext(readCtx, path, &name);
2884        }
2885        /* Cleanup directory reading context. */
2886        wc_ReadDirClose(readCtx);
2887
2888        /* When not WOLFSSL_QT, ret is always overwritten. */
2889        (void)ret;
2890
2891        /* Return real directory read failure error codes. */
2892        if (fileRet != WC_READDIR_NOFILE) {
2893            ret = fileRet;
2894        #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
2895            /* Ignore bad path error when flag set. */
2896            if ((ret == WC_NO_ERR_TRACE(BAD_PATH_ERROR)) &&
2897                    (flags & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR)) {
2898               /* QSslSocket always loads certs in system folder
2899                * when it is initialized.
2900                * Compliant with OpenSSL when flag set.
2901                */
2902                ret = 1;
2903            }
2904            else {
2905                /* qssl socket wants to know errors. */
2906                WOLFSSL_ERROR(ret);
2907            }
2908        #endif
2909        }
2910        /* Report failure if no files successfully loaded or there were
2911         * failures. */
2912        else if ((successCount == 0) || (failCount > 0)) {
2913            /* Use existing error code if exists. */
2914        #if defined(WOLFSSL_QT)
2915            /* Compliant with OpenSSL when flag set. */
2916            if (!(flags & WOLFSSL_LOAD_FLAG_IGNORE_ZEROFILE))
2917        #endif
2918            {
2919                /* Return 0 when no files loaded. */
2920                ret = 0;
2921            }
2922        }
2923        else {
2924            /* We loaded something so it is a success. */
2925            ret = 1;
2926        }
2927
2928        WC_FREE_VAR_EX(readCtx, ctx->heap, DYNAMIC_TYPE_DIRCTX);
2929    }
2930
2931    return ret;
2932}
2933#endif
2934
2935/* Load a file and/or files in path
2936 *
2937 * No c_rehash.
2938 *
2939 * @param [in, out] ctx    SSL context object.
2940 * @param [in]      file   Name of file to load. May be NULL.
2941 * @param [in]      path   Path to directory containing PEM CA files.
2942 *                         May be NULL.
2943 * @param [in]      flags  Flags representing options for loading.
2944 * @return  1 on success.
2945 * @return  0 on failure.
2946 * @return  NOT_COMPILED_IN when directory reading not supported and path is
2947 *          not NULL.
2948 * @return  Other negative on error.
2949 */
2950int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
2951    const char* path, word32 flags)
2952{
2953    int ret = 1;
2954#ifndef NO_WOLFSSL_DIR
2955    int successCount = 0;
2956#endif
2957    int verify = WOLFSSL_VERIFY_DEFAULT;
2958
2959    WOLFSSL_MSG("wolfSSL_CTX_load_verify_locations_ex");
2960
2961    /* Validate parameters. */
2962    if ((ctx == NULL) || ((file == NULL) && (path == NULL))) {
2963        ret = 0;
2964    }
2965
2966#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
2967    if (ret == 1) {
2968    /* TEST ONLY CODE: force native cert validation on */
2969        WOLFSSL_MSG("ANCV Test: Loading system CA certs");
2970        wolfSSL_CTX_load_system_CA_certs(ctx);
2971    }
2972#endif
2973
2974    if (ret == 1) {
2975        /* Get setting on how to verify certificates. */
2976        verify = GET_VERIFY_SETTING_CTX(ctx);
2977        /* Overwrite setting when flag set. */
2978        if (flags & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) {
2979            verify = VERIFY_SKIP_DATE;
2980        }
2981
2982        if (file != NULL) {
2983#ifdef WOLFSSL_PEM_TO_DER
2984            /* Load the PEM formatted CA file */
2985            ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_PEM, CA_TYPE, NULL, 0,
2986                NULL, verify);
2987#else
2988            /* Load the DER formatted CA file */
2989            ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_ASN1, CA_TYPE, NULL,
2990                0, NULL, verify);
2991#endif
2992#ifndef NO_WOLFSSL_DIR
2993            if (ret == 1) {
2994                /* Include success in overall count. */
2995                successCount++;
2996            }
2997#endif
2998#if defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS)
2999            /* Load CA as a trusted peer certificate. */
3000#ifdef WOLFSSL_PEM_TO_DER
3001            ret = wolfSSL_CTX_trust_peer_cert(ctx, file, WOLFSSL_FILETYPE_PEM);
3002#else
3003            ret = wolfSSL_CTX_trust_peer_cert(ctx, file, WOLFSSL_FILETYPE_ASN1);
3004#endif
3005            if (ret != 1) {
3006                WOLFSSL_MSG("wolfSSL_CTX_trust_peer_cert error");
3007            }
3008#endif
3009        }
3010    }
3011
3012    if ((ret == 1) && (path != NULL)) {
3013#ifndef NO_WOLFSSL_DIR
3014        /* Load CA files form path. */
3015        ret = wolfssl_ctx_load_path(ctx, path, flags, verify, successCount);
3016#else
3017        /* Loading a path not supported. */
3018        ret = NOT_COMPILED_IN;
3019        (void)flags;
3020#endif
3021    }
3022
3023    return ret;
3024}
3025
3026/* Load a file and/or files in path
3027 *
3028 * No c_rehash.
3029 *
3030 * @param [in, out] ctx    SSL context object.
3031 * @param [in]      file   Name of file to load. May be NULL.
3032 * @param [in]      path   Path to directory containing PEM CA files.
3033 *                         May be NULL.
3034 * @return  1 on success.
3035 * @return  0 on failure.
3036 */
3037WOLFSSL_ABI
3038int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
3039                                     const char* path)
3040{
3041    /* Load using default flags/options. */
3042    int ret = wolfSSL_CTX_load_verify_locations_ex(ctx, file, path,
3043        WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS);
3044
3045    /* Return 1 on success or 0 on failure. */
3046    return WS_RETURN_CODE(ret, 0);
3047}
3048
3049/* Load a file and/or files in path, with OpenSSL-compatible semantics.
3050 *
3051 * No c_rehash.
3052 *
3053 * @param [in, out] ctx    SSL context object.
3054 * @param [in]      file   Name of file to load. May be NULL.
3055 * @param [in]      path   Path to directory containing PEM CA files.
3056 *                         May be NULL.
3057 * @return  1 on success.
3058 * @return  0 on failure.
3059 */
3060int wolfSSL_CTX_load_verify_locations_compat(WOLFSSL_CTX* ctx, const char* file,
3061                                     const char* path)
3062{
3063    /* We want to keep trying to load more CA certs even if one cert in the
3064     * directory is bad and can't be used (e.g. if one is expired), and we
3065     * want to return success if any were successfully loaded (mimicking
3066     * OpenSSL SSL_CTX_load_verify_locations() semantics), so we use
3067     * WOLFSSL_LOAD_FLAG_IGNORE_ERR.  OpenSSL (as of v3.3.2) actually
3068     * returns success even if no certs are loaded (e.g. because the
3069     * supplied "path" doesn't exist or access is prohibited), and only
3070     * returns failure if the "file" is non-null and fails to load.
3071     *
3072     * Note that if a file is supplied and can't be successfully loaded, the
3073     * overall call fails and the path is never even evaluated.  This is
3074     * consistent with OpenSSL behavior.
3075     */
3076
3077    int ret = wolfSSL_CTX_load_verify_locations_ex(ctx, file, path,
3078        WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS | WOLFSSL_LOAD_FLAG_IGNORE_ERR);
3079
3080    /* Return 1 on success or 0 on failure. */
3081    return WS_RETURN_CODE(ret, 0);
3082}
3083
3084#ifdef WOLFSSL_TRUST_PEER_CERT
3085/* Load a trusted peer certificate into SSL context.
3086 *
3087 * @param [in, out] ctx     SSL context object.
3088 * @param [in]      file    Name of peer certificate file.
3089 * @param [in]      format  Format of data:
3090 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3091 * @return  1 on success.
3092 * @return  0 when ctx or file is NULL.
3093 */
3094int wolfSSL_CTX_trust_peer_cert(WOLFSSL_CTX* ctx, const char* file, int format)
3095{
3096    int ret;
3097
3098    WOLFSSL_ENTER("wolfSSL_CTX_trust_peer_cert");
3099
3100    /* Validate parameters. */
3101    if ((ctx == NULL) || (file == NULL)) {
3102        ret = 0;
3103    }
3104    else {
3105        ret = ProcessFile(ctx, file, format, TRUSTED_PEER_TYPE, NULL, 0, NULL,
3106            GET_VERIFY_SETTING_CTX(ctx));
3107    }
3108
3109    return ret;
3110}
3111
3112/* Load a trusted peer certificate into SSL.
3113 *
3114 * @param [in, out] ssl     SSL object.
3115 * @param [in]      file    Name of peer certificate file.
3116 * @param [in]      format  Format of data:
3117 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3118 * @return  1 on success.
3119 * @return  0 when ssl or file is NULL.
3120 */
3121int wolfSSL_trust_peer_cert(WOLFSSL* ssl, const char* file, int format)
3122{
3123    int ret;
3124
3125    WOLFSSL_ENTER("wolfSSL_trust_peer_cert");
3126
3127    /* Validate parameters. */
3128    if ((ssl == NULL) || (file == NULL)) {
3129        ret = 0;
3130    }
3131    else {
3132        ret = ProcessFile(NULL, file, format, TRUSTED_PEER_TYPE, ssl, 0, NULL,
3133            GET_VERIFY_SETTING_SSL(ssl));
3134    }
3135
3136    return ret;
3137}
3138#endif /* WOLFSSL_TRUST_PEER_CERT */
3139
3140
3141#ifdef WOLFSSL_DER_LOAD
3142
3143/* Load a CA certificate into SSL context.
3144 *
3145 * @param [in, out] ctx     SSL context object.
3146 * @param [in]      file    Name of peer certificate file.
3147 * @param [in]      format  Format of data:
3148 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3149 * @return  1 on success.
3150 * @return  0 on failure.
3151 */
3152int wolfSSL_CTX_der_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
3153    int format)
3154{
3155    int ret;
3156
3157    WOLFSSL_ENTER("wolfSSL_CTX_der_load_verify_locations");
3158
3159    /* Validate parameters. */
3160    if ((ctx == NULL) || (file == NULL)) {
3161        ret = 0;
3162    }
3163    else {
3164#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
3165        /* TEST ONLY CODE: force native cert validation on */
3166        WOLFSSL_MSG("ANCV Test: loading system CA certs");
3167        wolfSSL_CTX_load_system_CA_certs(ctx);
3168#endif
3169        ret = ProcessFile(ctx, file, format, CA_TYPE, NULL, 0, NULL,
3170            GET_VERIFY_SETTING_CTX(ctx));
3171    }
3172
3173    /* Return 1 on success or 0 on failure. */
3174    return WS_RC(ret);
3175}
3176
3177#endif /* WOLFSSL_DER_LOAD */
3178
3179
3180/* Load a user certificate into SSL context.
3181 *
3182 * @param [in, out] ctx     SSL context object.
3183 * @param [in]      file    Name of user certificate file.
3184 * @param [in]      format  Format of data:
3185 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3186 * @return  1 on success.
3187 * @return  0 on failure.
3188 */
3189WOLFSSL_ABI
3190int wolfSSL_CTX_use_certificate_file(WOLFSSL_CTX* ctx, const char* file,
3191    int format)
3192{
3193    int ret;
3194
3195    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_file");
3196
3197    ret = ProcessFile(ctx, file, format, CERT_TYPE, NULL, 0, NULL,
3198        GET_VERIFY_SETTING_CTX(ctx));
3199
3200    /* Return 1 on success or 0 on failure. */
3201    return WS_RC(ret);
3202}
3203
3204
3205/* Load a private key into SSL context.
3206 *
3207 * @param [in, out] ctx     SSL context object.
3208 * @param [in]      file    Name of private key file.
3209 * @param [in]      format  Format of data:
3210 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3211 * @return  1 on success.
3212 * @return  0 on failure.
3213 */
3214WOLFSSL_ABI
3215int wolfSSL_CTX_use_PrivateKey_file(WOLFSSL_CTX* ctx, const char* file,
3216    int format)
3217{
3218    int ret;
3219
3220    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_file");
3221
3222    ret = ProcessFile(ctx, file, format, PRIVATEKEY_TYPE, NULL, 0, NULL,
3223        GET_VERIFY_SETTING_CTX(ctx));
3224
3225    /* Return 1 on success or 0 on failure. */
3226    return WS_RC(ret);
3227}
3228
3229#ifdef WOLFSSL_DUAL_ALG_CERTS
3230/* Load an alternative private key into SSL context.
3231 *
3232 * @param [in, out] ctx     SSL context object.
3233 * @param [in]      file    Name of private key file.
3234 * @param [in]      format  Format of data:
3235 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3236 * @return  1 on success.
3237 * @return  0 on failure.
3238 */
3239int wolfSSL_CTX_use_AltPrivateKey_file(WOLFSSL_CTX* ctx, const char* file,
3240    int format)
3241{
3242    int ret;
3243
3244    WOLFSSL_ENTER("wolfSSL_CTX_use_AltPrivateKey_file");
3245
3246    ret = ProcessFile(ctx, file, format, ALT_PRIVATEKEY_TYPE, NULL, 0, NULL,
3247        GET_VERIFY_SETTING_CTX(ctx));
3248
3249    /* Return 1 on success or 0 on failure. */
3250    return WS_RC(ret);
3251}
3252#endif /* WOLFSSL_DUAL_ALG_CERTS */
3253
3254
3255/* Load a PEM certificate chain into SSL context.
3256 *
3257 * @param [in, out] ctx     SSL context object.
3258 * @param [in]      file    Name of PEM certificate chain file.
3259 * @return  1 on success.
3260 * @return  0 on failure.
3261 */
3262WOLFSSL_ABI
3263int wolfSSL_CTX_use_certificate_chain_file(WOLFSSL_CTX* ctx, const char* file)
3264{
3265    int ret;
3266
3267    /* process up to MAX_CHAIN_DEPTH plus subject cert */
3268    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_chain_file");
3269
3270#ifdef WOLFSSL_PEM_TO_DER
3271    ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_PEM, CERT_TYPE, NULL, 1, NULL,
3272        GET_VERIFY_SETTING_CTX(ctx));
3273#else
3274    ret = ProcessFile(ctx, file, WOLFSSL_FILETYPE_ASN1, CERT_TYPE, NULL, 1,
3275        NULL, GET_VERIFY_SETTING_CTX(ctx));
3276#endif
3277
3278    /* Return 1 on success or 0 on failure. */
3279    return WS_RC(ret);
3280}
3281
3282/* Load certificate chain into SSL context.
3283 *
3284 * Processes up to MAX_CHAIN_DEPTH plus subject cert.
3285 *
3286 * @param [in, out] ctx     SSL context object.
3287 * @param [in]      file    Name of private key file.
3288 * @param [in]      format  Format of data:
3289 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3290 * @return  1 on success.
3291 * @return  0 on failure.
3292 */
3293int wolfSSL_CTX_use_certificate_chain_file_format(WOLFSSL_CTX* ctx,
3294     const char* file, int format)
3295{
3296    int ret;
3297
3298    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_chain_file_format");
3299
3300    ret = ProcessFile(ctx, file, format, CERT_TYPE, NULL, 1, NULL,
3301        GET_VERIFY_SETTING_CTX(ctx));
3302
3303    /* Return 1 on success or 0 on failure. */
3304    return WS_RC(ret);
3305}
3306
3307#endif /* NO_FILESYSTEM */
3308
3309#ifdef WOLFSSL_SYS_CA_CERTS
3310
3311#ifdef USE_WINDOWS_API
3312
3313/* Load CA certificate from Windows store.
3314 *
3315 * Assumes loaded is 0.
3316 *
3317 * @param [in, out] ctx     SSL context object.
3318 * @param [out]     loaded  Whether CA certificates were loaded.
3319 * @return  1 on success.
3320 * @return  0 on failure.
3321 */
3322static int LoadSystemCaCertsWindows(WOLFSSL_CTX* ctx, byte* loaded)
3323{
3324    int ret = 1;
3325    word32 i;
3326    HANDLE handle = NULL;
3327    PCCERT_CONTEXT certCtx = NULL;
3328    LPCSTR storeNames[2] = {"ROOT", "CA"};
3329    HCRYPTPROV_LEGACY hProv = (HCRYPTPROV_LEGACY)NULL;
3330
3331    if ((ctx == NULL) || (loaded == NULL)) {
3332        ret = 0;
3333    }
3334
3335    for (i = 0; (ret == 1) && (i < sizeof(storeNames)/sizeof(*storeNames));
3336         ++i) {
3337        handle = CertOpenSystemStoreA(hProv, storeNames[i]);
3338        if (handle != NULL) {
3339            while ((certCtx = CertEnumCertificatesInStore(handle, certCtx))
3340                   != NULL) {
3341                if (certCtx->dwCertEncodingType == X509_ASN_ENCODING) {
3342                    if (ProcessBuffer(ctx, certCtx->pbCertEncoded,
3343                          certCtx->cbCertEncoded, WOLFSSL_FILETYPE_ASN1,
3344                          CA_TYPE, NULL, NULL, 0,
3345                          GET_VERIFY_SETTING_CTX(ctx),
3346                          storeNames[i]) == 1) {
3347                        /*
3348                         * Set "loaded" as long as we've loaded one CA
3349                         * cert.
3350                         */
3351                        *loaded = 1;
3352                    }
3353                }
3354            }
3355        }
3356        else {
3357            WOLFSSL_MSG_EX("Failed to open cert store %s.", storeNames[i]);
3358        }
3359
3360        if (handle != NULL && !CertCloseStore(handle, 0)) {
3361            WOLFSSL_MSG_EX("Failed to close cert store %s.", storeNames[i]);
3362            ret = 0;
3363        }
3364    }
3365
3366    return ret;
3367}
3368
3369#elif defined(__APPLE__)
3370
3371#if defined(HAVE_SECURITY_SECTRUSTSETTINGS_H) \
3372  && !defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION)
3373/* Manually obtains certificates from the system trust store and loads them
3374 * directly into wolfSSL "the old way".
3375 *
3376 * As of MacOS 14.0 we are still able to use this method to access system
3377 * certificates. Accessibility of this API is indicated by the presence of the
3378 * Security/SecTrustSettings.h header. In the likely event that Apple removes
3379 * access to this API on Macs, this function should be removed and the
3380 * DoAppleNativeCertValidation() routine should be used for all devices.
3381 *
3382 * Assumes loaded is 0.
3383 *
3384 * @param [in, out] ctx     SSL context object.
3385 * @param [out]     loaded  Whether CA certificates were loaded.
3386 * @return  1 on success.
3387 * @return  0 on failure.
3388 */
3389static int LoadSystemCaCertsMac(WOLFSSL_CTX* ctx, byte* loaded)
3390{
3391    int ret = 1;
3392    word32 i;
3393    const unsigned int trustDomains[] = {
3394        kSecTrustSettingsDomainUser,
3395        kSecTrustSettingsDomainAdmin,
3396        kSecTrustSettingsDomainSystem
3397    };
3398    CFArrayRef certs;
3399    OSStatus stat;
3400    CFIndex numCerts;
3401    CFDataRef der;
3402    CFIndex j;
3403
3404    if ((ctx == NULL) || (loaded == NULL)) {
3405        ret = 0;
3406    }
3407
3408    for (i = 0; (ret == 1) && (i < sizeof(trustDomains)/sizeof(*trustDomains));
3409         ++i) {
3410        stat = SecTrustSettingsCopyCertificates(
3411            (SecTrustSettingsDomain)trustDomains[i], &certs);
3412        if (stat == errSecSuccess) {
3413            numCerts = CFArrayGetCount(certs);
3414            for (j = 0; j < numCerts; ++j) {
3415                der = SecCertificateCopyData((SecCertificateRef)
3416                          CFArrayGetValueAtIndex(certs, j));
3417                if (der != NULL) {
3418                    if (ProcessBuffer(ctx, CFDataGetBytePtr(der),
3419                          CFDataGetLength(der), WOLFSSL_FILETYPE_ASN1,
3420                          CA_TYPE, NULL, NULL, 0,
3421                          GET_VERIFY_SETTING_CTX(ctx),
3422                          "MacOSX trustDomains") == 1) {
3423                        /*
3424                         * Set "loaded" as long as we've loaded one CA
3425                         * cert.
3426                         */
3427                        *loaded = 1;
3428                    }
3429
3430                    CFRelease(der);
3431                }
3432            }
3433
3434            CFRelease(certs);
3435        }
3436        else if (stat == errSecNoTrustSettings) {
3437            WOLFSSL_MSG_EX("No trust settings for domain %d, moving to next "
3438                "domain.", trustDomains[i]);
3439        }
3440        else {
3441            WOLFSSL_MSG_EX("SecTrustSettingsCopyCertificates failed with"
3442                " status %d.", stat);
3443            ret = 0;
3444            break;
3445        }
3446    }
3447
3448    return ret;
3449}
3450#endif /* defined(HAVE_SECURITY_SECTRUSTSETTINGS_H) */
3451
3452#elif !defined(NO_FILESYSTEM)
3453
3454/* Potential system CA certs directories on Linux/Unix distros. */
3455static const char* systemCaDirs[] = {
3456#if defined(__ANDROID__) || defined(ANDROID)
3457    "/system/etc/security/cacerts"      /* Android */
3458#else
3459    "/etc/ssl/certs",                   /* Debian, Ubuntu, Gentoo, others */
3460    "/etc/pki/ca-trust/source/anchors", /* Fedora, RHEL */
3461    "/etc/pki/tls/certs"                /* Older RHEL */
3462#endif
3463};
3464
3465/* Get CA directory list.
3466 *
3467 * @param [out] num  Number of CA directories.
3468 * @return  CA directory list.
3469 * @return  NULL when num is NULL.
3470 */
3471const char** wolfSSL_get_system_CA_dirs(word32* num)
3472{
3473    const char** ret;
3474
3475    /* Validate parameters. */
3476    if (num == NULL) {
3477        ret = NULL;
3478    }
3479    else {
3480        ret = systemCaDirs;
3481        *num = sizeof(systemCaDirs)/sizeof(*systemCaDirs);
3482    }
3483
3484    return ret;
3485}
3486
3487/* Load CA certificate from default system directories.
3488 *
3489 * Assumes loaded is 0.
3490 *
3491 * @param [in, out] ctx     SSL context object.
3492 * @param [out]     loaded  Whether CA certificates were loaded.
3493 * @return  1 on success.
3494 * @return  0 on failure.
3495 */
3496static int LoadSystemCaCertsNix(WOLFSSL_CTX* ctx, byte* loaded) {
3497    int ret = 1;
3498    word32 i;
3499
3500    if ((ctx == NULL) || (loaded == NULL)) {
3501        ret = 0;
3502    }
3503
3504    for (i = 0; (ret == 1) && (i < sizeof(systemCaDirs)/sizeof(*systemCaDirs));
3505         ++i) {
3506        WOLFSSL_MSG_EX("Attempting to load system CA certs from %s.",
3507            systemCaDirs[i]);
3508        /*
3509         * We want to keep trying to load more CA certs even if one cert in
3510         * the directory is bad and can't be used (e.g. if one is expired),
3511         * so we use WOLFSSL_LOAD_FLAG_IGNORE_ERR.
3512         */
3513        if (wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, systemCaDirs[i],
3514                WOLFSSL_LOAD_FLAG_IGNORE_ERR) != 1) {
3515            WOLFSSL_MSG_EX("Failed to load CA certs from %s, trying "
3516                "next possible location.", systemCaDirs[i]);
3517        }
3518        else {
3519            WOLFSSL_MSG_EX("Loaded CA certs from %s.",
3520                systemCaDirs[i]);
3521            *loaded = 1;
3522            /* Stop searching after we've loaded one directory. */
3523            break;
3524        }
3525    }
3526
3527    return ret;
3528}
3529
3530#endif
3531
3532/* Load CA certificates from system defined locations.
3533 *
3534 * @param [in, out] ctx  SSL context object.
3535 * @return  1 on success.
3536 * @return  0 on failure.
3537 * @return  WOLFSSL_BAD_PATH when no error but no certificates loaded.
3538 */
3539int wolfSSL_CTX_load_system_CA_certs(WOLFSSL_CTX* ctx)
3540{
3541    int ret;
3542    byte loaded = 0;
3543
3544    WOLFSSL_ENTER("wolfSSL_CTX_load_system_CA_certs");
3545
3546#ifdef USE_WINDOWS_API
3547
3548    ret = LoadSystemCaCertsWindows(ctx, &loaded);
3549
3550#elif defined(__APPLE__)
3551
3552#if defined(HAVE_SECURITY_SECTRUSTSETTINGS_H) \
3553  && !defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION)
3554    /* As of MacOS 14.0 we are still able to access system certificates and
3555     * load them manually into wolfSSL "the old way". Accessibility of this API
3556     * is indicated by the presence of the Security/SecTrustSettings.h header */
3557    ret = LoadSystemCaCertsMac(ctx, &loaded);
3558#elif defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION)
3559    /* For other Apple devices, Apple has removed the ability to obtain
3560     * certificates from the trust store, so we can't use wolfSSL's built-in
3561     * certificate validation mechanisms anymore. We instead must call into the
3562     * Security Framework APIs to authenticate peer certificates when received.
3563     * (see src/internal.c:DoAppleNativeCertValidation()).
3564     * Thus, there is no CA "loading" required, but to keep behavior consistent
3565     * with the current API (not using system CA certs unless this function has
3566     * been called), we simply set a flag indicating that the new apple trust
3567     * verification routine should be used later */
3568    ctx->doAppleNativeCertValidationFlag = 1;
3569    ret = 1;
3570    loaded = 1;
3571
3572#if FIPS_VERSION_GE(2,0) /* Gate back to cert 3389 FIPS modules */
3573#warning "Cryptographic operations may occur outside the FIPS module boundary" \
3574         "Please review FIPS claims for cryptography on this Apple device"
3575#endif /* FIPS_VERSION_GE(2,0) */
3576
3577#else
3578/* HAVE_SECURITY_SECXXX_H macros are set by autotools or CMake when searching
3579 * system for the required SDK headers. If building with user_settings.h, you
3580 * will need to manually define WOLFSSL_APPLE_NATIVE_CERT_VALIDATION
3581 * and ensure the appropriate Security.framework headers and libraries are
3582 * visible to your compiler */
3583#error "WOLFSSL_SYS_CA_CERTS on Apple devices requires Security.framework" \
3584       " header files to be detected, or a manual override with" \
3585       " WOLFSSL_APPLE_NATIVE_CERT_VALIDATION"
3586#endif
3587
3588#else
3589
3590    ret = LoadSystemCaCertsNix(ctx, &loaded);
3591
3592#endif
3593
3594    /* If we didn't fail but didn't load then we error out. */
3595    if ((ret == 1) && (!loaded)) {
3596        ret = WOLFSSL_BAD_PATH;
3597    }
3598
3599    WOLFSSL_LEAVE("wolfSSL_CTX_load_system_CA_certs", ret);
3600
3601    return ret;
3602}
3603
3604#endif /* WOLFSSL_SYS_CA_CERTS */
3605
3606#ifdef OPENSSL_EXTRA
3607
3608/* Load a private key into SSL.
3609 *
3610 * @param [in, out] ssl   SSL object.
3611 * @param [in]      pkey  EVP private key.
3612 * @return  1 on success.
3613 * @return  0 on failure.
3614 */
3615int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey)
3616{
3617    int ret;
3618
3619    WOLFSSL_ENTER("wolfSSL_use_PrivateKey");
3620
3621    /* Validate parameters. */
3622    if ((ssl == NULL) || (pkey == NULL)) {
3623        ret = 0;
3624    }
3625    else {
3626        /* Get DER encoded key data from EVP private key. */
3627        ret = wolfSSL_use_PrivateKey_buffer(ssl, (unsigned char*)pkey->pkey.ptr,
3628            pkey->pkey_sz, WOLFSSL_FILETYPE_ASN1);
3629    }
3630
3631    return ret;
3632}
3633
3634/* Load a DER encoded private key in a buffer into SSL.
3635 *
3636 * @param [in]      pri    Indicates type of private key. Ignored.
3637 * @param [in, out] ssl    SSL object.
3638 * @param [in]      der    Buffer holding DER encoded private key.
3639 * @param [in]      derSz  Size of data in bytes.
3640 * @return  1 on success.
3641 * @return  0 on failure.
3642 */
3643int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl, const unsigned char* der,
3644    long derSz)
3645{
3646    int ret;
3647
3648    WOLFSSL_ENTER("wolfSSL_use_PrivateKey_ASN1");
3649
3650    (void)pri;
3651
3652    /* Validate parameters. */
3653    if ((ssl == NULL) || (der == NULL)) {
3654        ret = 0;
3655    }
3656    else {
3657        ret = wolfSSL_use_PrivateKey_buffer(ssl, der, derSz,
3658            WOLFSSL_FILETYPE_ASN1);
3659    }
3660
3661    return ret;
3662}
3663
3664/* Load a DER encoded private key in a buffer into SSL context.
3665 *
3666 * @param [in]      pri    Indicates type of private key. Ignored.
3667 * @param [in, out] ctx    SSL context object.
3668 * @param [in]      der    Buffer holding DER encoded private key.
3669 * @param [in]      derSz  Size of data in bytes.
3670 * @return  1 on success.
3671 * @return  0 on failure.
3672 */
3673int wolfSSL_CTX_use_PrivateKey_ASN1(int pri, WOLFSSL_CTX* ctx,
3674    unsigned char* der, long derSz)
3675{
3676    int ret;
3677
3678    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_ASN1");
3679
3680    (void)pri;
3681
3682    /* Validate parameters. */
3683    if ((ctx == NULL) || (der == NULL)) {
3684        ret = 0;
3685    }
3686    else {
3687        ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, derSz,
3688            WOLFSSL_FILETYPE_ASN1);
3689    }
3690
3691    return ret;
3692}
3693
3694
3695#ifndef NO_RSA
3696/* Load a DER encoded RSA private key in a buffer into SSL.
3697 *
3698 * @param [in, out] ssl    SSL object.
3699 * @param [in]      der    Buffer holding DER encoded RSA private key.
3700 * @param [in]      derSz  Size of data in bytes.
3701 * @return  1 on success.
3702 * @return  0 on failure.
3703 */
3704int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, unsigned char* der, long derSz)
3705{
3706    int ret;
3707
3708    WOLFSSL_ENTER("wolfSSL_use_RSAPrivateKey_ASN1");
3709
3710    /* Validate parameters. */
3711    if ((ssl == NULL) || (der == NULL)) {
3712        ret = 0;
3713    }
3714    else {
3715        ret = wolfSSL_use_PrivateKey_buffer(ssl, der, derSz,
3716            WOLFSSL_FILETYPE_ASN1);
3717    }
3718
3719    return ret;
3720}
3721#endif
3722
3723/* Load a certificate into SSL.
3724 *
3725 * @param [in, out] ssl   SSL object.
3726 * @param [in]      x509  X509 certificate object.
3727 * @return  1 on success.
3728 * @return  0 on failure.
3729 */
3730int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509)
3731{
3732    int ret;
3733
3734    WOLFSSL_ENTER("wolfSSL_use_certificate");
3735
3736    /* Validate parameters. */
3737    if ((ssl == NULL) || (x509 == NULL) || (x509->derCert == NULL)) {
3738        ret = 0;
3739    }
3740    else {
3741        long idx = 0;
3742
3743        /* Get DER encoded certificate data from X509 object. */
3744        ret = ProcessBuffer(NULL, x509->derCert->buffer, x509->derCert->length,
3745            WOLFSSL_FILETYPE_ASN1, CERT_TYPE, ssl, &idx, 0,
3746            GET_VERIFY_SETTING_SSL(ssl),
3747            "x509 buffer");
3748    }
3749
3750    /* Return 1 on success or 0 on failure. */
3751    return WS_RC(ret);
3752}
3753
3754#endif /* OPENSSL_EXTRA */
3755
3756/* Load a DER encoded certificate in a buffer into SSL.
3757 *
3758 * @param [in, out] ssl    SSL object.
3759 * @param [in]      der    Buffer holding DER encoded certificate.
3760 * @param [in]      derSz  Size of data in bytes.
3761 * @return  1 on success.
3762 * @return  0 on failure.
3763 */
3764int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, const unsigned char* der,
3765    int derSz)
3766{
3767    int ret;
3768
3769    WOLFSSL_ENTER("wolfSSL_use_certificate_ASN1");
3770
3771    /* Validate parameters. */
3772    if ((ssl == NULL) || (der == NULL)) {
3773        ret = 0;
3774    }
3775    else {
3776        long idx = 0;
3777
3778        ret = ProcessBuffer(NULL, der, derSz, WOLFSSL_FILETYPE_ASN1, CERT_TYPE,
3779            ssl, &idx, 0, GET_VERIFY_SETTING_SSL(ssl),
3780            "asn1 buffer");
3781    }
3782
3783    /* Return 1 on success or 0 on failure. */
3784    return WS_RC(ret);
3785}
3786
3787#ifndef NO_FILESYSTEM
3788
3789/* Load a certificate from a file into SSL.
3790 *
3791 * @param [in, out] ssl     SSL object.
3792 * @param [in]      file    Name of file.
3793 * @param [in]      format  Format of data:
3794 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3795 * @return  1 on success.
3796 * @return  0 on failure.
3797 * @return  BAD_FUNC_ARG when ssl is NULL.
3798 */
3799WOLFSSL_ABI
3800int wolfSSL_use_certificate_file(WOLFSSL* ssl, const char* file, int format)
3801{
3802    int ret;
3803
3804    WOLFSSL_ENTER("wolfSSL_use_certificate_file");
3805
3806    /* Validate parameters. */
3807    if (ssl == NULL) {
3808        ret = BAD_FUNC_ARG;
3809    }
3810    else {
3811        ret = ProcessFile(ssl->ctx, file, format, CERT_TYPE, ssl, 0, NULL,
3812            GET_VERIFY_SETTING_SSL(ssl));
3813        /* Return 1 on success or 0 on failure. */
3814        ret = WS_RC(ret);
3815    }
3816
3817    return ret;
3818}
3819
3820
3821/* Load a private key from a file into SSL.
3822 *
3823 * @param [in, out] ssl     SSL object.
3824 * @param [in]      file    Name of file.
3825 * @param [in]      format  Format of data:
3826 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3827 * @return  1 on success.
3828 * @return  0 on failure.
3829 * @return  BAD_FUNC_ARG when ssl is NULL.
3830 */
3831WOLFSSL_ABI
3832int wolfSSL_use_PrivateKey_file(WOLFSSL* ssl, const char* file, int format)
3833{
3834    int ret;
3835
3836    WOLFSSL_ENTER("wolfSSL_use_PrivateKey_file");
3837
3838    /* Validate parameters. */
3839    if (ssl == NULL) {
3840        ret = BAD_FUNC_ARG;
3841    }
3842    else {
3843        ret = ProcessFile(ssl->ctx, file, format, PRIVATEKEY_TYPE, ssl, 0, NULL,
3844            GET_VERIFY_SETTING_SSL(ssl));
3845        /* Return 1 on success or 0 on failure. */
3846        ret = WS_RC(ret);
3847    }
3848
3849    return ret;
3850}
3851
3852
3853/* Load a PEM encoded certificate chain from a file into SSL.
3854 *
3855 * Process up to MAX_CHAIN_DEPTH plus subject cert.
3856 *
3857 * @param [in, out] ssl     SSL object.
3858 * @param [in]      file    Name of file.
3859 * @return  1 on success.
3860 * @return  0 on failure.
3861 * @return  BAD_FUNC_ARG when ssl is NULL.
3862 */
3863WOLFSSL_ABI
3864int wolfSSL_use_certificate_chain_file(WOLFSSL* ssl, const char* file)
3865{
3866    int ret;
3867
3868    WOLFSSL_ENTER("wolfSSL_use_certificate_chain_file");
3869
3870    /* Validate parameters. */
3871    if (ssl == NULL) {
3872        ret = BAD_FUNC_ARG;
3873    }
3874    else {
3875#ifdef WOLFSSL_PEM_TO_DER
3876        ret = ProcessFile(ssl->ctx, file, WOLFSSL_FILETYPE_PEM, CERT_TYPE, ssl,
3877            1, NULL, GET_VERIFY_SETTING_SSL(ssl));
3878#else
3879        ret = ProcessFile(ssl->ctx, file, WOLFSSL_FILETYPE_ASN1, CERT_TYPE, ssl,
3880            1, NULL, GET_VERIFY_SETTING_SSL(ssl));
3881#endif
3882        /* Return 1 on success or 0 on failure. */
3883        ret = WS_RC(ret);
3884    }
3885
3886   return ret;
3887}
3888
3889/* Load a certificate chain from a file into SSL.
3890 *
3891 * @param [in, out] ssl     SSL object.
3892 * @param [in]      file    Name of file.
3893 * @param [in]      format  Format of data:
3894 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3895 * @return  1 on success.
3896 * @return  0 on failure.
3897 * @return  BAD_FUNC_ARG when ssl is NULL.
3898 */
3899int wolfSSL_use_certificate_chain_file_format(WOLFSSL* ssl, const char* file,
3900    int format)
3901{
3902    int ret;
3903
3904    /* process up to MAX_CHAIN_DEPTH plus subject cert */
3905    WOLFSSL_ENTER("wolfSSL_use_certificate_chain_file_format");
3906
3907    /* Validate parameters. */
3908    if (ssl == NULL) {
3909        ret = BAD_FUNC_ARG;
3910    }
3911    else {
3912        ret = ProcessFile(ssl->ctx, file, format, CERT_TYPE, ssl, 1, NULL,
3913            GET_VERIFY_SETTING_SSL(ssl));
3914        /* Return 1 on success or 0 on failure. */
3915        ret = WS_RC(ret);
3916    }
3917
3918    return ret;
3919}
3920
3921#endif /* !NO_FILESYSTEM */
3922
3923#ifdef OPENSSL_EXTRA
3924
3925#ifndef NO_FILESYSTEM
3926/* Load an RSA private key from a file into SSL context.
3927 *
3928 * @param [in, out] ctx     SSL context object.
3929 * @param [in]      file    Name of file.
3930 * @param [in]      format  Format of data:
3931 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3932 * @return  1 on success.
3933 * @return  0 on failure.
3934 */
3935int wolfSSL_CTX_use_RSAPrivateKey_file(WOLFSSL_CTX* ctx,const char* file,
3936    int format)
3937{
3938    WOLFSSL_ENTER("wolfSSL_CTX_use_RSAPrivateKey_file");
3939
3940    return wolfSSL_CTX_use_PrivateKey_file(ctx, file, format);
3941}
3942
3943/* Load an RSA private key from a file into SSL.
3944 *
3945 * @param [in, out] ssl     SSL object.
3946 * @param [in]      file    Name of file.
3947 * @param [in]      format  Format of data:
3948 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3949 * @return  1 on success.
3950 * @return  0 on failure.
3951 * @return  BAD_FUNC_ARG when ssl is NULL.
3952 */
3953int wolfSSL_use_RSAPrivateKey_file(WOLFSSL* ssl, const char* file, int format)
3954{
3955    WOLFSSL_ENTER("wolfSSL_use_RSAPrivateKey_file");
3956
3957    return wolfSSL_use_PrivateKey_file(ssl, file, format);
3958}
3959#endif /* NO_FILESYSTEM */
3960
3961#endif /* OPENSSL_EXTRA */
3962
3963/* Load a buffer of certificate/s into SSL context.
3964 *
3965 * @param [in, out] ctx        SSL context object.
3966 * @param [in]      in         Buffer holding certificate or private key.
3967 * @param [in]      sz         Length of data in buffer in bytes.
3968 * @param [in]      format     Format of data:
3969 *                               WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
3970 * @param [in]      userChain  Whether file contains chain of certificates.
3971 * @param [in]      flags      Flags representing options for loading.
3972 * @return  1 on success.
3973 * @return  0 on failure.
3974 * @return  Negative on error.
3975 */
3976int wolfSSL_CTX_load_verify_buffer_ex(WOLFSSL_CTX* ctx, const unsigned char* in,
3977    long sz, int format, int userChain, word32 flags)
3978{
3979    int ret;
3980    int verify;
3981
3982    WOLFSSL_ENTER("wolfSSL_CTX_load_verify_buffer_ex");
3983
3984#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
3985    /* TEST ONLY CODE: force native cert validation on */
3986    if (ctx != NULL) {
3987        WOLFSSL_MSG("ANCV Test: loading system CA certs");
3988        wolfSSL_CTX_load_system_CA_certs(ctx);
3989    }
3990#endif
3991
3992    /* Get setting on how to verify certificates. */
3993    verify = GET_VERIFY_SETTING_CTX(ctx);
3994    /* Overwrite setting when flag set. */
3995    if (flags & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) {
3996        verify = VERIFY_SKIP_DATE;
3997    }
3998
3999    /* When PEM, treat as certificate chain of CA certificates. */
4000    if (format == WOLFSSL_FILETYPE_PEM) {
4001        ret = ProcessChainBuffer(ctx, NULL, in, sz, CA_TYPE, verify,
4002                                 "PEM buffer");
4003    }
4004    /* When DER, load the CA certificate. */
4005    else {
4006        ret = ProcessBuffer(ctx, in, sz, format, CA_TYPE, NULL, NULL,
4007            userChain, verify, "buffer");
4008    }
4009#if defined(WOLFSSL_TRUST_PEER_CERT) && defined(OPENSSL_COMPATIBLE_DEFAULTS)
4010    if (ret == 1) {
4011        /* Load certificate/s as trusted peer certificate. */
4012        ret = wolfSSL_CTX_trust_peer_buffer(ctx, in, sz, format);
4013    }
4014#endif
4015
4016    WOLFSSL_LEAVE("wolfSSL_CTX_load_verify_buffer_ex", ret);
4017    return ret;
4018}
4019
4020/* Load a buffer of certificate/s into SSL context.
4021 *
4022 * @param [in, out] ctx     SSL context object.
4023 * @param [in]      in      Buffer holding certificate or private key.
4024 * @param [in]      sz      Length of data in buffer in bytes.
4025 * @param [in]      format  Format of data:
4026 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4027 * @return  1 on success.
4028 * @return  0 on failure.
4029 * @return  Negative on error.
4030 */
4031int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
4032    long sz, int format)
4033{
4034    return wolfSSL_CTX_load_verify_buffer_ex(ctx, in, sz, format, 0,
4035        WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS);
4036}
4037
4038/* Load a buffer of certificate chain into SSL context.
4039 *
4040 * @param [in, out] ctx     SSL context object.
4041 * @param [in]      in      Buffer holding certificate chain.
4042 * @param [in]      sz      Length of data in buffer in bytes.
4043 * @param [in]      format  Format of data:
4044 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4045 * @return  1 on success.
4046 * @return  0 on failure.
4047 * @return  Negative on error.
4048 */
4049int wolfSSL_CTX_load_verify_chain_buffer_format(WOLFSSL_CTX* ctx,
4050    const unsigned char* in, long sz, int format)
4051{
4052    return wolfSSL_CTX_load_verify_buffer_ex(ctx, in, sz, format, 1,
4053        WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS);
4054}
4055
4056
4057#ifdef WOLFSSL_TRUST_PEER_CERT
4058/* Load a buffer of certificate/s into SSL context.
4059 *
4060 * @param [in, out] ctx     SSL context object.
4061 * @param [in]      in      Buffer holding certificate/s.
4062 * @param [in]      sz      Length of data in buffer in bytes.
4063 * @param [in]      format  Format of data:
4064 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4065 * @return  1 on success.
4066 * @return  0 on failure.
4067 * @return  BAD_FUNC_ARG when ctx or in is NULL, or sz is less than zero.
4068 */
4069int wolfSSL_CTX_trust_peer_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
4070    long sz, int format)
4071{
4072    int ret;
4073    int verify;
4074
4075    WOLFSSL_ENTER("wolfSSL_CTX_trust_peer_buffer");
4076
4077    /* Validate parameters. */
4078    if ((ctx == NULL) || (in == NULL) || (sz < 0)) {
4079        ret = BAD_FUNC_ARG;
4080    }
4081    else {
4082    #if WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY
4083        verify = VERIFY_SKIP_DATE;
4084    #else
4085        verify = GET_VERIFY_SETTING_CTX(ctx);
4086    #endif
4087
4088        /* When PEM, treat as certificate chain of trusted peer certificates. */
4089        if (format == WOLFSSL_FILETYPE_PEM) {
4090            ret = ProcessChainBuffer(ctx, NULL, in, sz, TRUSTED_PEER_TYPE,
4091                verify, "peer");
4092        }
4093        /* When DER, load the trusted peer certificate. */
4094        else {
4095            ret = ProcessBuffer(ctx, in, sz, format, TRUSTED_PEER_TYPE, NULL,
4096                NULL, 0, verify, "peer");
4097        }
4098    }
4099
4100    return ret;
4101}
4102#endif /* WOLFSSL_TRUST_PEER_CERT */
4103
4104/* Load a certificate in a buffer into SSL context.
4105 *
4106 * @param [in, out] ctx     SSL context object.
4107 * @param [in]      in      Buffer holding certificate.
4108 * @param [in]      sz      Size of data in bytes.
4109 * @param [in]      format  Format of data:
4110 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4111 * @return  1 on success.
4112 * @return  0 on failure.
4113 * @return  Negative on error.
4114 */
4115int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX* ctx,
4116    const unsigned char* in, long sz, int format)
4117{
4118    int ret;
4119
4120    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_buffer");
4121    ret = ProcessBuffer(ctx, in, sz, format, CERT_TYPE, NULL, NULL, 0,
4122        GET_VERIFY_SETTING_CTX(ctx), "buffer");
4123    WOLFSSL_LEAVE("wolfSSL_CTX_use_certificate_buffer", ret);
4124
4125    return ret;
4126}
4127
4128/* Load a private key in a buffer into SSL context.
4129 *
4130 * @param [in, out] ctx     SSL context object.
4131 * @param [in]      in      Buffer holding private key.
4132 * @param [in]      sz      Size of data in bytes.
4133 * @param [in]      format  Format of data:
4134 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4135 * @return  1 on success.
4136 * @return  0 on failure.
4137 * @return  Negative on error.
4138 */
4139int wolfSSL_CTX_use_PrivateKey_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
4140    long sz, int format)
4141{
4142    int ret;
4143    long consumed = 0;
4144
4145    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_buffer");
4146
4147    ret = ProcessBuffer(ctx, in, sz, format, PRIVATEKEY_TYPE, NULL, &consumed,
4148        0, GET_VERIFY_SETTING_CTX(ctx), "key buffer");
4149#ifdef WOLFSSL_DUAL_ALG_CERTS
4150    if ((ret == 1) && (consumed < sz)) {
4151        /* When support for dual algorithm certificates is enabled, the
4152         * buffer may contain both the primary and the alternative
4153         * private key. Hence, we have to parse both of them.
4154         */
4155        ret = ProcessBuffer(ctx, in + consumed, sz - consumed, format,
4156            ALT_PRIVATEKEY_TYPE, NULL, NULL, 0, GET_VERIFY_SETTING_CTX(ctx),
4157            "key buffer");
4158    }
4159#endif
4160
4161    (void)consumed;
4162
4163    WOLFSSL_LEAVE("wolfSSL_CTX_use_PrivateKey_buffer", ret);
4164    return ret;
4165}
4166
4167#ifdef WOLFSSL_DUAL_ALG_CERTS
4168int wolfSSL_CTX_use_AltPrivateKey_buffer(WOLFSSL_CTX* ctx,
4169    const unsigned char* in, long sz, int format)
4170{
4171    int ret;
4172
4173    WOLFSSL_ENTER("wolfSSL_CTX_use_AltPrivateKey_buffer");
4174    ret = ProcessBuffer(ctx, in, sz, format, ALT_PRIVATEKEY_TYPE, NULL,
4175        NULL, 0, GET_VERIFY_SETTING_CTX(ctx), "alt key buffer");
4176    WOLFSSL_LEAVE("wolfSSL_CTX_use_AltPrivateKey_buffer", ret);
4177
4178    return ret;
4179}
4180#endif /* WOLFSSL_DUAL_ALG_CERTS */
4181
4182#ifdef WOLF_PRIVATE_KEY_ID
4183/* Load the id of a private key into SSL context.
4184 *
4185 * @param [in, out] ctx    SSL context object.
4186 * @param [in]      id     Buffer holding id.
4187 * @param [in]      sz     Size of data in bytes.
4188 * @param [in]      devId  Device identifier.
4189 * @return  1 on success.
4190 * @return  0 on failure.
4191 */
4192int wolfSSL_CTX_use_PrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id,
4193    long sz, int devId)
4194{
4195    int ret = 1;
4196
4197    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_Id");
4198
4199    if (ctx == NULL || id == NULL || sz < 0) {
4200        return 0;
4201    }
4202
4203    /* Dispose of old private key and allocate and copy in id. */
4204    FreeDer(&ctx->privateKey);
4205    if (AllocCopyDer(&ctx->privateKey, id, (word32)sz, PRIVATEKEY_TYPE,
4206            ctx->heap) != 0) {
4207        ret = 0;
4208    }
4209    if (ret == 1) {
4210        /* Private key is an id. */
4211        ctx->privateKeyId = 1;
4212        ctx->privateKeyLabel = 0;
4213        /* Set private key device id to be one passed in or for SSL context. */
4214        if (devId != INVALID_DEVID) {
4215            ctx->privateKeyDevId = devId;
4216        }
4217        else {
4218            ctx->privateKeyDevId = ctx->devId;
4219        }
4220
4221    #ifdef WOLFSSL_DUAL_ALG_CERTS
4222        /* Set the ID for the alternative key, too. User can still override that
4223         * afterwards. */
4224        ret = wolfSSL_CTX_use_AltPrivateKey_Id(ctx, id, sz, devId);
4225    #endif
4226    }
4227
4228    WOLFSSL_LEAVE("wolfSSL_CTX_use_PrivateKey_Id", ret);
4229    return ret;
4230}
4231
4232/* Load the id of a private key into SSL context and set key size.
4233 *
4234 * @param [in, out] ctx    SSL context object.
4235 * @param [in]      id     Buffer holding id.
4236 * @param [in]      sz     Size of data in bytes.
4237 * @param [in]      devId  Device identifier.
4238 * @param [in]      keySz  Size of key.
4239 * @return  1 on success.
4240 * @return  0 on failure.
4241 */
4242int wolfSSL_CTX_use_PrivateKey_Id_ex(WOLFSSL_CTX* ctx, const unsigned char* id,
4243    long sz, int devId, long keySz)
4244{
4245    int ret;
4246
4247    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_Id_ex");
4248
4249    ret = wolfSSL_CTX_use_PrivateKey_Id(ctx, id, sz, devId);
4250    if (ret == 1) {
4251        /* Set the key size which normally is calculated during decoding. */
4252        ctx->privateKeySz = (int)keySz;
4253    }
4254
4255    WOLFSSL_LEAVE("wolfSSL_CTX_use_PrivateKey_Id_ex", ret);
4256    return ret;
4257}
4258
4259/* Load the label name of a private key into SSL context.
4260 *
4261 * @param [in, out] ctx    SSL context object.
4262 * @param [in]      label  Buffer holding label.
4263 * @param [in]      devId  Device identifier.
4264 * @return  1 on success.
4265 * @return  0 on failure.
4266 */
4267int wolfSSL_CTX_use_PrivateKey_Label(WOLFSSL_CTX* ctx, const char* label,
4268    int devId)
4269{
4270    int ret = 1;
4271    word32 sz;
4272
4273    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_Label");
4274
4275    if (ctx == NULL || label == NULL) {
4276        return 0;
4277    }
4278
4279    sz = (word32)XSTRLEN(label) + 1;
4280
4281    /* Dispose of old private key and allocate and copy in label. */
4282    FreeDer(&ctx->privateKey);
4283    if (AllocCopyDer(&ctx->privateKey, (const byte*)label, (word32)sz,
4284            PRIVATEKEY_TYPE, ctx->heap) != 0) {
4285        ret = 0;
4286    }
4287    if (ret == 1) {
4288        /* Private key is a label. */
4289        ctx->privateKeyId = 0;
4290        ctx->privateKeyLabel = 1;
4291        /* Set private key device id to be one passed in or for SSL context. */
4292        if (devId != INVALID_DEVID) {
4293            ctx->privateKeyDevId = devId;
4294        }
4295        else {
4296            ctx->privateKeyDevId = ctx->devId;
4297        }
4298
4299    #ifdef WOLFSSL_DUAL_ALG_CERTS
4300        /* Set the ID for the alternative key, too. User can still override that
4301         * afterwards. */
4302        ret = wolfSSL_CTX_use_AltPrivateKey_Label(ctx, label, devId);
4303    #endif
4304    }
4305
4306    WOLFSSL_LEAVE("wolfSSL_CTX_use_PrivateKey_Label", ret);
4307    return ret;
4308}
4309
4310#ifdef WOLFSSL_DUAL_ALG_CERTS
4311int wolfSSL_CTX_use_AltPrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id,
4312    long sz, int devId)
4313{
4314    int ret = 1;
4315
4316    WOLFSSL_ENTER("wolfSSL_CTX_use_AltPrivateKey_Id");
4317
4318    if ((ctx == NULL) || (id == NULL) || (sz < 0)) {
4319        ret = 0;
4320    }
4321
4322    if (ret == 1) {
4323        FreeDer(&ctx->altPrivateKey);
4324        if (AllocDer(&ctx->altPrivateKey, (word32)sz, ALT_PRIVATEKEY_TYPE,
4325                ctx->heap) != 0) {
4326            ret = 0;
4327        }
4328    }
4329    if (ret == 1) {
4330        XMEMCPY(ctx->altPrivateKey->buffer, id, (word32)sz);
4331        ctx->altPrivateKeyId = 1;
4332        if (devId != INVALID_DEVID) {
4333            ctx->altPrivateKeyDevId = devId;
4334        }
4335        else {
4336            ctx->altPrivateKeyDevId = ctx->devId;
4337        }
4338    }
4339
4340    WOLFSSL_LEAVE("wolfSSL_CTX_use_AltPrivateKey_Id", ret);
4341    return ret;
4342}
4343
4344int wolfSSL_CTX_use_AltPrivateKey_Id_ex(WOLFSSL_CTX* ctx,
4345    const unsigned char* id, long sz, int devId, long keySz)
4346{
4347    int ret;
4348
4349    WOLFSSL_ENTER("wolfSSL_CTX_use_AltPrivateKey_Id_ex");
4350
4351    ret = wolfSSL_CTX_use_AltPrivateKey_Id(ctx, id, sz, devId);
4352    if (ret == 1) {
4353        ctx->altPrivateKeySz = (word32)keySz;
4354    }
4355
4356    WOLFSSL_LEAVE("wolfSSL_CTX_use_AltPrivateKey_Id_ex", ret);
4357    return ret;
4358}
4359
4360int wolfSSL_CTX_use_AltPrivateKey_Label(WOLFSSL_CTX* ctx, const char* label,
4361    int devId)
4362{
4363    int ret = 1;
4364    word32 sz;
4365
4366    WOLFSSL_ENTER("wolfSSL_CTX_use_AltPrivateKey_Label");
4367
4368    if ((ctx == NULL) || (label == NULL)) {
4369        ret = 0;
4370    }
4371
4372    if (ret == 1) {
4373        sz = (word32)XSTRLEN(label) + 1;
4374        FreeDer(&ctx->altPrivateKey);
4375        if (AllocDer(&ctx->altPrivateKey, (word32)sz, ALT_PRIVATEKEY_TYPE,
4376                ctx->heap) != 0) {
4377            ret = 0;
4378        }
4379    }
4380    if (ret == 1) {
4381        XMEMCPY(ctx->altPrivateKey->buffer, label, sz);
4382        ctx->altPrivateKeyLabel = 1;
4383        if (devId != INVALID_DEVID) {
4384            ctx->altPrivateKeyDevId = devId;
4385        }
4386        else {
4387            ctx->altPrivateKeyDevId = ctx->devId;
4388        }
4389    }
4390
4391    WOLFSSL_LEAVE("wolfSSL_CTX_use_AltPrivateKey_Label", ret);
4392    return ret;
4393}
4394#endif /* WOLFSSL_DUAL_ALG_CERTS */
4395#endif /* WOLF_PRIVATE_KEY_ID */
4396
4397#if defined(WOLF_CRYPTO_CB) && !defined(NO_CERTS)
4398
4399static int wolfSSL_CTX_use_certificate_ex(WOLFSSL_CTX* ctx,
4400    const char *label, const unsigned char *id, int idLen, int devId)
4401{
4402    int ret;
4403    byte *certData = NULL;
4404    word32 certDataLen = 0;
4405    word32 labelLen = 0;
4406    int certFormat = 0;
4407
4408    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_ex");
4409
4410    if (label != NULL) {
4411        labelLen = (word32)XSTRLEN(label);
4412    }
4413
4414    ret = wc_CryptoCb_GetCert(devId, label, labelLen, id, idLen,
4415        &certData, &certDataLen, &certFormat, ctx->heap);
4416    if (ret != 0) {
4417        ret = WOLFSSL_FAILURE;
4418        goto exit;
4419    }
4420
4421    ret = ProcessBuffer(ctx, certData, certDataLen, certFormat,
4422        CERT_TYPE, NULL, NULL, 0, GET_VERIFY_SETTING_CTX(ctx),
4423        label ? label : "cert buffer");
4424
4425exit:
4426    XFREE(certData, ctx->heap, DYNAMIC_TYPE_CERT);
4427    return ret;
4428}
4429
4430/* Load the label name of a certificate into the SSL context.
4431 *
4432 * @param [in, out] ctx    SSL context object.
4433 * @param [in]      label  Buffer holding label.
4434 * @param [in]      devId  Device identifier.
4435 * @return  1 on success.
4436 * @return  0 on failure.
4437 */
4438int wolfSSL_CTX_use_certificate_label(WOLFSSL_CTX* ctx,
4439    const char *label, int devId)
4440{
4441    if ((ctx == NULL) || (label == NULL)) {
4442        return WOLFSSL_FAILURE;
4443    }
4444
4445    return wolfSSL_CTX_use_certificate_ex(ctx, label, NULL, 0, devId);
4446}
4447
4448/* Load the id of a certificate into SSL context.
4449 *
4450 * @param [in, out] ctx    SSL context object.
4451 * @param [in]      id     Buffer holding id.
4452 * @param [in]      idLen  Size of data in bytes.
4453 * @param [in]      devId  Device identifier.
4454 * @return  1 on success.
4455 * @return  0 on failure.
4456 */
4457int wolfSSL_CTX_use_certificate_id(WOLFSSL_CTX* ctx,
4458    const unsigned char *id, int idLen, int devId)
4459{
4460    if ((ctx == NULL) || (id == NULL) || (idLen <= 0)) {
4461        return WOLFSSL_FAILURE;
4462    }
4463
4464    return wolfSSL_CTX_use_certificate_ex(ctx, NULL, id, idLen, devId);
4465}
4466
4467#endif /* if defined(WOLF_CRYPTO_CB) && !defined(NO_CERTS) */
4468
4469/* Load a certificate chain in a buffer into SSL context.
4470 *
4471 * @param [in, out] ctx     SSL context object.
4472 * @param [in]      in      Buffer holding DER encoded certificate chain.
4473 * @param [in]      sz      Size of data in bytes.
4474 * @param [in]      format  Format of data:
4475 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4476 * @return  1 on success.
4477 * @return  0 on failure.
4478 * @return  Negative on error.
4479 */
4480int wolfSSL_CTX_use_certificate_chain_buffer_format(WOLFSSL_CTX* ctx,
4481    const unsigned char* in, long sz, int format)
4482{
4483    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_chain_buffer_format");
4484    return ProcessBuffer(ctx, in, sz, format, CERT_TYPE, NULL, NULL, 1,
4485        GET_VERIFY_SETTING_CTX(ctx), "cert chain buffer");
4486}
4487
4488/* Load a PEM encoded certificate chain in a buffer into SSL context.
4489 *
4490 * @param [in, out] ctx     SSL context object.
4491 * @param [in]      in      Buffer holding DER encoded certificate chain.
4492 * @param [in]      sz      Size of data in bytes.
4493 * @return  1 on success.
4494 * @return  0 on failure.
4495 * @return  Negative on error.
4496 */
4497int wolfSSL_CTX_use_certificate_chain_buffer(WOLFSSL_CTX* ctx,
4498    const unsigned char* in, long sz)
4499{
4500#ifdef WOLFSSL_PEM_TO_DER
4501    return wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, in, sz,
4502        WOLFSSL_FILETYPE_PEM);
4503#else
4504    return wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, in, sz,
4505        WOLFSSL_FILETYPE_ASN1);
4506#endif
4507}
4508
4509/* Load a user certificate in a buffer into SSL.
4510 *
4511 * @param [in, out] ssl     SSL object.
4512 * @param [in]      in      Buffer holding user certificate.
4513 * @param [in]      sz      Size of data in bytes.
4514 * @param [in]      format  Format of data:
4515 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4516 * @return  1 on success.
4517 * @return  0 on failure.
4518 * @return  BAD_FUNC_ARG when ssl is NULL.
4519 */
4520int wolfSSL_use_certificate_buffer(WOLFSSL* ssl, const unsigned char* in,
4521    long sz, int format)
4522{
4523    int ret;
4524
4525    WOLFSSL_ENTER("wolfSSL_use_certificate_buffer");
4526
4527    /* Validate parameters. */
4528    if (ssl == NULL) {
4529        ret = BAD_FUNC_ARG;
4530    }
4531    else {
4532        ret = ProcessBuffer(ssl->ctx, in, sz, format, CERT_TYPE, ssl, NULL, 0,
4533            GET_VERIFY_SETTING_SSL(ssl), "cert buffer");
4534    }
4535
4536    return ret;
4537}
4538
4539/* Load a private key in a buffer into SSL.
4540 *
4541 * @param [in, out] ssl     SSL object.
4542 * @param [in]      in      Buffer holding private key.
4543 * @param [in]      sz      Size of data in bytes.
4544 * @param [in]      format  Format of data:
4545 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4546 * @return  1 on success.
4547 * @return  0 on failure.
4548 * @return  BAD_FUNC_ARG when ssl is NULL.
4549 */
4550int wolfSSL_use_PrivateKey_buffer(WOLFSSL* ssl, const unsigned char* in,
4551    long sz, int format)
4552{
4553    int ret;
4554    long consumed = 0;
4555
4556    WOLFSSL_ENTER("wolfSSL_use_PrivateKey_buffer");
4557
4558    /* Validate parameters. */
4559    if (ssl == NULL) {
4560        ret = BAD_FUNC_ARG;
4561    }
4562    else {
4563        ret = ProcessBuffer(ssl->ctx, in, sz, format, PRIVATEKEY_TYPE, ssl,
4564            &consumed, 0, GET_VERIFY_SETTING_SSL(ssl), "key buffer");
4565    #ifdef WOLFSSL_DUAL_ALG_CERTS
4566        if ((ret == 1) && (consumed < sz)) {
4567            /* When support for dual algorithm certificates is enabled, the
4568             * buffer may contain both the primary and the alternative
4569             * private key. Hence, we have to parse both of them.
4570             */
4571            ret = ProcessBuffer(ssl->ctx, in + consumed, sz - consumed, format,
4572                ALT_PRIVATEKEY_TYPE, ssl, NULL, 0, GET_VERIFY_SETTING_SSL(ssl),
4573                "key buffer");
4574        }
4575    #endif
4576    }
4577
4578    return ret;
4579}
4580
4581#ifdef WOLFSSL_DUAL_ALG_CERTS
4582int wolfSSL_use_AltPrivateKey_buffer(WOLFSSL* ssl, const unsigned char* in,
4583    long sz, int format)
4584{
4585    int ret;
4586
4587    WOLFSSL_ENTER("wolfSSL_use_AltPrivateKey_buffer");
4588    ret = ProcessBuffer(ssl->ctx, in, sz, format, ALT_PRIVATEKEY_TYPE, ssl,
4589        NULL, 0, GET_VERIFY_SETTING_SSL(ssl), "alt key buffer");
4590    WOLFSSL_LEAVE("wolfSSL_use_AltPrivateKey_buffer", ret);
4591
4592    return ret;
4593}
4594#endif /* WOLFSSL_DUAL_ALG_CERTS */
4595
4596#ifdef WOLF_PRIVATE_KEY_ID
4597/* Load the id of a private key into SSL.
4598 *
4599 * @param [in, out] ssl    SSL object.
4600 * @param [in]      id     Buffer holding id.
4601 * @param [in]      sz     Size of data in bytes.
4602 * @param [in]      devId  Device identifier.
4603 * @return  1 on success.
4604 * @return  0 on failure.
4605 */
4606int wolfSSL_use_PrivateKey_Id(WOLFSSL* ssl, const unsigned char* id,
4607                              long sz, int devId)
4608{
4609    int ret = 1;
4610
4611    if (ssl == NULL || id == NULL || sz < 0) {
4612        return 0;
4613    }
4614
4615    /* Dispose of old private key if owned and allocate and copy in id. */
4616    if (ssl->buffers.weOwnKey) {
4617        FreeDer(&ssl->buffers.key);
4618    #ifdef WOLFSSL_BLIND_PRIVATE_KEY
4619        FreeDer(&ssl->buffers.keyMask);
4620    #endif
4621    }
4622    if (AllocCopyDer(&ssl->buffers.key, id, (word32)sz, PRIVATEKEY_TYPE,
4623            ssl->heap) != 0) {
4624        ret = 0;
4625    }
4626    if (ret == 1) {
4627        /* Buffer now ours. */
4628        ssl->buffers.weOwnKey = 1;
4629        /* Private key is an id. */
4630        ssl->buffers.keyId = 1;
4631        ssl->buffers.keyLabel = 0;
4632        /* Set private key device id to be one passed in or for SSL. */
4633        if (devId != INVALID_DEVID) {
4634            ssl->buffers.keyDevId = devId;
4635        }
4636        else {
4637            ssl->buffers.keyDevId = ssl->devId;
4638        }
4639
4640    #ifdef WOLFSSL_DUAL_ALG_CERTS
4641        /* Set the ID for the alternative key, too. User can still override that
4642         * afterwards. */
4643        ret = wolfSSL_use_AltPrivateKey_Id(ssl, id, sz, devId);
4644    #endif
4645    }
4646
4647    return ret;
4648}
4649
4650/* Load the id of a private key into SSL and set key size.
4651 *
4652 * @param [in, out] ssl    SSL object.
4653 * @param [in]      id     Buffer holding id.
4654 * @param [in]      sz     Size of data in bytes.
4655 * @param [in]      devId  Device identifier.
4656 * @param [in]      keySz  Size of key.
4657 * @return  1 on success.
4658 * @return  0 on failure.
4659 */
4660int wolfSSL_use_PrivateKey_Id_ex(WOLFSSL* ssl, const unsigned char* id,
4661    long sz, int devId, long keySz)
4662{
4663    int ret = wolfSSL_use_PrivateKey_Id(ssl, id, sz, devId);
4664    if (ret == 1) {
4665        /* Set the key size which normally is calculated during decoding. */
4666        ssl->buffers.keySz = (int)keySz;
4667    }
4668
4669    return ret;
4670}
4671
4672/* Load the label name of a private key into SSL.
4673 *
4674 * @param [in, out] ssl    SSL object.
4675 * @param [in]      label  Buffer holding label.
4676 * @param [in]      devId  Device identifier.
4677 * @return  1 on success.
4678 * @return  0 on failure.
4679 */
4680int wolfSSL_use_PrivateKey_Label(WOLFSSL* ssl, const char* label, int devId)
4681{
4682    int ret = 1;
4683    word32 sz;
4684
4685    if (ssl == NULL || label == NULL) {
4686        return 0;
4687    }
4688
4689    sz = (word32)XSTRLEN(label) + 1;
4690
4691    /* Dispose of old private key if owned and allocate and copy in label. */
4692    if (ssl->buffers.weOwnKey) {
4693        FreeDer(&ssl->buffers.key);
4694    #ifdef WOLFSSL_BLIND_PRIVATE_KEY
4695        FreeDer(&ssl->buffers.keyMask);
4696    #endif
4697    }
4698    if (AllocCopyDer(&ssl->buffers.key, (const byte*)label, (word32)sz,
4699            PRIVATEKEY_TYPE, ssl->heap) != 0) {
4700        ret = 0;
4701    }
4702    if (ret == 1) {
4703        /* Buffer now ours. */
4704        ssl->buffers.weOwnKey = 1;
4705        /* Private key is a label. */
4706        ssl->buffers.keyId = 0;
4707        ssl->buffers.keyLabel = 1;
4708        /* Set private key device id to be one passed in or for SSL. */
4709        if (devId != INVALID_DEVID) {
4710            ssl->buffers.keyDevId = devId;
4711        }
4712        else {
4713            ssl->buffers.keyDevId = ssl->devId;
4714        }
4715
4716    #ifdef WOLFSSL_DUAL_ALG_CERTS
4717        /* Set the label for the alternative key, too. User can still override
4718         * that afterwards. */
4719        ret = wolfSSL_use_AltPrivateKey_Label(ssl, label, devId);
4720    #endif
4721    }
4722
4723    return ret;
4724}
4725
4726#ifdef WOLFSSL_DUAL_ALG_CERTS
4727int wolfSSL_use_AltPrivateKey_Id(WOLFSSL* ssl, const unsigned char* id, long sz,
4728    int devId)
4729{
4730    int ret = 1;
4731
4732    if ((ssl == NULL) || (id == NULL) || (sz < 0)) {
4733        ret = 0;
4734    }
4735
4736    if (ret == 1) {
4737        if (ssl->buffers.weOwnAltKey) {
4738            FreeDer(&ssl->buffers.altKey);
4739        #ifdef WOLFSSL_BLIND_PRIVATE_KEY
4740            FreeDer(&ssl->buffers.altKeyMask);
4741        #endif
4742        }
4743        if (AllocDer(&ssl->buffers.altKey, (word32)sz, ALT_PRIVATEKEY_TYPE,
4744                ssl->heap) != 0) {
4745            ret = 0;
4746        }
4747    }
4748    if (ret == 1) {
4749        XMEMCPY(ssl->buffers.altKey->buffer, id, (word32)sz);
4750        ssl->buffers.weOwnAltKey = 1;
4751        ssl->buffers.altKeyId = 1;
4752        if (devId != INVALID_DEVID) {
4753            ssl->buffers.altKeyDevId = devId;
4754        }
4755        else {
4756            ssl->buffers.altKeyDevId = ssl->devId;
4757        }
4758    }
4759
4760    return ret;
4761}
4762
4763int wolfSSL_use_AltPrivateKey_Id_ex(WOLFSSL* ssl, const unsigned char* id,
4764    long sz, int devId, long keySz)
4765{
4766    int ret = wolfSSL_use_AltPrivateKey_Id(ssl, id, sz, devId);
4767    if (ret == 1) {
4768        ssl->buffers.altKeySz = (word32)keySz;
4769    }
4770
4771    return ret;
4772}
4773
4774int wolfSSL_use_AltPrivateKey_Label(WOLFSSL* ssl, const char* label, int devId)
4775{
4776    int ret = 1;
4777    word32 sz;
4778
4779    if ((ssl == NULL) || (label == NULL)) {
4780        ret = 0;
4781    }
4782
4783    if (ret == 1) {
4784        sz = (word32)XSTRLEN(label) + 1;
4785        if (ssl->buffers.weOwnAltKey) {
4786            FreeDer(&ssl->buffers.altKey);
4787        #ifdef WOLFSSL_BLIND_PRIVATE_KEY
4788            FreeDer(&ssl->buffers.altKeyMask);
4789        #endif
4790        }
4791        if (AllocDer(&ssl->buffers.altKey, (word32)sz, ALT_PRIVATEKEY_TYPE,
4792                ssl->heap) != 0) {
4793            ret = 0;
4794        }
4795    }
4796    if (ret == 1) {
4797        XMEMCPY(ssl->buffers.altKey->buffer, label, sz);
4798        ssl->buffers.weOwnAltKey = 1;
4799        ssl->buffers.altKeyLabel = 1;
4800        if (devId != INVALID_DEVID) {
4801            ssl->buffers.altKeyDevId = devId;
4802        }
4803        else {
4804            ssl->buffers.altKeyDevId = ssl->devId;
4805        }
4806    }
4807
4808    return ret;
4809}
4810#endif /* WOLFSSL_DUAL_ALG_CERTS */
4811#endif /* WOLF_PRIVATE_KEY_ID */
4812
4813/* Load a certificate chain in a buffer into SSL.
4814 *
4815 * @param [in, out] ssl     SSL object.
4816 * @param [in]      in      Buffer holding DER encoded certificate chain.
4817 * @param [in]      sz      Size of data in bytes.
4818 * @param [in]      format  Format of data:
4819 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
4820 * @return  1 on success.
4821 * @return  0 on failure.
4822 * @return  BAD_FUNC_ARG when ssl is NULL.
4823 */
4824int wolfSSL_use_certificate_chain_buffer_format(WOLFSSL* ssl,
4825    const unsigned char* in, long sz, int format)
4826{
4827    int ret;
4828
4829    WOLFSSL_ENTER("wolfSSL_use_certificate_chain_buffer_format");
4830
4831    /* Validate parameters. */
4832    if (ssl == NULL) {
4833        ret = BAD_FUNC_ARG;
4834    }
4835    else {
4836        ret = ProcessBuffer(ssl->ctx, in, sz, format, CERT_TYPE, ssl, NULL, 1,
4837            GET_VERIFY_SETTING_SSL(ssl), "cert chain buffer");
4838    }
4839
4840    return ret;
4841}
4842
4843/* Load a PEM encoded certificate chain in a buffer into SSL.
4844 *
4845 * @param [in, out] ssl     SSL object.
4846 * @param [in]      in      Buffer holding DER encoded certificate chain.
4847 * @param [in]      sz      Size of data in bytes.
4848 * @return  1 on success.
4849 * @return  0 on failure.
4850 * @return  Negative on error.
4851 */
4852int wolfSSL_use_certificate_chain_buffer(WOLFSSL* ssl, const unsigned char* in,
4853    long sz)
4854{
4855#ifdef WOLFSSL_PEM_TO_DER
4856    return wolfSSL_use_certificate_chain_buffer_format(ssl, in, sz,
4857        WOLFSSL_FILETYPE_PEM);
4858#else
4859    return wolfSSL_use_certificate_chain_buffer_format(ssl, in, sz,
4860        WOLFSSL_FILETYPE_ASN1);
4861#endif
4862}
4863
4864#if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
4865    defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
4866    defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
4867    defined(WOLFSSL_HAPROXY)
4868/* Add certificate to chain.
4869 *
4870 * @param [in, out] chain   Buffer holding encoded certificate for TLS.
4871 * @param [in]      weOwn   Indicates we need to free chain if repleced.
4872 * @param [in]      cert    Buffer holding DER encoded certificate.
4873 * @param [in]      certSz  Size of DER encoded certificate in bytes.
4874 * @param [in]      heap    Dynamic memory allocation hint.
4875 * @return  1 on success.
4876 * @return  0 on failure.
4877 */
4878static int wolfssl_add_to_chain(DerBuffer** chain, int weOwn, const byte* cert,
4879    word32 certSz, void* heap)
4880{
4881    int res = 1;
4882    int ret;
4883    DerBuffer* oldChain = *chain;
4884    DerBuffer* newChain = NULL;
4885    word32 len = 0;
4886
4887    if (oldChain != NULL) {
4888        /* Get length of previous chain. */
4889        len = oldChain->length;
4890    }
4891    /* Check for integer overflow in size calculation. */
4892    if ((len > WOLFSSL_MAX_32BIT - CERT_HEADER_SZ) ||
4893            (certSz > WOLFSSL_MAX_32BIT - CERT_HEADER_SZ - len)) {
4894        WOLFSSL_MSG("wolfssl_add_to_chain overflow");
4895        res = 0;
4896    }
4897    if (res == 1) {
4898        /* Allocate DER buffer big enough to hold old and new certificates. */
4899        ret = AllocDer(&newChain, len + CERT_HEADER_SZ + certSz, CERT_TYPE,
4900            heap);
4901        if (ret != 0) {
4902            WOLFSSL_MSG("AllocDer error");
4903            res = 0;
4904        }
4905    }
4906
4907    if (res == 1) {
4908        if (oldChain != NULL) {
4909            /* Place old chain in new buffer. */
4910            XMEMCPY(newChain->buffer, oldChain->buffer, len);
4911        }
4912        /* Append length and DER encoded certificate. */
4913        c32to24(certSz, newChain->buffer + len);
4914        XMEMCPY(newChain->buffer + len + CERT_HEADER_SZ, cert, certSz);
4915
4916        /* Dispose of old chain if we own it. */
4917        if (weOwn) {
4918            FreeDer(chain);
4919        }
4920        /* Replace chain. */
4921        *chain = newChain;
4922    }
4923
4924    return res;
4925}
4926#endif
4927
4928#ifdef OPENSSL_EXTRA
4929
4930/* Add a certificate to end of chain sent in TLS handshake.
4931 *
4932 * @param [in, out] ctx    SSL context.
4933 * @param [in]      der    Buffer holding DER encoded certificate.
4934 * @param [in]      derSz  Size of data in buffer.
4935 * @return  1 on success.
4936 * @return  0 on failure.
4937 */
4938static int wolfssl_ctx_add_to_chain(WOLFSSL_CTX* ctx, const byte* der,
4939    int derSz)
4940{
4941    int res = 1;
4942    int ret;
4943    DerBuffer* derBuffer = NULL;
4944
4945    /* Create a DER buffer from DER encoding. */
4946    ret = AllocCopyDer(&derBuffer, der, (word32)derSz, CERT_TYPE, ctx->heap);
4947    if (ret != 0) {
4948        WOLFSSL_MSG("Memory Error");
4949        res = 0;
4950    }
4951    if (res == 1) {
4952        /* Add a user CA certificate to the certificate manager. */
4953        res = AddCA(ctx->cm, &derBuffer, WOLFSSL_USER_CA,
4954            GET_VERIFY_SETTING_CTX(ctx));
4955        if (res != 1) {
4956            res = 0;
4957        }
4958    }
4959
4960    if (res == 1) {
4961         /* Add chain to DER buffer. */
4962         res = wolfssl_add_to_chain(&ctx->certChain, 1, der, (word32)derSz,
4963             ctx->heap);
4964    #ifdef WOLFSSL_TLS13
4965        /* Update count of certificates. */
4966        ctx->certChainCnt++;
4967    #endif
4968    }
4969
4970    return res;
4971}
4972
4973/* Add a certificate to chain sent in TLS handshake.
4974 *
4975 * @param [in, out] ctx   SSL context.
4976 * @param [in]      x509  X509 certificate object.
4977 * @return  1 on success.
4978 * @return  0 on failure.
4979 */
4980long wolfSSL_CTX_add_extra_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509)
4981{
4982    int   ret = 1;
4983    int   derSz = 0;
4984    const byte* der = NULL;
4985
4986    WOLFSSL_ENTER("wolfSSL_CTX_add_extra_chain_cert");
4987
4988    /* Validate parameters. */
4989    if ((ctx == NULL) || (x509 == NULL)) {
4990        WOLFSSL_MSG("Bad Argument");
4991        ret = 0;
4992    }
4993
4994    if (ret == 1) {
4995        /* Get the DER encoding of the certificate from the X509 object. */
4996        der = wolfSSL_X509_get_der(x509, &derSz);
4997        /* Validate buffer. */
4998        if ((der == NULL) || (derSz <= 0)) {
4999            WOLFSSL_MSG("Error getting X509 DER");
5000            ret = 0;
5001        }
5002    }
5003
5004    if ((ret == 1) && (ctx->certificate == NULL)) {
5005        WOLFSSL_ENTER("wolfSSL_use_certificate_chain_buffer_format");
5006
5007        /* Process buffer makes first certificate the leaf. */
5008        ret = ProcessBuffer(ctx, der, derSz, WOLFSSL_FILETYPE_ASN1, CERT_TYPE,
5009            NULL, NULL, 1, GET_VERIFY_SETTING_CTX(ctx), "extra chain buffer");
5010        if (ret != 1) {
5011            ret = 0;
5012        }
5013    }
5014    else if (ret == 1) {
5015        /* Add certificate to existing chain. */
5016        ret = wolfssl_ctx_add_to_chain(ctx, der, derSz);
5017    }
5018
5019    if (ret == 1) {
5020        /* On success WOLFSSL_X509 memory is responsibility of SSL context. */
5021        wolfSSL_X509_free(x509);
5022        x509 = NULL;
5023    }
5024
5025    WOLFSSL_LEAVE("wolfSSL_CTX_add_extra_chain_cert", ret);
5026    return ret;
5027}
5028
5029#endif /* OPENSSL_EXTRA */
5030
5031#if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
5032    defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
5033    defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
5034    defined(WOLFSSL_HAPROXY)
5035/* Load a certificate into SSL context.
5036 *
5037 * @param [in, out] ctx   SSL context object.
5038 * @param [in]      x509  X509 certificate object.
5039 * @return  1 on success.
5040 * @return  0 on failure.
5041 */
5042int wolfSSL_CTX_use_certificate(WOLFSSL_CTX *ctx, WOLFSSL_X509 *x)
5043{
5044    int res = 1;
5045    int ret;
5046
5047    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate");
5048
5049    /* Validate parameters. */
5050    if ((ctx == NULL) || (x == NULL) || (x->derCert == NULL)) {
5051        WOLFSSL_MSG("Bad parameter");
5052        res = 0;
5053    }
5054
5055    if (res == 1) {
5056        /* Replace certificate buffer with one holding the new certificate. */
5057        FreeDer(&ctx->certificate);
5058        ret = AllocCopyDer(&ctx->certificate, x->derCert->buffer,
5059            x->derCert->length, CERT_TYPE, ctx->heap);
5060        if (ret != 0) {
5061            res = 0;
5062        }
5063    }
5064
5065#ifdef KEEP_OUR_CERT
5066    if (res == 1) {
5067        /* Dispose of our certificate if it is ours. */
5068        if ((ctx->ourCert != NULL) && ctx->ownOurCert) {
5069            wolfSSL_X509_free(ctx->ourCert);
5070        }
5071    #ifndef WOLFSSL_X509_STORE_CERTS
5072        /* Keep a reference to the new certificate. */
5073        ctx->ourCert = x;
5074        if (wolfSSL_X509_up_ref(x) != 1) {
5075            res = 0;
5076        }
5077    #else
5078        /* Keep a copy of the new certificate. */
5079        ctx->ourCert = wolfSSL_X509_d2i_ex(NULL, x->derCert->buffer,
5080            x->derCert->length, ctx->heap);
5081        if (ctx->ourCert == NULL) {
5082            res = 0;
5083        }
5084    #endif
5085        /* Now own our certificate. */
5086        ctx->ownOurCert = 1;
5087    }
5088#endif
5089
5090    if (res == 1) {
5091        /* Set have options based on public key OID. */
5092        wolfssl_set_have_from_key_oid(ctx, NULL, x->pubKeyOID);
5093    }
5094
5095    return res;
5096}
5097
5098/* Add the certificate to the chain in the SSL context and own the X509 object.
5099 *
5100 * @param [in, out] ctx   SSL context object.
5101 * @param [in]      x509  X509 certificate object.
5102 * @return  1 on success.
5103 * @return  0 on failure.
5104 */
5105int wolfSSL_CTX_add0_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509)
5106{
5107    int ret;
5108
5109    WOLFSSL_ENTER("wolfSSL_CTX_add0_chain_cert");
5110
5111    /* Add certificate to chain and copy or up reference it. */
5112    ret = wolfSSL_CTX_add1_chain_cert(ctx, x509);
5113    if (ret == 1) {
5114        /* Down reference or free original now as we own certificate. */
5115        wolfSSL_X509_free(x509);
5116        x509 = NULL;
5117    }
5118
5119    return ret;
5120}
5121
5122/* Add the certificate to the chain in the SSL context.
5123 *
5124 * X509 object copied or up referenced.
5125 *
5126 * @param [in, out] ctx   SSL context object.
5127 * @param [in]      x509  X509 certificate object.
5128 * @return  1 on success.
5129 * @return  0 on failure.
5130 */
5131int wolfSSL_CTX_add1_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509)
5132{
5133    int ret = 1;
5134
5135    WOLFSSL_ENTER("wolfSSL_CTX_add1_chain_cert");
5136
5137    /* Validate parameters. */
5138    if ((ctx == NULL) || (x509 == NULL) || (x509->derCert == NULL)) {
5139        ret = 0;
5140    }
5141
5142    /* Check if we already have set a certificate. */
5143    if ((ret == 1) && (ctx->certificate == NULL)) {
5144        /* Use the certificate. */
5145        ret = wolfSSL_CTX_use_certificate(ctx, x509);
5146    }
5147    /* Increase reference count as we will store it. */
5148    else if ((ret == 1) && ((ret = wolfSSL_X509_up_ref(x509)) == 1)) {
5149        /* Load the DER encoding. */
5150        ret = wolfSSL_CTX_load_verify_buffer(ctx, x509->derCert->buffer,
5151            x509->derCert->length, WOLFSSL_FILETYPE_ASN1);
5152        if (ret == 1) {
5153            /* Add DER encoding to chain. */
5154            ret = wolfssl_add_to_chain(&ctx->certChain, 1,
5155                x509->derCert->buffer, x509->derCert->length, ctx->heap);
5156        }
5157        /* Store cert in stack to free it later. */
5158        if ((ret == 1) && (ctx->x509Chain == NULL)) {
5159            /* Create a stack for certificates. */
5160            ctx->x509Chain = wolfSSL_sk_X509_new_null();
5161            if (ctx->x509Chain == NULL) {
5162                WOLFSSL_MSG("wolfSSL_sk_X509_new_null error");
5163                ret = 0;
5164            }
5165        }
5166        if (ret == 1) {
5167            /* Push the X509 object onto stack. */
5168            ret = wolfSSL_sk_X509_push(ctx->x509Chain, x509) > 0
5169                    ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
5170        }
5171
5172        if (ret != 1) {
5173            /* Decrease reference count on error as we didn't store it. */
5174            wolfSSL_X509_free(x509);
5175            x509 = NULL;
5176        }
5177    }
5178
5179    return WS_RC(ret);
5180}
5181
5182#ifdef KEEP_OUR_CERT
5183/* Add the certificate to the chain in the SSL and own the X509 object.
5184 *
5185 * @param [in, out] ssl   SSL object.
5186 * @param [in]      x509  X509 certificate object.
5187 * @return  1 on success.
5188 * @return  0 on failure.
5189 */
5190int wolfSSL_add0_chain_cert(WOLFSSL* ssl, WOLFSSL_X509* x509)
5191{
5192    int ret = 1;
5193
5194    WOLFSSL_ENTER("wolfSSL_add0_chain_cert");
5195
5196    /* Validate parameters. */
5197    if ((ssl == NULL) || (x509 == NULL) || (x509->derCert == NULL)) {
5198        ret = 0;
5199    }
5200
5201    /* Check if we already have set a certificate. */
5202    if ((ret == 1) && (ssl->buffers.certificate == NULL)) {
5203        /* Use the certificate. */
5204        ret = wolfSSL_use_certificate(ssl, x509);
5205        if (ret == 1) {
5206            /* Dispose of old certificate if we own it. */
5207            if (ssl->buffers.weOwnCert) {
5208                wolfSSL_X509_free(ssl->ourCert);
5209            }
5210            /* Store cert to free it later. */
5211            ssl->ourCert = x509;
5212            ssl->buffers.weOwnCert = 1;
5213        }
5214    }
5215    else if (ret == 1) {
5216        /* Add DER encoding to chain. */
5217        ret = wolfssl_add_to_chain(&ssl->buffers.certChain,
5218            ssl->buffers.weOwnCertChain, x509->derCert->buffer,
5219            x509->derCert->length, ssl->heap);
5220        if (ret == 1) {
5221            /* We now own cert chain. */
5222            ssl->buffers.weOwnCertChain = 1;
5223            /* Create a stack to put certificate into. */
5224            if (ssl->ourCertChain == NULL) {
5225                ssl->ourCertChain = wolfSSL_sk_X509_new_null();
5226                if (ssl->ourCertChain == NULL) {
5227                    WOLFSSL_MSG("wolfSSL_sk_X509_new_null error");
5228                    ret = 0;
5229                }
5230            }
5231        }
5232        if (ret == 1) {
5233            /* Push X509 object onto stack to be freed. */
5234            ret = wolfSSL_sk_X509_push(ssl->ourCertChain, x509) > 0
5235                    ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
5236        }
5237    }
5238    return WS_RC(ret);
5239}
5240
5241/* Add the certificate to the chain in the SSL.
5242 *
5243 * X509 object is up referenced.
5244 *
5245 * @param [in, out] ssl   SSL object.
5246 * @param [in]      x509  X509 certificate object.
5247 * @return  1 on success.
5248 * @return  0 on failure.
5249 */
5250int wolfSSL_add1_chain_cert(WOLFSSL* ssl, WOLFSSL_X509* x509)
5251{
5252    int ret = 1;
5253
5254    WOLFSSL_ENTER("wolfSSL_add1_chain_cert");
5255
5256    /* Validate parameters. */
5257    if ((ssl == NULL) || (x509 == NULL) || (x509->derCert == NULL)) {
5258        ret = 0;
5259    }
5260
5261    /* Increase reference count on X509 object before adding. */
5262    if ((ret == 1) && ((ret = wolfSSL_X509_up_ref(x509)) == 1)) {
5263        /* Add this to the chain. */
5264        if ((ret = wolfSSL_add0_chain_cert(ssl, x509)) != 1) {
5265            /* Decrease reference count on error as not stored. */
5266            wolfSSL_X509_free(x509);
5267            x509 = NULL;
5268        }
5269    }
5270
5271    return ret;
5272}
5273#endif /* KEEP_OUR_CERT */
5274#endif /* OPENSSL_EXTRA, HAVE_LIGHTY, WOLFSSL_MYSQL_COMPATIBLE, HAVE_STUNNEL,
5275          WOLFSSL_NGINX, HAVE_POCO_LIB, WOLFSSL_HAPROXY */
5276
5277#ifdef OPENSSL_EXTRA
5278
5279/* Load a private key into SSL context.
5280 *
5281 * @param [in, out] ctx   SSL context object.
5282 * @param [in]      pkey  EVP private key.
5283 * @return  1 on success.
5284 * @return  0 on failure.
5285 */
5286int wolfSSL_CTX_use_PrivateKey(WOLFSSL_CTX *ctx, WOLFSSL_EVP_PKEY *pkey)
5287{
5288    int ret = 1;
5289
5290    WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey");
5291
5292    /* Validate parameters. */
5293    if ((ctx == NULL) || (pkey == NULL) || (pkey->pkey.ptr == NULL)) {
5294        ret = 0;
5295    }
5296
5297    if (ret == 1) {
5298        switch (pkey->type) {
5299    #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
5300        case WC_EVP_PKEY_RSA:
5301            WOLFSSL_MSG("populating RSA key");
5302            ret = PopulateRSAEvpPkeyDer(pkey);
5303            break;
5304    #endif /* (WOLFSSL_KEY_GEN || OPENSSL_EXTRA) && !NO_RSA */
5305    #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
5306            defined(WOLFSSL_CERT_GEN)) && !defined(NO_DSA)
5307        case WC_EVP_PKEY_DSA:
5308            break;
5309    #endif /* !HAVE_SELFTEST && (WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN) &&
5310            * !NO_DSA */
5311    #ifdef HAVE_ECC
5312        case WC_EVP_PKEY_EC:
5313            WOLFSSL_MSG("populating ECC key");
5314            ret = ECC_populate_EVP_PKEY(pkey, pkey->ecc);
5315            break;
5316    #endif
5317    #ifdef HAVE_ED25519
5318        case WC_EVP_PKEY_ED25519:
5319            /* DER is already stored in pkey->pkey.ptr by d2i_evp_pkey. */
5320            WOLFSSL_MSG("populating Ed25519 key");
5321            break;
5322    #endif
5323    #ifdef HAVE_ED448
5324        case WC_EVP_PKEY_ED448:
5325            /* DER is already stored in pkey->pkey.ptr by d2i_evp_pkey. */
5326            WOLFSSL_MSG("populating Ed448 key");
5327            break;
5328    #endif
5329        default:
5330            ret = 0;
5331        }
5332    }
5333
5334    if (ret == 1) {
5335        /* ptr for WOLFSSL_EVP_PKEY struct is expected to be DER format */
5336        ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx,
5337            (const unsigned char*)pkey->pkey.ptr, pkey->pkey_sz,
5338            WOLFSSL_FILETYPE_ASN1);
5339    }
5340
5341    return ret;
5342}
5343
5344#endif /* OPENSSL_EXTRA */
5345
5346#if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || \
5347    defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_QT)
5348/* Load a DER encoded certificate in a buffer into SSL context.
5349 *
5350 * @param [in, out] ctx    SSL context object.
5351 * @param [in]      der    Buffer holding DER encoded certificate.
5352 * @param [in]      derSz  Size of data in bytes.
5353 * @return  1 on success.
5354 * @return  0 on failure.
5355 */
5356int wolfSSL_CTX_use_certificate_ASN1(WOLFSSL_CTX *ctx, int derSz,
5357    const unsigned char *der)
5358{
5359    int ret = 1;
5360
5361    WOLFSSL_ENTER("wolfSSL_CTX_use_certificate_ASN1");
5362
5363    /* Validate parameters. */
5364    if ((ctx == NULL) || (der == NULL)) {
5365        ret = 0;
5366    }
5367    /* Load DER encoded certificate into SSL context. */
5368    if ((ret == 1) && (wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
5369            WOLFSSL_FILETYPE_ASN1) != 1)) {
5370        ret = 0;
5371    }
5372
5373    return ret;
5374}
5375
5376#if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
5377/* Load an RSA private key into SSL context.
5378 *
5379 * @param [in, out] ctx   SSL context object.
5380 * @param [in]      rsa   RSA private key.
5381 * @return  1 on success.
5382 * @return  0 on failure.
5383 * @return  BAD_FUNC_ARG when ctx or rsa is NULL.
5384 * @return  MEMORY_E when dynamic memory allocation fails.
5385 */
5386int wolfSSL_CTX_use_RSAPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL_RSA* rsa)
5387{
5388    int ret = 1;
5389    int derSize = 0;
5390    unsigned char* der = NULL;
5391    unsigned char* p;
5392
5393    WOLFSSL_ENTER("wolfSSL_CTX_use_RSAPrivateKey");
5394
5395    /* Validate parameters. */
5396    if ((ctx == NULL) || (rsa == NULL)) {
5397        WOLFSSL_MSG("one or more inputs were NULL");
5398        ret = BAD_FUNC_ARG;
5399    }
5400
5401    /* Get DER encoding size. */
5402    if ((ret == 1) && ((derSize = wolfSSL_i2d_RSAPrivateKey(rsa, NULL)) <= 0)) {
5403        ret = 0;
5404    }
5405
5406    if (ret == 1) {
5407        /* Allocate memory to hold DER encoding.. */
5408        der = (unsigned char*)XMALLOC((size_t)derSize, NULL,
5409                                            DYNAMIC_TYPE_TMP_BUFFER);
5410        if (der == NULL) {
5411            WOLFSSL_MSG("Malloc failure");
5412            ret = MEMORY_E;
5413        }
5414    }
5415
5416    if (ret == 1) {
5417        /* Pointer passed in is modified.. */
5418        p = der;
5419        /* Encode the RSA key as DER into buffer and get size. */
5420        if ((derSize = wolfSSL_i2d_RSAPrivateKey(rsa, &p)) <= 0) {
5421            WOLFSSL_MSG("wolfSSL_i2d_RSAPrivateKey() failure");
5422            ret = 0;
5423        }
5424    }
5425
5426    if (ret == 1) {
5427        /* Load DER encoded certificate into SSL context. */
5428        ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, derSize,
5429            SSL_FILETYPE_ASN1);
5430        if (ret != WOLFSSL_SUCCESS) {
5431            WOLFSSL_MSG("wolfSSL_CTX_USE_PrivateKey_buffer() failure");
5432            ret = 0;
5433        }
5434    }
5435
5436    /* Dispos of dynamically allocated data. */
5437    if (der != NULL) {
5438        ForceZero(der, (word32)derSize);
5439    }
5440    XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
5441    return ret;
5442}
5443#endif /* WOLFSSL_KEY_GEN && !NO_RSA */
5444
5445#endif /* OPENSSL_ALL || WOLFSSL_ASIO || WOLFSSL_HAPROXY || WOLFSSL_QT */
5446
5447#endif /* !NO_CERTS */
5448
5449#ifdef OPENSSL_EXTRA
5450
5451/* Use the default paths to look for CA certificate.
5452 *
5453 * This is an OpenSSL compatibility layer function, but it doesn't mirror
5454 * the exact functionality of its OpenSSL counterpart. We don't support the
5455 * notion of an "OpenSSL directory". This function will attempt to load the
5456 * environment variables SSL_CERT_DIR and SSL_CERT_FILE, if either are
5457 * found, they will be loaded. Otherwise, it will act as a wrapper around
5458 * our native wolfSSL_CTX_load_system_CA_certs function. This function does
5459 * conform to OpenSSL's return value conventions.
5460 *
5461 * @param [in] ctx  SSL context object.
5462 * @return  1 on success.
5463 * @return  0 on failure.
5464 * @return  WOLFSSL_FATAL_ERROR when using a filesystem is not supported.
5465 */
5466int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
5467{
5468    int ret;
5469#if defined(XGETENV) && !defined(NO_GETENV)
5470    char* certDir = NULL;
5471    char* certFile = NULL;
5472    word32 flags = 0;
5473#elif !defined(WOLFSSL_SYS_CA_CERTS)
5474    (void)ctx;
5475#endif
5476
5477    WOLFSSL_ENTER("wolfSSL_CTX_set_default_verify_paths");
5478
5479#if defined(XGETENV) && !defined(NO_GETENV)
5480    /* // NOLINTBEGIN(concurrency-mt-unsafe) */
5481    certDir = wc_strdup_ex(XGETENV("SSL_CERT_DIR"), DYNAMIC_TYPE_TMP_BUFFER);
5482    certFile = wc_strdup_ex(XGETENV("SSL_CERT_FILE"), DYNAMIC_TYPE_TMP_BUFFER);
5483    flags = WOLFSSL_LOAD_FLAG_PEM_CA_ONLY;
5484
5485    if ((certDir != NULL) || (certFile != NULL)) {
5486        if (certDir != NULL) {
5487           /* We want to keep trying to load more CA certs even if one cert in
5488            * the directory is bad and can't be used (e.g. if one is
5489            * expired), so we use WOLFSSL_LOAD_FLAG_IGNORE_ERR.
5490            */
5491            flags |= WOLFSSL_LOAD_FLAG_IGNORE_ERR;
5492        }
5493
5494        /* Load CA certificates from environment variable locations. */
5495        ret = wolfSSL_CTX_load_verify_locations_ex(ctx, certFile, certDir,
5496            flags);
5497        if (ret != 1) {
5498            WOLFSSL_MSG_EX("Failed to load CA certs from SSL_CERT_FILE: %s"
5499                            " SSL_CERT_DIR: %s. Error: %d", certFile,
5500                            certDir, ret);
5501            ret = 0;
5502        }
5503    }
5504    /* // NOLINTEND(concurrency-mt-unsafe) */
5505    else
5506#endif
5507
5508    {
5509    #ifdef NO_FILESYSTEM
5510        WOLFSSL_MSG("wolfSSL_CTX_set_default_verify_paths not supported"
5511                    " with NO_FILESYSTEM enabled");
5512        ret = WOLFSSL_FATAL_ERROR;
5513    #elif defined(WOLFSSL_SYS_CA_CERTS)
5514        /* Load the system CA certificates. */
5515        ret = wolfSSL_CTX_load_system_CA_certs(ctx);
5516        if (ret == WC_NO_ERR_TRACE(WOLFSSL_BAD_PATH)) {
5517            /* OpenSSL doesn't treat the lack of a system CA cert directory as a
5518             * failure. We do the same here.
5519             */
5520            ret = 1;
5521        }
5522    #else
5523        /* No source available: SSL_CERT_DIR/SSL_CERT_FILE not set and
5524         * WOLFSSL_SYS_CA_CERTS not compiled in. Returning success would be
5525         * fail-open since no trust anchors were loaded. */
5526        WOLFSSL_MSG("wolfSSL_CTX_set_default_verify_paths: no CA source "
5527                    "available (build without WOLFSSL_SYS_CA_CERTS and no "
5528                    "SSL_CERT_DIR/SSL_CERT_FILE env)");
5529        ret = WOLFSSL_FAILURE;
5530    #endif
5531    }
5532
5533#if defined(XGETENV) && !defined(NO_GETENV)
5534    XFREE(certFile, NULL, DYNAMIC_TYPE_TMP_BUFFER);
5535    XFREE(certDir, NULL, DYNAMIC_TYPE_TMP_BUFFER);
5536#endif
5537    WOLFSSL_LEAVE("wolfSSL_CTX_set_default_verify_paths", ret);
5538
5539    return ret;
5540}
5541
5542#endif /* OPENSSL_EXTRA */
5543
5544#ifndef NO_DH
5545
5546/* Set the temporary DH parameters against the SSL.
5547 *
5548 * @param [in, out] ssl   SSL object.
5549 * @param [in]      p     Buffer holding prime.
5550 * @param [in]      pSz   Length of prime in bytes.
5551 * @param [in]      g     Buffer holding generator.
5552 * @param [in]      gSz   Length of generator in bytes.
5553 * @return  1 on success.
5554 * @return  0 on failure.
5555 * @return  DH_KEY_SIZE_E when the prime is too short or long.
5556 * @return  SIDE_ERROR when the SSL is for a client.
5557 */
5558static int wolfssl_set_tmp_dh(WOLFSSL* ssl, unsigned char* p, int pSz,
5559    unsigned char* g, int gSz)
5560{
5561    int ret = 1;
5562
5563    /* Check the size of the prime meets the requirements of the SSL. */
5564    if (((word16)pSz < ssl->options.minDhKeySz) ||
5565            ((word16)pSz > ssl->options.maxDhKeySz)) {
5566        ret = DH_KEY_SIZE_E;
5567    }
5568    /* Only able to set DH parameters on server. */
5569    if ((ret == 1) && (ssl->options.side == WOLFSSL_CLIENT_END)) {
5570        ret = SIDE_ERROR;
5571    }
5572
5573    if (ret == 1) {
5574    #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
5575        !defined(HAVE_SELFTEST)
5576        /* New DH parameters not tested for validity. */
5577        ssl->options.dhKeyTested = 0;
5578        /* New DH parameters must be tested for validity before use. */
5579        ssl->options.dhDoKeyTest = 1;
5580    #endif
5581
5582        /* Dispose of old DH parameters if we own it. */
5583        if (ssl->buffers.weOwnDH) {
5584            XFREE(ssl->buffers.serverDH_P.buffer, ssl->heap,
5585                DYNAMIC_TYPE_PUBLIC_KEY);
5586            XFREE(ssl->buffers.serverDH_G.buffer, ssl->heap,
5587                DYNAMIC_TYPE_PUBLIC_KEY);
5588        }
5589
5590        /* Assign the buffers and lengths to SSL. */
5591        ssl->buffers.serverDH_P.buffer = p;
5592        ssl->buffers.serverDH_G.buffer = g;
5593        ssl->buffers.serverDH_P.length = (unsigned int)pSz;
5594        ssl->buffers.serverDH_G.length = (unsigned int)gSz;
5595        /* We own the buffers. */
5596        ssl->buffers.weOwnDH = 1;
5597        /* We have a DH parameters to use. */
5598        ssl->options.haveDH = 1;
5599    }
5600
5601    /* Allocate space for cipher suites. */
5602    if ((ret == 1) && (AllocateSuites(ssl) != 0)) {
5603        ssl->buffers.serverDH_P.buffer = NULL;
5604        ssl->buffers.serverDH_G.buffer = NULL;
5605        ret = 0;
5606    }
5607    if (ret == 1) {
5608        /* Reset the cipher suites based on having a DH parameters now. */
5609        InitSuites(ssl->suites, ssl->version, SSL_KEY_SZ(ssl),
5610            WOLFSSL_HAVE_RSA, SSL_HAVE_PSK(ssl), ssl->options.haveDH,
5611            ssl->options.haveECDSAsig, ssl->options.haveECC, TRUE,
5612            ssl->options.haveStaticECC,
5613            ssl->options.useAnon, TRUE,
5614            TRUE, TRUE, TRUE, ssl->options.side);
5615    }
5616
5617    return ret;
5618}
5619
5620/* Set the temporary DH parameters against the SSL.
5621 *
5622 * @param [in, out] ssl   SSL object.
5623 * @param [in]      p     Buffer holding prime.
5624 * @param [in]      pSz   Length of prime in bytes.
5625 * @param [in]      g     Buffer holding generator.
5626 * @param [in]      gSz   Length of generator in bytes.
5627 * @return  1 on success.
5628 * @return  0 on failure.
5629 * @return  DH_KEY_SIZE_E when the prime is too short or long.
5630 * @return  SIDE_ERROR when the SSL is for a client.
5631 * @return  MEMORY_E when dynamic memory allocation fails.
5632 */
5633int wolfSSL_SetTmpDH(WOLFSSL* ssl, const unsigned char* p, int pSz,
5634    const unsigned char* g, int gSz)
5635{
5636    int ret = 1;
5637    byte* pAlloc = NULL;
5638    byte* gAlloc = NULL;
5639
5640    WOLFSSL_ENTER("wolfSSL_SetTmpDH");
5641
5642    /* Validate parameters. */
5643    if ((ssl == NULL) || (p == NULL) || (g == NULL)) {
5644        ret = 0;
5645    }
5646
5647    if (ret == 1) {
5648        /* Allocate buffers for p and g to be assigned into SSL. */
5649        pAlloc = (byte*)XMALLOC((size_t)pSz, ssl->heap,
5650            DYNAMIC_TYPE_PUBLIC_KEY);
5651        gAlloc = (byte*)XMALLOC((size_t)gSz, ssl->heap,
5652            DYNAMIC_TYPE_PUBLIC_KEY);
5653        if ((pAlloc == NULL) || (gAlloc == NULL)) {
5654            /* Memory will be freed below in the (ret != 1) block */
5655            ret = MEMORY_E;
5656        }
5657    }
5658    if (ret == 1) {
5659        /* Copy p and g into allocated buffers. */
5660        XMEMCPY(pAlloc, p, (size_t)pSz);
5661        XMEMCPY(gAlloc, g, (size_t)gSz);
5662        /* Set the buffers into SSL. */
5663        ret = wolfssl_set_tmp_dh(ssl, pAlloc, pSz, gAlloc, gSz);
5664    }
5665
5666    if (ret != 1 && ssl != NULL) {
5667        /* Free the allocated buffers if not assigned into SSL. */
5668        XFREE(pAlloc, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5669        XFREE(gAlloc, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5670    }
5671
5672    WOLFSSL_LEAVE("wolfSSL_SetTmpDH", ret);
5673    return ret;
5674}
5675
5676#if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
5677    !defined(HAVE_SELFTEST)
5678/* Check the DH parameters is valid.
5679 *
5680 * @param [in]      p     Buffer holding prime.
5681 * @param [in]      pSz   Length of prime in bytes.
5682 * @param [in]      g     Buffer holding generator.
5683 * @param [in]      gSz   Length of generator in bytes.
5684 * @return  1 on success.
5685 * @return  DH_CHECK_PUB_E when p is not a prime.
5686 * @return  BAD_FUNC_ARG when p or g is NULL, or pSz or gSz is 0.
5687 * @return  MEMORY_E when dynamic memory allocation fails.
5688 */
5689static int wolfssl_check_dh_key(unsigned char* p, int pSz, unsigned char* g,
5690    int gSz)
5691{
5692    WC_RNG rng;
5693    int ret = 0;
5694    WC_DECLARE_VAR(checkKey, DhKey, 1, 0);
5695
5696    WC_ALLOC_VAR_EX(checkKey, DhKey, 1, NULL, DYNAMIC_TYPE_DH,
5697        ret=MEMORY_E);
5698    /* Initialize a new random number generator. */
5699    if ((ret == 0) && ((ret = wc_InitRng(&rng)) == 0)) {
5700        /* Initialize a DH object. */
5701        if ((ret = wc_InitDhKey(checkKey)) == 0) {
5702            /* Check DH parameters. */
5703            ret = wc_DhSetCheckKey(checkKey, p, (word32)pSz, g, (word32)gSz,
5704                NULL, 0, 0, &rng);
5705            /* Dispose of DH object. */
5706            wc_FreeDhKey(checkKey);
5707        }
5708        /* Dispose of random number generator. */
5709        wc_FreeRng(&rng);
5710    }
5711
5712    WC_FREE_VAR_EX(checkKey, NULL, DYNAMIC_TYPE_DH);
5713    /* Convert wolfCrypt return code to 1 on success and ret on failure. */
5714    return WC_TO_WS_RC(ret);
5715}
5716#endif
5717
5718/* Set the temporary DH parameters against the SSL context.
5719 *
5720 * @param [in, out] ctx   SSL context object.
5721 * @param [in]      p     Buffer holding prime.
5722 * @param [in]      pSz   Length of prime in bytes.
5723 * @param [in]      g     Buffer holding generator.
5724 * @param [in]      gSz   Length of generator in bytes.
5725 * @return  1 on success.
5726 * @return  0 on failure.
5727 * @return  DH_KEY_SIZE_E when the prime is too short or long.
5728 * @return  SIDE_ERROR when the SSL is for a client.
5729 * @return  BAD_FUNC_ARG when ctx, p or g is NULL.
5730 * @return  DH_CHECK_PUB_E when p is not a prime.
5731 * @return  MEMORY_E when dynamic memory allocation fails.
5732 */
5733static int wolfssl_ctx_set_tmp_dh(WOLFSSL_CTX* ctx, unsigned char* p, int pSz,
5734    unsigned char* g, int gSz)
5735{
5736    int ret = 1;
5737
5738    WOLFSSL_ENTER("wolfSSL_CTX_SetTmpDH");
5739
5740    if ((ctx == NULL) || (p == NULL) || (g == NULL))
5741        ret = BAD_FUNC_ARG;
5742
5743    /* Check the size of the prime meets the requirements of the SSL context. */
5744    if (ret == 1) {
5745        if (((word16)pSz < ctx->minDhKeySz) || ((word16)pSz > ctx->maxDhKeySz)) {
5746            ret = DH_KEY_SIZE_E;
5747        }
5748    }
5749
5750#if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
5751    !defined(HAVE_SELFTEST)
5752    if (ret == 1) {
5753        /* Test DH parameters for validity. */
5754        ret = wolfssl_check_dh_key(p, pSz, g, gSz);
5755        /* Record as whether tested based on result of validity test. */
5756        ctx->dhKeyTested = (ret == 1);
5757    }
5758#endif
5759
5760    if (ret == 1) {
5761        /* Dispose of old DH parameters. */
5762        XFREE(ctx->serverDH_P.buffer, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5763        XFREE(ctx->serverDH_G.buffer, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5764        /* Assign the buffers and lengths to SSL context. */
5765        ctx->serverDH_P.buffer = p;
5766        ctx->serverDH_G.buffer = g;
5767        ctx->serverDH_P.length = (unsigned int)pSz;
5768        ctx->serverDH_G.length = (unsigned int)gSz;
5769        /* We have a DH parameters to use. */
5770        ctx->haveDH = 1;
5771    }
5772
5773    WOLFSSL_LEAVE("wolfSSL_CTX_SetTmpDH", 0);
5774    return ret;
5775}
5776
5777/* Set the temporary DH parameters against the SSL context.
5778 *
5779 * @param [in, out] ctx   SSL context object.
5780 * @param [in]      p     Buffer holding prime.
5781 * @param [in]      pSz   Length of prime in bytes.
5782 * @param [in]      g     Buffer holding generator.
5783 * @param [in]      gSz   Length of generator in bytes.
5784 * @return  1 on success.
5785 * @return  0 on failure.
5786 * @return  DH_KEY_SIZE_E when the prime is too short or long.
5787 * @return  SIDE_ERROR when the SSL is for a client.
5788 * @return  BAD_FUNC_ARG when ctx, p or g is NULL.
5789 * @return  DH_CHECK_PUB_E when p is not a prime.
5790 */
5791int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX* ctx, const unsigned char* p, int pSz,
5792                         const unsigned char* g, int gSz)
5793{
5794    int ret = 1;
5795    byte* pAlloc = NULL;
5796    byte* gAlloc = NULL;
5797
5798    /* Validate parameters. */
5799    if ((ctx == NULL) || (p == NULL) || (g == NULL)) {
5800        ret = BAD_FUNC_ARG;
5801    }
5802
5803    if (ret == 1) {
5804        /* Allocate buffers for p and g to be assigned into SSL context. */
5805        pAlloc = (byte*)XMALLOC((size_t)pSz, ctx->heap,
5806            DYNAMIC_TYPE_PUBLIC_KEY);
5807        gAlloc = (byte*)XMALLOC((size_t)gSz, ctx->heap,
5808            DYNAMIC_TYPE_PUBLIC_KEY);
5809        if ((pAlloc == NULL) || (gAlloc == NULL)) {
5810            ret = MEMORY_E;
5811        }
5812    }
5813
5814    if (ret == 1) {
5815        /* Copy p and g into allocated buffers. */
5816        XMEMCPY(pAlloc, p, (size_t)pSz);
5817        XMEMCPY(gAlloc, g, (size_t)gSz);
5818        /* Set the buffers into SSL context. */
5819        ret = wolfssl_ctx_set_tmp_dh(ctx, pAlloc, pSz, gAlloc, gSz);
5820    }
5821
5822    if ((ret != 1) && (ctx != NULL)) {
5823        /* Free the allocated buffers if not assigned into SSL context. */
5824        XFREE(pAlloc, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5825        XFREE(gAlloc, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5826    }
5827    return ret;
5828}
5829
5830#ifdef OPENSSL_EXTRA
5831/* Set the temporary DH parameters against the SSL.
5832 *
5833 * @param [in, out] ssl  SSL object.
5834 * @param [in]      dh   DH object.
5835 * @return  1 on success.
5836 * @return  0 on failure.
5837 * @return  WOLFSSL_FATAL_ERROR on failure.
5838 * @return  BAD_FUNC_ARG when ssl or dh is NULL.
5839 * @return  DH_KEY_SIZE_E when the prime is too short or long.
5840 * @return  SIDE_ERROR when the SSL is for a client.
5841 */
5842long wolfSSL_set_tmp_dh(WOLFSSL *ssl, WOLFSSL_DH *dh)
5843{
5844    int ret = 1;
5845    byte* p = NULL;
5846    byte* g = NULL;
5847    int pSz = 0;
5848    int gSz = 0;
5849
5850    WOLFSSL_ENTER("wolfSSL_set_tmp_dh");
5851
5852    /* Validate parameters. */
5853    if ((ssl == NULL) || (dh == NULL)) {
5854        ret = BAD_FUNC_ARG;
5855    }
5856
5857    if (ret == 1) {
5858        /* Get sizes of p and g. */
5859        pSz = wolfSSL_BN_bn2bin(dh->p, NULL);
5860        gSz = wolfSSL_BN_bn2bin(dh->g, NULL);
5861        /* Validate p and g size. */
5862        if ((pSz <= 0) || (gSz <= 0)) {
5863            ret = WOLFSSL_FATAL_ERROR;
5864        }
5865    }
5866
5867    if (ret == 1) {
5868        /* Allocate buffers for p and g to be assigned into SSL. */
5869        p = (byte*)XMALLOC((size_t)pSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5870        g = (byte*)XMALLOC((size_t)gSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5871        if ((p == NULL) || (g == NULL)) {
5872            ret = MEMORY_E;
5873        }
5874    }
5875    if (ret == 1) {
5876        /* Encode p and g and get sizes. */
5877        pSz = wolfSSL_BN_bn2bin(dh->p, p);
5878        gSz = wolfSSL_BN_bn2bin(dh->g, g);
5879        /* Check encoding worked. */
5880        if ((pSz <= 0) || (gSz <= 0)) {
5881            ret = WOLFSSL_FATAL_ERROR;
5882        }
5883    }
5884    if (ret == 1) {
5885        /* Set the buffers into SSL. */
5886        ret = wolfssl_set_tmp_dh(ssl, p, pSz, g, gSz);
5887    }
5888
5889    if ((ret != 1) && (ssl != NULL)) {
5890        /* Free the allocated buffers if not assigned into SSL. */
5891        XFREE(p, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5892        XFREE(g, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5893    }
5894    return ret;
5895}
5896
5897/* Set the temporary DH parameters object against the SSL context.
5898 *
5899 * @param [in, out] ctx     SSL context object.
5900 * @param [in]      dh      DH object.
5901 * @return  1 on success.
5902 * @return  0 on failure.
5903 * @return  DH_KEY_SIZE_E when the prime is too short or long.
5904 * @return  SIDE_ERROR when the SSL is for a client.
5905 * @return  BAD_FUNC_ARG when ctx, p or g is NULL.
5906 * @return  DH_CHECK_PUB_E when p is not a prime.
5907 */
5908long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh)
5909{
5910    int ret = 1;
5911    int pSz = 0;
5912    int gSz = 0;
5913    byte* p = NULL;
5914    byte* g = NULL;
5915
5916    WOLFSSL_ENTER("wolfSSL_CTX_set_tmp_dh");
5917
5918    /* Validate parameters. */
5919    if ((ctx == NULL) || (dh == NULL)) {
5920        ret = BAD_FUNC_ARG;
5921    }
5922
5923    if (ret == 1) {
5924        /* Get sizes of p and g. */
5925        pSz = wolfSSL_BN_bn2bin(dh->p, NULL);
5926        gSz = wolfSSL_BN_bn2bin(dh->g, NULL);
5927        /* Validate p and g size. */
5928        if ((pSz <= 0) || (gSz <= 0)) {
5929            ret = WOLFSSL_FATAL_ERROR;
5930        }
5931    }
5932
5933    if (ret == 1) {
5934        /* Allocate buffers for p and g to be assigned into SSL. */
5935        p = (byte*)XMALLOC((size_t)pSz, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5936        g = (byte*)XMALLOC((size_t)gSz, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5937        if ((p == NULL) || (g == NULL)) {
5938            ret = MEMORY_E;
5939        }
5940    }
5941
5942    if (ret == 1) {
5943        /* Encode p and g and get sizes. */
5944        pSz = wolfSSL_BN_bn2bin(dh->p, p);
5945        gSz = wolfSSL_BN_bn2bin(dh->g, g);
5946        /* Check encoding worked. */
5947        if ((pSz <= 0) || (gSz <= 0)) {
5948            ret = WOLFSSL_FATAL_ERROR;
5949        }
5950    }
5951    if (ret == 1) {
5952        /* Set the buffers into SSL context. */
5953        ret = wolfssl_ctx_set_tmp_dh(ctx, p, pSz, g, gSz);
5954    }
5955
5956    if ((ret != 1) && (ctx != NULL)) {
5957        /* Free the allocated buffers if not assigned into SSL. */
5958        XFREE(p, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5959        XFREE(g, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
5960    }
5961    return ret;
5962}
5963
5964#endif /* OPENSSL_EXTRA */
5965
5966#ifndef NO_CERTS
5967
5968/* Set the temporary DH parameters against the SSL context or SSL.
5969 *
5970 * @param [in, out] ctx     SSL context object.
5971 * @param [in, out] ssl     SSL object.
5972 * @param [in]      buf     Buffer holding encoded DH parameters.
5973 * @param [in]      sz      Size of encoded DH parameters.
5974 * @param [in]      format  Format of data:
5975 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
5976 * @return  1 on success.
5977 * @return  0 on failure.
5978 * @return  BAD_FUNC_ARG when ctx and ssl NULL or buf is NULL.
5979 * @return  NOT_COMPLED_IN when format is PEM but PEM is not supported.
5980 * @return  WOLFSSL_BAD_FILETYPE if format is not supported.
5981 */
5982static int ws_ctx_ssl_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
5983    const unsigned char* buf, long sz, int format)
5984{
5985    DerBuffer* der = NULL;
5986    int res = 1;
5987    int ret;
5988    /* p and g size to allocate set to maximum valid size. */
5989    word32 pSz = MAX_DH_SIZE;
5990    word32 gSz = MAX_DH_SIZE;
5991    byte* p = NULL;
5992    byte* g = NULL;
5993    void* heap = WOLFSSL_HEAP(ctx, ssl);
5994
5995    /* Validate parameters. */
5996    if (((ctx == NULL) && (ssl == NULL)) || (buf == NULL)) {
5997        res = BAD_FUNC_ARG;
5998    }
5999    /* Check format is supported. */
6000    if ((res == 1) && (format != WOLFSSL_FILETYPE_ASN1)) {
6001        if (format != WOLFSSL_FILETYPE_PEM) {
6002            res = WOLFSSL_BAD_FILETYPE;
6003        }
6004    #ifndef WOLFSSL_PEM_TO_DER
6005        else {
6006            res = NOT_COMPILED_IN;
6007        }
6008    #endif
6009    }
6010
6011    /* PemToDer allocates its own DER buffer. */
6012    if ((res == 1) && (format != WOLFSSL_FILETYPE_PEM)) {
6013        /* Create a DER buffer and copy in the encoded DH parameters. */
6014        ret = AllocDer(&der, (word32)sz, DH_PARAM_TYPE, heap);
6015        if (ret == 0) {
6016            XMEMCPY(der->buffer, buf, (word32)sz);
6017        }
6018        else {
6019            res = ret;
6020        }
6021    }
6022
6023    if (res == 1) {
6024        /* Allocate enough memory to p and g to support valid use cases. */
6025        p = (byte*)XMALLOC(pSz, heap, DYNAMIC_TYPE_PUBLIC_KEY);
6026        g = (byte*)XMALLOC(gSz, heap, DYNAMIC_TYPE_PUBLIC_KEY);
6027        if ((p == NULL) || (g == NULL)) {
6028            res = MEMORY_E;
6029        }
6030    }
6031
6032#ifdef WOLFSSL_PEM_TO_DER
6033    if ((res == 1) && (format == WOLFSSL_FILETYPE_PEM)) {
6034        /* Convert from PEM to DER. */
6035        /* Try converting DH parameters from PEM to DER. */
6036        ret = PemToDer(buf, sz, DH_PARAM_TYPE, &der, heap, NULL, NULL);
6037        if (ret < 0) {
6038            /* Otherwise, try converting X9.43 format DH parameters. */
6039            ret = PemToDer(buf, sz, X942_PARAM_TYPE, &der, heap, NULL, NULL);
6040        }
6041    #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
6042        if (ret < 0) {
6043            /* Otherwise, try converting DSA parameters. */
6044            ret = PemToDer(buf, sz, DSA_PARAM_TYPE, &der, heap, NULL, NULL);
6045        }
6046    #endif /* WOLFSSL_WPAS && !NO_DSA */
6047       if (ret < 0) {
6048           /* Return error from conversion. */
6049           res = ret;
6050       }
6051    }
6052#endif /* WOLFSSL_PEM_TO_DER */
6053
6054    if (res == 1) {
6055        /* Get the p and g from the DER encoded parameters. */
6056        if (wc_DhParamsLoad(der->buffer, der->length, p, &pSz, g, &gSz) < 0) {
6057            res = WOLFSSL_BAD_FILETYPE;
6058        }
6059        else if (ssl != NULL) {
6060            /* Set p and g into SSL. */
6061            res = wolfssl_set_tmp_dh(ssl, p, (int)pSz, g, (int)gSz);
6062        }
6063        else {
6064            /* Set p and g into SSL context. */
6065            res = wolfssl_ctx_set_tmp_dh(ctx, p, (int)pSz, g, (int)gSz);
6066        }
6067    }
6068
6069    /* Dispose of the DER buffer. */
6070    FreeDer(&der);
6071    if (res != 1) {
6072        /* Free the allocated buffers if not assigned into SSL or context. */
6073        XFREE(p, heap, DYNAMIC_TYPE_PUBLIC_KEY);
6074        XFREE(g, heap, DYNAMIC_TYPE_PUBLIC_KEY);
6075    }
6076    return res;
6077}
6078
6079
6080/* Set the temporary DH parameters against the SSL.
6081 *
6082 * @param [in, out] ssl     SSL object.
6083 * @param [in]      buf     Buffer holding encoded DH parameters.
6084 * @param [in]      sz      Size of encoded DH parameters.
6085 * @param [in]      format  Format of data:
6086 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
6087 * @return  1 on success.
6088 * @return  BAD_FUNC_ARG when ssl or buf is NULL.
6089 * @return  NOT_COMPLED_IN when format is PEM but PEM is not supported.
6090 * @return  WOLFSSL_BAD_FILETYPE if format is not supported.
6091 */
6092int wolfSSL_SetTmpDH_buffer(WOLFSSL* ssl, const unsigned char* buf, long sz,
6093    int format)
6094{
6095    return ws_ctx_ssl_set_tmp_dh(NULL, ssl, buf, sz, format);
6096}
6097
6098
6099/* Set the temporary DH parameters against the SSL context.
6100 *
6101 * @param [in, out] ctx     SSL context object.
6102 * @param [in]      buf     Buffer holding encoded DH parameters.
6103 * @param [in]      sz      Size of encoded DH parameters.
6104 * @param [in]      format  Format of data:
6105 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
6106 * @return  1 on success.
6107 * @return  BAD_FUNC_ARG when ctx or buf is NULL.
6108 * @return  NOT_COMPLED_IN when format is PEM but PEM is not supported.
6109 * @return  WOLFSSL_BAD_FILETYPE if format is not supported.
6110 */
6111int wolfSSL_CTX_SetTmpDH_buffer(WOLFSSL_CTX* ctx, const unsigned char* buf,
6112    long sz, int format)
6113{
6114    return ws_ctx_ssl_set_tmp_dh(ctx, NULL, buf, sz, format);
6115}
6116
6117#ifndef NO_FILESYSTEM
6118
6119/* Set the temporary DH parameters file against the SSL context or SSL.
6120 *
6121 * @param [in, out] ctx     SSL context object.
6122 * @param [in, out] ssl     SSL object.
6123 * @param [in]      fname   Name of file to load.
6124 * @param [in]      format  Format of data:
6125 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
6126 * @return  1 on success.
6127 * @return  BAD_FUNC_ARG when ctx and ssl NULL or fname is NULL.
6128 * @return  NOT_COMPLED_IN when format is PEM but PEM is not supported.
6129 * @return  WOLFSSL_BAD_FILETYPE if format is not supported.
6130 */
6131static int ws_ctx_ssl_set_tmp_dh_file(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
6132    const char* fname, int format)
6133{
6134    int    res = 1;
6135    int    ret;
6136#ifndef WOLFSSL_SMALL_STACK
6137    byte   stackBuffer[FILE_BUFFER_SIZE];
6138#endif
6139    StaticBuffer dhFile;
6140    long   sz = 0;
6141    void*  heap = WOLFSSL_HEAP(ctx, ssl);
6142
6143    /* Setup buffer to hold file contents. */
6144#ifdef WOLFSSL_SMALL_STACK
6145    static_buffer_init(&dhFile);
6146#else
6147    static_buffer_init(&dhFile, stackBuffer, FILE_BUFFER_SIZE);
6148#endif
6149
6150    /* Validate parameters. */
6151    if (((ctx == NULL) && (ssl == NULL)) || (fname == NULL)) {
6152        res = BAD_FUNC_ARG;
6153    }
6154
6155    if (res == 1) {
6156        /* Read file into static buffer. */
6157        ret = wolfssl_read_file_static(fname, &dhFile, heap, DYNAMIC_TYPE_FILE,
6158            &sz);
6159        if (ret != 0) {
6160            res = ret;
6161        }
6162    }
6163    if (res == 1) {
6164        if (ssl != NULL) {
6165            /* Set encoded DH parameters into SSL. */
6166            res = wolfSSL_SetTmpDH_buffer(ssl, dhFile.buffer, sz, format);
6167        }
6168        else {
6169            /* Set encoded DH parameters into SSL context. */
6170            res = wolfSSL_CTX_SetTmpDH_buffer(ctx, dhFile.buffer, sz, format);
6171        }
6172    }
6173
6174    /* Dispose of any dynamically allocated data. */
6175    static_buffer_free(&dhFile, heap, DYNAMIC_TYPE_FILE);
6176    return res;
6177}
6178
6179/* Set the temporary DH parameters file against the SSL.
6180 *
6181 * @param [in, out] ssl     SSL object.
6182 * @param [in]      fname   Name of file to load.
6183 * @param [in]      format  Format of data:
6184 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
6185 * @return  1 on success.
6186 * @return  BAD_FUNC_ARG when ssl or fname is NULL.
6187 * @return  NOT_COMPLED_IN when format is PEM but PEM is not supported.
6188 * @return  WOLFSSL_BAD_FILETYPE if format is not supported.
6189 */
6190int wolfSSL_SetTmpDH_file(WOLFSSL* ssl, const char* fname, int format)
6191{
6192    return ws_ctx_ssl_set_tmp_dh_file(NULL, ssl, fname, format);
6193}
6194
6195
6196/* Set the temporary DH parameters file against the SSL context.
6197 *
6198 * @param [in, out] ctx     SSL context object.
6199 * @param [in]      fname   Name of file to load.
6200 * @param [in]      format  Format of data:
6201 *                            WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_ASN1.
6202 * @return  1 on success.
6203 * @return  BAD_FUNC_ARG when ctx or fname is NULL.
6204 * @return  NOT_COMPLED_IN when format is PEM but PEM is not supported.
6205 * @return  WOLFSSL_BAD_FILETYPE if format is not supported.
6206 */
6207int wolfSSL_CTX_SetTmpDH_file(WOLFSSL_CTX* ctx, const char* fname, int format)
6208{
6209    return ws_ctx_ssl_set_tmp_dh_file(ctx, NULL, fname, format);
6210}
6211
6212#endif /* NO_FILESYSTEM */
6213
6214#endif /* NO_CERTS */
6215
6216#endif /* !NO_DH */
6217
6218#endif /* !WOLFSSL_SSL_LOAD_INCLUDED */
6219