@@ -2403,7 +2403,10 @@ int wolfSSH_ProcessBuffer(WOLFSSH_CTX* ctx,
24032403 if (der == NULL)
24042404 return WS_MEMORY_E;
24052405
2406- ret = wc_CertPemToDer(in, inSz, der, inSz, wcType);
2406+ if (type == BUFTYPE_PRIVKEY)
2407+ ret = wc_KeyPemToDer(in, inSz, der, inSz, NULL);
2408+ else
2409+ ret = wc_CertPemToDer(in, inSz, der, inSz, wcType);
24072410 if (ret < 0) {
24082411 WFREE(der, heap, dynamicType);
24092412 return WS_BAD_FILE_E;
@@ -7040,11 +7043,33 @@ static int DoUserAuthRequestRsa(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
70407043 }
70417044
70427045 if (ret == WS_SUCCESS) {
7043- if (publicKeyTypeSz != pk->publicKeyTypeSz
7044- || publicKeyType == NULL
7045- || WMEMCMP(publicKeyType, pk->publicKeyType,
7046- publicKeyTypeSz) != 0) {
7047-
7046+ int sigTypeOk = 0;
7047+ if (publicKeyType != NULL) {
7048+ if (publicKeyTypeSz == pk->publicKeyTypeSz
7049+ && WMEMCMP(publicKeyType, pk->publicKeyType,
7050+ publicKeyTypeSz) == 0) {
7051+ sigTypeOk = 1;
7052+ }
7053+ #ifdef WOLFSSH_CERTS
7054+ else if (pk->publicKeyTypeSz == 14
7055+ && WMEMCMP(pk->publicKeyType,
7056+ "x509v3-ssh-rsa", 14) == 0) {
7057+ /* RFC 6187 Section 5: the signature uses the underlying
7058+ * RSA algorithm, not the X.509 key type name. */
7059+ if ((publicKeyTypeSz == 7
7060+ && WMEMCMP(publicKeyType, "ssh-rsa", 7) == 0)
7061+ || (publicKeyTypeSz == 12
7062+ && WMEMCMP(publicKeyType,
7063+ "rsa-sha2-256", 12) == 0)
7064+ || (publicKeyTypeSz == 12
7065+ && WMEMCMP(publicKeyType,
7066+ "rsa-sha2-512", 12) == 0)) {
7067+ sigTypeOk = 1;
7068+ }
7069+ }
7070+ #endif
7071+ }
7072+ if (!sigTypeOk) {
70487073 WLOG(WS_LOG_DEBUG,
70497074 "Signature's type does not match public key type");
70507075 ret = WS_INVALID_ALGO_ID;
@@ -7179,10 +7204,33 @@ static int DoUserAuthRequestRsaCert(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
71797204 }
71807205
71817206 if (ret == WS_SUCCESS) {
7182- if (publicKeyTypeSz != pk->publicKeyTypeSz
7183- || WMEMCMP(publicKeyType, pk->publicKeyType,
7184- publicKeyTypeSz) != 0) {
7185-
7207+ int sigTypeOk = 0;
7208+ if (publicKeyType != NULL
7209+ && publicKeyTypeSz == pk->publicKeyTypeSz
7210+ && WMEMCMP(publicKeyType, pk->publicKeyType,
7211+ publicKeyTypeSz) == 0) {
7212+ sigTypeOk = 1;
7213+ }
7214+ #ifdef WOLFSSH_CERTS
7215+ else if (publicKeyType != NULL
7216+ && pk->publicKeyTypeSz == 14
7217+ && WMEMCMP(pk->publicKeyType,
7218+ "x509v3-ssh-rsa", 14) == 0) {
7219+ /* RFC 6187 Section 5: the signature uses the underlying
7220+ * RSA algorithm, not the X.509 key type name. */
7221+ if ((publicKeyTypeSz == 7
7222+ && WMEMCMP(publicKeyType, "ssh-rsa", 7) == 0)
7223+ || (publicKeyTypeSz == 12
7224+ && WMEMCMP(publicKeyType,
7225+ "rsa-sha2-256", 12) == 0)
7226+ || (publicKeyTypeSz == 12
7227+ && WMEMCMP(publicKeyType,
7228+ "rsa-sha2-512", 12) == 0)) {
7229+ sigTypeOk = 1;
7230+ }
7231+ }
7232+ #endif
7233+ if (!sigTypeOk) {
71867234 WLOG(WS_LOG_DEBUG,
71877235 "Signature's type does not match public key type");
71887236 ret = WS_INVALID_ALGO_ID;
@@ -12667,8 +12715,20 @@ int SendKexDhReply(WOLFSSH* ssh)
1266712715 * add it to the hash and then add K. */
1266812716 if (ret == WS_SUCCESS) {
1266912717 sigBlockSz = (LENGTH_SZ * 2) + sigKeyBlock_ptr->pubKeyNameSz + sigSz;
12670- payloadSz = MSG_ID_SZ + (LENGTH_SZ * 3) +
12671- sigKeyBlock_ptr->sz + fSz + fPad + sigBlockSz;
12718+ #ifdef WOLFSSH_CERTS
12719+ if (sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_SSH_RSA
12720+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP256
12721+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP384
12722+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP521) {
12723+ payloadSz = MSG_ID_SZ + (LENGTH_SZ * 2) +
12724+ sigKeyBlock_ptr->sz + fSz + fPad + sigBlockSz;
12725+ }
12726+ else
12727+ #endif
12728+ {
12729+ payloadSz = MSG_ID_SZ + (LENGTH_SZ * 3) +
12730+ sigKeyBlock_ptr->sz + fSz + fPad + sigBlockSz;
12731+ }
1267212732 ret = PreparePacket(ssh, payloadSz);
1267312733 }
1267412734
@@ -12678,15 +12738,28 @@ int SendKexDhReply(WOLFSSH* ssh)
1267812738
1267912739 output[idx++] = msgId;
1268012740
12681- /* Copy the key block size into the buffer */
12682- c32toa(sigKeyBlock_ptr->sz, output + idx);
12683- idx += LENGTH_SZ;
12741+ #ifdef WOLFSSH_CERTS
12742+ if (sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_SSH_RSA
12743+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP256
12744+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP384
12745+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP521) {
12746+ /* BuildRFC6187Info writes the complete K_S including
12747+ * the outer length and key type name. Skip common header. */
12748+ }
12749+ else
12750+ #endif
12751+ {
12752+ /* Copy the key block size into the buffer */
12753+ c32toa(sigKeyBlock_ptr->sz, output + idx);
12754+ idx += LENGTH_SZ;
1268412755
12685- /* Copy the key name into the buffer */
12686- c32toa(sigKeyBlock_ptr->pubKeyFmtNameSz, output + idx);
12687- idx += LENGTH_SZ;
12688- WMEMCPY(output + idx, sigKeyBlock_ptr->pubKeyFmtName, sigKeyBlock_ptr->pubKeyFmtNameSz);
12689- idx += sigKeyBlock_ptr->pubKeyFmtNameSz;
12756+ /* Copy the key name into the buffer */
12757+ c32toa(sigKeyBlock_ptr->pubKeyFmtNameSz, output + idx);
12758+ idx += LENGTH_SZ;
12759+ WMEMCPY(output + idx, sigKeyBlock_ptr->pubKeyFmtName,
12760+ sigKeyBlock_ptr->pubKeyFmtNameSz);
12761+ idx += sigKeyBlock_ptr->pubKeyFmtNameSz;
12762+ }
1269012763
1269112764 /* add host public key */
1269212765 switch (sigKeyBlock_ptr->pubKeyFmtId) {
0 commit comments