Use AFS string-to-key from libkrb5.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4262 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1998-01-03 21:24:41 +00:00
parent c74c191b03
commit ad6c0a43d5

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997 Kungliga Tekniska H<>gskolan * Copyright (c) 1997, 1998 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -54,10 +54,8 @@ int help;
struct getargs args[] = { struct getargs args[] = {
{ "version5", '5', arg_flag, &version5, "Output Kerberos v5 string-to-key" }, { "version5", '5', arg_flag, &version5, "Output Kerberos v5 string-to-key" },
{ "version4", '4', arg_flag, &version4, "Output Kerberos v4 string-to-key" }, { "version4", '4', arg_flag, &version4, "Output Kerberos v4 string-to-key" },
#ifdef KRB4
{ "afs", 'a', arg_flag, &afs, "Output AFS string-to-key" }, { "afs", 'a', arg_flag, &afs, "Output AFS string-to-key" },
{ "cell", 'c', arg_string, &cell, "AFS cell to use", "cell" }, { "cell", 'c', arg_string, &cell, "AFS cell to use", "cell" },
#endif
{ "password", 'w', arg_string, &password, "Password to use", "password" }, { "password", 'w', arg_string, &password, "Password to use", "password" },
{ "principal",'p', arg_string, &principal, "Kerberos v5 principal to use", "principal" }, { "principal",'p', arg_string, &principal, "Kerberos v5 principal to use", "principal" },
{ "keytype", 'k', arg_string, &keytype_str, "Keytype" }, { "keytype", 'k', arg_string, &keytype_str, "Keytype" },
@@ -74,14 +72,26 @@ usage(int status)
exit(status); exit(status);
} }
void
tokey(krb5_context context, const char *password, krb5_data *salt,
krb5_keytype keytype, const char *label)
{
int i;
krb5_keyblock key;
krb5_string_to_key(password, salt, keytype, &key);
printf("%s: ", label);
for(i = 0; i < key.keyvalue.length; i++)
printf("%02x", ((unsigned char*)key.keyvalue.data)[i]);
printf("\n");
krb5_free_keyblock_contents(context, &key);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
krb5_context context; krb5_context context;
krb5_principal princ; krb5_principal princ;
krb5_data salt; krb5_data salt;
krb5_keyblock key;
int i;
int optind; int optind;
char buf[1024]; char buf[1024];
krb5_keytype keytype; krb5_keytype keytype;
@@ -125,14 +135,12 @@ main(int argc, char **argv)
buf[strlen(buf) - 1] = 0; buf[strlen(buf) - 1] = 0;
principal = strdup(buf); principal = strdup(buf);
} }
#ifdef KRB4
if(afs && cell == NULL){ if(afs && cell == NULL){
printf("AFS cell: "); printf("AFS cell: ");
fgets(buf, sizeof(buf), stdin); fgets(buf, sizeof(buf), stdin);
buf[strlen(buf) - 1] = 0; buf[strlen(buf) - 1] = 0;
cell = strdup(buf); cell = strdup(buf);
} }
#endif
if(argv[0]) if(argv[0])
password = argv[0]; password = argv[0];
if(password == NULL){ if(password == NULL){
@@ -145,29 +153,17 @@ main(int argc, char **argv)
salt.length = 0; salt.length = 0;
salt.data = NULL; salt.data = NULL;
krb5_get_salt(princ, &salt); krb5_get_salt(princ, &salt);
krb5_string_to_key(password, &salt, keytype, &key); tokey(context, password, &salt, keytype, "Kerberos v5 key");
printf("Kerberos v5 key: ");
for(i = 0; i < key.keyvalue.length; i++)
printf("%02x", ((unsigned char*)key.keyvalue.data)[i]);
printf("\n");
} }
if(version4){ if(version4){
des_cblock key; salt.length = 0;
des_string_to_key(password, &key); salt.data = NULL;
printf("Kerberos v4 key: "); tokey(context, password, &salt, KEYTYPE_DES, "Kerberos v4 key");
for(i = 0; i < 8; i++)
printf("%02x", ((unsigned char*)key)[i]);
printf("\n");
} }
#ifdef KRB4
if(afs){ if(afs){
des_cblock key; salt.length = strlen(cell);
afs_string_to_key(password, cell, &key); salt.data = cell;
printf("AFS key: "); tokey(context, password, &salt, KEYTYPE_DES_AFS3, "AFS key");
for(i = 0; i < 8; i++)
printf("%02x", ((unsigned char*)key)[i]);
printf("\n");
} }
#endif
return 0; return 0;
} }