vnc/spice: add monitor command to change password.
cover vnc/spice: add monitor command to change password.
Hi,
This patch series adds a new monitor command to set the password with optional expiry time for spice and vnc remote desktop connections.
The patches are also available in the git repository at:
git://anongit.freedesktop.org/spice/qemu passwd.1
Gerd Hoffmann (3):
vnc: auth reject cleanup
vnc: support password expire
vnc/spice: add set_passwd monitor command.
console.h | 2 +- hmp-commands.hx | 23 ++++++++++++++++++++ monitor.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++- ui/qemu-spice.h | 3 ++ ui/spice-core.c | 7 ++++++ ui/vnc.c | 43 +++++++++++++++++++++++--------------- ui/vnc.h | 1 + 7 files changed, 120 insertions(+), 20 deletions(-)
PATCH 1/3 vnc: auth reject cleanup
protocol_client_auth_vnc() has two places where the auth can fail, with identical code sending the reject message to the client. Move the common code to the end of the function and make both error paths jump there. No functional change.
--- ui/vnc.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-)
ui/vnc.c +13 -17
@@ -2081,15 +2081,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)if (!vs->vd->password || !vs->vd->password[0 ]) {VNC_DEBUG ("No password configured on server" ); -vnc_write_u32 (vs,1 );/* Reject auth */ -if (vs->minor >=8 ) { -static const char err[] ="Authentication failed" ; -vnc_write_u32 (vs,sizeof (err)); -vnc_write (vs, err,sizeof (err)); - } -vnc_flush (vs); -vnc_client_error (vs); -return 0 ; + goto reject; }memcpy (response, vs->challenge,VNC_AUTH_CHALLENGE_SIZE );
@@ -2105,14 +2097,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)/* Compare expected vs actual challenge response */ if (memcmp (response, data,VNC_AUTH_CHALLENGE_SIZE ) !=0 ) {VNC_DEBUG ("Client challenge reponse did not match\n" ); -vnc_write_u32 (vs,1 );/* Reject auth */ -if (vs->minor >=8 ) { -static const char err[] ="Authentication failed" ; -vnc_write_u32 (vs,sizeof (err)); -vnc_write (vs, err,sizeof (err)); - } -vnc_flush (vs); -vnc_client_error (vs); + goto reject; }else {VNC_DEBUG ("Accepting VNC challenge response\n" );vnc_write_u32 (vs,0 );/* Accept auth */
@@ -2121,6 +2106,17 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)start_client_init (vs); }return 0 ; + +reject: +vnc_write_u32 (vs,1 );/* Reject auth */ +if (vs->minor >=8 ) { +static const char err[] ="Authentication failed" ; +vnc_write_u32 (vs,sizeof (err)); +vnc_write (vs, err,sizeof (err)); + } +vnc_flush (vs); +vnc_client_error (vs); +return 0 ; }void start_auth_vnc (VncState *vs)
Signature · 1 line
1.7.1
PATCH 2/3 vnc: support password expire
In reply to Gerd HoffmannThis patch adds support for expiring passwords to vnc. It adds a new lifetime parameter to the vnc_display_password() function, which specifies the number of seconds the new password will be valid. Passing zero as lifetime maintains current behavior (password never expires).
--- console.h | 2 +- monitor.c | 3 +-- ui/vnc.c | 15 ++++++++++++++- ui/vnc.h | 1 + 4 files changed, 17 insertions(+), 4 deletions(-)
console.h +1 -1
@@ -368,7 +368,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen);void vnc_display_init (DisplayState *ds);void vnc_display_close (DisplayState *ds);int vnc_display_open (DisplayState *ds,const char *display); -int vnc_display_password (DisplayState *ds,const char *password); +int vnc_display_password (DisplayState *ds,const char *password,int lifetime);void do_info_vnc_print (Monitor *mon,const QObject *data);void do_info_vnc (Monitor *mon,QObject **ret_data);char *vnc_display_local_addr (DisplayState *ds);
monitor.c +1 -2
@@ -966,11 +966,10 @@ static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)static int change_vnc_password (const char *password) { -if (vnc_display_password (NULL , password) <0 ) { +if (vnc_display_password (NULL , password,0 ) <0 ) {qerror_report (QERR_SET_PASSWD_FAILED );return -1 ; } -return 0 ; }
ui/vnc.c +14 -1
@@ -2078,11 +2078,19 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)unsigned char response[VNC_AUTH_CHALLENGE_SIZE ];int i, j, pwlen;unsigned char key[8 ]; +time_t now;if (!vs->vd->password || !vs->vd->password[0 ]) {VNC_DEBUG ("No password configured on server" ); goto reject; } +if (vs->vd->expires) { +time (&now); +if (vs->vd->expires < now) { +VNC_DEBUG ("Password is expired" ); + goto reject; + } + }memcpy (response, vs->challenge,VNC_AUTH_CHALLENGE_SIZE );
@@ -2474,7 +2482,7 @@ void vnc_display_close(DisplayState *ds)#endif } -int vnc_display_password (DisplayState *ds,const char *password) +int vnc_display_password (DisplayState *ds,const char *password,int lifetime) {VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
@@ -2492,6 +2500,11 @@ int vnc_display_password(DisplayState *ds, const char *password)if (vs->auth ==VNC_AUTH_NONE ) { vs->auth =VNC_AUTH_VNC ; } +if (lifetime) { + vs->expires =time (NULL ) + lifetime; + }else { + vs->expires =0 ; + } }else { vs->auth =VNC_AUTH_NONE ; }
ui/vnc.h +1 -0
@@ -120,6 +120,7 @@ struct VncDisplaychar *display;char *password; +time_t expires;int auth;bool lossy;#ifdef CONFIG_VNC_TLS
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Quoted 7 lines · Gerd Hoffmann
This patch adds support for expiring passwords to vnc. It adds a new lifetime parameter to the
vnc_display_password()function, which specifies the number of seconds the new password will be valid. Passing zero as lifetime maintains current behavior (password never expires).Signed-off-by Gerd Hoffmann<[email protected]>
This has been posted before and I've never understood it. Why can't a management tool just expire passwords on it's own?
How does password expiration help with security at all?
Regards,
Anthony Liguori
Quoted 95 lines
--- console.h | 2 +- monitor.c | 3 +-- ui/vnc.c | 15 ++++++++++++++- ui/vnc.h | 1 + 4 files changed, 17 insertions(+), 4 deletions(-)console.h +1
-1@@ -368,7 +368,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen);void vnc_display_init (DisplayState *ds);void vnc_display_close (DisplayState *ds);int vnc_display_open (DisplayState *ds,const char *display); -int vnc_display_password (DisplayState *ds,const char *password); +int vnc_display_password (DisplayState *ds,const char *password,int lifetime);void do_info_vnc_print (Monitor *mon,const QObject *data);void do_info_vnc (Monitor *mon,QObject **ret_data);char *vnc_display_local_addr (DisplayState *ds);monitor.c +1
-2@@ -966,11 +966,10 @@ static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)static int change_vnc_password (const char *password) { -if (vnc_display_password (NULL , password)<0 ) { +if (vnc_display_password (NULL , password,0 )<0 ) {qerror_report (QERR_SET_PASSWD_FAILED );return -1 ; } -return 0 ; }ui/vnc.c +14
-1@@ -2078,11 +2078,19 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)unsigned char response[VNC_AUTH_CHALLENGE_SIZE ];int i, j, pwlen;unsigned char key[8 ]; +time_t now;if (!vs->vd->password || !vs->vd->password[0 ]) {VNC_DEBUG ("No password configured on server" ); goto reject; } +if (vs->vd->expires) { +time (&now); +if (vs->vd->expires< now) { +VNC_DEBUG ("Password is expired" ); + goto reject; + } + }memcpy (response, vs->challenge,VNC_AUTH_CHALLENGE_SIZE );@@ -2474,7 +2482,7 @@ void vnc_display_close(DisplayState *ds)#endif } -int vnc_display_password (DisplayState *ds,const char *password) +int vnc_display_password (DisplayState *ds,const char *password,int lifetime) {VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;@@ -2492,6 +2500,11 @@ int vnc_display_password(DisplayState *ds, const char *password)if (vs->auth ==VNC_AUTH_NONE ) { vs->auth =VNC_AUTH_VNC ; } +if (lifetime) { + vs->expires =time (NULL ) + lifetime; + }else { + vs->expires =0 ; + } }else { vs->auth =VNC_AUTH_NONE ; }ui/vnc.h +1
-0@@ -120,6 +120,7 @@ struct VncDisplaychar *display;char *password; +time_t expires;int auth;bool lossy;#ifdef CONFIG_VNC_TLS
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Quoted 11 lines · Anthony Liguori
Quoted 7 lines · Gerd Hoffmann
This patch adds support for expiring passwords to vnc. It adds a new lifetime parameter to the
vnc_display_password()function, which specifies the number of seconds the new password will be valid. Passing zero as lifetime maintains current behavior (password never expires).Signed-off-by Gerd Hoffmann<[email protected]>This has been posted before and I've never understood it. Why can't a management tool just expire passwords on it's own?
If the management tool crashes or is restarted for some reason then it may miss the expiry task.
Quoted 1 line
How does password expiration help with security at all?
VNC passwords are obviously rather weak, so if you can limit the time the password is valid to the window in which you are expecting the incoming VNC connection this limits the time to attack the VNC password. A mgmt tool could do
- Set a VNC password
- Open the VNC connection
- Clear the VNC password
If anything goes wrong in the mgmt tool at step 2 though, then it may never to step 3, leaving the VNC server accessible. If it had set a password expiry at step 1, it would have a safety net that guarentees the password will be invalid after 'n' seconds, even if not explicitly cleared. Given how little code this is in QEMU, I think it is a worthwhile feature.
Regards,
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Hi,
Quoted 11 lines
Quoted 1 line
How does password expiration help with security at all?
VNC passwords are obviously rather weak, so if you can limit the time the password is valid to the window in which you are expecting the incoming VNC connection this limits the time to attack the VNC password. A mgmt tool could do
- Set a VNC password
- Open the VNC connection
- Clear the VNC password
Quoted 6 lines
If anything goes wrong in the mgmt tool at step 2 though, then it may never to step 3, leaving the VNC server accessible. If it had set a password expiry at step 1, it would have a safety net that guarentees the password will be invalid after 'n' seconds, even if not explicitly cleared. Given how little code this is in QEMU, I think it is a worthwhile feature.
Anthony? Do you agree? If so I have a updated tree to pull from for you (rebased to latest master, added sign-offs, otherwise unmodified).
thanks,
Gerd
The following changes since commit 7d72e76228351d18a856f1e4f5365b59d3205dc3:
intel-hda: documentation update (2010-11-02 00:41:04 +0300)
are available in the git repository at:
git://anongit.freedesktop.org/spice/qemu passwd.2
Gerd Hoffmann (3):
vnc: auth reject cleanup
vnc: support password expire
vnc/spice: add set_passwd monitor command.
console.h | 2 +- hmp-commands.hx | 23 ++++++++++++++++++++ monitor.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++- ui/qemu-spice.h | 3 ++ ui/spice-core.c | 7 ++++++ ui/vnc.c | 43 +++++++++++++++++++++++--------------- ui/vnc.h | 1 + 7 files changed, 120 insertions(+), 20 deletions(-)
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Quoted 22 lines · Gerd Hoffmann
Hi,
Quoted 11 lines
Quoted 1 line
How does password expiration help with security at all?
VNC passwords are obviously rather weak, so if you can limit the time the password is valid to the window in which you are expecting the incoming VNC connection this limits the time to attack the VNC password. A mgmt tool could do
- Set a VNC password
- Open the VNC connection
- Clear the VNC passwordQuoted 6 lines
If anything goes wrong in the mgmt tool at step 2 though, then it may never to step 3, leaving the VNC server accessible. If it had set a password expiry at step 1, it would have a safety net that guarentees the password will be invalid after 'n' seconds, even if not explicitly cleared. Given how little code this is in QEMU, I think it is a worthwhile feature.
Anthony? Do you agree? If so I have a updated tree to pull from for you (rebased to latest master, added sign-offs, otherwise unmodified).
[ ... ]
Quoted 2 lines
are available in the git repository at:
git://anongit.freedesktop.org/spice/qemupasswd.2
Ping? What is the status here?
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Quoted 4 lines · Gerd Hoffmann
Quoted 2 lines
are available in the git repository at:
git://anongit.freedesktop.org/spice/qemupasswd.2Ping? What is the status here?
My view is that it's wrong for QEMU because it's a specific management policy that isn't generally useful. It can be easily implemented outside of QEMU.
Of course, if both you and Dan disagree strongly, since this is so little code, I'll leave the final decision up to you.
Regards,
Anthony Liguori
Quoted 3 lines
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
In reply to Daniel P. BerrangeQuoted 26 lines · Daniel P. Berrange
Quoted 7 lines · Anthony Liguori
Quoted 5 lines · Gerd Hoffmann
This patch adds support for expiring passwords to vnc. It adds a new lifetime parameter to the
vnc_display_password()function, which specifies the number of seconds the new password will be valid. Passing zero as lifetime maintains current behavior (password never expires).Quoted 6 lines
Quoted 3 lines
Signed-off-by Gerd Hoffmann<[email protected]>This has been posted before and I've never understood it. Why can't a management tool just expire passwords on it's own?
If the management tool crashes or is restarted for some reason then it may miss the expiry task.
Quoted 2 lines
How does password expiration help with security at all?
VNC passwords are obviously rather weak, so if you can limit the time the password is valid to the window in which you are expecting the incoming VNC connection this limits the time to attack the VNC password. A mgmt tool could do
Quoted 7 lines
- Set a VNC password
- Open the VNC connection
- Clear the VNC passwordIf anything goes wrong in the mgmt tool at step 2 though, then it may never to step 3, leaving the VNC server accessible.
I think the point is that you can expire the password by just changing it through the monitor. Having an expiration policy builtin to QEMU (as opposed to libvirt) seems like the wrong place.
Quoted 5 lines
If it had set a password expiry at step 1, it would have a safety net that guarentees the password will be invalid after 'n' seconds, even if not explicitly cleared. Given how little code this is in QEMU, I think it is a worthwhile feature.\
It's a policy not a mechanism and I don't see a good reason to have the code in QEMU because it honestly is a policy for a specific product. I don't think it's a strong enough policy that it's going to be seen as widely useful.
Regards,
Anthony Liguori
Quoted 3 lines
Regards,
Daniel
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Hi,
Quoted 5 lines
Quoted 2 lines
If anything goes wrong in the mgmt tool at step 2 though, then it may never to step 3, leaving the VNC server accessible.
I think the point is that you can expire the password by just changing it through the monitor.
Well, you can't really expire it, you can only set it to $randomvalue. Unsetting the vnc password also disables authentication (in unstable), which is *not* what you want here ...
Quoted 2 lines
Having an expiration policy builtin to QEMU (as
opposed to libvirt) seems like the wrong place.
IMHO it doesn't build policy into qemu. It is still up to libvirt (or the management app building on top of libvirt) to decide if and when the password will expire. qemu will just do what libvirt asks for.
Instead of passing a expire time as implemented by the patches:
set-password $protocol $secret $time
we could add a expire-password command, then ask management to do
set-password $protocol $secret
[ let $time pass ]
expire-password $protocol
I fail to see why this is better though. The former is more robust and easier to implement in the management. The amount of code needed in qemu is probably quite similar ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Quoted 8 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
Quoted 2 lines
If anything goes wrong in the mgmt tool at step 2 though, then it may never to step 3, leaving the VNC server accessible.
I think the point is that you can expire the password by just changing it through the monitor.
Quoted 6 lines
Well, you can't really expire it, you can only set it to $randomvalue. Unsetting the vnc password also disables authentication (in unstable), which is *not* what you want here ...
Quoted 2 lines
Having an expiration policy builtin to QEMU (as
opposed to libvirt) seems like the wrong place.IMHO it doesn't build policy into qemu. It is still up to libvirt (or the management app building on top of libvirt) to decide if and when the password will expire.
Except if you want to cancel the expiration because the expiration policy changes. You'd have to set the password without an expiration time and you may not have ready access to the password.
Quoted 6 lines
qemu will just do what libvirt asks for.
Instead of passing a expire time as implemented by the patches:
set-password $protocol $secret $time
Quoted 7 lines
we could add a expire-password command, then ask management to do
set-password $protocol $secret
[ let $time pass ]
expire-password $protocolI fail to see why this is better though. The former is more robust and easier to implement in the management. The amount of code needed in qemu is probably quite similar ...
But the later let's a management tool implement arbitrarily complex expiration policies. It can also be used to generically disable any login which is effectively expiration but it may not be directly because of a timeout but rather because of some other operation. For instance, a management tool might want to implement a login policy whereas you're only allowed to log into a VM during business hours (9-5). Setting an expiration time for 8 hours is quite a bit less straight forward than just unsetting the password during the off hours.
Regards,
Anthony Liguori
Quoted 4 lines
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Hi,
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Having an expiration policy builtin to QEMU (as
opposed to libvirt) seems like the wrong place.IMHO it doesn't build policy into qemu. It is still up to libvirt (or the management app building on top of libvirt) to decide if and when the password will expire.
Except if you want to cancel the expiration because the expiration policy changes. You'd have to set the password without an expiration time and you may not have ready access to the password.
Point.
Quoted 10 lines
Quoted 7 lines
set-password $protocol $secret
[ let $time pass ]
expire-password $protocolI fail to see why this is better though. The former is more robust and easier to implement in the management. The amount of code needed in qemu is probably quite similar ...
But the later let's a management tool implement arbitrarily complex expiration policies.
Hmm, we could do this:
set-password $protocol $secret expire-password $protocol [ now | never | $seconds ]
Comments?
cheers,
Gerd
Re: [Qemu-devel] [PATCH 2/3] vnc: support password expire
Quoted 10 lines · Gerd Hoffmann
Quoted 2 lines
But the later let's a management tool implement arbitrarily complex expiration policies.
Hmm, we could do this:
set-password $protocol $secret expire-password $protocol [ now | never | $seconds ]
Comments?
I would be happy with this. I don't mind a bit of policy creeping into qemu as long as we're exposing the underlying mechanisms.
If it were me, I'd do:
set-password $protocol $secret
unset-password $protocol
expire-password [never | $seconds]
And I would implement expire-password in terms of unset-password.
Regards,
Anthony Liguori
Quoted 4 lines
cheers,
Gerd
PATCH 3/3 vnc/spice: add set_passwd monitor command.
In reply to Gerd HoffmannThis patch adds a new set_password monitor command which allows to change the password for spice and vnc connections. See the doc update patch chunk for details.
--- hmp-commands.hx | 23 +++++++++++++++++++++ monitor.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ui/qemu-spice.h | 3 ++ ui/spice-core.c | 7 ++++++ 4 files changed, 91 insertions(+), 0 deletions(-)
hmp-commands.hx +23 -0
@@ -1116,6 +1116,29 @@ Set the encrypted device @var{device} password to @var{password} ETEXI { + .name = "set_password", + .args_type = "protocol:s,password:s,expiration:i,connected:s?", + .params = "protocol password expiration action-if-connected", + .help = "set spice/vnc password", + .user_print = monitor_user_noop, + .mhandler.cmd_new = set_password, + }, + +STEXI +@item set_password [ vnc | spice ] password expiration [ action-if-connected ] +@findex set_password + +Change spice/vnc password. @var{expiration} specifies the number of +seconds the password will stay valid. Use zero to make the password +stay valid forever. @var{action-if-connected} specifies what should +happen in case a connection is established: @var{fail} makes the +password change fail. @var{disconnect} changes the password and +disconnects the client. @var{keep} changes the password and keeps the +connection up. @var{keep} is the default. + +ETEXI + + { .name = "info", .args_type = "item:s?", .params = "[subcommand]",
monitor.c +58 -0
70 lines not on this page · raw message
ui/qemu-spice.h +3 -0
@@ -31,10 +31,13 @@ void qemu_spice_init(void);void qemu_spice_input_init (void );void qemu_spice_display_init (DisplayState *ds);int qemu_spice_add_interface (SpiceBaseInstance *sin); +int qemu_spice_set_passwd (const char *passwd,int lifetime, +bool fail_if_connected,bool disconnect_if_connected);#else /* CONFIG_SPICE */ #define using_spice 0 +#define qemu_spice_set_passwd (_p, _l, _f1, _f2) (-1)#endif /* CONFIG_SPICE */
ui/spice-core.c +7 -0
@@ -176,6 +176,13 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin)return spice_server_add_interface (spice_server, sin); } +int qemu_spice_set_passwd (const char *passwd,int lifetime, +bool fail_if_connected,bool disconnect_if_connected) +{ +return spice_server_set_ticket (spice_server, passwd, lifetime, + fail_if_connected, disconnect_if_connected); +} +static void spice_register_config (void ) {qemu_add_opts (&qemu_spice_opts);
Signature · 1 line
1.7.1