Skip to content
Browse files

mem struct are ctypes-ed for ssh

  • Loading branch information...
1 parent 749a895 commit bb040003fd5308438222295d55b5826cb1f6be4f @trolldbois committed Mar 6, 2011
Showing with 867 additions and 39 deletions.
  1. +98 −12 README
  2. +7 −2 model.py
  3. +126 −25 opensshmodel.py
  4. +346 −0 ssh-types.c
  5. +12 −0 test/dsa.orig
  6. +1 −0 test/dsa.orig.pub
  7. +12 −0 test/id_dsa-1.key
  8. +203 −0 test/ssh/ssh.log
  9. +31 −0 test/ssh/types.c.log
  10. +31 −0 test/ssh/types.py.log
View
110 README
@@ -25,17 +25,103 @@ https://bitbucket.org/haypo/python-ptrace/wiki/Documentation
from ptrace.debugger.memory_mapping import readProcessMappings
+abouchet.py is passe-partout.py - OK - 04/03/2011
+
+next ssh :
+Keys are cleaned from memory (ssh.c:830) after ssh_login (ssh_connect.c:1097).
+
+ssh_login:
+--------------
+keys are read
+Key exchange is initiated (ssh_connect.c:1121) ssh_kex2 (ssh_connect2.c:105)
+-> session_id2 is created
+ssh_userauth2 is initiated (ssh_connect.c:1122) (ssh_connect2.c:360)
+end
+
+ssh_userauth2:
+--------------
+client ask server for AUTH (ssh_connect2.c:370)
+server says ok, go on (ssh_connect2.c:372)
+client use dispatch_run to get password or passphrase (ssh_connect2.c:414)
+
+in packet.c, struct session_state is the struct we want to target.
+there is
+ packet.c:197:static struct session_state *active_state, *backup_state;
+and defautl allocation never changed after that:
+ packet.c:206:s->max_packet_size = 32768;
+
+ssh_userauth2:
+--------------
+packet_start // use active_state
+packet_put_cstring("ssh-userauth"); // memcpy
+packet_send(); //// packet_send2 packet.c:960
+debug("SSH2_MSG_SERVICE_REQUEST sent");
+packet_write_wait(); -> packet goes out
+type = packet_read();
+[..]
+packet_check_eom()
+[..]
+pubkey_prepare(&authctxt);
+userauth_none(&authctxt);
+[..]
+dispatch_init(&input_userauth_error);
+dispatch_set(SSH2_MSG_USERAUTH_SUCCESS, &input_userauth_success);
+dispatch_set(SSH2_MSG_USERAUTH_FAILURE, &input_userauth_failure);
+dispatch_set(SSH2_MSG_USERAUTH_BANNER, &input_userauth_banner);
+dispatch_run(DISPATCH_BLOCK, &authctxt.success, &authctxt); /* loop until success */
+[..]
+pubkey_cleanup(&authctxt);
+dispatch_range(SSH2_MSG_USERAUTH_MIN, SSH2_MSG_USERAUTH_MAX, NULL);
+
+
+packet_send(2) packet.c:960
+------------
+if active_state->rekeying , alors, rien ne sort si ce n'est les SSH2_KEX_INIT
+sending is done by packet.c:839:packet_send2_wrapped(void)
+
+packet.c:839:packet_send2_wrapped(void)
+-----------------------------------------
+Encryption, Mac and Compression are done regarding to active_state->newkeys[MODE_OUT]->* values
+MODE_OUT ( enum == 1 je crois)
+active_state->outgoing_packet is compressed if required ( packet.c:866 )
+padding/random is added if necessary (packet.c:889)
+then MAC is calculated (packet.c:924)
+then buffer is encrypted with
+ cipher_crypt(&active_state->send_context, cp, (packet.c:933) ->OpenSSL EVP_Cipher
+MAC is appended unencrypted
+finally session is updated with seqnum++ and stuff like that
+and set_newkeys is called if it's was a rekey command
+[ packet is reading in active_state->output and will be sent by subsequent packet_write_wait]
+
+
+packet.c:728:set_newkeys
+------------------------
+cipher_cleanup -> call OpenSSL cipher_cleanup
+mac_clear() ->
+free data struct for enc, mac and comp ( IV & key )
+kex.c:538:kex_get_newkeys(int mode) -> use prepared memory current_keys[mode] struct (NULLs the pointer for reprocessiong)
+cipher_init
+set &active_state->max_blocks_out
+
+WHERE ARE THE KEY:
+-----------------
+&active_state->newkeys[mode]->enc
+enc->name
+enc->key
+enc->iv
+
+and they must be in OpenSSL format... EVP in CypherContext struct
+
+HOW TO READ:
+------------
+packet.c:1139
+ /* Decrypt data to incoming_packet. */
+ buffer_clear(&active_state->incoming_packet);
+ cp = buffer_append_space(&active_state->incoming_packet, padded_len);
+ cipher_crypt(&active_state->receive_context, cp,
+ buffer_ptr(&active_state->input), padded_len);
+
+
+
-dbg_init(
-dbg_attach
-if (from) {
- if ( dbg_get_memory(&p) )
- err(&p, "unable to fetch memory for process %d", pid);
- map = dbg_map_lookup_by_address(&p, from, &off_start);
- if (!map)
- err(&p, "0x%lx not mapped into process %i", from, pid);
- if (to) {
- map2 = dbg_map_lookup_by_address(&p, to, &off_end);
-
-dbg_map_cache
View
9 model.py
@@ -16,6 +16,7 @@
''' evp.h:91 '''
EVP_MAX_BLOCK_LENGTH=32
EVP_MAX_IV_LENGTH=16
+AES_MAXNR=14 # aes.h:66
''' returns if the address of the struct is in the mapping area
'''
@@ -426,8 +427,12 @@ class HMAC_CTX(ctypes.Structure):
("key", ctypes.c_char * HMAC_MAX_MD_CBLOCK)
]
-
-
+class AES_KEY(ctypes.Structure):
+ ''' aes.h:78 '''
+ _fields_ = [
+ ("rd_key", ctypes.c_ulong * 4 * (AES_MAXNR+1)),
+ ("rounds", ctypes.c_int)
+ ]
View
151 opensshmodel.py
@@ -12,10 +12,22 @@
log=logging.getLogger('openssh.model')
from model import is_valid_address,getaddress,sstr
-from model import EVP_CIPHER_CTX, EVP_MD, HMAC_CTX
+from model import EVP_CIPHER_CTX, EVP_MD, HMAC_CTX, AES_KEY
+
+MODE_MAX=2 #kex.h:62
+AES_BLOCK_LEN=16 #umac.c:168
+L1_KEY_LEN=1024 #umac.c:298
+L1_KEY_SHIFT=16 #umac.c:316
+UMAC_OUTPUT_LEN=8 #umac.c:55
+STREAMS=(UMAC_OUTPUT_LEN / 4) #umac.c:310
+HASH_BUF_BYTES=64 # umac.c:315
+SSH_SESSION_KEY_LENGTH=32 # ssh.h:84
+
+''' typedefs '''
+UINT64=ctypes.c_ulonglong
+UINT32=ctypes.c_ulong
+UINT8=ctypes.c_ubyte
-''' kex.h:62 '''
-MODE_MAX=2
class Cipher(ctypes.Structure):
''' cipher.c:60 '''
@@ -45,21 +57,48 @@ class Enc(ctypes.Structure):
("enabled", ctypes.c_int),
("key_len", ctypes.c_uint),
("block_size", ctypes.c_uint),
- ("key", ctypes.c_char_p), #u_char ?
+ ("key", ctypes.c_char_p), #u_char ? -> ctypes.c_byte_p ?
("iv", ctypes.c_char_p)
]
+class nh_ctx(ctypes.Structure):
+ ''' umac.c:323 '''
+ _fields_ = [
+ ("nh_key", UINT8 *(L1_KEY_LEN + L1_KEY_SHIFT * (STREAMS - 1)) ),
+ ("data", UINT8 * HASH_BUF_BYTES),
+ ("next_data_empty", ctypes.c_int),
+ ("bytes_hashed", ctypes.c_int),
+ ("state", UINT64 * STREAMS)
+ ]
+
+class uhash_ctx(ctypes.Structure):
+ ''' umac.c:772 '''
+ _fields_ = [
+ ("hash", nh_ctx),
+ ("poly_key_8", UINT64 * STREAMS),
+ ("poly_accum", UINT64 * STREAMS),
+ ("ip_keys", UINT64 * STREAMS * 4),
+ ("ip_trans", UINT32 * STREAMS),
+ ("msg_len", UINT32)
+ ]
+
+#AES_KEY
+class pdf_ctx(ctypes.Structure):
+ ''' umac:221 '''
+ _fields_ = [
+ ("cache", UINT8 * AES_BLOCK_LEN), #UINT8
+ ("nonce", UINT8 * AES_BLOCK_LEN), #UINT8
+ ("prf_key", AES_KEY * 1) #typedef AES_KEY aes_int_key[1];
+ ]
class umac_ctx(ctypes.Structure):
''' umac:1179 '''
- uhash_ctx hash; /* Hash function for message compression */
- pdf_ctx pdf; /* PDF for hashed output */
- void *free_ptr; /* Address to free this struct via */
-} umac_ctx;
-
-#EVP_MD k
-# HMAC_CTX
-#struct umac_ctx *
+ _fields_ = [
+ ("hash", uhash_ctx),
+ ("pdf", pdf_ctx),
+ ("free_ptr", ctypes.c_void_p)
+ ]
+
class Mac(ctypes.Structure):
''' kex.h:90 '''
_fields_ = [
@@ -71,7 +110,7 @@ class Mac(ctypes.Structure):
("type", ctypes.c_int),
("evp_md", ctypes.POINTER(EVP_MD)),
("evp_ctx", HMAC_CTX),
- ("umac_ctx", ctypes.POINTER(umac_ctx)) #struct umac_ctx
+ ("umac_ctx", ctypes.POINTER(umac_ctx))
]
class Comp(ctypes.Structure):
@@ -99,7 +138,41 @@ class Buffer(ctypes.Structure):
("end", ctypes.c_uint)
]
-NewkeysModeMax=Newkeys*MODE_MAX
+
+class packet_state(ctypes.Structure):
+ ''' packet.c:90 '''
+ _fields_ = [
+ ("seqnr", UINT32 ),
+ ("packets", UINT32 ),
+ ("blocks", UINT64 ),
+ ("bytes", UINT64 )
+ ]
+
+class packet(ctypes.Structure):
+ pass
+
+
+class TAILQ_HEAD_PACKET(ctypes.Structure):
+ ''' sys/queue.h:382 '''
+ _fields_ = [
+ ("tqh_first", ctypes.POINTER(packet) ),
+ ("tqh_last", ctypes.POINTER(ctypes.POINTER(packet)) )
+ ]
+
+class TAILQ_ENTRY_PACKET(ctypes.Structure):
+ ''' sys/queue.h:382 '''
+ _fields_ = [
+ ("tqe_next", ctypes.POINTER(packet) ),
+ ("tqe_prev", ctypes.POINTER(ctypes.POINTER(packet)) )
+ ]
+
+class packet(ctypes.Structure):
+ ''' packet.c:90 '''
+ _fields_ = [
+ ("next", TAILQ_ENTRY_PACKET),
+ ("type", ctypes.c_ubyte ), #u_char
+ ("payload", Buffer )
+ ]
class session_state(ctypes.Structure):
''' openssh/packet.c:103 '''
@@ -126,29 +199,57 @@ class session_state(ctypes.Structure):
("newkeys", ctypes.POINTER(Newkeys)*MODE_MAX ), #Newkeys *newkeys[MODE_MAX]; XXX
("p_read", packet_state ),
("p_send", packet_state ),
- ("max_blocks_in", ctypes.c_uint64 ), ## u_int64?
- ("max_blocks_out", ctypes.c_uint64 ), ## u_int64?
- ("rekey_limit", ctypes.c_uint32 ), ## u_int32?
- ("ssh1_key", ctypes.c_char ), # u_char ssh1_key[SSH_SESSION_KEY_LENGTH];
+ ("max_blocks_in", UINT64 ),
+ ("max_blocks_out", UINT64 ),
+ ("rekey_limit", UINT32 ),
+ ("ssh1_key", ctypes.c_char * SSH_SESSION_KEY_LENGTH ), # u_char ssh1_key[SSH_SESSION_KEY_LENGTH];
("ssh1_keylen", ctypes.c_uint ),
- ("extra_pad", ctypes.c_char ), #u_char
+ ("extra_pad", ctypes.c_char ),
("packet_discard", ctypes.c_uint ),
("packet_discard_mac", ctypes.POINTER(Mac) ),
("packlen", ctypes.c_uint ),
("rekeying", ctypes.c_int ),
("set_interactive_called", ctypes.c_int ),
("set_maxsize_called", ctypes.c_int ),
- ("outgoing", TAILQ_HEAD ) # TAILQ_HEAD(, packet) outgoing;
+ ("outgoing", TAILQ_HEAD_PACKET )
]
-
-
-
-
-
+def test():
+ print 'session_state:',ctypes.sizeof(session_state)
+ print 'Buffer:',ctypes.sizeof(Buffer)
+ print 'CipherContext:',ctypes.sizeof(CipherContext)
+ print 'Newkeys:',ctypes.sizeof(Newkeys)
+ print 'Mac:',ctypes.sizeof(Mac)
+ print 'Cipher:',ctypes.sizeof(Cipher)
+ print 'Comp:',ctypes.sizeof(Comp)
+ print 'EVP_CIPHER_CTX:',ctypes.sizeof(EVP_CIPHER_CTX)
+ print 'EVP_MD:',ctypes.sizeof(EVP_MD)
+ print 'Enc:',ctypes.sizeof(Enc)
+ print 'nh_ctx:',ctypes.sizeof(nh_ctx)
+ print 'packet:',ctypes.sizeof(packet)
+ print 'packet_state:',ctypes.sizeof(packet_state)
+ print 'pdf_ctx:',ctypes.sizeof(pdf_ctx)
+ print 'AES_KEY:',ctypes.sizeof(AES_KEY)
+ print 'uhash_ctx:',ctypes.sizeof(uhash_ctx)
+ print 'umac_ctx:',ctypes.sizeof(umac_ctx)
+ print 'HMAC_CTX:',ctypes.sizeof(HMAC_CTX)
+ print 'TAILQ_ENTRY_PACKET:',ctypes.sizeof(TAILQ_ENTRY_PACKET)
+ print 'TAILQ_HEAD_PACKET:',ctypes.sizeof(TAILQ_HEAD_PACKET)
+ print 'UINT32:',ctypes.sizeof(UINT32)
+ print 'UINT64:',ctypes.sizeof(UINT64)
+ print 'UINT8:',ctypes.sizeof(UINT8)
+ print 'AES_BLOCK_LEN:',AES_BLOCK_LEN
+ print 'HASH_BUF_BYTES:',HASH_BUF_BYTES
+ print 'UMAC_OUTPUT_LEN:',UMAC_OUTPUT_LEN
+ print 'SSH_SESSION_KEY_LENGTH:',SSH_SESSION_KEY_LENGTH
+ print 'L1_KEY_LEN:',L1_KEY_SHIFT
+ print 'L1_KEY_SHIFT:',L1_KEY_SHIFT
+ print 'MODE_MAX:',MODE_MAX
+ print 'STREAMS:',STREAMS
+test()
View
346 ssh-types.c
@@ -0,0 +1,346 @@
+/* $OpenBSD: packet.c,v 1.166 2009/06/27 09:29:06 andreas Exp $ */
+/*
+ * Author: Tatu Ylonen <ylo@cs.hut.fi>
+ * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
+ * All rights reserved
+ * This file contains code implementing the packet protocol and communication
+ * with the other side. This same code is used both on client and server side.
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose. Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ *
+ *
+ * SSH2 packet format added by Markus Friedl.
+ * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS"" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "includes.h"
+
+#include <sys/types.h>
+#include "openbsd-compat/sys-queue.h"
+#include <sys/param.h>
+#include <sys/socket.h>
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include "xmalloc.h"
+#include "buffer.h"
+#include "packet.h"
+#include "crc32.h"
+#include "compress.h"
+#include "deattack.h"
+#include "channels.h"
+#include "compat.h"
+#include "ssh1.h"
+#include "ssh2.h"
+#include "cipher.h"
+#include "key.h"
+#include "kex.h"
+#include "mac.h"
+#include "log.h"
+#include "canohost.h"
+#include "misc.h"
+#include "ssh.h"
+#include "roaming.h"
+
+#ifdef PACKET_DEBUG
+#define DBG(x) x
+#else
+#define DBG(x)
+#endif
+
+#define PACKET_MAX_SIZE (256 * 1024)
+
+struct packet_state {
+ u_int32_t seqnr;
+ u_int32_t packets;
+ u_int64_t blocks;
+ u_int64_t bytes;
+};
+
+struct packet {
+ TAILQ_ENTRY(packet) next;
+ u_char type;
+ Buffer payload;
+};
+
+struct session_state {
+ /*
+ * This variable contains the file descriptors used for
+ * communicating with the other side. connection_in is used for
+ * reading; connection_out for writing. These can be the same
+ * descriptor, in which case it is assumed to be a socket.
+ */
+ int connection_in;
+ int connection_out;
+
+ /* Protocol flags for the remote side. */
+ u_int remote_protocol_flags;
+
+ /* Encryption context for receiving data. Only used for decryption. */
+ CipherContext receive_context;
+
+ /* Encryption context for sending data. Only used for encryption. */
+ CipherContext send_context;
+
+ /* Buffer for raw input data from the socket. */
+ Buffer input;
+
+ /* Buffer for raw output data going to the socket. */
+ Buffer output;
+
+ /* Buffer for the partial outgoing packet being constructed. */
+ Buffer outgoing_packet;
+
+ /* Buffer for the incoming packet currently being processed. */
+ Buffer incoming_packet;
+
+ /* Scratch buffer for packet compression/decompression. */
+ Buffer compression_buffer;
+ int compression_buffer_ready;
+
+ /*
+ * Flag indicating whether packet compression/decompression is
+ * enabled.
+ */
+ int packet_compression;
+
+ /* default maximum packet size */
+ u_int max_packet_size;
+
+ /* Flag indicating whether this module has been initialized. */
+ int initialized;
+
+ /* Set to true if the connection is interactive. */
+ int interactive_mode;
+
+ /* Set to true if we are the server side. */
+ int server_side;
+
+ /* Set to true if we are authenticated. */
+ int after_authentication;
+
+ int keep_alive_timeouts;
+
+ /* The maximum time that we will wait to send or receive a packet */
+ int packet_timeout_ms;
+
+ /* Session key information for Encryption and MAC */
+ Newkeys *newkeys[MODE_MAX];
+ struct packet_state p_read, p_send;
+
+ u_int64_t max_blocks_in, max_blocks_out;
+ u_int32_t rekey_limit;
+
+ /* Session key for protocol v1 */
+ u_char ssh1_key[SSH_SESSION_KEY_LENGTH];
+ u_int ssh1_keylen;
+
+ /* roundup current message to extra_pad bytes */
+ u_char extra_pad;
+
+ /* XXX discard incoming data after MAC error */
+ u_int packet_discard;
+ Mac *packet_discard_mac;
+
+ /* Used in packet_read_poll2() */
+ u_int packlen;
+
+ /* Used in packet_send2 */
+ int rekeying;
+
+ /* Used in packet_set_interactive */
+ int set_interactive_called;
+
+ /* Used in packet_set_maxsize */
+ int set_maxsize_called;
+
+ TAILQ_HEAD(, packet) outgoing;
+};
+
+static struct session_state *active_state, *backup_state;
+
+static struct session_state *
+alloc_session_state(void)
+{
+ struct session_state *s = xcalloc(1, sizeof(*s));
+
+ s->connection_in = -1;
+ s->connection_out = -1;
+ s->max_packet_size = 32768;
+ s->packet_timeout_ms = -1;
+ return s;
+}
+#include "includes.h"
+
+#include <sys/types.h>
+
+#include <openssl/md5.h>
+
+#include <string.h>
+#include <stdarg.h>
+
+#include "xmalloc.h"
+#include "log.h"
+#include "cipher.h"
+
+/* compatibility with old or broken OpenSSL versions */
+#include "openbsd-compat/openssl-compat.h"
+
+
+struct Cipher {
+ char *name;
+ int number; /* for ssh1 only */
+ u_int block_size;
+ u_int key_len;
+ u_int discard_len;
+ u_int cbc_mode;
+ const EVP_CIPHER *(*evptype)(void);
+};
+
+/** umac */
+
+typedef u_int8_t UINT8; /* 1 byte */
+typedef u_int16_t UINT16; /* 2 byte */
+typedef u_int32_t UINT32; /* 4 byte */
+typedef u_int64_t UINT64; /* 8 bytes */
+typedef unsigned int UWORD; /* Register */
+
+#define AES_BLOCK_LEN 16
+#define UMAC_OUTPUT_LEN 8 /* Alowable: 4, 8, 12, 16 */
+
+/* OpenSSL's AES */
+//#include "openbsd-compat/openssl-compat.h"
+//#ifndef USE_BUILTIN_RIJNDAEL
+# include <openssl/aes.h>
+//#endif
+typedef AES_KEY aes_int_key[1];
+
+//#include <aes/aes.h>
+
+typedef struct pdf_ctx {
+ UINT8 cache[AES_BLOCK_LEN]; /* Previous AES output is saved */
+ UINT8 nonce[AES_BLOCK_LEN]; /* The AES input making above cache */
+ aes_int_key prf_key; /* Expanded AES key for PDF */
+} pdf_ctx;
+
+
+#define STREAMS (UMAC_OUTPUT_LEN / 4) /* Number of times hash is applied */
+#define L1_KEY_LEN 1024 /* Internal key bytes */
+#define L1_KEY_SHIFT 16 /* Toeplitz key shift between streams */
+#define L1_PAD_BOUNDARY 32 /* pad message to boundary multiple */
+#define ALLOC_BOUNDARY 16 /* Keep buffers aligned to this */
+#define HASH_BUF_BYTES 64 /* nh_aux_hb buffer multiple */
+
+typedef struct nh_ctx{
+ UINT8 nh_key [L1_KEY_LEN + L1_KEY_SHIFT * (STREAMS - 1)]; /* NH Key */
+ UINT8 data [HASH_BUF_BYTES]; /* Incomming data buffer */
+ int next_data_empty; /* Bookeeping variable for data buffer. */
+ int bytes_hashed; /* Bytes (out of L1_KEY_LEN) incorperated. */
+ UINT64 state[STREAMS]; /* on-line state */
+} nh_ctx;
+
+typedef struct uhash_ctx {
+ nh_ctx hash; /* Hash context for L1 NH hash */
+ UINT64 poly_key_8[STREAMS]; /* p64 poly keys */
+ UINT64 poly_accum[STREAMS]; /* poly hash result */
+ UINT64 ip_keys[STREAMS*4]; /* Inner-product keys */
+ UINT32 ip_trans[STREAMS]; /* Inner-product translation */
+ UINT32 msg_len; /* Total length of data passed */
+ /* to uhash */
+} uhash_ctx;
+
+
+typedef struct umac_ctx {
+ uhash_ctx hash; /* Hash function for message compression */
+ pdf_ctx pdf; /* PDF for hashed output */
+ void *free_ptr; /* Address to free this struct via */
+} umac_ctx;
+
+
+
+
+
+
+
+/**
+gcc -g -O2 -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wno-pointer-sign -Wformat-security -fno-strict-aliasing -fno-builtin-memset -fstack-protector-all -Os -DSSH_EXTRAVERSION=\"Debian-4ubuntu5\" -I. -I.. -DSSHDIR=\"/etc/ssh\" -D_PATH_SSH_PROGRAM=\"/usr/bin/ssh\" -D_PATH_SSH_ASKPASS_DEFAULT=\"/usr/bin/ssh-askpass\" -D_PATH_SFTP_SERVER=\"/usr/lib/openssh/sftp-server\" -D_PATH_SSH_KEY_SIGN=\"/usr/lib/openssh/ssh-keysign\" -D_PATH_SSH_PKCS11_HELPER=\"/usr/lib/openssh/ssh-pkcs11-helper\" -D_PATH_SSH_PIDDIR=\"/var/run\" -D_PATH_PRIVSEP_CHROOT_DIR=\"/var/run/sshd\" -DSSH_RAND_HELPER=\"/usr/lib/openssh/ssh-rand-helper\" -D_PATH_SSH_DATADIR=\"/usr/share/ssh\" -DHAVE_CONFIG_H -I build-deb/ test.c -o test
+
+*/
+
+#define MAX_PACKETS (1U<<31)
+
+int main(){
+
+ printf("session_state: %d\n",sizeof(struct session_state));
+ printf("Buffer: %d\n",sizeof(Buffer));
+ printf("CipherContext: %d\n",sizeof(CipherContext));
+ printf("Newkeys: %d\n",sizeof(Newkeys));
+ printf("Mac: %d\n",sizeof(Mac));
+ printf("Cipher: %d\n",sizeof(Cipher));
+ printf("Comp: %d\n",sizeof(Comp));
+ printf("EVP_CIPHER_CTX: %d\n",sizeof(EVP_CIPHER_CTX));
+ printf("EVP_MD: %d\n",sizeof(EVP_MD));
+ printf("Enc: %d\n",sizeof(Enc));
+ printf("nh_ctx: %d\n",sizeof(struct nh_ctx));
+ printf("packet: %d\n",sizeof(struct packet));
+ printf("packet_state: %d\n",sizeof(struct packet_state));
+ printf("pdf_ctx: %d\n",sizeof(struct pdf_ctx));
+ printf("AES_KEY: %d\n",sizeof(AES_KEY));
+ printf("uhash_ctx: %d\n",sizeof(struct uhash_ctx));
+ printf("umac_ctx: %d\n",sizeof(struct umac_ctx));
+ printf("HMAC_CTX: %d\n",sizeof(HMAC_CTX));
+ printf("TAILQ_ENTRY_PACKET: %d\n",sizeof(TAILQ_ENTRY(packet)));
+ printf("TAILQ_HEAD_PACKET: %d\n",sizeof(TAILQ_HEAD(,packet)));
+ printf("UINT32: %d\n",sizeof(UINT32));
+ printf("UINT64: %d\n",sizeof(UINT64));
+ printf("UINT8: %d\n",sizeof(UINT8));
+ printf("AES_BLOCK_LEN: %d\n",AES_BLOCK_LEN);
+ printf("HASH_BUF_BYTES: %d\n",HASH_BUF_BYTES);
+ printf("UMAC_OUTPUT_LEN: %d\n",UMAC_OUTPUT_LEN);
+ printf("SSH_SESSION_KEY_LENGTH: %d\n",SSH_SESSION_KEY_LENGTH);
+ printf("L1_KEY_LEN: %d\n",L1_KEY_SHIFT);
+ printf("L1_KEY_SHIFT: %d\n",L1_KEY_SHIFT);
+ printf("MODE_MAX: %d\n",MODE_MAX);
+ printf("STREAMS: %d\n",STREAMS);
+
+}
+
+
+
View
12 test/dsa.orig
@@ -0,0 +1,12 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBvAIBAAKBgQCb324iVmFLE+r3Jxk95ubtB4hYYa7quGawwYEqhyxmM0BqkBEp
+epv2RBNY+put0SbIw7RXP/onrAXNCFBs5JCwRkbb+q9tEdBvGaCl7ZkXB41VHs4N
+3w6NMZ3CW1FBDmR/5lEjd/hWLyKRnYhjBXIix3TGldDK3+x/uds7IJ47GwIVAOAx
+gol7ZRCr1dqdcSyhkAzRT+OhAoGBAIwvNhh+vIxEze+F/7/tBHmZ8V2EYZENEuQI
+3UORP1DhpwH530niJKCuLVqfbPoQr42Go+hZvQwd7wezAoa6WZLYlsQy/T9UTmxF
+EYrMk3b8vEIaGA9eDmj1VdWkq6LtJ1w/XxXsYfleWl8vhKg+rINUQXPwgIeJNgQd
+Cn+TuGq+AoGAS+m7idWUbgj2yTsQRM/SEKi7ADaeHYq2wOhN977ogSTl/OpTX6nG
+24Q+fe0FHh9FkjS/Yb9snHjFmT4IAz6bQVfPwvrjavwcgjUlA76bY93DwK1TXFvq
+a2PRrmMarWUpJMCQmvgoiWn3vOOM6N9OWDqYOawqhkL7RHYduB28QpgCFQCi1BL/
+aW5vEe6hZEtFW3oCrjjpzw==
+-----END DSA PRIVATE KEY-----
View
1 test/dsa.orig.pub
@@ -0,0 +1 @@
+ssh-dss AAAAB3NzaC1kc3MAAACBAJvfbiJWYUsT6vcnGT3m5u0HiFhhruq4ZrDBgSqHLGYzQGqQESl6m/ZEE1j6m63RJsjDtFc/+iesBc0IUGzkkLBGRtv6r20R0G8ZoKXtmRcHjVUezg3fDo0xncJbUUEOZH/mUSN3+FYvIpGdiGMFciLHdMaV0Mrf7H+52zsgnjsbAAAAFQDgMYKJe2UQq9XanXEsoZAM0U/joQAAAIEAjC82GH68jETN74X/v+0EeZnxXYRhkQ0S5AjdQ5E/UOGnAfnfSeIkoK4tWp9s+hCvjYaj6Fm9DB3vB7MChrpZktiWxDL9P1RObEURisyTdvy8QhoYD14OaPVV1aSrou0nXD9fFexh+V5aXy+EqD6sg1RBc/CAh4k2BB0Kf5O4ar4AAACAS+m7idWUbgj2yTsQRM/SEKi7ADaeHYq2wOhN977ogSTl/OpTX6nG24Q+fe0FHh9FkjS/Yb9snHjFmT4IAz6bQVfPwvrjavwcgjUlA76bY93DwK1TXFvqa2PRrmMarWUpJMCQmvgoiWn3vOOM6N9OWDqYOawqhkL7RHYduB28Qpg= jal@skippy
View
12 test/id_dsa-1.key
@@ -0,0 +1,12 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBvAIBAAKBgQCb324iVmFLE+r3Jxk95ubtB4hYYa7quGawwYEqhyxmM0BqkBEp
+epv2RBNY+put0SbIw7RXP/onrAXNCFBs5JCwRkbb+q9tEdBvGaCl7ZkXB41VHs4N
+3w6NMZ3CW1FBDmR/5lEjd/hWLyKRnYhjBXIix3TGldDK3+x/uds7IJ47GwIVAOAx
+gol7ZRCr1dqdcSyhkAzRT+OhAoGBAIwvNhh+vIxEze+F/7/tBHmZ8V2EYZENEuQI
+3UORP1DhpwH530niJKCuLVqfbPoQr42Go+hZvQwd7wezAoa6WZLYlsQy/T9UTmxF
+EYrMk3b8vEIaGA9eDmj1VdWkq6LtJ1w/XxXsYfleWl8vhKg+rINUQXPwgIeJNgQd
+Cn+TuGq+AoGAS+m7idWUbgj2yTsQRM/SEKi7ADaeHYq2wOhN977ogSTl/OpTX6nG
+24Q+fe0FHh9FkjS/Yb9snHjFmT4IAz6bQVfPwvrjavwcgjUlA76bY93DwK1TXFvq
+a2PRrmMarWUpJMCQmvgoiWn3vOOM6N9OWDqYOawqhkL7RHYduB28QpgCFQCi1BL/
+aW5vEe6hZEtFW3oCrjjpzw==
+-----END DSA PRIVATE KEY-----
View
203 test/ssh/ssh.log
@@ -0,0 +1,203 @@
+OpenSSH_5.5p1 Debian-4ubuntu5, OpenSSL 0.9.8o 01 Jun 2010
+debug1: Reading configuration data /etc/ssh/ssh_config
+debug1: Applying options for *
+debug2: ssh_connect: needpriv 0
+debug1: Connecting to adips.asso.fr [213.186.33.2] port 22.
+debug1: Connection established.
+debug3: Not a RSA1 key file /home/jal/.ssh/id_rsa.
+debug2: key_type_from_name: unknown key type '-----BEGIN'
+debug3: key_read: missing keytype
+debug2: key_type_from_name: unknown key type 'Proc-Type:'
+debug3: key_read: missing keytype
+debug2: key_type_from_name: unknown key type 'DEK-Info:'
+debug3: key_read: missing keytype
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug3: key_read: missing whitespace
+debug2: key_type_from_name: unknown key type '-----END'
+debug3: key_read: missing keytype
+debug1: identity file /home/jal/.ssh/id_rsa type 1
+debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
+debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
+debug1: identity file /home/jal/.ssh/id_rsa-cert type -1
+debug1: identity file /home/jal/.ssh/id_dsa type -1
+debug1: identity file /home/jal/.ssh/id_dsa-cert type -1
+debug1: Remote protocol version 2.0, remote software version OpenSSH_5.6
+debug1: match: OpenSSH_5.6 pat OpenSSH*
+debug1: Enabling compatibility mode for protocol 2.0
+debug1: Local version string SSH-2.0-OpenSSH_5.5p1 Debian-4ubuntu5
+debug2: fd 3 setting O_NONBLOCK
+debug1: SSH2_MSG_KEXINIT sent
+debug1: SSH2_MSG_KEXINIT received
+debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
+debug2: kex_parse_kexinit: ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-rsa,ssh-dss
+debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
+debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
+debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
+debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
+debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
+debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
+debug2: kex_parse_kexinit:
+debug2: kex_parse_kexinit:
+debug2: kex_parse_kexinit: first_kex_follows 0
+debug2: kex_parse_kexinit: reserved 0
+debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
+debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
+debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
+debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
+debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
+debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
+debug2: kex_parse_kexinit: none,zlib@openssh.com
+debug2: kex_parse_kexinit: none,zlib@openssh.com
+debug2: kex_parse_kexinit:
+debug2: kex_parse_kexinit:
+debug2: kex_parse_kexinit: first_kex_follows 0
+debug2: kex_parse_kexinit: reserved 0
+debug2: mac_setup: found hmac-md5
+debug1: kex: server->client aes128-ctr hmac-md5 none
+debug2: mac_setup: found hmac-md5
+debug1: kex: client->server aes128-ctr hmac-md5 none
+debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
+debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
+debug2: dh_gen_key: priv key bits set: 132/256
+debug2: bits set: 517/1024
+debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
+debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
+debug3: check_host_in_hostfile: host adips.asso.fr filename /home/jal/.ssh/known_hosts
+debug3: check_host_in_hostfile: host adips.asso.fr filename /home/jal/.ssh/known_hosts
+debug3: check_host_in_hostfile: match line 18
+debug3: check_host_in_hostfile: host 213.186.33.2 filename /home/jal/.ssh/known_hosts
+debug3: check_host_in_hostfile: host 213.186.33.2 filename /home/jal/.ssh/known_hosts
+debug3: check_host_in_hostfile: match line 19
+debug1: Host 'adips.asso.fr' is known and matches the RSA host key.
+debug1: Found key in /home/jal/.ssh/known_hosts:18
+debug2: bits set: 504/1024
+debug1: ssh_rsa_verify: signature correct
+debug2: kex_derive_keys
+debug2: set_newkeys: mode 1
+debug1: SSH2_MSG_NEWKEYS sent
+debug1: expecting SSH2_MSG_NEWKEYS
+debug2: set_newkeys: mode 0
+debug1: SSH2_MSG_NEWKEYS received
+debug1: Roaming not allowed by server
+debug1: SSH2_MSG_SERVICE_REQUEST sent
+debug2: service_accept: ssh-userauth
+debug1: SSH2_MSG_SERVICE_ACCEPT received
+debug2: key: /home/jal/.ssh/id_rsa (0xb92385f0)
+debug2: key: /home/jal/.ssh/id_rsa (0xb923af20)
+debug2: key: /home/jal/.ssh/id_dsa ((nil))
+debug1: Authentications that can continue: publickey,password,keyboard-interactive
+debug3: start over, passed a different list publickey,password,keyboard-interactive
+debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
+debug3: authmethod_lookup publickey
+debug3: remaining preferred: keyboard-interactive,password
+debug3: authmethod_is_enabled publickey
+debug1: Next authentication method: publickey
+debug1: Offering public key: /home/jal/.ssh/id_rsa
+debug3: send_pubkey_test
+debug2: we sent a publickey packet, wait for reply
+debug1: Server accepts key: pkalg ssh-rsa blen 279
+debug2: input_userauth_pk_ok: fp 70:67:25:79:83:98:81:2d:53:88:82:37:d5:72:eb:60
+debug3: sign_and_send_pubkey
+debug1: Authentication succeeded (publickey).
+debug2: fd 5 setting O_NONBLOCK
+debug3: fd 6 is O_NONBLOCK
+debug1: channel 0: new [client-session]
+debug3: ssh_session2_open: channel_new: 0
+debug2: channel 0: send open
+debug1: Requesting no-more-sessions@openssh.com
+debug1: Entering interactive session.
+debug2: callback start
+debug2: client_session2_setup: id 0
+debug2: channel 0: request pty-req confirm 1
+debug1: Sending environment.
+debug3: Ignored env ORBIT_SOCKETDIR
+debug3: Ignored env SSH_AGENT_PID
+debug3: Ignored env SHELL
+debug3: Ignored env TERM
+debug3: Ignored env XDG_SESSION_COOKIE
+debug3: Ignored env WINDOWID
+debug3: Ignored env GNOME_KEYRING_CONTROL
+debug3: Ignored env GTK_MODULES
+debug3: Ignored env USER
+debug3: Ignored env LS_COLORS
+debug3: Ignored env SSH_AUTH_SOCK
+debug3: Ignored env TERMCAP
+debug3: Ignored env DEFAULTS_PATH
+debug3: Ignored env USERNAME
+debug3: Ignored env SESSION_MANAGER
+debug3: Ignored env XDG_CONFIG_DIRS
+debug3: Ignored env PATH
+debug3: Ignored env DESKTOP_SESSION
+debug3: Ignored env STY
+debug3: Ignored env PWD
+debug3: Ignored env GDM_KEYBOARD_LAYOUT
+debug1: Sending env LANG = en_US.utf8
+debug2: channel 0: request env confirm 0
+debug3: Ignored env GDM_LANG
+debug3: Ignored env MANDATORY_PATH
+debug3: Ignored env UBUNTU_MENUPROXY
+debug3: Ignored env GDMSESSION
+debug3: Ignored env HOME
+debug3: Ignored env SHLVL
+debug3: Ignored env GNOME_DESKTOP_SESSION_ID
+debug3: Ignored env LOGNAME
+debug3: Ignored env WINDOW
+debug3: Ignored env DBUS_SESSION_BUS_ADDRESS
+debug3: Ignored env XDG_DATA_DIRS
+debug3: Ignored env LESSOPEN
+debug3: Ignored env WINDOWPATH
+debug3: Ignored env DISPLAY
+debug3: Ignored env LESSCLOSE
+debug3: Ignored env COLORTERM
+debug3: Ignored env XAUTHORITY
+debug3: Ignored env OLDPWD
+debug3: Ignored env _
+debug2: channel 0: request shell confirm 1
+debug2: fd 3 setting TCP_NODELAY
+debug2: callback done
+debug2: channel 0: open confirm rwindow 0 rmax 32768
+debug2: channel_input_status_confirm: type 99 id 0
+debug2: PTY allocation request accepted on channel 0
+debug2: channel 0: rcvd adjust 2097152
+debug2: channel_input_status_confirm: type 99 id 0
+debug2: shell request accepted on channel 0
+Last login: Sat Mar 5 21:10:07 2011 from c-68-54-3-179.hsd1.nm.comcast.net
+Linux ssh1.90.ha.ovh.net 2.6.32.7-mutu-grs-ipv4-32 #2 SMP Sat Feb 6 13:33:23 UTC 2010 i686
+adips@ssh1:~$
+adips@ssh1:~$
+adips@ssh1:~$
+adips@ssh1:~$
+adips@ssh1:~$ \
+>
+adips@ssh1:~$
+adips@ssh1:~$ debug1: channel 0: free: client-session, nchannels 1
+debug3: channel 0: status: The following connections are open:
+ #0 client-session (t4 r0 i0/0 o0/0 fd 4/5 cc -1)
+
+debug3: channel 0: close_fds r 4 w 5 e 6
+debug1: fd 1 clearing O_NONBLOCK
+debug3: fd 2 is not O_NONBLOCK
+debug1: Killed by signal 15.
View
31 test/ssh/types.c.log
@@ -0,0 +1,31 @@
+session_state: 572
+Buffer: 16
+CipherContext: 148
+Newkeys: 256
+Mac: 216
+Cipher: 28
+Comp: 12
+EVP_CIPHER_CTX: 140
+EVP_MD: 72
+Enc: 28
+nh_ctx: 1128
+packet: 28
+packet_state: 24
+pdf_ctx: 276
+AES_KEY: 244
+uhash_ctx: 1236
+umac_ctx: 1516
+HMAC_CTX: 184
+TAILQ_ENTRY_PACKET: 8
+TAILQ_HEAD_PACKET: 8
+UINT32: 4
+UINT64: 8
+UINT8: 1
+AES_BLOCK_LEN: 16
+HASH_BUF_BYTES: 64
+UMAC_OUTPUT_LEN: 8
+SSH_SESSION_KEY_LENGTH: 32
+L1_KEY_LEN: 16
+L1_KEY_SHIFT: 16
+MODE_MAX: 2
+STREAMS: 2
View
31 test/ssh/types.py.log
@@ -0,0 +1,31 @@
+session_state: 572
+Buffer: 16
+CipherContext: 148
+Newkeys: 256
+Mac: 216
+Cipher: 28
+Comp: 12
+EVP_CIPHER_CTX: 140
+EVP_MD: 72
+Enc: 28
+nh_ctx: 1128
+packet: 28
+packet_state: 24
+pdf_ctx: 276
+AES_KEY: 244
+uhash_ctx: 1236
+umac_ctx: 1516
+HMAC_CTX: 184
+TAILQ_ENTRY_PACKET: 8
+TAILQ_HEAD_PACKET: 8
+UINT32: 4
+UINT64: 8
+UINT8: 1
+AES_BLOCK_LEN: 16
+HASH_BUF_BYTES: 64
+UMAC_OUTPUT_LEN: 8
+SSH_SESSION_KEY_LENGTH: 32
+L1_KEY_LEN: 16
+L1_KEY_SHIFT: 16
+MODE_MAX: 2
+STREAMS: 2

0 comments on commit bb04000

Please sign in to comment.
Something went wrong with that request. Please try again.