crypto_obfuscate.c revision 8f1316a0c677f211eaaa1346e21a03446b8c4fb1
/*
SSSD
Password obfuscation logic
Authors:
George McCollister <george.mccollister@gmail.com>
Copyright (C) George McCollister 2012
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* READ ME:
*
* Please note that password obfuscation does not improve security in any
* way. It is just a mechanism to make the password human-unreadable. If you
* need to secure passwords in your application, you should probably take a
* look at storing passwords in NSS-backed database.
*/
#include "config.h"
#include <talloc.h>
#include <errno.h>
#include "util/crypto/sss_crypto.h"
#define OBF_BUFFER_SENTINEL "\0\1\2\3"
#define OBF_BUFFER_SENTINEL_SIZE 4
struct crypto_mech_data {
const EVP_CIPHER * (*cipher)(void);
};
static struct crypto_mech_data cmdata[] = {
/* AES with automatic padding, 256b key, 128b block */
/* sentinel */
{ 0, 0, 0 }
};
{
if (meth >= NUM_OBFMETHODS) {
return NULL;
}
}
{
int ret;
struct crypto_mech_data *mech_props;
unsigned char *keybuf;
unsigned char *ivbuf;
unsigned char *cryptotext;
int ct_maxsize;
int ctlen = 0;
int digestlen = 0;
int result_len;
unsigned char *obfbuf;
size_t p = 0;
if (!tmp_ctx) {
return ENOMEM;
}
ctx = EVP_CIPHER_CTX_new();
goto done;
}
if (mech_props == NULL) {
goto done;
}
goto done;
}
goto done;
}
/* cryptotext buffer must be at least len(plaintext)+blocksize */
if (!cryptotext) {
goto done;
}
goto done;
}
/* sample data we'll encrypt and decrypt */
goto done;
}
goto done;
}
goto done;
}
/* Pack the obfuscation buffer */
/* The buffer consists of:
* uint16_t the type of the cipher
* uint16_t length of the cryptotext in bytes (clen)
* uint8_t[klen] key
* uint8_t[blen] IV
* uint8_t[clen] cryptotext
* 4 bytes of "sentinel" denoting end of the buffer
*/
if (!obfbuf) {
goto done;
}
OBF_BUFFER_SENTINEL_SIZE, &p);
/* Base64 encode the resulting buffer */
goto done;
}
done:
return ret;
}
char **password)
{
int ret;
struct crypto_mech_data *mech_props;
int plainlen;
int digestlen;
char *pwdbuf;
/* for unmarshaling data */
size_t p = 0;
unsigned char *cryptotext;
unsigned char *keybuf;
unsigned char *ivbuf;
unsigned char sentinel_check[OBF_BUFFER_SENTINEL_SIZE];
if (!tmp_ctx) {
return ENOMEM;
}
ctx = EVP_CIPHER_CTX_new();
goto done;
}
/* Base64 decode the incoming buffer */
if (!obfbuf) {
goto done;
}
/* unpack obfuscation buffer */
if (mech_props == NULL) {
goto done;
}
/* check that we got sane mechanism properties and cryptotext size */
goto done;
}
/* copy out key, ivbuf and cryptotext */
goto done;
}
goto done;
}
if (cryptotext == NULL) {
goto done;
}
if (!pwdbuf) {
goto done;
}
goto done;
}
/* sample data we'll encrypt and decrypt */
goto done;
}
goto done;
}
done:
return ret;
}