mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-02-17 07:33:57 +00:00
fix(session): allow password/token to be longer than userkey
This commit is contained in:
@@ -162,11 +162,23 @@
|
|||||||
|
|
||||||
// Get the key length and its bytes
|
// Get the key length and its bytes
|
||||||
data = [theKey dataByDecodingBase64];
|
data = [theKey dataByDecodingBase64];
|
||||||
key = (char *)[data bytes];
|
|
||||||
klen = [data length];
|
klen = [data length];
|
||||||
|
|
||||||
|
|
||||||
|
//value longer than the key, concatenate the key with itself until long enough
|
||||||
if (klen < [theValue length])
|
if (klen < [theValue length])
|
||||||
[self errorWithFormat: @"Value to be secured is too big (%i > %i) -- secured value will be corrupted", [theValue length], klen, [theKey length]];
|
{
|
||||||
|
NSMutableData *concatenatedData = [NSMutableData data];
|
||||||
|
int j;
|
||||||
|
int nbDuplication = [theValue length]/klen;
|
||||||
|
for(j=0; j <= nbDuplication; j++)
|
||||||
|
[concatenatedData appendData:data];
|
||||||
|
|
||||||
|
data = [NSData dataWithData: concatenatedData];
|
||||||
|
klen = [data length];
|
||||||
|
}
|
||||||
|
|
||||||
|
key = (char *)[data bytes];
|
||||||
|
|
||||||
// Get the key - padding it with 0 with key length
|
// Get the key - padding it with 0 with key length
|
||||||
pass = (char *) calloc(klen, sizeof(char));
|
pass = (char *) calloc(klen, sizeof(char));
|
||||||
@@ -201,7 +213,6 @@
|
|||||||
|
|
||||||
// Get the key length and its bytes
|
// Get the key length and its bytes
|
||||||
dataKey = [theKey dataByDecodingBase64];
|
dataKey = [theKey dataByDecodingBase64];
|
||||||
key = (char *)[dataKey bytes];
|
|
||||||
klen = [dataKey length];
|
klen = [dataKey length];
|
||||||
|
|
||||||
// Get the secured value length and its bytes
|
// Get the secured value length and its bytes
|
||||||
@@ -209,6 +220,20 @@
|
|||||||
value = (char *)[dataValue bytes];
|
value = (char *)[dataValue bytes];
|
||||||
vlen = [dataValue length];
|
vlen = [dataValue length];
|
||||||
|
|
||||||
|
//If the key is shorer than the value, duplicate it with itself.
|
||||||
|
if(klen < vlen)
|
||||||
|
{
|
||||||
|
NSMutableData *concatenatedData = [NSMutableData data];
|
||||||
|
int j;
|
||||||
|
int nbDuplication = [dataValue length]/klen;
|
||||||
|
for(j=0; j <= nbDuplication; j++)
|
||||||
|
[concatenatedData appendData:dataKey];
|
||||||
|
|
||||||
|
dataKey = [NSData dataWithData: concatenatedData];
|
||||||
|
klen = [dataKey length];
|
||||||
|
}
|
||||||
|
key = (char *)[dataKey bytes];
|
||||||
|
|
||||||
// Target buffer
|
// Target buffer
|
||||||
buf = (char *) calloc(klen, sizeof(char));
|
buf = (char *) calloc(klen, sizeof(char));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user