/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "buffer.h"
#include "str.h"
#include "dcrypt.h"
#include "dcrypt-iostream.h"
#include "ostream.h"
#include "ostream-encrypt.h"
#include "istream.h"
#include "istream-decrypt.h"
#include "istream-hash.h"
#include "istream-base64.h"
#include "randgen.h"
#include "hash-method.h"
#include "test-common.h"
#include "hex-binary.h"
#include <fcntl.h>
#include <stdio.h>
"MIGpAgEAMBAGByqGSM49AgEGBSuBBAAjBIGRMIGOAgEBBEGz2V2VMi/5s+Z+GJh7\n" \
"4WfqZjZUpqqm+NJWojm6BbrZMY+9ZComlTGVcUZ007acFxV93oMmrfmtRUb5ynrb\n" \
"MRFskKFGA0QAAwHrAJc8TvyPzspOoz6UH1C1YRmaUVm8tsLu2d0dYtZeOKJUl52J\n" \
"4o8MKIg+ce4q0mTNFrhj+glKj29ppWti6JGAQA==\n" \
"-----END PRIVATE KEY-----";
"MFgwEAYHKoZIzj0CAQYFK4EEACMDRAADAesAlzxO/I/Oyk6jPpQfULVhGZpRWby2\n" \
"wu7Z3R1i1l44olSXnYnijwwoiD5x7irSZM0WuGP6CUqPb2mla2LokYBA\n" \
"-----END PUBLIC KEY-----";
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgtuQJA+uboZWVwgHc\n" \
"DciyVdrovAPwlMqshDK3s78IDDuhRANCAAQm0VEdzLB9PtD0HA8JK1zifWnj8M00\n" \
"-----END PRIVATE KEY-----";
"NBUM3nX6fUkLFsgPHc7OfzRUeTE3ul24f53ShLNc2R972eBZTa4pWXNLLQ==\n" \
"-----END PUBLIC KEY-----";
static const char test_sample_v1_hash[] = "1d7cc2cc1f1983f76241cc42389911e88590ad58cf9d54cafeb5b198d3723dd1";
static const char test_sample_v1_short_hash[] = "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c";
static const char test_sample_v2_hash[] = "2e31218656dd34db65b321688bf418dee4ee785e99eb9c21e0d29b4af27a863e";
static
void test_static_v1_input(void)
{
test_begin("test_static_v1_input");
if (is_4->stream_errno != 0)
test_end();
}
static
void test_static_v1_input_short(void)
{
test_begin("test_static_v1_input_short");
if (is_4->stream_errno != 0)
test_end();
}
static
void test_static_v2_input(void)
{
test_begin("test_static_v2_input");
if (is_4->stream_errno != 0)
test_end();
/** this code is left here to show how the sample file is created
struct istream *is = i_stream_create_file("../lib-fts/udhr_fra.txt", 8192);
struct istream *is_2 = i_stream_create_hash(is, hash, hash_ctx);
int fd = open("sample-v2.bin", O_CREAT|O_TRUNC|O_WRONLY, S_IRWXU);
struct ostream *os = o_stream_create_fd_file(fd, 0, TRUE);
struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v2_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD);
const unsigned char *ptr;
size_t siz;
while(i_stream_read_data(is_2, &ptr, &siz, 0)>0) {
o_stream_nsend(os_2, ptr, siz);
i_stream_skip(is_2, siz);
}
i_assert(o_stream_finish(os_2) > 0);
o_stream_close(os_2);
i_stream_close(is_2);
hash->result(hash_ctx, hash_dgst);
printf("%s\n", binary_to_hex(hash_dgst, sizeof(hash_dgst)));
*/
}
static
void test_write_read_v1(void)
{
test_begin("test_write_read_v1");
const unsigned char *ptr;
struct ostream *os_2 = o_stream_create_encrypt(os, "<unused>", test_v2_kp.pub, IO_STREAM_ENC_VERSION_1);
if (os_2->stream_errno != 0)
o_stream_unref(&os);
test_istream_set_size(is, 0);
else
}
i_stream_unref(&is);
buffer_free(&buf);
test_end();
}
static
void test_write_read_v1_short(void)
{
test_begin("test_write_read_v1_short");
const unsigned char *ptr;
struct ostream *os_2 = o_stream_create_encrypt(os, "<unused>", test_v2_kp.pub, IO_STREAM_ENC_VERSION_1);
if (os_2->stream_errno != 0)
o_stream_unref(&os);
test_istream_set_size(is, 0);
else
}
i_stream_unref(&is);
buffer_free(&buf);
test_end();
}
static
void test_write_read_v1_empty(void)
{
const unsigned char *ptr;
test_begin("test_write_read_v1_empty");
struct ostream *os_2 = o_stream_create_encrypt(os, "<unused>", test_v1_kp.pub, IO_STREAM_ENC_VERSION_1);
if (os_2->stream_errno != 0)
o_stream_unref(&os);
/* this should've been enough */
/* read should not fail */
test_istream_set_size(is, 0);
test_assert(ret == 0);
else
};
if (is_2->stream_errno != 0)
i_stream_unref(&is);
buffer_free(&buf);
test_end();
}
static
void test_write_read_v2(void)
{
test_begin("test_write_read_v2");
const unsigned char *ptr;
struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v1_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD);
if (os_2->stream_errno != 0)
o_stream_unref(&os);
/* test regression where read fails due to incorrect behaviour
when buffer is full before going to decrypt code */
test_istream_set_size(is, 0);
else
}
if (is_2->stream_errno != 0)
i_stream_unref(&is);
buffer_free(&buf);
test_end();
}
static
void test_write_read_v2_short(void)
{
test_begin("test_write_read_v2_short");
const unsigned char *ptr;
struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v1_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD);
if (os_2->stream_errno != 0)
o_stream_unref(&os);
test_istream_set_size(is, 0);
}
if (is_2->stream_errno != 0)
i_stream_unref(&is);
buffer_free(&buf);
test_end();
}
static
void test_write_read_v2_empty(void)
{
const unsigned char *ptr;
test_begin("test_write_read_v2_empty");
struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v1_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD);
if (os_2->stream_errno != 0)
o_stream_unref(&os);
/* this should've been enough */
/* read should not fail */
test_istream_set_size(is, 0);
test_assert(ret == 0);
};
if (is_2->stream_errno != 0)
i_stream_unref(&is);
buffer_free(&buf);
test_end();
}
const char **error_r ATTR_UNUSED,
void *context ATTR_UNUSED)
{
return 0;
}
static void test_read_0_to_400_byte_garbage(void)
{
test_begin("test_read_0_to_100_byte_garbage");
for (size_t s = 0; s <= 400; ++s) {
test_istream_set_size(is, 0);
if (offset == s)
}
test_assert_idx(siz < 0, s);
i_stream_unref(&ds);
i_stream_unref(&is);
}
test_end();
}
static void test_read_large_header(void)
{
test_begin("test_read_large_header");
i_stream_unref(&ds);
i_stream_unref(&is);
test_end();
}
static
void test_free_keys() {
}
int main(void) {
.module_dir = ".libs"
};
const char *error;
return 0;
}
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}