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