Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Updated set ssl/tls protocol version logic for cipher and import commands to use new APIs. |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk | main | tls-2.0 |
| Files: | files | file ages | folders |
| SHA3-256: |
e383f271925545d05f9b00d1ce17a489 |
| User & Date: | bohagan 2025-10-16 21:21:09 |
Context
|
2025-10-17
| ||
| 03:14 | Simplified logic for adding static libraries to TCLTLS_SSL_LIBS check-in: 85b45fc6e0 user: bohagan tags: trunk, main, tls-2.0 | |
|
2025-10-16
| ||
| 21:21 | Updated set ssl/tls protocol version logic for cipher and import commands to use new APIs. check-in: e383f27192 user: bohagan tags: trunk, main, tls-2.0 | |
| 18:20 | Updated set DH parameters for servers for OpenSSL 3.0+ APIs. check-in: 014250ffb8 user: bohagan tags: trunk, main, tls-2.0 | |
Changes
Changes to generic/tls.c.
| ︙ | ︙ | |||
1031 1032 1033 1034 1035 1036 1037 |
Tcl_Obj *const objv[]) /* Arguments as Tcl objects */
{
Tcl_Obj *objPtr = NULL;
SSL_CTX *ctx = NULL;
SSL *ssl = NULL;
STACK_OF(SSL_CIPHER) *sk;
char buf[BUFSIZ];
| | | | | > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > | 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
Tcl_Obj *const objv[]) /* Arguments as Tcl objects */
{
Tcl_Obj *objPtr = NULL;
SSL_CTX *ctx = NULL;
SSL *ssl = NULL;
STACK_OF(SSL_CIPHER) *sk;
char buf[BUFSIZ];
int index, verbose = 0, use_supported = 0, version = 0;
const SSL_METHOD *method = TLS_method();
dprintf("Called");
if ((objc < 1) || (objc > 4)) {
Tcl_WrongNumArgs(interp, 1, objv, "?protocol? ?verbose? ?supported?");
return TCL_ERROR;
}
if (objc > 1) {
if (Tcl_GetIndexFromObj(interp, objv[1], protocols, "protocol", 0, &index) != TCL_OK) {
return TCL_ERROR;
} else {
switch ((enum protocol)index) {
case TLS_SSL2:
#if OPENSSL_VERSION_NUMBER >= 0x10100000L || defined(NO_SSL2) || defined(OPENSSL_NO_SSL2)
version = -1;
#else
version = SSL2_VERSION;
#endif
break;
case TLS_SSL3:
#if defined(NO_SSL3) || defined(OPENSSL_NO_SSL3)
version = -1;
#else
version = SSL3_VERSION;
#endif
break;
case TLS_TLS1:
#if defined(NO_TLS1) || defined(OPENSSL_NO_TLS1)
version = -1;
#else
version = TLS1_VERSION;
#endif
break;
case TLS_TLS1_1:
#if defined(NO_TLS1_1) || defined(OPENSSL_NO_TLS1_1)
version = -1;
#else
version = TLS1_1_VERSION;
#endif
break;
case TLS_TLS1_2:
#if defined(NO_TLS1_2) || defined(OPENSSL_NO_TLS1_2)
version = -1;
#else
version = TLS1_2_VERSION;
#endif
break;
case TLS_TLS1_3:
#if defined(NO_TLS1_3) || defined(OPENSSL_NO_TLS1_3)
version = -1;
#else
version = TLS1_3_VERSION;
#endif
break;
default:
version = -1;
}
}
if (version < 0) {
Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *)NULL);
return TCL_ERROR;
}
}
if ((objc > 2) && Tcl_GetBooleanFromObj(interp, objv[2], &verbose) != TCL_OK) {
return TCL_ERROR;
}
if ((objc > 3) && Tcl_GetBooleanFromObj(interp, objv[3], &use_supported) != TCL_OK) {
return TCL_ERROR;
}
ERR_clear_error();
ctx = SSL_CTX_new(method);
if (ctx == NULL) {
Tcl_AppendResult(interp, GET_ERR_REASON(), (char *)NULL);
return TCL_ERROR;
}
SSL_CTX_set_min_proto_version(ctx, version);
SSL_CTX_set_max_proto_version(ctx, version);
ssl = SSL_new(ctx);
if (ssl == NULL) {
Tcl_AppendResult(interp, GET_ERR_REASON(), (char *)NULL);
SSL_CTX_free(ctx);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 |
Tcl_AppendToObj(objPtr, "UNKNOWN\n", 8);
}
}
}
if (use_supported) {
sk_SSL_CIPHER_free(sk);
}
}
SSL_free(ssl);
SSL_CTX_free(ctx);
Tcl_SetObjResult(interp, objPtr);
return TCL_OK;
}
| > > | 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 |
Tcl_AppendToObj(objPtr, "UNKNOWN\n", 8);
}
}
}
if (use_supported) {
sk_SSL_CIPHER_free(sk);
}
} else {
objPtr = Tcl_NewStringObj("",0);
}
SSL_free(ssl);
SSL_CTX_free(ctx);
Tcl_SetObjResult(interp, objPtr);
return TCL_OK;
}
|
| ︙ | ︙ | |||
1916 1917 1918 1919 1920 1921 1922 |
if (Tcl_ReadChars(in, buf, -1, 0) < 0) {
Tcl_Close(interp, in);
goto cleanup;
}
Tcl_Close(interp, in);
data = (const void *) Tcl_GetByteArrayFromObj(buf, &len);
| | | 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 |
if (Tcl_ReadChars(in, buf, -1, 0) < 0) {
Tcl_Close(interp, in);
goto cleanup;
}
Tcl_Close(interp, in);
data = (const void *) Tcl_GetByteArrayFromObj(buf, &len);
bio = BIO_new_mem_buf(data, (int)len);
if (bio == NULL) {
goto cleanup;
}
/* Where the certs go */
store = SSL_CTX_get_cert_store(ctx);
if (store == NULL) {
|
| ︙ | ︙ | |||
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 |
{
Tcl_Interp *interp = statePtr->interp;
SSL_CTX *ctx = NULL;
Tcl_DString ds;
int off = 0, abort = 0;
int load_private_key;
const SSL_METHOD *method;
dprintf("Called");
| > < < < < | < | < < < < < | | < < < | < < < < < < < < | < < < < < < < < < < < < < < < < < < < < | | < < < | | < < | | < < > > | | < < < | | < < | | < < < < < < < < < < < < < < < < < < < | | | < < > > > > > > > > > > > > > < < < < < < < | < > | | | | 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 |
{
Tcl_Interp *interp = statePtr->interp;
SSL_CTX *ctx = NULL;
Tcl_DString ds;
int off = 0, abort = 0;
int load_private_key;
const SSL_METHOD *method;
method = isServer ? TLS_server_method() : TLS_client_method();
dprintf("Called");
/* Get user defined allowed protocols */
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if !defined(NO_SSL2) && !defined(OPENSSL_NO_SSL2)
if (!(proto & TLS_PROTO_SSL2))
#endif
off |= SSL_OP_NO_SSLv2;
#endif
#if !defined(NO_SSL3) && !defined(OPENSSL_NO_SSL3)
if (!(proto & TLS_PROTO_SSL3))
#endif
off |= SSL_OP_NO_SSLv3;
#if !defined(NO_TLS1) && !defined(OPENSSL_NO_TLS1)
if (!(proto & TLS_PROTO_TLS1))
#endif
off |= SSL_OP_NO_TLSv1;
#if !defined(NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_1)
if (!(proto & TLS_PROTO_TLS1_1))
#endif
off |= SSL_OP_NO_TLSv1_1;
#if !defined(NO_TLS1_2) && !defined(OPENSSL_NO_TLS1_2)
if (!(proto & TLS_PROTO_TLS1_2))
#endif
off |= SSL_OP_NO_TLSv1_2;
#if !defined(NO_TLS1_3) && !defined(OPENSSL_NO_TLS1_3)
if (!(proto & TLS_PROTO_TLS1_3))
#endif
off |= SSL_OP_NO_TLSv1_3;
ERR_clear_error();
/* Create context */
ctx = SSL_CTX_new(method);
if (!ctx) {
return NULL;
}
/* Specify allowed protocol range */
if (!proto) {
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
SSL_CTX_set_max_proto_version(ctx, TLS1_3_VERSION);
} else {
SSL_CTX_set_min_proto_version(ctx, 0); /* Support all */
SSL_CTX_set_max_proto_version(ctx, 0);
SSL_CTX_set_options(ctx, off); /* Disable specific protocol versions */
}
/* Set crypyo key log file */
if (getenv(SSLKEYLOGFILE)) {
SSL_CTX_set_keylog_callback(ctx, KeyLogCallback);
}
/* Force client cipher selection order to set by server */
if (!isServer) {
SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
OpenSSL_add_all_algorithms(); /* Load ciphers and digests */
#endif
SSL_CTX_set_app_data(ctx, (void*)interp); /* remember the interpreter */
SSL_CTX_set_options(ctx, SSL_OP_ALL); /* Enable all SSL bug workarounds */
SSL_CTX_set_options(ctx, SSL_OP_NO_COMPRESSION); /* Disable compression even if supported */
/* Allow writes to report success when less than all records have been written */
SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
/* Disable attempts to try to process the next record instead of returning after a
non-app record. Avoids hangs in blocking mode, when using SSL_read() and a
non-application record was sent without any application data. */
/*SSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY);*/
/* Set number of sessions to cache */
SSL_CTX_sess_set_cache_size(ctx, 128);
/* Set user defined ciphers and cipher suites */
if ((ciphers != NULL) && !SSL_CTX_set_cipher_list(ctx, ciphers)) {
Tcl_AppendResult(interp, "Set ciphers failed: No valid ciphers", (char *)NULL);
SSL_CTX_free(ctx);
return NULL;
}
if ((ciphersuites != NULL) && !SSL_CTX_set_ciphersuites(ctx, ciphersuites)) {
Tcl_AppendResult(interp, "Set cipher suites failed: No valid cipher suites", (char *)NULL);
SSL_CTX_free(ctx);
return NULL;
}
/* Set automatic curve selection */
#if OPENSSL_VERSION_NUMBER < 0x10101000L
SSL_CTX_set_ecdh_auto(ctx, 1);
#endif
/* Set security level */
if (level > -1 && level < 6) {
/* SSL_set_security_level */
SSL_CTX_set_security_level(ctx, level);
}
/* Set get password callback */
SSL_CTX_set_default_passwd_cb(ctx, PasswordCallback);
SSL_CTX_set_default_passwd_cb_userdata(ctx, (void *)statePtr);
/* Set Diffie-Hellman parameters from file, or use the built-in one.
* Used by servers requiring ephemeral DH keys. */
Tcl_DStringInit(&ds);
#ifdef OPENSSL_NO_DH
|
| ︙ | ︙ | |||
2273 2274 2275 2276 2277 2278 2279 |
SSL_CTX_free(ctx);
return NULL;
}
}
}
#endif
| | | 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 |
SSL_CTX_free(ctx);
return NULL;
}
}
}
#endif
/* Set our certificate */
load_private_key = 0;
if (certfile != NULL) {
load_private_key = 1;
if (SSL_CTX_use_certificate_file(ctx, F2N(certfile, &ds), SSL_FILETYPE_PEM) <= 0) {
Tcl_DStringFree(&ds);
Tcl_AppendResult(interp, "unable to set certificate file ", certfile, ": ",
|
| ︙ | ︙ | |||
2308 2309 2310 2311 2312 2313 2314 |
GET_ERR_REASON(), (char *)NULL);
SSL_CTX_free(ctx);
return NULL;
#endif
}
}
| | | 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 |
GET_ERR_REASON(), (char *)NULL);
SSL_CTX_free(ctx);
return NULL;
#endif
}
}
/* Set our private key */
if (load_private_key) {
if (keyfile == NULL && key == NULL) {
keyfile = certfile;
}
if (keyfile != NULL) {
/* get the private key associated with this certificate */
|
| ︙ | ︙ |