commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "john (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CODEC-135) Null Pointer Exception
Date Wed, 21 Mar 2012 12:53:39 GMT

    [ https://issues.apache.org/jira/browse/CODEC-135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13234323#comment-13234323
] 

john  commented on CODEC-135:
-----------------------------

03-21 18:15:54.779: E/AndroidRuntime(608): FATAL EXCEPTION: main
03-21 18:15:54.779: E/AndroidRuntime(608): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.ams/com.ams.CertificateParserTestActivity}: java.lang.NullPointerException
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.os.Looper.loop(Looper.java:137)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at java.lang.reflect.Method.invokeNative(Native
Method)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at java.lang.reflect.Method.invoke(Method.java:511)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at dalvik.system.NativeStart.main(Native Method)
03-21 18:15:54.779: E/AndroidRuntime(608): Caused by: java.lang.NullPointerException
03-21 18:15:54.779: E/AndroidRuntime(608): 	at com.ams.certparser.CertificateParserUtil.getCertType(CertificateParserUtil.java:111)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at com.ams.CertificateParserTestActivity.onCreate(CertificateParserTestActivity.java:22)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.Activity.performCreate(Activity.java:4465)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-21 18:15:54.779: E/AndroidRuntime(608): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-21 18:15:54.779: E/AndroidRuntime(608): 	... 11 more

                
> Null Pointer Exception
> ----------------------
>
>                 Key: CODEC-135
>                 URL: https://issues.apache.org/jira/browse/CODEC-135
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Android Application Development
>            Reporter: john 
>   Original Estimate: 12h
>  Remaining Estimate: 12h
>
> I am trying to parse a certificate(.pfx).But I am getting following exception while parsing
the certificate.
> CertificateException:org.apache.harmony.security.asn1.ASN1Exception: DER:
> only definite length encoding MUST be user.
> {code}
> package com.ams;
> import java.io.BufferedInputStream;
> import java.io.FileInputStream;
> import java.security.KeyStore;
> import java.security.KeyStoreException;
> import java.security.cert.CertificateFactory;
> import java.security.cert.X509Certificate;
> import java.util.Enumeration;
> import javax.security.cert.Certificate;
> import android.content.Context;
> import android.util.Log;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.widget.Toast;
> public class CertificateComponent   {
> 	private static final String TAG = "CertificateParser";
> 	public static final String PFX = "sdcard/AC350.pfx";
> 	public static final String CER = "sdcard/test.cer";
> 	X509Certificate cert;
> 	FileInputStream in;
> 	Context ctx; 
> 	private Button Pkcs12Button;
> 	private Button CertButton;
> 	public void click(View v) {
> 		try {
> 			if (v.getId() == R.id.pkcs12_button) {
> 				String password = "TZ96dtbx";
> 				KeyStore ks = KeyStore.getInstance("PKCS12");
> 				 in= new FileInputStream(PFX);
> 				// byte[] p12 = readFile(PFX);
> 				 in.close();
> 				ks.load(in, password.toCharArray());
> 				Enumeration<String> aliasesEnum = ks.aliases();
> 				// Log.i(TAG, "certificate details:" + aliasesEnum);
> 				
> 				String alias = (String) aliasesEnum.nextElement();
> 				// System.out.println("Alias: " + alias);
> 				cert = (X509Certificate) ks.getCertificate(alias);
> 				
> 				while (aliasesEnum.hasMoreElements()) {
> 					
> 					Log.i(TAG, "Type:" + cert.getType());
> 					Log.i(TAG, "Key Algorithm:"
> 							+ cert.getPublicKey().getAlgorithm());
> 					Log.i(TAG, "Version:" + cert.getVersion());
> 					Log.i(TAG, "Issuer DN:" + cert.getIssuerDN());
> 					Log.i(TAG, "Subject:" + cert.getSubjectDN());
> 					Log.i(TAG, "Valid From:" + cert.getNotBefore());
> 					Log.i(TAG, "Valid Till:" + cert.getNotAfter());
> 					Log.i(TAG, "Public Key:" + cert.getPublicKey());
> 					Log.i(TAG, "Serial Number:" + cert.getSerialNumber());
> 					Log.i(TAG, "Signature:" + cert.getSignature());
> 					
> 					String message = "Check Logcat For Certificate Details";
> 					Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show();
> 				}
> 			} else if (v.getId() == R.id.cert_button) {
> 				// String filename = "sdcard/test_b64.cer";
> 				in = new FileInputStream(CER);
> 				BufferedInputStream bf = new BufferedInputStream(in);
> 				CertificateFactory cf = CertificateFactory.getInstance("X.509");
> 				
> 				cert = (X509Certificate) cf.generateCertificate(bf);
> 				
> 				while (bf.available() > 0) {
> 					
> 					Log.i(TAG, "Type:" + cert.getType());
> 					Log.i(TAG, "Key Algorithm:"
> 							+ cert.getPublicKey().getAlgorithm());
> 					Log.i(TAG, "Version:" + cert.getVersion());
> 					Log.i(TAG, "Issuer DN:" + cert.getIssuerDN());
> 					Log.i(TAG, "Subject:" + cert.getSubjectDN());
> 					Log.i(TAG, "Valid From:" + cert.getNotBefore());
> 					Log.i(TAG, "Valid Till:" + cert.getNotAfter());
> 					Log.i(TAG, "Public Key:" + cert.getPublicKey());
> 					Log.i(TAG, "Serial Number:" + cert.getSerialNumber());
> 					Log.i(TAG, "Signature:" + cert.getSignature());
> 					// Log.i(TAG, "certificate details:" + cert);
> 				}
> 				in.close();
> 				String message = "Check Logcat For Certificate Details";
> 				Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show();
> 			}
> 		} catch (KeyStoreException e) {
> 			Log.i(TAG, " KeyStoreException " + e.getMessage());
> 		} catch (Exception e) {
> 			// TODO Auto-generated catch block
> 			Log.i(TAG, " Exception: " + e.getMessage());
> 		}
> 		
> 		 
> 		
> 	}
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message