Skip to content

Commit

Permalink
Fix pks12docs (#2857)
Browse files Browse the repository at this point in the history
* docs: clarify and emphasize that when using a PKCS-12 certificate that the name or alias must be `user`
  • Loading branch information
davecramer committed Mar 17, 2023
1 parent aade7a0 commit b656c63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ In addition to the standard connection parameters the driver supports a number o
| sslfactoryarg (deprecated) | String | null | Argument forwarded to constructor of SSLSocketFactory class. |
| sslmode | String | prefer | Controls the preference for opening using an SSL encrypted connection. |
| sslcert | String | null | The location of the client's SSL certificate |
| sslkey | String | null | The location of the client's PKCS#8 SSL key |
| sslkey | String | null | The location of the client's PKCS#8 or PKCS#12 SSL key, for PKCS the extension must be .p12 or .pfx and the alias must be `user` |
| sslrootcert | String | null | The location of the root certificate for authenticating the server. |
| sslhostnameverifier | String | null | The name of a class (for use in [Class.forName(String)](https://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#forName%28java.lang.String%29)) that implements javax.net.ssl.HostnameVerifier and can verify the server hostname. |
| sslpasswordcallback | String | null | The name of a class (for use in [Class.forName(String)](https://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#forName%28java.lang.String%29)) that implements javax.security.auth.callback.CallbackHandler and can handle PasswordCallback for the ssl password. |
Expand Down
5 changes: 5 additions & 0 deletions docs/content/documentation/ssl.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ As of version 42.2.9 PKCS-12 is also supported. In this archive format the clien
one file, which needs to be set with the `sslkey` parameter. For the PKCS-12 format to be recognized, the file extension
must be ".p12" (supported since 42.2.9) or ".pfx" (since 42.2.16). (In this case the `sslcert` parameter is ignored.)

> **NOTE**
>
> When using a PKCS-12 client certificate the name or alias *MUST* be `user` when using `openssl pkcs12 -export -name user ...`
There are complete examples of how to export the certificate in the [certdir](https://raw.githubusercontent.com/pgjdbc/pgjdbc/master/certdir/Makefile) Makefile

Finer control of the SSL connection can be achieved using the `sslmode` connection parameter.
This parameter is the same as the libpq `sslmode` parameter and currently implements the
following
Expand Down
7 changes: 5 additions & 2 deletions docs/content/documentation/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ Provide the full path for the key file. Defaults to `defaultdir/postgresql.pk8`.

> **NOTE**
>
> The key file **must** be in [PKCS-12](https://en.wikipedia.org/wiki/PKCS_12) or in [PKCS-8](https://en.wikipedia.org/wiki/PKCS_8) [DER format](https://wiki.openssl.org/index.php/DER). A PEM key can be converted to DER format using the openssl command: `openssl pkcs8 -topk8 -inform PEM -in postgresql.key -outform DER -out postgresql.pk8 -v1 PBE-MD5-DES`
> The key file **must** be in [PKCS-12](https://en.wikipedia.org/wiki/PKCS_12) or in [PKCS-8](https://en.wikipedia.org/wiki/PKCS_8) [DER format](https://wiki.openssl.org/index.php/DER).
A PEM key can be converted to DER format using the openssl command: `openssl pkcs8 -topk8 -inform PEM -in postgresql.key -outform DER -out postgresql.pk8 -v1 PBE-MD5-DES`
When you create the key the `alias` or the `name` must be *user*. The test codes uses the following to create a .p12 key `openssl pkcs12 -export -in $< -inkey $*.key -out $@ -name user -CAfile $(SERVER_CRT_DIR)root.crt -caname local -passout pass:$(P12_PASSWORD)`

PKCS-12 key files are only recognized if they have the ".p12" (42.2.9+) or the ".pfx" (42.2.16+) extension.

If your key has a password, provide it using the `sslpassword` connection parameter described below. Otherwise, you can add the flag `-nocrypt` to the above command to prevent the driver from requesting a password.

> **NOTE**
>
> The use of -v1 PBE-MD5-DES might be inadequate in environments where high level of security is needed and the key is not protected by other means (e.g. access control of the OS), or the key file is transmitted in untrusted channels. We are depending on the cryptography providers provided by the java runtime. The solution documented here is known to work at the time of writing. If you have stricter security needs, please see [here](https://stackoverflow.com/questions/58488774/configure-tomcat-hibernate-to-have-a-cryptographic-provider-supporting-1-2-840-1) for a discussion of the problem and information on choosing a better cipher suite.
> The use of -v1 PBE-MD5-DES might be inadequate in environments where high level of security is needed and the key is not protected by other means (e.g. access control of the OS),
or the key file is transmitted in untrusted channels. We are depending on the cryptography providers provided by the java runtime. The solution documented here is known to work at the time of writing. If you have stricter security needs, please see [here](https://stackoverflow.com/questions/58488774/configure-tomcat-hibernate-to-have-a-cryptographic-provider-supporting-1-2-840-1) for a discussion of the problem and information on choosing a better cipher suite.

* **`sslrootcert (`*String*`)`** *Default `defaultdir/root.crt`*\
File name of the SSL root certificate. It can be a PEM encoded X509v3 certificate.
Expand Down

0 comments on commit b656c63

Please sign in to comment.