fd2893
diff -up openssl-1.0.2j/apps/s_client.c.krb5keytab openssl-1.0.2j/apps/s_client.c
fd2893
--- openssl-1.0.2j/apps/s_client.c.krb5keytab	2017-01-05 17:02:05.481441088 +0100
fd2893
+++ openssl-1.0.2j/apps/s_client.c	2017-01-05 17:08:28.311073180 +0100
fd2893
@@ -171,6 +171,10 @@ typedef unsigned int u_int;
fd2893
 #include "s_apps.h"
fd2893
 #include "timeouts.h"
fd2893
 
fd2893
+#ifndef OPENSSL_NO_KRB5
fd2893
+static char *krb5svc = NULL;
fd2893
+#endif
fd2893
+
fd2893
 #if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
fd2893
 /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
fd2893
 # undef FIONBIO
fd2893
@@ -400,6 +404,9 @@ static void sc_usage(void)
fd2893
     BIO_printf(bio_err,
fd2893
                "                 only \"smtp\", \"pop3\", \"imap\", \"ftp\" and \"xmpp\"\n");
fd2893
     BIO_printf(bio_err, "                 are supported.\n");
fd2893
+#ifndef OPENSSL_NO_KRB5
fd2893
+    BIO_printf(bio_err, " -krb5svc arg  - Kerberos service name\n");
fd2893
+#endif
fd2893
 #ifndef OPENSSL_NO_ENGINE
fd2893
     BIO_printf(bio_err,
fd2893
                " -engine id    - Initialise and use the specified engine\n");
fd2893
@@ -1069,6 +1076,13 @@ int MAIN(int argc, char **argv)
fd2893
             c_nbio = 1;
fd2893
         }
fd2893
 #endif
fd2893
+#ifndef OPENSSL_NO_KRB5
fd2893
+	else if	(strcmp(*argv, "-krb5svc") == 0) {
fd2893
+            if (--argc < 1)
fd2893
+                goto bad;
fd2893
+            krb5svc= *(++argv);
fd2893
+        }
fd2893
+#endif
fd2893
         else if (strcmp(*argv, "-starttls") == 0) {
fd2893
             if (--argc < 1)
fd2893
                 goto bad;
fd2893
@@ -1435,6 +1449,8 @@ int MAIN(int argc, char **argv)
fd2893
     if (con && (kctx = kssl_ctx_new()) != NULL) {
fd2893
         SSL_set0_kssl_ctx(con, kctx);
fd2893
         kssl_ctx_setstring(kctx, KSSL_SERVER, host);
fd2893
+        if (krb5svc != NULL)
fd2893
+            kssl_ctx_setstring(kctx, KSSL_SERVICE, krb5svc);
fd2893
     }
fd2893
 #endif                          /* OPENSSL_NO_KRB5 */
fd2893
 /*      SSL_set_cipher_list(con,"RC4-MD5"); */
fd2893
diff -up openssl-1.0.2j/apps/s_server.c.krb5keytab openssl-1.0.2j/apps/s_server.c
fd2893
--- openssl-1.0.2j/apps/s_server.c.krb5keytab	2017-01-05 17:02:05.482441111 +0100
fd2893
+++ openssl-1.0.2j/apps/s_server.c	2017-01-05 17:16:36.458078609 +0100
fd2893
@@ -206,6 +206,11 @@ typedef unsigned int u_int;
fd2893
 # include <fcntl.h>
fd2893
 #endif
fd2893
 
fd2893
+#ifndef OPENSSL_NO_KRB5
fd2893
+static char *krb5svc = NULL;
fd2893
+static char *keytab = NULL;
fd2893
+#endif
fd2893
+
fd2893
 #ifndef OPENSSL_NO_RSA
fd2893
 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength);
fd2893
 #endif
fd2893
@@ -579,6 +584,10 @@ static void sv_usage(void)
fd2893
     BIO_printf(bio_err, " -serverpref   - Use server's cipher preferences\n");
fd2893
     BIO_printf(bio_err, " -quiet        - No server output\n");
fd2893
     BIO_printf(bio_err, " -no_tmp_rsa   - Do not generate a tmp RSA key\n");
fd2893
+#ifndef OPENSSL_NO_KRB5
fd2893
+    BIO_printf(bio_err, " -krb5svc arg  - Kerberos service name\n");
fd2893
+    BIO_printf(bio_err, " -keytab arg   - Kerberos keytab filename\n");
fd2893
+#endif
fd2893
 #ifndef OPENSSL_NO_PSK
fd2893
     BIO_printf(bio_err, " -psk_hint arg - PSK identity hint to use\n");
fd2893
     BIO_printf(bio_err, " -psk arg      - PSK in hex (without 0x)\n");
fd2893
@@ -1326,6 +1335,17 @@ int MAIN(int argc, char *argv[])
fd2893
                 goto bad;
fd2893
             vfyCAfile = *(++argv);
fd2893
         }
fd2893
+#ifndef OPENSSL_NO_KRB5
fd2893
+        else if (strcmp(*argv, "-krb5svc") == 0) {
fd2893
+            if (--argc < 1)
fd2893
+                goto bad;
fd2893
+            krb5svc = *(++argv);
fd2893
+        } else if (strcmp(*argv, "-keytab") == 0) {
fd2893
+            if (--argc < 1)
fd2893
+                goto bad;
fd2893
+            keytab = *(++argv);
fd2893
+        }
fd2893
+#endif
fd2893
 #ifdef FIONBIO
fd2893
         else if (strcmp(*argv, "-nbio") == 0) {
fd2893
             s_nbio = 1;
fd2893
@@ -2226,8 +2246,10 @@ static int sv_body(char *hostname, int s
fd2893
 #ifndef OPENSSL_NO_KRB5
fd2893
         if ((kctx = kssl_ctx_new()) != NULL) {
fd2893
             SSL_set0_kssl_ctx(con, kctx);
fd2893
-            kssl_ctx_setstring(kctx, KSSL_SERVICE, KRB5SVC);
fd2893
-            kssl_ctx_setstring(kctx, KSSL_KEYTAB, KRB5KEYTAB);
fd2893
+            kssl_ctx_setstring(kctx, KSSL_SERVICE,
fd2893
+                krb5svc == NULL ? KRB5SVC : krb5svc);
fd2893
+            if (keytab != NULL)
fd2893
+                kssl_ctx_setstring(kctx, KSSL_KEYTAB, keytab);
fd2893
         }
fd2893
 #endif                          /* OPENSSL_NO_KRB5 */
fd2893
         if (context)
fd2893
@@ -2836,8 +2858,11 @@ static int www_body(char *hostname, int
fd2893
 #endif
fd2893
 #ifndef OPENSSL_NO_KRB5
fd2893
     if ((kctx = kssl_ctx_new()) != NULL) {
fd2893
-        kssl_ctx_setstring(kctx, KSSL_SERVICE, KRB5SVC);
fd2893
-        kssl_ctx_setstring(kctx, KSSL_KEYTAB, KRB5KEYTAB);
fd2893
+        SSL_set0_kssl_ctx(con, kctx);
fd2893
+        kssl_ctx_setstring(kctx, KSSL_SERVICE,
fd2893
+            krb5svc == NULL ? KRB5SVC : krb5svc);
fd2893
+        if (keytab != NULL)
fd2893
+            kssl_ctx_setstring(kctx, KSSL_KEYTAB, keytab);
fd2893
     }
fd2893
 #endif                          /* OPENSSL_NO_KRB5 */
fd2893
     if (context)
fd2893
diff -up openssl-1.0.2j/doc/apps/s_client.pod.krb5keytab openssl-1.0.2j/doc/apps/s_client.pod
fd2893
--- openssl-1.0.2j/doc/apps/s_client.pod.krb5keytab	2016-09-26 11:49:07.000000000 +0200
fd2893
+++ openssl-1.0.2j/doc/apps/s_client.pod	2017-01-05 17:21:30.562709291 +0100
fd2893
@@ -43,6 +43,7 @@ B<openssl> B<s_client>
fd2893
 [B<-fallback_scsv>]
fd2893
 [B<-bugs>]
fd2893
 [B<-cipher cipherlist>]
fd2893
+[B<-krb5svc service>]
fd2893
 [B<-serverpref>]
fd2893
 [B<-starttls protocol>]
fd2893
 [B<-engine id>]
fd2893
@@ -228,6 +229,12 @@ command for more information.
fd2893
 
fd2893
 use the server's cipher preferences; only used for SSLV2.
fd2893
 
fd2893
+=item B<-krb5svc service>
fd2893
+
fd2893
+the Kerberos service name to use (default "host"). This means s_server
fd2893
+will expect a ticket for the principal I<service>/hostname@REALM, and will
fd2893
+need keys for that principal in its keytab.
fd2893
+
fd2893
 =item B<-starttls protocol>
fd2893
 
fd2893
 send the protocol-specific message(s) to switch to TLS for communication.
fd2893
diff -up openssl-1.0.2j/doc/apps/s_server.pod.krb5keytab openssl-1.0.2j/doc/apps/s_server.pod
fd2893
--- openssl-1.0.2j/doc/apps/s_server.pod.krb5keytab	2017-01-05 17:02:05.482441111 +0100
fd2893
+++ openssl-1.0.2j/doc/apps/s_server.pod	2017-01-05 17:20:54.769902331 +0100
fd2893
@@ -37,6 +37,8 @@ B<openssl> B<s_server>
fd2893
 [B<-nocert>]
fd2893
 [B<-cipher cipherlist>]
fd2893
 [B<-serverpref>]
fd2893
+[B<-krb5svc service>]
fd2893
+[B<-keytab filename>]
fd2893
 [B<-quiet>]
fd2893
 [B<-no_tmp_rsa>]
fd2893
 [B<-ssl2>]
fd2893
@@ -246,6 +248,17 @@ the B<ciphers> command for more informat
fd2893
 
fd2893
 use the server's cipher preferences, rather than the client's preferences.
fd2893
 
fd2893
+=item B<-krb5svc service>
fd2893
+
fd2893
+the Kerberos service name to use (default "host"). This means s_server
fd2893
+will expect a ticket for the principal I<service>/hostname@REALM, and will
fd2893
+need keys for that principal in its keytab.
fd2893
+
fd2893
+=item B<-keytab filename>
fd2893
+
fd2893
+the Kerberos "keytab" (key table) file, containing keys for the s_server
fd2893
+service principal (Kerberos identity; see -krb5svc).
fd2893
+
fd2893
 =item B<-tlsextdebug>
fd2893
 
fd2893
 print out a hex dump of any TLS extensions received from the server.