Skip to content

Commit

Permalink
lanplus: Auto-select 'best' cipher suite available
Browse files Browse the repository at this point in the history
Based on current crypto alogrithms, one could rank cipher suites along
these lines:

17 > 3 >> all the rest

17 and 3 are the only cipher suites that implement any sort of
confidentiality alogorithm that is secure. In addition, any hmac-md5 or
md5 integrity algorithm used in integrity is weak at best and dangerous
for authentication.

This could possibly be enabled in a simpler mechanism by simply checking
for 17 and then choosing it before falling back to 3, but the way this
is implemented, it makes it easy to change the list of acceptable
algorithms from two to three or more items.

Resolves ipmitool#29

Signed-off-by: Vernon Mauery <vernon.mauery@intel.com>
  • Loading branch information
vmauery authored and AlexanderAmelkin committed Nov 1, 2018
1 parent a8862d7 commit 7772254
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 160 deletions.
47 changes: 47 additions & 0 deletions include/ipmitool/ipmi_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# include <config.h>
#endif
#include <ipmitool/ipmi.h>
#include <ipmitool/ipmi_intf.h>


#define IPMI_GET_CHANNEL_AUTH_CAP 0x38
Expand Down Expand Up @@ -77,6 +78,50 @@ struct channel_access_t {
uint8_t user_level_auth;
};

/*
* The Cipher Suite Record Format from table 22-18 of the IPMI v2.0 spec
*/
enum cipher_suite_format_tag {
STANDARD_CIPHER_SUITE = 0xc0,
OEM_CIPHER_SUITE = 0xc1,
};
#ifdef HAVE_PRAGMA_PACK
#pragma pack(1)
#endif
struct std_cipher_suite_record_t {
uint8_t start_of_record;
uint8_t cipher_suite_id;
uint8_t auth_alg;
uint8_t integrity_alg;
uint8_t crypt_alg;
} ATTRIBUTE_PACKING;
struct oem_cipher_suite_record_t {
uint8_t start_of_record;
uint8_t cipher_suite_id;
uint8_t iana[3];
uint8_t auth_alg;
uint8_t integrity_alg;
uint8_t crypt_alg;
} ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK
#pragma pack(0)
#endif
#define CIPHER_ALG_MASK 0x3f
#define MAX_CIPHER_SUITE_RECORD_OFFSET 0x40
#define MAX_CIPHER_SUITE_DATA_LEN 0x10
#define LIST_ALGORITHMS_BY_CIPHER_SUITE 0x80

/* Below is the theoretical maximum number of cipher suites that could be
* reported by a BMC. That is with the Get Channel Cipher Suites Command, at 16
* bytes at a time and 0x40 requests, it can report 1024 bytes, which is about
* 204 standard records or 128 OEM records. Really, we probably don't need more
* than about 20, which is the full set of standard records plus a few OEM
* records.
*/
#define MAX_CIPHER_SUITE_COUNT (MAX_CIPHER_SUITE_RECORD_OFFSET * \
MAX_CIPHER_SUITE_DATA_LEN / \
sizeof(struct std_cipher_suite_record_t))

/*
* The Get Authentication Capabilities response structure
* From table 22-15 of the IPMI v2.0 spec
Expand Down Expand Up @@ -131,6 +176,8 @@ struct get_channel_auth_cap_rsp {
int _ipmi_get_channel_access(struct ipmi_intf *intf,
struct channel_access_t *channel_access,
uint8_t get_volatile_settings);
int ipmi_get_channel_cipher_suites(struct ipmi_intf *intf, const char *payload_type,
uint8_t channel, struct cipher_suite_info *suites, size_t *count);
int _ipmi_get_channel_info(struct ipmi_intf *intf,
struct channel_info_t *channel_info);
int _ipmi_set_channel_access(struct ipmi_intf *intf,
Expand Down
39 changes: 37 additions & 2 deletions include/ipmitool/ipmi_intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,45 @@ enum LANPLUS_SESSION_STATE {
#define IPMI_SIK_BUFFER_SIZE IPMI_MAX_MD_SIZE
#define IPMI_KG_BUFFER_SIZE 21 /* key plus null byte */

enum cipher_suite_ids {
IPMI_LANPLUS_CIPHER_SUITE_0 = 0,
IPMI_LANPLUS_CIPHER_SUITE_1 = 1,
IPMI_LANPLUS_CIPHER_SUITE_2 = 2,
IPMI_LANPLUS_CIPHER_SUITE_3 = 3,
IPMI_LANPLUS_CIPHER_SUITE_4 = 4,
IPMI_LANPLUS_CIPHER_SUITE_5 = 5,
IPMI_LANPLUS_CIPHER_SUITE_6 = 6,
IPMI_LANPLUS_CIPHER_SUITE_7 = 7,
IPMI_LANPLUS_CIPHER_SUITE_8 = 8,
IPMI_LANPLUS_CIPHER_SUITE_9 = 9,
IPMI_LANPLUS_CIPHER_SUITE_10 = 10,
IPMI_LANPLUS_CIPHER_SUITE_11 = 11,
IPMI_LANPLUS_CIPHER_SUITE_12 = 12,
IPMI_LANPLUS_CIPHER_SUITE_13 = 13,
IPMI_LANPLUS_CIPHER_SUITE_14 = 14,
#ifdef HAVE_CRYPTO_SHA256
IPMI_LANPLUS_CIPHER_SUITE_15 = 15,
IPMI_LANPLUS_CIPHER_SUITE_16 = 16,
IPMI_LANPLUS_CIPHER_SUITE_17 = 17,
#endif /* HAVE_CRYPTO_SHA256 */
IPMI_LANPLUS_CIPHER_SUITE_RESERVED = 0xff,
};

struct cipher_suite_info {
enum cipher_suite_ids cipher_suite_id;
uint8_t auth_alg;
uint8_t integrity_alg;
uint8_t crypt_alg;
uint32_t iana;
};

struct ipmi_session_params {
char * hostname;
uint8_t username[17];
uint8_t authcode_set[IPMI_AUTHCODE_BUFFER_SIZE + 1];
uint8_t authtype_set;
uint8_t privlvl;
uint8_t cipher_suite_id;
enum cipher_suite_ids cipher_suite_id;
char sol_escape_char;
int password;
int port;
Expand Down Expand Up @@ -217,7 +249,10 @@ void ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username);
void ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password);
void ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, uint8_t privlvl);
void ipmi_intf_session_set_lookupbit(struct ipmi_intf * intf, uint8_t lookupbit);
void ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf, uint8_t cipher_suite_id);
#ifdef IPMI_INTF_LANPLUS
void ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf,
enum cipher_suite_ids cipher_suite_id);
#endif /* IPMI_INTF_LANPLUS */
void ipmi_intf_session_set_sol_escape_char(struct ipmi_intf * intf, char sol_escape_char);
void ipmi_intf_session_set_kgkey(struct ipmi_intf *intf, const uint8_t *kgkey);
void ipmi_intf_session_set_port(struct ipmi_intf * intf, int port);
Expand Down

0 comments on commit 7772254

Please sign in to comment.