Mac OS X Keychain management client
PATCH v2 1/1 Mac OS X Keychain management client
This patch adds support for using certificates stored in the Mac OSX Keychain to authenticate with the OpenVPN server. This works with certificates stored on the computer as well as certificates on hardware tokens that support Apple's tokend interface. The patch is based on the Windows Crypto API certificate functionality that currently exists in OpenVPN.
This patch version implements management client which handles rsa_sign command for RSA offloading. Also it handled new 'Cert' request to pass a certificate from the keychain to OpenVPN.
This is a PoC version of the patch. If the concept is OK for OpenVPN, I'll integrate it into autoconf, add documentation based on the manpage from the previous version of the patch, and add more strict argv checks for interferred options.
The patch is against commit 3341a98c2852d1d0c1eafdc70a3bdb218ec29049.
The previous version of the patch:
http://thread.gmane.org/gmane.network.openvpn.devel/9320
---
.gitignore +0 -1
@@ -19,7 +19,6 @@ Debug Win32-Output .deps .libs -Makefile Makefile.in aclocal.m4 autodefs.h
contrib/keychain-mcd/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +CFILES = cert_data.c common_osx.c crypto_osx.c main.c +OFILES = $(CFILES:.c=.o) ../../src/openvpn/base64.o +prog = keychain-mcd + +CC = gcc +CFLAGS = -Wall +LDFLAGS = -framework CoreFoundation -framework Security -framework CoreServices + +$(prog): $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) -o $(prog) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@
contrib/keychain-mcd/cert_data.c new file +761 -0
761 lines not on this page · raw message
contrib/keychain-mcd/cert_data.h new file +46 -0
46 lines not on this page · raw message
contrib/keychain-mcd/common_osx.c new file +94 -0
94 lines not on this page · raw message
contrib/keychain-mcd/common_osx.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* OpenVPN -- An application to securely tunnel IP networks +* over a single UDP port, with support for SSL/TLS-based +* session authentication and key exchange, +* packet encryption, packet authentication, and +* packet compression. +* +* Copyright (C) 2010 Brian Raderman <[email protected]...> +* Copyright (C) 2013-2014 Vasily Kulikov <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program (see the file COPYING included with this +* distribution); if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __common_osx_h__ +#define __common_osx_h__ + +#include <CoreFoundation/CoreFoundation.h> + +void printCFString (CFStringRef str); +char *cfstringToCstr (CFStringRef str); +CFStringRef createHexString (unsigned char *pData,int length); +void printHex (unsigned char *pData,int length); + +#endif //__Common_osx_h__
contrib/keychain-mcd/crypto_osx.c new file +75 -0
75 lines not on this page · raw message
contrib/keychain-mcd/crypto_osx.h new file +44 -0
44 lines not on this page · raw message
contrib/keychain-mcd/main.c new file +204 -0
204 lines not on this page · raw message
src/openvpn/manage.c +41 -1
54 lines not on this page · raw message
src/openvpn/manage.h +2 -0
@@ -338,6 +338,7 @@ struct management *management_init (void);#define MF_UP_DOWN (1<<10)#define MF_QUERY_REMOTE (1<<11)#define MF_QUERY_PROXY (1<<12) +#define MF_EXTERNAL_CERT (1<<13) bool management_open (struct management *man, const char *addr,
@@ -384,6 +385,7 @@ bool management_android_control (struct management *man, const char *command, co#define ANDROID_OPEN_BEFORE_CLOSE 3int managment_android_persisttun_action (struct management *man);#endif +char *management_query_cert (struct management *man);bool management_should_daemonize (struct management *man);bool management_would_hold (struct management *man);
src/openvpn/misc.h +1 -1
@@ -205,7 +205,7 @@ struct user_pass# ifdef ENABLE_PKCS11 # define USER_PASS_LEN 4096# else -# define USER_PASS_LEN 128 +# define USER_PASS_LEN 12800# endif char username[USER_PASS_LEN ];char password[USER_PASS_LEN ];
src/openvpn/options.c +9 -0
@@ -1591,6 +1591,9 @@ show_settings (const struct options *o)SHOW_STR (ca_file);SHOW_STR (ca_path);SHOW_STR (dh_file); +if ((o->management_flags &MF_EXTERNAL_CERT )) +SHOW_PARM ("cert_file" ,"EXTERNAL_CERT" ,"%s" ); +else SHOW_STR (cert_file);#ifdef MANAGMENT_EXTERNAL_KEY
@@ -2262,6 +2265,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne }else { +if (!(options->management_flags &MF_EXTERNAL_CERT ))notnull (options->cert_file,"certificate file (--cert) or PKCS#12 file (--pkcs12)" );#ifdef MANAGMENT_EXTERNAL_KEY if (!(options->management_flags &MF_EXTERNAL_KEY ))
@@ -4250,6 +4254,11 @@ add_option (struct options *options, options->management_flags |=MF_EXTERNAL_KEY ; }#endif + else if (streq (p[0], "management-external-cert")) + { +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->management_flags |=MF_EXTERNAL_CERT ; + }#ifdef MANAGEMENT_DEF_AUTH else if (streq (p[0], "management-client-auth")) {
src/openvpn/options.h +2 -2
@@ -52,8 +52,8 @@/* * Max size of options line and parameter. */ -#define OPTION_PARM_SIZE 256 -#define OPTION_LINE_SIZE 256 +#define OPTION_PARM_SIZE 4096 +#define OPTION_LINE_SIZE 4096extern const char title_string[];
src/openvpn/ssl.c +12 -4
@@ -516,10 +516,18 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx) }#endif #ifdef MANAGMENT_EXTERNAL_KEY - else if ((options->management_flags & MF_EXTERNAL_KEY) && options->cert_file) - { -tls_ctx_use_external_private_key (new_ctx, options->cert_file, - options->cert_file_inline); + else if ((options->management_flags & MF_EXTERNAL_KEY) && + (options->cert_file || options->management_flags & MF_EXTERNAL_CERT)) + { +if (options->cert_file) { +tls_ctx_use_external_private_key (new_ctx, options->cert_file, + options->cert_file_inline); + }else { +char *external_certificate =management_query_cert (management); +tls_ctx_use_external_private_key (new_ctx,INLINE_FILE_TAG , + external_certificate); +free (external_certificate); + } }#endif else
Quoted 9 lines · Vasily Kulikov
This patch adds support for using certificates stored in the Mac OSX Keychain to authenticate with the OpenVPN server. This works with certificates stored on the computer as well as certificates on hardware tokens that support Apple's tokend interface. The patch is based on the Windows Crypto API certificate functionality that currently exists in OpenVPN.
This patch version implements management client which handles
rsa_signcommand for RSA offloading.
FWIW we really ought to be supporting key types other than RSA by now. But I appreciate that's not a new limitation and not your fault.
It would be interesting to get feedback from those working on NetworkManager-openvpn, which may well want to use this API to allow key operations to happen in the user's session while OpenVPN is running as root.
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected]... Intel Corporation
Am 12.01.15 12:45, schrieb David Woodhouse:
Quoted 7 lines · Vasily Kulikov
Quoted 6 lines
This patch adds support for using certificates stored in the Mac OSX Keychain to authenticate with the OpenVPN server. This works with certificates stored on the computer as well as certificates on hardware tokens that support Apple's tokend interface. The patch is based on the Windows Crypto API certificate functionality that currently exists in OpenVPN.
I wonder why only certifcates and not ca certifcates. It would be logical to get all certifcates from the keychain.
Quoted 5 lines
Quoted 3 lines
This patch version implements management client which handles
rsa_signcommand for RSA offloading.FWIW we really ought to be supporting key types other than RSA by now. But I appreciate that's not a new limitation and not your fault.
Well although rsa-sign at the momemnt probably only supports RSA (it is implemented using rsa_method iirc) the API is not rsa specific. It is
just: "Please sign this hash with the private key". In the case of an RSA certificate this happens to be RSA encrypt in ECB mode with PKCS#1 padding.
I am not sure if there is an equivalent of rsa_method for EC in OpenSSL or if you have to use the engine functionality of OpenSSL for EC.
Quoted 4 lines
It would be interesting to get feedback from those working on NetworkManager-openvpn, which may well want to use this API to allow key operations to happen in the user's session while OpenVPN is running as root.
Quoted 2 lines · Arne Schwabe
I wonder why only certifcates and not ca certifcates. It would be logical to get all certifcates from the keychain.
Yes, that makes some sense. Although perhaps it should be the other way round — you present the peer's cert to the management client and it just gives you a "yes" or "no" answer. Perhaps after asking the user, if the certificate *wasn't* automatically trusted.
Quoted 5 lines
Well although rsa-sign at the momemnt probably only supports RSA (it is implemented using
rsa_methodiirc) the API is not rsa specific. It is
just: "Please sign this hash with the private key". In the case of an RSA certificate this happens to be RSA encrypt in ECB mode with PKCS#1 padding.
I hope it goes without saying, but obviously if we making that more generic, we should be careful not to do dangerous things like allowing the management client to do RSA encryption *without* padding. :)
Quoted 2 lines
I am not sure if there is an equivalent of
rsa_methodfor EC in OpenSSL or if you have to use the engine functionality of OpenSSL for EC.
An externally-built ENGINE can't do anything more than you can. Hence
http://rt.openssl.org/Ticket/Display.html?id=2459&user=guest&pass=guest
Signature · 1 line
dwmw2
Quoted 10 lines · Arne Schwabe
Am 12.01.15 12:45, schrieb David Woodhouse:
Quoted 7 lines · Vasily Kulikov
Quoted 6 lines
This patch adds support for using certificates stored in the Mac OSX Keychain to authenticate with the OpenVPN server. This works with certificates stored on the computer as well as certificates on hardware tokens that support Apple's tokend interface. The patch is based on the Windows Crypto API certificate functionality that currently exists in OpenVPN.
Quoted 2 lines
I wonder why only certifcates and not ca certifcates. It would be logical to get all certifcates from the keychain.
A user tells keychain-mcd which keychain identity to use for openvpn. The identity contains a certificate and a private key (might be non-extractable). CA is not related to this identity. It can be added to keychain-mcd and openvpn but a user should pass another certificate match string for CA.
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
This patch version implements management client which handles
rsa_signcommand for RSA offloading.FWIW we really ought to be supporting key types other than RSA by now. But I appreciate that's not a new limitation and not your fault.
Well although rsa-sign at the momemnt probably only supports RSA (it is implemented using
rsa_methodiirc) the API is not rsa specific. It is
just: "Please sign this hash with the private key". In the case of an RSA certificate this happens to be RSA encrypt in ECB mode with PKCS#1 padding.
Right. And my patch is not specific to RSA too. It uses generic Mac OS X API which should work with any key type:
SecIdentityCopyPrivateKey()
SecKeyRawSign()
Signature · 2 lines
Vasily Kulikov http://www.openwall.com - bringing security into open computing environments