b64_encode(ciphertext, b64ciphertext, cipher_len);
strip_b64_eq(b64ciphertext);
- ctx->encrypted_msg = strdup(b64ciphertext);
+ ctx->encrypted_msg = strdup(b64ciphertext);
+ ctx->encrypted_msg_len = strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE);
/* Clean-up
*/
if(ctx->encrypted_msg == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
+ if(! is_valid_encoded_msg_len(ctx->encrypted_msg_len))
+ return(FKO_ERROR_INVALID_DATA);
+
return(FKO_SUCCESS);
}
b64_encode(cipher, b64cipher, cipher_len);
strip_b64_eq(b64cipher);
- ctx->encrypted_msg = strdup(b64cipher);
+ ctx->encrypted_msg = strdup(b64cipher);
+ ctx->encrypted_msg_len = strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE);
/* Clean-up
*/
if(ctx->encrypted_msg == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
+ if(! is_valid_encoded_msg_len(ctx->encrypted_msg_len))
+ return(FKO_ERROR_INVALID_DATA);
+
return(FKO_SUCCESS);
}
* and the trailing '=' chars stripped off).
*/
data_with_hmac_len
- = strlen(ctx->encrypted_msg)+1+strlen(ctx->msg_hmac)+1;
+ = ctx->encrypted_msg_len+1+ctx->msg_hmac_len+1;
tbuf = realloc(ctx->encrypted_msg, data_with_hmac_len);
if (tbuf == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
hmac_sha256(ctx->encrypted_msg,
- strlen(ctx->encrypted_msg), hmac, hmac_key);
+ ctx->encrypted_msg_len, hmac, hmac_key);
b64_encode(hmac, hmac_base64, SHA256_DIGEST_LENGTH);
strip_b64_eq(hmac_base64);
- ctx->msg_hmac = strdup(hmac_base64);
+ ctx->msg_hmac = strdup(hmac_base64);
+ ctx->msg_hmac_len = strnlen(ctx->msg_hmac, SHA512_DIGEST_STRING_LENGTH);
free(hmac_base64);
+ if(! is_valid_digest_len(ctx->msg_hmac_len))
+ return(FKO_ERROR_INVALID_DATA);
+
return FKO_SUCCESS;
}