︙ | | | ︙ | |
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
*-------------------------------------------------------------------
*
* Tls_Error --
*
* Calls callback with error message.
*
* Side effects:
* The err field of the currently operative State is set
* to a string describing the SSL negotiation failure reason
*
*-------------------------------------------------------------------
*/
void
Tls_Error(
State *statePtr, /* Client state for TLS socket */
const char *msg) /* Error message */
|
|
|
|
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
*-------------------------------------------------------------------
*
* Tls_Error --
*
* Calls callback with error message.
*
* Side effects:
* The err field of the currently operative State is set to a
* string describing the SSL negotiation failure reason
*
*-------------------------------------------------------------------
*/
void
Tls_Error(
State *statePtr, /* Client state for TLS socket */
const char *msg) /* Error message */
|
︙ | | | ︙ | |
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
|
chan = Tcl_GetTopChannel(chan);
parent = Tcl_GetStackedChannel(chan);
/* Verify is a stacked channel */
if (parent == NULL) {
Tcl_AppendResult(interp, "bad channel \"", Tcl_GetChannelName(chan),
"\": not a stacked channel", (char *)NULL);
Tcl_SetErrorCode(interp, "TLS", "UNIMPORT", "CHANNEL", "INVALID", (char *)NULL);
return TCL_ERROR;
}
/* Flush any pending data */
if (Tcl_OutputBuffered(chan) > 0 && Tcl_Flush(chan) != TCL_OK) {
Tcl_AppendResult(interp, "can't flush channel", (char *)NULL);
return TCL_ERROR;
|
|
|
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
|
chan = Tcl_GetTopChannel(chan);
parent = Tcl_GetStackedChannel(chan);
/* Verify is a stacked channel */
if (parent == NULL) {
Tcl_AppendResult(interp, "bad channel \"", Tcl_GetChannelName(chan),
"\": not a stacked channel", (char *)NULL);
Tcl_SetErrorCode(interp, "TLS", "UNIMPORT", "CHANNEL", "INVALID", (char *)NULL);
return TCL_ERROR;
}
/* Flush any pending data */
if (Tcl_OutputBuffered(chan) > 0 && Tcl_Flush(chan) != TCL_OK) {
Tcl_AppendResult(interp, "can't flush channel", (char *)NULL);
return TCL_ERROR;
|
︙ | | | ︙ | |
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
|
goto cleanup;
}
}
/* Where the CA names go */
certNames = sk_X509_NAME_new_null();
if (!certNames) {
goto cleanup;
}
/* Attempt to load all certs from the PEM file */
while ((cert = PEM_read_bio_X509(bio, NULL, 0, NULL)) != NULL) {
if (X509_STORE_add_cert(store, cert) == 0) {
X509_free(cert);
ret = 0;
goto cleanup;
}
/* Copy name to stack before certificate gets freed */
name = X509_get_subject_name(cert);
if (name) {
X509_NAME *name_copy = X509_NAME_dup(name);
if (!name_copy || !sk_X509_NAME_push(certNames, name_copy)) {
X509_free(cert);
ret = 0;
goto cleanup;
}
}
X509_free(cert);
ret ++;
}
/* At least one cert was added so retain the store and CA list */
if (ret) {
if (SSL_CTX_get_cert_store(ctx) == NULL) {
SSL_CTX_set_cert_store(ctx, store);
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
|
goto cleanup;
}
}
/* Where the CA names go */
certNames = sk_X509_NAME_new_null();
if (!certNames) {
goto cleanup;
}
/* Attempt to load all certs from the PEM file */
while ((cert = PEM_read_bio_X509(bio, NULL, 0, NULL)) != NULL) {
if (X509_STORE_add_cert(store, cert) == 0) {
X509_free(cert);
ret = 0;
goto cleanup;
}
/* Copy name to stack before certificate gets freed */
name = X509_get_subject_name(cert);
if (name) {
X509_NAME *name_copy = X509_NAME_dup(name);
if (!name_copy || !sk_X509_NAME_push(certNames, name_copy)) {
X509_free(cert);
ret = 0;
goto cleanup;
}
}
X509_free(cert);
ret ++;
}
/* At least one cert was added so retain the store and CA list */
if (ret) {
if (SSL_CTX_get_cert_store(ctx) == NULL) {
SSL_CTX_set_cert_store(ctx, store);
}
|
︙ | | | ︙ | |
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
|
}
SSL_CTX_set_tmp_dh(ctx, dh);
DH_free(dh);
} else {
/* Use well known DH parameters that have built-in support in OpenSSL */
if (!SSL_CTX_set_dh_auto(ctx, 1)) {
Tcl_AppendResult(interp, "Could not enable set DH auto: ", GET_ERR_REASON(), (char *)NULL);
SSL_CTX_free(ctx);
return NULL;
}
}
}
#endif
|
|
>
|
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
|
}
SSL_CTX_set_tmp_dh(ctx, dh);
DH_free(dh);
} else {
/* Use well known DH parameters that have built-in support in OpenSSL */
if (!SSL_CTX_set_dh_auto(ctx, 1)) {
Tcl_AppendResult(interp, "Could not enable set DH auto: ", GET_ERR_REASON(),
(char *)NULL);
SSL_CTX_free(ctx);
return NULL;
}
}
}
#endif
|
︙ | | | ︙ | |
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
|
return NULL;
}
}
/* Now we know that a key and cert have been set against
* the SSL context */
if (!SSL_CTX_check_private_key(ctx)) {
Tcl_AppendResult(interp, "private key does not match the certificate public key",
(char *)NULL);
SSL_CTX_free(ctx);
return NULL;
}
}
/* Set to use the default location and file for Certificate Authority (CA) certificates.
* The default CA certificates directory is called certs in the default OpenSSL
|
|
|
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
|
return NULL;
}
}
/* Now we know that a key and cert have been set against
* the SSL context */
if (!SSL_CTX_check_private_key(ctx)) {
Tcl_AppendResult(interp, "private key does not match the certificate public key",
(char *)NULL);
SSL_CTX_free(ctx);
return NULL;
}
}
/* Set to use the default location and file for Certificate Authority (CA) certificates.
* The default CA certificates directory is called certs in the default OpenSSL
|
︙ | | | ︙ | |
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
|
return TCL_ERROR;
}
/* Make sure to operate on the topmost channel */
chan = Tcl_GetTopChannel(chan);
if (Tcl_GetChannelType(chan) != Tls_ChannelType()) {
Tcl_AppendResult(interp, "bad channel \"", Tcl_GetChannelName(chan),
"\": not a TLS channel", (char *)NULL);
Tcl_SetErrorCode(interp, "TLS", "CONNECTION", "CHANNEL", "INVALID", (char *)NULL);
return TCL_ERROR;
}
objPtr = Tcl_NewListObj(0, NULL);
/* Connection info */
|
|
|
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
|
return TCL_ERROR;
}
/* Make sure to operate on the topmost channel */
chan = Tcl_GetTopChannel(chan);
if (Tcl_GetChannelType(chan) != Tls_ChannelType()) {
Tcl_AppendResult(interp, "bad channel \"", Tcl_GetChannelName(chan),
"\": not a TLS channel", (char *)NULL);
Tcl_SetErrorCode(interp, "TLS", "CONNECTION", "CHANNEL", "INVALID", (char *)NULL);
return TCL_ERROR;
}
objPtr = Tcl_NewListObj(0, NULL);
/* Connection info */
|
︙ | | | ︙ | |
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
|
BIO_cleanup();
}
/*
*------------------------------------------------------*
*
* TlsLibInit --
*
* Initializes SSL library once per application
*
* Results:
* A standard Tcl result
*
* Side effects:
|
|
|
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
|
BIO_cleanup();
}
/*
*------------------------------------------------------*
*
* TlsLibInit --
*
* Initializes SSL library once per application
*
* Results:
* A standard Tcl result
*
* Side effects:
|
︙ | | | ︙ | |
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
|
return Tcl_PkgProvide(interp, PACKAGE_NAME, PACKAGE_VERSION);
}
/*
*-------------------------------------------------------------------
*
* Tls_SafeInit --
*
* This is a package initialization procedure for safe interps.
*
* Results:
* Same as of 'Tls_Init'
*
* Side effects:
|
|
|
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
|
return Tcl_PkgProvide(interp, PACKAGE_NAME, PACKAGE_VERSION);
}
/*
*-------------------------------------------------------------------
*
* Tls_SafeInit --
*
* This is a package initialization procedure for safe interps.
*
* Results:
* Same as of 'Tls_Init'
*
* Side effects:
|
︙ | | | ︙ | |