kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
kinetic_auth.c
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 
21 #include "kinetic_auth.h"
22 #include "kinetic_hmac.h"
23 #include "kinetic.pb-c.h"
24 #include "kinetic_logger.h"
25 
27 {
28  KINETIC_ASSERT(config);
29  if (!config->useSsl) {return KINETIC_STATUS_SSL_REQUIRED;}
31 }
32 
33 KineticStatus KineticAuth_PopulateHmac(KineticSessionConfig const * const config, KineticRequest * const pdu)
34 {
35  KINETIC_ASSERT(config);
36  KINETIC_ASSERT(pdu);
37 
38  LOG3("Adding HMAC auth info");
39 
40  if (config->hmacKey.data == NULL) { return KINETIC_STATUS_HMAC_REQUIRED; }
41 
42  Com__Seagate__Kinetic__Proto__Message* msg = &pdu->message.message;
43 
44  // Add HMAC authentication struct
45  msg->hmacauth = &pdu->message.hmacAuth;
47  msg->hmacauth = msg->hmacauth;
48  msg->pinauth = NULL;
50  msg->has_authtype = true;
51 
52  // Configure HMAC support
53  ByteArray const * const hmacKey = &config->hmacKey;
54  KINETIC_ASSERT(hmacKey->len <= KINETIC_HMAC_MAX_LEN); // NOCOMMIT
55  KINETIC_ASSERT(hmacKey->data != NULL);
56 
57  msg->hmacauth = &pdu->message.hmacAuth;
58 
59  msg->hmacauth->hmac = (ProtobufCBinaryData) {
60  .data = pdu->message.hmacData,
61  .len = KINETIC_HMAC_SHA1_LEN,
62  };
63 
64  msg->hmacauth->has_hmac = true;
65  msg->hmacauth->identity = config->identity;
66  msg->hmacauth->has_identity = true;
67 
68  // Populate with hashed HMAC
69  KineticHMAC hmac;
71  KineticHMAC_Populate(&hmac, &pdu->message.message, config->hmacKey);
72 
74 }
75 
76 KineticStatus KineticAuth_PopulatePin(KineticSessionConfig const * const config, KineticRequest * const pdu, ByteArray pin)
77 {
78  KINETIC_ASSERT(config);
79  KINETIC_ASSERT(pdu);
80 
81  LOG3("Adding PIN auth info");
82 
83  if (!config->useSsl) { return KINETIC_STATUS_SSL_REQUIRED; }
84 
85  KineticMessage* msg = &pdu->message;
86 
87  // Add PIN authentication struct
89  msg->message.pinauth = &msg->pinAuth;
90  msg->message.hmacauth = NULL;
92  msg->message.has_authtype = true;
93  msg->command.header = &msg->header;
94 
95  // Configure PIN support
97  if (pin.len > 0) { KINETIC_ASSERT(pin.data != NULL); }
98  msg->message.pinauth->pin = (ProtobufCBinaryData) {
99  .data = pin.data,
100  .len = pin.len,
101  };
102  msg->message.pinauth->has_pin = true;
103 
104  return KINETIC_STATUS_SUCCESS;
105 }
106 
108 {
109  (void)tag;
110  (void)algorithm;
111  (void)key;
112  return KINETIC_STATUS_INVALID;
113 }
Structure for handling generic arrays of bytes.
Definition: byte_array.h:34
#define KINETIC_PIN_MAX_LEN
Max PIN length.
Definition: kinetic_types.h:44
Structure for an embedded ByteArray as a buffer.
Definition: byte_array.h:53
Operation successful.
Structure used to specify the configuration for a session.
#define KINETIC_HMAC_MAX_LEN
HMAC max length.
Definition: kinetic_types.h:43
void KineticHMAC_Populate(KineticHMAC *hmac, Com__Seagate__Kinetic__Proto__Message *msg, const ByteArray key)
Definition: kinetic_hmac.c:47
void com__seagate__kinetic__proto__message__pinauth__init(Com__Seagate__Kinetic__Proto__Message__PINauth *message)
Definition: kinetic.pb-c.c:60
The operation requires an SSL connection and the specified connection is non-SSL. ...
int64_t identity
The identity associated with this request.
KineticAlgorithm
Enumeration of encryption/checksum key algorithms.
Definition: kinetic_types.h:73
Com__Seagate__Kinetic__Proto__Message message
KineticStatus KineticAuth_PopulatePin(KineticSessionConfig const *const config, KineticRequest *const pdu, ByteArray pin)
Definition: kinetic_auth.c:76
Com__Seagate__Kinetic__Proto__Command__Header header
#define KINETIC_ASSERT(cond)
Com__Seagate__Kinetic__Proto__Message__PINauth pinAuth
void com__seagate__kinetic__proto__message__hmacauth__init(Com__Seagate__Kinetic__Proto__Message__HMACauth *message)
Definition: kinetic.pb-c.c:54
void KineticHMAC_Init(KineticHMAC *hmac, Com__Seagate__Kinetic__Proto__Command__Security__ACL__HMACAlgorithm algorithm)
Definition: kinetic_hmac.c:31
size_t len
Number of bytes in the data field.
Definition: byte_array.h:35
#define LOG3(message)
KineticStatus KineticAuth_EnsureSslEnabled(KineticSessionConfig const *const config)
Definition: kinetic_auth.c:26
#define KINETIC_HMAC_SHA1_LEN
HMAC secure hash length.
Definition: kinetic_types.h:42
uint8_t * data
Pointer to an allocated array of data bytes.
Definition: byte_array.h:36
Status not available (no reponse/status available)
KineticStatus
Kinetic status codes.
KineticStatus KineticAuth_PopulateTag(ByteBuffer *const tag, KineticAlgorithm algorithm, ByteArray const *const key)
Definition: kinetic_auth.c:107
Com__Seagate__Kinetic__Proto__Command command
bool useSsl
Set to `true' to enable SSL for for this session.
KineticStatus KineticAuth_PopulateHmac(KineticSessionConfig const *const config, KineticRequest *const pdu)
Definition: kinetic_auth.c:33
HMAC key is empty or NULL.