Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X509v3 Certificate Generation Support (WolfSSLCertificate) #141

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

cconlon
Copy link
Member

@cconlon cconlon commented Jul 28, 2023

This PR adds X.509v3 certificate generation support to native wolfSSL JNI wrappers, exposed through the com.wolfssl.WolfSSLCertificate class. Note this is not inside the JSSE provider, and is a wolfSSL-specific API that closely wraps the native WOLFSSL_X509 certificate generation capabilities.

An example has been added which does both self-signed and CA-signed certificate generation (./examples/X509v3CertificateGeneration.java). Generated certificates are output in PEM and DER format under the directory ./examples/certs/generated). This is compiled when ant examples is run:

$ cd wolfssljni
$ ant examples
$ ./examples/X509v3CertificateGeneration.sh

JUnit test cases have also been added to test both self-signed and CA-signed certificate generation.

Other changes in this PR include:

  • Addition of Windows batch scripts to more easily run ProviderTest and X509v3CertificateGeneration examples.
  • Updated Visual Studio project to add new files
  • Updates example certificates to match current wolfssl master certs

Copy link
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

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

Running the new example appeared to fail for me. Is there more options needed when compiling wolfSSL than just --enable-jni?

$ ./examples/X509v3CertificateGeneration.sh 
wolfSSL JNI X509v3 Certificate Generation Example

Generating self-signed cert using filescom.wolfssl.WolfSSLException: Error setting extension into native WOLFSSL_X509 (ret: 0)
	at com.wolfssl.WolfSSLCertificate.addExtension(WolfSSLCertificate.java:759)
	at X509v3CertificateGeneration.generateSelfSignedUsingFiles(X509v3CertificateGeneration.java:199)
	at X509v3CertificateGeneration.run(X509v3CertificateGeneration.java:665)
	at X509v3CertificateGeneration.main(X509v3CertificateGeneration.java:683)

Example passed

Verifying certs with openssl...
Testing each can be opened with openssl x509 -text
Can't open ../certs/generated/*.der for reading, No such file or directory
4427615680:error:02001002:system library:fopen:No such file or directory:crypto/bio/bss_file.c:72:fopen('../certs/generated/*.der','rb')
4427615680:error:2006D080:BIO routines:BIO_new_file:no such file:crypto/bio/bss_file.c:79:
unable to load certificate
File not readable with openssl x509: ../certs/generated/*.der

native/com_wolfssl_WolfSSLX509Name.c Outdated Show resolved Hide resolved
…class, supporting key usage, extended key usage, subject alt name, and basic constraints extensions. Self signed and CA-signed support, along with example app. Update example certs to match current wolfssl.
@cconlon
Copy link
Member Author

cconlon commented Aug 22, 2023

@JacobBarthelmeh The additions in this PR are partially dependent on the fixes made to native wolfSSL post-5.6.3 (wolfSSL/wolfssl#6585). The fixes are specifically needed for use of setting the Key Usage and Extended Key Usage extension when generating a certificate.

I force pushed some additions here to wrap our native wolfSSL_lib_version_hex() and return a more helpful exception message for users on 5.6.3 or earlier.

@cconlon cconlon assigned JacobBarthelmeh and unassigned cconlon Aug 22, 2023
@JacobBarthelmeh JacobBarthelmeh merged commit d4aeb31 into wolfSSL:master Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants