| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | #include "includes.h" | - |
| 29 | | - |
| 30 | #include <sys/types.h> | - |
| 31 | | - |
| 32 | #include <stdio.h> | - |
| 33 | #include <string.h> | - |
| 34 | #include <signal.h> | - |
| 35 | | - |
| 36 | #include "sshkey.h" | - |
| 37 | #include "cipher.h" | - |
| 38 | #include "kex.h" | - |
| 39 | #include "log.h" | - |
| 40 | #include "packet.h" | - |
| 41 | #include "ssh2.h" | - |
| 42 | #include "sshbuf.h" | - |
| 43 | #include "digest.h" | - |
| 44 | #include "ssherr.h" | - |
| 45 | | - |
| 46 | static int | - |
| 47 | input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh); | - |
| 48 | | - |
| 49 | int | - |
| 50 | kexc25519_client(struct ssh *ssh) | - |
| 51 | { | - |
| 52 | struct kex *kex = ssh->kex; | - |
| 53 | int r; | - |
| 54 | | - |
| 55 | kexc25519_keygen(kex->c25519_client_key, kex->c25519_client_pubkey); | - |
| 56 | #ifdef DEBUG_KEXECDH | - |
| 57 | dump_digest("client private key:", kex->c25519_client_key, | - |
| 58 | sizeof(kex->c25519_client_key)); | - |
| 59 | #endif | - |
| 60 | if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_INIT)) != 0 ||| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 61 | (r = sshpkt_put_string(ssh, kex->c25519_client_pubkey,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 62 | sizeof(kex->c25519_client_pubkey))) != 0 ||| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 63 | (r = sshpkt_send(ssh)) != 0)| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 64 | return r; never executed: return r; | 0 |
| 65 | | - |
| 66 | debug("expecting SSH2_MSG_KEX_ECDH_REPLY"); | - |
| 67 | ssh_dispatch_set(ssh, SSH2_MSG_KEX_ECDH_REPLY, &input_kex_c25519_reply); | - |
| 68 | return 0;executed 20 times by 1 test: return 0; | 20 |
| 69 | } | - |
| 70 | | - |
| 71 | static int | - |
| 72 | input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh) | - |
| 73 | { | - |
| 74 | struct kex *kex = ssh->kex; | - |
| 75 | struct sshkey *server_host_key = NULL; | - |
| 76 | struct sshbuf *shared_secret = NULL; | - |
| 77 | u_char *server_pubkey = NULL; | - |
| 78 | u_char *server_host_key_blob = NULL, *signature = NULL; | - |
| 79 | u_char hash[SSH_DIGEST_MAX_LENGTH]; | - |
| 80 | size_t slen, pklen, sbloblen, hashlen; | - |
| 81 | int r; | - |
| 82 | | - |
| 83 | if (kex->verify_host_key == NULL) {| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 84 | r = SSH_ERR_INVALID_ARGUMENT; | - |
| 85 | goto out; never executed: goto out; | 0 |
| 86 | } | - |
| 87 | | - |
| 88 | | - |
| 89 | if ((r = sshpkt_get_string(ssh, &server_host_key_blob,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 90 | &sbloblen)) != 0 ||| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 91 | (r = sshkey_from_blob(server_host_key_blob, sbloblen,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 92 | &server_host_key)) != 0)| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 93 | goto out; never executed: goto out; | 0 |
| 94 | if (server_host_key->type != kex->hostkey_type ||| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 95 | (kex->hostkey_type == KEY_ECDSA &&| TRUE | evaluated 5 times by 1 test | | FALSE | evaluated 15 times by 1 test |
| 5-15 |
| 96 | server_host_key->ecdsa_nid != kex->hostkey_nid)) {| TRUE | never evaluated | | FALSE | evaluated 5 times by 1 test |
| 0-5 |
| 97 | r = SSH_ERR_KEY_TYPE_MISMATCH; | - |
| 98 | goto out; never executed: goto out; | 0 |
| 99 | } | - |
| 100 | if (kex->verify_host_key(server_host_key, ssh) == -1) {| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 101 | r = SSH_ERR_SIGNATURE_INVALID; | - |
| 102 | goto out; never executed: goto out; | 0 |
| 103 | } | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | if ((r = sshpkt_get_string(ssh, &server_pubkey, &pklen)) != 0 ||| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 108 | (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 109 | (r = sshpkt_get_end(ssh)) != 0)| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 110 | goto out; never executed: goto out; | 0 |
| 111 | if (pklen != CURVE25519_SIZE) {| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 112 | r = SSH_ERR_SIGNATURE_INVALID; | - |
| 113 | goto out; never executed: goto out; | 0 |
| 114 | } | - |
| 115 | | - |
| 116 | #ifdef DEBUG_KEXECDH | - |
| 117 | dump_digest("server public key:", server_pubkey, CURVE25519_SIZE); | - |
| 118 | #endif | - |
| 119 | | - |
| 120 | if ((shared_secret = sshbuf_new()) == NULL) {| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 121 | r = SSH_ERR_ALLOC_FAIL; | - |
| 122 | goto out; never executed: goto out; | 0 |
| 123 | } | - |
| 124 | if ((r = kexc25519_shared_key(kex->c25519_client_key, server_pubkey,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 125 | shared_secret)) < 0)| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 126 | goto out; never executed: goto out; | 0 |
| 127 | | - |
| 128 | | - |
| 129 | hashlen = sizeof(hash); | - |
| 130 | if ((r = kex_c25519_hash(| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 131 | kex->hash_alg,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 132 | kex->client_version_string,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 133 | kex->server_version_string,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 134 | sshbuf_ptr(kex->my), sshbuf_len(kex->my),| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 135 | sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 136 | server_host_key_blob, sbloblen,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 137 | kex->c25519_client_pubkey,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 138 | server_pubkey,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 139 | sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 140 | hash, &hashlen)) < 0)| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 141 | goto out; never executed: goto out; | 0 |
| 142 | | - |
| 143 | if ((r = sshkey_verify(server_host_key, signature, slen, hash, hashlen,| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 144 | kex->hostkey_alg, ssh->compat)) != 0)| TRUE | never evaluated | | FALSE | evaluated 20 times by 1 test |
| 0-20 |
| 145 | goto out; never executed: goto out; | 0 |
| 146 | | - |
| 147 | | - |
| 148 | if (kex->session_id == NULL) {| TRUE | evaluated 4 times by 1 test | | FALSE | evaluated 16 times by 1 test |
| 4-16 |
| 149 | kex->session_id_len = hashlen; | - |
| 150 | kex->session_id = malloc(kex->session_id_len); | - |
| 151 | if (kex->session_id == NULL) {| TRUE | never evaluated | | FALSE | evaluated 4 times by 1 test |
| 0-4 |
| 152 | r = SSH_ERR_ALLOC_FAIL; | - |
| 153 | goto out; never executed: goto out; | 0 |
| 154 | } | - |
| 155 | memcpy(kex->session_id, hash, kex->session_id_len); | - |
| 156 | }executed 4 times by 1 test: end of block | 4 |
| 157 | | - |
| 158 | if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)| TRUE | evaluated 20 times by 1 test | | FALSE | never evaluated |
| 0-20 |
| 159 | r = kex_send_newkeys(ssh);executed 20 times by 1 test: r = kex_send_newkeys(ssh); | 20 |
| 160 | out:code before this statement executed 20 times by 1 test: out: | 20 |
| 161 | explicit_bzero(hash, sizeof(hash)); | - |
| 162 | explicit_bzero(kex->c25519_client_key, sizeof(kex->c25519_client_key)); | - |
| 163 | free(server_host_key_blob); | - |
| 164 | free(server_pubkey); | - |
| 165 | free(signature); | - |
| 166 | sshkey_free(server_host_key); | - |
| 167 | sshbuf_free(shared_secret); | - |
| 168 | return r;executed 20 times by 1 test: return r; | 20 |
| 169 | } | - |
| | |