mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
Remove the BIO method custom... its not compat. Fix bio->ptr to be void*
.
This commit is contained in:
66
src/bio.c
66
src/bio.c
@ -185,8 +185,8 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len)
|
||||
|
||||
while (bio != NULL && ret >= 0) {
|
||||
/* check for custom read */
|
||||
if (bio && bio->method->custom && bio->method->custom->readCb) {
|
||||
ret = bio->method->custom->readCb(bio, (char*)buf, len);
|
||||
if (bio->method && bio->method->readCb) {
|
||||
ret = bio->method->readCb(bio, (char*)buf, len);
|
||||
}
|
||||
|
||||
/* formating data */
|
||||
@ -442,8 +442,8 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
|
||||
|
||||
while (bio != NULL && ret >= 0) {
|
||||
/* check for custom write */
|
||||
if (bio && bio->method->custom && bio->method->custom->writeCb) {
|
||||
ret = bio->method->custom->writeCb(bio, (const char*)data, len);
|
||||
if (bio->method && bio->method->writeCb) {
|
||||
ret = bio->method->writeCb(bio, (const char*)data, len);
|
||||
}
|
||||
|
||||
/* check for formating */
|
||||
@ -557,9 +557,8 @@ long wolfSSL_BIO_ctrl(WOLFSSL_BIO *bio, int cmd, long larg, void *parg)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_ctrl");
|
||||
|
||||
if (bio && bio->method && bio->method->custom &&
|
||||
bio->method->custom->ctrlCb) {
|
||||
return bio->method->custom->ctrlCb(bio, cmd, larg, parg);
|
||||
if (bio && bio->method && bio->method->ctrlCb) {
|
||||
return bio->method->ctrlCb(bio, cmd, larg, parg);
|
||||
}
|
||||
|
||||
switch(cmd) {
|
||||
@ -637,8 +636,8 @@ int wolfSSL_BIO_gets(WOLFSSL_BIO* bio, char* buf, int sz)
|
||||
}
|
||||
|
||||
/* check if is custom method */
|
||||
if (bio->method->custom && bio->method->custom->getsCb) {
|
||||
return bio->method->custom->getsCb(bio, buf, sz);
|
||||
if (bio->method && bio->method->getsCb) {
|
||||
return bio->method->getsCb(bio, buf, sz);
|
||||
}
|
||||
|
||||
switch (bio->type) {
|
||||
@ -757,8 +756,8 @@ int wolfSSL_BIO_puts(WOLFSSL_BIO* bio, const char* buf)
|
||||
}
|
||||
|
||||
/* check if is custom method */
|
||||
if (bio->method->custom && bio->method->custom->putsCb) {
|
||||
return bio->method->custom->putsCb(bio, buf);
|
||||
if (bio->method && bio->method->putsCb) {
|
||||
return bio->method->putsCb(bio, buf);
|
||||
}
|
||||
|
||||
sz = (int)XSTRLEN(buf);
|
||||
@ -1391,7 +1390,6 @@ long wolfSSL_BIO_set_nbio(WOLFSSL_BIO* bio, long on)
|
||||
WOLFSSL_BIO_METHOD *wolfSSL_BIO_meth_new(int type, const char *name)
|
||||
{
|
||||
WOLFSSL_BIO_METHOD* meth;
|
||||
WOLFSSL_BIO_METHOD_CUSTOM* custom;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_new");
|
||||
|
||||
@ -1403,19 +1401,8 @@ WOLFSSL_BIO_METHOD *wolfSSL_BIO_meth_new(int type, const char *name)
|
||||
}
|
||||
XMEMSET(meth, 0, sizeof(WOLFSSL_BIO_METHOD));
|
||||
meth->type = (byte)type;
|
||||
XSTRNCPY(meth->name, name, MAX_BIO_METHOD_NAME - 1);
|
||||
|
||||
custom = (WOLFSSL_BIO_METHOD_CUSTOM*)XMALLOC(
|
||||
sizeof(WOLFSSL_BIO_METHOD_CUSTOM), NULL, DYNAMIC_TYPE_OPENSSL);
|
||||
if (custom == NULL) {
|
||||
WOLFSSL_MSG("Error allocating memory for WOLFSSL_BIO_METHOD_CUSTOM");
|
||||
wolfSSL_BIO_meth_free(meth);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XMEMSET(custom, 0, sizeof(WOLFSSL_BIO_METHOD_CUSTOM));
|
||||
meth->custom = custom;
|
||||
|
||||
XSTRNCPY(custom->name, name, MAX_BIO_METHOD_NAME - 1);
|
||||
return meth;
|
||||
}
|
||||
|
||||
@ -1424,9 +1411,6 @@ void wolfSSL_BIO_meth_free(WOLFSSL_BIO_METHOD *biom)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_free");
|
||||
if (biom) {
|
||||
if (biom->custom) {
|
||||
XFREE(biom->custom, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||
}
|
||||
XFREE(biom, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||
}
|
||||
}
|
||||
@ -1436,8 +1420,8 @@ int wolfSSL_BIO_meth_set_write(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_write_cb biom_write)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_set_write");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->writeCb = biom_write;
|
||||
if (biom) {
|
||||
biom->writeCb = biom_write;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
@ -1448,8 +1432,8 @@ int wolfSSL_BIO_meth_set_read(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_read_cb biom_read)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_set_read");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->readCb = biom_read;
|
||||
if (biom) {
|
||||
biom->readCb = biom_read;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
@ -1460,8 +1444,8 @@ int wolfSSL_BIO_meth_set_puts(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_puts_cb biom_puts)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_set_puts");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->putsCb = biom_puts;
|
||||
if (biom) {
|
||||
biom->putsCb = biom_puts;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
@ -1472,8 +1456,8 @@ int wolfSSL_BIO_meth_set_gets(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_gets_cb biom_gets)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_set_gets");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->getsCb = biom_gets;
|
||||
if (biom) {
|
||||
biom->getsCb = biom_gets;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
@ -1484,8 +1468,8 @@ int wolfSSL_BIO_meth_set_ctrl(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_get_ctrl_cb biom_ctrl)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_set_ctrl");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->ctrlCb = biom_ctrl;
|
||||
if (biom) {
|
||||
biom->ctrlCb = biom_ctrl;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
@ -1496,8 +1480,8 @@ int wolfSSL_BIO_meth_set_create(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_create_cb biom_create)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_meth_set_create");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->createCb = biom_create;
|
||||
if (biom) {
|
||||
biom->createCb = biom_create;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
@ -1508,8 +1492,8 @@ int wolfSSL_BIO_meth_set_destroy(WOLFSSL_BIO_METHOD *biom,
|
||||
wolfSSL_BIO_meth_destroy_cb biom_destroy)
|
||||
{
|
||||
WOLFSSL_STUB("wolfSSL_BIO_meth_set_destroy");
|
||||
if (biom && biom->custom) {
|
||||
biom->custom->freeCb = biom_destroy;
|
||||
if (biom) {
|
||||
biom->freeCb = biom_destroy;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
return WOLFSSL_FAILURE;
|
||||
|
64
src/ssl.c
64
src/ssl.c
@ -13951,7 +13951,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
|
||||
WOLFSSL_ENTER("BIO_f_buffer");
|
||||
meth.type = WOLFSSL_BIO_BUFFER;
|
||||
meth.custom = NULL;
|
||||
|
||||
return &meth;
|
||||
}
|
||||
@ -13973,7 +13972,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_s_bio");
|
||||
bio_meth.type = WOLFSSL_BIO_BIO;
|
||||
bio_meth.custom = NULL;
|
||||
|
||||
return &bio_meth;
|
||||
}
|
||||
@ -13986,7 +13984,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_s_file");
|
||||
file_meth.type = WOLFSSL_BIO_FILE;
|
||||
file_meth.custom = NULL;
|
||||
|
||||
return &file_meth;
|
||||
}
|
||||
@ -13999,7 +13996,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_f_ssl");
|
||||
meth.type = WOLFSSL_BIO_SSL;
|
||||
meth.custom = NULL;
|
||||
|
||||
return &meth;
|
||||
}
|
||||
@ -14011,7 +14007,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_s_socket");
|
||||
meth.type = WOLFSSL_BIO_SOCKET;
|
||||
meth.custom = NULL;
|
||||
|
||||
return &meth;
|
||||
}
|
||||
@ -14099,8 +14094,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
}
|
||||
|
||||
/* check if is custom method */
|
||||
if (method->custom) {
|
||||
method->custom->createCb(bio);
|
||||
if (method->createCb) {
|
||||
method->createCb(bio);
|
||||
}
|
||||
}
|
||||
return bio;
|
||||
@ -14173,8 +14168,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
}
|
||||
|
||||
/* call custom set free callback */
|
||||
if (bio->method->custom && bio->method->custom->freeCb) {
|
||||
bio->method->custom->freeCb(bio);
|
||||
if (bio->method && bio->method->freeCb) {
|
||||
bio->method->freeCb(bio);
|
||||
}
|
||||
|
||||
/* remove from pair by setting the paired bios pair to NULL */
|
||||
@ -17698,7 +17693,7 @@ WOLFSSL_X509* wolfSSL_X509_d2i(WOLFSSL_X509** x509, const byte* in, int len)
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/* not an openssl compatibility function - getting for derCert */
|
||||
const byte* wolfSSL_X509_get_der(WOLFSSL_X509* x509, int* outSz)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_X509_get_der");
|
||||
@ -21118,7 +21113,6 @@ WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_mem(void)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_s_mem");
|
||||
meth.type = WOLFSSL_BIO_MEMORY;
|
||||
meth.custom = NULL;
|
||||
|
||||
return &meth;
|
||||
}
|
||||
@ -21130,7 +21124,6 @@ WOLFSSL_BIO_METHOD* wolfSSL_BIO_f_base64(void)
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_BIO_f_base64");
|
||||
meth.type = WOLFSSL_BIO_BASE64;
|
||||
meth.custom = NULL;
|
||||
|
||||
return &meth;
|
||||
}
|
||||
@ -35437,29 +35430,38 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
||||
|
||||
cert->version = (int)wolfSSL_X509_get_version(x509);
|
||||
|
||||
#ifdef WOLFSSL_ALT_NAMES
|
||||
if ((x509->notBefore.length + 2) < CTC_DATE_SIZE) {
|
||||
cert->beforeDate[0] = x509->notBefore.type;
|
||||
cert->beforeDate[1] = x509->notBefore.length;
|
||||
XMEMCPY(&cert->beforeDate[2], x509->notBefore.data,
|
||||
x509->notBefore.length);
|
||||
cert->beforeDateSz = x509->notBefore.length + 2;
|
||||
#ifdef WOLFSSL_ALT_NAMES
|
||||
if (x509->notBefore.length > 0) {
|
||||
if ((x509->notBefore.length + 2) < CTC_DATE_SIZE) {
|
||||
cert->beforeDate[0] = x509->notBefore.type;
|
||||
cert->beforeDate[1] = x509->notBefore.length;
|
||||
XMEMCPY(&cert->beforeDate[2], x509->notBefore.data,
|
||||
x509->notBefore.length);
|
||||
cert->beforeDateSz = x509->notBefore.length + 2;
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("Not before date too large");
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("Not before date too large");
|
||||
return WOLFSSL_FAILURE;
|
||||
cert->beforeDateSz = 0;
|
||||
}
|
||||
|
||||
if ((x509->notAfter.length + 2) < CTC_DATE_SIZE) {
|
||||
cert->afterDate[0] = x509->notAfter.type;
|
||||
cert->afterDate[1] = x509->notAfter.length;
|
||||
XMEMCPY(&cert->afterDate[2], x509->notAfter.data,
|
||||
x509->notAfter.length);
|
||||
cert->afterDateSz = x509->notAfter.length + 2;
|
||||
if (x509->notAfter.length > 0) {
|
||||
if ((x509->notAfter.length + 2) < CTC_DATE_SIZE) {
|
||||
cert->afterDate[0] = x509->notAfter.type;
|
||||
cert->afterDate[1] = x509->notAfter.length;
|
||||
XMEMCPY(&cert->afterDate[2], x509->notAfter.data,
|
||||
x509->notAfter.length);
|
||||
cert->afterDateSz = x509->notAfter.length + 2;
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("Not after date too large");
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("Not after date too large");
|
||||
return WOLFSSL_FAILURE;
|
||||
cert->afterDateSz = 0;
|
||||
}
|
||||
|
||||
/* copy over alt names */
|
||||
@ -35480,7 +35482,7 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
||||
}
|
||||
cert->altNamesSz = idx;
|
||||
}
|
||||
#endif
|
||||
#endif /* WOLFSSL_ALT_NAMES */
|
||||
|
||||
cert->sigType = wolfSSL_X509_get_signature_type(x509);
|
||||
cert->keyType = x509->pubKeyOID;
|
||||
|
10
src/wolfio.c
10
src/wolfio.c
@ -125,10 +125,9 @@ int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx)
|
||||
return WOLFSSL_CBIO_ERR_GENERAL;
|
||||
}
|
||||
|
||||
if (ssl->biord->method && ssl->biord->method->custom &&
|
||||
ssl->biord->method->custom->readCb) {
|
||||
if (ssl->biord->method && ssl->biord->method->readCb) {
|
||||
WOLFSSL_MSG("Calling custom biord");
|
||||
recvd = ssl->biord->method->custom->readCb(ssl->biord, buf, sz);
|
||||
recvd = ssl->biord->method->readCb(ssl->biord, buf, sz);
|
||||
if (recvd < 0 && recvd != WOLFSSL_CBIO_ERR_WANT_READ)
|
||||
return WOLFSSL_CBIO_ERR_GENERAL;
|
||||
return recvd;
|
||||
@ -179,10 +178,9 @@ int BioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx)
|
||||
return WOLFSSL_CBIO_ERR_GENERAL;
|
||||
}
|
||||
|
||||
if (ssl->biowr->method && ssl->biowr->method->custom &&
|
||||
ssl->biowr->method->custom->writeCb) {
|
||||
if (ssl->biowr->method && ssl->biowr->method->writeCb) {
|
||||
WOLFSSL_MSG("Calling custom biowr");
|
||||
sent = ssl->biowr->method->custom->writeCb(ssl->biowr, buf, sz);
|
||||
sent = ssl->biowr->method->writeCb(ssl->biowr, buf, sz);
|
||||
if (sent < 0) {
|
||||
return WOLFSSL_CBIO_ERR_GENERAL;
|
||||
}
|
||||
|
17
tests/api.c
17
tests/api.c
@ -21806,13 +21806,20 @@ static void test_wolfSSL_X509_sign(void)
|
||||
|
||||
ret = X509_sign(x509, priv, EVP_sha256());
|
||||
|
||||
/* Valid case - size should be 768 */
|
||||
#ifdef USE_CERT_BUFFERS_1024
|
||||
AssertIntEQ(ret, 768);
|
||||
#else
|
||||
AssertIntEQ(ret, 798);
|
||||
#if 0
|
||||
/* example for writting to file */
|
||||
XFILE tmpFile = XFOPEN("./signed.der", "wb");
|
||||
if (tmpFile) {
|
||||
int derSz = 0;
|
||||
const byte* der = wolfSSL_X509_get_der(x509, &derSz);
|
||||
XFWRITE(der, 1, derSz, tmpFile);
|
||||
}
|
||||
XFCLOSE(tmpFile);
|
||||
#endif
|
||||
|
||||
/* Valid case - size should be 798 */
|
||||
AssertIntEQ(ret, 798);
|
||||
|
||||
X509_NAME_free(name);
|
||||
EVP_PKEY_free(priv);
|
||||
EVP_PKEY_free(pub);
|
||||
|
@ -430,8 +430,12 @@ typedef long (*wolfSSL_BIO_meth_get_ctrl_cb)(WOLFSSL_BIO*, int, long, void*);
|
||||
typedef int (*wolfSSL_BIO_meth_create_cb)(WOLFSSL_BIO*);
|
||||
typedef int (*wolfSSL_BIO_meth_destroy_cb)(WOLFSSL_BIO*);
|
||||
|
||||
/* wolfSSL BIO_METHOD type */
|
||||
#ifndef MAX_BIO_METHOD_NAME
|
||||
#define MAX_BIO_METHOD_NAME 256
|
||||
typedef struct WOLFSSL_BIO_METHOD_CUSTOM {
|
||||
#endif
|
||||
struct WOLFSSL_BIO_METHOD {
|
||||
byte type; /* method type */
|
||||
char name[MAX_BIO_METHOD_NAME];
|
||||
|
||||
wolfSSL_BIO_meth_puts_cb putsCb;
|
||||
@ -444,12 +448,6 @@ typedef struct WOLFSSL_BIO_METHOD_CUSTOM {
|
||||
wolfSSL_BIO_meth_create_cb createCb;
|
||||
|
||||
wolfSSL_BIO_meth_get_ctrl_cb ctrlCb;
|
||||
} WOLFSSL_BIO_METHOD_CUSTOM;
|
||||
|
||||
/* wolfSSL BIO_METHOD type */
|
||||
struct WOLFSSL_BIO_METHOD {
|
||||
byte type; /* method type */
|
||||
WOLFSSL_BIO_METHOD_CUSTOM* custom;
|
||||
};
|
||||
|
||||
/* wolfSSL BIO type */
|
||||
@ -467,7 +465,7 @@ struct WOLFSSL_BIO {
|
||||
WOLFSSL_BIO* next; /* next in chain */
|
||||
WOLFSSL_BIO* pair; /* BIO paired with */
|
||||
void* heap; /* user heap hint */
|
||||
byte* ptr; /* memory buffer */
|
||||
void* ptr; /* memory buffer */
|
||||
void* usrCtx; /* user set pointer */
|
||||
char* infoArg; /* BIO callback argument */
|
||||
wolf_bio_info_cb infoCb; /* BIO callback */
|
||||
|
Reference in New Issue
Block a user