===================================================================== Found a 100 line (266 tokens) duplication in the following files: Starting at line 162 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/ExtendedX509V3CertificateGenerator.java Starting at line 128 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/ExtendedX509V2CRLGenerator.java } /** * Set the signature algorithm. This can be either a name or an OID, names * are treated as case insensitive. * * @param signatureAlgorithm string representation of the algorithm name. */ public void setSignatureAlgorithm( String signatureAlgorithm) { this.signatureAlgorithm = signatureAlgorithm; try { sigAlgId = new AlgorithmIdentifier( ExtendedX509Util.getAlgorithmOID(signatureAlgorithm), ExtendedX509Util.getAlgorithmParameters(signatureAlgorithm)); } catch (Exception e) { throw new IllegalArgumentException("Unknown signature type requested"); } tbsGen.setSignature(sigAlgId); } /** * add a given extension field for the standard extensions tag (tag 3) */ public void addExtension( String OID, boolean critical, DEREncodable value) { this.addExtension(new DERObjectIdentifier(OID), critical, value); } /** * add a given extension field for the standard extensions tag (tag 0) */ public void addExtension( DERObjectIdentifier OID, boolean critical, DEREncodable value) { if (extensions == null) { extensions = new Hashtable(); extOrdering = new Vector(); } ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); try { dOut.writeObject(value); } catch (IOException e) { throw new IllegalArgumentException("error encoding value: " + e); } this.addExtension(OID, critical, bOut.toByteArray()); } /** * add a given extension field for the standard extensions tag (tag 0) */ public void addExtension( String OID, boolean critical, byte[] value) { this.addExtension(new DERObjectIdentifier(OID), critical, value); } /** * add a given extension field for the standard extensions tag (tag 0) */ public void addExtension( DERObjectIdentifier OID, boolean critical, byte[] value) { if (extensions == null) { extensions = new Hashtable(); extOrdering = new Vector(); } extensions.put(OID, new X509Extension(critical, new DEROctetString(value))); extOrdering.addElement(OID); } /** * generate an X509 CRL, based on the current issuer and subject * using the default provider "BC". */ public X509CRL generateX509CRL( ===================================================================== Found a 74 line (230 tokens) duplication in the following files: Starting at line 285 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/ExtendedX509CRLObject.java Starting at line 173 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/ExtendedX509CertificateObject.java throw new CertificateEncodingException(e.toString()); } } public byte[] getSignature() { return c.getSignature().getBytes(); } /** * return a more "meaningful" representation for the signature algorithm used in * the certficate. */ public String getSigAlgName() { Provider prov = Security.getProvider("BC"); String algName = prov.getProperty("Alg.Alias.Signature." + this.getSigAlgOID()); if (algName != null) { return algName; } Provider[] provs = Security.getProviders(); // // search every provider looking for a real algorithm // for (int i = 0; i != provs.length; i++) { algName = provs[i].getProperty("Alg.Alias.Signature." + this.getSigAlgOID()); if (algName != null) { return algName; } } return this.getSigAlgOID(); } /** * return the object identifier for the signature. */ public String getSigAlgOID() { return c.getSignatureAlgorithm().getObjectId().getId(); } /** * return the signature parameters, or null if there aren't any. */ public byte[] getSigAlgParams() { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); if (c.getSignatureAlgorithm().getParameters() != null) { try { DEROutputStream dOut = new DEROutputStream(bOut); dOut.writeObject(c.getSignatureAlgorithm().getParameters()); } catch (Exception e) { throw new RuntimeException("exception getting sig parameters " + e); } return bOut.toByteArray(); } return null; } public boolean[] getIssuerUniqueID() ===================================================================== Found a 33 line (209 tokens) duplication in the following files: Starting at line 200 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/CACertServlet.java Starting at line 79 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/GetCRLServlet.java } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { log.debug(">doPost()"); doGet(req, res); log.debug("doGet()"); // Check if authorized EjbcaWebBean ejbcawebbean= (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) req.getSession().getAttribute("ejbcawebbean"); if ( ejbcawebbean == null ){ try { ejbcawebbean = (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean"); } catch (ClassNotFoundException exc) { throw new ServletException(exc.getMessage()); }catch (Exception exc) { throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean", exc); } req.getSession().setAttribute("ejbcawebbean", ejbcawebbean); } try{ ejbcawebbean.initialize(req, "/ca_functionality/basic_functions"); } catch(Exception e){ throw new java.io.IOException("Authorization Denied"); } String issuerdn = null; ===================================================================== Found a 28 line (192 tokens) duplication in the following files: Starting at line 197 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/CACertServlet.java Starting at line 86 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/CACertReqServlet.java } catch( Exception e ) { throw new ServletException(e); } } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { log.debug(">doPost()"); doGet(req, res); log.debug("doGet()"); // Check if authorized EjbcaWebBean ejbcawebbean= (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) req.getSession().getAttribute("ejbcawebbean"); if ( ejbcawebbean == null ){ try { ejbcawebbean = (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean"); } catch (ClassNotFoundException exc) { throw new ServletException(exc.getMessage()); }catch (Exception exc) { throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean", exc); } req.getSession().setAttribute("ejbcawebbean", ejbcawebbean); } ===================================================================== Found a 25 line (178 tokens) duplication in the following files: Starting at line 79 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/GetCRLServlet.java Starting at line 89 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/CACertReqServlet.java } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { log.debug(">doPost()"); doGet(req, res); log.debug("doGet()"); // Check if authorized EjbcaWebBean ejbcawebbean= (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) req.getSession().getAttribute("ejbcawebbean"); if ( ejbcawebbean == null ){ try { ejbcawebbean = (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean"); } catch (ClassNotFoundException exc) { throw new ServletException(exc.getMessage()); }catch (Exception exc) { throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean", exc); } req.getSession().setAttribute("ejbcawebbean", ejbcawebbean); } ===================================================================== Found a 15 line (160 tokens) duplication in the following files: Starting at line 380 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/CAAdminSessionBean.java Starting at line 1229 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/CAAdminSessionBean.java Iterator iter = cainfo.getExtendedCAServiceInfos().iterator(); while(iter.hasNext()){ ExtendedCAServiceInfo info = (ExtendedCAServiceInfo) iter.next(); if(info instanceof OCSPCAServiceInfo){ try{ ca.initExternalService(OCSPCAService.TYPE, ca); ArrayList ocspcertificate = new ArrayList(); ocspcertificate.add(((OCSPCAServiceInfo) ca.getExtendedCAServiceInfo(OCSPCAService.TYPE)).getOCSPSignerCertificatePath().get(0)); getSignSession().publishCACertificate(admin, ocspcertificate, ca.getCRLPublishers(), CertificateDataBean.CERTTYPE_ENDENTITY); }catch(Exception fe){ getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CACREATED,"Couldn't Create ExternalCAService.",fe); throw new EJBException(fe); } } } ===================================================================== Found a 85 line (155 tokens) duplication in the following files: Starting at line 43 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/BaseSessionBean.java Starting at line 43 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/BaseEntityBean.java log = Logger.getLogger(this.getClass()); } /** * Logs a message with priority DEBUG * * @param msg Message */ public void debug(String msg) { log.debug(msg); } /** * Logs a message and an exception with priority DEBUG * * @param msg Message * @param t Exception */ public void debug(String msg, Throwable t) { log.debug(msg, t); } /** * Logs a message with priority INFO * * @param msg Message */ public void info(String msg) { log.info(msg); } /** * Logs a message and an exception with priority INFO * * @param msg Message * @param t Exception */ public void info(String msg, Throwable t) { log.info(msg, t); } /** * Logs a message with priority WARN * * @param msg Message */ public void warn(String msg) { log.warn(msg); } /** * Logs a message and an exception with priority WARN * * @param msg Message * @param t Exception */ public void warn(String msg, Throwable t) { log.warn(msg, t); } /** * Logs a message with priority ERROR * * @param msg Message */ public void error(String msg) { log.error(msg); } /** * Logs a message and an exception with priority ERROR * * @param msg Message * @param t Exception */ public void error(String msg, Throwable t) { log.error(msg, t); } /** * Sets current entity context * * @param ctx current entity context */ public void setEntityContext(EntityContext ctx) { ===================================================================== Found a 28 line (137 tokens) duplication in the following files: Starting at line 304 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/apply/DemoCertReqServlet.java Starting at line 252 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/apply/CertReqServlet.java debug.printDebugInfo(); return; } catch (AuthLoginException ale) { log.debug("Wrong password for user!"); debug.printMessage("Wrong username or password!"); debug.printMessage( "To generate a certificate a valid username and password must be entered."); debug.printDebugInfo(); return; } catch (SignRequestException re) { log.debug("Invalid request!"); debug.printMessage("Invalid request!"); debug.printMessage("Please supply a correct request."); debug.printDebugInfo(); return; } catch (SignRequestSignatureException se) { log.debug("Invalid signature on certificate request!"); debug.printMessage("Invalid signature on certificate request!"); debug.printMessage("Please supply a correctly signed request."); debug.printDebugInfo(); return; } catch (java.lang.ArrayIndexOutOfBoundsException ae) { log.debug("Empty or invalid request received."); debug.printMessage("Empty or invalid request!"); debug.printMessage("Please supply a correct request."); debug.printDebugInfo(); return; } catch (se.anatom.ejbca.ca.exception.IllegalKeyException e) { ===================================================================== Found a 14 line (133 tokens) duplication in the following files: Starting at line 124 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/SoftCAToken.java Starting at line 167 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/SoftCAToken.java keystore.setKeyEntry(PRIVATESIGNKEYALIAS, p12privatekey,null,certchain); // generate enc keys. KeyPair enckeys = KeyTools.genKeys(keysize); // generate dummy certificate certchain[0] = CertTools.genSelfCert("CN=dummy2", 36500, null, enckeys.getPrivate(), enckeys.getPublic(), true); this.encCert = certchain[0]; keystore.setKeyEntry(PRIVATEDECKEYALIAS,enckeys.getPrivate(),null,certchain); java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); keystore.store(baos, keystorepass.toCharArray()); data.put(KEYSTORE, new String(Base64.encode(baos.toByteArray()))); data.put(KEYSIZE, new Integer(keysize)); data.put(KEYALGORITHM, SoftCATokenInfo.KEYALGORITHM_RSA); ===================================================================== Found a 42 line (129 tokens) duplication in the following files: Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenAuthCertificateProfile.java Starting at line 31 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/OCSPSignerCertificateProfile.java public OCSPSignerCertificateProfile() { setCertificateVersion(VERSION_X509V3); setValidity(730); setUseBasicConstraints(true); setBasicConstraintsCritical(true); setUseSubjectKeyIdentifier(true); setSubjectKeyIdentifierCritical(false); setUseAuthorityKeyIdentifier(true); setAuthorityKeyIdentifierCritical(false); setUseSubjectAlternativeName(true); setSubjectAlternativeNameCritical(false); setUseCRLDistributionPoint(false); setCRLDistributionPointCritical(false); setCRLDistributionPointURI(""); setUseCertificatePolicies(false); setCertificatePoliciesCritical(false); setCertificatePolicyId("2.5.29.32.0"); setType(TYPE_ENDENTITY); int[] bitlengths = {512,1024,2048,4096}; setAvailableBitLengths(bitlengths); // Standard key usages for end users are: digitalSignature | keyEncipherment or nonRepudiation // Default key usage is digitalSignature | keyEncipherment // Create an array for KeyUsage acoording to X509Certificate.getKeyUsage() setUseKeyUsage(true); setKeyUsage(new boolean[9]); setKeyUsage(DIGITALSIGNATURE,true); setKeyUsageCritical(true); setUseExtendedKeyUsage(true); ArrayList eku = new ArrayList(); eku.add(new Integer(OCSPSIGNING)); ===================================================================== Found a 7 line (128 tokens) duplication in the following files: Starting at line 195 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/hardtoken/LocalEjbcaHardTokenBatchJobSessionBean.java Starting at line 304 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/hardtoken/LocalEjbcaHardTokenBatchJobSessionBean.java if(rs.relative(index)){ // TODO add support for Extended Information returnval = new UserDataVO(rs.getString(1), rs.getString(2), rs.getInt(14), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6) , rs.getInt(10), rs.getInt(11) , new java.util.Date(rs.getLong(8)), new java.util.Date(rs.getLong(9)) , rs.getInt(12), rs.getInt(13), null); returnval.setPassword(rs.getString(7)); ===================================================================== Found a 7 line (128 tokens) duplication in the following files: Starting at line 1126 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/LocalUserAdminSessionBean.java Starting at line 248 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/hardtoken/LocalEjbcaHardTokenBatchJobSessionBean.java while(rs.next() && returnval.size() <= MAX_RETURNED_QUEUE_SIZE){ // TODO add support for Extended Information UserDataVO data = new UserDataVO(rs.getString(1), rs.getString(2), rs.getInt(14), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6) , rs.getInt(10), rs.getInt(11) , new java.util.Date(rs.getLong(8)), new java.util.Date(rs.getLong(9)) , rs.getInt(12), rs.getInt(13), null); data.setPassword(rs.getString(7)); ===================================================================== Found a 14 line (127 tokens) duplication in the following files: Starting at line 258 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/authorization/AdminGroupDataBean.java Starting at line 294 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/authorization/AdminGroupDataBean.java AdminEntity adminentity = (AdminEntity) iter.next(); AdminEntityPK datapk = createAdminEntityPK(getAdminGroupName(), getCaId(), adminentity.getMatchWith(), adminentity.getMatchType(), adminentity.getMatchValue()); Iterator i = getAdminEntities().iterator(); while (i.hasNext()) { AdminEntityDataLocal ue = (AdminEntityDataLocal) i.next(); // TODO use ue.getPrimaryKey() ? AdminEntityPK uepk = createAdminEntityPK(getAdminGroupName(), getCaId(), ue.getMatchWith(), ue.getMatchType(), ue.getMatchValue()); if (uepk.equals(datapk)) { getAdminEntities().remove(ue); try { ue.remove(); } catch (RemoveException e) { error("Error removing AdminEntities: ", e); ===================================================================== Found a 22 line (122 tokens) duplication in the following files: Starting at line 215 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/authorization/BasicAccessRuleSetEncoder.java Starting at line 319 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/authorization/BasicAccessRuleSetEncoder.java if(!isAllowedSupervisorRule(ar)) if(ar.getRule() == AccessRule.RULE_ACCEPT && ar.isRecursive() && requiredacceptrecrules.contains(ar.getAccessRule())) requiredacceptrecrules.remove(ar.getAccessRule()); else if(ar.getRule() == AccessRule.RULE_ACCEPT && !ar.isRecursive() && requiredacceptnonrecrules.contains(ar.getAccessRule())) requiredacceptnonrecrules.remove(ar.getAccessRule()); else{ illegal = true; break; } } if(!illegal && requiredacceptrecrules.size() ==0 && requiredacceptnonrecrules.size() == 0) returnval = true; } return returnval; } private boolean isAllowedSupervisorRule(AccessRule ar){ ===================================================================== Found a 12 line (115 tokens) duplication in the following files: Starting at line 33 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/ExtendedX509Util.java Starting at line 54 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/common/ExtendedPKCS10CertificationRequest.java algorithms.put("RSAWITHMD5", new DERObjectIdentifier("1.2.840.113549.1.1.4")); algorithms.put("SHA1WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.5")); algorithms.put("SHA1WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.5")); algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption); algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption); algorithms.put("SHA256WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha256WithRSAEncryption); algorithms.put("SHA256WITHRSA", PKCSObjectIdentifiers.sha256WithRSAEncryption); algorithms.put("SHA384WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha384WithRSAEncryption); algorithms.put("SHA384WITHRSA", PKCSObjectIdentifiers.sha384WithRSAEncryption); algorithms.put("SHA512WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha512WithRSAEncryption); algorithms.put("SHA512WITHRSA", PKCSObjectIdentifiers.sha512WithRSAEncryption); algorithms.put("RSAWITHSHA1", new DERObjectIdentifier("1.2.840.113549.1.1.5")); ===================================================================== Found a 41 line (114 tokens) duplication in the following files: Starting at line 1427 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/CAAdminSessionBean.java Starting at line 201 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/LocalCertificateStoreSessionBean.java } /** * Gets connection to log session bean */ private ILogSessionLocal getLogSession() { if (logsession == null) { try { ILogSessionLocalHome home = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME); logsession = home.create(); } catch (Exception e) { throw new EJBException(e); } } return logsession; } //getLogSession /** * Gets connection to authorization session bean * * @return Connection */ private IAuthorizationSessionLocal getAuthorizationSession() { if (authorizationsession == null) { try { IAuthorizationSessionLocalHome home = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME); authorizationsession = home.create(); } catch (Exception e) { throw new EJBException(e); } } return authorizationsession; } //getAuthorizationSession /** * Gets connection to publisher session bean * * @return Connection */ private IPublisherSessionLocal getPublisherSession() { ===================================================================== Found a 4 line (113 tokens) duplication in the following files: Starting at line 1128 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/LocalUserAdminSessionBean.java Starting at line 197 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/hardtoken/LocalEjbcaHardTokenBatchJobSessionBean.java returnval = new UserDataVO(rs.getString(1), rs.getString(2), rs.getInt(14), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6) , rs.getInt(10), rs.getInt(11) , new java.util.Date(rs.getLong(8)), new java.util.Date(rs.getLong(9)) , rs.getInt(12), rs.getInt(13),null); ===================================================================== Found a 26 line (112 tokens) duplication in the following files: Starting at line 193 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/publisher/LdapPublisher.java Starting at line 339 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/publisher/LdapPublisher.java } // Check if the entry is already present, we will update it with the new certificate. LDAPEntry oldEntry = null; try { // connect to the server lc.connect(getHostname(), Integer.parseInt(getPort())); // authenticate to the server lc.bind(ldapVersion, getLoginDN(), getLoginPassword()); // try to read the old object oldEntry = lc.read(dn); // disconnect with the server lc.disconnect(); } catch (LDAPException e) { if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT) { log.debug("No old entry exist for '" + dn + "'."); } else { log.error("Error binding to and reading from LDAP server: ", e); throw new PublisherException("Error binding to and reading from LDAP server."); } } LDAPEntry newEntry = null; LDAPModificationSet modSet = null; LDAPAttributeSet attributeSet = null; ===================================================================== Found a 17 line (108 tokens) duplication in the following files: Starting at line 85 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/admin/Upgrade.java Starting at line 109 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/admin/Upgrade.java command[1] = "setbaseurl"; command[2] = url; command[3] = "ejbca"; Process runcainit = Runtime.getRuntime().exec(command); BufferedReader br = new BufferedReader(new InputStreamReader(runcainit.getInputStream())); Thread.sleep(1000); String line = ""; while((line = br.readLine()) != null){ System.out.println(line); } if(runcainit.waitFor() != 0){ error("Error setting baseurl"); return false; } } catch (Exception e) { error("Error setting baseurl: ", e); ===================================================================== Found a 34 line (107 tokens) duplication in the following files: Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenAuthEncCertificateProfile.java Starting at line 31 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenEncCertificateProfile.java public HardTokenEncCertificateProfile() { setCertificateVersion(VERSION_X509V3); setValidity(730); setUseBasicConstraints(true); setBasicConstraintsCritical(true); setUseSubjectKeyIdentifier(true); setSubjectKeyIdentifierCritical(false); setUseAuthorityKeyIdentifier(true); setAuthorityKeyIdentifierCritical(false); setUseSubjectAlternativeName(true); setSubjectAlternativeNameCritical(false); setUseCRLDistributionPoint(false); setCRLDistributionPointCritical(false); setCRLDistributionPointURI(""); setUseCertificatePolicies(false); setCertificatePoliciesCritical(false); setCertificatePolicyId("2.5.29.32.0"); setType(TYPE_ENDENTITY); int[] bitlengths = {512,1024,2048,4096}; setAvailableBitLengths(bitlengths); setUseKeyUsage(true); setKeyUsage(new boolean[9]); setKeyUsage(KEYENCIPHERMENT,true); ===================================================================== Found a 37 line (107 tokens) duplication in the following files: Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenAuthCertificateProfile.java Starting at line 31 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/EndUserCertificateProfile.java public EndUserCertificateProfile() { setCertificateVersion(VERSION_X509V3); setValidity(730); setUseBasicConstraints(true); setBasicConstraintsCritical(true); setUseSubjectKeyIdentifier(true); setSubjectKeyIdentifierCritical(false); setUseAuthorityKeyIdentifier(true); setAuthorityKeyIdentifierCritical(false); setUseSubjectAlternativeName(true); setSubjectAlternativeNameCritical(false); setUseCRLDistributionPoint(false); setCRLDistributionPointCritical(false); setCRLDistributionPointURI(""); setUseCertificatePolicies(false); setCertificatePoliciesCritical(false); setCertificatePolicyId("2.5.29.32.0"); setType(TYPE_ENDENTITY); int[] bitlengths = {512,1024,2048,4096}; setAvailableBitLengths(bitlengths); // Standard key usages for end users are: digitalSignature | keyEncipherment or nonRepudiation // Default key usage is digitalSignature | keyEncipherment // Create an array for KeyUsage acoording to X509Certificate.getKeyUsage() setUseKeyUsage(true); setKeyUsage(new boolean[9]); setKeyUsage(DIGITALSIGNATURE,true); ===================================================================== Found a 32 line (106 tokens) duplication in the following files: Starting at line 44 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/ExtendedInformation.java Starting at line 215 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/caadmin/HardCATokenContainer.java HardCATokenContainer clone = new HardCATokenContainer(); HashMap clonedata = (HashMap) clone.saveData(); Iterator i = (data.keySet()).iterator(); while(i.hasNext()){ Object key = i.next(); clonedata.put(key, data.get(key)); } clone.loadData(clonedata); return clone; } /** * @see se.anatom.ejbca.ca.publisher.BasePublisher#getLatestVersion() */ public float getLatestVersion() { return LATEST_VERSION; } public void upgrade() { if(LATEST_VERSION != getVersion()){ // New version of the class, upgrade data.put(VERSION, new Float(LATEST_VERSION)); } } } ===================================================================== Found a 26 line (105 tokens) duplication in the following files: Starting at line 105 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/raadmin/AdminPreference.java Starting at line 44 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/ExtendedInformation.java ExtendedInformation clone = new ExtendedInformation(); HashMap clonedata = (HashMap) clone.saveData(); Iterator i = (data.keySet()).iterator(); while(i.hasNext()){ Object key = i.next(); clonedata.put(key, data.get(key)); } clone.loadData(clonedata); return clone; } /** Implemtation of UpgradableDataHashMap function getLatestVersion */ public float getLatestVersion(){ return LATEST_VERSION; } /** Implemtation of UpgradableDataHashMap function upgrade. */ public void upgrade(){ if(LATEST_VERSION != getVersion()){ // New version of the class, upgrade data.put(VERSION, new Float(LATEST_VERSION)); } } ===================================================================== Found a 24 line (104 tokens) duplication in the following files: Starting at line 256 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/util/JKStoPEM.java Starting at line 247 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/util/P12toPEM.java log.info( "User certificate is selfsigned, this is a RootCA, no CA certificates written."); } else { out = new FileOutputStream(tmpFile); for (int num = 1; num < chain.length; num++) { X509Certificate tmpX509Cert = (X509Certificate) chain[num]; byte[] tmpOutput = tmpX509Cert.getEncoded(); out.write(beginCertificate); out.write(NL); byte[] tmpCACertB64 = Base64.encode(tmpOutput); out.write(tmpCACertB64); out.write(NL); out.write(endCertificate); out.write(NL); } out.close(); } } // createPEM } ===================================================================== Found a 4 line (104 tokens) duplication in the following files: Starting at line 819 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/LocalUserAdminSessionBean.java Starting at line 862 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/LocalUserAdminSessionBean.java Starting at line 907 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/LocalUserAdminSessionBean.java UserDataVO user = new UserDataVO(data.getUsername(), data.getSubjectDN(), data.getCaId(), data.getSubjectAltName(), data.getSubjectEmail(), data.getStatus() , data.getType(), data.getEndEntityProfileId(), data.getCertificateProfileId() , new java.util.Date(data.getTimeCreated()), new java.util.Date(data.getTimeModified()) , data.getTokenType(), data.getHardTokenIssuerId(), data.getExtendedInformation()); ===================================================================== Found a 34 line (103 tokens) duplication in the following files: Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenAuthCertificateProfile.java Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenSignCertificateProfile.java Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenAuthEncCertificateProfile.java public HardTokenAuthEncCertificateProfile() { setCertificateVersion(VERSION_X509V3); setValidity(730); setUseBasicConstraints(true); setBasicConstraintsCritical(true); setUseSubjectKeyIdentifier(true); setSubjectKeyIdentifierCritical(false); setUseAuthorityKeyIdentifier(true); setAuthorityKeyIdentifierCritical(false); setUseSubjectAlternativeName(true); setSubjectAlternativeNameCritical(false); setUseCRLDistributionPoint(false); setCRLDistributionPointCritical(false); setCRLDistributionPointURI(""); setUseCertificatePolicies(false); setCertificatePoliciesCritical(false); setCertificatePolicyId("2.5.29.32.0"); setType(TYPE_ENDENTITY); int[] bitlengths = {512,1024,2048,4096}; setAvailableBitLengths(bitlengths); setUseKeyUsage(true); setKeyUsage(new boolean[9]); setKeyUsage(KEYENCIPHERMENT,true); ===================================================================== Found a 16 line (102 tokens) duplication in the following files: Starting at line 77 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/GetCRLServlet.java Starting at line 69 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/webdist/cainterface/EndEntityCertServlet.java public void init(ServletConfig config) throws ServletException { super.init(config); } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { log.debug(">doPost()"); doGet(req, res); log.debug("doGet()"); // Check if authorized EjbcaWebBean ejbcawebbean= (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) req.getSession().getAttribute("ejbcawebbean"); ===================================================================== Found a 21 line (102 tokens) duplication in the following files: Starting at line 230 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/batch/BatchMakeP12.java Starting at line 479 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/apply/CertReqServlet.java Certificate[] cachain = (Certificate[]) signsession.getCertificateChain(administrator, caid).toArray(new Certificate[0]); // Verify CA-certificate if (CertTools.isSelfSigned((X509Certificate) cachain[cachain.length - 1])) { try { cachain[cachain.length - 1].verify(cachain[cachain.length - 1].getPublicKey()); } catch (GeneralSecurityException se) { throw new Exception("RootCA certificate does not verify"); } } else { throw new Exception("RootCA certificate not self-signed"); } // Verify that the user-certificate is signed by our CA try { cert.verify(cachain[0].getPublicKey()); } catch (GeneralSecurityException se) { throw new Exception("Generated certificate does not verify using CA-certificate."); } if (savekeys) { ===================================================================== Found a 31 line (101 tokens) duplication in the following files: Starting at line 32 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/HardTokenAuthCertificateProfile.java Starting at line 139 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/CertificateProfile.java public CertificateProfile() { setCertificateVersion(VERSION_X509V3); setValidity(730); setUseBasicConstraints(true); setBasicConstraintsCritical(true); setUseSubjectKeyIdentifier(true); setSubjectKeyIdentifierCritical(false); setUseAuthorityKeyIdentifier(true); setAuthorityKeyIdentifierCritical(false); setUseSubjectAlternativeName(true); setSubjectAlternativeNameCritical(false); setUseCRLDistributionPoint(false); setCRLDistributionPointCritical(false); setCRLDistributionPointURI(""); setUseCertificatePolicies(false); setCertificatePoliciesCritical(false); setCertificatePolicyId("2.5.29.32.0"); setType(TYPE_ENDENTITY); int[] bitlengths = {512,1024,2048,4096}; setAvailableBitLengths(bitlengths); setUseKeyUsage(true); setKeyUsage(new boolean[9]); ===================================================================== Found a 25 line (101 tokens) duplication in the following files: Starting at line 338 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/publisher/LdapPublisher.java Starting at line 434 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/publisher/LdapPublisher.java throw new PublisherException("Error decoding input certificate."); } // Check if the entry is already present, we will update it with the new certificate. LDAPEntry oldEntry = null; try { // connect to the server lc.connect(getHostname(), Integer.parseInt(getPort())); // authenticate to the server lc.bind(ldapVersion, getLoginDN(), getLoginPassword()); // try to read the old object oldEntry = lc.read(dn); // disconnect with the server lc.disconnect(); } catch (LDAPException e) { if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT) { log.debug("No old entry exist for '" + dn + "'."); } else { log.error("Error binding to and reading from LDAP server: ", e); throw new PublisherException("Error binding to and reading from LDAP server."); } } ===================================================================== Found a 25 line (101 tokens) duplication in the following files: Starting at line 643 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ra/raadmin/EndEntityProfile.java Starting at line 633 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/store/certificateprofiles/CertificateProfile.java CertificateProfile clone = new CertificateProfile(); HashMap clonedata = (HashMap) clone.saveData(); Iterator i = (data.keySet()).iterator(); while(i.hasNext()){ Object key = i.next(); clonedata.put(key, data.get(key)); } clone.loadData(clonedata); return clone; } /** Implemtation of UpgradableDataHashMap function getLatestVersion */ public float getLatestVersion(){ return LATEST_VERSION; } /** Implemtation of UpgradableDataHashMap function upgrade. */ public void upgrade(){ log.debug(">upgrade"); if(LATEST_VERSION != getVersion()){ // New version of the class, upgrade log.info("upgrading certificateprofile with version "+getVersion()); ===================================================================== Found a 24 line (100 tokens) duplication in the following files: Starting at line 193 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/publisher/LdapPublisher.java Starting at line 435 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/ca/publisher/LdapPublisher.java } // Check if the entry is already present, we will update it with the new certificate. LDAPEntry oldEntry = null; try { // connect to the server lc.connect(getHostname(), Integer.parseInt(getPort())); // authenticate to the server lc.bind(ldapVersion, getLoginDN(), getLoginPassword()); // try to read the old object oldEntry = lc.read(dn); // disconnect with the server lc.disconnect(); } catch (LDAPException e) { if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT) { log.debug("No old entry exist for '" + dn + "'."); } else { log.error("Error binding to and reading from LDAP server: ", e); throw new PublisherException("Error binding to and reading from LDAP server."); } } ===================================================================== Found a 18 line (100 tokens) duplication in the following files: Starting at line 249 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/batch/BatchMakeP12.java Starting at line 499 of /home/tom/pmd/pmd-web/src/ejbca/src/java/se/anatom/ejbca/apply/CertReqServlet.java if (savekeys) { // Save generated keys to database. IKeyRecoverySessionRemote keyrecoverysession = keyrecoveryhome.create(); keyrecoverysession.addKeyRecoveryData(administrator, cert, username, rsaKeys); } // Use CN if as alias in the keystore, if CN is not present use username String alias = CertTools.getPartFromDN(CertTools.getSubjectDN(cert), "CN"); if (alias == null) alias = username; // Store keys and certificates in keystore. KeyStore ks = null; if (createJKS) { ks = KeyTools.createJKS(alias, rsaKeys.getPrivate(), password, cert, cachain); } else { ks = KeyTools.createP12(alias, rsaKeys.getPrivate(), cert, cachain); }