tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jni/native/src ssl.c sslcontext.c sslutils.c
Date Sun, 12 Jun 2005 07:33:08 GMT
mturk       2005/06/12 00:33:08

  Modified:    jni/java/org/apache/tomcat/jni SSL.java
               jni/native/include ssl_private.h
               jni/native/src ssl.c sslcontext.c sslutils.c
  Added:       jni/java/org/apache/tomcat/jni PasswordCallback.java
  Log:
  Change PasswordCallback instead BIO for obtaining passwords.
  A single global function is enough.
  
  Revision  Changes    Path
  1.18      +4 -4      jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/SSL.java
  
  Index: SSL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/SSL.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SSL.java	11 Jun 2005 18:16:42 -0000	1.17
  +++ SSL.java	12 Jun 2005 07:33:08 -0000	1.18
  @@ -220,10 +220,10 @@
        public static native int closeBIO(long bio);
   
       /**
  -     * Set global Password callback BIO for obtaining passwords.
  -     * @param bio BIO to use.
  +     * Set global Password callback for obtaining passwords.
  +     * @param callback PasswordCallback implementation to use.
        */
  -     public static native void setPasswordBIO(long bio);
  +     public static native void setPasswordCallback(PasswordCallback callback);
   
       /**
        * Set global Password for decrypting certificates and keys.
  
  
  
  1.1                  jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/PasswordCallback.java
  
  Index: PasswordCallback.java
  ===================================================================
  /*
   *  Copyright 1999-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.tomcat.jni;
  
  /** PasswordCallback Interface
   *
   * @author Mladen Turk
   * @version $Revision: 1.1 $, $Date: 2005/06/12 07:33:07 $
   */
  
  public interface PasswordCallback {
  
      /**
       * Called when the password is required
       * @param prompt Password prompt
       * @return Valid password or null
       */
      public String callback(String prompt);
  }
  
  
  
  1.27      +2 -2      jakarta-tomcat-connectors/jni/native/include/ssl_private.h
  
  Index: ssl_private.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/include/ssl_private.h,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ssl_private.h	11 Jun 2005 18:20:10 -0000	1.26
  +++ ssl_private.h	12 Jun 2005 07:33:08 -0000	1.27
  @@ -168,7 +168,7 @@
   typedef struct {
       char            password[SSL_MAX_PASSWORD_LEN];
       const char     *prompt;
  -    BIO            *bio;
  +    tcn_callback_t cb;
   } tcn_pass_cb_t;
   
   extern tcn_pass_cb_t tcn_password_callback;
  
  
  
  1.35      +21 -11    jakarta-tomcat-connectors/jni/native/src/ssl.c
  
  Index: ssl.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/ssl.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ssl.c	12 Jun 2005 07:01:03 -0000	1.34
  +++ ssl.c	12 Jun 2005 07:33:08 -0000	1.35
  @@ -113,6 +113,12 @@
       if (!ssl_initialized)
           return APR_SUCCESS;
       ssl_initialized = 0;
  +
  +    if (tcn_password_callback.cb.obj) {
  +        TCN_UNLOAD_CLASS(tcn_password_callback.cb.env,
  +                         tcn_password_callback.cb.obj);
  +    }
  +
       SSL_TMP_KEYS_FREE(RSA);
       SSL_TMP_KEYS_FREE(DH);
       /*
  @@ -693,19 +699,23 @@
       return APR_SUCCESS;
   }
   
  -TCN_IMPLEMENT_CALL(void, SSL, setPasswordBIO)(TCN_STDARGS, jlong bio)
  +TCN_IMPLEMENT_CALL(void, SSL, setPasswordCallback)(TCN_STDARGS,
  +                                                   jobject callback)
   {
  -    BIO *bio_handle   = J2P(bio, BIO *);
  +    jclass cls;
   
  -    UNREFERENCED_STDARGS;
  -    if (tcn_password_callback.bio &&
  -        tcn_password_callback.bio != bio_handle) {
  -        SSL_BIO_close(tcn_password_callback.bio);
  -        tcn_password_callback.bio = bio_handle;
  +    UNREFERENCED(o);
  +    if (tcn_password_callback.cb.obj) {
  +        TCN_UNLOAD_CLASS(tcn_password_callback.cb.env,
  +                         tcn_password_callback.cb.obj);
       }
  -    else
  -        return;
  -    SSL_BIO_doref(bio_handle);
  +    cls = (*e)->GetObjectClass(e, callback);
  +    tcn_password_callback.cb.env    = e;
  +    tcn_password_callback.cb.mid[0] = (*e)->GetMethodID(e, cls, "callback",
  +                           "(Ljava/lang/String;)Ljava/lang/String;");
  +    /* TODO: Check if method id is valid */
  +    tcn_password_callback.cb.obj    = (*e)->NewGlobalRef(e, callback);
  +
   }
   
   TCN_IMPLEMENT_CALL(void, SSL, setPassword)(TCN_STDARGS, jstring password)
  
  
  
  1.35      +1 -4      jakarta-tomcat-connectors/jni/native/src/sslcontext.c
  
  Index: sslcontext.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/sslcontext.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- sslcontext.c	11 Jun 2005 18:22:25 -0000	1.34
  +++ sslcontext.c	12 Jun 2005 07:33:08 -0000	1.35
  @@ -218,9 +218,6 @@
           if (c->bio_is && c->bio_is != bio_handle)
               SSL_BIO_close(c->bio_is);
           c->bio_is = bio_handle;
  -        if (!c->cb_data)
  -            c->cb_data = (tcn_pass_cb_t *)apr_pcalloc(c->pool, sizeof(tcn_pass_cb_t));
  -        c->cb_data->bio = bio_handle;
       }
       else
           return;
  
  
  
  1.27      +15 -4     jakarta-tomcat-connectors/jni/native/src/sslutils.c
  
  Index: sslutils.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/sslutils.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- sslutils.c	12 Jun 2005 07:01:03 -0000	1.26
  +++ sslutils.c	12 Jun 2005 07:33:08 -0000	1.27
  @@ -83,9 +83,20 @@
   {
       int rv = 0;
       data->password[0] = '\0';
  -    if (data->bio) {
  -        rv = BIO_gets(data->bio, data->password,
  -                      SSL_MAX_PASSWORD_LEN);
  +    if (data->cb.env && data->cb.obj) {
  +        JNIEnv *e = data->cb.env;
  +        jobject  o;
  +        jstring  prompt = AJP_TO_JSTRING(data->prompt);
  +        if ((o = (*e)->CallObjectMethod(e, data->cb.obj,
  +                            data->cb.mid[0], prompt))) {
  +            TCN_ALLOC_CSTRING(o);
  +            if (J2S(o)) {
  +                strncpy(data->password, J2S(o), SSL_MAX_PASSWORD_LEN);
  +                data->password[SSL_MAX_PASSWORD_LEN-1] = '\0';
  +                rv = (int)strlen(data->password);
  +            }
  +            TCN_FREE_CSTRING(o);
  +        }
       }
       else {
   #ifdef WIN32
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message