commons-issues mailing list archives

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

     [ https://issues.apache.org/jira/browse/CODEC-135?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Sebb updated CODEC-135:
-----------------------

    Description: 
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}


  was:
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.

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());
		}
		
		 
		
	}
}



    
> 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