[python module] default to HMAC SHA256 when an HMAC key is used but no HMAC mode was specified

This commit is contained in:
Michael Rash
2014-10-23 08:45:21 -04:00
parent d7be3f43ac
commit a2ce50e9e5
4 changed files with 33 additions and 22 deletions

View File

@@ -32,7 +32,7 @@ Example simple minimal fknop client:
# Generate the final SPA data string.
#
f.spa_data_final('put_pw_here')
f.spa_data_final('put_pw_here', 'put_hmac_pw_here')
# Display the final SPA data string.
#
@@ -563,7 +563,7 @@ class Fko:
else:
return _fko.get_raw_spa_digest(self.ctx)
def spa_encryption_mode(self, val=None):
def encryption_mode(self, val=None):
"""Get or set the spa_encryption mode
This is an integer value. If no argument is given, the current value
@@ -575,6 +575,11 @@ class Fko:
else:
return _fko.get_spa_encryption_mode(self.ctx)
def spa_encryption_mode(self, val=None):
"""Alias for encryption_mode() to maintain backwards compatibility
"""
return self.encryption_mode(val)
def hmac_type(self, val=None):
"""Get or set the spa_hmac_type
@@ -593,8 +598,13 @@ class Fko:
This function is the final step in creating a complete encrypted
SPA data string suitable for transmission to an fwknop server. It
does require all of the requisite SPA data fields be set. Otherwise,
it will fail and throw an fko.error exception.
it will fail and throw an fko.error exception. We do set the default
HMAC digest to SHA256 if an HMAC key was provided and the HMAC mode
was not already set.
"""
if hmac_key and not _fko.get_spa_hmac_type(self.ctx):
_fko.set_spa_hmac_type(self.ctx, FKO_HMAC_SHA256)
_fko.spa_data_final(self.ctx, key, hmac_key)
def gen_spa_data(self, key):
@@ -659,11 +669,6 @@ class Fko:
# --DSS
def encryption_type(self, enc_data):
"""Return the assumed encryption type based on the encryptped data
"""
_fko.encryption_type(enc_data)
def key_gen(self, keyb64, hmac_keyb64):
"""Generate Rijndael and HMAC keys and base64 encode them
"""
@@ -692,7 +697,7 @@ class Fko:
def get_spa_hmac(self):
"""Return the HMAC for the data in the current context
"""
_fko.get_spa_hmac(self.ctx)
return _fko.get_spa_hmac(self.ctx)
# GPG-related functions.

View File

@@ -1282,14 +1282,13 @@ base64_encode(PyObject *self, PyObject *args)
unsigned char *in;
int in_len;
char *out;
int res;
/* --DSS Note the order of args is different than the libfko call.
We need to do this for the following parse call. */
if(!PyArg_ParseTuple(args, "s#s", &in, &in_len, &out))
return NULL;
res = fko_base64_encode(in, out, in_len);
fko_base64_encode(in, out, in_len);
return Py_BuildValue("s", out);
}
@@ -1357,13 +1356,13 @@ static PyObject *
get_spa_hmac(PyObject *self, PyObject *args)
{
fko_ctx_t ctx;
char *enc_data;
char *hmac_data;
int res;
if(!PyArg_ParseTuple(args, "k", &ctx))
return NULL;
res = fko_get_spa_hmac(ctx, &enc_data);
res = fko_get_spa_hmac(ctx, &hmac_data);
if(res != FKO_SUCCESS)
{
@@ -1371,7 +1370,7 @@ get_spa_hmac(PyObject *self, PyObject *args)
return NULL;
}
return Py_BuildValue("s", enc_data);
return Py_BuildValue("s", hmac_data);
}
/*****************************************************************************