package be.iminds.ilabt.jfed.lowlevel;

import be.iminds.ilabt.jfed.util.KeyUtil;
import be.iminds.ilabt.jfed.util.RFC3339Util;
import org.testng.annotations.Test;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.Date;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class AbacCredentialTest {

    @Test
    public void testCreateSpeaksFor() throws Exception {
        Date expire = RFC3339Util.rfc3339StringToDate("2100-12-31T00:00:00Z");

        AbacCredential tst = AbacCredential.createSpeaksFor(expire, testCert2, testCert, testPrivateKey);

        System.out.println("Generated test ABAC SpeaksFor: "+tst.getCredentialXml());

        assertThat(tst.isSpeaksFor(), is(true));
        assertThat(tst.getCredentialXml().replaceAll("\n","").replaceAll("\r",""),
                is(equalTo(expectedCredentialXmlString.replaceAll("\n","").replaceAll("\r",""))));
    }

    @Test
    public void testKeyId() throws Exception {
        String keyId = AbacCredential.generateKeyId(wvdemeerCert);

        System.out.println("generated keyId="+keyId);
        System.out.println(" expected keyId="+wvdemeerKeyId);

        assertThat(keyId, is(equalTo(wvdemeerKeyId)));
    }

    @Test
    public void testParseAbac() throws Exception {
        AbacCredential cred = (AbacCredential) AnyCredential.createAutoDetect("test cred", expectedCredentialXmlString);

        assertThat(cred.isSpeaksFor(), is(true));

        assertThat(cred.getHeadKeyId(), is(equalTo("8de9389a0f75149bd6910734bb7c008fffe05904")));
        assertThat(cred.getTailKeyId(), is(equalTo("5d3aadc7a01ca922893a00142e49aa00d51c9b42")));
        assertThat(cred.getHeadRole(), is(equalTo("speaks_for_8de9389a0f75149bd6910734bb7c008fffe05904")));

        Date date = RFC3339Util.rfc3339StringToDate("2100-12-31T00:00:00Z");
        assertThat(cred.getExpires(), is(equalTo("2100-12-31T00:00:00Z")));
        assertThat(cred.getExpiresDate(), is(equalTo(date)));
    }




    private static final String expectedCredentialXmlString =
            "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><signed-credential xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.protogeni.net/resources/credential/credential.xsd\" xsi:schemaLocation=\"http://www.protogeni.net/resources/credential/ext/policy/1 http://www.protogeni.net/resources/credential/ext/policy/1/policy.xsd\">\n" +
                    "  <credential xml:id=\"_0\">\n" +
                    "\n" +
                    "        <type>abac</type>\n" +
                    "        <serial/>\n" +
                    "        <owner_gid/>\n" +
                    "        <target_gid/>\n" +
                    "        <uuid/>\n" +
                    "        <expires>2100-12-31T00:00:00Z</expires>\n" +
                    "        <abac>\n" +
                    "            <rt0>\n" +
                    "                <version>1.1</version>\n" +
                    "                <head>\n" +
                    "   <ABACprincipal><keyid>8de9389a0f75149bd6910734bb7c008fffe05904</keyid></ABACprincipal>\n" +
                    "   <role>speaks_for_8de9389a0f75149bd6910734bb7c008fffe05904</role>\n" +
                    "</head>\n" +
                    "<tail>\n" +
                    "   <ABACprincipal><keyid>5d3aadc7a01ca922893a00142e49aa00d51c9b42</keyid></ABACprincipal>\n" +
                    "</tail>\n" +
                    "\n" +
                    "            </rt0>\n" +
                    "        </abac>\n" +
                    "\n" +
                    "</credential>\n" +
                    "  <signatures>\n" +
                    "  <Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\" xml:id=\"Sig__0\">\n" +
                    "<SignedInfo>\n" +
                    "<CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\n" +
                    "<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\n" +
                    "<Reference URI=\"#_0\">\n" +
                    "<Transforms>\n" +
                    "<Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\n" +
                    "<Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\n" +
                    "</Transforms>\n" +
                    "<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\n" +
                    "<DigestValue>oK5N7PgvyQpRLpBp4mLGQkctw7g=</DigestValue>\n" +
                    "</Reference>\n" +
                    "</SignedInfo>\n" +
                    "<SignatureValue>d9lhBcX/15jfqw97cydwxEGxVoD4qbkfv95ZQEoDa/mXFg+j1+IKTa96cZE0Xhm7RJeIIxD2qz2r\n" +
                    "/pLx+m4gTBTpacj6nY9ciALgOYrn2n5J73cNzJi9Xm2eBCeM8AGAis4HJts3eacYHjjHV7Mmy7Rf\n" +
                    "CNwWquwqtlijIgZcD+Kh8HyDfI53ICFY1Wz3LQSyyoT/kgMj71xY+6sOBR3egyd6L8OsTxBY30sN\n" +
                    "Dk30d6wv11bjS+3ZHKMO72l6Xdgd/UQeSljrzcgxTsgprIJgG4QHO2VDLfql3Th5kzAWhFUJvM/H\n" +
                    "1/nM1mv/XIG1eoiZ/IWg0h+g9NU+SGA9tfR4Eg==</SignatureValue>\n" +
                    "<KeyInfo>\n" +
                    "<X509Data>\n" +
                    "<X509Certificate>MIIEozCCA4ugAwIBAgIJAKdm6CkA/TLMMA0GCSqGSIb3DQEBBQUAMIGRMQswCQYDVQQGEwJCRTET\n" +
                    "MBEGA1UECBMKU29tZS1TdGF0ZTEOMAwGA1UEBxMFR2hlbnQxDzANBgNVBAoTBmlNaW5kczEPMA0G\n" +
                    "A1UECxMGaWxhYi50MRQwEgYDVQQDEwtqRmVkIFRlc3RlcjElMCMGCSqGSIb3DQEJARYWamZlZEBs\n" +
                    "aXN0cy5mZWQ0ZmlyZS5ldTAgFw0xNDAzMjYwNzM1MThaGA8yMTUxMDIxNjA3MzUxOFowgZExCzAJ\n" +
                    "BgNVBAYTAkJFMRMwEQYDVQQIEwpTb21lLVN0YXRlMQ4wDAYDVQQHEwVHaGVudDEPMA0GA1UEChMG\n" +
                    "aU1pbmRzMQ8wDQYDVQQLEwZpbGFiLnQxFDASBgNVBAMTC2pGZWQgVGVzdGVyMSUwIwYJKoZIhvcN\n" +
                    "AQkBFhZqZmVkQGxpc3RzLmZlZDRmaXJlLmV1MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC\n" +
                    "AQEAt9DLTl6GDWg7RgCzepWyV9EpUfXUZUqQi1D8kJAWR5IcnyR1wCt5BqfUR5uBtvn2m2XSz3nD\n" +
                    "0jT6+sGsx0G1+50h31ukOA1JnRlvgENNiJztio76UP9eN0IrtFpuBK+g50kRrlrUhG/zfAV8snQp\n" +
                    "BO1Bue4YLJTf9mmnusTL2gWrzglGMalOfbIU2H3yjfPh5es5VOVutvNXpGGKVYoJrlOZ1SgkKwhl\n" +
                    "t+ANyrj6+cERaVqbgq1TeOOsFjdEq59HmP74eHTu0v9WrrWrlRbYElENbhDhGL2YXf0H9B+0eliT\n" +
                    "bkOly8ACIhGurjLKiPWIs6uKpaLLxcF0teQwsg0IFQIDAQABo4H5MIH2MB0GA1UdDgQWBBSN6Tia\n" +
                    "D3UUm9aRBzS7fACP/+BZBDCBxgYDVR0jBIG+MIG7gBSN6TiaD3UUm9aRBzS7fACP/+BZBKGBl6SB\n" +
                    "lDCBkTELMAkGA1UEBhMCQkUxEzARBgNVBAgTClNvbWUtU3RhdGUxDjAMBgNVBAcTBUdoZW50MQ8w\n" +
                    "DQYDVQQKEwZpTWluZHMxDzANBgNVBAsTBmlsYWIudDEUMBIGA1UEAxMLakZlZCBUZXN0ZXIxJTAj\n" +
                    "BgkqhkiG9w0BCQEWFmpmZWRAbGlzdHMuZmVkNGZpcmUuZXWCCQCnZugpAP0yzDAMBgNVHRMEBTAD\n" +
                    "AQH/MA0GCSqGSIb3DQEBBQUAA4IBAQA/QKeMMXDvoWzPYmPhnQKro4Bk7YKd9HGkrwQKAx2Qs/LL\n" +
                    "XV3pp6vYJ9t66XisfPZlz5l5L5uDzTdU98ugvrfdxCCPkPixFztytS1hbQXSc4V4Zv1tMy6cyKJO\n" +
                    "hzGR3t8f2tgn4kiBd6z1PaYci92f00/HuI8JQEYbOzC63ZboIHyK14voKVomqXANqVlm+UdSjt8L\n" +
                    "+v5v1vxt/hIeDZQHwHcP9iTvuNT1HZ47S38JUdX1vHU+YAMHetuBpDGOsM54OJT7IlXD140WNbgz\n" +
                    "nydvhEDK9cZZhb7DHJ/pNDUIkpUrhxlovpFi9rdhShOYL6XJEq4MlhDRNTM19qGRZIo9</X509Certificate>\n" +
                    "</X509Data>\n" +
                    "<KeyValue>\n" +
                    "<RSAKeyValue>\n" +
                    "<Modulus>\n" +
                    "t9DLTl6GDWg7RgCzepWyV9EpUfXUZUqQi1D8kJAWR5IcnyR1wCt5BqfUR5uBtvn2m2XSz3nD0jT6\n" +
                    "+sGsx0G1+50h31ukOA1JnRlvgENNiJztio76UP9eN0IrtFpuBK+g50kRrlrUhG/zfAV8snQpBO1B\n" +
                    "ue4YLJTf9mmnusTL2gWrzglGMalOfbIU2H3yjfPh5es5VOVutvNXpGGKVYoJrlOZ1SgkKwhlt+AN\n" +
                    "yrj6+cERaVqbgq1TeOOsFjdEq59HmP74eHTu0v9WrrWrlRbYElENbhDhGL2YXf0H9B+0eliTbkOl\n" +
                    "y8ACIhGurjLKiPWIs6uKpaLLxcF0teQwsg0IFQ==\n" +
                    "</Modulus>\n" +
                    "<Exponent>AQAB</Exponent>\n" +
                    "</RSAKeyValue>\n" +
                    "</KeyValue>\n" +
                    "</KeyInfo>\n" +
                    "</Signature></signatures>\n" +
                    "</signed-credential>";


    /* Note: This cert and key pair is generated for tests only, they are used nowhere "real". */
    private static final String testPemPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
            "MIIEowIBAAKCAQEAt9DLTl6GDWg7RgCzepWyV9EpUfXUZUqQi1D8kJAWR5IcnyR1\n" +
            "wCt5BqfUR5uBtvn2m2XSz3nD0jT6+sGsx0G1+50h31ukOA1JnRlvgENNiJztio76\n" +
            "UP9eN0IrtFpuBK+g50kRrlrUhG/zfAV8snQpBO1Bue4YLJTf9mmnusTL2gWrzglG\n" +
            "MalOfbIU2H3yjfPh5es5VOVutvNXpGGKVYoJrlOZ1SgkKwhlt+ANyrj6+cERaVqb\n" +
            "gq1TeOOsFjdEq59HmP74eHTu0v9WrrWrlRbYElENbhDhGL2YXf0H9B+0eliTbkOl\n" +
            "y8ACIhGurjLKiPWIs6uKpaLLxcF0teQwsg0IFQIDAQABAoIBABacqsXjPt5bWh9M\n" +
            "asfDroK7Cjg4433qZEmfFtK5xuPbB4ZUN+AB+QtmjeiZKqXVrg6DwiEfu4UaW12J\n" +
            "gbWpUbe4JriRT2xNxiZ7QIoovVr24wnOeOCJ6Y8mprWzAiG1cTfCd1hZeBcqpms1\n" +
            "SZeyTnF6tkEnFvY1AjAP40BIgUM6hamTNPZgwRuob2ISHrLljm1AIOGRTY1hDISi\n" +
            "KpfyY7yHTZJLwfUQVD6KBLg9YeiGy1NPzE9UmXrQlRooiipLw/kGA6SAoUblqvS3\n" +
            "kFqTg/qUFxF4VxbCg4FjGXCQY4ws71OfGo4zgN/DmiO1vrHKnJvLIkjpTacMy2gr\n" +
            "PrhWWUECgYEA8pX9euSto87peYxYkDYnQXYAK65X4mFIOV8CYW6hXMbltS5z/1hW\n" +
            "dZKCNJr8ui6LpbcWTKmTYjDSxR15w+kuF1Trib682pQ2E3LCPYneBOJ0Hogv+D02\n" +
            "KF5PsCOYcReVwHq8H1dEck9j2g5wGLaajDWw3Vu7o3trT6zbUQD72YkCgYEAwfrc\n" +
            "RfKOk53HLSipM7Ipr+hPtYLrUExQTip8dh+3mAtXeMOe/Nm8P5ERSBAa8ETNx9fD                                                                                                                              \n" +
            "pzcQY/7GqgtLwAzgIM73yRSnUe0mDV4JwCeteJ8wpdB+xbPprPgp+4xj0oO0zfrh                                                                                                                              \n" +
            "9Gi7Wl9lsFHGz03WLcLks2JNk9yEbWdStIUFsy0CgYEA1wkaLwvy2BgcYkCEaSF3                                                                                                                              \n" +
            "3tEpCY98HBI8IY8U3yVgKIuvJ9JLxPebfJEollUk3i1QYM9RFxfiq9G3pD+ipoVW                                                                                                                              \n" +
            "9Bu0xt+rLN7gqJC7mi1R/2Z1pHL4gsZP8azYWrzS7r0HZB3oEKgc5m91hd/yghWs                                                                                                                              \n" +
            "HcmiRDaCuEI5N+F0b/O9THECgYAPqqARsiZbu7lzZz5LI4+EWoHdigZRROiTd5D3                                                                                                                              \n" +
            "xVYBnKDi6wGzMC6o/6FirZJPZ28rPbzai3LycIhBAYqLpz6Ox8hxYA6najzRhY/K                                                                                                                              \n" +
            "CipTfJ/kNHOYqhAsXRqe61bAkMyQeju3jqHbCatf0yr4YTP0HDJ2XnEfiQbVAyxF                                                                                                                              \n" +
            "0hyEvQKBgDOyK9omGnMAFTZOMUu94y+atccMqHyxCDLZl6yh9ipB+gvGTDh9c6+G\n" +
            "mMua/QVmH8yFT3NWM++2P54vuUFgrn3WmIpq4pkIoQ5qF9xi192oC7Kocwwy3OTn\n" +
            "lmyfwPhutAcGcMFZcQoNPXPzrCj1Ku4duXtO6jkWy3kTqvr8ib8j\n" +
            "-----END RSA PRIVATE KEY-----";
    private static final String testPemCert = "-----BEGIN CERTIFICATE-----\n" +
            "MIIEozCCA4ugAwIBAgIJAKdm6CkA/TLMMA0GCSqGSIb3DQEBBQUAMIGRMQswCQYD\n" +
            "VQQGEwJCRTETMBEGA1UECBMKU29tZS1TdGF0ZTEOMAwGA1UEBxMFR2hlbnQxDzAN\n" +
            "BgNVBAoTBmlNaW5kczEPMA0GA1UECxMGaWxhYi50MRQwEgYDVQQDEwtqRmVkIFRl\n" +
            "c3RlcjElMCMGCSqGSIb3DQEJARYWamZlZEBsaXN0cy5mZWQ0ZmlyZS5ldTAgFw0x\n" +
            "NDAzMjYwNzM1MThaGA8yMTUxMDIxNjA3MzUxOFowgZExCzAJBgNVBAYTAkJFMRMw\n" +
            "EQYDVQQIEwpTb21lLVN0YXRlMQ4wDAYDVQQHEwVHaGVudDEPMA0GA1UEChMGaU1p\n" +
            "bmRzMQ8wDQYDVQQLEwZpbGFiLnQxFDASBgNVBAMTC2pGZWQgVGVzdGVyMSUwIwYJ\n" +
            "KoZIhvcNAQkBFhZqZmVkQGxpc3RzLmZlZDRmaXJlLmV1MIIBIjANBgkqhkiG9w0B\n" +
            "AQEFAAOCAQ8AMIIBCgKCAQEAt9DLTl6GDWg7RgCzepWyV9EpUfXUZUqQi1D8kJAW\n" +
            "R5IcnyR1wCt5BqfUR5uBtvn2m2XSz3nD0jT6+sGsx0G1+50h31ukOA1JnRlvgENN\n" +
            "iJztio76UP9eN0IrtFpuBK+g50kRrlrUhG/zfAV8snQpBO1Bue4YLJTf9mmnusTL\n" +
            "2gWrzglGMalOfbIU2H3yjfPh5es5VOVutvNXpGGKVYoJrlOZ1SgkKwhlt+ANyrj6\n" +
            "+cERaVqbgq1TeOOsFjdEq59HmP74eHTu0v9WrrWrlRbYElENbhDhGL2YXf0H9B+0\n" +
            "eliTbkOly8ACIhGurjLKiPWIs6uKpaLLxcF0teQwsg0IFQIDAQABo4H5MIH2MB0G\n" +
            "A1UdDgQWBBSN6TiaD3UUm9aRBzS7fACP/+BZBDCBxgYDVR0jBIG+MIG7gBSN6Tia\n" +
            "D3UUm9aRBzS7fACP/+BZBKGBl6SBlDCBkTELMAkGA1UEBhMCQkUxEzARBgNVBAgT\n" +
            "ClNvbWUtU3RhdGUxDjAMBgNVBAcTBUdoZW50MQ8wDQYDVQQKEwZpTWluZHMxDzAN\n" +
            "BgNVBAsTBmlsYWIudDEUMBIGA1UEAxMLakZlZCBUZXN0ZXIxJTAjBgkqhkiG9w0B\n" +
            "CQEWFmpmZWRAbGlzdHMuZmVkNGZpcmUuZXWCCQCnZugpAP0yzDAMBgNVHRMEBTAD\n" +
            "AQH/MA0GCSqGSIb3DQEBBQUAA4IBAQA/QKeMMXDvoWzPYmPhnQKro4Bk7YKd9HGk\n" +
            "rwQKAx2Qs/LLXV3pp6vYJ9t66XisfPZlz5l5L5uDzTdU98ugvrfdxCCPkPixFzty\n" +
            "tS1hbQXSc4V4Zv1tMy6cyKJOhzGR3t8f2tgn4kiBd6z1PaYci92f00/HuI8JQEYb\n" +
            "OzC63ZboIHyK14voKVomqXANqVlm+UdSjt8L+v5v1vxt/hIeDZQHwHcP9iTvuNT1\n" +
            "HZ47S38JUdX1vHU+YAMHetuBpDGOsM54OJT7IlXD140WNbgznydvhEDK9cZZhb7D\n" +
            "HJ/pNDUIkpUrhxlovpFi9rdhShOYL6XJEq4MlhDRNTM19qGRZIo9\n" +
            "-----END CERTIFICATE-----";
    private static final String testPemCert2 = "-----BEGIN CERTIFICATE-----\n" +
            "MIIDczCCAlugAwIBAgIJAL/+/v/MmM5BMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\n" +
            "BAYTAkJFMQwwCgYDVQQIDANPVkwxDTALBgNVBAcMBEdlbnQxDzANBgNVBAoMBmlN\n" +
            "aW5kczESMBAGA1UEAwwJVGVzdCBUb29sMCAXDTE1MTExODEyMDczM1oYDzIxNTIx\n" +
            "MDEwMTIwNzMzWjBPMQswCQYDVQQGEwJCRTEMMAoGA1UECAwDT1ZMMQ0wCwYDVQQH\n" +
            "DARHZW50MQ8wDQYDVQQKDAZpTWluZHMxEjAQBgNVBAMMCVRlc3QgVG9vbDCCASIw\n" +
            "DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKslQvr9oR7C7b2bcRUELhzbvcIA\n" +
            "NumqsYt/QgBSQzEZjsahoZQl+BuwqhmELlD1m02bUW+IHz7Vc9d+W0l7TmAMUzq8\n" +
            "sgSfnLpFKUvaZa5JuZoOwCvVUKo7xMbPm7w1ep2lh7Lblv/rgRW+33D4hXu8MVNU\n" +
            "4ASTWM1re0S7xhC+o8w+SP8D/FhA/52O7bbtIN90ajOvYiLnq+gfvU6eIh74fP+g\n" +
            "st1qqDZuht/Q8N6civU10t4jVcCl5u3JoXSjfxgoXicN3gG3VJCUA5bjI7o0SmU6\n" +
            "swAD4H0WPSRA4iMd82MolXW5CAwaqBi0cZv9mD3q3djxSl6jZCJMNSIkpFcCAwEA\n" +
            "AaNQME4wHQYDVR0OBBYEFF06rcegHKkiiToAFC5JqgDVHJtCMB8GA1UdIwQYMBaA\n" +
            "FF06rcegHKkiiToAFC5JqgDVHJtCMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEL\n" +
            "BQADggEBAGzgTdvukaMF6dgNS8ae5SLBq876BZFkX7KSE+9Lc/Gj4TClvP7S1ZpQ\n" +
            "PlEj9uQgRYFgVz+AGgy3ehLjuMDxcimKi+23TMwlLqrerqm9McfsMa7Q00Q/9V9e\n" +
            "2q28Jk2wknP8Fm7stL7aBJ+mK1dtMcYiHl1FDxdPilb8YguND1TJ+zfghSmBEMuy\n" +
            "C15t92J5v3xm+3cmuEz3m6wZEnrqLkbzXd1SOUCoxF/f9K5pI8UjCkRjgWOkn/SZ\n" +
            "qiheWk4+NOwQwlvNwFlMT+9o7ZM4j3JglG0Wbqd1yxVGaChc+Pt4ClC7uxslCdfI\n" +
            "sMilLddgHu+BsfI2ClbRLm2J8AwYv14=\n" +
            "-----END CERTIFICATE-----";
    private static final PrivateKey testPrivateKey;
    private static final PublicKey testPublicKey;
    private static final X509Certificate testCert;
    private static final X509Certificate testCert2;

    private static final String wvdemeerCertString = "-----BEGIN CERTIFICATE-----\n" +
            "MIIEDDCCA3WgAwIBAgIDAgcaMA0GCSqGSIb3DQEBBAUAMIG1MQswCQYDVQQGEwJC\n" +
            "RTELMAkGA1UECBMCT1YxDjAMBgNVBAcTBUdoZW50MRgwFgYDVQQKEw9pTWluZHMg\n" +
            "LSBpbGFiLnQxHjAcBgNVBAsTFUNlcnRpZmljYXRlIEF1dGhvcml0eTEjMCEGA1UE\n" +
            "AxMaYm9zcy53YWxsMi5pbGFidC5pbWluZHMuYmUxKjAoBgkqhkiG9w0BCQEWG3Z3\n" +
            "YWxsLW9wc0BhdGxhbnRpcy51Z2VudC5iZTAeFw0xNTA5MjkwNjEwMjVaFw0xNjA5\n" +
            "MjgwNjEwMjVaMIGyMQswCQYDVQQGEwJCRTELMAkGA1UECBMCT1YxGDAWBgNVBAoT\n" +
            "D2lNaW5kcyAtIGlsYWIudDEeMBwGA1UECxMVaW1pbmRzLXdhbGwyLnd2ZGVtZWVy\n" +
            "MS0wKwYDVQQDEyRiNzU2MTljYy0xNmI5LTExZTMtOTY2YS0wMDE1MTdiZWNkYzEx\n" +
            "LTArBgkqhkiG9w0BCQEWHnd2ZGVtZWVyQHdhbGwyLmlsYWJ0LmltaW5kcy5iZTCB\n" +
            "nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA37Y9en0GR8G3VZfclZJ6W2njdunq\n" +
            "eXdpDtFm8RsHMhOcjv9ZDEZozEwN5h8RZM1Enx3XyR16gHNL/+mClqJeXZ0UB37F\n" +
            "IBXhNIJH99OQED+/ZeA14U3RutgfmmWK1Pq0rYWl+lSPY30u9WrKRzUtTdq2syY3\n" +
            "j7cS6kWiBM/lrfECAwEAAaOCASkwggElMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYE\n" +
            "FKcVS7s7d5gVtjUXbBmzUwsA66RNMIGQBgNVHREEgYgwgYWGNHVybjpwdWJsaWNp\n" +
            "ZDpJRE4rd2FsbDIuaWxhYnQuaW1pbmRzLmJlK3VzZXIrd3ZkZW1lZXKBHnd2ZGVt\n" +
            "ZWVyQHdhbGwyLmlsYWJ0LmltaW5kcy5iZYYtdXJuOnV1aWQ6Yjc1NjE5Y2MtMTZi\n" +
            "OS0xMWUzLTk2NmEtMDAxNTE3YmVjZGMxMGMGCCsGAQUFBwEBBFcwVTBTBhRpg8yT\n" +
            "gKiYzKjHvbGngICqrteKG4Y7aHR0cHM6Ly93d3cud2FsbDIuaWxhYnQuaW1pbmRz\n" +
            "LmJlOjEyMzY5L3Byb3RvZ2VuaS94bWxycGMvc2EwDQYJKoZIhvcNAQEEBQADgYEA\n" +
            "IJxpE7n6PLvF5+UAoLWJAmxyKoT+43Bx3lGNlE4MKlQkBz3UgqEcmJq3OSL9zvKQ\n" +
            "Lq/tnbzFi+UjjxG9GwSsTY48/kC8Jlf4V14MKJc+nNp1vMZKqPKgNdiYVIGuMIMD\n" +
            "T1zbf+vmEohMTbajw2GlkCuZ2e3K8XX52h9UkPlOpvo=\n" +
            "-----END CERTIFICATE-----\n";
    private static final X509Certificate wvdemeerCert;
    private static final String wvdemeerKeyId = "a7154bbb3b779815b635176c19b3530b00eba44d";



    static {
        PrivateKey pk = null;
        X509Certificate c = null;
        X509Certificate c2 = null;
        try {
            pk = KeyUtil.pemToAnyPrivateKey(testPemPrivateKey, null);
            assert pk != null;
            c = KeyUtil.pemToX509Certificate(testPemCert);
            assert c != null;
            c2 = KeyUtil.pemToX509Certificate(testPemCert2);
            assert c2 != null;
            wvdemeerCert = KeyUtil.pemToX509Certificate(wvdemeerCertString);
            assert wvdemeerCert != null;
        } catch (Exception e) {
            throw new RuntimeException("Static initialize of XmlUtilTest failed: " + e.getMessage(), e);
        }
        testPrivateKey = pk;
        testCert = c;
        testCert2 = c2;
        testPublicKey = c.getPublicKey();
    }
}