26#if APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION < 4
28#error session_crypto_module requires APU v1.4.0 or later
30#elif APU_HAVE_CRYPTO == 0
32#error Crypto support must be enabled in APR
38#define CRYPTO_KEY "session_crypto_context"
40module AP_MODULE_DECLARE_DATA session_crypto_module;
64#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 6)
68#define AP_SIPHASH_DSIZE APR_SIPHASH_DSIZE
69#define AP_SIPHASH_KSIZE APR_SIPHASH_KSIZE
70#define ap_siphash24_auth apr_siphash24_auth
72#define ap_crypto_equals apr_crypto_equals
76#define AP_SIPHASH_DSIZE 8
77#define AP_SIPHASH_KSIZE 16
79#define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
82 (((apr_uint64_t)((p)[0]) ) | \
83 ((apr_uint64_t)((p)[1]) << 8) | \
84 ((apr_uint64_t)((p)[2]) << 16) | \
85 ((apr_uint64_t)((p)[3]) << 24) | \
86 ((apr_uint64_t)((p)[4]) << 32) | \
87 ((apr_uint64_t)((p)[5]) << 40) | \
88 ((apr_uint64_t)((p)[6]) << 48) | \
89 ((apr_uint64_t)((p)[7]) << 56))
91#define U64TO8_LE(p, v) \
93 (p)[0] = (unsigned char)((v) ); \
94 (p)[1] = (unsigned char)((v) >> 8); \
95 (p)[2] = (unsigned char)((v) >> 16); \
96 (p)[3] = (unsigned char)((v) >> 24); \
97 (p)[4] = (unsigned char)((v) >> 32); \
98 (p)[5] = (unsigned char)((v) >> 40); \
99 (p)[6] = (unsigned char)((v) >> 48); \
100 (p)[7] = (unsigned char)((v) >> 56); \
105 v0 += v1; v1=ROTL64(v1,13); v1 ^= v0; v0=ROTL64(v0,32); \
106 v2 += v3; v3=ROTL64(v3,16); v3 ^= v2; \
107 v0 += v3; v3=ROTL64(v3,21); v3 ^= v0; \
108 v2 += v1; v1=ROTL64(v1,17); v1 ^= v2; v2=ROTL64(v2,32); \
114 const unsigned char *ptr, *
end;
156 return v0 ^ v1 ^ v2 ^ v3;
171 const unsigned char *
p1 =
buf1;
172 const unsigned char *
p2 =
buf2;
173 unsigned char diff = 0;
180 return 1 & ((
diff - 1) >> 8);
216 "no ciphers returned by APR. "
217 "session encryption not possible");
228 char *options =
NULL;
249 "cipher '%s' not recognised by crypto driver. "
250 "session encryption not possible, options: %s", dconf->cipher, options);
275 const unsigned char *
iv =
NULL;
296 "failure generating key from passphrase");
300 "padding is not supported for cipher");
304 "the key type is not known");
308 "encryption could not be configured.");
315 "apr_crypto_block_encrypt_init failed");
321 (
const unsigned char *)
in, strlen(
in),
325 "apr_crypto_block_encrypt failed");
331 "apr_crypto_block_encrypt_finish failed");
385 "too short to decrypt, aborting");
397 for (;
i < dconf->passphrases->nelts;
i++) {
409 "auth does not match, skipping");
420 "failure generating key from passphrase");
425 "padding is not supported for cipher");
430 "the key type is not known");
435 "encryption could not be configured.");
442 "too short to decrypt, skipping");
455 "apr_crypto_block_decrypt_init failed");
468 "apr_crypto_block_decrypt failed");
476 "apr_crypto_block_decrypt_finish failed");
487 "decryption failed");
503 char *encoded =
NULL;
509 if (dconf->passphrases_set &&
z->encoded && *
z->encoded) {
514 "encrypt session failed");
517 z->encoded = encoded;
534 char *encoded =
NULL;
540 if ((dconf->passphrases_set) &&
z->encoded && *
z->encoded) {
546 "decrypt session failed, wrong passphrase?");
549 z->encoded = encoded;
583 "APR crypto could not be initialised");
590 "warning: crypto for '%s' was already initialised, "
591 "using existing configuration", conf->library);
596 "The crypto library '%s' could not be loaded: %s (%s: %d)", conf->library,
err->msg,
err->reason,
err->rc);
601 "The crypto library '%s' could not be found",
607 "The crypto library '%s' could not be loaded",
615 "The crypto library '%s' could not be initialised",
621 "The crypto library '%s' was loaded successfully",
640#ifdef APU_CRYPTO_RECOMMENDED_DRIVER
655 new->cipher =
"aes256";
666 new->passphrases = (add->passphrases_set == 0) ?
base->passphrases : add->
passphrases;
667 new->passphrases_set = add->passphrases_set ||
base->passphrases_set;
668 new->cipher = (add->cipher_set == 0) ?
base->cipher : add->
cipher;
669 new->cipher_set = add->cipher_set ||
base->cipher_set;
688 conf->library_set = 1;
706 "Unable to parse exec arguments from ",
713 "Invalid SessionCryptoPassphrase exec location:",
717 (
const char*)
argv[0], (
const char *
const *)
argv);
721 "Unable to get bind password from exec of ",
730 dconf->passphrases_set = 1;
771 dconf->cipher_set = 1;
779 "The passphrase(s) used to encrypt the session. First will be used for encryption, all phrases will be accepted for decryption"),
781 "File containing passphrase(s) used to encrypt the session, one per line. First will be used for encryption, all phrases will be accepted for decryption"),
783 "The underlying crypto cipher to use"),
785 "The underlying crypto library driver to use"),
const char apr_size_t len
APR-UTIL Base64 Encoding.
static const char base64[]
APR general purpose library routines.
APR-UTIL siphash library "SipHash-c-d is a family of pseudorandom functions (a.k.a....
APR-util Versioning Interface.
#define AP_INIT_TAKE1(directive, func, mconfig, where, help)
#define ap_get_module_config(v, m)
int ap_cfg_closefile(ap_configfile_t *cfp)
void ap_hook_post_config(ap_HOOK_post_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
apr_status_t ap_pcfg_openfile(ap_configfile_t **ret_cfg, apr_pool_t *p, const char *name)
#define AP_DECLARE_MODULE(foo)
#define AP_INIT_ITERATE(directive, func, mconfig, where, help)
char * ap_server_root_relative(apr_pool_t *p, const char *fname)
#define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help)
apr_status_t ap_cfg_getline(char *buf, apr_size_t bufsize, ap_configfile_t *cfp)
#define AP_SQ_MS_CREATE_PRE_CONFIG
int ap_state_query(int query_code)
#define APR_MD5_DIGESTSIZE
const char const apr_dbd_driver_t ** driver
apr_pool_t apr_dbd_t apr_dbd_results_t ** res
apr_pool_t const char * params
#define APR_STATUS_IS_ENOKEY(s)
#define APR_STATUS_IS_EKEYTYPE(s)
#define APR_STATUS_IS_EPADDING(s)
void ap_hook_session_encode(ap_HOOK_session_encode_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
void ap_hook_session_decode(ap_HOOK_session_decode_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
#define STANDARD20_MODULE_STUFF
char * ap_get_exec_line(apr_pool_t *p, const char *cmd, const char *const *argv)
char * ap_getword_conf(apr_pool_t *p, const char **line)
const char * ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden)
apr_seek_where_t apr_off_t * offset
const char apr_file_t * file
apr_array_header_t ** result
#define APR_HASH_KEY_STRING
#define apr_pcalloc(p, size)
apr_size_t const char * filename
#define APR_ARRAY_IDX(ary, i, type)
apr_int32_t apr_int32_t apr_int32_t err
const char const char *const * args
static void register_hooks(apr_pool_t *p)
Session Module for Apache.
A structure that represents the current request.
struct ap_conf_vector_t * per_dir_config
A structure to store information for each virtual server.
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray