Changeset 3266907


Ignore:
Timestamp:
May 29, 2016 11:47:59 AM (4 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
5cb285b, e16760d
Parents:
5439ff2
Message:

Dynamically load javax.naming classes to avoid VerifyErrors? on some Androids

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/CertUtil.java

    r5439ff2 r3266907  
    88import java.io.OutputStreamWriter;
    99import java.io.PrintWriter;
     10import java.lang.reflect.Constructor;
     11import java.lang.reflect.InvocationTargetException;
     12import java.lang.reflect.Method;
    1013import java.security.GeneralSecurityException;
    1114import java.security.InvalidKeyException;
     
    3235import java.util.Set;
    3336
    34 import javax.naming.InvalidNameException;
    35 import javax.naming.ldap.LdapName;
    36 import javax.naming.ldap.Rdn;
    3737import javax.security.auth.x500.X500Principal;
    3838
     
    200200        type = type.toUpperCase(Locale.US);
    201201        String subj = p.getName();
    202         try {
    203             LdapName name = new LdapName(subj);
    204             for (Rdn rdn : name.getRdns()) {
    205                 if (type.equals(rdn.getType().toUpperCase(Locale.US)))
    206                     return (String) rdn.getValue();
    207             }
    208         } catch (InvalidNameException ine) {}
     202        // Use reflection for this to avoid VerifyErrors on some Androids
     203        try {
     204            Class<?> ldapName = Class.forName("javax.naming.ldap.LdapName");
     205            Constructor<?> ldapCtor = ldapName.getConstructor(String.class);
     206            Object name = ldapCtor.newInstance(subj);
     207            Method getRdns = ldapName.getDeclaredMethod("getRdns");
     208            Class<?> rdnClass = Class.forName("javax.naming.ldap.Rdn");
     209            Method getType = rdnClass.getDeclaredMethod("getType");
     210            Method getValue = rdnClass.getDeclaredMethod("getValue");
     211            for (Object rdn : (List) getRdns.invoke(name)) {
     212                if (type.equals(((String) getType.invoke(rdn)).toUpperCase(Locale.US)))
     213                    return (String) getValue.invoke(rdn);
     214            }
     215        } catch (ClassNotFoundException e) {
     216        } catch (IllegalAccessException e) {
     217        } catch (InstantiationException e) {
     218        } catch (InvocationTargetException e) {
     219        } catch (NoSuchMethodException e) {
     220        }
    209221        return null;
    210222    }
  • history.txt

    r5439ff2 r3266907  
    112016-05-29 str4d
     2 * CertUtil: Dynamically load javax.naming classes to avoid
     3   VerifyErrors on some Androids
    24 * LogWriter: Dynamically load Android writer
    35
Note: See TracChangeset for help on using the changeset viewer.