1 13 14 package se.anatom.ejbca.ca.caadmin; 15 16 import java.security.cert.X509Certificate ; 17 import java.util.Arrays ; 18 19 import javax.naming.Context ; 20 import javax.naming.NamingException ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.log4j.Logger; 25 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionHome; 26 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionRemote; 27 import org.ejbca.core.model.ca.caadmin.X509CAInfo; 28 import org.ejbca.core.model.log.Admin; 29 30 35 public class TestRenewCA extends TestCase { 36 private static Logger log = Logger.getLogger(TestCAs.class); 37 38 private ICAAdminSessionRemote cacheAdmin; 39 private static ICAAdminSessionHome cacheHome; 40 41 private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER); 42 43 48 public TestRenewCA(String name) { 49 super(name); 50 } 51 52 protected void setUp() throws Exception { 53 54 log.debug(">setUp()"); 55 56 if (cacheAdmin == null) { 57 if (cacheHome == null) { 58 Context jndiContext = getInitialContext(); 59 Object obj1 = jndiContext.lookup("CAAdminSession"); 60 cacheHome = (ICAAdminSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, ICAAdminSessionHome.class); 61 } 62 63 cacheAdmin = cacheHome.create(); 64 } 65 66 log.debug("<setUp()"); 67 } 68 69 protected void tearDown() throws Exception { 70 } 71 72 private Context getInitialContext() throws NamingException { 73 log.debug(">getInitialContext"); 74 75 Context ctx = new javax.naming.InitialContext (); 76 log.debug("<getInitialContext"); 77 78 return ctx; 79 } 80 81 86 public void test01renewCA() throws Exception { 87 log.debug(">test01renewCA()"); 88 89 X509CAInfo info = (X509CAInfo) cacheAdmin.getCAInfo(admin, "TEST"); 90 X509Certificate orgcert = (X509Certificate ) info.getCertificateChain().iterator().next(); 91 92 cacheAdmin.renewCA(admin,info.getCAId(),null,false); 93 X509CAInfo newinfo = (X509CAInfo) cacheAdmin.getCAInfo(admin, "TEST"); 94 X509Certificate newcertsamekeys = (X509Certificate ) newinfo.getCertificateChain().iterator().next(); 95 assertTrue(!orgcert.getSerialNumber().equals(newcertsamekeys.getSerialNumber())); 96 byte[] orgkey = orgcert.getPublicKey().getEncoded(); 97 byte[] samekey = newcertsamekeys.getPublicKey().getEncoded(); 98 assertTrue(Arrays.equals(orgkey,samekey)); 99 assertTrue(newcertsamekeys.getNotAfter().after(orgcert.getNotAfter())); 101 102 cacheAdmin.renewCA(admin,info.getCAId(),null,true); 103 X509CAInfo newinfo2 = (X509CAInfo) cacheAdmin.getCAInfo(admin, "TEST"); 104 X509Certificate newcertnewkeys = (X509Certificate ) newinfo2.getCertificateChain().iterator().next(); 105 assertTrue(!orgcert.getSerialNumber().equals(newcertnewkeys.getSerialNumber())); 106 byte[] newkey = newcertnewkeys.getPublicKey().getEncoded(); 107 assertFalse(Arrays.equals(orgkey,newkey)); 108 109 log.debug("<test01renewCA()"); 110 } 111 112 } 113 | Popular Tags |