101 |
|
|
102 |
memset (&hint, 0, sizeof (hint)); |
memset (&hint, 0, sizeof (hint)); |
103 |
|
|
104 |
tmpserver = xmalloc (strlen(SERVICE) + strlen(sname) + 2); |
tmpserver = (char *)xmalloc (strlen(SERVICE) + strlen(sname) + 2); |
105 |
strcpy (tmpserver, SERVICE); |
strcpy (tmpserver, SERVICE); |
106 |
strcat (tmpserver, "/"); |
strcat (tmpserver, "/"); |
107 |
strcat (tmpserver, sname); |
strcat (tmpserver, sname); |
236 |
int rc; |
int rc; |
237 |
int i; |
int i; |
238 |
int error; |
int error; |
|
char result; |
|
239 |
/* KERBEROS 5 SENDAUTH MESSAGE */ |
/* KERBEROS 5 SENDAUTH MESSAGE */ |
240 |
char krb5sendauth[] = "KRB5_SENDAUTH_V1.0"; |
char krb5sendauth[] = "KRB5_SENDAUTH_V1.0"; |
241 |
/* PROTOCOL VERSION */ |
/* PROTOCOL VERSION */ |
333 |
|
|
334 |
/* Authentication type is ok */ |
/* Authentication type is ok */ |
335 |
|
|
336 |
result = '\0'; |
write (infd, "\0", 1); |
|
write (infd, &result, 1); |
|
337 |
|
|
338 |
/* Read Authentication request from client */ |
/* Read Authentication request from client */ |
339 |
|
|
465 |
readenc (Shishi * h, int sock, char *buf, int *len, shishi_ivector *iv, |
readenc (Shishi * h, int sock, char *buf, int *len, shishi_ivector *iv, |
466 |
Shishi_key * enckey, int proto) |
Shishi_key * enckey, int proto) |
467 |
{ |
{ |
468 |
char *out; |
char * out; |
469 |
char *outbis; |
char * outbis; |
470 |
char *iv2; |
char * iv2; |
471 |
|
|
472 |
int rc; |
int rc; |
473 |
int val; |
int val; |
495 |
dlen += blocksize - 1; |
dlen += blocksize - 1; |
496 |
if (proto == 2) |
if (proto == 2) |
497 |
dlen += 4; |
dlen += 4; |
498 |
if (shishi_key_type (enckey) != SHISHI_DES3_CBC_HMAC_SHA1_KD) |
if (enctype != SHISHI_DES3_CBC_HMAC_SHA1_KD) |
499 |
dlen += hashsize; |
dlen += hashsize; |
500 |
else |
else |
501 |
dlen += blocksize; |
dlen += blocksize; |
503 |
dlen /= blocksize; |
dlen /= blocksize; |
504 |
dlen *= blocksize; |
dlen *= blocksize; |
505 |
|
|
506 |
if (shishi_key_type (enckey) == SHISHI_DES3_CBC_HMAC_SHA1_KD) |
if (enctype == SHISHI_DES3_CBC_HMAC_SHA1_KD) |
507 |
dlen += hashsize; |
dlen += hashsize; |
508 |
|
|
509 |
/* read encrypted data */ |
/* read encrypted data */ |
510 |
outbis = malloc (dlen); |
outbis = (char *)xmalloc (dlen); |
511 |
if (outbis == NULL) |
if (outbis == NULL) |
512 |
{ |
{ |
513 |
printf ("Malloc error!\n"); |
printf ("Malloc error!\n"); |
518 |
if (rc != dlen) |
if (rc != dlen) |
519 |
{ |
{ |
520 |
printf ("Error during read socket\n"); |
printf ("Error during read socket\n"); |
521 |
|
free (outbis); |
522 |
return 1; |
return 1; |
523 |
} |
} |
524 |
|
|
526 |
{ |
{ |
527 |
rc = |
rc = |
528 |
shishi_decrypt (h, enckey, iv->keyusage, outbis, dlen, &out, &outlen); |
shishi_decrypt (h, enckey, iv->keyusage, outbis, dlen, &out, &outlen); |
529 |
|
if (rc != SHISHI_OK) |
530 |
|
{ |
531 |
|
printf ("decryption error\n"); |
532 |
|
free (outbis); |
533 |
|
return 1; |
534 |
|
} |
535 |
|
|
536 |
|
*len = outlen; |
537 |
|
val = 0; |
538 |
} |
} |
539 |
else |
else |
540 |
{ |
{ |
541 |
rc = |
rc = |
542 |
shishi_decrypt_ivupdate (h, enckey, iv->keyusage, iv->iv, iv->ivlen, &iv2, &iv->ivlen, outbis, |
shishi_decrypt_ivupdate (h, enckey, iv->keyusage, iv->iv, iv->ivlen, &iv2, &iv->ivlen, outbis, |
543 |
dlen, &out, &outlen); |
dlen, &out, &outlen); |
544 |
} |
if (rc != SHISHI_OK) |
545 |
if (rc != SHISHI_OK) |
{ |
546 |
{ |
printf ("decryption error\n"); |
547 |
printf ("decryption error\n"); |
free (outbis); |
548 |
return 1; |
return 1; |
549 |
} |
} |
550 |
|
|
|
/* len = first 4 bytes of decrypted data */ |
|
|
if (proto == 2) |
|
|
{ |
|
551 |
/* in KCMDV0.2 first 4 bytes of decrypted data = len of data */ |
/* in KCMDV0.2 first 4 bytes of decrypted data = len of data */ |
552 |
*len = ntohl (*((int *) out)); |
*len = ntohl (*((int *) out)); |
553 |
val = sizeof (int); |
val = sizeof (int); |
|
} |
|
|
else |
|
|
{ |
|
|
*len = outlen; |
|
|
val = 0; |
|
|
} |
|
554 |
|
|
|
if (proto == 2) |
|
|
{ |
|
555 |
/* update iv */ |
/* update iv */ |
556 |
memcpy (iv->iv, iv2, iv->ivlen); |
memcpy (iv->iv, iv2, iv->ivlen); |
557 |
} |
} |
588 |
/* data to encrypt = size + data */ |
/* data to encrypt = size + data */ |
589 |
if (proto == 2) |
if (proto == 2) |
590 |
{ |
{ |
591 |
bufbis = malloc (wlen + sizeof (int)); |
bufbis = (char *)xmalloc (wlen + sizeof (int)); |
|
memset (bufbis, 0, wlen + sizeof (int)); |
|
592 |
memcpy (bufbis, (char *) &dlen, sizeof (int)); |
memcpy (bufbis, (char *) &dlen, sizeof (int)); |
593 |
memcpy (bufbis + sizeof (int), buf, wlen); |
memcpy (bufbis + sizeof (int), buf, wlen); |
594 |
|
|
599 |
} |
} |
600 |
else |
else |
601 |
{ |
{ |
602 |
bufbis = malloc (wlen); |
bufbis = (char *)xmalloc (wlen); |
|
memset (bufbis, 0, wlen); |
|
603 |
memcpy (bufbis, buf, wlen); |
memcpy (bufbis, buf, wlen); |
604 |
|
|
605 |
/* data to encrypt = size + data */ |
/* data to encrypt = size + data */ |