Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > BOOK: Beginning Cryptography with Java
|
BOOK: Beginning Cryptography with Java
This is the forum to discuss the Wrox book Beginning Cryptography with Java by David Hook; ISBN: 9780764596339
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Cryptography with Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2013, 03:25 AM
Registered User
 
Join Date: Apr 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default X.509 Certificat with optional AlgorithmIdentifier.Parameters Field

Hello,

I'm currently struggling with creating a X.509 certificate that includes the optional 'Parameters' field for the AlgorithmIdentifier in the TBSCertificate. This field should contain the selected elliptic curve for the algorithm (SHA224WithECDSA). Creating the certificate without the optional parameter field works fines but I could not figure out how to add the Parameters field... so I wrote my own Signer class that just extends the "JcaContentSignerBuilder" and changes the 'AlgorithmIdentifier' which also works fine but then I get an error that says: "no such algorithm: 1.2.840.10045.4.3.1 for provider BC". So here is the code for the instantiation of my Signer class and the creation and checking of the certificate:

Code:
       ContentSigner contentSigner = new TESTECCContentSigner("SHA224withECDSA").setProvider("BC").build((ECPrivateKey)ca_key_pair_.getPrivate());

       // Generate signed certificate
       X509Certificate X509cert =  new JcaX509CertificateConverter().setProvider("BC").getCertificate(v3CertBuilder.build(contentSigner));
        
       // Verify certificate (just as test)
       X509cert.checkValidity(new Date());
       X509cert.verify(ca_key_pair_.getPublic());
And here is the code of the Signer class, which alters the "sigAlgID" in a cruel way... which was just for testing the concept before I write the complete class on my own ;)

Code:
public class TESTECCContentSigner extends JcaContentSignerBuilder implements
		ContentSigner {
	
	public TESTECCContentSigner(String arg0) {
		super(arg0);
		
		//Change field sigAlgID
		try {
		      final Field field = JcaContentSignerBuilder.class.getDeclaredField("sigAlgId");
		      field.setAccessible(true);
		      field.set(this, this.getAlgorithmIdentifier());
		    } catch (SecurityException ex) {
		      ex.printStackTrace();
		    } catch (NoSuchFieldException ex) {
		      ex.printStackTrace();
		    } catch (IllegalArgumentException ex) {
		      ex.printStackTrace();
		    } catch (IllegalAccessException ex) {
		      ex.printStackTrace();
		    }

		// TODO Auto-generated constructor stub
	}
	
	@Override
	public ContentSigner build(java.security.PrivateKey privateKey) throws OperatorCreationException
	{
		ContentSigner tmp = super.build(privateKey);
		
		return tmp;
	}

	@Override
	public AlgorithmIdentifier getAlgorithmIdentifier() {

		ASN1Sequence algIdentifierWithParam;
		try {
			algIdentifierWithParam = (ASN1Sequence) ASN1Sequence.fromByteArray(new byte[]{
					0x30, 0x11,
					   0x06, 0x08,
					      0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x01
					      ,0x06, 0x05,
					      0x2b, 0x81, 0x04, 0x00, 0x1b  // 27 = 1b
					});
			
			AlgorithmIdentifier myAlgID = new AlgorithmIdentifier(algIdentifierWithParam);
			
			return myAlgID;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		assert(false);
		return null;
	}
Depending on the content of the algIdentifierWithParam = (ASN1Sequence) ASN1Sequence.fromByteArray(new byte[]{ ... }, I get no error for:

0x30, 0x0a,
0x06, 0x08,
0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x01

but when I write this (which I would need):

0x30, 0x11,
0x06, 0x08,
0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x01,
0x06, 0x05,
0x2b, 0x81, 0x04, 0x00, 0x1b

I get this "no such algorithm: 1.2.840.10045.4.3.1 for provider BC". I use the "*-jdk16-146.jar" fiesl of bouncy castle.

Thank you for your help,

Hannes
 
Old April 4th, 2013, 12:21 AM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

No parameters are defined for the algorithm OID you are trying to use. At least not in X9.62. Hence, when you try to verify the signature the JCA tries to assign the parameters to initialise the signature verifier and discovers it can't, throwing an exception.

I have added some further comments on dev-crypto.

Regards,

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
Functions with multiple optional parameters baseliner XSLT 6 December 7th, 2009 05:31 PM
Alternative to optional parameters in C# asptwodev BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 November 12th, 2007 03:47 AM
Are Optional Parameters supported in Access 2000? howardb1 Access VBA 2 April 26th, 2006 10:01 AM
optional parameters in SP yuqlin BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 7 July 13th, 2004 03:28 PM
Optional Stored Proc Parameters? VBAHole22 SQL Server 2000 3 August 13th, 2003 11:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.