Create a ssh_get_hexa function.
This function converts a buffer into a colon separated hex string. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@308 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
1fd7a875be
Коммит
ae4ef84702
@ -231,7 +231,8 @@ void *string_data(STRING *str);
|
|||||||
void string_free(STRING *str);
|
void string_free(STRING *str);
|
||||||
|
|
||||||
/* useful for debug */
|
/* useful for debug */
|
||||||
void ssh_print_hexa(char *descr, const unsigned char *what, int len);
|
char *ssh_get_hexa(const unsigned char *what, size_t len);
|
||||||
|
void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
|
||||||
int ssh_get_random(void *where,int len,int strong);
|
int ssh_get_random(void *where,int len,int strong);
|
||||||
|
|
||||||
/* this one can be called by the client to see the hash of the public key before accepting it */
|
/* this one can be called by the client to see the hash of the public key before accepting it */
|
||||||
|
57
libssh/dh.c
57
libssh/dh.c
@ -141,17 +141,54 @@ void ssh_print_bignum(char *which,bignum num){
|
|||||||
free(hex);
|
free(hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_print_hexa(char *descr, const unsigned char *what, int len){
|
/**
|
||||||
int i;
|
* @brief Convert a buffer into a colon separated hex string.
|
||||||
printf("%s : ",descr);
|
* The caller has to free the memory.
|
||||||
if(len>16)
|
*
|
||||||
printf ("\n ");
|
* @param what What should be converted to a hex string.
|
||||||
for(i=0;i<len-1;i++){
|
*
|
||||||
printf("%.2hhx:",what[i]);
|
* @param len Length of the buffer to convert.
|
||||||
if((i+1) % 16 ==0)
|
*
|
||||||
printf("\n ");
|
* @return The hex string or NULL on error.
|
||||||
|
*/
|
||||||
|
char *ssh_get_hexa(const unsigned char *what, size_t len) {
|
||||||
|
char *hexa = NULL;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
hexa = malloc(len * 3 + 1);
|
||||||
|
if (hexa == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZERO_STRUCTP(hexa);
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
char hex[4];
|
||||||
|
snprintf(hex, sizeof(hex), "%02x:", what[i]);
|
||||||
|
strcat(hexa, hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
hexa[(len * 3) - 1] = '\0';
|
||||||
|
|
||||||
|
return hexa;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a buffer as colon separated hex string.
|
||||||
|
*
|
||||||
|
* @param descr Description printed infront of the hex string.
|
||||||
|
*
|
||||||
|
* @param what What should be converted to a hex string.
|
||||||
|
*
|
||||||
|
* @param len Length of the buffer to convert.
|
||||||
|
*/
|
||||||
|
void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len) {
|
||||||
|
char *hexa = ssh_get_hexa(what, len);
|
||||||
|
|
||||||
|
if (hexa == NULL) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
printf("%.2hhx\n",what[i]);
|
printf("%s: %s\n", descr, hexa);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dh_generate_x(SSH_SESSION *session){
|
void dh_generate_x(SSH_SESSION *session){
|
||||||
|
@ -8,7 +8,7 @@ SSH_0.3 {
|
|||||||
string_from_char; string_len; string_new; string_fill; string_to_char;
|
string_from_char; string_len; string_new; string_fill; string_to_char;
|
||||||
string_copy; string_burn; string_data;
|
string_copy; string_burn; string_data;
|
||||||
ssh_crypto_init;
|
ssh_crypto_init;
|
||||||
ssh_print_hexa; ssh_get_random;
|
ssh_get_hexa; ssh_print_hexa; ssh_get_random;
|
||||||
ssh_get_pubkey_hash; ssh_get_pubkey;
|
ssh_get_pubkey_hash; ssh_get_pubkey;
|
||||||
ssh_fd_poll; ssh_select; publickey_free;
|
ssh_fd_poll; ssh_select; publickey_free;
|
||||||
privatekey_from_file; publickey_to_string; publickey_from_privatekey;
|
privatekey_from_file; publickey_to_string; publickey_from_privatekey;
|
||||||
|
7
sample.c
7
sample.c
@ -403,6 +403,7 @@ int main(int argc, char **argv){
|
|||||||
int auth=0;
|
int auth=0;
|
||||||
char *password;
|
char *password;
|
||||||
char *banner;
|
char *banner;
|
||||||
|
char *hexa;
|
||||||
int state;
|
int state;
|
||||||
char buf[10];
|
char buf[10];
|
||||||
unsigned char hash[MD5_DIGEST_LEN];
|
unsigned char hash[MD5_DIGEST_LEN];
|
||||||
@ -446,9 +447,11 @@ int main(int argc, char **argv){
|
|||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
exit(-1);
|
exit(-1);
|
||||||
case SSH_SERVER_NOT_KNOWN:
|
case SSH_SERVER_NOT_KNOWN:
|
||||||
|
ssh_get_pubkey_hash(session, hash);
|
||||||
|
hexa = ssh_get_hexa(hash, MD5_DIGEST_LEN);
|
||||||
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
|
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
|
||||||
ssh_get_pubkey_hash(session,hash);
|
fprintf(stderr, "Public key hash: %s\n", hexa);
|
||||||
ssh_print_hexa("Public key hash",hash,MD5_DIGEST_LEN);
|
free(hexa);
|
||||||
fgets(buf,sizeof(buf),stdin);
|
fgets(buf,sizeof(buf),stdin);
|
||||||
if(strncasecmp(buf,"yes",3)!=0){
|
if(strncasecmp(buf,"yes",3)!=0){
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user