mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
misc: Add ssh_match_group().
This commit is contained in:
@@ -81,4 +81,6 @@ void ssh_timestamp_init(struct ssh_timestamp *ts);
|
|||||||
int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
|
int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
|
||||||
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
|
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
|
||||||
|
|
||||||
|
int ssh_match_group(const char *group, const char *object);
|
||||||
|
|
||||||
#endif /* MISC_H_ */
|
#endif /* MISC_H_ */
|
||||||
|
|||||||
27
src/dh.c
27
src/dh.c
@@ -54,6 +54,7 @@
|
|||||||
#include "libssh/buffer.h"
|
#include "libssh/buffer.h"
|
||||||
#include "libssh/session.h"
|
#include "libssh/session.h"
|
||||||
#include "libssh/keys.h"
|
#include "libssh/keys.h"
|
||||||
|
#include "libssh/misc.h"
|
||||||
#include "libssh/dh.h"
|
#include "libssh/dh.h"
|
||||||
#include "libssh/ssh2.h"
|
#include "libssh/ssh2.h"
|
||||||
|
|
||||||
@@ -1016,30 +1017,6 @@ ssh_string ssh_get_pubkey(ssh_session session){
|
|||||||
return ssh_string_copy(session->current_crypto->server_pubkey);
|
return ssh_string_copy(session->current_crypto->server_pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match(const char *group, const char *object){
|
|
||||||
const char *a;
|
|
||||||
const char *z;
|
|
||||||
|
|
||||||
z = group;
|
|
||||||
do {
|
|
||||||
a = strchr(z, ',');
|
|
||||||
if (a == NULL) {
|
|
||||||
if (strcmp(z, object) == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
if (strncmp(z, object, a - z) == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
z = a + 1;
|
|
||||||
} while(1);
|
|
||||||
|
|
||||||
/* not reached */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sig_verify(ssh_session session, ssh_public_key pubkey,
|
int sig_verify(ssh_session session, ssh_public_key pubkey,
|
||||||
SIGNATURE *signature, unsigned char *digest, int size) {
|
SIGNATURE *signature, unsigned char *digest, int size) {
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
@@ -1149,7 +1126,7 @@ int signature_verify(ssh_session session, ssh_string signature) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->wanted_methods[SSH_HOSTKEYS]) {
|
if (session->wanted_methods[SSH_HOSTKEYS]) {
|
||||||
if(!match(session->wanted_methods[SSH_HOSTKEYS],pubkey->type_c)) {
|
if(!ssh_match_group(session->wanted_methods[SSH_HOSTKEYS],pubkey->type_c)) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Public key from server (%s) doesn't match user preference (%s)",
|
"Public key from server (%s) doesn't match user preference (%s)",
|
||||||
pubkey->type_c, session->wanted_methods[SSH_HOSTKEYS]);
|
pubkey->type_c, session->wanted_methods[SSH_HOSTKEYS]);
|
||||||
|
|||||||
27
src/misc.c
27
src/misc.c
@@ -952,6 +952,33 @@ int ssh_timeout_update(struct ssh_timestamp *ts, int timeout){
|
|||||||
ret = timeout - ms;
|
ret = timeout - ms;
|
||||||
return ret >= 0 ? ret: 0;
|
return ret >= 0 ? ret: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ssh_match_group(const char *group, const char *object)
|
||||||
|
{
|
||||||
|
const char *a;
|
||||||
|
const char *z;
|
||||||
|
|
||||||
|
z = group;
|
||||||
|
do {
|
||||||
|
a = strchr(z, ',');
|
||||||
|
if (a == NULL) {
|
||||||
|
if (strcmp(z, object) == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
if (strncmp(z, object, a - z) == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
z = a + 1;
|
||||||
|
} while(1);
|
||||||
|
|
||||||
|
/* not reached */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/* vim: set ts=4 sw=4 et cindent: */
|
/* vim: set ts=4 sw=4 et cindent: */
|
||||||
|
|||||||
Reference in New Issue
Block a user