CPD Results

The following document contains the results of PMD's CPD 4.3.

Duplications

FileLine
org\nhindirect\stagent\cert\tools\certgen\CertGenerator.java119
org\nhindirect\stagent\cert\tools\certgen\CertGenerator.java187
		if (fields.getAttributes().containsKey("EMAILADDRESS"))
		{
			dnBuilder.append("EMAILADDRESS=").append(fields.getAttributes().get("EMAILADDRESS")).append(", ");
			altName = fields.getAttributes().get("EMAILADDRESS").toString();
		}
		
		if (fields.getAttributes().containsKey("CN"))
			dnBuilder.append("CN=").append(fields.getAttributes().get("CN")).append(", ");
		
		if (fields.getAttributes().containsKey("C"))
			dnBuilder.append("C=").append(fields.getAttributes().get("C")).append(", ");
		
		if (fields.getAttributes().containsKey("ST"))
			dnBuilder.append("ST=").append(fields.getAttributes().get("ST")).append(", ");	
		
		if (fields.getAttributes().containsKey("L"))
			dnBuilder.append("L=").append(fields.getAttributes().get("L")).append(", ");	
		
		if (fields.getAttributes().containsKey("O"))
			dnBuilder.append("O=").append(fields.getAttributes().get("O")).append(", ");				
		
		String DN = dnBuilder.toString().trim();
		if (DN.endsWith(","))
			DN = DN.substring(0, DN.length() - 1);
		
		X509V3CertificateGenerator  v1CertGen = new X509V3CertificateGenerator();
		
		Calendar start = Calendar.getInstance();
		Calendar end = Calendar.getInstance();
		end.add(Calendar.DAY_OF_MONTH, fields.getExpDays()); 
		
        v1CertGen.setSerialNumber(BigInteger.valueOf(generatePositiveRandom()));
        v1CertGen.setIssuerDN(new X509Principal(DN));
FileLine
org\nhindirect\stagent\cert\tools\DNSCertDumper.java96
org\nhindirect\stagent\cert\tools\LDAPCertDumper.java84
				Collection<X509Certificate> certs = dnsStore.getCertificates(new InternetAddress(emailAddress));
				if (certs == null || certs.size() == 0)
				{
					System.out.println("No certs found");
				}
				else
				{
					int idx = 1;
					for (X509Certificate cert : certs)
					{
						String certFileName= "";
						String certFileHold = (outFile == null || outFile.isEmpty())  ? emailAddress + ".der" : outFile;
						if (certs.size() > 1)
						{
							int index = certFileHold.lastIndexOf(".");
							if (index < 0)
								certFileHold += "(" + idx + ")";
							else
							{
								certFileName = certFileHold.substring(0, index - 1) + "(" + idx + ")" + certFileHold.substring(index);
							}
									
						}
						else
							certFileName = certFileHold;
						
						File certFile = new File(certFileName);
						if (certFile.exists())
							certFile.delete();
						
						
						System.out.println("Writing cert file: " + certFile.getAbsolutePath());
						FileUtils.writeByteArrayToFile(certFile, cert.getEncoded());						
						
						++idx;
					}
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}		
		System.exit(0);
	}
	
    private static void printUsage()
    {
        StringBuffer use = new StringBuffer();
        use.append("Usage:\n");
        use.append("java DNSCertDumper (options)...\n\n");
FileLine
org\nhindirect\stagent\cert\tools\certgen\CAPanel.java457
org\nhindirect\stagent\cert\tools\certgen\LeafCertGenDialog.java191
					"Empty Password", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
			
			if (selection == JOptionPane.NO_OPTION)
				return;			
		}
		
		
		
		// get the fields
		Map<String, Object> attributes = new HashMap<String, Object>(); 
		attributes.put("CN", cnField.getText());
		if (!countryField.getText().isEmpty())
			attributes.put("C", countryField.getText());
		if (!stateField.getText().isEmpty())
			attributes.put("ST", stateField.getText());		
		if (!locField.getText().isEmpty())
			attributes.put("L", locField.getText());				
		if (!orgField.getText().isEmpty())
			attributes.put("O", orgField.getText());	
		if (!emailField.getText().isEmpty())
			attributes.put("EMAILADDRESS", emailField.getText());	
FileLine
org\nhindirect\stagent\CryptoExtensions.java501
org\nhindirect\stagent\trust\TrustChainValidator.java445
    	X500Principal issuerPrin = certificate.getSubjectX500Principal();
    	
    	// get the domain name
		Map<String, String> oidMap = new HashMap<String, String>();
		oidMap.put("1.2.840.113549.1.9.1", "EMAILADDRESS");  // OID for email address
		String prinName = issuerPrin.getName(X500Principal.RFC1779, oidMap);    
		
		// see if there is an email address first in the DN
		String searchString = "EMAILADDRESS=";
		int index = prinName.indexOf(searchString);
		if (index == -1)
		{
			searchString = "CN=";
			// no Email.. check the CN
			index = prinName.indexOf(searchString);
			if (index == -1)
				return ""; // no CN... nothing else that can be done from here
		}
		
		// look for a "," to find the end of this attribute
		int endIndex = prinName.indexOf(",", index);
		if (endIndex > -1)
			address = prinName.substring(index + searchString.length(), endIndex);
		else 
			address= prinName.substring(index + searchString.length());
		
		return address;
    }    
}
FileLine
org\nhindirect\stagent\cert\tools\DNSCertDumper.java62
org\nhindirect\stagent\cert\tools\LDAPCertDumper.java50
            }
            else if (arg.equals("-out"))
            {
                if (i == args.length - 1 || args[i + 1].startsWith("-"))
                {
                    System.err.println("Error: Missing output file.");
                    System.exit(-1);
                }
                outFile = args[++i];
            }
            else if (arg.equals("-help"))
            {
                printUsage();
                System.exit(-1);
            }            
            else
            {
                System.err.println("Error: Unknown argument " + arg + "\n");
                printUsage();
                System.exit(-1);
            }
        }		
			
        if (emailAddress == null || emailAddress.isEmpty())
        {
        	System.err.println("You must provide an email address.");
        	printUsage();
        }        	
        else
		{
FileLine
org\nhindirect\stagent\cert\tools\DNSCertDumper.java29
org\nhindirect\stagent\cert\tools\LDAPCertDumper.java26
		String outFile = null;
		
		// Check parameters
        for (int i = 0; i < args.length; i++)
        {
            String arg = args[i];

            // Options
            if (!arg.startsWith("-"))
            {
                System.err.println("Error: Unexpected argument [" + arg + "]\n");
                printUsage();
                System.exit(-1);
            }
            else if (arg.equalsIgnoreCase("-add"))
            {
                if (i == args.length - 1 || args[i + 1].startsWith("-"))
                {
                    System.err.println("Error: Missing email address");
                    System.exit(-1);
                }
                
                emailAddress = args[++i];
                
            }
            else if (arg.equals("-server"))
FileLine
org\nhindirect\stagent\cert\tools\CreatePKCS12.java124
org\nhindirect\stagent\cert\tools\StripP12Passphrase.java113
                p12Pass = argv[++i];
            }    
            else if (arg.equals("-out"))
            {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-"))
                {
                    System.err.println("Error: Missing output file.");
                    System.exit(-1);
                }
                createFile = new File(argv[++i]);
            }
            else if (arg.equals("-help"))
            {
                printUsage();
                System.exit(-1);
            }            
            else
            {
                System.err.println("Error: Unknown argument " + arg + "\n");
                printUsage();
                System.exit(-1);
            }
        }

        if (validateParameters())        
FileLine
org\nhindirect\stagent\mail\Message.java247
org\nhindirect\stagent\mail\MimeEntity.java153
    }
    
    @Override
    public String toString()
    {
        return EntitySerializer.Default.serialize(this);
    }    
    
    /**
     * Gets the content (body) of the message as a byte array.
     * @return The content (body) of the message as a byte array.
     */
    public byte[] getContentAsBytes()
    {
    	byte retVal[] = null;
    	
    	try
    	{
	    	InputStream inStream = getRawInputStream();
	    	ByteArrayOutputStream oStream = new ByteArrayOutputStream();
	    	byte buffer[] = new byte[2048];
	    	int read;
	    	while ((read = inStream.read(buffer)) > -1)
	    		oStream.write(buffer, 0, read);
	    	
	    	retVal = oStream.toByteArray();
	    	IOUtils.closeQuietly(oStream);	
    	}
    	catch (Exception e)
    	{
    		throw new MimeException(MimeError.InvalidBody, e);
    	}
    	
    	return retVal; 
    }    
FileLine
org\nhindirect\stagent\CryptoExtensions.java473
org\nhindirect\stagent\trust\TrustChainValidator.java417
    		altNames = certificate.getSubjectAlternativeNames();
    	}
    	catch (CertificateParsingException ex)
    	{
    		/* no -op */
    	}	
		
    	if (altNames != null)
		{
    		for (List<?> entries : altNames)
    		{
    			if (entries.size() >= 2) // should always be the case according the altNames spec, but checking to be defensive
    			{
    				
    				Integer nameType = (Integer)entries.get(0);
    				// prefer email over over domain?
    				if (nameType == RFC822Name_TYPE)    					
    					address = (String)entries.get(1);
    				else if (nameType == DNSName_TYPE && address.isEmpty())
    					address = (String)entries.get(1);    				
    			}
    		}
		}
    	
    	if (!address.isEmpty())
    		return address;
    	
    	// can't find issuer address in alt names... try the principal 
    	X500Principal issuerPrin = certificate.getSubjectX500Principal();
FileLine
org\nhindirect\stagent\cert\impl\DNSCertificateStore.java555
org\nhindirect\stagent\cert\impl\LDAPCertificateStore.java148
	}
	
	private void applyCachePolicy(CertStoreCachePolicy policy)
	{
		if (getCache() != null)
		{
			try
			{
				ICompositeCacheAttributes attributes = cache.getCacheAttributes();
				attributes.setMaxObjects(policy.getMaxItems());
				attributes.setUseLateral(false);
				attributes.setUseRemote(false);
				cache.setCacheAttributes(attributes);
				
				IElementAttributes eattributes = cache.getDefaultElementAttributes();
				eattributes.setMaxLifeSeconds(policy.getSubjectTTL());
				eattributes.setIsEternal(false);
				eattributes.setIsLateral(false);
				eattributes.setIsRemote(false);		
				
				cache.setDefaultElementAttributes(eattributes);
			}
			catch (CacheException e)
			{
				// TODO: Handle exception
			}
		}
	}
FileLine
org\nhindirect\stagent\cert\impl\DNSCertificateStore.java273
org\nhindirect\stagent\cert\impl\LDAPCertificateStore.java222
    }    
    
    
	/**
	 * {@inheritDoc}
	 */  
    @SuppressWarnings("unchecked")
    @Override
    public Collection<X509Certificate> getCertificates(String subjectName)
    {
      	String realSubjectName;
    	int index;
		if ((index = subjectName.indexOf("EMAILADDRESS=")) > -1)
			realSubjectName = subjectName.substring(index + "EMAILADDRESS=".length());
		else
			realSubjectName = subjectName;    	
    	
    	Collection<X509Certificate> retVal;
    	
    	JCS cache = getCache();
    	
    	if (cache != null)
    	{
    		retVal = (Collection<X509Certificate>)cache.get(realSubjectName);
    		if (retVal == null || retVal.size() == 0)
    		{
    			retVal = this.lookupDNS(realSubjectName);