| 1 |
/* libossl.h - rsyslog's ossl crypto provider support library |
| 2 |
* |
| 3 |
* This file is part of rsyslog. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* -or- |
| 11 |
* see COPYING.ASL20 in the source distribution |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, software |
| 14 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
* See the License for the specific language governing permissions and |
| 17 |
* limitations under the License. |
| 18 |
*/ |
| 19 |
#ifndef INCLUDED_LIBOSSL_H |
| 20 |
#define INCLUDED_LIBOSSL_H |
| 21 |
#include <stdint.h> |
| 22 |
|
| 23 |
#include <openssl/conf.h> |
| 24 |
#include <openssl/evp.h> |
| 25 |
#include <openssl/err.h> |
| 26 |
|
| 27 |
struct osslctx_s { |
| 28 |
uchar* key; |
| 29 |
size_t keyLen; |
| 30 |
const EVP_CIPHER* cipher; /* container for algorithm + mode */ |
| 31 |
}; |
| 32 |
typedef struct osslctx_s* osslctx; |
| 33 |
typedef struct osslfile_s* osslfile; |
| 34 |
|
| 35 |
/* this describes a file, as far as libgcry is concerned */ |
| 36 |
struct osslfile_s { |
| 37 |
// gcry_cipher_hd_t chd; /* cypher handle */ TODO |
| 38 |
EVP_CIPHER_CTX* chd; |
| 39 |
size_t blkLength; /* size of low-level crypto block */ |
| 40 |
uchar* eiName; /* name of .encinfo file */ |
| 41 |
int fd; /* descriptor of .encinfo file (-1 if not open) */ |
| 42 |
char openMode; /* 'r': read, 'w': write */ |
| 43 |
osslctx ctx; |
| 44 |
uchar* readBuf; |
| 45 |
int16_t readBufIdx; |
| 46 |
int16_t readBufMaxIdx; |
| 47 |
int8_t bDeleteOnClose; /* for queue support, similar to stream subsys */ |
| 48 |
ssize_t bytesToBlkEnd; /* number of bytes remaining in current crypto block |
| 49 |
-1 means -> no end (still being writen to, queue files), |
| 50 |
0 means -> end of block, new one must be started. */ |
| 51 |
}; |
| 52 |
|
| 53 |
osslctx osslCtxNew(void); |
| 54 |
void rsosslCtxDel(osslctx ctx); |
| 55 |
rsRetVal rsosslSetAlgoMode(osslctx ctx, uchar* algorithm); |
| 56 |
int osslGetKeyFromFile(const char* const fn, char** const key, unsigned* const keylen); |
| 57 |
int rsosslSetKey(osslctx ctx, unsigned char* key, uint16_t keyLen); |
| 58 |
rsRetVal osslfileGetBytesLeftInBlock(osslfile gf, ssize_t* left); |
| 59 |
rsRetVal osslfileDeleteState(uchar* logfn); |
| 60 |
rsRetVal rsosslInitCrypt(osslctx ctx, osslfile* pgf, uchar* fname, char openMode); |
| 61 |
rsRetVal rsosslDecrypt(osslfile pF, uchar* buf, size_t* len); |
| 62 |
rsRetVal rsosslEncrypt(osslfile pF, uchar* buf, size_t* len); |
| 63 |
int osslfileDestruct(osslfile gf, off64_t offsLogfile); |
| 64 |
int rsosslInit(void); |
| 65 |
void rsosslExit(void); |
| 66 |
|
| 67 |
|
| 68 |
// FIXME refactor |
| 69 |
static inline void __attribute__((unused)) osslfileSetDeleteOnClose(osslfile gf, const int val) { |
| 70 |
if (gf != NULL) gf->bDeleteOnClose = val; |
| 71 |
} |
| 72 |
|
| 73 |
#endif /* #ifndef INCLUDED_LIBOSSL_H */ |