fix indentation -- no code changed.

This commit is contained in:
Moisés Guimarães
2014-09-08 21:34:07 -03:00
parent b22e3abfff
commit b2b5179392

160
src/ssl.c
View File

@@ -1292,9 +1292,9 @@ int CyaSSL_KeyPemToDer(const unsigned char* pem, int pemSz, unsigned char* buff,
if (pass) {
info->ctx = CyaSSL_CTX_new(CyaSSLv23_client_method());
if (info->ctx == NULL) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
return MEMORY_E;
}
@@ -1773,11 +1773,11 @@ int CyaSSL_Init(void)
#ifndef NO_CERTS
/* Remove PEM header/footer, convert to ASN1, store any encrypted data
/* Remove PEM header/footer, convert to ASN1, store any encrypted data
info->consumed tracks of PEM bytes consumed in case multiple parts */
int PemToDer(const unsigned char* buff, long longSz, int type,
int PemToDer(const unsigned char* buff, long longSz, int type,
buffer* der, void* heap, EncryptedInfo* info, int* eccKey)
{
{
char header[PEM_LINE_LEN];
char footer[PEM_LINE_LEN];
char* headerEnd;
@@ -1797,8 +1797,8 @@ int CyaSSL_Init(void)
if (type == CERT_TYPE || type == CA_TYPE) {
XSTRNCPY(header, "-----BEGIN CERTIFICATE-----", sizeof(header));
XSTRNCPY(footer, "-----END CERTIFICATE-----", sizeof(footer));
dynamicType = (type == CA_TYPE) ? DYNAMIC_TYPE_CA :
DYNAMIC_TYPE_CERT;
dynamicType = (type == CA_TYPE) ? DYNAMIC_TYPE_CA
: DYNAMIC_TYPE_CERT;
} else if (type == CERTREQ_TYPE) {
XSTRNCPY(header, "-----BEGIN CERTIFICATE REQUEST-----",
sizeof(header));
@@ -1870,7 +1870,7 @@ int CyaSSL_Init(void)
return SSL_BAD_FILE;
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
{
{
/* remove encrypted header if there */
char encHeader[] = "Proc-Type";
char* line = XSTRNSTR(headerEnd, encHeader, PEM_LINE_LEN);
@@ -1910,7 +1910,7 @@ int CyaSSL_Init(void)
newline++;
headerEnd = newline;
}
}
}
#endif /* OPENSSL_EXTRA || HAVE_WEBSERVER */
/* find footer */
@@ -1974,16 +1974,16 @@ int CyaSSL_Init(void)
#endif
return 0;
}
}
/* process the buffer buff, legnth sz, into ctx of format and type
/* process the buffer buff, legnth sz, into ctx of format and type
used tracks bytes consumed, userChain specifies a user cert chain
to pass during the handshake */
static int ProcessBuffer(CYASSL_CTX* ctx, const unsigned char* buff,
static int ProcessBuffer(CYASSL_CTX* ctx, const unsigned char* buff,
long sz, int format, int type, CYASSL* ssl,
long* used, int userChain)
{
{
buffer der; /* holds DER or RAW (for NTRU) */
int ret;
int dynamicType = 0;
@@ -2031,9 +2031,9 @@ int CyaSSL_Init(void)
if (format == SSL_FILETYPE_PEM) {
ret = PemToDer(buff, sz, type, &der, heap, info, &eccKey);
if (ret < 0) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
XFREE(der.buffer, heap, dynamicType);
return ret;
}
@@ -2043,11 +2043,11 @@ int CyaSSL_Init(void)
/* we may have a user cert chain, try to consume */
if (userChain && type == CERT_TYPE && info->consumed < sz) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
byte staticBuffer[1]; /* force heap usage */
#else
#else
byte staticBuffer[FILE_BUFFER_SIZE]; /* tmp chain buffer */
#endif
#endif
byte* chainBuffer = staticBuffer;
byte* shrinked = NULL; /* shrinked to size chainBuffer
* or staticBuffer */
@@ -2061,12 +2061,11 @@ int CyaSSL_Init(void)
CYASSL_MSG("Growing Tmp Chain Buffer");
bufferSz = (word32)(sz - consumed);
/* will shrink to actual size */
chainBuffer = (byte*)XMALLOC(bufferSz, heap,
DYNAMIC_TYPE_FILE);
chainBuffer = (byte*)XMALLOC(bufferSz, heap, DYNAMIC_TYPE_FILE);
if (chainBuffer == NULL) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
XFREE(der.buffer, heap, dynamicType);
return MEMORY_E;
}
@@ -2109,9 +2108,9 @@ int CyaSSL_Init(void)
CYASSL_MSG(" Error in Cert in Chain");
if (dynamicBuffer)
XFREE(chainBuffer, heap, DYNAMIC_TYPE_FILE);
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
XFREE(der.buffer, heap, dynamicType);
return ret;
}
@@ -2145,9 +2144,9 @@ int CyaSSL_Init(void)
XFREE(chainBuffer, heap, DYNAMIC_TYPE_FILE);
if (shrinked == NULL) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
XFREE(der.buffer, heap, dynamicType);
return MEMORY_E;
}
@@ -2156,9 +2155,9 @@ int CyaSSL_Init(void)
else { /* ASN1 (DER) or RAW (NTRU) */
der.buffer = (byte*) XMALLOC(sz, heap, dynamicType);
if (!der.buffer) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
return MEMORY_ERROR;
}
@@ -2237,9 +2236,9 @@ int CyaSSL_Init(void)
}
if (ret != 0) {
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
XFREE(der.buffer, heap, dynamicType);
return ret;
}
@@ -2262,8 +2261,7 @@ int CyaSSL_Init(void)
else if (type == CERT_TYPE) {
if (ssl) {
if (ssl->buffers.weOwnCert && ssl->buffers.certificate.buffer)
XFREE(ssl->buffers.certificate.buffer, heap,
dynamicType);
XFREE(ssl->buffers.certificate.buffer, heap, dynamicType);
ssl->buffers.certificate = der;
ssl->buffers.weOwnCert = 1;
}
@@ -2292,7 +2290,7 @@ int CyaSSL_Init(void)
}
if (type == PRIVATEKEY_TYPE && format != SSL_FILETYPE_RAW) {
#ifndef NO_RSA
#ifndef NO_RSA
if (!eccKey) {
/* make sure RSA key can be used */
RsaKey key;
@@ -2301,10 +2299,10 @@ int CyaSSL_Init(void)
ret = InitRsaKey(&key, 0);
if (ret != 0) return ret;
if (RsaPrivateKeyDecode(der.buffer,&idx,&key,der.length) != 0) {
#ifdef HAVE_ECC
#ifdef HAVE_ECC
/* could have DER ECC (or pkcs8 ecc), no easy way to tell */
eccKey = 1; /* so try it out */
#endif
#endif
if (!eccKey) {
FreeRsaKey(&key);
return SSL_BAD_FILE;
@@ -2315,8 +2313,8 @@ int CyaSSL_Init(void)
}
FreeRsaKey(&key);
}
#endif
#ifdef HAVE_ECC
#endif
#ifdef HAVE_ECC
if (!rsaKey) {
/* make sure ECC key can be used */
word32 idx = 0;
@@ -2334,7 +2332,7 @@ int CyaSSL_Init(void)
if (ssl)
ssl->options.haveStaticECC = 1;
}
#endif /* HAVE_ECC */
#endif /* HAVE_ECC */
}
else if (type == CERT_TYPE) {
DecodedCert cert;
@@ -2362,20 +2360,18 @@ int CyaSSL_Init(void)
break;
}
#ifdef HAVE_ECC
#ifdef HAVE_ECC
if (ctx)
ctx->pkCurveOID = cert.pkCurveOID;
if (ssl)
ssl->pkCurveOID = cert.pkCurveOID;
#endif
#endif
FreeDecodedCert(&cert);
}
return SSL_SUCCESS;
}
}
/* CA PEM file for verification, may have multiple/chain certs to process */
@@ -2437,20 +2433,20 @@ int CyaSSL_CertManagerVerifyBuffer(CYASSL_CERT_MANAGER* cm, const byte* buff,
if (format == SSL_FILETYPE_PEM) {
int eccKey = 0; /* not used */
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
EncryptedInfo* info;
#else
#else
EncryptedInfo info[1];
#endif
#endif
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
info = (EncryptedInfo*)XMALLOC(sizeof(EncryptedInfo), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (info == NULL) {
XFREE(cert, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return MEMORY_E;
}
#endif
#endif
info->set = 0;
info->ctx = NULL;
@@ -2461,9 +2457,9 @@ int CyaSSL_CertManagerVerifyBuffer(CYASSL_CERT_MANAGER* cm, const byte* buff,
if (ret == 0)
InitDecodedCert(cert, der.buffer, der.length, cm->heap);
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
}
else
InitDecodedCert(cert, (byte*)buff, (word32)sz, cm->heap);
@@ -2774,7 +2770,8 @@ int ProcessFile(CYASSL_CTX* ctx, const char* fname, int format, int type,
}
XFCLOSE(file);
if (dynamic) XFREE(myBuffer, heapHint, DYNAMIC_TYPE_FILE);
if (dynamic)
XFREE(myBuffer, heapHint, DYNAMIC_TYPE_FILE);
return ret;
}
@@ -2903,7 +2900,8 @@ int CyaSSL_CertManagerVerify(CYASSL_CERT_MANAGER* cm, const char* fname,
ret = CyaSSL_CertManagerVerifyBuffer(cm, myBuffer, sz, format);
XFCLOSE(file);
if (dynamic) XFREE(myBuffer, cm->heap, DYNAMIC_TYPE_FILE);
if (dynamic)
XFREE(myBuffer, cm->heap, DYNAMIC_TYPE_FILE);
return ret;
}
@@ -3418,7 +3416,8 @@ static int CyaSSL_SetTmpDH_file_wrapper(CYASSL_CTX* ctx, CYASSL* ssl,
}
XFCLOSE(file);
if (dynamic) XFREE(myBuffer, ctx->heap, DYNAMIC_TYPE_FILE);
if (dynamic)
XFREE(myBuffer, ctx->heap, DYNAMIC_TYPE_FILE);
return ret;
}
@@ -5686,11 +5685,11 @@ int CyaSSL_set_compression(CYASSL* ssl)
because of SSL_write behavior and because front adds may be small */
int CyaSSL_writev(CYASSL* ssl, const struct iovec* iov, int iovcnt)
{
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
byte staticBuffer[1]; /* force heap usage */
#else
#else
byte staticBuffer[FILE_BUFFER_SIZE];
#endif
#endif
byte* myBuffer = staticBuffer;
int dynamic = 0;
int sending = 0;
@@ -8387,13 +8386,13 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
if (format == SSL_FILETYPE_PEM) {
int ecc = 0;
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
EncryptedInfo* info;
#else
#else
EncryptedInfo info[1];
#endif
#endif
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
info = (EncryptedInfo*)XMALLOC(sizeof(EncryptedInfo), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (info == NULL) {
@@ -8402,7 +8401,7 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
return NULL;
}
#endif
#endif
info->set = 0;
info->ctx = NULL;
@@ -8419,9 +8418,9 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
}
}
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
}
else {
der.buffer = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_CERT);
@@ -9782,31 +9781,28 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
#ifdef OPENSSL_EXTRA
#ifdef FORTRESS
int CyaSSL_cmp_peer_cert_to_file(CYASSL* ssl, const char *fname)
{
int CyaSSL_cmp_peer_cert_to_file(CYASSL* ssl, const char *fname)
{
int ret = SSL_FATAL_ERROR;
CYASSL_ENTER("CyaSSL_cmp_peer_cert_to_file");
if (ssl != NULL && fname != NULL)
{
XFILE file = XBADFILE;
long sz = 0;
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
EncryptedInfo* info;
byte staticBuffer[1]; /* force heap usage */
#else
#else
EncryptedInfo info[1];
byte staticBuffer[FILE_BUFFER_SIZE];
#endif
#endif
byte* myBuffer = staticBuffer;
int dynamic = 0;
CYASSL_CTX* ctx = ssl->ctx;
buffer fileDer;
XFILE file = XBADFILE;
long sz = 0;
int eccKey = 0;
CYASSL_CTX* ctx = ssl->ctx;
CYASSL_X509* peer_cert = &ssl->peerCert;
#ifdef CYASSL_SMALL_STACK
EncryptedInfo* info;
#else
EncryptedInfo info[1];
#endif
buffer fileDer;
file = XFOPEN(fname, "rb");
if (file == XBADFILE)
@@ -9822,13 +9818,13 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
dynamic = 1;
}
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
info = (EncryptedInfo*)XMALLOC(sizeof(EncryptedInfo), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (info == NULL)
ret = MEMORY_E;
else
#endif
#endif
{
info->set = 0;
info->ctx = ctx;
@@ -9848,9 +9844,9 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
ret = 0;
}
#ifdef CYASSL_SMALL_STACK
#ifdef CYASSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
#endif
}
XFREE(fileDer.buffer, ctx->heap, DYNAMIC_TYPE_CERT);
@@ -9861,7 +9857,7 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
}
return ret;
}
}
#endif