* Initialise the encryption as per the current config. * * Returns APR_SUCCESS if successful. */
| 187 | * Returns APR_SUCCESS if successful. |
| 188 | */ |
| 189 | static apr_status_t crypt_init(request_rec *r, |
| 190 | const apr_crypto_t *f, apr_crypto_block_key_type_e **cipher, |
| 191 | session_crypto_dir_conf * dconf) |
| 192 | { |
| 193 | apr_status_t res; |
| 194 | apr_hash_t *ciphers; |
| 195 | |
| 196 | res = apr_crypto_get_block_key_types(&ciphers, f); |
| 197 | if (APR_SUCCESS != res) { |
| 198 | ap_log_rerror(APLOG_MARK, APLOG_ERR, res, r, APLOGNO(01823) |
| 199 | "no ciphers returned by APR. " |
| 200 | "session encryption not possible"); |
| 201 | return res; |
| 202 | } |
| 203 | |
| 204 | *cipher = apr_hash_get(ciphers, dconf->cipher, APR_HASH_KEY_STRING); |
| 205 | if (!(*cipher)) { |
| 206 | apr_hash_index_t *hi; |
| 207 | const void *key; |
| 208 | apr_ssize_t klen; |
| 209 | int sum = 0; |
| 210 | int offset = 0; |
| 211 | char *options = NULL; |
| 212 | |
| 213 | for (hi = apr_hash_first(r->pool, ciphers); hi; hi = apr_hash_next(hi)) { |
| 214 | apr_hash_this(hi, NULL, &klen, NULL); |
| 215 | sum += klen + 2; |
| 216 | } |
| 217 | for (hi = apr_hash_first(r->pool, ciphers); hi; hi = apr_hash_next(hi)) { |
| 218 | apr_hash_this(hi, &key, &klen, NULL); |
| 219 | if (!options) { |
| 220 | options = apr_palloc(r->pool, sum + 1); |
| 221 | } |
| 222 | else { |
| 223 | options[offset++] = ','; |
| 224 | options[offset++] = ' '; |
| 225 | } |
| 226 | strncpy(options + offset, key, klen); |
| 227 | offset += klen; |
| 228 | } |
| 229 | options[offset] = 0; |
| 230 | |
| 231 | ap_log_rerror(APLOG_MARK, APLOG_ERR, res, r, APLOGNO(01824) |
| 232 | "cipher '%s' not recognised by crypto driver. " |
| 233 | "session encryption not possible, options: %s", dconf->cipher, options); |
| 234 | |
| 235 | return APR_EGENERAL; |
| 236 | } |
| 237 | |
| 238 | return APR_SUCCESS; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Encrypt the string given as per the current config. |
no outgoing calls
no test coverage detected