test_class.file: OpenADRSecurity/src/test/java/com/avob/openadr/security/OadrPKISecurityTest.java
test_class.identifier: OadrPKISecurityTest
test_case.body: @Test
  	public void generateCredentialsTest()
  			throws NoSuchAlgorithmException, IOException, CertificateException, NoSuchProviderException,
  			OadrSecurityException, InvalidKeyException, SignatureException, OperatorCreationException {
  		KeyPair ca = OadrPKISecurity.generateRsaKeyPair();
  		SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(ca.getPublic().getEncoded());
  		AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA");
  		AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
  		Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  		BigInteger sn = new BigInteger(64, new SecureRandom());
  		X509v3CertificateBuilder certificateGenerator = new X509v3CertificateBuilder(
  				// These are the details of the CA
  				new X500Name("cn=TestCa"),
  				// This should be a serial number that the CA keeps track of
  				sn,
  				// Certificate validity start
  				Date.from(LocalDateTime.now().minusDays(1).toInstant(ZoneOffset.UTC)),
  				// Certificate validity end
  				Date.from(LocalDateTime.now().plusDays(365).toInstant(ZoneOffset.UTC)),
  				// Blanket grant the subject as requested in the CSR
  				// A real CA would want to vet this.
  				new X500Name("cn=TestSubject"),
  				// Public key of the certificate authority
  				subPubKeyInfo);
  
  		ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId)
  				.build(PrivateKeyFactory.createKey(ca.getPrivate().getEncoded()));
  
  		X509CertificateHolder holder = certificateGenerator.build(sigGen);
  		CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", "BC");
  		X509Certificate caCert = (X509Certificate) certificateFactory
  				.generateCertificate(new ByteArrayInputStream(holder.toASN1Structure().getEncoded()));
  
  		String commonName = "test.oadr.com";
  
  		// TEST RSA
  		OadrUserX509Credential generateCredentials = OadrPKISecurity.generateCredentials(ca, caCert, commonName,
  				OadrPKIAlgorithm.SHA256_RSA);
  		testGeneratedCredential(generateCredentials, "SHA256withRSA");
  
  		// TEST DSA
  		generateCredentials = OadrPKISecurity.generateCredentials(ca, caCert, commonName, OadrPKIAlgorithm.SHA256_DSA);
  		testGeneratedCredential(generateCredentials, "SHA256withDSA");
  
  	}
test_case.class_method_signature: OadrPKISecurityTest.generateCredentialsTest()
test_case.full_signature: @Test public void generateCredentialsTest()
test_case.identifier: generateCredentialsTest
test_case.invocations: generateRsaKeyPair getInstance getEncoded getPublic find find addProvider from toInstant minusDays now from toInstant plusDays now build createKey getEncoded getPrivate build getInstance generateCertificate getEncoded toASN1Structure generateCredentials testGeneratedCredential generateCredentials testGeneratedCredential
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void generateCredentialsTest()
focal_class.file: OpenADRSecurity/src/main/java/com/avob/openadr/security/OadrPKISecurity.java
focal_class.identifier: OadrPKISecurity
focal_class.class_method_signature: OadrPKISecurity.OadrPKISecurity()
focal_class.full_signature: private  OadrPKISecurity()
focal_class.identifier: OadrPKISecurity
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  OadrPKISecurity()
focal_class.class_method_signature: OadrPKISecurity.parsePrivateKey(String privateKeyFilePath)
focal_class.full_signature: public static PrivateKey parsePrivateKey(String privateKeyFilePath)
focal_class.identifier: parsePrivateKey
focal_class.modifiers: public static
focal_class.parameters: (String privateKeyFilePath)
focal_class.return: PrivateKey
focal_class.signature: PrivateKey parsePrivateKey(String privateKeyFilePath)
focal_class.class_method_signature: OadrPKISecurity.parsePrivateKey(FileReader fileReader)
focal_class.full_signature: public static PrivateKey parsePrivateKey(FileReader fileReader)
focal_class.identifier: parsePrivateKey
focal_class.modifiers: public static
focal_class.parameters: (FileReader fileReader)
focal_class.return: PrivateKey
focal_class.signature: PrivateKey parsePrivateKey(FileReader fileReader)
focal_class.class_method_signature: OadrPKISecurity.parseCertificate(String certificateFilePath)
focal_class.full_signature: public static X509Certificate parseCertificate(String certificateFilePath)
focal_class.identifier: parseCertificate
focal_class.modifiers: public static
focal_class.parameters: (String certificateFilePath)
focal_class.return: X509Certificate
focal_class.signature: X509Certificate parseCertificate(String certificateFilePath)
focal_class.class_method_signature: OadrPKISecurity.parseCertificate(FileReader fileReader)
focal_class.full_signature: public static X509Certificate parseCertificate(FileReader fileReader)
focal_class.identifier: parseCertificate
focal_class.modifiers: public static
focal_class.parameters: (FileReader fileReader)
focal_class.return: X509Certificate
focal_class.signature: X509Certificate parseCertificate(FileReader fileReader)
focal_class.class_method_signature: OadrPKISecurity.createKeyStore(String privateKeyFilePath, String clientCertificatefilePath, String password)
focal_class.full_signature: public static KeyStore createKeyStore(String privateKeyFilePath, String clientCertificatefilePath, String password)
focal_class.identifier: createKeyStore
focal_class.modifiers: public static
focal_class.parameters: (String privateKeyFilePath, String clientCertificatefilePath, String password)
focal_class.return: KeyStore
focal_class.signature: KeyStore createKeyStore(String privateKeyFilePath, String clientCertificatefilePath, String password)
focal_class.class_method_signature: OadrPKISecurity.createKeyManagerFactory(String clientPrivateKeyPemFilePath,
  			String clientCertificatePemFilePath, String password)
focal_class.full_signature: public static KeyManagerFactory createKeyManagerFactory(String clientPrivateKeyPemFilePath,
  			String clientCertificatePemFilePath, String password)
focal_class.identifier: createKeyManagerFactory
focal_class.modifiers: public static
focal_class.parameters: (String clientPrivateKeyPemFilePath,
  			String clientCertificatePemFilePath, String password)
focal_class.return: KeyManagerFactory
focal_class.signature: KeyManagerFactory createKeyManagerFactory(String clientPrivateKeyPemFilePath,
  			String clientCertificatePemFilePath, String password)
focal_class.class_method_signature: OadrPKISecurity.createTrustStore(List<String> certificates)
focal_class.full_signature: public static KeyStore createTrustStore(List<String> certificates)
focal_class.identifier: createTrustStore
focal_class.modifiers: public static
focal_class.parameters: (List<String> certificates)
focal_class.return: KeyStore
focal_class.signature: KeyStore createTrustStore(List<String> certificates)
focal_class.class_method_signature: OadrPKISecurity.createTrustManagerFactory(List<String> trustedCertificateFilePath)
focal_class.full_signature: public static TrustManagerFactory createTrustManagerFactory(List<String> trustedCertificateFilePath)
focal_class.identifier: createTrustManagerFactory
focal_class.modifiers: public static
focal_class.parameters: (List<String> trustedCertificateFilePath)
focal_class.return: TrustManagerFactory
focal_class.signature: TrustManagerFactory createTrustManagerFactory(List<String> trustedCertificateFilePath)
focal_class.class_method_signature: OadrPKISecurity.createSSLContext(String clientPrivateKeyPemFilePath, String clientCertificatePemFilePath,
  			List<String> trustCertificates, String password)
focal_class.full_signature: public static SSLContext createSSLContext(String clientPrivateKeyPemFilePath, String clientCertificatePemFilePath,
  			List<String> trustCertificates, String password)
focal_class.identifier: createSSLContext
focal_class.modifiers: public static
focal_class.parameters: (String clientPrivateKeyPemFilePath, String clientCertificatePemFilePath,
  			List<String> trustCertificates, String password)
focal_class.return: SSLContext
focal_class.signature: SSLContext createSSLContext(String clientPrivateKeyPemFilePath, String clientCertificatePemFilePath,
  			List<String> trustCertificates, String password)
focal_class.class_method_signature: OadrPKISecurity.md5Hex(String data)
focal_class.full_signature: public static String md5Hex(String data)
focal_class.identifier: md5Hex
focal_class.modifiers: public static
focal_class.parameters: (String data)
focal_class.return: String
focal_class.signature: String md5Hex(String data)
focal_class.class_method_signature: OadrPKISecurity.generateRsaKeyPair()
focal_class.full_signature: public static KeyPair generateRsaKeyPair()
focal_class.identifier: generateRsaKeyPair
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: KeyPair
focal_class.signature: KeyPair generateRsaKeyPair()
focal_class.class_method_signature: OadrPKISecurity.generateEccKeyPair()
focal_class.full_signature: public static KeyPair generateEccKeyPair()
focal_class.identifier: generateEccKeyPair
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: KeyPair
focal_class.signature: KeyPair generateEccKeyPair()
focal_class.class_method_signature: OadrPKISecurity.generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_class.full_signature: public static OadrUserX509Credential generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_class.identifier: generateCredentials
focal_class.modifiers: public static
focal_class.parameters: (KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_class.return: OadrUserX509Credential
focal_class.signature: OadrUserX509Credential generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_class.class_method_signature: OadrPKISecurity.generateKeyPair(String algo, int length)
focal_class.full_signature: private static KeyPair generateKeyPair(String algo, int length)
focal_class.identifier: generateKeyPair
focal_class.modifiers: private static
focal_class.parameters: (String algo, int length)
focal_class.return: KeyPair
focal_class.signature: KeyPair generateKeyPair(String algo, int length)
focal_class.class_method_signature: OadrPKISecurity.signCsr(PKCS10CertificationRequest csr, KeyPair caKeyPair, X509Certificate caCert,
  			BigInteger serialNumber)
focal_class.full_signature: private static X509Certificate signCsr(PKCS10CertificationRequest csr, KeyPair caKeyPair, X509Certificate caCert,
  			BigInteger serialNumber)
focal_class.identifier: signCsr
focal_class.modifiers: private static
focal_class.parameters: (PKCS10CertificationRequest csr, KeyPair caKeyPair, X509Certificate caCert,
  			BigInteger serialNumber)
focal_class.return: X509Certificate
focal_class.signature: X509Certificate signCsr(PKCS10CertificationRequest csr, KeyPair caKeyPair, X509Certificate caCert,
  			BigInteger serialNumber)
focal_class.class_method_signature: OadrPKISecurity.writeCrtToString(X509Certificate certificate)
focal_class.full_signature: private static String writeCrtToString(X509Certificate certificate)
focal_class.identifier: writeCrtToString
focal_class.modifiers: private static
focal_class.parameters: (X509Certificate certificate)
focal_class.return: String
focal_class.signature: String writeCrtToString(X509Certificate certificate)
focal_class.class_method_signature: OadrPKISecurity.writeKeyToString(KeyPair pair)
focal_class.full_signature: private static String writeKeyToString(KeyPair pair)
focal_class.identifier: writeKeyToString
focal_class.modifiers: private static
focal_class.parameters: (KeyPair pair)
focal_class.return: String
focal_class.signature: String writeKeyToString(KeyPair pair)
focal_class.class_method_signature: OadrPKISecurity.writePemToString(String type, byte[] content)
focal_class.full_signature: private static String writePemToString(String type, byte[] content)
focal_class.identifier: writePemToString
focal_class.modifiers: private static
focal_class.parameters: (String type, byte[] content)
focal_class.return: String
focal_class.signature: String writePemToString(String type, byte[] content)
focal_class.class_method_signature: OadrPKISecurity.writeToFile(String fileName, String fileExtension, String content)
focal_class.full_signature: private static File writeToFile(String fileName, String fileExtension, String content)
focal_class.identifier: writeToFile
focal_class.modifiers: private static
focal_class.parameters: (String fileName, String fileExtension, String content)
focal_class.return: File
focal_class.signature: File writeToFile(String fileName, String fileExtension, String content)
focal_class.class_method_signature: OadrPKISecurity.generateCsr(KeyPair pair, String x509PrincipalName, String algo)
focal_class.full_signature: private static PKCS10CertificationRequest generateCsr(KeyPair pair, String x509PrincipalName, String algo)
focal_class.identifier: generateCsr
focal_class.modifiers: private static
focal_class.parameters: (KeyPair pair, String x509PrincipalName, String algo)
focal_class.return: PKCS10CertificationRequest
focal_class.signature: PKCS10CertificationRequest generateCsr(KeyPair pair, String x509PrincipalName, String algo)
focal_class.class_method_signature: OadrPKISecurity.parsePem(FileReader fileReader)
focal_class.full_signature: private static Object parsePem(FileReader fileReader)
focal_class.identifier: parsePem
focal_class.modifiers: private static
focal_class.parameters: (FileReader fileReader)
focal_class.return: Object
focal_class.signature: Object parsePem(FileReader fileReader)
focal_method.body: public static OadrUserX509Credential generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo) throws OadrSecurityException {
  		try {
  			long now = System.currentTimeMillis();
  			String venCN = commonName;
  			BigInteger serialNumber = BigInteger.valueOf(now);
  
  			KeyPair venCred = null;
  			String csrAlgo = "";
  
  			if (OadrPKIAlgorithm.SHA256_DSA.equals(algo)) {
  				venCred = OadrPKISecurity.generateEccKeyPair();
  				csrAlgo = "SHA256withDSA";
  			} else if (OadrPKIAlgorithm.SHA256_RSA.equals(algo)) {
  				venCred = OadrPKISecurity.generateRsaKeyPair();
  				csrAlgo = "SHA256withRSA";
  			}
  
  			String x509PrincipalName = "C=FR, ST=Paris, L=Paris, O=Avob, OU=Avob, CN=" + venCN;
  			PKCS10CertificationRequest csr = OadrPKISecurity.generateCsr(venCred, x509PrincipalName, csrAlgo);
  			X509Certificate crt = OadrPKISecurity.signCsr(csr, caKeyPair, caCert, serialNumber);
  
  			String fingerprint = OadrFingerprintSecurity.getOadr20bFingerprint(crt);
  
  			File crtFile = writeToFile(venCN, "crt", OadrPKISecurity.writeCrtToString(crt));
  			File caCrtFile = writeToFile("ca", "crt", OadrPKISecurity.writeCrtToString(caCert));
  			File keyFile = writeToFile(venCN, "key", OadrPKISecurity.writeKeyToString(venCred));
  			File fingerprintFile = writeToFile(venCN, "fingerprint", fingerprint);
  
  			return new OadrUserX509Credential(fingerprint, caCrtFile, crtFile, keyFile, fingerprintFile);
  		} catch (NoSuchAlgorithmException | OperatorCreationException | CertificateException | NoSuchProviderException
  				| IOException e) {
  			throw new OadrSecurityException(e);
  		}
  
  	}
focal_method.class_method_signature: OadrPKISecurity.generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_method.full_signature: public static OadrUserX509Credential generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_method.identifier: generateCredentials
focal_method.invocations: currentTimeMillis valueOf equals generateEccKeyPair equals generateRsaKeyPair generateCsr signCsr getOadr20bFingerprint writeToFile writeCrtToString writeToFile writeCrtToString writeToFile writeKeyToString writeToFile
focal_method.modifiers: public static
focal_method.parameters: (KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)
focal_method.return: OadrUserX509Credential
focal_method.signature: OadrUserX509Credential generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
  			String commonName, OadrPKIAlgorithm algo)