Skip to contentSkip to conversation

Add auto value to pkcs11-id parameter

PATCH Superseded Chris J Arges 2 participants 3 messages Feb 20, 2013 – Mar 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add auto value to pkcs11-id parameter

This patch allows one to specify --pkcs11-id auto to automatically select the first certificate on a pkcs11 device. This simplifies scripts and usage in environments where clients may only use a single certificate for connecting to a VPN.
Based on a patch by Oliver Dumschat-Hötte.

---
 src/openvpn/pkcs11.c |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
src/openvpn/pkcs11.c +33 -8
index 3a15ef6..11d5e8f 100644
@@ -669,14 +669,39 @@ tls_ctx_use_pkcs11 (
 		}
 	}
 	else {
-		if (
-			(rv = pkcs11h_certificate_deserializeCertificateId (
-				&certificate_id,
-				pkcs11_id
-			)) != CKR_OK
-		) {
-			msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv));
-			goto cleanup;
+		if ( strcmp(pkcs11_id, "auto") == 0 ) {
+			char *pkcs11_id_read = NULL;
+			char *base64 = NULL;
+			if ( !pkcs11_management_id_get(
+			       0,
+			       &pkcs11_id_read,
+			       &base64
+			   )
+			) {
+				msg (M_WARN, "PKCS#11: pkcs11_management_id_get 0 failed");
+				goto cleanup;
+			}
+			if (
+				(rv = pkcs11h_certificate_deserializeCertificateId (
+					&certificate_id,
+					pkcs11_id_read
+				)) != CKR_OK
+			) {
+				msg (M_WARN, "PKCS#11: Cannot deserialize auto id %ld-'%s'", rv,
+				     pkcs11h_getMessage (rv));
+				goto cleanup;
+			}
+		} else {
+			if (
+				(rv = pkcs11h_certificate_deserializeCertificateId (
+					&certificate_id,
+					pkcs11_id
+				)) != CKR_OK
+			) {
+				msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv,
+				     pkcs11h_getMessage (rv));
+				goto cleanup;
+			}
 		}
 	}
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 7 lines · Chris J Arges

This patch allows one to specify --pkcs11-id auto to automatically select the first certificate on a pkcs11 device. This simplifies scripts and usage in environments where clients may only use a single certificate for connecting to a VPN.
Based on a patch by Oliver Dumschat-Hötte.

some security-minded (paranoid?) folks will say that you should never automatically select a certificate/key pair (which is what a normal user would want, of course). This patch does seem like a useful addition, and it actually restores some functionality found in earlier versions of OpenVPN, IIRC. Perhaps more warnings should be added about this being a (minor) security risk.

A man page snippet for this is missing from the patch, but that can be done if the patch is ACKed by others. I'm not authoratitive on ACKing patches, but as far as I am concerned: ACK

JJK

Quoted 59 lines
---
 src/openvpn/pkcs11.c |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
src/openvpn/pkcs11.c +33 -8
index 3a15ef6..11d5e8f 100644
@@ -669,14 +669,39 @@ tls_ctx_use_pkcs11 (
 		}
 	}
 	else {
-		if (
-			(rv = pkcs11h_certificate_deserializeCertificateId (
-				&certificate_id,
-				pkcs11_id
-			)) != CKR_OK
-		) {
-			msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv));
-			goto cleanup;
+		if ( strcmp(pkcs11_id, "auto") == 0 ) {
+			char *pkcs11_id_read = NULL;
+			char *base64 = NULL;
+			if ( !pkcs11_management_id_get(
+			       0,
+			       &pkcs11_id_read,
+			       &base64
+			   )
+			) {
+				msg (M_WARN, "PKCS#11: pkcs11_management_id_get 0 failed");
+				goto cleanup;
+			}
+			if (
+				(rv = pkcs11h_certificate_deserializeCertificateId (
+					&certificate_id,
+					pkcs11_id_read
+				)) != CKR_OK
+			) {
+				msg (M_WARN, "PKCS#11: Cannot deserialize auto id %ld-'%s'", rv,
+				     pkcs11h_getMessage (rv));
+				goto cleanup;
+			}
+		} else {
+			if (
+				(rv = pkcs11h_certificate_deserializeCertificateId (
+					&certificate_id,
+					pkcs11_id
+				)) != CKR_OK
+			) {
+				msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv,
+				     pkcs11h_getMessage (rv));
+				goto cleanup;
+			}
 		}
 	}
 
#2 lore raw

PATCH v2 1/1 Add auto value to pkcs11-id parameter

This patch allows one to specify --pkcs11-id auto to automatically select the first certificate on a pkcs11 device. This simplifies scripts and usage in environments where clients may only use a single certificate for connecting to a VPN.
Based on a patch by Oliver Dumschat-Hötte.

---
 doc/openvpn.8        |    7 +++++++
 src/openvpn/pkcs11.c |   41 +++++++++++++++++++++++++++++++++--------
 2 files changed, 40 insertions(+), 8 deletions(-)
doc/openvpn.8 +7 -0
index 829bbd2..84e38dd 100644
@@ -4228,6 +4228,13 @@ Specify the serialized certificate id to be used. The id can be gotten
 by the standalone
 .B \-\-show-pkcs11-ids
 option.
+If
+.B name
+is specified as the string
+.B 'auto'
+, then certificate id 0 will be used. This
+is useful in single user cases; however, care should be taken to ensure the correct
+certificate is selected.
 .\"*********************************************************
 .TP
 .B \-\-pkcs11-id-management
src/openvpn/pkcs11.c +33 -8

47 lines not on this page · raw message

Signature · 1 line
1.7.9.5