Skip to content

Commit

Permalink
Add back private key functionality and gate with isPrivate
Browse files Browse the repository at this point in the history
  • Loading branch information
aidangarske committed Dec 17, 2024
1 parent 49ec154 commit 9b583bd
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,11 @@ static int DoAsn1Key(const byte* in, word32 inSz, byte** out,
WOLFSSH_UNUSED(heap);

ret = IdentifyAsn1Key(in, inSz, isPrivate, heap, &key);
if (ret > 0) {
if (ret <= 0) {
WLOG(WS_LOG_DEBUG, "Unable to identify ASN.1 key");
}

if (ret > 0 && !isPrivate) {
long e;
byte n[RSA_MAX_SIZE]; /* TODO: Handle small stack */
word32 nSz = (word32)sizeof(n), eSz = (word32)sizeof(e);
Expand Down Expand Up @@ -1768,12 +1772,39 @@ static int DoAsn1Key(const byte* in, word32 inSz, byte** out,
}

wolfSSH_KEY_clean(key);
ret = WS_SUCCESS;
}
else if (ret > 0 && isPrivate) {
if (*out == NULL) {
newKey = (byte*)WMALLOC(inSz, heap, DYNTYPE_PRIVKEY);
if (newKey == NULL) {
ret = WS_MEMORY_E;
return ret;
}
}
else {
if (*outSz < inSz) {
WLOG(WS_LOG_DEBUG, "DER private key output size too small");
ret = WS_BUFFER_E;
return ret;
}
newKey = *out;
}

*out = newKey;
*outSz = inSz;
WMEMCPY(newKey, in, inSz);
*outType = (const byte*)IdToName(ret);
*outTypeSz = (word32)WSTRLEN((const char*)*outType);
}
else {
WLOG(WS_LOG_DEBUG, "Unable to identify ASN.1 key");
if (*out == NULL) {
WFREE(newKey, heap, DYNTYPE_PRIVKEY);
}
}

if (ret > 0)
ret = WS_SUCCESS;
return ret;
}

Expand Down

0 comments on commit 9b583bd

Please sign in to comment.