Openvpn future: probably certificate problems...
Hi all,
I'm still working on a renewed openvpn service wrapper( which's heading to allow a non-admin user to start/stop pre-defined tunnels via a tcp socket) and I see some big troubles in a near future.
The *great* actual cryptoapi patch allow a user to access local machine and local user certs. It's quite good right now because most of the openvpn users are using it with admin rights or non-interactive processing( like autostart at windows boot).
I'm worrying about those features when our aim will be to do let non-admin users start their tunnel and authenticate themselves on the openvpn server with their own certificate. In the actual openvpn it's not possible, because the SYSTEM account can only access to his own certs and the local machine certs, but not "Foo Bar User" certs.
We can ask ourselves few questions:
- is it possible to make SYSTEM access user certs?
- if not, how can we make openvpn access to those users data?
A friend of mine said an answer could be to let the GUI(or a user only component) manage the access to such user-related data, and let openvpn deal with this component in order to use the certs.
Of course, this problem is only windows-related.
What do you think of this problem?
Thanks,
Didier
Quoted 22 lines · Didier Conchaudron
Hi all,
I'm still working on a renewed openvpn service wrapper( which's heading to allow a non-admin user to start/stop pre-defined tunnels via a tcp socket) and I see some big troubles in a near future.
The *great* actual cryptoapi patch allow a user to access local machine and local user certs. It's quite good right now because most of the openvpn users are using it with admin rights or non-interactive processing( like autostart at windows boot).
I'm worrying about those features when our aim will be to do let non-admin users start their tunnel and authenticate themselves on the openvpn server with their own certificate. In the actual openvpn it's not possible, because the SYSTEM account can only access to his own certs and the local machine certs, but not "Foo Bar User" certs.
We can ask ourselves few questions:
- is it possible to make SYSTEM access user certs?
- if not, how can we make openvpn access to those users data?
Quoted 8 lines
A friend of mine said an answer could be to let the GUI(or a user only component) manage the access to such user-related data, and let openvpn deal with this component in order to use the certs.
Of course, this problem is only windows-related.
What do you think of this problem?
Defense in depth.
The user should not have the ability to logon to a machine with OpenVPN installed if they are not allowed to use OpenVPN, or that user should not have access to run the GUI (maybe the OpenVPN Service should not even be running).
The certificate is authenticating the computer.
Signature · 2 lines
Leonard Isham, CISSP Ostendo non ostento.
Quoted 35 lines · Leonard Isham
Quoted 22 lines · Didier Conchaudron
Hi all,
I'm still working on a renewed openvpn service wrapper( which's heading to allow a non-admin user to start/stop pre-defined tunnels via a tcp socket) and I see some big troubles in a near future.
The *great* actual cryptoapi patch allow a user to access local machine and local user certs. It's quite good right now because most of the openvpn users are using it with admin rights or non-interactive processing( like autostart at windows boot).
I'm worrying about those features when our aim will be to do let non-admin users start their tunnel and authenticate themselves on the openvpn server with their own certificate. In the actual openvpn it's not possible, because the SYSTEM account can only access to his own certs and the local machine certs, but not "Foo Bar User" certs.
We can ask ourselves few questions:
- is it possible to make SYSTEM access user certs?
- if not, how can we make openvpn access to those users data?Quoted 8 lines
A friend of mine said an answer could be to let the GUI(or a user only component) manage the access to such user-related data, and let openvpn deal with this component in order to use the certs.
Of course, this problem is only windows-related.
What do you think of this problem?
Quoted 6 lines
Defense in depth.
The user should not have the ability to logon to a machine with OpenVPN installed if they are not allowed to use OpenVPN, or that user should not have access to run the GUI (maybe the OpenVPN Service should not even be running).
These are not the questions. The ability to access to openvpn is not a matter of openvpn, just one of the computer admin. And even if a user have openvpn installed, a good conf must need a USER certificate or a user/pass to allow him to connect to the vpn server. So it's not a matter of openvpn too, but one of the openvpn admin.
Quoted 1 line
The certificate is authenticating the computer.
It's the actual openvpn features. But much openvpn addicts would be very pleased to make openvpn works like other commercial vpn, with USER certificate.
Btw, MSDN cryptoapi docs don't talk about a way to get userspace certs from a SYSTEM rights. I think a way to solve this issue would be to make
openvpn deals with a userspace component which one could get the
certificate and supply desired data to openvpn at tunnel startup. This userspace component could be openvpn-gui or another program. I really don't know if this kind of solution is technicaly possible. Only true openvpn hackers could ;-)
Didier
[snip]
Quoted 17 lines
Quoted 4 lines
The user should not have the ability to logon to a machine with OpenVPN installed if they are not allowed to use OpenVPN, or that user should not have access to run the GUI (maybe the OpenVPN Service should not even be running).
These are not the questions. The ability to access to openvpn is not a matter of openvpn, just one of the computer admin. And even if a user have openvpn installed, a good conf must need a USER certificate or a user/pass to allow him to connect to the vpn server. So it's not a matter of openvpn too, but one of the openvpn admin.
Quoted 1 line
The certificate is authenticating the computer.
It's the actual openvpn features. But much openvpn addicts would be very pleased to make openvpn works like other commercial vpn, with USER certificate.
Quoted 8 lines
Btw, MSDN cryptoapi docs don't talk about a way to get userspace certs from a SYSTEM rights. I think a way to solve this issue would be to make
openvpn deals with a userspace component which one could get the
certificate and supply desired data to openvpn at tunnel startup. This userspace component could be openvpn-gui or another program. I really don't know if this kind of solution is technicaly possible. Only true openvpn hackers could ;-)
All good points. I must add a couple of my own.
1) OpenVPN is cross platform.
2) Apparently a MS design implementation. Could possible be rectified my having the service use the user login instead of system.
3) At this stage I think changes of this magnitude, as you suggest, would most likely be post 2.0. James an the other brains behind this would know better.
Signature · 2 lines
Leonard Isham, CISSP Ostendo non ostento.
Leonard Isham wrote:
[snip]
Quoted 10 lines
Quoted 8 lines
Btw, MSDN cryptoapi docs don't talk about a way to get userspace certs from a SYSTEM rights. I think a way to solve this issue would be to make
openvpn deals with a userspace component which one could get the
certificate and supply desired data to openvpn at tunnel startup. This userspace component could be openvpn-gui or another program. I really don't know if this kind of solution is technicaly possible. Only true openvpn hackers could ;-)
Quoted 3 lines
All good points. I must add a couple of my own.
1) OpenVPN is cross platform.
Yes, those certificates problems are only windows-related. Linux and *BSD don't have such problems to make user certs available to root.
Quoted 2 lines
2) Apparently a MS design implementation. Could possible be rectified by having the service use the user login instead of system.
First, the certificate way of things like MS have coded it is not bad because it's quite usefull to disable user certificate access for admin/system. The MS problem comes from the missing of a su/sudo system in order to allow a user to temporary access other account data/rights.
Your suggestion about moving the service into userspace is not the solution because we need a system-space service in order to set up the tunnels(which require admin/system rights) instead of users, because they're not allowed to.
Finally, on win32 and in a company context, a system-space service is necessary to achieve tunnel set up, a user-space program is necessary in order to get the user certs and to let him choose when he want to set up the tunnel.
Quoted 3 lines
3) At this stage I think changes of this magnitude, as you suggest, would most likely be post 2.0. James an the other brains behind this would know better.
The new service wrapper was soon considered as a post 2.0 feature. Perhaps more.
The big problem is that we actually have a single binary which is able to do everything, a great gui which allow end-users to interact easily.
And what we are talking about is a global system, actually usefull for few of us, which will need 2 or 3 components in system/user space for just one platform. But this small case is what will bring openvpn on top of proprietary vpn challengers.
Is our community ready to get to a such level? Do we want to? In a personnal point of view, I think openvpn is a great piece of code and it deserve to be famous and widely used.
Didier
Quoted 14 lines · Didier Conchaudron
Leonard Isham wrote:
[snip]
Quoted 10 lines
Quoted 8 lines
Btw, MSDN cryptoapi docs don't talk about a way to get userspace certs from a SYSTEM rights. I think a way to solve this issue would be to make
openvpn deals with a userspace component which one could get the
certificate and supply desired data to openvpn at tunnel startup. This userspace component could be openvpn-gui or another program. I really don't know if this kind of solution is technicaly possible. Only true openvpn hackers could ;-)
Quoted 6 lines
Quoted 3 lines
All good points. I must add a couple of my own.
1) OpenVPN is cross platform.
Yes, those certificates problems are only windows-related. Linux and *BSD don't have such problems to make user certs available to root.
Exactly what I meant.
Quoted 13 lines
Quoted 2 lines
2) Apparently a MS design implementation. Could possible be rectified by having the service use the user login instead of system.
First, the certificate way of things like MS have coded it is not bad because it's quite usefull to disable user certificate access for admin/system. The MS problem comes from the missing of a su/sudo system in order to allow a user to temporary access other account data/rights.
Your suggestion about moving the service into userspace is not the solution because we need a system-space service in order to set up the tunnels(which require admin/system rights) instead of users, because they're not allowed to.
Quoted 4 lines
Finally, on win32 and in a company context, a system-space service is necessary to achieve tunnel set up, a user-space program is necessary in order to get the user certs and to let him choose when he want to set up the tunnel.
I wasn't bashing, just stating that it was due to the MS implementation not a bug.
Quoted 13 lines
Quoted 3 lines
3) At this stage I think changes of this magnitude, as you suggest, would most likely be post 2.0. James an the other brains behind this would know better.
The new service wrapper was soon considered as a post 2.0 feature. Perhaps more.
The big problem is that we actually have a single binary which is able to do everything, a great gui which allow end-users to interact easily. And what we are talking about is a global system, actually usefull for few of us, which will need 2 or 3 components in system/user space for just one platform. But this small case is what will bring openvpn on top of proprietary vpn challengers.
Quoted 4 lines
Is our community ready to get to a such level? Do we want to? In a personnal point of view, I think openvpn is a great piece of code and it deserve to be famous and widely used.
I personally have confidence in the developers.
Signature · 2 lines
Leonard Isham, CISSP Ostendo non ostento.
Quoted 22 lines · Didier Conchaudron
Hi all,
I'm still working on a renewed openvpn service wrapper( which's heading to allow a non-admin user to start/stop pre-defined tunnels via a tcp socket) and I see some big troubles in a near future.
The *great* actual cryptoapi patch allow a user to access local machine and local user certs. It's quite good right now because most of the openvpn users are using it with admin rights or non-interactive processing( like autostart at windows boot).
I'm worrying about those features when our aim will be to do let non-admin users start their tunnel and authenticate themselves on the openvpn server with their own certificate. In the actual openvpn it's not possible, because the SYSTEM account can only access to his own certs and the local machine certs, but not "Foo Bar User" certs.
We can ask ourselves few questions:
- is it possible to make SYSTEM access user certs?
- if not, how can we make openvpn access to those users data?
Quoted 7 lines
A friend of mine said an answer could be to let the GUI(or a user only component) manage the access to such user-related data, and let openvpn deal with this component in order to use the certs.
Of course, this problem is only windows-related.
What do you think of this problem?
First of all, the current impediments to running OpenVPN on Windows in non-admin user mode is:
(1a) The openvpn.exe process needs to open a device handle to the TAP-Win32 adapter. Windows does not provide a convenient way for the TAP-Win32 adapter to allow itself to be opened by non-admin apps.
(2a) OpenVPN needs to be able to modify the routing table. Most OSes (Windows & Linux included) require admin/root privileges for this.
Now it appears that we have another obstacle, this time going the other way.
(1b) The SYSTEM account (sort of like "Windows" root, the user under which services/daemons run) can't read a specific user's key from the Crypto API store.
Either we need to run openvpn.exe in user mode and solve (1a) and (2a) or run openvpn.exe in service mode and solve (1b). (1a) and (2a) seem relatively difficult to solve, so probably it's worthwhile to attempt to solve (1b) -- or at least study its difficulty in relation to (1a) and (2a).
James
Quoted 49 lines · James Yonan
Quoted 22 lines · Didier Conchaudron
Hi all,
I'm still working on a renewed openvpn service wrapper( which's heading to allow a non-admin user to start/stop pre-defined tunnels via a tcp socket) and I see some big troubles in a near future.
The *great* actual cryptoapi patch allow a user to access local machine and local user certs. It's quite good right now because most of the openvpn users are using it with admin rights or non-interactive processing( like autostart at windows boot).
I'm worrying about those features when our aim will be to do let non-admin users start their tunnel and authenticate themselves on the openvpn server with their own certificate. In the actual openvpn it's not possible, because the SYSTEM account can only access to his own certs and the local machine certs, but not "Foo Bar User" certs.
We can ask ourselves few questions:
- is it possible to make SYSTEM access user certs?
- if not, how can we make openvpn access to those users data?Quoted 7 lines
A friend of mine said an answer could be to let the GUI(or a user only component) manage the access to such user-related data, and let openvpn deal with this component in order to use the certs.
Of course, this problem is only windows-related.
What do you think of this problem?
First of all, the current impediments to running OpenVPN on Windows in non-admin user mode is:
(1a) The openvpn.exe process needs to open a device handle to the TAP-Win32 adapter. Windows does not provide a convenient way for the TAP-Win32 adapter to allow itself to be opened by non-admin apps.
(2a) OpenVPN needs to be able to modify the routing table. Most OSes (Windows & Linux included) require admin/root privileges for this.
Now it appears that we have another obstacle, this time going the other way.
(1b) The SYSTEM account (sort of like "Windows" root, the user under which services/daemons run) can't read a specific user's key from the Crypto API store.
Quoted 6 lines
Either we need to run openvpn.exe in user mode and solve (1a) and (2a) or run openvpn.exe in service mode and solve (1b). (1a) and (2a) seem relatively difficult to solve, so probably it's worthwhile to attempt to solve (1b) -- or at least study its difficulty in relation to (1a) and (2a).
What about a dual account/ID user situation? Where one user is a normal user with all the restrictions and the other has administrator rights. The first is used to login the second, administrator equivalent is for storing the certificate and running the service.
Signature · 2 lines
Leonard Isham, CISSP Ostendo non ostento.
Quoted 5 lines · Leonard Isham
What about a dual account/ID user situation? Where one user is a
normal user with all the restrictions and the other has administrator
rights. The first is used to login the second, administrator equivalent is for storing the certificate and running the service.
good point.
any privilege separation under windows ?
Regards
Julien
On 2005-01-15 04:03, James Yonan wrote:
[snip]
Quoted 3 lines
(1b) The SYSTEM account (sort of like "Windows" root, the user under which services/daemons run) can't read a specific user's key from the Crypto API store.
I believe that this should be possible. I don't have the time and means to try out stuff right now, but maybe someone can try out this patch?
cryptoapi.c renamed from cryptoapi-2.0_rc7.c +16 -2
@@ -1,5 +1,5 @@/* -* Copyright (c) 2004 Peter 'Luna' Runestig <[email protected]...> +* Copyright (c) 2004, 05 Peter 'Luna' Runestig <[email protected]...> * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifi-
@@ -339,7 +339,8 @@SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_FILE ,ERR_R_MALLOC_FAILURE ); goto err; } -/* search CURRENT_USER first, then LOCAL_MACHINE */ +/* search for the wanted certificate in different parts of the system store: +* search HKEY_CURRENT_USER first... */ cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_CURRENT_USER |CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" );if (cs ==NULL ) {
@@ -349,6 +350,7 @@ cd->cert_context =find_certificate_in_store (cert_prop, cs);CertCloseStore (cs,0 );if (!cd->cert_context) { +/* ...then HKEY_LOCAL_MACHINE... */ cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_LOCAL_MACHINE |CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" );if (cs ==NULL ) {
@@ -357,6 +359,18 @@ } cd->cert_context =find_certificate_in_store (cert_prop, cs);CertCloseStore (cs,0 ); + } +if (!cd->cert_context) { +/* ...then HKEY_USERS... */ +/* TODO: Maybe only try this if we're running as SYSTEM? */ + cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_USERS | +CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" ); +if (cs ==NULL ) { +CRYPTOAPIerr (CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE ); + goto err; + } + cd->cert_context =find_certificate_in_store (cert_prop, cs); +CertCloseStore (cs,0 );if (cd->cert_context ==NULL ) {CRYPTOAPIerr (CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE ); goto err;
Signature · 5 lines
Peter 'Luna' Runestig (fd. Altberg), Sweden <[email protected]...> PGP Key ID: 0xD07BBE13 Fingerprint: 7B5C 1F48 2997 C061 DE4B 42EA CB99 A35C D07B BE13 AOL Instant Messenger Screen name: PRunestig Yahoo! Messenger profile name: altberg
Looks like CERT_SYSTEM_STORE_USERS is undefined in the MinGW environment.
gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin -I/c/src/ openssl-0.9.7e/include -I/c/src/lzo-1.08/include -c cryptoapi.c -o cryptoapi.o cryptoapi.c: In function `SSL_CTX_use_CryptoAPI_certificate':
cryptoapi.c:366: `CERT_SYSTEM_STORE_USERS' undeclared (first use in this function) cryptoapi.c:366: (Each undeclared identifier is reported only once cryptoapi.c:366: for each function it appears in.)
make: *** [cryptoapi.o] Error 1
James
Quoted 11 lines · James Yonan
Looks like
CERT_SYSTEM_STORE_USERSis undefined in the MinGW environment.gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin -I/c/src/ openssl-0.9.7e/include -I/c/src/lzo-1.08/include -c
cryptoapi.c-o cryptoapi.ocryptoapi.c: In function `SSL_CTX_use_CryptoAPI_certificate':
cryptoapi.c:366: `CERT_SYSTEM_STORE_USERS' undeclared (first use in this function) cryptoapi.c:366: (Each undeclared identifier is reported only once cryptoapi.c:366: for each function it appears in.)
make: *** [cryptoapi.o] Error 1James
Maybe this is better?
cryptoapi.c renamed from cryptoapi-2.0_rc7.c +18 -2
@@ -1,5 +1,5 @@/* -* Copyright (c) 2004 Peter 'Luna' Runestig <[email protected]...> +* Copyright (c) 2004, 05 Peter 'Luna' Runestig <[email protected]...> * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifi-
@@ -41,7 +41,9 @@#define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)#define CERT_SYSTEM_STORE_LOCATION_SHIFT 16#define CERT_SYSTEM_STORE_CURRENT_USER_ID 1 +#define CERT_SYSTEM_STORE_USERS_ID 6#define CERT_SYSTEM_STORE_CURRENT_USER (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT) +#define CERT_SYSTEM_STORE_USERS (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)#define CERT_STORE_READONLY_FLAG 0x00008000#define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000#define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004
@@ -339,7 +341,8 @@SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_FILE ,ERR_R_MALLOC_FAILURE ); goto err; } -/* search CURRENT_USER first, then LOCAL_MACHINE */ +/* search for the wanted certificate in different parts of the system store: +* search HKEY_CURRENT_USER first... */ cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_CURRENT_USER |CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" );if (cs ==NULL ) {
@@ -349,6 +352,7 @@ cd->cert_context =find_certificate_in_store (cert_prop, cs);CertCloseStore (cs,0 );if (!cd->cert_context) { +/* ...then HKEY_LOCAL_MACHINE... */ cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_LOCAL_MACHINE |CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" );if (cs ==NULL ) {
@@ -357,6 +361,18 @@ } cd->cert_context =find_certificate_in_store (cert_prop, cs);CertCloseStore (cs,0 ); + } +if (!cd->cert_context) { +/* ...then HKEY_USERS... */ +/* TODO: Maybe only try this if we're running as SYSTEM? */ + cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_USERS | +CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" ); +if (cs ==NULL ) { +CRYPTOAPIerr (CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE ); + goto err; + } + cd->cert_context =find_certificate_in_store (cert_prop, cs); +CertCloseStore (cs,0 );if (cd->cert_context ==NULL ) {CRYPTOAPIerr (CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE ); goto err;
Signature · 5 lines
Peter 'Luna' Runestig (fd. Altberg), Sweden <[email protected]...> PGP Key ID: 0xD07BBE13 Fingerprint: 7B5C 1F48 2997 C061 DE4B 42EA CB99 A35C D07B BE13 AOL Instant Messenger Screen name: PRunestig Yahoo! Messenger profile name: altberg
Peter 'Luna' Runestig has put together a Crypto API patch which tries to access user-based certificate/key pairs even when OpenVPN is running as a service.
Given that Peter can't test this patch himself, it would be great if someone who uses this feature would volunteer to do some testing and report back to the list.
I've built a drop-in replacement for openvpn.exe (2.0-rc8) with the patch applied:
openvpn.exe -- this file is usually in \\Program Files\OpenVPN\bin openvpn.exe.asc -- GnuPG signature of above file
Thanks,
James
Quoted 80 lines · Peter 'Luna' Runestig
Quoted 11 lines · James Yonan
Looks like
CERT_SYSTEM_STORE_USERSis undefined in the MinGW environment.gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin -I/c/src/ openssl-0.9.7e/include -I/c/src/lzo-1.08/include -c
cryptoapi.c-o cryptoapi.ocryptoapi.c: In function `SSL_CTX_use_CryptoAPI_certificate':
cryptoapi.c:366: `CERT_SYSTEM_STORE_USERS' undeclared (first use in this function) cryptoapi.c:366: (Each undeclared identifier is reported only once cryptoapi.c:366: for each function it appears in.)
make: *** [cryptoapi.o] Error 1James
Maybe this is better?
cryptoapi.c renamed from cryptoapi-2.0_rc7.c +18
-2@@ -1,5 +1,5 @@/* -* Copyright (c) 2004 Peter 'Luna' Runestig <[email protected]...> +* Copyright (c) 2004, 05 Peter 'Luna' Runestig <[email protected]...> * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifi- @@ -41,7 +41,9 @@#define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)#define CERT_SYSTEM_STORE_LOCATION_SHIFT 16#define CERT_SYSTEM_STORE_CURRENT_USER_ID 1 +#define CERT_SYSTEM_STORE_USERS_ID 6#define CERT_SYSTEM_STORE_CURRENT_USER (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT) +#define CERT_SYSTEM_STORE_USERS (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)#define CERT_STORE_READONLY_FLAG 0x00008000#define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000#define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004@@ -339,7 +341,8 @@SSLerr (SSL_F_SSL_CTX_USE_CERTIFICATE_FILE ,ERR_R_MALLOC_FAILURE ); goto err; } -/* search CURRENT_USER first, then LOCAL_MACHINE */ +/* search for the wanted certificate in different parts of the system store: +* search HKEY_CURRENT_USER first... */ cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_CURRENT_USER |CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" );if (cs ==NULL ) {@@ -349,6 +352,7 @@ cd->cert_context =find_certificate_in_store (cert_prop, cs);CertCloseStore (cs,0 );if (!cd->cert_context) { +/* ...then HKEY_LOCAL_MACHINE... */ cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_LOCAL_MACHINE |CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" );if (cs ==NULL ) {@@ -357,6 +361,18 @@ } cd->cert_context =find_certificate_in_store (cert_prop, cs);CertCloseStore (cs,0 ); + } +if (!cd->cert_context) { +/* ...then HKEY_USERS... */ +/* TODO: Maybe only try this if we're running as SYSTEM? */ + cs =CertOpenStore ((LPCSTR )CERT_STORE_PROV_SYSTEM ,0 ,0 ,CERT_SYSTEM_STORE_USERS | +CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG ,L"MY" ); +if (cs ==NULL ) { +CRYPTOAPIerr (CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE ); + goto err; + } + cd->cert_context =find_certificate_in_store (cert_prop, cs); +CertCloseStore (cs,0 );if (cd->cert_context ==NULL ) {CRYPTOAPIerr (CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE ); goto err;Signature · 6 lines
-- Peter 'Luna' Runestig (fd. Altberg), Sweden <[email protected]...> PGP Key ID: 0xD07BBE13 Fingerprint: 7B5C 1F48 2997 C061 DE4B 42EA CB99 A35C D07B BE13 AOL Instant Messenger Screen name: PRunestig Yahoo! Messenger profile name: altberg