Skip to content

Commit 62317d5

Browse files
committed
Use key file only for RSA
1 parent 6f45731 commit 62317d5

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tools/xcrypt.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,25 @@ static void XCrypt_DisplayUsage(const char *pName)
178178

179179
static xbool_t XCrypt_GetKey(xcrypt_args_t *pArgs, xcrypt_key_t *pKey)
180180
{
181-
if (xstrused(pArgs->sKeyFile))
181+
if (xstrused(pArgs->sKey))
182182
{
183-
pKey->nLength = XPath_Read(pArgs->sKeyFile, (uint8_t*)pArgs->sKey, sizeof(pArgs->sKey));
184-
if (pKey->nLength && pKey->eCipher == XC_AES) pKey->nLength = pArgs->nKeySize;
185-
pArgs->sKeyFile[0] = XSTR_NUL;
183+
pKey->nLength = xstrncpy(pKey->sKey, sizeof(pKey->sKey), pArgs->sKey);
184+
if (pKey->eCipher == XC_AES) pKey->nLength = pArgs->nKeySize;
185+
return pKey->nLength ? XTRUE : XFALSE;
186186
}
187187

188-
if (xstrused(pArgs->sKey))
188+
char sKey[XSTR_MID];
189+
sKey[0] = XSTR_NUL;
190+
191+
#ifdef XCRYPT_USE_SSL
192+
if (xstrused(pArgs->sKeyFile) &&
193+
(pKey->eCipher == XC_RS256 || pKey->eCipher == XC_RSAPR || pKey->eCipher == XC_RSA))
194+
pKey->nLength = XPath_Read(pArgs->sKeyFile, (uint8_t*)sKey, sizeof(sKey));
195+
#endif
196+
197+
if (xstrused(sKey))
189198
{
190-
pKey->nLength = xstrncpy(pKey->sKey, sizeof(pKey->sKey), pArgs->sKey);
199+
pKey->nLength = xstrncpy(pKey->sKey, sizeof(pKey->sKey), sKey);
191200
if (pKey->eCipher == XC_AES) pKey->nLength = pArgs->nKeySize;
192201
return pKey->nLength ? XTRUE : XFALSE;
193202
}
@@ -203,7 +212,6 @@ static xbool_t XCrypt_GetKey(xcrypt_args_t *pArgs, xcrypt_key_t *pKey)
203212

204213
if (!pArgs->bDecrypt || pArgs->bForce)
205214
{
206-
char sKey[XSTR_MIN];
207215
printf("Re-enter keyword for the cipher '%s': ", pCipher);
208216

209217
if (!XCLI_GetPass(NULL, sKey, sizeof(sKey)))

0 commit comments

Comments
 (0)