6

我表演了

openssl rsa -check -in foo.key

并收到

RSA 密钥错误:dmq1 与 d 不一致

尽管如此,

外壳>回声$?

0

为什么即使出现错误,我也会收到返回码 0?

4

1 回答 1

5

不确定这是否是一种设计选择,但如果您检查OpenSSL源代码,您将观察到以下内容:

apps/rsa.c用于RSA_check_key()检查密钥的有效性。手册页告诉我们:

man RSA_check_key

描述

  This function validates RSA keys. It checks that p and q are in fact prime, and that n = p*q.
  It also checks that d*e = 1 mod (p-1*q-1), and that dmp1, dmq1 and iqmp are set correctly or are NULL.

[...]

返回值

  RSA_check_key() returns 1 if rsa is a valid RSA key, and 0 otherwise.  -1 is returned if an error occurs while checking the key.
  If the key is invalid or an error occurred, the reason code can be obtained using ERR_get_error(3).

因此,它区分了根本无法解析的-1键 ( ) 和具有无效属性的键 ( 0),例如非素数。

包装代码 ( ) 在返回时会apps/rsa.c以错误 ( 1)退出,但在RSA_check_key()返回时不会退出(请参阅控制流 wrt/ 设置和)。-10retgoto end;

在这种情况下,不出错似乎是一种刻意的选择,但我同意,这似乎很奇怪您可能想在OpenSSL邮件列表中询问,我相信那里的人可以对这种特殊行为有所了解(毕竟这可能是一个错误)。

于 2013-11-11T10:09:23.483 回答