Skip to content

Commit

Permalink
Log in slots with CKF_USER_PIN_INITIALIZED and not CKF_LOGIN_REQUIRED
Browse files Browse the repository at this point in the history
Fixes: #123 (for OpenSSL build)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
dwmw2 committed Apr 23, 2020
1 parent 10e40eb commit f97239a
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openssl-pkcs11.c
Expand Up @@ -381,7 +381,7 @@ int load_pkcs11_certificate(struct openconnect_info *vpninfo)
}
/* If there was precisely one matching slot, and we still didn't find the cert,
try logging in to it. */
if (matching_slots == 1 && login_slot->token->loginRequired) {
if (matching_slots == 1 && (login_slot->token->loginRequired || login_slot->token->userPinSet)) {
slot = login_slot;
vpn_progress(vpninfo, PRG_INFO,
_("Logging in to PKCS#11 slot '%s'\n"),
Expand Down Expand Up @@ -615,7 +615,7 @@ int load_pkcs11_key(struct openconnect_info *vpninfo)
login_slot = vpninfo->pkcs11_cert_slot;
vpninfo->pkcs11_cert_slot = NULL;
}
if (matching_slots == 1 && login_slot->token->loginRequired) {
if (matching_slots == 1 && (login_slot->token->loginRequired || login_slot->token->userPinSet)) {
slot = login_slot;
vpn_progress(vpninfo, PRG_INFO,
_("Logging in to PKCS#11 slot '%s'\n"),
Expand Down
34 changes: 34 additions & 0 deletions tests/Makefile.am
Expand Up @@ -69,6 +69,10 @@ if OPENCONNECT_GNUTLS
# the certs after we log in. Perhaps it's cached the results?
PKCS11_TOKENS += openconnect-test2
endif # OPENCONNECT_GNUTLS
if OPENCONNECT_OPENSSL
# GnuTLS build fails this one: https://gitlab.com/gnutls/gnutls/-/issues/977
PKCS11_TOKENS += openconnect-test3
endif # OPENCONNECT_OPENSSL
endif # TEST_PKCS11
endif # HAVE_CWRAP

Expand Down Expand Up @@ -258,3 +262,33 @@ softhsm-setup2:
--load-privkey $(certsdir)/ec-key-pkcs8.pem \
--label EC --id 03 --login \
--write "pkcs11:token=openconnect-test2;pin-value=1234"

# Fourth test: token lacks CKF_LOGIN_REQUIRED (#123)
softhsm-setup3:
$(SHM2_UTIL) --show-slots
$(SHM2_UTIL) --init-token --free --label openconnect-test3 \
--so-pin 12345678 --pin 1234

# Remove the CKF_LOGIN_REQUIRED flag
TOKOBJ=$$(grep -l openconnect-test3 $(srcdir)/softhsm/*/token.object); \
if [ -n "$$TOKOBJ" ] && od -t x1 $$TOKOBJ | grep -q '^0000160.* 04 2d$$'; then \
echo -en \\x29 | dd bs=1 count=1 conv=notrunc seek=127 of=$$TOKOBJ; \
else \
echo "Token file not understood"; \
exit 1; \
fi

$(P11TOOL) --load-certificate $(certsdir)/user-cert.pem \
--load-privkey $(certsdir)/user-key-pkcs8.pem \
--label RSA --id 01 --login \
--write "pkcs11:token=openconnect-test3;pin-value=1234"

$(P11TOOL) --load-certificate $(certsdir)/dsa-cert.pem \
--load-privkey $(certsdir)/dsa-key-pkcs8.pem \
--label DSA --id 02 --login \
--write "pkcs11:token=openconnect-test3;pin-value=1234"

$(P11TOOL) --load-certificate $(certsdir)/ec-cert.pem \
--load-privkey $(certsdir)/ec-key-pkcs8.pem \
--label EC --id 03 --login \
--write "pkcs11:token=openconnect-test3;pin-value=1234"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
1 change: 1 addition & 0 deletions www/changelog.xml
Expand Up @@ -27,6 +27,7 @@
<li>Fix crash with uninitialised OIDC token.</li>
<li>GlobalProtect: more resilient handling of periodic HIP check and login arguments, and predictable naming of challenge forms</li>
<li>Disable <a href="https://en.wikipedia.org/wiki/Nagle's_algorithm">Nagle's algorithm</a> for TLS sockets, to improve interactivity when tunnel runs over TCP rather than UDP.</li>
<li>Work around PKCS#11 tokens which forget to set <tt>CKF_LOGIN_REQUIRED</tt> (<a href="https://gitlab.com/openconnect/openconnect/issues/123">#123</a>).</li>
</ul><br/>
</li>
<li><b><a href="ftp://ftp.infradead.org/pub/openconnect/openconnect-8.07.tar.gz">OpenConnect v8.07</a></b>
Expand Down

0 comments on commit f97239a

Please sign in to comment.