- if (options.password_authentication)
- auth_mask |= 1 << SSH_AUTH_PASSWORD;
- packet_put_int(auth_mask);
-
- /* Send the packet and wait for it to be sent. */
- packet_send();
- packet_write_wait();
-
- debug("Sent %d bit public key and %d bit host key.",
- BN_num_bits(public_key->n), BN_num_bits(sensitive_data.host_key->n));
-
- /* Read clients reply (cipher type and session key). */
- packet_read_expect(&plen, SSH_CMSG_SESSION_KEY);
-
- /* Get cipher type. */
- cipher_type = packet_get_char();
-
- /* Get check bytes from the packet. These must match those we sent earlier
- with the public key packet. */
- for (i = 0; i < 8; i++)
- if (check_bytes[i] != packet_get_char())
- packet_disconnect("IP Spoofing check bytes do not match.");
-
- debug("Encryption type: %.200s", cipher_name(cipher_type));
-
- /* Get the encrypted integer. */
- session_key_int = BN_new();
- packet_get_bignum(session_key_int, &slen);
-
- /* Get protocol flags. */
- protocol_flags = packet_get_int();
- packet_set_protocol_flags(protocol_flags);
-
- packet_integrity_check(plen, 1 + 8 + slen + 4, SSH_CMSG_SESSION_KEY);
-
- /* Decrypt it using our private server key and private host key (key with
- larger modulus first). */
- if (BN_cmp(sensitive_data.private_key->n, sensitive_data.host_key->n) > 0)
- {
- /* Private key has bigger modulus. */
- if (BN_num_bits(sensitive_data.private_key->n) <
- BN_num_bits(sensitive_data.host_key->n) + SSH_KEY_BITS_RESERVED) {
- fatal("do_connection: private_key %d < host_key %d + SSH_KEY_BITS_RESERVED %d",
- BN_num_bits(sensitive_data.private_key->n),
- BN_num_bits(sensitive_data.host_key->n),
- SSH_KEY_BITS_RESERVED);
- }
-
- rsa_private_decrypt(session_key_int, session_key_int,
- sensitive_data.private_key);
- rsa_private_decrypt(session_key_int, session_key_int,
- sensitive_data.host_key);
- }
- else
- {
- /* Host key has bigger modulus (or they are equal). */
- if (BN_num_bits(sensitive_data.host_key->n) <
- BN_num_bits(sensitive_data.private_key->n) + SSH_KEY_BITS_RESERVED) {
- fatal("do_connection: host_key %d < private_key %d + SSH_KEY_BITS_RESERVED %d",
- BN_num_bits(sensitive_data.host_key->n),
- BN_num_bits(sensitive_data.private_key->n),
- SSH_KEY_BITS_RESERVED);
- }
- rsa_private_decrypt(session_key_int, session_key_int,
- sensitive_data.host_key);
- rsa_private_decrypt(session_key_int, session_key_int,
- sensitive_data.private_key);
- }
-
- /* Compute session id for this session. */
- compute_session_id(session_id, check_bytes,
- BN_num_bits(sensitive_data.host_key->n),
- sensitive_data.host_key->n,
- BN_num_bits(sensitive_data.private_key->n),
- sensitive_data.private_key->n);
-
- /* Extract session key from the decrypted integer. The key is in the
- least significant 256 bits of the integer; the first byte of the
- key is in the highest bits. */
- BN_mask_bits(session_key_int, sizeof(session_key) * 8);
- len = BN_num_bytes(session_key_int);
- if (len < 0 || len > sizeof(session_key))
- fatal("do_connection: bad len: session_key_int %d > sizeof(session_key) %d",
- len, sizeof(session_key));
- memset(session_key, 0, sizeof(session_key));
- BN_bn2bin(session_key_int, session_key + sizeof(session_key) - len);
-
- /* Xor the first 16 bytes of the session key with the session id. */
- for (i = 0; i < 16; i++)
- session_key[i] ^= session_id[i];
-
- /* Destroy the decrypted integer. It is no longer needed. */
- BN_clear_free(session_key_int);
-
- /* Set the session key. From this on all communications will be
- encrypted. */
- packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH,
- cipher_type, 0);
-
- /* Destroy our copy of the session key. It is no longer needed. */
- memset(session_key, 0, sizeof(session_key));
-
- debug("Received session key; encryption turned on.");
-
- /* Send an acknowledgement packet. Note that this packet is sent
- encrypted. */
- packet_start(SSH_SMSG_SUCCESS);
- packet_send();
- packet_write_wait();
-
- /* Get the name of the user that we wish to log in as. */
- packet_read_expect(&plen, SSH_CMSG_USER);
-
- /* Get the user name. */
- {
- int ulen;
- user = packet_get_string(&ulen);
- packet_integrity_check(plen, (4 + ulen), SSH_CMSG_USER);
- }
-
- /* Destroy the private and public keys. They will no longer be needed. */
- RSA_free(public_key);
- RSA_free(sensitive_data.private_key);
- RSA_free(sensitive_data.host_key);
-
- setproctitle("%s", user);
- /* Do the authentication. */
- do_authentication(user);
-}
+#ifdef SKEY
+ if (options.skey_authentication == 1)
+ auth_mask |= 1 << SSH_AUTH_TIS;
+#endif
+ if (options.password_authentication)
+ auth_mask |= 1 << SSH_AUTH_PASSWORD;
+ packet_put_int(auth_mask);
+
+ /* Send the packet and wait for it to be sent. */
+ packet_send();
+ packet_write_wait();
+
+ debug("Sent %d bit public key and %d bit host key.",
+ BN_num_bits(public_key->n), BN_num_bits(sensitive_data.host_key->n));
+
+ /* Read clients reply (cipher type and session key). */
+ packet_read_expect(&plen, SSH_CMSG_SESSION_KEY);
+
+ /* Get cipher type and check whether we accept this. */
+ cipher_type = packet_get_char();
+
+ if (!(cipher_mask() & (1 << cipher_type)))
+ packet_disconnect("Warning: client selects unsupported cipher.");
+
+ /* Get check bytes from the packet. These must match those we
+ sent earlier with the public key packet. */
+ for (i = 0; i < 8; i++)
+ if (check_bytes[i] != packet_get_char())
+ packet_disconnect("IP Spoofing check bytes do not match.");
+
+ debug("Encryption type: %.200s", cipher_name(cipher_type));
+
+ /* Get the encrypted integer. */
+ session_key_int = BN_new();
+ packet_get_bignum(session_key_int, &slen);
+
+ protocol_flags = packet_get_int();
+ packet_set_protocol_flags(protocol_flags);
+
+ packet_integrity_check(plen, 1 + 8 + slen + 4, SSH_CMSG_SESSION_KEY);
+
+ /*
+ * Decrypt it using our private server key and private host key (key
+ * with larger modulus first).
+ */
+ if (BN_cmp(sensitive_data.private_key->n, sensitive_data.host_key->n) > 0) {
+ /* Private key has bigger modulus. */
+ if (BN_num_bits(sensitive_data.private_key->n) <
+ BN_num_bits(sensitive_data.host_key->n) + SSH_KEY_BITS_RESERVED) {
+ fatal("do_connection: %s: private_key %d < host_key %d + SSH_KEY_BITS_RESERVED %d",
+ get_remote_ipaddr(),
+ BN_num_bits(sensitive_data.private_key->n),
+ BN_num_bits(sensitive_data.host_key->n),
+ SSH_KEY_BITS_RESERVED);
+ }
+ rsa_private_decrypt(session_key_int, session_key_int,
+ sensitive_data.private_key);
+ rsa_private_decrypt(session_key_int, session_key_int,
+ sensitive_data.host_key);
+ } else {
+ /* Host key has bigger modulus (or they are equal). */
+ if (BN_num_bits(sensitive_data.host_key->n) <
+ BN_num_bits(sensitive_data.private_key->n) + SSH_KEY_BITS_RESERVED) {
+ fatal("do_connection: %s: host_key %d < private_key %d + SSH_KEY_BITS_RESERVED %d",
+ get_remote_ipaddr(),
+ BN_num_bits(sensitive_data.host_key->n),
+ BN_num_bits(sensitive_data.private_key->n),
+ SSH_KEY_BITS_RESERVED);
+ }
+ rsa_private_decrypt(session_key_int, session_key_int,
+ sensitive_data.host_key);
+ rsa_private_decrypt(session_key_int, session_key_int,
+ sensitive_data.private_key);
+ }
+
+ compute_session_id(session_id, check_bytes,
+ sensitive_data.host_key->n,
+ sensitive_data.private_key->n);
+
+ /*
+ * Extract session key from the decrypted integer. The key is in the
+ * least significant 256 bits of the integer; the first byte of the
+ * key is in the highest bits.
+ */
+ BN_mask_bits(session_key_int, sizeof(session_key) * 8);
+ len = BN_num_bytes(session_key_int);
+ if (len < 0 || len > sizeof(session_key))
+ fatal("do_connection: bad len from %s: session_key_int %d > sizeof(session_key) %d",
+ get_remote_ipaddr(),
+ len, sizeof(session_key));
+ memset(session_key, 0, sizeof(session_key));
+ BN_bn2bin(session_key_int, session_key + sizeof(session_key) - len);
+
+ /* Xor the first 16 bytes of the session key with the session id. */
+ for (i = 0; i < 16; i++)
+ session_key[i] ^= session_id[i];
+
+ /* Destroy the decrypted integer. It is no longer needed. */
+ BN_clear_free(session_key_int);
+
+ /* Set the session key. From this on all communications will be encrypted. */
+ packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type);
+
+ /* Destroy our copy of the session key. It is no longer needed. */
+ memset(session_key, 0, sizeof(session_key));