blob: 788f61fd2631ea8941f31e60c939b470606ed47b [file] [log] [blame]
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Rampart_crypto_util will contain crypto functionalities of the rampart model
*
*/
#include <stdio.h>
#include <rampart_crypto_util.h>
#include <axis2_util.h>
#include <axis2_base64.h>
#include <openssl_digest.h>
/*Calculate the hash of concatenated string of
* nonce, created and the password.
*
*/
AXIS2_EXTERN axis2_char_t* AXIS2_CALL rampart_crypto_sha1(const axis2_env_t *env,
const axis2_char_t *nonce,
const axis2_char_t *created,
const axis2_char_t *password)
{
char* input = NULL;
axis2_char_t* digest = NULL;
axis2_char_t* decoded_nonce = NULL;
int decoded_nonce_length = 0;
/*Decode the nonce first*/
if(nonce){
int ret;
decoded_nonce_length = axis2_base64_decode_len(nonce);
decoded_nonce = AXIS2_MALLOC(env->allocator, axis2_base64_decode_len(nonce));
ret = axis2_base64_decode(decoded_nonce, nonce);
}
if ((!nonce) && (!created))
{/*If both nonce and created are omitted*/
input = AXIS2_MALLOC(env->allocator, AXIS2_STRLEN(password) + 1);
sprintf(input, "%s", password);
}
else if (!nonce)
{/*If nonce is omitted*/
input = AXIS2_MALLOC(env->allocator, AXIS2_STRLEN(created) + AXIS2_STRLEN(password) + 1);
sprintf(input, "%s%s", created, password);
}
else if (!created)
{/*If created is omitted*/
input = AXIS2_MALLOC(env->allocator, decoded_nonce_length + AXIS2_STRLEN(password) + 1);
sprintf(input, "%s%s", decoded_nonce, password);
}
else
{/*If all nonce, created and password are present*/
input = AXIS2_MALLOC(env->allocator, decoded_nonce_length + AXIS2_STRLEN(created) + AXIS2_STRLEN(password) + 1);
sprintf(input, "%s%s%s", decoded_nonce, created, password);
}
digest = openssl_sha1(env, input, AXIS2_STRLEN(input));
AXIS2_FREE(env->allocator, input);
return digest;
}