Giter Site home page Giter Site logo

Awful message for wrong password about openssl HOT 3 CLOSED

ruby avatar ruby commented on May 20, 2024
Awful message for wrong password

from openssl.

Comments (3)

zzak avatar zzak commented on May 20, 2024

Doing a quick search of the source shows us that this error message was implemented in the gem, so we can change it:

git grep 'PUB key nor PRIV key'
ext/openssl/ossl_pkey_dsa.c:248:            ossl_raise(eDSAError, "Neither PUB key nor PRIV key");
ext/openssl/ossl_pkey_rsa.c:247:            ossl_raise(eRSAError, "Neither PUB key nor PRIV key");

from openssl.

rhenium avatar rhenium commented on May 20, 2024

Raising more accurate exception is not impossible - if OpenSSL's error queue contains PEM_R_BAD_DECRYPT, then the passphrase must be wrong.

diff --git a/ext/openssl/ossl_pkey_rsa.c b/ext/openssl/ossl_pkey_rsa.c
index f1b4f04..218f8f5 100644
--- a/ext/openssl/ossl_pkey_rsa.c
+++ b/ext/openssl/ossl_pkey_rsa.c
@@ -239,6 +239,13 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
    in = ossl_obj2bio(arg);
    rsa = PEM_read_bio_RSAPrivateKey(in, NULL, ossl_pem_passwd_cb, (void *)pass);
    if (!rsa) {
+       long e;
+       while ((e = ERR_get_error())) {
+       if (ERR_GET_REASON(e) == PEM_R_BAD_DECRYPT) {
+           BIO_free(in);
+           ossl_raise(eRSAError, "passphrase invalid");
+       }
+       }
        OSSL_BIO_reset(in);
        rsa = PEM_read_bio_RSA_PUBKEY(in, NULL, NULL, NULL);
    }

But I don't know if I can rely on the 'error reason'. Is it stable enough?

from openssl.

rhenium avatar rhenium commented on May 20, 2024

I'm closing this for now. Unfortunately, I can't come up with a better and simple way to achieve this.

from openssl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.