mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45:10 +00:00
[MOD] Use specific SHA1/256 abstraction functions
This commit is contained in:
parent
6cd3df21db
commit
4c158ea186
9 changed files with 80 additions and 22 deletions
|
|
@ -25,8 +25,7 @@ JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name)
|
|||
{
|
||||
char *nonce_str = StrInt(nonce);
|
||||
char *input = StrConcat(4, sender, name, data->id, nonce_str);
|
||||
unsigned char *digest = Sha256(input);
|
||||
char *hex = ShaToHex(digest);
|
||||
char *hex = ParseeSHA256(input);
|
||||
|
||||
if (strlen(hex) >= 8)
|
||||
{
|
||||
|
|
@ -41,7 +40,6 @@ JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name)
|
|||
nonce++;
|
||||
|
||||
Free(nonce_str);
|
||||
Free(digest);
|
||||
Free(input);
|
||||
Free(hex);
|
||||
}
|
||||
|
|
|
|||
57
src/Parsee/SHA.c
Normal file
57
src/Parsee/SHA.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include <Parsee.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Sha.h>
|
||||
|
||||
static char *
|
||||
ToHex(unsigned char *input, size_t length)
|
||||
{
|
||||
char *hex = Malloc(length * 2 + 1);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
const char *table =
|
||||
"0123456789abcdef";
|
||||
unsigned char byte = input[i];
|
||||
hex[2 * i] = table[(byte >> 4) & 0xF];
|
||||
hex[2*i+1] = table[(byte >> 0) & 0xF];
|
||||
}
|
||||
|
||||
hex[length * 2] = '\0';
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
char *
|
||||
ParseeSHA256(char *string)
|
||||
{
|
||||
unsigned char *sha;
|
||||
char *returnString;
|
||||
if (!string)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sha = Sha256(string);
|
||||
returnString = ToHex(sha, 32);
|
||||
Free(sha);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
char *
|
||||
ParseeSHA1(char *string)
|
||||
{
|
||||
unsigned char *sha;
|
||||
char *returnString;
|
||||
if (!string)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sha = Sha1(string);
|
||||
returnString = ToHex(sha, 20);
|
||||
Free(sha);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
|
@ -12,8 +12,6 @@ static HashMap *nick_table = NULL;
|
|||
static char *
|
||||
GenerateKey(char *muc, char *mxid)
|
||||
{
|
||||
unsigned char *shaDigest;
|
||||
|
||||
char *concatStr;
|
||||
char *hexDigest;
|
||||
if (!muc || !mxid)
|
||||
|
|
@ -22,10 +20,8 @@ GenerateKey(char *muc, char *mxid)
|
|||
}
|
||||
|
||||
concatStr = StrConcat(3, muc, ":", mxid);
|
||||
shaDigest = Sha256(concatStr);
|
||||
hexDigest = ShaToHex(shaDigest);
|
||||
hexDigest = ParseeSHA256(concatStr);
|
||||
|
||||
Free (shaDigest);
|
||||
Free (concatStr);
|
||||
return hexDigest;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,19 +295,17 @@ char *
|
|||
ParseeGetDMID(char *mxid, char *jid)
|
||||
{
|
||||
char *concat, *sha;
|
||||
unsigned char *raw;
|
||||
if (!mxid || !jid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We really don't care about safety here. */
|
||||
jid = ParseeTrimJID(jid);
|
||||
concat = StrConcat(2, mxid, jid);
|
||||
raw = Sha1(concat);
|
||||
sha = ShaToHex(raw);
|
||||
sha = ParseeSHA1(concat);
|
||||
|
||||
Free(concat);
|
||||
Free(raw);
|
||||
Free(jid);
|
||||
|
||||
return sha;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <Parsee.h>
|
||||
#include <XML.h>
|
||||
|
||||
/* The default component port Prosody uses. */
|
||||
|
|
@ -81,14 +82,11 @@ static char *
|
|||
ComputeHandshake(char *shared, char *stream)
|
||||
{
|
||||
char *source;
|
||||
unsigned char *raw_sha;
|
||||
char *sha;
|
||||
|
||||
source = StrConcat(2, stream, shared);
|
||||
raw_sha = Sha1(source);
|
||||
sha = ShaToHex(raw_sha);
|
||||
sha = ParseeSHA1(source);
|
||||
|
||||
Free(raw_sha);
|
||||
Free(source);
|
||||
|
||||
return sha;
|
||||
|
|
|
|||
|
|
@ -166,7 +166,6 @@ ServerHasXEP421(ParseeData *data, char *from)
|
|||
static char *
|
||||
ScrambleOID(ParseeData *data, char *opaque_oid)
|
||||
{
|
||||
unsigned char *raw;
|
||||
char *sha, *mxid;
|
||||
const ParseeConfig *c = data->config;
|
||||
if (!opaque_oid)
|
||||
|
|
@ -175,9 +174,7 @@ ScrambleOID(ParseeData *data, char *opaque_oid)
|
|||
}
|
||||
|
||||
/* Turns this into a 128-byte long, Matrix-safe value. */
|
||||
raw = Sha256(opaque_oid);
|
||||
sha = ShaToHex(raw);
|
||||
Free(raw);
|
||||
sha = ParseeSHA256(opaque_oid);
|
||||
|
||||
/* TODO: Either mark this specially, or drop Parsee JID flags
|
||||
* altogether before any 1.0.0 */
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ end_error:
|
|||
room = ParseeFindDMRoom(args, to, from);
|
||||
data = body ? ArrayGet(body->children, 0) : NULL;
|
||||
|
||||
/* TODO: CLEAN THAT UP */
|
||||
/* TODO: CLEAN THAT UP INTO A CREATEDM FUNCTION */
|
||||
mroom_id = ParseeGetBridgedRoom(args, stanza);
|
||||
if (!mroom_id && !room && !XMPPIsParseeStanza(stanza) &&
|
||||
to && *to == '@')
|
||||
|
|
|
|||
|
|
@ -99,6 +99,20 @@ extern char * ParseeGenerateGetopt(const Argument *list);
|
|||
* Modifies: NOTHING */
|
||||
extern void ParseeGenerateHelp(const Argument *list);
|
||||
|
||||
/** Generates a hexadecimal version of the SHA-256 digest of the
|
||||
* original string.
|
||||
* ----------------
|
||||
* Returns: a hexadecimal string[HEAP]
|
||||
* Modifies: NOTHING */
|
||||
extern char * ParseeSHA256(char *string);
|
||||
|
||||
/** Generates a hexadecimal version of the SHA-1 digest of the
|
||||
* original string.
|
||||
* ----------------
|
||||
* Returns: a hexadecimal string[HEAP]
|
||||
* Modifies: NOTHING */
|
||||
extern char * ParseeSHA1(char *string);
|
||||
|
||||
/* Initialises a Parsee config from scratch, and writes to it
|
||||
* as JSON in the CWD. */
|
||||
extern void ParseeConfigInit(void);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
XMPPSetFormTitle(cmd, "Admin addition form"); \
|
||||
XMPPSetFormInstruction(cmd, "Select a glob pattern to add as an admin"); \
|
||||
}) \
|
||||
XMPP_COMMAND(DelAdminCallback, "del-admin", "Removes a glob from admin rights", { \
|
||||
XMPP_COMMAND(DelAdminCallback, "del-admin", "Removes glob from being admin", { \
|
||||
XMPPCmdOptionsCreator(cmd, FormDelAdminCallback); \
|
||||
XMPPSetFormTitle(cmd, "Admin removal form"); \
|
||||
XMPPSetFormInstruction(cmd, "Select a glob pattern to remove as an admin"); \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue