Topic: RsaUnPad error, bad formatting
Hi,
I am trying to create a HTTPS server using wolfssl and picoTCP on a pic32mz device. I already have the server running. However, when a browser try to connect to the webserver on the board I have the follwing set of messages:
Initializing pico stack
Protocol ipv4 registered (layer: 3).
Protocol icmp4 registered (layer: 4).
Protocol igmp registered (layer: 4).
Protocol udp registered (layer: 4).
Protocol tcp registered (layer: 4).
Assigned ipv4 192.168.0.150 to device virt-eth
wolfSSL Entering wolfSSL_Init
wolfSSL Entering WOLFSSL_CTX_new_ex
wolfSSL Entering wolfSSL_CertManagerNew
wolfSSL Leaving WOLFSSL_CTX_new, return 0
wolfSSL Entering wolfSSL_CTX_use_certificate_buffer
wolfSSL Entering PemToDer
Checking cert signature type
wolfSSL Entering GetExplicitVersion
wolfSSL Entering GetMyVersion
wolfSSL Entering GetSerialNumber
Got Cert Header
wolfSSL Entering GetAlgoId
wolfSSL Entering GetObjectId()
Got Algo ID
Getting Cert Name
Getting Cert Name
Got Subject Name
wolfSSL Entering GetAlgoId
wolfSSL Entering GetObjectId()
Got Key
Not ECDSA cert signature
wolfSSL Entering wolfSSL_CTX_use_PrivateKey_buffer
wolfSSL Entering PemToDer
wolfSSL Entering GetMyVersionen0: link up, 100Mbps, full duplexNew connection received
wolfSSL Entering SSL_new
wolfSSL Leaving SSL_new, return 0
wolfSSL Entering wolfSSL_set_using_nonblock
wolfSSL Entering SSL_accept()
wolfSSL error occurred, error = -323
wolfSSL Entering SSL_accept()
wolfSSL error occurred, error = -323
New connection received
wolfSSL Entering SSL_new
wolfSSL Leaving SSL_new, return 0
wolfSSL Entering wolfSSL_set_using_nonblock
wolfSSL Entering SSL_accept()
wolfSSL error occurred, error = -323
wolfSSL Entering SSL_accept()
wolfSSL error occurred, error = -323
wolfSSL Entering SSL_accept()
growing input bufferreceived record layer msg
wolfSSL Entering DoHandShakeMsg()
wolfSSL Entering DoHandShakeMsgType
processing client hello
Matched No Compression
wolfSSL Entering MatchSuite
wolfSSL Entering VerifyServerSuite
Requires RSA
Verified suite validity
wolfSSL Leaving DoHandShakeMsgType(), return 0
wolfSSL Leaving DoHandShakeMsg(), return 0
accept state ACCEPT_CLIENT_HELLO_DONE
accept state ACCEPT_FIRST_REPLY_DONE
growing output bufferShrinking output buffer
accept state SERVER_HELLO_SENT
growing output bufferShrinking output buffer
accept state CERT_SENT
wolfSSL Entering SendCertificateStatus
accept state CERT_STATUS_SENT
wolfSSL Entering SendServerKeyExchange
Using ephemeral ECDH
wolfSSL Entering EccMakeKey
wolfSSL Leaving EccMakeKey, return 0
wolfSSL Entering GetMyVersion
growing output bufferwolfSSL Entering RsaSign
wolfSSL Leaving RsaSign, return 0
wolfSSL Entering VerifyRsaSign
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
wolfSSL Leaving VerifyRsaSign, return -201
wolfSSL Leaving SendServerKeyExchange, return -201
wolfSSL error occurred, error = -201
wolfSSL Entering SSL_accept()
wolfSSL Entering SendServerKeyExchange
Using ephemeral ECDH
wolfSSL Entering GetMyVersion
wolfSSL Entering RsaSign
wolfSSL Leaving RsaSign, return 0
wolfSSL Entering VerifyRsaSign
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
wolfSSL Leaving VerifyRsaSign, return -201
wolfSSL Leaving SendServerKeyExchange, return -201
wolfSSL error occurred, error = -201
wolfSSL Entering SSL_accept()
growing input bufferreceived record layer msg
wolfSSL Entering DoHandShakeMsg()
wolfSSL Entering DoHandShakeMsgType
processing client hello
Matched No Compression
wolfSSL Entering MatchSuite
wolfSSL Entering VerifyServerSuite
Requires RSA
Verified suite validity
wolfSSL Leaving DoHandShakeMsgType(), return 0
wolfSSL Leaving DoHandShakeMsg(), return 0
accept state ACCEPT_CLIENT_HELLO_DONE
accept state ACCEPT_FIRST_REPLY_DONE
growing output bufferShrinking output buffer
accept state SERVER_HELLO_SENT
growing output bufferShrinking output buffer
accept state CERT_SENT
wolfSSL Entering SendCertificateStatus
accept state CERT_STATUS_SENT
wolfSSL Entering SendServerKeyExchange
Using ephemeral ECDH
wolfSSL Entering EccMakeKey
wolfSSL Leaving EccMakeKey, return 0
wolfSSL Entering GetMyVersion
growing output bufferwolfSSL Entering RsaSign
wolfSSL Leaving RsaSign, return 0
wolfSSL Entering VerifyRsaSign
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
wolfSSL Leaving VerifyRsaSign, return -201
wolfSSL Leaving SendServerKeyExchange, return -201
wolfSSL error occurred, error = -201
wolfSSL Entering SSL_accept()
wolfSSL Entering SendServerKeyExchange
Using ephemeral ECDH
wolfSSL Entering GetMyVersion
wolfSSL Entering RsaSign
wolfSSL Leaving RsaSign, return 0
wolfSSL Entering VerifyRsaSign
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
wolfSSL Leaving VerifyRsaSign, return -201
wolfSSL Leaving SendServerKeyExchange, return -201
wolfSSL error occurred, error = -201
wolfSSL Entering SSL_accept()
wolfSSL Entering SendServerKeyExchange
Using ephemeral ECDH
wolfSSL Entering GetMyVersion
wolfSSL Entering RsaSign
wolfSSL Leaving RsaSign, return 0
wolfSSL Entering VerifyRsaSign
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
wolfSSL Leaving VerifyRsaSign, return -201
wolfSSL Leaving SendServerKeyExchange, return -201
wolfSSL error occurred, error = -201
wolfSSL Entering SSL_accept()
wolfSSL Entering SendServerKeyExchange
Using ephemeral ECDH
wolfSSL Entering GetMyVersion
wolfSSL Entering RsaSign
wolfSSL Leaving RsaSign, return 0
wolfSSL Entering VerifyRsaSign
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
wolfSSL Leaving VerifyRsaSign, return -201
wolfSSL Leaving SendServerKeyExchange, return -201
wolfSSL error occurred, error = -201
The browser returns a timeout error. On the log messages, it appears that this is the cause: "RsaUnPad error, bad formatting".
I could reproduce the same error on a simpler application. The rsa_test() presented bellow is part of the original rsa_test() call obtained from wolfcrypt/test/test.c.
int rsa_test(void)
{
byte* tmp;
size_t bytes;
RsaKey key;
WC_RNG rng;
word32 idx = 0;
int ret;
byte in[] = "Everyone gets Friday off.";
word32 inLen = (word32)XSTRLEN((char*)in);
byte out[256];
byte plain[256];
tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (tmp == NULL)
return -40;
XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
bytes = sizeof_client_key_der_1024;
ret = wc_InitRsaKey_ex(&key, HEAP_HINT, devId);
if (ret != 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -39;
}
ret = wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes);
if (ret != 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -41;
}
ret = wc_InitRng(&rng);
if (ret != 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -42;
}
ret = wc_RsaPublicEncrypt(in, inLen, out, sizeof(out), &key, &rng);
if (ret < 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -43;
}
idx = ret; /* save off encrypted length */
ret = wc_RsaPrivateDecrypt(out, idx, plain, sizeof(plain), &key);
printf("\n%d", ret);
if (ret < 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -44;
}
return 0;
}
int main()
{
uint8_t mac[6];
uint32_t timer = 0;
/* Obtain the ethernet MAC address */
// eth_mac(mac);
/* const char *ipaddr="192.168.0.150";
uint16_t port_be = 0;*/
wolfSSL_Debugging_ON();
wolfCrypt_Init();
if (CheckCtcSettings() != 1)
printf("\nBuild vs runtime math mismatch\n", -1234);
if (CheckFastMathSettings() != 1)
printf("\nBuild vs runtime fastmath FP_MAX_BITS mismatch\n", -1235);
//interrupt_register(irq_timer, GUEST_TIMER_INT);
int32_t ret = rsa_test();
printf("\nret %d", ret);
return 0;
}
The output log message of this code is:
wolfSSL Entering GetMyVersion
wolfSSL Using RSA PKCSV15 padding
RsaUnPad error, bad formatting
I am compiling the wolfssl library with the following defines:
-DNO_DH -DWC_NO_RSA_OAEP -DUSE_FAST_MATH -DWOLFSSL_CERT_EXT -DWOLFSSL_DTLS -DNO_PSK -DCTYPE_USER -DOPENSSL_EXTRA -DWOLFSSL_LOG_PRINTF -DDEBUG_WOLFSSL -DNO_WOLFSSL_MEMORY -DWOLFSSL_PICOTCP -DNO_WRITEV -DNO_ERROR_STRINGS -DSMALL_SESSION_CACHE -DNO_FILESYSTEM -DNO_MD4 -DNO_DES3 -DPICOTCP -DHAVE_ECC -DSINGLE_THREADED -DWOLFSSL_USER_IO -DUSER_TIME -DXTIME=time -DXTOUPPER=toupper -DXISALPHA=isalpha -DXTOLOWER=tolower
Looking into the RsaUnPad() and RsaPad() function calls I couldn't figure out what is happening. It appears that I have some issue with RSA encrypt/decrypt.
I really apreciate if anyone could give a hint about this issue.
Regards