aboutsummaryrefslogtreecommitdiffstats
path: root/ossl.c
diff options
context:
space:
mode:
authorGOTOU Yuuzou <gotoyuzo@notwork.org>2003-06-19 11:30:52 +0000
committerGOTOU Yuuzou <gotoyuzo@notwork.org>2003-06-19 11:30:52 +0000
commit6433b09dfb95f9b9636abad0e7e7d135bf4076ef (patch)
treedd3379be95a11ba64d75be57b4a6ed59474d687d /ossl.c
parent7af73d98e6f44fa41c50cb9c8ef133b2f9d2765e (diff)
downloadruby-openssl-history-6433b09dfb95f9b9636abad0e7e7d135bf4076ef.tar.gz
* ossl.c: should protect allback Proc not to jump over the library's stack ftame.
Diffstat (limited to 'ossl.c')
-rw-r--r--ossl.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/ossl.c b/ossl.c
index eb8c48b..48a9461 100644
--- a/ossl.c
+++ b/ossl.c
@@ -183,20 +183,44 @@ string2hex(char *buf, int buf_len, char **hexbuf, int *hexbuf_len)
/*
* our default PEM callback
*/
+static VALUE
+ossl_pem_passwd_cb0(VALUE flag)
+{
+ VALUE pass;
+
+ pass = rb_yield(flag);
+ SafeStringValue(pass);
+
+ return pass;
+}
+
int
-ossl_pem_passwd_cb(char *buf, int max_len, int verify, void *pwd)
+ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
{
- int len;
- VALUE ver;
+ int len, status;
+ VALUE rflag, pass;
- if (pwd || !rb_block_given_p()) return PEM_def_callback(buf, max_len, verify, pwd);
-
- ver = verify ? Qtrue : Qfalse;
- while (1) {
- VALUE pass = rb_yield(ver);
- SafeStringValue(pass);
+ if (pwd || !rb_block_given_p())
+ return PEM_def_callback(buf, max_len, flag, pwd);
+
+ while(1){
+ /*
+ * when the flag is nonzero, this passphrase
+ * will be used to perform encryption; otherwise it will
+ * be used to perform decryption.
+ */
+ rflag = flag ? Qtrue : Qfalse;
+ pass = rb_protect(ossl_pem_passwd_cb0, rflag, &status);
+ if(status) return -1; /* exception was raised. */
len = RSTRING(pass)->len;
- if (len < 4 || len>max_len) continue; /* 4 is OpenSSL hardcoded limit */
+ if (len < 4){ /* 4 is OpenSSL hardcoded limit */
+ rb_warning("password must be longer than 4 bytes");
+ continue;
+ }
+ if (len > max_len){
+ rb_warning("password must be shorter then %d bytes", max_len-1);
+ continue;
+ }
memcpy(buf, RSTRING(pass)->ptr, len);
break;
}