|
|
8f2528 |
diff -up openssh-6.8p1/Makefile.in.kdf-cavs openssh-6.8p1/Makefile.in
|
|
|
8f2528 |
--- openssh-6.8p1/Makefile.in.kdf-cavs 2015-03-18 11:23:46.346049359 +0100
|
|
|
8f2528 |
+++ openssh-6.8p1/Makefile.in 2015-03-18 11:24:20.395968445 +0100
|
|
|
8f2528 |
@@ -29,6 +29,7 @@ SSH_LDAP_HELPER=$(libexecdir)/ssh-ldap-h
|
|
|
8f2528 |
SSH_LDAP_WRAPPER=$(libexecdir)/ssh-ldap-wrapper
|
|
|
8f2528 |
SSH_KEYCAT=$(libexecdir)/ssh-keycat
|
|
|
8f2528 |
CTR_CAVSTEST=$(libexecdir)/ctr-cavstest
|
|
|
8f2528 |
+SSH_CAVS=$(libexecdir)/ssh-cavs
|
|
|
8f2528 |
SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper
|
|
|
8f2528 |
PRIVSEP_PATH=@PRIVSEP_PATH@
|
|
|
8f2528 |
SSH_PRIVSEP_USER=@SSH_PRIVSEP_USER@
|
|
|
8f2528 |
@@ -67,7 +68,7 @@ EXEEXT=@EXEEXT@
|
|
|
8f2528 |
MANFMT=@MANFMT@
|
|
|
8f2528 |
INSTALL_SSH_LDAP_HELPER=@INSTALL_SSH_LDAP_HELPER@
|
|
|
8f2528 |
|
|
|
8f2528 |
-TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-ldap-helper$(EXEEXT) ssh-keycat$(EXEEXT) ctr-cavstest$(EXEEXT)
|
|
|
8f2528 |
+TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-ldap-helper$(EXEEXT) ssh-keycat$(EXEEXT) ctr-cavstest$(EXEEXT) ssh-cavs$(EXEEXT)
|
|
|
8f2528 |
|
|
|
8f2528 |
LIBOPENSSH_OBJS=\
|
|
|
8f2528 |
ssh_api.o \
|
|
|
8f2528 |
@@ -198,6 +199,9 @@ ssh-keycat$(EXEEXT): $(LIBCOMPAT) $(SSHD
|
|
|
8f2528 |
ctr-cavstest$(EXEEXT): $(LIBCOMPAT) libssh.a ctr-cavstest.o
|
|
|
8f2528 |
$(LD) -o $@ ctr-cavstest.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
|
|
|
8f2528 |
|
|
|
8f2528 |
+ssh-cavs$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-cavs.o
|
|
|
8f2528 |
+ $(LD) -o $@ ssh-cavs.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
|
8f2528 |
+
|
|
|
8f2528 |
ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o
|
|
|
8f2528 |
$(LD) -o $@ ssh-keyscan.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
|
|
|
8f2528 |
|
|
|
8f2528 |
@@ -331,6 +335,8 @@ install-files:
|
|
|
8f2528 |
fi
|
|
|
8f2528 |
$(INSTALL) -m 0755 $(STRIP_OPT) ssh-keycat$(EXEEXT) $(DESTDIR)$(libexecdir)/ssh-keycat$(EXEEXT)
|
|
|
8f2528 |
$(INSTALL) -m 0755 $(STRIP_OPT) ctr-cavstest$(EXEEXT) $(DESTDIR)$(libexecdir)/ctr-cavstest$(EXEEXT)
|
|
|
8f2528 |
+ $(INSTALL) -m 0755 $(STRIP_OPT) ssh-cavs$(EXEEXT) $(DESTDIR)$(libexecdir)/ssh-cavs$(EXEEXT)
|
|
|
8f2528 |
+ $(INSTALL) -m 0755 $(STRIP_OPT) ssh-cavs_driver.pl $(DESTDIR)$(libexecdir)/ssh-cavs_driver.pl
|
|
|
8f2528 |
$(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT)
|
|
|
8f2528 |
$(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
|
|
|
8f2528 |
$(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
|
|
|
8f2528 |
diff -up openssh-6.8p1/ssh-cavs.c.kdf-cavs openssh-6.8p1/ssh-cavs.c
|
|
|
8f2528 |
--- openssh-6.8p1/ssh-cavs.c.kdf-cavs 2015-03-18 11:23:46.348049354 +0100
|
|
|
8f2528 |
+++ openssh-6.8p1/ssh-cavs.c 2015-03-18 11:23:46.348049354 +0100
|
|
|
8f2528 |
@@ -0,0 +1,380 @@
|
|
|
8f2528 |
+/*
|
|
|
8f2528 |
+ * Copyright (C) 2015, Stephan Mueller <smueller@chronox.de>
|
|
|
8f2528 |
+ *
|
|
|
8f2528 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
8f2528 |
+ * modification, are permitted provided that the following conditions
|
|
|
8f2528 |
+ * are met:
|
|
|
8f2528 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
8f2528 |
+ * notice, and the entire permission notice in its entirety,
|
|
|
8f2528 |
+ * including the disclaimer of warranties.
|
|
|
8f2528 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
8f2528 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
8f2528 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
8f2528 |
+ * 3. The name of the author may not be used to endorse or promote
|
|
|
8f2528 |
+ * products derived from this software without specific prior
|
|
|
8f2528 |
+ * written permission.
|
|
|
8f2528 |
+ *
|
|
|
8f2528 |
+ * ALTERNATIVELY, this product may be distributed under the terms of
|
|
|
8f2528 |
+ * the GNU General Public License, in which case the provisions of the GPL2
|
|
|
8f2528 |
+ * are required INSTEAD OF the above restrictions. (This clause is
|
|
|
8f2528 |
+ * necessary due to a potential bad interaction between the GPL and
|
|
|
8f2528 |
+ * the restrictions contained in a BSD-style copyright.)
|
|
|
8f2528 |
+ *
|
|
|
8f2528 |
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
8f2528 |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
8f2528 |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
|
|
|
8f2528 |
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
|
|
8f2528 |
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
8f2528 |
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
|
8f2528 |
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
8f2528 |
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
8f2528 |
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
8f2528 |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
|
8f2528 |
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
8f2528 |
+ * DAMAGE.
|
|
|
8f2528 |
+ */
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+#include "includes.h"
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+#include <stdio.h>
|
|
|
8f2528 |
+#include <stdlib.h>
|
|
|
8f2528 |
+#include <errno.h>
|
|
|
8f2528 |
+#include <sys/types.h>
|
|
|
8f2528 |
+#include <string.h>
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+#include <openssl/bn.h>
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+#include "xmalloc.h"
|
|
|
8f2528 |
+#include "buffer.h"
|
|
|
8f2528 |
+#include "key.h"
|
|
|
8f2528 |
+#include "cipher.h"
|
|
|
8f2528 |
+#include "kex.h"
|
|
|
8f2528 |
+#include "packet.h"
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+static int bin_char(unsigned char hex)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ if (48 <= hex && 57 >= hex)
|
|
|
8f2528 |
+ return (hex - 48);
|
|
|
8f2528 |
+ if (65 <= hex && 70 >= hex)
|
|
|
8f2528 |
+ return (hex - 55);
|
|
|
8f2528 |
+ if (97 <= hex && 102 >= hex)
|
|
|
8f2528 |
+ return (hex - 87);
|
|
|
8f2528 |
+ return 0;
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+/*
|
|
|
8f2528 |
+ * Convert hex representation into binary string
|
|
|
8f2528 |
+ * @hex input buffer with hex representation
|
|
|
8f2528 |
+ * @hexlen length of hex
|
|
|
8f2528 |
+ * @bin output buffer with binary data
|
|
|
8f2528 |
+ * @binlen length of already allocated bin buffer (should be at least
|
|
|
8f2528 |
+ * half of hexlen -- if not, only a fraction of hexlen is converted)
|
|
|
8f2528 |
+ */
|
|
|
8f2528 |
+static void hex2bin(const char *hex, size_t hexlen,
|
|
|
8f2528 |
+ unsigned char *bin, size_t binlen)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ size_t i = 0;
|
|
|
8f2528 |
+ size_t chars = (binlen > (hexlen / 2)) ? (hexlen / 2) : binlen;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ for (i = 0; i < chars; i++) {
|
|
|
8f2528 |
+ bin[i] = bin_char(hex[(i*2)]) << 4;
|
|
|
8f2528 |
+ bin[i] |= bin_char(hex[((i*2)+1)]);
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+/*
|
|
|
8f2528 |
+ * Allocate sufficient space for binary representation of hex
|
|
|
8f2528 |
+ * and convert hex into bin
|
|
|
8f2528 |
+ *
|
|
|
8f2528 |
+ * Caller must free bin
|
|
|
8f2528 |
+ * @hex input buffer with hex representation
|
|
|
8f2528 |
+ * @hexlen length of hex
|
|
|
8f2528 |
+ * @bin return value holding the pointer to the newly allocated buffer
|
|
|
8f2528 |
+ * @binlen return value holding the allocated size of bin
|
|
|
8f2528 |
+ *
|
|
|
8f2528 |
+ * return: 0 on success, !0 otherwise
|
|
|
8f2528 |
+ */
|
|
|
8f2528 |
+static int hex2bin_alloc(const char *hex, size_t hexlen,
|
|
|
8f2528 |
+ unsigned char **bin, size_t *binlen)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ unsigned char *out = NULL;
|
|
|
8f2528 |
+ size_t outlen = 0;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ if (!hexlen)
|
|
|
8f2528 |
+ return -EINVAL;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ outlen = (hexlen + 1) / 2;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ out = calloc(1, outlen);
|
|
|
8f2528 |
+ if (!out)
|
|
|
8f2528 |
+ return -errno;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ hex2bin(hex, hexlen, out, outlen);
|
|
|
8f2528 |
+ *bin = out;
|
|
|
8f2528 |
+ *binlen = outlen;
|
|
|
8f2528 |
+ return 0;
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+static char hex_char_map_l[] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
8f2528 |
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
|
|
8f2528 |
+static char hex_char_map_u[] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
8f2528 |
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
|
|
8f2528 |
+static char hex_char(unsigned int bin, int u)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ if (bin < sizeof(hex_char_map_l))
|
|
|
8f2528 |
+ return (u) ? hex_char_map_u[bin] : hex_char_map_l[bin];
|
|
|
8f2528 |
+ return 'X';
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+/*
|
|
|
8f2528 |
+ * Convert binary string into hex representation
|
|
|
8f2528 |
+ * @bin input buffer with binary data
|
|
|
8f2528 |
+ * @binlen length of bin
|
|
|
8f2528 |
+ * @hex output buffer to store hex data
|
|
|
8f2528 |
+ * @hexlen length of already allocated hex buffer (should be at least
|
|
|
8f2528 |
+ * twice binlen -- if not, only a fraction of binlen is converted)
|
|
|
8f2528 |
+ * @u case of hex characters (0=>lower case, 1=>upper case)
|
|
|
8f2528 |
+ */
|
|
|
8f2528 |
+static void bin2hex(const unsigned char *bin, size_t binlen,
|
|
|
8f2528 |
+ char *hex, size_t hexlen, int u)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ size_t i = 0;
|
|
|
8f2528 |
+ size_t chars = (binlen > (hexlen / 2)) ? (hexlen / 2) : binlen;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ for (i = 0; i < chars; i++) {
|
|
|
8f2528 |
+ hex[(i*2)] = hex_char((bin[i] >> 4), u);
|
|
|
8f2528 |
+ hex[((i*2)+1)] = hex_char((bin[i] & 0x0f), u);
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+struct kdf_cavs {
|
|
|
8f2528 |
+ unsigned char *K;
|
|
|
8f2528 |
+ size_t Klen;
|
|
|
8f2528 |
+ unsigned char *H;
|
|
|
8f2528 |
+ size_t Hlen;
|
|
|
8f2528 |
+ unsigned char *session_id;
|
|
|
8f2528 |
+ size_t session_id_len;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ unsigned int iv_len;
|
|
|
8f2528 |
+ unsigned int ek_len;
|
|
|
8f2528 |
+ unsigned int ik_len;
|
|
|
8f2528 |
+};
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+static int sshkdf_cavs(struct kdf_cavs *test)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ int ret = 0;
|
|
|
8f2528 |
+ struct kex kex;
|
|
|
8f2528 |
+ BIGNUM *Kbn = NULL;
|
|
|
8f2528 |
+ int mode = 0;
|
|
|
8f2528 |
+ struct newkeys *ctoskeys;
|
|
|
8f2528 |
+ struct newkeys *stockeys;
|
|
|
8f2528 |
+ struct ssh *ssh = NULL;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+#define HEXOUTLEN 500
|
|
|
8f2528 |
+ char hex[HEXOUTLEN];
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ memset(&kex, 0, sizeof(struct kex));
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ Kbn = BN_new();
|
|
|
8f2528 |
+ BN_bin2bn(test->K, test->Klen, Kbn);
|
|
|
8f2528 |
+ if (!Kbn) {
|
|
|
8f2528 |
+ printf("cannot convert K into BIGNUM\n");
|
|
|
8f2528 |
+ ret = 1;
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ kex.session_id = test->session_id;
|
|
|
8f2528 |
+ kex.session_id_len = test->session_id_len;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* setup kex */
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* select the right hash based on struct ssh_digest digests */
|
|
|
8f2528 |
+ switch (test->ik_len) {
|
|
|
8f2528 |
+ case 20:
|
|
|
8f2528 |
+ kex.hash_alg = 2;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 32:
|
|
|
8f2528 |
+ kex.hash_alg = 3;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 48:
|
|
|
8f2528 |
+ kex.hash_alg = 4;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 64:
|
|
|
8f2528 |
+ kex.hash_alg = 5;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ default:
|
|
|
8f2528 |
+ printf("Wrong hash type %u\n", test->ik_len);
|
|
|
8f2528 |
+ ret = 1;
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* implement choose_enc */
|
|
|
8f2528 |
+ for (mode = 0; mode < 2; mode++) {
|
|
|
8f2528 |
+ kex.newkeys[mode] = calloc(1, sizeof(struct newkeys));
|
|
|
8f2528 |
+ if (!kex.newkeys[mode]) {
|
|
|
8f2528 |
+ printf("allocation of newkeys failed\n");
|
|
|
8f2528 |
+ ret = 1;
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ kex.newkeys[mode]->enc.iv_len = test->iv_len;
|
|
|
8f2528 |
+ kex.newkeys[mode]->enc.key_len = test->ek_len;
|
|
|
8f2528 |
+ kex.newkeys[mode]->enc.block_size = (test->iv_len == 64) ? 8 : 16;
|
|
|
8f2528 |
+ kex.newkeys[mode]->mac.key_len = test->ik_len;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* implement kex_choose_conf */
|
|
|
8f2528 |
+ kex.we_need = kex.newkeys[0]->enc.key_len;
|
|
|
8f2528 |
+ if (kex.we_need < kex.newkeys[0]->enc.block_size)
|
|
|
8f2528 |
+ kex.we_need = kex.newkeys[0]->enc.block_size;
|
|
|
8f2528 |
+ if (kex.we_need < kex.newkeys[0]->enc.iv_len)
|
|
|
8f2528 |
+ kex.we_need = kex.newkeys[0]->enc.iv_len;
|
|
|
8f2528 |
+ if (kex.we_need < kex.newkeys[0]->mac.key_len)
|
|
|
8f2528 |
+ kex.we_need = kex.newkeys[0]->mac.key_len;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* MODE_OUT (1) -> server to client
|
|
|
8f2528 |
+ * MODE_IN (0) -> client to server */
|
|
|
8f2528 |
+ kex.server = 1;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* do it */
|
|
|
8f2528 |
+ if ((ssh = ssh_packet_set_connection(NULL, -1, -1)) == NULL){
|
|
|
8f2528 |
+ printf("Allocation error\n");
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ ssh->kex = &ke;;
|
|
|
8f2528 |
+ kex_derive_keys_bn(ssh, test->H, test->Hlen, Kbn);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ ctoskeys = kex.newkeys[0];
|
|
|
8f2528 |
+ stockeys = kex.newkeys[1];
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ /* get data */
|
|
|
8f2528 |
+ memset(hex, 0, HEXOUTLEN);
|
|
|
8f2528 |
+ bin2hex(ctoskeys->enc.iv, (size_t)ctoskeys->enc.iv_len,
|
|
|
8f2528 |
+ hex, HEXOUTLEN, 0);
|
|
|
8f2528 |
+ printf("Initial IV (client to server) = %s\n", hex);
|
|
|
8f2528 |
+ memset(hex, 0, HEXOUTLEN);
|
|
|
8f2528 |
+ bin2hex(stockeys->enc.iv, (size_t)stockeys->enc.iv_len,
|
|
|
8f2528 |
+ hex, HEXOUTLEN, 0);
|
|
|
8f2528 |
+ printf("Initial IV (server to client) = %s\n", hex);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ memset(hex, 0, HEXOUTLEN);
|
|
|
8f2528 |
+ bin2hex(ctoskeys->enc.key, (size_t)ctoskeys->enc.key_len,
|
|
|
8f2528 |
+ hex, HEXOUTLEN, 0);
|
|
|
8f2528 |
+ printf("Encryption key (client to server) = %s\n", hex);
|
|
|
8f2528 |
+ memset(hex, 0, HEXOUTLEN);
|
|
|
8f2528 |
+ bin2hex(stockeys->enc.key, (size_t)stockeys->enc.key_len,
|
|
|
8f2528 |
+ hex, HEXOUTLEN, 0);
|
|
|
8f2528 |
+ printf("Encryption key (server to client) = %s\n", hex);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ memset(hex, 0, HEXOUTLEN);
|
|
|
8f2528 |
+ bin2hex(ctoskeys->mac.key, (size_t)ctoskeys->mac.key_len,
|
|
|
8f2528 |
+ hex, HEXOUTLEN, 0);
|
|
|
8f2528 |
+ printf("Integrity key (client to server) = %s\n", hex);
|
|
|
8f2528 |
+ memset(hex, 0, HEXOUTLEN);
|
|
|
8f2528 |
+ bin2hex(stockeys->mac.key, (size_t)stockeys->mac.key_len,
|
|
|
8f2528 |
+ hex, HEXOUTLEN, 0);
|
|
|
8f2528 |
+ printf("Integrity key (server to client) = %s\n", hex);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+out:
|
|
|
8f2528 |
+ if (Kbn)
|
|
|
8f2528 |
+ BN_free(Kbn);
|
|
|
8f2528 |
+ if (kex.newkeys[0])
|
|
|
8f2528 |
+ free(kex.newkeys[0]);
|
|
|
8f2528 |
+ if (kex.newkeys[1])
|
|
|
8f2528 |
+ free(kex.newkeys[1]);
|
|
|
8f2528 |
+ if (ssh)
|
|
|
8f2528 |
+ ssh_packet_close(ssh);
|
|
|
8f2528 |
+ return ret;
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+static void usage(void)
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ fprintf(stderr, "\nOpenSSH KDF CAVS Test\n\n");
|
|
|
8f2528 |
+ fprintf(stderr, "Usage:\n");
|
|
|
8f2528 |
+ fprintf(stderr, "\t-K\tShared secret string\n");
|
|
|
8f2528 |
+ fprintf(stderr, "\t-H\tHash string\n");
|
|
|
8f2528 |
+ fprintf(stderr, "\t-s\tSession ID string\n");
|
|
|
8f2528 |
+ fprintf(stderr, "\t-i\tIV length to be generated\n");
|
|
|
8f2528 |
+ fprintf(stderr, "\t-e\tEncryption key length to be generated\n");
|
|
|
8f2528 |
+ fprintf(stderr, "\t-m\tMAC key length to be generated\n");
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+/*
|
|
|
8f2528 |
+ * Test command example:
|
|
|
8f2528 |
+ * ./ssh-cavs -K 0055d50f2d163cc07cd8a93cc7c3430c30ce786b572c01ad29fec7597000cf8618d664e2ec3dcbc8bb7a1a7eb7ef67f61cdaf291625da879186ac0a5cb27af571b59612d6a6e0627344d846271959fda61c78354aa498773d59762f8ca2d0215ec590d8633de921f920d41e47b3de6ab9a3d0869e1c826d0e4adebf8e3fb646a15dea20a410b44e969f4b791ed6a67f13f1b74234004d5fa5e87eff7abc32d49bbdf44d7b0107e8f10609233b7e2b7eff74a4daf25641de7553975dac6ac1e5117df6f6dbaa1c263d23a6c3e5a3d7d49ae8a828c1e333ac3f85fbbf57b5c1a45be45e43a7be1a4707eac779b8285522d1f531fe23f890fd38a004339932b93eda4 -H d3ab91a850febb417a25d892ec48ed5952c7a5de -s d3ab91a850febb417a25d892ec48ed5952c7a5de -i 8 -e 24 -m 20
|
|
|
8f2528 |
+ *
|
|
|
8f2528 |
+ * Initial IV (client to server) = 4bb320d1679dfd3a
|
|
|
8f2528 |
+ * Initial IV (server to client) = 43dea6fdf263a308
|
|
|
8f2528 |
+ * Encryption key (client to server) = 13048cc600b9d3cf9095aa6cf8e2ff9cf1c54ca0520c89ed
|
|
|
8f2528 |
+ * Encryption key (server to client) = 1e483c5134e901aa11fc4e0a524e7ec7b75556148a222bb0
|
|
|
8f2528 |
+ * Integrity key (client to server) = ecef63a092b0dcc585bdc757e01b2740af57d640
|
|
|
8f2528 |
+ * Integrity key (server to client) = 7424b05f3c44a72b4ebd281fb71f9cbe7b64d479
|
|
|
8f2528 |
+ */
|
|
|
8f2528 |
+int main(int argc, char *argv[])
|
|
|
8f2528 |
+{
|
|
|
8f2528 |
+ struct kdf_cavs test;
|
|
|
8f2528 |
+ int ret = 1;
|
|
|
8f2528 |
+ int opt = 0;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ memset(&test, 0, sizeof(struct kdf_cavs));
|
|
|
8f2528 |
+ while((opt = getopt(argc, argv, "K:H:s:i:e:m:")) != -1)
|
|
|
8f2528 |
+ {
|
|
|
8f2528 |
+ size_t len = 0;
|
|
|
8f2528 |
+ switch(opt)
|
|
|
8f2528 |
+ {
|
|
|
8f2528 |
+ /*
|
|
|
8f2528 |
+ * CAVS K is MPINT
|
|
|
8f2528 |
+ * we want a hex (i.e. the caller must ensure the
|
|
|
8f2528 |
+ * following transformations already happened):
|
|
|
8f2528 |
+ * 1. cut off first four bytes
|
|
|
8f2528 |
+ * 2. if most significant bit of value is
|
|
|
8f2528 |
+ * 1, prepend 0 byte
|
|
|
8f2528 |
+ */
|
|
|
8f2528 |
+ case 'K':
|
|
|
8f2528 |
+ len = strlen(optarg);
|
|
|
8f2528 |
+ ret = hex2bin_alloc(optarg, len,
|
|
|
8f2528 |
+ &test.K, &test.Klen);
|
|
|
8f2528 |
+ if (ret)
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 'H':
|
|
|
8f2528 |
+ len = strlen(optarg);
|
|
|
8f2528 |
+ ret = hex2bin_alloc(optarg, len,
|
|
|
8f2528 |
+ &test.H, &test.Hlen);
|
|
|
8f2528 |
+ if (ret)
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 's':
|
|
|
8f2528 |
+ len = strlen(optarg);
|
|
|
8f2528 |
+ ret = hex2bin_alloc(optarg, len,
|
|
|
8f2528 |
+ &test.session_id,
|
|
|
8f2528 |
+ &test.session_id_len);
|
|
|
8f2528 |
+ if (ret)
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 'i':
|
|
|
8f2528 |
+ test.iv_len = strtoul(optarg, NULL, 10);
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 'e':
|
|
|
8f2528 |
+ test.ek_len = strtoul(optarg, NULL, 10);
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ case 'm':
|
|
|
8f2528 |
+ test.ik_len = strtoul(optarg, NULL, 10);
|
|
|
8f2528 |
+ break;
|
|
|
8f2528 |
+ default:
|
|
|
8f2528 |
+ usage();
|
|
|
8f2528 |
+ goto out;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ ret = sshkdf_cavs(&test);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+out:
|
|
|
8f2528 |
+ if (test.session_id)
|
|
|
8f2528 |
+ free(test.session_id);
|
|
|
8f2528 |
+ if (test.K)
|
|
|
8f2528 |
+ free(test.K);
|
|
|
8f2528 |
+ if (test.H)
|
|
|
8f2528 |
+ free(test.H);
|
|
|
8f2528 |
+ return ret;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
diff -up openssh-6.8p1/ssh-cavs_driver.pl.kdf-cavs openssh-6.8p1/ssh-cavs_driver.pl
|
|
|
8f2528 |
--- openssh-6.8p1/ssh-cavs_driver.pl.kdf-cavs 2015-03-18 11:23:46.348049354 +0100
|
|
|
8f2528 |
+++ openssh-6.8p1/ssh-cavs_driver.pl 2015-03-18 11:23:46.348049354 +0100
|
|
|
8f2528 |
@@ -0,0 +1,184 @@
|
|
|
8f2528 |
+#!/usr/bin/env perl
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# CAVS test driver for OpenSSH
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# Copyright (C) 2015, Stephan Mueller <smueller@chronox.de>
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
8f2528 |
+# of this software and associated documentation files (the "Software"), to deal
|
|
|
8f2528 |
+# in the Software without restriction, including without limitation the rights
|
|
|
8f2528 |
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
8f2528 |
+# copies of the Software, and to permit persons to whom the Software is
|
|
|
8f2528 |
+# furnished to do so, subject to the following conditions:
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# The above copyright notice and this permission notice shall be included in
|
|
|
8f2528 |
+# all copies or substantial portions of the Software.
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# NO WARRANTY
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
|
8f2528 |
+# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
|
8f2528 |
+# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
|
8f2528 |
+# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
|
8f2528 |
+# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
8f2528 |
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
|
8f2528 |
+# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
|
8f2528 |
+# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
|
8f2528 |
+# REPAIR OR CORRECTION.
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
|
8f2528 |
+# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
|
8f2528 |
+# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
|
8f2528 |
+# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
|
8f2528 |
+# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
|
8f2528 |
+# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
|
8f2528 |
+# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
|
8f2528 |
+# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
|
8f2528 |
+# POSSIBILITY OF SUCH DAMAGES.
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+use strict;
|
|
|
8f2528 |
+use warnings;
|
|
|
8f2528 |
+use IPC::Open2;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+# Executing a program by feeding STDIN and retrieving
|
|
|
8f2528 |
+# STDOUT
|
|
|
8f2528 |
+# $1: data string to be piped to the app on STDIN
|
|
|
8f2528 |
+# rest: program and args
|
|
|
8f2528 |
+# returns: STDOUT of program as string
|
|
|
8f2528 |
+sub pipe_through_program($@) {
|
|
|
8f2528 |
+ my $in = shift;
|
|
|
8f2528 |
+ my @args = @_;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my ($CO, $CI);
|
|
|
8f2528 |
+ my $pid = open2($CO, $CI, @args);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my $out = "";
|
|
|
8f2528 |
+ my $len = length($in);
|
|
|
8f2528 |
+ my $first = 1;
|
|
|
8f2528 |
+ while (1) {
|
|
|
8f2528 |
+ my $rin = "";
|
|
|
8f2528 |
+ my $win = "";
|
|
|
8f2528 |
+ # Output of prog is FD that we read
|
|
|
8f2528 |
+ vec($rin,fileno($CO),1) = 1;
|
|
|
8f2528 |
+ # Input of prog is FD that we write
|
|
|
8f2528 |
+ # check for $first is needed because we can have NULL input
|
|
|
8f2528 |
+ # that is to be written to the app
|
|
|
8f2528 |
+ if ( $len > 0 || $first) {
|
|
|
8f2528 |
+ (vec($win,fileno($CI),1) = 1);
|
|
|
8f2528 |
+ $first=0;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ # Let us wait for 100ms
|
|
|
8f2528 |
+ my $nfound = select(my $rout=$rin, my $wout=$win, undef, 0.1);
|
|
|
8f2528 |
+ if ( $wout ) {
|
|
|
8f2528 |
+ my $written = syswrite($CI, $in, $len);
|
|
|
8f2528 |
+ die "broken pipe" if !defined $written;
|
|
|
8f2528 |
+ $len -= $written;
|
|
|
8f2528 |
+ substr($in, 0, $written) = "";
|
|
|
8f2528 |
+ if ($len <= 0) {
|
|
|
8f2528 |
+ close $CI or die "broken pipe: $!";
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ if ( $rout ) {
|
|
|
8f2528 |
+ my $tmp_out = "";
|
|
|
8f2528 |
+ my $bytes_read = sysread($CO, $tmp_out, 4096);
|
|
|
8f2528 |
+ $out .= $tmp_out;
|
|
|
8f2528 |
+ last if ($bytes_read == 0);
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ close $CO or die "broken pipe: $!";
|
|
|
8f2528 |
+ waitpid $pid, 0;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ return $out;
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+# Parser of CAVS test vector file
|
|
|
8f2528 |
+# $1: Test vector file
|
|
|
8f2528 |
+# $2: Output file for test results
|
|
|
8f2528 |
+# return: nothing
|
|
|
8f2528 |
+sub parse($$) {
|
|
|
8f2528 |
+ my $infile = shift;
|
|
|
8f2528 |
+ my $outfile = shift;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my $out = "";
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my $K = "";
|
|
|
8f2528 |
+ my $H = "";
|
|
|
8f2528 |
+ my $session_id = "";
|
|
|
8f2528 |
+ my $ivlen = 0;
|
|
|
8f2528 |
+ my $eklen = "";
|
|
|
8f2528 |
+ my $iklen = "";
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ open(IN, "<$infile");
|
|
|
8f2528 |
+ while(<IN>) {
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my $line = $_;
|
|
|
8f2528 |
+ chomp($line);
|
|
|
8f2528 |
+ $line =~ s/\r//;
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ if ($line =~ /\[SHA-1\]/) {
|
|
|
8f2528 |
+ $iklen = 20;
|
|
|
8f2528 |
+ } elsif ($line =~ /\[SHA-256\]/) {
|
|
|
8f2528 |
+ $iklen = 32;
|
|
|
8f2528 |
+ } elsif ($line =~ /\[SHA-384\]/) {
|
|
|
8f2528 |
+ $iklen = 48;
|
|
|
8f2528 |
+ } elsif ($line =~ /\[SHA-512\]/) {
|
|
|
8f2528 |
+ $iklen = 64;
|
|
|
8f2528 |
+ } elsif ($line =~ /^\[IV length\s*=\s*(.*)\]/) {
|
|
|
8f2528 |
+ $ivlen = $1;
|
|
|
8f2528 |
+ $ivlen = $ivlen / 8;
|
|
|
8f2528 |
+ } elsif ($line =~ /^\[encryption key length\s*=\s*(.*)\]/) {
|
|
|
8f2528 |
+ $eklen = $1;
|
|
|
8f2528 |
+ $eklen = $eklen / 8;
|
|
|
8f2528 |
+ } elsif ($line =~ /^K\s*=\s*(.*)/) {
|
|
|
8f2528 |
+ $K = $1;
|
|
|
8f2528 |
+ $K = substr($K, 8);
|
|
|
8f2528 |
+ $K = "00" . $K;
|
|
|
8f2528 |
+ } elsif ($line =~ /^H\s*=\s*(.*)/) {
|
|
|
8f2528 |
+ $H = $1;
|
|
|
8f2528 |
+ } elsif ($line =~ /^session_id\s*=\s*(.*)/) {
|
|
|
8f2528 |
+ $session_id = $1;
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ $out .= $line . "\n";
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ if ($K ne "" && $H ne "" && $session_id ne "" &&
|
|
|
8f2528 |
+ $ivlen ne "" && $eklen ne "" && $iklen > 0) {
|
|
|
8f2528 |
+ $out .= pipe_through_program("", "./ssh-cavs -H $H -K $K -s $session_id -i $ivlen -e $eklen -m $iklen");
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ $K = "";
|
|
|
8f2528 |
+ $H = "";
|
|
|
8f2528 |
+ $session_id = "";
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ close IN;
|
|
|
8f2528 |
+ $out =~ s/\n/\r\n/g; # make it a dos file
|
|
|
8f2528 |
+ open(OUT, ">$outfile") or die "Cannot create output file $outfile: $?";
|
|
|
8f2528 |
+ print OUT $out;
|
|
|
8f2528 |
+ close OUT;
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+############################################################
|
|
|
8f2528 |
+#
|
|
|
8f2528 |
+# let us pretend to be C :-)
|
|
|
8f2528 |
+sub main() {
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my $infile=$ARGV[0];
|
|
|
8f2528 |
+ die "Error: Test vector file $infile not found" if (! -f $infile);
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ my $outfile = $infile;
|
|
|
8f2528 |
+ # let us add .rsp regardless whether we could strip .req
|
|
|
8f2528 |
+ $outfile =~ s/\.req$//;
|
|
|
8f2528 |
+ $outfile .= ".rsp";
|
|
|
8f2528 |
+ if (-f $outfile) {
|
|
|
8f2528 |
+ die "Output file $outfile could not be removed: $?"
|
|
|
8f2528 |
+ unless unlink($outfile);
|
|
|
8f2528 |
+ }
|
|
|
8f2528 |
+ print STDERR "Performing tests from source file $infile with results stored in destination file $outfile\n";
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+ # Do the job
|
|
|
8f2528 |
+ parse($infile, $outfile);
|
|
|
8f2528 |
+}
|
|
|
8f2528 |
+
|
|
|
8f2528 |
+###########################################
|
|
|
8f2528 |
+# Call it
|
|
|
8f2528 |
+main();
|
|
|
8f2528 |
+1;
|