]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - crypt.c
preparations for user list in memory
[paraslash.git] / crypt.c
diff --git a/crypt.c b/crypt.c
index 34407d782b910cab8f7e87aa269628d9a97aebf3..c2b50a7edca96f53fb1ccc3fd23ee9b9ffd9508f 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -46,7 +46,8 @@ static EVP_PKEY *load_key(const char *file, int private)
        return pkey;
 }
 
-static int get_key(char *key_file, RSA **rsa, int private)
+
+int get_rsa_key(char *key_file, RSA **rsa, int private)
 {
        EVP_PKEY *key = load_key(key_file, private);
 
@@ -77,7 +78,7 @@ int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *in
                        int rsa_inlen)
 {
        RSA *rsa;
-       int ret = get_key(key_file, &rsa, LOAD_PRIVATE_KEY);
+       int ret = get_rsa_key(key_file, &rsa, LOAD_PRIVATE_KEY);
 
        if (ret < 0)
                return ret;
@@ -100,12 +101,14 @@ int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *in
 int para_decrypt_challenge(char *key_file, long unsigned *challenge_nr,
                unsigned char *inbuf, int rsa_inlen)
 {
-       unsigned char *rsa_out = OPENSSL_malloc(128);
+       unsigned char *rsa_out = OPENSSL_malloc(rsa_inlen + 1);
        int ret = para_decrypt_buffer(key_file, rsa_out, inbuf, rsa_inlen);
 
-       if (ret >= 0)
+       if (ret >= 0) {
+               rsa_out[ret] = '\0';
                ret = sscanf((char *)rsa_out, "%lu", challenge_nr) == 1?
                        1 : -E_CHALLENGE;
+       }
        OPENSSL_free(rsa_out);
        return ret;
 }
@@ -126,7 +129,7 @@ int para_encrypt_buffer(char *key_file, unsigned char *inbuf,
                const unsigned len, unsigned char *outbuf)
 {
        RSA *rsa;
-       int ret = get_key(key_file, &rsa, LOAD_PUBLIC_KEY);
+       int ret = get_rsa_key(key_file, &rsa, LOAD_PUBLIC_KEY);
 
        if (ret < 0)
                return ret;