【问题标题】:Why does OpenSSL return 0 even though there's an error?为什么即使有错误,OpenSSL 也会返回 0?
【发布时间】:2013-11-10 10:28:15
【问题描述】:

我表演了

openssl rsa -check -in foo.key

收到了

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

尽管如此,

shell> 回声 $?

0

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

【问题讨论】:

  • 程序的返回码与shell无关。选择返回什么取决于程序。如果您认为 openssl 在您的情况下应该以非零返回码退出,请考虑提交错误报告(针对 openssl)。
  • 谢谢。我的问题特别是关于openssl。我想知道是否有一些标准实践、设计决策会促使 openssl 返回该返回代码,或者这可能只是其实现中的一个错误。

标签: bash openssl


【解决方案1】:

不确定这是否是一种设计选择,但如果您查看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),例如非素数。

如果RSA_check_key()返回-1,包装代码(apps/rsa.c)确实会退出并出现错误(1),但如果它返回0则不会(请参阅控制流wrt/设置@987654334 @ 和 goto end;)。

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

【讨论】:

  • @ChaimKut,你最终有没有在 OpenSSL 邮件列表中询问过这个问题?
猜你喜欢
  • 2012-12-08
  • 1970-01-01
  • 2019-07-29
  • 2013-01-19
  • 2019-04-03
  • 1970-01-01
  • 2020-03-26
  • 2010-09-09
  • 2012-07-14
相关资源
最近更新 更多