I'm in process of updating the client to support TLS 1.3. When trying to connect to TLS 1.3 server, client is reporting "Internal error". Wireshark traces showing that server responded with Verify Certificate, Finished message. But client fails to generate the keys with following call stack -
libcrypto-1_1.dll!ASN1_get_object(const unsigned char * * pp, long * plength, int * ptag, int * pclass, long omax) Line 101
libcrypto-1_1.dll!asn1_item_embed_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it, int tag, int aclass, char opt, ASN1_TLC_st * ctx, int depth) Line 287
[Inline Frame] libcrypto-1_1.dll!ASN1_item_ex_d2i(ASN1_VALUE_st * *) Line 124
libcrypto-1_1.dll!ASN1_item_d2i(ASN1_VALUE_st * * pval, const unsigned char * * in, long len, const ASN1_ITEM_st * it) Line 114
libcrypto-1_1.dll!d2i_X509_SIG(X509_sig_st * * a, const unsigned char * * in, long len) Line 21
MyCode.dll!PrivateKeyOperationCallback(ssl_st * pSSL, unsigned int type, unsigned int rsakeysize, const unsigned char * hash, unsigned int hashlen, unsigned char * sig, unsigned int sigmaxlen, unsigned int * siglen)
[Inline Frame] MyCode.dll!My_RSA_private_encrypt1(ssl_st *)
MyCode.dll!My_RSA_private_encrypt(int flen, const unsigned char * from, unsigned char * to, rsa_st * rsa, int padding)
libcrypto-1_1.dll!pkey_rsa_sign(evp_pkey_ctx_st * ctx, unsigned char * sig, unsigned int * siglen, const unsigned char * tbs, unsigned int tbslen) Line 185
libcrypto-1_1.dll!EVP_PKEY_sign(evp_pkey_ctx_st * ctx, unsigned char * sig, unsigned int * siglen, const unsigned char * tbs, unsigned int tbslen) Line 66
libcrypto-1_1.dll!EVP_DigestSignFinal(evp_md_ctx_st * ctx, unsigned char * sigret, unsigned int * siglen) Line 148
libcrypto-1_1.dll!EVP_DigestSign(evp_md_ctx_st * ctx, unsigned char * sigret, unsigned int * siglen, const unsigned char * tbs, unsigned int tbslen) Line 170
libssl-1_1.dll!tls_construct_cert_verify(ssl_st * s, wpacket_st * pkt) Line 307
libssl-1_1.dll!write_state_machine(ssl_st * s) Line 843
libssl-1_1.dll!state_machine(ssl_st * s, int server) Line 443
libssl-1_1.dll!ossl_statem_connect(ssl_st * s) Line 250
libssl-1_1.dll!SSL_do_handshake(ssl_st * s) Line 3661
libssl-1_1.dll!SSL_connect(ssl_st * s) Line 1662
ASN1_get_object returns "Header Too Long". Same client is able to connect to same server with TLS 1.2 and even able to connect to same server from browser with TLS 1.3.
Issue is specifically with mTLS (not with TLS).
That code path is not unique to TLS 1.3, and has been present in OpenSSL / libcrypto for quite a long time.
The error is occurring because an ASN.1 object encoded in the certificate has a definite length that exceeds the length of the data provided. Either the certificate data is corrupt, or the server is not sending the correct data.
If you're implementing the TLS 1.3 client yourself it is possible that your code is not properly handling certificate encryption, leading to garbled data being sent into the ASN.1 parsing code paths. Without further information (Wireshark dumps and the certificate itself) it is impossible to know what the specific error is.
Related
I am willing to transfer data from unsigned char hash[512 + 1] to char res[512 + 1] safely.
My C hashing library MHASH returns a result so it can be printed as listed below.
for (int i = 0; i < size /*hash block size*/; i++)
printf("%.2x", hash[i]); // which is unsigned char - it prints normal hash characters in range [a-z,0-9]
printf("\n");
I am willing to do something like that (see below).
const char* res = (const char *)hash; // "hash" to "res"
printf("%s\n", res); // print "res" (which is const char*) - if i do this, unknown characters are printed
I know the difference between char and unsigned char, but I don't know how to transfer data. Any answer would be greatly appreciated, thanks in advance. But please do not recommend me C++ (STD) code, I am working on a project that is not STD-linked.
Given that the contents of the unsigned char array are printable characters, you can always safely convert it to char. Either a hardcopy with memcpy or a pointer reference as in the code you have already written.
I'm guessing that the actual problem here is that the unsigned char array contents are not actually printable characters, but integers in some format. You'll have to convert them from integer to ASCII letters. How to do this depends on the format of the data, which isn't clear in your question.
Assuming the following:
#define ARR_SIZE (512 + 1)
unsigned char hash[ARR_SIZE];
char res[ARR_SIZE];
/* filling up hash here. */
Just do:
#include <string.h>
...
memcpy(res, hash, ARR_SIZE);
Well, thank you guys for your answers, but unfortunately nothing worked yet. I am now sticking with the code below.
char res[(sizeof(hash) * 2) + 1] = { '\0' };
char * pPtr = res;
for (int i = 0; i < hashBlockSize; i++)
sprintf(pPtr + (i * 2), "%.2x", hash[i]);
return (const char *)pPtr;
Until there is any other much more performant way to get this done. It's right, my question is strongly related to MHASH Library.
I'm now moving a big software from OWL to MFC, most of the mission has been done, but I face alot of problems like this one when the application is closing this exception arises
When I clicked break the debuger lead me to this
that was the call stack
msdart.dll!_UMSEnterCSWraper() Unknown
msado15.dll!ATL::AtlModuleGetClassObject(struct ATL::_ATL_MODULE *,struct _GUID const &,struct _GUID const &,void * *) Unknown
msado15.dll!ATL::CComModule::GetClassObject(struct _GUID const &,struct _GUID const &,void * *) Unknown
msado15.dll!_DllGetClassObject#12() Unknown
ole32.dll!CClassCache::CDllPathEntry::DllGetClassObject(const _GUID & rclsid, const _GUID & riid, IUnknown * * ppUnk, int fMakeValid) Line 3317 C++
ole32.dll!CClassCache::CDllFnPtrMoniker::BindToObject(const _GUID & riid, void * * ppvResult) C++
ole32.dll!CClassCache::SearchForLoadedClass(const ACTIVATION_PROPERTIES & ap, CClassCache::CDllClassEntry * * ppDCE) C++
ole32.dll!ICoCreateInstanceEx(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, unsigned long dwActvFlags, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn) Line 1163 C++
ole32.dll!CComActivator::DoCreateInstance(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn) Line 332 C++
ole32.dll!CoCreateInstanceEx(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, tagMULTI_QI * pResults) Line 157 C++
ole32.dll!CoCreateInstance(const _GUID & rclsid, IUnknown * pUnkOuter, unsigned long dwContext, const _GUID & riid, void * * ppv) Line 110 C++
> DBCore.dll!_com_ptr_t<_com_IIID<ADODB::_Command,&_GUID_b08400bd_f9d1_4d02_b856_71d5dba123e9> >::CreateInstance(const _GUID & rclsid, IUnknown * pOuter, unsigned long dwClsContext) Line 586 C++
DBCore.dll!TADOCommand::Init(TADOConnection * connection) Line 32 C++
DBCore.dll!TADOCommand::TADOCommand(TADOConnection * connection) Line 8 C++
AmnDbase.dll!TQuery::Init() Line 335 C++
AmnDbase.dll!TQuery::TQuery(const TDatabase * db, TTable * Tbl) Line 304 C++
AmnDbase.dll!TDirectQuery::TDirectQuery(const TDatabase * db) Line 932 C++
AmnDbase.dll!CommitUnsavedTransactions(TDatabase * db) Line 674 C++
AmnDbase.dll!TDatabase::Disconnect() Line 427 C++
AmnDbase.dll!TDatabase::CloseDb() Line 455 C++
AmnDbase.dll!TDatabase::Close() Line 417 C++
AmnLib2.dll!TStoreFile::Close() Line 3275 C++
AmnLib2.dll!TStoreFile::~TStoreFile() Line 1040 C++
AmnLib2.dll!`GetStoreFile'::`2'::`dynamic atexit destructor for 'StoreFile''() C++
AmnLib2.dll!_CRT_INIT(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 415 C
AmnLib2.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 526 C
AmnLib2.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 476 C
this is the code that called the CreateInstance
/// Init the command instance.
void TADOCommand::Init( TADOConnection* connection)
{
m_CmdText = "";
m_nRecordsAffected = 0;
m_Command = NULL;
m_ResultSet = NULL;
m_CmdConnection = NULL;
m_CmdRecordset = NULL;
if( connection->IsNull())
return;
m_Command.CreateInstance( __uuidof( Command));
SetConnection( connection);
SetCommandTimeOut( connection->GetCommandTimeout());
}
I want the code to stay working without changing any code especialy in the database layer is this due to call of couninitialize from MFC?? how can I detect that or solve this issue?
and the m_Command was defined as
_CommandPtr m_Command;
and it is com interface first it is set to null then call CreateInstance it works fine each time unless the last time it fails with this exception
The code seams to be executed when your DLL is unloaded or loaded, as far as I can see in the callstack.
When this is "loading code" the question arrises: Why is the LDL loaded again.
But using COM in DllMain is no good at all. See here
COM should never be used inside a DllMain code.
I suppose that your DLL is unloaded after the MFC already called CoUninitialize. Or your DLL is reloaded by some code, that shouldn't be executed in the shut down of your application.
I have a function:
-(void)ADPCMDecode:(char *)indata : (short *)outdata :(long)len {
indata is a char and the function does pointer arithmetic to iterate for a length of len, modifying outdata, which is a short and I will need to do pointer arithmetic to get the values from it.
I am attempting to call the function using:
const char *modulatedBytes1 = [modulatedAudio bytes];
char *modulatedBytes [] = modulatedBytes1;
unsigned int moduleatedLength = [modulatedAudio length];
short *decompressedBytes = NULL;
[self ADPCMDecode:modulatedBytes :decompressedBytes :moduleatedLength];
DLog(#"%hi",decompressedBytes[1]);
I get a BAD ACCESS error on this line: *outp++ = valprev; within the function, because I am passing a constant char * instead of a char *
How should I call the function, and how would I get the output from it?
I have no background in C, which is why I do not understand how to go about doing this.
Here is the C only version of the same question:
https://pastee.org/d3y3z
I have only been able to recreate this bug using xCode 4.6. Everything works as expected using Xcode 4.5
The issue is myVal has the correct bit structure to represent an int val of -1. However, it is showing a value of 4294967295 which is the value of the same bit structure if represented by an unsigned int. You'll notice that if i cast myVal to an int it will show the correct value. This is strange, because the enum should be an int to being with.
here is a screen shot showing the value of all of my variables in the debugger at the end of main. http://cl.ly/image/190s0a1P1b1t
typedef enum : int {
BTEnumValueNegOne = -1,
BTEnumValueZero = 0,
BTEnumValueOne = 1,
}BTEnumValue;
int main(int argc, const char * argv[])
{
#autoreleasepool {
//on this line of code myVal is 0
BTEnumValue myVal = BTEnumValueZero;
//we are adding -1 to the value of zero
myVal += BTEnumValueNegOne;
//at this moment myVal has the exact bit stucture
//of a signed int at -1, but it is displaying it
//as a unsigned int, so its value is 4294967295
//however, if i cast the enum (which should already
//be an int with a signing) to an int, it displays
//the correct value of -1
int myIntVal = (int)myVal;
}
return 0;
}
The new, preferred way to declare enum types is with the NS_ENUM macro as explained in this post: http://nshipster.com/ns_enum-ns_options/
we have couple of C applications which talk using the shared memory. first application adds the message and the second one always reads from the shared memory.
struct messagestruct {
unsigned int sessionid;
uint8_t message[16]; //unsigned 8bit int
}__attribute__ ((__packed__));
we need to have 3 sessions (for 3 users). so defined shared memory size as
#define SHARED_SIZE ( 3 * sizeof(messagestruct)) + sizeof(int)
we access the shared memory as
int sesskey = ftok("/path/to/a/file", "B");
int shmemoryid = shmget(sesskey, SHARED_SIZE, 0666 | IPC_CREAT);
during copying structs to shared memory, valgrind reports error (invalid write size 1)
void *shmaddr = shmat(shmemoryid, NULL, 0);
int *sessnum;
struct messagestruct *msgstruct;
sessnum = (int *)shmaddr;
msgstruct = (struct messagestruct*)((void*) shmaddr + sizeof(int));
memcpy(shmaddr, currentsessionsstruct, SHARED_SIZE); //-->valgrind error invalid write size 1
thanks for any helpful info.
memcpy(shmaddr, currentsessionsstruct, SHARED_SIZE);
You are copying 3 * sizeof(messagestruct) + sizeof(int). I believe you want to copy only sizeof(currentsessionstruct).