From ad6c0a43d58af82fcfe0f22acc9e18a24fc6d013 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Sat, 3 Jan 1998 21:24:41 +0000 Subject: [PATCH] Use AFS string-to-key from libkrb5. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4262 ec53bebd-3082-4978-b11e-865c3cabbd6b --- kdc/string2key.c | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/kdc/string2key.c b/kdc/string2key.c index 6d6e2a8c0..cf09ea26e 100644 --- a/kdc/string2key.c +++ b/kdc/string2key.c @@ -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). * All rights reserved. * @@ -54,10 +54,8 @@ int help; struct getargs args[] = { { "version5", '5', arg_flag, &version5, "Output Kerberos v5 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" }, { "cell", 'c', arg_string, &cell, "AFS cell to use", "cell" }, -#endif { "password", 'w', arg_string, &password, "Password to use", "password" }, { "principal",'p', arg_string, &principal, "Kerberos v5 principal to use", "principal" }, { "keytype", 'k', arg_string, &keytype_str, "Keytype" }, @@ -74,14 +72,26 @@ usage(int 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 main(int argc, char **argv) { krb5_context context; krb5_principal princ; krb5_data salt; - krb5_keyblock key; - int i; int optind; char buf[1024]; krb5_keytype keytype; @@ -125,14 +135,12 @@ main(int argc, char **argv) buf[strlen(buf) - 1] = 0; principal = strdup(buf); } -#ifdef KRB4 if(afs && cell == NULL){ printf("AFS cell: "); fgets(buf, sizeof(buf), stdin); buf[strlen(buf) - 1] = 0; cell = strdup(buf); } -#endif if(argv[0]) password = argv[0]; if(password == NULL){ @@ -145,29 +153,17 @@ main(int argc, char **argv) salt.length = 0; salt.data = NULL; krb5_get_salt(princ, &salt); - krb5_string_to_key(password, &salt, keytype, &key); - printf("Kerberos v5 key: "); - for(i = 0; i < key.keyvalue.length; i++) - printf("%02x", ((unsigned char*)key.keyvalue.data)[i]); - printf("\n"); + tokey(context, password, &salt, keytype, "Kerberos v5 key"); } if(version4){ - des_cblock key; - des_string_to_key(password, &key); - printf("Kerberos v4 key: "); - for(i = 0; i < 8; i++) - printf("%02x", ((unsigned char*)key)[i]); - printf("\n"); + salt.length = 0; + salt.data = NULL; + tokey(context, password, &salt, KEYTYPE_DES, "Kerberos v4 key"); } -#ifdef KRB4 if(afs){ - des_cblock key; - afs_string_to_key(password, cell, &key); - printf("AFS key: "); - for(i = 0; i < 8; i++) - printf("%02x", ((unsigned char*)key)[i]); - printf("\n"); + salt.length = strlen(cell); + salt.data = cell; + tokey(context, password, &salt, KEYTYPE_DES_AFS3, "AFS key"); } -#endif return 0; }