41 if (mode & CRYPTO_LOCK) {
60 num = CRYPTO_num_locks();
67 for (i = 0; i < num; i++) {
84 CRYPTO_set_locking_callback(NULL);
85 for (i = 0; i < CRYPTO_num_locks(); i++) {
98 if (!strcasecmp(name,
"md5"))
return EVP_md5();
99 if (!strcasecmp(name,
"sha1"))
return EVP_sha1();
100 if (!strcasecmp(name,
"sha-1"))
return EVP_sha1();
101 if (!strcasecmp(name,
"sha-256"))
return EVP_sha256();
102 if (!strcasecmp(name,
"sha-512"))
return EVP_sha512();
106 #if defined(_MSC_VER) || (defined(__SunOS_5_10) && defined(__SUNPRO_C))
113 char *strsep(
char **stringp,
const char *delim)
117 if (!stringp || !*stringp || !**stringp)
121 while (**stringp && !strchr(delim, **stringp))
136 char *tmp = strdup(fp->str);
141 while ((v = strsep(&p,
":")) && (i != (
MAX_FPLEN - 1))) {
142 sscanf(v,
"%02x", (uint32_t *) &fdata[i++]);
147 i = !memcmp(fdata, fp->data, i);
154 char *tmp = strdup(str);
159 while ((v = strsep(&p,
":")) && (i != (
MAX_FPLEN - 1))) {
160 sscanf(v,
"%02x", (uint32_t *) &fp->data[i++]);
175 if (X509_digest(x509, evp, fp->data, &fp->len) != 1 || fp->len <= 0) {
180 for (i = 0, j = 0; i < fp->len; ++i, j += 3){
181 sprintf((
char*)&fp->str[j], (i == (fp->len - 1)) ?
"%.2X" :
"%.2X:", fp->data[i]);
183 *(&fp->str[fp->len * 3]) =
'\0';
203 if (!(bio = BIO_new(BIO_s_file()))) {
208 if (BIO_read_filename(bio, rsa) != 1) {
213 if (!(x509 = PEM_read_bio_X509(bio, NULL, 0, NULL))) {
238 static int mkcert(X509 **x509p, EVP_PKEY **pkeyp,
int bits,
int serial,
int days);
244 EVP_PKEY *pkey = NULL;
245 char *rsa = NULL, *pvt = NULL;
252 pem = strdup(prefix);
274 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
278 mkcert(&x509, &pkey, 1024, 0, 36500);
284 if ((fp = fopen(pem,
"w"))) {
285 PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
286 PEM_write_X509(fp, x509);
291 if (pvt && (fp = fopen(pvt,
"w"))) {
292 PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
296 if (rsa && (fp = fopen(rsa,
"w"))) {
297 PEM_write_X509(fp, x509);
305 #ifndef OPENSSL_NO_ENGINE
308 CRYPTO_cleanup_all_ex_data();
324 static void callback(
int p,
int n,
void *arg)
336 static int mkcert(X509 **x509p, EVP_PKEY **pkeyp,
int bits,
int serial,
int days)
341 X509_NAME *
name=NULL;
346 if (*pkeyp == NULL) {
347 if ((pk = EVP_PKEY_new()) == NULL) {
354 if (*x509p == NULL) {
355 if ((x = X509_new()) == NULL) {
362 rsa = RSA_generate_key(bits, RSA_F4, NULL, NULL);
364 if (!EVP_PKEY_assign_RSA(pk, rsa)) {
371 X509_set_version(x, 0);
372 ASN1_INTEGER_set(X509_get_serialNumber(x), serial);
373 X509_gmtime_adj(X509_get_notBefore(x), -(
long)60*60*24*7);
374 X509_gmtime_adj(X509_get_notAfter(x), (
long)60*60*24*days);
375 X509_set_pubkey(x, pk);
377 name = X509_get_subject_name(x);
383 X509_NAME_add_entry_by_txt(name,
"C", MBSTRING_ASC, (
unsigned char *)
"US", -1, -1, 0);
384 X509_NAME_add_entry_by_txt(name,
"CN", MBSTRING_ASC, (
unsigned char *)
"FreeSWITCH", -1, -1, 0);
390 X509_set_issuer_name(x, name);
392 if (!X509_sign(x, pk, EVP_sha1()))
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_mutex_destroy(switch_mutex_t *lock)
#define SWITCH_CHANNEL_LOG
switch_cache_db_handle_type_t type
void switch_ssl_init_ssl_locks(void)
int switch_core_gen_certs(const char *prefix)
static unsigned long switch_ssl_ssl_thread_id(void)
int switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp, const char *str)
static switch_mutex_t ** ssl_mutexes
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
#define SWITCH_MUTEX_NESTED
int switch_core_cert_verify(dtls_fingerprint_t *fp)
#define SWITCH_PATH_SEPARATOR
int switch_core_cert_gen_fingerprint(const char *prefix, dtls_fingerprint_t *fp)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
void switch_ssl_destroy_ssl_locks(void)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
switch_byte_t switch_byte_t uint32_t switch_bitpack_mode_t mode
int switch_core_cert_extract_fingerprint(X509 *x509, dtls_fingerprint_t *fp)
switch_directories SWITCH_GLOBAL_dirs
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
struct apr_thread_mutex_t switch_mutex_t
static switch_bool_t switch_is_file_path(const char *file)
struct apr_pool_t switch_memory_pool_t
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
switch_thread_id_t switch_thread_self(void)
static void switch_ssl_ssl_lock_callback(int mode, int type, char *file, int line)
static switch_memory_pool_t * ssl_pool
static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
static const EVP_MD * get_evp_by_name(const char *name)