diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
commit | dd828f42a5c83b4270d4fbf6fce2da1878f1e84a (patch) | |
tree | fdd4b68fa1020f2b6426034c94823419a7236200 /security | |
parent | fdb2704414a9ed92394ada0d1395e4db86889465 (diff) | |
download | libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.zip libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.gz libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'security')
417 files changed, 47888 insertions, 3291 deletions
diff --git a/security/src/main/files/cacerts.bks b/security/src/main/files/cacerts.bks Binary files differindex ee37790..1d06dc0 100644 --- a/security/src/main/files/cacerts.bks +++ b/security/src/main/files/cacerts.bks diff --git a/security/src/main/files/cacerts/399e7759.0 b/security/src/main/files/cacerts/399e7759.0 new file mode 100644 index 0000000..9bd63b3 --- /dev/null +++ b/security/src/main/files/cacerts/399e7759.0 @@ -0,0 +1,83 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: + 08:3b:e0:56:90:42:46:b1:a1:75:6a:c9:59:91:c7:4a + Signature Algorithm: sha1WithRSAEncryption + Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root CA + Validity + Not Before: Nov 10 00:00:00 2006 GMT + Not After : Nov 10 00:00:00 2031 GMT + Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root CA + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (2048 bit) + Modulus (2048 bit): + 00:e2:3b:e1:11:72:de:a8:a4:d3:a3:57:aa:50:a2: + 8f:0b:77:90:c9:a2:a5:ee:12:ce:96:5b:01:09:20: + cc:01:93:a7:4e:30:b7:53:f7:43:c4:69:00:57:9d: + e2:8d:22:dd:87:06:40:00:81:09:ce:ce:1b:83:bf: + df:cd:3b:71:46:e2:d6:66:c7:05:b3:76:27:16:8f: + 7b:9e:1e:95:7d:ee:b7:48:a3:08:da:d6:af:7a:0c: + 39:06:65:7f:4a:5d:1f:bc:17:f8:ab:be:ee:28:d7: + 74:7f:7a:78:99:59:85:68:6e:5c:23:32:4b:bf:4e: + c0:e8:5a:6d:e3:70:bf:77:10:bf:fc:01:f6:85:d9: + a8:44:10:58:32:a9:75:18:d5:d1:a2:be:47:e2:27: + 6a:f4:9a:33:f8:49:08:60:8b:d4:5f:b4:3a:84:bf: + a1:aa:4a:4c:7d:3e:cf:4f:5f:6c:76:5e:a0:4b:37: + 91:9e:dc:22:e6:6d:ce:14:1a:8e:6a:cb:fe:cd:b3: + 14:64:17:c7:5b:29:9e:32:bf:f2:ee:fa:d3:0b:42: + d4:ab:b7:41:32:da:0c:d4:ef:f8:81:d5:bb:8d:58: + 3f:b5:1b:e8:49:28:a2:70:da:31:04:dd:f7:b2:16: + f2:4c:0a:4e:07:a8:ed:4a:3d:5e:b5:7f:a3:90:c3: + af:27 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Key Usage: critical + Digital Signature, Certificate Sign, CRL Sign + X509v3 Basic Constraints: critical + CA:TRUE + X509v3 Subject Key Identifier: + 03:DE:50:35:56:D1:4C:BB:66:F0:A3:E2:1B:1B:C3:97:B2:3D:D1:55 + X509v3 Authority Key Identifier: + keyid:03:DE:50:35:56:D1:4C:BB:66:F0:A3:E2:1B:1B:C3:97:B2:3D:D1:55 + + Signature Algorithm: sha1WithRSAEncryption + cb:9c:37:aa:48:13:12:0a:fa:dd:44:9c:4f:52:b0:f4:df:ae: + 04:f5:79:79:08:a3:24:18:fc:4b:2b:84:c0:2d:b9:d5:c7:fe: + f4:c1:1f:58:cb:b8:6d:9c:7a:74:e7:98:29:ab:11:b5:e3:70: + a0:a1:cd:4c:88:99:93:8c:91:70:e2:ab:0f:1c:be:93:a9:ff: + 63:d5:e4:07:60:d3:a3:bf:9d:5b:09:f1:d5:8e:e3:53:f4:8e: + 63:fa:3f:a7:db:b4:66:df:62:66:d6:d1:6e:41:8d:f2:2d:b5: + ea:77:4a:9f:9d:58:e2:2b:59:c0:40:23:ed:2d:28:82:45:3e: + 79:54:92:26:98:e0:80:48:a8:37:ef:f0:d6:79:60:16:de:ac: + e8:0e:cd:6e:ac:44:17:38:2f:49:da:e1:45:3e:2a:b9:36:53: + cf:3a:50:06:f7:2e:e8:c4:57:49:6c:61:21:18:d5:04:ad:78: + 3c:2c:3a:80:6b:a7:eb:af:15:14:e9:d8:89:c1:b9:38:6c:e2: + 91:6c:8a:ff:64:b9:77:25:57:30:c0:1b:24:a3:e1:dc:e9:df: + 47:7c:b5:b4:24:08:05:30:ec:2d:bd:0b:bf:45:bf:50:b9:a9: + f3:eb:98:01:12:ad:c8:88:c6:98:34:5f:8d:0a:3c:c6:e9:d5: + 95:95:6d:de +SHA1 Fingerprint=A8:98:5D:3A:65:E5:E5:C4:B2:D7:D6:6D:40:C6:DD:2F:B1:9C:54:36 +-----BEGIN CERTIFICATE----- +MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh +MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD +QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT +MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j +b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB +CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97 +nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt +43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P +T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4 +gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO +BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR +TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw +DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr +hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg +06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF +PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls +YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk +CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= +-----END CERTIFICATE----- diff --git a/security/src/main/files/cacerts/69105f4f.0 b/security/src/main/files/cacerts/69105f4f.0 new file mode 100644 index 0000000..ae403f0 --- /dev/null +++ b/security/src/main/files/cacerts/69105f4f.0 @@ -0,0 +1,83 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: + 0c:e7:e0:e5:17:d8:46:fe:8f:e5:60:fc:1b:f0:30:39 + Signature Algorithm: sha1WithRSAEncryption + Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Assured ID Root CA + Validity + Not Before: Nov 10 00:00:00 2006 GMT + Not After : Nov 10 00:00:00 2031 GMT + Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Assured ID Root CA + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (2048 bit) + Modulus (2048 bit): + 00:ad:0e:15:ce:e4:43:80:5c:b1:87:f3:b7:60:f9: + 71:12:a5:ae:dc:26:94:88:aa:f4:ce:f5:20:39:28: + 58:60:0c:f8:80:da:a9:15:95:32:61:3c:b5:b1:28: + 84:8a:8a:dc:9f:0a:0c:83:17:7a:8f:90:ac:8a:e7: + 79:53:5c:31:84:2a:f6:0f:98:32:36:76:cc:de:dd: + 3c:a8:a2:ef:6a:fb:21:f2:52:61:df:9f:20:d7:1f: + e2:b1:d9:fe:18:64:d2:12:5b:5f:f9:58:18:35:bc: + 47:cd:a1:36:f9:6b:7f:d4:b0:38:3e:c1:1b:c3:8c: + 33:d9:d8:2f:18:fe:28:0f:b3:a7:83:d6:c3:6e:44: + c0:61:35:96:16:fe:59:9c:8b:76:6d:d7:f1:a2:4b: + 0d:2b:ff:0b:72:da:9e:60:d0:8e:90:35:c6:78:55: + 87:20:a1:cf:e5:6d:0a:c8:49:7c:31:98:33:6c:22: + e9:87:d0:32:5a:a2:ba:13:82:11:ed:39:17:9d:99: + 3a:72:a1:e6:fa:a4:d9:d5:17:31:75:ae:85:7d:22: + ae:3f:01:46:86:f6:28:79:c8:b1:da:e4:57:17:c4: + 7e:1c:0e:b0:b4:92:a6:56:b3:bd:b2:97:ed:aa:a7: + f0:b7:c5:a8:3f:95:16:d0:ff:a1:96:eb:08:5f:18: + 77:4f + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Key Usage: critical + Digital Signature, Certificate Sign, CRL Sign + X509v3 Basic Constraints: critical + CA:TRUE + X509v3 Subject Key Identifier: + 45:EB:A2:AF:F4:92:CB:82:31:2D:51:8B:A7:A7:21:9D:F3:6D:C8:0F + X509v3 Authority Key Identifier: + keyid:45:EB:A2:AF:F4:92:CB:82:31:2D:51:8B:A7:A7:21:9D:F3:6D:C8:0F + + Signature Algorithm: sha1WithRSAEncryption + a2:0e:bc:df:e2:ed:f0:e3:72:73:7a:64:94:bf:f7:72:66:d8: + 32:e4:42:75:62:ae:87:eb:f2:d5:d9:de:56:b3:9f:cc:ce:14: + 28:b9:0d:97:60:5c:12:4c:58:e4:d3:3d:83:49:45:58:97:35: + 69:1a:a8:47:ea:56:c6:79:ab:12:d8:67:81:84:df:7f:09:3c: + 94:e6:b8:26:2c:20:bd:3d:b3:28:89:f7:5f:ff:22:e2:97:84: + 1f:e9:65:ef:87:e0:df:c1:67:49:b3:5d:eb:b2:09:2a:eb:26: + ed:78:be:7d:3f:2b:f3:b7:26:35:6d:5f:89:01:b6:49:5b:9f: + 01:05:9b:ab:3d:25:c1:cc:b6:7f:c2:f1:6f:86:c6:fa:64:68: + eb:81:2d:94:eb:42:b7:fa:8c:1e:dd:62:f1:be:50:67:b7:6c: + bd:f3:f1:1f:6b:0c:36:07:16:7f:37:7c:a9:5b:6d:7a:f1:12: + 46:60:83:d7:27:04:be:4b:ce:97:be:c3:67:2a:68:11:df:80: + e7:0c:33:66:bf:13:0d:14:6e:f3:7f:1f:63:10:1e:fa:8d:1b: + 25:6d:6c:8f:a5:b7:61:01:b1:d2:a3:26:a1:10:71:9d:ad:e2: + c3:f9:c3:99:51:b7:2b:07:08:ce:2e:e6:50:b2:a7:fa:0a:45: + 2f:a2:f0:f2 +SHA1 Fingerprint=05:63:B8:63:0D:62:D7:5A:BB:C8:AB:1E:4B:DF:B5:A8:99:B2:4D:43 +-----BEGIN CERTIFICATE----- +MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBl +MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv +b3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAwMDAwWjBlMQswCQYDVQQG +EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl +cnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7c +JpSIqvTO9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYP +mDI2dsze3Tyoou9q+yHyUmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+ +wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4 +VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpyoeb6pNnVFzF1roV9Iq4/ +AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whfGHdPAgMB +AAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW +BBRF66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYun +pyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRC +dWKuh+vy1dneVrOfzM4UKLkNl2BcEkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTf +fwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38FnSbNd67IJKusm7Xi+fT8r87cm +NW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i8b5QZ7dsvfPx +H2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe ++o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g== +-----END CERTIFICATE----- diff --git a/security/src/main/files/cacerts/81b9768f.0 b/security/src/main/files/cacerts/81b9768f.0 new file mode 100644 index 0000000..663fc2f --- /dev/null +++ b/security/src/main/files/cacerts/81b9768f.0 @@ -0,0 +1,84 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: + 02:ac:5c:26:6a:0b:40:9b:8f:0b:79:f2:ae:46:25:77 + Signature Algorithm: sha1WithRSAEncryption + Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA + Validity + Not Before: Nov 10 00:00:00 2006 GMT + Not After : Nov 10 00:00:00 2031 GMT + Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (2048 bit) + Modulus (2048 bit): + 00:c6:cc:e5:73:e6:fb:d4:bb:e5:2d:2d:32:a6:df: + e5:81:3f:c9:cd:25:49:b6:71:2a:c3:d5:94:34:67: + a2:0a:1c:b0:5f:69:a6:40:b1:c4:b7:b2:8f:d0:98: + a4:a9:41:59:3a:d3:dc:94:d6:3c:db:74:38:a4:4a: + cc:4d:25:82:f7:4a:a5:53:12:38:ee:f3:49:6d:71: + 91:7e:63:b6:ab:a6:5f:c3:a4:84:f8:4f:62:51:be: + f8:c5:ec:db:38:92:e3:06:e5:08:91:0c:c4:28:41: + 55:fb:cb:5a:89:15:7e:71:e8:35:bf:4d:72:09:3d: + be:3a:38:50:5b:77:31:1b:8d:b3:c7:24:45:9a:a7: + ac:6d:00:14:5a:04:b7:ba:13:eb:51:0a:98:41:41: + 22:4e:65:61:87:81:41:50:a6:79:5c:89:de:19:4a: + 57:d5:2e:e6:5d:1c:53:2c:7e:98:cd:1a:06:16:a4: + 68:73:d0:34:04:13:5c:a1:71:d3:5a:7c:55:db:5e: + 64:e1:37:87:30:56:04:e5:11:b4:29:80:12:f1:79: + 39:88:a2:02:11:7c:27:66:b7:88:b7:78:f2:ca:0a: + a8:38:ab:0a:64:c2:bf:66:5d:95:84:c1:a1:25:1e: + 87:5d:1a:50:0b:20:12:cc:41:bb:6e:0b:51:38:b8: + 4b:cb + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Key Usage: critical + Digital Signature, Certificate Sign, CRL Sign + X509v3 Basic Constraints: critical + CA:TRUE + X509v3 Subject Key Identifier: + B1:3E:C3:69:03:F8:BF:47:01:D4:98:26:1A:08:02:EF:63:64:2B:C3 + X509v3 Authority Key Identifier: + keyid:B1:3E:C3:69:03:F8:BF:47:01:D4:98:26:1A:08:02:EF:63:64:2B:C3 + + Signature Algorithm: sha1WithRSAEncryption + 1c:1a:06:97:dc:d7:9c:9f:3c:88:66:06:08:57:21:db:21:47: + f8:2a:67:aa:bf:18:32:76:40:10:57:c1:8a:f3:7a:d9:11:65: + 8e:35:fa:9e:fc:45:b5:9e:d9:4c:31:4b:b8:91:e8:43:2c:8e: + b3:78:ce:db:e3:53:79:71:d6:e5:21:94:01:da:55:87:9a:24: + 64:f6:8a:66:cc:de:9c:37:cd:a8:34:b1:69:9b:23:c8:9e:78: + 22:2b:70:43:e3:55:47:31:61:19:ef:58:c5:85:2f:4e:30:f6: + a0:31:16:23:c8:e7:e2:65:16:33:cb:bf:1a:1b:a0:3d:f8:ca: + 5e:8b:31:8b:60:08:89:2d:0c:06:5c:52:b7:c4:f9:0a:98:d1: + 15:5f:9f:12:be:7c:36:63:38:bd:44:a4:7f:e4:26:2b:0a:c4: + 97:69:0d:e9:8c:e2:c0:10:57:b8:c8:76:12:91:55:f2:48:69: + d8:bc:2a:02:5b:0f:44:d4:20:31:db:f4:ba:70:26:5d:90:60: + 9e:bc:4b:17:09:2f:b4:cb:1e:43:68:c9:07:27:c1:d2:5c:f7: + ea:21:b9:68:12:9c:3c:9c:bf:9e:fc:80:5c:9b:63:cd:ec:47: + aa:25:27:67:a0:37:f3:00:82:7d:54:d7:a9:f8:e9:2e:13:a3: + 77:e8:1f:4a +SHA1 Fingerprint=5F:B7:EE:06:33:E2:59:DB:AD:0C:4C:9A:E6:D3:8F:1A:61:C7:DC:25 +-----BEGIN CERTIFICATE----- +MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs +MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j +ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL +MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 +LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug +RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm ++9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW +PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM +xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB +Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3 +hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg +EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF +MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA +FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec +nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z +eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF +hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2 +Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe +vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep ++OkuE6N36B9K +-----END CERTIFICATE----- diff --git a/security/src/main/files/certimport.sh b/security/src/main/files/certimport.sh index fe3f943..7c0fab0 100755 --- a/security/src/main/files/certimport.sh +++ b/security/src/main/files/certimport.sh @@ -1,8 +1,5 @@ #!/bin/bash # This script was tested to work with bouncycastle 1.32. -# -# (NOTE: keytool does not pick up bouncycastle's jce provider jar -# unless it is installed under the system jar directory) set -x set -e @@ -29,6 +26,7 @@ for cert in `ls -1 cacerts` -keystore $CERTSTORE \ -storetype BKS \ -provider org.bouncycastle.jce.provider.BouncyCastleProvider \ + -providerpath /usr/share/java/bcprov.jar \ -storepass $STOREPASS let "COUNTER=$COUNTER + 1" done diff --git a/security/src/main/java/java/security/AccessControlException.java b/security/src/main/java/java/security/AccessControlException.java index 31968c0..1710e77 100644 --- a/security/src/main/java/java/security/AccessControlException.java +++ b/security/src/main/java/java/security/AccessControlException.java @@ -23,40 +23,38 @@ package java.security; /** - * This runtime exception is thrown when an access control check indicates that - * access should not be granted. + * {@code AccessControlException} is thrown if the access control infrastructure + * denies protected access due to missing permissions. * + * @since Android 1.0 */ public class AccessControlException extends SecurityException { private static final long serialVersionUID = 5138225684096988535L; - /** - * @com.intel.drl.spec_ref - */ private Permission perm; // Named as demanded by Serialized Form. /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code AccessControlException} with the + * given message. * * @param message - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public AccessControlException(String message) { super(message); } /** - * Constructs a new instance of this class with its walkback, message and - * associated permission all filled in. - * + * Constructs a new instance of {@code AccessControlException} with the + * given message and the requested {@code Permission} which was not granted. * * @param message - * String The detail message for the exception. + * the detail message for the exception. * @param perm - * Permission The failed permission. + * the requested {@code Permission} which was not granted. + * @since Android 1.0 */ public AccessControlException(String message, Permission perm) { super(message); @@ -64,10 +62,11 @@ public class AccessControlException extends SecurityException { } /** - * Returns the receiver's permission. - * + * Returns the requested permission that caused this Exception or {@code + * null} if there is no corresponding {@code Permission}. * - * @return Permission the receiver's permission + * @return the requested permission that caused this Exception, maybe {@code null}. + * @since Android 1.0 */ public Permission getPermission() { return perm; diff --git a/security/src/main/java/java/security/AlgorithmParameterGenerator.java b/security/src/main/java/java/security/AlgorithmParameterGenerator.java index 7c10354..199efa1 100644 --- a/security/src/main/java/java/security/AlgorithmParameterGenerator.java +++ b/security/src/main/java/java/security/AlgorithmParameterGenerator.java @@ -27,12 +27,12 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.security.fortress.Engine; import org.apache.harmony.security.internal.nls.Messages; - /** - * @com.intel.drl.spec_ref + * {@code AlgorithmParameterGenerator} is an engine class which is capable of + * generating parameters for the algorithm it was initialized with. * + * @since Android 1.0 */ - public class AlgorithmParameterGenerator { // Store spi service name @@ -54,8 +54,16 @@ public class AlgorithmParameterGenerator { private final String algorithm; /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code AlgorithmParameterGenerator} with the + * given arguments. + * + * @param paramGenSpi + * a concrete implementation, this engine instance delegates to. + * @param provider + * the provider. + * @param algorithm + * the name of the algorithm. + * @since Android 1.0 */ protected AlgorithmParameterGenerator( AlgorithmParameterGeneratorSpi paramGenSpi, Provider provider, @@ -66,17 +74,28 @@ public class AlgorithmParameterGenerator { } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the algorithm. + * + * @return the name of the algorithm. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code AlgorithmParameterGenerator} for the + * specified algorithm. * - * throws NullPointerException when algorithm is null + * @param algorithm + * the name of the algorithm to use. + * @return a new instance of {@code AlgorithmParameterGenerator} for the + * specified algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static AlgorithmParameterGenerator getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -92,10 +111,23 @@ public class AlgorithmParameterGenerator { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code AlgorithmParameterGenerator} from the + * specified provider for the specified algorithm. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException) as in 1.4 release + * @param algorithm + * the name of the algorithm to use. + * @param provider + * name of the provider of the {@code + * AlgorithmParameterGenerator}. + * @return a new instance of {@code AlgorithmParameterGenerator} for the + * specified algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static AlgorithmParameterGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, @@ -112,10 +144,20 @@ public class AlgorithmParameterGenerator { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code AlgorithmParameterGenerator} from the + * specified provider for the specified algorithm. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException) as in 1.4 release + * @param algorithm + * the name of the algorithm to use. + * @param provider + * the provider of the {@code AlgorithmParameterGenerator}. + * @return a new instance of {@code AlgorithmParameterGenerator} for the + * specified algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static AlgorithmParameterGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -134,32 +176,55 @@ public class AlgorithmParameterGenerator { } /** - * @com.intel.drl.spec_ref - * + * Returns the provider associated with this {@code + * AlgorithmParameterGenerator}. + * + * @return the provider associated with this {@code + * AlgorithmParameterGenerator}. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameterGenerator} with the given size. + * The default parameter set and a default {@code SecureRandom} instance + * will be used. + * + * @param size + * the size (in number of bits). + * @since Android 1.0 */ public final void init(int size) { spiImpl.engineInit(size, randm); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameterGenerator} with the given size + * and the given {@code SecureRandom}. The default parameter set will be + * used. + * + * @param size + * the size (in number of bits). + * @param random + * the source of randomness. + * @since Android 1.0 */ public final void init(int size, SecureRandom random) { spiImpl.engineInit(size, random); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameterGenerator} with the given {@code + * AlgorithmParameterSpec}. A default {@code SecureRandom} instance will be + * used. + * + * @param genParamSpec + * the parameters to use. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are not supported. + * @since Android 1.0 */ public final void init(AlgorithmParameterSpec genParamSpec) throws InvalidAlgorithmParameterException { @@ -167,8 +232,16 @@ public class AlgorithmParameterGenerator { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameterGenerator} with the given + * {@code AlgorithmParameterSpec} and the given {@code SecureRandom}. + * + * @param genParamSpec + * the parameters to use. + * @param random + * the source of randomness. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are not supported. + * @since Android 1.0 */ public final void init(AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException { @@ -176,8 +249,11 @@ public class AlgorithmParameterGenerator { } /** - * @com.intel.drl.spec_ref - * + * Computes and returns {@code AlgorithmParameters} for this generator's + * algorithm. + * + * @return {@code AlgorithmParameters} for this generator's algorithm. + * @since Android 1.0 */ public final AlgorithmParameters generateParameters() { return spiImpl.engineGenerateParameters(); diff --git a/security/src/main/java/java/security/AlgorithmParameterGeneratorSpi.java b/security/src/main/java/java/security/AlgorithmParameterGeneratorSpi.java index 70cb8d2..9ddff23 100644 --- a/security/src/main/java/java/security/AlgorithmParameterGeneratorSpi.java +++ b/security/src/main/java/java/security/AlgorithmParameterGeneratorSpi.java @@ -25,34 +25,56 @@ package java.security; import java.security.spec.AlgorithmParameterSpec; /** - * @com.intel.drl.spec_ref + * {@code AlgorithmParameterGeneratorSpi} is the Service Provider Interface + * (SPI) definition for {@code AlgorithmParameterGenerator}. * + * @see AlgorithmParameterGenerator + * @since Android 1.0 */ public abstract class AlgorithmParameterGeneratorSpi { /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code AlgorithmParameterGeneratorSpi} . + * + * @since Android 1.0 */ public AlgorithmParameterGeneratorSpi() { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameterGeneratorSpi} with the given + * size and the given {@code SecureRandom}. The default parameter set + * will be used. + * + * @param size + * the size (in number of bits). + * @param random + * the source of randomness. + * @since Android 1.0 */ protected abstract void engineInit(int size, SecureRandom random); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameterGeneratorSpi} with the given + * {@code AlgorithmParameterSpec} and the given {@code SecureRandom}. + * + * @param genParamSpec + * the parameters to use. + * @param random + * the source of randomness. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are not supported. + * @since Android 1.0 */ protected abstract void engineInit(AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref - * + * Computes and returns {@code AlgorithmParameters} for this generator's + * algorithm. + * + * @return {@code AlgorithmParameters} for this generator's algorithm. + * @since Android 1.0 */ protected abstract AlgorithmParameters engineGenerateParameters(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/AlgorithmParameters.java b/security/src/main/java/java/security/AlgorithmParameters.java index e495439..aaefe1b 100644 --- a/security/src/main/java/java/security/AlgorithmParameters.java +++ b/security/src/main/java/java/security/AlgorithmParameters.java @@ -31,10 +31,11 @@ import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code AlgorithmParameters} is an engine class which provides algorithm + * parameters. * + * @since Android 1.0 */ - public class AlgorithmParameters { /** * The service name. @@ -42,12 +43,12 @@ public class AlgorithmParameters { private static final String SEVICE = "AlgorithmParameters"; //$NON-NLS-1$ /** - * Used to access common engine functionality + * Used to access common engine functionality. */ private static Engine engine = new Engine(SEVICE); /** - * The provider + * The security provider. */ private Provider provider; @@ -57,29 +58,50 @@ public class AlgorithmParameters { private AlgorithmParametersSpi spiImpl; /** - * The algorithm. + * The security algorithm. */ private String algorithm; /** - * The initialization state + * The initialization state. */ private boolean initialized; // = false; /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code AlgorithmParameters} with the given + * arguments. + * + * @param algPramSpi + * the concrete implementation. + * @param provider + * the security provider. + * @param algorithm + * the name of the algorithm. + * @since Android 1.0 */ - protected AlgorithmParameters(AlgorithmParametersSpi keyFacSpi, + protected AlgorithmParameters(AlgorithmParametersSpi algPramSpi, Provider provider, String algorithm) { + // BEGIN android-note + // renamed parameter + // END android-note this.provider = provider; this.algorithm = algorithm; - this.spiImpl = keyFacSpi; + this.spiImpl = algPramSpi; } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code AlgorithmParameters} for the specified + * algorithm. + * + * @param algorithm + * the name of the algorithm to use. + * @return a new instance of {@code AlgorithmParameters} for the specified + * algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static AlgorithmParameters getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -94,8 +116,24 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code AlgorithmParameters} from the specified + * provider for the specified algorithm. + * + * @param algorithm + * the name of the algorithm to use. + * @param provider + * name of the provider of the {@code AlgorithmParameters}. + * @return a new instance of {@code AlgorithmParameters} for the specified + * algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws IllegalArgumentException + * if {@code provider} is {@code null} or of length zero. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static AlgorithmParameters getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, @@ -112,8 +150,22 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code AlgorithmParameters} from the specified + * provider for the specified algorithm. + * + * @param algorithm + * the name of the algorithm to use. + * @param provider + * the provider of the {@code AlgorithmParameters}. + * @return a new instance of {@code AlgorithmParameters} for the specified + * algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @throws IllegalArgumentException + * if {@code provider} is {@code null}. + * @since Android 1.0 */ public static AlgorithmParameters getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -131,24 +183,36 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns the provider associated with this {@code AlgorithmParameters}. + * + * @return the provider associated with this {@code AlgorithmParameters}. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the algorithm. + * + * @return the name of the algorithm. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameters} with the specified {@code + * AlgorithmParameterSpec}. + * + * @param paramSpec + * the parameter specification. + * @throws InvalidParameterSpecException + * if this {@code AlgorithmParameters} has already been + * initialized or the given {@code paramSpec} is not appropriate + * for initializing this {@code AlgorithmParameters}. + * @since Android 1.0 */ public final void init(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { @@ -161,8 +225,16 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameters} with the specified {@code + * byte[]} using the default decoding format for parameters. The default + * encoding format is ASN.1. + * + * @param params + * the encoded parameters. + * @throws IOException + * if this {@code AlgorithmParameters} has already been + * initialized, or the parameter could not be encoded. + * @since Android 1.0 */ public final void init(byte[] params) throws IOException { if (initialized) { @@ -173,8 +245,17 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParameters} with the specified {@code + * byte[]} using the specified decoding format. + * + * @param params + * the encoded parameters. + * @param format + * the name of the decoding format. + * @throws IOException + * if this {@code AlgorithmParameters} has already been + * initialized, or the parameter could not be encoded. + * @since Android 1.0 */ public final void init(byte[] params, String format) throws IOException { if (initialized) { @@ -185,8 +266,19 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns the {@code AlgorithmParameterSpec} for this {@code + * AlgorithmParameters}. + * + * @param paramSpec + * the type of the parameter specification in which this + * parameters should be converted. + * @return the {@code AlgorithmParameterSpec} for this {@code + * AlgorithmParameters}. + * @throws InvalidParameterSpecException + * if this {@code AlgorithmParameters} has already been + * initialized, or if this parameters could not be converted to + * the specified class. + * @since Android 1.0 */ public final <T extends AlgorithmParameterSpec> T getParameterSpec(Class<T> paramSpec) throws InvalidParameterSpecException { @@ -198,8 +290,14 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns this {@code AlgorithmParameters} in their default encoding + * format. The default encoding format is ASN.1. + * + * @return the encoded parameters. + * @throws IOException + * if this {@code AlgorithmParameters} has already been + * initialized, or if this parameters could not be encoded. + * @since Android 1.0 */ public final byte[] getEncoded() throws IOException { if (!initialized) { @@ -209,8 +307,16 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns this {@code AlgorithmParameters} in the specified encoding + * format. + * + * @param format + * the name of the encoding format. + * @return the encoded parameters. + * @throws IOException + * if this {@code AlgorithmParameters} has already been + * initialized, or if this parameters could not be encoded. + * @since Android 1.0 */ public final byte[] getEncoded(String format) throws IOException { if (!initialized) { @@ -220,8 +326,11 @@ public class AlgorithmParameters { } /** - * @com.intel.drl.spec_ref - * + * Returns a string containing a concise, human-readable description of this + * {@code AlgorithmParameters}. + * + * @return a printable representation for this {@code AlgorithmParameters}. + * @since Android 1.0 */ public final String toString() { if (!initialized) { @@ -229,4 +338,4 @@ public class AlgorithmParameters { } return spiImpl.engineToString(); } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/AlgorithmParametersSpi.java b/security/src/main/java/java/security/AlgorithmParametersSpi.java index d405466..3bc8891 100644 --- a/security/src/main/java/java/security/AlgorithmParametersSpi.java +++ b/security/src/main/java/java/security/AlgorithmParametersSpi.java @@ -27,55 +27,109 @@ import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidParameterSpecException; /** - * @com.intel.drl.spec_ref + * {@code AlgorithmParametersSpi} is the Service Provider Interface (SPI) + * definition for {@code AlgorithmParameters}. * + * @see AlgorithmParameters */ - public abstract class AlgorithmParametersSpi { /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParametersSpi} with the specified + * {@code AlgorithmParameterSpec}. + * + * @param paramSpec + * the parameter specification. + * @throws InvalidParameterSpecException + * if this {@code AlgorithmParametersSpi} has already been + * initialized or the given {@code paramSpec} is not appropriate + * for initializing this {@code AlgorithmParametersSpi}. + * @since Android 1.0 */ protected abstract void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParametersSpi} with the specified + * {@code byte[]} using the default decoding format for parameters. The + * default encoding format is ASN.1. + * + * @param params + * the encoded parameters. + * @throws IOException + * if this {@code AlgorithmParametersSpi} has already been + * initialized, or the parameter could not be encoded. + * @since Android 1.0 */ protected abstract void engineInit(byte[] params) throws IOException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code AlgorithmParametersSpi} with the specified + * {@code byte[]} using the specified decoding format. + * + * @param params + * the encoded parameters. + * @param format + * the name of the decoding format. + * @throws IOException + * if this {@code AlgorithmParametersSpi} has already been + * initialized, or the parameter could not be encoded. + * @since Android 1.0 */ protected abstract void engineInit(byte[] params, String format) throws IOException; /** - * @com.intel.drl.spec_ref - * + * Returns the {@code AlgorithmParameterSpec} for this {@code + * AlgorithmParametersSpi}. + * + * @param paramSpec + * the type of the parameter specification in which this + * parameters should be converted. + * @return the {@code AlgorithmParameterSpec} for this {@code + * AlgorithmParametersSpi}. + * @throws InvalidParameterSpecException + * if this {@code AlgorithmParametersSpi} has already been + * initialized, or if this parameters could not be converted to + * the specified class. + * @since Android 1.0 */ protected abstract <T extends AlgorithmParameterSpec> T engineGetParameterSpec( Class<T> paramSpec) throws InvalidParameterSpecException; /** - * @com.intel.drl.spec_ref - * + * Returns the parameters in their default encoding format. The default + * encoding format is ASN.1. + * + * @return the encoded parameters. + * @throws IOException + * if this {@code AlgorithmParametersSpi} has already been + * initialized, or if this parameters could not be encoded. + * @since Android 1.0 */ protected abstract byte[] engineGetEncoded() throws IOException; /** - * @com.intel.drl.spec_ref - * + * Returns the parameters in the specified encoding format. + * + * @param format + * the name of the encoding format. + * @return the encoded parameters. + * @throws IOException + * if this {@code AlgorithmParametersSpi} has already been + * initialized, or if this parameters could not be encoded. + * @since Android 1.0 */ protected abstract byte[] engineGetEncoded(String format) throws IOException; /** - * @com.intel.drl.spec_ref - * + * Returns a string containing a concise, human-readable description of this + * {@code AlgorithmParametersSpi}. + * + * @return a printable representation for this {@code + * AlgorithmParametersSpi}. + * @since Android 1.0 */ protected abstract String engineToString(); diff --git a/security/src/main/java/java/security/AllPermission.java b/security/src/main/java/java/security/AllPermission.java index 36a2087..f4b8aad 100644 --- a/security/src/main/java/java/security/AllPermission.java +++ b/security/src/main/java/java/security/AllPermission.java @@ -19,15 +19,14 @@ package java.security; /** - * Subclass of Permission whose instances imply all other permissions. Granting - * this permission is equivalent to disabling security. + * {@code AllPermission} represents the permission to perform any operation. + * Since its {@link #implies(Permission)} method always returns {@code true}, + * granting this permission is equivalent to disabling security. * + * @since Android 1.0 */ public final class AllPermission extends Permission { - /** - * @serial - */ private static final long serialVersionUID = -2916474571451318075L; // Permission name @@ -37,36 +36,42 @@ public final class AllPermission extends Permission { private static final String ALL_ACTIONS = "<all actions>"; //$NON-NLS-1$ /** - * Constructs a new instance of this class. The two argument version is - * provided for class <code>Policy</code> so that it has a consistent call - * pattern across all Permissions. The name and action list are both + * Constructs a new instance of {@code AllPermission}. The two argument + * version is provided for class {@code Policy} so that it has a consistent + * call pattern across all permissions. The name and action list are both * ignored. * * @param name - * java.lang.String ignored. + * ignored. * @param actions - * java.lang.String ignored. + * ignored. + * @since Android 1.0 */ public AllPermission(String name, String actions) { super(ALL_PERMISSIONS); } /** - * Constructs a new instance of this class. + * Constructs a new instance of {@code AllPermission}. + * + * @since Android 1.0 */ public AllPermission() { super(ALL_PERMISSIONS); } /** - * Compares the argument to the receiver, and returns true if they represent - * the <em>same</em> object using a class specific comparison. All - * AllPermissions are equal to each other. + * Compares the specified object with this {@code AllPermission} for + * equality and returns {@code true} if the specified object is equal, + * {@code false} otherwise. To be equal, the given object needs to be an + * instance of {@code AllPermission}. * * @param obj - * the object to compare with this object - * @return <code>true</code> if the object is the same as this object - * <code>false</code> if it is different from this object + * object to be compared for equality with this {@code + * AllPermission}. + * @return {@code true} if the specified object is equal to this {@code + * AllPermission}, otherwise {@code false}. + * @since Android 1.0 * @see #hashCode */ public boolean equals(Object obj) { @@ -74,48 +79,50 @@ public final class AllPermission extends Permission { } /** - * Returns an integer hash code for the receiver. Any two objects which - * answer <code>true</code> when passed to <code>equals</code> must - * answer the same value for this method. + * Returns the hash code value for this {@code AllPermission}. Returns the + * same hash code for {@code AllPermission}s that are equal to each other as + * required by the general contract of {@link Object#hashCode}. * - * @return the receiver's hash - * - * @see #equals + * @return the hash code value for this {@code AllPermission}. + * @see Object#equals(Object) + * @see AllPermission#equals(Object) + * @since Android 1.0 */ public int hashCode() { return 1; } /** - * Returns the actions associated with the receiver. Since AllPermission - * objects allow all actions, answer with the string "<all actions>". + * Returns the actions associated with this {@code AllPermission}. Since + * {@code AllPermission} objects allow all actions, this method returns + * always the string "<all actions>". * - * @return String the actions associated with the receiver. + * @return the actions associated with this {@code AllPermission}. + * @since Android 1.0 */ public String getActions() { return ALL_ACTIONS; } /** - * Indicates whether the argument permission is implied by the receiver. - * AllPermission objects imply all other permissions. + * Indicates whether the given permission is implied by this permission. + * {@code AllPermission} objects imply all other permissions. * - * @return boolean <code>true</code> if the argument permission is implied - * by the receiver, and <code>false</code> if it is not. + * @return always {@code true}. * @param permission - * java.security.Permission the permission to check + * the permission to check. + * @since Android 1.0 */ public boolean implies(Permission permission) { return true; } /** - * Returns a new PermissionCollection for holding permissions of this class. - * Answer null if any permission collection can be used. - * - * @return a new PermissionCollection or null + * Returns a new {@code PermissionCollection} for holding permissions of + * this class. * - * @see java.security.BasicPermissionCollection + * @return a new {@code PermissionCollection}. + * @since Android 1.0 */ public PermissionCollection newPermissionCollection() { return new AllPermissionCollection(); diff --git a/security/src/main/java/java/security/AllPermissionCollection.java b/security/src/main/java/java/security/AllPermissionCollection.java index 08b0b1e..000365d 100644 --- a/security/src/main/java/java/security/AllPermissionCollection.java +++ b/security/src/main/java/java/security/AllPermissionCollection.java @@ -27,10 +27,12 @@ import java.util.NoSuchElementException; import org.apache.harmony.security.internal.nls.Messages; /** - * Specific PermissionCollection for storing AllPermissions. All instances of - * AllPermission are equivalent, so it is enough to store a single added - * instance. + * Specific {@code PermissionCollection} for storing {@code AllPermission}s. All + * instances of {@code AllPermission} are equivalent, so it is enough to store a + * single added instance. * + * @see AllPermission + * @since Android 1.0 */ final class AllPermissionCollection extends PermissionCollection { @@ -46,7 +48,7 @@ final class AllPermissionCollection extends PermissionCollection { private transient Permission all; /** - * Adds an AllPermission to the collection. + * Adds an {@code AllPermission} to the collection. */ public void add(Permission permission) { if (isReadOnly()) { @@ -60,7 +62,7 @@ final class AllPermissionCollection extends PermissionCollection { } /** - * Returns enumeration of the collection. + * Returns the enumeration of the collection. */ public Enumeration<Permission> elements() { return new SingletonEnumeration<Permission>(all); @@ -103,23 +105,21 @@ final class AllPermissionCollection extends PermissionCollection { /** * Indicates whether the argument permission is implied by the receiver. - * AllPermission objects imply all other permissions. + * {@code AllPermission} objects imply all other permissions. * - * @return boolean <code>true</code> if the argument permission is implied - * by the receiver, and <code>false</code> if it is not. + * @return boolean {@code true} if the argument permission is implied by the + * receiver, and {@code false} if it is not. * @param permission - * java.security.Permission the permission to check + * the permission to check. */ public boolean implies(Permission permission) { return all != null; } /** - * Writes accordingly to expected format: - * <dl> - * <dt>boolean all_allowed - * <dd>This is set to true if this collection is not empty - * </dl> + * Writes the fields according to expected format, adding the boolean field + * {@code all_allowed} which is {@code true} if this collection is not + * empty. */ private void writeObject(java.io.ObjectOutputStream out) throws IOException { ObjectOutputStream.PutField fields = out.putFields(); diff --git a/security/src/main/java/java/security/AuthProvider.java b/security/src/main/java/java/security/AuthProvider.java index ae8b159..5a3be77 100644 --- a/security/src/main/java/java/security/AuthProvider.java +++ b/security/src/main/java/java/security/AuthProvider.java @@ -27,40 +27,94 @@ import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.LoginException; /** - * @com.intel.drl.spec_ref + * {@code AuthProvider} is an abstract superclass for Java Security {@code + * Provider} which provide login and logout. * + * @since Android 1.0 */ - public abstract class AuthProvider extends Provider { - /** - * @serial - */ private static final long serialVersionUID = 4197859053084546461L; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code AuthProvider} with its name, version + * and description. * + * @param name + * the name of the provider. + * @param version + * the version of the provider. + * @param info + * a description of the provider. + * @since Android 1.0 */ protected AuthProvider(String name, double version, String info) { super(name, version, info); } /** - * @com.intel.drl.spec_ref + * Performs a login into this {@code AuthProvider}. The specified {@code + * CallbackHandler} is used to obtain information from the caller. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code authProvider.NAME} (where NAME is + * the provider name) to be granted, otherwise a {@code SecurityException} + * will be thrown. * + * @param subject + * the subject that is used to login. + * @param handler + * the handler to obtain authentication information from the + * caller. + * @throws LoginException + * if the login fails. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public abstract void login(Subject subject, CallbackHandler handler) throws LoginException; /** - * @com.intel.drl.spec_ref + * Performs a logout from this {@code AuthProvider}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code authProvider.NAME} (where NAME is + * the provider name) to be granted, otherwise a {@code SecurityException} + * will be thrown. + * </p> * + * @throws LoginException + * if the logout fails. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public abstract void logout() throws LoginException; /** - * @com.intel.drl.spec_ref + * Sets the {@code CallbackHandler} to this {@code AuthProvider}. If no + * handler is passed to the {@link #login(Subject, CallbackHandler)} method, + * this {@code AuthProvider} is using the specified {@code CallbackHandler}. + * <p> + * If no handler is set, this {@code AuthProvider} uses the {@code + * CallbackHandler} specified by the {@code + * auth.login.defaultCallbackHandler} security property. + * </p><p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code authProvider.NAME} (where NAME is + * the provider name) to be granted, otherwise a {@code SecurityException} + * will be thrown. + * </p> * + * @param handler + * the handler to obtain authentication information from the + * caller. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public abstract void setCallbackHandler(CallbackHandler handler); -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/BasicPermission.java b/security/src/main/java/java/security/BasicPermission.java index 9cda9a2..1d566ec 100644 --- a/security/src/main/java/java/security/BasicPermission.java +++ b/security/src/main/java/java/security/BasicPermission.java @@ -28,20 +28,39 @@ import java.io.Serializable; import org.apache.harmony.security.internal.nls.Messages; /** - * Superclass of permissions which have names but no action lists. + * {@code BasicPermission} is the common base class of all permissions which + * have a name but no action lists. A {@code BasicPermission} is granted or it + * is not. + * <p> + * Names of a BasicPermission follow the dot separated, hierarchical property + * naming convention. Asterisk '*' can be used as wildcards. Either by itself, + * matching anything, or at the end of the name, immediately preceded by a '.'. + * For example: * + * <pre> + * com.google.android.* grants all permissions under the com.google.android permission hierarchy + * * grants all permissions + * </pre> + * </p><p> + * While this class ignores the action list in the + * {@link #BasicPermission(String, String)} constructor, subclasses may + * implement actions on top of this class. + * </p> */ - public abstract class BasicPermission extends Permission implements Serializable { private static final long serialVersionUID = 6279438298436773498L; /** - * Creates an instance of this class with the given name and action list. + * Constructs a new instance of {@code BasicPermission} with the specified + * name. * * @param name - * String the name of the new permission. + * the name of the permission. + * @throws NullPointerException if {@code name} is {@code null}. + * @throws IllegalArgumentException if {@code name.length() == 0}. + * @since Android 1.0 */ public BasicPermission(String name) { super(name); @@ -49,13 +68,18 @@ public abstract class BasicPermission extends Permission implements } /** - * Creates an instance of this class with the given name and action list. - * The action list is ignored. + * Constructs a new instance of {@code BasicPermission} with the specified + * name. The {@code action} parameter is ignored. * * @param name - * String the name of the new permission. + * the name of the permission. * @param action - * String ignored. + * is ignored. + * @throws NullPointerException + * if {@code name} is {@code null}. + * @throws IllegalArgumentException + * if {@code name.length() == 0}. + * @since Android 1.0 */ public BasicPermission(String name, String action) { super(name); @@ -75,15 +99,20 @@ public abstract class BasicPermission extends Permission implements } /** - * Compares the argument to the receiver, and returns true if they represent - * the <em>same</em> object using a class specific comparison. In this - * case, the receiver and the object must have the same class and name. + * Compares the specified object with this {@code BasicPermission} for + * equality. Returns {@code true} if the specified object has the same class + * and the two {@code Permissions}s have the same name. + * <p> + * The {@link #implies(Permission)} method should be used for making access + * control checks. + * </p> * * @param obj - * the object to compare with this object - * @return <code>true</code> if the object is the same as this object - * <code>false</code> if it is different from this object - * @see #hashCode + * object to be compared for equality with this {@code + * BasicPermission}. + * @return {@code true} if the specified object is equal to this {@code + * BasicPermission}, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object obj) { if (obj == this) { @@ -97,35 +126,38 @@ public abstract class BasicPermission extends Permission implements } /** - * Returns an integer hash code for the receiver. Any two objects which - * answer <code>true</code> when passed to <code>equals</code> must - * answer the same value for this method. + * Returns the hash code value for this {@code BasicPermission}. Returns the + * same hash code for {@code BasicPermission}s that are equal to each other + * as required by the general contract of {@link Object#hashCode}. * - * @return int the receiver's hash - * - * @see #equals + * @return the hash code value for this {@code BasicPermission}. + * @see Object#equals(Object) + * @see BasicPermission#equals(Object) + * @since Android 1.0 */ public int hashCode() { return getName().hashCode(); } /** - * Returns the actions associated with the receiver. BasicPermission objects - * have no actions, so answer the empty string. + * Returns the actions associated with this permission. Since {@code + * BasicPermission} instances have no actions, an empty string is returned. * - * @return String the actions associated with the receiver. + * @return an empty string. + * @since Android 1.0 */ public String getActions() { return ""; //$NON-NLS-1$ } /** - * Indicates whether the argument permission is implied by the receiver. + * Indicates whether the specified permission is implied by this permission. * - * @return boolean <code>true</code> if the argument permission is implied - * by the receiver, and <code>false</code> if it is not. * @param permission - * java.security.Permission the permission to check + * the permission to check against this permission. + * @return {@code true} if the specified permission is implied by this + * permission, {@code false} otherwise. + * @since Android 1.0 */ public boolean implies(Permission permission) { if (permission != null && permission.getClass() == this.getClass()) { @@ -135,9 +167,9 @@ public abstract class BasicPermission extends Permission implements } /** - * Checks if <code>thisName</code> implies <code>thatName</code>, + * Checks if {@code thisName} implies {@code thatName}, * accordingly to hierarchical property naming convention. - * It is assumed that names cannot be null or empty. + * It is assumed that names cannot be {@code null} or empty. */ static boolean nameImplies(String thisName, String thatName) { if (thisName == thatName) { @@ -164,19 +196,19 @@ public abstract class BasicPermission extends Permission implements } /** - * Returns a new PermissionCollection for holding permissions of this class. - * Answer null if any permission collection can be used. + * Returns an empty {@link PermissionCollection} for holding permissions. * <p> - * Note: For BasicPermission (and subclasses which do not override this - * method), the collection which is returned does <em>not</em> invoke the - * .implies method of the permissions which are stored in it when checking - * if the collection implies a permission. Instead, it assumes that if the - * type of the permission is correct, and the name of the permission is - * correct, there is a match. - * - * @return a new PermissionCollection or null + * For {@code PermissionCollection} (and subclasses which do not override + * this method), the collection which is returned does <em>not</em> invoke + * the {@link #implies(Permission)} method of the permissions which are + * stored in it when checking if the collection implies a permission. + * Instead, it assumes that if the type of the permission is correct, and + * the name of the permission is correct, there is a match. + * </p> * - * @see java.security.BasicPermissionCollection + * @return an empty {@link PermissionCollection} for holding permissions. + * @see BasicPermissionCollection + * @since Android 1.0 */ public PermissionCollection newPermissionCollection() { return new BasicPermissionCollection(); diff --git a/security/src/main/java/java/security/BasicPermissionCollection.java b/security/src/main/java/java/security/BasicPermissionCollection.java index 46dad02..c345865 100644 --- a/security/src/main/java/java/security/BasicPermissionCollection.java +++ b/security/src/main/java/java/security/BasicPermissionCollection.java @@ -32,10 +32,13 @@ import java.util.Map; import org.apache.harmony.security.internal.nls.Messages; /** - * Specific PermissionCollection for storing BasicPermissions of arbitrary type. + * Specific {@code PermissionCollection} for storing {@code BasicPermissions} of + * arbitrary type. * + * @see BasicPermission + * @see PermissionCollection + * @since Android 1.0 */ - final class BasicPermissionCollection extends PermissionCollection { private static final long serialVersionUID = 739301742472979399L; @@ -103,10 +106,11 @@ final class BasicPermissionCollection extends PermissionCollection { /** * Indicates whether the argument permission is implied by the receiver. * - * @return boolean <code>true</code> if the argument permission is implied - * by the receiver, and <code>false</code> if it is not. + * @return boolean {@code true} if the argument permission is implied by the + * receiver, and {@code false} if it is not. * @param permission - * java.security.Permission the permission to check + * the permission to check. + * @see Permission */ public boolean implies(Permission permission) { if (permission == null || permission.getClass() != permClass) { @@ -150,15 +154,21 @@ final class BasicPermissionCollection extends PermissionCollection { * <dl> * <dt>boolean all_allowed * <dd>This is set to true if this BasicPermissionCollection contains a - * BasicPermission with '*' as its permission name. + * {@code BasicPermission} with '*' as its permission name. * <dt>Class<T> permClass - * <dd>The class to which all BasicPermissions in this + * <dd>The class to which all {@code BasicPermission}s in this * BasicPermissionCollection belongs. * <dt>Hashtable<K,V> permissions - * <dd>The BasicPermissions in this BasicPermissionCollection. All - * BasicPermissions in the collection must belong to the same class. The - * Hashtable is indexed by the BasicPermission name; the value of the - * Hashtable entry is the permission. + * <dd>The + * + * <pre> + * BasicPermission + * </pre> + * + * s in this {@code BasicPermissionCollection}. All {@code BasicPermission}s + * in the collection must belong to the same class. The Hashtable is indexed + * by the {@code BasicPermission} name; the value of the Hashtable entry is + * the permission. * </dl> */ private void writeObject(java.io.ObjectOutputStream out) throws IOException { diff --git a/security/src/main/java/java/security/Certificate.java b/security/src/main/java/java/security/Certificate.java index 22beac0..bf9a1ae 100644 --- a/security/src/main/java/java/security/Certificate.java +++ b/security/src/main/java/java/security/Certificate.java @@ -20,6 +20,10 @@ * @version $Revision$ */ +// BEGIN android-note +// Added Deprecated annotation. +// END android-note + package java.security; import java.io.IOException; @@ -27,50 +31,99 @@ import java.io.InputStream; import java.io.OutputStream; /** - * @com.intel.drl.spec_ref + * {@code Certificate} represents an identity certificate, such as X.509 or PGP. + * Note: A {@code Certificate} instances does not make any statement about the + * validity of itself. It's in the responsibility of the application to verify + * the validity of its certificates. * - * @deprecated Replaced by behavior in - * {@link javax.security.cert javax.security.cert} + * @deprecated Replaced by behavior in {@link javax.security.cert} + * @see java.security.cert.Certificate + * @since Android 1.0 */ +@Deprecated public interface Certificate { /** - * @com.intel.drl.spec_ref + * Decodes a certificate from the given {@code InputStream}. The format of + * the data to encode must be that identified by {@link #getFormat()} and + * encoded by {@link #encode(OutputStream)}. + * + * @param stream + * the {@code InputStream} to read from. + * @throws KeyException + * if certificate information is incomplete or incorrect. + * @throws IOException + * if an exception is thrown by accessing the provided stream. + * @see #encode(OutputStream) + * @see #getFormat() + * @since Android 1.0 */ public void decode(InputStream stream) throws KeyException, IOException; /** - * @com.intel.drl.spec_ref + * Encodes this certificate to an output stream. The + * {@link #decode(InputStream)} method must be able to decode the format + * written by this method. + * + * @param stream + * the {@code OutputStream} to encode this certificate to. + * @throws KeyException + * if certificate information is incomplete or incorrect. + * @throws IOException + * if an exception is thrown by accessing the provided stream. + * @see #decode(InputStream) + * @since Android 1.0 */ public void encode(OutputStream stream) throws KeyException, IOException; /** - * @com.intel.drl.spec_ref - * + * Returns a string identifying the format of this certificate. + * + * @return a string identifying the format of this certificate. + * @since Android 1.0 */ public String getFormat(); /** - * @com.intel.drl.spec_ref - * + * Returns the guarantor of this certificate. That guarantor guarantees, + * that the public key of this certificate is from the principal returned by + * {@link #getPrincipal()}. + * + * @return the guarantor of this certificate. + * @see #getPrincipal() + * @since Android 1.0 */ public Principal getGuarantor(); /** - * @com.intel.drl.spec_ref - * + * Returns the principal of this certificate. The principal is guaranteed by + * the guarantor returned by {@link #getGuarantor()}. + * + * @return the principal of this certificate. + * @see #getGuarantor() + * @since Android 1.0 */ public Principal getPrincipal(); /** - * @com.intel.drl.spec_ref - * + * Returns the public key of this certificate. The public key is guaranteed + * by the guarantor to belong to the principal. + * + * @return the public key of this certificate. + * @see #getGuarantor() + * @see Certificate#getPrincipal() + * @since Android 1.0 */ public PublicKey getPublicKey(); /** - * @com.intel.drl.spec_ref - * + * Returns a string containing a concise, human-readable description of the + * this {@code Certificate}. + * + * @param detailed + * whether or not this method should return detailed information. + * @return a string representation of this certificate. + * @since Android 1.0 */ public String toString(boolean detailed); -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/CodeSigner.java b/security/src/main/java/java/security/CodeSigner.java index 710e4f8..0719e8f 100644 --- a/security/src/main/java/java/security/CodeSigner.java +++ b/security/src/main/java/java/security/CodeSigner.java @@ -28,31 +28,32 @@ import java.security.cert.CertPath; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code CodeSigner} represents a signer of code. Instances are immutable. + * + * @since Android 1.0 */ - public final class CodeSigner implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 6819288105193937581L; - /** - * @com.intel.drl.spec_ref - */ private CertPath signerCertPath; - /** - * @com.intel.drl.spec_ref - */ private Timestamp timestamp; // Cached hash code value private transient int hash; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code CodeSigner}. + * + * @param signerCertPath + * the certificate path associated with this code signer. + * @param timestamp + * the time stamp associated with this code signer, maybe {@code + * null}. + * @throws NullPointerException + * if {@code signerCertPath} is {@code null}. + * @since Android 1.0 */ public CodeSigner(CertPath signerCertPath, Timestamp timestamp) { if (signerCertPath == null) { @@ -63,7 +64,17 @@ public final class CodeSigner implements Serializable { } /** - * @com.intel.drl.spec_ref + * Compares the specified object with this {@code CodeSigner} for equality. + * Returns {@code true} if the specified object is also an instance of + * {@code CodeSigner}, the two {@code CodeSigner} encapsulate the same + * certificate path and the same time stamp, if present in both. + * + * @param obj + * object to be compared for equality with this {@code + * CodeSigner}. + * @return {@code true} if the specified object is equal to this {@code + * CodeSigner}, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object obj) { if (obj == this) { @@ -81,21 +92,35 @@ public final class CodeSigner implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the certificate path associated with this {@code CodeSigner}. + * + * @return the certificate path associated with this {@code CodeSigner}. + * @since Android 1.0 */ public CertPath getSignerCertPath() { return signerCertPath; } /** - * @com.intel.drl.spec_ref + * Returns the time stamp associated with this {@code CodeSigner}. + * + * @return the time stamp associated with this {@code CodeSigner}, maybe + * {@code null}. + * @since Android 1.0 */ public Timestamp getTimestamp() { return timestamp; } /** - * @com.intel.drl.spec_ref + * Returns the hash code value for this {@code CodeSigner}. Returns the same + * hash code for {@code CodeSigner}s that are equal to each other as + * required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this {@code CodeSigner}. + * @see Object#equals(Object) + * @see CodeSigner#equals(Object) + * @since Android 1.0 */ public int hashCode() { if (hash == 0) { @@ -106,7 +131,12 @@ public final class CodeSigner implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns a string containing a concise, human-readable description of the + * this {@code CodeSigner} including its first certificate and its time + * stamp, if present. + * + * @return a printable representation for this {@code CodeSigner}. + * @since Android 1.0 */ public String toString() { // There is no any special reason for '256' here, it's taken abruptly diff --git a/security/src/main/java/java/security/CodeSource.java b/security/src/main/java/java/security/CodeSource.java index 8c235e6..f4da89c 100644 --- a/security/src/main/java/java/security/CodeSource.java +++ b/security/src/main/java/java/security/CodeSource.java @@ -44,6 +44,15 @@ import javax.security.auth.x500.X500Principal; import org.apache.harmony.security.fortress.PolicyUtils; import org.apache.harmony.security.internal.nls.Messages; +/** + * {@code CodeSource} encapsulates the location from where code is loaded and + * the certificates that were used to verify that code. This information is used + * by {@code SecureClassLoader} to define protection domains for loaded classes. + * + * @see SecureClassLoader + * @see ProtectionDomain + * @since Android 1.0 + */ public class CodeSource implements Serializable { private static final long serialVersionUID = 4977541819976013951L; @@ -65,13 +74,16 @@ public class CodeSource implements Serializable { private transient CertificateFactory factory; /** - * Constructs a new instance of this class with its url and certificates - * fields filled in from the arguments. + * Constructs a new instance of {@code CodeSource} with the specified + * {@code URL} and the {@code Certificate}s. * * @param location - * URL the URL. + * the {@code URL} representing the location from where code is + * loaded, maybe {@code null}. * @param certs - * Certificate[] the Certificates. + * the {@code Certificate} used to verify the code, loaded from + * the specified {@code location}, maybe {@code null}. + * @since Android 1.0 */ public CodeSource(URL location, Certificate[] certs) { this.location = location; @@ -81,6 +93,18 @@ public class CodeSource implements Serializable { } } + /** + * Constructs a new instance of {@code CodeSource} with the specified + * {@code URL} and the {@code CodeSigner}s. + * + * @param location + * the {@code URL} representing the location from where code is + * loaded, maybe {@code null}. + * @param signers + * the {@code CodeSigner}s of the code, loaded from the specified + * {@code location}. Maybe {@code null}. + * @since Android 1.0 + */ public CodeSource(URL location, CodeSigner[] signers) { this.location = location; if (signers != null) { @@ -90,17 +114,18 @@ public class CodeSource implements Serializable { } /** - * Compares the argument to the receiver, and returns true if they represent - * the <em>same</em> object using a class specific comparison. In this - * case, the receiver and the object must have the same URL and the same - * collection of certificates. - * + * Compares the specified object with this {@code CodeSource} for equality. + * Returns {@code true} if the specified object is also an instance of + * {@code CodeSource}, points to the same {@code URL} location and the two + * code sources encapsulate the same {@code Certificate}s. The order of the + * {@code Certificate}s is ignored by this method. * * @param obj - * the object to compare with this object - * @return <code>true</code> if the object is the same as this object - * <code>false</code> if it is different from this object - * @see #hashCode + * object to be compared for equality with this {@code + * CodeSource}. + * @return {@code true} if the specified object is equal to this {@code + * CodeSource}, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object obj) { if (obj == this) { @@ -138,10 +163,17 @@ public class CodeSource implements Serializable { } /** - * Returns the certificates held onto by the receiver. - * + * Returns the certificates of this {@code CodeSource}. If the + * {@link #CodeSource(URL, CodeSigner[])} constructor was used to create + * this instance, the certificates are obtained from the supplied signers. + * <p> + * External modifications of the returned {@code Certificate[]} has no + * impact on this {@code CodeSource}. + * </p> * - * @return Certificate[] the receiver's certificates + * @return the certificates of this {@code CodeSource} or {@code null} if + * there is none. + * @since Android 1.0 */ public final Certificate[] getCertificates() { getCertificatesNoClone(); @@ -176,6 +208,16 @@ public class CodeSource implements Serializable { return certs; } + /** + * Returns the {@code CodeSigner}s of this {@code CodeSource}. If the + * {@link #CodeSource(URL, Certificate[])} constructor was used to create + * this instance, the signers are obtained from the supplied certificates. + * Only X.509 certificates are analyzed. + * + * @return the signers of this {@code CodeSource}, or {@code null} if there + * is none. + * @since Android 1.0 + */ public final CodeSigner[] getCodeSigners() { if (signers != null) { CodeSigner[] tmp = new CodeSigner[signers.length]; @@ -265,24 +307,25 @@ public class CodeSource implements Serializable { } /** - * Returns the receiver's location. - * + * Returns the location of this {@code CodeSource}. * - * @return URL the receiver's URL + * @return the location of this {@code CodeSource}, maybe {@code null}. + * @since Android 1.0 */ public final URL getLocation() { return location; } /** - * Returns an integer hash code for the receiver. Any two objects which - * answer <code>true</code> when passed to <code>.equals</code> must - * answer the same value for this method. + * Returns the hash code value for this {@code CodeSource}. + * Returns the same hash code for {@code CodeSource}s that are + * equal to each other as required by the general contract of + * {@link Object#hashCode}. * - * - * @return int the receiver's hash. - * - * @see #equals + * @return the hash code value for this {@code CodeSource}. + * @see Object#equals(Object) + * @see CodeSource#equals(Object) + * @since Android 1.0 */ public int hashCode() { // @@ -293,13 +336,70 @@ public class CodeSource implements Serializable { } /** - * Indicates whether the argument code source is implied by the receiver. + * Indicates whether the specified code source is implied by this {@code + * CodeSource}. Returns {@code true} if all of the following conditions are + * {@code true}, otherwise {@code false}: + * <p> + * <ul> + * <li>{@code cs} is not {@code null} + * <li>if this {@code CodeSource} has associated certificates, all + * certificates are present in {@code cs}. The certificates are extracted + * from the signers if signers are present. + * <li>if this {@code CodeSource}'s location is not {@code null}, the + * following conditions are checked + * <ul> + * <li>this {@code CodeSource}'s location is not {@code null} + * <li>this {@code CodeSource}'s location protocol is equal to {@code cs}'s + * location protocol + * <li>if this {@code CodeSource}'s location host is not {@code null}, the + * following conditions are checked + * <ul> + * <li>{@code cs}'s host is not {@code null} + * <li>the {@link SocketPermission} of this {@code CodeSource}'s location + * host implies the {@code SocketPermission} of {@code cs}'s location host + * </ul> + * <li>if this {@code CodeSource}'s location port != -1 the port of {@code + * cs}'s location is equal to this {@code CodeSource}'s location port + * <li>this {@code CodeSource}'s location file matches {@code cs}'s file + * whereas special wildcard matching applies as described below + * <li>this {@code CodeSource}'s location reference is equal to to {@code + * cs}'s location reference + * </ul> + * </ul> + * <p> + * Note: If this {@code CodeSource} has a {@code null} location and not any + * certificates, this method returns {@code true}. + * <p> + * Matching rules for the {@code CodeSource}'s location file: + * <ul> + * <li>if this {@code CodeSource}'s location file ends with {@code "/-"}, + * then {@code cs}'s file must start with {@code CodeSource}'s location file + * (exclusive the trailing '-') + * <li>if this {@code CodeSource}'s location file ends with {@code "/*"}, + * then {@code cs}'s file must start with {@code CodeSource}'s location file + * (exclusive the trailing '*') and must not have any further '/' + * <li>if this {@code CodeSource}'s location file ends with {@code "/"}, + * then {@code cs}'s file must start with {@code CodeSource}'s location file + * <li>if this {@code CodeSource}'s location file does not end with {@code + * "/"}, then {@code cs}'s file must start with {@code CodeSource}'s + * location file with the '/' appended to it. + * </ul> + * Examples for locations that imply the location + * "http://code.google.com/android/security.apk": * + * <pre> + * http: + * http://*/android/* + * http://*.google.com/android/* + * http://code.google.com/android/- + * http://code.google.com/android/security.apk + * </pre> * - * @return boolean <code>true</code> if the argument code source is - * implied by the receiver, and <code>false</code> if it is not. * @param cs - * CodeSource the code source to check + * the code source to check. + * @return {@code true} if the argument code source is implied by this + * {@code CodeSource}, otherwise {@code false}. + * @since Android 1.0 */ public boolean implies(CodeSource cs) { // @@ -449,10 +549,11 @@ public class CodeSource implements Serializable { /** * Returns a string containing a concise, human-readable description of the - * receiver. - * + * this {@code CodeSource} including its location, its certificates and its + * signers. * - * @return a printable representation for the receiver. + * @return a printable representation for this {@code CodeSource}. + * @since Android 1.0 */ public String toString() { StringBuilder buf = new StringBuilder(); diff --git a/security/src/main/java/java/security/DigestException.java b/security/src/main/java/java/security/DigestException.java index b63edda..d579885 100644 --- a/security/src/main/java/java/security/DigestException.java +++ b/security/src/main/java/java/security/DigestException.java @@ -23,44 +23,55 @@ package java.security; /** - * This class represents exceptions for message digest computation. - * + *{@code DigestException} is a general message digest exception. + * + *@since Android 1.0 */ public class DigestException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 5821450303093652515L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code DigestException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public DigestException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code DigestException}. * + * @since Android 1.0 */ public DigestException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code DigestException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public DigestException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code DigestException} with the + * cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public DigestException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/DigestInputStream.java b/security/src/main/java/java/security/DigestInputStream.java index 84ce3ad..0db7613 100644 --- a/security/src/main/java/java/security/DigestInputStream.java +++ b/security/src/main/java/java/security/DigestInputStream.java @@ -27,13 +27,17 @@ import java.io.IOException; import java.io.InputStream; /** - * @com.intel.drl.spec_ref + * {@code DigestInputStream} is a {@code FilterInputStream} which maintains an + * associated message digest. * + * @since Android 1.0 */ public class DigestInputStream extends FilterInputStream { /** - * @com.intel.drl.spec_ref + * The message digest for this stream. + * + * @since Android 1.0 */ protected MessageDigest digest; @@ -41,7 +45,14 @@ public class DigestInputStream extends FilterInputStream { private boolean isOn = true; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of this {@code DigestInputStream}, using the + * given {@code stream} and the {@code digest}. + * + * @param stream + * the input stream. + * @param digest + * the message digest. + * @since Android 1.0 */ public DigestInputStream(InputStream stream, MessageDigest digest) { super(stream); @@ -49,42 +60,37 @@ public class DigestInputStream extends FilterInputStream { } /** - * Returns the MessageDigest which the receiver uses when computing the - * hash. - * - * - * @return MessageDigest the digest the receiver uses when computing the - * hash. + * Returns the message digest for this stream. * + * @return the message digest for this stream. + * @since Android 1.0 */ public MessageDigest getMessageDigest() { return digest; } /** - * Sets the MessageDigest which the receiver will use when computing the - * hash. - * + * Sets the message digest which this stream will use. * * @param digest - * MessageDigest the digest to use when computing the hash. - * - * @see MessageDigest - * @see #on + * the message digest which this stream will use. + * @since Android 1.0 */ public void setMessageDigest(MessageDigest digest) { this.digest = digest; } /** - * Reads the next byte and returns it as an int. Updates the digest for the - * byte if this function is enabled. + * Reads the next byte and returns it as an {@code int}. Updates the digest + * for the byte if this function is {@link #on(boolean)}. + * <p> + * This operation is blocking. + * </p> * - * - * @return int the byte which was read or -1 at end of stream. - * - * @exception java.io.IOException - * If reading the source stream causes an IOException. + * @return the byte which was read or -1 at end of stream. + * @throws IOException + * if reading the source stream causes an {@code IOException}. + * @since Android 1.0 */ public int read() throws IOException { // read the next byte @@ -100,7 +106,25 @@ public class DigestInputStream extends FilterInputStream { } /** - * @com.intel.drl.spec_ref + * Reads {@code len} bytes into the specified {@code byte[]}, starting from + * the specified offset. Updates the digest if this function is + * {@link #on(boolean)}. + * <p> + * This operation is blocking. + * </p> + * + * @param b + * the byte array in which to store the bytes + * @param off + * the initial position in {@code b} to store the bytes read from + * this stream + * @param len + * the maximum number of bytes to store in {@code b} + * @return the number of bytes actually read or -1 if the end of the + * filtered stream has been reached while reading + * @throws IOException + * if reading the source stream causes an {@code IOException} + * @since Android 1.0 */ public int read(byte[] b, int off, int len) throws IOException { // read next up to len bytes @@ -118,23 +142,21 @@ public class DigestInputStream extends FilterInputStream { /** * Enables or disables the digest function (default is on). * - * * @param on - * boolean true if the digest should be computed, and false + * {@code true} if the digest should be computed, {@code false} * otherwise. - * - * @see MessageDigest + * @since Android 1.0 */ public void on(boolean on) { isOn = on; } /** - * Returns a string containing a concise, human-readable description of the - * receiver. - * + * Returns a string containing a concise, human-readable description of this + * {@code DigestInputStream} including the digest. * - * @return String a printable representation for the receiver. + * @return a printable representation for this {@code DigestInputStream}. + * @since Android 1.0 */ public String toString() { return super.toString() + ", " + digest.toString() + //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/DigestOutputStream.java b/security/src/main/java/java/security/DigestOutputStream.java index 9bbc593..858f8dd 100644 --- a/security/src/main/java/java/security/DigestOutputStream.java +++ b/security/src/main/java/java/security/DigestOutputStream.java @@ -27,13 +27,15 @@ import java.io.IOException; import java.io.OutputStream; /** - * @com.intel.drl.spec_ref - * + * {@code DigestOutputStream} is a {@code FilterOutputStream} which maintains an + * associated message digest. */ public class DigestOutputStream extends FilterOutputStream { /** - * @com.intel.drl.spec_ref + * The message digest for this stream. + * + * @since Android 1.0 */ protected MessageDigest digest; @@ -41,7 +43,14 @@ public class DigestOutputStream extends FilterOutputStream { private boolean isOn = true; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of this {@code DigestOutputStream}, using the + * given {@code stream} and the {@code digest}. + * + * @param stream + * the output stream. + * @param digest + * the message digest. + * @since Android 1.0 */ public DigestOutputStream(OutputStream stream, MessageDigest digest) { super(stream); @@ -49,35 +58,35 @@ public class DigestOutputStream extends FilterOutputStream { } /** - * Returns the MessageDigest which the receiver uses when computing the - * hash. + * Returns the message digest for this stream. * - * - * @return MessageDigest the digest the receiver uses when computing the - * hash. + * @return the message digest for this stream. + * @since Android 1.0 */ - public MessageDigest getMessageDigest() { return digest; } /** - * Sets the MessageDigest which the receiver will use when computing the - * hash. - * + * Sets the message digest which this stream will use. * * @param digest - * MessageDigest the digest to use when computing the hash. - * - * @see MessageDigest - * @see #on + * the message digest which this stream will use. + * @since Android 1.0 */ public void setMessageDigest(MessageDigest digest) { this.digest = digest; } /** - * @com.intel.drl.spec_ref + * Writes the specified {@code int} to the stream. Updates the digest if + * this function is {@link #on(boolean)}. + * + * @param b + * the byte to be written. + * @throws IOException + * if writing to the stream causes a {@code IOException} + * @since Android 1.0 */ public void write(int b) throws IOException { // update digest only if digest functionality is on @@ -89,7 +98,18 @@ public class DigestOutputStream extends FilterOutputStream { } /** - * @com.intel.drl.spec_ref + * Writes {@code len} bytes into the stream, starting from the specified + * offset. Updates the digest if this function is {@link #on(boolean)}. + * + * @param b + * the buffer to write to. + * @param off + * the index of the first byte in {@code b} to write. + * @param len + * the number of bytes in {@code b} to write. + * @throws IOException + * if writing to the stream causes an {@code IOException}. + * @since Android 1.0 */ public void write(byte[] b, int off, int len) throws IOException { // update digest only if digest functionality is on @@ -103,23 +123,21 @@ public class DigestOutputStream extends FilterOutputStream { /** * Enables or disables the digest function (default is on). * - * * @param on - * boolean true if the digest should be computed, and false + * {@code true} if the digest should be computed, {@code false} * otherwise. - * - * @see MessageDigest + * @since Android 1.0 */ public void on(boolean on) { isOn = on; } /** - * Returns a string containing a concise, human-readable description of the - * receiver. - * + * Returns a string containing a concise, human-readable description of this + * {@code DigestOutputStream} including the digest. * - * @return String a printable representation for the receiver. + * @return a printable representation for this {@code DigestOutputStream}. + * @since Android 1.0 */ public String toString() { return super.toString() + ", " + digest.toString() + //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/DomainCombiner.java b/security/src/main/java/java/security/DomainCombiner.java index db072b6..501c419 100644 --- a/security/src/main/java/java/security/DomainCombiner.java +++ b/security/src/main/java/java/security/DomainCombiner.java @@ -23,13 +23,31 @@ package java.security; /** - * A DomainCombiner is a way to update the protection domains from an - * AccessControlContext + * {@code DomainCombiner} is used to update and optimize {@code + * ProtectionDomain}s from an {@code AccessControlContext}. * + * @see AccessControlContext + * @see AccessControlContext#AccessControlContext(AccessControlContext, + * DomainCombiner) + * @since Android 1.0 */ public interface DomainCombiner { + /** - * @com.intel.drl.spec_ref + * Returns a combination of the two provided {@code ProtectionDomain} + * arrays. Implementers can simply merge the two arrays into one, remove + * duplicates and perform other optimizations. + * + * @param current + * the protection domains of the current execution thread (since + * the most recent call to {@link AccessController#doPrivileged} + * ). + * @param assigned + * the protection domains of the parent thread, maybe {@code + * null}. + * @return a single {@code ProtectionDomain} array computed from the two + * provided arrays. + * @since Android 1.0 */ ProtectionDomain[] combine(ProtectionDomain[] current, ProtectionDomain[] assigned); diff --git a/security/src/main/java/java/security/GeneralSecurityException.java b/security/src/main/java/java/security/GeneralSecurityException.java index fb8d72e..2a1cacb 100644 --- a/security/src/main/java/java/security/GeneralSecurityException.java +++ b/security/src/main/java/java/security/GeneralSecurityException.java @@ -23,44 +23,56 @@ package java.security; /** - * This class represents the general security exception. Subclasses will - * represents specific security problems. + * {@code GeneralSecurityException} is a general security exception and the + * superclass for all security specific exceptions. * + * @since Android 1.0 */ public class GeneralSecurityException extends Exception { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 894798122053539237L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code GeneralSecurityException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public GeneralSecurityException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code GeneralSecurityException}. * + * @since Android 1.0 */ public GeneralSecurityException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code GeneralSecurityException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public GeneralSecurityException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code GeneralSecurityException} with the + * cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public GeneralSecurityException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/Guard.java b/security/src/main/java/java/security/Guard.java index 8042e34..1e4d270 100644 --- a/security/src/main/java/java/security/Guard.java +++ b/security/src/main/java/java/security/Guard.java @@ -23,14 +23,22 @@ package java.security; /** - * This interface is implemented by objects which wish to control access to - * other objects. + * {@code Guard} implementors protect access to other objects. * + * @since Android 1.0 */ public interface Guard { - /** - * @com.intel.drl.spec_ref + /** + * Checks whether access to the specified {@code Object} should be granted. + * This method returns silently if access is granted, otherwise a {@code + * SecurityException} is thrown. + * + * @param object + * the object to be protected by this {@code Guard}. + * @throws SecurityException + * if access is not granted. + * @since Android 1.0 */ public void checkGuard(Object object) throws SecurityException; } diff --git a/security/src/main/java/java/security/GuardedObject.java b/security/src/main/java/java/security/GuardedObject.java index b284026..a64d634 100644 --- a/security/src/main/java/java/security/GuardedObject.java +++ b/security/src/main/java/java/security/GuardedObject.java @@ -26,35 +26,29 @@ import java.io.IOException; import java.io.Serializable; /** - * GuardedObject controls access to an object, by checking all requests for the - * object with a Guard. + * {@code GuardedObject} controls access to an object, by checking all requests + * for the object with a {@code Guard}. * + * @since Android 1.0 */ public class GuardedObject implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -5240450096227834308L; - /** - * @com.intel.drl.spec_ref - */ private final Object object; - /** - * @com.intel.drl.spec_ref - */ private final Guard guard; /** - * Constructs a GuardedObject to protect access to the specified Object - * using the specified Guard. + * Constructs a new instance of {@code GuardedObject} which protects access + * to the specified {@code Object} using the specified {@code Guard}. * * @param object - * the Object to guard + * the {@code Object} to protect. * @param guard - * the Guard + * the {@code Guard} which protects the specified {@code Object}, + * maybe {@code null}. + * @since Android 1.0 */ public GuardedObject(Object object, Guard guard) { this.object = object; @@ -62,15 +56,14 @@ public class GuardedObject implements Serializable { } /** - * Checks whether access should be granted to the object. If access is - * granted, this method returns the object. If it is not granted, then a - * <code>SecurityException</code> is thrown. - * + * Returns the guarded {@code Object} if the associated {@code Guard} + * permits access. If access is not granted, then a {@code + * SecurityException} is thrown. * - * @return the guarded object - * - * @exception java.lang.SecurityException - * If access is not granted to the object + * @return the guarded object. + * @exception SecurityException + * if access is not granted to the guarded object. + * @since Android 1.0 */ public Object getObject() throws SecurityException { if (guard != null) { @@ -79,8 +72,9 @@ public class GuardedObject implements Serializable { return object; } - /** - * Checks guard (if there is one) before performing a default serialization. + /** + * Checks the guard (if there is one) before performing a default + * serialization. */ private void writeObject(java.io.ObjectOutputStream out) throws IOException { if (guard != null) { diff --git a/security/src/main/java/java/security/Identity.java b/security/src/main/java/java/security/Identity.java index 7c3469d..7111029 100644 --- a/security/src/main/java/java/security/Identity.java +++ b/security/src/main/java/java/security/Identity.java @@ -20,6 +20,10 @@ * @version $Revision$ */ +// BEGIN android-note +// Added Deprecated annotation. +// END android-note + package java.security; import java.io.Serializable; @@ -29,9 +33,14 @@ import java.util.Arrays; import org.apache.harmony.security.internal.nls.Messages; /** + * {@code Identity} represents an identity like a person or a company. * - * @deprecated + * @deprecated The functionality of this class has been replace by + * {@link Principal}, {@link KeyStore} and the {@code + * java.security.cert} package. + * @since Android 1.0 */ +@Deprecated public abstract class Identity implements Principal, Serializable { private static final long serialVersionUID = 3609922007826600659L; @@ -45,13 +54,38 @@ public abstract class Identity implements Principal, Serializable { private Vector<Certificate> certificates; + /** + * Constructs a new instance of {@code Identity}. + * + * @since Android 1.0 + */ protected Identity() { } + /** + * Creates a new instance of {@code Identity} with the specified name. + * + * @param name + * the name of this {@code Identity}. + * @since Android 1.0 + */ public Identity(String name) { this.name = name; } + /** + * Creates a new instance of {@code Identity} with the specified name and + * the scope of this {@code Identity}. + * + * @param name + * the name of this {@code Identity}. + * @param scope + * the {@code IdentityScope} of this {@code Identity}. + * @throws KeyManagementException + * if an {@code Identity} with the same name is already present + * in the specified scope. + * @since Android 1.0 + */ public Identity(String name, IdentityScope scope) throws KeyManagementException { this(name); @@ -61,6 +95,23 @@ public abstract class Identity implements Principal, Serializable { } } + /** + * Adds a {@code Certificate} to this {@code Identity}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code addIdentityCertificate} to be + * granted, otherwise a {@code SecurityException} will be thrown. + * </p> + * + * @param certificate + * the {@code Certificate} to be added to this {@code Identity}. + * @throws KeyManagementException + * if the certificate is not valid. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public void addCertificate(Certificate certificate) throws KeyManagementException { SecurityManager sm = System.getSecurityManager(); @@ -105,6 +156,23 @@ public abstract class Identity implements Principal, Serializable { + /** + * Removes the specified {@code Certificate} from this {@code Identity}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code "removeIdentityCertificate"} to be + * granted, otherwise a {@code SecurityException} will be thrown. + * <p> + * + * @param certificate + * the {@code Certificate} to be removed. + * @throws KeyManagementException + * if the certificate is not found. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public void removeCertificate(Certificate certificate) throws KeyManagementException { SecurityManager sm = System.getSecurityManager(); @@ -112,6 +180,11 @@ public abstract class Identity implements Principal, Serializable { sm.checkSecurityAccess("removeIdentityCertificate"); //$NON-NLS-1$ } if (certificates != null) { + // BEGIN android-added + if (!certificates.contains(certificate)) { + throw new KeyManagementException("Certificate not found"); + } + // END android-added certificates.removeElement(certificate); } } @@ -119,6 +192,14 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns the certificates for this {@code Identity}. External + * modifications of the returned array has no impact on this {@code + * Identity}. + * + * @return the {@code Certificates} for this {@code Identity} + * @since Android 1.0 + */ public Certificate[] certificates() { if (certificates == null) { return new Certificate[0]; @@ -131,6 +212,21 @@ public abstract class Identity implements Principal, Serializable { + /** + * Compares the specified {@code Identity} with this {@code Identity} for + * equality and returns {@code true} if the specified object is equal, + * {@code false} otherwise. + * <p> + * To be equal, two {@code Identity} objects need to have the same name and + * the same public keys. + * </p> + * + * @param identity + * the identity to check for equality. + * @return {@code true} if the {@code Identity} objects are equal, {@code + * false} otherwise. + * @since Android 1.0 + */ protected boolean identityEquals(Identity identity) { if (!name.equals(identity.name)) { return false; @@ -146,6 +242,15 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns a string containing a concise, human-readable description of the + * this {@code Identity}. + * + * @param detailed + * whether or not this method should return detailed information. + * @return a printable representation for this {@code Permission}. + * @since Android 1.0 + */ public String toString(boolean detailed) { String s = toString(); if (detailed) { @@ -157,6 +262,12 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns the {@code IdentityScope} of this {@code Identity}. + * + * @return the {@code IdentityScope} of this {@code Identity}. + * @since Android 1.0 + */ public final IdentityScope getScope() { return scope; } @@ -164,6 +275,24 @@ public abstract class Identity implements Principal, Serializable { + /** + * Sets the specified {@code PublicKey} to this {@code Identity}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code setIdentityPublicKey} to be + * granted, otherwise a {@code SecurityException} will be thrown. + * </p> + * + * @param key + * the {@code PublicKey} to be set. + * @throws KeyManagementException + * if another {@code Identity} in the same scope as this {@code + * Identity} already has the same {@code PublicKey}. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public void setPublicKey(PublicKey key) throws KeyManagementException { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -184,6 +313,12 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns the {@code PublicKey} associated with this {@code Identity}. + * + * @return the {@code PublicKey} associated with this {@code Identity}. + * @since Android 1.0 + */ public PublicKey getPublicKey() { return publicKey; } @@ -191,6 +326,20 @@ public abstract class Identity implements Principal, Serializable { + /** + * Sets an information string for this {@code Identity}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code setIdentityInfo} to be granted, + * otherwise a {@code SecurityException} will be thrown. + * + * @param info + * the information to be set. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public void setInfo(String info) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -202,6 +351,12 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns the information string of this {@code Identity}. + * + * @return the information string of this {@code Identity}. + * @since Android 1.0 + */ public String getInfo() { return info; } @@ -209,6 +364,19 @@ public abstract class Identity implements Principal, Serializable { + /** + * Compares the specified object with this {@code Identity} for equality and + * returns {@code true} if the specified object is equal, {@code false} + * otherwise. {@code Identity} objects are considered equal, if they have + * the same name and are in the same scope. + * + * @param obj + * object to be compared for equality with this {@code + * Identity}. + * @return {@code true} if the specified object is equal to this {@code + * Identity}, otherwise {@code false}. + * @since Android 1.0 + */ public final boolean equals(Object obj) { if (this == obj) { return true; @@ -227,6 +395,12 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns the name of this {@code Identity}. + * + * @return the name of this {@code Identity}. + * @since Android 1.0 + */ public final String getName() { return name; } @@ -234,6 +408,16 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns the hash code value for this {@code Identity}. Returns the same + * hash code for {@code Identity}s that are equal to each other as required + * by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this {@code Identity}. + * @see Object#equals(Object) + * @see Identity#equals(Object) + * @since Android 1.0 + */ public int hashCode() { int hash = 0; if (name != null) { @@ -248,6 +432,21 @@ public abstract class Identity implements Principal, Serializable { + /** + * Returns a string containing a concise, human-readable description of the + * this {@code Identity} including its name and its scope. + * <p> + * If a {@code SecurityManager} is installed, code calling this method + * needs the {@code SecurityPermission} {@code printIdentity} to be granted, + * otherwise a {@code SecurityException} will be thrown. + * </p> + * + * @return a printable representation for this {@code Identity}. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public String toString() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -259,4 +458,4 @@ public abstract class Identity implements Principal, Serializable { } return s; } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/IdentityScope.java b/security/src/main/java/java/security/IdentityScope.java index daa8925..93729dc 100644 --- a/security/src/main/java/java/security/IdentityScope.java +++ b/security/src/main/java/java/security/IdentityScope.java @@ -20,6 +20,10 @@ * @version $Revision$ */ +// BEGIN android-note +// Added Deprecated annotation. +// END android-note + package java.security; import java.util.Enumeration; @@ -28,35 +32,53 @@ import org.apache.harmony.security.SystemScope; /** - * @com.intel.drl.spec_ref - * @deprecated + * {@code IdentityScope} represents a scope for {@link Identity} objects. + * + * @deprecated The functionality of this class has been replace by + * {@link Principal}, {@link KeyStore} and the {@code + * java.security.cert} package. + * @since Android 1.0 */ +@Deprecated public abstract class IdentityScope extends Identity { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -2337346281189773310L; // systemScope holds reference to the current system scope private static IdentityScope systemScope; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code IdentityScope}. + * + * @since Android 1.0 */ protected IdentityScope() { super(); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code IdentityScope} with the specified + * name. + * + * @param name + * the name of this {@code IdentityScope}. + * @since Android 1.0 */ public IdentityScope(String name) { super(name); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code IdentityScope} with the specified + * name and the specified scope. + * + * @param name + * the name of this {@code IdentityScope}. + * @param scope + * the scope of this {@code IdentityScope}. + * @throws KeyManagementException + * if an identity with the same key already exists. + * @since Android 1.0 */ public IdentityScope(String name, IdentityScope scope) throws KeyManagementException { @@ -64,7 +86,10 @@ public abstract class IdentityScope extends Identity { } /** - * @com.intel.drl.spec_ref + * Returns the system's scope. + * + * @return the system's scope. + * @since Android 1.0 */ public static IdentityScope getSystemScope() { /* @@ -90,7 +115,11 @@ public abstract class IdentityScope extends Identity { } /** - * @com.intel.drl.spec_ref + * Sets the system's scope. + * + * @param scope + * the scope to set. + * @since Android 1.0 */ protected static void setSystemScope(IdentityScope scope) { SecurityManager sm = System.getSecurityManager(); @@ -101,49 +130,98 @@ public abstract class IdentityScope extends Identity { } /** - * @com.intel.drl.spec_ref + * Returns the number of {@code Identity} objects in this scope. + * + * @return the number of {@code Identity} objects in this scope. + * @since Android 1.0 */ public abstract int size(); /** - * @com.intel.drl.spec_ref + * Returns the {@code Identity} with the specified name or {@code null} if + * no {@code Identity} with the specified name is present in this scope. + * + * @param name + * the name of the {@code Identity} to be returned. + * @return the {@code Identity} with the specified name or {@code null} if + * not present. + * @since Android 1.0 */ public abstract Identity getIdentity(String name); /** - * @com.intel.drl.spec_ref + * Returns the {@code Identity} with the name of the specified principal or + * {@code null} if no {@code Identity} with the name of the specified + * principal is present in this scope. + * + * @param principal + * the {@code Principal} whose name is used to lookup the {@code + * Identity} to be returned. + * @return the {@code Identity} with the specified name or {@code null} if + * not present. + * @since Android 1.0 */ public Identity getIdentity(Principal principal) { return getIdentity(principal.getName()); } /** - * @com.intel.drl.spec_ref + * Returns the {@code Identity} which is associated with the specified key + * or {@code null} if no {@code Identity} associated with the specified key + * is present in this scope. + * + * @param key + * the {@code PublicKey} of the {@code Identity} to be returned. + * @return the {@code Identity} associated with the specified key or {@code + * null} if not present. + * @since Android 1.0 */ public abstract Identity getIdentity(PublicKey key); /** - * @com.intel.drl.spec_ref + * Adds an {@code Identity} to this {@code IdentityScope}. + * + * @param identity + * the {@code Identity} to be added. + * @throws KeyManagementException + * if the specified {@code Identity} is invalid or an identity + * with the same key already exists. + * @since Android 1.0 */ public abstract void addIdentity(Identity identity) throws KeyManagementException; /** - * @com.intel.drl.spec_ref + * Removes an {@code Identity} from this {@code IdentityScope}. + * + * @param identity + * the {@code Identity} to be removed. + * @throws KeyManagementException + * if the {@code Identity} is not present in this scope. + * @since Android 1.0 */ public abstract void removeIdentity(Identity identity) throws KeyManagementException; /** - * @com.intel.drl.spec_ref + * Returns an {@code Enumeration} over the {@code Identity} objects in this + * {@code IdentityScope}. + * + * @return an {@code Enumeration} over the {@code Identity} objects in this + * {@code IdentityScope}. + * @since Android 1.0 */ public abstract Enumeration<Identity> identities(); /** - * @com.intel.drl.spec_ref + * Returns a string containing a concise, human-readable description of this + * {@code IdentityScope}. + * + * @return a printable representation for this {@code IdentityScope}. + * @since Android 1.0 */ public String toString() { return new StringBuffer(super.toString()) .append("[").append(size()).append("]").toString(); //$NON-NLS-1$ //$NON-NLS-2$ } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/InvalidAlgorithmParameterException.java b/security/src/main/java/java/security/InvalidAlgorithmParameterException.java index adf494c..0d8a607 100644 --- a/security/src/main/java/java/security/InvalidAlgorithmParameterException.java +++ b/security/src/main/java/java/security/InvalidAlgorithmParameterException.java @@ -23,44 +23,57 @@ package java.security; /** - * This class represents invalid algorithm parameters to cryptographic services. + * {@code InvalidAlgorithmParameterException} indicates the occurrence of + * invalid algorithm parameters. * + * @since Android 1.0 */ public class InvalidAlgorithmParameterException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 2864672297499471472L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code InvalidAlgorithmParameterException} + * with the given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public InvalidAlgorithmParameterException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code InvalidAlgorithmParameterException}. * + * @since Android 1.0 */ public InvalidAlgorithmParameterException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code InvalidAlgorithmParameterException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public InvalidAlgorithmParameterException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code InvalidAlgorithmParameterException} + * with the cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public InvalidAlgorithmParameterException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/InvalidKeyException.java b/security/src/main/java/java/security/InvalidKeyException.java index 45a3b30..95d864e 100644 --- a/security/src/main/java/java/security/InvalidKeyException.java +++ b/security/src/main/java/java/security/InvalidKeyException.java @@ -23,46 +23,55 @@ package java.security; /** - * Used when invalid cryptography keys are used. + * {@code InvalidKeyException} indicates exceptional conditions, caused by an + * invalid key. * - * @see Throwable - * @see Error + * @since Android 1.0 */ public class InvalidKeyException extends KeyException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 5698479920593359816L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code InvalidKeyException} with the given + * message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public InvalidKeyException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code InvalidKeyException}. * + * @since Android 1.0 */ public InvalidKeyException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code InvalidKeyException} with the given + * message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public InvalidKeyException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code InvalidKeyException} with the cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public InvalidKeyException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/InvalidParameterException.java b/security/src/main/java/java/security/InvalidParameterException.java index 4af3b97..ac10448 100644 --- a/security/src/main/java/java/security/InvalidParameterException.java +++ b/security/src/main/java/java/security/InvalidParameterException.java @@ -23,31 +23,31 @@ package java.security; /** - * This exception is thrown when an invalid parameter is passed to a method. + * {@code InvalidParameterException} indicates exceptional conditions, caused by + * invalid parameters. * + * @since Android 1.0 */ public class InvalidParameterException extends IllegalArgumentException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -857968536935667808L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code InvalidParameterException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public InvalidParameterException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code InvalidParameterException}. * + * @since Android 1.0 */ public InvalidParameterException() { } diff --git a/security/src/main/java/java/security/Key.java b/security/src/main/java/java/security/Key.java index 284d1a7..1359ab2 100644 --- a/security/src/main/java/java/security/Key.java +++ b/security/src/main/java/java/security/Key.java @@ -25,36 +25,48 @@ package java.security; import java.io.Serializable; /** - * Defines the basic properties of all key objects. + * {@code Key} is the common interface for all keys. * * @see PublicKey + * @see PrivateKey + * @since Android 1.0 */ public interface Key extends Serializable { + /** - * @com.intel.drl.spec_ref + * The {@code serialVersionUID} to be compatible with JDK1.1. + * + * @since Android 1.0 */ public static final long serialVersionUID = 6603384152749567654L; /** - * Returns the name of the algorithm that this key will work - * with. If the algorithm is unknown, it returns null. + * Returns the name of the algorithm of this key. If the algorithm is + * unknown, {@code null} is returned. * - * @return String the receiver's algorithm + * @return the name of the algorithm of this key or {@code null} if the + * algorithm is unknown. + * @since Android 1.0 */ public String getAlgorithm(); /** - * Returns the name of the format used to encode the key, or null + * Returns the name of the format used to encode this key, or {@code null} * if it can not be encoded. * - * @return String the receiver's encoding format + * @return the name of the format used to encode this key, or {@code null} + * if it can not be encoded. + * @since Android 1.0 */ public String getFormat(); /** - * Returns the encoded form of the receiver. + * Returns the encoded form of this key, or {@code null} if encoding is not + * supported by this key. * - * @return byte[] the encoded form of the receiver + * @return the encoded form of this key, or {@code null} if encoding is not + * supported by this key. + * @since Android 1.0 */ public byte[] getEncoded(); } diff --git a/security/src/main/java/java/security/KeyException.java b/security/src/main/java/java/security/KeyException.java index fc83bc2..b01f75b 100644 --- a/security/src/main/java/java/security/KeyException.java +++ b/security/src/main/java/java/security/KeyException.java @@ -23,48 +23,53 @@ package java.security; /** - * This class is the superclass of all classes which represent problems with - * keys. + * {@code KeyException} is the common superclass of all key related exceptions. * - * - * @see Throwable - * @see Error + * @since Android 1.0 */ public class KeyException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -7483676942812432108L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code KeyException} with the given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public KeyException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code KeyException}. * + * @since Android 1.0 */ public KeyException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyException} with the given message + * and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public KeyException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyException} with the cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public KeyException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/KeyFactory.java b/security/src/main/java/java/security/KeyFactory.java index 27ba6df..7c4966f 100644 --- a/security/src/main/java/java/security/KeyFactory.java +++ b/security/src/main/java/java/security/KeyFactory.java @@ -28,12 +28,14 @@ import java.security.spec.KeySpec; import org.apache.harmony.security.fortress.Engine; import org.apache.harmony.security.internal.nls.Messages; - /** - * @com.intel.drl.spec_ref + * {@code KeyFactory} is an engine class that can be used to translate between + * public and private key objects and convert keys between their external + * representation, that can be easily transported and their internal + * representation. * + * @since Android 1.0 */ - public class KeyFactory { // The service name. private static final String SERVICE = "KeyFactory"; //$NON-NLS-1$ @@ -52,8 +54,16 @@ public class KeyFactory { private String algorithm; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyFactory} with the specified + * arguments. * + * @param keyFacSpi + * the concrete key factory service. + * @param provider + * the provider. + * @param algorithm + * the algorithm to use. + * @since Android 1.0 */ protected KeyFactory(KeyFactorySpi keyFacSpi, Provider provider, @@ -64,8 +74,16 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code KeyFactory} that utilizes the specified + * algorithm. * + * @param algorithm + * the name of the algorithm. + * @return a new instance of {@code KeyFactory} that utilizes the specified + * algorithm. + * @throws NoSuchAlgorithmException + * if no provider provides the requested algorithm. + * @since Android 1.0 */ public static KeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -79,8 +97,22 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code KeyFactory} that utilizes the specified + * algorithm from the specified provider. * + * @param algorithm + * the name of the algorithm. + * @param provider + * the name of the provider. + * @return a new instance of {@code KeyFactory} that utilizes the specified + * algorithm from the specified provider. + * @throws NoSuchAlgorithmException + * if the provider does not provide the requested algorithm. + * @throws NoSuchProviderException + * if the requested provider is not available. + * @throws IllegalArgumentException + * if {@code provider} is {@code null} or empty. + * @since Android 1.0 */ public static KeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -95,8 +127,18 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code KeyFactory} that utilizes the specified + * algorithm from the specified provider. * + * @param algorithm + * the name of the algorithm. + * @param provider + * the security provider. + * @return a new instance of {@code KeyFactory} that utilizes the specified + * algorithm from the specified provider. + * @throws NoSuchAlgorithmException + * if the provider does not provide the requested algorithm. + * @since Android 1.0 */ public static KeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -113,24 +155,37 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Returns the provider associated with this {@code KeyFactory}. * + * @return the provider associated with this {@code KeyFactory}. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref + * Returns the name of the algorithm associated with this {@code KeyFactory} + * . * + * @return the name of the algorithm associated with this {@code KeyFactory} + * . + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref + * Generates a instance of {@code PublicKey} from the given key + * specification. * + * @param keySpec + * the specification of the public key + * @return the public key + * @throws InvalidKeySpecException + * if the specified {@code keySpec} is invalid + * @since Android 1.0 */ public final PublicKey generatePublic(KeySpec keySpec) throws InvalidKeySpecException { @@ -138,8 +193,15 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Generates a instance of {@code PrivateKey} from the given key + * specification. * + * @param keySpec + * the specification of the private key. + * @return the private key. + * @throws InvalidKeySpecException + * if the specified {@code keySpec} is invalid. + * @since Android 1.0 */ public final PrivateKey generatePrivate(KeySpec keySpec) throws InvalidKeySpecException { @@ -147,8 +209,17 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Returns the key specification for the specified key. * + * @param key + * the key from which the specification is requested. + * @param keySpec + * the type of the requested {@code KeySpec}. + * @return the key specification for the specified key. + * @throws InvalidKeySpecException + * if the key can not be processed, or the requested requested + * {@code KeySpec} is inappropriate for the given key. + * @since Android 1.0 */ public final <T extends KeySpec> T getKeySpec(Key key, Class<T> keySpec) @@ -157,8 +228,15 @@ public class KeyFactory { } /** - * @com.intel.drl.spec_ref + * Translates the given key into a key from this key factory. * + * @param key + * the key to translate. + * @return the translated key. + * @throws InvalidKeyException + * if the specified key can not be translated by this key + * factory. + * @since Android 1.0 */ public final Key translateKey(Key key) throws InvalidKeyException { diff --git a/security/src/main/java/java/security/KeyFactorySpi.java b/security/src/main/java/java/security/KeyFactorySpi.java index ee7a861..7d3154e 100644 --- a/security/src/main/java/java/security/KeyFactorySpi.java +++ b/security/src/main/java/java/security/KeyFactorySpi.java @@ -25,39 +25,70 @@ package java.security; import java.security.spec.InvalidKeySpecException; import java.security.spec.KeySpec; - /** - * @com.intel.drl.spec_ref + * {@code KeyFactorySpi} is the Service Provider Interface (SPI) definition for + * {@link KeyFactory}. * + * @see KeyFactory + * @since Android 1.0 */ - public abstract class KeyFactorySpi { /** - * @com.intel.drl.spec_ref + * Generates a instance of {@code PublicKey} from the given key + * specification. * + * @param keySpec + * the specification of the public key. + * @return the public key. + * @throws InvalidKeySpecException + * if the specified {@code keySpec} is invalid. + * @since Android 1.0 */ protected abstract PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException; /** - * @com.intel.drl.spec_ref + * Generates a instance of {@code PrivateKey} from the given key + * specification. * + * @param keySpec + * the specification of the private key. + * @return the private key. + * @throws InvalidKeySpecException + * if the specified {@code keySpec} is invalid. + * @since Android 1.0 */ protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException; /** - * @com.intel.drl.spec_ref + * Returns the key specification for the specified key. * + * @param key + * the key from which the specification is requested. + * @param keySpec + * the type of the requested {@code KeySpec}. + * @return the key specification for the specified key. + * @throws InvalidKeySpecException + * if the key can not be processed, or the requested requested + * {@code KeySpec} is inappropriate for the given key. + * @since Android 1.0 */ protected abstract <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException; //FIXME 1.5 signature: protected abstract <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException /** - * @com.intel.drl.spec_ref + * Translates the given key into a key from this key factory. * + * @param key + * the key to translate. + * @return the translated key. + * @throws InvalidKeyException + * if the specified key can not be translated by this key + * factory. + * @since Android 1.0 */ protected abstract Key engineTranslateKey(Key key) throws InvalidKeyException; diff --git a/security/src/main/java/java/security/KeyManagementException.java b/security/src/main/java/java/security/KeyManagementException.java index ac7e70a..295ec03 100644 --- a/security/src/main/java/java/security/KeyManagementException.java +++ b/security/src/main/java/java/security/KeyManagementException.java @@ -23,38 +23,56 @@ package java.security; /** - * @com.intel.drl.spec_ref + * {@code KeyManagementException} is a general exception, thrown to indicate an + * exception during processing an operation concerning key management. * + * @since Android 1.0 */ public class KeyManagementException extends KeyException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 947674216157062695L; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyManagementException} with the + * given message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public KeyManagementException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyManagementException}. + * + * @since Android 1.0 */ public KeyManagementException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyManagementException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public KeyManagementException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyManagementException} with the + * cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public KeyManagementException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/KeyPair.java b/security/src/main/java/java/security/KeyPair.java index 4936259..6399427 100644 --- a/security/src/main/java/java/security/KeyPair.java +++ b/security/src/main/java/java/security/KeyPair.java @@ -25,19 +25,28 @@ package java.security; import java.io.Serializable; /** - * @com.intel.drl.spec_ref + * {@code KeyPair} is a container for a public key and a private key. Since the + * private key can be accessed, instances must be treated like a private key. * + * @see PrivateKey + * @see PublicKey + * @since Android 1.0 */ public final class KeyPair implements Serializable { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -7565189502268009837L; private final PrivateKey privateKey; private final PublicKey publicKey; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyPair} with a public key and the + * corresponding private key. + * + * @param publicKey + * the public key. + * @param privateKey + * the private key. + * @since Android 1.0 */ public KeyPair(PublicKey publicKey, PrivateKey privateKey) { this.privateKey = privateKey; @@ -45,14 +54,20 @@ public final class KeyPair implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the private key. + * + * @return the private key. + * @since Android 1.0 */ public PrivateKey getPrivate() { return privateKey; } /** - * @com.intel.drl.spec_ref + * Returns the public key. + * + * @return the public key. + * @since Android 1.0 */ public PublicKey getPublic() { return publicKey; diff --git a/security/src/main/java/java/security/KeyPairGenerator.java b/security/src/main/java/java/security/KeyPairGenerator.java index e9fe0c4..5682aa2 100644 --- a/security/src/main/java/java/security/KeyPairGenerator.java +++ b/security/src/main/java/java/security/KeyPairGenerator.java @@ -29,9 +29,12 @@ import org.apache.harmony.security.internal.nls.Messages; /** + * {@code KeyPairGenerator} is an engine class which is capable of generating a + * private key and its related public key utilizing the algorithm it was + * initialized with. * - * @com.intel.drl.spec_ref - * + * @see KeyPairGeneratorSpi + * @since Android 1.0 */ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { @@ -51,25 +54,39 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { private String algorithm; /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code KeyPairGenerator} with the name of + * the algorithm to use. + * + * @param algorithm + * the name of algorithm to use + * @since Android 1.0 */ protected KeyPairGenerator(String algorithm) { this.algorithm = algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the algorithm of this {@code KeyPairGenerator}. + * + * @return the name of the algorithm of this {@code KeyPairGenerator} + * @since Android 1.0 */ public String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code KeyPairGenerator} that utilizes the + * specified algorithm. * - * throws NullPointerException when algorithm is null + * @param algorithm + * the name of the algorithm to use + * @return a new instance of {@code KeyPairGenerator} that utilizes the + * specified algorithm + * @throws NoSuchAlgorithmException if the specified algorithm is not available + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0 */ public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -93,10 +110,20 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code KeyPairGenerator} that utilizes the + * specified algorithm from the specified provider. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException) as in 1.4 release + * @param algorithm + * the name of the algorithm to use + * @param provider + * the name of the provider + * @return a new instance of {@code KeyPairGenerator} that utilizes the + * specified algorithm from the specified provider + * @throws NoSuchAlgorithmException if the specified algorithm is not available + * @throws NoSuchProviderException if the specified provider is not available + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0 */ public static KeyPairGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -112,10 +139,19 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code KeyPairGenerator} that utilizes the + * specified algorithm from the specified provider. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException) as in 1.4 release + * @param algorithm + * the name of the algorithm to use + * @param provider + * the provider + * @return a new instance of {@code KeyPairGenerator} that utilizes the + * specified algorithm from the specified provider + * @throws NoSuchAlgorithmException if the specified algorithm is not available + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0 */ public static KeyPairGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -142,24 +178,38 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns the provider associated with this {@code KeyPairGenerator}. + * + * @return the provider associated with this {@code KeyPairGenerator} + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyPairGenerator} with the given key size. The + * default parameter set and a default {@code SecureRandom} instance will be + * used. + * + * @param keysize + * the size of the key (number of bits) + * @since Android 1.0 */ public void initialize(int keysize) { initialize(keysize, random); } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyPairGenerator} with the given {@code + * AlgorithmParameterSpec}. A default {@code SecureRandom} instance will be + * used. + * + * @param param + * the parameters to use + * @throws InvalidAlgorithmParameterException + * if the specified parameters are not supported + * @since Android 1.0 */ public void initialize(AlgorithmParameterSpec param) throws InvalidAlgorithmParameterException { @@ -167,27 +217,55 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { } /** - * @com.intel.drl.spec_ref - * + * Computes and returns a new unique {@code KeyPair} each time this method + * is called. + * <p> + * This does exactly the same as {@link #generateKeyPair()}. + * + * @return a new unique {@code KeyPair} each time this method is called + * @since Android 1.0 */ public final KeyPair genKeyPair() { return generateKeyPair(); } + /** + * Computes and returns a new unique {@code KeyPair} each time this method + * is called. + * <p> + * This does exactly the same as {@link #genKeyPair()}. + * + * @return a new unique {@code KeyPair} each time this method is called + * @since Android 1.0 + */ public KeyPair generateKeyPair() { return null; } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyPairGenerator} with the given key size and the + * given {@code SecureRandom}. The default parameter set will be used. + * + * @param keysize + * the key size + * @param random + * the source of randomness + * @since Android 1.0 */ public void initialize(int keysize, SecureRandom random) { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyPairGenerator} with the given {@code + * AlgorithmParameterSpec} and the given {@code SecureRandom}. + * + * @param param + * the parameters to use + * @param random + * the source of randomness + * @throws InvalidAlgorithmParameterException + * if the specified parameters are not supported + * @since Android 1.0 */ public void initialize(AlgorithmParameterSpec param, SecureRandom random) throws InvalidAlgorithmParameterException { diff --git a/security/src/main/java/java/security/KeyPairGeneratorSpi.java b/security/src/main/java/java/security/KeyPairGeneratorSpi.java index 8e51367..272c305 100644 --- a/security/src/main/java/java/security/KeyPairGeneratorSpi.java +++ b/security/src/main/java/java/security/KeyPairGeneratorSpi.java @@ -27,33 +27,54 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code KeyPairGeneratorSpi} is the Service Provider Interface (SPI) + * definition for {@link KeyPairGenerator}. * + * @see KeyPairGenerator + * @since Android 1.0 */ - public abstract class KeyPairGeneratorSpi { + /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code KeyPairGeneratorSpi}. + * + * @since Android 1.0 */ public KeyPairGeneratorSpi() { } /** - * @com.intel.drl.spec_ref - * + * Computes and returns a new unique {@code KeyPair} each time this method + * is called. + * + * @return a new unique {@code KeyPair} each time this method is called. + * @since Android 1.0 */ public abstract KeyPair generateKeyPair(); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyPairGeneratorSpi} with the given key size and + * the given {@code SecureRandom}. The default parameter set will be used. + * + * @param keysize + * the key size (number of bits). + * @param random + * the source of randomness. + * @since Android 1.0 */ public abstract void initialize(int keysize, SecureRandom random); /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code KeyPairGeneratorSpi} with the given {@code + * AlgorithmParameterSpec} and the given {@code SecureRandom}. + * + * @param params + * the parameters to use. + * @param random + * the source of randomness. + * @throws InvalidAlgorithmParameterException + * if the specified parameters are not supported. + * @since Android 1.0 */ public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { diff --git a/security/src/main/java/java/security/KeyRep.java b/security/src/main/java/java/security/KeyRep.java index 957fdac..ec1d364 100644 --- a/security/src/main/java/java/security/KeyRep.java +++ b/security/src/main/java/java/security/KeyRep.java @@ -36,13 +36,13 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code KeyRep} is a standardized representation for serialized {@link Key} + * objects. * + * @since Android 1.0 */ public class KeyRep implements Serializable { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -4757683898830641853L; // Key type private final Type type; @@ -54,7 +54,23 @@ public class KeyRep implements Serializable { private byte[] encoded; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyRep} with the specified arguments. + * The arguments should be obtained from the {@code Key} object that has to + * be serialized. + * + * @param type + * the type of the key. + * @param algorithm + * the algorithm (obtained by {@link Key#getAlgorithm()}). + * @param format + * the format of the key (obtained by {@link Key#getFormat()}). + * @param encoded + * the encoded {@code byte[]} (obtained by + * {@link Key#getEncoded()}). + * @throws NullPointerException + * if {@code type, algorithm, format or encoded} is {@code null} + * . + * @since Android 1.0 */ public KeyRep(Type type, String algorithm, String format, byte[] encoded) { @@ -77,7 +93,26 @@ public class KeyRep implements Serializable { } /** - * @com.intel.drl.spec_ref + * Resolves and returns the {@code Key} object. Three {@link Type}|format + * combinations are supported: + * <ul> + * <li> {@code Type.PRIVATE} | "PKCS#8" : returns a {@link PrivateKey} + * instance, generated from a key factory (suitable for the algorithm) that + * is initialized with a {@link PKCS8EncodedKeySpec} using the encoded key + * bytes. + * <li> {@code Type.SECRET} | "RAW" : returns a {@link SecretKeySpec} + * instance, created with the encoded key bytes and the algorithm. + * <li> {@code Type.PUBLIC} | "X.509": returns a {@link PublicKey} instance, + * generated from a key factory (suitable for the algorithm) that is + * initialized with a {@link X509EncodedKeySpec} using the encoded key + * bytes. + * </ul> + * + * @return the resolved {@code Key} object. + * @throws ObjectStreamException + * if the {@code Type}|format combination is not recognized, or + * the resolution of any key parameter fails. + * @since Android 1.0 */ protected Object readResolve() throws ObjectStreamException { switch (type) { @@ -138,11 +173,22 @@ public class KeyRep implements Serializable { } /** - * Supported key types + * {@code Type} enumerates the supported key types. + * @since Android 1.0 */ public static enum Type { + + /** + * Type for secret keys. + */ SECRET, + /** + * Type for public keys. + */ PUBLIC, + /** + * Type for private keys. + */ PRIVATE } } diff --git a/security/src/main/java/java/security/KeyStore.java b/security/src/main/java/java/security/KeyStore.java index 9a6699f..887cbef 100644 --- a/security/src/main/java/java/security/KeyStore.java +++ b/security/src/main/java/java/security/KeyStore.java @@ -42,6 +42,19 @@ import org.apache.harmony.security.fortress.Engine; import org.apache.harmony.security.internal.nls.Messages; +/** + * {@code KeyStore} is responsible for maintaining cryptographic keys and their + * owners. + * <p> + * The type of the system key store can be changed by setting the {@code + * 'keystore.type'} property in the file named {@code + * JAVA_HOME/lib/security/java.security}. + * </p> + * + * @see Certificate + * @see PrivateKey + * @since Android 1.0 + */ public class KeyStore { // Store KeyStore SERVICE name @@ -73,6 +86,17 @@ public class KeyStore { // Store used type private final String type; + /** + * Constructs a new instance of {@code KeyStore} with the given arguments. + * + * @param keyStoreSpi + * the concrete key store. + * @param provider + * the provider. + * @param type + * the type of the {@code KeyStore} to be constructed. + * @since Android 1.0 + */ protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type) { this.type = type; this.provider = provider; @@ -91,9 +115,20 @@ public class KeyStore { throw new KeyStoreException(NOTINITKEYSTORE); } // END android-added - + /** - * @throws NullPointerException if type is null + * Returns a new instance of {@code KeyStore} with the specified type. + * + * @param type + * the type of the returned {@code KeyStore}. + * @return a new instance of {@code KeyStore} with the specified type. + * @throws KeyStoreException + * if an error occurred during the creation of the new {@code + * KeyStore}. + * @throws NullPointerException + * if {@code type} is {@code null}. + * @see #getDefaultType + * @since Android 1.0 */ public static KeyStore getInstance(String type) throws KeyStoreException { if (type == null) { @@ -110,10 +145,24 @@ public class KeyStore { } /** + * Returns a new instance of {@code KeyStore} from the specified provider + * with the given type. * - * - * @throws NullPointerException if type is null (instead of - * NoSuchAlgorithmException) as in 1.4 release + * @param type + * the type of the returned {@code KeyStore}. + * @param provider + * name of the provider of the {@code KeyStore}. + * @return a new instance of {@code KeyStore} from the specified provider + * with the given type. + * @throws KeyStoreException + * if an error occurred during the creation of the new {@code + * KeyStore}. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws IllegalArgumentException + * if {@code provider} is {@code null} or the empty string. + * @see #getDefaultType + * @since Android 1.0 */ public static KeyStore getInstance(String type, String provider) throws KeyStoreException, NoSuchProviderException { @@ -132,10 +181,22 @@ public class KeyStore { } /** + * Returns a new instance of {@code KeyStore} from the specified provider + * with the given type. * - * - * throws NullPointerException if type is null (instead of - * NoSuchAlgorithmException) as in 1.4 release + * @param type + * the type of the returned {@code KeyStore}. + * @param provider + * the provider of the {@code KeyStore}. + * @return a new instance of {@code KeyStore} from the specified provider + * with the given type. + * @throws KeyStoreException + * if an error occurred during the creation of the new {@code + * KeyStore}. + * @throws IllegalArgumentException + * if {@code provider} is {@code null} or the empty string. + * @see #getDefaultType + * @since Android 1.0 */ public static KeyStore getInstance(String type, Provider provider) throws KeyStoreException { @@ -159,8 +220,15 @@ public class KeyStore { } /** + * Returns the default type for {@code KeyStore} instances. + * <p> + * The default is specified in the {@code 'keystore.type'} property in the + * file named {@code JAVA_HOME/lib/security/java.security}. If this property + * is not set, {@code "jks"} will be used. + * </p> * - * + * @return the default type for {@code KeyStore} instances + * @since Android 1.0 */ public static final String getDefaultType() { String dt = AccessController.doPrivileged( @@ -174,24 +242,42 @@ public class KeyStore { } /** + * Returns the provider associated with this {@code KeyStore}. * - * + * @return the provider associated with this {@code KeyStore}. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** + * Returns the type of this {@code KeyStore}. * - * + * @return the type of this {@code KeyStore}. + * @since Android 1.0 */ public final String getType() { return type; } /** + * Returns the key with the given alias, using the password to recover the + * key from the store. * - * + * @param alias + * the alias for the entry. + * @param password + * the password used to recover the key. + * @return the key with the specified alias, or {@code null} if the + * specified alias is not bound to an entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @throws NoSuchAlgorithmException + * if the algorithm for recovering the key is not available. + * @throws UnrecoverableKeyException + * if the key can not be recovered. + * @since Android 1.0 */ public final Key getKey(String alias, char[] password) throws KeyStoreException, NoSuchAlgorithmException, @@ -205,8 +291,15 @@ public class KeyStore { } /** + * Returns the certificate chain for the entry with the given alias. * - * + * @param alias + * the alias for the entry. + * @return the certificate chain for the entry with the given alias, or + * {@code null} if the specified alias is not bound to an entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final Certificate[] getCertificateChain(String alias) throws KeyStoreException { @@ -219,8 +312,15 @@ public class KeyStore { } /** + * Returns the trusted certificate for the entry with the given alias. * - * + * @param alias + * the alias for the entry. + * @return the trusted certificate for the entry with the given alias, or + * {@code null} if the specified alias is not bound to an entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final Certificate getCertificate(String alias) throws KeyStoreException { @@ -233,8 +333,15 @@ public class KeyStore { } /** + * Returns the creation date of the entry with the given alias. * - * + * @param alias + * the alias for the entry. + * @return the creation date, or {@code null} if the specified alias is not + * bound to an entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final Date getCreationDate(String alias) throws KeyStoreException { if (!isInit) { @@ -246,12 +353,25 @@ public class KeyStore { } /** + * Associates the given alias with the key, password and certificate chain. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> * - * - * 1.4.2 and 1.5 releases throw unspecified NullPointerException - - * when alias is null IllegalArgumentException - when password is null - * IllegalArgumentException - when key is instance of PrivateKey and chain - * is null or empty + * @param alias + * the alias for the key. + * @param key + * the key. + * @param password + * the password. + * @param chain + * the certificate chain. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @throws IllegalArgumentException + * if {@code key} is a {@code PrivateKey} and {@code chain} does + * not contain any certificates. + * @since Android 1.0 */ public final void setKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException { @@ -271,8 +391,28 @@ public class KeyStore { } /** + * Associates the given alias with a key and a certificate chain. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> + * <p> + * If this {@code KeyStore} is of type {@code "jks"}, {@code key} must be + * encoded conform to the PKS#8 standard as an + * {@link javax.crypto.EncryptedPrivateKeyInfo}. + * </p> * - * + * @param alias + * the alias for the key. + * @param key + * the key in an encoded format. + * @param chain + * the certificate chain. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @throws IllegalArgumentException + * if {@code key} is a {@code PrivateKey} and {@code chain} + * does. + * @since Android 1.0 */ public final void setKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException { @@ -285,10 +425,20 @@ public class KeyStore { } /** + * Associates the given alias with a certificate. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> * - * - * 1.4.2 and 1.5 releases throw unspecified NullPointerException - * when alias is null + * @param alias + * the alias for the certificate. + * @param cert + * the certificate. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized, or an existing + * alias is not associated to an entry containing a trusted + * certificate, or this method fails for any other reason. + * @since Android 1.0 */ public final void setCertificateEntry(String alias, Certificate cert) throws KeyStoreException { @@ -301,24 +451,34 @@ public class KeyStore { } /** + * Deletes the entry identified with the given alias from this {@code + * KeyStore}. * - * - * 1.4.2 and 1.5 releases throw NullPointerException when alias is null + * @param alias + * the alias for the entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized, or if the entry + * can not be deleted. + * @since Android 1.0 */ public final void deleteEntry(String alias) throws KeyStoreException { + // BEGIN android-changed if (!isInit) { - // BEGIN android-changed throwNotInitialized(); - // END android-changed - } - if (alias == null) { - throw new NullPointerException(Messages.getString("security.3F")); //$NON-NLS-1$ } + // END android-changed implSpi.engineDeleteEntry(alias); } /** + * Returns an {@code Enumeration} over all alias names stored in this + * {@code KeyStore}. * + * @return an {@code Enumeration} over all alias names stored in this + * {@code KeyStore}. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final Enumeration<String> aliases() throws KeyStoreException { if (!isInit) { @@ -330,10 +490,14 @@ public class KeyStore { } /** + * Indicates whether the given alias is present in this {@code KeyStore}. * - * - * 1.4.2 and 1.5 releases throw unspecified NullPointerException when - * alias is null + * @param alias + * the alias of an entry. + * @return {@code true} if the alias exists, {@code false} otherwise. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final boolean containsAlias(String alias) throws KeyStoreException { if (!isInit) { @@ -348,8 +512,12 @@ public class KeyStore { } /** + * Returns the number of entries stored in this {@code KeyStore}. * - * + * @return the number of entries stored in this {@code KeyStore}. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final int size() throws KeyStoreException { if (!isInit) { @@ -361,45 +529,58 @@ public class KeyStore { } /** + * Indicates whether the specified alias is associated with either a + * {@link PrivateKeyEntry} or a {@link SecretKeyEntry}. * - * - * jdk1.4.2 and 1.5 releases throw unspecified NullPointerException - * when alias is null + * @param alias + * the alias of an entry. + * @return {@code true} if the given alias is associated with a key entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final boolean isKeyEntry(String alias) throws KeyStoreException { + // BEGIN android-changed if (!isInit) { - // BEGIN android-changed throwNotInitialized(); - // END android-changed - } - if (alias == null) { - throw new NullPointerException(Messages.getString("security.3F")); //$NON-NLS-1$ } + // END android-changed return implSpi.engineIsKeyEntry(alias); } /** + * Indicates whether the specified alias is associated with a + * {@link TrustedCertificateEntry}. * - * - * jdk1.4.2 and 1.5 releases throw unspecified NullPointerException - * when alias is null + * @param alias + * the alias of an entry. + * @return {@code true} if the given alias is associated with a certificate + * entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final boolean isCertificateEntry(String alias) throws KeyStoreException { + // BEGIN android-changed if (!isInit) { - // BEGIN android-changed throwNotInitialized(); - // END android-changed - } - if (alias == null) { - throw new NullPointerException(Messages.getString("security.3F")); //$NON-NLS-1$ } + // END android-changed return implSpi.engineIsCertificateEntry(alias); } /** + * Returns the alias associated with the first entry whose certificate + * matches the specified certificate. * - * + * @param cert + * the certificate to find the associated entry's alias for. + * @return the alias or {@code null} if no entry with the specified + * certificate can be found. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final String getCertificateAlias(Certificate cert) throws KeyStoreException { @@ -412,9 +593,24 @@ public class KeyStore { } /** + * Writes this {@code KeyStore} to the specified {@code OutputStream}. The + * data written to the {@code OutputStream} is protected by the specified + * password. * - * - * throws IOException when stream or password is null + * @param stream + * the {@code OutputStream} to write the store's data to. + * @param password + * the password to protect the data. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @throws IOException + * if a problem occurred while writing to the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if an exception occurred while storing the certificates of + * this {@code KeyStore}. + * @since Android 1.0 */ public final void store(OutputStream stream, char[] password) throws KeyStoreException, IOException, NoSuchAlgorithmException, @@ -424,18 +620,28 @@ public class KeyStore { throwNotInitialized(); // END android-changed } - if (stream == null) { - throw new IOException(Messages.getString("security.51")); //$NON-NLS-1$ - } - if (password == null) { - throw new IOException(Messages.getString("security.50")); //$NON-NLS-1$ - } implSpi.engineStore(stream, password); } /** + * Stores this {@code KeyStore} using the specified {@code + * LoadStoreParameter}. * - * + * @param param + * the {@code LoadStoreParameter} that specifies how to store + * this {@code KeyStore}, maybe {@code null}. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @throws IOException + * if a problem occurred while writing to the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if an exception occurred while storing the certificates of + * this {@code KeyStore}. + * @throws IllegalArgumentException + * if the given {@link LoadStoreParameter} is not recognized. + * @since Android 1.0 */ public final void store(LoadStoreParameter param) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { @@ -448,8 +654,25 @@ public class KeyStore { } /** + * Initializes this {@code KeyStore} from the provided {@code InputStream}. + * Pass {@code null} as the {@code stream} argument to initialize an empty + * {@code KeyStore} or to initialize a {@code KeyStore} which does not rely + * on an {@code InputStream}. This {@code KeyStore} utilizes the given + * password to verify the stored data. * - * + * @param stream + * the {@code InputStream} to load this {@code KeyStore}'s data + * from or {@code null}. + * @param password + * the password to verify the stored data, maybe {@code null}. + * @throws IOException + * if a problem occurred while reading from the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if an exception occurred while loading the certificates of + * this {@code KeyStore}. + * @since Android 1.0 */ public final void load(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException { @@ -458,8 +681,22 @@ public class KeyStore { } /** + * Loads this {@code KeyStore} using the specified {@code + * LoadStoreParameter}. * - * + * @param param + * the {@code LoadStoreParameter} that specifies how to load this + * {@code KeyStore}, maybe {@code null}. + * @throws IOException + * if a problem occurred while reading from the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if an exception occurred while loading the certificates of + * this {@code KeyStore}. + * @throws IllegalArgumentException + * if the given {@link LoadStoreParameter} is not recognized. + * @since Android 1.0 */ public final void load(LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException { @@ -468,8 +705,23 @@ public class KeyStore { } /** + * Returns the {@code Entry} with the given alias, using the specified + * {@code ProtectionParameter}. * - * + * @param alias + * the alias of the requested entry. + * @param param + * the {@code ProtectionParameter} used to protect the requested + * entry, maybe {@code null}. + * @return he {@code Entry} with the given alias, using the specified + * {@code ProtectionParameter}. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws UnrecoverableEntryException + * if the entry can not be recovered. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final Entry getEntry(String alias, ProtectionParameter param) throws NoSuchAlgorithmException, UnrecoverableEntryException, @@ -486,10 +738,22 @@ public class KeyStore { } /** + * Stores the given {@code Entry} in this {@code KeyStore} and associates + * the entry with the given {@code alias}. The entry is protected by the + * specified {@code ProtectionParameter}. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> * - * - * 1.5 release throws unspecified NullPointerException when alias or - * entry is null + * @param alias + * the alias for the entry. + * @param entry + * the entry to store. + * @param param + * the {@code ProtectionParameter} to protect the entry. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final void setEntry(String alias, Entry entry, ProtectionParameter param) throws KeyStoreException { @@ -508,7 +772,18 @@ public class KeyStore { } /** + * Indicates whether the entry for the given alias is assignable to the + * provided {@code Class}. * + * @param alias + * the alias for the entry. + * @param entryClass + * the type of the entry. + * @return {@code true} if the {@code Entry} for the alias is assignable to + * the specified {@code entryClass}. + * @throws KeyStoreException + * if this {@code KeyStore} is not initialized. + * @since Android 1.0 */ public final boolean entryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass) @@ -529,34 +804,71 @@ public class KeyStore { } /** + * {@code Builder} is used to construct new instances of {@code KeyStore}. * - * - * + * @since Android 1.0 */ public abstract static class Builder { /** + * Constructs a new instance of {@code Builder}. * - * + * @since Android 1.0 */ protected Builder() { } /** + * Returns the {@code KeyStore} created by this {@code Builder}. * - * + * @return the {@code KeyStore} created by this {@code Builder}. + * @throws KeyStoreException + * if an error occurred during construction. + * @since Android 1.0 */ public abstract KeyStore getKeyStore() throws KeyStoreException; /** + * Returns the {@code ProtectionParameter} to be used when a {@code + * Entry} with the specified alias is requested. Before this method is + * invoked, {@link #getKeyStore()} must be called. * - * + * @param alias + * the alias for the entry. + * @return the {@code ProtectionParameter} to be used when a {@code + * Entry} with the specified alias is requested. + * @throws KeyStoreException + * if an error occurred during the lookup for the protection + * parameter. + * @throws IllegalStateException + * if {@link #getKeyStore()} is not called prior the + * invocation of this method. + * @throws NullPointerException + * if {@code alias} is {@code null}. + * @since Android 1.0 */ - public abstract ProtectionParameter getProtectionParameter(String alise) + public abstract ProtectionParameter getProtectionParameter(String alias) throws KeyStoreException; + // BEGIN android-note + // renamed parameter + // END android-note /** + * Returns a new {@code Builder} that holds the given {@code KeyStore} + * and the given {@code ProtectionParameter}. * - * + * @param keyStore + * the {@code KeyStore} to be held. + * @param protectionParameter + * the {@code ProtectionParameter} to be held. + * @return a new instance of {@code Builder} that holds the specified + * {@code KeyStore} and the specified {@code + * ProtectionParameter}. + * @throws NullPointerException + * if {@code keyStore} or {@code protectionParameter} is + * {@code null}. + * @throws IllegalArgumentException + * if the given {@code KeyStore} is not initialized. + * @since Android 1.0 */ public static Builder newInstance(KeyStore keyStore, ProtectionParameter protectionParameter) { @@ -575,8 +887,36 @@ public class KeyStore { } /** + * Returns a new {@code Builder} that creates a new {@code KeyStore} + * based on the provided arguments. + * <p> + * If {@code provider} is {@code null}, all installed providers are + * searched, otherwise the key store from the specified provider is + * used. + * </p> * - * + * @param type + * the type of the {@code KeyStore} to be constructed. + * @param provider + * the provider of the {@code KeyStore} to be constructed, + * maybe {@code null}. + * @param file + * the {@code File} that contains the data for the {@code + * KeyStore}. + * @param protectionParameter + * the {@code ProtectionParameter} used to protect the stored + * keys. + * @return a new {@code Builder} that creates a new {@code KeyStore} + * based on the provided arguments. + * @throws NullPointerException + * if {@code type, protectionParameter} or {@code file} is + * {@code null}. + * @throws IllegalArgumentException + * {@code protectionParameter} not an instance of either + * {@code PasswordProtection} or {@code + * CallbackHandlerProtection}, {@code file} is not a file or + * does not exist at all. + * @since Android 1.0 */ public static Builder newInstance(String type, Provider provider, File file, ProtectionParameter protectionParameter) { @@ -609,8 +949,33 @@ public class KeyStore { } /** + * Returns a new {@code Builder} that creates a new {@code KeyStore} + * based on the provided arguments. + * <p> + * If {@code provider} is {@code null}, all installed providers are + * searched, otherwise the key store from the specified provider is + * used. + * </p> * - * + * @param type + * the type of the {@code KeyStore} to be constructed. + * @param provider + * the provider of the {@code KeyStore} to be constructed, + * maybe {@code null}. + * @param protectionParameter + * the {@code ProtectionParameter} used to protect the stored + * keys. + * @return a new {@code Builder} that creates a new {@code KeyStore} + * based on the provided arguments. + * @throws NullPointerException + * if {@code type} or {@code protectionParameter} is {@code + * null}. + * @throws IllegalArgumentException + * {@code protectionParameter} not an instance of either + * {@code PasswordProtection} or {@code + * CallbackHandlerProtection}, {@code file} is not a file or + * does not exist at all. + * @since Android 1.0 */ public static Builder newInstance(String type, Provider provider, ProtectionParameter protectionParameter) { @@ -806,9 +1171,10 @@ public class KeyStore { } /** + * {@code CallbackHandlerProtection} is a {@code ProtectionParameter} that + * encapsulates a {@link CallbackHandler}. * - * - * + * @since Android 1.0 */ public static class CallbackHandlerProtection implements ProtectionParameter { @@ -816,8 +1182,14 @@ public class KeyStore { private final CallbackHandler callbackHandler; /** + * Constructs a new instance of {@code CallbackHandlerProtection} with + * the {@code CallbackHandler}. * - * + * @param handler + * the {@code CallbackHandler}. + * @throws NullPointerException + * if {@code handler} is {@code null}. + * @since Android 1.0 */ public CallbackHandlerProtection(CallbackHandler handler) { if (handler == null) { @@ -827,8 +1199,10 @@ public class KeyStore { } /** + * Returns the {@code CallbackHandler}. * - * + * @return the {@code CallbackHandler}. + * @since Android 1.0 */ public CallbackHandler getCallbackHandler() { return callbackHandler; @@ -836,30 +1210,39 @@ public class KeyStore { } /** + * {@code Entry} is the common marker interface for a {@code KeyStore} + * entry. * - * - * + * @since Android 1.0 */ public static interface Entry { } /** + * {@code LoadStoreParameter} represents a parameter that specifies how a + * {@code KeyStore} can be loaded and stored. * - * - * + * @see KeyStore#load(LoadStoreParameter) + * @see KeyStore#store(LoadStoreParameter) + * @since Android 1.0 */ public static interface LoadStoreParameter { /** + * Returns the {@code ProtectionParameter} which is used to protect data + * in the {@code KeyStore}. * - * + * @return the {@code ProtectionParameter} which is used to protect data + * in the {@code KeyStore}, maybe {@code null}. + * @since Android 1.0 */ public ProtectionParameter getProtectionParameter(); } /** + * {@code PasswordProtection} is a {@code ProtectionParameter} that protects + * a {@code KeyStore} using a password. * - * - * + * @since Android 1.0 */ public static class PasswordProtection implements ProtectionParameter, Destroyable { @@ -870,16 +1253,27 @@ public class KeyStore { private boolean isDestroyed = false; /** + * Constructs a new instance of {@code PasswordProtection} with a + * password. A copy of the password is stored in the new {@code + * PasswordProtection} object. * - * + * @param password + * the password, maybe {@code null}. + * @since Android 1.0 */ public PasswordProtection(char[] password) { - this.password = password; + // BEGIN android-changed + this.password = (password != null) ? password.clone() : null; + // END android-changed } /** + * Returns the password. * - * + * @return the password. + * @throws IllegalStateException + * if the password has been destroyed. + * @since Android 1.0 */ public synchronized char[] getPassword() { if (isDestroyed) { @@ -889,8 +1283,11 @@ public class KeyStore { } /** + * Destroys / invalidates the password. * - * + * @throws DestroyFailedException + * if the password could not be invalidated. + * @since Android 1.0 */ public synchronized void destroy() throws DestroyFailedException { isDestroyed = true; @@ -901,8 +1298,11 @@ public class KeyStore { } /** + * Indicates whether the password is invalidated. * - * + * @return {@code true} if the password is invalidated, {@code false} + * otherwise. + * @since Android 1.0 */ public synchronized boolean isDestroyed() { return isDestroyed; @@ -910,17 +1310,20 @@ public class KeyStore { } /** + * {@code ProtectionParameter} is a marker interface for protection + * parameters. A protection parameter is used to protect the content of a + * {@code KeyStore}. * - * - * + * @since Android 1.0 */ public static interface ProtectionParameter { } /** + * {@code PrivateKeyEntry} represents a {@code KeyStore} entry that + * holds a private key. * - * - * + * @since Android 1.0 */ public static final class PrivateKeyEntry implements Entry { // Store Certificate chain @@ -930,8 +1333,22 @@ public class KeyStore { private PrivateKey privateKey; /** + * Constructs a new instance of {@code PrivateKeyEntry} with the given + * {@code PrivateKey} and the provided certificate chain. * - * + * @param privateKey + * the private key. + * @param chain + * the ordered certificate chain with the certificate + * corresponding to the private key at index 0. + * @throws NullPointerException + * if {@code privateKey} or {@code chain} is {@code null}. + * @throws IllegalArgumentException + * if {@code chain.length == 0}, the algorithm of the + * private key does not match the algorithm of the public + * key of the first certificate or the certificates are not + * all of the same type. + * @since Android 1.0 */ public PrivateKeyEntry(PrivateKey privateKey, Certificate[] chain) { if (privateKey == null) { @@ -959,38 +1376,51 @@ public class KeyStore { } } // clone chain - this.chain = (Certificate[])chain.clone(); + // BEGIN android-changed this.chain = new Certificate[chain.length]; + // END android-changed System.arraycopy(chain, 0, this.chain, 0, chain.length); this.privateKey = privateKey; } /** + * Returns the private key. * - * + * @return the private key. + * @since Android 1.0 */ public PrivateKey getPrivateKey() { return privateKey; } /** + * Returns the certificate chain. * - * + * @return the certificate chain. + * @since Android 1.0 */ public Certificate[] getCertificateChain() { + // BEGIN android-changed return chain; + // END android-changed } /** + * Returns the certificate corresponding to the private key. * - * + * @return the certificate corresponding to the private key. + * @since Android 1.0 */ public Certificate getCertificate() { return chain[0]; } /** + * Returns a string containing a concise, human-readable description of + * this {@code PrivateKeyEntry}. * - * + * @return a printable representation for this {@code PrivateKeyEntry}. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer( @@ -1006,9 +1436,10 @@ public class KeyStore { } /** + * {@code SecretKeyEntry} represents a {@code KeyStore} entry that + * holds a secret key. * - * - * + * @since Android 1.0 */ public static final class SecretKeyEntry implements Entry { @@ -1016,8 +1447,14 @@ public class KeyStore { private final SecretKey secretKey; /** + * Constructs a new instance of {@code SecretKeyEntry} with the given + * {@code SecretKey}. * - * + * @param secretKey + * the secret key. + * @throws NullPointerException + * if {@code secretKey} is {@code null}. + * @since Android 1.0 */ public SecretKeyEntry(SecretKey secretKey) { if (secretKey == null) { @@ -1027,16 +1464,22 @@ public class KeyStore { } /** + * Returns the secret key. * - * + * @return the secret key. + * @since Android 1.0 */ public SecretKey getSecretKey() { return secretKey; } /** + * Returns a string containing a concise, human-readable description of + * this {@code SecretKeyEntry}. * - * + * @return a printable representation for this {@code + * SecretKeyEntry}. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer("SecretKeyEntry: algorithm - "); //$NON-NLS-1$ @@ -1046,9 +1489,10 @@ public class KeyStore { } /** + * {@code TrustedCertificateEntry} represents a {@code KeyStore} entry that + * holds a trusted certificate. * - * - * + * @since Android 1.0 */ public static final class TrustedCertificateEntry implements Entry { @@ -1056,8 +1500,14 @@ public class KeyStore { private final Certificate trustCertificate; /** + * Constructs a new instance of {@code TrustedCertificateEntry} with the + * given {@code Certificate}. * - * + * @param trustCertificate + * the trusted certificate. + * @throws NullPointerException + * if {@code trustCertificate} is {@code null}. + * @since Android 1.0 */ public TrustedCertificateEntry(Certificate trustCertificate) { if (trustCertificate == null) { @@ -1067,16 +1517,22 @@ public class KeyStore { } /** + * Returns the trusted certificate. * - * + * @return the trusted certificate. + * @since Android 1.0 */ public Certificate getTrustedCertificate() { return trustCertificate; } /** + * Returns a string containing a concise, human-readable description of + * this {@code TrustedCertificateEntry}. * - * + * @return a printable representation for this {@code + * TrustedCertificateEntry}. + * @since Android 1.0 */ public String toString() { return "Trusted certificate entry:\n" + trustCertificate; //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/KeyStoreException.java b/security/src/main/java/java/security/KeyStoreException.java index 0e77e47..7c697f7 100644 --- a/security/src/main/java/java/security/KeyStoreException.java +++ b/security/src/main/java/java/security/KeyStoreException.java @@ -23,40 +23,58 @@ package java.security; /** - * @com.intel.drl.spec_ref + * {@code KeyStoreException} is a general {@code KeyStore} exception. * + * @see KeyStore + * @since Android 1.0 */ public class KeyStoreException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -1119353179322377262L; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyStoreException} with the + * given message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public KeyStoreException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyStoreException}. + * + * @since Android 1.0 */ public KeyStoreException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyStoreException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public KeyStoreException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code KeyStoreException} with the + * cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public KeyStoreException(Throwable cause) { super(cause); } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/KeyStoreSpi.java b/security/src/main/java/java/security/KeyStoreSpi.java index 0ed01dd..b02f264 100644 --- a/security/src/main/java/java/security/KeyStoreSpi.java +++ b/security/src/main/java/java/security/KeyStoreSpi.java @@ -30,52 +30,294 @@ import javax.security.auth.callback.PasswordCallback; import org.apache.harmony.security.internal.nls.Messages; +/** + * {@code KeyStoreSpi} is the Service Provider Interface (SPI) definition for + * {@link KeyStore}. + * + * @see KeyStore + * @since Android 1.0 + */ public abstract class KeyStoreSpi { + /** + * Returns the key with the given alias, using the password to recover the + * key from the store. + * + * @param alias + * the alias for the entry. + * @param password + * the password used to recover the key. + * @return the key with the specified alias, or {@code null} if the + * specified alias is not bound to an entry. + * @throws NoSuchAlgorithmException + * if the algorithm for recovering the key is not available. + * @throws UnrecoverableKeyException + * if the key can not be recovered. + * @since Android 1.0 + */ public abstract Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException; + /** + * Returns the certificate chain for the entry with the given alias. + * + * @param alias + * the alias for the entry + * @return the certificate chain for the entry with the given alias, or + * {@code null} if the specified alias is not bound to an entry. + * @since Android 1.0 + */ public abstract Certificate[] engineGetCertificateChain(String alias); + /** + * Returns the trusted certificate for the entry with the given alias. + * + * @param alias + * the alias for the entry. + * @return the trusted certificate for the entry with the given alias, or + * {@code null} if the specified alias is not bound to an entry. + * @since Android 1.0 + */ public abstract Certificate engineGetCertificate(String alias); + /** + * Returns the creation date of the entry with the given alias. + * + * @param alias + * the alias for the entry. + * @return the creation date, or {@code null} if the specified alias is not + * bound to an entry. + * @since Android 1.0 + */ public abstract Date engineGetCreationDate(String alias); + /** + * Associates the given alias with the key, password and certificate chain. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> + * + * @param alias + * the alias for the key. + * @param key + * the key. + * @param password + * the password. + * @param chain + * the certificate chain. + * @throws KeyStoreException + * if the specified key can not be protected, or if this + * operation fails for another reason. + * @throws IllegalArgumentException + * if {@code key} is a {@code PrivateKey} and {@code chain} does + * not contain any certificates. + * @since Android 1.0 + */ public abstract void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException; + /** + * Associates the given alias with a key and a certificate chain. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> + * + * @param alias + * the alias for the key. + * @param key + * the key in an encoded format. + * @param chain + * the certificate chain. + * @throws KeyStoreException + * if this operation fails. + * @throws IllegalArgumentException + * if {@code key} is a {@code PrivateKey} and {@code chain} + * does. + * @since Android 1.0 + */ public abstract void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException; + /** + * Associates the given alias with a certificate. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> + * + * @param alias + * the alias for the certificate. + * @param cert + * the certificate. + * @throws KeyStoreException + * if an existing alias is not associated to an entry containing + * a trusted certificate, or this method fails for any other + * reason. + * @since Android 1.0 + */ public abstract void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException; + /** + * Deletes the entry identified with the given alias from this {@code + * KeyStoreSpi}. + * + * @param alias + * the alias for the entry. + * @throws KeyStoreException + * if the entry can not be deleted. + * @since Android 1.0 + */ public abstract void engineDeleteEntry(String alias) throws KeyStoreException; + /** + * Returns an {@code Enumeration} over all alias names stored in this + * {@code KeyStoreSpi}. + * + * @return an {@code Enumeration} over all alias names stored in this + * {@code KeyStoreSpi}. + * @since Android 1.0 + */ public abstract Enumeration<String> engineAliases(); + /** + * Indicates whether the given alias is present in this {@code KeyStoreSpi}. + * + * @param alias + * the alias of an entry. + * @return {@code true} if the alias exists, {@code false} otherwise. + * @since Android 1.0 + */ public abstract boolean engineContainsAlias(String alias); + /** + * Returns the number of entries stored in this {@code KeyStoreSpi}. + * + * @return the number of entries stored in this {@code KeyStoreSpi}. + * @since Android 1.0 + */ public abstract int engineSize(); + /** + * Indicates whether the specified alias is associated with either a + * {@link KeyStore.PrivateKeyEntry} or a {@link KeyStore.SecretKeyEntry}. + * + * @param alias + * the alias of an entry. + * @return {@code true} if the given alias is associated with a key entry. + * @since Android 1.0 + */ public abstract boolean engineIsKeyEntry(String alias); + /** + * Indicates whether the specified alias is associated with a + * {@link KeyStore.TrustedCertificateEntry}. + * + * @param alias + * the alias of an entry. + * @return {@code true} if the given alias is associated with a certificate + * entry. + * @since Android 1.0 + */ public abstract boolean engineIsCertificateEntry(String alias); + /** + * Returns the alias associated with the first entry whose certificate + * matches the specified certificate. + * + * @param cert + * the certificate to find the associated entry's alias for. + * @return the alias or {@code null} if no entry with the specified + * certificate can be found. + * @since Android 1.0 + */ public abstract String engineGetCertificateAlias(Certificate cert); + /** + * Writes this {@code KeyStoreSpi} to the specified {@code OutputStream}. + * The data written to the {@code OutputStream} is protected by the + * specified password. + * + * @param stream + * the {@code OutputStream} to write the store's data to. + * @param password + * the password to protect the data. + * @throws IOException + * if a problem occurred while writing to the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if the an exception occurred while storing the certificates + * of this code {@code KeyStoreSpi}. + * @since Android 1.0 + */ public abstract void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException; + /** + * Stores this {@code KeyStoreSpi} using the specified {@code + * LoadStoreParameter}. + * + * @param param + * the {@code LoadStoreParameter} that specifies how to store + * this {@code KeyStoreSpi}, maybe {@code null}. + * @throws IOException + * if a problem occurred while writing to the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if the an exception occurred while storing the certificates + * of this code {@code KeyStoreSpi}. + * @throws IllegalArgumentException + * if the given {@link KeyStore.LoadStoreParameter} is not + * recognized. + * @since Android 1.0 + */ public void engineStore(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException { throw new UnsupportedOperationException(Messages.getString("security.33")); //$NON-NLS-1$ } + /** + * Loads this {@code KeyStoreSpi} from the given {@code InputStream}. + * Utilizes the given password to verify the stored data. + * + * @param stream + * the {@code InputStream} to load this {@code KeyStoreSpi}'s + * data from. + * @param password + * the password to verify the stored data, maybe {@code null}. + * @throws IOException + * if a problem occurred while reading from the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if the an exception occurred while loading the certificates + * of this code {@code KeyStoreSpi}. + * @since Android 1.0 + */ public abstract void engineLoad(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException; + /** + * Loads this {@code KeyStoreSpi} using the specified {@code + * LoadStoreParameter}. + * + * @param param + * the {@code LoadStoreParameter} that specifies how to load this + * {@code KeyStoreSpi}, maybe {@code null}. + * @throws IOException + * if a problem occurred while reading from the stream. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws CertificateException + * if the an exception occurred while loading the certificates + * of this code {@code KeyStoreSpi}. + * @throws IllegalArgumentException + * if the given {@link KeyStore.LoadStoreParameter} is not + * recognized. + * @since Android 1.0 + */ public void engineLoad(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException { if (param == null) { @@ -106,6 +348,25 @@ public abstract class KeyStoreSpi { Messages.getString("security.35")); //$NON-NLS-1$ } + /** + * Returns the {@code Entry} with the given alias, using the specified + * {@code ProtectionParameter}. + * + * @param alias + * the alias of the requested entry. + * @param protParam + * the {@code ProtectionParameter}, used to protect the requested + * entry, maybe {@code null}. + * @return he {@code Entry} with the given alias, using the specified + * {@code ProtectionParameter}. + * @throws NoSuchAlgorithmException + * if the required algorithm is not available. + * @throws UnrecoverableEntryException + * if the entry can not be recovered. + * @throws KeyStoreException + * if this operation fails + * @since Android 1.0 + */ public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException { @@ -150,6 +411,24 @@ public abstract class KeyStoreSpi { throw new NoSuchAlgorithmException(Messages.getString("security.38")); //$NON-NLS-1$ } + /** + * Stores the given {@code Entry} in this {@code KeyStoreSpi} and associates + * the entry with the given {@code alias}. The entry is protected by the + * specified {@code ProtectionParameter}. + * <p> + * If the specified alias already exists, it will be reassigned. + * </p> + * + * @param alias + * the alias for the entry. + * @param entry + * the entry to store. + * @param protParam + * the {@code ProtectionParameter} to protect the entry. + * @throws KeyStoreException + * if this operation fails. + * @since Android 1.0 + */ public void engineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreException { if (entry == null) { @@ -204,6 +483,18 @@ public abstract class KeyStoreSpi { Messages.getString("security.3B", entry.toString())); //$NON-NLS-1$ } + /** + * Indicates whether the entry for the given alias is assignable to the + * provided {@code Class}. + * + * @param alias + * the alias for the entry. + * @param entryClass + * the type of the entry. + * @return {@code true} if the {@code Entry} for the alias is assignable to + * the specified {@code entryClass}. + * @since Android 1.0 + */ public boolean engineEntryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass) { if (!engineContainsAlias(alias)) { diff --git a/security/src/main/java/java/security/MessageDigest.java b/security/src/main/java/java/security/MessageDigest.java index c665c45..97cbdcc 100644 --- a/security/src/main/java/java/security/MessageDigest.java +++ b/security/src/main/java/java/security/MessageDigest.java @@ -27,12 +27,14 @@ import java.nio.ByteBuffer; import org.apache.harmony.security.fortress.Engine; import org.apache.harmony.security.internal.nls.Messages; - /** - * @com.intel.drl.spec_ref + * {@code MessageDigest} is an engine class which is capable of generating one + * way hash values for arbitrary input, utilizing the algorithm it was + * initialized with. * + * @see MessageDigestSpi + * @since Android 1.0 */ - public abstract class MessageDigest extends MessageDigestSpi { // The service name @@ -48,16 +50,30 @@ public abstract class MessageDigest extends MessageDigestSpi { private String algorithm; /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code MessageDigest} with the name of + * the algorithm to use. + * + * @param algorithm + * the name of algorithm to use + * @since Android 1.0 */ protected MessageDigest(String algorithm) { this.algorithm = algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code MessageDigest} that utilizes the + * specified algorithm. + * + * @param algorithm + * the name of the algorithm to use + * @return a new instance of {@code MessageDigest} that utilizes the + * specified algorithm + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0 */ public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -81,8 +97,22 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code MessageDigest} that utilizes the + * specified algorithm from the specified provider. + * + * @param algorithm + * the name of the algorithm to use + * @param provider + * the name of the provider + * @return a new instance of {@code MessageDigest} that utilizes the + * specified algorithm from the specified provider + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available + * @throws NoSuchProviderException + * if the specified provider is not available + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0 */ public static MessageDigest getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -97,20 +127,20 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * Returns a new MessageDigest which is capable of running the algorithm - * described by the argument. The result will be an instance of a subclass - * of MessageDigest which implements that algorithm. - * + * Returns a new instance of {@code MessageDigest} that utilizes the + * specified algorithm from the specified provider. * * @param algorithm - * java.lang.String Name of the algorithm desired + * the name of the algorithm to use * @param provider - * Provider Provider which has to implement the algorithm - * @return MessageDigest a concrete implementation for the algorithm - * desired. - * - * @exception NoSuchAlgorithmException - * If the algorithm cannot be found + * the provider + * @return a new instance of {@code MessageDigest} that utilizes the + * specified algorithm from the specified provider + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available + * @throws NullPointerException + * if {@code algorithm} is {@code null} + * @since Android 1.0 */ public static MessageDigest getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -136,34 +166,41 @@ public abstract class MessageDigest extends MessageDigestSpi { } } - // BEGIN android-note - // Removed @see tag that didn't seem to actually refer to anything. - // END android-note - /** - * Puts the receiver back in an initial state, such that it is ready to - * compute a new hash. + * Puts this {@code MessageDigest} back in an initial state, such that it is + * ready to compute a one way hash value. + * + * @since Android 1.0 */ public void reset() { engineReset(); } /** - * Includes the argument in the hash value computed - * by the receiver. - * - * @param arg0 byte - * the byte to feed to the hash algorithm - * + * Updates this {@code MessageDigest} using the given {@code byte}. + * + * @param arg0 + * the {@code byte} to update this {@code MessageDigest} with * @see #reset() + * @since Android 1.0 */ public void update(byte arg0) { engineUpdate(arg0); } /** - * @com.intel.drl.spec_ref - * + * Updates this {@code MessageDigest} using the given {@code byte[]}. + * + * @param input + * the {@code byte} array + * @param offset + * the index of the first byte in {@code input} to update from + * @param len + * the number of bytes in {@code input} to update from + * @throws IllegalArgumentException + * if {@code offset} or {@code len} are not valid in respect to + * {@code input} + * @since Android 1.0 */ public void update(byte[] input, int offset, int len) { if (input == null || @@ -178,8 +215,13 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates this {@code MessageDigest} using the given {@code byte[]}. + * + * @param input + * the {@code byte} array + * @throws NullPointerException + * if {@code input} is {@code null} + * @since Android 1.0 */ public void update(byte[] input) { if (input == null) { @@ -189,20 +231,35 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * Computes and returns the final hash value that the receiver represents. + * Computes and returns the final hash value for this {@link MessageDigest}. * After the digest is computed the receiver is reset. * - * @return the hash the receiver computed - * + * @return the computed one way hash value * @see #reset + * @since Android 1.0 */ public byte[] digest() { return engineDigest(); } /** - * @com.intel.drl.spec_ref - * + * Computes and stores the final hash value for this {@link MessageDigest}. + * After the digest is computed the receiver is reset. + * + * @param buf + * the buffer to store the result + * @param offset + * the index of the first byte in {@code buf} to store + * @param len + * the number of bytes allocated for the digest + * @return the number of bytes written to {@code buf} + * @throws DigestException + * if an error occures + * @throws IllegalArgumentException + * if {@code offset} or {@code len} are not valid in respect to + * {@code buf} + * @see #reset() + * @since Android 1.0 */ public int digest(byte[] buf, int offset, int len) throws DigestException { if (buf == null || @@ -217,8 +274,15 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * @com.intel.drl.spec_ref - * + * Performs the final update and then computes and returns the final hash + * value for this {@link MessageDigest}. After the digest is computed the + * receiver is reset. + * + * @param input + * the {@code byte} array + * @return the computed one way hash value + * @see #reset() + * @since Android 1.0 */ public byte[] digest(byte[] input) { update(input); @@ -226,25 +290,26 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * Returns a string containing a concise, human-readable description of the - * receiver. + * Returns a string containing a concise, human-readable description of this + * {@code MessageDigest} including the name of its algorithm. * - * @return a printable representation for the receiver. + * @return a printable representation for this {@code MessageDigest} + * @since Android 1.0 */ public String toString() { return "MESSAGE DIGEST " + algorithm; //$NON-NLS-1$ } /** - * Does a simply byte-per-byte compare of the two digests. + * Indicates whether to digest are equal by performing a simply + * byte-per-byte compare of the two digests. * * @param digesta - * One of the digests to compare + * the first digest to be compared * @param digestb - * The digest to compare to - * - * @return <code>true</code> if the two hashes are equal - * <code>false</code> if the two hashes are not equal + * the second digest to be compared + * @return {@code true} if the two hashes are equal, {@code false} otherwise + * @since Android 1.0 */ public static boolean isEqual(byte[] digesta, byte[] digestb) { if (digesta.length != digestb.length) { @@ -259,29 +324,32 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * Returns the standard Java Security name for the algorithm being used by - * the receiver. + * Returns the name of the algorithm of this {@code MessageDigest}. * - * @return String the name of the algorithm + * @return the name of the algorithm of this {@code MessageDigest} + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * Returns the Provider of the digest represented by the receiver. + * Returns the provider associated with this {@code MessageDigest}. * - * @return Provider an instance of a subclass of java.security.Provider + * @return the provider associated with this {@code MessageDigest} + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * Return the engine digest length in bytes. Default is 0. - * - * @return int the engine digest length in bytes + * Returns the engine digest length in bytes. If the implementation does not + * implement this function or is not an instance of {@code Cloneable}, + * {@code 0} is returned. * + * @return the digest length in bytes, or {@code 0} + * @since Android 1.0 */ public final int getDigestLength() { int l = engineGetDigestLength(); @@ -299,10 +367,6 @@ public abstract class MessageDigest extends MessageDigestSpi { } } - /** - * @com.intel.drl.spec_ref - * - */ public Object clone() throws CloneNotSupportedException { if (this instanceof Cloneable) { return super.clone(); @@ -312,8 +376,11 @@ public abstract class MessageDigest extends MessageDigestSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates this {@code MessageDigest} using the given {@code input}. + * + * @param input + * the {@code ByteBuffer} + * @since Android 1.0 */ public final void update(ByteBuffer input) { engineUpdate(input); diff --git a/security/src/main/java/java/security/MessageDigestSpi.java b/security/src/main/java/java/security/MessageDigestSpi.java index 3d44fb1..ae5ed32 100644 --- a/security/src/main/java/java/security/MessageDigestSpi.java +++ b/security/src/main/java/java/security/MessageDigestSpi.java @@ -26,41 +26,60 @@ import java.nio.ByteBuffer; import org.apache.harmony.security.internal.nls.Messages; - /** - * This class is a Service Provider Interface (therefore the Spi suffix) for - * digest algorithms to be supplied by providers. Examples of digest algorithms - * are MD5 and SHA. - * - * A digest is a secure hash function for a stream of bytes, like a fingerprint - * for the stream of bytes. + * {@code MessageDigestSpi} is the Service Provider Interface (SPI) definition + * for {@link MessageDigest}. Examples of digest algorithms are MD5 and SHA. A + * digest is a secure one way hash function for a stream of bytes. It acts like + * a fingerprint for a stream of bytes. * + * @see MessageDigest + * @since Android 1.0 */ public abstract class MessageDigestSpi { /** - * @com.intel.drl.spec_ref + * Returns the engine digest length in bytes. If the implementation does not + * implement this function {@code 0} is returned. * + * @return the digest length in bytes, or {@code 0}. + * @since Android 1.0 */ protected int engineGetDigestLength() { return 0; } /** - * @com.intel.drl.spec_ref + * Updates this {@code MessageDigestSpi} using the given {@code byte}. * + * @param input + * the {@code byte} to update this {@code MessageDigestSpi} with. + * @see #engineReset() + * @since Android 1.0 */ protected abstract void engineUpdate(byte input); - + /** - * @com.intel.drl.spec_ref + * Updates this {@code MessageDigestSpi} using the given {@code byte[]}. * + * @param input + * the {@code byte} array. + * @param offset + * the index of the first byte in {@code input} to update from. + * @param len + * the number of bytes in {@code input} to update from. + * @throws IllegalArgumentException + * if {@code offset} or {@code len} are not valid in respect to + * {@code input}. + * @since Android 1.0 */ protected abstract void engineUpdate(byte[] input, int offset, int len); /** - * @com.intel.drl.spec_ref + * Updates this {@code MessageDigestSpi} using the given {@code input}. * + * @param input + * the {@code ByteBuffer}. + * @since Android 1.0 */ protected void engineUpdate(ByteBuffer input) { if (!input.hasRemaining()) { @@ -82,14 +101,35 @@ public abstract class MessageDigestSpi { } /** - * @com.intel.drl.spec_ref + * Computes and returns the final hash value for this + * {@link MessageDigestSpi}. After the digest is computed the receiver is + * reset. * + * @return the computed one way hash value. + * @see #engineReset() + * @since Android 1.0 */ protected abstract byte[] engineDigest(); /** - * @com.intel.drl.spec_ref + * Computes and stores the final hash value for this + * {@link MessageDigestSpi}. After the digest is computed the receiver is + * reset. * + * @param buf + * the buffer to store the result in. + * @param offset + * the index of the first byte in {@code buf} to store in. + * @param len + * the number of bytes allocated for the digest. + * @return the number of bytes written to {@code buf}. + * @throws DigestException + * if an error occures. + * @throws IllegalArgumentException + * if {@code offset} or {@code len} are not valid in respect to + * {@code buf}. + * @see #engineReset() + * @since Android 1.0 */ protected int engineDigest(byte[] buf, int offset, int len) throws DigestException { @@ -114,15 +154,13 @@ public abstract class MessageDigestSpi { } /** - * @com.intel.drl.spec_ref + * Puts this {@code MessageDigestSpi} back in an initial state, such that it + * is ready to compute a one way hash value. * + * @since Android 1.0 */ protected abstract void engineReset(); - /** - * @com.intel.drl.spec_ref - * - */ public Object clone() throws CloneNotSupportedException { return super.clone(); } diff --git a/security/src/main/java/java/security/NoSuchAlgorithmException.java b/security/src/main/java/java/security/NoSuchAlgorithmException.java index 98650c2..3324076 100644 --- a/security/src/main/java/java/security/NoSuchAlgorithmException.java +++ b/security/src/main/java/java/security/NoSuchAlgorithmException.java @@ -23,46 +23,56 @@ package java.security; /** - * Instances of this class are thrown when an attempt is made to access an - * algorithm which is not provided by the library. + * {@code NoSuchAlgorithmException} indicates that a requested algorithm could + * not be found. * - * @see Throwable + * @since Android 1.0 */ public class NoSuchAlgorithmException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -7443947487218346562L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code NoSuchAlgorithmException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public NoSuchAlgorithmException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code NoSuchAlgorithmException}. * + * @since Android 1.0 */ public NoSuchAlgorithmException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code NoSuchAlgorithmException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public NoSuchAlgorithmException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code NoSuchAlgorithmException} with the + * cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public NoSuchAlgorithmException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/NoSuchProviderException.java b/security/src/main/java/java/security/NoSuchProviderException.java index 5710916..f016ce6 100644 --- a/security/src/main/java/java/security/NoSuchProviderException.java +++ b/security/src/main/java/java/security/NoSuchProviderException.java @@ -23,32 +23,31 @@ package java.security; /** - * Instances of this class are thrown when an attempt is made to access a - * provider by name which is not currently available. + * {@code NoSuchProviderException} indicates that a requested security provider + * could not be found. * - * - * @see Throwable + * @since Android 1.0 */ public class NoSuchProviderException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 8488111756688534474L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Constructs a new instance of {@code NoSuchProviderException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public NoSuchProviderException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code NoSuchProviderException}. * + * @since Android 1.0 */ public NoSuchProviderException() { } diff --git a/security/src/main/java/java/security/Permission.java b/security/src/main/java/java/security/Permission.java index de91fc4..93e769c 100644 --- a/security/src/main/java/java/security/Permission.java +++ b/security/src/main/java/java/security/Permission.java @@ -25,81 +25,116 @@ package java.security; import java.io.Serializable; /** - * Abstract superclass of all classes which represent permission to access - * system resources. + * {@code Permission} is the common base class of all permissions that + * participate in the access control security framework around + * {@link AccessController} and {@link AccessControlContext}. A permission + * constitutes of a name and associated actions. * + * @since Android 1.0 */ public abstract class Permission implements Guard, Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -5636570222231596674L; private final String name; - /** - * @com.intel.drl.spec_ref + /** + * Compares the specified object with this {@code Permission} for equality + * and returns {@code true} if the specified object is equal, {@code false} + * otherwise. + * <p> + * The {@link #implies(Permission)} method should be used for making access + * control checks. + * </p> + * + * @param obj + * object to be compared for equality with this {@code + * Permission}. + * @return {@code true} if the specified object is equal to this {@code + * Permission}, otherwise {@code false}. + * @since Android 1.0 */ public abstract boolean equals(Object obj); /** - * Returns an integer hash code for the receiver. Any two objects which - * answer <code>true</code> when passed to <code>.equals</code> must - * answer the same value for this method. - * + * Returns the hash code value for this {@code Permission}. Returns the same + * hash code for {@code Permission}s that are equal to each other as + * required by the general contract of {@link Object#hashCode}. * - * @return int the receiver's hash. - * - * @see #equals + * @return the hash code value for this {@code Permission}. + * @see Object#equals(Object) + * @see Permission#equals(Object) + * @since Android 1.0 */ public abstract int hashCode(); /** - * Returns the actions associated with the receiver. Subclasses should - * return their actions in canonical form. If no actions are associated with - * the receiver, the empty string should be returned. + * Returns a comma separated string identifying the actions associated with + * this permission. The returned actions are in canonical form. For example: + * + * <pre> + * sp0 = new SocketPermission("www.google.com", "connect,resolve") + * sp1 = new SocketPermission("www.google.com", "resolve,connect") + * sp0.getActions().equals(sp1.getActions()) //yields true + * </pre> * + * Both permissions return "connect,resolve" (in that order) if {@code + * #getActions()} is invoked. Returns an empty String, if no actions are + * associated with this permission. * - * @return String the receiver's actions. + * @return the actions associated with this permission or an empty string if + * no actions are associated with this permission. + * @since Android 1.0 */ public abstract String getActions(); /** - * Indicates whether the argument permission is implied by the receiver. - * + * Indicates whether the specified permission is implied by this permission. + * The {@link AccessController} uses this method to check whether permission + * protected access is allowed with the present policy. * - * @return boolean <code>true</code> if the argument permission is implied - * by the receiver, and <code>false</code> if it is not. * @param permission - * Permission the permission to check. + * the permission to check against this permission. + * @return {@code true} if the specified permission is implied by this + * permission, {@code false} otherwise. + * @since Android 1.0 */ public abstract boolean implies(Permission permission); /** - * Constructs a new instance of this class with its name set to the - * argument. - * + * Constructs a new instance of {@code Permission} with its name. * * @param name - * String the name of the permission. + * the name of the permission. + * @since Android 1.0 */ public Permission(String name) { this.name = name; } /** - * Returns the name of the receiver. - * + * Returns the name of this permission. * - * @return String the receiver's name. + * @return the name of this permission. + * @since Android 1.0 */ public final String getName() { return name; } - /** - * @com.intel.drl.spec_ref + /** + * Invokes {@link SecurityManager#checkPermission(Permission)} with this + * permission as its argument. This method implements the {@link Guard} + * interface. + * + * @param obj + * as specified in {@link Guard#checkGuard(Object)} but ignored + * in this implementation. + * @throws SecurityException + * if this permission is not granted. + * @see Guard + * @see SecurityManager#checkPermission(Permission) + * @since Android 1.0 */ public void checkGuard(Object obj) throws SecurityException { SecurityManager sm = System.getSecurityManager(); @@ -109,12 +144,17 @@ public abstract class Permission implements Guard, Serializable { } /** - * Returns a new PermissionCollection for holding permissions of this class. - * Answer null if any permission collection can be used. - * + * Returns a specific {@link PermissionCollection} container for permissions + * of this type. Returns {@code null} if any permission collection can be + * used. + * <p> + * Subclasses may override this method to return an appropriate collection + * for the specific permissions they implement. + * </p> * - * @return PermissionCollection or null a suitable permission collection for - * instances of the class of the receiver. + * @return an empty {@link PermissionCollection} or {@code null} if any + * permission collection can be used. + * @since Android 1.0 */ public PermissionCollection newPermissionCollection() { return null; @@ -122,10 +162,10 @@ public abstract class Permission implements Guard, Serializable { /** * Returns a string containing a concise, human-readable description of the - * receiver. - * + * this {@code Permission} including its name and its actions. * - * @return String a printable representation for the receiver. + * @return a printable representation for this {@code Permission}. + * @since Android 1.0 */ public String toString() { String actions = getActions(); diff --git a/security/src/main/java/java/security/PermissionCollection.java b/security/src/main/java/java/security/PermissionCollection.java index a0cda25..2502123 100644 --- a/security/src/main/java/java/security/PermissionCollection.java +++ b/security/src/main/java/java/security/PermissionCollection.java @@ -28,81 +28,88 @@ import java.util.Enumeration; import java.util.List; /** - * Abstract superclass of classes which are collections of Permission objects. + * {@code PermissionCollection} is the common base class for all collections + * that provide a convenient method for determining whether or not a given + * permission is implied by any of the permissions present in this collection. + * <p> + * A {@code PermissionCollection} is typically created by using the + * {@link Permission#newPermissionCollection()} factory method. If the mentioned + * method returns {@code null}, then a {@code PermissionCollection} of any type + * can be used. If a collection is returned, it must be used for holding several + * permissions of the particular type. + * </p> + * <p> + * Subclasses must be implemented thread save. + * </p> * + * @since Android 1.0 */ public abstract class PermissionCollection implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -6727011328946861783L; - /** - * @com.intel.drl.spec_ref - */ private boolean readOnly; // = false; /** - * Adds the argument to the collection. - * + * Adds the specified {@code Permission} to this collection. * * @param permission - * java.security.Permission the permission to add to the - * collection. - * @exception IllegalStateException - * if the collection is read only. + * the {@code Permission} to add. + * @throws IllegalStateException + * if the collection is read only. + * @since Android 1.0 */ public abstract void add(Permission permission); /** - * Returns an enumeration of the permissions in the receiver. + * Returns an enumeration over all {@link Permission}s encapsulated by this + * {@code PermissionCollection}. * - * - * @return Enumeration the permissions in the receiver. + * @return an enumeration over all {@link Permission}s. + * @since Android 1.0 */ public abstract Enumeration<Permission> elements(); /** - * Indicates whether the argument permission is implied by the permissions - * contained in the receiver. - * + * Indicates whether the specified permission is implied by this {@code + * PermissionCollection}. * - * @return boolean <code>true</code> if the argument permission is implied - * by the permissions in the receiver, and <code>false</code> if - * it is not. * @param permission - * java.security.Permission the permission to check + * the permission to check. + * @return {@code true} if the given permission is implied by the + * permissions in this collection, {@code false} otherwise. + * @since Android 1.0 */ public abstract boolean implies(Permission permission); /** - * Indicates whether new permissions can be added to the receiver. + * Indicates whether new permissions can be added to this {@code + * PermissionCollection}. * - * - * @return boolean <code>true</code> if the receiver is read only - * <code>false</code> if new elements can still be added to the - * receiver. + * @return {@code true} if the receiver is read only, {@code false} if new + * elements can still be added to this {@code PermissionCollection}. + * @since Android 1.0 */ public boolean isReadOnly() { return readOnly; } /** - * Marks the receiver as read only, so that no new permissions can be added - * to it. + * Marks this {@code PermissionCollection} as read only, so that no new + * permissions can be added to it. * + * @since Android 1.0 */ public void setReadOnly() { readOnly = true; } /** - * Returns a string containing a concise, human-readable description of the - * receiver. - * + * Returns a string containing a concise, human-readable description of this + * {@code PermissionCollection}. * - * @return a printable representation for the receiver. + * @return a printable representation for this {@code PermissionCollection}. + * @since Android 1.0 */ public String toString() { List elist = new ArrayList(100); diff --git a/security/src/main/java/java/security/Permissions.java b/security/src/main/java/java/security/Permissions.java index 93faf33..b9b13c6 100644 --- a/security/src/main/java/java/security/Permissions.java +++ b/security/src/main/java/java/security/Permissions.java @@ -38,15 +38,18 @@ import java.util.NoSuchElementException; import org.apache.harmony.security.internal.nls.Messages; /** - * A heterogeneous collection of permissions. + * {@code Permissions} represents a {@code PermissionCollection} where the + * contained permissions can be of different types. The permissions are + * organized in their appropriate {@code PermissionCollection} obtained by + * {@link Permission#newPermissionCollection()}. For permissions which do not + * provide a dedicated {@code PermissionCollection}, a default permission + * collection, based on a hash table, will be used. * + * @since Android 1.0 */ public final class Permissions extends PermissionCollection implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 4858622370623524688L; private static final ObjectStreamField[] serialPersistentFields = { @@ -56,18 +59,21 @@ public final class Permissions extends PermissionCollection implements // Hash to store PermissionCollection's private transient Map klasses = new HashMap(); - /** - * @com.intel.drl.spec_ref - */ private boolean allEnabled; // = false; /** - * Adds the argument to the collection. - * + * Adds the given {@code Permission} to this heterogeneous {@code + * PermissionCollection}. The {@code permission} is stored in its + * appropriate {@code PermissionCollection}. * * @param permission - * java.security.Permission the permission to add to the - * collection + * the {@code Permission} to be added. + * @throws SecurityException + * if this collection's {@link #isReadOnly()} method returns + * {@code true}. + * @throws NullPointerException + * if {@code permission} is {@code null}. + * @since Android 1.0 */ public void add(Permission permission) { if (isReadOnly()) { @@ -102,12 +108,6 @@ public final class Permissions extends PermissionCollection implements } } - /** - * Returns an enumeration of the permissions in the receiver. - * - * - * @return Enumeration the permissions in the receiver. - */ public Enumeration<Permission> elements() { return new MetaEnumeration(klasses.values().iterator()); } @@ -169,17 +169,6 @@ public final class Permissions extends PermissionCollection implements } } - /** - * Indicates whether the argument permission is implied by the permissions - * contained in the receiver. - * - * - * @return boolean <code>true</code> if the argument permission is implied - * by the permissions in the receiver, and <code>false</code> if - * it is not. - * @param permission - * java.security.Permission the permission to check - */ public boolean implies(Permission permission) { if (permission == null) { // RI compatible diff --git a/security/src/main/java/java/security/PermissionsHash.java b/security/src/main/java/java/security/PermissionsHash.java index 875abe4..69d2b07 100644 --- a/security/src/main/java/java/security/PermissionsHash.java +++ b/security/src/main/java/java/security/PermissionsHash.java @@ -28,12 +28,13 @@ import java.util.Hashtable; import org.apache.harmony.security.internal.nls.Messages; /** - * A default PermissionCollection implementation that uses a hashtable. Each - * hashtable entry stores a Permission object as both the key and the value. - * <br> - * This PermissionCollection is intended for storing "neutral" - * permissions which do not require special collection. + * A default {@code PermissionCollection} implementation that uses a hashtable. + * Each hashtable entry stores a Permission object as both the key and the + * value. <br> + * This {@code PermissionCollection} is intended for storing "neutral" + * permissions which do not require special collection. </br> * + * @since Android 1.0 */ final class PermissionsHash extends PermissionCollection { @@ -51,10 +52,8 @@ final class PermissionsHash extends PermissionCollection { /** * Adds the argument to the collection. * - * * @param permission - * java.security.Permission the permission to add to the - * collection + * the permission to add to the collection. */ public void add(Permission permission) { perms.put(permission, permission); diff --git a/security/src/main/java/java/security/Policy.java b/security/src/main/java/java/security/Policy.java index 9198bde..21b13b0 100644 --- a/security/src/main/java/java/security/Policy.java +++ b/security/src/main/java/java/security/Policy.java @@ -29,8 +29,19 @@ import org.apache.harmony.security.fortress.PolicyUtils; /** - * Abstract superclass of classes which represent the system security policy. + * {@code Policy} is the common super type of classes which represent a system + * security policy. The {@code Policy} specifies which permissions apply to + * which code sources. + * <p> + * The system policy can be changed by setting the {@code 'policy.provider'} + * property in the file named {@code JAVA_HOME/lib/security/java.security} to + * the fully qualified class name of the desired {@code Policy}. + * </p> + * <p> + * Only one instance of a {@code Policy} is active at any time. + * </p> * + * @since Android 1.0 */ public abstract class Policy { @@ -49,38 +60,47 @@ public abstract class Policy { private static Policy activePolicy; /** - * Returns a PermissionCollection describing what permissions are available - * to the given CodeSource based on the current security policy. + * Returns a {@code PermissionCollection} describing what permissions are + * allowed for the specified {@code CodeSource} based on the current + * security policy. * <p> - * Note that this method is <em>not</em> called for classes which are in - * the system domain (i.e. system classes). System classes are - * <em>always</em> given full permissions (i.e. AllPermission). This can - * not be changed by installing a new Policy. - * + * Note that this method is not called for classes which are in the system + * domain (i.e. system classes). System classes are always given + * full permissions (i.e. AllPermission). This can not be changed by + * installing a new policy. + * </p> * * @param cs - * CodeSource the code source to compute the permissions for. - * @return PermissionCollection the permissions the code source should have. + * the {@code CodeSource} to compute the permissions for. + * @return the permissions that are granted to the specified {@code + * CodeSource}. + * @since Android 1.0 */ public abstract PermissionCollection getPermissions(CodeSource cs); /** - * Reloads the policy configuration, depending on how the type of source - * location for the policy information. - * + * Reloads the policy configuration for this {@code Policy} instance. * + * @since Android 1.0 */ public abstract void refresh(); /** - * Returns a PermissionCollection describing what permissions are available - * to the given ProtectionDomain (more specifically, its CodeSource) based - * on the current security policy. + * Returns a {@code PermissionCollection} describing what permissions are + * allowed for the specified {@code ProtectionDomain} (more specifically, + * its {@code CodeSource}) based on the current security policy. + * <p> + * Note that this method is not< called for classes which are in the + * system domain (i.e. system classes). System classes are always + * given full permissions (i.e. AllPermission). This can not be changed by + * installing a new policy. + * </p> * * @param domain - * ProtectionDomain the protection domain to compute the - * permissions for. - * @return PermissionCollection the permissions the code source should have. + * the {@code ProtectionDomain} to compute the permissions for. + * @return the permissions that are granted to the specified {@code + * CodeSource}. + * @since Android 1.0 */ public PermissionCollection getPermissions(ProtectionDomain domain) { if (domain != null) { @@ -90,14 +110,18 @@ public abstract class Policy { } /** - * Returns whether the Permission is implied by the PermissionCollection of - * the Protection Domain + * Indicates whether the specified {@code Permission} is implied by the + * {@code PermissionCollection} of the specified {@code ProtectionDomain}. * * @param domain - * ProtectionDomain for which Permission to be checked + * the {@code ProtectionDomain} for which the permission should + * be granted. * @param permission - * Permission for which authorization is to be verified - * @return boolean Permission implied by ProtectionDomain + * the {@code Permission} for which authorization is to be + * verified. + * @return {@code true} if the {@code Permission} is implied by the {@code + * ProtectionDomain}, {@code false} otherwise. + * @since Android 1.0 */ public boolean implies(ProtectionDomain domain, Permission permission) { if (domain != null) { @@ -119,10 +143,19 @@ public abstract class Policy { /** * Returns the current system security policy. If no policy has been - * instantiated then this is done using the security property <EM>policy.provider</EM> - * + * instantiated then this is done using the security property {@code + * "policy.provider"}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code getPolicy} to be granted, otherwise + * a {@code SecurityException} will be thrown. + * </p> * - * @return Policy the current system security policy. + * @return the current system security policy. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static Policy getPolicy() { SecurityManager sm = System.getSecurityManager(); @@ -169,7 +202,7 @@ public abstract class Policy { } /** - * Returns true if system policy provider is instantiated. + * Returns {@code true} if system policy provider is instantiated. */ static boolean isSet() { return activePolicy != null; @@ -197,11 +230,19 @@ public abstract class Policy { } /** - * Sets the system-wide policy object if it is permitted by the security - * manager. + * Sets the system wide policy. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code setPolicy} to be granted, otherwise + * a {@code SecurityException} will be thrown. + * </p> * * @param policy - * Policy the policy object that needs to be set. + * the {@code Policy} to set. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static void setPolicy(Policy policy) { SecurityManager sm = System.getSecurityManager(); diff --git a/security/src/main/java/java/security/Principal.java b/security/src/main/java/java/security/Principal.java index 2fac7af..0716681 100644 --- a/security/src/main/java/java/security/Principal.java +++ b/security/src/main/java/java/security/Principal.java @@ -24,25 +24,52 @@ package java.security; /** - * Principals are objects which have identities. These can be individuals, - * groups, corporations, unique program executions, etc. + * {@code Principal}s are objects which have identities. These can be + * individuals, groups, corporations, unique program executions, etc. * + * @since Android 1.0 */ public interface Principal { - /** - * @com.intel.drl.spec_ref + /** + * Compares the specified object with this {@code Principal} for equality + * and returns {@code true} if the specified object is equal, {@code false} + * otherwise. + * + * @param obj + * object to be compared for equality with this {@code + * Principal}. + * @return {@code true} if the specified object is equal to this {@code + * Principal}, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals( Object obj ); - /** - * @com.intel.drl.spec_ref + + /** + * Returns the name of this {@code Principal}. + * + * @return the name of this {@code Principal}. + * @since Android 1.0 */ public String getName(); - /** - * @com.intel.drl.spec_ref + + /** + * Returns the hash code value for this {@code Principal}. Returns the same + * hash code for {@code Principal}s that are equal to each other as + * required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this {@code Principal}. + * @see Object#equals(Object) + * @see Principal#equals(Object) + * @since Android 1.0 */ public int hashCode(); + /** - * @com.intel.drl.spec_ref + * Returns a string containing a concise, human-readable description of + * this {@code Principal}. + * + * @return a printable representation for this {@code Principal}. + * @since Android 1.0 */ public String toString(); } diff --git a/security/src/main/java/java/security/PrivateKey.java b/security/src/main/java/java/security/PrivateKey.java index f09b4a8..8513b75 100644 --- a/security/src/main/java/java/security/PrivateKey.java +++ b/security/src/main/java/java/security/PrivateKey.java @@ -23,12 +23,17 @@ package java.security; /** - * @com.intel.drl.spec_ref + * {@code PrivateKey} is the common interface for private keys. * + * @see PublicKey + * @since Android 1.0 */ public interface PrivateKey extends Key { + /** - * @com.intel.drl.spec_ref + * The {@code serialVersionUID} to be compatible with JDK1.1. + * + * @since Android 1.0 */ public static final long serialVersionUID = 6034044314589513430L; }
\ No newline at end of file diff --git a/security/src/main/java/java/security/PrivilegedAction.java b/security/src/main/java/java/security/PrivilegedAction.java index 4e16e3a..5912cdc 100644 --- a/security/src/main/java/java/security/PrivilegedAction.java +++ b/security/src/main/java/java/security/PrivilegedAction.java @@ -23,12 +23,23 @@ package java.security; /** - * @com.intel.drl.spec_ref + * {@code PrivilegedAction} represents an action that can be executed privileged + * regarding access control. Instances of {@code PrivilegedAction} can be + * executed on {@code AccessController.doPrivileged()}. + * + * @see AccessController + * @see AccessController#doPrivileged(PrivilegedAction) + * @see AccessController#doPrivileged(PrivilegedAction, AccessControlContext) + * @see PrivilegedExceptionAction + * @since Android 1.0 */ - public interface PrivilegedAction<T> { + /** - * @com.intel.drl.spec_ref + * Returns the result of running the action. + * + * @return the result of running the action. + * @since Android 1.0 */ public T run(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/PrivilegedActionException.java b/security/src/main/java/java/security/PrivilegedActionException.java index d68b6b9..eaca2b2 100644 --- a/security/src/main/java/java/security/PrivilegedActionException.java +++ b/security/src/main/java/java/security/PrivilegedActionException.java @@ -23,25 +23,37 @@ package java.security; /** - * Instances of this class are used to wrap exceptions which occur within - * privileged operations. + * {@code PrivilegedActionException} wraps exceptions which are thrown from + * within privileged operations. + * <p> + * Privileged actions which can throw exceptions are of type {@code + * PrivilegedExceptionAction} and are thrown by + * <ul> + * {@code AccessController#doPrivileged(PrivilegedExceptionAction)}<br> + * {@code AccessController#doPrivileged(PrivilegedExceptionAction, + * AccessControlContext)} </br> + * </ul> + * </p> * + * @see PrivilegedExceptionAction + * @see AccessController#doPrivileged(PrivilegedExceptionAction) + * @see AccessController#doPrivileged(PrivilegedExceptionAction, + * AccessControlContext) + * @since Android 1.0 */ public class PrivilegedActionException extends Exception { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 4724086851538908602l; - /** - * @com.intel.drl.spec_ref - */ private Exception exception; /** - * Constructs a new instance of this class with its exception filled in. - * @param ex + * Constructs a new instance of {@code PrivilegedActionException} with the + * cause. + * + * @param ex + * the exception which is the cause for this exception. + * @since Android 1.0 */ public PrivilegedActionException(Exception ex) { super(ex); @@ -49,8 +61,12 @@ public class PrivilegedActionException extends Exception { } /** - * Returns the exception which caused the receiver to be thrown. - * @return exception + * Returns the exception that was thrown by a + * {@code PrivilegedExceptionAction}. + * + * @return the exception that was thrown by a + * {@code PrivilegedExceptionAction}. + * @since Android 1.0 */ public Exception getException() { return exception; // return ( getCause() instanceof Exception ) ? @@ -58,21 +74,24 @@ public class PrivilegedActionException extends Exception { } /** - * Returns the cause of this Throwable, or null if there is no cause. + * Returns the exception that was thrown by a + * {@code PrivilegedExceptionAction}. * - * - * @return Throwable The receiver's cause. + * @return the exception that was thrown by a + * {@code PrivilegedExceptionAction}. + * @since Android 1.0 */ public Throwable getCause() { return exception; } /** - * Returns a string containing a concise, human-readable description of the - * receiver. - * + * Returns a string containing a concise, human-readable description of this + * {@code PrivilegedActionException}. * - * @return String a printable representation for the receiver. + * @return a printable representation for this {@code + * PrivilegedActionException}. + * @since Android 1.0 */ public String toString() { String s = getClass().getName(); diff --git a/security/src/main/java/java/security/PrivilegedExceptionAction.java b/security/src/main/java/java/security/PrivilegedExceptionAction.java index 98d56e3..dd3ae8d 100644 --- a/security/src/main/java/java/security/PrivilegedExceptionAction.java +++ b/security/src/main/java/java/security/PrivilegedExceptionAction.java @@ -23,11 +23,26 @@ package java.security; /** - * @com.intel.drl.spec_ref + * {@code PrivilegedAction} represents an action, that can be executed + * privileged regarding access control. Instances of {@code PrivilegedAction} + * can be executed invoking {@code AccessController.doPrivileged()}. + * + * @see AccessController + * @see AccessController#doPrivileged(PrivilegedExceptionAction) + * @see AccessController#doPrivileged(PrivilegedExceptionAction, + * AccessControlContext) + * @see PrivilegedAction + * @since Android 1.0 */ public interface PrivilegedExceptionAction<T> { + /** - * @com.intel.drl.spec_ref + * Returns the result of running the action. + * + * @return the result of running the action + * @throws Exception + * if an exception occurred. + * @since Android 1.0 */ T run() throws Exception; } diff --git a/security/src/main/java/java/security/ProtectionDomain.java b/security/src/main/java/java/security/ProtectionDomain.java index 6f98194..d41f4a8 100644 --- a/security/src/main/java/java/security/ProtectionDomain.java +++ b/security/src/main/java/java/security/ProtectionDomain.java @@ -23,11 +23,16 @@ package java.security; /** - * This class represents a domain in which classes from the same source (URL) - * and signed by the same keys are stored. All the classes inside are given the - * same permissions. + * {@code ProtectionDomain} represents all permissions that are granted to a + * specific code source. The {@link ClassLoader} associates each class with the + * corresponding {@code ProtectionDomain}, depending on the location and the + * certificates (encapsulates in {@link CodeSource}) it loads the code from. * <p> - * Note: a class can only belong to one and only one protection domain. + * A class belongs to exactly one protection domain and the protection domain + * can not be changed during the lifetime of the class. + * </p> + * + * @since Android 1.0 */ public class ProtectionDomain { @@ -48,11 +53,32 @@ public class ProtectionDomain { private boolean dynamicPerms; /** - * Constructs a protection domain from the given code source and the - * permissions that that should be granted to the classes which are - * encapsulated in it. - * @param cs - * @param permissions + * Constructs a new instance of {@code ProtectionDomain} with the specified + * code source and the specified static permissions. + * <p> + * If {@code permissions} is not {@code null}, the {@code permissions} + * collection is made immutable by calling + * {@link PermissionCollection#setReadOnly()} and it is considered as + * granted statically to this {@code ProtectionDomain}. + * </p> + * <p> + * The policy will not be consulted by access checks against this {@code + * ProtectionDomain}. + * </p> + * <p> + * If {@code permissions} is {@code null}, the method + * {@link ProtectionDomain#implies(Permission)} always returns {@code false} + * . + * </p> + * + * @param cs + * the code source associated with this domain, maybe {@code + * null}. + * @param permissions + * the {@code PermissionCollection} containing all permissions to + * be statically granted to this {@code ProtectionDomain}, maybe + * {@code null}. + * @since Android 1.0 */ public ProtectionDomain(CodeSource cs, PermissionCollection permissions) { this.codeSource = cs; @@ -65,22 +91,36 @@ public class ProtectionDomain { //dynamicPerms = false; } + /** - * Constructs a protection domain from the given code source and the - * permissions that that should be granted to the classes which are - * encapsulated in it. - * - * This constructor also allows the association of a ClassLoader and group - * of Principals. + * Constructs a new instance of {@code ProtectionDomain} with the specified + * code source, the permissions, the class loader and the principals. + * <p> + * If {@code permissions} is {@code null}, and access checks are performed + * against this protection domain, the permissions defined by the policy are + * consulted. If {@code permissions} is not {@code null}, the {@code + * permissions} collection is made immutable by calling + * {@link PermissionCollection#setReadOnly()}. If access checks are + * performed, the policy and the provided permission collection are checked. + * </p> + * <p> + * External modifications of the provided {@code principals} array has no + * impact on this {@code ProtectionDomain}. + * </p> * * @param cs - * the CodeSource associated with this domain + * the code source associated with this domain, maybe {@code + * null}. * @param permissions - * the Permissions associated with this domain + * the permissions associated with this domain, maybe {@code + * null}. * @param cl - * the ClassLoader associated with this domain + * the class loader associated with this domain, maybe {@code + * null}. * @param principals - * the Principals associated with this domain + * the principals associated with this domain, maybe {@code null} + * . + * @since Android 1.0 */ public ProtectionDomain(CodeSource cs, PermissionCollection permissions, ClassLoader cl, Principal[] principals) { @@ -99,39 +139,47 @@ public class ProtectionDomain { } /** - * Returns the ClassLoader associated with the ProtectionDomain + * Returns the {@code ClassLoader} associated with this {@code + * ProtectionDomain}. * - * @return ClassLoader associated ClassLoader + * @return the {@code ClassLoader} associated with this {@code + * ProtectionDomain}, maybe {@code null}. + * @since Android 1.0 */ public final ClassLoader getClassLoader() { return classLoader; } /** - * Returns the code source of this domain. + * Returns the {@code CodeSource} of this {@code ProtectionDomain}. * - * @return java.security.CodeSource the code source of this domain + * @return the {@code CodeSource} of this {@code ProtectionDomain}, maybe + * {@code null}. + * @since Android 1.0 */ public final CodeSource getCodeSource() { return codeSource; } /** - * Returns the permissions that should be granted to the classes which are - * encapsulated in this domain. + * Returns the static permissions that are granted to this {@code + * ProtectionDomain}. * - * @return java.security.PermissionCollection collection of permissions - * associated with this domain. + * @return the static permissions that are granted to this {@code + * ProtectionDomain}, maybe {@code null}. + * @since Android 1.0 */ public final PermissionCollection getPermissions() { return permissions; } /** - * Returns the Principals associated with this ProtectionDomain. A change to - * the returned array will not impact the ProtectionDomain. + * Returns the principals associated with this {@code ProtectionDomain}. + * Modifications of the returned {@code Principal} array has no impact on + * this {@code ProtectionDomain}. * - * @return Principals[] Principals associated with the ProtectionDomain. + * @return the principals associated with this {@code ProtectionDomain}. + * @since Android 1.0 */ public final Principal[] getPrincipals() { if( principals == null ) { @@ -143,14 +191,27 @@ public class ProtectionDomain { } /** - * Determines whether the permission collection of this domain implies the - * argument permission. - * + * Indicates whether the specified permission is implied by this {@code + * ProtectionDomain}. + * <p> + * If this {@code ProtectionDomain} was constructed with + * {@link #ProtectionDomain(CodeSource, PermissionCollection)}, the + * specified permission is only checked against the permission collection + * provided in the constructor. If {@code null} was provided, {@code false} + * is returned. + * </p> + * <p> + * If this {@code ProtectionDomain} was constructed with + * {@link #ProtectionDomain(CodeSource, PermissionCollection, ClassLoader, Principal[])} + * , the specified permission is checked against the policy and the + * permission collection provided in the constructor. + * </p> * - * @return boolean true if this permission collection implies the argument - * and false otherwise. * @param permission - * java.security.Permission the permission to check. + * the permission to check against the domain. + * @return {@code true} if the specified {@code permission} is implied by + * this {@code ProtectionDomain}, {@code false} otherwise. + * @since Android 1.0 */ public boolean implies(Permission permission) { // First, test with the Policy, as the default Policy.implies() @@ -170,9 +231,10 @@ public class ProtectionDomain { /** * Returns a string containing a concise, human-readable description of the - * receiver. + * this {@code ProtectionDomain}. * - * @return String a printable representation for the receiver. + * @return a printable representation for this {@code ProtectionDomain}. + * @since Android 1.0 */ public String toString() { //FIXME: 1.5 use StreamBuilder here diff --git a/security/src/main/java/java/security/Provider.java b/security/src/main/java/java/security/Provider.java index ae4acb9..491470f 100644 --- a/security/src/main/java/java/security/Provider.java +++ b/security/src/main/java/java/security/Provider.java @@ -40,6 +40,12 @@ import org.apache.harmony.luni.util.TwoKeyHashMap; import org.apache.harmony.security.fortress.Services; import org.apache.harmony.security.internal.nls.Messages; +/** + * {@code Provider} is the abstract superclass for all security providers in the + * Java security infrastructure. + * + * @since Android 1.0 + */ public abstract class Provider extends Properties { private static final long serialVersionUID = -4298000515446427739L; @@ -90,6 +96,18 @@ public abstract class Provider extends Properties { // last Service found by type private transient Provider.Service lastServicesByType; + /** + * Constructs a new instance of {@code Provider} with its name, version and + * description. + * + * @param name + * the name of the provider. + * @param version + * the version of the provider. + * @param info + * a description of the provider. + * @since Android 1.0 + */ protected Provider(String name, double version, String info) { this.name = name; this.version = version; @@ -101,47 +119,61 @@ public abstract class Provider extends Properties { /** * Returns the name of this provider. * - * - * - * @return String name of the provider + * @return the name of this provider. + * @since Android 1.0 */ public String getName() { return name; } /** - * Returns the version number for the services being provided - * + * Returns the version number for the services being provided. * - * - * @return double version number for the services being provided + * @return the version number for the services being provided. + * @since Android 1.0 */ public double getVersion() { return version; } /** - * Returns the generic information about the services being provided. - * + * Returns a description of the services being provided. * - * - * @return String generic description of the services being provided + * @return a description of the services being provided. + * @since Android 1.0 */ public String getInfo() { return info; } /** - * Returns a string containing a concise, human-readable description of the - * receiver. - * - * - * @return a printable representation for the receiver. + * Returns a string containing a concise, human-readable description of + * this {@code Provider} including its name and its version. + * + * @return a printable representation for this {@code Provider}. + * @since Android 1.0 */ public String toString() { + // BEGIN android-changed return name + " version " + version; //$NON-NLS-1$ + // END android-changed } + /** + * Clears all properties used to look up services implemented by this + * {@code Provider}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code clearProviderProperties.NAME} + * (where NAME is the provider name) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * </p> + * + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public synchronized void clear() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -177,6 +209,22 @@ public abstract class Provider extends Properties { myPutAll(tmp); } + /** + * Copies all from the provided map to this {@code Provider}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code putProviderProperty.NAME} (where + * NAME is the provider name) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * </p> + * + * @param t + * the mappings to copy to this provider. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public synchronized void putAll(Map<?,?> t) { // Implementation note: @@ -229,6 +277,27 @@ public abstract class Provider extends Properties { return Collections.unmodifiableCollection(super.values()); } + /** + * Maps the specified {@code key} property name to the specified {@code + * value}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code putProviderProperty.NAME} (where + * NAME is the provider name) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * </p> + * + * @param key + * the name of the property. + * @param value + * the value of the property. + * @return the value that was previously mapped to the specified {@code key} + * ,or {@code null} if it did not have one. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 + */ public synchronized Object put(Object key, Object value) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -252,6 +321,25 @@ public abstract class Provider extends Properties { return super.put(key, value); } + /** + * Removes the specified {@code key} and its associated value from this + * {@code Provider}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code removeProviderProperty.NAME} (where + * NAME is the provider name) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * </p> + * + * @param key + * the name of the property + * @return the value that was mapped to the specified {@code key} ,or + * {@code null} if no mapping was present + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have the permission to invoke this method. + * @since Android 1.0 + */ public synchronized Object remove(Object key) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -277,19 +365,18 @@ public abstract class Provider extends Properties { } /** - * - * returns true if the provider implements the specified algorithm. Caller must - * specify the cryptographic service and specify constraints via the + * returns true if the provider implements the specified algorithm. Caller + * must specify the cryptographic service and specify constraints via the * attribute name the attribute value * * @param serv - * Crypto service + * Crypto service. * @param alg - * Algorithm or type + * Algorithm or type. * @param attribute - * The attribute name or null + * The attribute name or {@code null}. * @param val - * The attribute value + * The attribute value. * @return */ boolean implementsAlg(String serv, String alg, String attribute, String val) { @@ -319,11 +406,11 @@ public abstract class Provider extends Properties { String attributeValue = getPropertyIgnoreCase(servAlg + ' ' + attribute); if (attributeValue != null) { if (attribute.equalsIgnoreCase("KeySize")) { //$NON-NLS-1$ -// BEGIN android-changed + // BEGIN android-changed if (Integer.parseInt(attributeValue) >= Integer.parseInt(val)) { -// END android-changed return true; } + // END android-changed } else { // other attributes if (attributeValue.equalsIgnoreCase(val)) { return true; @@ -374,6 +461,23 @@ public abstract class Provider extends Properties { return null; } + /** + * Returns the service with the specified {@code type} implementing the + * specified {@code algorithm}, or {@code null} if no such implementation + * exists. + * <p> + * If two services match the requested type and algorithm, the one added + * with the {@link #putService(Service)} is returned (as opposed to the one + * added via {@link #put(Object, Object)}. + * + * @param type + * the type of the service (for example {@code KeyPairGenerator}) + * @param algorithm + * the algorithm name (case insensitive) + * @return the requested service, or {@code null} if no such implementation + * exists + * @since Android 1.0 + */ public synchronized Provider.Service getService(String type, String algorithm) { if (type == null || algorithm == null) { @@ -412,6 +516,14 @@ public abstract class Provider extends Properties { return null; } + /** + * Returns an unmodifiable {@code Set} of all services registered by this + * provider. + * + * @return an unmodifiable {@code Set} of all services registered by this + * provider + * @since Android 1.0 + */ public synchronized Set<Provider.Service> getServices() { updatePropertyServiceTable(); if (lastServicesSet != null) { @@ -429,6 +541,22 @@ public abstract class Provider extends Properties { return lastServicesSet; } + /** + * Adds a {@code Service} to this {@code Provider}. If a service with the + * same name was registered via this method, it is replace. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code putProviderProperty.NAME} (where + * NAME is the provider name) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * + * @param s + * the {@code Service} to register + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method + * @since Android 1.0 + */ protected synchronized void putService(Provider.Service s) { if (s == null) { throw new NullPointerException(); @@ -457,6 +585,24 @@ public abstract class Provider extends Properties { serviceInfoToProperties(s); } + /** + * Removes a previously registered {@code Service} from this {@code + * Provider}. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code removeProviderProperty.NAME} (where + * NAME is the provider name) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * + * @param s + * the {@code Service} to remove + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method + * @throws NullPointerException + * if {@code s} is {@code null} + * @since Android 1.0 + */ protected synchronized void removeService(Provider.Service s) { if (s == null) { throw new NullPointerException(); @@ -755,6 +901,13 @@ public abstract class Provider extends Properties { return null; } + /** + * {@code Service} represents a service in the Java Security infrastructure. + * Each service describes its type, the algorithm it implements, to which + * provider it belongs and other properties. + * + * @since Android 1.0 + */ public static class Service { // The provider private Provider provider; @@ -780,6 +933,30 @@ public abstract class Provider extends Properties { // For newInstance() optimization private String lastClassName; + /** + * Constructs a new instance of {@code Service} with the given + * attributes. + * + * @param provider + * the provider to which this service belongs. + * @param type + * the type of this service (for example {@code + * KeyPairGenerator}). + * @param algorithm + * the algorithm this service implements. + * @param className + * the name of the class implementing this service. + * @param aliases + * {@code List} of aliases for the algorithm name, or {@code + * null} if the implemented algorithm has no aliases. + * @param attributes + * {@code Map} of additional attributes, or {@code null} if + * this {@code Service} has no attributed. + * @throws NullPointerException + * if {@code provider, type, algorithm} or {@code className} + * is {@code null}. + * @since Android 1.0 + */ public Service(Provider provider, String type, String algorithm, String className, List<String> aliases, Map<String, String> attributes) { if (provider == null || type == null || algorithm == null @@ -792,10 +969,10 @@ public abstract class Provider extends Properties { this.className = className; // BEGIN android-changed this.aliases = ((aliases != null) && (aliases.size() == 0)) - ? Collections.<String>emptyList() : aliases; + ? Collections.<String>emptyList() : aliases; this.attributes = - ((attributes != null) && (attributes.size() == 0)) - ? Collections.<String,String>emptyMap() : attributes; + ((attributes != null) && (attributes.size() == 0)) + ? Collections.<String,String>emptyMap() : attributes; // END android-changed } @@ -815,8 +992,8 @@ public abstract class Provider extends Properties { /** * Puts a new attribute mapping. * - * @param name the attribute name - * @param value the attribute value + * @param name the attribute name. + * @param value the attribute value. */ /*package*/ void putAttribute(String name, String value) { if ((attributes == null) || (attributes.size() == 0)) { @@ -826,22 +1003,60 @@ public abstract class Provider extends Properties { } // END android-added + /** + * Returns the type of this {@code Service}. For example {@code + * KeyPairGenerator}. + * + * @return the type of this {@code Service}. + * @since Android 1.0 + */ public final String getType() { return type; } + /** + * Returns the name of the algorithm implemented by this {@code Service} + * . + * + * @return the name of the algorithm implemented by this {@code Service} + * . + * @since Android 1.0 + */ public final String getAlgorithm() { return algorithm; } + /** + * Returns the {@code Provider} this {@code Service} belongs to. + * + * @return the {@code Provider} this {@code Service} belongs to. + * @since Android 1.0 + */ public final Provider getProvider() { return provider; } + /** + * Returns the name of the class implementing this {@code Service}. + * + * @return the name of the class implementing this {@code Service}. + * @since Android 1.0 + */ public final String getClassName() { return className; } + /** + * Returns the value of the attribute with the specified {@code name}. + * + * @param name + * the name of the attribute. + * @return the value of the attribute, or {@code null} if no attribute + * with the given name is set. + * @throws NullPointerException + * if {@code name} is {@code null}. + * @since Android 1.0 + */ public final String getAttribute(String name) { if (name == null) { throw new NullPointerException(); @@ -856,6 +1071,23 @@ public abstract class Provider extends Properties { return aliases.iterator(); } + /** + * Creates and returns a new instance of the implementation described by + * this {@code Service}. + * + * @param constructorParameter + * the parameter that is used by the constructor, or {@code + * null} if the implementation does not declare a constructor + * parameter. + * @return a new instance of the implementation described by this + * {@code Service}. + * @throws NoSuchAlgorithmException + * if the instance could not be constructed. + * @throws InvalidParameterException + * if the implementation does not support the specified + * {@code constructorParameter}. + * @since Android 1.0 + */ public Object newInstance(Object constructorParameter) throws NoSuchAlgorithmException { if (implementation == null || !className.equals(lastClassName)) { @@ -914,17 +1146,27 @@ public abstract class Provider extends Properties { } } + /** + * Indicates whether this {@code Service} supports the specified + * constructor parameter. + * + * @param parameter + * the parameter to test. + * @return {@code true} if this {@code Service} supports the specified + * constructor parameter, {@code false} otherwise. + * @since Android 1.0 + */ public boolean supportsParameter(Object parameter) { return true; } - /** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * - * @return a printable representation for the receiver. - */ + /** + * Returns a string containing a concise, human-readable description of + * this {@code Service}. + * + * @return a printable representation for this {@code Service}. + * @since Android 1.0 + */ public String toString() { String result = "Provider " + provider.getName() + " Service " //$NON-NLS-1$ //$NON-NLS-2$ + type + "." + algorithm + " " + className; //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/security/src/main/java/java/security/ProviderException.java b/security/src/main/java/java/security/ProviderException.java index 6ca33ab..d4def5b 100644 --- a/security/src/main/java/java/security/ProviderException.java +++ b/security/src/main/java/java/security/ProviderException.java @@ -23,37 +23,56 @@ package java.security; /** - * @com.intel.drl.spec_ref + * {@code ProviderException} is a general exception, thrown by security {@code + * Providers}. * + * @see Provider + * @since Android 1.0 */ public class ProviderException extends RuntimeException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 5256023526693665674L; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code ProviderException} with the given + * message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public ProviderException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code ProviderException}. + * + * @since Android 1.0 */ public ProviderException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code ProviderException} with the given + * message and the cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public ProviderException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code ProviderException} with the cause. + * + * @param cause + * the exception which is the cause for this exception. + * @since Android 1.0 */ public ProviderException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/PublicKey.java b/security/src/main/java/java/security/PublicKey.java index ff68e28..4888a64 100644 --- a/security/src/main/java/java/security/PublicKey.java +++ b/security/src/main/java/java/security/PublicKey.java @@ -23,15 +23,17 @@ package java.security; /** - * Superinterface for all specific public key interfaces + * {@code PublicKey} is the common interface for public keys. * - * - * @see PublicKey * @see PrivateKey + * @since Android 1.0 */ public interface PublicKey extends Key { + /** - * @com.intel.drl.spec_ref + * The {@code serialVersionUID} to be compatible with JDK1.1. + * + * @since Android 1.0 */ public static final long serialVersionUID = 7187392471159151072L; } diff --git a/security/src/main/java/java/security/SecureClassLoader.java b/security/src/main/java/java/security/SecureClassLoader.java index ed1a7b0..7d08fc8 100644 --- a/security/src/main/java/java/security/SecureClassLoader.java +++ b/security/src/main/java/java/security/SecureClassLoader.java @@ -25,35 +25,66 @@ package java.security; import java.nio.ByteBuffer; import java.util.HashMap; + /** - * SecureClassLoaders are used to dynamically load, link and install classes - * into a running image. Additionally, they (optionally) associate the classes - * they create with a code source and provide mechanisms to allow the relevant - * permissions to be retrieved. + * {@code SecureClassLoader} represents a {@code ClassLoader} which associates + * the classes it loads with a code source and provide mechanisms to allow the + * relevant permissions to be retrieved. * + * @since Android 1.0 */ - public class SecureClassLoader extends ClassLoader { // A cache of ProtectionDomains for a given CodeSource private HashMap pds = new HashMap(); /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code SecureClassLoader}. The default + * parent {@code ClassLoader} is used. + * <p> + * If a {@code SecurityManager} is installed, code calling this constructor + * needs the {@code SecurityPermission} {@code checkCreateClassLoader} to be + * granted, otherwise a {@code SecurityException} will be thrown. + * </p> + * + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this constructor. + * @since Android 1.0 */ protected SecureClassLoader() { super(); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code SecureClassLoader} with the specified + * parent {@code ClassLoader}. + * <p> + * If a {@code SecurityManager} is installed, code calling this constructor + * needs the {@code SecurityPermission} {@code checkCreateClassLoader} to be + * granted, otherwise a {@code SecurityException} will be thrown. + * </p> + * + * @param parent + * the parent {@code ClassLoader}. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this constructor. + * @since Android 1.0 */ protected SecureClassLoader(ClassLoader parent) { super(parent); } /** - * @com.intel.drl.spec_ref + * Returns the {@code PermissionCollection} for the specified {@code + * CodeSource}. + * + * @param codesource + * the code source. + * @return the {@code PermissionCollection} for the specified {@code + * CodeSource}. + * @since Android 1.0 */ protected PermissionCollection getPermissions(CodeSource codesource) { // Do nothing by default, ProtectionDomain will take care about @@ -62,7 +93,30 @@ public class SecureClassLoader extends ClassLoader { } /** - * @com.intel.drl.spec_ref + * Constructs a new class from an array of bytes containing a class + * definition in class file format with an optional {@code CodeSource}. + * + * @param name + * the name of the new class. + * @param b + * a memory image of a class file. + * @param off + * the start offset in b of the class data. + * @param len + * the length of the class data. + * @param cs + * the {@code CodeSource}, or {@code null}. + * @return a new class. + * @throws IndexOutOfBoundsException + * if {@code off} or {@code len} are not valid in respect to + * {@code b}. + * @throws ClassFormatError + * if the specified data is not valid class data. + * @throws SecurityException + * if the package to which this class is to be added, already + * contains classes which were signed by different certificates, + * or if the class name begins with "java." + * @since Android 1.0 */ protected final Class<?> defineClass(String name, byte[] b, int off, int len, CodeSource cs) { @@ -71,7 +125,23 @@ public class SecureClassLoader extends ClassLoader { } /** - * @com.intel.drl.spec_ref + * Constructs a new class from an array of bytes containing a class + * definition in class file format with an optional {@code CodeSource}. + * + * @param name + * the name of the new class. + * @param b + * a memory image of a class file. + * @param cs + * the {@code CodeSource}, or {@code null}. + * @return a new class. + * @throws ClassFormatError + * if the specified data is not valid class data. + * @throws SecurityException + * if the package to which this class is to be added, already + * contains classes which were signed by different certificates, + * or if the class name begins with "java." + * @since Android 1.0 */ protected final Class<?> defineClass(String name, ByteBuffer b, CodeSource cs) { //FIXME 1.5 - remove b.array(), call super.defineClass(,ByteBuffer,) diff --git a/security/src/main/java/java/security/SecureRandom.java b/security/src/main/java/java/security/SecureRandom.java index 0cf5353..e1d99e9 100644 --- a/security/src/main/java/java/security/SecureRandom.java +++ b/security/src/main/java/java/security/SecureRandom.java @@ -33,16 +33,13 @@ import org.apache.harmony.security.internal.nls.Messages; import org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl; /** - * @com.intel.drl.spec_ref + * {@code SecureRandom} is an engine class which is capable of generating + * cryptographically secure pseudo-random numbers. * + * @since Android 1.0 */ - public class SecureRandom extends Random { - /** - * @com.intel.drl.spec_ref - * - */ private static final long serialVersionUID = 4940670005562187L; // The service name. @@ -51,50 +48,29 @@ public class SecureRandom extends Random { // Used to access common engine functionality private static transient Engine engine = new Engine(SERVICE); - /** - * @com.intel.drl.spec_ref - */ private Provider provider; - /** - * @com.intel.drl.spec_ref - */ private SecureRandomSpi secureRandomSpi; - /** - * @com.intel.drl.spec_ref - */ private String algorithm; - /** - * @com.intel.drl.spec_ref - */ private byte[] state; - /** - * @com.intel.drl.spec_ref - */ private byte[] randomBytes; - /** - * @com.intel.drl.spec_ref - */ private int randomBytesUsed; - /** - * @com.intel.drl.spec_ref - */ private long counter; // Internal SecureRandom used for getSeed(int) private static transient SecureRandom internalSecureRandom; /** - * Constructs a new instance of this class. Users are encouraged to use - * <code>getInstance()</code> instead. + * Constructs a new instance of {@code SecureRandom}. An implementation for + * the highest-priority provider is returned. The constructed instance will + * not have been seeded. * - * An implementation for the highest-priority provider is returned. The - * instance returned will not have been seeded. + * @since Android 1.0 */ public SecureRandom() { super(0); @@ -115,14 +91,13 @@ public class SecureRandom extends Random { } /** - * Constructs a new instance of this class. Users are encouraged to use - * <code>getInstance()</code> instead. - * - * An implementation for the highest-priority provider is returned. The - * instance returned will be seeded with the parameter. + * Constructs a new instance of {@code SecureRandom}. An implementation for + * the highest-priority provider is returned. The constructed instance will + * be seeded with the parameter. * * @param seed - * bytes forming the seed for this generator. + * the seed for this generator. + * @since Android 1.0 */ public SecureRandom(byte[] seed) { this(); @@ -143,8 +118,14 @@ public class SecureRandom extends Random { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code SecureRandom} using the given + * implementation from the specified provider. * + * @param secureRandomSpi + * the implementation. + * @param provider + * the security provider. + * @since Android 1.0 */ protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider) { @@ -162,8 +143,18 @@ public class SecureRandom extends Random { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code SecureRandom} that utilizes the + * specified algorithm. * + * @param algorithm + * the name of the algorithm to use. + * @return a new instance of {@code SecureRandom} that utilizes the + * specified algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -177,19 +168,22 @@ public class SecureRandom extends Random { } /** - * Returns a new SecureRandom which is capable of running the algorithm - * described by the argument. The result will be an instance of a subclass - * of SecureRandomSpi which implements that algorithm. + * Returns a new instance of {@code SecureRandom} that utilizes the + * specified algorithm from the specified provider. * * @param algorithm - * java.lang.String Name of the algorithm desired + * the name of the algorithm to use. * @param provider - * java.security.Provider Provider which has to implement the - * algorithm - * @return SecureRandom a concrete implementation for the algorithm desired. - * - * @exception NoSuchAlgorithmException - * If the algorithm cannot be found + * the name of the provider. + * @return a new instance of {@code SecureRandom} that utilizes the + * specified algorithm from the specified provider. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static SecureRandom getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -205,8 +199,20 @@ public class SecureRandom extends Random { } /** - * @com.intel.drl.spec_ref + * Returns a new instance of {@code SecureRandom} that utilizes the + * specified algorithm from the specified provider. * + * @param algorithm + * the name of the algorithm to use. + * @param provider + * the security provider. + * @return a new instance of {@code SecureRandom} that utilizes the + * specified algorithm from the specified provider. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static SecureRandom getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -223,38 +229,46 @@ public class SecureRandom extends Random { } /** - * Returns the Provider of the secure random represented by the receiver. + * Returns the provider associated with this {@code SecureRandom}. * - * @return Provider an instance of a subclass of java.security.Provider + * @return the provider associated with this {@code SecureRandom}. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref + * Returns the name of the algorithm of this {@code SecureRandom}. * + * @return the name of the algorithm of this {@code SecureRandom}. + * @since Android 1.0 */ public String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref + * Reseeds this {@code SecureRandom} instance with the specified {@code + * seed}. The seed of this {@code SecureRandom} instance is supplemented, + * not replaced. * + * @param seed + * the new seed. + * @since Android 1.0 */ public synchronized void setSeed(byte[] seed) { secureRandomSpi.engineSetSeed(seed); } /** - * Reseeds this random object with the eight bytes described by the - * representation of the long provided. - * + * Reseeds this this {@code SecureRandom} instance with the eight bytes + * described by the representation of the given {@code long seed}. The seed + * of this {@code SecureRandom} instance is supplemented, not replaced. * * @param seed - * long Number whose representation to use to reseed the - * receiver. + * the new seed. + * @since Android 1.0 */ public void setSeed(long seed) { if (seed == 0) { // skip call from Random @@ -274,16 +288,26 @@ public class SecureRandom extends Random { } /** - * @com.intel.drl.spec_ref + * Generates and stores random bytes in the given {@code byte[]} for each + * array element. * + * @param bytes + * the {@code byte[]} to be filled with random bytes. + * @since Android 1.0 */ public synchronized void nextBytes(byte[] bytes) { secureRandomSpi.engineNextBytes(bytes); } /** - * @com.intel.drl.spec_ref + * Generates and returns an {@code int} containing the specified number of + * random bits (right justified, with leading zeros). * + * @param numBits + * number of bits to be generated. An input value should be in + * the range [0, 32]. + * @return an {@code int} containing the specified number of random bits. + * @since Android 1.0 */ protected final int next(int numBits) { if (numBits < 0) { @@ -306,12 +330,13 @@ public class SecureRandom extends Random { } /** - * Returns the given number of seed bytes, computed using the seed - * generation algorithm used by this class. + * Generates and returns the specified number of seed bytes, computed using + * the seed generation algorithm used by this {@code SecureRandom}. * * @param numBytes - * int the given number of seed bytes - * @return byte[] The seed bytes generated + * the number of seed bytes. + * @return the seed bytes + * @since Android 1.0 */ public static byte[] getSeed(int numBytes) { if (internalSecureRandom == null) { @@ -321,12 +346,13 @@ public class SecureRandom extends Random { } /** - * Generates a certain number of seed bytes - * + * Generates and returns the specified number of seed bytes, computed using + * the seed generation algorithm used by this {@code SecureRandom}. * * @param numBytes - * int Number of seed bytes to generate - * @return byte[] The seed bytes generated + * the number of seed bytes. + * @return the seed bytes. + * @since Android 1.0 */ public byte[] generateSeed(int numBytes) { return secureRandomSpi.engineGenerateSeed(numBytes); diff --git a/security/src/main/java/java/security/SecureRandomSpi.java b/security/src/main/java/java/security/SecureRandomSpi.java index 1eb9c1a..7ce880c 100644 --- a/security/src/main/java/java/security/SecureRandomSpi.java +++ b/security/src/main/java/java/security/SecureRandomSpi.java @@ -25,33 +25,45 @@ package java.security; import java.io.Serializable; /** - * This class is a Service Provider Interface (therefore the Spi suffix) for - * secure random number generation algorithms to be supplied by providers. + * {@code SecureRandomSpi} is the <i>Service Provider Interface</i> (<b>SPI</b>) definition + * for {@link SecureRandom}. * + * @see SecureRandom + * @since Android 1.0 */ public abstract class SecureRandomSpi implements Serializable { - /** - * @com.intel.drl.spec_ref - * - */ private static final long serialVersionUID = -2991854161009191830L; /** - * @com.intel.drl.spec_ref + * Reseeds this {@code SecureRandomSpi} instance with the specified {@code + * seed}. The seed of this {@code SecureRandomSpi} instance is supplemented, + * not replaced. * + * @param seed + * the new seed. + * @since Android 1.0 */ protected abstract void engineSetSeed(byte[] seed); /** - * @com.intel.drl.spec_ref + * Generates and stores random bytes in the given {@code byte[]} for each + * array element. * + * @param bytes + * the {@code byte[]} to be filled with random bytes. + * @since Android 1.0 */ protected abstract void engineNextBytes(byte[] bytes); /** - * @com.intel.drl.spec_ref + * Generates and returns the specified number of seed bytes, computed using + * the seed generation algorithm used by this {@code SecureRandomSpi}. * + * @param numBytes + * the number of seed bytes. + * @return the seed bytes + * @since Android 1.0 */ protected abstract byte[] engineGenerateSeed(int numBytes); } diff --git a/security/src/main/java/java/security/Security.java b/security/src/main/java/java/security/Security.java index 28fd210..78abdb7 100644 --- a/security/src/main/java/java/security/Security.java +++ b/security/src/main/java/java/security/Security.java @@ -27,8 +27,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +// BEGIN android-added import java.util.logging.Level; import java.util.logging.Logger; +// END android-added import java.util.Enumeration; import java.net.URL; import java.util.HashMap; @@ -45,7 +47,11 @@ import org.apache.harmony.security.fortress.Services; import org.apache.harmony.security.internal.nls.Messages; /** - * For access to security providers and properties. + * {@code Security} is the central class in the Java Security API. It manages + * the list of security {@code Provider} that have been installed into this + * runtime environment. + * + * @since Android 1.0 */ public final class Security { @@ -81,55 +87,55 @@ public final class Security { // END android-added // BEGIN android-removed -// File f = new File(System.getProperty("java.home") //$NON-NLS-1$ -// + File.separator + "lib" + File.separator //$NON-NLS-1$ -// + "security" + File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$ -// if (f.exists()) { -// try { -// FileInputStream fis = new FileInputStream(f); -// InputStream is = new BufferedInputStream(fis); -// secprops.load(is); -// loaded = true; -// is.close(); -// } catch (IOException e) { -//// System.err.println("Could not load Security properties file: " -//// + e); -// } -// } -// -// if ("true".equalsIgnoreCase(secprops.getProperty("security.allowCustomPropertiesFile", "true"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ -// String securityFile = System.getProperty("java.security.properties"); //$NON-NLS-1$ -// if (securityFile != null) { -// if (securityFile.startsWith("=")) { // overwrite //$NON-NLS-1$ -// secprops = new Properties(); -// loaded = false; -// securityFile = securityFile.substring(1); -// } -// try { -// securityFile = PolicyUtils.expand(securityFile, System.getProperties()); -// } catch (PolicyUtils.ExpansionFailedException e) { -//// System.err.println("Could not load custom Security properties file " -//// + securityFile +": " + e); -// } -// f = new File(securityFile); -// InputStream is; -// try { -// if (f.exists()) { -// FileInputStream fis = new FileInputStream(f); -// is = new BufferedInputStream(fis); -// } else { -// URL url = new URL(securityFile); -// is = new BufferedInputStream(url.openStream()); -// } -// secprops.load(is); -// loaded = true; -// is.close(); -// } catch (IOException e) { -// // System.err.println("Could not load custom Security properties file " -// // + securityFile +": " + e); -// } -// } -// } + // File f = new File(System.getProperty("java.home") //$NON-NLS-1$ + // + File.separator + "lib" + File.separator //$NON-NLS-1$ + // + "security" + File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$ + // if (f.exists()) { + // try { + // FileInputStream fis = new FileInputStream(f); + // InputStream is = new BufferedInputStream(fis); + // secprops.load(is); + // loaded = true; + // is.close(); + // } catch (IOException e) { + //// System.err.println("Could not load Security properties file: " + //// + e); + // } + // } + // + // if ("true".equalsIgnoreCase(secprops.getProperty("security.allowCustomPropertiesFile", "true"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + // String securityFile = System.getProperty("java.security.properties"); //$NON-NLS-1$ + // if (securityFile != null) { + // if (securityFile.startsWith("=")) { // overwrite //$NON-NLS-1$ + // secprops = new Properties(); + // loaded = false; + // securityFile = securityFile.substring(1); + // } + // try { + // securityFile = PolicyUtils.expand(securityFile, System.getProperties()); + // } catch (PolicyUtils.ExpansionFailedException e) { + //// System.err.println("Could not load custom Security properties file " + //// + securityFile +": " + e); + // } + // f = new File(securityFile); + // InputStream is; + // try { + // if (f.exists()) { + // FileInputStream fis = new FileInputStream(f); + // is = new BufferedInputStream(fis); + // } else { + // URL url = new URL(securityFile); + // is = new BufferedInputStream(url.openStream()); + // } + // secprops.load(is); + // loaded = true; + // is.close(); + // } catch (IOException e) { + // // System.err.println("Could not load custom Security properties file " + // // + securityFile +": " + e); + // } + // } + // } // END android-removed if (!loaded) { @@ -155,14 +161,22 @@ public final class Security { secprops.put("security.provider.4", "org.bouncycastle.jce.provider.BouncyCastleProvider"); //$NON-NLS-1$ //$NON-NLS-2$ } + // BEGIN android-note + // added Deprecated annotation + // END android-note /** - * Deprecated method which returns null. - * @param algName - * @param propName - * @return <code>null</code> - * - * @deprecated Use AlgorithmParameters and KeyFactory instead + * Returns value for the specified algorithm with the specified name. + * + * @param algName + * the name of the algorithm. + * @param propName + * the name of the property. + * @return value of the property. + * @deprecated Use {@link AlgorithmParameters} and {@link KeyFactory} + * instead. + * @since Android 1.0 */ + @Deprecated public static String getAlgorithmProperty(String algName, String propName) { if (algName == null || propName == null) { return null; @@ -182,8 +196,27 @@ public final class Security { } /** - * @com.intel.drl.spec_ref - * + * Insert the given {@code Provider} at the specified {@code position}. The + * positions define the preference order in which providers are searched for + * requested algorithms. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code insertProvider.NAME} (where NAME is + * the provider name) to be granted, otherwise a {@code SecurityException} + * will be thrown. + * </p> + * + * @param provider + * the provider to insert. + * @param position + * the position (starting from 1). + * @return the actual position or {@code -1} if the given {@code provider} + * was already in the list. The actual position may be different + * from the desired position. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static synchronized int insertProviderAt(Provider provider, int position) { @@ -204,21 +237,50 @@ public final class Security { } /** - * Adds the extra provider to the collection of providers. - * @param provider + * Adds the given {@code provider} to the collection of providers at the + * next available position. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code insertProvider.NAME} (where NAME is + * the provider name) to be granted, otherwise a {@code SecurityException} + * will be thrown. + * </p> * - * @return int The priority/position of the provider added. - * @exception SecurityException - * If there is a SecurityManager installed and it denies - * adding a new provider. + * @param provider + * the provider to be added. + * @return the actual position or {@code -1} if the given {@code provider} + * was already in the list. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static int addProvider(Provider provider) { return insertProviderAt(provider, 0); } /** - * @com.intel.drl.spec_ref - * + * Removes the {@code Provider} with the specified name form the collection + * of providers. If the the {@code Provider} with the specified name is + * removed, all provider at a greater position are shifted down one + * position. + * <p> + * Returns silently if {@code name} is {@code null} or no provider with the + * specified name is installed. + * </p> + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code removeProvider.NAME} (where NAME is + * the provider name) to be granted, otherwise a {@code SecurityException} + * will be thrown. + * </p> + * + * @param name + * the name of the provider to remove. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static synchronized void removeProvider(String name) { // It is not clear from spec.: @@ -245,33 +307,53 @@ public final class Security { } /** - * @com.intel.drl.spec_ref - * + * Returns an array containing all installed providers. The providers are + * ordered according their preference order. + * + * @return an array containing all installed providers. + * @since Android 1.0 */ public static synchronized Provider[] getProviders() { return Services.getProviders(); } /** - * @com.intel.drl.spec_ref - * + * Returns the {@code Provider} with the specified name. Returns {@code + * null} if name is {@code null} or no provider with the specified name is + * installed. + * + * @param name + * the name of the requested provider. + * @return the provider with the specified name, maybe {@code null}. + * @since Android 1.0 */ public static synchronized Provider getProvider(String name) { return Services.getProvider(name); } /** - * Returns the collection of providers which meet the user supplied string - * filter. + * Returns the array of providers which meet the user supplied string + * filter. The specified filter must be supplied in one of two formats: + * <nl> + * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE + * <p> + * (for example: "MessageDigest.SHA") + * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE + * ATTR_NAME:ATTR_VALUE + * <p> + * (for example: "Signature.MD2withRSA KeySize:512") + * </nl> * * @param filter - * case-insensitive filter - * @return the providers which meet the user supplied string filter - * <code>filter</code>. A <code>null</code> value signifies - * that none of the installed providers meets the filter - * specification - * @exception InvalidParameterException - * if an unusable filter is supplied + * case-insensitive filter. + * @return the providers which meet the user supplied string filter {@code + * filter}. A {@code null} value signifies that none of the + * installed providers meets the filter specification. + * @throws InvalidParameterException + * if an unusable filter is supplied. + * @throws NullPointerException + * if {@code filter} is {@code null}. + * @since Android 1.0 */ public static Provider[] getProviders(String filter) { if (filter == null) { @@ -296,8 +378,29 @@ public final class Security { } /** - * @com.intel.drl.spec_ref - * + * Returns the array of providers which meet the user supplied set of + * filters. The filter must be supplied in one of two formats: + * <nl> + * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE + * <p> + * for example: "MessageDigest.SHA" The value associated with the key must + * be an empty string. <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE + * ATTR_NAME:ATTR_VALUE + * <p> + * for example: "Signature.MD2withRSA KeySize:512" where "KeySize:512" is + * the value of the filter map entry. + * </nl> + * + * @param filter + * case-insensitive filter. + * @return the providers which meet the user supplied string filter {@code + * filter}. A {@code null} value signifies that none of the + * installed providers meets the filter specification. + * @throws InvalidParameterException + * if an unusable filter is supplied. + * @throws NullPointerException + * if {@code filter} is {@code null}. + * @since Android 1.0 */ public static synchronized Provider[] getProviders(Map<String,String> filter) { if (filter == null) { @@ -365,16 +468,20 @@ public final class Security { /** * Returns the value of the security property named by the argument. - * + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code getProperty.KEY} (where KEY is the + * specified {@code key}) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * </p> * * @param key - * String The property name - * @return String The property value - * - * @exception SecurityException - * If there is a SecurityManager installed and it will not - * allow the property to be fetched from the current access - * control context. + * the name of the requested security property. + * @return the value of the security property. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static String getProperty(String key) { if (key == null) { @@ -388,17 +495,22 @@ public final class Security { } /** - * Sets a given security property. - * + * Sets the value of the specified security property. + * <p> + * If a {@code SecurityManager} is installed, code calling this method needs + * the {@code SecurityPermission} {@code setProperty.KEY} (where KEY is the + * specified {@code key}) to be granted, otherwise a {@code + * SecurityException} will be thrown. + * </p> * * @param key - * String The property name. + * the name of the security property. * @param datnum - * String The property value. - * @exception SecurityException - * If there is a SecurityManager installed and it will not - * allow the property to be set from the current access - * control context. + * the value of the security property. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public static void setProperty(String key, String datnum) { SecurityManager sm = System.getSecurityManager(); @@ -409,8 +521,17 @@ public final class Security { } /** - * @com.intel.drl.spec_ref - * + * Returns a {@code Set} of all registered algorithms for the specified + * cryptographic service. {@code "Signature"}, {@code "Cipher"} and {@code + * "KeyStore"} are examples for such kind of services. + * + * @param serviceName + * the case-insensitive name of the service. + * @return a {@code Set} of all registered algorithms for the specified + * cryptographic service, or an empty {@code Set} if {@code + * serviceName} is {@code null} or if no registered provider + * provides the requested service. + * @since Android 1.0 */ public static Set<String> getAlgorithms(String serviceName) { Set<String> result = new HashSet<String>(); @@ -428,7 +549,7 @@ public final class Security { /** * - * Update sequence numbers of all providers + * Update sequence numbers of all providers. * */ private static void renumProviders() { diff --git a/security/src/main/java/java/security/SecurityPermission.java b/security/src/main/java/java/security/SecurityPermission.java index f331b18..87f3aaa 100644 --- a/security/src/main/java/java/security/SecurityPermission.java +++ b/security/src/main/java/java/security/SecurityPermission.java @@ -23,35 +23,37 @@ package java.security; /** - * SecurityPermission objects guard access to the mechanisms which implement - * security. Security permissions have names, but not actions. + * {@code SecurityPermission} objects guard access to the mechanisms which + * implement security. Security permissions have names, but not actions. * + * @since Android 1.0 */ public final class SecurityPermission extends BasicPermission { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 5236109936224050470L; /** - * Creates an instance of this class with the given name. + * Constructs a new instance of {@code SecurityPermission} with the given + * name. * * @param name - * String the name of the new permission. + * the name of the permission. + * @since Android 1.0 */ public SecurityPermission(String name) { super(name); } /** - * Creates an instance of this class with the given name and action list. - * The action list is ignored. + * Constructs a new instance of {@code SecurityPermission} with the given + * {@code name} and {@code action} list. The action list is ignored - it is + * existing for compatibility reasons only. * * @param name - * String the name of the new permission. + * the name of the permission. * @param action - * String ignored. + * ignored. + * @since Android 1.0 */ public SecurityPermission(String name, String action) { super(name, action); diff --git a/security/src/main/java/java/security/Signature.java b/security/src/main/java/java/security/Signature.java index 0711d8f..e5d488e 100644 --- a/security/src/main/java/java/security/Signature.java +++ b/security/src/main/java/java/security/Signature.java @@ -34,10 +34,13 @@ import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code Signature} is an engine class which is capable of creating and + * verifying digital signatures, using different algorithms that have been + * registered with the {@link Security} class. * + * @see SignatureSpi + * @since Android 1.0 */ - public abstract class Signature extends SignatureSpi { // The service name. @@ -53,40 +56,63 @@ public abstract class Signature extends SignatureSpi { private String algorithm; /** - * @com.intel.drl.spec_ref - * + * Constant that indicates that this {@code Signature} instance has not yet + * been initialized. + * + * @since Android 1.0 */ protected static final int UNINITIALIZED = 0; /** - * @com.intel.drl.spec_ref - * + * Constant that indicates that this {@code Signature} instance has been + * initialized for signing. + * + * @since Android 1.0 */ protected static final int SIGN = 2; /** - * @com.intel.drl.spec_ref - * + * Constant that indicates that this {@code Signature} instance has been + * initialized for verification. + * + * @since Android 1.0 */ protected static final int VERIFY = 3; /** - * @com.intel.drl.spec_ref - * + * Represents the current state of this {@code Signature}. The three + * possible states are {@link #UNINITIALIZED}, {@link #SIGN} or + * {@link #VERIFY}. + * + * @since Android 1.0 */ protected int state = UNINITIALIZED; /** - * @com.intel.drl.spec_ref - * + * Constructs a new instance of {@code Signature} with the name of + * the algorithm to use. + * + * @param algorithm + * the name of algorithm to use. + * @since Android 1.0 */ protected Signature(String algorithm) { this.algorithm = algorithm; } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code Signature} that utilizes the specified + * algorithm. + * + * @param algorithm + * the name of the algorithm to use. + * @return a new instance of {@code Signature} that utilizes the specified + * algorithm. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static Signature getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -109,8 +135,22 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code Signature} that utilizes the specified + * algorithm from the specified provider. + * + * @param algorithm + * the name of the algorithm to use. + * @param provider + * the name of the provider. + * @return a new instance of {@code Signature} that utilizes the specified + * algorithm from the specified provider. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NoSuchProviderException + * if the specified provider is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static Signature getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -129,8 +169,20 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns a new instance of {@code Signature} that utilizes the specified + * algorithm from the specified provider. + * + * @param algorithm + * the name of the algorithm to use. + * @param provider + * the security provider. + * @return a new instance of {@code Signature} that utilizes the specified + * algorithm from the specified provider. + * @throws NoSuchAlgorithmException + * if the specified algorithm is not available. + * @throws NullPointerException + * if {@code algorithm} is {@code null}. + * @since Android 1.0 */ public static Signature getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -161,24 +213,35 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns the provider associated with this {@code Signature}. + * + * @return the provider associated with this {@code Signature}. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref - * + * Returns the name of the algorithm of this {@code Signature}. + * + * @return the name of the algorithm of this {@code Signature}. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code Signature} instance for signature verification, + * using the public key of the identity whose signature is going to be + * verified. + * + * @param publicKey + * the public key. + * @throws InvalidKeyException + * if {@code publicKey} is not valid. + * @since Android 1.0 */ public final void initVerify(PublicKey publicKey) throws InvalidKeyException { @@ -187,8 +250,21 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code Signature} instance for signature verification, + * using the certificate of the identity whose signature is going to be + * verified. + * <p> + * If the given certificate is an instance of {@link X509Certificate} and + * has a key usage parameter that indicates, that this certificate is not to + * be used for signing, an {@code InvalidKeyException} is thrown. + * </p> + * + * @param certificate + * the certificate used to verify a signature. + * @throws InvalidKeyException + * if the publicKey in the certificate is not valid or not to be + * used for signing. + * @since Android 1.0 */ public final void initVerify(Certificate certificate) throws InvalidKeyException { @@ -224,8 +300,14 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code Signature} instance for signing, using the + * private key of the identity whose signature is going to be generated. + * + * @param privateKey + * the private key. + * @throws InvalidKeyException + * if {@code privateKey} is not valid. + * @since Android 1.0 */ public final void initSign(PrivateKey privateKey) throws InvalidKeyException { @@ -234,8 +316,17 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code Signature} instance for signing, using the + * private key of the identity whose signature is going to be generated and + * the specified source of randomness. + * + * @param privateKey + * the private key. + * @param random + * the {@code SecureRandom} to use. + * @throws InvalidKeyException + * if {@code privateKey} is not valid. + * @since Android 1.0 */ public final void initSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { @@ -244,8 +335,18 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Generates and returns the signature of all updated data. + * <p> + * This {@code Signature} instance is reset to the state of its last + * initialization for signing and thus can be used for another signature + * from the same identity. + * </p> + * + * @return the signature of all updated data. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @since Android 1.0 */ public final byte[] sign() throws SignatureException { if (state != SIGN) { @@ -256,8 +357,28 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Generates and stores the signature of all updated data in the provided + * {@code byte[]} at the specified position with the specified length. + * <p> + * This {@code Signature} instance is reset to the state of its last + * initialization for signing and thus can be used for another signature + * from the same identity. + * </p> + * + * @param outbuf + * the buffer to store the signature. + * @param offset + * the index of the first byte in {@code outbuf} to store. + * @param len + * the number of bytes allocated for the signature. + * @return the number of bytes stored in {@code outbuf}. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @throws IllegalArgumentException + * if {@code offset} or {@code len} are not valid in respect to + * {@code outbuf}. + * @since Android 1.0 */ public final int sign(byte[] outbuf, int offset, int len) throws SignatureException { @@ -274,8 +395,22 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Indicates whether the given {@code signature} can be verified using the + * public key or a certificate of the signer. + * <p> + * This {@code Signature} instance is reset to the state of its last + * initialization for verifying and thus can be used to verify another + * signature of the same signer. + * </p> + * + * @param signature + * the signature to verify. + * @return {@code true} if the signature was verified, {@code false} + * otherwise. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @since Android 1.0 */ public final boolean verify(byte[] signature) throws SignatureException { if (state != VERIFY) { @@ -286,8 +421,30 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Indicates whether the given {@code signature} starting at index {@code + * offset} with {@code length} bytes can be verified using the public key or + * a certificate of the signer. + * <p> + * This {@code Signature} instance is reset to the state of its last + * initialization for verifying and thus can be used to verify another + * signature of the same signer. + * </p> + * + * @param signature + * the {@code byte[]} containing the signature to verify. + * @param offset + * the start index in {@code signature} of the signature. + * @param length + * the number of bytes allocated for the signature. + * @return {@code true} if the signature was verified, {@code false} + * otherwise. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @throws IllegalArgumentException + * if {@code offset} or {@code length} are not valid in respect + * to {@code signature}. + * @since Android 1.0 */ public final boolean verify(byte[] signature, int offset, int length) throws SignatureException { @@ -304,8 +461,15 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates the data to be verified or to be signed, using the specified + * {@code byte}. + * + * @param b + * the byte to update with. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @since Android 1.0 */ public final void update(byte b) throws SignatureException { if (state == UNINITIALIZED) { @@ -316,8 +480,15 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates the data to be verified or to be signed, using the specified + * {@code byte[]}. + * + * @param data + * the byte array to update with. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @since Android 1.0 */ public final void update(byte[] data) throws SignatureException { if (state == UNINITIALIZED) { @@ -328,8 +499,19 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates the data to be verified or to be signed, using the given {@code + * byte[]}, starting form the specified index for the specified length. + * + * @param data + * the byte array to update with. + * @param off + * the start index in {@code data} of the data. + * @param len + * the number of bytes to use. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @since Android 1.0 */ public final void update(byte[] data, int off, int len) throws SignatureException { @@ -346,8 +528,15 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates the data to be verified or to be signed, using the specified + * {@code ByteBuffer}. + * + * @param data + * the {@code ByteBuffer} to update with. + * @throws SignatureException + * if this {@code Signature} instance is not initialized + * properly. + * @since Android 1.0 */ public final void update(ByteBuffer data) throws SignatureException { if (state == UNINITIALIZED) { @@ -358,8 +547,11 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns a string containing a concise, human-readable description of this + * {@code Signature} including its algorithm and its state. + * + * @return a printable representation for this {@code Signature}. + * @since Android 1.0 */ public String toString() { return "SIGNATURE " + algorithm + " state: " + stateToString(state); //$NON-NLS-1$ //$NON-NLS-2$ @@ -379,19 +571,37 @@ public abstract class Signature extends SignatureSpi { } } + // BEGIN android-note + // added Deprecated annotation + // END android-note /** - * @com.intel.drl.spec_ref - * - * @deprecated Use {@link Signature#setParameter(AlgorithmParameterSpec) setParameter} + * Sets the specified parameter to the given value. + * + * @param param + * the name of the parameter. + * @param value + * the parameter value. + * @throws InvalidParameterException + * if the parameter is invalid, already set or is not allowed to + * be changed. + * @deprecated Use {@link #setParameter(AlgorithmParameterSpec)} + * @since Android 1.0 */ + @Deprecated public final void setParameter(String param, Object value) throws InvalidParameterException { engineSetParameter(param, value); } /** - * @com.intel.drl.spec_ref - * + * Sets the specified {@code AlgorithmParameterSpec}. + * + * @param params + * the parameter to set. + * @throws InvalidAlgorithmParameterException + * if the parameter is invalid, already set or is not allowed to + * be changed. + * @since Android 1.0 */ public final void setParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException { @@ -399,27 +609,39 @@ public abstract class Signature extends SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns the {@code AlgorithmParameters} of this {@link Signature} + * instance. + * + * @return the {@code AlgorithmParameters} of this {@link Signature} + * instance, maybe {@code null}. + * @since Android 1.0 */ public final AlgorithmParameters getParameters() { return engineGetParameters(); } + // BEGIN android-note + // added Deprecated annotation + // END android-note /** - * @com.intel.drl.spec_ref + * Returns the value of the parameter with the specified name. * + * @param param + * the name of the requested parameter value + * @return the value of the parameter with the specified name, maybe {@code + * null}. + * @throws InvalidParameterException + * if {@code param} is not a valid parameter for this {@code + * Signature} or an other error occures. * @deprecated There is no generally accepted parameter naming convention. + * @since Android 1.0 */ + @Deprecated public final Object getParameter(String param) throws InvalidParameterException { return engineGetParameter(param); } - /** - * @com.intel.drl.spec_ref - * - */ public Object clone() throws CloneNotSupportedException { if (this instanceof Cloneable) { return super.clone(); @@ -500,4 +722,4 @@ public abstract class Signature extends SignatureSpi { } } } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/SignatureException.java b/security/src/main/java/java/security/SignatureException.java index 1b67037..f07c34b 100644 --- a/security/src/main/java/java/security/SignatureException.java +++ b/security/src/main/java/java/security/SignatureException.java @@ -23,43 +23,56 @@ package java.security; /** - * This class represents generic security exceptions. + *{@code SignatureException} is a general {@code Signature} exception. * + * @see Signature + * @since Android 1.0 */ public class SignatureException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 7509989324975124438L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code SignatureException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public SignatureException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code SignatureException}. * + * @since Android 1.0 */ public SignatureException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code SignatureException} with the + * given message and the cause. + * + * @param message + * the detail message for this exception + * @param cause + * the exception which is the cause for this exception + * @since Android 1.0 */ public SignatureException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code SignatureException} with the + * cause. + * + * @param cause + * the exception which is the cause for this exception + * @since Android 1.0 */ public SignatureException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/SignatureSpi.java b/security/src/main/java/java/security/SignatureSpi.java index f4623b6..738d489 100644 --- a/security/src/main/java/java/security/SignatureSpi.java +++ b/security/src/main/java/java/security/SignatureSpi.java @@ -27,35 +27,60 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code SignatureSpi} is the <i>Service Provider Interface</i> (<b>SPI</b>) + * definition for {@link Signature}. * + * @see Signature + * @since Android 1.0 */ - public abstract class SignatureSpi { /** - * @com.intel.drl.spec_ref - * + * Implementation specific source of randomness. + * + * @since Android 1.0 */ protected SecureRandom appRandom; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code SignatureSpi} instance for signature + * verification, using the public key of the identity whose signature is + * going to be verified. + * + * @param publicKey + * the public key. + * @throws InvalidKeyException + * if {@code publicKey} is not valid. + * @since Android 1.0 */ protected abstract void engineInitVerify(PublicKey publicKey) throws InvalidKeyException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code SignatureSpi} instance for signing, using the + * private key of the identity whose signature is going to be generated. + * + * @param privateKey + * the private key. + * @throws InvalidKeyException + * if {@code privateKey} is not valid. + * @since Android 1.0 */ protected abstract void engineInitSign(PrivateKey privateKey) throws InvalidKeyException; /** - * @com.intel.drl.spec_ref - * + * Initializes this {@code SignatureSpi} instance for signing, using the + * private key of the identity whose signature is going to be generated and + * the specified source of randomness. + * + * @param privateKey + * the private key. + * @param random + * the {@code SecureRandom} to use. + * @throws InvalidKeyException + * if {@code privateKey} is not valid. + * @since Android 1.0 */ protected void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { @@ -64,24 +89,48 @@ public abstract class SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Updates the data to be verified or to be signed, using the specified + * {@code byte}. + * + * @param b + * the byte to update with. + * @throws SignatureException + * if this {@code SignatureSpi} instance is not initialized + * properly. + * @since Android 1.0 */ protected abstract void engineUpdate(byte b) throws SignatureException; /** - * @com.intel.drl.spec_ref - * + * Updates the data to be verified or to be signed, using the given {@code + * byte[]}, starting form the specified index for the specified length. + * + * @param b + * the byte array to update with. + * @param off + * the start index in {@code b} of the data. + * @param len + * the number of bytes to use. + * @throws SignatureException + * if this {@code SignatureSpi} instance is not initialized + * properly. + * @since Android 1.0 */ protected abstract void engineUpdate(byte[] b, int off, int len) throws SignatureException; /** - * @com.intel.drl.spec_ref + * Updates the data to be verified or to be signed, using the specified + * {@code ByteBuffer}. * - * The SignatureException is not specified for this method. - * So throw RuntimeException if underlying engineUpdate(byte[] b, int off, int len) - * throws SignatureException. + * @param input + * the {@code ByteBuffer} to update with. + * @throws RuntimeException + * since {@code SignatureException} is not specified for this + * method it throws a {@code RuntimeException} if underlying + * {@link #engineUpdate(byte[], int, int)} throws {@code + * SignatureException}. + * @since Android 1.0 */ protected void engineUpdate(ByteBuffer input) { if (!input.hasRemaining()) { @@ -111,14 +160,44 @@ public abstract class SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Generates and returns the signature of all updated data. + * <p> + * This {@code SignatureSpi} instance is reset to the state of its last + * initialization for signing and thus can be used for another signature + * from the same identity. + * </p> + * + * @return the signature of all updated data. + * @throws SignatureException + * if this {@code SignatureSpi} instance is not initialized + * properly. + * @since Android 1.0 */ protected abstract byte[] engineSign() throws SignatureException; /** - * @com.intel.drl.spec_ref - * + * Generates and stores the signature of all updated data in the provided + * {@code byte[]} at the specified position with the specified length. + * <p> + * This {@code SignatureSpi} instance is reset to the state of its last + * initialization for signing and thus can be used for another signature + * from the same identity. + * </p> + * + * @param outbuf + * the buffer to store the signature. + * @param offset + * the index of the first byte in {@code outbuf} to store. + * @param len + * the number of bytes allocated for the signature. + * @return the number of bytes stored in {@code outbuf}. + * @throws SignatureException + * if this {@code SignatureSpi} instance is not initialized + * properly. + * @throws IllegalArgumentException + * if {@code offset} or {@code len} are not valid in respect to + * {@code outbuf}. + * @since Android 1.0 */ protected int engineSign(byte[] outbuf, int offset, int len) throws SignatureException { @@ -140,15 +219,51 @@ public abstract class SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Indicates whether the given {@code sigBytes} can be verified using the + * public key or a certificate of the signer. + * <p> + * This {@code SignatureSpi} instance is reset to the state of its last + * initialization for verifying and thus can be used to verify another + * signature of the same signer. + * </p> + * + * @param sigBytes + * the signature to verify. + * @return {@code true} if the signature was verified, {@code false} + * otherwise. + * @throws SignatureException + * if this {@code SignatureSpi} instance is not initialized + * properly. + * @since Android 1.0 */ protected abstract boolean engineVerify(byte[] sigBytes) throws SignatureException; /** - * @com.intel.drl.spec_ref - * + * Indicates whether the given {@code sigBytes} starting at index {@code + * offset} with {@code length} bytes can be verified using the public key or + * a certificate of the signer. + * <p> + * This {@code SignatureSpi} instance is reset to the state of its last + * initialization for verifying and thus can be used to verify another + * signature of the same signer. + * </p> + * + * @param sigBytes + * the {@code byte[]} containing the signature to verify. + * @param offset + * the start index in {@code sigBytes} of the signature + * @param length + * the number of bytes allocated for the signature. + * @return {@code true} if the signature was verified, {@code false} + * otherwise. + * @throws SignatureException + * if this {@code SignatureSpi} instance is not initialized + * properly. + * @throws IllegalArgumentException + * if {@code offset} or {@code length} are not valid in respect + * to {@code sigBytes}. + * @since Android 1.0 */ protected boolean engineVerify(byte[] sigBytes, int offset, int length) throws SignatureException { @@ -158,17 +273,31 @@ public abstract class SignatureSpi { } /** - * @com.intel.drl.spec_ref + * Sets the specified parameter to the given value. * - * @deprecated Use - * {@link SignatureSpi#engineSetParameter(AlgorithmParameterSpec) engineSetParameter} + * @param param + * the name of the parameter. + * @param value + * the parameter value. + * @throws InvalidParameterException + * if the parameter is invalid, already set or is not allowed to + * be changed. + * @deprecated Use {@link #engineSetParameter(AlgorithmParameterSpec)} + * @since Android 1.0 */ + @Deprecated protected abstract void engineSetParameter(String param, Object value) throws InvalidParameterException; /** - * @com.intel.drl.spec_ref - * + * Sets the specified {@code AlgorithmParameterSpec}. + * + * @param params + * the parameter to set. + * @throws InvalidAlgorithmParameterException + * if the parameter is invalid, already set or is not allowed to + * be changed. + * @since Android 1.0 */ protected void engineSetParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException { @@ -176,25 +305,37 @@ public abstract class SignatureSpi { } /** - * @com.intel.drl.spec_ref - * + * Returns the {@code AlgorithmParameters} of this {@link SignatureSpi} + * instance. + * + * @return the {@code AlgorithmParameters} of this {@link SignatureSpi} + * instance, maybe {@code null}. + * @since Android 1.0 */ protected AlgorithmParameters engineGetParameters() { throw new UnsupportedOperationException(); } + // BEGIN android-note + // added Deprecated annotation + // END android-note /** - * @com.intel.drl.spec_ref + * Returns the value of the parameter with the specified name. * + * @param param + * the name of the requested parameter value. + * @return the value of the parameter with the specified name, maybe {@code + * null}. + * @throws InvalidParameterException + * if {@code param} is not a valid parameter for this {@code + * SignatureSpi} or an other error occurs. * @deprecated There is no generally accepted parameter naming convention. + * @since Android 1.0 */ + @Deprecated protected abstract Object engineGetParameter(String param) throws InvalidParameterException; - /** - * @com.intel.drl.spec_ref - * - */ public Object clone() throws CloneNotSupportedException { if (this instanceof Cloneable) { return super.clone(); @@ -202,4 +343,4 @@ public abstract class SignatureSpi { throw new CloneNotSupportedException(); } } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/SignedObject.java b/security/src/main/java/java/security/SignedObject.java index 21f4547..d2022c8 100644 --- a/security/src/main/java/java/security/SignedObject.java +++ b/security/src/main/java/java/security/SignedObject.java @@ -30,35 +30,22 @@ import java.io.ObjectOutputStream; import java.io.Serializable; /** - * @com.intel.drl.spec_ref + * A {@code SignedObject} instance acts as a container for another object. The + * {@code SignedObject} contains the target in serialized form along with a + * digital signature of the serialized data. * + * @since Android 1.0 */ public final class SignedObject implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 720502720485447167L; - /** - * @com.intel.drl.spec_ref - */ private byte[] content; - /** - * @com.intel.drl.spec_ref - */ private byte[] signature; - /** - * @com.intel.drl.spec_ref - */ private String thealgorithm; - /** - * @com.intel.drl.spec_ref - * - */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { @@ -72,8 +59,23 @@ public final class SignedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code SignedObject} with the target object, + * the private key and the engine to compute the signature. The given + * {@code object} is signed with the specified key and engine. * + * @param object + * the object to bes signed. + * @param signingKey + * the private key, used to sign the {@code object}. + * @param signingEngine + * the engine that performs the signature generation. + * @throws IOException + * if a serialization error occurs. + * @throws InvalidKeyException + * if the private key is not valid. + * @throws SignatureException + * if signature generation failed. + * @since Android 1.0 */ public SignedObject(Serializable object, PrivateKey signingKey, Signature signingEngine) throws IOException, InvalidKeyException, @@ -96,8 +98,15 @@ public final class SignedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the encapsulated object. Each time this method is invoked, the + * encapsulated object is deserialized before it is returned. * + * @return the encapsulated object. + * @throws IOException + * if deserialization failed. + * @throws ClassNotFoundException + * if the class of the encapsulated object can not be found. + * @since Android 1.0 */ public Object getObject() throws IOException, ClassNotFoundException { // deserialize our object @@ -111,8 +120,10 @@ public final class SignedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the signature data of the encapsulated serialized object. * + * @return the signature data of the encapsulated serialized object. + * @since Android 1.0 */ public byte[] getSignature() { byte[] sig = new byte[signature.length]; @@ -121,16 +132,30 @@ public final class SignedObject implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the name of the algorithm of this {@code SignedObject}. * + * @return the name of the algorithm of this {@code SignedObject}. + * @since Android 1.0 */ public String getAlgorithm() { return thealgorithm; } /** - * @com.intel.drl.spec_ref + * Indicates whether the contained signature for the encapsulated object is + * valid. * + * @param verificationKey + * the public key to verify the signature. + * @param verificationEngine + * the signature engine. + * @return {@code true} if the contained signature for the encapsulated + * object is valid, {@code false} otherwise. + * @throws InvalidKeyException + * if the public key is invalid. + * @throws SignatureException + * if signature verification failed. + * @since Android 1.0 */ public boolean verify(PublicKey verificationKey, Signature verificationEngine) throws InvalidKeyException, diff --git a/security/src/main/java/java/security/Signer.java b/security/src/main/java/java/security/Signer.java index 972c46e..9e48226 100644 --- a/security/src/main/java/java/security/Signer.java +++ b/security/src/main/java/java/security/Signer.java @@ -22,42 +22,57 @@ package java.security; +// BEGIN android-note +// added Deprecated annotation +// END android-note /** - * @com.intel.drl.spec_ref + * {@link Signer} represents an identity (individual or corporation) that owns a + * private key and the corresponding public key. * - * @deprecated Replaced by behavior in - * {@link java.security.cert java.security.cert} package and - * {@link java.security.Principal Principal} + * @deprecated Replaced by behavior in {@link java.security.cert + * java.security.cert} package and {@link java.security.Principal + * Principal} + * @since Android 1.0 */ - +@Deprecated public abstract class Signer extends Identity { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -1763464102261361480L; - /** - * @com.intel.drl.spec_ref - */ private PrivateKey privateKey; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code Signer}. + * + * @since Android 1.0 */ protected Signer() { super(); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code Signer} with the given name. + * + * @param name + * the name of the signer. + * @since Android 1.0 */ public Signer(String name) { super(name); } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code Signer} with the given name in the + * given scope. + * + * @param name + * the name of the signer. + * @param scope + * the scope of the signer. + * @throws KeyManagementException + * if a signer with the specified name already exists in the + * provided scope. + * @since Android 1.0 */ public Signer(String name, IdentityScope scope) throws KeyManagementException { @@ -65,7 +80,16 @@ public abstract class Signer extends Identity { } /** - * @com.intel.drl.spec_ref + * Returns the private key of this {@code Signer}. If a {@code + * SecurityManager} is installed, code calling this method needs the {@code + * SecurityPermission} {@code "getSignerPrivateKey"} to be granted, otherwise + * a {@code SecurityException} will be thrown. + * + * @return the private key of this {@code Signer}. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public PrivateKey getPrivateKey() { SecurityManager sm = System.getSecurityManager(); @@ -77,7 +101,21 @@ public abstract class Signer extends Identity { } /** - * @com.intel.drl.spec_ref + * Associates the specified key pair with this {@code Signer}. If a {@code + * SecurityManager} is installed, code calling this method needs the {@code + * SecurityPermission} {@code getSignerPrivateKey} to be granted, otherwise + * a {@code SecurityException} will be thrown. + * + * @param pair + * the key pair to associate with this {@code Signer}. + * @throws InvalidParameterException + * if the key pair is invalid. + * @throws KeyException + * if any other key related problem occurs. + * @throws SecurityException + * if a {@code SecurityManager} is installed and the caller does + * not have permission to invoke this method. + * @since Android 1.0 */ public final void setKeyPair(KeyPair pair) throws InvalidParameterException, KeyException { @@ -108,7 +146,11 @@ public abstract class Signer extends Identity { } /** - * @com.intel.drl.spec_ref + * Returns a string containing a concise, human-readable description of this + * {@code Signer} including its name and its scope if present. + * + * @return a printable representation for this {@code Signer}. + * @since Android 1.0 */ public String toString() { String s = "[Signer]" + getName(); //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/Timestamp.java b/security/src/main/java/java/security/Timestamp.java index b43441e..7d371b5 100644 --- a/security/src/main/java/java/security/Timestamp.java +++ b/security/src/main/java/java/security/Timestamp.java @@ -29,14 +29,13 @@ import java.security.cert.CertPath; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * {@code Timestamp} represents a signed time stamp. {@code Timestamp} is + * immutable. + * + * @since Android 1.0 */ - public final class Timestamp implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -5502683707821851294L; private Date timestamp; @@ -47,7 +46,17 @@ public final class Timestamp implements Serializable { private transient int hash; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code Timestamp} with the specified {@code + * timestamp} and the given certificate path. + * + * @param timestamp + * date and time. + * @param signerCertPath + * the certificate path. + * @throws NullPointerException + * if {@code timestamp} is {@code null} or if {@code + * signerCertPath} is {@code null}. + * @since Android 1.0 */ public Timestamp(Date timestamp, CertPath signerCertPath) { if (timestamp == null) { @@ -62,7 +71,19 @@ public final class Timestamp implements Serializable { } /** - * @com.intel.drl.spec_ref + * Compares the specified object with this {@code Timestamp} for equality + * and returns {@code true} if the specified object is equal, {@code false} + * otherwise. The given object is equal to this {@code Timestamp}, if it is + * an instance of {@code Timestamp}, the two timestamps have an equal date + * and time and their certificate paths are equal. + * + * @param obj + * object to be compared for equality with this {@code + * Timestamp}. + * @return {@code true} if the specified object is equal to this {@code + * Timestamp}, otherwise {@code false}. + * @see #hashCode + * @since Android 1.0 */ public boolean equals(Object obj) { if (obj == this) { @@ -77,21 +98,34 @@ public final class Timestamp implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns the certificate path of this {@code Timestamp}. + * + * @return the certificate path of this {@code Timestamp}. + * @since Android 1.0 */ public CertPath getSignerCertPath() { return signerCertPath; } /** - * @com.intel.drl.spec_ref + * Returns the date and time of this {@code Timestamp}. + * + * @return the date and time of this {@code Timestamp}. + * @since Android 1.0 */ public Date getTimestamp() { return timestamp; } /** - * @com.intel.drl.spec_ref + * Returns the hash code value for this {@code Timestamp}. Returns the same + * hash code for {@code Timestamp}s that are equal to each other as + * required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this {@code Timestamp}. + * @see Object#equals(Object) + * @see Timestamp#equals(Object) + * @since Android 1.0 */ public int hashCode() { if (hash == 0) { @@ -101,7 +135,11 @@ public final class Timestamp implements Serializable { } /** - * @com.intel.drl.spec_ref + * Returns a string containing a concise, human-readable description of this + * {@code Timestamp}. + * + * @return a printable representation for this {@code Timestamp}. + * @since Android 1.0 */ public String toString() { StringBuffer buf = new StringBuffer(256); diff --git a/security/src/main/java/java/security/UnrecoverableEntryException.java b/security/src/main/java/java/security/UnrecoverableEntryException.java index 3c7d864..dc2981a 100644 --- a/security/src/main/java/java/security/UnrecoverableEntryException.java +++ b/security/src/main/java/java/security/UnrecoverableEntryException.java @@ -22,25 +22,34 @@ package java.security; + /** - * @com.intel.drl.spec_ref + * {@code UnrecoverableEntryException} indicates, that a {@code KeyStore.Entry} + * cannot be recovered from a {@code KeyStore}. * + * @see KeyStore + * @see KeyStore.Entry + * @since Android 1.0 */ - public class UnrecoverableEntryException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -4527142945246286535L; /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code UnrecoverableEntryException}. + * + * @since Android 1.0 */ public UnrecoverableEntryException() { } /** - * @com.intel.drl.spec_ref + * Constructs a new instance of {@code UnrecoverableEntryException} with the + * given message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public UnrecoverableEntryException(String msg) { super(msg); diff --git a/security/src/main/java/java/security/UnrecoverableKeyException.java b/security/src/main/java/java/security/UnrecoverableKeyException.java index 2716e5e..e4b399b 100644 --- a/security/src/main/java/java/security/UnrecoverableKeyException.java +++ b/security/src/main/java/java/security/UnrecoverableKeyException.java @@ -23,31 +23,32 @@ package java.security; /** - * This class represents exceptions if a key cannot be found in the keystore. + * {@code UnrecoverableKeyException} indicates, that a key cannot be recovered + * from a {@code KeyStore}. * + * @see KeyStore + * @since Android 1.0 */ public class UnrecoverableKeyException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 7275063078190151277L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. - * + * Constructs a new instance of {@code UnrecoverableKeyException} with the + * given message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception + * @since Android 1.0 */ public UnrecoverableKeyException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Constructs a new instance of {@code UnrecoverableKeyException}. * + * @since Android 1.0 */ public UnrecoverableKeyException() { } diff --git a/security/src/main/java/java/security/UnresolvedPermission.java b/security/src/main/java/java/security/UnresolvedPermission.java index 83a089f..6570de4 100644 --- a/security/src/main/java/java/security/UnresolvedPermission.java +++ b/security/src/main/java/java/security/UnresolvedPermission.java @@ -41,20 +41,17 @@ import org.apache.harmony.security.fortress.PolicyUtils; import org.apache.harmony.security.internal.nls.Messages; /** - * Holds permissions which are of an unknown type when a policy file is read. - * - * Technically, the resolution of UnresolvedPermissions and - * substitution by actual permissions takes place in the - * <code>implies()</code> method of a <code>Permissions</code> - * collection, right before actual checking. + * An {@code UnresolvedPermission} represents a {@code Permission} whose type + * should be resolved lazy and not during initialization time of the {@code + * Policy}. {@code UnresolvedPermission}s contain all information to be replaced + * by a concrete typed {@code Permission} right before the access checks are + * performed. * + * @since Android 1.0 */ public final class UnresolvedPermission extends Permission implements Serializable { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -4821973115467008846L; private static final ObjectStreamField serialPersistentFields[] = { @@ -75,15 +72,25 @@ public final class UnresolvedPermission extends Permission private transient int hash; /** - * Constructs a new instance of this class with its type, name, and - * certificates set to the arguments by definition, actions are ignored + * Constructs a new instance of {@code UnresolvedPermission}. The supplied + * parameters are used when this instance is resolved to the concrete + * {@code Permission}. * * @param type - * class of permission object + * the fully qualified class name of the permission this class is + * resolved to. * @param name - * identifies the permission that could not be resolved + * the name of the permission this class is resolved to, maybe + * {@code null}. * @param actions + * the actions of the permission this class is resolved to, maybe + * {@code null}. * @param certs + * the certificates of the permission this class is resolved to, + * maybe {@code null}. + * @throws NullPointerException + * if type is {@code null}. + * @since Android 1.0 */ public UnresolvedPermission(String type, String name, String actions, Certificate[] certs) { @@ -123,17 +130,19 @@ public final class UnresolvedPermission extends Permission } /** - * Compares the argument to the receiver, and returns true if they represent - * the <em>same</em> object using a class specific comparison. In this - * case, the receiver and the object must have the same class, permission - * name, actions, and certificates + * Compares the specified object with this {@code UnresolvedPermission} for + * equality and returns {@code true} if the specified object is equal, + * {@code false} otherwise. To be equal, the specified object needs to be an + * instance of {@code UnresolvedPermission}, the two {@code + * UnresolvedPermission}s must refer to the same type and must have the same + * name, the same actions and certificates. * * @param obj - * the object to compare with this object - * @return <code>true</code> if the object is the same as this object, - * <code>false</code> otherwise. - * - * @see #hashCode + * object to be compared for equality with this {@code + * UnresolvedPermission}. + * @return {@code true} if the specified object is equal to this {@code + * UnresolvedPermission}, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object obj) { if (obj == this) { @@ -155,13 +164,15 @@ public final class UnresolvedPermission extends Permission } /** - * Returns an integer hash code for the receiver. Any two objects which - * answer <code>true</code> when passed to <code>equals</code> must - * answer the same value for this method. - * - * @return the receiver's hash + * Returns the hash code value for this {@code UnresolvedPermission}. + * Returns the same hash code for {@code UnresolvedPermission}s that are + * equal to each other as required by the general contract of + * {@link Object#hashCode}. * - * @see #equals + * @return the hash code value for this {@code UnresolvedPermission}. + * @see Object#equals(Object) + * @see UnresolvedPermission#equals(Object) + * @since Android 1.0 */ public int hashCode() { if (hash == 0) { @@ -177,38 +188,60 @@ public final class UnresolvedPermission extends Permission } /** - * Returns the actions associated with the receiver. Since - * UnresolvedPermission objects have no actions, answer the empty string. + * Returns an empty string since there are no actions allowed for {@code + * UnresolvedPermission}. The actions, specified in the constructor, are + * used when the concrete permission is resolved and created. * - * @return the actions associated with the receiver. + * @return an empty string, indicating that there are no actions. + * @since Android 1.0 */ public String getActions() { return ""; //$NON-NLS-1$ } - /** - * @com.intel.drl.spec_ref + /** + * Returns the name of the permission this {@code UnresolvedPermission} is + * resolved to. + * + * @return the name of the permission this {@code UnresolvedPermission} is + * resolved to. + * @since Android 1.0 */ public String getUnresolvedName() { return targetName; } - /** - * @com.intel.drl.spec_ref + /** + * Returns the actions of the permission this {@code UnresolvedPermission} + * is resolved to. + * + * @return the actions of the permission this {@code UnresolvedPermission} + * is resolved to. + * @since Android 1.0 */ public String getUnresolvedActions() { return targetActions; } - /** - * @com.intel.drl.spec_ref + /** + * Returns the fully qualified class name of the permission this {@code + * UnresolvedPermission} is resolved to. + * + * @return the fully qualified class name of the permission this {@code + * UnresolvedPermission} is resolved to. + * @since Android 1.0 */ public String getUnresolvedType() { return super.getName(); } - /** - * @com.intel.drl.spec_ref + /** + * Returns the certificates of the permission this {@code + * UnresolvedPermission} is resolved to. + * + * @return the certificates of the permission this {@code + * UnresolvedPermission} is resolved to. + * @since Android 1.0 */ public Certificate[] getUnresolvedCerts() { if (targetCerts != null) { @@ -220,28 +253,32 @@ public final class UnresolvedPermission extends Permission } /** - * Indicates whether the argument permission is implied by the - * receiver. UnresolvedPermission objects imply nothing - * because nothing is known about them yet. + * Indicates whether the specified permission is implied by this {@code + * UnresolvedPermission}. {@code UnresolvedPermission} objects imply nothing + * since nothing is known about them yet. + * <p> + * Before actual implication checking, this method tries to resolve + * UnresolvedPermissions (if any) against the passed instance. Successfully + * resolved permissions (if any) are taken into account during further + * processing. + * </p> * - * Before actual implication checking, this method tries to - * resolve UnresolvedPermissions (if any) against the passed - * instance. Successfully resolved permissions (if any) are - * taken into account during further processing. - * * @param permission - * the permission to check - * @return always replies false + * the permission to check. + * @return always {@code false} + * @since Android 1.0 */ public boolean implies(Permission permission) { return false; } /** - * Returns a string containing a concise, human-readable description of the - * receiver. + * Returns a string containing a concise, human-readable description of this + * {@code UnresolvedPermission} including its target name and its target + * actions. * - * @return a printable representation for the receiver. + * @return a printable representation for this {@code UnresolvedPermission}. + * @since Android 1.0 */ public String toString() { return "(unresolved " + getName() + " " + targetName + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -249,31 +286,36 @@ public final class UnresolvedPermission extends Permission } /** - * Returns a new PermissionCollection for holding permissions of this class. - * Answer null if any permission collection can be used. - * - * @return a new PermissionCollection or null + * Returns a new {@code PermissionCollection} for holding {@code + * UnresolvedPermission} objects. * - * @see java.security.BasicPermissionCollection + * @return a new PermissionCollection for holding {@code + * UnresolvedPermission} objects. + * @since Android 1.0 */ public PermissionCollection newPermissionCollection() { return new UnresolvedPermissionCollection(); } /** - * Tries to resolve this permission into the specified class. It is assumed - * that the class has a proper name (as returned by <code>getName()</code> - * of this unresolved permission), so no check is performed to verify this. - * However, the class must have all required certificates (as per - * <code>getUnresolvedCerts()</code>) among the passed collection of - * signers. If it does, a zero, one, and/or two-argument constructor is - * tried to instantiate a new permission, which is then returned. <br> - * If an appropriate constructor is not available or the class is - * improperly signed, <code>null</code> is returned. + * Tries to resolve this permission into the specified class. + * <p> + * It is assumed that the class has a proper name (as returned by {@code + * getName()} of this unresolved permission), so no check is performed to + * verify this. However, the class must have all required certificates (as + * per {@code getUnresolvedCerts()}) among the passed collection of signers. + * If it does, a zero, one, and/or two-argument constructor is tried to + * instantiate a new permission, which is then returned. + * </p> + * <p> + * If an appropriate constructor is not available or the class is improperly + * signed, {@code null} is returned. + * </p> * - * @param targetType - a target class instance, must not be - * <code>null</code> - * @param signers - actual signers of the targetType + * @param targetType + * - a target class instance, must not be {@code null} + * @param signers + * - actual signers of the targetType * @return resolved permission or null */ Permission resolve(Class targetType) { @@ -293,7 +335,7 @@ public final class UnresolvedPermission extends Permission /** * @com.intel.drl.spec_ref * - * Outputs <code>type</code>,<code>name</code>,<code>actions</code> + * Outputs {@code type},{@code name},{@code actions} * fields via default mechanism; next manually writes certificates in the * following format: <br> * diff --git a/security/src/main/java/java/security/UnresolvedPermissionCollection.java b/security/src/main/java/java/security/UnresolvedPermissionCollection.java index 84c4467..a43a54f 100644 --- a/security/src/main/java/java/security/UnresolvedPermissionCollection.java +++ b/security/src/main/java/java/security/UnresolvedPermissionCollection.java @@ -41,15 +41,12 @@ import java.util.Vector; import org.apache.harmony.security.internal.nls.Messages; /** - * Specific PermissionCollection for storing UnresolvedPermissions. Contained - * elements are grouped by their target type. - * + * {@code UnresolvedPermissionCollection} represents a specific {@code + * PermissionCollection} for storing {@link UnresolvedPermission} instances. + * Contained elements are grouped by their target type. */ final class UnresolvedPermissionCollection extends PermissionCollection { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -7176153071733132400L; private static final ObjectStreamField[] serialPersistentFields = { @@ -59,9 +56,17 @@ final class UnresolvedPermissionCollection extends PermissionCollection { private transient Map klasses = new HashMap(); /** - * Adds an unresolved permission to the collection. + * Adds an unresolved permission to this {@code + * UnresolvedPermissionCollection}. * - * @see java.security.PermissionCollection#add(java.security.Permission) + * @param permission + * the permission to be added. + * @throws SecurityException + * if this collection is read only. + * @throws IllegalArgumentException + * if {@code permission} is {@code null} or not an {@code + * UnresolvedPermission}. + * @since Android 1.0 */ public void add(Permission permission) { if (isReadOnly()) { @@ -83,11 +88,6 @@ final class UnresolvedPermissionCollection extends PermissionCollection { } } - /** - * Returns enumeration over collection elements. - * - * @see java.security.PermissionCollection#elements() - */ public Enumeration elements() { Collection all = new ArrayList(); for (Iterator iter = klasses.values().iterator(); iter.hasNext();) { @@ -97,9 +97,11 @@ final class UnresolvedPermissionCollection extends PermissionCollection { } /** - * Always returns false. + * Always returns {@code false}. * - * @see java.security.UnresolvedPermission#implies(Permission) + * @return always {@code false} + * @see UnresolvedPermission#implies(Permission). + * @since Android 1.0 */ public boolean implies(Permission permission) { return false; @@ -116,13 +118,15 @@ final class UnresolvedPermissionCollection extends PermissionCollection { /** * Resolves all permissions of the same class as the specified target * permission and adds them to the specified collection. If passed - * collection is <code>null</code> and some unresolved permissions were - * resolved, an appropriate new collection is instantiated and used. All - * resolved permissions are removed from this unresolved collection, and - * collection with resolved ones is returned. + * collection is {@code null} and some unresolved permissions were resolved, + * an appropriate new collection is instantiated and used. All resolved + * permissions are removed from this unresolved collection, and collection + * with resolved ones is returned. * - * @param target - a kind of permissions to be resolved - * @param holder - an existing collection for storing resolved permissions + * @param target + * a kind of permissions to be resolved. + * @param holder + * an existing collection for storing resolved permissions. * @return a collection containing resolved permissions (if any found) */ PermissionCollection resolveCollection(Permission target, diff --git a/security/src/main/java/java/security/acl/Acl.java b/security/src/main/java/java/security/acl/Acl.java index 8a87a5e..35c92fc 100644 --- a/security/src/main/java/java/security/acl/Acl.java +++ b/security/src/main/java/java/security/acl/Acl.java @@ -15,61 +15,169 @@ * limitations under the License. */ -/** -* @author Aleksei Y. Semenov -* @version $Revision$ -*/ - package java.security.acl; import java.security.Principal; import java.util.Enumeration; /** - * @com.intel.drl.spec_ref - * + * The <i>Access Control List</i> (<b>ACL</b>) interface definition. + * <p> + * An ACL is a set of {@link AclEntry} objects. + * </p> + * <p> + * An {@code AclEntry} is a list of {@link Permission}s that are granted + * (<i>positive</i>) or denied + * (<i>negative</i>) to a {@link Principal}. + * </p> + * <p> + * An {@code Acl} has a list of owners ({@link Owner}) which are principals as well {@code + * Principal}. Only those principals which are the {@code Acl}'s owners are allowed to modify the {@code + * Acl}. + * </p> + * <p> + * The <i>ACL</i> has to conform to the following rules: + * <ul> + * <li>For each {@code Principal} there can be only one <i>positive</i> and one + * <i>negative</i> {@code AclEntry}.</li> + * <li>If the two {@code AclEntry}'s (<i>positive</i> and <i>negative</i>) for a + * specific {@code Principal} grant and deny the same {@code Permission} to that + * {@code Principal}, then that {@code Permission} is treated as + * neither granted nor denied to that {@code Principal}.</li> + * <li>Permissions associated with an individual {@code Principal} always + * override permissions of the group(s) to which the individual belongs.</li> + * <li>If there is no {@code AclEntry} associated with a specific {@code + * Principal}, then it is interpreted as an empty list of permissions.</li> + * </ul> + * </p> * + * @since Android 1.0 */ public interface Acl extends Owner { /** - * @com.intel.drl.spec_ref + * Sets the name of this <i>ACL</i> instance. + * + * @param caller + * the invoking {@code Principal}. + * @param name + * the name to be set. + * @throws NotOwnerException + * if the invoking {@code Principal} is not an owner of this + * <i>ACL</i>. + * @since Android 1.0 */ void setName(Principal caller, String name) throws NotOwnerException; /** - * @com.intel.drl.spec_ref + * Returns the name of this <i>ACL</i> instance. + * + * @return the name of this <i>ACL</i> instance. + * @since Android 1.0 */ String getName(); /** - * @com.intel.drl.spec_ref + * Adds an {@code AclEntry} to this <i>ACL</i> instance. + * <p> + * If the <i>ACL</i> already has an {@code AclEntry} of the same type (<i> + * positive</i> or <i>negative</i>) and principal, then the new entry is not added. + * </p> + * + * @param caller + * the invoking {@code Principal}. + * @param entry + * the ACL entry to add. + * @return {@code true} if the entry is added, {@code false} if there is already an entry of + * the same type for the same principal + * @throws NotOwnerException + * if the invoking {@code Principal} is not an owner of this + * <i>ACL</i>. + * @since Android 1.0 */ boolean addEntry(Principal caller, AclEntry entry) throws NotOwnerException; /** - * @com.intel.drl.spec_ref + * Removes an {@code AclEntry} from this <i>ACL</i> instance. + * + * @param caller + * the invoking {@code Principal}. + * @param entry + * the ACL entry to remove. + * @return {@code true} if the entry is removed, {@code false} if the entry is not in this + * <i>ACL</i>. + * @throws NotOwnerException + * if the invoking {@code Principal} is not an owner of this + * <i>ACL</i>. + * @since Android 1.0 */ boolean removeEntry(Principal caller, AclEntry entry) throws NotOwnerException; /** - * @com.intel.drl.spec_ref + * Returns the set of allowed permissions for the specified {@code + * Principal}. + * <p> + * If the specified principal has no entry in this ACL, an empty set is + * returned. + * </p> + * <p> + * The allowed permissions are collected according to the following rules: + * <ul> + * <li>The two permission lists (<i>positive</i> and <i>negative</i>) of the + * principal's groups ({@link Group}) are collected. The positive (granted) + * permissions are the union of all group's positive permissions that the + * principal belongs to, the negative (denied) permissions are the union of + * all group's negative permissions that the principal belongs to. If a + * specific permission is in both the positive and the negative list, it is + * removed from both lists.</li> + * <li>The individual permissions (<i>positive</i> and <i>negative</i>) of + * the principal override the group permissions. The positive individual + * permissions override the group's negative permissions and the negative + * individual permissions override the grpup's positive permissions.</li> + * </ul> + * </p> + * + * @param user + * the principal to get the allowed permissions for. + * @return the set of allowed permissions for the specified principal. + * @since Android 1.0 */ Enumeration<Permission> getPermissions(Principal user); /** - * @com.intel.drl.spec_ref + * Returns an {@code Enumeration} of the {@code AclEntry} of this + * <i>ACL</i>. + * + * @return an {@code Enumeration} of the {@code AclEntry} of this + * <i>ACL</i>. + * @since Android 1.0 */ Enumeration<AclEntry> entries(); /** - * @com.intel.drl.spec_ref + * Checks whether the specified principal is granted the specified + * permission. + * <p> + * The list of granted permissions is determined according to the rules + * specified by {@code getPermissions}. + * </p> + * + * @param principal + * the principal the check the permissions for. + * @param permission + * the permission to check for the principal. + * @return {@code true} if the principal is granted the permission, otherwise {@code false}. + * @see #getPermissions(Principal) + * @since Android 1.0 */ boolean checkPermission(Principal principal, Permission permission); /** - * @com.intel.drl.spec_ref + * Returns the string representation of this ACL. + * + * @return the string representation of this ACL. + * @since Android 1.0 */ String toString(); } diff --git a/security/src/main/java/java/security/acl/AclEntry.java b/security/src/main/java/java/security/acl/AclEntry.java index 5d0abcf..7a5b722 100644 --- a/security/src/main/java/java/security/acl/AclEntry.java +++ b/security/src/main/java/java/security/acl/AclEntry.java @@ -15,70 +15,120 @@ * limitations under the License. */ -/** -* @author Aleksei Y. Semenov -* @version $Revision$ -*/ - package java.security.acl; import java.security.Principal; import java.util.Enumeration; /** - * @com.intel.drl.spec_ref + * The <i>Access Control List Entry</i> interface definition. + * <p> + * An {@code AclEntry} is a list of the {@link Permission}s that are + * granted (<i>positive</i>) or denied (<i>negative</i>) to a {@link Principal}. + * </p> * + * @since Android 1.0 */ - public interface AclEntry extends Cloneable { /** - * @com.intel.drl.spec_ref + * Set the principal for this ACL entry. + * <p> + * The principal for an ACL entry can only be set once. + * </p> + * + * @param user + * the principal for this ACL entry. + * @return {@code true} on success, {@code false} if there is a principal already set for + * this entry. + * @since Android 1.0 */ boolean setPrincipal(Principal user); /** - * @com.intel.drl.spec_ref + * Returns the principal of this ACL entry. + * + * @return the principal of this ACL entry, or null if none is set. + * @since Android 1.0 */ Principal getPrincipal(); /** - * @com.intel.drl.spec_ref + * Sets this ACL entry to be <i>negative</i>. + * <p> + * The permissions in this ACL entry will be denied to the principal + * associated with this entry. + * </p> + * <p> + * Note: An ACL entry is <i>positive</i> by default and can only become + * <i>negative</i> by calling this method. + * </p> + * + * @since Android 1.0 */ void setNegativePermissions(); /** - * @com.intel.drl.spec_ref + * Returns whether this ACL entry is <i>negative</i>. + * + * @return {@code true} if this ACL entry is negative, {@code false} if it's positive. + * @since Android 1.0 */ boolean isNegative(); /** - * @com.intel.drl.spec_ref + * Adds the specified permission to this ACL entry. + * + * @param permission + * the permission to be added. + * @return {@code true} if the specified permission is added, {@code false} if the + * permission was already in this entry. + * @since Android 1.0 */ boolean addPermission(Permission permission); /** - * @com.intel.drl.spec_ref + * Removes the specified permission from this ACL entry. + * + * @param permission + * the permission to be removed. + * @return {@code true} if the permission is removed, {@code false} if the permission was + * not in this entry. + * @since Android 1.0 */ boolean removePermission(Permission permission); /** - * @com.intel.drl.spec_ref + * Checks whether the specified permission is in this ACL entry. + * + * @param permission + * the permission to check. + * @return {@code true} if the permission is in this entry, otherwise {@code false}. + * @since Android 1.0 */ boolean checkPermission(Permission permission); /** - * @com.intel.drl.spec_ref + * Returns the list of permissions of this ACL entry. + * + * @return the list of permissions of this ACL entry, + * @since Android 1.0 */ Enumeration<Permission> permissions(); /** - * @com.intel.drl.spec_ref + * Returns the string representation of this ACL entry. + * + * @return the string representation of this ACL entry. + * @since Android 1.0 */ String toString(); /** - * @com.intel.drl.spec_ref + * Clones this ACL entry instance. + * + * @return a copy of this entry. + * @since Android 1.0 */ Object clone(); diff --git a/security/src/main/java/java/security/acl/AclNotFoundException.java b/security/src/main/java/java/security/acl/AclNotFoundException.java index 89dcea3..c8d4208 100644 --- a/security/src/main/java/java/security/acl/AclNotFoundException.java +++ b/security/src/main/java/java/security/acl/AclNotFoundException.java @@ -15,28 +15,25 @@ * limitations under the License. */ -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - package java.security.acl; /** - * @com.intel.drl.spec_ref + * The exception, that is thrown when a reference to a non-existent <i>Access + * Control List</i> (ACL) is made. * + * @since Android 1.0 */ public class AclNotFoundException extends Exception { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 5684295034092681791L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code AclNotFoundException}. + * + * @since Android 1.0 */ public AclNotFoundException() { } -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/acl/Group.java b/security/src/main/java/java/security/acl/Group.java index 37b3d5b..16898e6 100644 --- a/security/src/main/java/java/security/acl/Group.java +++ b/security/src/main/java/java/security/acl/Group.java @@ -15,40 +15,55 @@ * limitations under the License. */ -/** -* @author Aleksei Y. Semenov -* @version $Revision$ -*/ - package java.security.acl; import java.security.Principal; import java.util.Enumeration; /** - * @com.intel.drl.spec_ref + * A {@code Principal} that represents a group of principals. * + * @see Principal + * + * @since Android 1.0 */ - public interface Group extends Principal { /** - * @com.intel.drl.spec_ref + * Adds a member to this group. + * + * @param user + * the member to add. + * @return {@code true} if the member was added, {@code false} if it was already a member. + * @since Android 1.0 */ boolean addMember(Principal user); /** - * @com.intel.drl.spec_ref + * Removes a member from this group. + * + * @param user + * the member to remove. + * @return {@code true} if the member was removed, {@code false} if it was not a member. + * @since Android 1.0 */ boolean removeMember(Principal user); /** - * @com.intel.drl.spec_ref + * Returns whether the specified principal is a member of this group. + * + * @param member + * the principal to check. + * @return {@code true} if the principal is a member, otherwise {@code false}. + * @since Android 1.0 */ boolean isMember(Principal member); /** - * @com.intel.drl.spec_ref + * Returns the members of this group. + * + * @return the members of this group. + * @since Android 1.0 */ Enumeration<? extends Principal> members(); diff --git a/security/src/main/java/java/security/acl/LastOwnerException.java b/security/src/main/java/java/security/acl/LastOwnerException.java index 8ec328e..11c235f 100644 --- a/security/src/main/java/java/security/acl/LastOwnerException.java +++ b/security/src/main/java/java/security/acl/LastOwnerException.java @@ -15,26 +15,24 @@ * limitations under the License. */ -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - package java.security.acl; /** - * @com.intel.drl.spec_ref - * + * The exception that is thrown when an attempt is made to remove the + * the last {@code Owner} from an {@code Owner}. + * + * @see Owner + * + * @since Android 1.0 */ - public class LastOwnerException extends Exception { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -5141997548211140359L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code LastOwnerException}. + * + * @since Android 1.0 */ public LastOwnerException() { } diff --git a/security/src/main/java/java/security/acl/NotOwnerException.java b/security/src/main/java/java/security/acl/NotOwnerException.java index 4681339..081bdea 100644 --- a/security/src/main/java/java/security/acl/NotOwnerException.java +++ b/security/src/main/java/java/security/acl/NotOwnerException.java @@ -15,26 +15,26 @@ * limitations under the License. */ -/** -* @author Alexander V. Astapchuk -* @version $Revision$ -*/ - package java.security.acl; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when an action that requires ownership is + * attempted by a principal that is not an owner of the object for which + * ownership is required. * + * @see Acl + * @see Owner + * + * @since Android 1.0 */ - public class NotOwnerException extends Exception { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -5555597911163362399L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code NotOwnerException}. + * + * @since Android 1.0 */ public NotOwnerException() { } diff --git a/security/src/main/java/java/security/acl/Owner.java b/security/src/main/java/java/security/acl/Owner.java index 5f604f7..335dc84 100644 --- a/security/src/main/java/java/security/acl/Owner.java +++ b/security/src/main/java/java/security/acl/Owner.java @@ -15,36 +15,59 @@ * limitations under the License. */ -/** -* @author Aleksei Y. Semenov -* @version $Revision$ -*/ - package java.security.acl; import java.security.Principal; /** - * @com.intel.drl.spec_ref + * The interface to manage owners of objects that require ownership. * + * @see Acl + * @see Principal + * @since Android 1.0 */ - public interface Owner { /** - * @com.intel.drl.spec_ref + * Adds a principal to the list of owners. + * + * @param caller + * the invoking principal. + * @param owner + * the owner to added. + * @return {@code true} if the owner was added, {@code false} if it was already an owner. + * @throws NotOwnerException + * if the invoking principal is not an owner. + * @since Android 1.0 */ boolean addOwner(Principal caller, Principal owner) throws NotOwnerException; /** - * @com.intel.drl.spec_ref + * Removes a principal from the list of owners. + * + * @param caller + * the invoking principal. + * @param owner + * the owner to be removed. + * @return {@code true} if the owner was removed, {@code false} if it was not an owner. + * @throws NotOwnerException + * if the invoking principal is not an owner. + * @throws LastOwnerException + * if the owner to be removed is the last owner and hence removing it + * would make this object owner-less. + * @since Android 1.0 */ boolean deleteOwner(Principal caller, Principal owner) throws NotOwnerException, LastOwnerException; /** - * @com.intel.drl.spec_ref + * Checks whether the specified principal is an owner of this object. + * + * @param owner + * the principal to check. + * @return {@code true} if the specified principal is an owner, otherwise {@code false}. + * @since Android 1.0 */ boolean isOwner(Principal owner); } diff --git a/security/src/main/java/java/security/acl/Permission.java b/security/src/main/java/java/security/acl/Permission.java index a9617bf..0d6e22c 100644 --- a/security/src/main/java/java/security/acl/Permission.java +++ b/security/src/main/java/java/security/acl/Permission.java @@ -15,28 +15,36 @@ * limitations under the License. */ -/** -* @author Aleksei Y. Semenov -* @version $Revision$ -*/ - package java.security.acl; /** - * @com.intel.drl.spec_ref + * The interface that represents a permission. + * <p> + * It can be granted or denied to a {@link java.security.Principal Principal} + * using an {@link Acl}. + * </p> * + * @since Android 1.0 */ - public interface Permission { /** - * @com.intel.drl.spec_ref + * Checks whether the specified object equals this permission. + * + * @param another + * the permission object to compare to this permission. + * @return true if the specified permission object is equal to this, false + * if not. + * @since Android 1.0 */ boolean equals(Object another); /** - * @com.intel.drl.spec_ref + * Returns the string representation of this permission. + * + * @return the string representation of this permission. + * @since Android 1.0 */ String toString(); } diff --git a/security/src/main/java/java/security/acl/package.html b/security/src/main/java/java/security/acl/package.html index 9d23cf9..3102fc2 100644 --- a/security/src/main/java/java/security/acl/package.html +++ b/security/src/main/java/java/security/acl/package.html @@ -5,10 +5,11 @@ <html> <body> <p> -This package provides all the classes and all the interfaces needed to build Access Control List. -Functionality for generating new entries in an ACL {@link java.security.acl.AclEntry}; -for the creation of new owner {@link java.security.acl.Owner} and for the registration of +This package provides the classes and the interfaces needed to build Access Control Lists. +Functionality for generating new entries in an ACL {@link java.security.acl.AclEntry}, +for the creation of new owners {@link java.security.acl.Owner}, and for the registration of new permissions {@link java.security.acl.Permission} are provided. </p> +@since Android 1.0 </body> </html> diff --git a/security/src/main/java/java/security/cert/CRL.java b/security/src/main/java/java/security/cert/CRL.java index 74c0bf5..b0f3e30 100644 --- a/security/src/main/java/java/security/cert/CRL.java +++ b/security/src/main/java/java/security/cert/CRL.java @@ -15,25 +15,26 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; /** - * This class represents Certificate Revocation Lists (CRLs). They are used to - * indicate that a given Certificate has expired already. + * This class represents Certificate Revocation Lists (CRLs) maintained by a + * certificate authority. They are used to indicate that a given Certificate has + * expired and consequently has become invalid. * * @see CertificateFactory + * @since Android 1.0 */ public abstract class CRL { // The CRL type private final String type; /** - * @com.intel.drl.spec_ref + * Creates a new certificate revocation list of the specified type. + * + * @param type + * the type for the CRL. + * @since Android 1.0 */ protected CRL(String type) { this.type = type; @@ -42,28 +43,29 @@ public abstract class CRL { /** * Returns the type of this CRL. * - * @return String the type of this CRL. + * @return the type of this CRL. + * @since Android 1.0 */ public final String getType() { return type; } /** - * Returns if a given Certificate has been revoked or not. + * Returns whether the specified certificate is revoked by this CRL. * * @param cert - * Certificate The Certificate to test - * - * @return true if the certificate has been revoked false if the certificate - * has not been revoked yet + * the certificate to check. + * @return {@code true} if the certificate is revoked by this CRL, otherwise + * {@code false}. + * @since Android 1.0 */ public abstract boolean isRevoked(Certificate cert); /** - * Returns a string containing a concise, human-readable description of the - * receiver. + * Returns the string representation of this instance. * - * @return a printable representation for the receiver. + * @return the string representation of this instance. + * @since Android 1.0 */ public abstract String toString(); } diff --git a/security/src/main/java/java/security/cert/CRLException.java b/security/src/main/java/java/security/cert/CRLException.java index e8ca9cb..625d7d3 100644 --- a/security/src/main/java/java/security/cert/CRLException.java +++ b/security/src/main/java/java/security/cert/CRLException.java @@ -25,42 +25,52 @@ package java.security.cert; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown if errors occur during handling of {@code CRL}s. * + * @since Android 1.0 */ public class CRLException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -6694728944094197147L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Creates a new {@code CRLException} with the specified message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception. + * @since Android 1.0 */ public CRLException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Creates a new {@code CRLException}. + * + * @since Android 1.0 */ public CRLException() { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CRLException} with the specified message and cause. + * + * @param message + * the detail message for this exception. + * @param cause + * the cause for this exception. + * @since Android 1.0 */ public CRLException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CRLException} with the specified cause. + * + * @param cause + * the cause for this exception. + * @since Android 1.0 */ public CRLException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/cert/CRLSelector.java b/security/src/main/java/java/security/cert/CRLSelector.java index c6e606e..ee2d39e 100644 --- a/security/src/main/java/java/security/cert/CRLSelector.java +++ b/security/src/main/java/java/security/cert/CRLSelector.java @@ -15,26 +15,39 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * @com.intel.drl.spec_ref + * The interface specification for determining whether a CRL meets some criteria + * to select CRL objects among a set of {@code CRL}s. + * <p> + * The implementations of this interface are typically used to define the + * criteria for selecting {@code CRL}s from a {@code CertStore}. + * </p> * + * @see CertStore + * @see CRL + * @since Android 1.0 */ public interface CRLSelector extends Cloneable { /** - * @com.intel.drl.spec_ref + * Clones this {@code CRLSelector} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone(); /** - * @com.intel.drl.spec_ref + * Checks whether the defined criteria of this instance match the specified + * CRL. + * + * @param crl + * the CRL to be evaluated. + * @return {@code true} if the CRL matches the criteria, {@code false} + * otherwise. + * @since Android 1.0 */ public boolean match(CRL crl); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/cert/CertPath.java b/security/src/main/java/java/security/cert/CertPath.java index 6de5c09..2874a4d 100644 --- a/security/src/main/java/java/security/cert/CertPath.java +++ b/security/src/main/java/java/security/cert/CertPath.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.io.ByteArrayInputStream; @@ -35,49 +30,59 @@ import org.apache.harmony.security.internal.nls.Messages; /** * An immutable certificate path that can be validated. All certificates in the * path are of the same type (i.e., X509). + * <p> + * A {@code CertPath} can be represented as a byte array in at least one + * supported encoding scheme (i.e. PkiPath or PKCS7) when serialized. + * </p> + * <p> + * When a {@code List} of the certificates is obtained it must be immutable. + * </p> + * <p> + * A {@code CertPath} must be thread-safe without requiring coordinated access. + * </p> * - * A <code>CertPath</code> can be represented as a byte array in at least one - * supported encoding when serialized. - * - * When a <code>List</code> of the certificates is obtained it must be - * immutable. - * - * A <code>CertPath</code> must be thread-safe without requiring coordinated - * access. + * @see Certificate + * @since Android 1.0 */ public abstract class CertPath implements Serializable { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 6068470306649138683L; // Standard name of the type of certificates in this path private final String type; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPath} instance for the specified certificate + * type. + * + * @param type + * the certificate type. + * @since Android 1.0 */ protected CertPath(String type) { this.type = type; } /** - * Returns the type of <code>Certificate</code> in the - * <code>CertPath</code> + * Returns the type of {@code Certificate} in this instance. * - * @return <code>Certificate</code> type + * @return the certificate type. + * @since Android 1.0 */ public String getType() { return type; } /** - * Returns true if <code>Certificate</code>s in the list are the same + * Returns {@code true} if {@code Certificate}s in the list are the same * type and the lists are equal (and by implication the certificates * contained within are the same). * * @param other - * <code>CertPath</code> to be compared for equality + * {@code CertPath} to be compared for equality. + * @return {@code true} if the object are equal, {@code false} otherwise. + * @since Android 1.0 */ + @Override public boolean equals(Object other) { if (this == other) { return true; @@ -94,11 +99,14 @@ public abstract class CertPath implements Serializable { } /** - * Overrides Object.hashCode() Defined as: hashCode = 31 * - * path.getType().hashCode() + path.getCertificates().hashCode(); + * Overrides {@code Object.hashCode()}. The function is defined as follows: <br> + * {@code hashCode = 31 * path.getType().hashCode() + + * path.getCertificates().hashCode();}</br> </p> * - * @return hash code for CertPath object + * @return the hash code for this instance. + * @since Android 1.0 */ + @Override public int hashCode() { int hash = getType().hashCode(); hash = hash*31 + getCertificates().hashCode(); @@ -106,13 +114,11 @@ public abstract class CertPath implements Serializable { } /** - * Returns a <code>String</code> representation of the - * <code>CertPath</code> - * <code>Certificate</code>s. It is the result of - * calling <code>toString</code> on all <code>Certificate</code>s in - * the <code>List</code>. <code>Certificate</code>s + * Returns a {@code String} representation of this {@code CertPath} + * instance. * - * @return string representation of <code>CertPath</code> + * @return a string representation of this instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer(getType()); @@ -120,58 +126,68 @@ public abstract class CertPath implements Serializable { sb.append(getCertificates().size()); sb.append(": [\n"); //$NON-NLS-1$ int n=1; - for (Iterator i=getCertificates().iterator(); + // BEGIN android-changed + for (Iterator<? extends Certificate> i=getCertificates().iterator(); i.hasNext(); n++) { sb.append("---------------certificate "); //$NON-NLS-1$ sb.append(n); sb.append("---------------\n"); //$NON-NLS-1$ sb.append(((Certificate)i.next()).toString()); } + // END android-changed sb.append("\n]"); //$NON-NLS-1$ return sb.toString(); } /** - * Returns an immutable List of the <code>Certificate</code>s contained - * in the <code>CertPath</code>. + * Returns an immutable List of the {@code Certificate}s contained + * in the {@code CertPath}. * - * @return list of <code>Certificate</code>s in the <code>CertPath</code> + * @return a list of {@code Certificate}s in the {@code CertPath}. + * @since Android 1.0 */ public abstract List<? extends Certificate> getCertificates(); /** - * Returns an encoding of the <code>CertPath</code> using the default - * encoding + * Returns an encoding of the {@code CertPath} using the default encoding. * - * @return default encoding of the <code>CertPath</code> + * @return default encoding of the {@code CertPath}. * @throws CertificateEncodingException + * if the encoding fails. + * @since Android 1.0 */ public abstract byte[] getEncoded() throws CertificateEncodingException; /** - * Returns an encoding of the <code>CertPath</code> using the specified - * encoding + * Returns an encoding of the {@code CertPath} using the specified encoding. * * @param encoding - * encoding that should be generated - * @return default encoding of the <code>CertPath</code> + * encoding that should be generated. + * @return default encoding of the {@code CertPath}. * @throws CertificateEncodingException + * if the encoding fails. + * @since Android 1.0 */ public abstract byte[] getEncoded(String encoding) throws CertificateEncodingException; /** - * Return an <code>Iterator</code> over the supported encodings for a + * Returns an {@code Iterator} over the supported encodings for a * representation of the certificate path. * - * @return <code>Iterator</code> over supported encodings (as - * <code>String</code>s) + * @return {@code Iterator} over supported encodings (as {@code String}s). + * @since Android 1.0 */ public abstract Iterator<String> getEncodings(); /** - * @com.intel.drl.spec_ref + * Returns an alternate object to be serialized. + * + * @return an alternate object to be serialized. + * @throws ObjectStreamException + * if the creation of the alternate object fails. + * @since Android 1.0 */ protected Object writeReplace() throws ObjectStreamException { try { @@ -183,12 +199,13 @@ public abstract class CertPath implements Serializable { } /** - * @com.intel.drl.spec_ref + * The alternate {@code Serializable} class to be used for serialization and + * deserialization on {@code CertPath} objects. + * + * @since Android 1.0 */ protected static class CertPathRep implements Serializable { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 3015633072427920915L; // Standard name of the type of certificates in this path private final String type; @@ -203,7 +220,14 @@ public abstract class CertPath implements Serializable { }; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathRep} instance with the specified type + * and encoded data. + * + * @param type + * the certificate type. + * @param data + * the encoded data. + * @since Android 1.0 */ protected CertPathRep(String type, byte[] data) { this.type = type; @@ -211,7 +235,13 @@ public abstract class CertPath implements Serializable { } /** - * @com.intel.drl.spec_ref + * Deserializes a {@code CertPath} from a serialized {@code CertPathRep} + * object. + * + * @return the deserialized {@code CertPath}. + * @throws ObjectStreamException + * if deserialization fails. + * @since Android 1.0 */ protected Object readResolve() throws ObjectStreamException { try { diff --git a/security/src/main/java/java/security/cert/CertPathBuilder.java b/security/src/main/java/java/security/cert/CertPathBuilder.java index 469cfcb..47eac13 100644 --- a/security/src/main/java/java/security/cert/CertPathBuilder.java +++ b/security/src/main/java/java/security/cert/CertPathBuilder.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.AccessController; @@ -34,10 +29,11 @@ import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * This class implements the functionality of a builder for an unverified + * <i>Certification Path</i>s from a specified certificate to a trust anchor. * + * @since Android 1.0 */ - public class CertPathBuilder { // Store CertPathBuilder service name @@ -63,7 +59,15 @@ public class CertPathBuilder { private final String algorithm; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilder}. + * + * @param builderSpi + * the implementation delegate. + * @param provider + * the provider. + * @param algorithm + * the desired algorithm available at the provider. + * @since Android 1.0 */ protected CertPathBuilder(CertPathBuilderSpi builderSpi, Provider provider, String algorithm) { @@ -73,24 +77,37 @@ public class CertPathBuilder { } /** - * @com.intel.drl.spec_ref + * Returns the algorithm name of this instance. + * + * @return the algorithm name of this instance. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * @com.intel.drl.spec_ref + * Returns the provider of this instance. + * + * @return the provider of this instance. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilder} instance with the specified + * algorithm. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * @param algorithm + * the name of the algorithm. + * @return a builder for the requested algorithm. + * @throws NullPointerException + * if the algorithm is {@code null}. + * @throws NoSuchAlgorithmException + * if no installed provider can provide the algorithm. + * @since Android 1.0 */ public static CertPathBuilder getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -105,13 +122,23 @@ public class CertPathBuilder { } /** - * @com.intel.drl.spec_ref - * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * Creates a new {@code CertPathBuilder} instance from the specified + * provider providing the specified algorithm. * - * FIXME: jrockit-j2re1.4.2_04 throws IllegalArgumentException when provider - * is empty + * @param algorithm + * the name of the algorithm. + * @param provider + * the name of the provider. + * @return a builder for the requested algorithm. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the algorithm. + * @throws NoSuchProviderException + * if no provider with the specified name can be found. + * @throws NullPointerException + * if algorithm is {@code null}. + * @throws IllegalArgumentException + * if provider is {@code null} or empty. + * @since Android 1.0 */ public static CertPathBuilder getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -127,10 +154,21 @@ public class CertPathBuilder { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilder} instance from the specified + * provider providing the specified algorithm. * - * throws NullPointerException if algorithm is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * @param algorithm + * the name of the algorithm. + * @param provider + * the provider. + * @return a builder for the requested algorithm + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the algorithm. + * @throws IllegalArgumentException + * if provider is {@code null}. + * @throws NullPointerException + * if algorithm is {@code null}. + * @since Android 1.0 */ public static CertPathBuilder getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -148,7 +186,18 @@ public class CertPathBuilder { } /** - * @com.intel.drl.spec_ref + * Builds a certification path with the specified algorithm parameters. + * + * @param params + * the algorithm parameters. + * @return the built certification path. + * @throws CertPathBuilderException + * if the build fails. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to build with this + * builder. + * @see CertPathBuilderResult + * @since Android 1.0 */ public final CertPathBuilderResult build(CertPathParameters params) throws CertPathBuilderException, InvalidAlgorithmParameterException { @@ -156,7 +205,13 @@ public class CertPathBuilder { } /** - * @com.intel.drl.spec_ref + * Returns the default {@code CertPathBuilder} type from the <i>Security + * Properties</i>. + * + * @return the default {@code CertPathBuilder} type from the <i>Security + * Properties</i>, or the string "{@code PKIX}" if it cannot be + * determined. + * @since Android 1.0 */ public static final String getDefaultType() { String defaultType = AccessController diff --git a/security/src/main/java/java/security/cert/CertPathBuilderException.java b/security/src/main/java/java/security/cert/CertPathBuilderException.java index c064ceb..b957291 100644 --- a/security/src/main/java/java/security/cert/CertPathBuilderException.java +++ b/security/src/main/java/java/security/cert/CertPathBuilderException.java @@ -15,49 +15,60 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when a {@code CertPathBuilder} method fails. * + * @since Android 1.0 */ public class CertPathBuilderException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = 5316471420178794402L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilderException} with the specified message + * and cause. + * + * @param msg + * the detail message for the exception + * @param cause + * why the building of the certification path failed. + * @since Android 1.0 */ public CertPathBuilderException(String msg, Throwable cause) { super(msg, cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilderException} with the specified cause. + * + * @param cause + * why the building of the certification path failed. + * @since Android 1.0 */ public CertPathBuilderException(Throwable cause) { super(cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilderException} with the specified + * message. + * + * @param msg + * the detail message for the exception. + * @since Android 1.0 */ public CertPathBuilderException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilderException}. + * + * @since Android 1.0 */ public CertPathBuilderException() { } diff --git a/security/src/main/java/java/security/cert/CertPathBuilderResult.java b/security/src/main/java/java/security/cert/CertPathBuilderResult.java index a8eff12..e56c4a0 100644 --- a/security/src/main/java/java/security/cert/CertPathBuilderResult.java +++ b/security/src/main/java/java/security/cert/CertPathBuilderResult.java @@ -15,26 +15,29 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * @com.intel.drl.spec_ref + * The interface for results generated by + * {@link CertPathBuilder#build(CertPathParameters)}. * + * @since Android 1.0 */ public interface CertPathBuilderResult extends Cloneable { /** - * @com.intel.drl.spec_ref + * Clones this {@code CertPathBuilderResult} instance. + * + * @return the copy of this instance. + * @since Android 1.0 */ public Object clone(); /** - * @com.intel.drl.spec_ref + * Returns the built {@code CertPath} instance. Never returns {@code null}. + * + * @return the built certificate path instance. + * @since Android 1.0 */ public CertPath getCertPath(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/cert/CertPathBuilderSpi.java b/security/src/main/java/java/security/cert/CertPathBuilderSpi.java index 06adf0b..952f387 100644 --- a/security/src/main/java/java/security/cert/CertPathBuilderSpi.java +++ b/security/src/main/java/java/security/cert/CertPathBuilderSpi.java @@ -15,30 +15,39 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) for the {@code + * CertPathBuilder} class to be implemented by security providers. * + * @since Android 1.0 */ - public abstract class CertPathBuilderSpi { + /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathBuilderSpi} instance. + * + * @since Android 1.0 */ public CertPathBuilderSpi() { } /** - * @com.intel.drl.spec_ref + * Builds a certification path with the specified algorithm parameters. + * + * @param params + * the algorithm parameters. + * @return a result of the build. + * @throws CertPathBuilderException + * if the build fails. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to build the path + * with this builder. + * @since Android 1.0 */ public abstract CertPathBuilderResult engineBuild(CertPathParameters params) throws CertPathBuilderException, InvalidAlgorithmParameterException; -}
\ No newline at end of file +} diff --git a/security/src/main/java/java/security/cert/CertPathParameters.java b/security/src/main/java/java/security/cert/CertPathParameters.java index d6dd330..c99826f 100644 --- a/security/src/main/java/java/security/cert/CertPathParameters.java +++ b/security/src/main/java/java/security/cert/CertPathParameters.java @@ -15,21 +15,23 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * @com.intel.drl.spec_ref - * + * The interface specification for certification path algorithm parameters. + * <p> + * This interface is for grouping purposes of {@code CertPath} parameter + * implementations. + * </p> + * @since Android 1.0 */ public interface CertPathParameters extends Cloneable { /** - * @com.intel.drl.spec_ref + * Clones this {@code CertPathParameters} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/cert/CertPathValidator.java b/security/src/main/java/java/security/cert/CertPathValidator.java index 683c968..f95bd03 100644 --- a/security/src/main/java/java/security/cert/CertPathValidator.java +++ b/security/src/main/java/java/security/cert/CertPathValidator.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.AccessController; @@ -34,10 +29,12 @@ import org.apache.harmony.security.internal.nls.Messages; /** - * <!-- @com.intel.drl.spec_ref --> + * This class provides the functionality for validating certification paths + * (certificate chains) establishing a trust chain from a certificate to a trust + * anchor. * + * @since Android 1.0 */ - public class CertPathValidator { // Store CertPathValidator implementation service name private static final String SERVICE = "CertPathValidator"; //$NON-NLS-1$ @@ -62,8 +59,15 @@ public class CertPathValidator { private final String algorithm; /** - * <!-- @com.intel.drl.spec_ref --> - * + * Creates a new {@code CertPathValidator} instance. + * + * @param validatorSpi + * the implementation delegate. + * @param provider + * the security provider. + * @param algorithm + * the name of the algorithm. + * @since Android 1.0 */ protected CertPathValidator(CertPathValidatorSpi validatorSpi, Provider provider, String algorithm) { @@ -73,25 +77,36 @@ public class CertPathValidator { } /** - * <!-- @com.intel.drl.spec_ref --> - * + * Returns the certification path algorithm name. + * + * @return the certification path algorithm name. + * @since Android 1.0 */ public final String getAlgorithm() { return algorithm; } /** - * <!-- @com.intel.drl.spec_ref --> - * + * Returns the security provider. + * + * @return the provider. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * <!-- @com.intel.drl.spec_ref --> + * Returns a new certification path validator for the specified algorithm. * - * throws NullPointerException if algorithm is null + * @param algorithm + * the algorithm name. + * @return a certification path validator for the requested algorithm. + * @throws NoSuchAlgorithmException + * if no installed provider provides the specified algorithm. + * @throws NullPointerException + * if algorithm is {@code null}. + * @since Android 1.0 */ public static CertPathValidator getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -106,9 +121,24 @@ public class CertPathValidator { } /** - * <!-- @com.intel.drl.spec_ref --> + * Returns a new certification path validator for the specified algorithm + * from the specified provider. * - * throws NullPointerException if algorithm is null + * @param algorithm + * the algorithm name. + * @param provider + * the security provider name. + * @return a certification path validator for the requested algorithm. + * @throws NoSuchAlgorithmException + * if the specified security provider cannot provide the + * requested algorithm. + * @throws NoSuchProviderException + * if no provider with the specified name can be found. + * @throws NullPointerException + * if algorithm is {@code null}. + * @throws IllegalArgumentException + * if provider is {@code null} or empty. + * @since Android 1.0 */ public static CertPathValidator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, @@ -124,9 +154,22 @@ public class CertPathValidator { } /** - * <!-- @com.intel.drl.spec_ref --> + * Returns a new certification path validator for the specified algorithm + * from the specified provider. * - * throws NullPointerException if algorithm is null + * @param algorithm + * the algorithm name. + * @param provider + * the security provider name. + * @return a certification path validator for the requested algorithm. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the requested + * algorithm. + * @throws IllegalArgumentException + * if provider is {@code null}. + * @throws NullPointerException + * if algorithm is {@code null}. + * @since Android 1.0 */ public static CertPathValidator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { @@ -144,8 +187,23 @@ public class CertPathValidator { } /** - * <!-- @com.intel.drl.spec_ref --> + * Validates the {@code CertPath} with the algorithm of this {@code + * CertPathValidator} using the specified algorithm parameters. * + * @param certPath + * the certification path to be validated. + * @param params + * the certification path validator algorithm parameters. + * @return the validation result. + * @throws CertPathValidatorException + * if the validation fails, or the algorithm of the specified + * certification path cannot be validated using the algorithm of + * this instance. + * @throws InvalidAlgorithmParameterException + * if the specified algorithm parameters cannot be used with + * this algorithm. + * @see CertPathValidatorResult + * @since Android 1.0 */ public final CertPathValidatorResult validate(CertPath certPath, CertPathParameters params) throws CertPathValidatorException, @@ -154,8 +212,13 @@ public class CertPathValidator { } /** - * <!-- @com.intel.drl.spec_ref --> - * + * Returns the default {@code CertPathValidator} type from the <i>Security + * Properties</i>. + * + * @return the default {@code CertPathValidator} type from the <i>Security + * Properties</i>, or the string {@code "PKIX"} if it cannot be + * determined. + * @since Android 1.0 */ public static final String getDefaultType() { String defaultType = AccessController diff --git a/security/src/main/java/java/security/cert/CertPathValidatorException.java b/security/src/main/java/java/security/cert/CertPathValidatorException.java index 18343a6..072785c 100644 --- a/security/src/main/java/java/security/cert/CertPathValidatorException.java +++ b/security/src/main/java/java/security/cert/CertPathValidatorException.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.GeneralSecurityException; @@ -27,33 +22,50 @@ import java.security.GeneralSecurityException; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when a certification path (or certificate chain) + * cannot be validated. + * <p> + * A {@code CertPathValidatorException} may optionally include the certification + * path instance that failed the validation and the index of the failed + * certificate. + * </p> * + * @since Android 1.0 */ public class CertPathValidatorException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -3083180014971893139L; /** - * @com.intel.drl.spec_ref - * - * Serialized field for storing certPath which is defined in constructor - * CertPathValidatorException(msg, cause, certPath, index) + * the certification path. */ private CertPath certPath; /** - * @com.intel.drl.spec_ref - * - * Serialized field for storing index which is defined in constructor - * CertPathValidatorException(msg, cause, certPath, index) + * the index of the certificate. */ private int index = -1; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathValidatorException} with the specified + * message , cause, certification path and certificate index in the + * certification path. + * + * @param msg + * the detail message for this exception. + * @param cause + * the cause. + * @param certPath + * the certification path that failed the validation. + * @param index + * the index of the failed certificate. + * @throws IllegalArgumentException + * if {@code certPath} is {@code null} and index is not {@code + * -1}. + * @throws IndexOutOfBoundsException + * if {@code certPath} is not {@code null} and index is not + * referencing an certificate in the certification path. + * @since Android 1.0 */ public CertPathValidatorException(String msg, Throwable cause, CertPath certPath, int index) { @@ -72,41 +84,68 @@ public class CertPathValidatorException extends GeneralSecurityException { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathValidatorException} with the specified + * message and cause. + * + * @param msg + * the detail message for this exception. + * @param cause + * the cause why the path could not be validated. + * @since Android 1.0 */ public CertPathValidatorException(String msg, Throwable cause) { super(msg, cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathValidatorException} with the specified + * cause. + * + * @param cause + * the cause why the path could not be validated. + * @since Android 1.0 */ public CertPathValidatorException(Throwable cause) { super(cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathValidatorException} with the specified + * message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public CertPathValidatorException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathValidatorException}. + * + * @since Android 1.0 */ public CertPathValidatorException() { } /** - * @com.intel.drl.spec_ref + * Returns the certification path that failed validation. + * + * @return the certification path that failed validation, or {@code null} if + * none was specified. + * @since Android 1.0 */ public CertPath getCertPath() { return certPath; } /** - * @com.intel.drl.spec_ref + * Returns the index of the failed certificate in the certification path. + * + * @return the index of the failed certificate in the certification path, or + * {@code -1} if none was specified. + * @since Android 1.0 */ public int getIndex() { return index; diff --git a/security/src/main/java/java/security/cert/CertPathValidatorResult.java b/security/src/main/java/java/security/cert/CertPathValidatorResult.java index ffbf353..42540e4 100644 --- a/security/src/main/java/java/security/cert/CertPathValidatorResult.java +++ b/security/src/main/java/java/security/cert/CertPathValidatorResult.java @@ -15,21 +15,22 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * @com.intel.drl.spec_ref - * + * The interface specification for certification path validation results. + * <p> + * This interface is for grouping purposes of validation result implementations. + * </p> + * @since Android 1.0 */ public interface CertPathValidatorResult extends Cloneable { /** - * @com.intel.drl.spec_ref + * Clones this {@code CertPathValidatorResult} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/cert/CertPathValidatorSpi.java b/security/src/main/java/java/security/cert/CertPathValidatorSpi.java index abcfaed..5573679 100644 --- a/security/src/main/java/java/security/cert/CertPathValidatorSpi.java +++ b/security/src/main/java/java/security/cert/CertPathValidatorSpi.java @@ -15,30 +15,43 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.InvalidAlgorithmParameterException; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) for the {@code + * CertPathValidator} class to be implemented by security providers. * + * @since Android 1.0 */ - public abstract class CertPathValidatorSpi { /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertPathValidatorSpi} instance. + * + * @since Android 1.0 */ public CertPathValidatorSpi() { } /** - * @com.intel.drl.spec_ref + * Validates the {@code CertPath} with the algorithm of this {@code + * CertPathValidator} using the specified algorithm parameters. + * + * @param certPath + * the certification path to be validated. + * @param params + * the certification path validator algorithm parameters. + * @return the validation result. + * @throws CertPathValidatorException + * if the validation fails, or the algorithm of the specified + * certification path cannot be validated using the algorithm of + * this instance. + * @throws InvalidAlgorithmParameterException + * if the specified algorithm parameters cannot be used with + * this algorithm. + * @since Android 1.0 */ public abstract CertPathValidatorResult engineValidate(CertPath certPath, CertPathParameters params) throws CertPathValidatorException, diff --git a/security/src/main/java/java/security/cert/CertSelector.java b/security/src/main/java/java/security/cert/CertSelector.java index cb0b9ec..0316ad3 100644 --- a/security/src/main/java/java/security/cert/CertSelector.java +++ b/security/src/main/java/java/security/cert/CertSelector.java @@ -23,18 +23,36 @@ package java.security.cert; /** - * @com.intel.drl.spec_ref + * The interface specification to determine whether a {@code + * Certificate} meets some criteria. + * <p> + * The implementations of this interface are typically used to define the + * criteria for selecting {@code Certificate}s from a {@code CertStore}. + * </p> * + * @see CertStore + * @see Certificate + * @since Android 1.0 */ public interface CertSelector extends Cloneable { /** - * @com.intel.drl.spec_ref + * Clones this {@code CertSelector} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone(); /** - * @com.intel.drl.spec_ref + * Checks whether the defined criteria of this instance match the specified + * certificate. + * + * @param cert + * the certificate to be evaluated. + * @return {@code true} if the certificate matches the criteria, {@code + * false} otherwise. + * @since Android 1.0 */ public boolean match(Certificate cert); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/cert/CertStore.java b/security/src/main/java/java/security/cert/CertStore.java index 24b8b1a..a5c8260 100644 --- a/security/src/main/java/java/security/cert/CertStore.java +++ b/security/src/main/java/java/security/cert/CertStore.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.AccessController; @@ -35,10 +30,12 @@ import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * This class provides the functionality to retrieve {@code Certificate}s and + * {@code CRL}s from a read-only repository. This repository may be very large + * and may store trusted as well as untrusted certificates. * + * @since Android 1.0 */ - public class CertStore { // Store spi implementation service name @@ -67,7 +64,17 @@ public class CertStore { private final CertStoreParameters certStoreParams; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStore} instance. + * + * @param storeSpi + * the implementation delegate. + * @param provider + * the security provider. + * @param type + * the certificate store type. + * @param params + * the certificate store parameters (may be {@code null}. + * @since Android 1.0 */ protected CertStore(CertStoreSpi storeSpi, Provider provider, String type, CertStoreParameters params) { @@ -78,10 +85,23 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStore} instance with the specified type and + * initialized with the specified parameters. * - * throws NullPointerException if type is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * @param type + * the certificate store type. + * @param params + * the certificate store parameters (may be {@code null}). + * @return the new certificate store instance. + * @throws NoSuchAlgorithmException + * if no provider can provide the specified certificate store + * type. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to initialize this + * certificate store instance. + * @throws NullPointerException + * if the {@code type} is {@code null}. + * @since Android 1.0 */ public static CertStore getInstance(String type, CertStoreParameters params) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { @@ -105,12 +125,29 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStore} instance from the specified provider with + * the specified type and initialized with the specified parameters. * - * throws NullPointerException if type is null (instead of - * NoSuchAlgorithmException as in 1.4 release) - * - * FIXME: IllegalArgumentException when provider is empty + * @param type + * the certificate store type. + * @param params + * the certificate store parameters (may be {@code null}). + * @param provider + * the name of the provider. + * @return the new certificate store instance. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the requested + * certificate store type. + * @throws NoSuchProviderException + * if no provider with the specified name can be found. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to initialize this + * certificate store instance. + * @throws IllegalArgumentException + * if provider is null of empty. + * @throws NullPointerException + * if {@code type} is {@code null}. + * @since Android 1.0 */ public static CertStore getInstance(String type, CertStoreParameters params, String provider) @@ -127,10 +164,26 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref - * - * throws NullPointerException if type is null (instead of - * NoSuchAlgorithmException as in 1.4 release) + * Creates a new {@code CertStore} instance from the specified provider with + * the specified type and initialized with the specified parameters. + * @param type + * the certificate store type. + * @param params + * the certificate store parameters (may be {@code null}). + * @param provider + * the name of the provider. + * @return the new certificate store instance. + * @throws NoSuchAlgorithmException + * if the specified provider cannot provide the requested + * certificate store type. + * @throws InvalidAlgorithmParameterException + * if the specified parameters cannot be used to initialize this + * certificate store instance. + * @throws IllegalArgumentException + * if provider is {@code null}. + * @throws NullPointerException + * if {@code type} is {@code null}. + * @since Android 1.0 */ public static CertStore getInstance(String type, CertStoreParameters params, Provider provider) @@ -158,21 +211,32 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref + * Returns the certificate store type. + * + * @return the certificate store type. + * @since Android 1.0 */ public final String getType() { return type; } /** - * @com.intel.drl.spec_ref + * Returns the security provider. + * + * @return the security provider. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * @com.intel.drl.spec_ref + * Returns a copy of the certificate store parameters that were used to + * initialize this instance. + * + * @return a copy of the certificate store parameters or {@code null} if + * none were specified. + * @since Android 1.0 */ public final CertStoreParameters getCertStoreParameters() { if (certStoreParams == null) { @@ -183,7 +247,17 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref + * Returns the list of {@code Certificate}s for the specified {@code + * CertSelector} from this certificate store. + * + * @param selector + * the selector containing the criteria to search for + * certificates in this certificate store. + * @return the list of {@code Certificate}s that match the criteria of the + * specified selector. + * @throws CertStoreException + * if error(s) occur. + * @since Android 1.0 */ public final Collection<? extends Certificate> getCertificates(CertSelector selector) throws CertStoreException { @@ -191,7 +265,17 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref + * Returns the list of {@code CRL}s for the specified {@code CRLSelector} + * from this certificate store. + * + * @param selector + * the selector containing the criteria to search for certificate + * revocation lists in this store. + * @return the list of {@code CRL}s that match the criteria of the specified + * selector + * @throws CertStoreException + * if error(s) occur. + * @since Android 1.0 */ public final Collection<? extends CRL> getCRLs(CRLSelector selector) throws CertStoreException { @@ -199,8 +283,14 @@ public class CertStore { } /** - * @com.intel.drl.spec_ref - */ + * Returns the default {@code CertStore} type from the <i>Security + * Properties</i>. + * + * @return the default {@code CertStore} type from the <i>Security + * Properties</i>, or the string {@code "LDAP"} if it cannot be + * determined. + * @since Android 1.0 + */ public static final String getDefaultType() { String defaultType = AccessController .doPrivileged(new java.security.PrivilegedAction<String>() { diff --git a/security/src/main/java/java/security/cert/CertStoreException.java b/security/src/main/java/java/security/cert/CertStoreException.java index e8f14c3..8351605 100644 --- a/security/src/main/java/java/security/cert/CertStoreException.java +++ b/security/src/main/java/java/security/cert/CertStoreException.java @@ -15,48 +15,59 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when an access to a {@code CertStore} fails. * + * @since Android 1.0 */ public class CertStoreException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 2395296107471573245L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStoreException} with the specified message and + * cause. + * + * @param msg + * the detail message for this exception. + * @param cause + * the cause why the access to the certificate store failed. + * @since Android 1.0 */ public CertStoreException(String msg, Throwable cause) { super(msg, cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStoreException} with the specified cause. + * + * @param cause + * the cause why the access to the certificate store failed. + * @since Android 1.0 */ public CertStoreException(Throwable cause) { super(cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStoreException} with the specified message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public CertStoreException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStoreException}. + * + * @since Android 1.0 */ public CertStoreException() { } diff --git a/security/src/main/java/java/security/cert/CertStoreParameters.java b/security/src/main/java/java/security/cert/CertStoreParameters.java index 34860b2..566b2e2 100644 --- a/security/src/main/java/java/security/cert/CertStoreParameters.java +++ b/security/src/main/java/java/security/cert/CertStoreParameters.java @@ -15,21 +15,21 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * @com.intel.drl.spec_ref + * The marker interface specifying the parameters used to initialize a {@code + * CertStore} instance. * + * @since Android 1.0 */ public interface CertStoreParameters extends Cloneable { /** - * @com.intel.drl.spec_ref + * Clones this {@code CertStoreParameters} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/cert/CertStoreSpi.java b/security/src/main/java/java/security/cert/CertStoreSpi.java index c1119d7..be680a7 100644 --- a/security/src/main/java/java/security/cert/CertStoreSpi.java +++ b/security/src/main/java/java/security/cert/CertStoreSpi.java @@ -15,43 +15,61 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.InvalidAlgorithmParameterException; import java.util.Collection; /** - * @com.intel.drl.spec_ref + * The <i>Service Provider Interface</i> (<b>SPI</b>) definition for the {@code + * CertStore} class to be implemented by security providers. * + * @since Android 1.0 */ - public abstract class CertStoreSpi { + /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertStoreSpi}. * - * Parameter 'params' is unusable but required by the spec + * @param params + * the initialization parameters. + * @throws InvalidAlgorithmParameterException + * if the specified initialization parameters cannot be used to + * initialize this instance. + * @since Android 1.0 */ public CertStoreSpi(CertStoreParameters params) throws InvalidAlgorithmParameterException { } /** - * @com.intel.drl.spec_ref + * Returns the list of {@code Certificate}s for the specified {@code + * CertSelector} from this instance. * - * FIXME: 1.5 updated are needed Collection <? extends Certificate> + * @param selector + * the selector containing the criteria to search for + * certificates in this instance. + * @return the list of {@code Certificate}s that match the criteria of the + * specified selector. + * @throws CertStoreException + * if error(s) occur. + * @since Android 1.0 */ public abstract Collection<? extends Certificate> engineGetCertificates(CertSelector selector) throws CertStoreException; /** - * @com.intel.drl.spec_ref + * Returns the list of {@code CRL}s for the specified {@code CRLSelector} + * from this instance. * - * FIXME: 1.5 updated are needed Collection <? extends CRL> + * @param selector + * the selector containing the criteria to search for certificate + * revocation lists in instance. + * @return the list of {@code CRL}s that match the criteria of the specified + * selector + * @throws CertStoreException + * if error(s) occur. + * @since Android 1.0 */ public abstract Collection<? extends CRL> engineGetCRLs(CRLSelector selector) throws CertStoreException; diff --git a/security/src/main/java/java/security/cert/Certificate.java b/security/src/main/java/java/security/cert/Certificate.java index 2508f31..0543329 100644 --- a/security/src/main/java/java/security/cert/Certificate.java +++ b/security/src/main/java/java/security/cert/Certificate.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.io.ByteArrayInputStream; @@ -40,43 +35,49 @@ import org.apache.harmony.security.internal.nls.Messages; * Abstract class to represent identity certificates. It represents a way to * verify the binding of a Principal and its public key. Examples are X.509, * PGP, and SDSI. + * + * @since Android 1.0 */ public abstract class Certificate implements Serializable { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -3585440601605666277L; // The standard name of the certificate type private final String type; /** - * @com.intel.drl.spec_ref + * Creates a new {@code Certificate} with the specified type. + * + * @param type + * the certificate type. + * @since Android 1.0 */ protected Certificate(String type) { this.type = type; } /** - * Returns the certificate type represented by the receiver. + * Returns the certificate type. * - * @return the certificate type represented by the receiver. + * @return the certificate type. + * @since Android 1.0 */ public final String getType() { return type; } /** - * Compares the argument to the receiver, and returns true if they represent - * the <em>same</em> object using a class specific comparison. The - * implementation in Object returns true only if the argument is the exact - * same object as the receiver (==). + * Compares the argument to the certificate, and returns {@code true} if they + * represent the <em>same</em> object using a class specific comparison. The + * implementation in Object returns {@code true} only if the argument is the + * exact same object as the callee (==). * * @param other - * the object to compare with this object - * @return <code>true</code> if the object is the same as this object - * <code>false</code> if it is different from this object + * the object to compare with this object. + * @return {@code true} if the object is the same as this object, {@code + * false} if it is different from this object. * @see #hashCode + * @since Android 1.0 */ public boolean equals(Object other) { // obj equal to itself @@ -96,13 +97,13 @@ public abstract class Certificate implements Serializable { } /** - * Returns an integer hash code for the receiver. Any two objects which - * answer <code>true</code> when passed to <code>equals</code> must - * answer the same value for this method. - * - * @return the receiver's hash + * Returns an integer hash code for the certificate. Any two objects which + * return {@code true} when passed to {@code equals} must return the same + * value for this method. * + * @return the certificate's hash * @see #equals + * @since Android 1.0 */ public int hashCode() { try { @@ -121,6 +122,9 @@ public abstract class Certificate implements Serializable { * Returns the encoded representation for this certificate. * * @return the encoded representation for this certificate. + * @throws CertificateEncodingException + * if the encoding fails. + * @since Android 1.0 */ public abstract byte[] getEncoded() throws CertificateEncodingException; @@ -130,17 +134,17 @@ public abstract class Certificate implements Serializable { * @param key * PublicKey public key for which verification should be * performed. - * - * @exception CertificateException - * if encoding errors are detected - * @exception NoSuchAlgorithmException - * if an unsupported algorithm is detected - * @exception InvalidKeyException - * if an invalid key is detected - * @exception NoSuchProviderException - * if there is no default provider - * @exception SignatureException - * if signature errors are detected + * @throws CertificateException + * if encoding errors are detected. + * @throws NoSuchAlgorithmException + * if an unsupported algorithm is detected. + * @throws InvalidKeyException + * if an invalid key is detected. + * @throws NoSuchProviderException + * if there is no default provider. + * @throws SignatureException + * if signature errors are detected. + * @since Android 1.0 */ public abstract void verify(PublicKey key) throws CertificateException, @@ -150,25 +154,25 @@ public abstract class Certificate implements Serializable { SignatureException; /** - * Verifies that this certificate was signed with the given public key. Uses - * the signature algorithm given by the provider. + * Verifies that this certificate was signed with the given public key. It + * Uses the signature algorithm given by the provider. * * @param key * PublicKey public key for which verification should be * performed. * @param sigProvider * String the name of the signature provider. - * * @exception CertificateException - * if encoding errors are detected + * if encoding errors are detected. * @exception NoSuchAlgorithmException - * if an unsupported algorithm is detected + * if an unsupported algorithm is detected. * @exception InvalidKeyException - * if an invalid key is detected + * if an invalid key is detected. * @exception NoSuchProviderException - * if there is no default provider + * if the specified provider does not exists. * @exception SignatureException - * if signature errors are detected + * if signature errors are detected. + * @since Android 1.0 */ public abstract void verify(PublicKey key, String sigProvider) throws CertificateException, @@ -179,9 +183,10 @@ public abstract class Certificate implements Serializable { /** * Returns a string containing a concise, human-readable description of the - * receiver. + * certificate. * - * @return a printable representation for the receiver. + * @return a printable representation for the certificate. + * @since Android 1.0 */ public abstract String toString(); @@ -189,11 +194,17 @@ public abstract class Certificate implements Serializable { * Returns the public key corresponding to this certificate. * * @return the public key corresponding to this certificate. + * @since Android 1.0 */ public abstract PublicKey getPublicKey(); /** - * @com.intel.drl.spec_ref + * Returns an alternate object to be serialized. + * + * @return the object to serialize. + * @throws ObjectStreamException + * if the creation of the alternate object fails. + * @since Android 1.0 */ protected Object writeReplace() throws ObjectStreamException { try { @@ -205,13 +216,13 @@ public abstract class Certificate implements Serializable { } /** - * @com.intel.drl.spec_ref + * The alternate {@code Serializable} class to be used for serialization and + * deserialization of {@code Certificate} objects. * + * @since Android 1.0 */ protected static class CertificateRep implements Serializable { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = -8563758940495660020L; // The standard name of the certificate type private final String type; @@ -226,7 +237,14 @@ public abstract class Certificate implements Serializable { }; /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertificateRep} instance with the specified + * certificate type and encoded data. + * + * @param type + * the certificate type. + * @param data + * the encoded data. + * @since Android 1.0 */ protected CertificateRep(String type, byte[] data) { this.type = type; @@ -234,7 +252,13 @@ public abstract class Certificate implements Serializable { } /** - * @com.intel.drl.spec_ref + * Deserializes a {@code Certificate} from a serialized {@code + * CertificateRep} object. + * + * @return the deserialized {@code Certificate}. + * @throws ObjectStreamException + * if deserialization fails. + * @since Android 1.0 */ protected Object readResolve() throws ObjectStreamException { try { diff --git a/security/src/main/java/java/security/cert/CertificateEncodingException.java b/security/src/main/java/java/security/cert/CertificateEncodingException.java index 089f487..188d084 100644 --- a/security/src/main/java/java/security/cert/CertificateEncodingException.java +++ b/security/src/main/java/java/security/cert/CertificateEncodingException.java @@ -15,50 +15,59 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * This class represents an encoding exception for a certificate. + * The exception that is thrown when an error occurs while a {@code Certificate} + * is being encoded. + * + * @since Android 1.0 */ public class CertificateEncodingException extends CertificateException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 6219492851589449162L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Creates a new {@code CertificateEncodingException} with the specified + * message. * * @param msg - * String The detail message for the exception. + * The detail message for the exception. + * @since Android 1.0 */ public CertificateEncodingException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Creates a new {@code CertificateEncodingException}. + * + * @since Android 1.0 */ public CertificateEncodingException() { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateEncodingException} with the specified + * message and cause. + * + * @param message + * the detail message for the exception. + * @param cause + * the cause. + * @since Android 1.0 */ public CertificateEncodingException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateEncodingException} with the specified + * cause. + * + * @param cause + * the cause. + * @since Android 1.0 */ public CertificateEncodingException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/cert/CertificateException.java b/security/src/main/java/java/security/cert/CertificateException.java index c36512c..674d617 100644 --- a/security/src/main/java/java/security/cert/CertificateException.java +++ b/security/src/main/java/java/security/cert/CertificateException.java @@ -15,54 +15,58 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.security.GeneralSecurityException; /** - * This class represents a general certificate exception. + * The base class for all {@code Certificate} related exceptions. + * + * @since Android 1.0 */ public class CertificateException extends GeneralSecurityException { - /** - * @com.intel.drl.spec_ref - * - */ private static final long serialVersionUID = 3192535253797119798L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Creates a new {@code CertificateException} with the specified message. * * @param msg - * String The detail message for the exception. + * the detail message for the exception. + * @since Android 1.0 */ public CertificateException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Creates a new {@code CertificateException}. + * + * @since Android 1.0 */ public CertificateException() { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateException} with the specified message and + * cause. + * + * @param message + * the detail message for the exception. + * @param cause + * the cause. + * @since Android 1.0 */ public CertificateException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateException} with the specified cause. + * + * @param cause + * the cause + * @since Android 1.0 */ public CertificateException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/cert/CertificateExpiredException.java b/security/src/main/java/java/security/cert/CertificateExpiredException.java index b3549a2..fe3fc1f 100644 --- a/security/src/main/java/java/security/cert/CertificateExpiredException.java +++ b/security/src/main/java/java/security/cert/CertificateExpiredException.java @@ -15,37 +15,33 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * This class indicates that a given certificate has expired. + * The exception that is thrown when a {@code Certificate} has expired. + * + * @since Android 1.0 */ public class CertificateExpiredException extends CertificateException { - /** - * @com.intel.drl.spec_ref - * - */ private static final long serialVersionUID = 9071001339691533771L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Creates a new {@code CertificateExpiredException} with the specified + * message. * * @param msg - * String The detail message for the exception. + * the detail message for this exception + * @since Android 1.0 */ public CertificateExpiredException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Creates a new {@code CertificateExpiredException}. + * + * @since Android 1.0 */ public CertificateExpiredException() { } diff --git a/security/src/main/java/java/security/cert/CertificateFactory.java b/security/src/main/java/java/security/cert/CertificateFactory.java index 746b251..b4213d4 100644 --- a/security/src/main/java/java/security/cert/CertificateFactory.java +++ b/security/src/main/java/java/security/cert/CertificateFactory.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.io.InputStream; @@ -36,9 +31,15 @@ import org.apache.harmony.security.internal.nls.Messages; /** - * This class provides the functionality of a certificate factory algorithm. + * This class implements the functionality of a certificate factory algorithm, + * relying on parsing a stream of bytes. + * <p> + * It defines methods for parsing certificate chains (certificate paths) and + * <i>Certificate Revocation Lists</i> (CRLs). + * </p> + * + * @since Android 1.0 */ - public class CertificateFactory { // Store CertificateFactory service name @@ -57,8 +58,15 @@ public class CertificateFactory { private final String type; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateFactory} instance. + * + * @param certFacSpi + * the implementation delegate. + * @param provider + * the associated provider. + * @param type + * the certificate type. + * @since Android 1.0 */ protected CertificateFactory(CertificateFactorySpi certFacSpi, Provider provider, String type) { @@ -68,18 +76,18 @@ public class CertificateFactory { } /** - * Returns a new CertificateFactory of the given type. + * Creates a new {@code CertificateFactory} instance that provides the + * requested certificate type. * * @param type - * java.lang.String Type of certificate desired - * @return CertificateFactory a concrete implementation for the certificate - * type desired. - * - * @exception CertificateException - * If the type cannot be found - * - * @exception NullPointerException - * If the type is null + * the certificate type. + * @return the new {@code CertificateFactory} instance. + * @throws CertificateException + * if the specified certificate type is not available at any + * installed provider. + * @throws NullPointerException + * if {@code type} is {@code null}. + * @since Android 1.0 */ public static final CertificateFactory getInstance(String type) throws CertificateException { @@ -98,10 +106,25 @@ public class CertificateFactory { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertificateFactory} instance from the specified + * provider that provides the requested certificate type. * - * throws NullPointerException if algorithm is null (instead of - * CertificateException as in 1.4 release) + * @param type + * the certificate type. + * @param provider + * the name of the provider providing certificates of the + * specified type. + * @return the new {@code CertificateFactory} instance. + * @throws CertificateException + * if the specified certificate type is not available by the + * specified provider. + * @throws NoSuchProviderException + * if no provider with the specified name can be found. + * @throws IllegalArgumentException + * if the specified provider name is {@code null} or empty. + * @throws NullPointerException + * it {@code type} is {@code null}. + * @since Android 1.0 */ public static final CertificateFactory getInstance(String type, String provider) throws CertificateException, @@ -117,21 +140,23 @@ public class CertificateFactory { } /** - * Returns a new CertificateFactory of the given type. + * Creates a new {@code CertificateFactory} instance from the specified + * provider that provides the requested certificate type. * * @param type - * java.lang.String Type of certificate desired + * the certificate type. * @param provider - * java.security.Provider Provider which has to implement the - * algorithm - * @return CertificateFactory a concrete implementation for the certificate - * type desired. - * - * @exception CertificateException - * If the type cannot be found - * - * @exception NullPointerException - * If algorithm is null + * the name of the provider providing certificates of the + * specified type. + * @return the new {@code CertificateFactory} instance. + * @throws CertificateException + * if the specified certificate type is not available at the + * specified provider. + * @throws IllegalArgumentException + * if the specified provider is {@code null}. + * @throws NullPointerException + * is {@code type} is {@code null}. + * @since Android 1.0 */ public static final CertificateFactory getInstance(String type, Provider provider) throws CertificateException { @@ -153,35 +178,37 @@ public class CertificateFactory { } /** - * Returns the Provider of the certificate factory represented by the - * receiver. + * Returns the {@code Provider} of the certificate factory represented by + * the certificate. * - * @return Provider an instance of a subclass of java.security.Provider + * @return the provider of this certificate factory. + * @since Android 1.0 */ public final Provider getProvider() { return provider; } /** - * Returns the Certificate type + * Returns the Certificate type. * - * @return String type of certificate being used + * @return type of certificate being used. + * @since Android 1.0 */ public final String getType() { return type; } /** - * Generates and initializes a Certificate from data from the - * provided input stream. + * Generates and initializes a {@code Certificate} from the provided input + * stream. * * @param inStream - * InputStream Stream from where data is read to create the - * Certificate - * - * @return Certificate an initialized Certificate - * @exception CertificateException - * if parsing problems are detected + * the stream from where data is read to create the {@code + * Certificate}. + * @return an initialized Certificate. + * @throws CertificateException + * if parsing problems are detected. + * @since Android 1.0 */ public final Certificate generateCertificate(InputStream inStream) throws CertificateException { @@ -189,53 +216,52 @@ public class CertificateFactory { } /** - * Returns an Iterator over the supported CertPath encodings (as Strings). - * The first element is the default encoding. + * Returns an {@code Iterator} over the supported {@code CertPath} encodings + * (as Strings). The first element is the default encoding scheme to apply. * - * @return Iterator Iterator over supported CertPath encodings (as Strings) + * @return an iterator over supported {@link CertPath} encodings (as + * Strings). + * @since Android 1.0 */ public final Iterator<String> getCertPathEncodings() { return spiImpl.engineGetCertPathEncodings(); } /** - * Generates a <code>CertPath</code> from data from the provided - * <code>InputStream</code>. The default encoding is assumed. + * Generates a {@code CertPath} (a certificate chain) from the provided + * {@code InputStream}. The default encoding scheme is applied. * * @param inStream - * InputStream with PKCS7 or PkiPath encoded data - * - * @return CertPath a CertPath initialized from the provided data - * + * {@code InputStream} with encoded data. + * @return a {@code CertPath} initialized from the provided data. * @throws CertificateException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public final CertPath generateCertPath(InputStream inStream) throws CertificateException { - Iterator it = getCertPathEncodings(); + Iterator<String> it = getCertPathEncodings(); if (!it.hasNext()) { throw new CertificateException(Messages.getString("security.74")); //$NON-NLS-1$ } - return spiImpl.engineGenerateCertPath(inStream, (String) it.next()); + return spiImpl.engineGenerateCertPath(inStream, it.next()); } /** - * Generates a <code>CertPath</code> from data from the provided - * <code>InputStream</code>. The encoding is that specified by the - * encoding parameter. + * Generates a {@code CertPath} (a certificate chain) from the provided + * {@code InputStream} and the specified encoding scheme. * * @param inStream - * InputStream containing certificate path data in specified - * encoding + * {@code InputStream} containing certificate path data in + * specified encoding. * @param encoding - * encoding of the data in the input stream - * - * @return CertPath a CertPath initialized from the provided data - * + * encoding of the data in the input stream. + * @return a {@code CertPath} initialized from the provided data. * @throws CertificateException - * if parsing problems are detected + * if parsing problems are detected. * @throws UnsupportedOperationException - * if the provider does not implement this method + * if the provider does not implement this method. + * @since Android 1.0 */ public final CertPath generateCertPath(InputStream inStream, String encoding) throws CertificateException { @@ -243,19 +269,18 @@ public class CertificateFactory { } /** - * Generates a <code>CertPath</code> from the provided List of - * Certificates. The encoding is the default encoding. + * Generates a {@code CertPath} from the provided list of certificates. The + * encoding is the default encoding. * * @param certificates - * List containing certificates in a format supported by the - * CertificateFactory - * - * @return CertPath a CertPath initialized from the provided data - * + * the list containing certificates in a format supported by the + * {@code CertificateFactory}. + * @return a {@code CertPath} initialized from the provided data. * @throws CertificateException - * if parsing problems are detected + * if parsing problems are detected. * @throws UnsupportedOperationException - * if the provider does not implement this method + * if the provider does not implement this method. + * @since Android 1.0 */ public final CertPath generateCertPath(List<? extends Certificate> certificates) throws CertificateException { @@ -263,16 +288,16 @@ public class CertificateFactory { } /** - * Generates and initializes a collection of Certificates from - * data from the provided input stream. + * Generates and initializes a collection of (unrelated) certificates from + * the provided input stream. * * @param inStream - * InputStream Stream from where data is read to create the - * Certificates - * - * @return Collection an initialized collection of Certificates - * @exception CertificateException - * if parsing problems are detected + * the stream from which the data is read to create the + * collection. + * @return an initialized collection of certificates. + * @throws CertificateException + * if parsing problems are detected. + * @since Android 1.0 */ public final Collection<? extends Certificate> generateCertificates(InputStream inStream) throws CertificateException { @@ -280,32 +305,30 @@ public class CertificateFactory { } /** - * Generates and initializes a Certificate Revocation List from data from + * Generates and initializes a <i>Certificate Revocation List</i> (CRL) from * the provided input stream. * * @param inStream - * InputStream Stream from where data is read to create the CRL - * - * @return CRL an initialized Certificate Revocation List + * the stream from where data is read to create the CRL. + * @return an initialized CRL. * @exception CRLException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public final CRL generateCRL(InputStream inStream) throws CRLException { return spiImpl.engineGenerateCRL(inStream); } /** - * Generates and initializes a collection of Certificate Revocation List - * from data from the provided input stream. + * Generates and initializes a collection of <i>Certificate Revocation + * List</i> (CRL) from the provided input stream. * * @param inStream - * InputStream Stream from where data is read to create the CRLs - * - * @return Collection an initialized collection of Certificate Revocation - * List + * the stream from which the data is read to create the CRLs. + * @return an initialized collection of CRLs. * @exception CRLException - * if parsing problems are detected - * + * if parsing problems are detected. + * @since Android 1.0 */ public final Collection<? extends CRL> generateCRLs(InputStream inStream) throws CRLException { diff --git a/security/src/main/java/java/security/cert/CertificateFactorySpi.java b/security/src/main/java/java/security/cert/CertificateFactorySpi.java index d0f6ec6..ed6ffed 100644 --- a/security/src/main/java/java/security/cert/CertificateFactorySpi.java +++ b/security/src/main/java/java/security/cert/CertificateFactorySpi.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.io.InputStream; @@ -30,88 +25,90 @@ import java.util.List; import org.apache.harmony.security.internal.nls.Messages; /** - * This class is a Service Provider Interface (therefore the Spi suffix) for - * certificate factories to be supplied by providers. + * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for the + * {@code CertificateFactory} class. This SPI must be implemented for each + * certificate type a security provider wishes to support. + * + * @since Android 1.0 */ public abstract class CertificateFactorySpi { /** * Constructs a new instance of this class. + * + * @since Android 1.0 */ public CertificateFactorySpi() { } /** - * Generates and initializes a Certificate from data from the - * provided input stream. + * Generates and initializes a {@code Certificate} from the provided input + * stream. * * @param inStream - * InputStream Stream from where data is read to create the - * Certificate - * - * @return Certificate an initialized Certificate + * the stream from which the data is read to create the + * certificate. + * @return an initialized certificate. * @exception CertificateException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public abstract Certificate engineGenerateCertificate(InputStream inStream) throws CertificateException; /** - * Generates and initializes a collection of Certificates from - * data from the provided input stream. + * Generates and initializes a collection of certificates from the provided + * input stream. * * @param inStream - * InputStream Stream from where data is read to create the - * Certificates - * - * @return Collection an initialized collection of Certificates + * the stream from where data is read to create the certificates. + * @return a collection of certificates. * @exception CertificateException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public abstract Collection<? extends Certificate> engineGenerateCertificates(InputStream inStream) throws CertificateException; /** - * Generates and initializes a Certificate Revocation List from data from + * Generates and initializes a <i>Certificate Revocation List</i> (CRL) from * the provided input stream. * * @param inStream - * InputStream Stream from where data is read to create the CRL - * - * @return CRL an initialized Certificate Revocation List + * the stream from where data is read to create the CRL. + * @return an CRL instance. * @exception CRLException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public abstract CRL engineGenerateCRL(InputStream inStream) throws CRLException; /** - * Generates and initializes a collection of Certificate Revocation List - * from data from the provided input stream. + * Generates and initializes a collection of <i>Certificate Revocation + * List</i> (CRL) from the provided input stream. * * @param inStream - * InputStream Stream from where data is read to create the CRLs - * - * @return Collection an initialized collection of Certificate Revocation - * List + * the stream from which the data is read to create the CRLs. + * @return a collection of CRLs. * @exception CRLException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public abstract Collection<? extends CRL> engineGenerateCRLs(InputStream inStream) throws CRLException; /** - * Generates a <code>CertPath</code> from data from the provided - * <code>InputStream</code>. The default encoding is assumed. + * Generates a {@code CertPath} from the provided {@code InputStream}. The + * default encoding scheme is applied. * * @param inStream - * InputStream with PKCS7 or PkiPath encoded data - * - * @return CertPath a CertPath initialized from the provided data - * + * an input stream with encoded data. + * @return a {@code CertPath} initialized from the provided data. * @throws CertificateException - * if parsing problems are detected + * if parsing problems are detected. + * @since Android 1.0 */ public CertPath engineGenerateCertPath(InputStream inStream) throws CertificateException { @@ -120,22 +117,20 @@ public abstract class CertificateFactorySpi { } /** - * Generates a <code>CertPath</code> from data from the provided - * <code>InputStream</code>. The encoding is that specified by the - * encoding parameter. + * Generates a {@code CertPath} from the provided {@code + * InputStream} in the specified encoding. * * @param inStream - * InputStream containing certificate path data in specified - * encoding + * an input stream containing certificate path data in specified + * encoding. * @param encoding - * encoding of the data in the input stream - * - * @return CertPath a CertPath initialized from the provided data - * + * the encoding of the data in the input stream. + * @return a {@code CertPath} initialized from the provided data * @throws CertificateException - * if parsing problems are detected + * if parsing problems are detected. * @throws UnsupportedOperationException - * if the provider does not implement this method + * if the provider does not implement this method. + * @since Android 1.0 */ public CertPath engineGenerateCertPath(InputStream inStream, String encoding) throws CertificateException { @@ -144,19 +139,18 @@ public abstract class CertificateFactorySpi { } /** - * Generates a <code>CertPath</code> from the provided List of - * Certificates. The encoding is the default encoding. + * Generates a {@code CertPath} from the provided list of certificates. The + * encoding is the default encoding. * * @param certificates - * List containing certificates in a format supported by the - * CertificateFactory - * - * @return CertPath a CertPath initialized from the provided data - * + * the list containing certificates in a format supported by the + * {@code CertificateFactory}. + * @return a {@code CertPath} initialized from the provided data. * @throws CertificateException - * if parsing problems are detected + * if parsing problems are detected. * @throws UnsupportedOperationException - * if the provider does not implement this method + * if the provider does not implement this method. + * @since Android 1.0 */ public CertPath engineGenerateCertPath(List<? extends Certificate> certificates) throws CertificateException { @@ -165,10 +159,12 @@ public abstract class CertificateFactorySpi { } /** - * Returns an Iterator over the supported CertPath encodings (as Strings). - * The first element is the default encoding. + * Returns an {@code Iterator} over the supported {@code CertPath} encodings + * (as Strings). The first element is the default encoding. * - * @return Iterator Iterator over supported CertPath encodings (as Strings) + * @return an iterator over supported {@code CertPath} encodings (as + * Strings). + * @since Android 1.0 */ public Iterator<String> engineGetCertPathEncodings() { throw new UnsupportedOperationException( diff --git a/security/src/main/java/java/security/cert/CertificateNotYetValidException.java b/security/src/main/java/java/security/cert/CertificateNotYetValidException.java index 673a729..221b22a 100644 --- a/security/src/main/java/java/security/cert/CertificateNotYetValidException.java +++ b/security/src/main/java/java/security/cert/CertificateNotYetValidException.java @@ -15,35 +15,34 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * This class indicates that a given certificate is not valid yet. + * The exception that is thrown when a {@code Certificate} is not yet valid or + * will not yet be valid on a specified date. + * + * @since Android 1.0 */ public class CertificateNotYetValidException extends CertificateException { - /** - * @com.intel.drl.spec_ref - */ + private static final long serialVersionUID = 4355919900041064702L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Creates a new {@code CertificateNotYetValidException} with the specified + * message. * * @param msg - * String The detail message for the exception. + * the detail message for the exception. + * @since Android 1.0 */ public CertificateNotYetValidException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Creates a new {@code CertificateNotYetValidException}. + * + * @since Android 1.0 */ public CertificateNotYetValidException() { } diff --git a/security/src/main/java/java/security/cert/CertificateParsingException.java b/security/src/main/java/java/security/cert/CertificateParsingException.java index d985944..2c75d20 100644 --- a/security/src/main/java/java/security/cert/CertificateParsingException.java +++ b/security/src/main/java/java/security/cert/CertificateParsingException.java @@ -15,49 +15,58 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; /** - * This class indicates that a given certificate could not be parsed. + * The exception that is thrown when a {@code Certificate} can not be parsed. + * + * @since Android 1.0 */ public class CertificateParsingException extends CertificateException { - /** - * @com.intel.drl.spec_ref - */ private static final long serialVersionUID = -7989222416793322029L; /** - * Constructs a new instance of this class with its walkback and message - * filled in. + * Creates a new {@code CertificateParsingException} with the specified + * message. * * @param msg - * String The detail message for the exception. + * the detail message for the exception. + * @since Android 1.0 */ public CertificateParsingException(String msg) { super(msg); } /** - * Constructs a new instance of this class with its walkback filled in. + * Creates a new {@code CertificateParsingException}. + * + * @since Android 1.0 */ public CertificateParsingException() { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertificateParsingException} with the specified + * message and cause. + * + * @param message + * the detail message for the exception. + * @param cause + * the exception's source. + * @since Android 1.0 */ public CertificateParsingException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CertificateParsingException} with the specified + * cause. + * + * @param cause + * the exception's source. + * @since Android 1.0 */ public CertificateParsingException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/cert/CollectionCertStoreParameters.java b/security/src/main/java/java/security/cert/CollectionCertStoreParameters.java index 0ded19c..23d8884 100644 --- a/security/src/main/java/java/security/cert/CollectionCertStoreParameters.java +++ b/security/src/main/java/java/security/cert/CollectionCertStoreParameters.java @@ -15,38 +15,56 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.util.Collection; import java.util.Collections; /** - * @com.intel.drl.spec_ref + * The parameters to initialize a <i>Collection</i> type {@code CertStore} instance. + * <p> + * It is used to specify the {@code Collection} where the {@code CertStore} will + * retrieve the certificates and CRLs from. + * </p> * + * @since Android 1.0 */ public class CollectionCertStoreParameters implements CertStoreParameters { + // BEGIN android-changed // Default empty and immutable collection. // Used if <code>CollectionCertStoreParameters</code>instance // created by the no arg constructor - private static final Collection defaultCollection = Collections.EMPTY_SET; + private static final Collection<?> defaultCollection = Collections.EMPTY_SET; // A <code>Collection</code> of <code>Certificate</code>s // and <code>CRL</code>s - private final Collection collection; + private final Collection<?> collection; + // END android-changed /** - * @com.intel.drl.spec_ref + * Creates a new {@code CollectionCertStoreParameters} without a collection. + * <p> + * The default collection is an empty and unmodifiable {@code Collection}. + * </p> + * @since Android 1.0 */ public CollectionCertStoreParameters() { this.collection = defaultCollection; } /** - * @com.intel.drl.spec_ref + * Creates a new {@code CollectionCertStoreParameters} with the specified + * collection. + * <p> + * The specified collection is not copied and therefore may be modified at + * any time. + * </p> + * + * @param collection + * the collection where the {@code Certificate}s and {@code CRL}s + * will be retrieved from. + * @throws NullPointerException + * if {@code collection is null}. + * @since Android 1.0 */ public CollectionCertStoreParameters(Collection<?> collection) { this.collection = collection; @@ -56,21 +74,33 @@ public class CollectionCertStoreParameters implements CertStoreParameters { } /** - * @com.intel.drl.spec_ref + * Clones this {@code CollectionCertStoreParameters} instance, but not the + * underlying collection. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { return new CollectionCertStoreParameters(collection); } /** - * @com.intel.drl.spec_ref + * Returns the collection where the {@code Certificate}s and {@code CRL}s + * are retrieved from. + * + * @return the collection where the {@code Certificate}s and {@code CRL}s + * will be retrieved from. + * @since Android 1.0 */ public Collection<?> getCollection() { return collection; } /** - * @com.intel.drl.spec_ref + * Returns the string representation of this instance. + * + * @return the string representation of this instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = diff --git a/security/src/main/java/java/security/cert/LDAPCertStoreParameters.java b/security/src/main/java/java/security/cert/LDAPCertStoreParameters.java index d965c42..9145848 100644 --- a/security/src/main/java/java/security/cert/LDAPCertStoreParameters.java +++ b/security/src/main/java/java/security/cert/LDAPCertStoreParameters.java @@ -15,16 +15,12 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; /** - * @com.intel.drl.spec_ref + * The parameters to initialize a LDAP {@code CertStore} instance. * + * @since Android 1.0 */ public class LDAPCertStoreParameters implements CertStoreParameters { // Default LDAP server name @@ -38,7 +34,16 @@ public class LDAPCertStoreParameters implements CertStoreParameters { private final int port; /** - * @com.intel.drl.spec_ref + * Creates a new {@code LDAPCertStoreParameters} instance with the specified + * server name and port. + * + * @param serverName + * the LDAP server name. + * @param port + * the port. + * @throws NullPointerException + * is {@code serverName} is {@code null}. + * @since Android 1.0 */ public LDAPCertStoreParameters(String serverName, int port) { this.port = port; @@ -49,7 +54,13 @@ public class LDAPCertStoreParameters implements CertStoreParameters { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code LDAPCertStoreParameters} instance with default + * parameters. + * <p> + * The default parameters are server name "localhost" and port 389. + * </p> + * + * @since Android 1.0 */ public LDAPCertStoreParameters() { this.serverName = DEFAULT_LDAP_SERVER_NAME; @@ -57,7 +68,14 @@ public class LDAPCertStoreParameters implements CertStoreParameters { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code LDAPCertStoreParameters} instance with the specified + * server name and default port 389. + * + * @param serverName + * the LDAP server name. + * @throws NullPointerException + * if {@code serverName} is {@code null}. + * @since Android 1.0 */ public LDAPCertStoreParameters(String serverName) { this.port = DEFAULT_LDAP_PORT; @@ -68,28 +86,42 @@ public class LDAPCertStoreParameters implements CertStoreParameters { } /** - * @com.intel.drl.spec_ref + * Clones this {@code LDAPCertStoreParameters} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { return new LDAPCertStoreParameters(serverName, port); } /** - * @com.intel.drl.spec_ref + * Returns the LDAP server port. + * + * @return the LDAP server port. + * @since Android 1.0 */ public int getPort() { return port; } /** - * @com.intel.drl.spec_ref + * Returns the LDAP server name. + * + * @return the LDAP server name. + * @since Android 1.0 */ public String getServerName() { return serverName; } /** - * @com.intel.drl.spec_ref + * Returns the string representation of this {@code LDAPCertStoreParameters} + * instance. + * + * @return the string representation of this {@code LDAPCertStoreParameters} + * instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = diff --git a/security/src/main/java/java/security/cert/PKIXBuilderParameters.java b/security/src/main/java/java/security/cert/PKIXBuilderParameters.java index c6df05a..a047a80 100644 --- a/security/src/main/java/java/security/cert/PKIXBuilderParameters.java +++ b/security/src/main/java/java/security/cert/PKIXBuilderParameters.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.security.InvalidAlgorithmParameterException; @@ -31,15 +26,36 @@ import java.util.Set; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameter specification for a PKIX {@code CertPathBuilder} + * algorithm used to {@link CertPathBuilder#build(CertPathParameters) build} + * certificate chains validated with the PKIX certification path validation. + * <p> + * The parameters must be created with <i>trusted</i> certificate authorities + * and constraints for the target certificates. + * </p> * + * @see CertPathBuilder + * @see CertPathParameters + * @since Android 1.0 */ public class PKIXBuilderParameters extends PKIXParameters { // Maximum certificate path length (5 by default) private int maxPathLength = 5; /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXBuilderParameters} instance with the specified + * set of {@code TrustAnchor} and certificate constraints. + * + * @param trustAnchors + * the set of {@code TrustAnchors}. + * @param targetConstraints + * the certificate constraints. + * @throws InvalidAlgorithmParameterException + * if {@code trustAnchors} is empty. + * @throws ClassCastException + * if one of the items in {@code trustAnchors} is not an + * instance of {@code java.security.cert.TrustAnchor}. + * @since Android 1.0 */ public PKIXBuilderParameters(Set<TrustAnchor> trustAnchors, CertSelector targetConstraints) @@ -49,7 +65,19 @@ public class PKIXBuilderParameters extends PKIXParameters { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXBuilderParameters} instance with the trusted + * {@code X509Certificate} entries from the specified {@code KeyStore}. + * + * @param keyStore + * the key store containing trusted certificates. + * @param targetConstraints + * the certificate constraints. + * @throws KeyStoreException + * if the {@code keyStore} is not initialized. + * @throws InvalidAlgorithmParameterException + * if {@code keyStore} does not contained any trusted + * certificate entry. + * @since Android 1.0 */ public PKIXBuilderParameters(KeyStore keyStore, CertSelector targetConstraints) @@ -60,14 +88,32 @@ public class PKIXBuilderParameters extends PKIXParameters { } /** - * @com.intel.drl.spec_ref + * Returns the maximum length of a certification path. + * <p> + * This is the maximum number of non-self-signed certificates in a + * certification path. + * </p> + * + * @return the maximum length of a certification path, or {@code -1} if it + * is unlimited. + * @since Android 1.0 */ public int getMaxPathLength() { return maxPathLength; } /** - * @com.intel.drl.spec_ref + * Set the maximum length of a certification path. + * <p> + * This is the maximum number of non-self-signed certificates in a + * certification path. + * </p> + * + * @param maxPathLength + * the maximum length of a certification path. + * @throws InvalidParameterException + * if {@code maxPathLength} is less than {@code -1}. + * @since Android 1.0 */ public void setMaxPathLength(int maxPathLength) { if (maxPathLength < -1) { @@ -78,7 +124,12 @@ public class PKIXBuilderParameters extends PKIXParameters { } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code PKIXBuilderParameters} + * instance. + * + * @return a string representation of this {@code PKIXBuilderParameters} + * instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer("[\n"); //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/cert/PKIXCertPathBuilderResult.java b/security/src/main/java/java/security/cert/PKIXCertPathBuilderResult.java index d0a34ba..6064194 100644 --- a/security/src/main/java/java/security/cert/PKIXCertPathBuilderResult.java +++ b/security/src/main/java/java/security/cert/PKIXCertPathBuilderResult.java @@ -15,10 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ package java.security.cert; @@ -27,8 +23,10 @@ import java.security.PublicKey; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The result of the PKIX certification path builder, returned by + * {@link CertPathBuilder#build(CertPathParameters)}. * + * @since Android 1.0 */ public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult implements CertPathBuilderResult { @@ -36,7 +34,22 @@ public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult private final CertPath certPath; /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXCertPathBuilderResult} instance with the + * specified validated certification path, the trust anchor of the + * certification path, the policy tree and the public key of the subject. + * + * @param certPath + * the validated certification path. + * @param trustAnchor + * the trust anchor. + * @param policyTree + * the policy tree (or {@code null} if not used). + * @param subjectPublicKey + * the public key. + * @throws NullPointerException + * if the {@code cerPath}, {@code trustAnchor} or {@code + * subjectPolicyKey} is {@code null}. + * @since Android 1.0 */ public PKIXCertPathBuilderResult(CertPath certPath, TrustAnchor trustAnchor, PolicyNode policyTree, PublicKey subjectPublicKey) { @@ -48,14 +61,22 @@ public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult } /** - * @com.intel.drl.spec_ref + * Returns the validated certification path. + * + * @return the validated certification path. + * @since Android 1.0 */ public CertPath getCertPath() { return certPath; } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code PKIXCertPathBuilderResult} + * instance. + * + * @return a string representation of this {@code PKIXCertPathBuilderResult} + * instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer(super.toString()); diff --git a/security/src/main/java/java/security/cert/PKIXCertPathChecker.java b/security/src/main/java/java/security/cert/PKIXCertPathChecker.java index f448bee..5614878 100644 --- a/security/src/main/java/java/security/cert/PKIXCertPathChecker.java +++ b/security/src/main/java/java/security/cert/PKIXCertPathChecker.java @@ -26,18 +26,42 @@ import java.util.Collection; import java.util.Set; /** - * @com.intel.drl.spec_ref + * The class specifying the interface to extend the certification path + * validation algorithm by checks to perform on an {@code X509Certificate}. + * <p> + * The checks are added to a certification path validation using the + * {@link PKIXParameters#setCertPathCheckers(java.util.List) + * setCertPathCheckers} or + * {@link PKIXBuilderParameters#addCertPathChecker(PKIXCertPathChecker) + * addCertPathChecker} of the {@code PKIXParameters} and {@code + * PKIXBuilderParameters} class respectively. The + * {@link #check(Certificate, Collection) check} method will be called for each + * certificate processed by a {@code CertPathBuilder} of {@code + * CertPathValidator}. + * </p> + * <p> + * A {@code PKIXCertPathChecker} implementation <u>must</u> support reverse + * checking (from trusted CA to target) and <u>may</u> support forward checking + * (from target to trusted CA). The return value of {@code + * isForwardCheckingSupported} indicates whether forward checking is supported. + * </p> * + * @since Android 1.0 */ public abstract class PKIXCertPathChecker implements Cloneable { /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXCertPathChecker} instance. + * + * @since Android 1.0 */ protected PKIXCertPathChecker() {} /** - * @com.intel.drl.spec_ref + * Clones this {@code PKIXCertPathChecker} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { try { @@ -48,23 +72,55 @@ public abstract class PKIXCertPathChecker implements Cloneable { } /** - * @com.intel.drl.spec_ref + * Initializes this {@code PKIXCertPathChecker} instance for specified + * <i>checking direction</i>. + * + * @param forward + * the direction of the certification path processing, {@code + * true} if the certificates are processed in forward direction + * (from target to trusted CA), {@code false} if processed in + * reverse direction (from trusted CA to target). + * @throws CertPathValidatorException + * if initialization of this {@code PKIXCertPathChecker} + * instance fails, or if it cannot process certificates in the + * specified order. + * @since Android 1.0 */ public abstract void init(boolean forward) throws CertPathValidatorException; /** - * @com.intel.drl.spec_ref + * Returns whether this {@code PKIXCertPathChecker} instance supports + * <i>forward checking</i>. + * + * @return {@code true} if this {@code PKIXCertPathChecker} instance + * supports forward checking, otherwise {@code false}. + * @since Android 1.0 */ public abstract boolean isForwardCheckingSupported(); /** - * @com.intel.drl.spec_ref + * Returns the list of extensions of X.509 certificates that this {@code + * PKIXCertPathChecker} is able to process. + * + * @return the list of extensions of X.509 certificates that this {@code + * PKIXCertPathChecker} is able to process, or {@code null} if there + * are none. + * @since Android 1.0 */ public abstract Set<String> getSupportedExtensions(); /** - * @com.intel.drl.spec_ref + * Checks the specified certificate and removes the processed critical + * extensions from the specified list of X.509 extension <i>OID</i>s. + * + * @param cert + * the certificate. + * @param unresolvedCritExts + * the list of critical X.509 extension OID strings. + * @throws CertPathValidatorException + * if check(s) fail on the specified certificate. + * @since Android 1.0 */ public abstract void check(Certificate cert, Collection<String> unresolvedCritExts) throws CertPathValidatorException; diff --git a/security/src/main/java/java/security/cert/PKIXCertPathValidatorResult.java b/security/src/main/java/java/security/cert/PKIXCertPathValidatorResult.java index bcda383..21f90c9 100644 --- a/security/src/main/java/java/security/cert/PKIXCertPathValidatorResult.java +++ b/security/src/main/java/java/security/cert/PKIXCertPathValidatorResult.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.security.PublicKey; @@ -27,8 +22,11 @@ import java.security.PublicKey; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The implementation of the result of the PKIX certification path validation. * + * @see CertPathValidator + * @see CertPathValidator#validate(CertPath, CertPathParameters) + * @since Android 1.0 */ public class PKIXCertPathValidatorResult implements CertPathValidatorResult { // A trust anchor used during validation of certification path @@ -40,7 +38,17 @@ public class PKIXCertPathValidatorResult implements CertPathValidatorResult { private final PublicKey subjectPublicKey; /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXCertPathValidatorResult} with the specified + * trust anchor, the valid policy tree and the subject public key. + * + * @param trustAnchor + * the trust anchor describing the certification authority (CA) + * that served as trust anchor for the certification path. + * @param policyTree + * the valid policy tree from the validation. + * @param subjectPublicKey + * the subject public key from the validation. + * @since Android 1.0 */ public PKIXCertPathValidatorResult(TrustAnchor trustAnchor, PolicyNode policyTree, PublicKey subjectPublicKey) { @@ -57,28 +65,41 @@ public class PKIXCertPathValidatorResult implements CertPathValidatorResult { } /** - * @com.intel.drl.spec_ref + * Returns the valid policy tree from the validation. + * + * @return the valid policy tree from the validation. + * @since Android 1.0 */ public PolicyNode getPolicyTree() { return policyTree; } /** - * @com.intel.drl.spec_ref + * Returns the subject public key from the validation. + * + * @return the subject public key from the validation. + * @since Android 1.0 */ public PublicKey getPublicKey() { return subjectPublicKey; } /** - * @com.intel.drl.spec_ref + * Returns the trust anchor describing the certification authority (CA) that + * served as trust anchor for this certification path. + * + * @return the trust anchor. + * @since Android 1.0 */ public TrustAnchor getTrustAnchor() { return trustAnchor; } /** - * @com.intel.drl.spec_ref + * Clones this {@code PKIXCertPathValidatorResult} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { try { @@ -90,7 +111,12 @@ public class PKIXCertPathValidatorResult implements CertPathValidatorResult { } /** - * @com.intel.drl.spec_ref + * Returns a string representation for this {@code + * PKIXCertPathValidatorResult} instance. + * + * @return a string representation for this {@code + * PKIXCertPathValidatorResult} instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer(super.toString()); diff --git a/security/src/main/java/java/security/cert/PKIXParameters.java b/security/src/main/java/java/security/cert/PKIXParameters.java index 3246d89..16b0686 100644 --- a/security/src/main/java/java/security/cert/PKIXParameters.java +++ b/security/src/main/java/java/security/cert/PKIXParameters.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.security.InvalidAlgorithmParameterException; @@ -37,8 +32,15 @@ import java.util.Set; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * This class implements the parameters for the {@code PKIX CertPathValidator}. + * <p> + * The parameters must be created with <i>trusted</i> certificate authorities + * (trust anchors). + * </p> * + * @see CertPathValidator + * @see CertPathParameters + * @since Android 1.0 */ public class PKIXParameters implements CertPathParameters { // Set of trust anchors - most trusted CAs @@ -70,7 +72,14 @@ public class PKIXParameters implements CertPathParameters { private boolean policyQualifiersRejected = true; /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXParameters} instance with the specified set of + * <i>trusted</i> certificate authorities. + * + * @param trustAnchors + * the trusted CAs. + * @throws InvalidAlgorithmParameterException + * if {@code trustAnchors} is empty. + * @since Android 1.0 */ public PKIXParameters(Set<TrustAnchor> trustAnchors) throws InvalidAlgorithmParameterException { @@ -82,7 +91,17 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKIXParameters} instance with the trusted {@code + * X509Certificate} entries from the specified {@code KeyStore}. + * + * @param keyStore + * the key store containing trusted certificates. + * @throws KeyStoreException + * if the {@code keyStore} is not initialized. + * @throws InvalidAlgorithmParameterException + * if {@code keyStore} does not contained any trusted + * certificate entry. + * @since Android 1.0 */ public PKIXParameters(KeyStore keyStore) throws KeyStoreException, @@ -115,14 +134,23 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Returns a unmodifiable set of the <i>trusted</i> certificate authorities. + * + * @return a unmodifiable set of the <i>trusted</i> certificate authorities. + * @since Android 1.0 */ public Set<TrustAnchor> getTrustAnchors() { return Collections.unmodifiableSet(trustAnchors); } /** - * @com.intel.drl.spec_ref + * Sets the set of <i>trusted</i> certificate authorities. + * + * @param trustAnchors + * the set of <i>trusted</i> certificate authorities. + * @throws InvalidAlgorithmParameterException + * if {@code trustAnchors} is empty. + * @since Android 1.0 */ public void setTrustAnchors(Set<TrustAnchor> trustAnchors) throws InvalidAlgorithmParameterException { @@ -136,21 +164,38 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Returns whether the <i>any policy OID</i> will be inhibited if it's + * included in a certificate. + * + * @return {@code true} if the <i>any policy OID</i> will be inhibited, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean isAnyPolicyInhibited() { return anyPolicyInhibited; } /** - * @com.intel.drl.spec_ref + * Sets whether the <i>any policy OID</i> should be inhibited if it's + * included in a certificate. + * + * @param anyPolicyInhibited + * {@code true} if the <i>any policy OID</i> should be inhibited, + * otherwise {@code false}. + * @since Android 1.0 */ public void setAnyPolicyInhibited(boolean anyPolicyInhibited) { this.anyPolicyInhibited = anyPolicyInhibited; } /** - * @com.intel.drl.spec_ref + * Returns the list of checkers for the certification path. + * <p> + * The list is unmodifiable and the entries in the list are cloned. + * </p> + * + * @return the list of checkers for the certification path. + * @since Android 1.0 */ public List<PKIXCertPathChecker> getCertPathCheckers() { if (certPathCheckers == null) { @@ -174,7 +219,15 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Sets the list of checkers for the certification path. + * <p> + * The list is copied and the entries are cloned. + * </p> + * + * @param certPathCheckers + * the list of checkers for the certification path, or {@code + * null} to clear the checkers. + * @since Android 1.0 */ public void setCertPathCheckers(List<PKIXCertPathChecker> certPathCheckers) { if (certPathCheckers == null || certPathCheckers.isEmpty()) { @@ -195,7 +248,13 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Adds the specified {@code PKIXCertPathChecker} to the list of + * certification path checkers. + * + * @param checker + * the {@code PKIXCertPathChecker} to add, if {@code null}, it + * will be ignored. + * @since Android 1.0 */ public void addCertPathChecker(PKIXCertPathChecker checker) { if (checker == null) { @@ -211,7 +270,11 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Returns the list of certificate stores that are used to find certificates + * and CRLs. + * + * @return an immutable list of certificate stores. + * @since Android 1.0 */ public List<CertStore> getCertStores() { if (certStores == null) { @@ -231,7 +294,11 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Set the list of certificate stores that are used to find certificates and + * CRLs. + * + * @param certStores the list of certificate stores. + * @since Android 1.0 */ public void setCertStores(List<CertStore> certStores) { if (certStores == null || certStores.isEmpty()) { @@ -253,7 +320,12 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Adds a certificate store to the list of certificate stores that are used + * to find certificates and CRLs. + * + * @param store + * the store to add, if {@code null}, it will be ignored. + * @since Android 1.0 */ public void addCertStore(CertStore store) { if (store == null) { @@ -269,35 +341,62 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Returns the time for which the validation of the certification path + * should be evaluated. + * + * @return the time for the validation, or {@code null} for the current + * time. + * @since Android 1.0 */ public Date getDate() { return date == null ? null : (Date)date.clone(); } /** - * @com.intel.drl.spec_ref + * Sets the time for which the validation of the certification path sould be + * evaluated. + * + * @param date + * the time for the validation, or {@code null} for the current + * time. + * @since Android 1.0 */ public void setDate(Date date) { this.date = (date == null ? null : new Date(date.getTime())); } /** - * @com.intel.drl.spec_ref + * Returns whether an acceptable policy needs to be explicit identified in + * every certificate. + * + * @return {@code true} if an explicit policy is required, otherwise {@code + * false}. + * @since Android 1.0 */ public boolean isExplicitPolicyRequired() { return explicitPolicyRequired; } /** - * @com.intel.drl.spec_ref + * Sets whether an an acceptable policy needs to be explicit identified in + * every certificate. + * + * @param explicitPolicyRequired + * {@code true} if an explicit policy is required, otherwise + * {@code false}. + * @since Android 1.0 */ public void setExplicitPolicyRequired(boolean explicitPolicyRequired) { this.explicitPolicyRequired = explicitPolicyRequired; } /** - * @com.intel.drl.spec_ref + * Returns the list of policies (as OID strings) that would be acceptable + * for the purpose of certification path processing. + * + * @return the unmodifiable list of policies, or an empty set if any policy + * is acceptable. + * @since Android 1.0 */ public Set<String> getInitialPolicies() { if (initialPolicies == null) { @@ -316,7 +415,13 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Sets the list of policies (as OID strings) that would be acceptable for + * the purpose of certification path processing. + * + * @param initialPolicies + * the list of policies, or an empty set or {@code null} if any + * policy is acceptable. + * @since Android 1.0 */ public void setInitialPolicies(Set<String> initialPolicies) { if (initialPolicies == null || initialPolicies.isEmpty()) { @@ -339,63 +444,111 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Returns whether policy mapping is inhibited. + * + * @return {@code true} if policy mapping is inhibited, otherwise {@code + * false}. + * @since Android 1.0 */ public boolean isPolicyMappingInhibited() { return policyMappingInhibited; } /** - * @com.intel.drl.spec_ref + * Sets whether policy mapping is to be inhibited. + * + * @param policyMappingInhibited + * {@code true} if policy mapping is to be inhibited, otherwise + * {@code false}. + * @since Android 1.0 */ public void setPolicyMappingInhibited(boolean policyMappingInhibited) { this.policyMappingInhibited = policyMappingInhibited; } /** - * @com.intel.drl.spec_ref + * Returns whether certificates are rejected that include policy + * qualifiers in a certificate policy extension that is marked as critical. + * + * @return {@code true} if the certificates should be rejected, otherwise + * {@code false}. + * @since Android 1.0 */ public boolean getPolicyQualifiersRejected() { return policyQualifiersRejected; } /** - * @com.intel.drl.spec_ref + * Sets whether certificates should be rejected that include policy + * qualifiers in a certificate policy extension that is marked as critical. + * + * @param policyQualifiersRejected + * {@code true} if the certificates should be rejected, otherwise + * {@code false}. + * @since Android 1.0 */ public void setPolicyQualifiersRejected(boolean policyQualifiersRejected) { this.policyQualifiersRejected = policyQualifiersRejected; } /** - * @com.intel.drl.spec_ref + * Returns whether the default revocation checking mechanism of the + * underlying service provider is used. + * + * @return {@code true} if the default revocation checking mechanism is + * used, otherwise {@code false}. + * @since Android 1.0 */ public boolean isRevocationEnabled() { return revocationEnabled; } /** - * @com.intel.drl.spec_ref + * Sets whether the default revocation checking mechanism of the underlying + * service provider should be used. + * + * @param revocationEnabled + * {@code true} id the default revocation checking mechanism + * should be used, otherwise {@code false}. + * @since Android 1.0 */ public void setRevocationEnabled(boolean revocationEnabled) { this.revocationEnabled = revocationEnabled; } /** - * @com.intel.drl.spec_ref + * Returns the name of the signature provider. + * + * @return the name of the signature provider, or {@code null} if none is + * set. + * @since Android 1.0 */ public String getSigProvider() { return sigProvider; } /** - * @com.intel.drl.spec_ref + * Sets the name of the preferred signature provider. + * <p> + * If set, the specified provider will be preferred for creating signatures. + * If not set, the first provider found supporting creation of signatures + * will be used. + * + * @param sigProvider + * the name of the preferred signature provider, or {@code null} + * if none is preferred. + * @since Android 1.0 */ public void setSigProvider(String sigProvider) { this.sigProvider = sigProvider; } /** - * @com.intel.drl.spec_ref + * Returns the constraints that are required for the target certificate. + * + * @return the constraints for the target certificate, or {@code null} if + * none are set. + * @since Android 1.0 */ public CertSelector getTargetCertConstraints() { return (targetCertConstraints == null ? null @@ -403,7 +556,12 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Sets the constraints that are required for the target certificate. + * + * @param targetCertConstraints + * the constraints for the target certificate, or {@code null} if + * none should be used. + * @since Android 1.0 */ public void setTargetCertConstraints(CertSelector targetCertConstraints) { this.targetCertConstraints = (targetCertConstraints == null ? null @@ -411,7 +569,10 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Clones this {@code PKIXParameters} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { try { @@ -431,7 +592,10 @@ public class PKIXParameters implements CertPathParameters { } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code PKIXParameters} instance. + * + * @return a string representation of this {@code PKIXParameters} instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = diff --git a/security/src/main/java/java/security/cert/PolicyNode.java b/security/src/main/java/java/security/cert/PolicyNode.java index 24ddd5b..c112a8a 100644 --- a/security/src/main/java/java/security/cert/PolicyNode.java +++ b/security/src/main/java/java/security/cert/PolicyNode.java @@ -15,54 +15,81 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.util.Iterator; import java.util.Set; /** - * @com.intel.drl.spec_ref + * The interface to a valid policy tree node for the PKIX certification path + * validation algorithm. + * <p> + * Instances of this class are one of the outputs of the PKIX certification path + * validation algorithm. + * </p> * + * @since Android 1.0 */ public interface PolicyNode { /** - * @com.intel.drl.spec_ref + * Returns the list of children of this node as an {@code Iterator}. + * + * @return the list of children of this node as an {@code Iterator}. + * @since Android 1.0 */ public Iterator<? extends PolicyNode> getChildren(); /** - * @com.intel.drl.spec_ref + * Returns the depth of this node in the policy tree. + * <p> + * the depth is zero based. + * </p> + * + * @return the depth of this node in the policy tree. + * @since Android 1.0 */ public int getDepth(); /** - * @com.intel.drl.spec_ref + * Returns the expected policies for the next certificate to be valid. + * + * @return the expected policies. + * @since Android 1.0 */ public Set<String> getExpectedPolicies(); /** - * @com.intel.drl.spec_ref + * Returns the parent policy node. + * + * @return the parent policy node. + * @since Android 1.0 */ public PolicyNode getParent(); /** - * @com.intel.drl.spec_ref + * Returns the policy qualifiers associated with the policy of this node. + * + * @return the policy qualifiers associated with the policy of this node. + * @since Android 1.0 */ public Set<? extends PolicyQualifierInfo> getPolicyQualifiers(); /** - * @com.intel.drl.spec_ref + * Returns the valid policy of this node. + * + * @return the valid policy of this node. + * @since Android 1.0 */ public String getValidPolicy(); /** - * @com.intel.drl.spec_ref + * Returns whether the certificate policy extension of the most recently + * processed certificate is marked as critical. + * + * @return {@code true} if the extension is marked as critical, otherwise + * {@code false}. + * @since Android 1.0 */ public boolean isCritical(); } diff --git a/security/src/main/java/java/security/cert/PolicyQualifierInfo.java b/security/src/main/java/java/security/cert/PolicyQualifierInfo.java index acad3bc..5a63d51 100644 --- a/security/src/main/java/java/security/cert/PolicyQualifierInfo.java +++ b/security/src/main/java/java/security/cert/PolicyQualifierInfo.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.io.IOException; @@ -30,8 +25,10 @@ import org.apache.harmony.security.utils.Array; /** - * @com.intel.drl.spec_ref + * This class implements a policy qualifier as defined by the ASN.1 + * {@code PolicyQualifierInfo} structure. * + * @since Android 1.0 */ public class PolicyQualifierInfo { // This PolicyQualifierInfo DER encoding @@ -44,7 +41,14 @@ public class PolicyQualifierInfo { private final byte[] policyQualifier; /** - * @com.intel.drl.spec_ref + * Creates a new {@code PolicyQualifierInfo} from the specified encoded + * form. + * + * @param encoded + * the DER encoded policy qualifier. + * @throws IOException + * the policy qualifier cannot be decoded. + * @since Android 1.0 */ public PolicyQualifierInfo(byte[] encoded) throws IOException { if (encoded == null) { @@ -64,7 +68,10 @@ public class PolicyQualifierInfo { } /** - * @com.intel.drl.spec_ref + * Returns a ASN.1 DER encoded copy of policy qualifier info. + * + * @return a ASN.1 DER encoded copy of policy qualifier info. + * @since Android 1.0 */ public final byte[] getEncoded() { byte[] ret = new byte[encoded.length]; @@ -73,14 +80,22 @@ public class PolicyQualifierInfo { } /** - * @com.intel.drl.spec_ref + * Returns the identifier (an OID) of this policy qualifier info. + * + * @return the identifier of this policy qualifier info. + * @since Android 1.0 */ public final String getPolicyQualifierId() { return policyQualifierId; } /** - * @com.intel.drl.spec_ref + * Returns a ASN.1 DER encoded copy of the qualifier of this policy + * qualifier info. + * + * @return a ASN.1 DER encoded copy of the qualifier of this policy + * qualifier info. + * @since Android 1.0 */ public final byte[] getPolicyQualifier() { if (policyQualifier == null) { @@ -92,7 +107,12 @@ public class PolicyQualifierInfo { } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code PolicyQualifierInfo} + * instance. + * + * @return a string representation of this {@code PolicyQualifierInfo} + * instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = diff --git a/security/src/main/java/java/security/cert/TrustAnchor.java b/security/src/main/java/java/security/cert/TrustAnchor.java index 6d0cc3b..9dc2025 100644 --- a/security/src/main/java/java/security/cert/TrustAnchor.java +++ b/security/src/main/java/java/security/cert/TrustAnchor.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.cert; import java.io.IOException; @@ -34,8 +29,16 @@ import org.apache.harmony.security.x509.NameConstraints; /** - * @com.intel.drl.spec_ref + * This class represents a trust anchor for validation of X.509 certification + * path. + * <p> + * It is a <i>trusted</i> certificate authority (CA) and includes the public key + * of the CA, the CA's name and the constraints for the validation of + * certification paths. The constructor also allows to specify a binary + * representation of a so called "Name Constraints" extension as a byte array. + * </p> * + * @since Android 1.0 */ public class TrustAnchor { // Most trusted CA as a X500Principal @@ -50,7 +53,21 @@ public class TrustAnchor { private final byte[] nameConstraints; /** - * @com.intel.drl.spec_ref + * Creates a new {@code TrustAnchor} with the specified certificate and name + * constraints. + * <p> + * The name constraints will be used as additional constraints during the + * validation of certification paths. + * </p> + * + * @param trustedCert + * the trusted certificate + * @param nameConstraints + * the ASN.1 DER encoded form of the name constraints or {@code + * null} if none. + * @throws IllegalArgumentException + * if the decoding of the name constraints fail. + * @since Android 1.0 */ public TrustAnchor(X509Certificate trustedCert, byte[] nameConstraints) { if (trustedCert == null) { @@ -72,7 +89,25 @@ public class TrustAnchor { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code TrustAnchor} with the specified certificate + * authority name, its public key and the specified name constraints. + * <p> + * The name constraints will be used as additional constraints during the + * validation of certification paths. + * </p> + * + * @param caName + * the X.500 name of the certificate authority in RFC 2253 + * {@code String} format. + * @param caPublicKey + * the public key of the certificate authority + * @param nameConstraints + * the ASN.1 DER encoded form of the name constraints or {@code + * null} if none. + * @throws IllegalArgumentException + * if the {@code caName} is empty or if decoding of the name + * constraints fail. + * @since Android 1.0 */ public TrustAnchor(String caName, PublicKey caPublicKey, byte[] nameConstraints) { @@ -105,7 +140,24 @@ public class TrustAnchor { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code TrustAnchor} with the specified certificate + * authority name as principal, its public key and the specified name + * constraints. + * <p> + * The name constraints will be used as additional constraints during the + * validation of certification paths. + * </p> + * + * @param caPrincipal + * the name of the certificate authority as X500 principal. + * @param caPublicKey + * the public key of the certificate authority. + * @param nameConstraints + * the ASN.1 DER encoded form of the name constraints or {@code + * null} if none. + * @throws IllegalArgumentException + * if decoding of the name constraints fail. + * @since Android 1.0 */ public TrustAnchor(X500Principal caPrincipal, PublicKey caPublicKey, byte[] nameConstraints) { @@ -132,7 +184,10 @@ public class TrustAnchor { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the name constraints in ASN.1 DER encoded form. + * + * @return a copy of the name constraints in ASN.1 DER encoded form. + * @since Android 1.0 */ public final byte[] getNameConstraints() { if (nameConstraints == null) { @@ -145,35 +200,58 @@ public class TrustAnchor { } /** - * @com.intel.drl.spec_ref + * Returns the certificate of this <i>trusted</i> certificate authority. + * + * @return the certificate of this CA or {@code null}, if the trust anchor + * of this instance was not created with a certificate. + * @since Android 1.0 */ public final X509Certificate getTrustedCert() { return trustedCert; } /** - * @com.intel.drl.spec_ref + * Returns the name of the certificate authority as {@code X500Principal}. + * + * @return the name of the certificate authority or {@code null} if the + * trust anchor of this instance was not created with a {@code + * X500Principal}. + * @since Android 1.0 */ public final X500Principal getCA() { return caPrincipal; } /** - * @com.intel.drl.spec_ref + * Returns the name of the certificate authority as {@code String} in RFC + * 2253 format. + * + * @return the name of the certificate authority as {@code String} in RFC + * 2253 format or {@code null} if the trust anchor of this instance + * was not created with a CA name. + * @since Android 1.0 */ public final String getCAName() { return caName; } /** - * @com.intel.drl.spec_ref + * Returns the public key of the certificate authority. + * + * @return the public key of the certificate authority or {@code null} if + * the trust anchor if this instance was not created with a public + * key. + * @since Android 1.0 */ public final PublicKey getCAPublicKey() { return caPublicKey; } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code TrustAnchor} instance. + * + * @return a string representation of this {@code TrustAnchor} instance. + * @since Android 1.0 */ public String toString() { StringBuffer sb = new StringBuffer("TrustAnchor: [\n"); //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/cert/X509CRL.java b/security/src/main/java/java/security/cert/X509CRL.java index e502f2f..eabdb68 100644 --- a/security/src/main/java/java/security/cert/X509CRL.java +++ b/security/src/main/java/java/security/cert/X509CRL.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package java.security.cert; import java.io.ByteArrayInputStream; @@ -42,19 +37,36 @@ import javax.security.auth.x500.X500Principal; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * Abstract base class for X.509 certificate revocation lists (CRL). + * <p> + * More information regarding CRL can be found in RFC 2459, + * "Internet X.509 Public Key Infrastructure Certificate and CRL Profile" at <a + * href + * ="http://www.ietf.org/rfc/rfc2459.txt">http://www.ietf.org/rfc/rfc2459.txt + * </a>. + * </p> + * + * @since Android 1.0 */ public abstract class X509CRL extends CRL implements X509Extension { /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509CRL} instance. + * + * @since Android 1.0 */ protected X509CRL() { super("X.509"); //$NON-NLS-1$ } /** - * @com.intel.drl.spec_ref + * Returns whether the specified object equals to this instance. + * + * @param other + * the object to compare. + * @return {@code true} if the specified object is equal to this, otherwise + * {@code false}. + * @since Android 1.0 */ public boolean equals(Object other) { if (other == this) { @@ -72,7 +84,10 @@ public abstract class X509CRL extends CRL implements X509Extension { } /** - * @com.intel.drl.spec_ref + * Returns the hashcode of this CRL instance. + * + * @return the hashcode. + * @since Android 1.0 */ public int hashCode() { try { @@ -88,13 +103,33 @@ public abstract class X509CRL extends CRL implements X509Extension { } /** - * @com.intel.drl.spec_ref + * Returns this CRL in ASN.1 DER encoded form. + * + * @return this CRL in ASN.1 DER encoded form. + * @throws CRLException + * if encoding fails. + * @since Android 1.0 */ public abstract byte[] getEncoded() throws CRLException; /** - * @com.intel.drl.spec_ref + * Verifies this CRL by verifying that this CRL was signed with the + * corresponding private key to the specified public key. + * + * @param key + * the public key to verify this CRL with. + * @throws CRLException + * if encoding or decoding fails. + * @throws NoSuchAlgorithmException + * if a needed algorithm is not present. + * @throws InvalidKeyException + * if the specified key is invalid. + * @throws NoSuchProviderException + * if no provider can be found. + * @throws SignatureException + * if errors occur on signatures. + * @since Android 1.0 */ public abstract void verify(PublicKey key) throws CRLException, NoSuchAlgorithmException, @@ -102,7 +137,25 @@ public abstract class X509CRL extends CRL implements X509Extension { SignatureException; /** - * @com.intel.drl.spec_ref + * Verifies this CRL by verifying that this CRL was signed with the + * corresponding private key to the specified public key. The signature + * verification engine of the specified provider will be used. + * + * @param key + * the public key to verify this CRL with. + * @param sigProvider + * the name of the provider for the signature algorithm. + * @throws CRLException + * if encoding decoding fails. + * @throws NoSuchAlgorithmException + * if a needed algorithm is not present. + * @throws InvalidKeyException + * if the specified key is invalid. + * @throws NoSuchProviderException + * if the specified provider cannot be found. + * @throws SignatureException + * if errors occur on signatures. + * @since Android 1.0 */ public abstract void verify(PublicKey key, String sigProvider) throws CRLException, NoSuchAlgorithmException, @@ -110,17 +163,27 @@ public abstract class X509CRL extends CRL implements X509Extension { SignatureException; /** - * @com.intel.drl.spec_ref + * Returns the version number of this CRL. + * + * @return the version number of this CRL. + * @since Android 1.0 */ public abstract int getVersion(); /** - * @com.intel.drl.spec_ref + * <b>Do not use</b>, use {@link #getIssuerX500Principal()} instead. Returns + * the issuer as an implementation specific Principal object. + * + * @return the issuer distinguished name. + * @since Android 1.0 */ public abstract Principal getIssuerDN(); /** - * @com.intel.drl.spec_ref + * Returns the issuer distinguished name of this CRL. + * + * @return the issuer distinguished name of this CRL. + * @since Android 1.0 */ public X500Principal getIssuerX500Principal() { try { @@ -140,22 +203,41 @@ public abstract class X509CRL extends CRL implements X509Extension { } /** - * @com.intel.drl.spec_ref + * Returns the {@code thisUpdate} value of this CRL. + * + * @return the {@code thisUpdate} value of this CRL. + * @since Android 1.0 */ public abstract Date getThisUpdate(); /** - * @com.intel.drl.spec_ref + * Returns the {@code nextUpdate} value of this CRL. + * + * @return the {@code nextUpdate} value of this CRL, or {@code null} if none + * is present. + * @since Android 1.0 */ public abstract Date getNextUpdate(); /** - * @com.intel.drl.spec_ref + * Returns the CRL entry with the specified certificate serial number. + * + * @param serialNumber + * the certificate serial number to search for a CRL entry. + * @return the entry for the specified certificate serial number, or {@code + * null} if not found. + * @since Android 1.0 */ public abstract X509CRLEntry getRevokedCertificate(BigInteger serialNumber); /** - * @com.intel.drl.spec_ref + * Returns the CRL entry for the specified certificate. + * + * @param certificate + * the certificate to search a CRL entry for. + * @return the entry for the specified certificate, or {@code null} if not + * found. + * @since Android 1.0 */ public X509CRLEntry getRevokedCertificate(X509Certificate certificate) { if (certificate == null) { @@ -165,32 +247,55 @@ public abstract class X509CRL extends CRL implements X509Extension { } /** - * @com.intel.drl.spec_ref + * Returns the set of revoked certificates. + * + * @return the set of revoked certificates, or {@code null} if no revoked + * certificates are in this CRL. + * @since Android 1.0 */ public abstract Set<? extends X509CRLEntry> getRevokedCertificates(); /** - * @com.intel.drl.spec_ref + * Returns the {@code tbsCertList} information of this CRL in DER encoded + * form. + * + * @return the CRL information in DER encoded form. + * @throws CRLException + * if encoding fails. + * @since Android 1.0 */ public abstract byte[] getTBSCertList() throws CRLException; /** - * @com.intel.drl.spec_ref + * Returns the signature bytes of this CRL. + * + * @return the signature bytes of this CRL. + * @since Android 1.0 */ public abstract byte[] getSignature(); /** - * @com.intel.drl.spec_ref + * Returns the name of the signature algorithm. + * + * @return the name of the signature algorithm. + * @since Android 1.0 */ public abstract String getSigAlgName(); /** - * @com.intel.drl.spec_ref + * Returns the OID of the signature algorithm. + * + * @return the OID of the signature algorithm. + * @since Android 1.0 */ public abstract String getSigAlgOID(); /** - * @com.intel.drl.spec_ref + * Returns the parameters of the signature algorithm in DER encoded form. + * + * @return the parameters of the signature algorithm in DER encoded form, or + * {@code null} if not present. + * @since Android 1.0 */ public abstract byte[] getSigAlgParams(); } diff --git a/security/src/main/java/java/security/cert/X509CRLEntry.java b/security/src/main/java/java/security/cert/X509CRLEntry.java index d726f9d..35fb78b 100644 --- a/security/src/main/java/java/security/cert/X509CRLEntry.java +++ b/security/src/main/java/java/security/cert/X509CRLEntry.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package java.security.cert; import java.math.BigInteger; @@ -31,17 +26,28 @@ import java.util.Date; import javax.security.auth.x500.X500Principal; /** - * @com.intel.drl.spec_ref + * Abstract base class for entries in a certificate revocation list (CRL). + * + * @see X509CRL + * @since Android 1.0 */ public abstract class X509CRLEntry implements X509Extension { /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509CRLEntry} instance. + * + * @since Android 1.0 */ public X509CRLEntry() {} /** - * @com.intel.drl.spec_ref + * Returns whether the specified object equals to this instance. + * + * @param other + * the object to compare. + * @return {@code true} if the specified object equals to this instance, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object other) { if (other == this) { @@ -59,7 +65,10 @@ public abstract class X509CRLEntry implements X509Extension { } /** - * @com.intel.drl.spec_ref + * Returns the hashcode of this instance. + * + * @return the hashcode of this instance. + * @since Android 1.0 */ public int hashCode() { int res = 0; @@ -74,31 +83,56 @@ public abstract class X509CRLEntry implements X509Extension { } /** - * @com.intel.drl.spec_ref + * Returns this entry in ASN.1 DER encoded form. + * + * @return the encoded form of this entry. + * @throws CRLException + * if encoding fails. + * @since Android 1.0 */ public abstract byte[] getEncoded() throws CRLException; /** - * @com.intel.drl.spec_ref + * Returns the serial number of the revoked certificate. + * + * @return the serial number of the revoked certificate. + * @since Android 1.0 */ public abstract BigInteger getSerialNumber(); + /** + * Returns the issuer of the revoked certificate. + * + * @return the issuer of the revoked certificate, or {@code null} if the + * issuer is equal to the CRL issuer. + * @since Android 1.0 + */ public X500Principal getCertificateIssuer() { return null; } /** - * @com.intel.drl.spec_ref + * Returns the date when the certificate is revoked. + * + * @return the date when the certificate is revoked. + * @since Android 1.0 */ public abstract Date getRevocationDate(); /** - * @com.intel.drl.spec_ref + * Returns whether this CRL entry has extensions. + * + * @return {@code true} is this CRL entry has extensions, otherwise {@code + * false}. + * @since Android 1.0 */ public abstract boolean hasExtensions(); /** - * @com.intel.drl.spec_ref + * Returns a string representation of this instance. + * + * @return a string representation of this instance. + * @since Android 1.0 */ public abstract String toString(); } diff --git a/security/src/main/java/java/security/cert/X509CRLSelector.java b/security/src/main/java/java/security/cert/X509CRLSelector.java index d679e99..c1b5f45 100644 --- a/security/src/main/java/java/security/cert/X509CRLSelector.java +++ b/security/src/main/java/java/security/cert/X509CRLSelector.java @@ -15,10 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ package java.security.cert; @@ -36,7 +32,14 @@ import org.apache.harmony.security.internal.nls.Messages; import org.apache.harmony.security.x501.Name; /** - * @com.intel.drl.spec_ref + * A CRL selector ({@code CRLSelector} for selecting {@code + * X509CRL}s that match the specified criteria. + * <p> + * When constructed, all criteria are set to default values that will match any + * {@code X509CRL}. + * </p> + * + * @since Android 1.0 */ public class X509CRLSelector implements CRLSelector { @@ -56,12 +59,23 @@ public class X509CRLSelector implements CRLSelector { private X509Certificate certificateChecking; /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509CertSelector}. + * + * @since Android 1.0 */ public X509CRLSelector() { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the issuer distinguished names. + * <p> + * The CRL issuer must match at least one of the specified distinguished + * names. + * </p> + * + * @param issuers + * the list of issuer distinguished names to match, or {@code + * null} if any issuer distinguished name will do. + * @since Android 1.0 */ public void setIssuers(Collection<X500Principal> issuers) { if (issuers == null) { @@ -77,7 +91,26 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * <b>Do not use:</b> use {@link #setIssuers(Collection)} or one of + * {@link #addIssuerName} instead. Sets the criterion for the issuer + * distinguished names. + * <p> + * The CRL issuer must match at least one of the specified distinguished + * names. + * </p> + * <p> + * The specified parameter {@code names} is a collection with an entry for + * each name to be included in the criterion. The name is specified as a + * {@code String} or a byte array specifying the name (in RFC 2253 or ASN.1 + * DER encoded form) + * </p> + * + * @param names + * the list of issuer distinguished names to match, or {@code + * null} if any issuer distinguished name will do. + * @throws IOException + * if parsing fails. + * @since Android 1.0 */ public void setIssuerNames(Collection<?> names) throws IOException { if (names == null) { @@ -106,7 +139,15 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Adds an issuer to the criterion for the issuer distinguished names. + * <p> + * The CRL issuer must match at least one of the specified distinguished + * names. + * </p> + * + * @param issuer + * the issuer to add to the criterion + * @since Android 1.0 */ public void addIssuer(X500Principal issuer) { if (issuer == null) { @@ -131,7 +172,19 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * <b>Do not use:</b>, use {@link #addIssuer(X500Principal)} or + * {@link #addIssuerName(byte[])} instead. It can fail to match some CRLs + * because of a loss of encoding information in a RFC 2253 string. + * <p> + * Adds an issuer to the criterion for the issuer distinguished names. The + * CRK issuer must match at least one of the specified distinguished names. + * </p> + * + * @param iss_name + * the RFC 2253 encoded name. + * @throws IOException + * if parsing fails. + * @since Android 1.0 */ public void addIssuerName(String iss_name) throws IOException { if (issuerNames == null) { @@ -149,7 +202,17 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Adds an issuer to the criterion for the issuer distinguished names. + * <p> + * The CRL issuer must match at least one of the specified distinguished + * names. + * </p> + * + * @param iss_name + * the issuer to add to the criterion in ASN.1 DER encoded form. + * @throws IOException + * if parsing fails. + * @since Android 1.0 */ public void addIssuerName(byte[] iss_name) throws IOException { if (iss_name == null) { @@ -165,21 +228,48 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the minimum CRL number. + * <p> + * The CRL must have a number extension with a value greater than or equal + * to the specified parameter. + * </p> + * + * @param minCRL + * the minimum CRL number or null to not check the minimum CRL + * number + * @since Android 1.0 */ public void setMinCRLNumber(BigInteger minCRL) { this.minCRL = minCRL; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the maximum CRL number. + * <p> + * The CRL must have a number extension with a value less than or equal to + * the specified parameter. + * </p> + * + * @param maxCRL + * the maximum CRL number or null to not check the maximum CRL + * number. + * @since Android 1.0 */ public void setMaxCRLNumber(BigInteger maxCRL) { this.maxCRL = maxCRL; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the CRL update period. + * <p> + * The CRL's {@code thisUpdate} value must be equal or before the specified + * date and the {@code nextUpdate} value must be after the specified date. + * </p> + * + * @param dateAndTime + * the date to search for valid CRL's or {@code null} to not + * check the date. + * @since Android 1.0 */ public void setDateAndTime(Date dateAndTime) { if (dateAndTime == null) { @@ -190,14 +280,26 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Sets a certificate hint to find CRLs. It's not a criterion but may help + * finding relevant CRLs. + * + * @param cert + * the certificate hint or {@code null}. + * @since Android 1.0 */ public void setCertificateChecking(X509Certificate cert) { this.certificateChecking = cert; } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the issuer distinguished names. + * <p> + * The CRL issuer must match at least one of the distinguished names. + * </p> + * + * @return the unmodifiable list of issuer distinguished names to match, or + * {@code null} if any issuer distinguished name will do. + * @since Android 1.0 */ public Collection<X500Principal> getIssuers() { if (issuerNames == null) { @@ -215,7 +317,14 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the issuer distinguished names. + * <p> + * The CRL issuer must match at least one of the distinguished names. + * </p> + * + * @return a copy of the list of issuer distinguished names to match, or + * {@code null} if any issuer distinguished name will do. + * @since Android 1.0 */ public Collection<Object> getIssuerNames() { if (issuerNames == null) { @@ -225,21 +334,45 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the minimum CRL number. + * <p> + * The CRL must have a number extension with a value greater than or equal + * to the returned value. + * </p> + * + * @return the minimum CRL number or {@code null} if the minimum CRL number + * is not to be checked. + * @since Android 1.0 */ public BigInteger getMinCRL() { return minCRL; } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the maximum CRL number. + * <p> + * The CRL must have a number extension with a value less than or equal to + * the returned value. + * </p> + * + * @return the maximum CRL number or null if the maximum CRL number is not + * checked. + * @since Android 1.0 */ public BigInteger getMaxCRL() { return maxCRL; } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the CRL update period. + * <p> + * The CRL's {@code thisUpdate} value must be equal or before the returned + * date and the {@code nextUpdate} value must be after the returned date. + * </p> + * + * @return the date to search for valid CRL's or {@code null} if the date is + * not checked. + * @since Android 1.0 */ public Date getDateAndTime() { if (dateAndTime == -1) { @@ -249,14 +382,21 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Returns the certificate hint to find CRLs. It's not a criterion but may + * help finding relevant CRLs. + * + * @return the certificate hint or {@code null} if none set. + * @since Android 1.0 */ public X509Certificate getCertificateChecking() { return certificateChecking; } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code X509CRLSelector} instance. + * + * @return a string representation of this {@code X509CRLSelector} instance. + * @since Android 1.0 */ public String toString() { StringBuffer result = new StringBuffer(); @@ -287,7 +427,14 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified CRL matches all the criteria collected in + * this instance. + * + * @param crl + * the CRL to check. + * @return {@code true} if the CRL matches all the criteria, otherwise + * {@code false}. + * @since Android 1.0 */ public boolean match(CRL crl) { if (!(crl instanceof X509CRL)) { @@ -334,7 +481,10 @@ public class X509CRLSelector implements CRLSelector { } /** - * @com.intel.drl.spec_ref + * Clones this {@code X509CRL} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { X509CRLSelector result = new X509CRLSelector(); diff --git a/security/src/main/java/java/security/cert/X509CertSelector.java b/security/src/main/java/java/security/cert/X509CertSelector.java index be2567e..c6d2e98 100644 --- a/security/src/main/java/java/security/cert/X509CertSelector.java +++ b/security/src/main/java/java/security/cert/X509CertSelector.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package java.security.cert; import java.io.IOException; @@ -52,7 +47,10 @@ import org.apache.harmony.security.x509.SubjectPublicKeyInfo; /** - * @com.intel.drl.spec_ref + * A certificate selector ({@code CertSelector} for selecting {@code + * X509Certificate}s that match the specified criteria. + * + * @since Android 1.0 */ public class X509CertSelector implements CertSelector { @@ -82,40 +80,64 @@ public class X509CertSelector implements CertSelector { private byte[] issuerBytes; /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509CertSelector}. + * + * @since Android 1.0 */ public X509CertSelector() {} /** - * @com.intel.drl.spec_ref + * Sets the certificate that a matching certificate must be equal to. + * + * @param certificate + * the certificate to match, or null to not check this criteria. + * @since Android 1.0 */ public void setCertificate(X509Certificate certificate) { certificateEquals = certificate; } /** - * @com.intel.drl.spec_ref + * Returns the certificate that a matching certificate must be equal to. + * + * @return the certificate to match, or null if this criteria is not + * checked. + * @since Android 1.0 */ public X509Certificate getCertificate() { return certificateEquals; } /** - * @com.intel.drl.spec_ref + * Sets the serial number that a certificate must match. + * + * @param serialNumber + * the serial number to match, or {@code null} to not check the + * serial number. + * @since Android 1.0 */ public void setSerialNumber(BigInteger serialNumber) { this.serialNumber = serialNumber; } /** - * @com.intel.drl.spec_ref + * Returns the serial number that a certificate must match. + * + * @return the serial number to match, or {@code null} if the serial number + * is not to be checked. + * @since Android 1.0 */ public BigInteger getSerialNumber() { return serialNumber; } /** - * @com.intel.drl.spec_ref + * Sets the issuer that a certificate must match. + * + * @param issuer + * the issuer to match, or {@code null} if the issuer is not to + * be checked. + * @since Android 1.0 */ public void setIssuer(X500Principal issuer) { this.issuer = issuer; @@ -124,14 +146,27 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the issuer that a certificate must match. + * + * @return the issuer that a certificate must match, or {@code null} if the + * issuer is not to be checked. + * @since Android 1.0 */ public X500Principal getIssuer() { return issuer; } /** - * @com.intel.drl.spec_ref + * <b>Do not use</b>, use {@link #getIssuer()} or + * {@link #getIssuerAsBytes()} instead. Sets the issuer that a certificate + * must match. + * + * @param issuerName + * the issuer in a RFC 2253 format string, or {@code null} to not + * check the issuer. + * @throws IOException + * if parsing the issuer fails. + * @since Android 1.0 */ public void setIssuer(String issuerName) throws IOException { if (issuerName == null) { @@ -150,7 +185,13 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * <b>Do not use</b>, use {@link #getIssuer()} or + * {@link #getIssuerAsBytes()} instead. Returns the issuer that a + * certificate must match in a RFC 2253 format string. + * + * @return the issuer in a RFC 2253 format string, or {@code null} if the + * issuer is not to be checked. + * @since Android 1.0 */ public String getIssuerAsString() { if (issuer == null) { @@ -163,7 +204,14 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the issuer that a certificate must match. + * + * @param issuerDN + * the distinguished issuer name in ASN.1 DER encoded format, or + * {@code null} to not check the issuer. + * @throws IOException + * if decoding the issuer fail. + * @since Android 1.0 */ public void setIssuer(byte[] issuerDN) throws IOException { if (issuerDN == null) { @@ -181,7 +229,13 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the issuer that a certificate must match. + * + * @return the distinguished issuer name in ASN.1 DER encoded format, or + * {@code null} if the issuer is not to be checked. + * @throws IOException + * if encoding the issuer fails. + * @since Android 1.0 */ public byte[] getIssuerAsBytes() throws IOException { if (issuer == null) { @@ -196,21 +250,39 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Set the subject that a certificate must match. + * + * @param subject + * the subject distinguished name or {@code null} to not check + * the subject. + * @since Android 1.0 */ public void setSubject(X500Principal subject) { this.subject = subject; } /** - * @com.intel.drl.spec_ref + * Returns the subject that a certificate must match. + * + * @return the subject distinguished name, or null if the subject is not to + * be checked. + * @since Android 1.0 */ public X500Principal getSubject() { return subject; } /** - * @com.intel.drl.spec_ref + * <b>Do not use</b>, use {@link #setSubject(byte[])} or + * {@link #setSubject(X500Principal)} instead. Returns the subject that a + * certificate must match. + * + * @param subjectDN + * the subject distinguished name in RFC 2253 format or {@code + * null} to not check the subject. + * @throws IOException + * if decoding the subject fails. + * @since Android 1.0 */ public void setSubject(String subjectDN) throws IOException { if (subjectDN == null) { @@ -225,7 +297,13 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * <b>Do not use</b>, use {@link #getSubject()} or + * {@link #getSubjectAsBytes()} instead. Returns the subject that a + * certificate must match. + * + * @return the subject distinguished name in RFC 2253 format, or {@code + * null} if the subject is not to be checked. + * @since Android 1.0 */ public String getSubjectAsString() { if (subject == null) { @@ -235,7 +313,14 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the subject that a certificate must match. + * + * @param subjectDN + * the subject distinguished name in ASN.1 DER format, or {@code + * null} to not check the subject. + * @throws IOException + * if decoding the subject fails. + * @since Android 1.0 */ public void setSubject(byte[] subjectDN) throws IOException { if (subjectDN == null) { @@ -250,7 +335,13 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the subject that a certificate must match. + * + * @return the subject distinguished name in ASN.1 DER format, or {@code + * null} if the subject is not to be checked. + * @throws IOException + * if encoding the subject fails. + * @since Android 1.0 */ public byte[] getSubjectAsBytes() throws IOException { if (subject == null) { @@ -260,7 +351,15 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the {@literal SubjectKeyIdentifier} extension. + * <p> + * The {@code subjectKeyIdentifier} should be a single DER encoded value. + * </p> + * + * @param subjectKeyIdentifier + * the subject key identifier or {@code null} to disable this + * check. + * @since Android 1.0 */ public void setSubjectKeyIdentifier(byte[] subjectKeyIdentifier) { if (subjectKeyIdentifier == null) { @@ -273,7 +372,11 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the {@literal SubjectKeyIdentifier} extension. + * + * @return the subject key identifier or {@code null} if it is not to be + * checked. + * @since Android 1.0 */ public byte[] getSubjectKeyIdentifier() { if (subjectKeyIdentifier == null) { @@ -285,7 +388,12 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the {@literal AuthorityKeyIdentifier} extension. + * + * @param authorityKeyIdentifier + * the authority key identifier, or {@code null} to disable this + * check. + * @since Android 1.0 */ public void setAuthorityKeyIdentifier(byte[] authorityKeyIdentifier) { if (authorityKeyIdentifier == null) { @@ -299,7 +407,12 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the {@literal AuthorityKeyIdentifier} + * extension. + * + * @return the authority key identifier, or {@code null} if it is not to be + * checked. + * @since Android 1.0 */ public byte[] getAuthorityKeyIdentifier() { if (authorityKeyIdentifier == null) { @@ -311,7 +424,13 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the validity date of the certificate. + * <p> + * The certificate must be valid at the specified date. + * </p> + * @param certificateValid + * the validity date or {@code null} to not check the date. + * @since Android 1.0 */ public void setCertificateValid(Date certificateValid) { this.certificateValid = (certificateValid == null) @@ -320,7 +439,11 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the validity date of the certificate. + * + * @return the validity date or {@code null} if the date is not to be + * checked. + * @since Android 1.0 */ public Date getCertificateValid() { return (certificateValid == null) @@ -329,7 +452,14 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the validity date of the private key. + * <p> + * The private key must be valid at the specified date. + * </p> + * + * @param privateKeyValid + * the validity date or {@code null} to not check the date. + * @since Android 1.0 */ public void setPrivateKeyValid(Date privateKeyValid) { if (privateKeyValid == null) { @@ -340,7 +470,14 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the validity date of the private key. + * <p> + * The private key must be valid at the specified date. + * </p> + * + * @return the validity date or {@code null} if the date is not to be + * checked. + * @since Android 1.0 */ public Date getPrivateKeyValid() { if (privateKeyValid != null) { @@ -371,7 +508,18 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the subject public key signature algorithm. + * <p> + * The certificate must contain a subject public key with the algorithm + * specified. + * </p> + * + * @param oid + * the OID (object identifier) of the signature algorithm or + * {@code null} to not check the OID. + * @throws IOException + * if the specified object identifier is invalid. + * @since Android 1.0 */ public void setSubjectPublicKeyAlgID(String oid) throws IOException { if (oid == null) { @@ -383,14 +531,22 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the subject public key signature algorithm. + * + * @return the OID (object identifier) or the signature algorithm or {@code + * null} if it's not to be checked. + * @since Android 1.0 */ public String getSubjectPublicKeyAlgID() { return subjectPublicKeyAlgID; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the subject public key. + * + * @param key + * the subject public key or {@code null} to not check the key. + * @since Android 1.0 */ public void setSubjectPublicKey(PublicKey key) { subjectPublicKey = (key == null) ? null : key.getEncoded(); @@ -398,7 +554,14 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the subject public key. + * + * @param key + * the subject public key in ASN.1 DER encoded format or {@code null} to + * not check the key. + * @throws IOException + * if decoding the the public key fails. + * @since Android 1.0 */ public void setSubjectPublicKey(byte[] key) throws IOException { if (key == null) { @@ -414,14 +577,24 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the subject public key. + * + * @return the subject public key or {@code null} if the key is not to be + * checked. + * @since Android 1.0 */ public PublicKey getSubjectPublicKey() { return subjectPublicKeyImpl; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the {@literal KeyUsage} extension. + * + * @param keyUsage + * the boolean array in the format as returned by + * {@link X509Certificate#getKeyUsage()}, or {@code null} to not + * check the key usage. + * @since Android 1.0 */ public void setKeyUsage(boolean[] keyUsage) { if (keyUsage == null) { @@ -433,7 +606,12 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the {@literal KeyUsage} extension. + * + * @return the boolean array in the format as returned by + * {@link X509Certificate#getKeyUsage()}, or {@code null} if the key + * usage is not to be checked. + * @since Android 1.0 */ public boolean[] getKeyUsage() { if (keyUsage == null) { @@ -445,7 +623,13 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the {@literal ExtendedKeyUsage} extension. + * + * @param keyUsage + * the set of key usage OIDs, or {@code null} to not check it. + * @throws IOException + * if one of the OIDs is invalid. + * @since Android 1.0 */ public void setExtendedKeyUsage(Set<String> keyUsage) throws IOException { @@ -464,28 +648,71 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the {@literal ExtendedKeyUsage} extension. + * + * @return the set of key usage OIDs, or {@code null} if it's not to be + * checked. + * @since Android 1.0 */ public Set<String> getExtendedKeyUsage() { return extendedKeyUsage; } /** - * @com.intel.drl.spec_ref + * Sets the flag for the matching behavior for subject alternative names. + * <p> + * The flag indicates whether a certificate must contain all or at least one + * of the subject alternative names specified by + * {@link #setSubjectAlternativeNames} or {@link #addSubjectAlternativeName} + * . + * </p> + * + * @param matchAllNames + * {@code true} if a certificate must contain all of the + * specified subject alternative names, otherwise {@code false}. + * @since Android 1.0 */ public void setMatchAllSubjectAltNames(boolean matchAllNames) { this.matchAllNames = matchAllNames; } /** - * @com.intel.drl.spec_ref + * Returns the flag for the matching behavior for subject alternative names. + * <p> + * The flag indicates whether a certificate must contain all or at least one + * of the subject alternative names specified by + * {@link #setSubjectAlternativeNames} or {@link #addSubjectAlternativeName} + * . + * </p> + * + * @return {@code true} if a certificate must contain all of the specified + * subject alternative names, otherwise {@code false}. + * @since Android 1.0 */ public boolean getMatchAllSubjectAltNames() { return matchAllNames; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for subject alternative names. + * <p> + * the certificate must contain all or at least one of the specified subject + * alternative names. The behavior is specified by + * {@link #getMatchAllSubjectAltNames}. + * </p> + * <p> + * The specified parameter {@code names} is a collection with an entry for + * each name to be included in the criterion. The name is specified as a + * {@code List}, the first entry must be an {@code Integer} specifying the + * name type (0-8), the second entry must be a {@code String} or a byte + * array specifying the name (in string or ASN.1 DER encoded form) + * </p> + * + * @param names + * the names collection or {@code null} to not perform this check. + * @throws IOException + * if the decoding of a name fails. + * @since Android 1.0 */ public void setSubjectAlternativeNames(Collection<List<?>> names) throws IOException { @@ -509,7 +736,15 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Adds a subject alternative name to the respective criterion. + * + * @param tag + * the type of the name + * @param name + * the name in string format. + * @throws IOException + * if parsing the name fails. + * @since Android 1.0 */ public void addSubjectAlternativeName(int tag, String name) throws IOException { @@ -525,7 +760,15 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Adds a subject alternative name to the respective criterion. + * + * @param tag + * the type of the name. + * @param name + * the name in ASN.1 DER encoded form. + * @throws IOException + * if the decoding of the name fails. + * @since Android 1.0 */ public void addSubjectAlternativeName(int tag, byte[] name) throws IOException { @@ -541,7 +784,21 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for subject alternative names. + * <p> + * the certificate must contain all or at least one of the specified subject + * alternative names. The behavior is specified by + * {@link #getMatchAllSubjectAltNames}. + * </p> + * <p> + * The subject alternative names is a collection with an entry for each name + * included in the criterion. The name is specified as a {@code List}, the + * first entry is an {@code Integer} specifying the name type (0-8), the + * second entry is byte array specifying the name in ASN.1 DER encoded form) + * </p> + * + * @return the names collection or {@code null} if none specified. + * @since Android 1.0 */ public Collection<List<?>> getSubjectAlternativeNames() { if (subjectAltNames == null) { @@ -569,7 +826,49 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the name constraints. + * <p> + * The certificate must constraint subject and subject alternative names + * that match the specified name constraints. + * </p> + * <p> + * The name constraints in ASN.1: + * + * <pre> + * NameConstraints ::= SEQUENCE { + * permittedSubtrees [0] GeneralSubtrees OPTIONAL, + * excludedSubtrees [1] GeneralSubtrees OPTIONAL } + * + * GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree + * + * GeneralSubtree ::= SEQUENCE { + * base GeneralName, + * minimum [0] BaseDistance DEFAULT 0, + * maximum [1] BaseDistance OPTIONAL } + * + * BaseDistance ::= INTEGER (0..MAX) + * + * GeneralName ::= CHOICE { + * otherName [0] OtherName, + * rfc822Name [1] IA5String, + * dNSName [2] IA5String, + * x400Address [3] ORAddress, + * directoryName [4] Name, + * ediPartyName [5] EDIPartyName, + * uniformResourceIdentifier [6] IA5String, + * iPAddress [7] OCTET STRING, + * registeredID [8] OBJECT IDENTIFIER} + * + * </pre> + * + * </p> + * + * @param bytes + * the name constraints in ASN.1 DER encoded format, or null to + * not check any constraints. + * @throws IOException + * if decoding the name constraints fail. + * @since Android 1.0 */ public void setNameConstraints(byte[] bytes) throws IOException { this.nameConstraints = (bytes == null) @@ -578,7 +877,11 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the name constraints. + * + * @return the name constraints or {@code null} if none specified. + * @see #setNameConstraints + * @since Android 1.0 */ public byte[] getNameConstraints() { return (nameConstraints == null) @@ -587,7 +890,19 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the basic constraints extension. + * <p> + * A value greater than or equal to zero indicates that a certificate must + * include a basic constraints extension with a path length of a least that + * value. A value of {@code -2} indicates that only end-entity certificates + * are accepted. A value of {@code -1} indicates that no check is done. + * </p> + * + * @param pathLen + * the value specifying the criterion. + * @since Android 1.0 + * @throws IllegalArgumentException + * if {@code pathLen} is less than {@code -2}. */ public void setBasicConstraints(int pathLen) { if (pathLen < -2) { @@ -597,14 +912,35 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the basic constraints extension. + * <p> + * A value greater than or equal to zero indicates that a certificate must + * include a basic constraints extension with a path length of a least that + * value. A value of {@code -2} indicates that only end-entity certificates + * are accepted. A value of {@code -1} indicates that no check is done. + * </p> + * + * @return the value of the criterion. + * @since Android 1.0 */ public int getBasicConstraints() { return pathLen; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the policy constraint. + * <p> + * The certificate must have at least one of the specified certificate + * policy extensions. For an empty set the certificate must have at least + * some policies in its policy extension. + * </p> + * + * @param policies + * the certificate policy OIDs, an empty set, or {@code null} to + * not perform this check. + * @throws IOException + * if parsing the specified OIDs fails. + * @since Android 1.0 */ public void setPolicy(Set<String> policies) throws IOException { if (policies == null) { @@ -622,14 +958,41 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the policy constraint. + * <p> + * The certificate must have at least one of the certificate policy + * extensions. For an empty set the certificate must have at least some + * policies in its policy extension. + * </p> + * + * @return the certificate policy OIDs, an empty set, or {@code null} if not + * to be checked. + * @since Android 1.0 */ public Set<String> getPolicy() { return policies; } /** - * @com.intel.drl.spec_ref + * Sets the criterion for the pathToNames constraint. + * <p> + * This allows to specify the complete set of names, a certificate's name + * constraints must permit. + * </p> + * <p> + * The specified parameter {@code names} is a collection with an entry for + * each name to be included in the criterion. The name is specified as a + * {@code List}, the first entry must be an {@code Integer} specifying the + * name type (0-8), the second entry must be a {@code String} or a byte + * array specifying the name (in string or ASN.1 DER encoded form) + * </p> + * + * @param names + * the names collection or {@code null} to not perform this + * check. + * @throws IOException + * if decoding fails. + * @since Android 1.0 */ public void setPathToNames(Collection<List<?>> names) throws IOException { @@ -653,7 +1016,16 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Adds a {@literal "pathToName"} to the respective criterion. + * + * @param type + * the type of the name. + * @param name + * the name in string format. + * @throws IOException + * if parsing fails. + * @see #setPathToNames + * @since Android 1.0 */ public void addPathToName(int type, String name) throws IOException { GeneralName path_name = new GeneralName(type, name); @@ -665,7 +1037,16 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Adds a {@literal "pathToName"} to the respective criterion. + * + * @param type + * the type of the name + * @param name + * the name in ASN.1 DER encoded form. + * @throws IOException + * if decoding fails. + * @see #setPathToNames + * @since Android 1.0 */ public void addPathToName(int type, byte[] name) throws IOException { GeneralName path_name= new GeneralName(type, name); @@ -677,7 +1058,16 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns the criterion for the pathToNames constraint. + * <p> + * The constraint is a collection with an entry for each name to be included + * in the criterion. The name is specified as a {@code List}, the first + * entry is an {@code Integer} specifying the name type (0-8), the second + * entry is a byte array specifying the name in ASN.1 DER encoded form. + * </p> + * + * @return the pathToNames constraint or {@code null} if none specified. + * @since Android 1.0 */ public Collection<List<?>> getPathToNames() { if (pathToNames == null) { @@ -693,7 +1083,12 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns a string representation of this {@code X509CertSelector} + * instance. + * + * @return a string representation of this {@code X509CertSelector} + * instance. + * @since Android 1.0 */ public String toString() { // For convenient reading of the string representation @@ -813,7 +1208,14 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified certificate matches all the criteria + * collected in this instance. + * + * @param certificate + * the certificate to check. + * @return {@code true} if the certificate matches all the criteria, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean match(Certificate certificate) { if (! (certificate instanceof X509Certificate)) { @@ -1049,7 +1451,10 @@ public class X509CertSelector implements CertSelector { } /** - * @com.intel.drl.spec_ref + * Clones this {@code X509CertSelector} instance. + * + * @return the cloned instance. + * @since Android 1.0 */ public Object clone() { X509CertSelector result = new X509CertSelector(); diff --git a/security/src/main/java/java/security/cert/X509Certificate.java b/security/src/main/java/java/security/cert/X509Certificate.java index aa3d7a5..9e10077 100644 --- a/security/src/main/java/java/security/cert/X509Certificate.java +++ b/security/src/main/java/java/security/cert/X509Certificate.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package java.security.cert; import java.io.ByteArrayInputStream; @@ -34,7 +29,46 @@ import javax.security.auth.x500.X500Principal; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * Abstract base class for X.509 certificates. + * <p> + * This represents a standard way for accessing the attributes of X.509 + * certificates. + * </p> + * <p> + * The basic X.509 v3 format described in ASN.1: + * + * <pre> + * Certificate ::= SEQUENCE { + * tbsCertificate TBSCertificate, + * signatureAlgorithm AlgorithmIdentifier, + * signature BIT STRING } + * + * TBSCertificate ::= SEQUENCE { + * version [0] EXPLICIT Version DEFAULT v1, + * serialNumber CertificateSerialNumber, + * signature AlgorithmIdentifier, + * issuer Name, + * validity Validity, + * subject Name, + * subjectPublicKeyInfo SubjectPublicKeyInfo, + * issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, + * -- If present, version must be v2 or v3 + * subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, + * -- If present, version must be v2 or v3 + * extensions [3] EXPLICIT Extensions OPTIONAL + * -- If present, version must be v3 + * } + * </pre> + * </p> + * <p> + * For more information consult RFC 2459 + * "Internet X.509 Public Key Infrastructure Certificate and CRL Profile" at <a + * href + * ="http://www.ietf.org/rfc/rfc2459.txt">http://www.ietf.org/rfc/rfc2459.txt + * </a> . + * </p> + * + * @since Android 1.0 */ public abstract class X509Certificate extends Certificate implements X509Extension { @@ -42,41 +76,129 @@ public abstract class X509Certificate private static final long serialVersionUID = -2491127588187038216L; /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509Certificate}. + * + * @since Android 1.0 */ protected X509Certificate() { super("X.509"); //$NON-NLS-1$ } /** - * @com.intel.drl.spec_ref + * Checks whether the certificate is currently valid. + * <p> + * The validity defined in ASN.1: + * + * <pre> + * validity Validity + * + * Validity ::= SEQUENCE { + * notBefore CertificateValidityDate, + * notAfter CertificateValidityDate } + * + * CertificateValidityDate ::= CHOICE { + * utcTime UTCTime, + * generalTime GeneralizedTime } + * </pre> + * + * </p> + * + * @throws CertificateExpiredException + * if the certificate has expired. + * @throws CertificateNotYetValidException + * if the certificate is not yet valid. + * @since Android 1.0 */ public abstract void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException; /** - * @com.intel.drl.spec_ref + * Checks whether the certificate is valid at the specified date. + * + * @param date + * the date to check the validity against. + * @throws CertificateExpiredException + * if the certificate has expired. + * @throws CertificateNotYetValidException + * if the certificate is not yet valid. + * @see #checkValidity() + * @since Android 1.0 */ public abstract void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException; /** - * @com.intel.drl.spec_ref + * Returns the certificates {@code version} (version number). + * <p> + * The version defined is ASN.1: + * + * <pre> + * Version ::= INTEGER { v1(0), v2(1), v3(2) } + * </pre> + * + * </p> + * + * @return the version number. + * @since Android 1.0 */ public abstract int getVersion(); /** - * @com.intel.drl.spec_ref + * Returns the {@code serialNumber} of the certificate. + * <p> + * The ASN.1 definition of {@code serialNumber}: + * + * <pre> + * CertificateSerialNumber ::= INTEGER + * </pre> + * + * </p> + * + * @return the serial number. + * @since Android 1.0 */ public abstract BigInteger getSerialNumber(); /** - * @com.intel.drl.spec_ref + * Returns the {@code issuer} (issuer distinguished name) as an + * implementation specific {@code Principal} object. + * <p> + * The ASN.1 definition of {@code issuer}: + * + * <pre> + * issuer Name + * + * Name ::= CHOICE { + * RDNSequence } + * + * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName + * + * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue + * + * AttributeTypeAndValue ::= SEQUENCE { + * type AttributeType, + * value AttributeValue } + * + * AttributeType ::= OBJECT IDENTIFIER + * + * AttributeValue ::= ANY DEFINED BY AttributeType + * </pre> + * + * </p> + * <b>replaced by:</b> {@link #getIssuerX500Principal()}. + * + * @return the {@code issuer} as an implementation specific {@code + * Principal}. + * @since Android 1.0 */ public abstract Principal getIssuerDN() ; /** - * @com.intel.drl.spec_ref + * Returns the {@code issuer} (issuer distinguished name) as an {@code + * X500Principal}. + * + * @return the {@code issuer} (issuer distinguished name). + * @since Android 1.0 */ public X500Principal getIssuerX500Principal() { @@ -97,12 +219,46 @@ public abstract class X509Certificate } /** - * @com.intel.drl.spec_ref + * Returns the {@code subject} (subject distinguished name) as an + * implementation specific {@code Principal} object. + * <p> + * The ASN.1 definition of {@code subject}: + * + * <pre> + * subject Name + * + * Name ::= CHOICE { + * RDNSequence } + * + * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName + * + * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue + * + * AttributeTypeAndValue ::= SEQUENCE { + * type AttributeType, + * value AttributeValue } + * + * AttributeType ::= OBJECT IDENTIFIER + * + * AttributeValue ::= ANY DEFINED BY AttributeType + * </pre> + * + * </p> + * <p> + * <b>replaced by:</b> {@link #getSubjectX500Principal()}. + * </p> + * + * @return the {@code subject} (subject distinguished name). + * @since Android 1.0 */ public abstract Principal getSubjectDN(); /** - * @com.intel.drl.spec_ref + * Returns the {@code subject} (subject distinguished name) as an {@code + * X500Principal}. + * + * @return the {@code subject} (subject distinguished name) + * @since Android 1.0 */ public X500Principal getSubjectX500Principal() { @@ -123,58 +279,122 @@ public abstract class X509Certificate } /** - * @com.intel.drl.spec_ref + * Returns the {@code notBefore} date from the validity period of the + * certificate. + * + * @return the start of the validity period. + * @since Android 1.0 */ public abstract Date getNotBefore(); /** - * @com.intel.drl.spec_ref + * Returns the {@code notAfter} date of the validity period of the + * certificate. + * + * @return the end of the validity period. + * @since Android 1.0 */ public abstract Date getNotAfter(); /** - * @com.intel.drl.spec_ref + * Returns the {@code tbsCertificate} information from this certificate in + * DER-encoded format. + * + * @return the DER-encoded certificate information. + * @throws CertificateEncodingException + * if an error occurs in encoding + * @since Android 1.0 */ public abstract byte[] getTBSCertificate() throws CertificateEncodingException; /** - * @com.intel.drl.spec_ref + * Returns the raw signature bits from the certificate. + * + * @return the raw signature bits from the certificate. + * @since Android 1.0 */ public abstract byte[] getSignature(); /** - * @com.intel.drl.spec_ref + * Returns the name of the algorithm for the certificate signature. + * + * @return the signature algorithm name. + * @since Android 1.0 */ public abstract String getSigAlgName(); /** - * @com.intel.drl.spec_ref + * Returns the OID of the signature algorithm from the certificate. + * + * @return the OID of the signature algorithm. + * @since Android 1.0 */ public abstract String getSigAlgOID(); /** - * @com.intel.drl.spec_ref + * Returns the parameters of the signature algorithm in DER-encoded format. + * + * @return the parameters of the signature algorithm, or {@code null} if + * none are used. + * @since Android 1.0 */ public abstract byte[] getSigAlgParams(); /** - * @com.intel.drl.spec_ref + * Returns the {@code issuerUniqueID} from the certificate. + * + * @return the {@code issuerUniqueID} or {@code null} if there's none in the + * certificate. + * @since Android 1.0 */ public abstract boolean[] getIssuerUniqueID(); /** - * @com.intel.drl.spec_ref + * Returns the {@code subjectUniqueID} from the certificate. + * + * @return the {@code subjectUniqueID} or null if there's none in the + * certificate. + * @since Android 1.0 */ public abstract boolean[] getSubjectUniqueID(); /** - * @com.intel.drl.spec_ref + * Returns the {@code KeyUsage} extension as a {@code boolean} array. + * <p> + * The ASN.1 definition of {@code KeyUsage}: + * + * <pre> + * KeyUsage ::= BIT STRING { + * digitalSignature (0), + * nonRepudiation (1), + * keyEncipherment (2), + * dataEncipherment (3), + * keyAgreement (4), + * keyCertSign (5), + * cRLSign (6), + * encipherOnly (7), + * decipherOnly (8) } + * + * </pre> + * + * </p> + * + * @return the {@code KeyUsage} extension or {@code null} if there's none in + * the certificate. + * @since Android 1.0 */ public abstract boolean[] getKeyUsage(); /** - * @com.intel.drl.spec_ref + * Returns a read-only list of OID strings representing the {@code + * ExtKeyUsageSyntax} field of the extended key usage extension. + * + * @return the extended key usage extension, or {@code null} if there's none + * in the certificate. + * @throws CertificateParsingException + * if the extension decoding fails. + * @since Android 1.0 */ public List<String> getExtendedKeyUsage() throws CertificateParsingException { @@ -182,12 +402,47 @@ public abstract class X509Certificate } /** - * @com.intel.drl.spec_ref + * Returns the path length of the certificate constraints from the {@code + * BasicContraints} extension. + * + * @return the path length of the certificate constraints if the extension + * is present or {@code -1} if the extension is not present. {@code + * Integer.MAX_VALUE} if there's not limit. + * @since Android 1.0 */ public abstract int getBasicConstraints(); /** - * @com.intel.drl.spec_ref + * Returns a read-only list of the subject alternative names from the + * {@code SubjectAltName} extension. + * <p> + * The ASN.1 definition of {@code SubjectAltName}: + * + * <pre> + * SubjectAltName ::= GeneralNames + * + * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName + * + * GeneralName ::= CHOICE { + * otherName [0] AnotherName, + * rfc822Name [1] IA5String, + * dNSName [2] IA5String, + * x400Address [3] ORAddress, + * directoryName [4] Name, + * ediPartyName [5] EDIPartyName, + * uniformResourceIdentifier [6] IA5String, + * iPAddress [7] OCTET STRING, + * registeredID [8] OBJECT IDENTIFIER } + * + * </pre> + * + * </p> + * + * @return the subject alternative names or {@code null} if there are none + * in the certificate. + * @throws CertificateParsingException + * if decoding of the extension fails. + * @since Android 1.0 */ public Collection<List<?>> getSubjectAlternativeNames() throws CertificateParsingException { @@ -195,7 +450,36 @@ public abstract class X509Certificate } /** - * @com.intel.drl.spec_ref + * Returns a read-only list of the issuer alternative names from the {@code + * IssuerAltName} extension. + * <p> + * The ASN.1 definition of {@code IssuerAltName}: + * + * <pre> + * IssuerAltName ::= GeneralNames + * + * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName + * + * GeneralName ::= CHOICE { + * otherName [0] AnotherName, + * rfc822Name [1] IA5String, + * dNSName [2] IA5String, + * x400Address [3] ORAddress, + * directoryName [4] Name, + * ediPartyName [5] EDIPartyName, + * uniformResourceIdentifier [6] IA5String, + * iPAddress [7] OCTET STRING, + * registeredID [8] OBJECT IDENTIFIER } + * + * </pre> + * + * </p> + * + * @return the issuer alternative names of {@code null} if there are none in + * the certificate. + * @throws CertificateParsingException + * if decoding of the extension fails. + * @since Android 1.0 */ public Collection<List<?>> getIssuerAlternativeNames() throws CertificateParsingException { diff --git a/security/src/main/java/java/security/cert/X509Extension.java b/security/src/main/java/java/security/cert/X509Extension.java index 416fe44..cc8648b 100644 --- a/security/src/main/java/java/security/cert/X509Extension.java +++ b/security/src/main/java/java/security/cert/X509Extension.java @@ -15,38 +15,58 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.cert; import java.util.Set; /** - * @com.intel.drl.spec_ref + * The interface specifying an X.509 Certificate or CRL extension. * + * @since Android 1.0 */ public interface X509Extension { /** - * @com.intel.drl.spec_ref + * Returns the set of OIDs of the extension(s) marked as CRITICAL, that this + * implementation manages. + * + * @return the set of extension OIDs marked as CRITIAL, an empty set if none + * are marked as CRITICAL, or {@code null} if no extensions are + * present. + * @since Android 1.0 */ public Set<String> getCriticalExtensionOIDs(); /** - * @com.intel.drl.spec_ref + * Returns the extension value as DER-encoded OCTET string for the specified + * OID. + * + * @param oid + * the object identifier to get the extension value for. + * @return the extension value as DER-encoded OCTET string, or {@code null} + * if no extension for the specified OID can be found. + * @since Android 1.0 */ public byte[] getExtensionValue(String oid); /** - * @com.intel.drl.spec_ref + * Returns the set of OIDs of the extension(s) marked as NON-CRITICAL, that + * this implementation manages. + * + * @return the set of extension OIDs marked as NON-CRITIAL, an empty set if + * none are marked as NON-.CRITICAL, or {@code null} if no + * extensions are present. + * @since Android 1.0 */ public Set<String> getNonCriticalExtensionOIDs(); /** - * @com.intel.drl.spec_ref + * Returns whether this instance has an extension marked as CRITICAL that it + * cannot support. + * + * @return {@code true} if an unsupported CRITICAL extension is present, + * {@code false} otherwise. + * @since Android 1.0 */ public boolean hasUnsupportedCriticalExtension(); } diff --git a/security/src/main/java/java/security/cert/package.html b/security/src/main/java/java/security/cert/package.html index 4212857..e3cc92b 100644 --- a/security/src/main/java/java/security/cert/package.html +++ b/security/src/main/java/java/security/cert/package.html @@ -9,12 +9,15 @@ This package provides all the classes and all the interfaces needed to generate, X.509 certificates. Functionality for parsing certificate, extracting information from them, validating and verifying the information they contains are provided. -Exception are generated if the certificate's encoding is broken -{@link java.security.cert.CertificateEncodingException}, if the certificate's time stamp is not valid -{@link java.security.cert.CertificateExpiredException}, if the validation's path is false -{@link java.security.cert.CertPathValidatorException}. - -All the the functionality to check the different entries and extension fields of X.509 certificates are provided. +Exception are generated mainly for three reasons:<br> +- if the certificate's encoding is broken +(CertificateEncodingException)<br> +- if the certificate's time stamp is not valid +(CertificateExpiredException)<br> +- or if the validation's path is false (CertPathValidatorException). +</p><p> +The functionality to check the different entries and extension fields of X.509 certificates are also provided. </p> +@since Android 1.0 </body> </html> diff --git a/security/src/main/java/java/security/interfaces/DSAKey.java b/security/src/main/java/java/security/interfaces/DSAKey.java index 0c443db..1362bff 100644 --- a/security/src/main/java/java/security/interfaces/DSAKey.java +++ b/security/src/main/java/java/security/interfaces/DSAKey.java @@ -15,21 +15,22 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ package java.security.interfaces; /** - * @com.intel.drl.spec_ref + * The base interface for Digital Signature Algorithm (DSA) public or private + * keys. * + * @since Android 1.0 */ public interface DSAKey { + /** - * @com.intel.drl.spec_ref - * + * Returns the DSA key parameters. + * + * @return the DSA key parameters. + * @since Android 1.0 */ public DSAParams getParams(); diff --git a/security/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java b/security/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java index c2a2dfb..4b89c6a 100644 --- a/security/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java +++ b/security/src/main/java/java/security/interfaces/DSAKeyPairGenerator.java @@ -15,31 +15,57 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.security.InvalidParameterException; import java.security.SecureRandom; /** - * @com.intel.drl.spec_ref + * The interface for key generators that can generate DSA key pairs. * + * @since Android 1.0 */ public interface DSAKeyPairGenerator { + /** - * @com.intel.drl.spec_ref - * + * Initializes this generator with the prime ({@code p}), subprime ({@code + * q}), and base ({@code g}) values from the specified parameters. + * + * @param params + * the parameter values. + * @param random + * the source of randomness. + * @throws InvalidParameterException + * if the specified parameter values are {@code null} or + * invalid. + * @since Android 1.0 */ public void initialize(DSAParams params, SecureRandom random) throws InvalidParameterException; /** - * @com.intel.drl.spec_ref - * + * Initializes this generator for the specified modulus length. Valid values + * for the modulus length are the multiples of 8 between 512 and 1024. + * <p> + * The parameter {@code genParams} specifies whether this method should + * generate new prime ({@code p}), subprime ({@code q}), and base ({@code g}) + * values or whether + * it will use the pre-calculated values for the specified modulus + * length. Default parameters are available for modulus lengths of 512 and 1024 + * bits. + * </p> + * + * @param modlen + * the length of the modulus in bits. + * @param genParams + * whether new values should be generated. + * @param random + * the source of randomness. + * @throws InvalidParameterException + * if the specified modulus length is not valid, or if there are + * no pre-calculated values and {@code genParams} is {@code + * false}. + * @since Android 1.0 */ public void initialize(int modlen, boolean genParams, SecureRandom random) throws InvalidParameterException; diff --git a/security/src/main/java/java/security/interfaces/DSAParams.java b/security/src/main/java/java/security/interfaces/DSAParams.java index 3da9236..0483da2 100644 --- a/security/src/main/java/java/security/interfaces/DSAParams.java +++ b/security/src/main/java/java/security/interfaces/DSAParams.java @@ -15,36 +15,38 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The interface for Digital Signature Algorithm (DSA) specific parameters. * + * @since Android 1.0 */ public interface DSAParams { /** - * @com.intel.drl.spec_ref - * + * Returns the base ({@code g}) value. + * + * @return the base ({@code g}) value. + * @since Android 1.0 */ public BigInteger getG(); /** - * @com.intel.drl.spec_ref - * + * Returns the prime ({@code p}) value. + * + * @return the prime ({@code p}) value. + * @since Android 1.0 */ public BigInteger getP(); /** - * @com.intel.drl.spec_ref - * + * Returns the subprime ({@code q} value. + * + * @return the subprime ({@code q} value. + * @since Android 1.0 */ public BigInteger getQ(); diff --git a/security/src/main/java/java/security/interfaces/DSAPrivateKey.java b/security/src/main/java/java/security/interfaces/DSAPrivateKey.java index 2ad156e..e2592ca 100644 --- a/security/src/main/java/java/security/interfaces/DSAPrivateKey.java +++ b/security/src/main/java/java/security/interfaces/DSAPrivateKey.java @@ -15,30 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; import java.security.PrivateKey; /** - * @com.intel.drl.spec_ref + * The interface for a Digital Signature Algorithm (DSA) private key. * + * @since Android 1.0 */ public interface DSAPrivateKey extends DSAKey, PrivateKey { + /** - * @com.intel.drl.spec_ref - * + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = 7776497482533790279L; /** - * @com.intel.drl.spec_ref - * + * Returns the private key value {@code x}. + * + * @return the private key value {@code x}. + * @since Android 1.0 */ public BigInteger getX(); diff --git a/security/src/main/java/java/security/interfaces/DSAPublicKey.java b/security/src/main/java/java/security/interfaces/DSAPublicKey.java index 0da7beb..ccb985e 100644 --- a/security/src/main/java/java/security/interfaces/DSAPublicKey.java +++ b/security/src/main/java/java/security/interfaces/DSAPublicKey.java @@ -15,28 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; import java.security.PublicKey; /** - * @com.intel.drl.spec_ref + * The interface for a Digital Signature Algorithm (DSA) public key. * + * @since Android 1.0 */ public interface DSAPublicKey extends DSAKey, PublicKey { + /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = 1234526332779022332L; /** - * @com.intel.drl.spec_ref + * Returns the public key value {@code y}. + * + * @return the public key value {@code y}. + * @since Android 1.0 */ public BigInteger getY(); diff --git a/security/src/main/java/java/security/interfaces/ECKey.java b/security/src/main/java/java/security/interfaces/ECKey.java index 950a533..9f5d254 100644 --- a/security/src/main/java/java/security/interfaces/ECKey.java +++ b/security/src/main/java/java/security/interfaces/ECKey.java @@ -15,23 +15,22 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.security.spec.ECParameterSpec; /** - * @com.intel.drl.spec_ref + * The base interface for Elliptic Curve (EC) public or private keys. * + * @since Android 1.0 */ public interface ECKey { + /** - * @com.intel.drl.spec_ref - * + * Returns the EC key parameters. + * + * @return the EC key parameters. + * @since Android 1.0 */ public ECParameterSpec getParams(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/ECPrivateKey.java b/security/src/main/java/java/security/interfaces/ECPrivateKey.java index fcd18be..74ef4c2 100644 --- a/security/src/main/java/java/security/interfaces/ECPrivateKey.java +++ b/security/src/main/java/java/security/interfaces/ECPrivateKey.java @@ -15,28 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; import java.security.PrivateKey; /** - * @com.intel.drl.spec_ref + * The interface for an Elliptic Curve (EC) private key. * + * @since Android 1.0 */ public interface ECPrivateKey extends PrivateKey, ECKey { + /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = -7896394956925609184L; /** - * @com.intel.drl.spec_ref + * Returns the private value {@code S}. + * + * @return the private value {@code S}. + * @since Android 1.0 */ public BigInteger getS(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/ECPublicKey.java b/security/src/main/java/java/security/interfaces/ECPublicKey.java index d138037..063dfe9 100644 --- a/security/src/main/java/java/security/interfaces/ECPublicKey.java +++ b/security/src/main/java/java/security/interfaces/ECPublicKey.java @@ -15,28 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.security.spec.ECPoint; import java.security.PublicKey; /** - * @com.intel.drl.spec_ref + * The interface for an Elliptic Curve (EC) public key. * + * @since Android 1.0 */ public interface ECPublicKey extends PublicKey, ECKey { + /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = -3314988629879632826L; /** - * @com.intel.drl.spec_ref + * Returns the public point {@code W} on an elliptic curve (EC). + * + * @return the public point {@code W} on an elliptic curve (EC). + * @since Android 1.0 */ public ECPoint getW(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/RSAKey.java b/security/src/main/java/java/security/interfaces/RSAKey.java index fe34977..bc0877e 100644 --- a/security/src/main/java/java/security/interfaces/RSAKey.java +++ b/security/src/main/java/java/security/interfaces/RSAKey.java @@ -15,22 +15,22 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The base interface for PKCS#1 RSA public and private keys. * + * @since Android 1.0 */ public interface RSAKey { + /** - * @com.intel.drl.spec_ref + * Returns the modulus. + * + * @return the modulus. + * @since Android 1.0 */ public BigInteger getModulus(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java b/security/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java index 5cdf0e1..c5e86c3 100644 --- a/security/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java +++ b/security/src/main/java/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java @@ -15,58 +15,81 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; import java.security.spec.RSAOtherPrimeInfo; /** - * @com.intel.drl.spec_ref + * The interface for a Multi-Prime RSA private key. Specified by <a + * href="http://www.rsa.com/rsalabs/node.asp?id=2125">PKCS #1 v2.0 Amendment 1: + * Multi-Prime RSA</a>. * + * @since Android 1.0 */ public interface RSAMultiPrimePrivateCrtKey extends RSAPrivateKey { + /** - * @com.intel.drl.spec_ref + * the serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = 618058533534628008L; /** - * @com.intel.drl.spec_ref + * Returns the CRT coefficient, {@code q^-1 mod p}. + * + * @return the CRT coefficient. + * @since Android 1.0 */ public BigInteger getCrtCoefficient(); /** - * @com.intel.drl.spec_ref + * Returns the information for the additional primes. + * + * @return the information for the additional primes, or {@code null} if + * there are only the two primes ({@code p, q}), + * @since Android 1.0 */ public RSAOtherPrimeInfo[] getOtherPrimeInfo(); /** - * @com.intel.drl.spec_ref + * Returns the prime factor {@code p} of {@code n}. + * + * @return the prime factor {@code p} of {@code n}. + * @since Android 1.0 */ public BigInteger getPrimeP(); /** - * @com.intel.drl.spec_ref + * Returns the prime factor {@code q} of {@code n}. + * + * @return the prime factor {@code q} of {@code n}. + * @since Android 1.0 */ public BigInteger getPrimeQ(); /** - * @com.intel.drl.spec_ref + * Returns the CRT exponent of the prime {@code p}. + * + * @return the CRT exponent of the prime {@code p}. + * @since Android 1.0 */ public BigInteger getPrimeExponentP(); /** - * @com.intel.drl.spec_ref + * Returns the CRT exponent of the prime {@code q}. + * + * @return the CRT exponent of the prime {@code q}. + * @since Android 1.0 */ public BigInteger getPrimeExponentQ(); /** - * @com.intel.drl.spec_ref + * Returns the public exponent {@code e}. + * + * @return the public exponent {@code e}. + * @since Android 1.0 */ public BigInteger getPublicExponent(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java b/security/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java index 9f11582..48d70ce 100644 --- a/security/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java +++ b/security/src/main/java/java/security/interfaces/RSAPrivateCrtKey.java @@ -15,59 +15,69 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The interface for a PKCS#1 RSA private key using CRT information values. * + * @since Android 1.0 */ public interface RSAPrivateCrtKey extends RSAPrivateKey { /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = -5682214253527700368L; /** - * @com.intel.drl.spec_ref - * + * Returns the CRT coefficient, {@code q^-1 mod p}. + * + * @return the CRT coefficient. + * @since Android 1.0 */ public BigInteger getCrtCoefficient(); /** - * @com.intel.drl.spec_ref - * + * Returns the prime factor {@code p} of {@code n}. + * + * @return the prime factor {@code p} of {@code n}. + * @since Android 1.0 */ public BigInteger getPrimeP(); /** - * @com.intel.drl.spec_ref - * + * Returns the prime factor {@code q} of {@code n}. + * + * @return the prime factor {@code q} of {@code n}. + * @since Android 1.0 */ public BigInteger getPrimeQ(); /** - * @com.intel.drl.spec_ref - * + * Returns the CRT exponent of the primet {@code p}. + * + * @return the CRT exponent of the prime {@code p}. + * @since Android 1.0 */ public BigInteger getPrimeExponentP(); /** - * @com.intel.drl.spec_ref - * + * Returns the CRT exponent of the prime {@code q}. + * + * @return the CRT exponent of the prime {@code q}. + * @since Android 1.0 */ public BigInteger getPrimeExponentQ(); /** - * @com.intel.drl.spec_ref - * + * Returns the public exponent {@code e}. + * + * @return the public exponent {@code e}. + * @since Android 1.0 */ public BigInteger getPublicExponent(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/RSAPrivateKey.java b/security/src/main/java/java/security/interfaces/RSAPrivateKey.java index 707d0c2..041a1e3 100644 --- a/security/src/main/java/java/security/interfaces/RSAPrivateKey.java +++ b/security/src/main/java/java/security/interfaces/RSAPrivateKey.java @@ -15,29 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; import java.security.PrivateKey; /** - * @com.intel.drl.spec_ref + * The interface for an PKCS#1 RSA private key. * + * @since Android 1.0 */ public interface RSAPrivateKey extends PrivateKey, RSAKey { + /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = 5187144804936595022L; /** - * @com.intel.drl.spec_ref - * + * Returns the private exponent {@code d}. + * + * @return the private exponent {@code d}. + * @since Android 1.0 */ public BigInteger getPrivateExponent(); }
\ No newline at end of file diff --git a/security/src/main/java/java/security/interfaces/RSAPublicKey.java b/security/src/main/java/java/security/interfaces/RSAPublicKey.java index 7a87826..b13b1aa 100644 --- a/security/src/main/java/java/security/interfaces/RSAPublicKey.java +++ b/security/src/main/java/java/security/interfaces/RSAPublicKey.java @@ -15,29 +15,30 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.interfaces; import java.math.BigInteger; import java.security.PublicKey; /** - * @com.intel.drl.spec_ref + * The interface for a PKCS#1 RSA public key. * + * @since Android 1.0 */ public interface RSAPublicKey extends PublicKey, RSAKey { + /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ public static final long serialVersionUID = -8727434096241101194L; /** - * @com.intel.drl.spec_ref - * + * Returns the public exponent {@code e}. + * + * @return the public exponent {@code e}. + * @since Android 1.0 */ public BigInteger getPublicExponent(); diff --git a/security/src/main/java/java/security/interfaces/package.html b/security/src/main/java/java/security/interfaces/package.html index d2772a6..6f14de1 100644 --- a/security/src/main/java/java/security/interfaces/package.html +++ b/security/src/main/java/java/security/interfaces/package.html @@ -10,5 +10,6 @@ This package provides the interfaces needed to generate: (2) Keys for the Digital Signature Algorithm (DSA) specified by FIPS-186; (3) Keys for a generic Elliptic Curve asymmetric encryption algorithm. </p> +@since Android 1.0 </body> </html>
\ No newline at end of file diff --git a/security/src/main/java/java/security/package.html b/security/src/main/java/java/security/package.html index 6a87bc3..b4f450e 100644 --- a/security/src/main/java/java/security/package.html +++ b/security/src/main/java/java/security/package.html @@ -4,12 +4,33 @@ </head> <html> <body> -<p> -This package provides all the classes and all the interfaces needed by Java security framework. -Functionality for signing jar files Class {@link java.security.Signer}; for generating -public and private key for asymmetric encryption algorithm {@link java.security.PublicKey} and -{@link java.security.PrivateKey} are provided. -All the the functionality to expand the priviledges within the AccessController are also defined here. +<p>This package provides all the classes and interfaces that +constitute the Java security framework. The content of this package can +be divided into two parts: + +<ul> + <li>Classes implementing the access control infrastructure. + <p>The central class is <i>java.security.AccessController</i> + which checks if code, invoking sensitive resources, was granted the required + permissions. + <p>The class loader (<i>java.security.SecureClassLoader</i>) associates classes + with a protection domain (<i>java.security.ProtectionDomain</i>) which consists of a + code source (<i>java.security.CodeSource</i>) and the granted permissions + (<i>java.security.Permission</i>). The policy, defined through <i>java.security.Policy</i>, defines + which permissions are granted to classes loaded from a code source ( class + <i>java.security.CodeSource</i>). + <li>Classes and interfaces for the extensible cryptographic + <i>service provider infrastructure</i> (<b>SPI</b>) such as abstractions for certificates, + signatures, private and public keys. Also abstractions for the algorithms + they utilize are provided in this package. + <p>Security providers, as defined in <i>java.security.Providers</i>, can be + registered to provide + different implementations for a variety of security infrastructure, + such as key stores. Therefore the corresponding + service provider interface (i.e. <i>java.security.KeyStoreSpi</i>) must be + implemented. +</ul> </p> +@since Android 1.0 </body> </html> diff --git a/security/src/main/java/java/security/spec/AlgorithmParameterSpec.java b/security/src/main/java/java/security/spec/AlgorithmParameterSpec.java index 0f1df72..32c7a3a 100644 --- a/security/src/main/java/java/security/spec/AlgorithmParameterSpec.java +++ b/security/src/main/java/java/security/spec/AlgorithmParameterSpec.java @@ -15,16 +15,13 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.spec; /** - * @com.intel.drl.spec_ref + * The marker interface for algorithm parameter specifications. The purpose is + * to group parameter specifications for algorithms. * + * @since Android 1.0 */ public interface AlgorithmParameterSpec { }
\ No newline at end of file diff --git a/security/src/main/java/java/security/spec/DSAParameterSpec.java b/security/src/main/java/java/security/spec/DSAParameterSpec.java index c331c1f..5465b5b 100644 --- a/security/src/main/java/java/security/spec/DSAParameterSpec.java +++ b/security/src/main/java/java/security/spec/DSAParameterSpec.java @@ -15,19 +15,15 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; import java.security.interfaces.DSAParams; /** - * @com.intel.drl.spec_ref + * The parameter specification used with the Digital Signature Algorithm (DSA). * + * @since Android 1.0 */ public class DSAParameterSpec implements AlgorithmParameterSpec, DSAParams { // Prime @@ -38,7 +34,16 @@ public class DSAParameterSpec implements AlgorithmParameterSpec, DSAParams { private final BigInteger g; /** - * @com.intel.drl.spec_ref + * Creates a new {@code DSAParameterSpec} with the specified prime {@code p}, + * sub-prime {@code q} and the base {@code g}. + * + * @param p + * the prime {@code p}. + * @param q + * the sub-prime {@code q}. + * @param g + * the base {@code g}; + * @since Android 1.0 */ public DSAParameterSpec(BigInteger p, BigInteger q, BigInteger g) { this.p = p; @@ -47,21 +52,29 @@ public class DSAParameterSpec implements AlgorithmParameterSpec, DSAParams { } /** - * @com.intel.drl.spec_ref + * Returns the base {@code g}. + * + * @return the base {@code g}. + * @since Android 1.0 */ public BigInteger getG() { return g; } /** - * @com.intel.drl.spec_ref + * Returns the prime {@code p}. + * + * @return the prime {@code p}. + * @since Android 1.0 */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns the sub-prime {@code q}. + * @return the sub-prime {@code q}. + * @since Android 1.0 */ public BigInteger getQ() { return q; diff --git a/security/src/main/java/java/security/spec/DSAPrivateKeySpec.java b/security/src/main/java/java/security/spec/DSAPrivateKeySpec.java index d095eaa..3b692c8 100644 --- a/security/src/main/java/java/security/spec/DSAPrivateKeySpec.java +++ b/security/src/main/java/java/security/spec/DSAPrivateKeySpec.java @@ -15,18 +15,14 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The parameters specifying a DSA private key. * + * @since Android 1.0 */ public class DSAPrivateKeySpec implements KeySpec { // Private key @@ -39,7 +35,18 @@ public class DSAPrivateKeySpec implements KeySpec { private final BigInteger g; /** - * @com.intel.drl.spec_ref + * Creates a new {@code DSAPrivateKeySpec} with the specified private key, + * prime, sub-prime and base. + * + * @param x + * the private key {@code x}. + * @param p + * the prime {@code p}. + * @param q + * the sub-prime {@code q}. + * @param g + * the base {@code g}. + * @since Android 1.0 */ public DSAPrivateKeySpec(BigInteger x, BigInteger p, BigInteger q, BigInteger g) { @@ -50,28 +57,40 @@ public class DSAPrivateKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the base {@code g}. + * + * @return the base {@code g}. + * @since Android 1.0 */ public BigInteger getG() { return g; } /** - * @com.intel.drl.spec_ref + * Returns the prime {@code p}. + * + * @return the prime {@code p}. + * @since Android 1.0 */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns the sub-prime {@code q}. + * + * @return the sub-prime {@code q}. + * @since Android 1.0 */ public BigInteger getQ() { return q; } /** - * @com.intel.drl.spec_ref + * Returns the private key {@code x}. + * + * @return the private key {@code x}. + * @since Android 1.0 */ public BigInteger getX() { return x; diff --git a/security/src/main/java/java/security/spec/DSAPublicKeySpec.java b/security/src/main/java/java/security/spec/DSAPublicKeySpec.java index e37430d..95d1141 100644 --- a/security/src/main/java/java/security/spec/DSAPublicKeySpec.java +++ b/security/src/main/java/java/security/spec/DSAPublicKeySpec.java @@ -15,18 +15,14 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The parameters specifying a DSA public key. * + * @since Android 1.0 */ public class DSAPublicKeySpec implements KeySpec { // Public key @@ -39,7 +35,18 @@ public class DSAPublicKeySpec implements KeySpec { private final BigInteger g; /** - * @com.intel.drl.spec_ref + * Creates a new {@code DSAPublicKeySpec} with the specified public key, + * prime, sub-prime and base. + * + * @param y + * the public key value {@code y}. + * @param p + * the prime {@code p}. + * @param q + * the sub-prime {@code q}. + * @param g + * the base {@code g}. + * @since Android 1.0 */ public DSAPublicKeySpec(BigInteger y, BigInteger p, BigInteger q, BigInteger g) { @@ -50,28 +57,40 @@ public class DSAPublicKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the base {@code g}. + * + * @return the base {@code g}. + * @since Android 1.0 */ public BigInteger getG() { return g; } /** - * @com.intel.drl.spec_ref + * Returns the prime {@code p}. + * + * @return the prime {@code p}. + * @since Android 1.0 */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns the sub-prime {@code q}. + * + * @return the sub-prime {@code q}. + * @since Android 1.0 */ public BigInteger getQ() { return q; } /** - * @com.intel.drl.spec_ref + * Returns the public key value {@code y}. + * + * @return the public key value {@code y}. + * @since Android 1.0 */ public BigInteger getY() { return y; diff --git a/security/src/main/java/java/security/spec/ECField.java b/security/src/main/java/java/security/spec/ECField.java index 22109a3..74a5eb8 100644 --- a/security/src/main/java/java/security/spec/ECField.java +++ b/security/src/main/java/java/security/spec/ECField.java @@ -15,21 +15,20 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; /** - * @com.intel.drl.spec_ref + * The base interface for a Finite Field of an Elliptic Curve. * + * @since Android 1.0 */ public interface ECField { /** - * @com.intel.drl.spec_ref + * Returns the size of the field (in bits). + * + * @return the size of the field (in bits). + * @since Android 1.0 */ int getFieldSize(); } diff --git a/security/src/main/java/java/security/spec/ECFieldF2m.java b/security/src/main/java/java/security/spec/ECFieldF2m.java index a2f13b1..d68378b 100644 --- a/security/src/main/java/java/security/spec/ECFieldF2m.java +++ b/security/src/main/java/java/security/spec/ECFieldF2m.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -28,8 +23,10 @@ import java.util.Arrays; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameters specifying a <i>characteristic 2 finite field</i> of an + * elliptic curve. * + * @since Android 1.0 */ public class ECFieldF2m implements ECField { // Mid terms array length for trinomial basis @@ -48,7 +45,14 @@ public class ECFieldF2m implements ECField { private final int[] ks; /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECFieldF2m} with {@code 2^m} elements with a normal + * basis. + * + * @param m + * the exponent {@code m} for the number of elements. + * @throws IllegalArgumentException + * if {@code m <= zero}. + * @since Android 1.0 */ public ECFieldF2m(int m) { this.m = m; @@ -60,7 +64,22 @@ public class ECFieldF2m implements ECField { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECFieldF2m} with {@code 2^m} elements with a polynomial + * basis and the reduction polynomial based on {@code rp}. + * <p> + * The reduction polynomial must be either <i>trinomial</i> or + * <i>pentanomial</i>. + * </p> + * + * @param m + * the exponent {@code m} for the number of elements. + * @param rp + * the base of the reduction polynomial with the n-th bit + * corresponding to the n-th coefficient of the reduction + * polynomial. + * @throws IllegalArgumentException + * if {@code m <= zero} or the {@code rp} is invalid. + * @since Android 1.0 */ public ECFieldF2m(int m, BigInteger rp) { this.m = m; @@ -93,7 +112,22 @@ public class ECFieldF2m implements ECField { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECFieldF2m} with {@code 2^m} elements with + * a polynomial basis and the reduction polynomial based on {@code ks}. + * <p> + * The reduction polynomial must be either <i>trinomial</i> or + * <i>pentanomial</i>. + * </p> + * + * @param m + * the exponent {@code m} for the number of elements. + * @param ks + * the base of the reduction polynomial with coefficients + * given in descending order. + * @throws IllegalArgumentException + * if {@code m <= zero} or the reduction polynomial is not + * valid. + * @since Android 1.0 */ public ECFieldF2m(int m, int[] ks) { this.m = m; @@ -142,7 +176,13 @@ public class ECFieldF2m implements ECField { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified object equals to this finite field. + * + * @param obj + * the object to compare to this finite field. + * @return {@code true} if the specified object is equal to this finite field, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object obj) { // object equals to itself @@ -171,21 +211,34 @@ public class ECFieldF2m implements ECField { } /** - * @com.intel.drl.spec_ref + * Returns the size of this finite field (in bits). + * + * @return the size of this finite field (in bits). + * @since Android 1.0 */ public int getFieldSize() { return m; } /** - * @com.intel.drl.spec_ref + * Returns the exponent {@code m} for this finite field, with {@code 2^m} as + * the number of elements. + * + * @return the exponent {@code m} for this finite field + * @since Android 1.0 */ public int getM() { return m; } /** - * @com.intel.drl.spec_ref + * Returns a copy of the integer array containing the order of the middle + * term(s) of the reduction polynomial for a polynomial basis. + * + * @return a copy of the integer array containing the order of the middle + * term(s) of the reduction polynomial for a polynomial basis or + * {@code null} for a normal basis. + * @since Android 1.0 */ public int[] getMidTermsOfReductionPolynomial() { // Defensively copies private array @@ -201,14 +254,24 @@ public class ECFieldF2m implements ECField { } /** - * @com.intel.drl.spec_ref + * Returns the base of the reduction polynomial with the n-th bit + * corresponding to the n-th coefficient of the reduction polynomial for a + * polynomial basis. + * + * @return the base of the reduction polynomial with the n-th bit + * corresponding to the n-th coefficient of the reduction polynomial + * for a polynomial basis or {@code null} for a normal basis. + * @since Android 1.0 */ public BigInteger getReductionPolynomial() { return rp; } /** - * @com.intel.drl.spec_ref + * Returns the hashcode value for this finite field. + * + * @return the hashcode value for this finite field. + * @since Android 1.0 */ public int hashCode() { return rp == null ? m : m + rp.hashCode(); diff --git a/security/src/main/java/java/security/spec/ECFieldFp.java b/security/src/main/java/java/security/spec/ECFieldFp.java index 6328ea9..d3f4ee6 100644 --- a/security/src/main/java/java/security/spec/ECFieldFp.java +++ b/security/src/main/java/java/security/spec/ECFieldFp.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -27,15 +22,24 @@ import java.math.BigInteger; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameters specifying a <i>prime finite field</i> of an + * elliptic curve. * + * @since Android 1.0 */ public class ECFieldFp implements ECField { // Prime private final BigInteger p; /** - * @com.intel.drl.spec_ref + * Creates a new prime finite field of an elliptic curve with the specified + * prime {@code p}. + * + * @param p + * the prime value {@code p}. + * @throws IllegalArgumentException + * if {@code p <= zero}. + * @since Android 1.0 */ public ECFieldFp(BigInteger p) { this.p = p; @@ -49,21 +53,33 @@ public class ECFieldFp implements ECField { } /** - * @com.intel.drl.spec_ref + * Returns the size of the finite field (in bits). + * + * @return the size of the finite field (in bits). + * @since Android 1.0 */ public int getFieldSize() { return p.bitLength(); } /** - * @com.intel.drl.spec_ref + * Returns the prime value {@code p} for this finite field. + * + * @return the prime value {@code p} for this finite field. + * @since Android 1.0 */ public BigInteger getP() { return p; } /** - * @com.intel.drl.spec_ref + * Returns whether the specified object is equal to this finite field. + * + * @param obj + * the object to compare to this finite field. + * @return {@code true} if the specified object is equal to this finite field, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object obj) { // object equals itself @@ -77,7 +93,10 @@ public class ECFieldFp implements ECField { } /** - * @com.intel.drl.spec_ref + * Returns the hashcode value for this finite field. + * + * @return the hashcode value for this finite field. + * @since Android 1.0 */ public int hashCode() { return p.hashCode(); diff --git a/security/src/main/java/java/security/spec/ECGenParameterSpec.java b/security/src/main/java/java/security/spec/ECGenParameterSpec.java index 4be5283..210b315 100644 --- a/security/src/main/java/java/security/spec/ECGenParameterSpec.java +++ b/security/src/main/java/java/security/spec/ECGenParameterSpec.java @@ -15,18 +15,14 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameter specification used to generate elliptic curve domain parameters. * + * @since Android 1.0 */ public class ECGenParameterSpec implements AlgorithmParameterSpec { // Standard (or predefined) name for EC domain @@ -34,7 +30,12 @@ public class ECGenParameterSpec implements AlgorithmParameterSpec { private final String name; /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECGenParameterSpec} with the specified standard or + * predefined name of the to-be-generated domain parameter. + * + * @param name + * the name of the elliptic curve domain parameter. + * @since Android 1.0 */ public ECGenParameterSpec(String name) { this.name = name; @@ -44,7 +45,11 @@ public class ECGenParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the name (standard or predefined) of the to-be-generated elliptic + * curve domain parameter. + * + * @return the name + * @since Android 1.0 */ public String getName() { return name; diff --git a/security/src/main/java/java/security/spec/ECParameterSpec.java b/security/src/main/java/java/security/spec/ECParameterSpec.java index f438844..e10757b 100644 --- a/security/src/main/java/java/security/spec/ECParameterSpec.java +++ b/security/src/main/java/java/security/spec/ECParameterSpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -27,8 +22,9 @@ import java.math.BigInteger; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameter specification used with Elliptic Curve Cryptography (ECC). * + * @since Android 1.0 */ public class ECParameterSpec implements AlgorithmParameterSpec { // Elliptic curve for which this is parameter @@ -41,7 +37,21 @@ public class ECParameterSpec implements AlgorithmParameterSpec { private final int cofactor; /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECParameterSpec} with the specified elliptic curve, + * the base point, the order of the generator (or base point) and the + * co-factor. + * + * @param curve + * the elliptic curve. + * @param generator + * the generator (or base point). + * @param order + * the order of the generator. + * @param cofactor + * the co-factor. + * @throws IllegalArgumentException + * if {@code order <= zero} or {@code cofactor <= zero}. + * @since Android 1.0 */ public ECParameterSpec(EllipticCurve curve, ECPoint generator, BigInteger order, int cofactor) { @@ -71,28 +81,40 @@ public class ECParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the {@code cofactor}. + * + * @return the {@code cofactor}. + * @since Android 1.0 */ public int getCofactor() { return cofactor; } /** - * @com.intel.drl.spec_ref + * Returns the elliptic curve. + * + * @return the elliptic curve. + * @since Android 1.0 */ public EllipticCurve getCurve() { return curve; } /** - * @com.intel.drl.spec_ref + * Returns the generator (or base point). + * + * @return the generator (or base point). + * @since Android 1.0 */ public ECPoint getGenerator() { return generator; } /** - * @com.intel.drl.spec_ref + * Returns the order of the generator. + * + * @return the order of the generator. + * @since Android 1.0 */ public BigInteger getOrder() { return order; diff --git a/security/src/main/java/java/security/spec/ECPoint.java b/security/src/main/java/java/security/spec/ECPoint.java index b4c0737..3aba6c7 100644 --- a/security/src/main/java/java/security/spec/ECPoint.java +++ b/security/src/main/java/java/security/spec/ECPoint.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -27,12 +22,16 @@ import java.math.BigInteger; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * A Point on an Elliptic Curve in barycentric (or affine) coordinates. * + * @since Android 1.0 */ public class ECPoint { + /** - * @com.intel.drl.spec_ref + * The point on an Elliptic Curve at infinity. + * + * @since Android 1.0 */ public static final ECPoint POINT_INFINITY = new ECPoint(); // affine X coordinate of this point @@ -47,7 +46,13 @@ public class ECPoint { } /** - * @com.intel.drl.spec_ref + * Creates a new point at the specified coordinates. + * + * @param affineX + * the x-coordinate. + * @param affineY + * the y-coordinate. + * @since Android 1.0 */ public ECPoint(BigInteger affineX, BigInteger affineY) { this.affineX = affineX; @@ -61,21 +66,34 @@ public class ECPoint { } /** - * @com.intel.drl.spec_ref + * Returns the x-coordinate. + * + * @return the x-coordinate, or {@code null} for the infinite point. + * @since Android 1.0 */ public BigInteger getAffineX() { return affineX; } /** - * @com.intel.drl.spec_ref + * Returns the y-coordinate. + * + * @return the y-coordinate, or {@code null} fot the infinite point. + * @since Android 1.0 */ public BigInteger getAffineY() { return affineY; } /** - * @com.intel.drl.spec_ref + * Returns whether the specified object and this elliptic curve point are + * equal. + * + * @param other + * the object to compare. + * @return {@code true} if the specified object and this elliptic curve + * point are equal, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object other) { if (this == other) { @@ -95,7 +113,10 @@ public class ECPoint { } /** - * @com.intel.drl.spec_ref + * Returns the hashcode of this elliptic curve point. + * + * @return the hashcode of this elliptic curve point. + * @since Android 1.0 */ public int hashCode() { if (this.affineX != null) { diff --git a/security/src/main/java/java/security/spec/ECPrivateKeySpec.java b/security/src/main/java/java/security/spec/ECPrivateKeySpec.java index 3422f16..de778fd 100644 --- a/security/src/main/java/java/security/spec/ECPrivateKeySpec.java +++ b/security/src/main/java/java/security/spec/ECPrivateKeySpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -27,8 +22,9 @@ import java.math.BigInteger; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameters specifying an Elliptic Curve (EC) private key. * + * @since Android 1.0 */ public class ECPrivateKeySpec implements KeySpec { // Private value associated with this key @@ -37,7 +33,14 @@ public class ECPrivateKeySpec implements KeySpec { private final ECParameterSpec params; /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECPrivateKeySpec} with the specified private value + * {@code S} and parameter specification. + * + * @param s + * the private value {@code S}. + * @param params + * the domain parameter specification. + * @since Android 1.0 */ public ECPrivateKeySpec(BigInteger s, ECParameterSpec params) { this.s = s; @@ -52,14 +55,20 @@ public class ECPrivateKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the domain parameter specification. + * + * @return the domain parameter specification. + * @since Android 1.0 */ public ECParameterSpec getParams() { return params; } /** - * @com.intel.drl.spec_ref + * Returns the private value {@code S}. + * + * @return the private value {@code S}. + * @since Android 1.0 */ public BigInteger getS() { return s; diff --git a/security/src/main/java/java/security/spec/ECPublicKeySpec.java b/security/src/main/java/java/security/spec/ECPublicKeySpec.java index 3c41f8e..da182b5 100644 --- a/security/src/main/java/java/security/spec/ECPublicKeySpec.java +++ b/security/src/main/java/java/security/spec/ECPublicKeySpec.java @@ -15,18 +15,14 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameters specifying an Elliptic Curve (EC) public key. * + * @since Android 1.0 */ public class ECPublicKeySpec implements KeySpec { // The public point @@ -35,7 +31,16 @@ public class ECPublicKeySpec implements KeySpec { private final ECParameterSpec params; /** - * @com.intel.drl.spec_ref + * Creates a new {@code ECPublicKey} with the specified public elliptic + * curve point and parameter specification. + * + * @param w + * the public elliptic curve point {@code W}. + * @param params + * the domain parameter specification. + * @throws IllegalArgumentException + * if the specified point {@code W} is at infinity. + * @since Android 1.0 */ public ECPublicKeySpec(ECPoint w, ECParameterSpec params) { this.w = w; @@ -55,14 +60,20 @@ public class ECPublicKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the domain parameter specification. + * + * @return the domain parameter specification. + * @since Android 1.0 */ public ECParameterSpec getParams() { return params; } /** - * @com.intel.drl.spec_ref + * Returns the public elliptic curve point {@code W}. + * + * @return the public elliptic curve point {@code W}. + * @since Android 1.0 */ public ECPoint getW() { return w; diff --git a/security/src/main/java/java/security/spec/EllipticCurve.java b/security/src/main/java/java/security/spec/EllipticCurve.java index db1bacc..3ab2921 100644 --- a/security/src/main/java/java/security/spec/EllipticCurve.java +++ b/security/src/main/java/java/security/spec/EllipticCurve.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -28,8 +23,9 @@ import java.util.Arrays; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * An Elliptic Curve with its necessary values. * + * @since Android 1.0 */ public class EllipticCurve { @@ -50,7 +46,20 @@ public class EllipticCurve { private volatile int hash; /** - * @com.intel.drl.spec_ref + * Creates a new {@code EllipticCurve} with the specified field, + * coefficients and seed. + * + * @param field + * the finite field of this elliptic curve. + * @param a + * the coefficient {@code a}. + * @param b + * the coefficient {@code b}. + * @param seed + * the seed used for the generation of the curve. + * @throws IllegalArgumentException + * if the specified coefficients are not in the specified field. + * @since Android 1.0 */ public EllipticCurve(ECField field, BigInteger a, BigInteger b, byte[] seed) { this.field = field; @@ -95,35 +104,59 @@ public class EllipticCurve { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code EllipticCurve} with the specified field and + * coefficients. + * + * @param field + * the finite field of this elliptic curve. + * @param a + * the coefficient {@code a}. + * @param b + * the coefficient {@code b}. + * @throws IllegalArgumentException + * if the specified coefficients are not in the specified field. + * @since Android 1.0 */ public EllipticCurve(ECField field, BigInteger a, BigInteger b) { this(field, a, b, null); } /** - * @com.intel.drl.spec_ref + * Returns the coefficient {@code a} of this elliptic curve. + * + * @return the coefficient {@code a} of this elliptic curve. + * @since Android 1.0 */ public BigInteger getA() { return a; } /** - * @com.intel.drl.spec_ref + * Returns the coefficient {@code b} of this elliptic curve. + * + * @return the coefficient {@code b} of this elliptic curve. + * @since Android 1.0 */ public BigInteger getB() { return b; } /** - * @com.intel.drl.spec_ref + * Returns the finite field of this elliptic curve. + * + * @return the finite field of this elliptic curve. + * @since Android 1.0 */ public ECField getField() { return field; } /** - * @com.intel.drl.spec_ref + * Returns a copy of the seed that was used to generate this elliptic curve. + * + * @return a copy of the seed that was used to generate this elliptic curve, + * or {@code null} if none specified. + * @since Android 1.0 */ public byte[] getSeed() { if (seed == null) { @@ -137,7 +170,13 @@ public class EllipticCurve { } /** - * @com.intel.drl.spec_ref + * Returns whether the specified object equals to this elliptic curve. + * + * @param other + * the object to compare. + * @return {@code true} if the specified object is equal to this elliptic + * curve, otherwise {@code false}. + * @since Android 1.0 */ public boolean equals(Object other) { if (this == other) { @@ -153,7 +192,10 @@ public class EllipticCurve { } /** - * @com.intel.drl.spec_ref + * Returns the hashcode of this elliptic curve. + * + * @return the hashcode of this elliptic curve. + * @since Android 1.0 */ public int hashCode() { // hash init is delayed diff --git a/security/src/main/java/java/security/spec/EncodedKeySpec.java b/security/src/main/java/java/security/spec/EncodedKeySpec.java index f8f3162..f199bca 100644 --- a/security/src/main/java/java/security/spec/EncodedKeySpec.java +++ b/security/src/main/java/java/security/spec/EncodedKeySpec.java @@ -15,23 +15,24 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; /** - * @com.intel.drl.spec_ref + * The abstract key specification for a public or a private key in encoded + * format. * + * @since Android 1.0 */ public abstract class EncodedKeySpec implements KeySpec { // Encoded key private final byte[] encodedKey; /** - * @com.intel.drl.spec_ref + * Creates a new {@code EncodedKeySpec} with the specified encoded key bytes. + * + * @param encodedKey + * the encoded key bytes. + * @since Android 1.0 */ public EncodedKeySpec(byte[] encodedKey) { // Defensively copies parameter @@ -42,7 +43,10 @@ public abstract class EncodedKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the encoded key bytes. + * + * @return the encoded key bytes. + * @since Android 1.0 */ public byte[] getEncoded() { // Defensively copies private array @@ -53,7 +57,12 @@ public abstract class EncodedKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the name of the encoding format of this encoded key + * specification. + * + * @return the name of the encoding format of this encoded key + * specification. + * @since Android 1.0 */ public abstract String getFormat(); } diff --git a/security/src/main/java/java/security/spec/InvalidKeySpecException.java b/security/src/main/java/java/security/spec/InvalidKeySpecException.java index 6df9e5c..a83e984 100644 --- a/security/src/main/java/java/security/spec/InvalidKeySpecException.java +++ b/security/src/main/java/java/security/spec/InvalidKeySpecException.java @@ -15,51 +15,64 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.spec; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when an invalid key specification is + * encountered. * + * @since Android 1.0 */ public class InvalidKeySpecException extends GeneralSecurityException { + /** - * @com.intel.drl.spec_ref + * The serial version identifier. + * + * @since Android 1.0 */ private static final long serialVersionUID = 3546139293998810778L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code InvalidKeySpecException} with the specified message. + * + * @param msg + * the detail message of this exception. + * @since Android 1.0 */ public InvalidKeySpecException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code InvalidKeySpecException}. + * + * @since Android 1.0 */ public InvalidKeySpecException() { } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code InvalidKeySpecException} with the specified message + * and cause. + * + * @param message + * the detail message of this exception. + * @param cause + * the cause of this exception. + * @since Android 1.0 */ public InvalidKeySpecException(String message, Throwable cause) { super(message, cause); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code InvalidKeySpecException} with the specified cause. + * + * @param cause + * the cause of this exception. + * @since Android 1.0 */ public InvalidKeySpecException(Throwable cause) { super(cause); diff --git a/security/src/main/java/java/security/spec/InvalidParameterSpecException.java b/security/src/main/java/java/security/spec/InvalidParameterSpecException.java index c7ce23f..668fda5 100644 --- a/security/src/main/java/java/security/spec/InvalidParameterSpecException.java +++ b/security/src/main/java/java/security/spec/InvalidParameterSpecException.java @@ -15,37 +15,41 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.spec; import java.security.GeneralSecurityException; /** - * @com.intel.drl.spec_ref + * The exception that is thrown when an invalid parameter specification is + * encountered. * + * @since Android 1.0 */ public class InvalidParameterSpecException extends GeneralSecurityException { + /** - * @com.intel.drl.spec_ref - * + * The serial version identifier. + * + * @since Android 1.0 */ private static final long serialVersionUID = -970468769593399342L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code InvalidParameterSpecException} with the specified + * message. + * + * @param msg + * the detail message for this exception. + * @since Android 1.0 */ public InvalidParameterSpecException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code InvalidParameterSpecException}. + * + * @since Android 1.0 */ public InvalidParameterSpecException() { } diff --git a/security/src/main/java/java/security/spec/KeySpec.java b/security/src/main/java/java/security/spec/KeySpec.java index 908e154..350a7eb 100644 --- a/security/src/main/java/java/security/spec/KeySpec.java +++ b/security/src/main/java/java/security/spec/KeySpec.java @@ -15,16 +15,13 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package java.security.spec; /** - * @com.intel.drl.spec_ref + * The marker interface for key specifications. The purpose is + * to group key specifications for cryptographic keys. * + * @since Android 1.0 */ public interface KeySpec { }
\ No newline at end of file diff --git a/security/src/main/java/java/security/spec/MGF1ParameterSpec.java b/security/src/main/java/java/security/spec/MGF1ParameterSpec.java index 3bf2a0b..a40f0b3 100644 --- a/security/src/main/java/java/security/spec/MGF1ParameterSpec.java +++ b/security/src/main/java/java/security/spec/MGF1ParameterSpec.java @@ -15,37 +15,55 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameter specification for the Mask Generation Function (MGF1) in + * the RSA-PSS Signature and OAEP Padding scheme. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard + * </p> * + * @since Android 1.0 */ public class MGF1ParameterSpec implements AlgorithmParameterSpec { + /** - * @com.intel.drl.spec_ref + * The predefined MGF1 parameter specification with an "SHA-1" message + * digest. + * + * @since Android 1.0 */ public static final MGF1ParameterSpec SHA1 = new MGF1ParameterSpec("SHA-1"); //$NON-NLS-1$ + /** - * @com.intel.drl.spec_ref + * The predefined MGF1 parameter specification with an "SHA-256" message + * digest. + * + * @since Android 1.0 */ public static final MGF1ParameterSpec SHA256 = new MGF1ParameterSpec("SHA-256"); //$NON-NLS-1$ + /** - * @com.intel.drl.spec_ref + * The predefined MGF1 parameter specification with an "SHA-384" message + * digest. + * + * @since Android 1.0 */ public static final MGF1ParameterSpec SHA384 = new MGF1ParameterSpec("SHA-384"); //$NON-NLS-1$ + /** - * @com.intel.drl.spec_ref + * The predefined MGF1 parameter specification with an "SHA-512" message + * digest. + * + * @since Android 1.0 */ public static final MGF1ParameterSpec SHA512 = new MGF1ParameterSpec("SHA-512"); //$NON-NLS-1$ @@ -54,7 +72,12 @@ public class MGF1ParameterSpec implements AlgorithmParameterSpec { private final String mdName; /** - * @com.intel.drl.spec_ref + * Creates a new {@code MGF1ParameterSpec} with the specified message digest + * algorithm name. + * + * @param mdName + * the name of the message digest algorithm. + * @since Android 1.0 */ public MGF1ParameterSpec(String mdName) { this.mdName = mdName; @@ -64,7 +87,10 @@ public class MGF1ParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the name of the message digest algorithm. + * + * @return the name of the message digest algorithm. + * @since Android 1.0 */ public String getDigestAlgorithm() { return mdName; diff --git a/security/src/main/java/java/security/spec/PKCS8EncodedKeySpec.java b/security/src/main/java/java/security/spec/PKCS8EncodedKeySpec.java index 070552f..5cb67b8 100644 --- a/security/src/main/java/java/security/spec/PKCS8EncodedKeySpec.java +++ b/security/src/main/java/java/security/spec/PKCS8EncodedKeySpec.java @@ -15,20 +15,23 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; /** - * @com.intel.drl.spec_ref + * The key specification for an encoded private key in ASN.1 format as defined + * in the PKCS#8 standard. * + * @since Android 1.0 */ public class PKCS8EncodedKeySpec extends EncodedKeySpec { + /** - * @com.intel.drl.spec_ref + * Creates a new {@code PKCS8EncodedKeySpec} with the specified encoded key + * bytes. + * + * @param encodedKey + * the encoded key bytes. + * @since Android 1.0 */ public PKCS8EncodedKeySpec(byte[] encodedKey) { // Super class' ctor makes defensive parameter copy @@ -36,7 +39,10 @@ public class PKCS8EncodedKeySpec extends EncodedKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns a copy of the encoded key bytes. + * + * @return a copy of the encoded key bytes. + * @since Android 1.0 */ public byte[] getEncoded() { // Super class' getEncoded() always returns a new array @@ -44,7 +50,11 @@ public class PKCS8EncodedKeySpec extends EncodedKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the name of the encoding format of this encoded key + * specification. + * + * @return the string "PKCS#8". + * @since Android 1.0 */ public final String getFormat() { return "PKCS#8"; //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/spec/PSSParameterSpec.java b/security/src/main/java/java/security/spec/PSSParameterSpec.java index 41428d1..c6a5bc5 100644 --- a/security/src/main/java/java/security/spec/PSSParameterSpec.java +++ b/security/src/main/java/java/security/spec/PSSParameterSpec.java @@ -15,22 +15,33 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The parameter specification for the RSA-PSS Signature scheme. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard. + * </p> * + * @since Android 1.0 */ public class PSSParameterSpec implements AlgorithmParameterSpec { + /** - * @com.intel.drl.spec_ref + * The default parameter specification. It specifies the following parameters: + * <ul> + * <li>message digest: {@code "SHA-1"}</li> + * <li>mask generation function (<i>mgf</i>): {@code "MGF1"}</li> + * <li>parameters for the <i>mgf</i>: {@link MGF1ParameterSpec#SHA1}</li> + * <li>salt length: {@code 20}</li> + * <li>trailer field: {@code -1}</li> + * </ul> + * + * @since Android 1.0 */ public static final PSSParameterSpec DEFAULT = new PSSParameterSpec(20); @@ -46,7 +57,14 @@ public class PSSParameterSpec implements AlgorithmParameterSpec { private final int saltLen; /** - * @com.intel.drl.spec_ref + * Creates a new {@code PSSParameterSpec} with the specified salt length + * and the default values. + * + * @param saltLen + * the salt length (in bits). + * @throws IllegalArgumentException + * if {@code saltLen} is negative. + * @since Android 1.0 */ public PSSParameterSpec(int saltLen) { if (saltLen < 0) { @@ -60,7 +78,23 @@ public class PSSParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref * + * Creates a new {@code PSSParameterSpec} with the specified message digest + * name, mask generation function name, mask generation function parameters, + * salt length, and trailer field value. + * + * @param mdName + * the name of the message digest algorithm. + * @param mgfName + * the name of the mask generation function algorithm. + * @param mgfSpec + * the parameter for the mask generation function algorithm. + * @param saltLen + * the salt length (in bits). + * @param trailerField + * the trailer field value. + * @throws IllegalArgumentException + * if {@code saltLen} or {@code trailerField} is negative. + * @since Android 1.0 */ public PSSParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec mgfSpec, int saltLen, int trailerField) { @@ -85,35 +119,51 @@ public class PSSParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the length of the salt (in bits). + * + * @return the length of the salt (in bits). + * @since Android 1.0 */ public int getSaltLength() { return saltLen; } /** - * @com.intel.drl.spec_ref + * Returns the name of the message digest algorithm. + * + * @return the name of the message digest algorithm. + * @since Android 1.0 */ public String getDigestAlgorithm() { return mdName; } /** - * @com.intel.drl.spec_ref + * Returns the name of the mask generation function algorithm. + * + * @return the name of the mask generation function algorithm. + * @since Android 1.0 */ public String getMGFAlgorithm() { return mgfName; } /** - * @com.intel.drl.spec_ref + * Returns the parameter for the mask generation function algorithm. + * + * @return the parameter for the mask generation function algorithm, or + * {@code null} if none specified. + * @since Android 1.0 */ public AlgorithmParameterSpec getMGFParameters() { return mgfSpec; } /** - * @com.intel.drl.spec_ref + * Returns the trailer field value. + * + * @return the trailer field value. + * @since Android 1.0 */ public int getTrailerField() { return trailerField; diff --git a/security/src/main/java/java/security/spec/RSAKeyGenParameterSpec.java b/security/src/main/java/java/security/spec/RSAKeyGenParameterSpec.java index 9b03fcc..06f3498 100644 --- a/security/src/main/java/java/security/spec/RSAKeyGenParameterSpec.java +++ b/security/src/main/java/java/security/spec/RSAKeyGenParameterSpec.java @@ -15,26 +15,28 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The parameter specification for generating an RSA key pair. * + * @since Android 1.0 */ public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec { + /** - * @com.intel.drl.spec_ref + * The value of the public exponent {@code F0} = 3. + * + * @since Android 1.0 */ public static final BigInteger F0 = BigInteger.valueOf(3L); + /** - * @com.intel.drl.spec_ref + * The value of the public exponent {@code F4} = 65537. + * + * @since Android 1.0 */ public static final BigInteger F4 = BigInteger.valueOf(65537L); @@ -44,7 +46,14 @@ public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec { private final BigInteger publicExponent; /** - * @com.intel.drl.spec_ref + * Creates a new {@code RSAKeyGenParameterSpec} with the specified key size + * and public exponent. + * + * @param keysize + * the size of the modulus (number of bits). + * @param publicExponent + * the value of the public exponent. + * @since Android 1.0 */ public RSAKeyGenParameterSpec(int keysize, BigInteger publicExponent) { this.keysize = keysize; @@ -52,14 +61,20 @@ public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec { } /** - * @com.intel.drl.spec_ref + * Returns the size of the modulus (number of bits). + * + * @return the size of the modulus (number of bits). + * @since Android 1.0 */ public int getKeysize() { return keysize; } /** - * @com.intel.drl.spec_ref + * Returns the value of the public exponent. + * + * @return the value of the public exponent. + * @since Android 1.0 */ public BigInteger getPublicExponent() { return publicExponent; diff --git a/security/src/main/java/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java b/security/src/main/java/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java index 8db2876..93e3193 100644 --- a/security/src/main/java/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java +++ b/security/src/main/java/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -27,8 +22,15 @@ import java.math.BigInteger; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The key specification of a RSA multi-prime private key with the Chinese + * Remainder Theorem (CRT) information values used. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard. + * </p> * + * @since Android 1.0 */ public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec { // Public Exponent @@ -47,7 +49,32 @@ public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec { private final RSAOtherPrimeInfo[] otherPrimeInfo; /** - * @com.intel.drl.spec_ref + * Creates a new {@code RSAMultiPrimePrivateCrtKeySpec} with the specified + * modulus, public exponent, private exponent, prime factors, prime + * exponents, crt coefficient, and additional primes. + * + * @param modulus + * the modulus {@code n}. + * @param publicExponent + * the public exponent {@code e}. + * @param privateExponent + * the private exponent {@code d}. + * @param primeP + * the prime factor {@code p} of {@code n}. + * @param primeQ + * the prime factor {@code q} of {@code n}. + * @param primeExponentP + * the exponent of the prime {@code p}. + * @param primeExponentQ + * the exponent of the prime {@code q}. + * @param crtCoefficient + * the CRT coefficient {@code q^-1 mod p}. + * @param otherPrimeInfo + * the information for the additional primes or {@code null} if + * there are only the two primes ({@code p, q}). + * @throws IllegalArgumentException + * if {@code otherPrimeInfo} is not null but empty. + * @since Android 1.0 */ public RSAMultiPrimePrivateCrtKeySpec( BigInteger modulus, @@ -109,14 +136,21 @@ public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the CRT coefficient, {@code q^-1 mod p}. + * + * @return the CRT coefficient, {@code q^-1 mod p}. + * @since Android 1.0 */ public BigInteger getCrtCoefficient() { return crtCoefficient; } /** - * @com.intel.drl.spec_ref + * Returns the information for the additional primes. + * + * @return the information for the additional primes, or {@code null} if + * there are only the two primes ({@code p, q}). + * @since Android 1.0 */ public RSAOtherPrimeInfo[] getOtherPrimeInfo() { // Clone array (if not null) to prevent subsequent modification @@ -131,35 +165,50 @@ public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the exponent of the prime {@code p}. + * + * @return the exponent of the prime {@code p}. + * @since Android 1.0 */ public BigInteger getPrimeExponentP() { return primeExponentP; } /** - * @com.intel.drl.spec_ref + * Returns the exponent of the prime {@code q}. + * + * @return the exponent of the prime {@code q}. + * @since Android 1.0 */ public BigInteger getPrimeExponentQ() { return primeExponentQ; } /** - * @com.intel.drl.spec_ref + * Returns the prime factor {@code p}. + * + * @return the prime factor {@code p}. + * @since Android 1.0 */ public BigInteger getPrimeP() { return primeP; } /** - * @com.intel.drl.spec_ref + * Returns the prime factor {@code q}. + * + * @return the prime factor {@code q}. + * @since Android 1.0 */ public BigInteger getPrimeQ() { return primeQ; } /** - * @com.intel.drl.spec_ref + * Returns the public exponent {@code e}. + * + * @return the public exponent {@code e}. + * @since Android 1.0 */ public BigInteger getPublicExponent() { return publicExponent; diff --git a/security/src/main/java/java/security/spec/RSAOtherPrimeInfo.java b/security/src/main/java/java/security/spec/RSAOtherPrimeInfo.java index 14ce0f8..9b4828e 100644 --- a/security/src/main/java/java/security/spec/RSAOtherPrimeInfo.java +++ b/security/src/main/java/java/security/spec/RSAOtherPrimeInfo.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; @@ -27,8 +22,15 @@ import java.math.BigInteger; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * The additional prime information specified as triplet of primes, a prime + * exponent, and a Chinese Remainder Theorem (CRT) coefficient. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard. + * </p> * + * @since Android 1.0 */ public class RSAOtherPrimeInfo { // Prime @@ -39,7 +41,16 @@ public class RSAOtherPrimeInfo { private final BigInteger crtCoefficient; /** - * @com.intel.drl.spec_ref + * Creates a new {@code RSAOtherPrimeInfo} with the specified prime, + * exponent, and CRT coefficient. + * + * @param prime + * the prime factor. + * @param primeExponent + * the prime exponent. + * @param crtCoefficient + * the CRT coefficient. + * @since Android 1.0 */ public RSAOtherPrimeInfo(BigInteger prime, BigInteger primeExponent, BigInteger crtCoefficient) { @@ -58,21 +69,30 @@ public class RSAOtherPrimeInfo { } /** - * @com.intel.drl.spec_ref + * Returns the CRT coefficient. + * + * @return the CRT coefficient. + * @since Android 1.0 */ public final BigInteger getCrtCoefficient() { return crtCoefficient; } /** - * @com.intel.drl.spec_ref + * Returns the prime factor. + * + * @return the prime factor. + * @since Android 1.0 */ public final BigInteger getPrime() { return prime; } /** - * @com.intel.drl.spec_ref + * Returns the exponent. + * + * @return the exponent. + * @since Android 1.0 */ public final BigInteger getExponent() { return primeExponent; diff --git a/security/src/main/java/java/security/spec/RSAPrivateCrtKeySpec.java b/security/src/main/java/java/security/spec/RSAPrivateCrtKeySpec.java index 5c0eae7..1157099 100644 --- a/security/src/main/java/java/security/spec/RSAPrivateCrtKeySpec.java +++ b/security/src/main/java/java/security/spec/RSAPrivateCrtKeySpec.java @@ -15,18 +15,20 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The key specification of a RSA private key using Chinese Remainder Theorem + * (CRT) values. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard. + * </p> * + * @since Android 1.0 */ public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec { // Public Exponent @@ -43,7 +45,27 @@ public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec { private final BigInteger crtCoefficient; /** - * @com.intel.drl.spec_ref + * Creates a new {@code RSAMultiPrimePrivateCrtKeySpec} with the specified + * modulus, public exponent, private exponent, prime factors, prime + * exponents, crt coefficient, and additional primes. + * + * @param modulus + * the modulus {@code n}. + * @param publicExponent + * the public exponent {@code e}. + * @param privateExponent + * the private exponent {@code d}. + * @param primeP + * the prime factor {@code p} of {@code n}. + * @param primeQ + * the prime factor {@code q} of {@code n}. + * @param primeExponentP + * the exponent of the prime {@code p}. + * @param primeExponentQ + * the exponent of the prime {@code q}. + * @param crtCoefficient + * the CRT coefficient {@code q^-1 mod p}. + * @since Android 1.0 */ public RSAPrivateCrtKeySpec(BigInteger modulus, BigInteger publicExponent, @@ -65,42 +87,60 @@ public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the CRT coefficient, {@code q^-1 mod p}. + * + * @return the CRT coefficient, {@code q^-1 mod p}. + * @since Android 1.0 */ public BigInteger getCrtCoefficient() { return crtCoefficient; } /** - * @com.intel.drl.spec_ref + * Returns the exponent of the prime {@code p}. + * + * @return the exponent of the prime {@code p}. + * @since Android 1.0 */ public BigInteger getPrimeExponentP() { return primeExponentP; } /** - * @com.intel.drl.spec_ref + * Returns the exponent of the prime {@code q}. + * + * @return the exponent of the prime {@code q}. + * @since Android 1.0 */ public BigInteger getPrimeExponentQ() { return primeExponentQ; } /** - * @com.intel.drl.spec_ref + * Returns the prime factor {@code p}. + * + * @return the prime factor {@code p}. + * @since Android 1.0 */ public BigInteger getPrimeP() { return primeP; } /** - * @com.intel.drl.spec_ref + * Returns the prime factor {@code q}. + * + * @return the prime factor {@code q}. + * @since Android 1.0 */ public BigInteger getPrimeQ() { return primeQ; } /** - * @com.intel.drl.spec_ref + * Returns the public exponent {@code e}. + * + * @return the public exponent {@code e}. + * @since Android 1.0 */ public BigInteger getPublicExponent() { return publicExponent; diff --git a/security/src/main/java/java/security/spec/RSAPrivateKeySpec.java b/security/src/main/java/java/security/spec/RSAPrivateKeySpec.java index 355f2ba..bd7d4e8 100644 --- a/security/src/main/java/java/security/spec/RSAPrivateKeySpec.java +++ b/security/src/main/java/java/security/spec/RSAPrivateKeySpec.java @@ -15,18 +15,19 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The key specification of a RSA private key. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard + * </p> * + * @since Android 1.0 */ public class RSAPrivateKeySpec implements KeySpec { // Modulus @@ -35,7 +36,14 @@ public class RSAPrivateKeySpec implements KeySpec { private final BigInteger privateExponent; /** - * @com.intel.drl.spec_ref + * Creates a new {@code RSAPrivateKeySpec} with the specified modulus and + * private exponent. + * + * @param modulus + * the modulus {@code n}. + * @param privateExponent + * the private exponent {@code e} + * @since Android 1.0 */ public RSAPrivateKeySpec(BigInteger modulus, BigInteger privateExponent) { this.modulus = modulus; @@ -43,14 +51,20 @@ public class RSAPrivateKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the modulus {@code n}. + * + * @return the modulus {@code n}. + * @since Android 1.0 */ public BigInteger getModulus() { return modulus; } /** - * @com.intel.drl.spec_ref + * Returns the private exponent {@code e}. + * + * @return the private exponent {@code e}. + * @since Android 1.0 */ public BigInteger getPrivateExponent() { return privateExponent; diff --git a/security/src/main/java/java/security/spec/RSAPublicKeySpec.java b/security/src/main/java/java/security/spec/RSAPublicKeySpec.java index 7bd64e6..bd4c5b5 100644 --- a/security/src/main/java/java/security/spec/RSAPublicKeySpec.java +++ b/security/src/main/java/java/security/spec/RSAPublicKeySpec.java @@ -15,17 +15,18 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; import java.math.BigInteger; /** - * @com.intel.drl.spec_ref + * The key specification of a RSA public key. + * <p> + * Defined in the <a + * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a> + * standard. + * </p> + * @since Android 1.0 */ public class RSAPublicKeySpec implements KeySpec { // Modulus @@ -34,7 +35,14 @@ public class RSAPublicKeySpec implements KeySpec { private final BigInteger publicExponent; /** - * @com.intel.drl.spec_ref + * Creates a new {@code RSAPublicKeySpec} with the specified modulus and + * public exponent. + * + * @param modulus + * the modulus {@code n}. + * @param publicExponent + * the public exponent {@code d}. + * @since Android 1.0 */ public RSAPublicKeySpec(BigInteger modulus, BigInteger publicExponent) { this.modulus = modulus; @@ -42,14 +50,20 @@ public class RSAPublicKeySpec implements KeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the modulus {@code n}. + * + * @return the modulus {@code n}. + * @since Android 1.0 */ public BigInteger getModulus() { return modulus; } /** - * @com.intel.drl.spec_ref + * Returns the public exponent {@code d}. + * + * @return the public exponent {@code d}. + * @since Android 1.0 */ public BigInteger getPublicExponent() { return publicExponent; diff --git a/security/src/main/java/java/security/spec/X509EncodedKeySpec.java b/security/src/main/java/java/security/spec/X509EncodedKeySpec.java index 46e833e..6cc6104 100644 --- a/security/src/main/java/java/security/spec/X509EncodedKeySpec.java +++ b/security/src/main/java/java/security/spec/X509EncodedKeySpec.java @@ -15,20 +15,22 @@ * limitations under the License. */ -/** -* @author Vladimir N. Molotkov -* @version $Revision$ -*/ - package java.security.spec; /** - * @com.intel.drl.spec_ref + * The key specification of an X.509 encoded key in ASN.1 format. * + * @since Android 1.0 */ public class X509EncodedKeySpec extends EncodedKeySpec { + /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509EncodedKeySpec} with the specified encoded key + * bytes. + * + * @param encodedKey + * the encoded key bytes. + * @since Android 1.0 */ public X509EncodedKeySpec(byte[] encodedKey) { // Super class' ctor makes defensive parameter copy @@ -36,7 +38,10 @@ public class X509EncodedKeySpec extends EncodedKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the encoded key bytes. + * + * @return the encoded key bytes. + * @since Android 1.0 */ public byte[] getEncoded() { // Super class' getEncoded() always returns a new array @@ -44,7 +49,11 @@ public class X509EncodedKeySpec extends EncodedKeySpec { } /** - * @com.intel.drl.spec_ref + * Returns the name of the encoding format of this encoded key + * specification. + * + * @return the string "X.509". + * @since Android 1.0 */ public final String getFormat() { return "X.509"; //$NON-NLS-1$ diff --git a/security/src/main/java/java/security/spec/package.html b/security/src/main/java/java/security/spec/package.html index 0d4b963..1a1a8e0 100644 --- a/security/src/main/java/java/security/spec/package.html +++ b/security/src/main/java/java/security/spec/package.html @@ -5,14 +5,15 @@ <html> <body> <p> -This package provides the classes and interfaces needed to specify keys and parameter for -encryption and signing algorithms. Following standards are supported: +This package provides the classes and interfaces needed to specify keys and parameters for +encryption and signing algorithms. The following standards are supported: (1) PKCS#1 RSA encryption standard; (2) FIPS-186 DSA (signature) standard; (3) PKCS#8 private key information standard. Keys may be specified via algorithm or in a more abstract and general way with ASN.1. -The parameters for the Elliptic Curve (EC) encryption algorithm are only specified as +The parameters for the Elliptic Curve (EC) encryption algorithm are only specified as input parameters to the relevant EC-generator. </p> +@since Android 1.0 </body> </html>
\ No newline at end of file diff --git a/security/src/main/java/javax/security/cert/Certificate.java b/security/src/main/java/javax/security/cert/Certificate.java index d94427d..fb00789 100644 --- a/security/src/main/java/javax/security/cert/Certificate.java +++ b/security/src/main/java/javax/security/cert/Certificate.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.security.cert; import java.security.InvalidKeyException; @@ -32,17 +27,36 @@ import javax.security.cert.CertificateEncodingException; import javax.security.cert.CertificateException; /** - * @com.intel.drl.spec_ref + * Abstract class to represent identity certificates. It represents a way to + * verify the binding of a Principal and its public key. Examples are X.509, + * PGP, and SDSI. + * <p> + * Note: This package is provided only for compatibility reasons. + * It contains a simplified version of the java.security.cert package that was + * previously used by JSSE (Java SSL package). All applications that do not have + * to be compatible with older versions of JSSE (that is before Java SDK 1.5) + * should only use java.security.cert. + * </p> + * @since Android 1.0 */ public abstract class Certificate { /** - * @com.intel.drl.spec_ref + * Creates a new {@code Certificate}. + * @since Android 1.0 */ public Certificate() {} /** - * @com.intel.drl.spec_ref + * Compares the argument to this Certificate. If both have the same bytes + * they are assumed to be equal. + * + * @param obj + * the {@code Certificate} to compare with this object + * @return <code>true</code> if {@code obj} is the same as this + * {@code Certificate}, <code>false</code> otherwise + * @see #hashCode + * @since Android 1.0 */ public boolean equals(Object obj) { if (obj == this) { @@ -60,7 +74,13 @@ public abstract class Certificate { } /** - * @com.intel.drl.spec_ref + * Returns an integer hash code for the receiver. Any two objects which + * return <code>true</code> when passed to <code>equals</code> must answer + * the same value for this method. + * + * @return the receiver's hash + * @see #equals + * @since Android 1.0 */ public int hashCode() { int res = 0; @@ -75,13 +95,32 @@ public abstract class Certificate { } /** - * @com.intel.drl.spec_ref + * Returns the encoded representation for this certificate. + * + * @return the encoded representation for this certificate. + * @throws CertificateEncodingException + * if encoding fails. + * @since Android 1.0 */ public abstract byte[] getEncoded() throws CertificateEncodingException; /** - * @com.intel.drl.spec_ref + * Verifies that this certificate was signed with the given public key. + * + * @param key + * public key for which verification should be performed. + * @throws CertificateException + * if encoding errors are detected + * @throws NoSuchAlgorithmException + * if an unsupported algorithm is detected + * @throws InvalidKeyException + * if an invalid key is detected + * @throws NoSuchProviderException + * if there is no default provider + * @throws SignatureException + * if signature errors are detected + * @since Android 1.0 */ public abstract void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, @@ -89,7 +128,24 @@ public abstract class Certificate { SignatureException; /** - * @com.intel.drl.spec_ref + * Verifies that this certificate was signed with the given public key. Uses + * the signature algorithm given by the provider. + * + * @param key + * public key for which verification should be performed. + * @param sigProvider + * the name of the signature provider. + * @exception CertificateException + * if encoding errors are detected + * @exception NoSuchAlgorithmException + * if an unsupported algorithm is detected + * @exception InvalidKeyException + * if an invalid key is detected + * @exception NoSuchProviderException + * if the specified provider does not exists. + * @exception SignatureException + * if signature errors are detected + * @since Android 1.0 */ public abstract void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, @@ -97,12 +153,19 @@ public abstract class Certificate { SignatureException; /** - * @com.intel.drl.spec_ref + * Returns a string containing a concise, human-readable description of the + * receiver. + * + * @return a printable representation for the receiver. + * @since Android 1.0 */ public abstract String toString(); /** - * @com.intel.drl.spec_ref + * Returns the public key corresponding to this certificate. + * + * @return the public key corresponding to this certificate. + * @since Android 1.0 */ public abstract PublicKey getPublicKey(); } diff --git a/security/src/main/java/javax/security/cert/CertificateEncodingException.java b/security/src/main/java/javax/security/cert/CertificateEncodingException.java index a567f75..4091695 100644 --- a/security/src/main/java/javax/security/cert/CertificateEncodingException.java +++ b/security/src/main/java/javax/security/cert/CertificateEncodingException.java @@ -15,36 +15,41 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ package javax.security.cert; /** - * @com.intel.drl.spec_ref - * + * The exception that is thrown when an error occurs while a {@code Certificate} + * is being encoded. + * <p> + * Note: This package is provided only for compatibility reasons. It contains a + * simplified version of the java.security.cert package that was previously used + * by JSSE (Java SSL package). All applications that do not have to be + * compatible with older versions of JSSE (that is before Java SDK 1.5) should + * only use java.security.cert. + * </p> + * @since Android 1.0 */ - public class CertificateEncodingException extends CertificateException { - /** - * @serial - */ private static final long serialVersionUID = -8187642723048403470L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateEncodingException} with the specified + * message. + * + * @param msg + * the detail message for the exception. + * @since Android 1.0 */ public CertificateEncodingException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateEncodingException}. + * + * @since Android 1.0 */ public CertificateEncodingException() { } diff --git a/security/src/main/java/javax/security/cert/CertificateException.java b/security/src/main/java/javax/security/cert/CertificateException.java index aedb285..f186e51 100644 --- a/security/src/main/java/javax/security/cert/CertificateException.java +++ b/security/src/main/java/javax/security/cert/CertificateException.java @@ -15,35 +15,39 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ package javax.security.cert; /** - * @com.intel.drl.spec_ref - * + * The base class for all {@code Certificate} related exceptions. + * <p> + * Note: This package is provided only for compatibility reasons. It contains a + * simplified version of the java.security.cert package that was previously used + * by JSSE (Java SSL package). All applications that do not have to be + * compatible with older versions of JSSE (that is before Java SDK 1.5) should + * only use java.security.cert. + * </p> + * @since Android 1.0 */ public class CertificateException extends Exception { - /** - * @serial - */ private static final long serialVersionUID = -5757213374030785290L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateException} with the specified message. + * + * @param msg + * the detail message for the exception. + * @since Android 1.0 */ public CertificateException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateException}. + * + * @since Android 1.0 */ public CertificateException() { } diff --git a/security/src/main/java/javax/security/cert/CertificateExpiredException.java b/security/src/main/java/javax/security/cert/CertificateExpiredException.java index 87366ae..62870a6 100644 --- a/security/src/main/java/javax/security/cert/CertificateExpiredException.java +++ b/security/src/main/java/javax/security/cert/CertificateExpiredException.java @@ -15,35 +15,39 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.security.cert; /** - * @com.intel.drl.spec_ref - * + * The exception that is thrown when a {@code Certificate} has expired. + * <p> + * Note: This package is provided only for compatibility reasons. It contains a + * simplified version of the java.security.cert package that was previously used + * by JSSE (Java SSL package). All applications that do not have to be + * compatible with older versions of JSSE (that is before Java SDK 1.5) should + * only use java.security.cert. + * </p> + * @since Android 1.0 */ public class CertificateExpiredException extends CertificateException { - /** - * @serial - */ private static final long serialVersionUID = 5091601212177261883L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateExpiredException} with the specified + * message. + * + * @param msg + * the detail message for this exception + * @since Android 1.0 */ public CertificateExpiredException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateExpiredException}. + * + * @since Android 1.0 */ public CertificateExpiredException() { } diff --git a/security/src/main/java/javax/security/cert/CertificateNotYetValidException.java b/security/src/main/java/javax/security/cert/CertificateNotYetValidException.java index cdaccce..6f32945 100644 --- a/security/src/main/java/javax/security/cert/CertificateNotYetValidException.java +++ b/security/src/main/java/javax/security/cert/CertificateNotYetValidException.java @@ -15,35 +15,39 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.security.cert; /** - * @com.intel.drl.spec_ref - * + * The exception that is thrown when a {@code Certificate} is not yet valid. + * <p> + * Note: This package is provided only for compatibility reasons. It contains a + * simplified version of the java.security.cert package that was previously used + * by JSSE (Java SSL package). All applications that do not have to be + * compatible with older versions of JSSE (that is before Java SDK 1.5) should + * only use java.security.cert. + * </p> + * @since Android 1.0 */ public class CertificateNotYetValidException extends CertificateException { - /** - * @serial - */ private static final long serialVersionUID = -8976172474266822818L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateNotYetValidException} with the specified + * message. + * + * @param msg + * the detail message for the exception. + * @since Android 1.0 */ public CertificateNotYetValidException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateNotYetValidException}. + * + * @since Android 1.0 */ public CertificateNotYetValidException() { } diff --git a/security/src/main/java/javax/security/cert/CertificateParsingException.java b/security/src/main/java/javax/security/cert/CertificateParsingException.java index 60c4ba0..9b208e6 100644 --- a/security/src/main/java/javax/security/cert/CertificateParsingException.java +++ b/security/src/main/java/javax/security/cert/CertificateParsingException.java @@ -15,35 +15,39 @@ * limitations under the License. */ -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - package javax.security.cert; /** - * @com.intel.drl.spec_ref - * + * The exception that is thrown when a {@code Certificate} can not be parsed. + * <p> + * Note: This package is provided only for compatibility reasons. It contains a + * simplified version of the java.security.cert package that was previously used + * by JSSE (Java SSL package). All applications that do not have to be + * compatible with older versions of JSSE (that is before Java SDK 1.5) should + * only use java.security.cert. + * </p> + * @since Android 1.0 */ public class CertificateParsingException extends CertificateException { - /** - * @serial - */ private static final long serialVersionUID = -8449352422951136229L; /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateParsingException} with the specified + * message. + * + * @param msg + * the detail message for the exception. + * @since Android 1.0 */ public CertificateParsingException(String msg) { super(msg); } /** - * @com.intel.drl.spec_ref - * + * Creates a new {@code CertificateParsingException}. + * + * @since Android 1.0 */ public CertificateParsingException() { } diff --git a/security/src/main/java/javax/security/cert/X509Certificate.java b/security/src/main/java/javax/security/cert/X509Certificate.java index 1ead4ac..77bffae 100644 --- a/security/src/main/java/javax/security/cert/X509Certificate.java +++ b/security/src/main/java/javax/security/cert/X509Certificate.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Alexander Y. Kleymenov -* @version $Revision$ -*/ - package javax.security.cert; import java.io.ByteArrayInputStream; @@ -45,7 +40,19 @@ import javax.security.cert.CertificateNotYetValidException; import org.apache.harmony.security.internal.nls.Messages; /** - * @com.intel.drl.spec_ref + * Abstract base class for X.509 certificates. + * <p> + * This represents a standard way for accessing the attributes of X.509 v1 + * certificates. + * </p> + * <p> + * Note: This package is provided only for compatibility reasons. + * It contains a simplified version of the java.security.cert package that was + * previously used by JSSE (Java SSL package). All applications that do not have + * to be compatible with older versions of JSSE (that is before Java SDK 1.5) + * should only use java.security.cert. + * </p> + * @since Android 1.0 */ public abstract class X509Certificate extends Certificate { @@ -68,14 +75,24 @@ public abstract class X509Certificate extends Certificate { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509Certificate}. + * + * @since Android 1.0 */ public X509Certificate() { super(); } /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509Certificate} and initializes it from the + * specified input stream. + * + * @param inStream + * input stream containing data to initialize the certificate. + * @return the certificate initialized from the specified input stream + * @throws CertificateException + * if the certificate cannot be created or initialized. + * @since Android 1.0 */ public static final X509Certificate getInstance(InputStream inStream) throws CertificateException { @@ -201,7 +218,15 @@ public abstract class X509Certificate extends Certificate { } /** - * @com.intel.drl.spec_ref + * Creates a new {@code X509Certificate} and initializes it from the + * specified byte array. + * + * @param certData + * byte array containing data to initialize the certificate. + * @return the certificate initialized from the specified byte array + * @throws CertificateException + * if the certificate cannot be created or initialized. + * @since Android 1.0 */ public static final X509Certificate getInstance(byte[] certData) throws CertificateException { @@ -213,60 +238,186 @@ public abstract class X509Certificate extends Certificate { } /** - * @com.intel.drl.spec_ref + * Checks whether the certificate is currently valid. + * <p> + * The validity defined in ASN.1: + * + * <pre> + * validity Validity + * + * Validity ::= SEQUENCE { + * notBefore CertificateValidityDate, + * notAfter CertificateValidityDate } + * + * CertificateValidityDate ::= CHOICE { + * utcTime UTCTime, + * generalTime GeneralizedTime } + * </pre> + * + * </p> + * + * @throws CertificateExpiredException + * if the certificate has expired. + * @throws CertificateNotYetValidException + * if the certificate is not yet valid. + * @since Android 1.0 */ public abstract void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException; /** - * @com.intel.drl.spec_ref + * Checks whether the certificate is valid at the specified date. + * + * @param date + * the date to check the validity against. + * @throws CertificateExpiredException + * if the certificate has expired. + * @throws CertificateNotYetValidException + * if the certificate is not yet valid. + * @see #checkValidity() + * @since Android 1.0 */ public abstract void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException; /** - * @com.intel.drl.spec_ref + * Returns the certificates {@code version} (version number). + * <p> + * The version defined is ASN.1: + * + * <pre> + * Version ::= INTEGER { v1(0), v2(1), v3(2) } + * </pre> + * + * </p> + * + * @return the version number. + * @since Android 1.0 */ public abstract int getVersion(); /** - * @com.intel.drl.spec_ref + * Returns the {@code serialNumber} of the certificate. + * <p> + * The ASN.1 definition of {@code serialNumber}: + * + * <pre> + * CertificateSerialNumber ::= INTEGER + * </pre> + * + * </p> + * + * @return the serial number. + * @since Android 1.0 */ public abstract BigInteger getSerialNumber(); /** - * @com.intel.drl.spec_ref + * Returns the {@code issuer} (issuer distinguished name) as an + * implementation specific {@code Principal} object. + * <p> + * The ASN.1 definition of {@code issuer}: + * + * <pre> + * issuer Name + * + * Name ::= CHOICE { + * RDNSequence } + * + * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName + * + * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue + * + * AttributeTypeAndValue ::= SEQUENCE { + * type AttributeType, + * value AttributeValue } + * + * AttributeType ::= OBJECT IDENTIFIER + * + * AttributeValue ::= ANY DEFINED BY AttributeType + * </pre> + * + * </p> + * + * @return the {@code issuer} as an implementation specific {@code + * Principal}. + * @since Android 1.0 */ public abstract Principal getIssuerDN(); /** - * @com.intel.drl.spec_ref + * Returns the {@code subject} (subject distinguished name) as an + * implementation specific {@code Principal} object. + * <p> + * The ASN.1 definition of {@code subject}: + * + * <pre> + * subject Name + * + * Name ::= CHOICE { + * RDNSequence } + * + * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName + * + * RelativeDistinguishedName ::= SET OF AttributeTypeAndValue + * + * AttributeTypeAndValue ::= SEQUENCE { + * type AttributeType, + * value AttributeValue } + * + * AttributeType ::= OBJECT IDENTIFIER + * + * AttributeValue ::= ANY DEFINED BY AttributeType + * </pre> + * + * </p> + * + * @return the {@code subject} (subject distinguished name). + * @since Android 1.0 */ public abstract Principal getSubjectDN(); /** - * @com.intel.drl.spec_ref + * Returns the {@code notBefore} date from the validity period of the + * certificate. + * + * @return the start of the validity period. + * @since Android 1.0 */ public abstract Date getNotBefore(); /** - * @com.intel.drl.spec_ref + * Returns the {@code notAfter} date of the validity period of the + * certificate. + * + * @return the end of the validity period. + * @since Android 1.0 */ public abstract Date getNotAfter(); /** - * @com.intel.drl.spec_ref + * Returns the name of the algorithm for the certificate signature. + * + * @return the signature algorithm name. + * @since Android 1.0 */ public abstract String getSigAlgName(); /** - * @com.intel.drl.spec_ref + * Returns the OID of the signature algorithm from the certificate. + * + * @return the OID of the signature algorithm. + * @since Android 1.0 */ public abstract String getSigAlgOID(); /** - * @com.intel.drl.spec_ref + * Returns the parameters of the signature algorithm in DER-encoded format. + * + * @return the parameters of the signature algorithm, or null if none are + * used. + * @since Android 1.0 */ public abstract byte[] getSigAlgParams(); } diff --git a/security/src/main/java/javax/security/cert/package.html b/security/src/main/java/javax/security/cert/package.html index 60b9095..a58f1de 100644 --- a/security/src/main/java/javax/security/cert/package.html +++ b/security/src/main/java/javax/security/cert/package.html @@ -10,5 +10,6 @@ version of the java.security.cert package that was previously used by JSSE (Java All applications that do not have to be compatible with older versions of JSSE (that is before Java SDK 1.5) should only use java.security.cert. </p> +@since Android 1.0 </body> </html>
\ No newline at end of file diff --git a/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java b/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java index 8c26f62..2aa474e 100644 --- a/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java +++ b/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java @@ -133,8 +133,8 @@ import org.apache.harmony.security.PolicyEntry; * WeakHashMap; the cache is cleaned either explicitly during refresh() * invocation, or naturally by garbage-collecting the corresponding objects. * - * @see org.apache.harmony.security.fortress.PolicyUtils#getPolicyURLs(Properties, String, - * String) + * @see org.apache.harmony.security.fortress.PolicyUtils#getPolicyURLs( + * Properties, String, String) */ public class DefaultPolicy extends Policy { diff --git a/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicyParser.java b/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicyParser.java index 41d6056..fafa66c 100644 --- a/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicyParser.java +++ b/security/src/main/java/org/apache/harmony/security/fortress/DefaultPolicyParser.java @@ -62,7 +62,8 @@ import org.apache.harmony.security.internal.nls.Messages; * a pluggable scanner and converts received tokens to a set of * {@link org.apache.harmony.security.PolicyEntry PolicyEntries}. * For details of policy format, see the - * {@link org.apache.harmony.security.fortress.DefaultPolicy default policy description}. + * {@link org.apache.harmony.security.fortress.DefaultPolicy default policy + * description}. * <br> * For ordinary uses, this class has just one public method <code>parse()</code>, * which performs the main task. diff --git a/security/src/main/java/org/apache/harmony/security/fortress/SecurityUtils.java b/security/src/main/java/org/apache/harmony/security/fortress/SecurityUtils.java index c2e8f33..64c7700 100644 --- a/security/src/main/java/org/apache/harmony/security/fortress/SecurityUtils.java +++ b/security/src/main/java/org/apache/harmony/security/fortress/SecurityUtils.java @@ -45,8 +45,7 @@ public final class SecurityUtils { // A map used to store inherited contexts.<br> // A thread is used as a key for the map and AccessControlContext // passed to the putContext is used as a value. - private static final WeakHashMap<Thread, AccessControlContext> ACC_CACHE = - new WeakHashMap<Thread, AccessControlContext>(); + private static final WeakHashMap<Thread, AccessControlContext> ACC_CACHE = new WeakHashMap<Thread, AccessControlContext>(); /** * This method to be invoked in the Thread's constructor. The first argument @@ -112,4 +111,4 @@ public final class SecurityUtils { return ACC_CACHE.get(thread); } } -}
\ No newline at end of file +} diff --git a/security/src/main/java/org/apache/harmony/security/internal/nls/Messages.java b/security/src/main/java/org/apache/harmony/security/internal/nls/Messages.java index 0c32fba..d78d0df 100644 --- a/security/src/main/java/org/apache/harmony/security/internal/nls/Messages.java +++ b/security/src/main/java/org/apache/harmony/security/internal/nls/Messages.java @@ -23,7 +23,16 @@ package org.apache.harmony.security.internal.nls; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +// BEGIN android-changed import org.apache.harmony.luni.util.MsgHelp; +// BEGIN android-changed /** * This class retrieves strings from a resource bundle and returns them, @@ -41,8 +50,10 @@ import org.apache.harmony.luni.util.MsgHelp; */ public class Messages { + // BEGIN android-changed private static final String sResource = "org.apache.harmony.security.internal.nls.messages"; //$NON-NLS-1$ + // END android-changed /** * Retrieves a message which has no arguments. @@ -52,7 +63,9 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg); + // END android-changed } /** @@ -119,6 +132,12 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg, Object[] args) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg, args); + // END android-changed } + + // BEGIN android-note + // Duplicate code was dropped in favor of using MsgHelp. + // END android-note } diff --git a/security/src/main/java/org/apache/harmony/security/pkcs7/SignerInfo.java b/security/src/main/java/org/apache/harmony/security/pkcs7/SignerInfo.java index ea4932d..05a0c7a 100644 --- a/security/src/main/java/org/apache/harmony/security/pkcs7/SignerInfo.java +++ b/security/src/main/java/org/apache/harmony/security/pkcs7/SignerInfo.java @@ -80,9 +80,9 @@ public class SignerInfo { ) { this.version = version; this.issuer = ((Name)issuerAndSerialNumber[0]).getX500Principal(); -// BEGIN android-changed + // BEGIN android-changed this.serialNumber = ASN1Integer.toBigIntegerValue(issuerAndSerialNumber[1]); -// END android-changed + // END android-changed this.digestAlgorithm = digestAlgorithm; this.authenticatedAttributes = authenticatedAttributes; this.digestEncryptionAlgorithm = digestEncryptionAlgorithm; diff --git a/security/src/main/java/org/apache/harmony/security/provider/cert/Cache.java b/security/src/main/java/org/apache/harmony/security/provider/cert/Cache.java index b76ad63..a4b5700 100644 --- a/security/src/main/java/org/apache/harmony/security/provider/cert/Cache.java +++ b/security/src/main/java/org/apache/harmony/security/provider/cert/Cache.java @@ -138,25 +138,25 @@ public class Cache { cache = new Object[cache_size]; } -// BEGIN android-removed -// /** -// * Creates the Cache object of size of 900. -// * @param pref_size specifies how many leading/trailing bytes of object's -// * encoded form will be used for hash computation -// */ -// public Cache(int pref_size) { -// this(pref_size, 900); -// } -// -// /** -// * Creates the Cache object of size of 900. -// */ -// public Cache() { -// this(28, 900); -// } -// END android-removed + // BEGIN android-removed + // /** + // * Creates the Cache object of size of 900. + // * @param pref_size specifies how many leading/trailing bytes of object's + // * encoded form will be used for hash computation + // */ + // public Cache(int pref_size) { + // this(pref_size, 900); + // } + // + // /** + // * Creates the Cache object of size of 900. + // */ + // public Cache() { + // this(28, 900); + // } + // END android-removed -// BEGIN android-added + // BEGIN android-added /** * Creates the Cache object of size of 9. * @param pref_size specifies how many leading/trailing bytes of object's @@ -172,7 +172,7 @@ public class Cache { public Cache() { this(28, 9); } -// END android-added + // END android-added /** * Returns the hash code for the array. This code is used to diff --git a/security/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java b/security/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java index 09b437c..20e73bd 100644 --- a/security/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java +++ b/security/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java @@ -38,7 +38,6 @@ import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.CertificateParsingException; import java.security.cert.X509Certificate; -import java.security.interfaces.RSAPublicKey; import java.util.Collection; import java.util.Date; import java.util.List; @@ -52,7 +51,11 @@ import org.apache.harmony.security.x509.Certificate; import org.apache.harmony.security.x509.Extension; import org.apache.harmony.security.x509.Extensions; import org.apache.harmony.security.x509.TBSCertificate; + +// BEGIN android-added +import java.security.interfaces.RSAPublicKey; import org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl; +// END android-added /** * This class is an implementation of X509Certificate. It wraps @@ -175,12 +178,16 @@ public class X509CertImpl extends X509Certificate { } long time = date.getTime(); if (time < notBefore) { + // BEGIN android-changed throw new CertificateNotYetValidException("current time: " + date + ", validation time: " + new Date(notBefore)); + // END android-changed } if (time > notAfter) { + // BEGIN android-changed throw new CertificateExpiredException("current time: " + date + ", expiration time: " + new Date(notAfter)); + // END android-changed } } diff --git a/security/src/main/java/org/bouncycastle/jce/provider/JCEBlockCipher.java b/security/src/main/java/org/bouncycastle/jce/provider/JCEBlockCipher.java index 85b94e0..d2b50ef 100644 --- a/security/src/main/java/org/bouncycastle/jce/provider/JCEBlockCipher.java +++ b/security/src/main/java/org/bouncycastle/jce/provider/JCEBlockCipher.java @@ -666,10 +666,21 @@ public class JCEBlockCipher extends WrapCipherSpi int inputLen, byte[] output, int outputOffset) - throws IllegalBlockSizeException, BadPaddingException + throws IllegalBlockSizeException, BadPaddingException, ShortBufferException { + // BEGIN android-note + // added ShortBufferException to the throws statement + // END android-note int len = 0; + // BEGIN android-added + int outputLen = cipher.getOutputSize(inputLen); + + if (outputLen + outputOffset > output.length) { + throw new ShortBufferException("need at least " + outputLen + " bytes"); + } + // BEGIN android-added + if (inputLen != 0) { len = cipher.processBytes(input, inputOffset, inputLen, output, outputOffset); diff --git a/security/src/main/java/org/bouncycastle/jce/provider/WrapCipherSpi.java b/security/src/main/java/org/bouncycastle/jce/provider/WrapCipherSpi.java index 4f14b85..5ac8938 100644 --- a/security/src/main/java/org/bouncycastle/jce/provider/WrapCipherSpi.java +++ b/security/src/main/java/org/bouncycastle/jce/provider/WrapCipherSpi.java @@ -250,16 +250,19 @@ public abstract class WrapCipherSpi extends CipherSpi return null; } + // BEGIN android-changed + // added ShortBufferException to throws statement protected int engineDoFinal( byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) - throws IllegalBlockSizeException, BadPaddingException + throws IllegalBlockSizeException, BadPaddingException, ShortBufferException { return 0; } + // END android-changed protected byte[] engineWrap( Key key) @@ -292,8 +295,11 @@ public abstract class WrapCipherSpi extends CipherSpi byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) - throws InvalidKeyException + throws InvalidKeyException, NoSuchAlgorithmException { + // BEGIN android-note + // added ShortBufferException to throws statement + // END android-note byte[] encoded = null; try { @@ -395,10 +401,12 @@ public abstract class WrapCipherSpi extends CipherSpi { throw new InvalidKeyException("Unknown key type " + e.getMessage()); } - catch (NoSuchAlgorithmException e) - { - throw new InvalidKeyException("Unknown key type " + e.getMessage()); - } + // BEGIN android-removed + // catch (NoSuchAlgorithmException e) + // { + // throw new InvalidKeyException("Unknown key type " + e.getMessage()); + // } + // END android-removed catch (InvalidKeySpecException e2) { throw new InvalidKeyException("Unknown key type " + e2.getMessage()); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java index e9088de..552c1b4 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlException2Test.java @@ -17,9 +17,15 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + import java.io.FilePermission; import java.security.AccessControlException; +@TestTargetClass(AccessControlException.class) public class AccessControlException2Test extends junit.framework.TestCase { FilePermission filePermission; @@ -30,6 +36,15 @@ public class AccessControlException2Test extends junit.framework.TestCase { /** * @tests java.security.AccessControlException#AccessControlException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "AccessControlException", + methodArgs = {java.lang.String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.AccessControlException(java.lang.String) @@ -43,6 +58,15 @@ public class AccessControlException2Test extends junit.framework.TestCase { * @tests java.security.AccessControlException#AccessControlException(java.lang.String, * java.security.Permission) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "AccessControlException", + methodArgs = {java.lang.String.class, java.security.Permission.class} + ) + }) public void test_ConstructorLjava_lang_StringLjava_security_Permission() { // Test for method // java.security.AccessControlException(java.lang.String, @@ -57,6 +81,15 @@ public class AccessControlException2Test extends junit.framework.TestCase { /** * @tests java.security.AccessControlException#getPermission() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPermission", + methodArgs = {} + ) + }) public void test_getPermission() { // Test for method java.security.Permission // java.security.AccessControlException.getPermission() diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java index cf58e97..b3162e8 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessControlExceptionTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AccessControlException; import java.security.AllPermission; import java.security.Permission; @@ -32,7 +37,7 @@ import junit.framework.TestCase; /** * Unit test for AccessControlException. */ - +@TestTargetClass(AccessControlException.class) public class AccessControlExceptionTest extends TestCase { /** @@ -46,6 +51,15 @@ public class AccessControlExceptionTest extends TestCase { /** * Tests AccessControlException(String) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "AccessControlException", + methodArgs = {java.lang.String.class} + ) + }) public void testAccessControlExceptionString() { new AccessControlException(null); new AccessControlException("Failure"); @@ -54,6 +68,15 @@ public class AccessControlExceptionTest extends TestCase { /** * Tests AccessControlException(String, Permission) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with positive arguments only", + targets = { + @TestTarget( + methodName = "AccessControlException", + methodArgs = {java.lang.String.class, java.security.Permission.class} + ) + }) public void testAccessControlExceptionStringPermission() { Permission perm = new AllPermission(); new AccessControlException("001", perm); @@ -63,6 +86,15 @@ public class AccessControlExceptionTest extends TestCase { * * Tests AccessControlException.getPermission() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPermission", + methodArgs = {} + ) + }) public void testGetPermission() { Permission perm = new UnresolvedPermission("unresolvedType", "unresolvedName", "unresolvedActions", null); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java index 6ebb735..a12d01f 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java @@ -17,18 +17,34 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AccessController; import java.security.AllPermission; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; +@TestTargetClass(AccessController.class) public class AccessController2Test extends junit.framework.TestCase { /** * @tests java.security.AccessController#doPrivileged(java.security.PrivilegedAction, * java.security.AccessControlContext)) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. Need remove conversion (Boolean) before AccessController.doPrivileged method in the test." + + "2. Exception NullPointerException if the action is null is not checked.", + targets = { + @TestTarget( + methodName = "doPrivileged", + methodArgs = {PrivilegedAction.class, java.security.AccessControlContext.class} + ) + }) public void testDoPrivilegedLjava_security_PrivilegedActionLjava_security_AccessControlContext() { Boolean pass; @@ -66,6 +82,16 @@ public class AccessController2Test extends junit.framework.TestCase { /** * @tests java.security.AccessController#doPrivileged(java.security.PrivilegedAction)) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. Need remove conversion (Boolean) before AccessController.doPrivileged method in the test." + + "2. Exception NullPointerException if the action is null is not checked.", + targets = { + @TestTarget( + methodName = "doPrivileged", + methodArgs = {PrivilegedAction.class} + ) + }) public void testDoPrivilegedLjava_security_PrivilegedAction() { Boolean pass; @@ -90,6 +116,17 @@ public class AccessController2Test extends junit.framework.TestCase { * @tests java.security.AccessController#doPrivileged(java.security.PrivilegedExceptionAction, * java.security.AccessControlContext)) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. Need remove conversion (Boolean) before AccessController.doPrivileged method in the test." + + "2. Exception NullPointerException if the action is null is not checked." + + "3. Exception PrivilegedActionException is not checked.", + targets = { + @TestTarget( + methodName = "doPrivileged", + methodArgs = {PrivilegedExceptionAction.class, java.security.AccessControlContext.class} + ) + }) public void testDoPrivilegedLjava_security_PrivilegedExceptionActionLjava_security_AccessControlContext() { Boolean pass; try { @@ -130,6 +167,17 @@ public class AccessController2Test extends junit.framework.TestCase { /** * @tests java.security.AccessController#doPrivileged(java.security.PrivilegedExceptionAction)) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. Need remove conversion (Boolean) before AccessController.doPrivileged method in the test." + + "2. Exception NullPointerException if the action is null is not checked." + + "3. Exception PrivilegedActionException is not checked.", + targets = { + @TestTarget( + methodName = "doPrivileged", + methodArgs = {PrivilegedExceptionAction.class} + ) + }) public void testDoPrivilegedLjava_security_PrivilegedExceptionAction() { Boolean pass; try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java index a07a52a..cbd5529 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator1Test.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameterGeneratorSpi; import java.security.AlgorithmParameters; @@ -35,8 +41,7 @@ import org.apache.harmony.security.tests.support.MyAlgorithmParameterGeneratorSp import org.apache.harmony.security.tests.support.SpiEngUtils; import junit.framework.TestCase; - - +@TestTargetClass(AlgorithmParameterGenerator.class) /** * Tests for <code>AlgorithmParameterGenerator</code> class constructors and * methods. @@ -101,6 +106,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * throws NoSuchAlgorithmException must be thrown if algorithm is not available * */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testAlgorithmParameterGenerator01() throws NoSuchAlgorithmException { try { @@ -123,6 +137,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * Assertion: returns AlgorithmParameterGenerator instance * when algorithm is DSA */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testAlgorithmParameterGenerator02() throws NoSuchAlgorithmException { if (!DSASupported) { @@ -142,6 +165,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * Assertion: * throws IllegalArgumentException if provider is null or empty */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testAlgorithmParameterGenerator03() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DSASupported) { @@ -169,6 +201,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * Assertion: throws NoSuchProviderException if provider is not * available */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testAlgorithmParameterGenerator04() throws NoSuchAlgorithmException { if (!DSASupported) { @@ -195,6 +236,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * throws NullPointerException must be thrown is null * throws NoSuchAlgorithmException must be thrown if algorithm is not available */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testAlgorithmParameterGenerator05() throws NoSuchProviderException { if (!DSASupported) { @@ -223,6 +273,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * method * Assertion: return AlgorithmParameterGenerator */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testAlgorithmParameterGenerator06() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DSASupported) { @@ -244,6 +303,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * method * Assertion: throws IllegalArgumentException when provider is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testAlgorithmParameterGenerator07() throws NoSuchAlgorithmException { if (!DSASupported) { @@ -267,6 +335,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * throws NullPointerException must be thrown is null * throws NoSuchAlgorithmException must be thrown if algorithm is not available */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testAlgorithmParameterGenerator08() { if (!DSASupported) { fail(validAlgName + " algorithm is not supported"); @@ -294,6 +371,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * method * Assertion: returns AlgorithmParameterGenerator object */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testAlgorithmParameterGenerator09() throws NoSuchAlgorithmException { if (!DSASupported) { @@ -312,7 +398,16 @@ public class AlgorithmParameterGenerator1Test extends TestCase { /** * Test for <code>generateParameters()</code> method * Assertion: returns AlgorithmParameters object - */ + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "generateParameters", + methodArgs = {} + ) + }) public void testAlgorithmParameterGenerator10() throws NoSuchAlgorithmException { if (!DSASupported) { @@ -333,6 +428,19 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * methods * Assertion: throws InvalidAlgorithmParameterException when param is null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exception case was verified only", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {AlgorithmParameterSpec.class} + ), + @TestTarget( + methodName = "init", + methodArgs = {AlgorithmParameterSpec.class, SecureRandom.class} + ) + }) public void testAlgorithmParameterGenerator12() { if (!DSASupported) { fail(validAlgName + " algorithm is not supported"); @@ -345,9 +453,17 @@ public class AlgorithmParameterGenerator1Test extends TestCase { apgs); for (int i = 0; i < apgs.length; i++) { try { + apgs[i].init(aps); + fail("InvalidAlgorithmParameterException must be throws when param is null"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } + + try { apgs[i].init(aps, random); fail("InvalidAlgorithmParameterException must be throws when param is null"); - } catch (InvalidAlgorithmParameterException e) { + } catch (InvalidAlgorithmParameterException e) { + //expected } } } @@ -356,6 +472,15 @@ public class AlgorithmParameterGenerator1Test extends TestCase { * Test for <code>AlgorithmParameterGenerator</code> constructor * Assertion: returns AlgorithmParameterGenerator object */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Constructor was used without invalid parameters", + targets = { + @TestTarget( + methodName = "AlgorithmParameterGenerator", + methodArgs = {AlgorithmParameterGeneratorSpi.class, Provider.class, String.class} + ) + }) public void testAlgorithmParameterGeneratorConstr() throws NoSuchAlgorithmException { if (!DSASupported) { fail(validAlgName + " algorithm is not supported"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java index 7fc2171..f3dceea 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator2Test.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; @@ -34,8 +40,7 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.security.tests.support.SpiEngUtils; import junit.framework.TestCase; - - +@TestTargetClass(AlgorithmParameterGenerator.class) /** * Tests for <code>AlgorithmParameterGenerator</code> class constructors and * methods. @@ -124,6 +129,15 @@ public class AlgorithmParameterGenerator2Test extends TestCase { * throws NoSuchAlgorithmException must be thrown if algorithm is not available * returns AlgorithmParameterGenerator object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testGetInstance01() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { try { @@ -160,6 +174,15 @@ public class AlgorithmParameterGenerator2Test extends TestCase { * throws NoSuchProviderException when provider is available; * returns AlgorithmParameterGenerator object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testGetInstance02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException { @@ -220,6 +243,15 @@ public class AlgorithmParameterGenerator2Test extends TestCase { * throws IllegalArgumentException when provider is null; * returns AlgorithmParameterGenerator object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testGetInstance03() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator3Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator3Test.java index 0b0ddcd..5b09b59 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator3Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator3Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.math.BigInteger; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; @@ -27,11 +32,21 @@ import java.security.SecureRandom; import java.security.Security; import java.security.spec.DSAParameterSpec; +@TestTargetClass(AlgorithmParameterGenerator.class) public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { /** * @tests java.security.AlgorithmParameterGenerator#generateParameters() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "generateParameters", + methodArgs = {} + ) + }) public void test_generateParameters() throws Exception { //fail("Takes ages. Problem with SecureRandom and stub math ?"); @@ -50,6 +65,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { /** * @tests java.security.AlgorithmParameterGenerator#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() throws Exception { // Test for method java.lang.String // java.security.AlgorithmParameterGenerator.getAlgorithm() @@ -61,6 +85,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { /** * @tests java.security.AlgorithmParameterGenerator#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies getInstance with parameter", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() throws Exception { // Test for method java.security.AlgorithmParameterGenerator // java.security.AlgorithmParameterGenerator.getInstance(java.lang.String) @@ -71,6 +104,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { * @tests java.security.AlgorithmParameterGenerator#getInstance(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test NoSuchAlgorithmException is missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception { // Test for method java.security.AlgorithmParameterGenerator // java.security.AlgorithmParameterGenerator.getInstance(java.lang.String, @@ -115,6 +157,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { /** * @tests java.security.AlgorithmParameterGenerator#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies provider with null parameter", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() throws Exception { // Test for method java.security.Provider // java.security.AlgorithmParameterGenerator.getProvider() @@ -127,6 +178,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { /** * @tests java.security.AlgorithmParameterGenerator#init(int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Boundary/invalid/negative parameters checking missed", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class} + ) + }) public void test_initI() throws Exception { // Test for method void // java.security.AlgorithmParameterGenerator.init(int) @@ -140,6 +200,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { * @tests java.security.AlgorithmParameterGenerator#init(int, * java.security.SecureRandom) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Boundary/invalid/negative parameters checking missed", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {int.class, SecureRandom.class} + ) + }) public void test_initILjava_security_SecureRandom() throws Exception { // Test for method void // java.security.AlgorithmParameterGenerator.init(int, @@ -153,6 +222,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { /** * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies InvalidAlgorithmParameterException exception only", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class} + ) + }) public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception { // Test for method void // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec) @@ -173,6 +251,15 @@ public class AlgorithmParameterGenerator3Test extends junit.framework.TestCase { * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec, * java.security.SecureRandom) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies InvalidAlgorithmParameterException exception only", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class, SecureRandom.class} + ) + }) public void test_initLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom() throws Exception { // Test for method void // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec, diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java index 70a9f45..37c8590 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.IOException; import java.math.BigInteger; import java.security.AlgorithmParameters; @@ -34,7 +39,7 @@ import java.security.spec.InvalidParameterSpecException; import java.util.Arrays; import junit.framework.TestCase; - +@TestTargetClass(AlgorithmParameters.class) /** * Tests for <code>AlgorithmParameters</code> class constructors and * methods. @@ -67,6 +72,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() throws Exception { // test: null value @@ -81,6 +95,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getEncoded() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) public void test_getEncoded() throws Exception { final byte[] enc = new byte[] { 0x02, 0x01, 0x03 }; @@ -114,6 +137,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getEncoded(String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {java.lang.String.class} + ) + }) public void test_getEncodedLjava_lang_String() throws Exception { final byte[] enc = new byte[] { 0x02, 0x01, 0x03 }; @@ -165,6 +197,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getInstance(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exception NoSuchAlgorithmException wasn't checked", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) public void test_getInstanceLjava_lang_String() throws Exception { AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC"); @@ -179,6 +220,16 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getInstance(String, String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions NoSuchAlgorithmException, NoSuchProviderException," + + " IllegalArgumentException weren't checked", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception { @@ -195,6 +246,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getParameterSpec(Class) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParameterSpec", + methodArgs = {java.lang.Class.class} + ) + }) public void test_getParameterSpecLjava_lang_Class() throws Exception { final MyAlgorithmParameterSpec myParamSpec = new MyAlgorithmParameterSpec(); @@ -253,6 +313,16 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getInstance(String, Provider) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions NoSuchAlgorithmException, IllegalArgumentException" + + " weren't checked", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_security_Provider() throws Exception { @@ -268,6 +338,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() throws Exception { // test: null value AlgorithmParameters ap = new DummyAlgorithmParameters(null, null, "AAA"); @@ -281,6 +360,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#init(java.security.spec.AlgorithmParameterSpec) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {AlgorithmParameterSpec.class} + ) + }) public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception { @@ -351,6 +439,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#init(byte[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {byte[].class} + ) + }) public void test_init$B() throws Exception { // @@ -418,6 +515,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#init(byte[],String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {byte[].class, String.class} + ) + }) public void test_init$BLjava_lang_String() throws Exception { // @@ -495,6 +601,15 @@ public class AlgorithmParametersTest extends TestCase { /** * @tests java.security.AlgorithmParameters#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() throws Exception { final String str = "AlgorithmParameters"; @@ -518,6 +633,15 @@ public class AlgorithmParametersTest extends TestCase { /** * Tests DSA AlgorithmParameters provider */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just DSA parameter checked", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) public void testDSAProvider() throws Exception { AlgorithmParameters params = AlgorithmParameters.getInstance("DSA"); @@ -566,6 +690,15 @@ public class AlgorithmParametersTest extends TestCase { /** * Tests OAEP AlgorithmParameters provider */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just OAEP parameter tested", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testOAEPProvider() throws Exception { AlgorithmParameters params = AlgorithmParameters.getInstance("OAEP"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java index e651221..680286c 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AllPermission2Test.java @@ -17,17 +17,32 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AllPermission; import java.security.Permission; import java.security.PermissionCollection; import java.security.SecurityPermission; import java.util.Enumeration; +@TestTargetClass(AllPermission.class) public class AllPermission2Test extends junit.framework.TestCase { /** * @tests java.security.AllPermission#AllPermission() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "AllPermission", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.AllPermission() AllPermission ap = new AllPermission(); @@ -39,6 +54,15 @@ public class AllPermission2Test extends junit.framework.TestCase { * @tests java.security.AllPermission#AllPermission(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null/empty parameters checking missed", + targets = { + @TestTarget( + methodName = "AllPermission", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void test_ConstructorLjava_lang_StringLjava_lang_String() { // Test for method java.security.AllPermission(java.lang.String, // java.lang.String) @@ -54,6 +78,16 @@ public class AllPermission2Test extends junit.framework.TestCase { /** * @tests java.security.AllPermission#equals(java.lang.Object) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Update comment for first assertTrue method." + + "Because: Two AllPermission objects are always equal", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void test_equalsLjava_lang_Object() { // Test for method boolean // java.security.AllPermission.equals(java.lang.Object) @@ -66,6 +100,15 @@ public class AllPermission2Test extends junit.framework.TestCase { /** * @tests java.security.AllPermission#getActions() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getActions", + methodArgs = {} + ) + }) public void test_getActions() { AllPermission ap = new AllPermission(); // Test for method java.lang.String @@ -77,6 +120,15 @@ public class AllPermission2Test extends junit.framework.TestCase { /** * @tests java.security.AllPermission#hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void test_hashCode() { final int ALLPERMISSION_HASH = 1; // Test for method int java.security.AllPermission.hashCode() @@ -90,6 +142,15 @@ public class AllPermission2Test extends junit.framework.TestCase { /** * @tests java.security.AllPermission#implies(java.security.Permission) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {java.security.Permission.class} + ) + }) public void test_impliesLjava_security_Permission() { // Test for method boolean // java.security.AllPermission.implies(java.security.Permission) @@ -104,6 +165,15 @@ public class AllPermission2Test extends junit.framework.TestCase { /** * @tests java.security.AllPermission#newPermissionCollection() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void test_newPermissionCollection() { AllPermission ap1 = new AllPermission(); AllPermission ap2 = new AllPermission("Don't remember this stupid name", diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AllTests.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AllTests.java index 10fb18a..d76400e 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AllTests.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AllTests.java @@ -35,7 +35,7 @@ public class AllTests { suite.addTestSuite(AccessControlException2Test.class); suite.addTestSuite(AccessControlExceptionTest.class); - suite.addTestSuite(AccessController2Test.class); +// suite.addTestSuite(AccessController2Test.class); suite.addTestSuite(AlgorithmParameterGenerator1Test.class); suite.addTestSuite(AlgorithmParameterGenerator2Test.class); suite.addTestSuite(AlgorithmParameterGenerator3Test.class); @@ -112,7 +112,7 @@ public class AllTests { suite.addTestSuite(ProviderServiceTest.class); suite.addTestSuite(ProviderTest.class); suite.addTestSuite(PublicKeyTest.class); - suite.addTestSuite(SecureClassLoader2Test.class); +// suite.addTestSuite(SecureClassLoader2Test.class); suite.addTestSuite(SecureRandom2Test.class); suite.addTestSuite(Security2Test.class); suite.addTestSuite(SecurityPermission2Test.class); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/AuthProviderTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/AuthProviderTest.java index 7e511b3..9da1d46 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/AuthProviderTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/AuthProviderTest.java @@ -16,13 +16,18 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AuthProvider; import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import junit.framework.TestCase; - +@TestTargetClass(AuthProvider.class) public class AuthProviderTest extends TestCase { protected void setUp() throws Exception { @@ -36,7 +41,16 @@ public class AuthProviderTest extends TestCase { /** * @tests java.security.AuthProvider#AuthProvider(String, double, String) */ - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies all negative variants in the one test case instead of" + + " three tests for each case", + targets = { + @TestTarget( + methodName = "AuthProvider", + methodArgs = {java.lang.String.class, double.class, java.lang.String.class} + ) + }) public void testConstructor() { AuthProviderStub ap = new AuthProviderStub("name", 1.0, "info"); assertEquals("name", ap.getName()); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java index de99a0b..729e3ce 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java @@ -17,9 +17,15 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.BasicPermission; import java.security.PermissionCollection; +@TestTargetClass(BasicPermission.class) public class BasicPermission2Test extends junit.framework.TestCase { public static class BasicPermissionSubclass extends BasicPermission { @@ -45,6 +51,17 @@ public class BasicPermission2Test extends junit.framework.TestCase { /** * @tests java.security.BasicPermission#BasicPermission(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test cases, where parameter name is null (expect NullPointerException)" + + " and parameter name is empty (expect IllegalArgumentException)" + + " are absent", + targets = { + @TestTarget( + methodName = "BasicPermission", + methodArgs = {java.lang.String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.BasicPermission(java.lang.String) assertEquals("Incorrect name returned", "aName", bp.getName()); @@ -54,6 +71,17 @@ public class BasicPermission2Test extends junit.framework.TestCase { * @tests java.security.BasicPermission#BasicPermission(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test cases, where parameter name is null (expect NullPointerException)" + + " and parameter name is empty (expect IllegalArgumentException)" + + " are absent", + targets = { + @TestTarget( + methodName = "BasicPermission", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void test_ConstructorLjava_lang_StringLjava_lang_String() { // Test for method java.security.BasicPermission(java.lang.String, // java.lang.String) @@ -63,6 +91,15 @@ public class BasicPermission2Test extends junit.framework.TestCase { /** * @tests java.security.BasicPermission#equals(java.lang.Object) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void test_equalsLjava_lang_Object() { // Test for method boolean // java.security.BasicPermission.equals(java.lang.Object) @@ -75,6 +112,15 @@ public class BasicPermission2Test extends junit.framework.TestCase { /** * @tests java.security.BasicPermission#getActions() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getActions", + methodArgs = {} + ) + }) public void test_getActions() { // Test for method java.lang.String // java.security.BasicPermission.getActions() @@ -87,6 +133,15 @@ public class BasicPermission2Test extends junit.framework.TestCase { /** * @tests java.security.BasicPermission#hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void test_hashCode() { // Test for method int java.security.BasicPermission.hashCode() assertTrue("Equal objects should return same hash", @@ -96,6 +151,15 @@ public class BasicPermission2Test extends junit.framework.TestCase { /** * @tests java.security.BasicPermission#implies(java.security.Permission) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {java.security.Permission.class} + ) + }) public void test_impliesLjava_security_Permission() { // Test for method boolean // java.security.BasicPermission.implies(java.security.Permission) @@ -110,6 +174,15 @@ public class BasicPermission2Test extends junit.framework.TestCase { /** * @tests java.security.BasicPermission#newPermissionCollection() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void test_newPermissionCollection() { // Test for method java.security.PermissionCollection // java.security.BasicPermission.newPermissionCollection() diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java index 1061d91..677c68e 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSignerTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.CodeSigner; import java.security.Timestamp; import java.security.cert.CertPath; @@ -29,8 +35,7 @@ import java.util.Date; import org.apache.harmony.security.tests.support.TestCertUtils; import junit.framework.TestCase; - - +@TestTargetClass(CodeSigner.class) /** * Unit test for CodeSigner. */ @@ -53,6 +58,15 @@ public class CodeSignerTest extends TestCase { /** * must throw NPE if signerCertPath is null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test case where parameters are not null is absent", + targets = { + @TestTarget( + methodName = "CodeSigner", + methodArgs = {CertPath.class, Timestamp.class} + ) + }) public void testCodeSigner_00() { try { new CodeSigner(null, ts); @@ -65,6 +79,15 @@ public class CodeSignerTest extends TestCase { /** * timestamp can be null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test case where timestamp is not null is absent", + targets = { + @TestTarget( + methodName = "CodeSigner", + methodArgs = {CertPath.class, Timestamp.class} + ) + }) public final void testCodeSigner_01() { new CodeSigner(cpath, null); } @@ -72,6 +95,15 @@ public class CodeSignerTest extends TestCase { /** * Test various assertions about equals() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public final void testEqualsObject() { CodeSigner one = new CodeSigner(cpath, ts); @@ -97,6 +129,15 @@ public class CodeSignerTest extends TestCase { /** * Tests CodeSigner.getSignerCertPath() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSignerCertPath", + methodArgs = {} + ) + }) public void testGetSignerCertPath() { assertSame(new CodeSigner(cpath, null).getSignerCertPath(), cpath); } @@ -104,6 +145,15 @@ public class CodeSignerTest extends TestCase { /** * Tests CodeSigner.getTimeStamp() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getTimestamp", + methodArgs = {} + ) + }) public void testGetTimestamp() { assertNull(new CodeSigner(cpath, null).getTimestamp()); assertSame(new CodeSigner(cpath, ts).getTimestamp(), ts); @@ -112,6 +162,15 @@ public class CodeSignerTest extends TestCase { /** * Tests CodeSigner.toString() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Need use method equals for returned string", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { assertTrue(new CodeSigner(cpath, null).toString().contains("")); assertTrue(new CodeSigner(cpath, ts).toString().contains("")); @@ -120,6 +179,15 @@ public class CodeSignerTest extends TestCase { /** * Tests CodeSigner.hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode() { CodeSigner cs1 = new CodeSigner(cpath, ts); CodeSigner cs2 = new CodeSigner(cpath, ts); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java index 6fe01a0..e270604 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSource2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.net.URL; import java.security.CodeSigner; import java.security.CodeSource; @@ -29,7 +34,7 @@ import java.util.Date; import org.apache.harmony.security.tests.support.TestCertUtils; - +@TestTargetClass(CodeSource.class) public class CodeSource2Test extends junit.framework.TestCase { /** @@ -37,6 +42,15 @@ public class CodeSource2Test extends junit.framework.TestCase { * @tests java.security.CodeSource#CodeSource(java.net.URL, * java.security.cert.Certificate[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with valid URL and null certificate array", + targets = { + @TestTarget( + methodName = "CodeSource", + methodArgs = {URL.class, Certificate[].class} + ) + }) public void test_ConstructorLjava_net_URL$Ljava_security_cert_Certificate() throws Exception { // Test for method java.security.CodeSource(java.net.URL, @@ -49,6 +63,15 @@ public class CodeSource2Test extends junit.framework.TestCase { * @tests java.security.CodeSource#CodeSource(java.net.URL, * java.security.CodeSigner[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CodeSource", + methodArgs = {URL.class, CodeSigner[].class} + ) + }) public void test_ConstructorLjava_net_URL$Ljava_security_CodeSigner() { // Test for method java.security.CodeSource(java.net.URL, // java.security.cert.CodeSigner []) @@ -83,6 +106,15 @@ public class CodeSource2Test extends junit.framework.TestCase { /** * @tests java.security.CodeSource#equals(java.lang.Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "CodeSource object was created with CodeSource(URL url, Certificate[] certs) only", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void test_equalsLjava_lang_Object() throws Exception { // Test for method boolean // java.security.CodeSource.equals(java.lang.Object) @@ -96,6 +128,15 @@ public class CodeSource2Test extends junit.framework.TestCase { /** * @tests java.security.CodeSource#hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void test_hashCode() throws Exception { URL url = new java.net.URL("file:///test"); CodeSource cs = new CodeSource(url, (Certificate[]) null); @@ -106,6 +147,15 @@ public class CodeSource2Test extends junit.framework.TestCase { /** * @tests java.security.CodeSource#getCertificates() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies case for null certificates only", + targets = { + @TestTarget( + methodName = "getCertificates", + methodArgs = {} + ) + }) public void test_getCertificates() throws Exception { CodeSource cs = new CodeSource(new java.net.URL("file:///test"), (Certificate[]) null); @@ -116,6 +166,15 @@ public class CodeSource2Test extends junit.framework.TestCase { /** * @tests java.security.CodeSource#getLocation() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getLocation", + methodArgs = {} + ) + }) public void test_getLocation() throws Exception { // Test for method java.net.URL java.security.CodeSource.getLocation() CodeSource cs = new CodeSource(new java.net.URL("file:///test"), @@ -127,6 +186,15 @@ public class CodeSource2Test extends junit.framework.TestCase { /** * @tests java.security.CodeSource#implies(java.security.CodeSource) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void test_impliesLjava_security_CodeSource() throws Exception { // Test for method boolean // java.security.CodeSource.implies(java.security.CodeSource) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java index 010f687..5457c50 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.net.URL; import java.net.InetAddress; @@ -34,8 +40,7 @@ import java.security.cert.Certificate; import org.apache.harmony.security.tests.support.TestCertUtils; import junit.framework.TestCase; - - +@TestTargetClass(CodeSource.class) /** * Unit test for CodeSource. * @@ -124,6 +129,15 @@ public class CodeSourceTest extends TestCase { * Tests hashCode().<br> * javadoc says nothing, so test DRL-specific implementation. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode() { // when nothing is specified, then hashCode obviously must be 0. assertTrue(new CodeSource(null, (Certificate[]) null).hashCode() == 0); @@ -138,6 +152,15 @@ public class CodeSourceTest extends TestCase { /** * Tests CodeSource(URL, Certificate[]). */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CodeSource", + methodArgs = {URL.class, Certificate[].class} + ) + }) public void testCodeSourceURLCertificateArray() { new CodeSource(null, (Certificate[]) null); new CodeSource(urlSite, (Certificate[]) null); @@ -148,6 +171,15 @@ public class CodeSourceTest extends TestCase { /** * Tests CodeSource(URL, CodeSigner[]). */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameters only", + targets = { + @TestTarget( + methodName = "CodeSource", + methodArgs = {URL.class, CodeSigner[].class} + ) + }) public void testCodeSourceURLCodeSignerArray() { if (!has_15_features()) { return; @@ -159,6 +191,15 @@ public class CodeSourceTest extends TestCase { /** * equals(Object) must return <code>false</code> for null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Null parameter checked", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEqualsObject_00() { CodeSource thiz = new CodeSource(urlSite, (Certificate[]) null); assertFalse(thiz.equals(null)); @@ -168,6 +209,15 @@ public class CodeSourceTest extends TestCase { /** * equals(Object) must return <code>true</code> for the same object */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Same objects checked", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEqualsObject_01() { CodeSource thiz = new CodeSource(urlSite, (Certificate[]) null); assertTrue(thiz.equals(thiz)); @@ -178,6 +228,15 @@ public class CodeSourceTest extends TestCase { * The signer certificate chain must contain the same set of certificates, but * the order of the certificates is not taken into account. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEqualsObject_02() { Certificate cert0 = new TestCertUtils.TestCertificate(); Certificate cert1 = new TestCertUtils.TestCertificate(); @@ -192,6 +251,15 @@ public class CodeSourceTest extends TestCase { * Test for equals(Object)<br> * Checks that both 'null' and not-null URLs are taken into account - properly. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEqualsObject_04() { CodeSource thiz = new CodeSource(urlSite, (Certificate[]) null); CodeSource that = new CodeSource(null, (Certificate[]) null); @@ -206,6 +274,15 @@ public class CodeSourceTest extends TestCase { /** * Tests CodeSource.getCertificates(). */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificates", + methodArgs = {} + ) + }) public void testGetCertificates_00() { assertNull(new CodeSource(null, (Certificate[]) null).getCertificates()); java.security.cert.Certificate[] got = new CodeSource(null, chain) @@ -220,6 +297,15 @@ public class CodeSourceTest extends TestCase { * Tests whether the getCertificates() returns certificates obtained from * the signers. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificates", + methodArgs = {} + ) + }) public void testGetCertificates_01() { if (!has_15_features()) { return; @@ -318,6 +404,15 @@ public class CodeSourceTest extends TestCase { /** * Tests CodeSource.getCodeSigners(). */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getCodeSigners", + methodArgs = {} + ) + }) public void testGetCodeSigners_00() { if (!has_15_features()) { return; @@ -342,6 +437,18 @@ public class CodeSourceTest extends TestCase { } } + /** + * Tests CodeSource.getCodeSigners() for null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getCodeSigners", + methodArgs = {} + ) + }) public void testGetCoderSignersNull() throws Exception{ assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners()); //$NON-NLS-1$ } @@ -349,6 +456,15 @@ public class CodeSourceTest extends TestCase { /** * Tests CodeSource.getLocation() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getLocation", + methodArgs = {} + ) + }) public void testGetLocation() { assertTrue(new CodeSource(urlSite, (Certificate[]) null).getLocation() == urlSite); assertTrue(new CodeSource(urlSite, chain).getLocation() == urlSite); @@ -359,6 +475,15 @@ public class CodeSourceTest extends TestCase { /** * Tests CodeSource.toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { // Javadoc keeps silence about String's format, // just make sure it can be invoked. @@ -389,6 +514,15 @@ public class CodeSourceTest extends TestCase { /** * must not imply null CodeSource */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_00() { CodeSource cs0 = new CodeSource(null, (Certificate[]) null); assertFalse(cs0.implies(null)); @@ -398,6 +532,15 @@ public class CodeSourceTest extends TestCase { * CodeSource with location=null && Certificate[] == null implies any other * CodeSource */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_01() throws Exception { CodeSource thizCS = new CodeSource(urlSite, (Certificate[]) null); CodeSource thatCS = new CodeSource(null, (Certificate[]) null); @@ -410,6 +553,15 @@ public class CodeSourceTest extends TestCase { /** * If this object's location equals codesource's location, then return true. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_02() throws Exception { CodeSource thizCS = new CodeSource(urlSite, (Certificate[]) null); CodeSource thatCS = new CodeSource(thizCS.getLocation(), @@ -434,7 +586,15 @@ public class CodeSourceTest extends TestCase { assertFalse(thatCS.implies(thizCS)); } */ - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_03_tmp() throws Exception { CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); CodeSource thatCS = new CodeSource(urlDir_FileProtocol, @@ -448,6 +608,15 @@ public class CodeSourceTest extends TestCase { * SocketPermission constructed with this object's host must imply the * SocketPermission constructed with codesource's host. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_04() throws Exception { CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); CodeSource thatCS = new CodeSource(urlDirIP, (Certificate[]) null); @@ -477,6 +646,15 @@ public class CodeSourceTest extends TestCase { * If this object's port (getLocation().getPort()) is not equal to -1 (that * is, if a port is specified), it must equal codesource's port. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_05() throws Exception { CodeSource thizCS = new CodeSource(urlDir_port80, (Certificate[]) null); CodeSource thatCS = new CodeSource(urlDir, (Certificate[]) null); @@ -502,6 +680,15 @@ public class CodeSourceTest extends TestCase { * If this object's file (getLocation().getFile()) doesn't equal * codesource's file, then the following checks are made: ... */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_06() throws Exception { CodeSource thizCS = new CodeSource(urlFile, (Certificate[]) null); CodeSource thatCS = new CodeSource(urlFile, (Certificate[]) null); @@ -512,6 +699,15 @@ public class CodeSourceTest extends TestCase { * ... If this object's file ends with "/-", then codesource's file must * start with this object's file (exclusive the trailing "-"). */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_07() throws Exception { CodeSource thiz = new CodeSource(urlFileDirMinus, (Certificate[]) null); CodeSource that = new CodeSource(urlFile, (Certificate[]) null); @@ -529,6 +725,15 @@ public class CodeSourceTest extends TestCase { * start with this object's file and must not have any further "/" * separators. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_08() throws Exception { CodeSource thiz = new CodeSource(urlFileDirStar, (Certificate[]) null); CodeSource that = new CodeSource(urlFile, (Certificate[]) null); @@ -548,6 +753,15 @@ public class CodeSourceTest extends TestCase { * ... If this object's file doesn't end with a "/", then codesource's file * must match this object's file with a '/' appended. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_09() throws Exception { CodeSource thizCS = new CodeSource(urlDir, (Certificate[]) null); CodeSource thatCS = new CodeSource(urlDirWithSlash, @@ -560,6 +774,15 @@ public class CodeSourceTest extends TestCase { * If this object's reference (getLocation().getRef()) is not null, it must * equal codesource's reference. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_0A() throws Exception { CodeSource thizCS = new CodeSource(urlRef1, (Certificate[]) null); CodeSource thatCS = new CodeSource(urlRef1, (Certificate[]) null); @@ -575,6 +798,15 @@ public class CodeSourceTest extends TestCase { * If this certificates are not null, then all of this certificates should * be presented in certificates of that codesource. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_0B() { Certificate c0 = new TestCertUtils.TestCertificate("00"); @@ -601,6 +833,15 @@ public class CodeSourceTest extends TestCase { * These special URLs have a special processing in implies(), * so they need to be covered and performance need to be checked */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_0C() throws Exception { URL url0 = new URL("http://localhost/someDir"); URL url1 = new URL("http://localhost/someOtherDir"); @@ -616,6 +857,15 @@ public class CodeSourceTest extends TestCase { * These special URLs have a special processing in implies(), * so they need to be covered and performance need to be checked */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {CodeSource.class} + ) + }) public void testImplies_0D() throws Exception { URL url0 = new URL("file:///" + System.getProperty("user.home") + File.separator + "someDir"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestException2Test.java index cfadaed..bf87901 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.DigestException; +@TestTargetClass(DigestException.class) public class DigestException2Test extends junit.framework.TestCase { /** * @tests java.security.DigestException#DigestException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.DigestException() DigestException de = new DigestException(); @@ -34,6 +49,16 @@ public class DigestException2Test extends junit.framework.TestCase { /** * @tests java.security.DigestException#DigestException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Different variants of string parameter (empty, null, etc.) " + + "weren't checked", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.DigestException(java.lang.String) DigestException de = new DigestException("Test message"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java index 5cefbe0..26b8bc3 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.DigestException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.DigestException; +import junit.framework.TestCase; +@TestTargetClass(DigestException.class) /** * Tests for <code>DigestException</code> class constructors and methods. * @@ -55,6 +60,15 @@ public class DigestExceptionTest extends TestCase { * Test for <code>DigestException()</code> constructor Assertion: * constructs DigestException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {} + ) + }) public void testDigestException01() { DigestException tE = new DigestException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -66,6 +80,15 @@ public class DigestExceptionTest extends TestCase { * constructs DigestException with detail message msg. Parameter * <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies case with differents parameters (parameter is not null)", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class} + ) + }) public void testDigestException02() { DigestException tE; for (int i = 0; i < msgs.length; i++) { @@ -80,6 +103,15 @@ public class DigestExceptionTest extends TestCase { * Test for <code>DigestException(String)</code> constructor Assertion: * constructs DigestException when <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies case with null parameter", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class} + ) + }) public void testDigestException03() { String msg = null; DigestException tE = new DigestException(msg); @@ -91,6 +123,15 @@ public class DigestExceptionTest extends TestCase { * Test for <code>DigestException(Throwable)</code> constructor Assertion: * constructs DigestException when <code>cause</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies case with null parameter", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {Throwable.class} + ) + }) public void testDigestException04() { Throwable cause = null; DigestException tE = new DigestException(cause); @@ -102,6 +143,15 @@ public class DigestExceptionTest extends TestCase { * Test for <code>DigestException(Throwable)</code> constructor Assertion: * constructs DigestException when <code>cause</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies case with not null parameter", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {Throwable.class} + ) + }) public void testDigestException05() { DigestException tE = new DigestException(tCause); if (tE.getMessage() != null) { @@ -120,6 +170,15 @@ public class DigestExceptionTest extends TestCase { * Assertion: constructs DigestException when <code>cause</code> is null * <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testDigestException06() { DigestException tE = new DigestException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -131,6 +190,15 @@ public class DigestExceptionTest extends TestCase { * Assertion: constructs DigestException when <code>cause</code> is null * <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testDigestException07() { DigestException tE; for (int i = 0; i < msgs.length; i++) { @@ -146,6 +214,15 @@ public class DigestExceptionTest extends TestCase { * Assertion: constructs DigestException when <code>cause</code> is not * null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testDigestException08() { DigestException tE = new DigestException(null, tCause); if (tE.getMessage() != null) { @@ -164,6 +241,15 @@ public class DigestExceptionTest extends TestCase { * Assertion: constructs DigestException when <code>cause</code> is not * null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "DigestException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testDigestException09() { DigestException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStream2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStream2Test.java index 5f7a3a8..8ee87a8 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStream2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStream2Test.java @@ -17,12 +17,18 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +@TestTargetClass(DigestInputStream.class) public class DigestInputStream2Test extends junit.framework.TestCase { ByteArrayInputStream inStream; @@ -35,6 +41,15 @@ public class DigestInputStream2Test extends junit.framework.TestCase { * @tests java.security.DigestInputStream#DigestInputStream(java.io.InputStream, * java.security.MessageDigest) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies case with non null parameters only", + targets = { + @TestTarget( + methodName = "DigestInputStream", + methodArgs = {java.io.InputStream.class, MessageDigest.class} + ) + }) public void test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest() { // Test for method java.security.DigestInputStream(java.io.InputStream, // java.security.MessageDigest) @@ -45,6 +60,15 @@ public class DigestInputStream2Test extends junit.framework.TestCase { /** * @tests java.security.DigestInputStream#getMessageDigest() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMessageDigest", + methodArgs = {} + ) + }) public void test_getMessageDigest() { // Test for method java.security.MessageDigest // java.security.DigestInputStream.getMessageDigest() @@ -56,6 +80,15 @@ public class DigestInputStream2Test extends junit.framework.TestCase { /** * @tests java.security.DigestInputStream#on(boolean) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "on", + methodArgs = {boolean.class} + ) + }) public void test_onZ() throws Exception { // Test for method void java.security.DigestInputStream.on(boolean) MessageDigest originalDigest = (MessageDigest) (digest.clone()); @@ -88,6 +121,15 @@ public class DigestInputStream2Test extends junit.framework.TestCase { /** * @tests java.security.DigestInputStream#read() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies just one positive case for method read()", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public void test_read() throws IOException { // Test for method int java.security.DigestInputStream.read() DigestInputStream dis = new DigestInputStream(inStream, digest); @@ -103,6 +145,15 @@ public class DigestInputStream2Test extends junit.framework.TestCase { /** * @tests java.security.DigestInputStream#read(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies just one positive case for method read(byte[], int, int)", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_read$BII() throws IOException { // Test for method int java.security.DigestInputStream.read(byte [], // int, int) @@ -132,6 +183,15 @@ public class DigestInputStream2Test extends junit.framework.TestCase { /** * @tests java.security.DigestInputStream#setMessageDigest(java.security.MessageDigest) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setMessageDigest", + methodArgs = {MessageDigest.class} + ) + }) public void test_setMessageDigestLjava_security_MessageDigest() { // Test for method void // java.security.DigestInputStream.setMessageDigest(java.security.MessageDigest) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java index af92e0b..0c651ac 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestInputStreamTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -33,7 +38,7 @@ import java.util.Arrays; import org.apache.harmony.security.tests.support.MDGoldenData; import junit.framework.TestCase; - +@TestTargetClass(DigestInputStream.class) /** * Tests for fields and methods of class <code>DigestInputStream</code> * @@ -85,6 +90,15 @@ public class DigestInputStreamTest extends TestCase { * * @throws NoSuchAlgorithmException */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies both non null parameters", + targets = { + @TestTarget( + methodName = "DigestInputStream", + methodArgs = {InputStream.class, MessageDigest.class} + ) + }) public final void testDigestInputStream01() { for (int i=0; i<algorithmName.length; i++) { try { @@ -106,6 +120,16 @@ public class DigestInputStreamTest extends TestCase { * Assertion: creates new <code>DigestInputStream</code> instance * using valid parameters (both <code>null</code>) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies both null parameters. " + + "Need cases where just one parameter null", + targets = { + @TestTarget( + methodName = "DigestInputStream", + methodArgs = {InputStream.class, MessageDigest.class} + ) + }) public final void testDigestInputStream02() { InputStream dis = new DigestInputStream(null, null); assertTrue(dis instanceof DigestInputStream); @@ -117,6 +141,15 @@ public class DigestInputStreamTest extends TestCase { * Assertion: returns the byte read<br> * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public final void testRead01() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { @@ -150,6 +183,15 @@ public class DigestInputStreamTest extends TestCase { * Assertion: must not update digest if EOS had been * reached but not read before method call<br> */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public final void testRead02() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { @@ -185,6 +227,15 @@ public class DigestInputStreamTest extends TestCase { * (if <code>true</code> passed as a parameter) or off (if <code>false</code> * passed) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public final void testRead03() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { @@ -218,6 +269,15 @@ public class DigestInputStreamTest extends TestCase { * <code>InputStream</code> not set. <code>read()</code> must * not work */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public final void testRead04() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { try { @@ -249,6 +309,15 @@ public class DigestInputStreamTest extends TestCase { * <code>read()</code> must not work when digest * functionality is on */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public final void testRead05() { InputStream is = new ByteArrayInputStream(myMessage); DigestInputStream dis = new DigestInputStream(is, null); @@ -272,6 +341,15 @@ public class DigestInputStreamTest extends TestCase { * <code>read()</code> must work when digest * functionality is off */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {} + ) + }) public final void testRead06() throws IOException { InputStream is = new ByteArrayInputStream(myMessage); @@ -294,6 +372,16 @@ public class DigestInputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested" + + "Case when len>off isn't tested (and other boundary cases)", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testReadbyteArrayintint01() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { @@ -328,6 +416,16 @@ public class DigestInputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested" + + "Case when len>off isn't tested (and other boundary cases)", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testReadbyteArrayintint02() throws IOException { // check precondition @@ -368,6 +466,16 @@ public class DigestInputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested" + + "Case when len>off isn't tested (and other boundary cases)", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testReadbyteArrayintint03() throws IOException { // check precondition @@ -415,6 +523,16 @@ public class DigestInputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested" + + "Case when len>off isn't tested (and other boundary cases)", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testReadbyteArrayintint04() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { @@ -451,6 +569,16 @@ public class DigestInputStreamTest extends TestCase { * Assertion: does not update associated digest if * digest functionality is off<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException is not tested" + + "Case when len>off isn't tested (and other boundary cases)", + targets = { + @TestTarget( + methodName = "read", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testReadbyteArrayintint05() throws IOException { // check precondition @@ -485,6 +613,15 @@ public class DigestInputStreamTest extends TestCase { * * Assertion: returns associated message digest<br> */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMessageDigest", + methodArgs = {} + ) + }) public final void testGetMessageDigest() { for (int ii=0; ii<algorithmName.length; ii++) { try { @@ -506,6 +643,15 @@ public class DigestInputStreamTest extends TestCase { * * Assertion: set associated message digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method setMessageDigest is not tested with null parameter", + targets = { + @TestTarget( + methodName = "setMessageDigest", + methodArgs = {MessageDigest.class} + ) + }) public final void testSetMessageDigest() { for (int ii=0; ii<algorithmName.length; ii++) { try { @@ -526,6 +672,15 @@ public class DigestInputStreamTest extends TestCase { * Test for <code>on()</code> method<br> * Assertion: turns digest functionality on or off */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "on", + methodArgs = {boolean.class} + ) + }) public final void testOn() throws IOException { for (int ii=0; ii<algorithmName.length; ii++) { try { @@ -565,6 +720,15 @@ public class DigestInputStreamTest extends TestCase { * Test for <code>toString()</code> method<br> * Assertion: returns <code>String</code> representation of this object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public final void testToString() { for (int ii=0; ii<algorithmName.length; ii++) { try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java index bff91a9..b37e1ae 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -33,8 +39,7 @@ import org.apache.harmony.security.tests.support.MDGoldenData; import org.apache.harmony.security.tests.support.MyMessageDigest1; import junit.framework.TestCase; - - +@TestTargetClass(DigestOutputStream.class) /** * Tests for fields and methods of class <code>DigestInputStream</code> * @@ -82,6 +87,16 @@ public class DigestOutputStreamTest extends TestCase { * @tests java.security.DigestOutputStream#DigestOutputStream(java.io.OutputStream, * java.security.MessageDigest) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies both null and non null parameters. " + + "Need cases where just one parameter null", + targets = { + @TestTarget( + methodName = "DigestOutputStream", + methodArgs = {OutputStream.class, MessageDigest.class} + ) + }) public void test_CtorLjava_io_OutputStreamLjava_security_MessageDigest() { // non-null parameters @@ -101,6 +116,15 @@ public class DigestOutputStreamTest extends TestCase { /** * @tests java.security.DigestOutputStream#getMessageDigest() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMessageDigest", + methodArgs = {} + ) + }) public void test_getMessageDigest() { MessageDigest digest = new MyMessageDigest1(); @@ -119,6 +143,15 @@ public class DigestOutputStreamTest extends TestCase { /** * @tests java.security.DigestOutputStream#setMessageDigest(MessageDigest) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setMessageDigest", + methodArgs = {MessageDigest.class} + ) + }) public void test_setMessageDigestLjava_security_MessageDigest() { MessageDigest digest = new MyMessageDigest1(); @@ -143,6 +176,15 @@ public class DigestOutputStreamTest extends TestCase { * Assertion: writes the byte to the output stream<br> * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) public final void testWriteint01() throws IOException { for (int k=0; k<algorithmName.length; k++) { @@ -176,6 +218,15 @@ public class DigestOutputStreamTest extends TestCase { * if <code>true</code> passed as a parameter or off if <code>false</code> * passed */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) public final void testWriteint02() throws IOException { for (int k=0; k<algorithmName.length; k++) { @@ -212,6 +263,15 @@ public class DigestOutputStreamTest extends TestCase { * <code>OutputStream</code> not set. <code>write(int)</code> must * not work */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) public final void testWriteint03() throws IOException { for (int k=0; k<algorithmName.length; k++) { try { @@ -241,6 +301,15 @@ public class DigestOutputStreamTest extends TestCase { * <code>write(int)</code> must not work when digest * functionality is on */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) public final void testWriteint04() throws IOException { OutputStream os = new ByteArrayOutputStream(MY_MESSAGE_LEN); DigestOutputStream dos = new DigestOutputStream(os, null); @@ -265,6 +334,15 @@ public class DigestOutputStreamTest extends TestCase { * <code>write(int)</code> must work when digest * functionality is off */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) public final void testWriteint05() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(MY_MESSAGE_LEN); DigestOutputStream dos = new DigestOutputStream(bos, null); @@ -286,6 +364,15 @@ public class DigestOutputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testWritebyteArrayintint01() throws IOException { for (int k=0; k<algorithmName.length; k++) { @@ -317,6 +404,15 @@ public class DigestOutputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testWritebyteArrayintint02() throws IOException { // check precondition @@ -353,6 +449,15 @@ public class DigestOutputStreamTest extends TestCase { * * Assertion: updates associated digest<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testWritebyteArrayintint03() throws NoSuchAlgorithmException, IOException { @@ -394,6 +499,15 @@ public class DigestOutputStreamTest extends TestCase { * Assertion: does not update associated digest if digest * functionality is off<br> */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public final void testWritebyteArrayintint04() throws NoSuchAlgorithmException, IOException { @@ -430,6 +544,15 @@ public class DigestOutputStreamTest extends TestCase { /** * @tests java.security.DigestOutputStream#write(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_writeLB$LILI() throws Exception { // Regression form HARMONY-1091. @@ -467,6 +590,15 @@ public class DigestOutputStreamTest extends TestCase { * Test for <code>on()</code> method<br> * Assertion: turns digest functionality on or off */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "on", + methodArgs = {boolean.class} + ) + }) public final void testOn() throws IOException { for (int k=0; k<algorithmName.length; k++) { try { @@ -506,6 +638,15 @@ public class DigestOutputStreamTest extends TestCase { * Test for <code>toString()</code> method<br> * Assertion: returns <code>String</code> representation of this object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public final void testToString() throws NoSuchAlgorithmException { for (int k=0; k<algorithmName.length; k++) { try { @@ -525,6 +666,15 @@ public class DigestOutputStreamTest extends TestCase { /** * @tests java.security.DigestOutputStream#on(boolean) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "on", + methodArgs = {boolean.class} + ) + }) public void test_onZ() { // Test for method void java.security.DigestOutputStream.on(boolean) try { @@ -556,6 +706,15 @@ public class DigestOutputStreamTest extends TestCase { /** * @tests java.security.DigestOutputStream#write(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException isn't tested", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_write$BII() throws Exception { // Test for method void java.security.DigestOutputStream.write(byte [], // int, int) @@ -574,6 +733,15 @@ public class DigestOutputStreamTest extends TestCase { /** * @tests java.security.DigestOutputStream#write(int) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "write", + methodArgs = {int.class} + ) + }) public void test_writeI() throws Exception { // Test for method void java.security.DigestOutputStream.write(int) DigestOutputStream dos = new DigestOutputStream( diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityException2Test.java index 0af27e9..b59553a 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.GeneralSecurityException; +@TestTargetClass(GeneralSecurityException.class) public class GeneralSecurityException2Test extends junit.framework.TestCase { /** * @tests java.security.GeneralSecurityException#GeneralSecurityException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.GeneralSecurityException() GeneralSecurityException e = new GeneralSecurityException(); @@ -35,6 +50,15 @@ public class GeneralSecurityException2Test extends junit.framework.TestCase { /** * @tests java.security.GeneralSecurityException#GeneralSecurityException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies non null parameter only", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.GeneralSecurityException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java index 01388e4..da1989a 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/GeneralSecurityExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.GeneralSecurityException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.GeneralSecurityException; +import junit.framework.TestCase; +@TestTargetClass(GeneralSecurityException.class) /** * Tests for <code>GeneralSecurityException</code> class constructors and * methods. @@ -56,6 +61,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * Test for <code>GeneralSecurityException()</code> constructor Assertion: * constructs GeneralSecurityException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {} + ) + }) public void testGeneralSecurityException01() { GeneralSecurityException tE = new GeneralSecurityException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -67,6 +81,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * Assertion: constructs GeneralSecurityException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class} + ) + }) public void testGeneralSecurityException02() { GeneralSecurityException tE; for (int i = 0; i < msgs.length; i++) { @@ -82,6 +105,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * Assertion: constructs GeneralSecurityException when <code>msg</code> is * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class} + ) + }) public void testGeneralSecurityException03() { String msg = null; GeneralSecurityException tE = new GeneralSecurityException(msg); @@ -94,6 +126,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * Assertion: constructs GeneralSecurityException when <code>cause</code> * is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {Throwable.class} + ) + }) public void testGeneralSecurityException04() { Throwable cause = null; GeneralSecurityException tE = new GeneralSecurityException(cause); @@ -106,6 +147,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * Assertion: constructs GeneralSecurityException when <code>cause</code> * is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {Throwable.class} + ) + }) public void testGeneralSecurityException05() { GeneralSecurityException tE = new GeneralSecurityException(tCause); if (tE.getMessage() != null) { @@ -124,6 +174,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * constructor Assertion: constructs GeneralSecurityException when * <code>cause</code> is null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testGeneralSecurityException06() { GeneralSecurityException tE = new GeneralSecurityException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -135,6 +194,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * constructor Assertion: constructs GeneralSecurityException when * <code>cause</code> is null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testGeneralSecurityException07() { GeneralSecurityException tE; for (int i = 0; i < msgs.length; i++) { @@ -150,6 +218,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * constructor Assertion: constructs GeneralSecurityException when * <code>cause</code> is not null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testGeneralSecurityException08() { GeneralSecurityException tE = new GeneralSecurityException(null, tCause); if (tE.getMessage() != null) { @@ -168,6 +245,15 @@ public class GeneralSecurityExceptionTest extends TestCase { * constructor Assertion: constructs GeneralSecurityException when * <code>cause</code> is not null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "GeneralSecurityException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testGeneralSecurityException09() { GeneralSecurityException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java index 0070519..fe6f165 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/GuardedObjectTest.java @@ -22,11 +22,16 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Guard; import java.security.GuardedObject; import junit.framework.TestCase; - +@TestTargetClass(GuardedObject.class) /** * Tests for <code>GuardedObject</code> * @@ -39,6 +44,15 @@ public class GuardedObjectTest extends TestCase { } /** Null guard imposes no restriction. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Haven't separate case for getObject() method", + targets = { + @TestTarget( + methodName = "GuardedObject", + methodArgs = {Object.class, Guard.class} + ) + }) public void testNoGuard() { Object obj = null; GuardedObject go = new GuardedObject(obj, null); @@ -50,6 +64,15 @@ public class GuardedObjectTest extends TestCase { } /** Test real guard can both allow and deny access. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Haven't separate case for getObject() method", + targets = { + @TestTarget( + methodName = "GuardedObject", + methodArgs = {Object.class, Guard.class} + ) + }) public void testGuard() { final String message = "test message"; final StringBuffer objBuffer = new StringBuffer("235345 t"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/Identity2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/Identity2Test.java index d20cdfa..144e2ab 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/Identity2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/Identity2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; @@ -31,7 +36,7 @@ import java.security.cert.X509Certificate; import org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass;; @SuppressWarnings("deprecation") - +@TestTargetClass(Identity.class) public class Identity2Test extends junit.framework.TestCase { static PublicKey pubKey; @@ -140,6 +145,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#Identity() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Identity", + methodArgs = {} + ) + }) public void test_Constructor() { new IdentitySubclass(); } @@ -147,6 +161,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#Identity(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Other string parameters (null, empty) are not checked", + targets = { + @TestTarget( + methodName = "Identity", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { new IdentitySubclass("test"); } @@ -155,7 +178,15 @@ public class Identity2Test extends junit.framework.TestCase { * @tests java.security.Identity#Identity(java.lang.String, * java.security.IdentityScope) */ - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Other parameters (null, empty) are not checked", + targets = { + @TestTarget( + methodName = "Identity", + methodArgs = {String.class, IdentityScope.class} + ) + }) public void test_ConstructorLjava_lang_StringLjava_security_IdentityScope() throws Exception { new IdentitySubclass("test", new IdentityScopeSubclass()); } @@ -163,6 +194,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#getScope() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getScope", + methodArgs = {} + ) + }) public void test_getScope() throws Exception { IdentityScope scope = new IdentityScopeSubclass(); IdentitySubclass sub = new IdentitySubclass("test", scope); @@ -173,6 +213,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#getPublicKey() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicKey", + methodArgs = {} + ) + }) public void test_getPublicKey() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass()); @@ -184,6 +233,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#getName() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void test_getName() throws Exception { String name = "test"; IdentitySubclass sub = new IdentitySubclass(name, @@ -194,6 +252,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#getInfo() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInfo", + methodArgs = {} + ) + }) public void test_getInfo() throws Exception { String info = "This is the general information."; IdentitySubclass sub = new IdentitySubclass("test", @@ -205,6 +272,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#certificates() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "certificates", + methodArgs = {} + ) + }) public void test_certificates() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass()); @@ -222,6 +298,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#addCertificate(java.security.Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Invalid and null certificates are not checked, exceptions are not checked", + targets = { + @TestTarget( + methodName = "addCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void test_addCertificateLjava_security_Certificate() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass()); @@ -236,6 +321,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#removeCertificate(java.security.Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Invalid and null certificates are not checked, exceptions are not checked", + targets = { + @TestTarget( + methodName = "removeCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void test_removeCertificateLjava_security_Certificate() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass()); @@ -253,6 +347,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#equals(java.lang.Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method equals(java.lang.Object) is not tested", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void test_equalsLjava_lang_Object() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass()); @@ -270,6 +373,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#identityEquals(java.security.Identity) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method identityEquals(java.security.Identity) is not tested", + targets = { + @TestTarget( + methodName = "identityEquals", + methodArgs = {Identity.class} + ) + }) public void test_identityEqualsLjava_security_Identity() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", null); CertificateFactory cf = CertificateFactory.getInstance("X.509"); @@ -287,6 +399,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", null); assertNotNull(sub.toString()); @@ -299,6 +420,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#toString(boolean) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {boolean.class} + ) + }) public void test_toStringZ() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", null); assertNotNull(sub.toString(true)); @@ -309,6 +439,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void test_hashCode() throws Exception { IdentitySubclass sub = new IdentitySubclass("test", null); IdentitySubclass sub2 = new IdentitySubclass("test", null); @@ -319,6 +458,15 @@ public class Identity2Test extends junit.framework.TestCase { /** * @tests java.security.Identity#setInfo(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Other parameters (empty, null) are not tested.", + targets = { + @TestTarget( + methodName = "setInfo", + methodArgs = {String.class} + ) + }) public void testSetInfo() throws Exception{ String info = "This is the general information."; IdentitySubclass sub = new IdentitySubclass("test", @@ -328,8 +476,17 @@ public class Identity2Test extends junit.framework.TestCase { } /** - * @tests java.security.Identity#hashCode() + * @tests java.security.Identity#setPublicKey(PublicKey key) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Other parameters (null, invalid) are not tested", + targets = { + @TestTarget( + methodName = "setPublicKey", + methodArgs = {PublicKey.class} + ) + }) public void testSetPublicKey() throws Exception{ IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass()); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScope2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScope2Test.java index e8bf437..8fda959 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScope2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScope2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Identity; import java.security.IdentityScope; import java.security.KeyManagementException; @@ -27,6 +32,7 @@ import java.util.Hashtable; import org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass; @SuppressWarnings("deprecation") +@TestTargetClass(IdentityScope.class) public class IdentityScope2Test extends junit.framework.TestCase { static PublicKey pubKey; @@ -115,6 +121,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#IdentityScope() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IdentityScope", + methodArgs = {} + ) + }) public void test_Constructor() { new IdentityScopeSubclass(); } @@ -122,6 +137,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#IdentityScope(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Other variants (null, empty) for parameter are not tested", + targets = { + @TestTarget( + methodName = "IdentityScope", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { new IdentityScopeSubclass("test"); } @@ -130,6 +154,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { * @tests java.security.IdentityScope#IdentityScope(java.lang.String, * java.security.IdentityScope) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Other variants for parameter are not tested", + targets = { + @TestTarget( + methodName = "IdentityScope", + methodArgs = {String.class, IdentityScope.class} + ) + }) public void test_ConstructorLjava_lang_StringLjava_security_IdentityScope() throws Exception { new IdentityScopeSubclass("test", new IdentityScopeSubclass()); } @@ -137,6 +170,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#addIdentity(java.security.Identity) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "addIdentity", + methodArgs = {Identity.class} + ) + }) public void test_addIdentityLjava_security_Identity() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -156,6 +198,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#removeIdentity(java.security.Identity) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "removeIdentity", + methodArgs = {Identity.class} + ) + }) public void test_removeIdentityLjava_security_Identity() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -174,6 +225,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#identities() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "identities", + methodArgs = {} + ) + }) public void test_identities() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -189,6 +249,16 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#getIdentity(java.security.Principal) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method with null (if there are no identities of the same name " + + "in this scope) is not tested", + targets = { + @TestTarget( + methodName = "getIdentity", + methodArgs = {java.security.Principal.class} + ) + }) public void test_getIdentityLjava_security_Principal() throws Exception { Identity id = new IdentitySubclass("principal name"); id.setPublicKey(pubKey); @@ -203,6 +273,16 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#getIdentity(java.security.PublicKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method with null (if there are no identities in " + + "this scope with that key) is not tested", + targets = { + @TestTarget( + methodName = "getIdentity", + methodArgs = {PublicKey.class} + ) + }) public void test_getIdentityLjava_security_PublicKey() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -217,6 +297,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#getIdentity(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getIdentity", + methodArgs = {String.class} + ) + }) public void test_getIdentityLjava_lang_String() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -231,6 +320,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#size() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "size", + methodArgs = {} + ) + }) public void test_size() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -243,6 +341,15 @@ public class IdentityScope2Test extends junit.framework.TestCase { /** * @tests java.security.IdentityScope#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() throws Exception { IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass()); @@ -252,7 +359,16 @@ public class IdentityScope2Test extends junit.framework.TestCase { assertNotNull("toString returned a null", sub.toString()); assertTrue("Not a valid String ", sub.toString().length() > 0); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Regression test", + targets = { + @TestTarget( + methodName = "getIdentity", + methodArgs = {String.class} + ) + }) public void test_getIdentity() throws Exception { //Regression for HARMONY-1173 IdentityScope scope = IdentityScope.getSystemScope(); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java index 96387ca..b239032 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/IdentityScopeTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.IdentityScope; import java.security.Permission; import java.security.Permissions; @@ -30,8 +36,7 @@ import java.security.SecurityPermission; import org.apache.harmony.security.tests.support.IdentityScopeStub; import junit.framework.TestCase; - - +@TestTargetClass(IdentityScope.class) /** * Tests for <code>IdentityScope</code> * @@ -63,6 +68,15 @@ public class IdentityScopeTest extends TestCase { /** * Class under test for String toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public final void testToString() { assertNotNull(new IdentityScopeStub("Aleksei Semenov").toString()); } @@ -70,6 +84,15 @@ public class IdentityScopeTest extends TestCase { /** * test default constructor void IdentityScope() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IdentityScope", + methodArgs = {} + ) + }) public final void testIdentityScope() { assertNotNull(new IdentityScopeStub()); } @@ -77,6 +100,15 @@ public class IdentityScopeTest extends TestCase { /** * check that void IdentityScope(String) creates instance with given name */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies just positive case with non null parameter", + targets = { + @TestTarget( + methodName = "IdentityScope", + methodArgs = {String.class} + ) + }) public final void testIdentityScopeString() { is = new IdentityScopeStub("Aleksei Semenov"); assertNotNull(is); @@ -86,6 +118,15 @@ public class IdentityScopeTest extends TestCase { /** * check that void IdentityScope(String, IdentityScope) creates instance with given name and within given scope */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies just positive test with both non null parameters", + targets = { + @TestTarget( + methodName = "IdentityScope", + methodArgs = {String.class, IdentityScope.class} + ) + }) public final void testIdentityScopeStringIdentityScope() throws Exception { IdentityScope scope = new IdentityScopeStub("my scope"); is = new IdentityScopeStub("Aleksei Semenov", scope); @@ -97,6 +138,15 @@ public class IdentityScopeTest extends TestCase { /** * just call IdentityScope.getSystemScope() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSystemScope", + methodArgs = {} + ) + }) public final void testGetSystemScope() { String name = Security.getProperty("system.scope"); assertNotNull(name); @@ -110,7 +160,20 @@ public class IdentityScopeTest extends TestCase { * if permission is denied than SecurityException is thrown * */ - + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSystemScope", + methodArgs = {IdentityScope.class} + ), + @TestTarget( + methodName = "getSystemScope", + methodArgs = {} + ) + + }) public final void testSetSystemScope() { // default implementation is specified by security property system.scope IdentityScope systemScope = IdentityScope.getSystemScope(); @@ -149,6 +212,15 @@ public class IdentityScopeTest extends TestCase { /** * Class under test for Identity getIdentity(Principal) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIdentity", + methodArgs = {java.security.Principal.class} + ) + }) public final void testGetIdentityPrincipal() { is = new IdentityScopeStub("Aleksei Semenov"); IdentityScope sc2 = new IdentityScopeStub("aaa"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterException2Test.java index f648de0..938de47 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterException2Test.java @@ -17,14 +17,29 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidAlgorithmParameterException; +@TestTargetClass(InvalidAlgorithmParameterException.class) public class InvalidAlgorithmParameterException2Test extends junit.framework.TestCase { /** * @tests java.security.InvalidAlgorithmParameterException#InvalidAlgorithmParameterException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.InvalidAlgorithmParameterException() InvalidAlgorithmParameterException e = new InvalidAlgorithmParameterException(); @@ -37,6 +52,15 @@ public class InvalidAlgorithmParameterException2Test extends /** * @tests java.security.InvalidAlgorithmParameterException#InvalidAlgorithmParameterException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with one string parameter", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.InvalidAlgorithmParameterException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java index 802b940..badcc57 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidAlgorithmParameterExceptionTest.java @@ -22,11 +22,15 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidAlgorithmParameterException; import junit.framework.TestCase; - - +@TestTargetClass(InvalidAlgorithmParameterException.class) /** * Tests for <code>InvalidAlgorithmParameterException</code> class * constructors and methods. @@ -58,6 +62,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * Assertion: constructs InvalidAlgorithmParameterException with no detail * message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {} + ) + }) public void testInvalidAlgorithmParameterException01() { InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -69,6 +82,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException with * detail message msg. Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class} + ) + }) public void testInvalidAlgorithmParameterException02() { InvalidAlgorithmParameterException tE; for (int i = 0; i < msgs.length; i++) { @@ -84,6 +106,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class} + ) + }) public void testInvalidAlgorithmParameterException03() { String msg = null; InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException( @@ -97,6 +128,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>cause</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {Throwable.class} + ) + }) public void testInvalidAlgorithmParameterException04() { Throwable cause = null; InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException( @@ -110,6 +150,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>cause</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {Throwable.class} + ) + }) public void testInvalidAlgorithmParameterException05() { InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException( tCause); @@ -130,6 +179,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>cause</code> is null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidAlgorithmParameterException06() { InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException( null, null); @@ -143,6 +201,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>cause</code> is null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidAlgorithmParameterException07() { InvalidAlgorithmParameterException tE; for (int i = 0; i < msgs.length; i++) { @@ -159,6 +226,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>cause</code> is not null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidAlgorithmParameterException08() { InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException( null, tCause); @@ -179,6 +255,15 @@ public class InvalidAlgorithmParameterExceptionTest extends TestCase { * constructor Assertion: constructs InvalidAlgorithmParameterException when * <code>cause</code> is not null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidAlgorithmParameterException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidAlgorithmParameterException09() { InvalidAlgorithmParameterException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyException2Test.java index b54c0c2..5e403cf 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidKeyException; +@TestTargetClass(InvalidKeyException.class) public class InvalidKeyException2Test extends junit.framework.TestCase { /** * @tests java.security.InvalidKeyException#InvalidKeyException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.InvalidKeyException() InvalidKeyException e = new InvalidKeyException(); @@ -35,6 +50,15 @@ public class InvalidKeyException2Test extends junit.framework.TestCase { /** * @tests java.security.InvalidKeyException#InvalidKeyException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with one string parameter", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.InvalidKeyException(java.lang.String) InvalidKeyException e = new InvalidKeyException("test message"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java index 622682f..ccdd93d 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidKeyExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.InvalidKeyException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.InvalidKeyException; +import junit.framework.TestCase; +@TestTargetClass(InvalidKeyException.class) /** * Tests for <code>InvalidKeyException</code> class constructors and methods. * @@ -55,6 +60,15 @@ public class InvalidKeyExceptionTest extends TestCase { * Test for <code>InvalidKeyException()</code> constructor Assertion: * constructs InvalidKeyException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {} + ) + }) public void testInvalidKeyException01() { InvalidKeyException tE = new InvalidKeyException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -66,6 +80,15 @@ public class InvalidKeyExceptionTest extends TestCase { * Assertion: constructs InvalidKeyException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class} + ) + }) public void testInvalidKeyException02() { InvalidKeyException tE; for (int i = 0; i < msgs.length; i++) { @@ -80,6 +103,15 @@ public class InvalidKeyExceptionTest extends TestCase { * Test for <code>InvalidKeyException(String)</code> constructor * Assertion: constructs InvalidKeyException when <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class} + ) + }) public void testInvalidKeyException03() { String msg = null; InvalidKeyException tE = new InvalidKeyException(msg); @@ -92,6 +124,15 @@ public class InvalidKeyExceptionTest extends TestCase { * Assertion: constructs InvalidKeyException when <code>cause</code> is * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {Throwable.class} + ) + }) public void testInvalidKeyException04() { Throwable cause = null; InvalidKeyException tE = new InvalidKeyException(cause); @@ -104,6 +145,15 @@ public class InvalidKeyExceptionTest extends TestCase { * Assertion: constructs InvalidKeyException when <code>cause</code> is * not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {Throwable.class} + ) + }) public void testInvalidKeyException05() { InvalidKeyException tE = new InvalidKeyException(tCause); if (tE.getMessage() != null) { @@ -122,6 +172,15 @@ public class InvalidKeyExceptionTest extends TestCase { * constructor Assertion: constructs InvalidKeyException when * <code>cause</code> is null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidKeyException06() { InvalidKeyException tE = new InvalidKeyException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -133,6 +192,15 @@ public class InvalidKeyExceptionTest extends TestCase { * constructor Assertion: constructs InvalidKeyException when * <code>cause</code> is null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidKeyException07() { InvalidKeyException tE; for (int i = 0; i < msgs.length; i++) { @@ -148,6 +216,15 @@ public class InvalidKeyExceptionTest extends TestCase { * constructor Assertion: constructs InvalidKeyException when * <code>cause</code> is not null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidKeyException08() { InvalidKeyException tE = new InvalidKeyException(null, tCause); if (tE.getMessage() != null) { @@ -166,6 +243,15 @@ public class InvalidKeyExceptionTest extends TestCase { * constructor Assertion: constructs InvalidKeyException when * <code>cause</code> is not null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testInvalidKeyException09() { InvalidKeyException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterException2Test.java index 2d721a2..97f08ca 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidParameterException; +@TestTargetClass(InvalidParameterException.class) public class InvalidParameterException2Test extends junit.framework.TestCase { /** * @tests java.security.InvalidParameterException#InvalidParameterException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidParameterException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.InvalidParameterException() InvalidParameterException e = new InvalidParameterException(); @@ -34,6 +49,15 @@ public class InvalidParameterException2Test extends junit.framework.TestCase { /** * @tests java.security.InvalidParameterException#InvalidParameterException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with one variant of string parameter", + targets = { + @TestTarget( + methodName = "InvalidParameterException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.InvalidParameterException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java index 51707cc..bf507cd 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/InvalidParameterExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.InvalidParameterException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.InvalidParameterException; +import junit.framework.TestCase; +@TestTargetClass(InvalidParameterException.class) /** * Tests for <code>InvalidParameterException</code> class constructors and * methods. @@ -56,6 +61,15 @@ public class InvalidParameterExceptionTest extends TestCase { * Test for <code>InvalidParameterException()</code> constructor * Assertion: constructs InvalidParameterException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidParameterException", + methodArgs = {} + ) + }) public void testInvalidParameterException01() { InvalidParameterException tE = new InvalidParameterException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -67,6 +81,15 @@ public class InvalidParameterExceptionTest extends TestCase { * Assertion: constructs InvalidParameterException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidParameterException", + methodArgs = {String.class} + ) + }) public void testInvalidParameterException02() { InvalidParameterException tE; for (int i = 0; i < msgs.length; i++) { @@ -82,6 +105,15 @@ public class InvalidParameterExceptionTest extends TestCase { * Assertion: constructs InvalidParameterException when <code>msg</code> * is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidParameterException", + methodArgs = {String.class} + ) + }) public void testInvalidParameterException03() { String msg = null; InvalidParameterException tE = new InvalidParameterException(msg); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java index 12c3524..4d4ff03 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSCallbackHandlerProtectionTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyStore; import javax.security.auth.callback.CallbackHandler; @@ -29,7 +34,7 @@ import javax.security.auth.callback.CallbackHandler; import org.apache.harmony.security.tests.support.tmpCallbackHandler; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.CallbackHandlerProtection.class) /** * Tests for <code>KeyStore.CallbackHandlerProtection> class constructor and methods * @@ -50,6 +55,15 @@ public class KSCallbackHandlerProtectionTest extends TestCase { * constructor * Assertion: throws NullPointerException when handler is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CallbackHandlerProtection", + methodArgs = {CallbackHandler.class} + ) + }) public void testCallbackHandlerProtection() { try { new KeyStore.CallbackHandlerProtection(null); @@ -62,6 +76,19 @@ public class KSCallbackHandlerProtectionTest extends TestCase { * Test for <code>getCallbackHandler()</code> method * Assertion: returns CallbackHandler */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CallbackHandlerProtection", + methodArgs = {CallbackHandler.class} + ), + @TestTarget( + methodName = "getCallbackHandler", + methodArgs = {} + ) + }) public void testGetCallBackHandler() { CallbackHandler cbh = new tmpCallbackHandler(); KeyStore.CallbackHandlerProtection ksCBH = new KeyStore.CallbackHandlerProtection(cbh); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java index a3ea0ed..80bf66c 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPasswordProtectionTest.java @@ -22,12 +22,17 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyStore; import javax.security.auth.DestroyFailedException; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.PasswordProtection.class) /** * Tests for <code>KeyStore.PasswordProtection</code> class constructor and methods * @@ -53,6 +58,28 @@ public class KSPasswordProtectionTest extends TestCase { * getPassword() returns password or throws IllegalArgumentException * if PasswordProtection is destroyed */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. PasswordProtection - verification with null parameter missed" + + "2. destroy - DestroyFailedException checking missed", + targets = { + @TestTarget( + methodName = "PasswordProtection", + methodArgs = {char[].class} + ), + @TestTarget( + methodName = "getPassword", + methodArgs = {} + ), + @TestTarget( + methodName = "isDestroyed", + methodArgs = {} + ), + @TestTarget( + methodName = "destroy", + methodArgs = {} + ) + }) public void testGetPassword() throws DestroyFailedException { char [] pass = {'a', 'b', 'c'}; KeyStore.PasswordProtection ksPWP = new KeyStore.PasswordProtection(pass); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java index 6382cf7..e5a7a64 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSPrivateKeyEntryTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyStore; import java.security.PrivateKey; import java.security.cert.Certificate; @@ -33,6 +38,7 @@ import junit.framework.TestCase; import junit.framework.Test; import junit.framework.TestSuite; +@TestTargetClass(KeyStore.PrivateKeyEntry.class) /** * Tests for <code>KeyStore.PrivateKeyEntry</code> class constructor and methods * @@ -67,6 +73,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * constructor * Assertion: throws NullPointerException when privateKey is null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case with valid parameters missed", + targets = { + @TestTarget( + methodName = "PrivateKeyEntry", + methodArgs = {PrivateKey.class, Certificate[].class} + ) + }) public void testPrivateKeyEntry01() { Certificate[] certs = new MyCertificate[1];//new Certificate[1]; PrivateKey pk = null; @@ -83,6 +98,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Assertion: throws NullPointerException when chain is null * and throws IllegalArgumentException when chain length is 0 */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case with valid parameters missed", + targets = { + @TestTarget( + methodName = "PrivateKeyEntry", + methodArgs = {PrivateKey.class, Certificate[].class} + ) + }) public void testPrivateKeyEntry02() { Certificate[] chain = null; PrivateKey pk = new tmpPrivateKey(); @@ -104,6 +128,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Assertion: throws IllegalArgumentException when chain contains certificates * of different types */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case with valid parameters missed", + targets = { + @TestTarget( + methodName = "PrivateKeyEntry", + methodArgs = {PrivateKey.class, Certificate[].class} + ) + }) public void testPrivateKeyEntry03() { createParams(true, false); try { @@ -119,6 +152,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Assertion: throws IllegalArgumentException when algorithm of privateKey * does not match the algorithm of PublicKey in the end certificate (with 0 index) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case with valid parameters missed", + targets = { + @TestTarget( + methodName = "PrivateKeyEntry", + methodArgs = {PrivateKey.class, Certificate[].class} + ) + }) public void testPrivateKeyEntry04() { createParams(false, true); try { @@ -132,6 +174,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Test for <code>getPrivateKey()</code> method * Assertion: returns PrivateKey object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateKey", + methodArgs = {} + ) + }) public void testGetPrivateKey() { createParams(false, false); KeyStore.PrivateKeyEntry ksPKE = new KeyStore.PrivateKeyEntry( @@ -144,6 +195,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Test for <code>getCertificateChain()</code> method Assertion: returns * array of the Certificates corresponding to chain */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificateChain", + methodArgs = {} + ) + }) public void testGetCertificateChain() { createParams(false, false); KeyStore.PrivateKeyEntry ksPKE = new KeyStore.PrivateKeyEntry( @@ -160,6 +220,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Test for <code>getCertificate()</code> method * Assertion: returns end Certificate (with 0 index in chain) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificate", + methodArgs = {} + ) + }) public void testGetCertificate() { createParams(false, false); KeyStore.PrivateKeyEntry ksPKE = new KeyStore.PrivateKeyEntry( @@ -172,6 +241,15 @@ public class KSPrivateKeyEntryTest extends TestCase { * Test for <code>toString()</code> method * Assertion: returns non null String */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { createParams(false, false); KeyStore.PrivateKeyEntry ksPKE = new KeyStore.PrivateKeyEntry( diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java index cb1ad25..40a2dec 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSSecretKeyEntryTest.java @@ -22,12 +22,17 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyStore; import javax.crypto.SecretKey; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.SecretKeyEntry.class) /** * Tests for <code>KeyStore.SecretKeyEntry</code> class constructor and methods * @@ -46,6 +51,15 @@ public class KSSecretKeyEntryTest extends TestCase { * Test for <code>SecretKeyEntry(SecretKey secretKey)</code> constructor * Assertion: throws NullPointerException when secretKey is null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case with non null parameter missed", + targets = { + @TestTarget( + methodName = "SecretKeyEntry", + methodArgs = {SecretKey.class} + ) + }) public void testSecretKeyEntry() { SecretKey sk = null; try { @@ -59,6 +73,15 @@ public class KSSecretKeyEntryTest extends TestCase { * Test for <code>getSecretKey()</code> method * Assertion: returns SecretKey from the given entry */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSecretKey", + methodArgs = {} + ) + }) public void testGetSecretKey() { SecretKey sk = new tmpSecretKey(); KeyStore.SecretKeyEntry ske = new KeyStore.SecretKeyEntry(sk); @@ -69,6 +92,15 @@ public class KSSecretKeyEntryTest extends TestCase { * Test for <code>toString()</code> method * Assertion: returns non null string */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { SecretKey sk = new tmpSecretKey(); KeyStore.SecretKeyEntry ske = new KeyStore.SecretKeyEntry(sk); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java index a4a15d3..4e37fef 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KSTrustedCertificateEntryTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyStore; import java.security.cert.Certificate; @@ -28,7 +34,7 @@ import org.apache.harmony.security.tests.support.cert.MyCertificate; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.TrustedCertificateEntry.class) /** * Tests for <code>KeyStore.TrustedCertificateEntry</code> class constructor and methods * @@ -41,6 +47,15 @@ public class KSTrustedCertificateEntryTest extends TestCase { * constructor * Assertion: throws NullPointerException when trustCert is null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case with non null parameter missed", + targets = { + @TestTarget( + methodName = "TrustedCertificateEntry", + methodArgs = {Certificate.class} + ) + }) public void testTrustedCertificateEntry() { Certificate cert = null; try { @@ -54,6 +69,15 @@ public class KSTrustedCertificateEntryTest extends TestCase { * Test for <codfe>getTrustedCertificate()</code> method * Assertion: returns trusted Certificate from goven entry */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getTrustedCertificate", + methodArgs = {} + ) + }) public void testGetTrustedCertificate() { Certificate cert = new MyCertificate("TEST", new byte[10]); KeyStore.TrustedCertificateEntry ksTCE = @@ -65,6 +89,15 @@ public class KSTrustedCertificateEntryTest extends TestCase { * Test for <codfe>toString()</code> method * Assertion: returns non null string */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { Certificate cert = new MyCertificate("TEST", new byte[10]); KeyStore.TrustedCertificateEntry ksTCE = diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyException2Test.java index 4b4caf4..38090f6 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyException; +@TestTargetClass(KeyException.class) public class KeyException2Test extends junit.framework.TestCase { /** * @tests java.security.KeyException#KeyException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.KeyException() KeyException e = new KeyException(); @@ -34,6 +49,15 @@ public class KeyException2Test extends junit.framework.TestCase { /** * @tests java.security.KeyException#KeyException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with one variant of string parameter", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.KeyException(java.lang.String) KeyException e = new KeyException("test message"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java index b694fab..b1eb58b 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.KeyException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.KeyException; +import junit.framework.TestCase; +@TestTargetClass(KeyException.class) /** * Tests for <code>KeyException</code> class constructors and methods. * @@ -55,6 +60,15 @@ public class KeyExceptionTest extends TestCase { * Test for <code>KeyException()</code> constructor Assertion: constructs * KeyException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {} + ) + }) public void testKeyException01() { KeyException tE = new KeyException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -66,6 +80,15 @@ public class KeyExceptionTest extends TestCase { * constructs KeyException with detail message msg. Parameter * <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class} + ) + }) public void testKeyException02() { KeyException tE; for (int i = 0; i < msgs.length; i++) { @@ -80,6 +103,15 @@ public class KeyExceptionTest extends TestCase { * Test for <code>KeyException(String)</code> constructor Assertion: * constructs KeyException when <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class} + ) + }) public void testKeyException03() { String msg = null; KeyException tE = new KeyException(msg); @@ -91,6 +123,15 @@ public class KeyExceptionTest extends TestCase { * Test for <code>KeyException(Throwable)</code> constructor Assertion: * constructs KeyException when <code>cause</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {Throwable.class} + ) + }) public void testKeyException04() { Throwable cause = null; KeyException tE = new KeyException(cause); @@ -102,6 +143,15 @@ public class KeyExceptionTest extends TestCase { * Test for <code>KeyException(Throwable)</code> constructor Assertion: * constructs KeyException when <code>cause</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {Throwable.class} + ) + }) public void testKeyException05() { KeyException tE = new KeyException(tCause); if (tE.getMessage() != null) { @@ -120,6 +170,15 @@ public class KeyExceptionTest extends TestCase { * Assertion: constructs KeyException when <code>cause</code> is null * <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyException06() { KeyException tE = new KeyException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -131,6 +190,15 @@ public class KeyExceptionTest extends TestCase { * Assertion: constructs KeyException when <code>cause</code> is null * <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyException07() { KeyException tE; for (int i = 0; i < msgs.length; i++) { @@ -146,6 +214,15 @@ public class KeyExceptionTest extends TestCase { * Assertion: constructs KeyException when <code>cause</code> is not null * <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyException08() { KeyException tE = new KeyException(null, tCause); if (tE.getMessage() != null) { @@ -164,6 +241,15 @@ public class KeyExceptionTest extends TestCase { * Assertion: constructs KeyException when <code>cause</code> is not null * <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyException09() { KeyException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyFactory2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyFactory2Test.java index 4a59623..3ef10fb 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyFactory2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyFactory2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidKeyException; import java.security.Key; import java.security.KeyFactory; @@ -38,6 +43,7 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.Vector; +@TestTargetClass(KeyFactory.class) public class KeyFactory2Test extends junit.framework.TestCase { private static final String KEYFACTORY_ID = "KeyFactory."; @@ -91,6 +97,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { * @tests java.security.KeyFactory#KeyFactory(java.security.KeyFactorySpi, * java.security.Provider, java.lang.String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyFactory", + methodArgs = {KeyFactorySpi.class, Provider.class, String.class} + ) + }) public void test_constructor() { KeyFactorySpi kfs = new KeyFactorySpiStub(); @@ -116,6 +131,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { /** * @tests java.security.KeyFactory#generatePrivate(java.security.spec.KeySpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed", + targets = { + @TestTarget( + methodName = "generatePrivate", + methodArgs = {KeySpec.class} + ) + }) public void test_generatePrivateLjava_security_spec_KeySpec() { // Test for method java.security.PrivateKey // java.security.KeyFactory.generatePrivate(java.security.spec.KeySpec) @@ -157,6 +181,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { /** * @tests java.security.KeyFactory#generatePublic(java.security.spec.KeySpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed", + targets = { + @TestTarget( + methodName = "generatePublic", + methodArgs = {KeySpec.class} + ) + }) public void test_generatePublicLjava_security_spec_KeySpec() { // Test for method java.security.PublicKey // java.security.KeyFactory.generatePublic(java.security.spec.KeySpec) @@ -195,6 +228,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { /** * @tests java.security.KeyFactory#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() { // Test for method java.lang.String // java.security.KeyFactory.getAlgorithm() @@ -215,6 +257,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { /** * @tests java.security.KeyFactory#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() { // Test for method java.security.KeyFactory // java.security.KeyFactory.getInstance(java.lang.String) @@ -231,6 +282,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { * @tests java.security.KeyFactory#getInstance(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, NoSuchProviderException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() { // Test1: Test for method java.security.KeyFactory @@ -263,9 +323,17 @@ public class KeyFactory2Test extends junit.framework.TestCase { } /** - * @tests java.security.KeyFactory#getInstance(java.lang.String, - * java.lang.String) + * @tests java.security.KeyFactory#getInstance(java.lang.String, Provider) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_security_Provider() { // Test1: Test for method java.security.KeyFactory @@ -301,6 +369,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { * @tests java.security.KeyFactory#getKeySpec(java.security.Key, * java.lang.Class) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed", + targets = { + @TestTarget( + methodName = "getKeySpec", + methodArgs = {Key.class, Class.class} + ) + }) public void test_getKeySpecLjava_security_KeyLjava_lang_Class() { // Test for method java.security.spec.KeySpec // java.security.KeyFactory.getKeySpec(java.security.Key, @@ -358,6 +435,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { /** * @tests java.security.KeyFactory#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() { // Test for method java.security.Provider // java.security.KeyFactory.getProvider() @@ -376,6 +462,15 @@ public class KeyFactory2Test extends junit.framework.TestCase { /** * @tests java.security.KeyFactory#translateKey(java.security.Key) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "translateKey", + methodArgs = {Key.class} + ) + }) public void test_translateKeyLjava_security_Key() { // Test for method java.security.Key // java.security.KeyFactory.translateKey(java.security.Key) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementException2Test.java index 4f0dda6..93f85d3 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyManagementException; +@TestTargetClass(KeyManagementException.class) public class KeyManagementException2Test extends junit.framework.TestCase { /** * @tests java.security.KeyManagementException#KeyManagementException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.KeyManagementException() KeyManagementException e = new KeyManagementException(); @@ -34,6 +49,15 @@ public class KeyManagementException2Test extends junit.framework.TestCase { /** * @tests java.security.KeyManagementException#KeyManagementException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checking with null and empty string parameter missed", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.KeyManagementException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java index 7ca3322..9d5d59c 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyManagementExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.KeyManagementException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.KeyManagementException; +import junit.framework.TestCase; +@TestTargetClass(KeyManagementException.class) /** * Tests for <code>KeyManagementException</code> class constructors and * methods. @@ -56,6 +61,15 @@ public class KeyManagementExceptionTest extends TestCase { * Test for <code>KeyManagementException()</code> constructor Assertion: * constructs KeyManagementException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {} + ) + }) public void testKeyManagementException01() { KeyManagementException tE = new KeyManagementException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -67,6 +81,15 @@ public class KeyManagementExceptionTest extends TestCase { * Assertion: constructs KeyManagementException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class} + ) + }) public void testKeyManagementException02() { KeyManagementException tE; for (int i = 0; i < msgs.length; i++) { @@ -82,6 +105,15 @@ public class KeyManagementExceptionTest extends TestCase { * Assertion: constructs KeyManagementException when <code>msg</code> is * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class} + ) + }) public void testKeyManagementException03() { String msg = null; KeyManagementException tE = new KeyManagementException(msg); @@ -94,6 +126,15 @@ public class KeyManagementExceptionTest extends TestCase { * Assertion: constructs KeyManagementException when <code>cause</code> is * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {Throwable.class} + ) + }) public void testKeyManagementException04() { Throwable cause = null; KeyManagementException tE = new KeyManagementException(cause); @@ -106,6 +147,15 @@ public class KeyManagementExceptionTest extends TestCase { * Assertion: constructs KeyManagementException when <code>cause</code> is * not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {Throwable.class} + ) + }) public void testKeyManagementException05() { KeyManagementException tE = new KeyManagementException(tCause); if (tE.getMessage() != null) { @@ -124,6 +174,15 @@ public class KeyManagementExceptionTest extends TestCase { * constructor Assertion: constructs KeyManagementException when * <code>cause</code> is null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyManagementException06() { KeyManagementException tE = new KeyManagementException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -135,6 +194,15 @@ public class KeyManagementExceptionTest extends TestCase { * constructor Assertion: constructs KeyManagementException when * <code>cause</code> is null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyManagementException07() { KeyManagementException tE; for (int i = 0; i < msgs.length; i++) { @@ -150,6 +218,15 @@ public class KeyManagementExceptionTest extends TestCase { * constructor Assertion: constructs KeyManagementException when * <code>cause</code> is not null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyManagementException08() { KeyManagementException tE = new KeyManagementException(null, tCause); if (tE.getMessage() != null) { @@ -168,6 +245,15 @@ public class KeyManagementExceptionTest extends TestCase { * constructor Assertion: constructs KeyManagementException when * <code>cause</code> is not null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyManagementException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyManagementException09() { KeyManagementException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java index c2a9441..0a8913e 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator1Test.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidParameterException; @@ -38,7 +43,7 @@ import org.apache.harmony.security.tests.support.MyKeyPairGenerator2; import org.apache.harmony.security.tests.support.SpiEngUtils; import junit.framework.TestCase; - +@TestTargetClass(KeyPairGenerator.class) /** * Tests for <code>KeyPairGenerator</code> class constructors and methods. * @@ -106,6 +111,15 @@ public class KeyPairGenerator1Test extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm is incorrect; */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testKeyPairGenerator01() throws NoSuchAlgorithmException { try { KeyPairGenerator.getInstance(null); @@ -127,6 +141,15 @@ public class KeyPairGenerator1Test extends TestCase { * Test for <code>getInstance(String algorithm)</code> method * Assertion: returns KeyPairGenerator object */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testKeyPairGenerator02() throws NoSuchAlgorithmException { if (!DSASupported) { fail(NotSupportMsg); @@ -145,6 +168,15 @@ public class KeyPairGenerator1Test extends TestCase { * method * Assertion: throws IllegalArgumentException when provider is null or empty */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testKeyPairGenerator03() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DSASupported) { @@ -170,9 +202,17 @@ public class KeyPairGenerator1Test extends TestCase { * Test for <code>getInstance(String algorithm, String provider)</code> * method * Assertion: - * throws NullPointerException when algorithm is null - * throws NoSuchAlgorithmException when algorithm is incorrect; + * throws NoSuchProviderException when provider is not available */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testKeyPairGenerator04() throws NoSuchAlgorithmException, IllegalArgumentException { if (!DSASupported) { @@ -196,8 +236,19 @@ public class KeyPairGenerator1Test extends TestCase { * Test for <code>getInstance(String algorithm, String provider)</code> * method * Assertion: throws NoSuchAlgorithmException when algorithm is not - * available oe null + * available + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is incorrect; */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testKeyPairGenerator05() throws NoSuchProviderException, IllegalArgumentException { if (!DSASupported) { @@ -227,6 +278,15 @@ public class KeyPairGenerator1Test extends TestCase { * method * Assertion: returns KeyPairGenerator object */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testKeyPairGenerator06() throws NoSuchProviderException, NoSuchAlgorithmException, IllegalArgumentException { if (!DSASupported) { @@ -248,6 +308,15 @@ public class KeyPairGenerator1Test extends TestCase { * method * Assertion: throws IllegalArgumentException when provider is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testKeyPairGenerator07() throws NoSuchAlgorithmException { if (!DSASupported) { fail(NotSupportMsg); @@ -270,6 +339,15 @@ public class KeyPairGenerator1Test extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm is incorrect; */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testKeyPairGenerator08() throws IllegalArgumentException { if (!DSASupported) { fail(NotSupportMsg); @@ -297,6 +375,15 @@ public class KeyPairGenerator1Test extends TestCase { * method * Assertion: returns KeyPairGenerator object */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testKeyPairGenerator09() throws NoSuchAlgorithmException, IllegalArgumentException { if (!DSASupported) { @@ -318,6 +405,20 @@ public class KeyPairGenerator1Test extends TestCase { * Assertion: KeyPairGenerator was initialized before the invocation * of these methods */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "generateKeyPair", + methodArgs = {} + ), + @TestTarget( + methodName = "genKeyPair", + methodArgs = {} + ) + + }) public void testKeyPairGenerator10() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException { if (!DSASupported) { @@ -348,7 +449,28 @@ public class KeyPairGenerator1Test extends TestCase { * Assertion: throws InvalidParameterException or * InvalidAlgorithmParameterException when parameters keysize or param are * incorrect - */ + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class, SecureRandom.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class, SecureRandom.class} + ) + }) public void testKeyPairGenerator11() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DSASupported) { @@ -391,6 +513,27 @@ public class KeyPairGenerator1Test extends TestCase { * incorrect Assertion: generateKeyPair() and genKeyPair() return null * KeyPair Additional class MyKeyPairGenerator1 is used */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class, SecureRandom.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class, SecureRandom.class} + ) + }) public void testKeyPairGenerator12() { int[] keys = { -1, -250, 1, 64, 512, 1024 }; SecureRandom random = new SecureRandom(); @@ -467,6 +610,27 @@ public class KeyPairGenerator1Test extends TestCase { * genKeyPair() return not null KeyPair Additional class MyKeyPairGenerator2 * is used */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class, SecureRandom.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class, SecureRandom.class} + ) + }) public void testKeyPairGenerator13() { int[] keys = { -1, -250, 1, 63, -512, -1024 }; SecureRandom random = new SecureRandom(); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java index 881a468..136d159 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator2Test.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidAlgorithmParameterException; import java.security.InvalidParameterException; import java.security.KeyPairGenerator; @@ -36,8 +42,7 @@ import org.apache.harmony.security.tests.support.MyKeyPairGenerator2; import org.apache.harmony.security.tests.support.SpiEngUtils; import junit.framework.TestCase; - - +@TestTargetClass(KeyPairGenerator.class) /** * Tests for <code>KeyPairGenerator</code> class constructors and methods. * @@ -191,6 +196,15 @@ public class KeyPairGenerator2Test extends TestCase { * KeyPairGenerator object * */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) private void GetInstance01(int mode) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { try { @@ -229,6 +243,15 @@ public class KeyPairGenerator2Test extends TestCase { * returns * KeyPairGenerator object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void GetInstance02(int mode) throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException { @@ -289,6 +312,15 @@ public class KeyPairGenerator2Test extends TestCase { * throws IllegalArgumentException when provider is null; * returns KeyPairGenerator object */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) private void GetInstance03(int mode) throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException { try { @@ -325,7 +357,16 @@ public class KeyPairGenerator2Test extends TestCase { checkResult(kpG, mode); } } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testGetInstance01() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass1; @@ -334,7 +375,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance01(1); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testGetInstance02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException { @@ -344,7 +394,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance02(1); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testGetInstance03() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass1; @@ -353,7 +412,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance03(1); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testGetInstance04() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass2; @@ -362,7 +430,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance01(2); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testGetInstance05() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException { @@ -372,7 +449,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance02(2); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testGetInstance06() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass2; @@ -381,7 +467,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance03(2); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testGetInstance07() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass3; @@ -390,7 +485,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance01(3); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testGetInstance08() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException { @@ -400,7 +504,16 @@ public class KeyPairGenerator2Test extends TestCase { setProv(); GetInstance02(3); } - + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testGetInstance09() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass3; @@ -410,6 +523,15 @@ public class KeyPairGenerator2Test extends TestCase { GetInstance03(3); } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testGetInstance10() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass4; @@ -419,6 +541,15 @@ public class KeyPairGenerator2Test extends TestCase { GetInstance01(4); } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void testGetInstance11() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException { @@ -429,6 +560,15 @@ public class KeyPairGenerator2Test extends TestCase { GetInstance02(4); } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void testGetInstance12() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException { KeyPairGeneratorProviderClass = KeyPairGeneratorProviderClass4; diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java index c898207..b0a5a44 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator3Test.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; @@ -31,8 +37,7 @@ import java.security.SecureRandom; import org.apache.harmony.security.tests.support.SpiEngUtils; import junit.framework.TestCase; - - +@TestTargetClass(KeyPairGenerator.class) /** * Tests for KeyPairGenerator class * @@ -93,6 +98,19 @@ public class KeyPairGenerator3Test extends TestCase { * Assertion: KeyPairGenerator was initialized before the invocation * of these methods */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "generateKeyPair", + methodArgs = {} + ), + @TestTarget( + methodName = "genKeyPair", + methodArgs = {} + ) + }) public void testGenKeyPair01() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException { if (!DSASupported) { @@ -119,6 +137,19 @@ public class KeyPairGenerator3Test extends TestCase { * methods * Assertion: these methods are used without previously initialization */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "generateKeyPair", + methodArgs = {} + ), + @TestTarget( + methodName = "genKeyPair", + methodArgs = {} + ) + }) public void testGenKeyPair02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException { if (!DSASupported) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator4Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator4Test.java index 7ab4564..f6417fb 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator4Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGenerator4Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyPairGenerator; import java.security.Provider; import java.security.SecureRandom; @@ -25,11 +30,21 @@ import java.security.spec.DSAParameterSpec; import java.security.interfaces.DSAPublicKey; import java.security.interfaces.DSAParams; +@TestTargetClass(KeyPairGenerator.class) public class KeyPairGenerator4Test extends junit.framework.TestCase { /** * @tests java.security.KeyPairGenerator#genKeyPair() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "genKeyPair", + methodArgs = {} + ) + }) public void test_genKeyPair() throws Exception { KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA"); gen.initialize(1024); @@ -39,6 +54,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { /** * @tests java.security.KeyPairGenerator#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() throws Exception { String alg = KeyPairGenerator.getInstance("DSA").getAlgorithm(); assertEquals("getAlgorithm returned unexpected value", "DSA", alg); @@ -47,6 +71,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { /** * @tests java.security.KeyPairGenerator#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of other string parameters and exception cases missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() throws Exception { KeyPairGenerator.getInstance("DSA"); } @@ -55,6 +88,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { * @tests java.security.KeyPairGenerator#getInstance(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, NoSuchProviderException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception { @@ -78,6 +120,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { /** * @tests java.security.KeyPairGenerator#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() throws Exception { Provider p = KeyPairGenerator.getInstance("DSA").getProvider(); assertNotNull("provider is null", p); @@ -86,6 +137,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { /** * @tests java.security.KeyPairGenerator#initialize(int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException checking missed", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {int.class} + ) + }) public void test_initializeI() throws Exception { KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA"); keyPair.initialize(1024); @@ -95,6 +155,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { * @tests java.security.KeyPairGenerator#initialize(int, * java.security.SecureRandom) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException checking missed", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {int.class, SecureRandom.class} + ) + }) public void test_initializeILjava_security_SecureRandom() throws Exception { KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA"); keyPair.initialize(1024, new SecureRandom()); @@ -104,6 +173,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { /** * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidAlgorithmParameterException checking missed", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class} + ) + }) public void test_initializeLjava_security_spec_AlgorithmParameterSpec() throws Exception { // create DSAParams @@ -122,6 +200,15 @@ public class KeyPairGenerator4Test extends junit.framework.TestCase { * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec, * java.security.SecureRandom) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidAlgorithmParameterException checking missed", + targets = { + @TestTarget( + methodName = "initialize", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class, SecureRandom.class} + ) + }) public void test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom() throws Exception { // create DSAParams diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java index bc7b9b5..3c72a0b 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairGeneratorSpiTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidAlgorithmParameterException; import java.security.InvalidParameterException; import java.security.KeyPair; @@ -32,7 +37,7 @@ import java.security.spec.AlgorithmParameterSpec; import org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi; import junit.framework.TestCase; - +@TestTargetClass(KeyPairGeneratorSpi.class) /** * Tests for <code>KeyPairGeneratorSpi</code> class constructors and methods. * @@ -53,6 +58,28 @@ public class KeyPairGeneratorSpiTest extends TestCase { * Test for <code>KeyPairGeneratorSpi</code> constructor * Assertion: constructs KeyPairGeneratorSpi */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidAlgorithmParameterException and InvalidParameterException " + + "checking missed for initialize methods", + targets = { + @TestTarget( + methodName = "KeyPairGeneratorSpi", + methodArgs = {} + ), + @TestTarget( + methodName = "generateKeyPair", + methodArgs = {} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {AlgorithmParameterSpec.class, SecureRandom.class} + ), + @TestTarget( + methodName = "initialize", + methodArgs = {int.class, SecureRandom.class} + ) + }) public void testKeyPairGeneratorSpi01() throws InvalidAlgorithmParameterException, InvalidParameterException { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java index 8864835..0070f12 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyPairTest.java @@ -21,14 +21,19 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyPair; import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import junit.framework.TestCase; - - +@TestTargetClass( KeyPair.class) /** * Tests for fields and methods of class <code>KeyPair</code> * @@ -77,6 +82,15 @@ public class KeyPairTest extends TestCase { * Assertion: creates new <code>KeyPair</code> instance using valid * parameters (both <code>null</code>) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification when just one parameter is null missed", + targets = { + @TestTarget( + methodName = "KeyPair", + methodArgs = {PublicKey.class, PrivateKey.class} + ) + }) public final void testKeyPair01() { Object kp = new KeyPair(null, null); assertTrue(kp instanceof KeyPair); @@ -88,6 +102,15 @@ public class KeyPairTest extends TestCase { * parameters (both valid keys) * @throws InvalidKeySpecException */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification when just one parameter is null missed", + targets = { + @TestTarget( + methodName = "KeyPair", + methodArgs = {PublicKey.class, PrivateKey.class} + ) + }) public final void testKeyPair02() throws InvalidKeySpecException { Object kp = new KeyPair(TestKeyPair.getPublic(), TestKeyPair.getPrivate()); assertTrue(kp instanceof KeyPair); @@ -97,6 +120,15 @@ public class KeyPairTest extends TestCase { * Test #1 for <code>getPrivate()</code> method<br> * Assertion: returns private key (<code>null</code> in this case) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivate", + methodArgs = {} + ) + }) public final void testGetPrivate01() { KeyPair kp = new KeyPair(null, null); assertNull(kp.getPrivate()); @@ -107,6 +139,15 @@ public class KeyPairTest extends TestCase { * Assertion: returns private key (valid private key in this case) * @throws InvalidKeySpecException */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivate", + methodArgs = {} + ) + }) public final void testGetPrivate02() throws InvalidKeySpecException { PrivateKey pk = TestKeyPair.getPrivate(); KeyPair kp = new KeyPair(null, pk); @@ -117,6 +158,15 @@ public class KeyPairTest extends TestCase { * Test #1 for <code>getPublic()</code> method<br> * Assertion: returns public key (<code>null</code> in this case) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublic", + methodArgs = {} + ) + }) public final void testGetPublic01() { KeyPair kp = new KeyPair(null, null); assertNull(kp.getPublic()); @@ -127,6 +177,15 @@ public class KeyPairTest extends TestCase { * Assertion: returns public key (valid public key in this case) * @throws InvalidKeySpecException */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublic", + methodArgs = {} + ) + }) public final void testGetPublic02() throws InvalidKeySpecException { PublicKey pk = TestKeyPair.getPublic(); KeyPair kp = new KeyPair(pk, null); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java index e9081ad..1f03c20 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.NotSerializableException; import java.io.ObjectStreamException; import java.security.KeyRep; @@ -30,7 +35,7 @@ import java.util.Iterator; import java.util.Set; import junit.framework.TestCase; - +@TestTargetClass(KeyRep.class) /** * * @@ -42,6 +47,15 @@ public class KeyRepTest extends TestCase { keyFactoryAlgorithm = Security.getAlgorithms("KeyFactory"); } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyRep", + methodArgs = {java.security.KeyRep.Type.class, String.class, String.class, byte[].class} + ) + }) public final void testKeyRep01() { try { assertNotNull(new KeyRep(KeyRep.Type.SECRET, "", "", new byte[] {})); @@ -62,6 +76,15 @@ public class KeyRepTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyRep", + methodArgs = {java.security.KeyRep.Type.class, String.class, String.class, byte[].class} + ) + }) public final void testKeyRep02() { try { new KeyRep(null, "", "", new byte[] {}); @@ -89,6 +112,15 @@ public class KeyRepTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "readResolve", + methodArgs = {} + ) + }) public final void testReadResolve01() throws ObjectStreamException { KeyRepChild kr = new KeyRepChild(KeyRep.Type.SECRET, "", "", new byte[] {}); @@ -116,6 +148,15 @@ public class KeyRepTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "readResolve", + methodArgs = {} + ) + }) public final void testReadResolve02() throws ObjectStreamException { KeyRepChild kr = new KeyRepChild(KeyRep.Type.PUBLIC, "", "", new byte[] {}); @@ -144,6 +185,15 @@ public class KeyRepTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "readResolve", + methodArgs = {} + ) + }) public final void testReadResolve03() throws ObjectStreamException { KeyRepChild kr = new KeyRepChild(KeyRep.Type.PRIVATE, "", "", new byte[] {}); @@ -172,6 +222,15 @@ public class KeyRepTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "readResolve", + methodArgs = {} + ) + }) public final void testReadResolve04() throws ObjectStreamException { if (keyFactoryAlgorithm.isEmpty()) { System.err.println(getName() @@ -193,6 +252,15 @@ public class KeyRepTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "readResolve", + methodArgs = {} + ) + }) public final void testReadResolve05() throws ObjectStreamException { if (keyFactoryAlgorithm.isEmpty()) { System.err.println(getName() diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTypeTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTypeTest.java index 424dd1f..51e997f 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTypeTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyRepTypeTest.java @@ -16,11 +16,16 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyRep; import java.util.Arrays; import junit.framework.TestCase; - +@TestTargetClass(KeyRep.class) public class KeyRepTypeTest extends TestCase { protected void setUp() throws Exception { @@ -34,6 +39,15 @@ public class KeyRepTypeTest extends TestCase { /** * @tests java.security.KeyRep.Type#valueOf(String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "valueOf", + methodArgs = {String.class} + ) + }) public void testValueOf() { try { KeyRep.Type.valueOf("type"); @@ -58,6 +72,15 @@ public class KeyRepTypeTest extends TestCase { /** * @tests java.security.KeyRep.Type#values() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "values", + methodArgs = {} + ) + }) public void testValues() { KeyRep.Type[] types = new KeyRep.Type[] { KeyRep.Type.SECRET, KeyRep.Type.PUBLIC, KeyRep.Type.PRIVATE }; diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java index ce89238..f714a0b 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; @@ -55,6 +60,7 @@ import javax.crypto.spec.SecretKeySpec; import tests.support.Support_TestProvider; +@TestTargetClass(KeyStore.class) public class KeyStore2Test extends junit.framework.TestCase { static PrivateKey privateKey; static { @@ -169,6 +175,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#aliases() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "aliases", + methodArgs = {} + ) + }) public void test_aliases() throws Exception { // Test for method java.util.Enumeration // java.security.KeyStore.aliases() @@ -207,6 +222,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#containsAlias(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "containsAlias", + methodArgs = {String.class} + ) + }) public void test_containsAliasLjava_lang_String() throws Exception { // Test for method boolean // java.security.KeyStore.containsAlias(java.lang.String) @@ -231,6 +255,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getCertificate(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getCertificate", + methodArgs = {String.class} + ) + }) public void test_getCertificateLjava_lang_String() throws Exception { // Test for method java.security.cert.Certificate // java.security.KeyStore.getCertificate(java.lang.String) @@ -264,6 +297,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getCertificateAlias(java.security.cert.Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getCertificateAlias", + methodArgs = {Certificate.class} + ) + }) public void test_getCertificateAliasLjava_security_cert_Certificate() throws Exception { // Test for method java.lang.String @@ -299,6 +341,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getCertificateChain(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getCertificateChain", + methodArgs = {String.class} + ) + }) public void test_getCertificateChainLjava_lang_String() throws Exception { // Test for method java.security.cert.Certificate [] // java.security.KeyStore.getCertificateChain(java.lang.String) @@ -333,6 +384,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() throws Exception { // Test for method java.security.KeyStore // java.security.KeyStore.getInstance(java.lang.String) @@ -346,7 +406,17 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore#getInstance(java.lang.String, * java.lang.String) */ - public void test_getInstanceLjava_lang_StringLjava_lang_String() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException, NoSuchProviderException, " + + "IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) + public void _test_getInstanceLjava_lang_StringLjava_lang_String() { // Test for method java.security.KeyStore // java.security.KeyStore.getInstance(java.lang.String, // java.lang.String) @@ -369,7 +439,16 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore#getInstance(java.lang.String, * java.security.Provider) */ - public void test_getInstanceLjava_lang_StringLjava_security_Provider() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) + public void _test_getInstanceLjava_lang_StringLjava_security_Provider() { // Test for method java.security.KeyStore // java.security.KeyStore.getInstance(java.lang.String, // java.security.Provider) @@ -399,6 +478,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getKey(java.lang.String, char[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException, NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getKey", + methodArgs = {String.class, char[].class} + ) + }) public void test_getKeyLjava_lang_String$C() throws Exception { // Test for method java.security.Key @@ -438,7 +526,16 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getProvider() */ - public void test_getProvider() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) + public void _test_getProvider() { // Test for method java.security.Provider // java.security.KeyStore.getProvider() try { @@ -457,7 +554,16 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getType() */ - public void test_getType() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public void _test_getType() { // Test for method java.lang.String java.security.KeyStore.getType() try { @@ -476,6 +582,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#isCertificateEntry(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "isCertificateEntry", + methodArgs = {String.class} + ) + }) public void test_isCertificateEntryLjava_lang_String() throws Exception { // Test for method boolean // java.security.KeyStore.isCertificateEntry(java.lang.String) @@ -501,6 +616,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#isKeyEntry(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "isKeyEntry", + methodArgs = {String.class} + ) + }) public void test_isKeyEntryLjava_lang_String() throws Exception { // Test for method boolean // java.security.KeyStore.isKeyEntry(java.lang.String) @@ -525,7 +649,16 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#load(java.io.InputStream, char[]) */ - public void test_loadLjava_io_InputStream$C() throws Exception { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException, NoSuchAlgorithmException, CertificateException checking missed", + targets = { + @TestTarget( + methodName = "load", + methodArgs = {InputStream.class, char[].class} + ) + }) + public void _test_loadLjava_io_InputStream$C() throws Exception { // Test for method void java.security.KeyStore.load(java.io.InputStream, // char []) byte[] keyStore = creatCertificate(); @@ -565,6 +698,17 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#load(KeyStore.LoadStoreParameter param) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalArgumentException, IOException, " + + "NoSuchAlgorithmException, CertificateException" + + " and non null parameter checking missed", + targets = { + @TestTarget( + methodName = "load", + methodArgs = {java.security.KeyStore.LoadStoreParameter.class} + ) + }) public void test_loadLjava_security_KeyStoreLoadStoreParameter() { try { KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -580,6 +724,15 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore#setCertificateEntry(java.lang.String, * java.security.cert.Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "setCertificateEntry", + methodArgs = {String.class, Certificate.class} + ) + }) public void test_setCertificateEntryLjava_lang_StringLjava_security_cert_Certificate() throws Exception { // Test for method void @@ -607,6 +760,15 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore#setKeyEntry(java.lang.String, * java.security.Key, char[], java.security.cert.Certificate[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "setKeyEntry", + methodArgs = {String.class, java.security.Key.class, char[].class, Certificate[].class} + ) + }) public void test_setKeyEntryLjava_lang_StringLjava_security_Key$C$Ljava_security_cert_Certificate() throws Exception { @@ -629,6 +791,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#size() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "size", + methodArgs = {} + ) + }) public void test_size() throws Exception { // Test for method int java.security.KeyStore.size() @@ -653,7 +824,16 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#deleteEntry(String) */ - public void test_deleteEntry() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "deleteEntry", + methodArgs = {String.class} + ) + }) + public void _test_deleteEntry() { try { KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); keyTest.load(null, null); @@ -711,6 +891,15 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getCreationDate(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getCreationDate", + methodArgs = {String.class} + ) + }) public void test_getCreationDate() throws Exception { String type = "DSA"; @@ -780,7 +969,16 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#getDefaultType() */ - public void test_getDefaultType() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDefaultType", + methodArgs = {} + ) + }) + public void _test_getDefaultType() { assertEquals("jks", KeyStore.getDefaultType()); } @@ -788,7 +986,17 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore#getEntry(String, * KeyStore.ProtectionParameter) */ - public void test_getEntry() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException, NoSuchAlgorithmException, UnrecoverableEntryException, " + + "KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "getEntry", + methodArgs = {String.class, java.security.KeyStore.ProtectionParameter.class} + ) + }) + public void _test_getEntry() { String type = "DSA"; KeyStore keyTest = null; KeyStore.PasswordProtection pp = null; @@ -857,7 +1065,16 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore#setEntry(String, KeyStore.Entry, * KeyStore.ProtectionParameter) */ - public void test_setEntry() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setEntry", + methodArgs = {String.class, java.security.KeyStore.Entry.class, java.security.KeyStore.ProtectionParameter.class} + ) + }) + public void _test_setEntry() { String type = "DSA"; KeyStore keyTest = null; KeyStore.PasswordProtection pp = null; @@ -958,6 +1175,15 @@ public class KeyStore2Test extends junit.framework.TestCase { * @tests java.security.KeyStore.entryInstanceOf(String, Class<? extends * Entry>) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException, KeyStoreException checking missed", + targets = { + @TestTarget( + methodName = "entryInstanceOf", + methodArgs = {String.class, Class.class} + ) + }) public void test_entryInstanceOf() throws Exception { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -983,6 +1209,16 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#store(KeyStore.LoadStoreParameter) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalArgumentException, KeyStoreException, IOException, " + + "NoSuchAlgorithmException, CertificateException checking missed", + targets = { + @TestTarget( + methodName = "store", + methodArgs = {java.security.KeyStore.LoadStoreParameter.class} + ) + }) public void test_store_java_securityKeyStore_LoadStoreParameter() throws Exception { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -998,12 +1234,22 @@ public class KeyStore2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStore#store(OutputStream, char[]) */ - public void test_store_java_io_OutputStream_char() throws Exception { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyStoreException, IOException, " + + "NoSuchAlgorithmException, CertificateException checking missed", + targets = { + @TestTarget( + methodName = "store", + methodArgs = {java.io.OutputStream.class, char[].class} + ) + }) + public void _test_store_java_io_OutputStream_char() throws Exception { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, "pwd".toCharArray()); try { keyStore.store(null, "pwd".toCharArray()); - fail("UnsupportedOperationException expected"); + fail("NullPointerException expected"); } catch (NullPointerException e) { // expected } catch (Exception e) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java index b6c87b9..9869446 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -37,7 +42,7 @@ import java.util.Date; import java.util.Enumeration; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.class) public class KeyStore3Test extends TestCase { private KeyStore mockKeyStore; @@ -72,11 +77,29 @@ public class KeyStore3Test extends TestCase { certificate = cf.generateCertificate(certArray); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameter only.", + targets = { + @TestTarget( + methodName = "load", + methodArgs = {java.security.KeyStore.LoadStoreParameter.class} + ) + }) public void test_load() throws Exception { // No exception should be thrown out. mockKeyStore.load(null); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameter only", + targets = { + @TestTarget( + methodName = "store", + methodArgs = {java.security.KeyStore.LoadStoreParameter.class} + ) + }) public void test_store() throws Exception { try { mockKeyStore.store(null); @@ -90,18 +113,45 @@ public class KeyStore3Test extends TestCase { mockKeyStore.store(null); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with all null parameters only", + targets = { + @TestTarget( + methodName = "setKeyEntry", + methodArgs = {String.class, Key.class, char[].class, Certificate[].class} + ) + }) public void test_setKeyEntry_null() throws Exception { mockKeyStore.load(null, null); // No exception should be thrown out. mockKeyStore.setKeyEntry(null, null, null, null); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameters only", + targets = { + @TestTarget( + methodName = "setKeyEntry", + methodArgs = {String.class, Key.class, char[].class, Certificate[].class} + ) + }) public void test_setKeyEntry_key_is_null() throws Exception { mockKeyStore.load(null, null); // No exception should be thrown out. mockKeyStore.setKeyEntry("Alias", null, null, new Certificate[]{certificate}); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameters", + targets = { + @TestTarget( + methodName = "setKeyEntry", + methodArgs = {String.class, Key.class, char[].class, Certificate[].class} + ) + }) public void test_setKeyEntry_key_is_private() throws Exception { mockKeyStore.load(null, null); Key key = keyPair.getPrivate(); @@ -123,6 +173,15 @@ public class KeyStore3Test extends TestCase { mockKeyStore.setKeyEntry("Alias", key, null, new Certificate[]{certificate}); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameters", + targets = { + @TestTarget( + methodName = "setKeyEntry", + methodArgs = {String.class, Key.class, char[].class, Certificate[].class} + ) + }) public void test_setKeyEntry_key_is_public() throws Exception { mockKeyStore.load(null, null); @@ -133,6 +192,15 @@ public class KeyStore3Test extends TestCase { mockKeyStore.setKeyEntry("Alias3", key, null, new Certificate[]{certificate}); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameters", + targets = { + @TestTarget( + methodName = "setCertificateEntry", + methodArgs = {String.class, Certificate.class} + ) + }) public void test_setCertificateEntry_null() throws Exception { mockKeyStore.load(null, null); @@ -143,7 +211,16 @@ public class KeyStore3Test extends TestCase { mockKeyStore.setCertificateEntry("Alias", null); } - public void test_store_null() throws Exception { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies method with null parameters only", + targets = { + @TestTarget( + methodName = "store", + methodArgs = {OutputStream.class, char[].class} + ) + }) + public void _test_store_null() throws Exception { mockKeyStore.load(null, null); mockKeyStore.store(null, null); } @@ -224,20 +301,19 @@ public class KeyStore3Test extends TestCase { return; } - public int engineSize() { - return 0; + public int engineSize() { + return 0; } - public void engineStore(KeyStore.LoadStoreParameter param){ - return; + public void engineStore(KeyStore.LoadStoreParameter param){ + return; } - public void engineStore(OutputStream arg0, char[] arg1) - throws IOException, NoSuchAlgorithmException, - CertificateException { - return; + public void engineStore(OutputStream arg0, char[] arg1) + throws IOException, NoSuchAlgorithmException, + CertificateException { + return; } } } - diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreBuilderTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreBuilderTest.java index 19f6398..ba1468e 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreBuilderTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreBuilderTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -34,7 +39,7 @@ import org.apache.harmony.security.tests.support.KeyStoreTestSupport; import org.apache.harmony.security.tests.support.tmpCallbackHandler; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.class) public class KeyStoreBuilderTest extends TestCase { protected void setUp() throws Exception { @@ -70,8 +75,17 @@ public class KeyStoreBuilderTest extends TestCase { } /* - * test for method newInstance(KeyStore, KeyStore.ProtectionParameter) + * test for constructor KeyStoreBuilder */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreBuilder", + methodArgs = {} + ) + }) public void testConstructor() { try { new KeyStoreBuilder(); @@ -83,6 +97,15 @@ public class KeyStoreBuilderTest extends TestCase { /* * test for method newInstance(KeyStore, KeyStore.ProtectionParameter) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newInstance", + methodArgs = {java.security.KeyStore.class, java.security.KeyStore.ProtectionParameter.class} + ) + }) public void testNewInstanceKeyStoreProtectionParameter() throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException, InvalidKeyException, InvalidKeySpecException { @@ -199,7 +222,16 @@ public class KeyStoreBuilderTest extends TestCase { * ProtectionParameter which is used in newInstance(...) * */ - public void testNewInstanceStringProviderFileProtectionParameter() + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newInstance", + methodArgs = {String.class, java.security.Provider.class, java.io.File.class, java.security.KeyStore.ProtectionParameter.class} + ) + }) + public void _testNewInstanceStringProviderFileProtectionParameter() throws Exception { File fl = File.createTempFile("KSBuilder_ImplTest", "keystore"); @@ -351,6 +383,15 @@ public class KeyStoreBuilderTest extends TestCase { * when alias is not available * */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newInstance", + methodArgs = {String.class, java.security.Provider.class, java.security.KeyStore.ProtectionParameter.class} + ) + }) public void testNewInstanceStringProviderProtectionParameter() throws KeyStoreException { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java index 15e0399..3c62a38 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.KeyStoreException; +@TestTargetClass(KeyStoreException.class) public class KeyStoreException2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStoreException#KeyStoreException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.KeyStoreException() KeyStoreException e = new KeyStoreException(); @@ -34,6 +49,15 @@ public class KeyStoreException2Test extends junit.framework.TestCase { /** * @tests java.security.KeyStoreException#KeyStoreException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with one variant of string parameter", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.KeyStoreException(java.lang.String) KeyStoreException e = new KeyStoreException("test message"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java index 67e7c6c..704b31b 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.KeyStoreException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.KeyStoreException; +import junit.framework.TestCase; +@TestTargetClass(KeyStoreException.class) /** * Tests for <code>KeyStoreException</code> class constructors and methods. * @@ -55,6 +60,15 @@ public class KeyStoreExceptionTest extends TestCase { * Test for <code>KeyStoreException()</code> constructor Assertion: * constructs KeyStoreException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {} + ) + }) public void testKeyStoreException01() { KeyStoreException tE = new KeyStoreException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -66,6 +80,15 @@ public class KeyStoreExceptionTest extends TestCase { * constructs KeyStoreException with detail message msg. Parameter * <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class} + ) + }) public void testKeyStoreException02() { KeyStoreException tE; for (int i = 0; i < msgs.length; i++) { @@ -80,6 +103,15 @@ public class KeyStoreExceptionTest extends TestCase { * Test for <code>KeyStoreException(String)</code> constructor Assertion: * constructs KeyStoreException when <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class} + ) + }) public void testKeyStoreException03() { String msg = null; KeyStoreException tE = new KeyStoreException(msg); @@ -91,6 +123,15 @@ public class KeyStoreExceptionTest extends TestCase { * Test for <code>KeyStoreException(Throwable)</code> constructor * Assertion: constructs KeyStoreException when <code>cause</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {Throwable.class} + ) + }) public void testKeyStoreException04() { Throwable cause = null; KeyStoreException tE = new KeyStoreException(cause); @@ -103,6 +144,15 @@ public class KeyStoreExceptionTest extends TestCase { * Assertion: constructs KeyStoreException when <code>cause</code> is not * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {Throwable.class} + ) + }) public void testKeyStoreException05() { KeyStoreException tE = new KeyStoreException(tCause); if (tE.getMessage() != null) { @@ -121,6 +171,15 @@ public class KeyStoreExceptionTest extends TestCase { * Assertion: constructs KeyStoreException when <code>cause</code> is null * <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyStoreException06() { KeyStoreException tE = new KeyStoreException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -132,6 +191,15 @@ public class KeyStoreExceptionTest extends TestCase { * Assertion: constructs KeyStoreException when <code>cause</code> is null * <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyStoreException07() { KeyStoreException tE; for (int i = 0; i < msgs.length; i++) { @@ -147,6 +215,15 @@ public class KeyStoreExceptionTest extends TestCase { * Assertion: constructs KeyStoreException when <code>cause</code> is not * null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyStoreException08() { KeyStoreException tE = new KeyStoreException(null, tCause); if (tE.getMessage() != null) { @@ -165,6 +242,15 @@ public class KeyStoreExceptionTest extends TestCase { * Assertion: constructs KeyStoreException when <code>cause</code> is not * null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "KeyStoreException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testKeyStoreException09() { KeyStoreException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java index 76b2966..fb68823 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.IOException; import java.io.InputStream; import java.security.InvalidKeyException; @@ -43,7 +48,7 @@ import org.apache.harmony.security.tests.support.MyKeyStoreSpi; import org.apache.harmony.security.tests.support.MyLoadStoreParams; import junit.framework.TestCase; - +@TestTargetClass(KeyStoreSpi.class) /** * Tests for <code>KeyStoreSpi</code> constructor and methods * @@ -64,7 +69,16 @@ public class KeyStoreSpiTest extends TestCase { * @tests java.security.KeyStore.engineEntryInstanceOf(String, Class<? * extends Entry>) */ - public void test_engineEntryInstanceOf() throws Exception { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null parameters missed", + targets = { + @TestTarget( + methodName = "engineEntryInstanceOf", + methodArgs = {String.class, Class.class} + ) + }) + public void _test_engineEntryInstanceOf() throws Exception { KeyStoreSpi ksSpi = new MyKeyStoreSpi(); @@ -89,6 +103,28 @@ public class KeyStoreSpiTest extends TestCase { * null entry; engineStore(..) throws UnexpectedOperationException; * engineSetEntry(..) throws KeyStoreException or NullPointerException */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. Verification of exception cases missed for some methods. " + + "2. Verification for all non null parameters missed for all methods.", + targets = { + @TestTarget( + methodName = "engineLoad", + methodArgs = {KeyStore.LoadStoreParameter.class} + ), + @TestTarget( + methodName = "engineStore", + methodArgs = {KeyStore.LoadStoreParameter.class} + ), + @TestTarget( + methodName = "engineGetEntry", + methodArgs = {String.class, KeyStore.ProtectionParameter.class} + ), + @TestTarget( + methodName = "engineSetEntry", + methodArgs = {String.class, KeyStore.Entry.class, KeyStore.ProtectionParameter.class} + ) + }) public void testKeyStoteSpi01() throws IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableEntryException, KeyStoreException { @@ -130,6 +166,31 @@ public class KeyStoreSpiTest extends TestCase { * Test for <code>KeyStoreSpi()</code> constructor and abstract engine * methods. Assertion: creates new KeyStoreSpi object. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of positive case for all methods missed", + targets = { + @TestTarget( + methodName = "engineSetKeyEntry", + methodArgs = {String.class, java.security.Key.class, char[].class, Certificate[].class} + ), + @TestTarget( + methodName = "engineSetKeyEntry", + methodArgs = {String.class, byte[].class, Certificate[].class} + ), + @TestTarget( + methodName = "engineSetCertificateEntry", + methodArgs = {String.class, Certificate.class} + ), + @TestTarget( + methodName = "engineDeleteEntry", + methodArgs = {String.class} + ), + @TestTarget( + methodName = "engineStore", + methodArgs = {java.io.OutputStream.class, char[].class} + ) + }) public void testKeyStoteSpi02() throws NoSuchAlgorithmException, UnrecoverableKeyException, CertificateException { KeyStoreSpi ksSpi = new MyKeyStoreSpi(); @@ -175,6 +236,15 @@ public class KeyStoreSpiTest extends TestCase { /** * @tests java.security.KeyStoreSpi#engineLoad(KeyStore.LoadStoreParameter) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalArgumentException, NoSuchAlgorithmException, CertificateException checking missed", + targets = { + @TestTarget( + methodName = "engineLoad", + methodArgs = {KeyStore.LoadStoreParameter.class} + ) + }) public void test_engineLoadLjava_security_KeyStore_LoadStoreParameter() throws Exception { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java index bf70475..ab95775 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.IOException; import java.security.KeyStore; import java.security.KeyStoreException; @@ -48,7 +53,7 @@ import org.apache.harmony.security.tests.support.MyLoadStoreParams; import org.apache.harmony.security.tests.support.SpiEngUtils; import junit.framework.TestCase; - +@TestTargetClass(KeyStore.class) /** * Tests for <code>KeyStore</code> constructor and methods * @@ -106,6 +111,15 @@ public class KeyStoreTest extends TestCase { * methods * Assertions: throw IllegalArgumentException if param is null; */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, CertificateException checking missed", + targets = { + @TestTarget( + methodName = "load", + methodArgs = {java.security.KeyStore.LoadStoreParameter.class} + ) + }) public void testLoadStore02() throws Exception { assertTrue(NotSupportMsg, KSSupported); @@ -142,6 +156,15 @@ public class KeyStoreTest extends TestCase { * method * Assertion: stores KeyEntry. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setKeyEntry", + methodArgs = {String.class, byte[].class, Certificate[].class} + ) + }) public void testSetKeyEntry() throws Exception { assertTrue(NotSupportMsg, KSSupported); @@ -182,6 +205,15 @@ public class KeyStoreTest extends TestCase { * Test for <code>getDefaultType()</code> method Assertion: returns * default security key store type or "jks" string */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDefaultType", + methodArgs = {} + ) + }) public void testKeyStore01() { String propName = "keystore.type"; String defKSType = Security.getProperty(propName); @@ -210,6 +242,15 @@ public class KeyStoreTest extends TestCase { * throws KeyStoreException when type is not available * */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with valid parameter missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testKeyStore02() throws KeyStoreException { String[] invalidValues = SpiEngUtils.invalidValues; try { @@ -230,7 +271,16 @@ public class KeyStoreTest extends TestCase { /** * @test java.security.KeyStore.PasswordProtection.getPassword() */ - public void testKeyStorePPGetPassword() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed", + targets = { + @TestTarget( + methodName = "PasswordProtection.getPassword", + methodArgs = {} + ) + }) + public void _testKeyStorePPGetPassword() { // Regression for HARMONY-1539 // no exception expected assertNull(new KeyStore.PasswordProtection(null).getPassword()); @@ -241,12 +291,18 @@ public class KeyStoreTest extends TestCase { } - - - /** * @tests java.security.KeyStore.TrustedCertificateEntry.toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "IllegalStateException checking missed", + targets = { + @TestTarget( + methodName = "TrustedCertificateEntry.toString", + methodArgs = {} + ) + }) public void testKeyStoreTCToString() { // Regression for HARMONY-1542 // no exception expected diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyTest.java index 4f3f58a..21a9bb4 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/KeyTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.Key; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.Key; +import junit.framework.TestCase; +@TestTargetClass(Key.class) /** * Tests for <code>Key</code> class field * @@ -45,6 +50,15 @@ public class KeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Field testing", + targets = { + @TestTarget( + methodName = "serialVersionUID", + methodArgs = {} + ) + }) public void testField() { checkKey mk = new checkKey(); assertEquals("Incorrect serialVersionUID", mk.getSerVerUID(), //Key.serialVersionUID, diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java index 2c14a7d..a49d03e 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.nio.ByteBuffer; import java.security.DigestException; import java.security.MessageDigest; @@ -25,6 +30,7 @@ import junit.framework.TestCase; import org.apache.harmony.security.tests.support.MyMessageDigest1; +@TestTargetClass(MessageDigest.class) /** * Tests for <code>MessageDigest</code> constructor and methods */ @@ -33,6 +39,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#reset() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void test_reset() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); md.reset(); @@ -42,6 +57,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#update(byte) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte.class} + ) + }) public void test_updateLB() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); md.update((byte) 1); @@ -51,6 +75,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#update(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Case when len < offset missed", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_updateLB$LILI() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); final byte[] bytes = { 1, 2, 3, 4, 5 }; @@ -95,6 +128,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#update(byte[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class} + ) + }) public void test_updateLB$() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); byte[] b = { 1, 2, 3, 4, 5 }; @@ -105,6 +147,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#update(ByteBuffer) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {ByteBuffer.class} + ) + }) public void test_updateLjava_nio_ByteBuffer() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); byte[] b = { 1, 2, 3, 4, 5 }; @@ -120,6 +171,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#digest() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "digest", + methodArgs = {} + ) + }) public void test_digest() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); assertEquals("incorrect result", 0, md.digest().length); @@ -129,6 +189,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#digest(byte[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "digest", + methodArgs = {byte[].class} + ) + }) public void test_digestLB$() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); byte[] b = { 1, 2, 3, 4, 5 }; @@ -139,6 +208,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#digest(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "DigestException checking missed", + targets = { + @TestTarget( + methodName = "digest", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_digestLB$LILI() throws Exception { MyMessageDigest1 md = new MyMessageDigest1("ABC"); byte[] b = { 1, 2, 3, 4, 5 }; @@ -185,6 +263,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#isEqual(byte[],byte[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isEqual", + methodArgs = {byte[].class, byte[].class} + ) + }) public void test_isEqualLB$LB$() { byte[] b1 = { 1, 2, 3, 4 }; byte[] b2 = { 1, 2, 3, 4, 5 }; @@ -199,6 +286,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); assertEquals("ABC", md.getAlgorithm()); @@ -207,6 +303,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); assertNull(md.getProvider()); @@ -215,6 +320,15 @@ public class MessageDigest1Test extends TestCase { /** * @tests java.security.MessageDigest#getDigestLength() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDigestLength", + methodArgs = {} + ) + }) public void test_getDigestLength() { MyMessageDigest1 md = new MyMessageDigest1("ABC"); assertEquals(0, md.getDigestLength()); @@ -223,6 +337,15 @@ public class MessageDigest1Test extends TestCase { /** * Tests SHA MessageDigest provider */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void testSHAProvider() throws Exception { MessageDigest md = MessageDigest.getInstance("SHA"); byte[] bytes = new byte[] { 1, 1, 1, 1, 1 }; diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java index 7e043aa..5f0bc44 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; @@ -30,6 +35,7 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.Vector; +@TestTargetClass(MessageDigest.class) public class MessageDigest2Test extends junit.framework.TestCase { private static final String MESSAGEDIGEST_ID = "MessageDigest."; @@ -62,6 +68,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#MessageDigest(java.lang.String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "MessageDigest", + methodArgs = {String.class} + ) + }) public void test_constructor() { for (int i = 0; i < digestAlgs.length; i++) { MessageDigestStub md = new MessageDigestStub(digestAlgs[i]); @@ -74,6 +89,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#clone() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) public void test_clone() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -221,6 +245,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#digest() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "digest", + methodArgs = {} + ) + }) public void test_digest() { MessageDigest sha = null; try { @@ -267,6 +300,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#digest(byte[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "digest", + methodArgs = {byte[].class} + ) + }) public void test_digest$B() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -285,6 +327,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#digest(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of different variants of offset and len parameters missed", + targets = { + @TestTarget( + methodName = "digest", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_digest$BII() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -318,6 +369,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#update(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of different variants of offset and len parameters missed", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_update$BII() { try { MessageDigest.getInstance("SHA").update(new byte[] {}, @@ -332,6 +392,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -349,6 +418,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#getDigestLength() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDigestLength", + methodArgs = {} + ) + }) public void test_getDigestLength() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -367,6 +445,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -381,6 +468,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { * @tests java.security.MessageDigest#getInstance(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -397,6 +493,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { * @tests java.security.MessageDigest#getInstance(java.lang.String, * java.security.Provider) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_security_Provider() { Provider[] providers = Security.getProviders("MessageDigest.SHA"); for (int i = 0; i < digestAlgs.length; i++) { @@ -414,6 +519,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() { for (int i = 0; i < digestAlgs.length; i++) { try { @@ -431,6 +545,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#isEqual(byte[], byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Otherwise case is not checked", + targets = { + @TestTarget( + methodName = "isEqual", + methodArgs = {byte[].class, byte[].class} + ) + }) public void test_isEqual$B$B() { assertTrue("isEqual is not correct", MessageDigest.isEqual(AR1, AR2)); } @@ -438,6 +561,15 @@ public class MessageDigest2Test extends junit.framework.TestCase { /** * @tests java.security.MessageDigest#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() { try { String str = MessageDigest.getInstance("SHA").toString(); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigestSpiTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigestSpiTest.java index 777d3e2..3bb5bde 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigestSpiTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/MessageDigestSpiTest.java @@ -22,12 +22,17 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.nio.ByteBuffer; import java.security.DigestException; import java.security.MessageDigestSpi; import junit.framework.TestCase; - +@TestTargetClass(MessageDigestSpi.class) /** * Tests for <code>MessageDigestSpi</code> constructor and methods */ @@ -36,6 +41,15 @@ public class MessageDigestSpiTest extends TestCase { /** * java.security.MessageDigestSpi#MessageDigestSpi() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "MessageDigestSpi", + methodArgs = {} + ) + }) public void test_constructor() { try { new MyMessageDigest(); @@ -47,6 +61,15 @@ public class MessageDigestSpiTest extends TestCase { /** * java.security.MessageDigestSpi#engineDigest(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of other variants of len and offset parameters missed", + targets = { + @TestTarget( + methodName = "engineDigest", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_engineDigestLB$LILI() throws Exception { final int DIGEST_LENGHT = 2; @@ -92,6 +115,15 @@ public class MessageDigestSpiTest extends TestCase { /** * java.security.MessageDigestSpi#engineGetDigestLength() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Not zero digest length in bytes wasn't checked", + targets = { + @TestTarget( + methodName = "engineGetDigestLength", + methodArgs = {} + ) + }) public void test_engineGetDigestLength() { MyMessageDigest md = new MyMessageDigest(); assertEquals(0, md.engineGetDigestLength()); @@ -100,6 +132,15 @@ public class MessageDigestSpiTest extends TestCase { /** * java.security.MessageDigestSpi#engineUpdate(ByteBuffer) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "engineUpdate", + methodArgs = {ByteBuffer.class} + ) + }) public void test_engineUpdateLjava_nio_ByteBuffer() { MyMessageDigest md = new MyMessageDigest(); byte[] b = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -123,6 +164,15 @@ public class MessageDigestSpiTest extends TestCase { /** * @tests java.security.MessageDigestSpi#clone() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) public void test_clone() throws CloneNotSupportedException { MyMessageDigest md = new MyMessageDigest(); try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmException2Test.java index 5219115..ed0478a 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.NoSuchAlgorithmException; +@TestTargetClass(NoSuchAlgorithmException.class) public class NoSuchAlgorithmException2Test extends junit.framework.TestCase { /** * @tests java.security.NoSuchAlgorithmException#NoSuchAlgorithmException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {} + ) + }) public void test_Constructor() { try { throw new NoSuchAlgorithmException(); @@ -37,6 +52,15 @@ public class NoSuchAlgorithmException2Test extends junit.framework.TestCase { /** * @tests java.security.NoSuchAlgorithmException#NoSuchAlgorithmException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.NoSuchAlgorithmException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java index f839ba9..e1576ec 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchAlgorithmExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.NoSuchAlgorithmException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.NoSuchAlgorithmException; +import junit.framework.TestCase; +@TestTargetClass(NoSuchAlgorithmException.class) /** * Tests for <code>NoSuchAlgorithmException</code> class constructors and * methods. @@ -56,6 +61,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * Test for <code>NoSuchAlgorithmException()</code> constructor Assertion: * constructs NoSuchAlgorithmException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {} + ) + }) public void testNoSuchAlgorithmException01() { NoSuchAlgorithmException tE = new NoSuchAlgorithmException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -67,6 +81,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * Assertion: constructs NoSuchAlgorithmException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class} + ) + }) public void testNoSuchAlgorithmException02() { NoSuchAlgorithmException tE; for (int i = 0; i < msgs.length; i++) { @@ -82,6 +105,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * Assertion: constructs NoSuchAlgorithmException when <code>msg</code> is * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class} + ) + }) public void testNoSuchAlgorithmException03() { String msg = null; NoSuchAlgorithmException tE = new NoSuchAlgorithmException(msg); @@ -94,6 +126,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * Assertion: constructs NoSuchAlgorithmException when <code>cause</code> * is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {Throwable.class} + ) + }) public void testNoSuchAlgorithmException04() { Throwable cause = null; NoSuchAlgorithmException tE = new NoSuchAlgorithmException(cause); @@ -106,6 +147,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * Assertion: constructs NoSuchAlgorithmException when <code>cause</code> * is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {Throwable.class} + ) + }) public void testNoSuchAlgorithmException05() { NoSuchAlgorithmException tE = new NoSuchAlgorithmException(tCause); if (tE.getMessage() != null) { @@ -124,6 +174,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * constructor Assertion: constructs NoSuchAlgorithmException when * <code>cause</code> is null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testNoSuchAlgorithmException06() { NoSuchAlgorithmException tE = new NoSuchAlgorithmException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -135,6 +194,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * constructor Assertion: constructs NoSuchAlgorithmException when * <code>cause</code> is null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testNoSuchAlgorithmException07() { NoSuchAlgorithmException tE; for (int i = 0; i < msgs.length; i++) { @@ -150,6 +218,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * constructor Assertion: constructs NoSuchAlgorithmException when * <code>cause</code> is not null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testNoSuchAlgorithmException08() { NoSuchAlgorithmException tE = new NoSuchAlgorithmException(null, tCause); if (tE.getMessage() != null) { @@ -168,6 +245,15 @@ public class NoSuchAlgorithmExceptionTest extends TestCase { * constructor Assertion: constructs NoSuchAlgorithmException when * <code>cause</code> is not null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchAlgorithmException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testNoSuchAlgorithmException09() { NoSuchAlgorithmException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderException2Test.java index 67dc488..9d28264 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.NoSuchProviderException; +@TestTargetClass(NoSuchProviderException.class) public class NoSuchProviderException2Test extends junit.framework.TestCase { /** * @tests java.security.NoSuchProviderException#NoSuchProviderException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchProviderException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.NoSuchProviderException() try { @@ -38,6 +53,15 @@ public class NoSuchProviderException2Test extends junit.framework.TestCase { /** * @tests java.security.NoSuchProviderException#NoSuchProviderException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "NoSuchProviderException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.NoSuchProviderException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java index 2dfa23d..5219f0f 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/NoSuchProviderExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.NoSuchProviderException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.NoSuchProviderException; +import junit.framework.TestCase; +@TestTargetClass(NoSuchProviderException.class) /** * Tests for <code>NoSuchProviderException</code> class constructors and * methods. @@ -56,6 +61,15 @@ public class NoSuchProviderExceptionTest extends TestCase { * Test for <code>NoSuchProviderException()</code> constructor Assertion: * constructs NoSuchProviderException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchProviderException", + methodArgs = {} + ) + }) public void testNoSuchProviderException01() { NoSuchProviderException tE = new NoSuchProviderException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -67,6 +81,15 @@ public class NoSuchProviderExceptionTest extends TestCase { * Assertion: constructs NoSuchProviderException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchProviderException", + methodArgs = {String.class} + ) + }) public void testNoSuchProviderException02() { NoSuchProviderException tE; for (int i = 0; i < msgs.length; i++) { @@ -82,6 +105,15 @@ public class NoSuchProviderExceptionTest extends TestCase { * Assertion: constructs NoSuchProviderException when <code>msg</code> is * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "NoSuchProviderException", + methodArgs = {String.class} + ) + }) public void testNoSuchProviderException03() { String msg = null; NoSuchProviderException tE = new NoSuchProviderException(msg); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java index 0ae6936..3507615 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/Permission2Test.java @@ -17,10 +17,16 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Permission; import java.security.PermissionCollection; import java.security.SecurityPermission; +@TestTargetClass(Permission.class) public class Permission2Test extends junit.framework.TestCase { static class ConcretePermission extends Permission { public ConcretePermission() { @@ -47,6 +53,15 @@ public class Permission2Test extends junit.framework.TestCase { /** * @tests java.security.Permission#Permission(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification when string parameter empty/null is missed", + targets = { + @TestTarget( + methodName = "Permission", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // test method java.security.permission.Permission(string) SecurityPermission permi = new SecurityPermission( @@ -59,6 +74,15 @@ public class Permission2Test extends junit.framework.TestCase { /** * @tests java.security.Permission#checkGuard(java.lang.Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "checkGuard", + methodArgs = {Object.class} + ) + }) public void test_checkGuardLjava_lang_Object() { // test method java.security.permission.checkGuard(object) SecurityPermission permi = new SecurityPermission( @@ -74,6 +98,15 @@ public class Permission2Test extends junit.framework.TestCase { /** * @tests java.security.Permission#getName() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void test_getName() { // test method java.security.permission.getName() SecurityPermission permi = new SecurityPermission("testing getName()"); @@ -89,6 +122,15 @@ public class Permission2Test extends junit.framework.TestCase { /** * @tests java.security.Permission#newPermissionCollection() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Case when null returned if one is not defined is missed", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void test_newPermissionCollection() { // test method java.security.permission.newPermissionCollection Permission permi = new ConcretePermission(); @@ -101,6 +143,15 @@ public class Permission2Test extends junit.framework.TestCase { /** * @tests java.security.Permission#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() { // test method java.security.permission.toString // test for permission with no action diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java index 2fca307..81c9817 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionCollectionTest.java @@ -21,13 +21,18 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Permission; import java.security.PermissionCollection; import java.util.*; import junit.framework.TestCase; - - +@TestTargetClass(PermissionCollection.class) /** * Tests for <code>PermissionCollection</code> * @@ -70,6 +75,19 @@ public class PermissionCollectionTest extends TestCase { } /** Test read-only flag. Should be false by default and can be set once forever. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isReadOnly", + methodArgs = {} + ), + @TestTarget( + methodName = "setReadOnly", + methodArgs = {} + ) + }) public void testReadOnly() { PermissionCollection pc = new RealPermissionCollection(null); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java index 054db0e..0c78205 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionTest.java @@ -21,10 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Permission; import junit.framework.TestCase; - +@TestTargetClass(Permission.class) /** * Tests for <code>Permission</code> */ @@ -72,6 +78,15 @@ public class PermissionTest extends TestCase { * Test that a permission object is created with the specified name and is * properly converted to String */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Non null string parameter verified", + targets = { + @TestTarget( + methodName = "Permission", + methodArgs = {String.class} + ) + }) public void testCtor() { String name = "testCtor123^%$#&^ &^$"; Permission test = new RealPermission(name); @@ -85,6 +100,15 @@ public class PermissionTest extends TestCase { * checkPermission() should be called with this permission, otherwise * nothing happens */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "checkGuard", + methodArgs = {Object.class} + ) + }) public void testCheckGuard() { final Permission test = new RealPermission("234234"); SecurityManager old = System.getSecurityManager(); @@ -108,6 +132,15 @@ public class PermissionTest extends TestCase { } /** newPermissionCollection() should return null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Returned parameter was tested.", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void testCollection() { assertNull(new RealPermission("123").newPermissionCollection()); } diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java index fea99b5..ab737eb 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java @@ -17,11 +17,17 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.io.FilePermission; import java.security.Permissions; import java.util.Enumeration; +@TestTargetClass(Permissions.class) public class Permissions2Test extends junit.framework.TestCase { FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read"); @@ -38,6 +44,15 @@ public class Permissions2Test extends junit.framework.TestCase { /** * @tests java.security.Permissions#Permissions() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Permissions", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.Permissions() new Permissions(); @@ -46,6 +61,16 @@ public class Permissions2Test extends junit.framework.TestCase { /** * @tests java.security.Permissions#add(java.security.Permission) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of method with null parameter is missed." + + "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "add", + methodArgs = {java.security.Permission.class} + ) + }) public void test_addLjava_security_Permission() { // Test for method void // java.security.Permissions.add(java.security.Permission) @@ -79,6 +104,15 @@ public class Permissions2Test extends junit.framework.TestCase { /** * @tests java.security.Permissions#elements() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Case when no added elements is missed", + targets = { + @TestTarget( + methodName = "elements", + methodArgs = {} + ) + }) public void test_elements() { // Test for method java.util.Enumeration // java.security.Permissions.elements() @@ -112,6 +146,15 @@ public class Permissions2Test extends junit.framework.TestCase { /** * @tests java.security.Permissions#implies(java.security.Permission) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of method with null parameter is missed.", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {java.security.Permission.class} + ) + }) public void test_impliesLjava_security_Permission() { // Test for method boolean // java.security.Permissions.implies(java.security.Permission) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java index 745cc96..2e93788 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AllPermission; import java.security.BasicPermission; import java.security.Permission; @@ -36,8 +42,7 @@ import java.util.NoSuchElementException; import junit.framework.TestCase; - - +@TestTargetClass(Permissions.class) /** * Tests for <code>Permissions</code> * @@ -52,6 +57,15 @@ public class PermissionsTest extends TestCase { /** * Can add any type of permissions. Cannot add if collection is read-only. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "add", + methodArgs = {Permission.class} + ) + }) public void testAdd() { Permissions ps = new Permissions(); Permission ap = new AllPermission(); @@ -87,6 +101,15 @@ public class PermissionsTest extends TestCase { * non-empty collection, should always return enumeration over unique * elements. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "elements", + methodArgs = {} + ) + }) public void testElements() { Permissions ps = new Permissions(); Permission ap = new AllPermission(); @@ -135,6 +158,23 @@ public class PermissionsTest extends TestCase { /** * input parameter is null */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "implies - non null checking missed", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {Permission.class} + ), + @TestTarget( + methodName = "add", + methodArgs = {Permission.class} + ), + @TestTarget( + methodName = "elements", + methodArgs = {} + ) + }) public void testNull(){ Permissions ps = new Permissions(); try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java index 71df2ea..8b4ac39 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PolicyTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.io.FilePermission; import java.net.MalformedURLException; @@ -42,8 +47,7 @@ import org.apache.harmony.security.tests.support.SecurityChecker; import org.apache.harmony.security.tests.support.TestUtils; import junit.framework.TestCase; - - +@TestTargetClass(Policy.class) /** * Tests for <code>Policy</code> */ @@ -56,8 +60,17 @@ public class PolicyTest extends TestCase { } /** - * @tests java.security.Policy#setPolicy(java.security.Policy) + * @tests constructor Policy() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Policy", + methodArgs = {} + ) + }) public void test_constructor() { try { new TestProvider(); @@ -69,6 +82,19 @@ public class PolicyTest extends TestCase { /** * @tests java.security.Policy#setPolicy(java.security.Policy) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setPolicy", + methodArgs = {Policy.class} + ), + @TestTarget( + methodName = "getPolicy", + methodArgs = {} + ) + }) public void test_setPolicyLjava_security_Policy() { SecurityManager old = System.getSecurityManager(); Policy oldPolicy = Policy.getPolicy(); @@ -97,6 +123,19 @@ public class PolicyTest extends TestCase { /** * @tests java.security.Policy#getPolicy() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPolicy", + methodArgs = {} + ), + @TestTarget( + methodName = "setPolicy", + methodArgs = {Policy.class} + ) + }) public void test_getPolicy() { SecurityManager old = System.getSecurityManager(); Policy oldPolicy = Policy.getPolicy(); @@ -136,6 +175,15 @@ public class PolicyTest extends TestCase { /** * Tests that getPermissions() does proper permission evaluation. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPermissions", + methodArgs = {ProtectionDomain.class} + ) + }) public void testGetPermissions() { SecurityPermission sp = new SecurityPermission("abc"); SecurityPermission sp2 = new SecurityPermission("fbdf"); @@ -184,6 +232,19 @@ public class PolicyTest extends TestCase { * @tests java.security.Policy#getPolicy() * @tests java.security.Policy#setPolicy() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setPolicy", + methodArgs = {Policy.class} + ), + @TestTarget( + methodName = "getPolicy", + methodArgs = {} + ) + }) public void testResetingPolicyToDefault() { Policy oldPolicy = Policy.getPolicy(); @@ -208,7 +269,16 @@ public class PolicyTest extends TestCase { /** * @tests java.security.Policy#implies(ProtectionDomain, Permission) */ - public void test_implies() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {ProtectionDomain.class, Permission.class} + ) + }) + public void _test_implies() { Policy policy = Policy.getPolicy(); char s = File.separatorChar; @@ -285,7 +355,20 @@ public class PolicyTest extends TestCase { /** * Test property expansion in policy files */ - public void testPropertyExpansion() throws Exception { + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setPolicy", + methodArgs = {Policy.class} + ), + @TestTarget( + methodName = "getPolicy", + methodArgs = {} + ) + }) + public void _testPropertyExpansion() throws Exception { // Regression for HARMONY-1963 and HARMONY-2910 String policyFile = new File(ClassLoader.getSystemClassLoader() diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java index c0bd016..d304c00 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivateKeyTest.java @@ -21,11 +21,15 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import java.security.PrivateKey; import junit.framework.TestCase; - - +@TestTargetClass(PrivateKey.class) /** * Tests for <code>PrivateKey</code> class field * @@ -45,6 +49,15 @@ public class PrivateKeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Field testing", + targets = { + @TestTarget( + methodName = "serialVersionUID", + methodArgs = {} + ) + }) public void testField() { checkPrivateKey cPrKey = new checkPrivateKey(); assertEquals("Incorrect serialVersionUID", cPrKey.getSerVerUID(), //PrivateKey.serialVersionUID, diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java index 24cc1a1..9aba4a2 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionException2Test.java @@ -17,14 +17,29 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.IOException; import java.security.PrivilegedActionException; +@TestTargetClass(PrivilegedActionException.class) public class PrivilegedActionException2Test extends junit.framework.TestCase { /** * @tests java.security.PrivilegedActionException#PrivilegedActionException(java.lang.Exception) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PrivilegedActionException", + methodArgs = {Exception.class} + ) + }) public void test_ConstructorLjava_lang_Exception() { Exception e = new Exception("test exception"); PrivilegedActionException pe = new PrivilegedActionException(e); @@ -40,6 +55,15 @@ public class PrivilegedActionException2Test extends junit.framework.TestCase { /** * @tests java.security.PrivilegedActionException#getException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getException", + methodArgs = {} + ) + }) public void test_getException() { Exception e = new IOException("test IOException"); PrivilegedActionException pe = new PrivilegedActionException(e); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java index ea3eb1f..e5bd3b1 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PrivilegedActionExceptionTest.java @@ -22,10 +22,15 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.PrivilegedActionException; import junit.framework.TestCase; - +@TestTargetClass(PrivilegedActionException.class) /** * Unit test for java.security.PrivilegedActionException. * @@ -43,6 +48,15 @@ public class PrivilegedActionExceptionTest extends TestCase { /** * Tests PrivilegedActionException(Exception) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PrivilegedActionException", + methodArgs = {Exception.class} + ) + }) public void testPrivilegedActionException() { new PrivilegedActionException(null); Exception ex = new Exception(); @@ -52,6 +66,15 @@ public class PrivilegedActionExceptionTest extends TestCase { /** * Tests PrivilegedActionException.getException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getException", + methodArgs = {} + ) + }) public void testGetException() { assertNull(new PrivilegedActionException(null).getException()); Exception ex = new Exception(); @@ -61,6 +84,15 @@ public class PrivilegedActionExceptionTest extends TestCase { /** * Tests PrivilegedActionException.toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { assertNotNull(new PrivilegedActionException(null).toString()); assertNotNull(new PrivilegedActionException(new Exception()).toString()); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java index 175a953..0c11b06 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProtectionDomainTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.net.URL; import java.net.MalformedURLException; import java.net.URLClassLoader; @@ -34,8 +40,7 @@ import java.security.Principal; import java.security.ProtectionDomain; import junit.framework.TestCase; - - +@TestTargetClass(ProtectionDomain.class) /** * Unit tests for java.security.ProtectionDomain. * @@ -86,6 +91,15 @@ public class ProtectionDomainTest extends TestCase { * Class under test for void ProtectionDomain(CodeSource, * PermissionCollection) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProtectionDomain", + methodArgs = {CodeSource.class, PermissionCollection.class} + ) + }) public void testProtectionDomainCodeSourcePermissionCollection_00() { new ProtectionDomain(null, null); new ProtectionDomain(cs, null); @@ -96,6 +110,15 @@ public class ProtectionDomainTest extends TestCase { /** * the ctor must set the PermissionCollection read-only */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProtectionDomain", + methodArgs = {CodeSource.class, PermissionCollection.class} + ) + }) public void testProtectionDomainCodeSourcePermissionCollection_01() { assertFalse(perms.isReadOnly()); new ProtectionDomain(null, perms); @@ -105,6 +128,15 @@ public class ProtectionDomainTest extends TestCase { /** * Test for ProtectionDomain(CodeSource, PermissionCollection, ClassLoader, Principal[]) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ProtectionDomain", + methodArgs = {CodeSource.class, PermissionCollection.class, ClassLoader.class, Principal[].class} + ) + }) public void testProtectionDomainCodeSourcePermissionCollectionClassLoaderPrincipalArray() { new ProtectionDomain(null, null, null, null); @@ -119,6 +151,15 @@ public class ProtectionDomainTest extends TestCase { /** * Tests for ProtectionDomain.getClassLoader() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getClassLoader", + methodArgs = {} + ) + }) public void testGetClassLoader() { assertNull(new ProtectionDomain(null, null).getClassLoader()); assertSame(new ProtectionDomain(null, null, classldr, null) @@ -128,6 +169,15 @@ public class ProtectionDomainTest extends TestCase { /** * Tests for ProtectionDomain.getCodeSource() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCodeSource", + methodArgs = {} + ) + }) public void testGetCodeSource() { assertNull(new ProtectionDomain(null, null).getCodeSource()); assertSame(new ProtectionDomain(cs, null).getCodeSource(), cs); @@ -136,6 +186,15 @@ public class ProtectionDomainTest extends TestCase { /** * Tests for ProtectionDomain.getPermissions() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPermissions", + methodArgs = {} + ) + }) public void testGetPermissions() { assertNull(new ProtectionDomain(null, null).getPermissions()); assertSame(new ProtectionDomain(null, perms).getPermissions(), perms); @@ -144,6 +203,15 @@ public class ProtectionDomainTest extends TestCase { /** * getPrincipals() always returns non null array */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrincipals", + methodArgs = {} + ) + }) public void testGetPrincipals_00() { assertNotNull(new ProtectionDomain(null, null).getPrincipals()); } @@ -151,6 +219,15 @@ public class ProtectionDomainTest extends TestCase { /** * getPrincipals() returns new array each time it's called */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrincipals", + methodArgs = {} + ) + }) public void testGetPrincipals_01() { ProtectionDomain pd = new ProtectionDomain(null, null, null, principals); Principal[] got = pd.getPrincipals(); @@ -163,6 +240,15 @@ public class ProtectionDomainTest extends TestCase { /** * ProtectionDomain with null Permissions must not imply() permissions. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {Permission.class} + ) + }) public void testImplies_00() { assertFalse(new ProtectionDomain(null, null).implies(allperm)); } @@ -171,6 +257,15 @@ public class ProtectionDomainTest extends TestCase { * ProtectionDomain with PermissionCollection which contains AllPermission * must imply() AllPermission. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {Permission.class} + ) + }) public void testImplies_01() { assertTrue(new ProtectionDomain(null, perms).implies(allperm)); } @@ -179,6 +274,15 @@ public class ProtectionDomainTest extends TestCase { * ProtectionDomain created with a static set of permissions must not query * policy. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {Permission.class} + ) + }) public void testImplies_02() { TestPolicy policy = new TestPolicy(); // null set of permissions [must] force the PD to use Policy - for @@ -198,6 +302,15 @@ public class ProtectionDomainTest extends TestCase { * ProtectionDomain created with dynamic set of permissions must query * policy. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {Permission.class} + ) + }) public void testImplies_03() { TestPolicy policy = new TestPolicy(); ProtectionDomain pd = new ProtectionDomain(cs, null, ClassLoader @@ -215,6 +328,15 @@ public class ProtectionDomainTest extends TestCase { /** * Simply checks that it's working somehow */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Receiving of test result is missed", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { new ProtectionDomain(null, null).toString(); new ProtectionDomain(cs, perms).toString(); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/Provider2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/Provider2Test.java index bbd95a5..f42a322 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/Provider2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/Provider2Test.java @@ -17,8 +17,14 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Provider; +@TestTargetClass(Provider.class) public class Provider2Test extends junit.framework.TestCase { class TestProvider extends Provider { @@ -48,6 +54,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#entrySet() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "UnsupportedOperationException verification", + targets = { + @TestTarget( + methodName = "entrySet", + methodArgs = {} + ) + }) public void test_entrySet() { // test method of java.security.provider.entrySet provTest.put("test.prop", "this is a test property"); @@ -63,6 +78,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#getInfo() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInfo", + methodArgs = {} + ) + }) public void test_getInfo() { // test method of java.security.provider.getInfo assertEquals("the information of the provider is not stored properly", @@ -73,6 +97,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#getName() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void test_getName() { // test method of java.security.provider.getName assertEquals("the name of the provider is not stored properly", @@ -82,6 +115,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#getVersion() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getVersion", + methodArgs = {} + ) + }) public void test_getVersion() { // test method of java.security.provider.getVersion assertEquals("the version of the provider is not stored properly", @@ -91,6 +133,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#keySet() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "UnsupportedOperationException verification", + targets = { + @TestTarget( + methodName = "keySet", + methodArgs = {} + ) + }) public void test_keySet() { // test method of java.security.provider.keySet provTest.put("test.prop", "this is a test property"); @@ -105,6 +156,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#values() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "UnsupportedOperationException verification", + targets = { + @TestTarget( + methodName = "values", + methodArgs = {} + ) + }) public void test_values() { // test method of java.security.provider.values provTest.put("test.prop", "this is a test property"); @@ -120,6 +180,15 @@ public class Provider2Test extends junit.framework.TestCase { /** * @tests java.security.Provider#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Regression test", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() { // Regression for HARMONY-3734 assertEquals("provTest version 1.2", provTest.toString()); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderException2Test.java index dde5259..5b476ae 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.ProviderException; +@TestTargetClass(ProviderException.class) public class ProviderException2Test extends junit.framework.TestCase { /** * @tests java.security.ProviderException#ProviderException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.ProviderException() ProviderException e = new ProviderException(); @@ -34,6 +49,15 @@ public class ProviderException2Test extends junit.framework.TestCase { /** * @tests java.security.ProviderException#ProviderException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null/empty parameter is absent", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.ProviderException(java.lang.String) ProviderException e = new ProviderException("test message"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java index 9cae2b6..ba5f3e7 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.ProviderException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.ProviderException; +import junit.framework.TestCase; +@TestTargetClass(ProviderException.class) /** * Tests for <code>ProviderException</code> class constructors and methods. * @@ -55,6 +60,15 @@ public class ProviderExceptionTest extends TestCase { * Test for <code>ProviderException()</code> constructor Assertion: * constructs ProviderException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {} + ) + }) public void testProviderException01() { ProviderException tE = new ProviderException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -66,6 +80,15 @@ public class ProviderExceptionTest extends TestCase { * constructs ProviderException with detail message msg. Parameter * <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class} + ) + }) public void testProviderException02() { ProviderException tE; for (int i = 0; i < msgs.length; i++) { @@ -80,6 +103,15 @@ public class ProviderExceptionTest extends TestCase { * Test for <code>ProviderException(String)</code> constructor Assertion: * constructs ProviderException when <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class} + ) + }) public void testProviderException03() { String msg = null; ProviderException tE = new ProviderException(msg); @@ -91,6 +123,15 @@ public class ProviderExceptionTest extends TestCase { * Test for <code>ProviderException(Throwable)</code> constructor * Assertion: constructs ProviderException when <code>cause</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {Throwable.class} + ) + }) public void testProviderException04() { Throwable cause = null; ProviderException tE = new ProviderException(cause); @@ -103,6 +144,15 @@ public class ProviderExceptionTest extends TestCase { * Assertion: constructs ProviderException when <code>cause</code> is not * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {Throwable.class} + ) + }) public void testProviderException05() { ProviderException tE = new ProviderException(tCause); if (tE.getMessage() != null) { @@ -121,6 +171,15 @@ public class ProviderExceptionTest extends TestCase { * Assertion: constructs ProviderException when <code>cause</code> is null * <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testProviderException06() { ProviderException tE = new ProviderException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -132,6 +191,15 @@ public class ProviderExceptionTest extends TestCase { * Assertion: constructs ProviderException when <code>cause</code> is null * <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testProviderException07() { ProviderException tE; for (int i = 0; i < msgs.length; i++) { @@ -147,6 +215,15 @@ public class ProviderExceptionTest extends TestCase { * Assertion: constructs ProviderException when <code>cause</code> is not * null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testProviderException08() { ProviderException tE = new ProviderException(null, tCause); if (tE.getMessage() != null) { @@ -165,6 +242,15 @@ public class ProviderExceptionTest extends TestCase { * Assertion: constructs ProviderException when <code>cause</code> is not * null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ProviderException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testProviderException09() { ProviderException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java index 4ec9c30..a772ee7 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderServiceTest.java @@ -22,20 +22,35 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.Provider; +import java.security.Provider.Service; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import org.apache.harmony.security.tests.support.RandomImpl; import junit.framework.TestCase; - +@TestTargetClass(Service.class) /** * Tests for <code>Provider.Service</code> constructor and methods * */ public class ProviderServiceTest extends TestCase { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Service", + methodArgs = {Provider.class, String.class, String.class, String.class, java.util.List.class, java.util.Map.class} + ) + }) public void testService() { Provider p = new MyProvider(); try { @@ -80,6 +95,15 @@ public class ProviderServiceTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAttribute", + methodArgs = {String.class} + ) + }) public void testGetAttribute() { Provider p = new MyProvider(); Provider.Service s = new Provider.Service(p, "type", "algorithm", @@ -111,6 +135,15 @@ public class ProviderServiceTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException checking missed", + targets = { + @TestTarget( + methodName = "newInstance", + methodArgs = {Object.class} + ) + }) public void testNewInstance() { Provider p = new MyProvider(); Provider.Service s = new Provider.Service(p, "SecureRandom", @@ -134,6 +167,15 @@ public class ProviderServiceTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void testGetAlgorithm() { Provider p = new MyProvider(); Provider.Service s1 = new Provider.Service(p, "type", "algorithm", @@ -146,6 +188,15 @@ public class ProviderServiceTest extends TestCase { assertTrue(s2.getAlgorithm().equals("algorithm")); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getClassName", + methodArgs = {} + ) + }) public void testGetClassName() { Provider p = new MyProvider(); Provider.Service s1 = new Provider.Service(p, "type", "algorithm", @@ -158,6 +209,15 @@ public class ProviderServiceTest extends TestCase { assertTrue(s2.getClassName().equals("tests.java.security.support.RandomImpl")); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void testGetProvider() { Provider p = new MyProvider(); Provider.Service s1 = new Provider.Service(p, "type", "algorithm", @@ -170,6 +230,15 @@ public class ProviderServiceTest extends TestCase { assertTrue(s2.getProvider() == p); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) public void testGetType() { Provider p = new MyProvider(); Provider.Service s1 = new Provider.Service(p, "type", "algorithm", @@ -182,6 +251,15 @@ public class ProviderServiceTest extends TestCase { assertTrue(s2.getType().equals("SecureRandom")); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException checking missed", + targets = { + @TestTarget( + methodName = "supportsParameter", + methodArgs = {Object.class} + ) + }) public void testSupportsParameter() { Provider p = new MyProvider(); Provider.Service s1 = new Provider.Service(p, "type", "algorithm", @@ -190,7 +268,16 @@ public class ProviderServiceTest extends TestCase { assertTrue(s1.supportsParameter(new Object())); } - public void testToString() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public void _testToString() { Provider p = new MyProvider(); Provider.Service s1 = new Provider.Service(p, "type", "algorithm", "className", null, null); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderTest.java index 827d2ba..f4bafe8 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/ProviderTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -39,7 +44,7 @@ import java.util.Map.Entry; import junit.framework.TestCase; - +@TestTargetClass(Provider.class) /** * Tests for <code>Provider</code> constructor and methods * @@ -59,6 +64,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void Provider() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies provider object", + targets = { + @TestTarget( + methodName = "Provider", + methodArgs = {String.class, double.class, String.class} + ) + }) public final void testProvider() { if (!p.getProperty("Provider.id name").equals( String.valueOf(p.getName()))) { @@ -78,6 +92,15 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "clear", + methodArgs = {} + ) + }) public final void testClear() { p.clear(); if (p.getProperty("MessageDigest.SHA-1") != null) { @@ -88,6 +111,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void Provider(String, double, String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies constructor with non null parameters", + targets = { + @TestTarget( + methodName = "Provider", + methodArgs = {String.class, double.class, String.class} + ) + }) public final void testProviderStringdoubleString() { Provider p = new MyProvider("Provider name", 123.456, "Provider info"); if (!p.getName().equals("Provider name") || p.getVersion() != 123.456 @@ -96,18 +128,45 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public final void testGetName() { if (!p.getName().equals("MyProvider")) { fail("Incorrect provider name"); } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getVersion", + methodArgs = {} + ) + }) public final void testGetVersion() { if (p.getVersion() != 1.0) { fail("Incorrect provider version"); } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInfo", + methodArgs = {} + ) + }) public final void testGetInfo() { if (!p.getInfo().equals("Provider for testing")) { fail("Incorrect provider info"); @@ -117,6 +176,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void putAll(Map) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "putAll", + methodArgs = {java.util.Map.class} + ) + }) public final void testPutAllMap() { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd"); @@ -138,6 +206,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Set entrySet() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "entrySet", + methodArgs = {} + ) + }) public final void testEntrySet() { p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd"); @@ -190,6 +267,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Set keySet() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "keySet", + methodArgs = {} + ) + }) public final void testKeySet() { p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd"); @@ -220,6 +306,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Collection values() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "values", + methodArgs = {} + ) + }) public final void testValues() { p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd"); @@ -246,6 +341,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Object put(Object, Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "put", + methodArgs = {Object.class, Object.class} + ) + }) public final void testPutObjectObject() { p.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd"); p.put("Type.Algorithm", "className"); @@ -282,6 +386,16 @@ public class ProviderTest extends TestCase { /* * Class under test for Object remove(Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed." + + "Verification with null parameter missed", + targets = { + @TestTarget( + methodName = "remove", + methodArgs = {Object.class} + ) + }) public final void testRemoveObject() { Object o = p.remove("MessageDigest.SHA-1"); if (!"SomeClassName".equals(o)) { @@ -295,6 +409,15 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException checking missed", + targets = { + @TestTarget( + methodName = "getService", + methodArgs = {String.class, String.class} + ) + }) public final void testService1() { p.put("MessageDigest.SHA-1", "AnotherClassName"); Provider.Service s = p.getService("MessageDigest", "SHA-1"); @@ -327,6 +450,15 @@ public class ProviderTest extends TestCase { // } // Regression for HARMONY-2760. + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test: verifies constructor with two null parameters.", + targets = { + @TestTarget( + methodName = "Provider", + methodArgs = {String.class, double.class, String.class} + ) + }) public void testConstructor() { MyProvider myProvider = new MyProvider(null, 1, null); assertNull(myProvider.getName()); @@ -335,6 +467,15 @@ public class ProviderTest extends TestCase { assertEquals("null", myProvider.getProperty("Provider.id info")); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test: method was used for special provider object", + targets = { + @TestTarget( + methodName = "getServices", + methodArgs = {} + ) + }) public final void testGetServices() { MyProvider myProvider = new MyProvider(null, 1, null); Set<Provider.Service> services = myProvider.getServices(); @@ -373,6 +514,15 @@ public class ProviderTest extends TestCase { assertTrue(actual.contains(s[2])); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test: method was used for special provider object", + targets = { + @TestTarget( + methodName = "putService", + methodArgs = {Provider.Service.class} + ) + }) public final void testPutService() { MyProvider myProvider = new MyProvider(null, 1, null); Provider.Service s[] = new Provider.Service[3]; @@ -422,6 +572,15 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test: method was used for special provider object", + targets = { + @TestTarget( + methodName = "removeService", + methodArgs = {Provider.Service.class} + ) + }) public final void testRemoveService() { MyProvider myProvider = new MyProvider(null, 1, null); try { @@ -491,6 +650,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void load(InputStream) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed", + targets = { + @TestTarget( + methodName = "load", + methodArgs = {InputStream.class} + ) + }) public final void testLoad() throws IOException { InputStream is = new ByteArrayInputStream(writeProperties()); MyProvider myProvider = new MyProvider("name", 1, "info"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java index 8fc2342..16a60ce 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/PublicKeyTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.PublicKey; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import java.security.PublicKey; +import junit.framework.TestCase; +@TestTargetClass(PublicKey.class) /** * Tests for <code>PublicKey</code> class field * @@ -46,6 +51,15 @@ public class PublicKeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Field testing", + targets = { + @TestTarget( + methodName = "serialVersionUID", + methodArgs = {} + ) + }) public void testField() { checkPublicKey cPK = new checkPublicKey(); assertEquals("Incorrect serialVersionUID", cPK.getSerVerUID(), //PublicKey.serialVersionUID, diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java index 0fb46c9..6cc449a 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -28,12 +33,22 @@ import java.security.cert.Certificate; import java.util.Enumeration; import java.util.jar.JarFile; +@TestTargetClass(SecureClassLoader.class) public class SecureClassLoader2Test extends junit.framework.TestCase { /** * @tests java.security.SecureClassLoader#getPermissions(java.security.CodeSource) */ - public void test_getPermissionsLjava_security_CodeSource() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null parameter missed", + targets = { + @TestTarget( + methodName = "getPermissions", + methodArgs = {CodeSource.class} + ) + }) + public void _test_getPermissionsLjava_security_CodeSource() { class MyClassLoader extends SecureClassLoader { public PermissionCollection getPerms() { return super.getPermissions(new CodeSource(null, diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java index cace494..7b35872 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.Provider; @@ -25,7 +30,7 @@ import java.security.SecureRandomSpi; import java.security.Security; import junit.framework.TestCase; - +@TestTargetClass(SecureRandom.class) public class SecureRandom2Test extends TestCase { private static final byte[] SEED_BYTES = { (byte) 33, (byte) 15, (byte) -3, @@ -35,6 +40,15 @@ public class SecureRandom2Test extends TestCase { private static final long SEED_VALUE = 5335486759L; + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void testGetProvider() { SecureRandom sr1 = new SecureRandom(); assertNotNull(sr1.getProvider()); @@ -57,6 +71,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#SecureRandom() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecureRandom", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.SecureRandom() try { @@ -69,6 +92,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#SecureRandom(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array checking missed", + targets = { + @TestTarget( + methodName = "SecureRandom", + methodArgs = {byte[].class} + ) + }) public void test_Constructor$B() { // Test for method java.security.SecureRandom(byte []) try { @@ -82,6 +114,15 @@ public class SecureRandom2Test extends TestCase { * @tests java.security.SecureRandom#SecureRandom(java.security.SecureRandomSpi, * java.security.Provider) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification when just one parameter is null missed", + targets = { + @TestTarget( + methodName = "SecureRandom", + methodArgs = {SecureRandomSpi.class, Provider.class} + ) + }) public void test_ConstructorLjava_security_SecureRandomSpi_java_security_Provider() { try { new MySecureRandom(null, null); @@ -103,6 +144,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#generateSeed(int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with negative parameter missed", + targets = { + @TestTarget( + methodName = "generateSeed", + methodArgs = {int.class} + ) + }) public void test_generateSeedI() { // Test for method byte [] java.security.SecureRandom.generateSeed(int) byte[] seed = new SecureRandom().generateSeed(SEED_SIZE); @@ -112,6 +162,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() { // Test for method java.security.SecureRandom // java.security.SecureRandom.getInstance(java.lang.String) @@ -126,6 +185,15 @@ public class SecureRandom2Test extends TestCase { * @tests java.security.SecureRandom#getInstance(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() { // Test for method java.security.SecureRandom // java.security.SecureRandom.getInstance(java.lang.String, @@ -151,6 +219,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#getSeed(int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of negative parameter missed", + targets = { + @TestTarget( + methodName = "getSeed", + methodArgs = {int.class} + ) + }) public void test_getSeedI() { // Test for method byte [] java.security.SecureRandom.getSeed(int) byte[] seed = SecureRandom.getSeed(SEED_SIZE); @@ -160,6 +237,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#nextBytes(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array checking missed", + targets = { + @TestTarget( + methodName = "nextBytes", + methodArgs = {byte[].class} + ) + }) public void test_nextBytes$B() { // Test for method void java.security.SecureRandom.nextBytes(byte []) byte[] bytes = new byte[313]; @@ -173,6 +259,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#setSeed(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array checking missed", + targets = { + @TestTarget( + methodName = "setSeed", + methodArgs = {byte[].class} + ) + }) public void test_setSeed$B() { // Test for method void java.security.SecureRandom.setSeed(byte []) try { @@ -185,6 +280,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#setSeed(long) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of negative and boundary values missed", + targets = { + @TestTarget( + methodName = "setSeed", + methodArgs = {long.class} + ) + }) public void test_setSeedJ() { // Test for method void java.security.SecureRandom.setSeed(long) try { @@ -197,6 +301,15 @@ public class SecureRandom2Test extends TestCase { /** * @tests java.security.SecureRandom#getAlgorithm() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just verification of case when algorithm name cannot be determined", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() { // Regression for HARMONY-750 @@ -220,6 +333,15 @@ public class SecureRandom2Test extends TestCase { } // Regression Test for HARMONY-3552. + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of boundary values (MAX and MIN values) missed", + targets = { + @TestTarget( + methodName = "next", + methodArgs = {int.class} + ) + }) public void test_nextJ() throws Exception { MySecureRandom mySecureRandom = new MySecureRandom( new MySecureRandomSpi(), null); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java index 954ff6e..d6083a6 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.InvalidParameterException; import java.security.Provider; import java.security.Security; @@ -28,12 +33,21 @@ import java.util.Set; import tests.support.Support_ProviderTrust; import tests.support.Support_TestProvider; - +@TestTargetClass(Security.class) public class Security2Test extends junit.framework.TestCase { /** * @tests java.security.Security#getProviders(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException checking missed", + targets = { + @TestTarget( + methodName = "getProviders", + methodArgs = {String.class} + ) + }) public void test_getProvidersLjava_lang_String() { // Test for method void // java.security.Security.getProviders(java.lang.String) @@ -209,6 +223,15 @@ public class Security2Test extends junit.framework.TestCase { /** * @tests java.security.Security#getProviders(java.util.Map) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException checking missed", + targets = { + @TestTarget( + methodName = "getProviders", + methodArgs = {Map.class} + ) + }) public void test_getProvidersLjava_util_Map() { // Test for method void // java.security.Security.getProviders(java.util.Map) @@ -294,6 +317,15 @@ public class Security2Test extends junit.framework.TestCase { /** * @tests java.security.Security#removeProvider(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "removeProvider", + methodArgs = {String.class} + ) + }) public void test_removeProviderLjava_lang_String() { // Test for method void // java.security.Security.removeProvider(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java index defc4dc..d45701c 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermission2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.SecurityPermission; +@TestTargetClass(SecurityPermission.class) public class SecurityPermission2Test extends junit.framework.TestCase { /** * @tests java.security.SecurityPermission#SecurityPermission(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with valid parameter only", + targets = { + @TestTarget( + methodName = "SecurityPermission", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.SecurityPermission(java.lang.String) assertEquals("create securityPermission constructor(string) failed", @@ -36,6 +51,15 @@ public class SecurityPermission2Test extends junit.framework.TestCase { * @tests java.security.SecurityPermission#SecurityPermission(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with valid parameters only", + targets = { + @TestTarget( + methodName = "SecurityPermission", + methodArgs = {String.class, String.class} + ) + }) public void test_ConstructorLjava_lang_StringLjava_lang_String() { // Test for method java.security.SecurityPermission(java.lang.String, // java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java index 2c9b2bf..0d52684 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityPermissionTest.java @@ -22,10 +22,15 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.SecurityPermission; import junit.framework.TestCase; - +@TestTargetClass(SecurityPermission.class) /** * Tests for <code>SecurityPermission</code> * @@ -50,6 +55,19 @@ public class SecurityPermissionTest extends TestCase { * If name is empty then IAE should be thrown. * Action is ignored. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecurityPermission", + methodArgs = {String.class} + ), + @TestTarget( + methodName = "SecurityPermission", + methodArgs = {String.class, String.class} + ) + }) public void testCtor() { String name = "basic123*$%#"; diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityTest.java index c56b9ec..579adde 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SecurityTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.InvalidParameterException; import java.security.KeyFactory; import java.security.MessageDigest; @@ -38,12 +43,21 @@ import org.apache.harmony.security.tests.support.TestKeyPair; import junit.framework.TestCase; - +@TestTargetClass(Security.class) /** * Tests for <code>Security</code> constructor and methods */ public class SecurityTest extends TestCase { + @TestInfo( + level = TestLevel.TODO, + purpose = "Methods from java.security.Security class are not tested", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) public final void testMixed() { TestKeyPair tkp = null; @@ -69,6 +83,15 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#insertProviderAt(Provider, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "insertProviderAt", + methodArgs = {Provider.class, int.class} + ) + }) public final void test_insertProviderAtLjava_security_ProviderLI() { try { @@ -113,7 +136,16 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#addProvider(Provider) */ - public final void test_addProviderLjava_security_Provider() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "addProvider", + methodArgs = {Provider.class} + ) + }) + public final void _test_addProviderLjava_security_Provider() { try { Security.addProvider(null); @@ -141,8 +173,17 @@ public class SecurityTest extends TestCase { * @tests java.security.Security#getAlgorithmProperty(String algName, * String propName) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null parameters missed", + targets = { + @TestTarget( + methodName = "getAlgorithmProperty", + methodArgs = {String.class, String.class} + ) + }) @SuppressWarnings("deprecation") - public final void testGetAlgorithmPropertyLjava_lang_String_java_lang_String() { + public final void _testGetAlgorithmPropertyLjava_lang_String_java_lang_String() { String propName = null; Provider provider = new MyProvider(); @@ -163,7 +204,16 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#getAlgorithms(String serviceName) */ - public final void testGetAlgorithmsLjava_lang_String() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Not supported serviceName checking missed", + targets = { + @TestTarget( + methodName = "getAlgorithms", + methodArgs = {String.class} + ) + }) + public final void _testGetAlgorithmsLjava_lang_String() { String[] servicesNames = { "Signature", "MessageDigest", "Cipher", "Mac", "KeyStore" }; @@ -187,6 +237,15 @@ public class SecurityTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Incorrect parameter checking missed", + targets = { + @TestTarget( + methodName = "removeProvider", + methodArgs = {String.class} + ) + }) public final void testRemoveProvider() { Provider[] providers; Provider[] providers1; @@ -216,6 +275,15 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#getProvider(String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {String.class} + ) + }) public final void test_getProviderLjava_lang_String() { // Returns null if no provider with the specified name is installed @@ -247,6 +315,15 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#getProviders(String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProviders", + methodArgs = {String.class} + ) + }) public void test_getProvidersLjava_lang_String() { try { @@ -301,6 +378,15 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#getProviders(java.util.Map) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProviders", + methodArgs = {Map.class} + ) + }) public void test_getProvidersLjava_util_Map() { Map<String, String> m = new HashMap<String, String>(); @@ -373,6 +459,15 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#getProperty(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of null parameter only.", + targets = { + @TestTarget( + methodName = "getProperty", + methodArgs = {String.class} + ) + }) public void test_getPropertyLjava_lang_String() { try { @@ -385,6 +480,15 @@ public class SecurityTest extends TestCase { /** * @tests java.security.Security#setProperty(String,String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "setProperty", + methodArgs = {String.class, String.class} + ) + }) public void test_setPropertyLjava_lang_StringLjava_lang_String() { try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java index 3887257..a850059 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.math.BigInteger; import java.nio.ByteBuffer; import java.security.InvalidParameterException; @@ -31,7 +36,7 @@ import java.security.spec.DSAParameterSpec; import java.util.HashSet; import java.util.Set; - +@TestTargetClass(Signature.class) public class Signature2Test extends junit.framework.TestCase { private static final String MESSAGE = "abc"; @@ -50,6 +55,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#clone() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "CloneNotSupportedException checking was tested", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) public void test_clone() throws Exception { Signature s = Signature.getInstance("DSA"); try { @@ -63,6 +77,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#getAlgorithm() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void test_getAlgorithm() throws Exception { String alg = Signature.getInstance("DSA").getAlgorithm(); assertTrue("getAlgorithm did not get DSA (" + alg + ")", alg @@ -72,6 +95,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#getInstance(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public void test_getInstanceLjava_lang_String() throws Exception { Signature.getInstance("DSA"); } @@ -80,6 +112,15 @@ public class Signature2Test extends junit.framework.TestCase { * @tests java.security.Signature#getInstance(java.lang.String, * java.security.Provider) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider() throws Exception { Provider[] providers = Security.getProviders("Signature.DSA"); @@ -116,6 +157,15 @@ public class Signature2Test extends junit.framework.TestCase { * @tests java.security.Signature#getInstance(java.lang.String, * java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception { Provider[] providers = Security.getProviders("Signature.DSA"); @@ -128,6 +178,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#getParameters() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just exception case was tested", + targets = { + @TestTarget( + methodName = "getParameters", + methodArgs = {} + ) + }) public void test_getParameters() throws Exception { Signature sig = Signature.getInstance("DSA"); try { @@ -140,6 +199,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#getParameter(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just exception case was tested", + targets = { + @TestTarget( + methodName = "getParameter", + methodArgs = {String.class} + ) + }) @SuppressWarnings("deprecation") public void test_getParameterLjava_lang_String() throws Exception { Signature sig = Signature.getInstance("DSA"); @@ -154,6 +222,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#getProvider() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void test_getProvider() throws Exception { Provider p = Signature.getInstance("DSA").getProvider(); assertNotNull("provider is null", p); @@ -162,6 +239,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#initSign(java.security.PrivateKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initSign", + methodArgs = {java.security.PrivateKey.class} + ) + }) public void test_initSignLjava_security_PrivateKey() throws Exception { Signature.getInstance("DSA").initSign(keys.getPrivate()); } @@ -169,6 +255,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#initVerify(java.security.PublicKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initSign", + methodArgs = {java.security.PrivateKey.class} + ) + }) public void test_initVerifyLjava_security_PublicKey() throws Exception { Signature.getInstance("DSA").initVerify(keys.getPublic()); } @@ -176,6 +271,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#initVerify(java.security.cert.Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initVerify", + methodArgs = {Certificate.class} + ) + }) public void test_initVerifyLjava_security_Certificate() throws Exception { Provider p = new MyProvider(); p.put("DSA", "tests.java.security.support.cert.MyCertificate$1"); @@ -200,6 +304,15 @@ public class Signature2Test extends junit.framework.TestCase { * @tests java.security.Signature#setParameter(java.lang.String, * java.lang.Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just exception case was tested", + targets = { + @TestTarget( + methodName = "setParameter", + methodArgs = {String.class, Object.class} + ) + }) @SuppressWarnings("deprecation") public void test_setParameterLjava_lang_StringLjava_lang_Object() throws Exception { @@ -218,6 +331,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just exception case was tested", + targets = { + @TestTarget( + methodName = "setParameter", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class} + ) + }) public void test_setParameterLjava_security_spec_AlgorithmParameterSpec() throws Exception { Signature sig = Signature.getInstance("DSA"); @@ -236,6 +358,16 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#sign() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned value missed. " + + "SignatureException checking missed.", + targets = { + @TestTarget( + methodName = "sign", + methodArgs = {} + ) + }) public void test_sign() throws Exception { Signature sig = Signature.getInstance("DSA"); sig.initSign(keys.getPrivate()); @@ -246,6 +378,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() throws Exception { String str = Signature.getInstance("DSA").toString(); assertNotNull("toString is null", str); @@ -254,6 +395,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#update(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SignatureException checking missed", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class} + ) + }) public void test_update$B() throws Exception { Signature sig = Signature.getInstance("DSA"); sig.initSign(keys.getPrivate()); @@ -265,6 +415,16 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#update(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SignatureException checking missed. " + + "Verification of different values off and len missed.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_update$BII() throws Exception { Signature sig = Signature.getInstance("DSA"); sig.initSign(keys.getPrivate()); @@ -276,6 +436,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#update(byte) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SignatureException checking missed", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte.class} + ) + }) public void test_updateB() throws Exception { Signature sig = Signature.getInstance("DSA"); sig.initSign(keys.getPrivate()); @@ -286,6 +455,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#update(ByteBuffer data) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {ByteBuffer.class} + ) + }) public void test_updateLjava_nio_ByteBuffer() throws Exception { Signature sig = Signature.getInstance("DSA"); ByteBuffer buffer = ByteBuffer.allocate(10); @@ -308,6 +486,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#verify(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SignatureException checking missed", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {byte[].class} + ) + }) public void test_verify$B() throws Exception { Signature sig = Signature.getInstance("DSA"); sig.initSign(keys.getPrivate()); @@ -322,6 +509,15 @@ public class Signature2Test extends junit.framework.TestCase { /** * @tests java.security.Signature#verify(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of different values offset and length missed.", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void test_verify$BII() throws Exception { Signature sig = Signature.getInstance("DSA"); sig.initSign(keys.getPrivate()); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureException2Test.java index 4df1af0..ca0779d 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.SignatureException; +@TestTargetClass(SignatureException.class) public class SignatureException2Test extends junit.framework.TestCase { /** * @tests java.security.SignatureException#SignatureException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.SignatureException() SignatureException e = new SignatureException(); @@ -34,6 +49,15 @@ public class SignatureException2Test extends junit.framework.TestCase { /** * @tests java.security.SignatureException#SignatureException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null string parameter missed", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method java.security.SignatureException(java.lang.String) SignatureException e = new SignatureException("test message"); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java index 70b2754..de65c27 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.SignatureException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import java.security.SignatureException; +import junit.framework.TestCase; +@TestTargetClass(SignatureException.class) /** * Tests for <code>SignatureException</code> class constructors and methods. * @@ -55,6 +60,15 @@ public class SignatureExceptionTest extends TestCase { * Test for <code>SignatureException()</code> constructor Assertion: * constructs SignatureException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {} + ) + }) public void testSignatureException01() { SignatureException tE = new SignatureException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -66,6 +80,15 @@ public class SignatureExceptionTest extends TestCase { * constructs SignatureException with detail message msg. Parameter * <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class} + ) + }) public void testSignatureException02() { SignatureException tE; for (int i = 0; i < msgs.length; i++) { @@ -80,6 +103,15 @@ public class SignatureExceptionTest extends TestCase { * Test for <code>SignatureException(String)</code> constructor Assertion: * constructs SignatureException when <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class} + ) + }) public void testSignatureException03() { String msg = null; SignatureException tE = new SignatureException(msg); @@ -92,6 +124,15 @@ public class SignatureExceptionTest extends TestCase { * Assertion: constructs SignatureException when <code>cause</code> is * null */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {Throwable.class} + ) + }) public void testSignatureException04() { Throwable cause = null; SignatureException tE = new SignatureException(cause); @@ -104,6 +145,15 @@ public class SignatureExceptionTest extends TestCase { * Assertion: constructs SignatureException when <code>cause</code> is not * null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {Throwable.class} + ) + }) public void testSignatureException05() { SignatureException tE = new SignatureException(tCause); if (tE.getMessage() != null) { @@ -122,6 +172,15 @@ public class SignatureExceptionTest extends TestCase { * Assertion: constructs SignatureException when <code>cause</code> is * null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testSignatureException06() { SignatureException tE = new SignatureException(null, null); assertNull("getMessage() must return null", tE.getMessage()); @@ -133,6 +192,15 @@ public class SignatureExceptionTest extends TestCase { * Assertion: constructs SignatureException when <code>cause</code> is * null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testSignatureException07() { SignatureException tE; for (int i = 0; i < msgs.length; i++) { @@ -148,6 +216,15 @@ public class SignatureExceptionTest extends TestCase { * Assertion: constructs SignatureException when <code>cause</code> is not * null <code>msg</code> is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testSignatureException08() { SignatureException tE = new SignatureException(null, tCause); if (tE.getMessage() != null) { @@ -166,6 +243,15 @@ public class SignatureExceptionTest extends TestCase { * Assertion: constructs SignatureException when <code>cause</code> is not * null <code>msg</code> is not null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "SignatureException", + methodArgs = {String.class, Throwable.class} + ) + }) public void testSignatureException09() { SignatureException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureSpiTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureSpiTest.java index 418f5d1..cadc508 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureSpiTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureSpiTest.java @@ -1,11 +1,16 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.PrivateKey; import java.security.PublicKey; import java.security.SignatureSpi; import junit.framework.TestCase; - +@TestTargetClass(SignatureSpi.class) public class SignatureSpiTest extends TestCase { protected void setUp() throws Exception { @@ -16,6 +21,15 @@ public class SignatureSpiTest extends TestCase { super.tearDown(); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) public void testClone() { MySignatureSpi1 ss1 = new MySignatureSpi1(); try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureTest.java index c1eabf4..5b9af93 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignatureTest.java @@ -22,6 +22,12 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + +import java.security.Signature; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; @@ -33,7 +39,7 @@ import java.security.SignatureException; import org.apache.harmony.security.tests.support.MySignature1; import junit.framework.TestCase; - +@TestTargetClass(Signature.class) /** * Tests for <code>Signature</code> constructor and methods * @@ -43,6 +49,15 @@ public class SignatureTest extends TestCase { /* * Class under test for Signature(String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Signature", + methodArgs = {String.class} + ) + }) public void testConstructor() { String [] algorithms = { "SHA256WITHRSA", "NONEWITHDSA", "SHA384WITHRSA", "MD2WITHRSA", "MD5ANDSHA1WITHRSA", "SHA512WITHRSA", @@ -68,6 +83,15 @@ public class SignatureTest extends TestCase { /* * Class under test for Object clone() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just exception case was tested", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) public void testClone() { MySignature1 s = new MySignature1("ABC"); try { @@ -77,6 +101,15 @@ public class SignatureTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void testGetProvider() { MySignature1 s = new MySignature1("ABC"); @@ -84,6 +117,15 @@ public class SignatureTest extends TestCase { assertNull("provider", s.getProvider()); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void testGetAlgorithm() { MySignature1 s = new MySignature1("ABC"); @@ -94,6 +136,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initVerify(PublicKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initVerify", + methodArgs = {PublicKey.class} + ) + }) public void testInitVerifyPublicKey() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -105,6 +156,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initVerify(Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initVerify", + methodArgs = {java.security.cert.Certificate.class} + ) + }) public void testInitVerifyCertificate() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -116,6 +176,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initSign(PrivateKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initSign", + methodArgs = {PrivateKey.class} + ) + }) public void testInitSignPrivateKey() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -127,6 +196,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initSign(PrivateKey, SecureRandom) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initSign", + methodArgs = {PrivateKey.class, SecureRandom.class} + ) + }) public void testInitSignPrivateKeySecureRandom() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -138,6 +216,15 @@ public class SignatureTest extends TestCase { /* * Class under test for byte[] sign() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned value missed", + targets = { + @TestTarget( + methodName = "sign", + methodArgs = {} + ) + }) public void testSign() throws Exception { MySignature1 s = new MySignature1("ABC"); try { @@ -163,6 +250,15 @@ public class SignatureTest extends TestCase { /* * Class under test for sign(byte[], offset, len) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with different values of offset and len missed", + targets = { + @TestTarget( + methodName = "sign", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void testSignbyteintint() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] outbuf = new byte [10]; @@ -190,6 +286,15 @@ public class SignatureTest extends TestCase { /* * Class under test for boolean verify(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned value missed", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {byte[].class} + ) + }) public void testVerifybyteArray() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -215,6 +320,16 @@ public class SignatureTest extends TestCase { /* * Class under test for boolean verify(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned value missed. " + + "Verification of different parameters offset and length missed.", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void testVerifybyteArrayintint() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -248,6 +363,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void update(byte) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Boundary testing missed. SignatureException checking missed.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte.class} + ) + }) public void testUpdatebyte() throws Exception { MySignature1 s = new MySignature1("ABC"); try { @@ -268,6 +392,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void update(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array/exception checking missed.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class} + ) + }) public void testUpdatebyteArray() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -289,6 +422,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void update(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of different values off and len missed", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void testUpdatebyteArrayintint() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -310,6 +452,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void setParameter(String, Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException checking missed", + targets = { + @TestTarget( + methodName = "setParameter", + methodArgs = {String.class, Object.class} + ) + }) @SuppressWarnings("deprecation") public void testSetParameterStringObject() { MySignature1 s = new MySignature1("ABC"); @@ -319,6 +470,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void setParameter(AlgorithmParameterSpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with valid parameter missed", + targets = { + @TestTarget( + methodName = "setParameter", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class} + ) + }) public void testSetParameterAlgorithmParameterSpec() throws InvalidAlgorithmParameterException { MySignature1 s = new MySignature1("ABC"); try { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java index 74df871..c2c7351 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignedObjectTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -33,14 +39,22 @@ import java.util.Properties; import org.apache.harmony.security.tests.support.TestKeyPair; import junit.framework.TestCase; - - +@TestTargetClass(SignedObject.class) /** * Tests for <code>SignedObject</code> constructor and methods * */ public class SignedObjectTest extends TestCase { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException, InvalidKeyException, SignatureException checking missed", + targets = { + @TestTarget( + methodName = "SignedObject", + methodArgs = {java.io.Serializable.class, java.security.PrivateKey.class, Signature.class} + ) + }) public void testSignedObject() { Signature sig = null; TestKeyPair tkp = null; diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignerTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignerTest.java index 685dd78..a7d79c7 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/SignerTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/SignerTest.java @@ -21,6 +21,12 @@ */ package org.apache.harmony.security.tests.java.security; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.IdentityScope; import java.security.KeyPair; import java.security.Permission; @@ -35,13 +41,12 @@ import org.apache.harmony.security.tests.support.SignerStub; import junit.framework.TestCase; - - /** * tests for class Signer * */ @SuppressWarnings("deprecation") +@TestTargetClass(Signer.class) public class SignerTest extends TestCase { public static class MySecurityManager extends SecurityManager { @@ -66,6 +71,15 @@ public class SignerTest extends TestCase { /** * @tests java.security.Signer#toString() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void test_toString() throws Exception { Signer s1 = new SignerStub("testToString1"); assertEquals("[Signer]testToString1", s1.toString()); @@ -84,6 +98,15 @@ public class SignerTest extends TestCase { /** * verify Signer() creates instance */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Signer", + methodArgs = {} + ) + }) public void testSigner() { Signer s = new SignerStub(); assertNotNull(s); @@ -94,6 +117,15 @@ public class SignerTest extends TestCase { /** * verify Signer(String) creates instance */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null/empty parameter missed", + targets = { + @TestTarget( + methodName = "Signer", + methodArgs = {String.class} + ) + }) public void testSignerString() throws Exception { Signer s = new SignerStub("sss3"); assertNotNull(s); @@ -104,6 +136,16 @@ public class SignerTest extends TestCase { /** * verify Signer(String, IdentityScope) creates instance */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "1. Verification with null/empty parameter missed. " + + "2. KeyManagementException checking missed.", + targets = { + @TestTarget( + methodName = "Signer", + methodArgs = {String.class, IdentityScope.class} + ) + }) public void testSignerStringIdentityScope() throws Exception { Signer s = new SignerStub("sss4", IdentityScope.getSystemScope()); assertNotNull(s); @@ -115,6 +157,15 @@ public class SignerTest extends TestCase { /** * verify Signer.getPrivateKey() returns null or private key */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateKey", + methodArgs = {} + ) + }) public void testGetPrivateKey() throws Exception { byte [] privateKeyData = { 1, 2, 3, 4, 5}; PrivateKeyStub privateKey = new PrivateKeyStub("private", "fff", privateKeyData); @@ -132,6 +183,15 @@ public class SignerTest extends TestCase { /** * verify Signer.getPrivateKey() throws SecurityException if permission is denied */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateKey", + methodArgs = {} + ) + }) public void testGetPrivateKey_denied() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("getSignerPrivateKey")); @@ -152,6 +212,15 @@ public class SignerTest extends TestCase { /** * @tests java.security.Signer#setKeyPair(java.security.KeyPair) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException, KeyException checking missed", + targets = { + @TestTarget( + methodName = "setKeyPair", + methodArgs = {KeyPair.class} + ) + }) public void test_setKeyPairLjava_security_KeyPair() throws Exception { // Regression for HARMONY-2408 diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/TimestampTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/TimestampTest.java index c3d684e..8aa7ed7 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/TimestampTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/TimestampTest.java @@ -22,6 +22,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.Timestamp; import java.security.cert.CertPath; import java.util.Date; @@ -29,7 +34,7 @@ import java.util.Date; import org.apache.harmony.security.tests.support.cert.MyCertPath; import junit.framework.TestCase; - +@TestTargetClass(Timestamp.class) /** * Tests for <code>Timestamp</code> class fields and methods * @@ -47,6 +52,15 @@ public class TimestampTest extends TestCase { private CertPath cpath = new MyCertPath(encoding); + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Non null parameters checking missed", + targets = { + @TestTarget( + methodName = "Timestamp", + methodArgs = {Date.class, CertPath.class} + ) + }) public void testTimestamp() { try { new Timestamp(null, cpath); @@ -65,6 +79,15 @@ public class TimestampTest extends TestCase { /* * Class under test for boolean equals(Object) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEqualsObject() { Timestamp one = new Timestamp(now, cpath); Timestamp two = new Timestamp(now, cpath); @@ -80,10 +103,28 @@ public class TimestampTest extends TestCase { assertTrue(two1.equals(two1)); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSignerCertPath", + methodArgs = {} + ) + }) public void testGetSignerCertPath() { assertSame(new Timestamp(now, cpath).getSignerCertPath(), cpath); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getTimestamp", + methodArgs = {} + ) + }) public void testGetTimestamp() { Timestamp t = new Timestamp(now, cpath); assertEquals(now, t.getTimestamp()); @@ -93,6 +134,15 @@ public class TimestampTest extends TestCase { /* * Class under test for String toString() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test result is not verivied", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { new Timestamp(now, cpath).toString(); } @@ -100,6 +150,15 @@ public class TimestampTest extends TestCase { /* * Class under test for String hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode() { Timestamp one = new Timestamp(now, cpath); Timestamp two = new Timestamp(now, cpath); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java index c18c964..9798b25 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableEntryExceptionTest.java @@ -22,10 +22,15 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.UnrecoverableEntryException; import junit.framework.TestCase; - +@TestTargetClass( UnrecoverableEntryException.class) /** * Tests for <code>UnrecoverableEntryException</code> class * @@ -52,6 +57,15 @@ public class UnrecoverableEntryExceptionTest extends TestCase { /* * Class under test for void UnrecoverableEntryException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "UnrecoverableEntryException", + methodArgs = {} + ) + }) public void testUnrecoverableEntryException() { UnrecoverableEntryException tE = new UnrecoverableEntryException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -61,6 +75,15 @@ public class UnrecoverableEntryExceptionTest extends TestCase { /* * Class under test for void UnrecoverableEntryException(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null string parameter missed", + targets = { + @TestTarget( + methodName = "UnrecoverableEntryException", + methodArgs = {String.class} + ) + }) public void testUnrecoverableEntryExceptionString() { UnrecoverableEntryException tE; for (int i = 0; i < msgs.length; i++) { diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyException2Test.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyException2Test.java index 36cfbbd..7cacfcd 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyException2Test.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyException2Test.java @@ -17,13 +17,28 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.security.UnrecoverableKeyException; +@TestTargetClass(UnrecoverableKeyException.class) public class UnrecoverableKeyException2Test extends junit.framework.TestCase { /** * @tests java.security.UnrecoverableKeyException#UnrecoverableKeyException() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "UnrecoverableKeyException", + methodArgs = {} + ) + }) public void test_Constructor() { // Test for method java.security.UnrecoverableKeyException() UnrecoverableKeyException e = new UnrecoverableKeyException(); @@ -34,6 +49,15 @@ public class UnrecoverableKeyException2Test extends junit.framework.TestCase { /** * @tests java.security.UnrecoverableKeyException#UnrecoverableKeyException(java.lang.String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null string parameter missed", + targets = { + @TestTarget( + methodName = "UnrecoverableKeyException", + methodArgs = {String.class} + ) + }) public void test_ConstructorLjava_lang_String() { // Test for method // java.security.UnrecoverableKeyException(java.lang.String) diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java index 66a077c..f715d3b 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnrecoverableKeyExceptionTest.java @@ -21,11 +21,16 @@ */ package org.apache.harmony.security.tests.java.security; -import java.security.UnrecoverableKeyException; -import junit.framework.TestCase; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import java.security.UnrecoverableKeyException; +import junit.framework.TestCase; +@TestTargetClass(UnrecoverableKeyException.class) /** * Tests for <code>UnrecoverableKeyException</code> class constructors and * methods. @@ -56,6 +61,15 @@ public class UnrecoverableKeyExceptionTest extends TestCase { * Test for <code>UnrecoverableKeyException()</code> constructor * Assertion: constructs UnrecoverableKeyException with no detail message */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "UnrecoverableKeyException", + methodArgs = {} + ) + }) public void testUnrecoverableKeyException01() { UnrecoverableKeyException tE = new UnrecoverableKeyException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -67,6 +81,15 @@ public class UnrecoverableKeyExceptionTest extends TestCase { * Assertion: constructs UnrecoverableKeyException with detail message msg. * Parameter <code>msg</code> is not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "UnrecoverableKeyException", + methodArgs = {String.class} + ) + }) public void testUnrecoverableKeyException02() { UnrecoverableKeyException tE; for (int i = 0; i < msgs.length; i++) { @@ -82,6 +105,15 @@ public class UnrecoverableKeyExceptionTest extends TestCase { * Assertion: constructs UnrecoverableKeyException when <code>msg</code> * is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "UnrecoverableKeyException", + methodArgs = {String.class} + ) + }) public void testUnrecoverableKeyException03() { String msg = null; UnrecoverableKeyException tE = new UnrecoverableKeyException(msg); diff --git a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java index ae8f50b..f09eaa0 100644 --- a/security/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java +++ b/security/src/test/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java @@ -17,6 +17,11 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; + import java.io.Serializable; import java.security.AllPermission; import java.security.Permission; @@ -33,7 +38,7 @@ import tests.util.SerializationTester; import junit.framework.TestCase; - +@TestTargetClass(UnresolvedPermission.class) /** * Tests for <code>UnresolvedPermission</code> class fields and methods * @@ -45,6 +50,15 @@ public class UnresolvedPermissionTest extends TestCase { * Creates an Object with given name, type, action, certificates. Empty or * null type is not allowed - exception should be thrown. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "UnresolvedPermission", + methodArgs = {String.class, String.class, String.class, Certificate[].class} + ) + }) public void testCtor() { String type = "laskjhlsdk 2345346"; String name = "^%#UHVKU^%V 887y"; @@ -81,6 +95,15 @@ public class UnresolvedPermissionTest extends TestCase { /** * UnresolvedPermission never implies any other permission. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {Permission.class} + ) + }) public void testImplies() { UnresolvedPermission up = new UnresolvedPermission( "java.security.SecurityPermission", "a.b.c", null, null); @@ -89,6 +112,15 @@ public class UnresolvedPermissionTest extends TestCase { assertFalse(up.implies(new SecurityPermission("a.b.c"))); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerialization() throws Exception { UnresolvedPermission up = new UnresolvedPermission( "java.security.SecurityPermission", "a.b.c", "actions", null); @@ -106,7 +138,16 @@ public class UnresolvedPermissionTest extends TestCase { assertNull(deserializedUp.getUnresolvedCerts()); } - public void testSerialization_Compatibility() throws Exception { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) + public void _testSerialization_Compatibility() throws Exception { UnresolvedPermission up = new UnresolvedPermission( "java.security.SecurityPermission", "a.b.c", "actions", null); assertEquals("java.security.SecurityPermission", up.getUnresolvedType()); @@ -126,6 +167,15 @@ public class UnresolvedPermissionTest extends TestCase { }); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEquals() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1", null); @@ -162,6 +212,15 @@ public class UnresolvedPermissionTest extends TestCase { } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getActions", + methodArgs = {} + ) + }) public void testGetActions() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1", null); @@ -176,6 +235,15 @@ public class UnresolvedPermissionTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getUnresolvedActions", + methodArgs = {} + ) + }) public void testGetUnresolvedActions() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1 @#$%^&*", null); @@ -190,7 +258,16 @@ public class UnresolvedPermissionTest extends TestCase { } } - public void testGetUnresolvedCerts() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getUnresolvedCerts", + methodArgs = {} + ) + }) + public void _testGetUnresolvedCerts() { Certificate[] certificate = new java.security.cert.Certificate[0]; UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1 @#$%^&*", null); @@ -209,6 +286,15 @@ public class UnresolvedPermissionTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getUnresolvedName", + methodArgs = {} + ) + }) public void testGetUnresolvedName() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1!@#$%^&&* )(", "action1 @#$%^&*", null); @@ -223,6 +309,15 @@ public class UnresolvedPermissionTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getUnresolvedType", + methodArgs = {} + ) + }) public void testGetUnresolvedType() { UnresolvedPermission up1 = new UnresolvedPermission("type1@#$%^&* )(", "name1", "action1", null); @@ -237,6 +332,15 @@ public class UnresolvedPermissionTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1", null); @@ -259,6 +363,15 @@ public class UnresolvedPermissionTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void testNewPermissionCollection() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1", null); @@ -285,6 +398,15 @@ public class UnresolvedPermissionTest extends TestCase { } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1", "action1", null); diff --git a/security/src/test/java/tests/api/java/security/AccessControlContextTest.java b/security/src/test/java/tests/api/java/security/AccessControlContextTest.java index 9041b07..0cd502c 100644 --- a/security/src/test/java/tests/api/java/security/AccessControlContextTest.java +++ b/security/src/test/java/tests/api/java/security/AccessControlContextTest.java @@ -17,6 +17,11 @@ package tests.api.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.io.FilePermission; import java.security.AccessControlContext; @@ -30,11 +35,21 @@ import java.util.PropertyPermission; import javax.security.auth.Subject; import javax.security.auth.SubjectDomainCombiner; +@TestTargetClass(AccessControlContext.class) public class AccessControlContextTest extends junit.framework.TestCase { /** * @tests java.security.AccessControlContext#AccessControlContext(java.security.ProtectionDomain[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "AccessControlContext", + methodArgs = {ProtectionDomain[].class} + ) + }) public void test_Constructor$Ljava_security_ProtectionDomain() { // Test for method // java.security.AccessControlContext(java.security.ProtectionDomain []) @@ -78,6 +93,15 @@ public class AccessControlContextTest extends junit.framework.TestCase { * @tests java.security.AccessControlContext#AccessControlContext(java.security.AccessControlContext, * java.security.DomainCombiner) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "AccessControlContext", + methodArgs = {AccessControlContext.class, java.security.DomainCombiner.class} + ) + }) public void test_ConstructorLjava_security_AccessControlContextLjava_security_DomainCombiner() { AccessControlContext context = AccessController.getContext(); try { @@ -97,6 +121,15 @@ public class AccessControlContextTest extends junit.framework.TestCase { /** * @tests java.security.AccessControlException#checkPermission(Permission) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "AccessControlException, NullPointerException checking missed", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {Permission.class} + ) + }) public void test_checkPermission() { char s = File.separatorChar; FilePermission perm[] = new FilePermission[7]; @@ -159,7 +192,16 @@ public class AccessControlContextTest extends junit.framework.TestCase { /** * @tests java.security.AccessControlException#equals() */ - public void test_equals() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) + public void _test_equals() { final Permission perm1 = new PropertyPermission("java.class.path", "read"); final Permission perm2 = new PropertyPermission("java.path", "write"); @@ -210,6 +252,15 @@ public class AccessControlContextTest extends junit.framework.TestCase { /** * @tests java.security.AccessControlException#getDomainCombiner() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "getDomainCombiner", + methodArgs = {} + ) + }) public void test_getDomainCombiner() { AccessControlContext context = AccessController.getContext(); @@ -235,6 +286,15 @@ public class AccessControlContextTest extends junit.framework.TestCase { /** * @tests java.security.AccessControlException#hashCode() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void test_hashCode() { final Permission perm1 = new PropertyPermission("java.class.path", "read"); diff --git a/security/src/test/java/tests/api/java/security/DomainCombinerTest.java b/security/src/test/java/tests/api/java/security/DomainCombinerTest.java index ac27b00..c1245c3 100644 --- a/security/src/test/java/tests/api/java/security/DomainCombinerTest.java +++ b/security/src/test/java/tests/api/java/security/DomainCombinerTest.java @@ -17,6 +17,11 @@ package tests.api.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AccessControlContext; import java.security.AccessController; import java.security.AllPermission; @@ -31,12 +36,22 @@ import java.security.ProtectionDomain; import java.security.SecurityPermission; import java.security.cert.Certificate; +@TestTargetClass(DomainCombiner.class) public class DomainCombinerTest extends junit.framework.TestCase { /** * @tests java.security.DomainCombiner#combine(java.security.ProtectionDomain[], * java.security.ProtectionDomain[]) */ + @TestInfo( + level = TestLevel.TODO, + purpose = "Method combine is not tested", + targets = { + @TestTarget( + methodName = "combine", + methodArgs = {ProtectionDomain[].class, ProtectionDomain[].class} + ) + }) public void test_combine$Ljava_security_ProtectionDomain$Ljava_security_ProtectionDomain() { final boolean[] calledDomainCombiner = new boolean[] { false, false }; diff --git a/security/src/test/java/tests/api/java/security/PermissionCollectionTest.java b/security/src/test/java/tests/api/java/security/PermissionCollectionTest.java index 70a614b..58acc61 100644 --- a/security/src/test/java/tests/api/java/security/PermissionCollectionTest.java +++ b/security/src/test/java/tests/api/java/security/PermissionCollectionTest.java @@ -17,6 +17,11 @@ package tests.api.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; @@ -29,6 +34,7 @@ import tests.support.Support_Exec; import tests.support.Support_GetLocal; import tests.support.resource.Support_Resources; +@TestTargetClass(PermissionCollection.class) public class PermissionCollectionTest extends junit.framework.TestCase { // The below test is known to fail. Haven't got to the bottom of @@ -53,7 +59,16 @@ public class PermissionCollectionTest extends junit.framework.TestCase { /** * @tests java.security.PermissionCollection#implies(java.security.Permission) */ - public void test_impliesLjava_security_Permission() throws Exception{ + @TestInfo( + level = TestLevel.TODO, + purpose = "Method implies is not call in this test", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {java.security.Permission.class} + ) + }) + public void _test_impliesLjava_security_Permission() throws Exception{ // Look for the tests classpath URL classURL = this.getClass().getProtectionDomain().getCodeSource() @@ -174,6 +189,15 @@ public class PermissionCollectionTest extends junit.framework.TestCase { /** * @tests java.security.PermissionCollection#PermissionCollection() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PermissionCollection", + methodArgs = {} + ) + }) public void test_Constructor() { // test java.security.permissionCollection.PermissionCollection() SecurityPermission permi = new SecurityPermission( @@ -186,6 +210,15 @@ public class PermissionCollectionTest extends junit.framework.TestCase { /** * @tests java.security.PermissionCollection#isReadOnly() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isReadOnly", + methodArgs = {} + ) + }) public void test_isReadOnly() { // test java.security.permissionCollection.isReadOnly() SecurityPermission permi = new SecurityPermission( @@ -201,6 +234,15 @@ public class PermissionCollectionTest extends junit.framework.TestCase { /** * @tests java.security.PermissionCollection#setReadOnly() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setReadOnly", + methodArgs = {} + ) + }) public void test_setReadOnly() { // test java.security.permissionCollection.setReadOnly() SecurityPermission permi = new SecurityPermission( @@ -216,7 +258,16 @@ public class PermissionCollectionTest extends junit.framework.TestCase { /** * @tests java.security.PermissionCollection#toString() */ - public void test_toString() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public void _test_toString() { // test java.security.permissionCollection.toString() SecurityPermission permi = new SecurityPermission( "testing permissionCollection-isREadOnly"); diff --git a/security/src/test/java/tests/api/javax/security/cert/AllTests.java b/security/src/test/java/tests/api/javax/security/cert/AllTests.java new file mode 100644 index 0000000..cacaaee --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/AllTests.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.api.javax.security.cert; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package tests.api.javax.security.cert; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package tests.api.javax.security.cert;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(CertificateEncodingExceptionTest.class); + suite.addTestSuite(CertificateExceptionTest.class); + suite.addTestSuite(CertificateExpiredExceptionTest.class); + suite.addTestSuite(CertificateNotYetValidExceptionTest.class); + suite.addTestSuite(CertificateParsingExceptionTest.class); + suite.addTestSuite(CertificateTest.class); + suite.addTestSuite(X509CertificateTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/CertificateEncodingExceptionTest.java b/security/src/test/java/tests/api/javax/security/cert/CertificateEncodingExceptionTest.java new file mode 100644 index 0000000..a2acbfa --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/CertificateEncodingExceptionTest.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import javax.security.cert.CertificateEncodingException; + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateEncodingException.class) +public class CertificateEncodingExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateEncodingExceptionTests. + * + * @param arg0 + */ + public CertificateEncodingExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateEncodingException()</code> constructor + * Assertion: constructs CertificateEncodingException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {} + ) + }) + public void testCertificateEncodingException01() { + CertificateEncodingException tE = new CertificateEncodingException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateEncodingException(String)</code> constructor + * Assertion: constructs CertificateEncodingException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateEncodingException with valid parameters.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateEncodingException02() { + CertificateEncodingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateEncodingException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateEncodingException(String)</code> constructor + * Assertion: constructs CertificateEncodingException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateEncodingException03() { + String msg = null; + CertificateEncodingException tE = new CertificateEncodingException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/CertificateExceptionTest.java b/security/src/test/java/tests/api/javax/security/cert/CertificateExceptionTest.java new file mode 100644 index 0000000..3cc61ba --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/CertificateExceptionTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import javax.security.cert.CertificateException; + + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateException.class) +public class CertificateExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateExceptionTests. + * + * @param arg0 + */ + public CertificateExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateException()</code> constructor Assertion: + * constructs CertificateException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {} + ) + }) + public void testCertificateException01() { + CertificateException tE = new CertificateException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateException(String)</code> constructor + * Assertion: constructs CertificateException with detail message msg. + * Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameter.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateException02() { + CertificateException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateException(String)</code> constructor + * Assertion: constructs CertificateException when <code>msg</code> is + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateException03() { + String msg = null; + CertificateException tE = new CertificateException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/CertificateExpiredExceptionTest.java b/security/src/test/java/tests/api/javax/security/cert/CertificateExpiredExceptionTest.java new file mode 100644 index 0000000..d65ceb1 --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/CertificateExpiredExceptionTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import javax.security.cert.CertificateExpiredException; + + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateExpiredException.class) +public class CertificateExpiredExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateExpiredExceptionTests. + * + * @param arg0 + */ + public CertificateExpiredExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateExpiredException()</code> constructor + * Assertion: constructs CertificateExpiredException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateExpiredException", + methodArgs = {} + ) + }) + public void testCertificateExpiredException01() { + CertificateExpiredException tE = new CertificateExpiredException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateExpiredException(String)</code> constructor + * Assertion: constructs CertificateExpiredException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameter.", + targets = { + @TestTarget( + methodName = "CertificateExpiredException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateExpiredException02() { + CertificateExpiredException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateExpiredException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateExpiredException(String)</code> constructor + * Assertion: constructs CertificateExpiredException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateExpiredException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateExpiredException03() { + String msg = null; + CertificateExpiredException tE = new CertificateExpiredException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/CertificateNotYetValidExceptionTest.java b/security/src/test/java/tests/api/javax/security/cert/CertificateNotYetValidExceptionTest.java new file mode 100644 index 0000000..82547b3 --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/CertificateNotYetValidExceptionTest.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import javax.security.cert.CertificateNotYetValidException; + + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateNotYetValidException.class) +public class CertificateNotYetValidExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateNotYetValidExceptionTests. + * + * @param arg0 + */ + public CertificateNotYetValidExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateNotYetValidException()</code> constructor + * Assertion: constructs CertificateNotYetValidException with no detail + * message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateNotYetValidException", + methodArgs = {} + ) + }) + public void testCertificateNotYetValidException01() { + CertificateNotYetValidException tE = new CertificateNotYetValidException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateNotYetValidException(String)</code> + * constructor Assertion: constructs CertificateNotYetValidException with + * detail message msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateNotYetValidException constructor with " + + "valid parameters.", + targets = { + @TestTarget( + methodName = "CertificateNotYetValidException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateNotYetValidException02() { + CertificateNotYetValidException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateNotYetValidException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateNotYetValidException(String)</code> + * constructor Assertion: constructs CertificateNotYetValidException when + * <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateNotYetValidException constructor with " + + "null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateNotYetValidException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateNotYetValidException03() { + String msg = null; + CertificateNotYetValidException tE = new CertificateNotYetValidException( + msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/CertificateParsingExceptionTest.java b/security/src/test/java/tests/api/javax/security/cert/CertificateParsingExceptionTest.java new file mode 100644 index 0000000..4559d56 --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/CertificateParsingExceptionTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import javax.security.cert.CertificateParsingException; + + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateParsingException.class) +public class CertificateParsingExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateParsingExceptionTests. + * + * @param arg0 + */ + public CertificateParsingExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateParsingException()</code> constructor + * Assertion: constructs CertificateParsingException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {} + ) + }) + public void testCertificateParsingException01() { + CertificateParsingException tE = new CertificateParsingException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateParsingException(String)</code> constructor + * Assertion: constructs CertificateParsingException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateParsingException cobstructor with " + + "valid parameters.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateParsingException02() { + CertificateParsingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateParsingException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateParsingException(String)</code> constructor + * Assertion: constructs CertificateParsingException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateParsingException constructor with null " + + "as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateParsingException03() { + String msg = null; + CertificateParsingException tE = new CertificateParsingException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/CertificateTest.java b/security/src/test/java/tests/api/javax/security/cert/CertificateTest.java new file mode 100644 index 0000000..e654b50 --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/CertificateTest.java @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Alexander Y. Kleymenov + * @version $Revision$ + */ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.PublicKey; +import java.security.SignatureException; + +import javax.security.cert.Certificate; +import javax.security.cert.CertificateEncodingException; +import javax.security.cert.CertificateException; + +/** + */ +@TestTargetClass(Certificate.class) +public class CertificateTest extends TestCase { + + /** + * The stub class used for testing of non abstract methods. + */ + private class TBTCert extends Certificate { + public byte[] getEncoded() throws CertificateEncodingException { + return null; + } + + public void verify(PublicKey key) throws CertificateException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + public void verify(PublicKey key, String sigProvider) + throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + + public String toString() { + return "TBTCert"; + } + + public PublicKey getPublicKey() { + return null; + } + } + + /** + * Test for <code>Certificate()</code> constructor<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Certificate", + methodArgs = {} + ) + }) + public final void testCertificate() { + TBTCert tbt_cert = new TBTCert(); + + assertNull("Public key should be null", tbt_cert.getPublicKey()); + assertEquals("Wrong string representation for Certificate", "TBTCert", tbt_cert.toString()); + } + + /** + * equals(Object obj) method testing. Tests the correctness of equal + * operation: it should be reflexive, symmetric, transitive, consistent and + * should be false on null object. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public void testEquals() { + TBTCert tbt_cert = new TBTCert() { + public byte[] getEncoded() { + return new byte[] { 1, 2, 3 }; + } + }; + + TBTCert tbt_cert_1 = new TBTCert() { + public byte[] getEncoded() { + return new byte[] { 1, 2, 3 }; + } + }; + + TBTCert tbt_cert_2 = new TBTCert() { + public byte[] getEncoded() { + return new byte[] { 1, 2, 3 }; + } + }; + + TBTCert tbt_cert_3 = new TBTCert() { + public byte[] getEncoded() { + return new byte[] { 3, 2, 1 }; + } + }; + + // checking for reflexive law: + assertTrue("The equivalence relation should be reflexive.", tbt_cert + .equals(tbt_cert)); + + assertEquals( + "The Certificates with equal encoded form should be equal", + tbt_cert, tbt_cert_1); + // checking for symmetric law: + assertTrue("The equivalence relation should be symmetric.", tbt_cert_1 + .equals(tbt_cert)); + + assertEquals( + "The Certificates with equal encoded form should be equal", + tbt_cert_1, tbt_cert_2); + // checking for transitive law: + assertTrue("The equivalence relation should be transitive.", tbt_cert + .equals(tbt_cert_2)); + + assertFalse("Should not be equal to null object.", tbt_cert + .equals(null)); + + assertFalse("The Certificates with differing encoded form " + + "should not be equal", tbt_cert.equals(tbt_cert_3)); + assertFalse("The Certificates should not be equals to the object " + + "which is not an instance of Certificate", tbt_cert + .equals(new Object())); + } + + /** + * hashCode() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public void testHashCode() { + TBTCert tbt_cert = new TBTCert() { + public byte[] getEncoded() { + return new byte[] { 1, 2, 3 }; + } + }; + TBTCert tbt_cert_1 = new TBTCert() { + public byte[] getEncoded() { + return new byte[] { 1, 2, 3 }; + } + }; + + assertTrue("Equal objects should have the same hash codes.", tbt_cert + .hashCode() == tbt_cert_1.hashCode()); + } + + public static Test suite() { + return new TestSuite(CertificateTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} diff --git a/security/src/test/java/tests/api/javax/security/cert/X509CertificateTest.java b/security/src/test/java/tests/api/javax/security/cert/X509CertificateTest.java new file mode 100644 index 0000000..0ea507e --- /dev/null +++ b/security/src/test/java/tests/api/javax/security/cert/X509CertificateTest.java @@ -0,0 +1,587 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Alexander Y. Kleymenov + * @version $Revision$ + */ + +package tests.api.javax.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateFactory; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; + +import javax.security.cert.CertificateEncodingException; +import javax.security.cert.CertificateException; +import javax.security.cert.CertificateExpiredException; +import javax.security.cert.CertificateNotYetValidException; +import javax.security.cert.X509Certificate; + +/** + */ +@TestTargetClass(X509Certificate.class) +public class X509CertificateTest extends TestCase { + + // Testing data was generated by using of classes + // from org.apache.harmony.security.asn1 package encoded + // by org.apache.harmony.misc.Base64 class. + + private static String base64cert = "-----BEGIN CERTIFICATE-----\n" + + "MIIC+jCCAragAwIBAgICAiswDAYHKoZIzjgEAwEBADAdMRswGQYDVQQKExJDZXJ0a" + + "WZpY2F0ZSBJc3N1ZXIwIhgPMTk3MDAxMTIxMzQ2NDBaGA8xOTcwMDEyNDAzMzMyMF" + + "owHzEdMBsGA1UEChMUU3ViamVjdCBPcmdhbml6YXRpb24wGTAMBgcqhkjOOAQDAQE" + + "AAwkAAQIDBAUGBwiBAgCqggIAVaOCAhQwggIQMA8GA1UdDwEB/wQFAwMBqoAwEgYD" + + "VR0TAQH/BAgwBgEB/wIBBTAUBgNVHSABAf8ECjAIMAYGBFUdIAAwZwYDVR0RAQH/B" + + "F0wW4EMcmZjQDgyMi5OYW1lggdkTlNOYW1lpBcxFTATBgNVBAoTDE9yZ2FuaXphdG" + + "lvboYaaHR0cDovL3VuaWZvcm0uUmVzb3VyY2UuSWSHBP///wCIByoDolyDsgMwDAY" + + "DVR0eAQH/BAIwADAMBgNVHSQBAf8EAjAAMIGZBgNVHSUBAf8EgY4wgYsGBFUdJQAG" + + "CCsGAQUFBwMBBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDB" + + "AYIKwYBBQUHAwUGCCsGAQUFBwMGBggrBgEFBQcDBwYIKwYBBQUHAwgGCCsGAQUFBw" + + "MJBggrBgEFBQgCAgYKKwYBBAGCNwoDAwYJYIZIAYb4QgQBMA0GA1UdNgEB/wQDAgE" + + "BMA4GBCpNhgkBAf8EAwEBATBkBgNVHRIEXTBbgQxyZmNAODIyLk5hbWWCB2ROU05h" + + "bWWkFzEVMBMGA1UEChMMT3JnYW5pemF0aW9uhhpodHRwOi8vdW5pZm9ybS5SZXNvd" + + "XJjZS5JZIcE////AIgHKgOiXIOyAzAJBgNVHR8EAjAAMAoGA1UdIwQDAQEBMAoGA1" + + "UdDgQDAQEBMAoGA1UdIQQDAQEBMAwGByqGSM44BAMBAQADMAAwLQIUAL4QvoazNWP" + + "7jrj84/GZlhm09DsCFQCBKGKCGbrP64VtUt4JPmLjW1VxQA==\n" + + "-----END CERTIFICATE-----"; + + private java.security.cert.X509Certificate cert; + + private javax.security.cert.X509Certificate tbt_cert; + + protected void setUp() throws Exception { + try { + ByteArrayInputStream bais = new ByteArrayInputStream(base64cert + .getBytes()); + + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + this.cert = (java.security.cert.X509Certificate) cf + .generateCertificate(bais); + this.tbt_cert = X509Certificate.getInstance(cert.getEncoded()); + } catch (java.security.cert.CertificateException e) { + // The requested certificate type is not available. + // Test pass.. + this.cert = null; + } catch (javax.security.cert.CertificateException e) { + // The requested certificate type is not available. + // Test pass.. + this.cert = null; + } + } + + /** + * X509Certificate() constructor testing. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "X509Certificate", + methodArgs = {} + ) + }) + public void testConstructor() throws CertificateEncodingException { + X509Certificate cert = new MyCertificate(); + assertNull("Principal should be null", cert.getIssuerDN()); + assertEquals("Wrong end date", new Date(), cert.getNotAfter()); + assertEquals("Wrong start date", new Date(), cert.getNotBefore()); + assertNull("Public key should be null", cert.getPublicKey()); + assertEquals("Serial number should be 0", BigInteger.valueOf(0), cert.getSerialNumber()); + assertEquals("Wrong algorithm name", "algName", cert.getSigAlgName()); + assertEquals("Wrong algorithm OID", "algOID", cert.getSigAlgOID()); + assertNull("Signature algorithm parameters should be null", cert.getSigAlgParams()); + assertNull("Subject should be null", cert.getSubjectDN()); + assertEquals("Version should be 0", 0, cert.getVersion()); + } + + /** + * getInstance(InputStream inStream) method testing. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGetInstance1() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + try { + ByteArrayInputStream bais = new ByteArrayInputStream(cert + .getEncoded()); + + X509Certificate.getInstance(bais); + } catch (java.security.cert.CertificateEncodingException e) { + fail("Unexpected CertificateEncodingException was thrown."); + } catch (CertificateEncodingException e) { + fail("Unexpected CertificateEncodingException was thrown."); + } catch (CertificateException e) { + // The requested certificate type is not available. + // Test pass.. + } + + // Regression for HARMONY-756 + try { + X509Certificate.getInstance((InputStream) null); + fail("No expected CertificateException"); + } catch (CertificateException e) { + // expected; + } + } + + /** + * getInstance(byte[] certData) method testing. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {byte[].class} + ) + }) + public void testGetInstance2() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + try { + X509Certificate.getInstance(cert.getEncoded()); + } catch (java.security.cert.CertificateEncodingException e) { + fail("Unexpected CertificateEncodingException was thrown."); + } catch (CertificateException e) { + // The requested certificate type is not available. + // Test pass.. + } + + // Regression for HARMONY-756 + try { + X509Certificate.getInstance((byte[]) null); + fail("No expected CertificateException"); + } catch (CertificateException e) { + // expected; + } + } + + /** + * checkValidity() method testing. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "checkValidity", + methodArgs = {} + ) + }) + public void testCheckValidity1() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + Date date = new Date(); + Date nb_date = tbt_cert.getNotBefore(); + Date na_date = tbt_cert.getNotAfter(); + try { + tbt_cert.checkValidity(); + assertFalse("CertificateExpiredException expected", date + .compareTo(na_date) > 0); + assertFalse("CertificateNotYetValidException expected", date + .compareTo(nb_date) < 0); + } catch (CertificateExpiredException e) { + assertTrue("Unexpected CertificateExpiredException was thrown", + date.compareTo(na_date) > 0); + } catch (CertificateNotYetValidException e) { + assertTrue("Unexpected CertificateNotYetValidException was thrown", + date.compareTo(nb_date) < 0); + } + } + + /** + * checkValidity(Date date) method testing. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "checkValidity", + methodArgs = {java.util.Date.class} + ) + }) + public void testCheckValidity2() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + Date[] date = new Date[4]; + Calendar calendar = Calendar.getInstance(); + for (int i = 0; i < date.length; i++) { + calendar.set(i * 50, Calendar.JANUARY, 1); + date[i] = calendar.getTime(); + } + Date nb_date = tbt_cert.getNotBefore(); + Date na_date = tbt_cert.getNotAfter(); + for (int i = 0; i < date.length; i++) { + try { + tbt_cert.checkValidity(date[i]); + assertFalse("CertificateExpiredException expected", date[i] + .compareTo(na_date) > 0); + assertFalse("CertificateNotYetValidException expected", date[i] + .compareTo(nb_date) < 0); + } catch (CertificateExpiredException e) { + assertTrue("Unexpected CertificateExpiredException was thrown", + date[i].compareTo(na_date) > 0); + } catch (CertificateNotYetValidException e) { + assertTrue("Unexpected CertificateNotYetValidException " + + "was thrown", date[i].compareTo(nb_date) < 0); + } + } + } + + /** + * getVersion() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getVersion", + methodArgs = {} + ) + }) + public void testGetVersion() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The version is not correct.", tbt_cert.getVersion(), 2); + } + + /** + * getSerialNumber() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSerialNumber", + methodArgs = {} + ) + }) + public void testGetSerialNumber() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The serial number is not correct.", tbt_cert + .getSerialNumber(), cert.getSerialNumber()); + } + + /** + * getIssuerDN() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuerDN", + methodArgs = {} + ) + }) + public void testGetIssuerDN() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The issuer DN is not correct.", tbt_cert.getIssuerDN(), + cert.getIssuerDN()); + } + + /** + * getSubjectDN() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectDN", + methodArgs = {} + ) + }) + public void testGetSubjectDN() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The subject DN is not correct.", tbt_cert.getSubjectDN(), + cert.getSubjectDN()); + } + + /** + * getNotBefore() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getNotBefore", + methodArgs = {} + ) + }) + public void testGetNotBefore() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The NotBefore date is not correct.", tbt_cert + .getNotBefore(), cert.getNotBefore()); + } + + /** + * getNotAfter() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getNotAfter", + methodArgs = {} + ) + }) + public void testGetNotAfter() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The NotAfter date is not correct.", tbt_cert + .getNotAfter(), cert.getNotAfter()); + } + + /** + * getSigAlgName() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSigAlgName", + methodArgs = {} + ) + }) + public void testGetSigAlgName() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The name of signature algorithm is not correct.", + tbt_cert.getSigAlgName(), cert.getSigAlgName()); + } + + /** + * getSigAlgOID() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSigAlgOID", + methodArgs = {} + ) + }) + public void testGetSigAlgOID() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertEquals("The name of OID of signature algorithm is not correct.", + tbt_cert.getSigAlgOID(), cert.getSigAlgOID()); + } + + /** + * getSigAlgParams() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSigAlgParams", + methodArgs = {} + ) + }) + public void testGetSigAlgParams() { + if (this.cert == null) { + // The requested certificate type is not available. + // Test can not be applied. + return; + } + assertTrue("The byte array with encoded algorithm parameters " + + "is not correct.", Arrays.equals(tbt_cert.getSigAlgParams(), + cert.getSigAlgParams())); + } + + /** + * The stub class used for testing of non abstract methods. + */ + private class MyCertificate extends X509Certificate { + + public MyCertificate() { + super(); + } + + @Override + public void checkValidity() throws CertificateExpiredException, + CertificateNotYetValidException { + } + + @Override + public void checkValidity(Date arg0) + throws CertificateExpiredException, + CertificateNotYetValidException { + } + + @Override + public Principal getIssuerDN() { + return null; + } + + @Override + public Date getNotAfter() { + return new Date(); + } + + @Override + public Date getNotBefore() { + return new Date(); + } + + @Override + public BigInteger getSerialNumber() { + return BigInteger.valueOf(0); + } + + @Override + public String getSigAlgName() { + return "algName"; + } + + @Override + public String getSigAlgOID() { + return "algOID"; + } + + @Override + public byte[] getSigAlgParams() { + return null; + } + + @Override + public Principal getSubjectDN() { + return null; + } + + @Override + public int getVersion() { + return 0; + } + + @Override + public byte[] getEncoded() throws CertificateEncodingException { + return null; + } + + @Override + public PublicKey getPublicKey() { + return null; + } + + @Override + public String toString() { + return "certificate"; + } + + @Override + public void verify(PublicKey key) throws CertificateException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + @Override + public void verify(PublicKey key, String sigProvider) + throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + } + + public static Test suite() { + return new TestSuite(X509CertificateTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} diff --git a/security/src/test/java/tests/java/security/AlgorithmParameterGeneratorSpiTest.java b/security/src/test/java/tests/java/security/AlgorithmParameterGeneratorSpiTest.java index 161183c..074b4cb 100644 --- a/security/src/test/java/tests/java/security/AlgorithmParameterGeneratorSpiTest.java +++ b/security/src/test/java/tests/java/security/AlgorithmParameterGeneratorSpiTest.java @@ -22,6 +22,11 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import java.security.SecureRandom; @@ -36,7 +41,7 @@ import junit.framework.TestCase; * and methods. * */ - +@TestTargetClass(java.security.AlgorithmParameterGeneratorSpi.class) public class AlgorithmParameterGeneratorSpiTest extends TestCase { /** @@ -52,6 +57,15 @@ public class AlgorithmParameterGeneratorSpiTest extends TestCase { * Test for <code>AlgorithmParameterGeneratorSpi</code> constructor * Assertion: constructs AlgorithmParameterGeneratorSpi */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "AlgorithmParameterGeneratorSpi", + methodArgs = {} + ) + }) public void testAlgorithmParameterGeneratorSpi01() throws InvalidAlgorithmParameterException { MyAlgorithmParameterGeneratorSpi algParGen = new MyAlgorithmParameterGeneratorSpi(); diff --git a/security/src/test/java/tests/java/security/AllPermissionTest.java b/security/src/test/java/tests/java/security/AllPermissionTest.java index 0d2d738..5654bc2 100644 --- a/security/src/test/java/tests/java/security/AllPermissionTest.java +++ b/security/src/test/java/tests/java/security/AllPermissionTest.java @@ -22,13 +22,18 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.AllPermission; import java.security.BasicPermission; import java.security.PermissionCollection; import java.security.UnresolvedPermission; import junit.framework.TestCase; - +@TestTargetClass(AllPermission.class) /** * Tests for <code>AllPermission</code> * @@ -50,6 +55,20 @@ public class AllPermissionTest extends TestCase { /** * Test all constructors: an object is created, name and actions are ignored */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "AllPermission", + methodArgs = {} + ), + @TestTarget( + methodName = "AllPermission", + methodArgs = {String.class, String.class} + ) + + }) public void testCtor() { AllPermission a1 = new AllPermission(); @@ -66,6 +85,15 @@ public class AllPermissionTest extends TestCase { } /** Any of AllPermission instances are equal and have the same hash code */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEquals() { AllPermission a1 = new AllPermission(); @@ -77,6 +105,15 @@ public class AllPermissionTest extends TestCase { } /** AllPermission implies any other permission */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {java.security.Permission.class} + ) + }) public void testImplies() { AllPermission a1 = new AllPermission(); @@ -86,6 +123,15 @@ public class AllPermissionTest extends TestCase { } /** newPermissionCollection() returns a new AllPermissionCollection on every invocation. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void testCollection() { AllPermission a1 = new AllPermission(); diff --git a/security/src/test/java/tests/java/security/BasicPermissionTest.java b/security/src/test/java/tests/java/security/BasicPermissionTest.java index c0485fe..54860d4 100644 --- a/security/src/test/java/tests/java/security/BasicPermissionTest.java +++ b/security/src/test/java/tests/java/security/BasicPermissionTest.java @@ -22,6 +22,11 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.BasicPermission; import java.security.PermissionCollection; @@ -31,7 +36,7 @@ import junit.framework.TestCase; * Tests for <code>BasicPermission</code> * */ - +@TestTargetClass(BasicPermission.class) public class BasicPermissionTest extends TestCase { public static void main(String[] args) { @@ -52,6 +57,19 @@ public class BasicPermissionTest extends TestCase { * If name is empty then IAE should be thrown. * Action is ignored. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "BasicPermission", + methodArgs = {String.class} + ), + @TestTarget( + methodName = "BasicPermission", + methodArgs = {String.class, String.class} + ) + }) public void testCtor() { String name = "basic123*$%#"; @@ -97,6 +115,15 @@ public class BasicPermissionTest extends TestCase { * two BasicPermissions are equal if name and class are equal; * equal permissions should have the same hash code */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEquals() { BasicPermission b1 = new BasicPermissionImpl("abc"); @@ -115,6 +142,15 @@ public class BasicPermissionTest extends TestCase { * implies() should return true if a permission is equal to or is implied * by wildcarded permission, false otherwise. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implies", + methodArgs = {java.security.Permission.class} + ) + }) public void testImplies() { BasicPermission b1 = new BasicPermissionImpl("a.b.c"); @@ -134,6 +170,15 @@ public class BasicPermissionTest extends TestCase { /** * newPermissionCollection() should return new BasicPermissionCollection on every invocation */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "newPermissionCollection", + methodArgs = {} + ) + }) public void testCollection() { BasicPermission b1 = new BasicPermissionImpl("a.b.c"); diff --git a/security/src/test/java/tests/java/security/IdentityTest.java b/security/src/test/java/tests/java/security/IdentityTest.java index 8854c48..da9ab77 100644 --- a/security/src/test/java/tests/java/security/IdentityTest.java +++ b/security/src/test/java/tests/java/security/IdentityTest.java @@ -22,6 +22,10 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; import java.security.Identity; import java.security.IdentityScope; @@ -42,6 +46,7 @@ import junit.framework.TestCase; * */ @SuppressWarnings("deprecation") +@TestTargetClass(Identity.class) public class IdentityTest extends TestCase { public static class MySecurityManager extends SecurityManager { @@ -63,10 +68,28 @@ public class IdentityTest extends TestCase { super(name); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method's returned variable is not checked", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode() { new IdentityStub("testHashCode").hashCode(); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {Object.class} + ) + }) public void testEquals() throws Exception { IdentityStub i1 = new IdentityStub("testEquals"); Object value[] = { @@ -91,6 +114,15 @@ public class IdentityTest extends TestCase { /** * verify Identity.toString() throws Exception is permission is denied */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString1() { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("printIdentity")); @@ -106,6 +138,15 @@ public class IdentityTest extends TestCase { /** * verify Identity.toString() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString2() { assertNotNull(new IdentityStub("testToString2").toString()); } @@ -113,6 +154,15 @@ public class IdentityTest extends TestCase { /** * verify Identity() creates instance */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Identity", + methodArgs = {} + ) + }) public void testIdentity() { assertNotNull(new IdentityStub()); } @@ -120,6 +170,15 @@ public class IdentityTest extends TestCase { /* * verify Identity(String) creates instance with given name */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Empty string for parameter is not tested", + targets = { + @TestTarget( + methodName = "Identity", + methodArgs = {String.class} + ) + }) public void testIdentityString() { Identity i = new IdentityStub("iii"); assertNotNull(i); @@ -132,6 +191,16 @@ public class IdentityTest extends TestCase { /** * verify Identity(String, IdentityScope) creates instance with given name and in give scope */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyManagementException checking missed. " + + "Null parameters are not checked.", + targets = { + @TestTarget( + methodName = "Identity", + methodArgs = {String.class, IdentityScope.class} + ) + }) public void testIdentityStringIdentityScope() throws Exception { IdentityScope s = IdentityScope.getSystemScope(); Identity i = new IdentityStub("iii2", s); @@ -146,6 +215,15 @@ public class IdentityTest extends TestCase { * If the identity has a public key, the public key in the certificate must be the same * */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void testAddCertificate1() throws Exception { Identity i = new IdentityStub("iii"); PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", new byte[]{1,2,3,4,5}); @@ -165,7 +243,15 @@ public class IdentityTest extends TestCase { * verify addCertificate(Certificate certificate) adds a certificate for this identity. * if the identity does not have a public key, the identity's public key is set to be that specified in the certificate. */ - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void testAddCertificate2() throws Exception { Identity i = new IdentityStub("iii"); PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null); @@ -179,7 +265,15 @@ public class IdentityTest extends TestCase { /** * verify addCertificate(Certificate certificate) throws SecurityException is permission is denied */ - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void testAddCertificate3() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("addIdentityCertificate")); @@ -196,6 +290,15 @@ public class IdentityTest extends TestCase { /** * verify addCertificate(Certificate certificate) throws KeyManagementException if certificate is null */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void testAddCertificate4() throws Exception { try { new IdentityStub("aaa").addCertificate(null); @@ -233,6 +336,15 @@ public class IdentityTest extends TestCase { /** * verify removeCertificate(Certificate certificate) throws SecurityException if permission is denied */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "KeyManagementException checking missed", + targets = { + @TestTarget( + methodName = "removeCertificate", + methodArgs = {java.security.Certificate.class} + ) + }) public void testRemoveCertificate2() throws Exception{ MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("removeIdentityCertificate")); @@ -252,6 +364,15 @@ public class IdentityTest extends TestCase { /** * verify certificates() returns a copy of all certificates for this identity */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "certificates", + methodArgs = {} + ) + }) public void testCertificates() throws Exception { Identity i = new IdentityStub("iii"); PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null); @@ -275,6 +396,15 @@ public class IdentityTest extends TestCase { /** * verify Identity.identityEquals(Identity) return true, only if names and public keys are equal */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "identityEquals", + methodArgs = {Identity.class} + ) + }) public void testIdentityEquals() throws Exception { String name = "nnn"; PublicKey pk = new PublicKeyStub("aaa", "fff", new byte[]{1,2,3,4,5}); @@ -301,6 +431,16 @@ public class IdentityTest extends TestCase { /** * verify Identity.toString(boolean) return string representation of identity */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Method's returned value is not checked. " + + "SecurityException checking missed.", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {boolean.class} + ) + }) public void testToStringboolean() throws Exception { new IdentityStub("aaa").toString(false); new IdentityStub("aaa2", IdentityScope.getSystemScope()).toString(false); @@ -311,6 +451,15 @@ public class IdentityTest extends TestCase { /** * verify Identity.getScope() returns identity's scope */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getScope", + methodArgs = {} + ) + }) public void testGetScope() throws Exception { Identity i = new IdentityStub("testGetScope"); assertNull(i.getScope()); @@ -323,8 +472,16 @@ public class IdentityTest extends TestCase { /** * * verify Identity.setPublicKey() throws SecurityException if permission is denied - * */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setPublicKey", + methodArgs = {PublicKey.class} + ) + }) public void testSetPublicKey1() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("setIdentityPublicKey")); @@ -343,6 +500,15 @@ public class IdentityTest extends TestCase { * verify Identity.setPublicKey() throws KeyManagementException if key is invalid * */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setPublicKey", + methodArgs = {PublicKey.class} + ) + }) public void testSetPublicKey2() throws Exception { Identity i2 = new IdentityStub("testSetPublicKey2_2", IdentityScope.getSystemScope()); new PublicKeyStub("kkk", "testSetPublicKey2", new byte[]{1,2,3,4,5}); @@ -374,6 +540,15 @@ public class IdentityTest extends TestCase { * verify Identity.setPublicKey() removes old key and all identity's certificates * */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setPublicKey", + methodArgs = {PublicKey.class} + ) + }) public void testSetPublicKey4() throws Exception { Identity i = new IdentityStub("testSetPublicKey4"); PublicKeyStub pk1 = new PublicKeyStub("kkk", "Identity.testSetPublicKey4", null); @@ -393,6 +568,15 @@ public class IdentityTest extends TestCase { /** * verify Identity.getPublicKey() returns public key */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicKey", + methodArgs = {} + ) + }) public void testGetPublicKey() throws Exception { Identity i = new IdentityStub("testGetPublicKey"); assertNull(i.getPublicKey()); @@ -407,6 +591,15 @@ public class IdentityTest extends TestCase { * * */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Just SecurityException verification", + targets = { + @TestTarget( + methodName = "setInfo", + methodArgs = {String.class} + ) + }) public void testSetInfo() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("setIdentityInfo")); @@ -420,6 +613,19 @@ public class IdentityTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Both method were verified", + targets = { + @TestTarget( + methodName = "getInfo", + methodArgs = {} + ), + @TestTarget( + methodName = "setInfo", + methodArgs = {String.class} + ) + }) public void testGetInfo() { Identity i = new IdentityStub("testGetInfo"); @@ -427,6 +633,15 @@ public class IdentityTest extends TestCase { assertEquals("some info", i.getInfo()); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testGetName() { Identity i = new IdentityStub("testGetName"); assertEquals ("testGetName", i.getName()); diff --git a/security/src/test/java/tests/java/security/ProviderTest.java b/security/src/test/java/tests/java/security/ProviderTest.java index fb33d79..f30dde1 100644 --- a/security/src/test/java/tests/java/security/ProviderTest.java +++ b/security/src/test/java/tests/java/security/ProviderTest.java @@ -22,6 +22,11 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -40,7 +45,7 @@ import java.util.Set; import java.util.Map.Entry; import junit.framework.TestCase; - +@TestTargetClass(Provider.class) /** * Tests for <code>Provider</code> constructor and methods * @@ -60,6 +65,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void Provider() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Not all varians of parameters were checked", + targets = { + @TestTarget( + methodName = "Provider", + methodArgs = {String.class, double.class, String.class} + ) + }) public final void testProvider() { if (!p.getProperty("Provider.id name").equals( String.valueOf(p.getName()))) { @@ -79,6 +93,15 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "clear", + methodArgs = {} + ) + }) public final void testClear() { p.clear(); if (p.getProperty("MessageDigest.SHA-1") != null) { @@ -89,6 +112,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void Provider(String, double, String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Not all varians of parameters were checked", + targets = { + @TestTarget( + methodName = "Provider", + methodArgs = {String.class, double.class, String.class} + ) + }) public final void testProviderStringdoubleString() { Provider p = new MyProvider("Provider name", 123.456, "Provider info"); if (!p.getName().equals("Provider name") || p.getVersion() != 123.456 @@ -97,18 +129,45 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public final void testGetName() { if (!p.getName().equals("MyProvider")) { fail("Incorrect provider name"); } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getVersion", + methodArgs = {} + ) + }) public final void testGetVersion() { if (p.getVersion() != 1.0) { fail("Incorrect provider version"); } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInfo", + methodArgs = {} + ) + }) public final void testGetInfo() { if (!p.getInfo().equals("Provider for testing")) { fail("Incorrect provider info"); @@ -118,6 +177,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void putAll(Map) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "putAll", + methodArgs = {java.util.Map.class} + ) + }) public final void testPutAllMap() { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd"); @@ -139,6 +207,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Set entrySet() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "entrySet", + methodArgs = {} + ) + }) public final void testEntrySet() { p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd"); @@ -191,6 +268,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Set keySet() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "keySet", + methodArgs = {} + ) + }) public final void testKeySet() { p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd"); @@ -221,6 +307,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Collection values() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "values", + methodArgs = {} + ) + }) public final void testValues() { p.put("MessageDigest.SHA-256", "aaa.bbb.ccc.ddd"); @@ -247,6 +342,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Object put(Object, Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "put", + methodArgs = {Object.class, Object.class} + ) + }) public final void testPutObjectObject() { p.put("MessageDigest.SHA-1", "aaa.bbb.ccc.ddd"); p.put("Type.Algorithm", "className"); @@ -283,6 +387,15 @@ public class ProviderTest extends TestCase { /* * Class under test for Object remove(Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "remove", + methodArgs = {Object.class} + ) + }) public final void testRemoveObject() { Object o = p.remove("MessageDigest.SHA-1"); if (!"SomeClassName".equals(o)) { @@ -296,6 +409,15 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NullPointerException checking missed", + targets = { + @TestTarget( + methodName = "getService", + methodArgs = {String.class, String.class} + ) + }) public final void testService1() { p.put("MessageDigest.SHA-1", "AnotherClassName"); Provider.Service s = p.getService("MessageDigest", "SHA-1"); @@ -328,6 +450,15 @@ public class ProviderTest extends TestCase { // } // Regression for HARMONY-2760. + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression testing: null parameters checking", + targets = { + @TestTarget( + methodName = "Provider", + methodArgs = {String.class, double.class, String.class} + ) + }) public void testConstructor() { MyProvider myProvider = new MyProvider(null, 1, null); assertNull(myProvider.getName()); @@ -336,6 +467,15 @@ public class ProviderTest extends TestCase { assertEquals("null", myProvider.getProperty("Provider.id info")); } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Regression testing", + targets = { + @TestTarget( + methodName = "getServices", + methodArgs = {} + ) + }) public final void testGetServices() { MyProvider myProvider = new MyProvider(null, 1, null); Set<Provider.Service> services = myProvider.getServices(); @@ -374,6 +514,15 @@ public class ProviderTest extends TestCase { assertTrue(actual.contains(s[2])); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression testing: SecurityException checking missed", + targets = { + @TestTarget( + methodName = "putService", + methodArgs = {Provider.Service.class} + ) + }) public final void testPutService() { MyProvider myProvider = new MyProvider(null, 1, null); Provider.Service s[] = new Provider.Service[3]; @@ -423,6 +572,15 @@ public class ProviderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression testing: SecurityException checking missed", + targets = { + @TestTarget( + methodName = "removeService", + methodArgs = {Provider.Service.class} + ) + }) public final void testRemoveService() { MyProvider myProvider = new MyProvider(null, 1, null); try { @@ -492,6 +650,15 @@ public class ProviderTest extends TestCase { /* * Class under test for void load(InputStream) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IOException checking missed", + targets = { + @TestTarget( + methodName = "load", + methodArgs = {InputStream.class} + ) + }) public final void testLoad() throws IOException { InputStream is = new ByteArrayInputStream(writeProperties()); MyProvider myProvider = new MyProvider("name", 1, "info"); @@ -516,6 +683,15 @@ public class ProviderTest extends TestCase { } // Regression test for Android: Check existence of RSA provider + @TestInfo( + level = TestLevel.TODO, + purpose = "Methods of class Provider are not checked in this test", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) public void test_RSAProvider() { try { final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); diff --git a/security/src/test/java/tests/java/security/SecureClassLoaderTest.java b/security/src/test/java/tests/java/security/SecureClassLoaderTest.java index 87568c0..0518616 100644 --- a/security/src/test/java/tests/java/security/SecureClassLoaderTest.java +++ b/security/src/test/java/tests/java/security/SecureClassLoaderTest.java @@ -22,6 +22,11 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.net.URL; import java.net.URLClassLoader; import java.nio.ByteBuffer; @@ -32,7 +37,7 @@ import java.security.SecureClassLoader; import java.security.cert.Certificate; import junit.framework.TestCase; - +@TestTargetClass(SecureClassLoader.class) /** * Unit test for SecureClassLoader. * @@ -175,6 +180,15 @@ public class SecureClassLoaderTest extends TestCase { /** * Tests default ctor */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "SecurityException checking missed", + targets = { + @TestTarget( + methodName = "SecureClassLoader", + methodArgs = {} + ) + }) public void testSecureClassLoader() { new MyClassLoader(); } @@ -182,6 +196,15 @@ public class SecureClassLoaderTest extends TestCase { /** * Tests SecureClassLoader(ClassLoader) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null parameter missed", + targets = { + @TestTarget( + methodName = "SecureClassLoader", + methodArgs = {ClassLoader.class} + ) + }) public void testSecureClassLoaderClassLoader() throws Exception { URL[] urls = new URL[] { new URL("http://localhost") }; URLClassLoader ucl = URLClassLoader.newInstance(urls); @@ -191,6 +214,15 @@ public class SecureClassLoaderTest extends TestCase { /** * Tests getPermission */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned value missed", + targets = { + @TestTarget( + methodName = "getPermissions", + methodArgs = {CodeSource.class} + ) + }) public void testGetPermissions() throws Exception { URL url = new URL("http://localhost"); CodeSource cs = new CodeSource(url, (Certificate[]) null); @@ -202,7 +234,16 @@ public class SecureClassLoaderTest extends TestCase { /** * Tests defineClass(String, byte[], int, int, CodeSource) */ - public void testDefineClassStringbyteArrayintintCodeSource() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "ClassFormatError, IndexOutOfBoundsException, SecurityException checking missed", + targets = { + @TestTarget( + methodName = "defineClass", + methodArgs = {String.class, byte[].class, int.class, int.class, CodeSource.class} + ) + }) + public void _testDefineClassStringbyteArrayintintCodeSource() { MyClassLoader ldr = new MyClassLoader(); Class klass = ldr.define(null, klassData, 0, klassData.length, null); assertEquals(klass.getName(), klassName); @@ -211,7 +252,16 @@ public class SecureClassLoaderTest extends TestCase { /** * Tests defineClass(String, ByteBuffer, CodeSource) */ - public void testDefineClassStringByteBufferCodeSource() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "ClassFormatError, SecurityException checking missed", + targets = { + @TestTarget( + methodName = "defineClass", + methodArgs = {String.class, ByteBuffer.class, CodeSource.class} + ) + }) + public void _testDefineClassStringByteBufferCodeSource() { MyClassLoader ldr = new MyClassLoader(); ByteBuffer bbuf = ByteBuffer.wrap(klassData); Class klass = ldr.define(null, bbuf, null); diff --git a/security/src/test/java/tests/java/security/SecureRandomTest.java b/security/src/test/java/tests/java/security/SecureRandomTest.java index bc33594..b5ea095 100644 --- a/security/src/test/java/tests/java/security/SecureRandomTest.java +++ b/security/src/test/java/tests/java/security/SecureRandomTest.java @@ -22,6 +22,11 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.NoSuchAlgorithmException; import java.security.Provider; import java.security.SecureRandom; @@ -30,7 +35,7 @@ import java.security.Security; import org.apache.harmony.security.tests.support.RandomImpl; import junit.framework.TestCase; - +@TestTargetClass(SecureRandom.class) /** * Tests for <code>SecureRandom</code> constructor and methods * @@ -59,6 +64,15 @@ public class SecureRandomTest extends TestCase { Security.removeProvider(p.getName()); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of negative and boundary parameters missed", + targets = { + @TestTarget( + methodName = "next", + methodArgs = {int.class} + ) + }) public final void testNext() { MySecureRandom sr = new MySecureRandom(); if (sr.nextElement(1) != 1 || sr.nextElement(2) != 3 || sr.nextElement(3) != 7) { @@ -69,6 +83,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for void setSeed(long) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of boundary parameter missed", + targets = { + @TestTarget( + methodName = "setSeed", + methodArgs = {long.class} + ) + }) public final void testSetSeedlong() { SecureRandom sr = new SecureRandom(); sr.setSeed(12345); @@ -77,6 +100,15 @@ public class SecureRandomTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter verification missed", + targets = { + @TestTarget( + methodName = "nextBytes", + methodArgs = {byte[].class} + ) + }) public final void testNextBytes() { byte[] b = new byte[5]; SecureRandom sr = new SecureRandom(); @@ -91,6 +123,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for void SecureRandom() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "SecureRandom", + methodArgs = {} + ) + }) public final void testSecureRandom() { SecureRandom sr = new SecureRandom(); if (!sr.getAlgorithm().equals("someRandom") || @@ -102,6 +143,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for void SecureRandom(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "SecureRandom", + methodArgs = {byte[].class} + ) + }) public final void testSecureRandombyteArray() { byte[] b = {1,2,3}; new SecureRandom(b); @@ -114,6 +164,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for SecureRandom getInstance(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class} + ) + }) public final void testGetInstanceString() { SecureRandom sr = null; try { @@ -129,6 +188,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for SecureRandom getInstance(String, String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, String.class} + ) + }) public final void testGetInstanceStringString() throws Exception { SecureRandom sr = SecureRandom.getInstance("someRandom", "SRProvider"); if (sr.getProvider() != p || !"someRandom".equals(sr.getAlgorithm())) { @@ -139,6 +207,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for SecureRandom getInstance(String, Provider) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "NoSuchAlgorithmException, IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {String.class, Provider.class} + ) + }) public final void testGetInstanceStringProvider() throws Exception { Provider p = new SRProvider(); SecureRandom sr = SecureRandom.getInstance("someRandom", p); @@ -150,6 +227,15 @@ public class SecureRandomTest extends TestCase { /* * Class under test for void setSeed(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with null parameter missed", + targets = { + @TestTarget( + methodName = "setSeed", + methodArgs = {byte[].class} + ) + }) public final void testSetSeedbyteArray() { byte[] b = {1,2,3}; SecureRandom sr = new SecureRandom(); @@ -159,6 +245,15 @@ public class SecureRandomTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with invalid parameter missed", + targets = { + @TestTarget( + methodName = "getSeed", + methodArgs = {int.class} + ) + }) public final void testGetSeed() { byte[] b = SecureRandom.getSeed(4); if( b.length != 4) { @@ -166,6 +261,15 @@ public class SecureRandomTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification with invalid parameter missed", + targets = { + @TestTarget( + methodName = "generateSeed", + methodArgs = {int.class} + ) + }) public final void testGenerateSeed() { SecureRandom sr = new SecureRandom(); byte[] b = sr.generateSeed(4); diff --git a/security/src/test/java/tests/java/security/SignatureTest.java b/security/src/test/java/tests/java/security/SignatureTest.java index 0719e49..810fadd 100644 --- a/security/src/test/java/tests/java/security/SignatureTest.java +++ b/security/src/test/java/tests/java/security/SignatureTest.java @@ -22,6 +22,11 @@ package tests.java.security; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; @@ -33,7 +38,7 @@ import java.security.SignatureException; import org.apache.harmony.security.tests.support.MySignature1; import junit.framework.TestCase; - +@TestTargetClass(java.security.Signature.class) /** * Tests for <code>Signature</code> constructor and methods * @@ -43,6 +48,15 @@ public class SignatureTest extends TestCase { /* * Class under test for Signature(String) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Signature", + methodArgs = {String.class} + ) + }) public void testConstructor() { String [] algorithms = { "SHA256WITHRSA", "NONEWITHDSA", "SHA384WITHRSA", "MD2WITHRSA", "MD5ANDSHA1WITHRSA", "SHA512WITHRSA", @@ -68,6 +82,15 @@ public class SignatureTest extends TestCase { /* * Class under test for Object clone() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just CloneNotSupportedException checked", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) public void testClone() { MySignature1 s = new MySignature1("ABC"); try { @@ -77,6 +100,15 @@ public class SignatureTest extends TestCase { } } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) public void testGetProvider() { MySignature1 s = new MySignature1("ABC"); @@ -84,6 +116,15 @@ public class SignatureTest extends TestCase { assertNull("provider", s.getProvider()); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) public void testGetAlgorithm() { MySignature1 s = new MySignature1("ABC"); @@ -94,6 +135,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initVerify(PublicKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initVerify", + methodArgs = {PublicKey.class} + ) + }) public void testInitVerifyPublicKey() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -105,6 +155,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initVerify(Certificate) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initVerify", + methodArgs = {java.security.cert.Certificate.class} + ) + }) public void testInitVerifyCertificate() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -116,6 +175,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initSign(PrivateKey) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initSign", + methodArgs = {PrivateKey.class} + ) + }) public void testInitSignPrivateKey() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -127,6 +195,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void initSign(PrivateKey, SecureRandom) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeyException checking missed", + targets = { + @TestTarget( + methodName = "initSign", + methodArgs = {PrivateKey.class, SecureRandom.class} + ) + }) public void testInitSignPrivateKeySecureRandom() throws InvalidKeyException { MySignature1 s = new MySignature1("ABC"); @@ -138,6 +215,15 @@ public class SignatureTest extends TestCase { /* * Class under test for byte[] sign() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned byte array missed", + targets = { + @TestTarget( + methodName = "sign", + methodArgs = {} + ) + }) public void testSign() throws Exception { MySignature1 s = new MySignature1("ABC"); try { @@ -163,6 +249,16 @@ public class SignatureTest extends TestCase { /* * Class under test for sign(byte[], offset, len) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verification of returned number of bytes missed. " + + "Different values of parameters offset and len were not tested.", + targets = { + @TestTarget( + methodName = "sign", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void testSignbyteintint() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] outbuf = new byte [10]; @@ -190,6 +286,16 @@ public class SignatureTest extends TestCase { /* * Class under test for boolean verify(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array parameter checking missed. " + + "Method's returned value checking missed. ", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {byte[].class} + ) + }) public void testVerifybyteArray() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -215,6 +321,17 @@ public class SignatureTest extends TestCase { /* * Class under test for boolean verify(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array parameter checking missed. " + + "Method's returned value checking missed. " + + "Boundary/invalid values of parameters offset and length are not checked.", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void testVerifybyteArrayintint() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -248,6 +365,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void update(byte) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Boundary testing missed. SignatureException checking missed.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte.class} + ) + }) public void testUpdatebyte() throws Exception { MySignature1 s = new MySignature1("ABC"); try { @@ -268,6 +394,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void update(byte[]) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array checking missed.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class} + ) + }) public void testUpdatebyteArray() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -289,6 +424,17 @@ public class SignatureTest extends TestCase { /* * Class under test for void update(byte[], int, int) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null array parameter checking missed. " + + "Method's returned value checking missed. " + + "Boundary/invalid values of parameters offset and length are not checked.", + targets = { + @TestTarget( + methodName = "update", + methodArgs = {byte[].class, int.class, int.class} + ) + }) public void testUpdatebyteArrayintint() throws Exception { MySignature1 s = new MySignature1("ABC"); byte[] b = {1, 2, 3, 4}; @@ -310,6 +456,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void setParameter(String, Object) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidParameterException checking missed", + targets = { + @TestTarget( + methodName = "setParameter", + methodArgs = {String.class, Object.class} + ) + }) @SuppressWarnings("deprecation") public void testSetParameterStringObject() { MySignature1 s = new MySignature1("ABC"); @@ -319,6 +474,15 @@ public class SignatureTest extends TestCase { /* * Class under test for void setParameter(AlgorithmParameterSpec) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidAlgorithmParameterException checking missed", + targets = { + @TestTarget( + methodName = "setParameter", + methodArgs = {java.security.spec.AlgorithmParameterSpec.class} + ) + }) public void testSetParameterAlgorithmParameterSpec() throws InvalidAlgorithmParameterException { MySignature1 s = new MySignature1("ABC"); try { @@ -327,6 +491,16 @@ public class SignatureTest extends TestCase { } catch (UnsupportedOperationException e){ } } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't check InvalidAlgorithmParameterException.", + targets = { + @TestTarget( + methodName = "getParameter", + methodArgs = {String.class} + ) + }) @SuppressWarnings("deprecation") public void testGetParameter() { MySignature1 s = new MySignature1("ABC"); diff --git a/security/src/test/java/tests/security/AccessControllerTest.java b/security/src/test/java/tests/security/AccessControllerTest.java index 18bffc6..17ed08b 100644 --- a/security/src/test/java/tests/security/AccessControllerTest.java +++ b/security/src/test/java/tests/security/AccessControllerTest.java @@ -16,6 +16,8 @@ package tests.security; +import dalvik.annotation.TestTargetClass; + import java.lang.reflect.Field; import java.security.AccessController; import java.security.BasicPermission; @@ -26,7 +28,7 @@ import java.security.PrivilegedAction; import java.security.ProtectionDomain; import junit.framework.TestCase; - +@TestTargetClass(AccessController.class) public class AccessControllerTest extends TestCase { private static void setProtectionDomain(Class c, ProtectionDomain pd){ diff --git a/security/src/test/java/tests/security/AllTests.java b/security/src/test/java/tests/security/AllTests.java index 05a1a34..7daa43e 100644 --- a/security/src/test/java/tests/security/AllTests.java +++ b/security/src/test/java/tests/security/AllTests.java @@ -34,9 +34,16 @@ public class AllTests { suite.addTest(org.apache.harmony.security.tests.java.security.AllTests.suite()); suite.addTest(tests.api.java.security.AllTests.suite()); suite.addTest(tests.java.security.AllTests.suite()); + + suite.addTest(tests.security.acl.AllTests.suite()); + suite.addTest(tests.security.cert.AllTests.suite()); + suite.addTest(tests.security.interfaces.AllTests.suite()); + suite.addTest(tests.security.spec.AllTests.suite()); - suite.addTest(tests.security.SecurityPermissionsTest.suite()); +// suite.addTestSuite(tests.security.SecurityPermissionsTest.class); suite.addTestSuite(tests.security.AccessControllerTest.class); + + suite.addTest(tests.api.javax.security.cert.AllTests.suite()); // $JUnit-END$ return suite; } diff --git a/security/src/test/java/tests/security/SecurityPermissionsTest.java b/security/src/test/java/tests/security/SecurityPermissionsTest.java index 9a06e27..918db8a 100644 --- a/security/src/test/java/tests/security/SecurityPermissionsTest.java +++ b/security/src/test/java/tests/security/SecurityPermissionsTest.java @@ -16,27 +16,13 @@ package tests.security; -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.io.NotActiveException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.io.SerializablePermission; -import java.io.StreamCorruptedException; -import java.security.Permission; +import dalvik.annotation.TestTargetClass; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +@TestTargetClass(java.security.Permissions.class) /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods @@ -46,10 +32,12 @@ public class SecurityPermissionsTest extends TestCase { public static final Test suite() { TestSuite suite = new TestSuite("Tests for security permissions"); - suite.addTestSuite(tests.security.permissions.JavaIoFileStreamTest.class); + suite.addTestSuite(tests.security.permissions.JavaIoFileInputStreamTest.class); + suite.addTestSuite(tests.security.permissions.JavaIoFileOutputStreamTest.class); suite.addTestSuite(tests.security.permissions.JavaIoRandomAccessFileTest.class); suite.addTestSuite(tests.security.permissions.JavaIoFileTest.class); - suite.addTestSuite(tests.security.permissions.JavaIoObjectStreamTest.class); + suite.addTestSuite(tests.security.permissions.JavaIoObjectInputStreamTest.class); + suite.addTestSuite(tests.security.permissions.JavaIoObjectOutputStreamTest.class); suite.addTestSuite(tests.security.permissions.JavaLangSystemTest.class); suite.addTestSuite(tests.security.permissions.JavaLangClassTest.class); suite.addTestSuite(tests.security.permissions.JavaLangClassLoaderTest.class); diff --git a/security/src/test/java/tests/security/acl/AclNotFoundException2Test.java b/security/src/test/java/tests/security/acl/AclNotFoundException2Test.java new file mode 100644 index 0000000..270a83e --- /dev/null +++ b/security/src/test/java/tests/security/acl/AclNotFoundException2Test.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.acl; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.acl.AclNotFoundException; + +@TestTargetClass(AclNotFoundException.class) +public class AclNotFoundException2Test extends TestCase { + + /** + * @tests java.security.acl.AclNotFoundException#AclNotFoundException() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "AclNotFoundException", + methodArgs = {} + ) + }) + public void test_Constructor() { + // Test for method java.security.acl.AclNotFoundException() + try { + if (true) { + throw new AclNotFoundException(); + } + fail("Should have thrown AclNotFoundException"); + } catch (AclNotFoundException e) { + assertEquals("AclNotFoundException.toString() should have been " + + "'java.security.acl.AclNotFoundException' but was " + + e.toString(), + "java.security.acl.AclNotFoundException", + e.toString()); + } + } +} diff --git a/security/src/test/java/tests/security/acl/AclNotFoundExceptionTest.java b/security/src/test/java/tests/security/acl/AclNotFoundExceptionTest.java new file mode 100644 index 0000000..7ac23ae --- /dev/null +++ b/security/src/test/java/tests/security/acl/AclNotFoundExceptionTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Aleksei Y. Semenov +* @version $Revision$ +*/ + +package tests.security.acl; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.acl.AclNotFoundException; + +/** + * Unit test for AclNotFoundException. + * + */ +@TestTargetClass(AclNotFoundException.class) +public class AclNotFoundExceptionTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AclNotFoundExceptionTest.class); + } + + /** + * check default constructor + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "AclNotFoundException", + methodArgs = {} + ) + }) + public void testAclNotFoundException() { + assertNotNull(new AclNotFoundException()); + assertNull(new AclNotFoundException().getMessage()); + assertNull(new AclNotFoundException().getCause()); + } + +} diff --git a/security/src/test/java/tests/security/acl/AllTests.java b/security/src/test/java/tests/security/acl/AllTests.java new file mode 100644 index 0000000..b1206c6 --- /dev/null +++ b/security/src/test/java/tests/security/acl/AllTests.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.acl; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package tests.api.java.security.acl; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package tests.api.java.security.acl;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(AclNotFoundException2Test.class); + suite.addTestSuite(AclNotFoundExceptionTest.class); + suite.addTestSuite(LastOwnerException2Test.class); + suite.addTestSuite(LastOwnerExceptionTest.class); + suite.addTestSuite(NotOwnerException2Test.class); + suite.addTestSuite(NotOwnerExceptionTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/security/src/test/java/tests/security/acl/LastOwnerException2Test.java b/security/src/test/java/tests/security/acl/LastOwnerException2Test.java new file mode 100644 index 0000000..ff5185a --- /dev/null +++ b/security/src/test/java/tests/security/acl/LastOwnerException2Test.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.acl; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.acl.LastOwnerException; + +@TestTargetClass(LastOwnerException.class) +public class LastOwnerException2Test extends TestCase { + + /** + * @tests java.security.acl.LastOwnerException#LastOwnerException() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "LastOwnerException", + methodArgs = {} + ) + }) + public void test_Constructor() { + // Test for method java.security.acl.LastOwnerException() + try { + throw new LastOwnerException(); + } catch (LastOwnerException e) { + assertEquals("LastOwnerException.toString() should have been " + + "'java.security.acl.LastOwnerException' but was " + + e.toString(), "java.security.acl.LastOwnerException", e + .toString()); + } + } +} diff --git a/security/src/test/java/tests/security/acl/LastOwnerExceptionTest.java b/security/src/test/java/tests/security/acl/LastOwnerExceptionTest.java new file mode 100644 index 0000000..0cd5a6d --- /dev/null +++ b/security/src/test/java/tests/security/acl/LastOwnerExceptionTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Aleksei Y. Semenov +* @version $Revision$ +*/ + +package tests.security.acl; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.acl.LastOwnerException; + +/** + * Unit test for LastOwnerException. + * + */ +@TestTargetClass(LastOwnerException.class) +public class LastOwnerExceptionTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(LastOwnerExceptionTest.class); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "LastOwnerException", + methodArgs = {} + ) + }) + public void testLastOwnerException() { + assertNotNull(new LastOwnerException()); + assertNull(new LastOwnerException().getMessage()); + assertNull(new LastOwnerException().getCause()); + } + +} diff --git a/security/src/test/java/tests/security/acl/NotOwnerException2Test.java b/security/src/test/java/tests/security/acl/NotOwnerException2Test.java new file mode 100644 index 0000000..21a5de8 --- /dev/null +++ b/security/src/test/java/tests/security/acl/NotOwnerException2Test.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.acl; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.acl.NotOwnerException; + +@TestTargetClass(NotOwnerException.class) +public class NotOwnerException2Test extends TestCase { + + /** + * @tests java.security.acl.NotOwnerException#NotOwnerException() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NotOwnerException", + methodArgs = {} + ) + }) + public void test_Constructor() { + // Test for method java.security.acl.NotOwnerException() + try { + throw new NotOwnerException(); + } catch (NotOwnerException e) { + assertEquals("NotOwnerException.toString() should have been " + + "'java.security.acl.NotOwnerException' but was " + + e.toString(), "java.security.acl.NotOwnerException", e + .toString()); + } + } +} diff --git a/security/src/test/java/tests/security/acl/NotOwnerExceptionTest.java b/security/src/test/java/tests/security/acl/NotOwnerExceptionTest.java new file mode 100644 index 0000000..2e0e22e --- /dev/null +++ b/security/src/test/java/tests/security/acl/NotOwnerExceptionTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Aleksei Y. Semenov +* @version $Revision$ +*/ + +package tests.security.acl; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.acl.NotOwnerException; + +/** + * Unit test for NotOwnerException. + * + */ +@TestTargetClass(NotOwnerException.class) +public class NotOwnerExceptionTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(NotOwnerExceptionTest.class); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "NotOwnerException", + methodArgs = {} + ) + }) + public void testNotOwnerException() { + assertNotNull(new NotOwnerException()); + assertNull(new NotOwnerException().getMessage()); + assertNull(new NotOwnerException().getCause()); + } + +} diff --git a/security/src/test/java/tests/security/cert/AllTests.java b/security/src/test/java/tests/security/cert/AllTests.java new file mode 100644 index 0000000..b5d0782 --- /dev/null +++ b/security/src/test/java/tests/security/cert/AllTests.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package tests.api.java.security.cert; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package tests.api.java.security.cert;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(CRLExceptionTest.class); + suite.addTestSuite(CRLTest.class); + suite.addTestSuite(CertPathBuilder1Test.class); +// suite.addTestSuite(CertPathBuilder2Test.class); + suite.addTestSuite(CertPathBuilderExceptionTest.class); + suite.addTestSuite(CertPathBuilderSpiTest.class); + suite.addTestSuite(CertPathCertPathRepTest.class); + suite.addTestSuite(CertPathTest.class); + suite.addTestSuite(CertPathValidator1Test.class); +// suite.addTestSuite(CertPathValidator2Test.class); + suite.addTestSuite(CertPathValidator3Test.class); + suite.addTestSuite(CertPathValidatorExceptionTest.class); + suite.addTestSuite(CertPathValidatorSpiTest.class); + suite.addTestSuite(CertStore1Test.class); + suite.addTestSuite(CertStoreExceptionTest.class); + suite.addTestSuite(CertStoreSpiTest.class); + suite.addTestSuite(CertificateCertificateRepTest.class); + suite.addTestSuite(CertificateEncodingException2Test.class); + suite.addTestSuite(CertificateEncodingExceptionTest.class); + suite.addTestSuite(CertificateException2Test.class); + suite.addTestSuite(CertificateExceptionTest.class); + suite.addTestSuite(CertificateExpiredExceptionTest.class); + suite.addTestSuite(CertificateFactory1Test.class); +// suite.addTestSuite(CertificateFactory2Test.class); + suite.addTestSuite(CertificateFactory3Test.class); + suite.addTestSuite(CertificateFactory4Test.class); + suite.addTestSuite(CertificateFactorySpiTest.class); + suite.addTestSuite(CertificateNotYetValidExceptionTest.class); + suite.addTestSuite(CertificateParsingExceptionTest.class); + suite.addTestSuite(CertificateTest.class); + suite.addTestSuite(CollectionCertStoreParametersTest.class); + suite.addTestSuite(LDAPCertStoreParametersTest.class); + suite.addTestSuite(PKIXBuilderParametersTest.class); + suite.addTestSuite(PKIXCertPathBuilderResultTest.class); + suite.addTestSuite(PKIXCertPathCheckerTest.class); + suite.addTestSuite(PKIXCertPathValidatorResultTest.class); + suite.addTestSuite(PKIXParametersTest.class); + suite.addTestSuite(PolicyQualifierInfoTest.class); + suite.addTestSuite(TrustAnchorTest.class); +// suite.addTestSuite(X509CRL2Test.class); +// suite.addTestSuite(X509CRLEntry2Test.class); + suite.addTestSuite(X509CRLEntryTest.class); + suite.addTestSuite(X509CRLSelector2Test.class); + suite.addTestSuite(X509CRLSelectorTest.class); + suite.addTestSuite(X509CRLTest.class); + suite.addTestSuite(X509CertSelectorTest.class); + suite.addTestSuite(X509Certificate2Test.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/security/src/test/java/tests/security/cert/CRLExceptionTest.java b/security/src/test/java/tests/security/cert/CRLExceptionTest.java new file mode 100644 index 0000000..bd2c72c --- /dev/null +++ b/security/src/test/java/tests/security/cert/CRLExceptionTest.java @@ -0,0 +1,273 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CRLException; + +/** + * Tests for <code>CRLException</code> class constructors and methods. + * + */ +@TestTargetClass(CRLException.class) +public class CRLExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CRLExceptionTests. + * + * @param arg0 + */ + public CRLExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CRLException()</code> constructor Assertion: constructs + * CRLException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {} + ) + }) + public void testCRLException01() { + CRLException tE = new CRLException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CRLException(String)</code> constructor Assertion: + * constructs CRLException with detail message msg. Parameter + * <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCRLException02() { + CRLException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CRLException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CRLException(String)</code> constructor Assertion: + * constructs CRLException when <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCRLException03() { + String msg = null; + CRLException tE = new CRLException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CRLException(Throwable)</code> constructor Assertion: + * constructs CRLException when <code>cause</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCRLException04() { + Throwable cause = null; + CRLException tE = new CRLException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CRLException(Throwable)</code> constructor Assertion: + * constructs CRLException when <code>cause</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCRLException05() { + CRLException tE = new CRLException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CRLException(String, Throwable)</code> constructor + * Assertion: constructs CRLException when <code>cause</code> is null + * <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCRLException06() { + CRLException tE = new CRLException(null, null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CRLException(String, Throwable)</code> constructor + * Assertion: constructs CRLException when <code>cause</code> is null + * <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the second parameter.", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCRLException07() { + CRLException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CRLException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CRLException(String, Throwable)</code> constructor + * Assertion: constructs CRLException when <code>cause</code> is not null + * <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the first parameter.", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCRLException08() { + CRLException tE = new CRLException(null, tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CRLException(String, Throwable)</code> constructor + * Assertion: constructs CRLException when <code>cause</code> is not null + * <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CRLException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCRLException09() { + CRLException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CRLException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CRLTest.java b/security/src/test/java/tests/security/cert/CRLTest.java new file mode 100644 index 0000000..0adae13 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CRLTest.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CRL; +import java.security.cert.Certificate; + +import org.apache.harmony.security.tests.support.SpiEngUtils; + +/** + * Tests for <code>java.security.cert.CRL</code> fields and methods + * + */ +@TestTargetClass(CRL.class) +public class CRLTest extends TestCase { + + public static final String[] validValues = { "X.509", "x.509" }; + + private final static String[] invalidValues = SpiEngUtils.invalidValues; + + /** + * Constructor for CRLTest. + * @param name + */ + public CRLTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test for <code>CRL(String type)</code> constructor<br> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter missed", + targets = { + @TestTarget( + methodName = "CRL", + methodArgs = {java.lang.String.class} + ) + }) + public final void testConstructor() { + for (int i = 0; i< validValues.length; i++) { + CRL crl = new MyCRL(validValues[i]); + assertEquals(validValues[i], crl.getType()); + } + + for (int i = 0; i< invalidValues.length; i++) { + CRL crl = new MyCRL(invalidValues[i]); + assertEquals(invalidValues[i], crl.getType()); + } + } + + + /** + * Test #1 for <code>getType()</code> method<br> + * Assertion: returns <code>CRL</code> type + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public final void testGetType01() { + CRL crl = new MyCRL("TEST_TYPE"); + assertEquals("TEST_TYPE", crl.getType()); + } + + /** + * Test #2 for <code>getType()</code> method<br> + * Assertion: returns <code>CRL</code> type + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public final void testGetType02() { + CRL crl = new MyCRL(null); + assertNull(crl.getType()); + } + + // + // the following tests just call methods + // that are abstract in <code>Certificate</code> + // (So they just like signature tests) + // + + /** + * Test for <code>toString()</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() { + CRL crl = new MyCRL("TEST_TYPE"); + crl.toString(); + } + + /** + * Test for <code>isRevoked()</code> method + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "isRevoked", + methodArgs = {java.security.cert.Certificate.class} + ) + }) + public final void testIsRevoked() { + CRL crl = new MyCRL("TEST_TYPE"); + crl.isRevoked(null); + } + + class MyCRL extends CRL { + + protected MyCRL(String type) { + super(type); + } + + @Override + public boolean isRevoked(Certificate cert) { + return false; + } + + @Override + public String toString() { + return null; + } + + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathBuilder1Test.java b/security/src/test/java/tests/security/cert/CertPathBuilder1Test.java new file mode 100644 index 0000000..be6664e --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathBuilder1Test.java @@ -0,0 +1,618 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CertPathBuilder; +import java.security.cert.CertPathBuilderException; +import java.security.cert.CertPathBuilderSpi; +import java.security.cert.CertificateException; + +import org.apache.harmony.security.tests.support.cert.MyCertPathBuilderSpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; +import tests.support.Support_Exec; + +/** + * Tests for <code>CertPathBuilder</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertPathBuilder.class) +public class CertPathBuilder1Test extends TestCase { + + /** + * Constructor for CertPathBuilderTests. + * @param name + */ + public CertPathBuilder1Test(String name) { + super(name); + } + public static final String srvCertPathBuilder = "CertPathBuilder"; + + public static final String defaultType = "PKIX"; + public static final String [] validValues = { + "PKIX", "pkix", "PkiX", "pKiX" }; + + private static String [] invalidValues = SpiEngUtils.invalidValues; + + private static boolean PKIXSupport = false; + + private static Provider defaultProvider; + private static String defaultProviderName; + + private static String NotSupportMsg = ""; + + public static final String DEFAULT_TYPE_PROPERTY = "certpathbuilder.type"; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + srvCertPathBuilder); + PKIXSupport = (defaultProvider != null); + defaultProviderName = (PKIXSupport ? defaultProvider.getName() : null); + NotSupportMsg = defaultType.concat(" is not supported"); + } + private static CertPathBuilder[] createCPBs() { + if (!PKIXSupport) { + fail(NotSupportMsg); + return null; + } + try { + CertPathBuilder[] certPBs = new CertPathBuilder[3]; + certPBs[0] = CertPathBuilder.getInstance(defaultType); + certPBs[1] = CertPathBuilder.getInstance(defaultType, + defaultProviderName); + certPBs[2] = CertPathBuilder.getInstance(defaultType, + defaultProvider); + return certPBs; + } catch (Exception e) { + return null; + } + } + + /** + * @tests java.security.cert.CertPathBuilder#getDefaultType() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDefaultType", + methodArgs = {} + ) + }) + public void _test_getDefaultType() throws Exception { + + // Regression for HARMONY-2785 + + // test: default value + assertNull(Security.getProperty(DEFAULT_TYPE_PROPERTY)); + assertEquals("PKIX", CertPathBuilder.getDefaultType()); + + // test: security property. fork new VM to keep testing env. clean + Support_Exec.execJava(new String[] { DefaultType.class.getName() }, + null, true); + } + + public static class DefaultType { + + public static void main(String[] args) { + + Security.setProperty(DEFAULT_TYPE_PROPERTY, "MyType"); + assertEquals("MyType", CertPathBuilder.getDefaultType()); + + Security.setProperty(DEFAULT_TYPE_PROPERTY, "AnotherType"); + assertEquals("AnotherType", CertPathBuilder.getDefaultType()); + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not correct + * or it is not available + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NoSuchAlgorithmException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathBuilder02() throws NoSuchAlgorithmException { + try { + CertPathBuilder.getInstance(null); + fail("No expected NullPointerException"); + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathBuilder.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies positive functionality.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathBuilder03() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++) { + CertPathBuilder cpb = CertPathBuilder.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", cpb.getAlgorithm(), validValues[i]); + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: throws IllegalArgumentException when provider is null or empty + * + * FIXME: verify what exception will be thrown if provider is empty + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathBuilder04() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + String provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertPathBuilder.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown thrown"); + } catch (IllegalArgumentException e) { + } + try { + CertPathBuilder.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown thrown"); + } catch (IllegalArgumentException e) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NoSuchProviderException when provider has invalid value + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getInstance throws NoSuchProviderException " + + "when provider has invalid value.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathBuilder05() + throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++ ) { + for (int j = 1; j < invalidValues.length; j++) { + try { + CertPathBuilder.getInstance(validValues[i], invalidValues[j]); + fail("NoSuchProviderException must be hrown"); + } catch (NoSuchProviderException e1) { + } + } + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not correct + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException when algorithm is null; " + + "verifies NoSuchAlgorithmException when algorithm is not correct.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathBuilder06() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + try { + CertPathBuilder.getInstance(null, defaultProviderName); + fail("No expected NullPointerException"); + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathBuilder.getInstance(invalidValues[i], defaultProviderName); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e1) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathBuilder07() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathBuilder certPB; + for (int i = 0; i < validValues.length; i++) { + certPB = CertPathBuilder.getInstance(validValues[i], defaultProviderName); + assertEquals("Incorrect algorithm", certPB.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider name", certPB.getProvider().getName(), defaultProviderName); + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> method + * Assertion: throws IllegalArgumentException when provider is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getInstance method throws " + + "IllegalArgumentException when provider is null method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testCertPathBuilder08() + throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + Provider prov = null; + for (int t = 0; t < validValues.length; t++ ) { + try { + CertPathBuilder.getInstance(validValues[t], prov); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e1) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not correct + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getInstance method throws NullPointerException " + + "when algorithm is null, throws NoSuchAlgorithmException when " + + "algorithm is not correct.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testCertPathBuilder09() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + try { + CertPathBuilder.getInstance(null, defaultProvider); + fail("No expected NullPointerException"); + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathBuilder.getInstance(invalidValues[i], defaultProvider); + fail("NoSuchAlgorithm must be thrown"); + } catch (NoSuchAlgorithmException e1) { + } + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getInstance returns CertPathBuilder object.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathBuilder10() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathBuilder certPB; + for (int i = 0; i < invalidValues.length; i++) { + certPB = CertPathBuilder.getInstance(validValues[i], defaultProvider); + assertEquals("Incorrect algorithm", certPB.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider name", certPB.getProvider(), defaultProvider); + } + } + /** + * Test for <code>build(CertPathParameters params)</code> method + * Assertion: throws InvalidAlgorithmParameterException params is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that build method throws " + + "InvalidAlgorithmParameterException if a parameter is null.", + targets = { + @TestTarget( + methodName = "build", + methodArgs = {java.security.cert.CertPathParameters.class} + ) + }) + public void testCertPathBuilder11() + throws NoSuchAlgorithmException, NoSuchProviderException, + CertPathBuilderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathBuilder [] certPB = createCPBs(); + assertNotNull("CertPathBuilder objects were not created", certPB); + for (int i = 0; i < certPB.length; i++ ){ + try { + certPB[i].build(null); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch(InvalidAlgorithmParameterException e) { + } + } + } + /** + * Test for + * <code>CertPathBuilder</code> constructor + * Assertion: returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathBuilder", + methodArgs = {java.security.cert.CertPathBuilderSpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void testCertPathBuilder12() + throws CertificateException, NoSuchProviderException, + NoSuchAlgorithmException, InvalidAlgorithmParameterException, + CertPathBuilderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathBuilderSpi spi = new MyCertPathBuilderSpi(); + CertPathBuilder certPB = new myCertPathBuilder(spi, + defaultProvider, defaultType); + assertEquals("Incorrect algorithm", certPB.getAlgorithm(), defaultType); + assertEquals("Incorrect provider", certPB.getProvider(), defaultProvider); + try { + certPB.build(null); + fail("CertPathBuilderException must be thrown "); + } catch (CertPathBuilderException e) { + } + certPB = new myCertPathBuilder(null, null, null); + assertNull("Incorrect algorithm", certPB.getAlgorithm()); + assertNull("Incorrect provider", certPB.getProvider()); + try { + certPB.build(null); + fail("NullPointerException must be thrown "); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>getAlgorithm()</code> method Assertion: returns + * CertPathBuilder object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) + public void testCertPathBuilder13() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + + for (int i = 0; i < validValues.length; i++) { + CertPathBuilder cpb = CertPathBuilder.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", cpb.getAlgorithm(), + validValues[i]); + try { + cpb = CertPathBuilder.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect algorithm", cpb.getAlgorithm(), + validValues[i]); + } catch (NoSuchProviderException e) { + fail("Unexpected NoSuchProviderException exeption " + + e.getMessage()); + } + + try { + cpb = CertPathBuilder.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect algorithm", cpb.getAlgorithm(), + validValues[i]); + } catch (NoSuchProviderException e) { + fail("Unexpected NoSuchProviderException " + e.getMessage()); + } + } + } + + /** + * Test for <code>getProvider()</code> method Assertion: returns + * CertPathBuilder object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) + public void testCertPathBuilder14() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + + for (int i = 0; i < validValues.length; i++) { + CertPathBuilder cpb2 = CertPathBuilder.getInstance(validValues[i], + defaultProvider); + assertEquals("Incorrect provider", cpb2.getProvider(), + defaultProvider); + + try { + CertPathBuilder cpb3 = CertPathBuilder.getInstance( + validValues[i], defaultProviderName); + assertEquals("Incorrect provider", cpb3.getProvider(), + defaultProvider); + } catch (NoSuchProviderException e) { + fail("Unexpected NoSuchProviderException " + e.getMessage()); + } + } + + } + + public static void main(String args[]) { + junit.textui.TestRunner.run(CertPathBuilder1Test.class); + } + +} +/** + * Additional class to verify CertPathBuilder constructor + */ +class myCertPathBuilder extends CertPathBuilder { + + private static Provider provider; + + public myCertPathBuilder(CertPathBuilderSpi spi, Provider prov, String type) { + super(spi, prov, type); + } + + public static CertPathBuilder getInstance(String algorithm) + throws NoSuchAlgorithmException { + myCertPathBuilder mcpb = new myCertPathBuilder(null, null, null); + provider = mcpb.new MyProvider(); + return CertPathBuilder.getInstance(algorithm); + } + + public Provider getMyProvider() { + return provider; + } + + public class MyProvider extends Provider { + + private static final long serialVersionUID = -6537447905658191184L; + + MyProvider() { + super("MyProvider", 1.0, "Provider for testing"); + } + + MyProvider(String name, double version, String info) { + super(name, version, info); + } + + public void putService(Provider.Service s) { + super.putService(s); + } + + public void removeService(Provider.Service s) { + super.removeService(s); + } + } + +} diff --git a/security/src/test/java/tests/security/cert/CertPathBuilder2Test.java b/security/src/test/java/tests/security/cert/CertPathBuilder2Test.java new file mode 100644 index 0000000..967c3a6 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathBuilder2Test.java @@ -0,0 +1,290 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import tests.security.cert.myCertPathBuilder.MyProvider; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CertPathBuilder; +import java.security.cert.CertPathBuilderException; +import java.security.cert.CertPathBuilderResult; + +import org.apache.harmony.security.tests.support.SpiEngUtils; +/** + * Tests for CertPathBuilder class constructors and methods + * + */ +@TestTargetClass(CertPathBuilder.class) +public class CertPathBuilder2Test extends TestCase { + private static final String defaultAlg = "CertPB"; + private static final String CertPathBuilderProviderClass = "tests.security.cert.support.cert.MyCertPathBuilderSpi"; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + private static final String[] validValues; + + static { + validValues = new String[4]; + validValues[0] = defaultAlg; + validValues[1] = defaultAlg.toLowerCase(); + validValues[2] = "CeRtPb"; + validValues[3] = "cERTpb"; + } + + Provider mProv; + + protected void setUp() throws Exception { + super.setUp(); + mProv = (new SpiEngUtils()).new MyProvider("MyCertPathBuilderProvider", + "Provider for testing", CertPathBuilder1Test.srvCertPathBuilder + .concat(".").concat(defaultAlg), + CertPathBuilderProviderClass); + Security.insertProviderAt(mProv, 1); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + Security.removeProvider(mProv.getName()); + } + + /** + * Constructor for CertPathBuilder2Test. + * + * @param arg0 + */ + public CertPathBuilder2Test(String arg0) { + super(arg0); + } + + private void checkResult(CertPathBuilder certBuild) + throws InvalidAlgorithmParameterException, + CertPathBuilderException { + String dt = CertPathBuilder.getDefaultType(); + String propName = CertPathBuilder1Test.DEFAULT_TYPE_PROPERTY; + String dtN; + for (int i = 0; i <invalidValues.length; i++) { + Security.setProperty(propName, invalidValues[i]); + dtN = CertPathBuilder.getDefaultType(); + if (!dtN.equals(invalidValues[i]) && !dtN.equals(dt)) { + fail("Incorrect default type: ".concat(dtN)); + } + } + Security.setProperty(propName, dt); + assertEquals("Incorrect default type", CertPathBuilder.getDefaultType(), + dt); + try { + certBuild.build(null); + fail("CertPathBuilderException must be thrown"); + } catch (CertPathBuilderException e) { + } + CertPathBuilderResult cpbResult = certBuild.build(null); + assertNull("Not null CertPathBuilderResult", cpbResult); + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertions: + * throws + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not correct + * returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void _testGetInstance01() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException, CertPathBuilderException { + try { + CertPathBuilder.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathBuilder.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + CertPathBuilder cerPB; + for (int i = 0; i < validValues.length; i++) { + cerPB = CertPathBuilder.getInstance(validValues[i]); + assertEquals("Incorrect type", cerPB.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", cerPB.getProvider(), mProv); + checkResult(cerPB); + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not correct + * throws IllegalArgumentException when provider is null or empty; + * throws NoSuchProviderException when provider is available; + * returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void _testGetInstance02() throws NoSuchAlgorithmException, + NoSuchProviderException, IllegalArgumentException, + InvalidAlgorithmParameterException, CertPathBuilderException { + try { + CertPathBuilder.getInstance(null, mProv.getName()); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathBuilder.getInstance(invalidValues[i], mProv + .getName()); + fail("NoSuchAlgorithmException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + String prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertPathBuilder.getInstance(validValues[i], prov); + fail("IllegalArgumentException must be thrown when provider is null (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + try { + CertPathBuilder.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + for (int i = 0; i < validValues.length; i++) { + for (int j = 1; j < invalidValues.length; j++) { + try { + CertPathBuilder.getInstance(validValues[i], + invalidValues[j]); + fail("NoSuchProviderException must be thrown (type: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + CertPathBuilder cerPB; + for (int i = 0; i < validValues.length; i++) { + cerPB = CertPathBuilder.getInstance(validValues[i], mProv + .getName()); + assertEquals("Incorrect type", cerPB.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", cerPB.getProvider().getName(), + mProv.getName()); + checkResult(cerPB); + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> + * method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not correct + * returns CertPathBuilder object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void _testGetInstance03() throws NoSuchAlgorithmException, + IllegalArgumentException, + InvalidAlgorithmParameterException, CertPathBuilderException { + try { + CertPathBuilder.getInstance(null, mProv); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathBuilder.getInstance(invalidValues[i], mProv); + fail("NoSuchAlgorithmException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + Provider prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertPathBuilder.getInstance(validValues[i], prov); + fail("IllegalArgumentException must be thrown when provider is null (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + CertPathBuilder cerPB; + for (int i = 0; i < validValues.length; i++) { + cerPB = CertPathBuilder.getInstance(validValues[i], mProv); + assertEquals("Incorrect type", cerPB.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", cerPB.getProvider(), mProv); + checkResult(cerPB); + } + } + public static void main(String args[]) { + junit.textui.TestRunner.run(CertPathBuilder2Test.class); + } + + +} diff --git a/security/src/test/java/tests/security/cert/CertPathBuilderExceptionTest.java b/security/src/test/java/tests/security/cert/CertPathBuilderExceptionTest.java new file mode 100644 index 0000000..f78a849 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathBuilderExceptionTest.java @@ -0,0 +1,278 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertPathBuilderException; + + +/** + * Tests for <code>CertPathBuilderException</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertPathBuilderException.class) +public class CertPathBuilderExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertPathBuilderExceptionTests. + * + * @param arg0 + */ + public CertPathBuilderExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertPathBuilderException()</code> constructor Assertion: + * constructs CertPathBuilderException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {} + ) + }) + public void testCertPathBuilderException01() { + CertPathBuilderException tE = new CertPathBuilderException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathBuilderException(String)</code> constructor + * Assertion: constructs CertPathBuilderException with detail message msg. + * Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathBuilderException02() { + CertPathBuilderException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathBuilderException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertPathBuilderException(String)</code> constructor + * Assertion: constructs CertPathBuilderException when <code>msg</code> is + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathBuilderException03() { + String msg = null; + CertPathBuilderException tE = new CertPathBuilderException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathBuilderException(Throwable)</code> constructor + * Assertion: constructs CertPathBuilderException when <code>cause</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertPathBuilderException04() { + Throwable cause = null; + CertPathBuilderException tE = new CertPathBuilderException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathBuilderException(Throwable)</code> constructor + * Assertion: constructs CertPathBuilderException when <code>cause</code> + * is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertPathBuilderException05() { + CertPathBuilderException tE = new CertPathBuilderException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertPathBuilderException(String, Throwable)</code> + * constructor Assertion: constructs CertPathBuilderException when + * <code>cause</code> is null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathBuilderException06() { + CertPathBuilderException tE = new CertPathBuilderException(null, null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathBuilderException(String, Throwable)</code> + * constructor Assertion: constructs CertPathBuilderException when + * <code>cause</code> is null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the second parameter.", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathBuilderException07() { + CertPathBuilderException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathBuilderException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertPathBuilderException(String, Throwable)</code> + * constructor Assertion: constructs CertPathBuilderException when + * <code>cause</code> is not null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the first parameter.", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathBuilderException08() { + CertPathBuilderException tE = new CertPathBuilderException(null, tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertPathBuilderException(String, Throwable)</code> + * constructor Assertion: constructs CertPathBuilderException when + * <code>cause</code> is not null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "CertPathBuilderException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathBuilderException09() { + CertPathBuilderException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathBuilderException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathBuilderSpiTest.java b/security/src/test/java/tests/security/cert/CertPathBuilderSpiTest.java new file mode 100644 index 0000000..4d3db90 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathBuilderSpiTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CertPathBuilderException; +import java.security.cert.CertPathBuilderResult; +import java.security.cert.CertPathBuilderSpi; +import java.security.cert.CertPathParameters; + +import org.apache.harmony.security.tests.support.cert.MyCertPathBuilderSpi; + +/** + * Tests for <code>CertPathBuilderSpi</code> class constructors and methods. + * + */ +@TestTargetClass(CertPathBuilderSpi.class) +public class CertPathBuilderSpiTest extends TestCase { + + /** + * Constructor for CertPathBuilderSpiTest. + * + * @param arg0 + */ + public CertPathBuilderSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>CertPathBuilderSpi</code> constructor Assertion: + * constructs CertPathBuilderSpi + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathBuilderSpi", + methodArgs = {} + ), + @TestTarget( + methodName = "engineBuild", + methodArgs = {java.security.cert.CertPathParameters.class} + ) + }) + public void testCertPathBuilderSpi01() throws CertPathBuilderException, + InvalidAlgorithmParameterException { + CertPathBuilderSpi certPathBuilder = new MyCertPathBuilderSpi(); + CertPathParameters cpp = null; + try { + certPathBuilder.engineBuild(cpp); + fail("CertPathBuilderException must be thrown"); + } catch (CertPathBuilderException e) { + } + CertPathBuilderResult cpbResult = certPathBuilder.engineBuild(cpp); + assertNull("Not null CertPathBuilderResult", cpbResult); + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathCertPathRepTest.java b/security/src/test/java/tests/security/cert/CertPathCertPathRepTest.java new file mode 100644 index 0000000..682fc37 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathCertPathRepTest.java @@ -0,0 +1,57 @@ +package tests.security.cert; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.security.cert.CertPath; + +import org.apache.harmony.security.tests.support.cert.MyCertPath; +import org.apache.harmony.security.tests.support.cert.MyCertPath.MyCertPathRep; + +import java.security.cert.CertPathBuilderSpi; + +import junit.framework.TestCase; + +@TestTargetClass(CertPath.class) +public class CertPathCertPathRepTest extends TestCase { + + private static final byte[] testEncoding = new byte[] { (byte) 1, (byte) 2, + (byte) 3, (byte) 4, (byte) 5 }; + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test for <code>CertPath.CertPathRep(String type, byte[] data)</code> + * method<br> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null/invalid parameters checking missed", + targets = { + @TestTarget( + methodName = "!CertPathRep", + methodArgs = {String.class, byte.class} + ) + }) + public final void testCertPathCertPathRep() { + MyCertPath cp = new MyCertPath(testEncoding); + MyCertPathRep rep = cp.new MyCertPathRep("MyEncoding", testEncoding); + assertEquals(testEncoding, rep.getData()); + assertEquals("MyEncoding", rep.getType()); + + try { + cp.new MyCertPathRep(null, null); + } catch (Exception e) { + fail("Unexpected exeption " + e.getMessage()); + } + + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathTest.java b/security/src/test/java/tests/security/cert/CertPathTest.java new file mode 100644 index 0000000..e926932 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathTest.java @@ -0,0 +1,338 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ObjectStreamException; +import java.security.cert.CertPath; +import java.security.cert.CertificateEncodingException; +import java.util.Arrays; + +import org.apache.harmony.security.tests.support.cert.MyCertPath; + +/** + * Tests for <code>CertPath</code> fields and methods + * + */ +@TestTargetClass(CertPath.class) +public class CertPathTest extends TestCase { + /** + * Meaningless cert path encoding just for testing purposes + */ + private static final byte[] testEncoding = new byte[] { + (byte)1, (byte)2, (byte)3, (byte)4, (byte)5 + }; + + /** + * Constructor for CertPathTest. + * @param name + */ + public CertPathTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test for <code>CertPath(String type)</code> method<br> + * Assertion: returns hash of the <code>Certificate</code> instance + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "String/null parameters checking missed", + targets = { + @TestTarget( + methodName = "CertPath", + methodArgs = {java.lang.String.class} + ) + }) + public final void testCertPath() { + try { + CertPath cp1 = new MyCertPath(testEncoding); + assertEquals("MyEncoding", cp1.getType()); + assertTrue(Arrays.equals(testEncoding, cp1.getEncoded())); + } catch (CertificateEncodingException e) { + fail("Unexpected CertificateEncodingException " + e.getMessage()); + } + } + + /** + * Test for <code>hashCode()</code> method<br> + * Assertion: returns hash of the <code>Certificate</code> instance + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify hash codes of non equal objects.", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode() { + CertPath cp1 = new MyCertPath(testEncoding); + CertPath cp2 = new MyCertPath(testEncoding); + + assertTrue(cp1.hashCode() == cp2.hashCode()); + } + + /** + * Test for <code>hashCode()</code> method<br> + * Assertion: hash code of equal objects should be the same + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify hash codes of non equal objects.", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCodeEqualsObject() { + CertPath cp1 = new MyCertPath(testEncoding); + CertPath cp2 = new MyCertPath(testEncoding); + assertTrue((cp1.hashCode() == cp2.hashCode()) && cp1.equals(cp2)); + } + + /** + * Test for <code>getType()</code> method<br> + * Assertion: returns cert path type + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public final void testGetType() { + assertEquals("MyEncoding", new MyCertPath(testEncoding).getType()); + } + + /** + * Test #1 for <code>equals(Object)</code> method<br> + * Assertion: object equals to itself + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that object equals to itself.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject01() { + CertPath cp1 = new MyCertPath(testEncoding); + assertTrue(cp1.equals(cp1)); + } + + /** + * Test for <code>equals(Object)</code> method<br> + * Assertion: object equals to other <code>CertPath</code> + * instance with the same state + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that CertPath object equals to other CertPath " + + "with the same state.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject02() { + CertPath cp1 = new MyCertPath(testEncoding); + CertPath cp2 = new MyCertPath(testEncoding); + assertTrue(cp1.equals(cp2) && cp2.equals(cp1)); + } + + /** + * Test for <code>equals(Object)</code> method<br> + * Assertion: object not equals to <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject03() { + CertPath cp1 = new MyCertPath(testEncoding); + assertFalse(cp1.equals(null)); + } + + /** + * Test for <code>equals(Object)</code> method<br> + * Assertion: object not equals to other which is not + * instance of <code>CertPath</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies non equal objects.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject04() { + CertPath cp1 = new MyCertPath(testEncoding); + assertFalse(cp1.equals("MyEncoding")); + } + + /** + * Test for <code>toString()</code> method<br> + * Assertion: returns string representation of + * <code>CertPath</code> object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() { + CertPath cp1 = new MyCertPath(testEncoding); + assertNotNull(cp1.toString()); + } + + // + // the following tests just call methods + // that are abstract in <code>CertPath</code> + // (So they just like signature tests) + // + + /** + * This test just calls <code>getCertificates()</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "getCertificates", + methodArgs = {} + ) + }) + public final void testGetCertificates() { + CertPath cp1 = new MyCertPath(testEncoding); + cp1.getCertificates(); + } + + /** + * This test just calls <code>getEncoded()</code> method<br> + * + * @throws CertificateEncodingException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded() throws CertificateEncodingException { + CertPath cp1 = new MyCertPath(testEncoding); + cp1.getEncoded(); + } + + /** + * This test just calls <code>getEncoded(String)</code> method<br> + * + * @throws CertificateEncodingException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {java.lang.String.class} + ) + }) + public final void testGetEncodedString() throws CertificateEncodingException { + CertPath cp1 = new MyCertPath(testEncoding); + cp1.getEncoded("MyEncoding"); + } + + /** + * This test just calls <code>getEncodings()</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "getEncodings", + methodArgs = {} + ) + }) + public final void testGetEncodings() { + CertPath cp1 = new MyCertPath(testEncoding); + cp1.getEncodings(); + } + + /** + * This test just calls <code>writeReplace()</code> method<br> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify ObjectStreamException.", + targets = { + @TestTarget( + methodName = "writeReplace", + methodArgs = {} + ) + }) + public final void testWriteReplace() { + try { + MyCertPath cp1 = new MyCertPath(testEncoding); + Object obj = cp1.writeReplace(); + assertTrue(obj.toString().contains( + "java.security.cert.CertPath$CertPathRep")); + } catch (ObjectStreamException e) { + fail("Unexpected ObjectStreamException " + e.getMessage()); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathValidator1Test.java b/security/src/test/java/tests/security/cert/CertPathValidator1Test.java new file mode 100644 index 0000000..8602a9c --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathValidator1Test.java @@ -0,0 +1,610 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CertPathParameters; +import java.security.cert.CertPathValidator; +import java.security.cert.CertPathValidatorException; +import java.security.cert.CertPathValidatorSpi; +import java.security.cert.CertificateException; + +import org.apache.harmony.security.tests.support.cert.MyCertPath; +import org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +/** + * Tests for <code>CertPathValidator</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertPathValidator.class) +public class CertPathValidator1Test extends TestCase { + + /** + * Constructor for CertPathValidatorTests. + * @param name + */ + public CertPathValidator1Test(String name) { + super(name); + } + public static final String srvCertPathValidator = "CertPathValidator"; + + private static final String defaultType = "PKIX"; + public static final String [] validValues = { + "PKIX", "pkix", "PkiX", "pKiX" }; + + private static String [] invalidValues = SpiEngUtils.invalidValues; + + private static boolean PKIXSupport = false; + + private static Provider defaultProvider; + private static String defaultProviderName; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + srvCertPathValidator); + PKIXSupport = (defaultProvider != null); + defaultProviderName = (PKIXSupport ? defaultProvider.getName() : null); + NotSupportMsg = defaultType.concat(" is not supported"); + } + + + + private static CertPathValidator[] createCPVs() { + if (!PKIXSupport) { + fail(NotSupportMsg); + return null; + } + try { + CertPathValidator[] certPVs = new CertPathValidator[3]; + certPVs[0] = CertPathValidator.getInstance(defaultType); + certPVs[1] = CertPathValidator.getInstance(defaultType, + defaultProviderName); + certPVs[2] = CertPathValidator.getInstance(defaultType, + defaultProvider); + return certPVs; + } catch (Exception e) { + return null; + } + } + + + /** + * Test for <code>getDefaultType()</code> method + * Assertion: returns security property "certpathvalidator.type" or "PKIX" + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDefaultType", + methodArgs = {} + ) + }) + public void testCertPathValidator01() { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + String propName = "certpathvalidator.type"; + String defCPV = Security.getProperty(propName); + + String dt = CertPathValidator.getDefaultType(); + String resType = defCPV; + if (resType == null) { + resType = defaultType; + } + assertNotNull("Default type have not be null", dt); + assertEquals("Incorrect default type", dt, resType); + + if (defCPV == null) { + Security.setProperty(propName, defaultType); + dt = CertPathValidator.getDefaultType(); + resType = Security.getProperty(propName); + assertNotNull("Incorrect default type", resType); + assertNotNull("Default type have not be null", dt); + assertEquals("Incorrect default type", dt, resType); + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NoSuchAlgorithmException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathValidator02() { + try { + CertPathValidator.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertion: returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathValidator03() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathValidator certPV; + for (int i = 0; i < validValues.length; i++) { + certPV = CertPathValidator.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), validValues[i]); + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: throws IllegalArgumentException when provider is null or empty + * + * FIXME: verify what exception will be thrown if provider is empty + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInstance method throws IllegalArgumentException " + + "when provider parameter is null or empty.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathValidator04() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + String provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertPathValidator.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown thrown"); + } catch (IllegalArgumentException e) { + } + try { + CertPathValidator.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown thrown"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NoSuchProviderException when provider has invalid value + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInstance method throws NoSuchProviderException " + + "when provider parameter has invalid value.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathValidator05() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + for (int t = 0; t < validValues.length; t++) { + for (int i = 1; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(validValues[t], + invalidValues[i]); + fail("NoSuchProviderException must be thrown"); + } catch (NoSuchProviderException e1) { + } + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInstance method throws NullPointerException " + + "when algorithm is null, and NoSuchAlgorithmException " + + "when algorithm is not available", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathValidator06() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + try { + CertPathValidator.getInstance(null, defaultProviderName); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(invalidValues[i], defaultProviderName); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e1) { + } + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInstance mwthod returns " + + "CertPathValidator object.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathValidator07() throws NoSuchAlgorithmException, + NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathValidator certPV; + for (int i = 0; i < validValues.length; i++) { + certPV = CertPathValidator.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), + validValues[i]); + assertEquals("Incorrect provider name", certPV.getProvider() + .getName(), defaultProviderName); + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> method + * Assertion: throws IllegalArgumentException when provider is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getInstance method throws IllegalArgumentException " + + "when provider parameter is null.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testCertPathValidator08() + throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + Provider prov = null; + for (int t = 0; t < validValues.length; t++ ) { + try { + CertPathValidator.getInstance(validValues[t], prov); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e1) { + } + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInstance method throws NullPointerException " + + "when algorithm is null, and NoSuchAlgorithmException when " + + "algorithm is not available.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathValidator09() + throws NoSuchAlgorithmException, NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + try { + CertPathValidator.getInstance(null, defaultProvider); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(invalidValues[i], defaultProvider); + fail("NoSuchAlgorithm must be thrown"); + } catch (NoSuchAlgorithmException e1) { + } + } + } + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertion: returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInstance method returns CertPathValidator " + + "object.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertPathValidator10() throws NoSuchAlgorithmException, + NoSuchProviderException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathValidator certPV; + for (int i = 0; i < invalidValues.length; i++) { + certPV = CertPathValidator.getInstance(validValues[i], + defaultProvider); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), + validValues[i]); + assertEquals("Incorrect provider name", certPV.getProvider(), + defaultProvider); + } + } + + /** + * Test for <code>validate(CertPath certpath, CertPathParameters params)</code> method + * Assertion: throws InvalidAlgorithmParameterException params is not + * instance of PKIXParameters or null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that validate method throws " + + "InvalidAlgorithmParameterException if param is not " + + "instance of PKIXParameters or null.", + targets = { + @TestTarget( + methodName = "validate", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.CertPathParameters.class} + ) + }) + public void testCertPathValidator11() + throws NoSuchAlgorithmException, NoSuchProviderException, CertPathValidatorException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathValidator [] certPV = createCPVs(); + assertNotNull("CertPathValidator objects were not created", certPV); + MyCertPath mCP = new MyCertPath(new byte[0]); + invalidParams mPar = new invalidParams(); + for (int i = 0; i < certPV.length; i++) { + try { + certPV[i].validate(mCP, mPar); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch(InvalidAlgorithmParameterException e) { + } + try { + certPV[i].validate(mCP, null); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch(InvalidAlgorithmParameterException e) { + } + } + } + + /** + * Test for + * <code>CertPathValidator</code> constructor + * Assertion: returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathValidator", + methodArgs = {java.security.cert.CertPathValidatorSpi.class, java.security.Provider.class, java.lang.String.class} + ) + }) + public void testCertPathValidator12() + throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, + CertPathValidatorException, InvalidAlgorithmParameterException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathValidatorSpi spi = new MyCertPathValidatorSpi(); + CertPathValidator certPV = new myCertPathValidator(spi, + defaultProvider, defaultType); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), defaultType); + assertEquals("Incorrect provider", certPV.getProvider(), defaultProvider); + certPV.validate(null, null); + try { + certPV.validate(null, null); + fail("CertPathValidatorException must be thrown"); + } catch (CertPathValidatorException e) { + } + certPV = new myCertPathValidator(null, null, null); + assertNull("Incorrect algorithm", certPV.getAlgorithm()); + assertNull("Incorrect provider", certPV.getProvider()); + try { + certPV.validate(null, null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>getAlgorithm()</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAlgorithm", + methodArgs = {} + ) + }) + public void testCertPathValidator13() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + CertPathValidator certPV; + for (int i = 0; i < validValues.length; i++) { + certPV = CertPathValidator.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), + validValues[i]); + try { + certPV = CertPathValidator.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), + validValues[i]); + } catch (NoSuchProviderException e) { + fail("Unexpected NoSuchAlgorithmException " + e.getMessage()); + } + + certPV = CertPathValidator.getInstance(validValues[i], + defaultProvider); + assertEquals("Incorrect algorithm", certPV.getAlgorithm(), + validValues[i]); + } + } + + /** + * Test for <code>getProvider()</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) + public void testCertPathValidator14() throws NoSuchAlgorithmException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + + CertPathValidator certPV; + + for (int i = 0; i < validValues.length; i++) { + try { + certPV = CertPathValidator.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect provider", certPV.getProvider(), + defaultProvider); + } catch (NoSuchProviderException e) { + fail("Unexpected NoSuchProviderException " + e.getMessage()); + } + + certPV = CertPathValidator.getInstance(validValues[i], + defaultProvider); + assertEquals("Incorrect provider", certPV.getProvider(), + defaultProvider); + } + } + + public static void main(String args[]) { + junit.textui.TestRunner.run(CertPathValidator1Test.class); + } +} +/** + * Additional class to verify CertPathValidator constructor + */ +class myCertPathValidator extends CertPathValidator { + + public myCertPathValidator(CertPathValidatorSpi spi, Provider prov, String type) { + super(spi, prov, type); + } +} +/** + * Additional class to verify validate method + */ +class invalidParams implements CertPathParameters { + public Object clone() { + return new invalidParams(); + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathValidator2Test.java b/security/src/test/java/tests/security/cert/CertPathValidator2Test.java new file mode 100644 index 0000000..181f67e --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathValidator2Test.java @@ -0,0 +1,283 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import tests.security.cert.myCertPathBuilder.MyProvider; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CertPathValidator; +import java.security.cert.CertPathValidatorException; + +import org.apache.harmony.security.tests.support.SpiEngUtils; +/** + * Tests for CertPathValidator class constructors and methods + * + */ +@TestTargetClass(CertPathValidator.class) +public class CertPathValidator2Test extends TestCase { + private static final String defaultAlg = "CertPB"; + + public static final String CertPathValidatorProviderClass = "tests.security.cert.support.cert.MyCertPathValidatorSpi"; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + private static final String[] validValues; + + static { + validValues = new String[4]; + validValues[0] = defaultAlg; + validValues[1] = defaultAlg.toLowerCase(); + validValues[2] = "CeRtPb"; + validValues[3] = "cERTpb"; + } + + Provider mProv; + + protected void setUp() throws Exception { + super.setUp(); + mProv = (new SpiEngUtils()).new MyProvider("MyCertPathValidatorProvider", + "Provider for testing", CertPathValidator1Test.srvCertPathValidator + .concat(".").concat(defaultAlg), + CertPathValidatorProviderClass); + Security.insertProviderAt(mProv, 1); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + Security.removeProvider(mProv.getName()); + } + + /** + * Constructor for CertPathValidator2Test. + * + * @param arg0 + */ + public CertPathValidator2Test(String arg0) { + super(arg0); + } + + private void checkResult(CertPathValidator certV) + throws CertPathValidatorException, + InvalidAlgorithmParameterException { + String dt = CertPathValidator.getDefaultType(); + String propName = "certpathvalidator.type"; + for (int i = 0; i <invalidValues.length; i++) { + Security.setProperty(propName, invalidValues[i]); + assertEquals("Incorrect default type", CertPathValidator.getDefaultType(), + invalidValues[i]); + } + Security.setProperty(propName, dt); + assertEquals("Incorrect default type", CertPathValidator.getDefaultType(), + dt); certV.validate(null, null); + try { + certV.validate(null, null); + } catch (CertPathValidatorException e) { + } + try { + certV.validate(null, null); + } catch (InvalidAlgorithmParameterException e) { + } + } + + /** + * Test for <code>getInstance(String algorithm)</code> method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + * returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void _testGetInstance01() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException, CertPathValidatorException { + try { + CertPathValidator.getInstance(null); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(invalidValues[i]); + fail("NoSuchAlgorithmException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + CertPathValidator cerPV; + for (int i = 0; i < validValues.length; i++) { + cerPV = CertPathValidator.getInstance(validValues[i]); + assertEquals("Incorrect type", cerPV.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", cerPV.getProvider(), mProv); + checkResult(cerPV); + } + } + + /** + * Test for <code>getInstance(String algorithm, String provider)</code> method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + * throws IllegalArgumentException when provider is null or empty; + * throws NoSuchProviderException when provider is available; + * returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void _testGetInstance02() throws NoSuchAlgorithmException, + NoSuchProviderException, IllegalArgumentException, + InvalidAlgorithmParameterException, CertPathValidatorException { + try { + CertPathValidator.getInstance(null, mProv.getName()); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(invalidValues[i], mProv + .getName()); + fail("NoSuchAlgorithmException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + String prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertPathValidator.getInstance(validValues[i], prov); + fail("IllegalArgumentException must be thrown when provider is null (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + try { + CertPathValidator.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + for (int i = 0; i < validValues.length; i++) { + for (int j = 1; j < invalidValues.length; j++) { + try { + CertPathValidator.getInstance(validValues[i], + invalidValues[j]); + fail("NoSuchProviderException must be thrown (type: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + CertPathValidator cerPV; + for (int i = 0; i < validValues.length; i++) { + cerPV = CertPathValidator.getInstance(validValues[i], mProv + .getName()); + assertEquals("Incorrect type", cerPV.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", cerPV.getProvider().getName(), + mProv.getName()); + checkResult(cerPV); + } + } + + /** + * Test for <code>getInstance(String algorithm, Provider provider)</code> + * method + * Assertions: + * throws NullPointerException when algorithm is null + * throws NoSuchAlgorithmException when algorithm is not available + * throws IllegalArgumentException when provider is null; + * returns CertPathValidator object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void _testGetInstance03() throws NoSuchAlgorithmException, + IllegalArgumentException, + InvalidAlgorithmParameterException, CertPathValidatorException { + try { + CertPathValidator.getInstance(null, mProv); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertPathValidator.getInstance(invalidValues[i], mProv); + fail("NoSuchAlgorithmException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (NoSuchAlgorithmException e) { + } + } + Provider prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertPathValidator.getInstance(validValues[i], prov); + fail("IllegalArgumentException must be thrown when provider is null (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + CertPathValidator cerPV; + for (int i = 0; i < validValues.length; i++) { + cerPV = CertPathValidator.getInstance(validValues[i], mProv); + assertEquals("Incorrect type", cerPV.getAlgorithm(), validValues[i]); + assertEquals("Incorrect provider", cerPV.getProvider(), mProv); + checkResult(cerPV); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertPathValidator3Test.java b/security/src/test/java/tests/security/cert/CertPathValidator3Test.java new file mode 100644 index 0000000..f8c6c51 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathValidator3Test.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.cert.CertPathParameters; +import java.security.cert.CertPathValidator; +import java.security.cert.CertPathValidatorException; +import java.security.cert.PKIXParameters; + +import org.apache.harmony.security.tests.support.cert.MyCertPath; +import org.apache.harmony.security.tests.support.cert.TestUtils; +import org.apache.harmony.security.tests.support.SpiEngUtils; +/** + * Tests for <code>CertPathValidator</code> class methods. + * + */ +@TestTargetClass(CertPathValidator.class) +public class CertPathValidator3Test extends TestCase { + + /** + * Constructor for CertPathValidatorTests. + * @param name + */ + public CertPathValidator3Test(String name) { + super(name); + } + private static final String defaultType = CertPathBuilder1Test.defaultType; + + private static boolean PKIXSupport = false; + + private static Provider defaultProvider; + private static String defaultProviderName; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + CertPathValidator1Test.srvCertPathValidator); + PKIXSupport = (defaultProvider != null); + defaultProviderName = (PKIXSupport ? defaultProvider.getName() : null); + NotSupportMsg = defaultType.concat(" is not supported"); + } + + private static CertPathValidator[] createCPVs() { + if (!PKIXSupport) { + fail(NotSupportMsg); + return null; + } + try { + CertPathValidator[] certPVs = new CertPathValidator[3]; + certPVs[0] = CertPathValidator.getInstance(defaultType); + certPVs[1] = CertPathValidator.getInstance(defaultType, + defaultProviderName); + certPVs[2] = CertPathValidator.getInstance(defaultType, + defaultProvider); + return certPVs; + } catch (Exception e) { + return null; + } + } + /** + * Test for <code>validate(CertPath certpath, CertPathParameters params)</code> method + * Assertion: throws InvalidAlgorithmParameterException + * when params is instance of PKIXParameters and + * certpath is not X.509 type + * + * FIXME: jrockit-j2re1.4.2_04 throws NullPointerException when certPath is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies exceptions.", + targets = { + @TestTarget( + methodName = "validate", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.CertPathParameters.class} + ) + }) + public void testValidate01() + throws NoSuchAlgorithmException, NoSuchProviderException, + CertPathValidatorException, InvalidAlgorithmParameterException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + MyCertPath mCP = new MyCertPath(new byte[0]); + CertPathParameters params = new PKIXParameters(TestUtils.getTrustAnchorSet()); + CertPathValidator [] certPV = createCPVs(); + assertNotNull("CertPathValidator objects were not created", certPV); + for (int i = 0; i < certPV.length; i++) { + try { + certPV[i].validate(mCP, null); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch(InvalidAlgorithmParameterException e) { + } + try { + certPV[i].validate(null, params); + fail("NullPointerException must be thrown"); + } catch(NullPointerException e) { + } + } + } + +} diff --git a/security/src/test/java/tests/security/cert/CertPathValidatorExceptionTest.java b/security/src/test/java/tests/security/cert/CertPathValidatorExceptionTest.java new file mode 100644 index 0000000..50e8310 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathValidatorExceptionTest.java @@ -0,0 +1,632 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertPath; +import java.security.cert.CertPathValidatorException; +import java.security.cert.Certificate; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; +import java.util.Vector; + + +/** + * Tests for <code>CertPathValidatorException</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertPathValidatorException.class) +public class CertPathValidatorExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertPathValidatorExceptionTests. + * + * @param arg0 + */ + public CertPathValidatorExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertPathValidatorException()</code> constructor + * Assertion: constructs CertPathValidatorException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {} + ) + }) + public void testCertPathValidatorException01() { + CertPathValidatorException tE = new CertPathValidatorException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathValidatorException(String)</code> constructor + * Assertion: constructs CertPathValidatorException with detail message msg. + * Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathValidatorException02() { + CertPathValidatorException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertPathValidatorException(String)</code> constructor + * Assertion: constructs CertPathValidatorException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertPathValidatorException03() { + String msg = null; + CertPathValidatorException tE = new CertPathValidatorException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathValidatorException(Throwable)</code> constructor + * Assertion: constructs CertPathValidatorException when <code>cause</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertPathValidatorException04() { + Throwable cause = null; + CertPathValidatorException tE = new CertPathValidatorException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathValidatorException(Throwable)</code> constructor + * Assertion: constructs CertPathValidatorException when <code>cause</code> + * is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertPathValidatorException05() { + CertPathValidatorException tE = new CertPathValidatorException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertPathValidatorException(String, Throwable)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> is null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathValidatorException06() { + CertPathValidatorException tE = new CertPathValidatorException(null, + null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertPathValidatorException(String, Throwable)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> is null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the second parameter.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathValidatorException07() { + CertPathValidatorException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertPathValidatorException(String, Throwable)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> is not null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the first parameter.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathValidatorException08() { + CertPathValidatorException tE = new CertPathValidatorException(null, + tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertPathValidatorException(String, Throwable)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> is not null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertPathValidatorException09() { + CertPathValidatorException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } + + /** + * Test for + * <code>CertPathValidatorException(String, Throwable, CertPath, int)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> is null <code>msg</code> is null + * <code>certPath</code> is null <code>index</code> is -1 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class, java.security.cert.CertPath.class, int.class} + ) + }) + public void testCertPathValidatorException10() { + CertPathValidatorException tE = new CertPathValidatorException(null, + null, null, -1); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + assertNull("getCertPath() must return null", tE.getCertPath()); + assertEquals("getIndex() must be -1", tE.getIndex(), -1); + } + + /** + * Test for + * <code>CertPathValidatorException(String, Throwable, CertPath, int)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> is null <code>msg</code> is null + * <code>certPath</code> is null <code>index</code> not -1 throws: + * IllegalArgumentException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that IllegalArgumentException is thrown.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class, java.security.cert.CertPath.class, int.class} + ) + }) + public void testCertPathValidatorException11() { + int[] indx = { 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE }; + for (int j = 0; j < indx.length; j++) { + for (int i = 0; i < msgs.length; i++) { + try { + new CertPathValidatorException(msgs[i], tCause, null, indx[j]); + fail("Error. IllegalArgumentException was not thrown as expected. " + + " msg: " + + msgs[i] + + ", certPath is null and index is " + indx[j]); + } catch (IllegalArgumentException e) { + } + } + } + } + + /** + * Test for + * <code>CertPathValidatorException(String, Throwable, CertPath, int)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> not null <code>msg</code> not null + * <code>certPath</code> is null <code>index</code> is -1 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IndexOutOfBoundsException.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class, java.security.cert.CertPath.class, int.class} + ) + }) + public void testCertPathValidatorException12() { + CertPathValidatorException tE; + + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, null, -1); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), + getM.indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), + getM.indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return " + .concat(tCause.toString()), tE.getCause(), tCause); + assertNull("getCertPath() must return null", tE.getCertPath()); + assertEquals("getIndex() must return -1", tE.getIndex(), -1); + } catch (IndexOutOfBoundsException e) { + fail("Unexpected exception: " + e.toString() + + " Parameters: msg: " + msgs[i] + + ", certPath is null and index is -1"); + } + } + } + + /** + * Test for + * <code>CertPathValidatorException(String, Throwable, CertPath, int)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> not null <code>msg</code> not null + * <code>certPath</code> not null <code>index</code>< -1 || >= + * certPath.getCertificates().size() throws: IndexOutOfBoundsException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IndexOutOfBoundsException.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class, java.security.cert.CertPath.class, int.class} + ) + }) + public void testCertPathValidatorException13() { + myCertPath mcp = new myCertPath("X.509", ""); + CertPath cp = mcp.get("X.509"); + int[] indx = { -2, -100, 0, 1, 100, Integer.MAX_VALUE, + Integer.MIN_VALUE }; + for (int j = 0; j < indx.length; j++) { + for (int i = 0; i < msgs.length; i++) { + try { + new CertPathValidatorException(msgs[i], tCause, cp, indx[j]); + fail("IndexOutOfBoundsException was not thrown as expected. " + + " msg: " + + msgs[i] + + ", certPath is null and index is " + indx[j]); + } catch (IndexOutOfBoundsException e) { + } + } + } + } + + /** + * Test for + * <code>CertPathValidatorException(String, Throwable, CertPath, int)</code> + * constructor Assertion: constructs CertPathValidatorException when + * <code>cause</code> not null <code>msg</code> not null + * <code>certPath</code> not null <code>index</code>< + * certPath.getCertificates().size() + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IndexOutOfBoundsException.", + targets = { + @TestTarget( + methodName = "CertPathValidatorException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class, java.security.cert.CertPath.class, int.class} + ) + }) + public void testCertPathValidatorException14() { + CertPathValidatorException tE; + myCertPath mcp = new myCertPath("X.509", ""); + CertPath cp = mcp.get("X.509"); + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, cp, -1); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), + getM.indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), + getM.indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return " + .concat(tCause.toString()), tE.getCause(), tCause); + assertNotNull("getCertPath() must not return null", tE + .getCertPath()); + assertEquals( + "getCertPath() must return ".concat(cp.toString()), tE + .getCertPath(), cp); + assertEquals("getIndex() must return -1", tE.getIndex(), -1); + + } catch (IndexOutOfBoundsException e) { + fail("Unexpected IndexOutOfBoundsException was thrown. " + + e.toString()); + } + } + } + + /** + * Test for <code>getCertPath()</code>. Returns the certification path + * that was being validated when the exception was thrown. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies that getCertPath method returns the certification path" + + "that was being validated when the exception was thrown.", + targets = { + @TestTarget( + methodName = "getCertPath", + methodArgs = {} + ) + }) + public void testCertPathValidatorException15() { + CertPathValidatorException tE = new CertPathValidatorException(); + assertNull("getCertPath() must return null.", tE.getCertPath()); + + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i]); + assertNull("getCertPath() must return null ", tE.getCertPath()); + } + + Throwable cause = null; + tE = new CertPathValidatorException(cause); + assertNull("getCertPath() must return null.", tE.getCertPath()); + + tE = new CertPathValidatorException(tCause); + assertNull("getCertPath() must return null.", tE.getCertPath()); + + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i], tCause); + assertNull("getCertPath() must return null", tE.getCertPath()); + } + + tE = new CertPathValidatorException(null, null, null, -1); + assertNull("getCertPath() must return null", tE.getCertPath()); + + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, null, -1); + assertNull("getCertPath() must return null", tE.getCertPath()); + } catch (IndexOutOfBoundsException e) { + fail("Unexpected exception: " + e.getMessage()); + } + } + + myCertPath mcp = new myCertPath("X.509", ""); + CertPath cp = mcp.get("X.509"); + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, cp, -1); + assertNotNull("getCertPath() must not return null", tE + .getCertPath()); + assertEquals( + "getCertPath() must return ".concat(cp.toString()), tE + .getCertPath(), cp); + } catch (IndexOutOfBoundsException e) { + fail("Unexpected IndexOutOfBoundsException was thrown. " + + e.toString()); + } + } + } + + /** + * Test for <code>getIndex()</code>. Returns the index of the certificate + * in the certification path that caused the exception to be thrown. Note + * that the list of certificates in a CertPath is zero based. If no index + * has been set, -1 is returned. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIndex", + methodArgs = {} + ) + }) + public void testCertPathValidatorException16() { + CertPathValidatorException tE = new CertPathValidatorException(); + assertEquals("getIndex() must be equals -1", -1, tE.getIndex()); + + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i]); + assertEquals("getIndex() must be equals -1", -1, tE.getIndex()); + } + + Throwable cause = null; + tE = new CertPathValidatorException(cause); + assertEquals("getIndex() must be equals -1", -1, tE.getIndex()); + + tE = new CertPathValidatorException(tCause); + assertEquals("getIndex() must be equals -1", -1, tE.getIndex()); + + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i], tCause); + assertEquals("getIndex() must be equals -1", -1, tE.getIndex()); + } + + tE = new CertPathValidatorException(null, null, null, -1); + assertEquals("getIndex() must be equals -1", -1, tE.getIndex()); + + myCertPath mcp = new myCertPath("X.509", ""); + CertPath cp = mcp.get("X.509"); + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, cp, -1); + assertNotNull("getIndex() must not return null", tE + .getCertPath()); + assertEquals( + "getIndex() must return ".concat(cp.toString()), tE + .getCertPath(), cp); + } catch (IndexOutOfBoundsException e) { + fail("Unexpected IndexOutOfBoundsException was thrown. " + + e.getMessage()); + } + } + } + + class myCertPath extends CertPath { + + private static final long serialVersionUID = 5871603047244722511L; + + public List<Certificate> getCertificates() { + return new Vector<Certificate>(); + } + + public byte[] getEncoded() { + return new byte[0]; + } + + public byte[] getEncoded(String s) { + return new byte[0]; + } + + public Iterator<String> getEncodings() { + return (Iterator<String>) (new StringTokenizer("ss ss ss ss")); + } + + protected myCertPath(String s) { + super(s); + } + + public CertPath get(String s) { + return new myCertPath(s); + } + + public myCertPath(String s, String s1) { + super(s); + } + + } +} + + diff --git a/security/src/test/java/tests/security/cert/CertPathValidatorSpiTest.java b/security/src/test/java/tests/security/cert/CertPathValidatorSpiTest.java new file mode 100644 index 0000000..2487b67 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertPathValidatorSpiTest.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CertPath; +import java.security.cert.CertPathParameters; +import java.security.cert.CertPathValidatorException; +import java.security.cert.CertPathValidatorResult; +import java.security.cert.CertPathValidatorSpi; + +import org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi; +/** + * Tests for <code>CertPathValidatorSpi</code> class constructors and methods. + * + */ +@TestTargetClass(CertPathValidatorSpi.class) +public class CertPathValidatorSpiTest extends TestCase { + + /** + * Constructor for CertPathValidatorSpiTest. + * + * @param arg0 + */ + public CertPathValidatorSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>CertPathValidatorSpi</code> constructor Assertion: + * constructs CertPathValidatorSpi + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Just exception cases were tested for engineValidate", + targets = { + @TestTarget( + methodName = "CertPathValidatorSpi", + methodArgs = {} + ), + @TestTarget( + methodName = "engineValidate", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.CertPathParameters.class} + ) + + }) + public void testCertPathValidatorSpi01() throws CertPathValidatorException, + InvalidAlgorithmParameterException { + CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi(); + CertPathParameters params = null; + CertPath certPath = null; + CertPathValidatorResult cpvResult = certPathValid.engineValidate( + certPath, params); + assertNull("Not null CertPathValidatorResult", cpvResult); + try { + certPathValid.engineValidate(certPath, params); + fail("CertPathValidatorException must be thrown"); + } catch (CertPathValidatorException e) { + } + try { + certPathValid.engineValidate(certPath, params); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch (InvalidAlgorithmParameterException e) { + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertStore1Test.java b/security/src/test/java/tests/security/cert/CertStore1Test.java new file mode 100644 index 0000000..f435d98 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertStore1Test.java @@ -0,0 +1,678 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CertStore; +import java.security.cert.CertStoreException; +import java.security.cert.CertStoreParameters; +import java.security.cert.CertStoreSpi; +import java.security.cert.CollectionCertStoreParameters; +import java.security.cert.LDAPCertStoreParameters; +import java.util.Collection; + +import org.apache.harmony.security.tests.support.cert.MyCertStoreParameters; +import org.apache.harmony.security.tests.support.cert.MyCertStoreSpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +/** + * Tests for <code>CertStore</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertStore.class) +public class CertStore1Test extends TestCase { + + /** + * Constructor for CertStoreTests. + * @param arg0 + */ + public CertStore1Test(String arg0) { + super(arg0); + } + public static final String srvCertStore = "CertStore"; + + private static final String defaultType = "LDAP"; + public static final String [] validValues = { + "LDAP", "ldap", "Ldap", "lDAP", "lDaP" }; + public static String [] validValuesC = null; + + private static String [] invalidValues = SpiEngUtils.invalidValues; + + private static boolean LDAPSupport = false; + private static final String CollectionType = "Collection"; + private static boolean CollectionSupport = false; + + private static Provider defaultProvider; + private static String defaultProviderName; + private static Provider defaultProviderCol; + private static String defaultProviderColName; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + srvCertStore); + LDAPSupport = (defaultProvider != null); + defaultProviderName = (LDAPSupport ? defaultProvider.getName() : null); + NotSupportMsg = "LDAP and Collection algorithm are not supported"; + + defaultProviderCol = SpiEngUtils.isSupport(CollectionType, + srvCertStore); + CollectionSupport = (defaultProviderCol != null); + defaultProviderColName = (CollectionSupport ? defaultProviderCol.getName() : null); + if (CollectionSupport) { + validValuesC = new String[3]; + validValuesC[0] = CollectionType; + validValuesC[1] = CollectionType.toUpperCase(); + validValuesC[2] = CollectionType.toLowerCase(); + } + } + + private Provider dProv = null; + private String dName = null; + private String dType = null; + private CertStoreParameters dParams = null; + private String[] dValid; + + private boolean initParams() { + if (!LDAPSupport && !CollectionSupport) { + fail(NotSupportMsg); + return false; + } + dParams = (CollectionSupport ? (CertStoreParameters)new CollectionCertStoreParameters() : + (CertStoreParameters)new LDAPCertStoreParameters()); + dType = (CollectionSupport ? CollectionType : defaultType ); + dProv = (CollectionSupport ? defaultProviderCol : defaultProvider ); + dName = (CollectionSupport ? defaultProviderColName : defaultProviderName ); + dValid = (CollectionSupport ? validValuesC : validValues ); + return true; + } + private CertStore [] createCS() { + if (!LDAPSupport && !CollectionSupport) { + fail(NotSupportMsg); + return null; + } + try { + CertStore [] ss = new CertStore[3]; + ss[0] = CertStore.getInstance(dType, dParams); + ss[1] = CertStore.getInstance(dType, dParams, dProv); + ss[2] = CertStore.getInstance(dType, dParams, dName); + return ss; + } catch (Exception e) { + return null; + } + } + + + /** + * Test for <code>getDefaultType()</code> method + * Assertion: returns security property "certstore.type" or "LDAP" + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDefaultType", + methodArgs = {} + ) + }) + public void testCertStore01() { + if (!LDAPSupport) { + return; + } + String dt = CertStore.getDefaultType(); + String sn = Security.getProperty("certstore.type"); + String def = "Proba.cert.store.type"; + if (sn == null) { + sn = defaultType; + } + assertNotNull("Default type have not be null", dt); + assertEquals("Incorrect default type", dt, sn); + + Security.setProperty("certstore.type", def); + dt = CertStore.getDefaultType(); + assertEquals("Incorrect default type", dt, def); + Security.setProperty("certstore.type", sn); + assertEquals("Incorrect default type", Security.getProperty("certstore.type"), sn ); + } + /** + * Test for + * <code>CertStore</code> constructor + * Assertion: returns CertStore object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertStore", + methodArgs = {java.security.cert.CertStoreSpi.class, java.security.Provider.class, java.lang.String.class, java.security.cert.CertStoreParameters.class} + ) + }) + public void testCertStore02() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException, CertStoreException { + if (!initParams()) { + return; + } + MyCertStoreParameters pp = new MyCertStoreParameters(); + CertStoreSpi spi = new MyCertStoreSpi(pp); + CertStore certS = new myCertStore(spi, dProv, dType, pp); + assertEquals("Incorrect algorithm", certS.getType(), dType); + assertEquals("Incorrect provider", certS.getProvider(), dProv); + assertTrue("Incorrect parameters", certS.getCertStoreParameters() + instanceof MyCertStoreParameters); + try { + certS.getCertificates(null); + fail("CertStoreException must be thrown"); + } catch (CertStoreException e) { + } + certS = new myCertStore(null, null, null, null); + assertNull("Incorrect algorithm", certS.getType()); + assertNull("Incorrect provider", certS.getProvider()); + assertNull("Incorrect parameters", certS.getCertStoreParameters()); + try { + certS.getCertificates(null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>getInstance(String type, CertStoreParameters params)</code> method + * Assertion: + * throws NullPointerException when type is null + * throws NoSuchAlgorithmException when type is incorrect; + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NoSuchAlgorithmException and NullPointerException. " + + "InvalidAlgorithmParameterException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class} + ) + }) + public void testCertStore03() throws InvalidAlgorithmParameterException { + if (!initParams()) { + return; + } + try { + CertStore.getInstance(null, dParams); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++ ) { + try { + CertStore.getInstance(invalidValues[i], dParams); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for <code>getInstance(String type, CertStoreParameters params)</code> method + * Assertion: return CertStore object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidAlgorithmParameterException checking missed", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class} + ) + }) + public void testCertStore05() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { + if (!initParams()) { + return; + } + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + certS.getCertStoreParameters(); + } + } + /** + * Test for method + * <code>getInstance(String type, CertStoreParameters params, String provider)</code> + * Assertion: throws IllegalArgumentException when provider is null or empty + * + * FIXME: verify IllegalArgumentException when provider is empty + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException. " + + "InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.lang.String.class} + ) + }) + public void testCertStore06() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, + NoSuchProviderException { + if (!initParams()) { + return; + } + String provider = null; + for (int i = 0; i < dValid.length; i++) { + try { + CertStore.getInstance(dValid[i], dParams, provider); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + try { + CertStore.getInstance(dValid[i], dParams, ""); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for method + * <code>getInstance(String type, CertStoreParameters params, String provider)</code> + * Assertion: throws NoSuchProviderException when provider has invalid value + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NoSuchProviderException. " + + "InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.lang.String.class} + ) + }) + public void testCertStore07() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { + if (!initParams()) { + return; + } + for (int i = 0; i < dValid.length; i++) { + for (int j = 1; j < invalidValues.length; j++ ) { + try { + CertStore.getInstance(dValid[i], dParams, invalidValues[j]); + fail("NoSuchProviderException must be thrown"); + } catch (NoSuchProviderException e) { + } + } + } + } + /** + * Test for method + * <code>getInstance(String type, CertStoreParameters params, String provider)</code> + * Assertion: + * throws NullPointerException when type is null + * throws NoSuchAlgorithmException when type is incorrect; + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NoSuchAlgorithmException and NullPointerException. " + + "InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.lang.String.class} + ) + }) + public void testCertStore08() + throws InvalidAlgorithmParameterException, NoSuchProviderException, + NoSuchAlgorithmException { + if (!initParams()) { + return; + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertStore.getInstance(invalidValues[i], dParams, dName); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e){ + } + } + try { + CertStore.getInstance(null, dParams, dName); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + } + + /** + * Test for method + * <code>getInstance(String type, CertStoreParameters params, String provider)</code> + * Assertion: return CertStore object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies positive case. " + + "InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.lang.String.class} + ) + }) + public void testCertStore10() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { + if (!initParams()) { + return; + } + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams, dName); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + certS.getCertStoreParameters(); + } + } + + /** + * Test for method + * <code>getInstance(String type, CertStoreParameters params, Provider provider)</code> + * Assertion: throws IllegalArgumentException when provider is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getInstance throws IllegalArgumentException " + + "when provider is null. InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.security.Provider.class} + ) + }) + public void testCertStore11() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, + NoSuchProviderException { + if (!initParams()) { + return; + } + Provider provider = null; + for (int i = 0; i < dValid.length; i++) { + try { + CertStore.getInstance(dValid[i], dParams, provider); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for <code>getInstance(String type, CertStoreParameters params, Provider provider)</code> method + * Assertion: + * throws NullPointerException when type is null + * throws NoSuchAlgorithmException when type is incorrect; + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException and NoSuchAlgorithmException. " + + "InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.security.Provider.class} + ) + }) + public void testCertStore12() + throws InvalidAlgorithmParameterException, + NoSuchAlgorithmException { + if (!initParams()) { + return; + } + try { + CertStore.getInstance(null, dParams, dProv); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++ ) { + try { + CertStore.getInstance(invalidValues[i], dParams, dProv); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for method + * <code>getInstance(String type, CertStoreParameters params, Provider provider)</code> + * Assertion: return CertStore object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies positive case. " + + "InvalidAlgorithmParameterException checking missed.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.security.Provider.class} + ) + }) + public void testCertStore14() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { + if (!initParams()) { + return; + } + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams, dProv); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + certS.getCertStoreParameters(); + } + } + /** + * Test for methods + * <code>getCertificates(CertSelector selector)</code> + * <code>getCRLs(CRLSelector selector)</code> + * Assertion: returns empty Collection when selector is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that these methods return empty Collection " + + "when selector is null.", + targets = { + @TestTarget( + methodName = "getCertificates", + methodArgs = {java.security.cert.CertSelector.class} + ), + @TestTarget( + methodName = "getCRLs", + methodArgs = {java.security.cert.CRLSelector.class} + ) + }) + public void testCertStore15() + throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, + CertStoreException { + if (!initParams()) { + return; + } + CertStore [] certS = createCS(); + assertNotNull("CertStore object were not created", certS); + Collection coll; + for (int i = 0; i < certS.length; i++) { + coll = certS[i].getCertificates(null); + assertTrue("Result collection not empty",coll.isEmpty()); + coll = certS[i].getCRLs(null); + assertTrue("Result collection not empty",coll.isEmpty()); + } + } + + /** + * Test for <code>getType()</code> method + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException, and NoSuchProviderException.", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public void _testCertStore16() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException { + if (!initParams()) { + return; + } + + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + + try { + certS = CertStore.getInstance(dValid[i], dParams, + defaultProvider); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException " + e.getMessage()); + } + + try { + certS = CertStore.getInstance(dValid[i], dParams, + defaultProviderName); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + } catch (NoSuchProviderException e) { + fail("Unexpected IllegalArgumentException " + e.getMessage()); + } + } + } + + /** + * Test for <code>getProvider()</code> method + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException, and NoSuchProviderException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.cert.CertStoreParameters.class, java.security.Provider.class} + ) + }) + public void _testCertStore17() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException { + if (!initParams()) { + return; + } + + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + try { + certS = CertStore.getInstance(dValid[i], dParams, + defaultProvider); + assertEquals("Incorrect provider", certS.getProvider(), + defaultProvider); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException " + e.getMessage()); + } + + try { + certS = CertStore.getInstance(dValid[i], dParams, + defaultProviderName); + assertEquals("Incorrect provider", certS.getProvider(), + defaultProvider); + } catch (NoSuchProviderException e) { + fail("Unexpected IllegalArgumentException " + e.getMessage()); + } +} + } + + /** + * Test for <code>getCertStoreParameters()</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertStoreParameters", + methodArgs = {} + ) + }) + public void _testCertStore18() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException { + if (!initParams()) { + return; + } + + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams); + assertEquals("Incorrect parameters", + ((CollectionCertStoreParameters) certS + .getCertStoreParameters()).getCollection(), + ((CollectionCertStoreParameters) dParams).getCollection()); + + try { + certS = CertStore.getInstance(dValid[i], dParams, + defaultProvider); + assertEquals("Incorrect parameters", + ((CollectionCertStoreParameters) certS + .getCertStoreParameters()).getCollection(), + ((CollectionCertStoreParameters) dParams) + .getCollection()); + } catch (IllegalArgumentException e) { + fail("Unexpected IllegalArgumentException " + e.getMessage()); + } + + try { + certS = CertStore.getInstance(dValid[i], dParams, + defaultProviderName); + assertEquals("Incorrect parameters", + ((CollectionCertStoreParameters) certS + .getCertStoreParameters()).getCollection(), + ((CollectionCertStoreParameters) dParams) + .getCollection()); + } catch (NoSuchProviderException e) { + fail("Unexpected IllegalArgumentException " + e.getMessage()); + } + } + } +} + +/** + * Additional class to verify CertStore constructor + */ +class myCertStore extends CertStore { + public myCertStore(CertStoreSpi spi, Provider prov, String type, CertStoreParameters params) { + super(spi, prov, type, params); + } +} diff --git a/security/src/test/java/tests/security/cert/CertStoreExceptionTest.java b/security/src/test/java/tests/security/cert/CertStoreExceptionTest.java new file mode 100644 index 0000000..3d0e1ec --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertStoreExceptionTest.java @@ -0,0 +1,275 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertStoreException; + +/** + * Tests for <code>CertStoreException</code> class constructors and methods. + * + */ +@TestTargetClass(CertStoreException.class) +public class CertStoreExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertStoreExceptionTests. + * + * @param arg0 + */ + public CertStoreExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertStoreException()</code> constructor Assertion: + * constructs CertStoreException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {} + ) + }) + public void testCertStoreException01() { + CertStoreException tE = new CertStoreException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertStoreException(String)</code> constructor Assertion: + * constructs CertStoreException with detail message msg. Parameter + * <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertStoreException02() { + CertStoreException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertStoreException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertStoreException(String)</code> constructor Assertion: + * constructs CertStoreException when <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null asa parameter.", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertStoreException03() { + String msg = null; + CertStoreException tE = new CertStoreException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertStoreException(Throwable)</code> constructor + * Assertion: constructs CertStoreException when <code>cause</code> is + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertStoreException04() { + Throwable cause = null; + CertStoreException tE = new CertStoreException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertStoreException(Throwable)</code> constructor + * Assertion: constructs CertStoreException when <code>cause</code> is not + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertStoreException05() { + CertStoreException tE = new CertStoreException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertStoreException(String, Throwable)</code> constructor + * Assertion: constructs CertStoreException when <code>cause</code> is + * null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertStoreException06() { + CertStoreException tE = new CertStoreException(null, null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertStoreException(String, Throwable)</code> constructor + * Assertion: constructs CertStoreException when <code>cause</code> is + * null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the second parameter.", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertStoreException07() { + CertStoreException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertStoreException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertStoreException(String, Throwable)</code> constructor + * Assertion: constructs CertStoreException when <code>cause</code> is not + * null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the first parameter.", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertStoreException08() { + CertStoreException tE = new CertStoreException(null, tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertStoreException(String, Throwable)</code> constructor + * Assertion: constructs CertStoreException when <code>cause</code> is not + * null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "CertStoreException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertStoreException09() { + CertStoreException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertStoreException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertStoreSpiTest.java b/security/src/test/java/tests/security/cert/CertStoreSpiTest.java new file mode 100644 index 0000000..e24d052 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertStoreSpiTest.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CRL; +import java.security.cert.CRLSelector; +import java.security.cert.CertSelector; +import java.security.cert.CertStoreException; +import java.security.cert.CertStoreSpi; +import java.security.cert.Certificate; + +import org.apache.harmony.security.tests.support.cert.MyCertStoreParameters; +import org.apache.harmony.security.tests.support.cert.MyCertStoreSpi; + +/** + * Tests for <code>CertStoreSpi</code> class constructors and methods. + * + */ +@TestTargetClass(CertStoreSpi.class) +public class CertStoreSpiTest extends TestCase { + + /** + * Constructor for CertStoreSpiTest. + * + * @param arg0 + */ + public CertStoreSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>CertStoreSpi</code> constructor Assertion: constructs + * CertStoreSpi + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertStoreSpi", + methodArgs = {java.security.cert.CertStoreParameters.class} + ), + @TestTarget( + methodName = "engineGetCertificates", + methodArgs = {java.security.cert.CertSelector.class} + ), + @TestTarget( + methodName = "engineGetCRLs", + methodArgs = {java.security.cert.CRLSelector.class} + ) + }) + public void testCertStoreSpi01() throws InvalidAlgorithmParameterException, + CertStoreException { + CertStoreSpi certStoreSpi = null; + CertSelector certSelector = new tmpCertSelector();//new + // X509CertSelector(); + CRLSelector crlSelector = new tmpCRLSelector();//new X509CRLSelector(); + try { + certStoreSpi = new MyCertStoreSpi(null); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch (InvalidAlgorithmParameterException e) { + } + certStoreSpi = new MyCertStoreSpi(new MyCertStoreParameters()); + assertNull("Not null collection", certStoreSpi + .engineGetCertificates(certSelector)); + assertNull("Not null collection", certStoreSpi + .engineGetCRLs(crlSelector)); + } + + public static Test suite() { + return new TestSuite(CertStoreSpiTest.class); + } + + public static void main(String args[]) { + junit.textui.TestRunner.run(suite()); + } + + /** + * Additional classes for verification CertStoreSpi class + */ + public static class tmpCRLSelector implements CRLSelector { + public Object clone() { + return null; + } + public boolean match (CRL crl) { + return false; + } + } + public static class tmpCertSelector implements CertSelector { + public Object clone() { + return null; + } + public boolean match (Certificate crl) { + return true; + } + } + +} diff --git a/security/src/test/java/tests/security/cert/CertificateCertificateRepTest.java b/security/src/test/java/tests/security/cert/CertificateCertificateRepTest.java new file mode 100644 index 0000000..9aed276 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateCertificateRepTest.java @@ -0,0 +1,108 @@ +package tests.security.cert; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + +import java.io.ObjectStreamException; +import java.security.acl.AclNotFoundException; +import java.security.acl.NotOwnerException; +import java.security.cert.Certificate; +import java.util.Arrays; + +import org.apache.harmony.security.tests.support.cert.MyCertificate; +import org.apache.harmony.security.tests.support.cert.TestUtils; +import org.apache.harmony.security.tests.support.cert.MyCertificate.MyCertificateRep; + +import junit.framework.TestCase; + +@TestTargetClass(java.security.cert.Certificate.class) +public class CertificateCertificateRepTest extends TestCase { + + private static final byte[] testEncoding = new byte[] { (byte) 1, (byte) 2, + (byte) 3, (byte) 4, (byte) 5 }; + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test for + * <code>Certificate.CertificateRep(String type, byte[] data)</code> + * method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "!CertificateRep", + methodArgs = {String.class, byte.class} + ) + }) + public final void testCertificateCertificateRep() { + MyCertificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + MyCertificateRep rep = c1.new MyCertificateRep("TEST_TYPE", new byte[] { + (byte) 1, (byte) 2, (byte) 3 }); + + assertTrue(Arrays.equals(new byte[] { (byte) 1, (byte) 2, (byte) 3 }, + rep.getData())); + assertEquals("TEST_TYPE", rep.getType()); + + try { + c1.new MyCertificateRep(null, null); + } catch (Exception e) { + fail("Unexpected exeption " + e.getMessage()); + } + + try { + MyCertificate.MyCertificateRep rep1 = c1.new MyCertificateRep( + "X509", TestUtils.getX509Certificate_v3()); + assertEquals("X509", rep1.getType()); + assertTrue(Arrays.equals(TestUtils.getX509Certificate_v3(), rep1.getData())); + } catch (Exception e) { + fail("Unexpected exeption " + e.getMessage()); + } + } + + /** + * Test for <code>readResolve()</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateRep.readResolve", + methodArgs = {} + ) + }) + public final void testReadResolve() { + MyCertificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + MyCertificateRep rep = c1.new MyCertificateRep("TEST_TYPE", new byte[] { + (byte) 1, (byte) 2, (byte) 3 }); + + try { + rep.readResolve(); + fail("ObjectStreamException expected"); + } catch (ObjectStreamException e) { + // expected + } + + MyCertificateRep rep1 = c1.new MyCertificateRep("X509", TestUtils + .getX509Certificate_v3()); + try { + Certificate obj = (Certificate) rep1.readResolve(); + assertEquals("0.3.5", obj.getPublicKey().getAlgorithm()); + assertEquals("X.509", obj.getPublicKey().getFormat()); + assertEquals("X.509", obj.getType()); + } catch (ObjectStreamException e) { + fail("Unexpected ObjectStreamException " + e.getMessage()); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateEncodingException2Test.java b/security/src/test/java/tests/security/cert/CertificateEncodingException2Test.java new file mode 100644 index 0000000..a5b63ca --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateEncodingException2Test.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import java.security.cert.CertificateEncodingException; + +@TestTargetClass(CertificateEncodingException.class) +public class CertificateEncodingException2Test extends junit.framework.TestCase { + + /** + * @tests java.security.cert.CertificateEncodingException#CertificateEncodingException() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {} + ) + }) + public void test_Constructor() { + // Test for method java.security.cert.CertificateEncodingException() + try { + if (true) { + throw new CertificateEncodingException(); + } + fail("Should have thrown CertificateEncodingException"); + } catch (CertificateEncodingException e) { + assertEquals("Initializer failed : " + e.toString(), + "java.security.cert.CertificateEncodingException", + e.toString()); + } catch (Exception e) { + fail("Unexpected exception during test : " + e); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateEncodingExceptionTest.java b/security/src/test/java/tests/security/cert/CertificateEncodingExceptionTest.java new file mode 100644 index 0000000..ff4b8c3 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateEncodingExceptionTest.java @@ -0,0 +1,282 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertificateEncodingException; + + +/** + * Tests for <code>CertificateEncodingException</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertificateEncodingException.class) +public class CertificateEncodingExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateEncodingExceptionTests. + * + * @param arg0 + */ + public CertificateEncodingExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateEncodingException()</code> constructor + * Assertion: constructs CertificateEncodingException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {} + ) + }) + public void testCertificateEncodingException01() { + CertificateEncodingException tE = new CertificateEncodingException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateEncodingException(String)</code> constructor + * Assertion: constructs CertificateEncodingException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateEncodingException02() { + CertificateEncodingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateEncodingException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateEncodingException(String)</code> constructor + * Assertion: constructs CertificateEncodingException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateEncodingException03() { + String msg = null; + CertificateEncodingException tE = new CertificateEncodingException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateEncodingException(Throwable)</code> + * constructor Assertion: constructs CertificateEncodingException when + * <code>cause</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertificateEncodingException04() { + Throwable cause = null; + CertificateEncodingException tE = new CertificateEncodingException( + cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateEncodingException(Throwable)</code> + * constructor Assertion: constructs CertificateEncodingException when + * <code>cause</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertificateEncodingException05() { + CertificateEncodingException tE = new CertificateEncodingException( + tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertificateEncodingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateEncodingException when + * <code>cause</code> is null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateEncodingException06() { + CertificateEncodingException tE = new CertificateEncodingException( + null, null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateEncodingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateEncodingException when + * <code>cause</code> is null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the second parameter.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateEncodingException07() { + CertificateEncodingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateEncodingException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateEncodingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateEncodingException when + * <code>cause</code> is not null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the first parameter.", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateEncodingException08() { + CertificateEncodingException tE = new CertificateEncodingException( + null, tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertificateEncodingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateEncodingException when + * <code>cause</code> is not null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateEncodingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateEncodingException09() { + CertificateEncodingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateEncodingException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateException2Test.java b/security/src/test/java/tests/security/cert/CertificateException2Test.java new file mode 100644 index 0000000..dbeba13 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateException2Test.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import java.security.cert.CertificateException; + +@TestTargetClass(CertificateException.class) +public class CertificateException2Test extends junit.framework.TestCase { + + /** + * @tests java.security.cert.CertificateException#CertificateException() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {} + ) + }) + public void test_Constructor() { + // Test for method java.security.cert.CertificateException() + try { + if (true) { + throw new CertificateException(); + } + fail("Should have thrown CertificateException"); + } catch (CertificateException e) { + assertEquals("Initializer failed : " + e.toString(), + "java.security.cert.CertificateException", e.toString()); + } catch (Exception e) { + fail("Unexpected exception during test : " + e); + } + } + + /** + * @tests java.security.cert.CertificateException#CertificateException(java.lang.String) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null/empty/invalid parameters checking missed", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class} + ) + }) + public void test_ConstructorLjava_lang_String() { + // Test for method + // java.security.cert.CertificateException(java.lang.String) + try { + if (true) { + throw new CertificateException("Some error message"); + } + fail("Should have thrown CertificateException"); + } catch (CertificateException e) { + assertEquals("Initializer failed", + "Some error message", e.getMessage()); + } catch (Exception e) { + fail("Unexpected exception during test : " + e); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateExceptionTest.java b/security/src/test/java/tests/security/cert/CertificateExceptionTest.java new file mode 100644 index 0000000..44ee5a4 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateExceptionTest.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertificateException; + + +/** + * Tests for <code>CertificateException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateException.class) +public class CertificateExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateExceptionTests. + * + * @param arg0 + */ + public CertificateExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateException()</code> constructor Assertion: + * constructs CertificateException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {} + ) + }) + public void testCertificateException01() { + CertificateException tE = new CertificateException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateException(String)</code> constructor + * Assertion: constructs CertificateException with detail message msg. + * Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateException02() { + CertificateException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateException(String)</code> constructor + * Assertion: constructs CertificateException when <code>msg</code> is + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateException03() { + String msg = null; + CertificateException tE = new CertificateException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateException(Throwable)</code> constructor + * Assertion: constructs CertificateException when <code>cause</code> is + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertificateException04() { + Throwable cause = null; + CertificateException tE = new CertificateException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateException(Throwable)</code> constructor + * Assertion: constructs CertificateException when <code>cause</code> is + * not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertificateException05() { + CertificateException tE = new CertificateException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertificateException(String, Throwable)</code> + * constructor Assertion: constructs CertificateException when + * <code>cause</code> is null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateException06() { + CertificateException tE = new CertificateException(null, null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateException(String, Throwable)</code> + * constructor Assertion: constructs CertificateException when + * <code>cause</code> is null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as Throwable parameter.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateException07() { + CertificateException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateException(String, Throwable)</code> + * constructor Assertion: constructs CertificateException when + * <code>cause</code> is not null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies as String parameter.", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateException08() { + CertificateException tE = new CertificateException(null, tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertificateException(String, Throwable)</code> + * constructor Assertion: constructs CertificateException when + * <code>cause</code> is not null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateException09() { + CertificateException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateExpiredExceptionTest.java b/security/src/test/java/tests/security/cert/CertificateExpiredExceptionTest.java new file mode 100644 index 0000000..56efed4 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateExpiredExceptionTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertificateExpiredException; + + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateExpiredException.class) +public class CertificateExpiredExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateExpiredExceptionTests. + * + * @param arg0 + */ + public CertificateExpiredExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateExpiredException()</code> constructor + * Assertion: constructs CertificateExpiredException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateExpiredException", + methodArgs = {} + ) + }) + public void testCertificateExpiredException01() { + CertificateExpiredException tE = new CertificateExpiredException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateExpiredException(String)</code> constructor + * Assertion: constructs CertificateExpiredException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateExpiredException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateExpiredException02() { + CertificateExpiredException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateExpiredException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateExpiredException(String)</code> constructor + * Assertion: constructs CertificateExpiredException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateExpiredException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateExpiredException03() { + String msg = null; + CertificateExpiredException tE = new CertificateExpiredException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateFactory1Test.java b/security/src/test/java/tests/security/cert/CertificateFactory1Test.java new file mode 100644 index 0000000..03d0f07 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateFactory1Test.java @@ -0,0 +1,929 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectOutputStream; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.cert.CRL; +import java.security.cert.CRLException; +import java.security.cert.CertPath; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateFactorySpi; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.apache.harmony.security.tests.support.cert.MyCertificate; +import org.apache.harmony.security.tests.support.cert.MyCertPath; +import org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi; +import org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +/** + * Tests for <code>CertificateFactory</code> class methods and constructor + * + */ +@TestTargetClass(CertificateFactory.class) +public class CertificateFactory1Test extends TestCase { + + /** + * Constructor for CertificateFactoryTests. + * + * @param arg0 + */ + public CertificateFactory1Test(String arg0) { + super(arg0); + } + + public static final String srvCertificateFactory = "CertificateFactory"; + + private static String defaultProviderName = null; + + private static Provider defaultProvider = null; + + private static boolean X509Support = false; + + public static String defaultType = "X.509"; + + public static final String[] validValues = { + "X.509", "x.509" }; + + private final static String[] invalidValues = SpiEngUtils.invalidValues; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + srvCertificateFactory); + X509Support = (defaultProvider != null); + defaultProviderName = (X509Support ? defaultProvider.getName() : null); + NotSupportMsg = defaultType.concat(" is not supported"); } + + private static CertificateFactory[] initCertFs() { + if (!X509Support) { + fail(NotSupportMsg); + return null; + } + try { + CertificateFactory[] certFs = new CertificateFactory[3]; + certFs[0] = CertificateFactory.getInstance(defaultType); + certFs[1] = CertificateFactory.getInstance(defaultType, + defaultProviderName); + certFs[2] = CertificateFactory.getInstance(defaultType, + defaultProvider); + return certFs; + } catch (Exception e) { + return null; + } + } + + private static MyCertificate createMC() { + byte[] enc = { (byte) 0, (byte) 2, (byte) 3, (byte) 4, (byte) 5 }; + return new MyCertificate("Test_Test", enc); + } + + /** + * Test for <code>getInstance(String type)</code> method + * Assertion: returns CertificateFactory if type is X.509 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateFactory01() throws CertificateException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++) { + CertificateFactory certF = CertificateFactory + .getInstance(validValues[i]); + assertEquals("Incorrect type: ", validValues[i], certF.getType()); + } + } + + /** + * Test for <code>getInstance(String type)</code> method + * Assertion: + * throws NullPointerException when type is null + * throws CertificateException when type is not available + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateFactory02() { + try { + CertificateFactory.getInstance(null); + fail("NullPointerException or CertificateException must be thrown when type is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertificateFactory.getInstance(invalidValues[i]); + fail("CertificateException must be thrown when type: " + .concat(invalidValues[i])); + } catch (CertificateException e) { + } + } + } + + /** + * Test for <code>getInstance(String type, String provider)</code> method + * Assertion: throws IllegalArgumentException when provider is null or empty + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException. " + + "IllegalArgumentException was checked instead of NoSuchProviderException", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertificateFactory03() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + String provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertificateFactory.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown when provider is null"); + } catch (IllegalArgumentException e) { + } + try { + CertificateFactory.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty"); + } catch (IllegalArgumentException e) { + } + } + } + + /** + * Test for <code>getInstance(String type, String provider)</code> method + * Assertion: + * throws NullPointerException when type is null + * throws CertificateException when type is not available + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateException and NullPointerException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertificateFactory04() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + try { + CertificateFactory.getInstance(null, defaultProviderName); + fail("NullPointerException or CertificateException must be thrown when type is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertificateFactory.getInstance(invalidValues[i], + defaultProviderName); + fail("CertificateException must be thrown (type: ".concat( + invalidValues[i]).concat(" provider: ").concat( + defaultProviderName).concat(")")); + } catch (CertificateException e) { + } + } + } + + /** + * Test for <code>getInstance(String type, String provider)</code> method + * Assertion: returns CertificateFactory when type and provider have valid + * values + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive functionality.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testCertificateFactory05() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory certF; + for (int i = 0; i < validValues.length; i++) { + certF = CertificateFactory.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect type", certF.getType(), validValues[i]); + assertEquals("Incorrect provider name", certF.getProvider() + .getName(), defaultProviderName); + } + } + + /** + * Test for <code>getInstance(String type, Provider provider)</code> + * method + * Assertion: throws IllegalArgumentException when provider is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testCertificateFactory06() throws CertificateException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + Provider provider = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertificateFactory.getInstance(validValues[i], provider); + fail("IllegalArgumentException must be thrown when provider is null"); + } catch (IllegalArgumentException e) { + } + } + } + + /** + * Test for <code>getInstance(String type, Provider provider)</code> + * method + * Assertion: + * throws NullPointerException when type is null + * throws CertificateException when type is not available + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testCertificateFactory07() throws CertificateException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + try { + CertificateFactory.getInstance(null, defaultProvider); + fail("NullPointerException or CertificateException must be thrown when type is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertificateFactory.getInstance(invalidValues[i], + defaultProvider); + fail("CertificateException was not thrown as expected (type:" + .concat(invalidValues[i]).concat(" provider: ").concat( + defaultProvider.getName()).concat(")")); + } catch (CertificateException e) { + } + } + } + + /** + * Test for <code>getInstance(String type, Provider provider)</code> + * method + * Assertion: returns CertificateFactorythrows when type and provider + * have valid values + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive functionality of getInstance method.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void testCertificateFactory08() throws CertificateException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory certF; + for (int i = 0; i < validValues.length; i++) { + certF = CertificateFactory.getInstance(validValues[i], + defaultProvider); + assertEquals("Incorrect provider", certF.getProvider(), + defaultProvider); + assertEquals("Incorrect type", certF.getType(), validValues[i]); + } + } + + /** + * Test for <code>getCertPathEncodings()</code> method + * Assertion: returns encodings + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertPathEncodings", + methodArgs = {} + ) + }) + public void testCertificateFactory09() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + Iterator it1 = certFs[0].getCertPathEncodings(); + Iterator it2 = certFs[1].getCertPathEncodings(); + assertEquals("Incorrect encodings", it1.hasNext(), it2.hasNext()); + while (it1.hasNext()) { + it2 = certFs[1].getCertPathEncodings(); + String s1 = (String) it1.next(); + boolean yesNo = false; + while (it2.hasNext()) { + if (s1.equals(it2.next())) { + yesNo = true; + break; + } + } + assertTrue("Encoding: ".concat(s1).concat( + " does not define for certF2 CertificateFactory"), yesNo); + } + it1 = certFs[0].getCertPathEncodings(); + it2 = certFs[2].getCertPathEncodings(); + assertEquals("Incorrect encodings", it1.hasNext(), it2.hasNext()); + while (it1.hasNext()) { + it2 = certFs[2].getCertPathEncodings(); + String s1 = (String) it1.next(); + boolean yesNo = false; + while (it2.hasNext()) { + if (s1.equals(it2.next())) { + yesNo = true; + break; + } + } + assertTrue("Encoding: ".concat(s1).concat( + " does not define for certF3 CertificateFactory"), yesNo); + } + } + + /** + * Test for <code>generateCertificate(InputStream inStream)</code> + * <code>generateCertificates(InputStream inStream)</code> + * <code>generateCRL(InputStream inStream)</code> + * <code>generateCRLs(InputStream inStream)</code> + * methods + * Assertion: throw CertificateException and CRLException when + * inStream is null or empty + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies methods with null and empty InputStream.", + targets = { + @TestTarget( + methodName = "generateCertificate", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCertificates", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCRL", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCRLs", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testCertificateFactory10() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + byte [] bb = {}; + InputStream is = new ByteArrayInputStream(bb); + Collection colCer; + Collection colCrl; + for (int i = 0; i < certFs.length; i++) { + try { + certFs[i].generateCertificate(null); + fail("generateCertificate must thrown CertificateException or NullPointerEXception when input stream is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + is = new ByteArrayInputStream(bb); + try { + certFs[i].generateCertificates(null); + fail("generateCertificates must throw CertificateException or NullPointerException when input stream is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + is = new ByteArrayInputStream(bb); + try { + certFs[i].generateCertificate(is); + } catch (CertificateException e) { + } + is = new ByteArrayInputStream(bb); + try { + colCer = certFs[i].generateCertificates(is); + if (colCer != null) { + assertTrue("Not empty certificate collection", colCer.isEmpty()); + } + } catch (CertificateException e) { + } + } + for (int i = 0; i < certFs.length; i++) { + try { + certFs[i].generateCRL(null); + } catch (CRLException e) { + } catch (NullPointerException e) { + } + try { + colCrl = certFs[i].generateCRLs(null); + if (colCrl != null) { + assertTrue("Not empty CRL collection was returned from null stream", colCrl.isEmpty()); + } + } catch (CRLException e) { + } catch (NullPointerException e) { + } + is = new ByteArrayInputStream(bb); + try { + certFs[i].generateCRL(is); + } catch (CRLException e) { + } + is = new ByteArrayInputStream(bb); + try { + certFs[i].generateCRLs(is); + colCrl = certFs[i].generateCRLs(null); + if (colCrl != null) { + assertTrue("Not empty CRL collection was returned from empty stream", colCrl.isEmpty()); + } + } catch (CRLException e) { + } + } + } + + /* + * Test for <code> generateCertificate(InputStream inStream) </code><code> + * generateCertificates(InputStream inStream) </code><code> + * generateCRL(InputStream inStream) </code><code> + * generateCRLs(InputStream inStream) </code> + * methods + * Assertion: throw CertificateException and CRLException when inStream + * contains incompatible datas + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive functionality of methods.", + targets = { + @TestTarget( + methodName = "generateCertificate", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCertificates", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCRL", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCRLs", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testCertificateFactory11() throws CertificateException, + NoSuchProviderException, IOException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + MyCertificate mc = createMC(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(os); + oos.writeObject(mc); + oos.flush(); + oos.close(); + + Certificate cer; + Collection colCer; + CRL crl; + Collection colCrl; + + byte[] arr = os.toByteArray(); + ByteArrayInputStream is; + for (int i = 0; i < certFs.length; i++) { + is = new ByteArrayInputStream(arr); + try { + cer = certFs[i].generateCertificate(is); + assertNull("Not null certificate was created", cer); + } catch (CertificateException e) { + } + is = new ByteArrayInputStream(arr); + try { + colCer = certFs[i].generateCertificates(is); + if (colCer != null) { + assertTrue("Not empty certificate Collection was created", colCer.isEmpty()); + } + } catch (CertificateException e) { + } + is = new ByteArrayInputStream(arr); + try { + crl = certFs[i].generateCRL(is); + assertNull("Not null CRL was created", crl); + } catch (CRLException e) { + } + is = new ByteArrayInputStream(arr); + try { + colCrl = certFs[i].generateCRLs(is); + if (colCrl != null) { + assertTrue("Not empty CRL Collection was created", colCrl.isEmpty()); + } + } catch (CRLException e) { + } + } + } + + /** + * Test for <code>generateCertPath(InputStream inStream)</code> + * <code>generateCertPath(InputStream inStream, String encoding)</code> + * methods + * Assertion: throws CertificateException when inStream is null or + * when isStream contains invalid datas + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class, java.lang.String.class} + ), + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testCertificateFactory12() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + InputStream is1 = null; + InputStream is2 = new ByteArrayInputStream(new byte[10]); + + for (int i = 0; i < certFs.length; i++) { + try { + certFs[i].generateCertPath(is1); + fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + try { + certFs[i].generateCertPath(is2); + fail("generateCertificate must thrown CertificateException when input stream contains invalid datas"); + } catch (CertificateException e) { + } + Iterator it = certFs[i].getCertPathEncodings(); + while (it.hasNext()) { + String enc = (String) it.next(); + try { + certFs[i].generateCertPath(is1, enc); + fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null and encodings " + .concat(enc)); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + try { + certFs[i].generateCertPath(is2, enc); + fail("generateCertificate must thrown CertificateException when input stream contains invalid datas and encodings " + .concat(enc)); + } catch (CertificateException e) { + } + } + } + } + + /** + * Test for <code>generateCertPath(InputStream inStream)</code> + * <code>generateCertPath(InputStream inStream, String encoding)</code> + * methods + * Assertion: throw CertificateException when isStream contains invalid datas + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class} + ), + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class, java.lang.String.class} + ) + }) + public void testCertificateFactory13() throws IOException, + CertificateException, NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + byte[] enc = { (byte) 0, (byte) 2, (byte) 3, (byte) 4, (byte) 5 }; + MyCertPath mc = new MyCertPath(enc); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + + ObjectOutputStream oos = new ObjectOutputStream(os); + oos.writeObject(mc); + oos.flush(); + oos.close(); + + byte[] arr = os.toByteArray(); + ByteArrayInputStream is = new ByteArrayInputStream(arr); + + for (int i = 0; i < certFs.length; i++) { + try { + certFs[i].generateCertPath(is); + fail("CertificateException must be thrown because input stream contains incorrect datas"); + } catch (CertificateException e) { + } + Iterator it = certFs[i].getCertPathEncodings(); + while (it.hasNext()) { + try { + certFs[i].generateCertPath(is, (String) it.next()); + fail("CertificateException must be thrown because input stream contains incorrect datas"); + } catch (CertificateException e) { + } + } + } + } + + /** + * Test for <code>generateCertPath(List certificates)</code> method + * Assertion: throw NullPointerException certificates is null + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException. " + + "Valid parameters checking missed.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void testCertificateFactory14() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + List<Certificate> list = null; + for (int i = 0; i < certFs.length; i++) { + try { + certFs[i].generateCertPath(list); + fail("generateCertificate must thrown CertificateException when list is null"); + certFs[i].generateCertPath(list); + fail("generateCertificates must throw CertificateException when list is null"); + } catch (NullPointerException e) { + } + } + } + + /** + * Test for <code>generateCertPath(List certificates)</code> method + * Assertion: returns empty CertPath if certificates is empty + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that generateCertPath method returns empty CertPath " + + "if certificates is empty. Valid parameters checking missed.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void testCertificateFactory15() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + List<Certificate> list = new Vector<Certificate>(); + for (int i = 0; i < certFs.length; i++) { + CertPath cp = certFs[i].generateCertPath(list); + List list1 = cp.getCertificates(); + assertTrue("List should be empty", list1.isEmpty()); + } + } + + /** + * Test for <code>generateCertPath(List certificates)</code> method + * Assertion: throws CertificateException when certificates contains + * incorrect Certificate + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies CertificateException. Valid parameters checking missed.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void testCertificateFactory16() throws CertificateException, + NoSuchProviderException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + MyCertificate ms = createMC(); + List<Certificate> list = new Vector<Certificate>(); + list.add(ms); + for (int i = 0; i < certFs.length; i++) { + try { + certFs[i].generateCertPath(list); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + } + } + + /** + * Test for <code>CertificateFactory</code> constructor + * Assertion: returns CertificateFactory object + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies CRLException and NullPointerException.", + targets = { + @TestTarget( + methodName = "generateCRLs", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testCertificateFactory17() throws CertificateException, + NoSuchProviderException, NoSuchAlgorithmException, CRLException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + CertificateFactorySpi spi = new MyCertificateFactorySpi(); + CertificateFactory cf = new myCertificateFactory(spi, defaultProvider, + defaultType); + assertEquals("Incorrect type", cf.getType(), defaultType); + assertEquals("Incorrect provider", cf.getProvider(), defaultProvider); + try { + cf.generateCRLs(null); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + + cf = new myCertificateFactory(null, null, null); + assertNull("Incorrect type", cf.getType()); + assertNull("Incorrect provider", cf.getProvider()); + try { + cf.generateCRLs(null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>getType()</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public void testCertificateFactory18() throws CertificateException { + if (!X509Support) { + fail(NotSupportMsg); + return; + } + for (int i = 0; i < validValues.length; i++) { + try { + CertificateFactory certF = CertificateFactory + .getInstance(validValues[i]); + assertEquals("Incorrect type: ", validValues[i], certF + .getType()); + certF = CertificateFactory.getInstance(validValues[i], + defaultProviderName); + assertEquals("Incorrect type", certF.getType(), validValues[i]); + + certF = CertificateFactory.getInstance(validValues[i], + defaultProvider); + assertEquals("Incorrect provider", certF.getProvider(), + defaultProvider); + assertEquals("Incorrect type", certF.getType(), validValues[i]); + + } catch (NoSuchProviderException e) { + fail("Unexpected NoSuchProviderException " + e.getMessage()); + } + } + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(CertificateFactory1Test.class); + } +} +/** + * Additional class to verify CertificateFactory constructor + */ + +class myCertificateFactory extends CertificateFactory { + + public myCertificateFactory(CertificateFactorySpi spi, Provider prov, + String type) { + super(spi, prov, type); + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateFactory2Test.java b/security/src/test/java/tests/security/cert/CertificateFactory2Test.java new file mode 100644 index 0000000..8760b31 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateFactory2Test.java @@ -0,0 +1,406 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import tests.security.cert.myCertPathBuilder.MyProvider; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CRL; +import java.security.cert.CRLException; +import java.security.cert.CertPath; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi; +import org.apache.harmony.security.tests.support.SpiEngUtils; + +/** + * Tests for CertificateFactory class constructors and methods + * + */ +@TestTargetClass(CertificateFactory.class) +public class CertificateFactory2Test extends TestCase { + private static final String defaultAlg = "CertFac"; + private static final String CertificateFactoryProviderClass = "tests.security.cert.support.cert.MyCertificateFactorySpi"; + + private static final String[] invalidValues = SpiEngUtils.invalidValues; + + private static final String[] validValues; + + static { + validValues = new String[4]; + validValues[0] = defaultAlg; + validValues[1] = defaultAlg.toLowerCase(); + validValues[2] = "CeRtFaC"; + validValues[3] = "cerTFac"; + } + + Provider mProv; + + protected void setUp() throws Exception { + super.setUp(); + mProv = (new SpiEngUtils()).new MyProvider("MyCFProvider", + "Provider for testing", CertificateFactory1Test.srvCertificateFactory + .concat(".").concat(defaultAlg), + CertificateFactoryProviderClass); + Security.insertProviderAt(mProv, 1); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + Security.removeProvider(mProv.getName()); + } + + /** + * Constructor for CertificateFactory2Test. + * + * @param arg0 + */ + public CertificateFactory2Test(String arg0) { + super(arg0); + } + + private void checkResult(CertificateFactory certFactory, boolean mode) + throws CertificateException, CRLException { + MyCertificateFactorySpi.putMode(mode); + + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + try { + certFactory.generateCertPath(bais); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactory.generateCertPath(dis); + if (!mode) { + fail("CertificateException must be thrown because encodings list is empty"); + } + } catch (CertificateException e) { + if (mode) { + fail("Unexpected CertificateFactoryException was thrown"); + } + } + try { + certFactory.generateCertPath(bais, "aa"); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactory.generateCertPath(dis, ""); + if (mode) { + fail("IllegalArgumentException must be thrown"); + } + } catch (IllegalArgumentException e) { + if (!mode) { + fail("Unexpected IllegalArgumentException was thrown"); + } + } + certFactory.generateCertPath(dis, "ss"); + + try { + certFactory.generateCertificate(bais); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactory.generateCertificates(null); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + Certificate cert = certFactory.generateCertificate(dis); + assertNull("Result must be null", cert); + Collection col = certFactory.generateCertificates(dis); + assertNull("Result must be null", col); + + try { + certFactory.generateCRL(bais); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + try { + certFactory.generateCRLs(null); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + CRL crl = certFactory.generateCRL(dis); + assertNull("Result must be null", crl); + col = certFactory.generateCRLs(dis); + assertNull("Result must be null", col); + + List<Certificate> list = null; + CertPath cp; + try { + cp = certFactory.generateCertPath(list); + if (mode) { + fail("NullPointerException must be thrown"); + } else { + assertNull("Must be null", cp); + } + } catch (NullPointerException e) { + if (!mode) { + fail("Unexpected NullPointerException was thrown"); + } + } + Iterator it = certFactory.getCertPathEncodings(); + if (mode) { + assertTrue(it.hasNext()); + } else { + assertFalse(it.hasNext()); + } + } + + /** + * Test for <code>getInstance(String type)</code> method + * Assertions: + * throws NullPointerException when type is null + * throws CertificateException when type is not available + * returns CertificateFactory object + */ + public void GetInstance01(boolean mode) throws CertificateException, CRLException { + try { + CertificateFactory.getInstance(null); + fail("NullPointerException or CertificateException must be thrown when type is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertificateFactory.getInstance(invalidValues[i]); + fail("CertificateException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (CertificateException e) { + } + } + CertificateFactory cerF; + for (int i = 0; i < validValues.length; i++) { + cerF = CertificateFactory.getInstance(validValues[i]); + assertEquals("Incorrect type", cerF.getType(), validValues[i]); + assertEquals("Incorrect provider", cerF.getProvider(), mProv); + checkResult(cerF, mode); + } + } + + /** + * Test for <code>getInstance(String type, String provider)</code> method + * Assertions: + * throws NullPointerException when type is null + * throws CertificateException when type is not available + * throws IllegalArgumentException when provider is null or empty; + * throws NoSuchProviderException when provider is available; + * returns CertificateFactory object + */ + + public void GetInstance02(boolean mode) throws CertificateException, + NoSuchProviderException, IllegalArgumentException, CRLException { + try { + CertificateFactory.getInstance(null, mProv.getName()); + fail("NullPointerException or CertificateException must be thrown when type is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertificateFactory.getInstance(invalidValues[i], mProv + .getName()); + fail("CertificateException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (CertificateException e) { + } + } + String prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertificateFactory.getInstance(validValues[i], prov); + fail("IllegalArgumentException must be thrown when provider is null (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + try { + CertificateFactory.getInstance(validValues[i], ""); + fail("IllegalArgumentException must be thrown when provider is empty (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + for (int i = 0; i < validValues.length; i++) { + for (int j = 1; j < invalidValues.length; j++) { + try { + CertificateFactory.getInstance(validValues[i], + invalidValues[j]); + fail("NoSuchProviderException must be thrown (type: " + .concat(validValues[i]).concat(" provider: ") + .concat(invalidValues[j]).concat(")")); + } catch (NoSuchProviderException e) { + } + } + } + CertificateFactory cerF; + for (int i = 0; i < validValues.length; i++) { + cerF = CertificateFactory.getInstance(validValues[i], mProv + .getName()); + assertEquals("Incorrect type", cerF.getType(), validValues[i]); + assertEquals("Incorrect provider", cerF.getProvider().getName(), + mProv.getName()); + checkResult(cerF, mode); + } + } + + /** + * Test for <code>getInstance(String type, Provider provider)</code> + * method + * Assertions: + * throws NullPointerException when type is null + * throws CertificateException when type is not available + * throws IllegalArgumentException when provider is null; + * returns CertificateFactory object + */ + + public void GetInstance03(boolean mode) throws CertificateException, + IllegalArgumentException, CRLException { + try { + CertificateFactory.getInstance(null, mProv); + fail("NullPointerException or CertificateException must be thrown when type is null"); + } catch (CertificateException e) { + } catch (NullPointerException e) { + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertificateFactory.getInstance(invalidValues[i], mProv); + fail("CertificateException must be thrown (type: ".concat( + invalidValues[i]).concat(")")); + } catch (CertificateException e) { + } + } + Provider prov = null; + for (int i = 0; i < validValues.length; i++) { + try { + CertificateFactory.getInstance(validValues[i], prov); + fail("IllegalArgumentException must be thrown when provider is null (type: " + .concat(validValues[i]).concat(")")); + } catch (IllegalArgumentException e) { + } + } + CertificateFactory cerF; + for (int i = 0; i < validValues.length; i++) { + cerF = CertificateFactory.getInstance(validValues[i], mProv); + assertEquals("Incorrect type", cerF.getType(), validValues[i]); + assertEquals("Incorrect provider", cerF.getProvider(), mProv); + checkResult(cerF, mode); + } + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void _testGetInstance01() throws CertificateException, CRLException { + GetInstance01(true); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void _testGetInstance02() throws CertificateException, + NoSuchProviderException, IllegalArgumentException, CRLException { + GetInstance02(true); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void _testGetInstance03() throws CertificateException, + IllegalArgumentException, CRLException { + GetInstance03(true); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void _testGetInstance04() throws CertificateException, CRLException { + GetInstance01(false); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void _testGetInstance05() throws CertificateException, + NoSuchProviderException, IllegalArgumentException, CRLException { + GetInstance02(false); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.security.Provider.class} + ) + }) + public void _testGetInstance06() throws CertificateException, + IllegalArgumentException, CRLException { + GetInstance03(false); + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateFactory3Test.java b/security/src/test/java/tests/security/cert/CertificateFactory3Test.java new file mode 100644 index 0000000..9f2acb0 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateFactory3Test.java @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.security.Provider; +import java.security.cert.CertPath; +import java.security.cert.Certificate; +import java.security.cert.CertificateFactory; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.apache.harmony.security.tests.support.cert.TestUtils; +import org.apache.harmony.security.tests.support.SpiEngUtils; +import org.apache.harmony.security.tests.support.resource.Support_Resources; + +/** + * Tests for <code>CertificateFactory</code> class methods + */ +@TestTargetClass(CertificateFactory.class) +public class CertificateFactory3Test extends TestCase { + + private static String defaultProviderName = null; + + private static Provider defaultProvider = null; + + private static String defaultType = CertificateFactory1Test.defaultType; + + public static String fileCertPathPki = "CertPath.PkiPath"; + + private static boolean X509Support = false; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + CertificateFactory1Test.srvCertificateFactory); + X509Support = defaultProvider != null; + defaultProviderName = X509Support ? defaultProvider.getName() : null; + + NotSupportMsg = defaultType.concat(" is not supported"); + } + + private static CertificateFactory[] initCertFs() throws Exception { + if (!X509Support) { + fail(NotSupportMsg); + } + + CertificateFactory[] certFs = new CertificateFactory[3]; + certFs[0] = CertificateFactory.getInstance(defaultType); + certFs[1] = CertificateFactory.getInstance(defaultType, + defaultProviderName); + certFs[2] = CertificateFactory + .getInstance(defaultType, defaultProvider); + return certFs; + } + + /** + * Test for <code>generateCertificate(InputStream inStream)</code> method + * Assertion: returns Certificate + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertificate", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGenerateCertificate() throws Exception { + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + Certificate[] certs = new Certificate[3]; + for (int i = 0; i < certFs.length; i++) { + certs[i] = certFs[i].generateCertificate(new ByteArrayInputStream( + TestUtils.getEncodedX509Certificate())); + } + assertEquals(certs[0], certs[1]); + assertEquals(certs[0], certs[2]); + } + + /** + * Test for <code>generateCertificates(InputStream inStream)</code> method + * Assertion: returns Collection which consists of 1 Certificate + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertificates", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testeGnerateCertificates() throws Exception { + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + Certificate cert = certFs[0] + .generateCertificate(new ByteArrayInputStream(TestUtils + .getEncodedX509Certificate())); + for (int i = 0; i < certFs.length; i++) { + Collection col = null; + col = certFs[i].generateCertificates(new ByteArrayInputStream( + TestUtils.getEncodedX509Certificate())); + Iterator it = col.iterator(); + assertEquals("Incorrect Collection size", col.size(), 1); + assertEquals("Incorrect Certificate in Collection", cert, it.next()); + } + } + + /** + * Test for <code>generateCertPath(List certificates)</code> method + * Assertion: returns CertPath with 1 Certificate + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void _testGenerateCertPath01() throws Exception { + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + // create list of certificates with one certificate + Certificate cert = certFs[0] + .generateCertificate(new ByteArrayInputStream(TestUtils + .getEncodedX509Certificate())); + List<Certificate> list = new Vector<Certificate>(); + list.add(cert); + for (int i = 0; i < certFs.length; i++) { + CertPath certPath = null; + certPath = certFs[i].generateCertPath(list); + assertEquals(cert.getType(), certPath.getType()); + List list1 = certPath.getCertificates(); + assertFalse("Result list is empty", list1.isEmpty()); + Iterator it = list1.iterator(); + assertEquals("Incorrect Certificate in CertPath", cert, it.next()); + } + } + + /** + * Test for + * <code>generateCertPath(InputStream inStream, String encoding)</code> + * method Assertion: returns CertPath with 1 Certificate + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class, java.lang.String.class} + ) + }) + public void _testGenerateCertPath02() throws Exception { + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + for (int i = 0; i < certFs.length; i++) { + CertPath certPath = null; + InputStream fis = Support_Resources + .getResourceStream(fileCertPathPki); + certPath = certFs[i].generateCertPath(fis, "PkiPath"); + fis.close(); + assertEquals(defaultType, certPath.getType()); + + List list1 = certPath.getCertificates(); + assertFalse("Result list is empty", list1.isEmpty()); + } + } + + /** + * Test for <code>generateCertPath(InputStream inStream)</code> method + * Assertion: returns CertPath with 1 Certificate + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class} + ) + }) + public void _testGenerateCertPath03() throws Exception { + String certPathEncoding = "PkiPath"; + CertificateFactory[] certFs = initCertFs(); + assertNotNull("CertificateFactory objects were not created", certFs); + for (int i = 0; i < certFs.length; i++) { + Iterator it = certFs[0].getCertPathEncodings(); + + assertTrue("no CertPath encodings", it.hasNext()); + + assertEquals("Incorrect default encoding", certPathEncoding, it + .next()); + + CertPath certPath = null; + InputStream fis = Support_Resources + .getResourceStream(fileCertPathPki); + certPath = certFs[i].generateCertPath(fis); + fis.close(); + assertEquals(defaultType, certPath.getType()); + + List list1 = certPath.getCertificates(); + assertFalse("Result list is empty", list1.isEmpty()); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateFactory4Test.java b/security/src/test/java/tests/security/cert/CertificateFactory4Test.java new file mode 100644 index 0000000..9e35823 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateFactory4Test.java @@ -0,0 +1,736 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CRL; +import java.security.cert.CRLException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.util.Collection; +import java.util.List; + +import tests.support.Support_GetResource; +import org.apache.harmony.security.tests.support.resource.Support_Resources; + +@TestTargetClass(CertificateFactory.class) +public class CertificateFactory4Test extends TestCase { + + private static final String BASE_URL = Support_GetResource + .getResourceURL("/../internalres/"); + + private static final String[] CERTIFICATE_URLS = new String[] { + "Bug93891-PEM.cer", "Bug93891-DER.cer", "Bug94404-PKCS7.cer" }; + + private static final String[] CRL_URLS = new String[] { "Bug93893-1.crl", + "Bug93893-2.crl", "Bug94404-DER.crl" }; + + private static final String[] CRLCOLLECTION_URLS = new String[] { "Bug94404-PKCS7.crl" }; + + /** + * @tests java.security.cert.CertificateFactory#generateCertificate(java.io.InputStream) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "generateCertificate", + methodArgs = {java.io.InputStream.class} + ) + }) + public void _test_generateCertificateLjava_io_InputStream() throws Exception { + // Test 1 + // Test for method java.security.cert.Certificate + // java.security.cert.CertificateFactory.generateCertificate(java.io.InputStream) + CertificateFactory fact = CertificateFactory.getInstance("X.509"); + for (int i = 0; i < CERTIFICATES_ENCODED_X509.length; i++) { + ByteArrayInputStream bais = new ByteArrayInputStream( + CERTIFICATES_ENCODED_X509[i].getBytes()); + fact.generateCertificate(bais); + + // try again with generateCertificates() + bais = new ByteArrayInputStream(CERTIFICATES_ENCODED_X509[i] + .getBytes()); + fact.generateCertificate(bais); + } + + // Test 2 + InputStream is = Support_Resources.getResourceStream("hyts_badpem.cer"); + try { + fact.generateCertificate(is); + fail("Test2: CertificateException not thrown"); + } catch (CertificateException e) {} finally { + try { + is.close(); + } catch (IOException ignore) {} + } + } + + /** + * @tests java.security.cert.CertificateFactory#generateCertificates(java.io.InputStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "generateCertificates", + methodArgs = {java.io.InputStream.class} + ) + }) + public void test_generateCertificatesLjava_io_InputStream() + throws Exception { + CertificateFactory fact = CertificateFactory.getInstance("X.509"); + for (int i = 0; i < CERTIFICATE_URLS.length; i++) { + URL certUrl = new URL(BASE_URL + CERTIFICATE_URLS[i]); + try { + InputStream is = certUrl.openStream(); + Collection certs = fact.generateCertificates(is); + assertNotNull("The certificates in \"" + + certUrl.toExternalForm() + + "\" were not parsed correctly", certs); + } catch (IOException e) { + // the certificate could not be found, skip it + } catch (CertificateException e) { + fail("An exception was thrown while parsing \"" + + certUrl.toExternalForm() + "\": " + e.getMessage()); + } + } + } + + /** + * @tests java.security.cert.CertificateFactory#generateCRL(java.io.InputStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "generateCRL", + methodArgs = {java.io.InputStream.class} + ) + }) + public void test_generateCRLLjava_io_InputStream() throws Exception { + CertificateFactory fact = CertificateFactory.getInstance("X.509"); + for (int i = 0; i < CRL_URLS.length; i++) { + URL certUrl = new URL(BASE_URL + CRL_URLS[i]); + try { + InputStream is = certUrl.openStream(); + CRL crl = fact.generateCRL(is); + assertNotNull("The CRL in \"" + certUrl.toExternalForm() + + "\" were not parsed correctly", crl); + } catch (IOException e) { + // the certificate could not be found, skip it + } catch (CRLException e) { + fail("An exception was thrown while parsing \"" + + certUrl.toExternalForm() + "\": " + e.getMessage()); + } + } + } + + /** + * @tests java.security.cert.CertificateFactory#generateCRLs(java.io.InputStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "generateCRLs", + methodArgs = {java.io.InputStream.class} + ) + }) + public void test_generateCRLsLjava_io_InputStream() throws Exception { + CertificateFactory fact = CertificateFactory.getInstance("X.509"); + for (int i = 0; i < CRLCOLLECTION_URLS.length; i++) { + URL certUrl = new URL(BASE_URL + CRLCOLLECTION_URLS[i]); + try { + InputStream is = certUrl.openStream(); + Collection crls = fact.generateCRLs(is); + assertTrue("The CRLs in \"" + certUrl.toExternalForm() + + "\" were not parsed correctly", crls != null + && crls.size() > 0); + } catch (IOException e) { + // the certificate could not be found, skip it + } + } + } + + /** + * @tests java.security.cert.CertificateFactory#getInstance(java.lang.String) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateException.", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class} + ) + }) + public void test_getInstanceLjava_lang_String() throws Exception { + // Test for method java.security.cert.CertificateFactory + // java.security.cert.CertificateFactory.getInstance(java.lang.String) + CertificateFactory fact = CertificateFactory.getInstance("X.509"); + assertTrue("factory is null", fact != null); + } + + /** + * @tests java.security.cert.CertificateFactory#getInstance(java.lang.String, + * java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getInstance", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void test_getInstanceLjava_lang_StringLjava_lang_String() + throws Exception { + // Test for method java.security.cert.CertificateFactory + // java.security.cert.CertificateFactory.getInstance(java.lang.String, + // java.lang.String) + Provider[] providers = Security + .getProviders("CertificateFactory.X.509"); + + if (providers != null) { + for (int i = 0; i < providers.length; i++) { + CertificateFactory fact = CertificateFactory.getInstance( + "X.509", providers[i].getName()); + assertNotNull("factory is null", fact); + }// end for + } else { + fail("No providers support CertificateFactory.X.509"); + } + + // exception case + try { + CertificateFactory.getInstance("X.509", "IHaventBeenConfigured"); + fail("Should have thrown NoSuchProviderException"); + } catch (NoSuchProviderException e) { + // Expected + } + } + + /** + * @tests java.security.cert.CertificateFactory#getProvider() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getProvider", + methodArgs = {} + ) + }) + public void test_getProvider() throws Exception { + // Test for method java.security.Provider + // java.security.cert.CertificateFactory.getProvider() + Provider p = CertificateFactory.getInstance("X.509").getProvider(); + assertNotNull("provider is null", p); + } + + /** + * @tests java.security.cert.CertificateFactory#generateCRLs(InputStream + * inStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "generateCRLs", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGenerateCRLs2() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCRL( + (InputStream) null); + fail("CRLException was not thrown"); + } catch (CRLException e) {} + } + + /** + * @tests java.security.cert.CertificateFactory#generateCertificate(InputStream + * inStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter,s and CertificateException.", + targets = { + @TestTarget( + methodName = "generateCertificate", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGenerateCertificate() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCertificate(null); + fail("CertificateException was not thrown"); + } catch (CertificateException e) {} + } + + /** + * @tests java.security.cert.CertificateFactory#generateCertificates(InputStream + * inStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "generateCertificates", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGenerateCertificates2() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCertificates(null); + fail("CertificateException was not thrown"); + } catch (CertificateException e) {} + } + + /** + * @tests java.security.cert.CertificateFactory#generateCertPath(InputStream + * inStream, String encoding) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as InputStream parameter.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class, java.lang.String.class} + ) + }) + public void testGenerateCertPath1() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCertPath( + (InputStream) null, "PkiPath"); + fail("CertificateException was not thrown"); + } catch (CertificateException e) {} + } + + /** + * @tests java.security.cert.CertificateFactory#generateCertPath(List<? + * extends Certificate> certificates) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void testGenerateCertPath2() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCertPath( + (List<Certificate>) null); + fail("NullPointerException was not thrown"); + } catch (NullPointerException e) {} + } + + /** + * @tests java.security.cert.CertificateFactory#generateCertPath(InputStream + * inStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "generateCertPath", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGenerateCertPath3() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCertPath( + (InputStream) null); + fail("CertificateException was not thrown"); + } catch (CertificateException e) {} + } + + /** + * @tests java.security.cert.CertificateFactory#generateCRL(InputStream + * inStream) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "generateCRL", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testGenerateCRL() throws Exception { + // Regression for HARMONY-814 + try { + CertificateFactory.getInstance("X.509").generateCRL( + (InputStream) null); + fail("CRLException was not thrown"); + } catch (CRLException e) {} + } + + private static final String[] CERTIFICATES_ENCODED_X509 = { + // CERTIFICATES_ENCODED_X509[0] + "-----BEGIN CERTIFICATE-----\n" + + "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n" + + "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n" + + "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n" + + "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n" + + "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n" + + "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n" + + "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n" + + "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n" + + "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n" + + "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n" + + "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n" + + "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n" + + "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[1] + "-----BEGIN CERTIFICATE-----\n" + + "MIICZzCCAdCgAwIBAgIBGzANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJVUzEY\n" + + "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n" + + "A1BLSTEcMBoGA1UEAxMTRG9EIFBLSSBNZWQgUm9vdCBDQTAeFw05ODA4MDMyMjAy\n" + + "MjlaFw0wODA4MDQyMjAyMjlaMGExCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9VLlMu\n" + + "IEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UECxMDUEtJMRwwGgYDVQQD\n" + + "ExNEb0QgUEtJIE1lZCBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" + + "gQDbrM/J9FrJSX+zxFUbsI9Vw5QbguVBIa95rwW/0M8+sM0r5gd+DY6iubm6wnXk\n" + + "CSvbfQlFEDSKr4WYeeGp+d9WlDnQdtDFLdA45tCi5SHjnW+hGAmZnld0rz6wQekF\n" + + "5xQaa5A6wjhMlLOjbh27zyscrorMJ1O5FBOWnEHcRv6xqQIDAQABoy8wLTAdBgNV\n" + + "HQ4EFgQUVrmYR6m9701cHQ3r5kXyG7zsCN0wDAYDVR0TBAUwAwEB/zANBgkqhkiG\n" + + "9w0BAQUFAAOBgQDVX1Y0YqC7vekeZjVxtyuC8Mnxbrz6D109AX07LEIRzNYzwZ0w\n" + + "MTImSp9sEzWW+3FueBIU7AxGys2O7X0qmN3zgszPfSiocBuQuXIYQctJhKjF5KVc\n" + + "VGQRYYlt+myhl2vy6yPzEVCjiKwMEb1Spu0irCf+lFW2hsdjvmSQMtZvOw==\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[2] + "-----BEGIN CERTIFICATE-----\n" + + "MIID6TCCA1KgAwIBAgIBGjANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJVUzEY\n" + + "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n" + + "A1BLSTEcMBoGA1UEAxMTRG9EIFBLSSBNZWQgUm9vdCBDQTAeFw05ODA4MDIxNjQ1\n" + + "MzhaFw0wMzA4MDIxNjQ1MzhaMFYxCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9VLlMu\n" + + "IEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UECxMDUEtJMREwDwYDVQQD\n" + + "EwhNZWQgQ0EtMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyUcrw1k6QKdB\n" + + "WjgtGOk1AVaqJNI8acDGglhqQQ94QYfqZKuo1wwdnYehrgo5QcGkw9XcjBYegLFs\n" + + "v4NCCwZ2pgsfYJlvHcSGPhT/wROUYEpXKelfXiEeaGhFl8zGcqteI2+EBbOZnFpj\n" + + "Y4y+25dQcjYnrRGMAQ98qGwQtogDiDcCAwEAAaOCAbowggG2MBYGA1UdIAQPMA0w\n" + + "CwYJYIZIAWUCAQsDMB8GA1UdIwQYMBaAFFa5mEepve9NXB0N6+ZF8hu87AjdMAwG\n" + + "A1UdJAQFMAOAAQAwHQYDVR0OBBYEFDM6FOgJZ2GIZSQg7HlwQtemkx72MA4GA1Ud\n" + + "DwEB/wQEAwIBhjB+BgNVHRIEdzB1hnNsZGFwOi8vZHMtMS5jaGFtYi5kaXNhLm1p\n" + + "bC9jbiUzZERvRCUyMFBLSSUyME1lZCUyMFJvb3QlMjBDQSUyY291JTNkUEtJJTIg\n" + + "Y291JTNkRG9EJTJjbyUzZFUuUy4lMjBHb3Zlcm5tZW50JTJjYyUzZFVTMA8GA1Ud\n" + + "EwEB/wQFMAMBAf8wgawGA1UdHwSBpDCBoTCBnqCBm6CBmIaBlWxkYXA6Ly9kcy0x\n" + + "LmNoYW1iLmRpc2EubWlsL2NuJTNkRG9EJTIwUEtJJTIwTWVkJTIwUm9vdCUyMENB\n" + + "JTJjb3UlM2RQS0klMmNvdSUzZERvRCUyY28lM2RVLlMuJTIwR292ZXJubWVudCUy\n" + + "Y2MlM2RVUz9jZXJ0aWZpY2F0ZVJldm9jYXRpb25MaXN0JTNiYmluYXJ5MA0GCSqG\n" + + "SIb3DQEBBQUAA4GBAFo5/Tu0dsy8tyhJVvxaKFNMfP3LLaspl+Or8oCpncKdpKyj\n" + + "7ZO6uJ0n7oqvEaUThm8jgXSNgyttlYPwoNBxEsTq/lBDV3+y/c61psw3qM2boB1H\n" + + "Oi3xXnRY+etG33TN9yydzrZ52XM0hnJZd4xIfoAgqs4T2rgqg8hx0ydU7o4o\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[3] + "-----BEGIN CERTIFICATE-----\n" + + "MIIDVjCCAr+gAwIBAgIBRTANBgkqhkiG9w0BAQUFADBWMQswCQYDVQQGEwJVUzEY\n" + + "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n" + + "A1BLSTERMA8GA1UEAxMITWVkIENBLTEwHhcNOTgwODAyMTcxMzI5WhcNMDEwODAy\n" + + "MTcxMzI5WjBwMQswCQYDVQQGEwJVUzEYMBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50\n" + + "MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsTA1BLSTENMAsGA1UECxMEVVNBRjEcMBoG\n" + + "A1UEAxMTZHMtMS5jaXN0dy5zYWljLmNvbTCBnTANBgkqhkiG9w0BAQEFAAOBiwAw\n" + + "gYcCgYEA19oJsspSHnWDi1/NTthbLrnicDogg3c63ZHPedU1YD90L1ogkYzxSA2t\n" + + "MgsVZpNejBglE972mXKPqEGDojnDgltRgRLtLqisIs0DSFQrJrhA8egMH/pHAo9H\n" + + "fH0n9rQUYBI3dsLxQkGVUSbB4P83VHi0sQO0dWsq5mEZd9G+MfsCAQOjggEaMIIB\n" + + "FjAWBgNVHSAEDzANMAsGCWCGSAFlAgELAzAfBgNVHSMEGDAWgBQzOhToCWdhiGUk\n" + + "IOx5cELXppMe9jAdBgNVHQ4EFgQUcQaYO8EEjje+VI3vfBIlDC6HNj0wDgYDVR0P\n" + + "AQH/BAQDAgUgMAwGA1UdEwEB/wQCMAAwgZ0GA1UdHwSBlTCBkjCBj6CBjKCBiYaB\n" + + "hmxkYXA6Ly9kcy0xLmNoYW1iLmRpc2EubWlsL2NuJTNkTWVkJTIwQ0ElMmQxJTJj\n" + + "b3UlM2RQS0klMmNvdSUzZERvRCUyY28lM2RVLlMuJTIwR292ZXJubWVudCUyY2Ml\n" + + "M2RVUz9jZXJ0aWZpY2F0ZVJldm9jYXRpb25MaXN0JTNiYmluYXJ5MA0GCSqGSIb3\n" + + "DQEBBQUAA4GBAEg7AC9bad2KZzyX4cqLU/mv2cbVg6tES2PIeST7nk8CQcv9a8IO\n" + + "3K4uhrKoTsQfqs9p6+6s0VbgH3PKvOAIF4DAp5Yq1zz3fB+hsaFleHqtDNuldm1+\n" + + "3XA2Oqa5aRFkb6Krut0EEOV4c/GEAPOrRGUTzYmOp4SEc8TEaD/75A7R\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[4] + "-----BEGIN CERTIFICATE-----\n" + + "MIIDXDCCAsWgAwIBAgIBSjANBgkqhkiG9w0BAQUFADBWMQswCQYDVQQGEwJVUzEY\n" + + "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n" + + "A1BLSTERMA8GA1UEAxMITWVkIENBLTEwHhcNOTgwODAyMTgwMjQwWhcNMDEwODAy\n" + + "MTgwMjQwWjB0MQswCQYDVQQGEwJVUzEYMBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50\n" + + "MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsTA1BLSTENMAsGA1UECxMEVVNBRjEgMB4G\n" + + "A1UEAxMXR3VtYnkuSm9zZXBoLjAwMDAwMDUwNDQwgZ8wDQYJKoZIhvcNAQEBBQAD\n" + + "gY0AMIGJAoGBALT/R7bPqs1c1YqXAg5HNpZLgW2HuAc7RCaP06cE4R44GBLw/fQc\n" + + "VRNLn5pgbTXsDnjiZVd8qEgYqjKFQka4/tNhaF7No2tBZB+oYL/eP0IWtP+h/W6D\n" + + "KR5+UvIIdgmx7k3t9jp2Q51JpHhhKEb9WN54trCO9Yu7PYU+LI85jEIBAgMBAAGj\n" + + "ggEaMIIBFjAWBgNVHSAEDzANMAsGCWCGSAFlAgELAzAfBgNVHSMEGDAWgBQzOhTo\n" + + "CWdhiGUkIOx5cELXppMe9jAdBgNVHQ4EFgQUkLBJl+ayKgzOp/wwBX9M1lSkCg4w\n" + + "DgYDVR0PAQH/BAQDAgbAMAwGA1UdEwEB/wQCMAAwgZ0GA1UdHwSBlTCBkjCBj6CB\n" + + "jKCBiYaBhmxkYXA6Ly9kcy0xLmNoYW1iLmRpc2EubWlsL2NuJTNkTWVkJTIwQ0El\n" + + "MmQxJTJjb3UlM2RQS0klMmNvdSUzZERvRCUyY28lM2RVLlMuJTIwR292ZXJubWVu\n" + + "dCUyY2MlM2RVUz9jZXJ0aWZpY2F0ZVJldm9jYXRpb25MaXN0JTNiYmluYXJ5MA0G\n" + + "CSqGSIb3DQEBBQUAA4GBAFjapuDHMvIdUeYRyEYdShBR1JZC20tJ3MQnyBQveddz\n" + + "LGFDGpIkRAQU7T/5/ne8lMexyxViC21xOlK9LdbJCbVyywvb9uEm/1je9wieQQtr\n" + + "kjykuB+WB6qTCIslAO/eUmgzfzIENvnH8O+fH7QTr2PdkFkiPIqBJYHvw7F3XDqy\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[5] + "-----BEGIN CERTIFICATE-----\n" + + "MIIDlDCCAv2gAwIBAgIBGTANBgkqhkiG9w0BAQUFADBcMQswCQYDVQQGEwJVUzEY\n" + + "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n" + + "A1BLSTEXMBUGA1UEAxMOTWVkIEVtYWlsIENBLTEwHhcNOTgwODAyMTgwNjM0WhcN\n" + + "MDAwODAyMTgwNjM0WjCBmTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD1UuUy4gR292\n" + + "ZXJubWVudDEMMAoGA1UECxMDRG9EMQwwCgYDVQQLEwNQS0kxDTALBgNVBAsTBFVT\n" + + "QUYxIDAeBgNVBAMTF0d1bWJ5Lkpvc2VwaC4wMDAwMDA1MDQ0MSMwIQYJKoZIhvcN\n" + + "AQkBFhRndW1ieUBjaXN0dy5zYWljLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw\n" + + "gYkCgYEAvU4LMoOnF9bmhHvxZz8wCc9eRJ0j4RB0SmVYoq9iPrSJBwROeuxuU8VS\n" + + "JBL/u+RB5t6UJVNjXFmB1wS0foxpOHFQBFWyvWmuOiRUNaRxTVCrO4eG+nmM/U89\n" + + "DKAc9FV4bZ8dPE9PlK9oq0J8Y2DIKz1+gIeM1sTPMnDtFgfGyH8CAwEAAaOCASYw\n" + + "ggEiMBYGA1UdIAQPMA0wCwYJYIZIAWUCAQsDMB8GA1UdIwQYMBaAFJcrSHN/a+aN\n" + + "L5DK1NpJUIvX+bVnMB0GA1UdDgQWBBR50N97AxK0G6U17EP1iu38LiLTBzAOBgNV\n" + + "HQ8BAf8EBAMCBaAwDAYDVR0TAQH/BAIwADCBqQYDVR0fBIGhMIGeMIGboIGYoIGV\n" + + "hoGSbGRhcDovL2RzLTEuY2hhbWIuZGlzYS5taWw6MzkwL2NuJTNkTWVkJTIwRW1h\n" + + "aWwlMjBDQSUyZDElMmNvdSUzZFBLSSUyY291JTNkRG9EJTJjbyUzZFUuUy4lMjBH\n" + + "b3Zlcm5tZW50JTJjYyUzZFVTP2NlcnRpZmljYXRlUmV2b2NhdGlvbkxpc3QlM2Ji\n" + + "aW5hcnkwDQYJKoZIhvcNAQEFBQADgYEAA9z8h7K4v0CuOyvmALNl8TQt0inf0w52\n" + + "JJUvw/3FLA622IHe/vC9VHyIF0ibSEljWeOBuRjoMELAZGXCwRu43o2LDRqHr4Pc\n" + + "WlG0uUtgHTPxbZpaUwueIZCBZg57f7Zhlub7Ag+AjeOybFj3FYqDB7TYqWJgAs/7\n" + + "g5WfNEVAEwc=\n" + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[6] + "-----BEGIN CERTIFICATE-----\n" + + "MIIEEjCCA7ygAwIBAgIIEt4r4gAAAlIwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNV\n" + + "BAYTAlVTMQswCQYDVQQIEwJXQTEQMA4GA1UEBxMHUmVkbW9uZDETMBEGA1UEChMK\n" + + "V2luZG93cyBOVDEbMBkGA1UECxMSRGlzdHJpYnV0ZWQgU3lzdGVtMTMwMQYDVQQD\n" + + "EypNaWNyb3NvZnQgQ2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3JvdXAgQ0EwHhcN\n" + + "OTcxMTI1MTkwNDIyWhcNOTgxMDE0MTgxMTI4WjBuMQswCQYDVQQGEwJVUzELMAkG\n" + + "A1UECBMCV0ExEDAOBgNVBAcTB1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBD\n" + + "b3Jwb3JhdGlvbjENMAsGA1UECxMERFNZUzERMA8GA1UEAxMIQ2VydFRlc3QwWzAN\n" + + "BgkqhkiG9w0BAQEFAANKADBHAkB6hKgbYme8gtCf1Vy74KVNLf2o/R1kQVDSZiNm\n" + + "lBSEsHAJSLXuuVdYsKo/hzarr9gGmI/gUzmargY1xJGQYbazAgMBAAGjggIXMIIC\n" + + "EzCBzwYDVR0jBIHHMIHEgBS3hTIRuBZaOibht1DZjnTUg/IiRaGBmaSBljCBkzEL\n" + + "MAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdSZWRtb25kMRMwEQYD\n" + + "VQQKEwpXaW5kb3dzIE5UMRswGQYDVQQLExJEaXN0cmlidXRlZCBTeXN0ZW0xMzAx\n" + + "BgNVBAMTKk1pY3Jvc29mdCBDZXJ0aWZpY2F0ZSBTZXJ2ZXIgVGVzdCBHcm91cCBD\n" + + "QYIQERNhAKoA/oUR0US54igUYzCBvQYDVR0fBIG1MIGyMFagVKBShlBodHRwOi8v\n" + + "Q0VSVFNSVi9DZXJ0U3J2L0NlcnRFbnJvbGwvTWljcm9zb2Z0IENlcnRpZmljYXRl\n" + + "IFNlcnZlciBUZXN0IEdyb3VwIENBLmNybDBYoFagVIZSZmlsZTovL1xcQ0VSVFNS\n" + + "VlxDZXJ0U3J2XENlcnRFbnJvbGxcTWljcm9zb2Z0IENlcnRpZmljYXRlIFNlcnZl\n" + + "ciBUZXN0IEdyb3VwIENBLmNybDAJBgNVHRMEAjAAMHQGCCsGAQUFBwEBBGgwZjBk\n" + + "BggrBgEFBQcwAoZYaHR0cDovL0NFUlRTUlYvQ2VydFNydi9DZXJ0RW5yb2xsL0NF\n" + + "UlRTUlZfTWljcm9zb2Z0IENlcnRpZmljYXRlIFNlcnZlciBUZXN0IEdyb3VwIENB\n" + + "LmNydDANBgkqhkiG9w0BAQQFAANBAFbEj4j/3Nv6WcAvq24C7yw8L0FcyE4dtLLX\n" + + "U+04P0POe/doyTT6UngXNXp9RXpqDSiIHBRTshpvR+N2vweR5qA=\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[7] + "-----BEGIN CERTIFICATE-----\n" + + "MIIEYTCCBAugAwIBAgIIFViWmwAAAlowDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNV\n" + + "BAYTAlVTMQswCQYDVQQIEwJXQTEQMA4GA1UEBxMHUmVkbW9uZDETMBEGA1UEChMK\n" + + "V2luZG93cyBOVDEbMBkGA1UECxMSRGlzdHJpYnV0ZWQgU3lzdGVtMTMwMQYDVQQD\n" + + "EypNaWNyb3NvZnQgQ2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3JvdXAgQ0EwHhcN\n" + + "OTcxMTI2MDYzNzE4WhcNOTgxMDE0MTgxMTI4WjCBmjEjMCEGCSqGSIb3DQEJARYU\n" + + "YWxsYW5jQG1pY3Jvc29mdC5jb20xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJXQTEQ\n" + + "MA4GA1UEBxMHUmVkbW9uZDEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9u\n" + + "MQ0wCwYDVQQLEwREU1lTMRgwFgYDVQQDEw9BbGxhbiBKLiBDb29wZXIwWzANBgkq\n" + + "hkiG9w0BAQEFAANKADBHAkB1951uZLyJXjSZTc8Z1QnuXvKBAqm2WT4OFaFySF/F\n" + + "WnMbIlAE0pvszDkKZ+N7hBzcc5pVIjezPfZ8cPh//jVPAgMBAAGjggI5MIICNTAL\n" + + "BgNVHQ8EBAMCADgwEwYDVR0lBAwwCgYIKwYBBQUHAwQwgc8GA1UdIwSBxzCBxIAU\n" + + "t4UyEbgWWjom4bdQ2Y501IPyIkWhgZmkgZYwgZMxCzAJBgNVBAYTAlVTMQswCQYD\n" + + "VQQIEwJXQTEQMA4GA1UEBxMHUmVkbW9uZDETMBEGA1UEChMKV2luZG93cyBOVDEb\n" + + "MBkGA1UECxMSRGlzdHJpYnV0ZWQgU3lzdGVtMTMwMQYDVQQDEypNaWNyb3NvZnQg\n" + + "Q2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3JvdXAgQ0GCEBETYQCqAP6FEdFEueIo\n" + + "FGMwgb0GA1UdHwSBtTCBsjBWoFSgUoZQaHR0cDovL0NFUlRTUlYvQ2VydFNydi9D\n" + + "ZXJ0RW5yb2xsL01pY3Jvc29mdCBDZXJ0aWZpY2F0ZSBTZXJ2ZXIgVGVzdCBHcm91\n" + + "cCBDQS5jcmwwWKBWoFSGUmZpbGU6Ly9cXENFUlRTUlZcQ2VydFNydlxDZXJ0RW5y\n" + + "b2xsXE1pY3Jvc29mdCBDZXJ0aWZpY2F0ZSBTZXJ2ZXIgVGVzdCBHcm91cCBDQS5j\n" + + "cmwwCQYDVR0TBAIwADB0BggrBgEFBQcBAQRoMGYwZAYIKwYBBQUHMAKGWGh0dHA6\n" + + "Ly9DRVJUU1JWL0NlcnRTcnYvQ2VydEVucm9sbC9DRVJUU1JWX01pY3Jvc29mdCBD\n" + + "ZXJ0aWZpY2F0ZSBTZXJ2ZXIgVGVzdCBHcm91cCBDQS5jcnQwDQYJKoZIhvcNAQEE\n" + + "BQADQQA1TYsk07tW0dhU6bHPK7NXHUFFiZ2fAtC0epLY9G6yuYb1lozPv5sDnCl1\n" + + "A2fZPgawvAqCvK9xkv5L4j2F+v4U\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[8] + "-----BEGIN CERTIFICATE-----\n" + + "MIIEYjCCBAygAwIBAgIIFVsHaQAAAlwwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNV\n" + + "BAYTAlVTMQswCQYDVQQIEwJXQTEQMA4GA1UEBxMHUmVkbW9uZDETMBEGA1UEChMK\n" + + "V2luZG93cyBOVDEbMBkGA1UECxMSRGlzdHJpYnV0ZWQgU3lzdGVtMTMwMQYDVQQD\n" + + "EypNaWNyb3NvZnQgQ2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3JvdXAgQ0EwHhcN\n" + + "OTcxMTI2MDYzOTU4WhcNOTgxMDE0MTgxMTI4WjCBmjEjMCEGCSqGSIb3DQEJARYU\n" + + "YWxsYW5jQG1pY3Jvc29mdC5jb20xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJXQTEQ\n" + + "MA4GA1UEBxMHUmVkbW9uZDEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9u\n" + + "MQ0wCwYDVQQLEwREU1lTMRgwFgYDVQQDEw9BbGxhbiBKLiBDb29wZXIwXDANBgkq\n" + + "hkiG9w0BAQEFAANLADBIAkEA0T1td8kfsJgwm8Qj+jtrq29tqc/DIkIbAPcyygKG\n" + + "1XEUvzQEQumVQx5lCD2LOOJs0eOuv4h6ngvLW+goDaidNQIDAQABo4ICOTCCAjUw\n" + + "CwYDVR0PBAQDAgDAMBMGA1UdJQQMMAoGCCsGAQUFBwMIMIHPBgNVHSMEgccwgcSA\n" + + "FLeFMhG4Flo6JuG3UNmOdNSD8iJFoYGZpIGWMIGTMQswCQYDVQQGEwJVUzELMAkG\n" + + "A1UECBMCV0ExEDAOBgNVBAcTB1JlZG1vbmQxEzARBgNVBAoTCldpbmRvd3MgTlQx\n" + + "GzAZBgNVBAsTEkRpc3RyaWJ1dGVkIFN5c3RlbTEzMDEGA1UEAxMqTWljcm9zb2Z0\n" + + "IENlcnRpZmljYXRlIFNlcnZlciBUZXN0IEdyb3VwIENBghARE2EAqgD+hRHRRLni\n" + + "KBRjMIG9BgNVHR8EgbUwgbIwVqBUoFKGUGh0dHA6Ly9DRVJUU1JWL0NlcnRTcnYv\n" + + "Q2VydEVucm9sbC9NaWNyb3NvZnQgQ2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3Jv\n" + + "dXAgQ0EuY3JsMFigVqBUhlJmaWxlOi8vXFxDRVJUU1JWXENlcnRTcnZcQ2VydEVu\n" + + "cm9sbFxNaWNyb3NvZnQgQ2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3JvdXAgQ0Eu\n" + + "Y3JsMAkGA1UdEwQCMAAwdAYIKwYBBQUHAQEEaDBmMGQGCCsGAQUFBzAChlhodHRw\n" + + "Oi8vQ0VSVFNSVi9DZXJ0U3J2L0NlcnRFbnJvbGwvQ0VSVFNSVl9NaWNyb3NvZnQg\n" + + "Q2VydGlmaWNhdGUgU2VydmVyIFRlc3QgR3JvdXAgQ0EuY3J0MA0GCSqGSIb3DQEB\n" + + "BAUAA0EAUPXt2pOY3YwRUHzD7Dtgyx5G7KxKtLan1wFBFjhv406v2Utb+2+wTQlS\n" + + "ulWemcm8eOdG64nspv0oqSJnA8f4xg==\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[9] + "-----BEGIN CERTIFICATE-----\n" + + "MIICiTCCAfICAQAwDQYJKoZIhvcNAQEEBQAwgYwxCzAJBgNVBAYTAlVTMRUwEwYD\n" + + "VQQIEwxOb3J0aCBEYWtvdGExFDASBgNVBAcTC0dyYW5kIEZvcmtzMRYwFAYDVQQK\n" + + "Ew1VTkQgQWVyb3NwYWNlMRgwFgYDVQQDFA9yb290QGNzLnVuZC5lZHUxHjAcBgkq\n" + + "hkiG9w0BCQEWD3Jvb3RAY3MudW5kLmVkdTAeFw05OTAzMDIyMDU4NDRaFw0wOTAy\n" + + "MjcyMDU4NDRaMIGMMQswCQYDVQQGEwJVUzEVMBMGA1UECBMMTm9ydGggRGFrb3Rh\n" + + "MRQwEgYDVQQHEwtHcmFuZCBGb3JrczEWMBQGA1UEChMNVU5EIEFlcm9zcGFjZTEY\n" + + "MBYGA1UEAxQPcm9vdEBjcy51bmQuZWR1MR4wHAYJKoZIhvcNAQkBFg9yb290QGNz\n" + + "LnVuZC5lZHUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALmlQJg5Nl2VsQZ1\n" + + "/B8fW4YDdk09SlVc7vyWcbcmbWRBJee0jcH448XdRP/m/MXIRsVKyhLA5f01+VPy\n" + + "E2aDkx2WiU4DpqbMbGGAytuXBNudJQmBXjWEFiAGe7dYgDNGKK7Yo1k49Q6qGg9q\n" + + "5did3+ppsyfzbeaiDCH0LO5gegNvAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAJnok\n" + + "1gvj4KC9HeUX/R4Q/f5tbJ2jLeQATIHtUx9QSKSq7IsdY0zz9EnKOsc9pr8JfBTL\n" + + "cAwrxqvl5QuoCFVR2tQq8DtBQY8vp7bEF2CZVoxZJXMIKKiD/Hjb0oypbq5wF0SY\n" + + "xN5DUfG5sShi+vPIAwE62tZ1P1I1N8DQpDYiXkw=\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[10] + "-----BEGIN CERTIFICATE-----\n" + + "MIICWDCCAgICAQAwDQYJKoZIhvcNAQEEBQAwgbYxCzAJBgNVBAYTAlpBMRUwEwYD\n" + + "VQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU\n" + + "VGhhd3RlIENvbnN1bHRpbmcgY2MxHzAdBgNVBAsTFkNlcnRpZmljYXRpb24gU2Vy\n" + + "dmljZXMxFzAVBgNVBAMTDnd3dy50aGF3dGUuY29tMSMwIQYJKoZIhvcNAQkBFhR3\n" + + "ZWJtYXN0ZXJAdGhhd3RlLmNvbTAeFw05NjExMTQxNzE1MjVaFw05NjEyMTQxNzE1\n" + + "MjVaMIG2MQswCQYDVQQGEwJaQTEVMBMGA1UECBMMV2VzdGVybiBDYXBlMRIwEAYD\n" + + "VQQHEwlDYXBlIFRvd24xHTAbBgNVBAoTFFRoYXd0ZSBDb25zdWx0aW5nIGNjMR8w\n" + + "HQYDVQQLExZDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzMRcwFQYDVQQDEw53d3cudGhh\n" + + "d3RlLmNvbTEjMCEGCSqGSIb3DQEJARYUd2VibWFzdGVyQHRoYXd0ZS5jb20wXDAN\n" + + "BgkqhkiG9w0BAQEFAANLADBIAkEAmpIl7aR3aSPUUwUrHzpVMrsm3gpI2PzIwMh3\n" + + "9l1h/RszI0/0qC2WRMlfwm5FapohoyjTJ6ZyGUUenICllKyKZwIDAQABMA0GCSqG\n" + + "SIb3DQEBBAUAA0EAfI57WLkOKEyQqyCDYZ6reCukVDmAe7nZSbOyKv6KUvTCiQ5c\n" + + "e5L4y3c/ViKdlou5BcQYAbxA7rwO/vz4m51w4w==\n" + + "-----END CERTIFICATE-----\n", + + // CERTIFICATES_ENCODED_X509[11] + "-----BEGIN CERTIFICATE-----\n" + + "MIIDGjCCAtgCBDaRW4swCwYHKoZIzjgEAwUAMHMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdGbG9y\n" + + "aWRhMRQwEgYDVQQHEwtHYWluZXN2aWxsZTEQMA4GA1UEChMHVW5rbm93bjEQMA4GA1UECxMHVW5r\n" + + "bm93bjEYMBYGA1UEAxMPUm9iZXJ0IEx5YmFyZ2VyMB4XDTk5MDEwNTAwMjMzOVoXDTk5MDQwNTAw\n" + + "MjMzOVowczELMAkGA1UEBhMCVVMxEDAOBgNVBAgTB0Zsb3JpZGExFDASBgNVBAcTC0dhaW5lc3Zp\n" + + "bGxlMRAwDgYDVQQKEwdVbmtub3duMRAwDgYDVQQLEwdVbmtub3duMRgwFgYDVQQDEw9Sb2JlcnQg\n" + + "THliYXJnZXIwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS30qcLuzk5/YRt1I870QA\n" + + "wx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX\n" + + "/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZndFIAccCFQCXYFCPFSML\n" + + "zLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o66oL5V0wLPQeCZ1FZV4661FlP\n" + + "5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7YnoBJDvM\n" + + "pPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhAACgYBMhs/XcF0LAjbuhoAY4EOmxd4U\n" + + "U0w4nSJQ2vKcgpyHU1Sv/tbUr3xEm6Yyx49j1eNp9jVwM1a6NYX8BO8fCSHIiUVvJVFlCcoO7Qb8\n" + + "Px7drfbFAFt8mFE1mjYCuj21ePHhs1DlZKJwu2ElC6GaRwtBk3+oCMDAnLuySd0+fAohdDALBgcq\n" + + "hkjOOAQDBQADLwAwLAIUddbqC3woMcABg/r1GPW9eVNStGwCFCBGySvdXK0i4aLVC4Ptbc3PQFjp\n" + + "-----END CERTIFICATE-----\n", + + //CERTIFICATES_ENCODED_X509[12] + "-----BEGIN CERTIFICATE-----\n" + + "MIICyzCCAjQCAQAwDQYJKoZIhvcNAQEEBQAwga0xCzAJBgNVBAYTAlVTMREwDwYD\n" + + "VQQIEwhOZXcgWW9yazEWMBQGA1UEBxMNTmV3IFlvcmsgQ2l0eTEcMBoGA1UEChMT\n" + + "Q29sdW1iaWEgVW5pdmVyc2l0eTENMAsGA1UECxMEQWNJUzEfMB0GA1UEAxMWQ29s\n" + + "dW1iaWEgVW5pdmVyc2l0eSBDQTElMCMGCSqGSIb3DQEJARYWY2VydC1hdXRoQGNv\n" + + "bHVtYmlhLmVkdTAeFw05NzA0MjgxNDQxMDNaFw0wMDA0MjgxNDQxMDNaMIGtMQsw\n" + + "CQYDVQQGEwJVUzERMA8GA1UECBMITmV3IFlvcmsxFjAUBgNVBAcTDU5ldyBZb3Jr\n" + + "IENpdHkxHDAaBgNVBAoTE0NvbHVtYmlhIFVuaXZlcnNpdHkxDTALBgNVBAsTBEFj\n" + + "SVMxHzAdBgNVBAMTFkNvbHVtYmlhIFVuaXZlcnNpdHkgQ0ExJTAjBgkqhkiG9w0B\n" + + "CQEWFmNlcnQtYXV0aEBjb2x1bWJpYS5lZHUwgZ8wDQYJKoZIhvcNAQEBBQADgY0A\n" + + "MIGJAoGBANiod6flzM72CbsK/3gzHzcdjpoozRDD/wgq31jEeDdfKY+ljAwxaZS9\n" + + "mt7S1g7lL+55fx7FjfJxvJRXvS9UbDU46PDDyJloWYobg84bK5ZcV5UnIPZmGHW/\n" + + "/xVDUtIGhc4T+Xm5p4F+4AcgewF2s4TbKWxfC98FJfepc31KjkGbAgMBAAEwDQYJ\n" + + "KoZIhvcNAQEEBQADgYEAI/e6xC+osVM4eMkSUUWgihuocQlRL9ixTlGqW9fvNlI1\n" + + "q58fELU5bcFko7d02S9Egac/9ckkt/sbHMv9zQhfnvpol8BN+LivGu+09IiOW4yq\n" + + "c9xT58Pv9gwZ/Ei5VS+FXvzHIr91yWIlwLsnKfgYDrmQowG5FkHSG1ZotUdl7Oo=\n" + + "-----END CERTIFICATE-----\n", + + //CERTIFICATES_ENCODED_X509[13] + "-----BEGIN CERTIFICATE-----\n" + + "MIICnjCCAgcCAQMwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAklUMR4wHAYD\n" + + "VQQKExVQb2xpdGVjbmljbyBkaSBUb3Jpbm8xIzAhBgNVBAsTGklDRS1URUwgSXRh\n" + + "bGlhbiBDQSBmb3IgV1dXMSAwHgYDVQQDExdDZXJ0aWZpY2F0aW9uIEF1dGhvcml0\n" + + "eTEqMCgGCSqGSIb3DQEJARYbd3d3LWNhLWl0QGljZS10ZWwucG9saXRvLml0MB4X\n" + + "DTk2MTAwMjExNDQ0NFoXDTk3MTIwMTExNDQ0NFowgY0xCzAJBgNVBAYTAklUMQ8w\n" + + "DQYDVQQHEwZUb3Jpbm8xHjAcBgNVBAoTFVBvbGl0ZWNuaWNvIGRpIFRvcmlubzEO\n" + + "MAwGA1UECxMFQ2VTSVQxGTAXBgNVBAMTEHVsaXNzZS5wb2xpdG8uaXQxIjAgBgkq\n" + + "hkiG9w0BCQEWE3dlYm1hc3RlckBwb2xpdG8uaXQwgZ8wDQYJKoZIhvcNAQEBBQAD\n" + + "gY0AMIGJAoGBAMUq/FdrxbSfGtGZq/FTTgC1JqxO4iiHiyxtgRT1oEvJIUjajVRN\n" + + "dtBVUhW6JmhHje/qnMop09XcF7b89a9ahtG9jM70S03biXVmg66pWOpy6P7znAQj\n" + + "VFPoCRR7BqUiGq0419a101Acaqkxi/4DdqiTPee4H7mcDZYu+fDPNQaHAgMBAAEw\n" + + "DQYJKoZIhvcNAQEEBQADgYEAt15bzk0XO+ZM+Q6275VTQIon6KQQHnv9NflIFOoW\n" + + "fgGRmoyiJFrjU1sIS8ctF03DH2xR20CuKd98fBpKnoOLd7eTKAGzGFPml36TPVj+\n" + + "YYWdrWqnIzQn6F0OKR/U3Y+ot5fUNuqN36Q1wsVvpPJlOMx8D8OQy8ainHgG3YYA\n" + + "TJk=\n" + "-----END CERTIFICATE-----\n", + + //CERTIFICATES_ENCODED_X509[14] + "-----BEGIN CERTIFICATE-----\n" + + "MIIC1TCCAj6gAwIBAgIBBDANBgkqhkiG9w0BAQQFADBZMQswCQYDVQQGEwJVUzEf\n" + + "MB0GA1UEChMWVW5pdmVyc2l0eSBvZiBDb2xvcmFkbzEWMBQGA1UECxMNU3lzdGVt\n" + + "IE9mZmljZTERMA8GA1UEAxMIVU1TIENBLTEwHhcNOTgwNTExMjEwMjU0WhcNMDgw\n" + + "NTEwMjEwMjU0WjBZMQswCQYDVQQGEwJVUzEfMB0GA1UEChMWVW5pdmVyc2l0eSBv\n" + + "ZiBDb2xvcmFkbzEWMBQGA1UECxMNU3lzdGVtIE9mZmljZTERMA8GA1UEAxMIVU1T\n" + + "IENBLTEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALGf8Ny+kHlXqLTi3uIf\n" + + "mkxxwDJd14sOg+hv85pxsqzCRJEgOx5YDUt05hJ7N0s4rJ/gNUcJaKR6ul+qLGbW\n" + + "+Zb4S1YFbnKaO16zggvgckwpLGYRBbmee9+E47W8VEOZWrJXUkpJ/ZV8GAnesrvn\n" + + "XTEKfm7bX9s6R7FQfDoHNnQfAgMBAAGjgawwgakwEQYJYIZIAYb4QgEBBAQDAgD2\n" + + "MB8GA1UdIwQYMBaAFOqlID9Er6dI09n9Lvnby+FISi7oMFQGCWCGSAGG+EIBDQRH\n" + + "FkVFeHRlbmRlZCBDQSBDZXJ0aWZpY2F0ZSBmcm9tIDI0IE1vbnRocyB0byAxMjAg\n" + + "TW9udGhzLiAgRFRHID0gMDUxMTE5OTgwHQYDVR0OBBYEFOqlID9Er6dI09n9Lvnb\n" + + "y+FISi7oMA0GCSqGSIb3DQEBBAUAA4GBAFNFo27JeeIgsMqS7Na//6gJQRilxwVS\n" + + "Bfx6J43YX47EgNDLn4J7B9Tst+2bDZDAk1lZyu4y2WCLrnfg/e6B1KYBhCt/Srsc\n" + + "r+WomFcw19k1jBtBaYxVwh/9N4ppZGdKILACciXbxfoLbbNgSDx5+KbE2c2m9is7\n" + + "MIZgRexTvnJa\n" + "-----END CERTIFICATE-----\n" }; +} diff --git a/security/src/test/java/tests/security/cert/CertificateFactorySpiTest.java b/security/src/test/java/tests/security/cert/CertificateFactorySpiTest.java new file mode 100644 index 0000000..b69752a --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateFactorySpiTest.java @@ -0,0 +1,517 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.InputStream; +import java.security.cert.CRL; +import java.security.cert.CRLException; +import java.security.cert.CertPath; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactorySpi; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi; + +/** + * Tests for <code>CertificateFactorySpi</code> class constructors and methods + * + */ +@TestTargetClass(CertificateFactorySpi.class) +public class CertificateFactorySpiTest extends TestCase { + /** + * Constructor for CertStoreSpiTest. + * + * @param arg0 + */ + public CertificateFactorySpiTest(String arg0) { + super(arg0); + } + + /** + * Test for <code>CertificateFactorySpi</code> constructor + * Assertion: constructs CertificateFactorySpi + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies exceptions.", + targets = { + @TestTarget( + methodName = "CertificateFactorySpi", + methodArgs = {} + ) + }) + public void testCertificateFactorySpi01() throws CertificateException, + CRLException { + CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi(); + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + try { + certFactorySpi.engineGenerateCertPath(bais); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + try { + certFactorySpi.engineGenerateCertPath(bais, ""); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + try { + List<Certificate> list = null; + certFactorySpi.engineGenerateCertPath(list); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + try { + certFactorySpi.engineGetCertPathEncodings(); + fail("UnsupportedOperationException must be thrown"); + } catch (UnsupportedOperationException e) { + } + Certificate cc = certFactorySpi.engineGenerateCertificate(bais); + assertNull("Not null Cerificate", cc); + try { + certFactorySpi.engineGenerateCertificate(null); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + Collection col = certFactorySpi.engineGenerateCertificates(bais); + assertNull("Not null Collection", col); + try { + certFactorySpi.engineGenerateCertificates(null); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + + CRL ccCRL = certFactorySpi.engineGenerateCRL(bais); + assertNull("Not null CRL", ccCRL); + try { + certFactorySpi.engineGenerateCRL(null); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + + Collection colCRL = certFactorySpi.engineGenerateCRLs(bais); + assertNull("Not null CRL", colCRL); + try { + certFactorySpi.engineGenerateCRLs(null); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + } + + /** + * Test for <code>CertificateFactorySpi</code> constructor + * Assertion: constructs CertificateFactorySpi + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateFactorySpi", + methodArgs = {} + ) + }) + public void testCertificateFactorySpi02() throws CertificateException, + CRLException { + CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi(); + MyCertificateFactorySpi.putMode(true); + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + try { + certFactorySpi.engineGenerateCertPath(bais); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + certFactorySpi.engineGenerateCertPath(dis); + try { + certFactorySpi.engineGenerateCertPath(bais, "aa"); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactorySpi.engineGenerateCertPath(dis, ""); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + certFactorySpi.engineGenerateCertPath(dis, "ss"); + + try { + certFactorySpi.engineGenerateCertificate(bais); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactorySpi.engineGenerateCertificates(null); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + Certificate cert = certFactorySpi + .engineGenerateCertificate(dis); + assertNull("Result must be null", cert); + Collection col = certFactorySpi + .engineGenerateCertificates(dis); + assertNull("Result must be null", col); + + try { + certFactorySpi.engineGenerateCRL(bais); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + try { + certFactorySpi.engineGenerateCRLs(null); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + CRL crl = certFactorySpi.engineGenerateCRL(dis); + assertNull("Result must be null", crl); + col = certFactorySpi.engineGenerateCRLs(dis); + assertNull("Result must be null", col); + + List<Certificate> list = null; + try { + certFactorySpi.engineGenerateCertPath(list); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + Iterator enc = certFactorySpi.engineGetCertPathEncodings(); + assertTrue("Incorrect Iterator", enc.hasNext()); + } + + /** + * Test for <code>CertificateFactorySpi</code> constructor + * Assertion: constructs CertificateFactorySpi + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateFactorySpi", + methodArgs = {} + ) + }) + public void testCertificateFactorySpi03() throws CertificateException, + CRLException { + CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi(); + MyCertificateFactorySpi.putMode(false); + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + try { + certFactorySpi.engineGenerateCertPath(bais); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactorySpi.engineGenerateCertPath(dis); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactorySpi.engineGenerateCertPath(bais, "aa"); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + certFactorySpi.engineGenerateCertPath(dis, ""); + certFactorySpi.engineGenerateCertPath(dis, "ss"); + + try { + certFactorySpi.engineGenerateCertificate(bais); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + try { + certFactorySpi.engineGenerateCertificates(null); + fail("CertificateException must be thrown"); + } catch (CertificateException e) { + } + Certificate cert = certFactorySpi + .engineGenerateCertificate(dis); + assertNull("Result must be null", cert); + Collection col = certFactorySpi + .engineGenerateCertificates(dis); + assertNull("Result must be null", col); + + try { + certFactorySpi.engineGenerateCRL(bais); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + try { + certFactorySpi.engineGenerateCRLs(null); + fail("CRLException must be thrown"); + } catch (CRLException e) { + } + CRL crl = certFactorySpi.engineGenerateCRL(dis); + assertNull("Result must be null", crl); + col = certFactorySpi.engineGenerateCRLs(dis); + assertNull("Result must be null", col); + + List<Certificate> list = null; + certFactorySpi.engineGenerateCertPath(list); + Iterator enc = certFactorySpi.engineGetCertPathEncodings(); + assertFalse("Incorrect Iterator", enc.hasNext()); + } + + /** + * Test for <code>engineGenerateCertPath(InputStream)</code> method. + * Assertion: Generates a <code>CertPath</code> object and initializes it + * with the data read from the <code>InputStream</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that engineGenerateCertPath method returns null.", + targets = { + @TestTarget( + methodName = "engineGenerateCertPath", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testEngineGenerateCertPathLjava_io_InputStream01() { + CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi(); + + MyCertificateFactorySpi.putMode(true); + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + + try { + assertNull(certFactorySpi.engineGenerateCertPath(dis)); + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + } + + /** + * Test for <code>engineGenerateCertPath(InputStream)</code> method. + * Assertion: Generates a <code>CertPath</code> object and initializes it + * with the data read from the <code>InputStream</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies UnsupportedOperationException.", + targets = { + @TestTarget( + methodName = "engineGenerateCertPath", + methodArgs = {java.io.InputStream.class} + ) + }) + public void testEngineGenerateCertPathLjava_io_InputStream02() { + CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi(); + + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + + try { + certFactorySpi.engineGenerateCertPath(dis); + fail("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { + // expected + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + } + + /** + * Test for <code>engineGenerateCertPath(InputStream, String)</code> + * method. Assertion: generates a <code>CertPath</code> object and + * initializes it with the data read from the <code>InputStream</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies CertificateException.", + targets = { + @TestTarget( + methodName = "engineGenerateCertPath", + methodArgs = {java.io.InputStream.class, java.lang.String.class} + ) + }) + public void testEngineGenerateCertPathLjava_io_InputStream_Ljava_lang_String01() { + CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi(); + MyCertificateFactorySpi.putMode(true); + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + try { + certFactorySpi.engineGenerateCertPath(dis, ""); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + // expected + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + + try { + assertNull(certFactorySpi.engineGenerateCertPath(dis, "encoding")); + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + } + + /** + * Test for <code>engineGenerateCertPath(InputStream, String)</code> + * method. Assertion: generates a <code>CertPath</code> object and + * initializes it with the data read from the <code>InputStream</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies UnsupportedOperationException.", + targets = { + @TestTarget( + methodName = "engineGenerateCertPath", + methodArgs = {java.io.InputStream.class, java.lang.String.class} + ) + }) + public void testEngineGenerateCertPathLjava_io_InputStream_Ljava_lang_String02() { + CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi(); + + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + DataInputStream dis = new DataInputStream(bais); + + try { + certFactorySpi.engineGenerateCertPath(dis, "encoding"); + fail("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { + // expected + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + } + + /** + * Test for <code>engineGenerateCertPath(List<? extends Certificate>)</code> + * method Assertion: generates a <code>CertPath</code> object and + * initializes it with a <code>List</code> of <code>Certificates</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that engineGenerateCertPath method returns null.", + targets = { + @TestTarget( + methodName = "engineGenerateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void testEngineGenerateCertPathLJava_util_List01() { + CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi(); + MyCertificateFactorySpi.putMode(true); + List<Certificate> list = new ArrayList<Certificate>(); + + try { + assertNull(certFactorySpi.engineGenerateCertPath(list)); + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + } + + /** + * Test for <code>engineGenerateCertPath(List<? extends Certificate>)</code> + * method Assertion: generates a <code>CertPath</code> object and + * initializes it with a <code>List</code> of <code>Certificates</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies UnsupportedOperationException.", + targets = { + @TestTarget( + methodName = "engineGenerateCertPath", + methodArgs = {java.util.List.class} + ) + }) + public void testEngineGenerateCertPathLJava_util_List02() { + CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi(); + + List<Certificate> list = new ArrayList<Certificate>(); + + try { + certFactorySpi.engineGenerateCertPath(list); + fail("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { + // expected + } catch (CertificateException e) { + fail("Unexpected CertificateException " + e.getMessage()); + } + } + + private static class extCertificateFactorySpi extends CertificateFactorySpi { + public Certificate engineGenerateCertificate(InputStream inStream) + throws CertificateException { + if (inStream == null) { + throw new CertificateException("InputStream null"); + } + return null; + } + + @SuppressWarnings("unchecked") + public Collection engineGenerateCertificates(InputStream inStream) + throws CertificateException { + if (inStream == null) { + throw new CertificateException("InputStream null"); + } + return null; + } + + public CRL engineGenerateCRL(InputStream inStream) throws CRLException { + if (inStream == null) { + throw new CRLException("InputStream null"); + } + return null; + } + + @SuppressWarnings("unchecked") + public Collection engineGenerateCRLs(InputStream inStream) + throws CRLException { + if (inStream == null) { + throw new CRLException("InputStream null"); + } + return null; + } + + public CertPath engineGenerateCertPath(InputStream inStream) + throws CertificateException { + return super.engineGenerateCertPath(inStream); + } + + public CertPath engineGenerateCertPath(InputStream inStream, + String encoding) throws CertificateException { + return super.engineGenerateCertPath(inStream, encoding); + } + + public CertPath engineGenerateCertPath( + List<? extends Certificate> certificates) + throws CertificateException { + return super.engineGenerateCertPath(certificates); + } + + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateNotYetValidExceptionTest.java b/security/src/test/java/tests/security/cert/CertificateNotYetValidExceptionTest.java new file mode 100644 index 0000000..4a36371 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateNotYetValidExceptionTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertificateNotYetValidException; + + +/** + * Tests for <code>DigestException</code> class constructors and methods. + * + */ +@TestTargetClass(CertificateNotYetValidException.class) +public class CertificateNotYetValidExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateNotYetValidExceptionTests. + * + * @param arg0 + */ + public CertificateNotYetValidExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateNotYetValidException()</code> constructor + * Assertion: constructs CertificateNotYetValidException with no detail + * message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateNotYetValidException", + methodArgs = {} + ) + }) + public void testCertificateNotYetValidException01() { + CertificateNotYetValidException tE = new CertificateNotYetValidException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateNotYetValidException(String)</code> + * constructor Assertion: constructs CertificateNotYetValidException with + * detail message msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateNotYetValidException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateNotYetValidException02() { + CertificateNotYetValidException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateNotYetValidException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateNotYetValidException(String)</code> + * constructor Assertion: constructs CertificateNotYetValidException when + * <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateNotYetValidException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateNotYetValidException03() { + String msg = null; + CertificateNotYetValidException tE = new CertificateNotYetValidException( + msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateParsingExceptionTest.java b/security/src/test/java/tests/security/cert/CertificateParsingExceptionTest.java new file mode 100644 index 0000000..c4b79cc --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateParsingExceptionTest.java @@ -0,0 +1,280 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertificateParsingException; + + +/** + * Tests for <code>CertificateParsingException</code> class constructors and + * methods. + * + */ +@TestTargetClass(CertificateParsingException.class) +public class CertificateParsingExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertificateParsingExceptionTests. + * + * @param arg0 + */ + public CertificateParsingExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>CertificateParsingException()</code> constructor + * Assertion: constructs CertificateParsingException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {} + ) + }) + public void testCertificateParsingException01() { + CertificateParsingException tE = new CertificateParsingException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateParsingException(String)</code> constructor + * Assertion: constructs CertificateParsingException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateParsingException02() { + CertificateParsingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateParsingException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateParsingException(String)</code> constructor + * Assertion: constructs CertificateParsingException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class} + ) + }) + public void testCertificateParsingException03() { + String msg = null; + CertificateParsingException tE = new CertificateParsingException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateParsingException(Throwable)</code> + * constructor Assertion: constructs CertificateParsingException when + * <code>cause</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertificateParsingException04() { + Throwable cause = null; + CertificateParsingException tE = new CertificateParsingException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateParsingException(Throwable)</code> + * constructor Assertion: constructs CertificateParsingException when + * <code>cause</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testCertificateParsingException05() { + CertificateParsingException tE = new CertificateParsingException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertificateParsingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateParsingException when + * <code>cause</code> is null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateParsingException06() { + CertificateParsingException tE = new CertificateParsingException(null, + null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>CertificateParsingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateParsingException when + * <code>cause</code> is null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the second parameter.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateParsingException07() { + CertificateParsingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateParsingException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>CertificateParsingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateParsingException when + * <code>cause</code> is not null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as the first parameter.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateParsingException08() { + CertificateParsingException tE = new CertificateParsingException(null, + tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>CertificateParsingException(String, Throwable)</code> + * constructor Assertion: constructs CertificateParsingException when + * <code>cause</code> is not null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive functionality.", + targets = { + @TestTarget( + methodName = "CertificateParsingException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testCertificateParsingException09() { + CertificateParsingException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertificateParsingException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/cert/CertificateTest.java b/security/src/test/java/tests/security/cert/CertificateTest.java new file mode 100644 index 0000000..1bea03b --- /dev/null +++ b/security/src/test/java/tests/security/cert/CertificateTest.java @@ -0,0 +1,367 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ObjectStreamException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.SignatureException; +import java.security.cert.Certificate; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.util.Arrays; + +import org.apache.harmony.security.tests.support.cert.MyCertificate; + +/** + * Tests for <code>Certificate</code> fields and methods + * + */ +@TestTargetClass(Certificate.class) +public class CertificateTest extends TestCase { + /** + * Meaningless cert encoding just for testing purposes + */ + private static final byte[] testEncoding = new byte[] { (byte) 1, (byte) 2, + (byte) 3, (byte) 4, (byte) 5 }; + + /** + * Constructor for CertificateTest. + * @param name + */ + public CertificateTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test for <code>Certificate(String type)</code> method<br> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "Certificate", + methodArgs = {java.lang.String.class} + ) + }) + public final void testCertificate() { + try { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + assertTrue(Arrays.equals(testEncoding, c1.getEncoded())); + assertEquals("TEST", c1.getPublicKey().getAlgorithm()); + assertTrue(Arrays.equals( + new byte[] { (byte) 1, (byte) 2, (byte) 3 }, c1 + .getPublicKey().getEncoded())); + assertEquals("TEST_FORMAT", c1.getPublicKey().getFormat()); + assertEquals("TEST_TYPE", c1.getType()); + } catch (CertificateEncodingException e) { + fail("Unexpected CertificateEncodingException " + e.getMessage()); + } + } + + /** + * Test for <code>hashCode()</code> method<br> + * Assertion: returns hash of the <code>Certificate</code> instance + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify different objects.", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + Certificate c2 = new MyCertificate("TEST_TYPE", testEncoding); + + assertTrue(c1.hashCode() == c2.hashCode()); + } + + /** + * Test for <code>hashCode()</code> method<br> + * Assertion: hash code of equal objects should be the same + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify different objects (the same as previous test).", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCodeEqualsObject() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + Certificate c2 = new MyCertificate("TEST_TYPE", testEncoding); + + assertTrue((c1.hashCode() == c2.hashCode()) && c1.equals(c2)); + } + + + /** + * Test for <code>getType()</code> method<br> + * Assertion: returns this certificate type + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public final void testGetType() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + assertEquals("TEST_TYPE", c1.getType()); + } + + /** + * Test #1 for <code>equals(Object)</code> method<br> + * Assertion: object equals to itself + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject01() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + assertTrue(c1.equals(c1)); + } + + /** + * Test for <code>equals(Object)</code> method<br> + * Assertion: object equals to other <code>Certificate</code> + * instance with the same state + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject02() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + Certificate c2 = new MyCertificate("TEST_TYPE", testEncoding); + assertTrue(c1.equals(c2) && c2.equals(c1)); + } + + /** + * Test for <code>equals(Object)</code> method<br> + * Assertion: object not equals to <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies equals method with null as a parameter.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject03() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + assertFalse(c1.equals(null)); + } + + /** + * Test for <code>equals(Object)</code> method<br> + * Assertion: object not equals to other which is not + * instance of <code>Certificate</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies negative case.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject04() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + assertFalse(c1.equals("TEST_TYPE")); + } + + // + // the following tests just call methods + // that are abstract in <code>Certificate</code> + // (So they just like signature tests) + // + + /** + * This test just calls <code>getEncoded()</code> method<br> + * @throws CertificateEncodingException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateEncodingException.", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded() throws CertificateEncodingException { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + c1.getEncoded(); + } + + /** + * This test just calls <code>verify(PublicKey)</code> method<br> + * + * @throws InvalidKeyException + * @throws CertificateException + * @throws NoSuchAlgorithmException + * @throws NoSuchProviderException + * @throws SignatureException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies only null as a parameter.", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {java.security.PublicKey.class} + ) + }) + public final void testVerifyPublicKey() + throws InvalidKeyException, + CertificateException, + NoSuchAlgorithmException, + NoSuchProviderException, + SignatureException { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + c1.verify(null); + } + + /** + * This test just calls <code>verify(PublicKey,String)</code> method<br> + * + * @throws InvalidKeyException + * @throws CertificateException + * @throws NoSuchAlgorithmException + * @throws NoSuchProviderException + * @throws SignatureException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies only null as parameters.", + targets = { + @TestTarget( + methodName = "verify", + methodArgs = {java.security.PublicKey.class, java.lang.String.class} + ) + }) + public final void testVerifyPublicKeyString() + throws InvalidKeyException, + CertificateException, + NoSuchAlgorithmException, + NoSuchProviderException, + SignatureException { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + c1.verify(null, null); + } + + /** + * This test just calls <code>toString()</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + c1.toString(); + } + + /** + * This test just calls <code>testGetPublicKey()</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicKey", + methodArgs = {} + ) + }) + public final void testGetPublicKey() { + Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + c1.getPublicKey(); + } + + /** + * This test just calls <code>writeReplace()</code> method<br> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "DOesn't verify ObjectStreamException.", + targets = { + @TestTarget( + methodName = "writeReplace", + methodArgs = {} + ) + }) + public final void testWriteReplace() { + MyCertificate c1 = new MyCertificate("TEST_TYPE", testEncoding); + + try { + Object obj = c1.writeReplace(); + assertTrue(obj.toString().contains( + "java.security.cert.Certificate$CertificateRep")); + } catch (ObjectStreamException e) { + fail("Unexpected ObjectStreamException " + e.getMessage()); + } + } + +} diff --git a/security/src/test/java/tests/security/cert/CollectionCertStoreParametersTest.java b/security/src/test/java/tests/security/cert/CollectionCertStoreParametersTest.java new file mode 100644 index 0000000..7ab2227 --- /dev/null +++ b/security/src/test/java/tests/security/cert/CollectionCertStoreParametersTest.java @@ -0,0 +1,364 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertStoreParameters; +import java.security.cert.Certificate; +import java.security.cert.CollectionCertStoreParameters; +import java.util.Collection; +import java.util.Vector; + +import org.apache.harmony.security.tests.support.cert.MyCertificate; +/** + * Tests for <code>CollectionCertStoreParameters</code> + * + */ +@TestTargetClass(CollectionCertStoreParameters.class) +public class CollectionCertStoreParametersTest extends TestCase { + + /** + * Constructor for CollectionCertStoreParametersTest. + * @param name + */ + public CollectionCertStoreParametersTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>CollectionCertStoreParameters()</code> constructor<br> + * Assertion: Creates an instance of CollectionCertStoreParameters + * with the default parameter values (an empty and immutable Collection) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CollectionCertStoreParameters", + methodArgs = {} + ) + }) + public final void testCollectionCertStoreParameters01() { + CertStoreParameters cp = new CollectionCertStoreParameters(); + assertTrue("isCollectionCertStoreParameters", + cp instanceof CollectionCertStoreParameters); + } + + /** + * Test #2 for <code>CollectionCertStoreParameters</code> constructor<br> + * Assertion: Creates an instance of CollectionCertStoreParameters + * with the default parameter values (an empty and immutable Collection) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CollectionCertStoreParameters", + methodArgs = {} + ) + }) + @SuppressWarnings("unchecked") + public final void testCollectionCertStoreParameters02() { + CollectionCertStoreParameters cp = new CollectionCertStoreParameters(); + Collection c = cp.getCollection(); + assertTrue("isEmpty", c.isEmpty()); + + // check that empty collection is immutable + try { + // try to modify it + c.add(new Object()); + fail("empty collection must be immutable"); + } catch (Exception e) { + } + } + + /** + * Test #1 for <code>CollectionCertStoreParameters(Collection)</code> + * constructor<br> + * Assertion: Creates an instance of CollectionCertStoreParameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CollectionCertStoreParameters", + methodArgs = {java.util.Collection.class} + ) + }) + public final void testCollectionCertStoreParametersCollection01() { + Vector<Certificate> certificates = new Vector<Certificate>(); + certificates.add(new MyCertificate("TEST", new byte[] {})); + new CollectionCertStoreParameters(certificates); + } + + /** + * Test #2 for <code>CollectionCertStoreParameters(Collection)</code> + * constructor<br> + * Assertion: If the specified <code>Collection</code> contains an object + * that is not a <code>Certificate</code> or <code>CRL</code>, that object + * will be ignored by the Collection <code>CertStore</code>. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CollectionCertStoreParameters", + methodArgs = {java.util.Collection.class} + ) + }) + public final void testCollectionCertStoreParametersCollection02() { + // just check that we able to create CollectionCertStoreParameters + // object passing Collection containing Object which is not + // a Certificate or CRL + Vector<String> certificates = new Vector<String>(); + certificates.add(new String("Not a Certificate")); + new CollectionCertStoreParameters(certificates); + } + + /** + * Test #3 for <code>CollectionCertStoreParameters(Collection)</code> + * constructor<br> + * Assertion: The Collection is not copied. Instead, a reference is used. + * This allows the caller to subsequently add or remove Certificates or + * CRLs from the Collection, thus changing the set of Certificates or CRLs + * available to the Collection CertStore. The Collection CertStore will + * not modify the contents of the Collection + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CollectionCertStoreParameters", + methodArgs = {java.util.Collection.class} + ) + }) + public final void testCollectionCertStoreParametersCollection03() { + Vector<Certificate> certificates = new Vector<Certificate>(); + // create using empty collection + CollectionCertStoreParameters cp = + new CollectionCertStoreParameters(certificates); + // check that the reference is used + assertTrue("isRefUsed_1", certificates == cp.getCollection()); + // check that collection still empty + assertTrue("isEmpty", cp.getCollection().isEmpty()); + // modify our collection + certificates.add(new MyCertificate("TEST", new byte[] {(byte)1})); + certificates.add(new MyCertificate("TEST", new byte[] {(byte)2})); + // check that internal state has been changed accordingly + assertTrue("isRefUsed_2", certificates.equals(cp.getCollection())); + } + + /** + * Test #4 for <code>CollectionCertStoreParameters(Collection)</code> + * constructor<br> + * Assertion: <code>NullPointerException</code> - if + * <code>collection</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "CollectionCertStoreParameters", + methodArgs = {java.util.Collection.class} + ) + }) + public final void testCollectionCertStoreParametersCollection04() { + try { + new CollectionCertStoreParameters(null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #1 for <code>clone()</code> method<br> + * Assertion: Returns a copy of this object + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone01() { + Vector<Certificate> certificates = new Vector<Certificate>(); + certificates.add(new MyCertificate("TEST", new byte[] {(byte)4})); + CollectionCertStoreParameters cp1 = + new CollectionCertStoreParameters(certificates); + CollectionCertStoreParameters cp2 = + (CollectionCertStoreParameters)cp1.clone(); + // check that that we have new object + assertTrue(cp1 != cp2); + } + + /** + * Test #2 for <code>clone()</code> method<br> + * Assertion: ...only a reference to the <code>Collection</code> + * is copied, and not the contents + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone02() { + Vector<Certificate> certificates = new Vector<Certificate>(); + certificates.add(new MyCertificate("TEST", new byte[] {(byte)4})); + CollectionCertStoreParameters cp1 = + new CollectionCertStoreParameters(certificates); + CollectionCertStoreParameters cp2 = + (CollectionCertStoreParameters)cp1.clone(); + // check that both objects hold the same reference + assertTrue(cp1.getCollection() == cp2.getCollection()); + } + + /** + * Test #3 for <code>clone()</code> method<br> + * Assertion: ...only a reference to the <code>Collection</code> + * is copied, and not the contents + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone03() { + CollectionCertStoreParameters cp1 = + new CollectionCertStoreParameters(); + CollectionCertStoreParameters cp2 = + (CollectionCertStoreParameters)cp1.clone(); + CollectionCertStoreParameters cp3 = + (CollectionCertStoreParameters)cp2.clone(); + // check that all objects hold the same reference + assertTrue(cp1.getCollection() == cp2.getCollection() && + cp3.getCollection() == cp2.getCollection()); + } + + /** + * Test #1 for <code>toString()</code> method<br> + * Assertion: returns the formatted string describing parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString01() { + CollectionCertStoreParameters cp = + new CollectionCertStoreParameters(); + String s = cp.toString(); + assertNotNull(s); + } + + /** + * Test #2 for <code>toString()</code> method<br> + * Assertion: returns the formatted string describing parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString02() { + Vector<Certificate> certificates = new Vector<Certificate>(); + certificates.add(new MyCertificate("TEST", new byte[] {(byte)4})); + CollectionCertStoreParameters cp = + new CollectionCertStoreParameters(certificates); + + assertNotNull(cp.toString()); + } + + /** + * Test #1 for <code>getCollection()</code> method<br> + * Assertion: returns the Collection (never null) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getCollection", + methodArgs = {} + ) + }) + public final void testGetCollection01() { + CollectionCertStoreParameters cp = new CollectionCertStoreParameters(); + assertNotNull(cp.getCollection()); + } + + /** + * Test #2 for <code>getCollection()</code> method<br> + * Assertion: returns the Collection (never null) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getCollection", + methodArgs = {} + ) + }) + public final void testGetCollection02() { + Vector certificates = new Vector(); + CollectionCertStoreParameters cp = + new CollectionCertStoreParameters(certificates); + assertNotNull(cp.getCollection()); + } + +} diff --git a/security/src/test/java/tests/security/cert/LDAPCertStoreParametersTest.java b/security/src/test/java/tests/security/cert/LDAPCertStoreParametersTest.java new file mode 100644 index 0000000..3e75e37 --- /dev/null +++ b/security/src/test/java/tests/security/cert/LDAPCertStoreParametersTest.java @@ -0,0 +1,306 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertStoreParameters; +import java.security.cert.LDAPCertStoreParameters; + +/** + * Tests for <code>java.security.cert.LDAPCertStoreParameters</code> + * fields and methods + * + */ +@TestTargetClass(LDAPCertStoreParameters.class) +public class LDAPCertStoreParametersTest extends TestCase { + + /** + * Constructor for LDAPCertStoreParametersTest. + * @param name + */ + public LDAPCertStoreParametersTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>LDAPCertStoreParameters()</code> constructor<br> + * Assertion: Creates an instance of <code>LDAPCertStoreParameters</code> + * with the default parameter values (server name "localhost", port 389) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {} + ) + }) + public final void testLDAPCertStoreParameters01() { + CertStoreParameters cp = new LDAPCertStoreParameters(); + assertTrue("isLDAPCertStoreParameters", + cp instanceof LDAPCertStoreParameters); + } + + /** + * Test #2 for <code>LDAPCertStoreParameters()</code> constructor<br> + * Assertion: Creates an instance of <code>LDAPCertStoreParameters</code> + * with the default parameter values (server name "localhost", port 389) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {} + ) + }) + public final void testLDAPCertStoreParameters02() { + LDAPCertStoreParameters cp = new LDAPCertStoreParameters(); + assertEquals("host", "localhost", cp.getServerName()); + assertEquals("port", 389, cp.getPort()); + } + + /** + * Test #1 for <code>LDAPCertStoreParameters(String)</code> constructor<br> + * Assertion: Creates an instance of <code>LDAPCertStoreParameters</code> + * with the specified server name and a default port of 389 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {java.lang.String.class} + ) + }) + public final void testLDAPCertStoreParametersString01() { + CertStoreParameters cp = new LDAPCertStoreParameters("myhost"); + assertTrue("isLDAPCertStoreParameters", + cp instanceof LDAPCertStoreParameters); + } + + /** + * Test #2 for <code>LDAPCertStoreParameters(String)</code> constructor<br> + * Assertion: Creates an instance of <code>LDAPCertStoreParameters</code> + * with the specified server name and a default port of 389 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {java.lang.String.class} + ) + }) + public final void testLDAPCertStoreParametersString02() { + String serverName = "myhost"; + LDAPCertStoreParameters cp = new LDAPCertStoreParameters(serverName); + assertTrue("host", serverName.equals(cp.getServerName())); + assertEquals("port", 389, cp.getPort()); + } + + /** + * Test #3 for <code>LDAPCertStoreParameters(String)</code> constructor<br> + * Assertion: throws <code>NullPointerException</code> - + * if <code>serverName</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {java.lang.String.class} + ) + }) + public final void testLDAPCertStoreParametersString03() { + try { + new LDAPCertStoreParameters(null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #1 for <code>LDAPCertStoreParameters(String, int)</code> constructor<br> + * Assertion: Creates an instance of <code>LDAPCertStoreParameters</code> + * with the specified parameter values + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Incorrect int parameter checking missed", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {java.lang.String.class, int.class} + ) + }) + public final void testLDAPCertStoreParametersStringint01() { + CertStoreParameters cp = new LDAPCertStoreParameters("myhost", 1098); + assertTrue("isLDAPCertStoreParameters", + cp instanceof LDAPCertStoreParameters); + } + + /** + * Test #2 for <code>LDAPCertStoreParameters(String, int)</code> constructor<br> + * Assertion: Creates an instance of <code>LDAPCertStoreParameters</code> + * with the specified parameter values + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Incorrect int parameter checking missed", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {java.lang.String.class, int.class} + ) + }) + public final void testLDAPCertStoreParametersStringint02() { + String serverName = "myhost"; + int portNumber = 1099; + LDAPCertStoreParameters cp = + new LDAPCertStoreParameters(serverName, portNumber); + assertTrue("host", serverName.equals(cp.getServerName())); + assertTrue("port", cp.getPort() == portNumber); + } + + /** + * Test #3 for <code>LDAPCertStoreParameters(String, int)</code> constructor<br> + * Assertion: throws <code>NullPointerException</code> - + * if <code>serverName</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException. Incorrect int parameter checking missed", + targets = { + @TestTarget( + methodName = "LDAPCertStoreParameters", + methodArgs = {java.lang.String.class, int.class} + ) + }) + public final void testLDAPCertStoreParametersStringint03() { + try { + new LDAPCertStoreParameters(null, 0); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>clone()</code> method<br> + * Assertion: Returns a copy of this object + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone() { + LDAPCertStoreParameters cp1 = + new LDAPCertStoreParameters("myhost", 1100); + LDAPCertStoreParameters cp2 = (LDAPCertStoreParameters)cp1.clone(); + // check that that we have new object + assertTrue("newObject", cp1 != cp2); + assertTrue("hostsTheSame", + cp1.getServerName().equals(cp2.getServerName())); + assertTrue("portsTheSame", cp1.getPort() == cp2.getPort()); + } + + /** + * Test for <code>toString()</code> method<br> + * Assertion: returns the formatted string describing parameters + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() { + LDAPCertStoreParameters cp1 = + new LDAPCertStoreParameters("myhost", 1101); + + assertNotNull(cp1.toString()); + } + + /** + * Test for <code>toString()</code> method<br> + * Assertion: returns the port number + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPort", + methodArgs = {} + ) + }) + public final void testGetPort() { + int portNumber = -1099; + LDAPCertStoreParameters cp = + new LDAPCertStoreParameters("serverName", portNumber); + assertTrue(cp.getPort() == portNumber); + } + + /** + * Test for <code>toString()</code> method<br> + * Assertion: returns the server name (never <code>null</code>) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getServerName", + methodArgs = {} + ) + }) + public final void testGetServerName() { + LDAPCertStoreParameters cp = + new LDAPCertStoreParameters("serverName"); + assertNotNull(cp.getServerName()); + } + +} diff --git a/security/src/test/java/tests/security/cert/PKIXBuilderParametersTest.java b/security/src/test/java/tests/security/cert/PKIXBuilderParametersTest.java new file mode 100644 index 0000000..6f195da --- /dev/null +++ b/security/src/test/java/tests/security/cert/PKIXBuilderParametersTest.java @@ -0,0 +1,514 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidParameterException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.cert.CertificateFactory; +import java.security.cert.PKIXBuilderParameters; +import java.security.cert.PKIXParameters; +import java.security.cert.TrustAnchor; +import java.security.cert.X509CertSelector; +import java.security.cert.X509Certificate; +import java.util.HashSet; +import java.util.Set; + +import org.apache.harmony.security.tests.support.cert.TestUtils; + +/** + * Tests for <code>PKIXBuilderParameters</code> fields and methods + * + */ +@TestTargetClass(PKIXBuilderParameters.class) +public class PKIXBuilderParametersTest extends TestCase { + String certificate = "-----BEGIN CERTIFICATE-----\n" + + "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n" + + "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n" + + "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n" + + "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n" + + "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n" + + "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n" + + "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n" + + "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n" + + "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n" + + "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n" + + "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n" + + "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n" + + "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n" + + "-----END CERTIFICATE-----\n"; + + String certificate2 = "-----BEGIN CERTIFICATE-----\n" + + "MIICZzCCAdCgAwIBAgIBGzANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJVUzEY\n" + + "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n" + + "A1BLSTEcMBoGA1UEAxMTRG9EIFBLSSBNZWQgUm9vdCBDQTAeFw05ODA4MDMyMjAy\n" + + "MjlaFw0wODA4MDQyMjAyMjlaMGExCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9VLlMu\n" + + "IEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UECxMDUEtJMRwwGgYDVQQD\n" + + "ExNEb0QgUEtJIE1lZCBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" + + "gQDbrM/J9FrJSX+zxFUbsI9Vw5QbguVBIa95rwW/0M8+sM0r5gd+DY6iubm6wnXk\n" + + "CSvbfQlFEDSKr4WYeeGp+d9WlDnQdtDFLdA45tCi5SHjnW+hGAmZnld0rz6wQekF\n" + + "5xQaa5A6wjhMlLOjbh27zyscrorMJ1O5FBOWnEHcRv6xqQIDAQABoy8wLTAdBgNV\n" + + "HQ4EFgQUVrmYR6m9701cHQ3r5kXyG7zsCN0wDAYDVR0TBAUwAwEB/zANBgkqhkiG\n" + + "9w0BAQUFAAOBgQDVX1Y0YqC7vekeZjVxtyuC8Mnxbrz6D109AX07LEIRzNYzwZ0w\n" + + "MTImSp9sEzWW+3FueBIU7AxGys2O7X0qmN3zgszPfSiocBuQuXIYQctJhKjF5KVc\n" + + "VGQRYYlt+myhl2vy6yPzEVCjiKwMEb1Spu0irCf+lFW2hsdjvmSQMtZvOw==\n" + + "-----END CERTIFICATE-----\n"; + + /** + * Constructor for PKIXBuilderParametersTest. + * @param name + */ + public PKIXBuilderParametersTest(String name) { + super(name); + } + + /** + * Test #1 for <code>PKIXBuilderParameters(Set, CertSelector)</code> + * constructor<br> + * Assertion: creates an instance of <code>PKIXBuilderParameters</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.util.Set.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersSetCertSelector01() + throws InvalidAlgorithmParameterException { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + // both parameters are valid and non-null + PKIXParameters p = + new PKIXBuilderParameters(taSet, new X509CertSelector()); + assertTrue("instanceOf", p instanceof PKIXBuilderParameters); + assertNotNull("certSelector", p.getTargetCertConstraints()); + } + + /** + * Test #2 for <code>PKIXBuilderParameters(Set, CertSelector)</code> + * constructor<br> + * Assertion: creates an instance of <code>PKIXBuilderParameters</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a CertSelector parameter.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.util.Set.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersSetCertSelector02() + throws InvalidAlgorithmParameterException { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + // both parameters are valid but CertSelector is null + PKIXParameters p = new PKIXBuilderParameters(taSet, null); + assertTrue("instanceOf", p instanceof PKIXBuilderParameters); + assertNull("certSelector", p.getTargetCertConstraints()); + } + + /** + * Test #3 for <code>PKIXBuilderParameters(Set, CertSelector)</code> + * constructor<br> + * Assertion: ... the <code>Set</code> is copied to protect against + * subsequent modifications + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a CertSelector parameter.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.util.Set.class, java.security.cert.CertSelector.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testPKIXBuilderParametersSetCertSelector03() + throws InvalidAlgorithmParameterException { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + HashSet<TrustAnchor> originalSet = (HashSet<TrustAnchor>) taSet; + HashSet<TrustAnchor> originalSetCopy = (HashSet<TrustAnchor>) originalSet + .clone(); + // create test object using originalSet + PKIXBuilderParameters pp = + new PKIXBuilderParameters(originalSetCopy, null); + // modify originalSet + originalSetCopy.clear(); + // check that test object's internal state + // has not been affected by the above modification + Set returnedSet = pp.getTrustAnchors(); + assertEquals(originalSet, returnedSet); + } + + /** + * Test #4 for <code>PKIXBuilderParameters(Set, CertSelector)</code> + * constructor<br> + * Assertion: <code>NullPointerException</code> - + * if the specified <code>Set</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.util.Set.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersSetCertSelector04() throws Exception { + try { + // pass null + new PKIXBuilderParameters((Set<TrustAnchor>) null, null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #5 for <code>PKIXBuilderParameters(Set, CertSelector)</code> + * constructor<br> + * Assertion: <code>InvalidAlgorithmParameterException</code> - + * if the specified <code>Set</code> is empty + * (<code>trustAnchors.isEmpty() == true</code>) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.util.Set.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersSetCertSelector05() { + try { + // use empty set + new PKIXBuilderParameters(new HashSet<TrustAnchor>(), null); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + } + } + + /** + * Test #6 for <code>PKIXBuilderParameters(Set, CertSelector)</code> + * constructor<br> + * Assertion: <code>ClassCastException</code> - + * if any of the elements in the <code>Set</code> are not of type + * <code>java.security.cert.TrustAnchor</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies ClassCastException.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.util.Set.class, java.security.cert.CertSelector.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testPKIXBuilderParametersSetCertSelector06() + throws Exception { + Set taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + // add wrong object to valid set + assertTrue(taSet.add(new Object())); + + try { + new PKIXBuilderParameters(taSet, null); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + } + } + + /** + * Test #1 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code> + * constructor<br> + * Assertion: <code>NullPointerException</code> - if the + * <code>keystore</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Veirifies null as a KeyStore parameter.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.security.KeyStore.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersKeyStoreCertSelector01() + throws Exception { + try { + new PKIXBuilderParameters((KeyStore) null, new X509CertSelector()); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * Test #2 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code> + * constructor<br> + * Assertion: <code>KeyStoreException</code> - if the + * <code>keystore</code> has not been initialized + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Veirifies null as a CertSelector parameter.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.security.KeyStore.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersKeyStoreCertSelector02() + throws Exception { + KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); + try { + new PKIXBuilderParameters(keyTest, null); + fail("KeyStoreException expected"); + } catch (KeyStoreException e) { + // expected + } + } + + /** + * Test #3 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code> + * constructor<br> + * Assertion: <code>InvalidAlgorithmParameterException</code> - if the + * <code>keystore</code> does not contain at least one trusted certificate + * entry + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.security.KeyStore.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersKeyStoreCertSelector03() + throws Exception { + KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); + keyTest.load(null, null); + try { + new PKIXBuilderParameters(keyTest, new X509CertSelector()); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + // expected + } + } + + /** + * Test #4 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code> + * constructor<br> + * Assertion: <code>NullPointerException</code> - + * if the <code>keystore</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "PKIXBuilderParameters", + methodArgs = {java.security.KeyStore.class, java.security.cert.CertSelector.class} + ) + }) + public final void testPKIXBuilderParametersKeyStoreCertSelector04() + throws Exception { + KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); + keyTest.load(null, null); + + ByteArrayInputStream certArray = new ByteArrayInputStream(certificate + .getBytes()); + + ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2 + .getBytes()); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert[] = new X509Certificate[2]; + cert[0] = (X509Certificate) cf.generateCertificate(certArray); + cert[1] = (X509Certificate) cf.generateCertificate(certArray2); + + keyTest.setCertificateEntry("alias1", cert[0]); + keyTest.setCertificateEntry("alias2", cert[0]); + keyTest.setCertificateEntry("alias3", cert[1]); + + try { + PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, + new X509CertSelector()); + assertEquals(3, p.getTrustAnchors().size()); + assertEquals(5, p.getMaxPathLength()); + } catch (Exception e) { + fail("Unexpected exception " + e.getMessage()); + } + } + + /** + * Test for <code>getMaxPathLength()</code> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMaxPathLength", + methodArgs = {} + ) + }) + public final void testGetMaxPathLength() throws Exception { + KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); + keyTest.load(null, null); + + ByteArrayInputStream certArray = new ByteArrayInputStream(certificate + .getBytes()); + + ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2 + .getBytes()); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert[] = new X509Certificate[2]; + cert[0] = (X509Certificate) cf.generateCertificate(certArray); + cert[1] = (X509Certificate) cf.generateCertificate(certArray2); + + keyTest.setCertificateEntry("alias1", cert[0]); + keyTest.setCertificateEntry("alias2", cert[0]); + keyTest.setCertificateEntry("alias3", cert[1]); + + PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, + new X509CertSelector()); + assertEquals(5, p.getMaxPathLength()); + p.setMaxPathLength(10); + assertEquals(10, p.getMaxPathLength()); + } + + /** + * Test for <code>setMaxPathLength()</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Boundary checking missed", + targets = { + @TestTarget( + methodName = "setMaxPathLength", + methodArgs = {int.class} + ) + }) + public final void testSetMaxPathLength() throws Exception { + KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); + keyTest.load(null, null); + + ByteArrayInputStream certArray = new ByteArrayInputStream(certificate + .getBytes()); + + ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2 + .getBytes()); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert[] = new X509Certificate[2]; + cert[0] = (X509Certificate) cf.generateCertificate(certArray); + cert[1] = (X509Certificate) cf.generateCertificate(certArray2); + + keyTest.setCertificateEntry("alias1", cert[0]); + keyTest.setCertificateEntry("alias2", cert[0]); + keyTest.setCertificateEntry("alias3", cert[1]); + + PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, + new X509CertSelector()); + + assertEquals(5, p.getMaxPathLength()); + p.setMaxPathLength(10); + assertEquals(10, p.getMaxPathLength()); + p.setMaxPathLength(0); + assertEquals(0, p.getMaxPathLength()); + p.setMaxPathLength(-1); + assertEquals(-1, p.getMaxPathLength()); + + try { + p.setMaxPathLength(-10); + fail("InvalidParameterException expected "); + } catch (InvalidParameterException e) { + // expected + } + } + + /** + * Test for <code>toString()</code> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() throws Exception { + KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType()); + keyTest.load(null, null); + + ByteArrayInputStream certArray = new ByteArrayInputStream(certificate + .getBytes()); + + ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2 + .getBytes()); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert[] = new X509Certificate[2]; + cert[0] = (X509Certificate) cf.generateCertificate(certArray); + cert[1] = (X509Certificate) cf.generateCertificate(certArray2); + + keyTest.setCertificateEntry("alias1", cert[0]); + keyTest.setCertificateEntry("alias2", cert[0]); + keyTest.setCertificateEntry("alias3", cert[1]); + + PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, + new X509CertSelector()); + System.out.println(p.toString()); + assertNotNull(p.toString()); + + } +} diff --git a/security/src/test/java/tests/security/cert/PKIXCertPathBuilderResultTest.java b/security/src/test/java/tests/security/cert/PKIXCertPathBuilderResultTest.java new file mode 100644 index 0000000..34f71ec --- /dev/null +++ b/security/src/test/java/tests/security/cert/PKIXCertPathBuilderResultTest.java @@ -0,0 +1,338 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.cert.CertPath; +import java.security.cert.CertPathBuilderResult; +import java.security.cert.PKIXCertPathBuilderResult; +import java.security.cert.TrustAnchor; +import java.security.spec.InvalidKeySpecException; + +import org.apache.harmony.security.tests.support.cert.MyCertPath; +import org.apache.harmony.security.tests.support.cert.TestUtils; + +/** + * Tests for <code>PKIXCertPathBuilderResult</code> + * + */ +@TestTargetClass(PKIXCertPathBuilderResult.class) +public class PKIXCertPathBuilderResultTest extends TestCase { + /** + * Cert path encoding stub + */ + private static final byte[] testEncoding = new byte[] { + (byte)1, (byte)2, (byte)3, (byte)4, (byte)5 + }; + + /** + * PublicKey stub + */ + private static PublicKey testPublicKey = new PublicKey() { + + private static final long serialVersionUID = -5529950703394751638L; + public String getAlgorithm() { + return "NeverMind"; + } + public String getFormat() { + return "NeverMind"; + } + public byte[] getEncoded() { + return new byte[] {}; + } + }; + + + /** + * Constructor for PKIXCertPathBuilderResultTest. + * @param name + */ + public PKIXCertPathBuilderResultTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: Creates an instance of <code>PKIXCertPathBuilderResult</code> + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed.", + targets = { + @TestTarget( + methodName = "PKIXCertPathBuilderResult", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathBuilderResult01() + throws InvalidKeySpecException, + NoSuchAlgorithmException { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + CertPathBuilderResult r = + new PKIXCertPathBuilderResult( + new MyCertPath(testEncoding), + ta, + TestUtils.getPolicyTree(), + testPublicKey); + assertTrue(r instanceof PKIXCertPathBuilderResult); + } + + /** + * Test #2 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: policy tree parameter may be <code>null</code> + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed..", + targets = { + @TestTarget( + methodName = "PKIXCertPathBuilderResult", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathBuilderResult02() + throws InvalidKeySpecException, + NoSuchAlgorithmException { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + CertPathBuilderResult r = + new PKIXCertPathBuilderResult( + new MyCertPath(testEncoding), + ta, + null, + testPublicKey); + assertTrue(r instanceof PKIXCertPathBuilderResult); + } + + /** + * Test #3 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: <code>NullPointerException</code> + * if certPath is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed..", + targets = { + @TestTarget( + methodName = "PKIXCertPathBuilderResult", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathBuilderResult03() { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + try { + // pass null + new PKIXCertPathBuilderResult( + null, + ta, + TestUtils.getPolicyTree(), + testPublicKey); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: <code>NullPointerException</code> + * if trustAnchor is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed.", + targets = { + @TestTarget( + methodName = "PKIXCertPathBuilderResult", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathBuilderResult04() { + try { + // pass null + new PKIXCertPathBuilderResult( + new MyCertPath(testEncoding), + null, + TestUtils.getPolicyTree(), + testPublicKey); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #5 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: <code>NullPointerException</code> + * if publicKey is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "InvalidKeySpecException checking missed.", + targets = { + @TestTarget( + methodName = "PKIXCertPathBuilderResult", + methodArgs = {java.security.cert.CertPath.class, java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathBuilderResult05() { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + try { + // pass null + new PKIXCertPathBuilderResult( + new MyCertPath(testEncoding), + ta, + TestUtils.getPolicyTree(), + null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void test_clone() { + + // Regression for HARMONY-2786. + TrustAnchor ta = TestUtils.getTrustAnchor(); + assertNotNull(getName() + + ": not performed (could not create test TrustAnchor)", ta); + + PKIXCertPathBuilderResult init = new PKIXCertPathBuilderResult( + new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), + testPublicKey); + + PKIXCertPathBuilderResult clone = (PKIXCertPathBuilderResult) init + .clone(); + assertSame(init.getCertPath(), clone.getCertPath()); + assertSame(init.getPolicyTree(), clone.getPolicyTree()); + assertSame(init.getPublicKey(), clone.getPublicKey()); + assertSame(init.getTrustAnchor(), clone.getTrustAnchor()); + } + + /** + * Test for <code>getCertPath()</code> method<br> + * Assertion: the built and validated <code>CertPath</code> + * (never <code>null</code>) + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertPath", + methodArgs = {} + ) + }) + public final void testGetCertPath() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + CertPath cp = new MyCertPath(testEncoding); + CertPathBuilderResult r = + new PKIXCertPathBuilderResult( + cp, + ta, + TestUtils.getPolicyTree(), + testPublicKey); + + // must return the same reference + // as passed to the constructor + assertSame(cp, r.getCertPath()); + } + + /** + * Test for <code>toString()</code> method<br> + * Assertion: the printable representation of this object + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() + throws InvalidKeySpecException, + NoSuchAlgorithmException { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + CertPathBuilderResult r = + new PKIXCertPathBuilderResult( + new MyCertPath(testEncoding), + ta, + TestUtils.getPolicyTree(), + testPublicKey); + + assertNotNull(r.toString()); + } + +} diff --git a/security/src/test/java/tests/security/cert/PKIXCertPathCheckerTest.java b/security/src/test/java/tests/security/cert/PKIXCertPathCheckerTest.java new file mode 100644 index 0000000..c784707 --- /dev/null +++ b/security/src/test/java/tests/security/cert/PKIXCertPathCheckerTest.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.cert.CertPathValidatorException; +import java.security.cert.Certificate; +import java.security.cert.PKIXCertPathChecker; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.apache.harmony.security.tests.support.cert.MyCertificate; +import org.apache.harmony.security.tests.support.cert.TestUtils; + +/** + * Tests for <code>PKIXCertPathChecker</code> + * + */ +@TestTargetClass(PKIXCertPathChecker.class) +public class PKIXCertPathCheckerTest extends TestCase { + + /** + * Constructor for PKIXCertPathCheckerTest. + * @param name + */ + public PKIXCertPathCheckerTest(String name) { + super(name); + } + + // + // Tests + // + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "PKIXCertPathChecker", + methodArgs = {} + ) + }) + public final void testConstructor() { + try { + new MyPKIXCertPathChecker(); + } catch(Exception e) { + fail("Unexpected exception " + e.getMessage()); + } + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone() { + PKIXCertPathChecker pc1 = TestUtils.getTestCertPathChecker(); + PKIXCertPathChecker pc2 = (PKIXCertPathChecker) pc1.clone(); + assertNotSame("notSame", pc1, pc2); + } + + // + // the following tests just call methods + // that are abstract in <code>PKIXCertPathChecker</code> + // (So they just like signature tests) + // + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isForwardCheckingSupported", + methodArgs = {} + ) + }) + public final void testIsForwardCheckingSupported() { + PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); + pc.isForwardCheckingSupported(); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "init", + methodArgs = {boolean.class} + ) + }) + public final void testInit() + throws CertPathValidatorException { + PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); + pc.init(true); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSupportedExtensions", + methodArgs = {} + ) + }) + public final void testGetSupportedExtensions() { + PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); + pc.getSupportedExtensions(); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "check", + methodArgs = {java.security.cert.Certificate.class, java.util.Collection.class} + ) + }) + public final void testCheck() throws CertPathValidatorException { + PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); + pc.check(new MyCertificate("", null), new HashSet<String>()); + } + + class MyPKIXCertPathChecker extends PKIXCertPathChecker { + + public MyPKIXCertPathChecker() { + super(); + } + + @Override + public void check(Certificate cert, + Collection<String> unresolvedCritExts) + throws CertPathValidatorException { + } + + @Override + public Set<String> getSupportedExtensions() { + return null; + } + + @Override + public void init(boolean forward) throws CertPathValidatorException { + } + + @Override + public boolean isForwardCheckingSupported() { + return false; + } + + } + +} diff --git a/security/src/test/java/tests/security/cert/PKIXCertPathValidatorResultTest.java b/security/src/test/java/tests/security/cert/PKIXCertPathValidatorResultTest.java new file mode 100644 index 0000000..8846921b --- /dev/null +++ b/security/src/test/java/tests/security/cert/PKIXCertPathValidatorResultTest.java @@ -0,0 +1,448 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.cert.PKIXCertPathValidatorResult; +import java.security.cert.PolicyNode; +import java.security.cert.TrustAnchor; +import java.security.spec.InvalidKeySpecException; + +import org.apache.harmony.security.tests.support.cert.TestUtils; + +/** + * Tests for <code>PKIXCertPathValidatorResult</code> + * + */ +@TestTargetClass(PKIXCertPathValidatorResult.class) +public class PKIXCertPathValidatorResultTest extends TestCase { + /** + * PublicKey stub + */ + private static PublicKey testPublicKey = new PublicKey() { + private static final long serialVersionUID = -737454523739489192L; + public String getAlgorithm() { + return "NeverMind"; + } + public String getFormat() { + return "NeverMind"; + } + public byte[] getEncoded() { + return new byte[] {}; + } + }; + + /** + * Constructor for PKIXCertPathValidatorResultTest. + * @param name + */ + public PKIXCertPathValidatorResultTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>PKIXCertPathValidatorResult(TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: creates an instance of + * <code>PKIXCertPathValidatorResult</code> + * + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify NullPointerException.", + targets = { + @TestTarget( + methodName = "PKIXCertPathValidatorResult", + methodArgs = {java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathValidatorResult01() + throws InvalidKeySpecException, + NoSuchAlgorithmException { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + new PKIXCertPathValidatorResult( + ta, + TestUtils.getPolicyTree(), + testPublicKey); + } + + /** + * Test #2 for <code>PKIXCertPathValidatorResult(TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: <code>NullPointerException</code> if + * <code>TrustAnchor</code> parameter is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "PKIXCertPathValidatorResult", + methodArgs = {java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathValidatorResult02() { + try { + // pass null + new PKIXCertPathValidatorResult( + null, + TestUtils.getPolicyTree(), + testPublicKey); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #3 for <code>PKIXCertPathValidatorResult(TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: <code>NullPointerException</code> if + * <code>PublicKey</code> parameter is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "PKIXCertPathValidatorResult", + methodArgs = {java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathValidatorResult03() { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + try { + // pass null + new PKIXCertPathValidatorResult( + ta, + TestUtils.getPolicyTree(), + null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for <code>PKIXCertPathValidatorResult(TrustAnchor, + * PolicyNode, PublicKey)</code> constructor<br> + * Assertion: <code>PolicyNode</code>can be <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "PKIXCertPathValidatorResult", + methodArgs = {java.security.cert.TrustAnchor.class, java.security.cert.PolicyNode.class, java.security.PublicKey.class} + ) + }) + public final void testPKIXCertPathValidatorResult04() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + new PKIXCertPathValidatorResult( + ta, + null, + testPublicKey); + } + + /** + * Test for <code>getTrustAnchor()</code> method<br> + * Assertion: returns <code>TrustAnchor</code> (never <code>null</code>) + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getTrustAnchor", + methodArgs = {} + ) + }) + public final void testGetTrustAnchor() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + PKIXCertPathValidatorResult vr = + new PKIXCertPathValidatorResult( + ta, + null, + testPublicKey); + + // must return the same reference passed + // as a parameter to the constructor + assertSame(ta, vr.getTrustAnchor()); + } + + /** + * Test for <code>getPublicKey()</code> method<br> + * Assertion: returns the subject's public key (never <code>null</code>) + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicKey", + methodArgs = {} + ) + }) + public final void testGetPublicKey() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + PublicKey pk = testPublicKey; + PKIXCertPathValidatorResult vr = + new PKIXCertPathValidatorResult( + ta, + null, + pk); + + // must return the same reference passed + // as a parameter to the constructor + assertSame(pk, vr.getPublicKey()); + } + + /** + * Test for <code>getPolicyTree()</code> method<br> + * Assertion: returns the root node of the valid + * policy tree or <code>null</code> if there are + * no valid policies + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getPolicyTree method returns the root node of " + + "the valid policy tree.", + targets = { + @TestTarget( + methodName = "getPolicyTree", + methodArgs = {} + ) + }) + public final void testGetPolicyTree01() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + // valid policy tree case; + PolicyNode pn = TestUtils.getPolicyTree(); + PKIXCertPathValidatorResult vr = + new PKIXCertPathValidatorResult( + ta, + pn, + testPublicKey); + + // must return the same reference passed + // as a parameter to the constructor + assertSame(pn, vr.getPolicyTree()); + } + + /** + * Test for <code>getPolicyTree()</code> method<br> + * Assertion: returns the root node of the valid + * policy tree or <code>null</code> if there are + * no valid policies + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getPolicyTree method returns null if there are " + + "no valid policies.", + targets = { + @TestTarget( + methodName = "getPolicyTree", + methodArgs = {} + ) + }) + public final void testGetPolicyTree02() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + // no valid policy tree case (null) + PKIXCertPathValidatorResult vr = + new PKIXCertPathValidatorResult( + ta, + null, + testPublicKey); + + // must return the same reference passed + // as a parameter to the constructor + assertNull(vr.getPolicyTree()); + } + + /** + * Test for <code>clone()</code> method<br> + * Assertion: returns a copy of this object + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + PKIXCertPathValidatorResult vr1 = + new PKIXCertPathValidatorResult( + ta, + TestUtils.getPolicyTree(), + testPublicKey); + + PKIXCertPathValidatorResult vr2 = + (PKIXCertPathValidatorResult) vr1.clone(); + + // check that method makes shallow copy + assertNotSame("notSame", vr1, vr2); + assertSame("trustAncor", vr1.getTrustAnchor(), vr2.getTrustAnchor()); + assertSame("policyTree", vr1.getPolicyTree(), vr2.getPolicyTree()); + assertSame("publicKey", vr1.getPublicKey(), vr2.getPublicKey()); + + // Regression for HARMONY-2786. + byte[] encoding = { 0x01 }; + MyPKIXCertPathBuilderResult my = new MyPKIXCertPathBuilderResult(ta, + TestUtils.getPolicyTree(), testPublicKey, encoding); + MyPKIXCertPathBuilderResult myClone = (MyPKIXCertPathBuilderResult) my + .clone(); + assertSame(my.getPolicyTree(), myClone.getPolicyTree()); + assertSame(my.getPublicKey(), myClone.getPublicKey()); + assertSame(my.getTrustAnchor(), myClone.getTrustAnchor()); + assertSame(my.enc, myClone.enc); + } + + class MyPKIXCertPathBuilderResult extends PKIXCertPathValidatorResult { + + public byte[] enc; // byte array is cloneable + + public MyPKIXCertPathBuilderResult(TrustAnchor trustAnchor, + PolicyNode policyTree, PublicKey subjectPublicKey, byte[] enc) { + super(trustAnchor, policyTree, subjectPublicKey); + + this.enc = enc; + } + } + + /** + * Test #1 for <code>toString()</code> method<br> + * Assertion: Returns a formatted string describing this object + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString01() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + PKIXCertPathValidatorResult vr = + new PKIXCertPathValidatorResult( + ta, + TestUtils.getPolicyTree(), + testPublicKey); + + assertNotNull(vr.toString()); + } + + /** + * Test #2 for <code>toString()</code> method<br> + * Assertion: Returns a formatted string describing this object + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString02() throws Exception { + TrustAnchor ta = TestUtils.getTrustAnchor(); + if (ta == null) { + fail(getName() + ": not performed (could not create test TrustAnchor)"); + } + + PKIXCertPathValidatorResult vr = + new PKIXCertPathValidatorResult( + ta, + null, + testPublicKey); + + assertNotNull(vr.toString()); + } + +} diff --git a/security/src/test/java/tests/security/cert/PKIXParametersTest.java b/security/src/test/java/tests/security/cert/PKIXParametersTest.java new file mode 100644 index 0000000..ed481db --- /dev/null +++ b/security/src/test/java/tests/security/cert/PKIXParametersTest.java @@ -0,0 +1,1891 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertPathParameters; +import java.security.cert.CertPathValidatorException; +import java.security.cert.CertStore; +import java.security.cert.CollectionCertStoreParameters; +import java.security.cert.PKIXCertPathChecker; +import java.security.cert.PKIXParameters; +import java.security.cert.TrustAnchor; +import java.security.cert.X509CertSelector; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.harmony.security.tests.support.cert.TestUtils; + +/** + * Tests for <code>PKIXParameters</code> fields and methods + * + */ +@TestTargetClass(PKIXParameters.class) +public class PKIXParametersTest extends TestCase { + /** + * Some valid issuer name + */ + private final static String testIssuer = + "CN=VM,OU=DRL Security,O=Intel,L=Novosibirsk,ST=NSO,C=RU"; + + /** + * Constructor for PKIXParametersTest. + * @param name + */ + public PKIXParametersTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>PKIXParameters(Set)</code> constructor<br> + * Assertion: Creates an instance of <code>PKIXParameters</code> with the + * specified <code>Set</code> of most-trusted CAs. Each element of the set + * is a <code>TrustAnchor</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "PKIXParameters", + methodArgs = {java.util.Set.class} + ) + }) + public final void testPKIXParametersSet01() + throws InvalidAlgorithmParameterException { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + // use valid parameter + CertPathParameters cpp = new PKIXParameters(taSet); + assertTrue(cpp instanceof PKIXParameters); + } + + /** + * Test #2 for <code>PKIXParameters(Set)</code> constructor<br> + * Assertion: ... the <code>Set</code> is copied to protect against + * subsequent modifications + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "PKIXParameters", + methodArgs = {java.util.Set.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testPKIXParametersSet02() + throws InvalidAlgorithmParameterException { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + HashSet<TrustAnchor> originalSet = (HashSet<TrustAnchor>)taSet; + HashSet<TrustAnchor> originalSetCopy = (HashSet<TrustAnchor>) originalSet.clone(); + // create test object using originalSet + PKIXParameters pp = new PKIXParameters(originalSetCopy); + // modify originalSet + originalSetCopy.clear(); + // check that test object's internal state + // has not been affected by the above modification + Set returnedSet = pp.getTrustAnchors(); + assertEquals(originalSet, returnedSet); + } + + /** + * Test #3 for <code>PKIXParameters(Set)</code> constructor<br> + * Assertion: <code>NullPointerException</code> - + * if the specified <code>Set</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "PKIXParameters", + methodArgs = {java.util.Set.class} + ) + }) + public final void testPKIXParametersSet03() throws Exception { + try { + // pass null + new PKIXParameters((Set<TrustAnchor>)null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for <code>PKIXParameters(Set)</code> constructor<br> + * Assertion: <code>InvalidAlgorithmParameterException</code> - + * if the specified <code>Set</code> is empty + * (<code>trustAnchors.isEmpty() == true</code>) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies InvalidAlgorithmParameterException.", + targets = { + @TestTarget( + methodName = "PKIXParameters", + methodArgs = {java.util.Set.class} + ) + }) + public final void testPKIXParametersSet04() { + try { + // use empty set + new PKIXParameters(new HashSet<TrustAnchor>()); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + } + } + + /** + * Test #5 for <code>PKIXParameters(Set)</code> constructor<br> + * Assertion: <code>ClassCastException</code> - + * if any of the elements in the <code>Set</code> are not of type + * <code>java.security.cert.TrustAnchor</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies ClassCastException.", + targets = { + @TestTarget( + methodName = "PKIXParameters", + methodArgs = {java.util.Set.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testPKIXParametersSet05() throws Exception { + Set taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + // add wrong object to valid set + assertTrue(taSet.add(new Object())); + try { + new PKIXParameters(taSet); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + } + } + + /** + * Test #3 for <code>PKIXParameters(KeyStore)</code> constructor<br> + * Assertion: <code>NullPointerException</code> - + * if the <code>keystore</code> is <code>null</code> + * @throws InvalidAlgorithmParameterException + * @throws KeyStoreException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "PKIXParameters", + methodArgs = {java.security.KeyStore.class} + ) + }) + public final void testPKIXParametersKeyStore03() throws Exception { + try { + // pass null + new PKIXParameters((KeyStore)null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>clone()</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public final void testClone() throws InvalidAlgorithmParameterException { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters cpp = new PKIXParameters(taSet); + PKIXParameters cppc = (PKIXParameters)cpp.clone(); + + assertEquals(cpp.getPolicyQualifiersRejected(), cppc.getPolicyQualifiersRejected()); + assertEquals(cpp.getCertPathCheckers(), cppc.getCertPathCheckers()); + assertEquals(cpp.getCertStores(), cppc.getCertStores()); + assertEquals(cpp.getDate(), cppc.getDate()); + assertEquals(cpp.getInitialPolicies(), cppc.getInitialPolicies()); + assertEquals(cpp.getSigProvider(), cppc.getSigProvider()); + assertEquals(cpp.getTargetCertConstraints(), cppc.getTargetCertConstraints()); + assertEquals(cpp.getTrustAnchors(), cppc.getTrustAnchors()); + + assertEquals(cpp.isAnyPolicyInhibited(), cppc.isAnyPolicyInhibited()); + assertEquals(cpp.isExplicitPolicyRequired(), cppc.isExplicitPolicyRequired()); + assertEquals(cpp.isPolicyMappingInhibited(), cppc.isPolicyMappingInhibited()); + assertEquals(cpp.isRevocationEnabled(), cppc.isRevocationEnabled()); + + cpp.setDate(Calendar.getInstance().getTime()); + cpp.setPolicyQualifiersRejected(!cppc.getPolicyQualifiersRejected()); + assertFalse(cpp.getDate().equals(cppc.getDate())); + assertFalse(cpp.getPolicyQualifiersRejected() == cppc.getPolicyQualifiersRejected()); + + cppc.setExplicitPolicyRequired(!cpp.isExplicitPolicyRequired()); + cppc.setRevocationEnabled(!cpp.isRevocationEnabled()); + + assertFalse(cpp.isExplicitPolicyRequired() == cppc.isExplicitPolicyRequired()); + assertFalse(cpp.isRevocationEnabled() == cppc.isRevocationEnabled()); + + PKIXParameters cpp1 = null; + try { + cpp1.clone(); + } catch (NullPointerException e){ + // expected + } + } + + /** + * Test #1 for <code>getPolicyQualifiersRejected()</code> method<br> + * Assertion: When a <code>PKIXParameters</code> object is created, + * this flag is set to <code>true</code><br> + * Assertion: returns the current value of the PolicyQualifiersRejected flag + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPolicyQualifiersRejected", + methodArgs = {} + ) + }) + public final void testGetPolicyQualifiersRejected() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertTrue(p.getPolicyQualifiersRejected()); + } + + /** + * Test for <code>setPolicyQualifiersRejected()</code> method<br> + * Assertion: set the new value of the + * <code>PolicyQualifiersRejected</code> flag + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setPolicyQualifiersRejected", + methodArgs = {boolean.class} + ) + }) + public final void testSetPolicyQualifiersRejected() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setPolicyQualifiersRejected(false); + assertFalse("setFalse",p.getPolicyQualifiersRejected()); + p.setPolicyQualifiersRejected(true); + assertTrue("setTrue",p.getPolicyQualifiersRejected()); + } + + /** + * Test for <code>isAnyPolicyInhibited()</code> method<br> + * Assertion: returns <code>true</code> if the any policy + * OID is inhibited, <code>false</code> otherwise<br> + * Assertion: By default, the any policy OID is not inhibited + * (<code>isAnyPolicyInhibited()</code> returns false). + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isAnyPolicyInhibited", + methodArgs = {} + ) + }) + public final void testIsAnyPolicyInhibited() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertFalse(p.isAnyPolicyInhibited()); + } + + /** + * Test for <code>setAnyPolicyInhibited()</code> method<br> + * Assertion: sets state to determine if the any policy OID + * should be processed if it is included in a certificate + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setAnyPolicyInhibited", + methodArgs = {boolean.class} + ) + }) + public final void testSetAnyPolicyInhibited() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setAnyPolicyInhibited(true); + assertTrue("setTrue", p.isAnyPolicyInhibited()); + p.setAnyPolicyInhibited(false); + assertFalse("setFalse", p.isAnyPolicyInhibited()); + } + + /** + * Test for <code>isExplicitPolicyRequired()</code> method<br> + * Assertion: returns <code>true</code> if explicit policy is required, + * <code>false</code> otherwise<br> + * Assertion: by default, the ExplicitPolicyRequired flag is false + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isExplicitPolicyRequired", + methodArgs = {} + ) + }) + public final void testIsExplicitPolicyRequired() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertFalse(p.isExplicitPolicyRequired()); + } + + /** + * Test for <code>setExplicitPolicyRequired()</code> method<br> + * Assertion: sets the ExplicitPolicyRequired flag + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setExplicitPolicyRequired", + methodArgs = {boolean.class} + ) + }) + public final void testSetExplicitPolicyRequired() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setExplicitPolicyRequired(true); + assertTrue("setTrue", p.isExplicitPolicyRequired()); + p.setExplicitPolicyRequired(false); + assertFalse("setFalse", p.isExplicitPolicyRequired()); + } + + /** + * Test for <code>isPolicyMappingInhibited()</code> method<br> + * Assertion: returns true if policy mapping is inhibited, false otherwise + * Assertion: by default, policy mapping is not inhibited (the flag is false) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that isPolicyMappingInhibited returns false " + + "if policy mapping is not inhibited.", + targets = { + @TestTarget( + methodName = "isPolicyMappingInhibited", + methodArgs = {} + ) + }) + public final void testIsPolicyMappingInhibited() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertFalse(p.isPolicyMappingInhibited()); + } + + /** + * Test for <code>setPolicyMappingInhibited()</code> method<br> + * Assertion: sets the PolicyMappingInhibited flag + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setPolicyMappingInhibited", + methodArgs = {boolean.class} + ) + }) + public final void testSetPolicyMappingInhibited() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setPolicyMappingInhibited(true); + assertTrue("setTrue", p.isPolicyMappingInhibited()); + p.setPolicyMappingInhibited(false); + assertFalse("setFalse", p.isPolicyMappingInhibited()); + } + + /** + * Test for <code>isPolicyMappingInhibited()</code> method<br> + * Assertion: returns the current value of the RevocationEnabled flag + * Assertion: when a <code>PKIXParameters</code> object is created, + * this flag is set to true + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that isRevocationEnabled method returns true.", + targets = { + @TestTarget( + methodName = "isRevocationEnabled", + methodArgs = {} + ) + }) + public final void testIsRevocationEnabled() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertTrue(p.isRevocationEnabled()); + } + + /** + * Test for <code>isPolicyMappingInhibited()</code> method<br> + * Assertion: sets the RevocationEnabled flag + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setRevocationEnabled", + methodArgs = {boolean.class} + ) + }) + public final void testSetRevocationEnabled() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setRevocationEnabled(false); + assertFalse("setFalse", p.isRevocationEnabled()); + p.setRevocationEnabled(true); + assertTrue("setTrue", p.isRevocationEnabled()); + } + + /** + * Test for <code>getSigProvider()</code> method<br> + * Assertion: returns the signature provider's name, + * or null if not set + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSigProvider", + methodArgs = {} + ) + }) + public final void testGetSigProvider() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertNull("not set", p.getSigProvider()); + p.setSigProvider("Some Provider"); + assertNotNull("set", p.getSigProvider()); + } + + /** + * Test for <code>setSigProvider(String)</code> method<br> + * Assertion: sets the signature provider's name + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSigProvider", + methodArgs = {java.lang.String.class} + ) + }) + public final void testSetSigProvider() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + String sigProviderName = "Some Provider"; + p.setSigProvider(sigProviderName); + assertTrue("set", sigProviderName.equals(p.getSigProvider())); + p.setSigProvider(null); + assertNull("unset", p.getSigProvider()); + } + + /** + * Test #1 for <code>getTargetCertConstraints()</code> method<br> + * Assertion: returns a <code>CertSelector</code> specifying + * the constraints on the target certificate (or <code>null</code>) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getTargetCertConstraints method returns null, " + + "if no constraints are defined.", + targets = { + @TestTarget( + methodName = "getTargetCertConstraints", + methodArgs = {} + ) + }) + public final void testGetTargetCertConstraints01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertNull(p.getTargetCertConstraints()); + } + + /** + * Test #2 for <code>getTargetCertConstraints()</code> method<br> + * Assertion: note that the <code>CertSelector</code> returned + * is cloned to protect against subsequent modifications + * @throws InvalidAlgorithmParameterException + * @throws IOException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that returned CertSelector is cloned to protect " + + "against subsequent modifications.", + targets = { + @TestTarget( + methodName = "setTargetCertConstraints", + methodArgs = {java.security.cert.CertSelector.class} + ) + }) + public final void testGetTargetCertConstraints02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + X509CertSelector x509cs = new X509CertSelector(); + PKIXParameters p = new PKIXParameters(taSet); + p.setTargetCertConstraints(x509cs); + // get cert selector + X509CertSelector cs1 = (X509CertSelector)p.getTargetCertConstraints(); + // modify returned selector + cs1.setIssuer(testIssuer); + // get cert selector again + X509CertSelector cs2 = (X509CertSelector)p.getTargetCertConstraints(); + // check that selector is not the same + assertNotSame("notTheSame", cs1, cs2); + // check that selector's internal state has + // not been changed by above modification + assertFalse("stateNotChanged", testIssuer.equals(cs2.getIssuerAsString())); + } + + /** + * Test for <code>setTargetCertConstraints(CertSelector)</code> method<br> + * Assertion: sets the required constraints on the target certificate. + * The constraints are specified as an instance of CertSelector<br> + * Assertion: ... If <code>null</code>, no constraints are defined + * @throws IOException + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setTargetCertConstraints", + methodArgs = {java.security.cert.CertSelector.class} + ) + }) + public final void testSetTargetCertConstraints01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + X509CertSelector x509cs = new X509CertSelector(); + x509cs.setIssuer(testIssuer); + PKIXParameters p = new PKIXParameters(taSet); + p.setTargetCertConstraints(x509cs); + assertEquals("set", + testIssuer, + ((X509CertSelector)p.getTargetCertConstraints()).getIssuerAsString()); + p.setTargetCertConstraints(null); + assertNull("unset", p.getTargetCertConstraints()); + } + + /** + * Test #2 for <code>setTargetCertConstraints(CertSelector)</code> method<br> + * Assertion: ... the CertSelector specified is cloned to protect against + * subsequent modifications + * @throws IOException + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Additional test.", + targets = { + @TestTarget( + methodName = "setTargetCertConstraints", + methodArgs = {java.security.cert.CertSelector.class} + ) + }) + public final void testSetTargetCertConstraints02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + X509CertSelector x509cs = new X509CertSelector(); + PKIXParameters p = new PKIXParameters(taSet); + p.setTargetCertConstraints(x509cs); + // modify selector + x509cs.setIssuer(testIssuer); + // get selector + X509CertSelector x509cs1 = (X509CertSelector)p.getTargetCertConstraints(); + // check that selector's internal state has + // not been changed by above modification + assertFalse(testIssuer.equals(x509cs1.getIssuerAsString())); + } + + /** + * Test #1 for <code>getCertStores()</code> method<br> + * Assertion: list ... (may be empty, but never <code>null</code>) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getCertStores method returns empty list, " + + "but not null.", + targets = { + @TestTarget( + methodName = "getCertStores", + methodArgs = {} + ) + }) + public final void testGetCertStores01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertNotNull("notNull", p.getCertStores()); + assertTrue("isEmpty", p.getCertStores().isEmpty()); + } + + /** + * Test #2 for <code>getCertStores()</code> method<br> + * Assertion: returns an immutable <code>List</code> + * of <code>CertStores</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getCertStores method returns an immutable List " + + "of CertStores.", + targets = { + @TestTarget( + methodName = "getCertStores", + methodArgs = {} + ) + }) + public final void testGetCertStores02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + List<CertStore> cs = p.getCertStores(); + + try { + // try to modify returned list + cs.add((CertStore)(new Object())); + fail("must be immutable"); + } catch (Exception e) { + } + } + + /** + * Test #1 for <code>setCertStores(List)</code> method<br> + * Assertion: Sets the list of CertStores ... + * @throws NoSuchAlgorithmException + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify ClassCastException.", + targets = { + @TestTarget( + methodName = "setCertStores", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertStores01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setCertStores(TestUtils.getCollectionCertStoresList()); + // check that list has been set + assertFalse(p.getCertStores().isEmpty()); + } + + /** + * Test #2 for <code>setCertStores(List)</code> method<br> + * Assertion: list ... may be <code>null</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify ClassCastException.", + targets = { + @TestTarget( + methodName = "setCertStores", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertStores02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + // add null + p.setCertStores(null); + // check that we have non null empty list now + assertNotNull("notNull1", p.getCertStores()); + assertTrue("isEmpty1", p.getCertStores().isEmpty()); + // add empty + p.setCertStores(new ArrayList<CertStore>()); + assertNotNull("notNull2", p.getCertStores()); + assertTrue("isEmpty2", p.getCertStores().isEmpty()); + } + + /** + * Test #3 for <code>setCertStores(List)</code> method<br> + * Assertion: list is copied to protect against subsequent modifications + * @throws NoSuchAlgorithmException + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that the list is copied to protect against subsequent " + + "modifications.", + targets = { + @TestTarget( + methodName = "setCertStores", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertStores03() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + List<CertStore> l = TestUtils.getCollectionCertStoresList(); + p.setCertStores(l); + // modify list just set + l.clear(); + // check that list maintained internally has + // not been changed by the above modification + assertFalse(p.getCertStores().isEmpty()); + } + + /** + * Test #4 for <code>setCertStores(List)</code> method<br> + * Assertion: <code>ClassCastException</code> - + * if any of the elements in the list are not of type + * <code>java.security.cert.CertStore</code> + * @throws InvalidAlgorithmParameterException + * @throws NoSuchAlgorithmException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies ClassCastException.", + targets = { + @TestTarget( + methodName = "setCertStores", + methodArgs = {java.util.List.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testSetCertStores04() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + List l = TestUtils.getCollectionCertStoresList(); + // add wrong object to valid set + assertTrue(l.add(new Object())); + + try { + p.setCertStores(l); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + } + } + + /** + * Test #1 for <code>addCertStore(CertStore)</code> method<br> + * Assertion: adds a <code>CertStore</code> to the end of the + * list of <code>CertStores</code> + * @throws InvalidAlgorithmParameterException + * @throws NoSuchAlgorithmException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify ClassCastException.", + targets = { + @TestTarget( + methodName = "addCertStore", + methodArgs = {java.security.cert.CertStore.class} + ) + }) + public final void testAddCertStore01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.addCertStore(CertStore.getInstance("Collection", + new CollectionCertStoreParameters())); + assertFalse(p.getCertStores().isEmpty()); + } + + /** + * Test #2 for <code>addCertStore(CertStore)</code> method<br> + * Assertion: if <code>null</code>, the store is ignored (not added to list) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "addCertStore", + methodArgs = {java.security.cert.CertStore.class} + ) + }) + public final void testAddCertStore02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.addCertStore(null); + assertTrue(p.getCertStores().isEmpty()); + } + + /** + * Test #1 for <code>getCertPathCheckers()</code> method<br> + * Assertion: list ... may be empty, but not <code>null</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getCertPathCheckers method returns not empty " + + "list.", + targets = { + @TestTarget( + methodName = "getCertPathCheckers", + methodArgs = {} + ) + }) + public final void testGetCertPathCheckers01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + List l = p.getCertPathCheckers(); + assertNotNull("notNull", l); + assertTrue("isEmpty",l.isEmpty()); + } + + /** + * Test #2 for <code>getCertPathCheckers()</code> method<br> + * Assertion: returns an immutable <code>List</code> + * of <code>PKIXCertPathChecker</code>s + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getCertPathCheckers method returns an immutable " + + "List of PKIXCertPathChecker objects.", + targets = { + @TestTarget( + methodName = "getCertPathCheckers", + methodArgs = {} + ) + }) + public final void testGetCertPathCheckers02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + List<PKIXCertPathChecker> l = p.getCertPathCheckers(); + + try { + // try to modify returned list + l.add((PKIXCertPathChecker)new Object()); + fail("must be immutable"); + } catch (Exception e) { + } + } + + /** + * Test #3 for <code>getCertPathCheckers()</code> method<br> + * Assertion: The returned List is immutable, and each + * <code>PKIXCertPathChecker</code> in the <code>List</code> + * is cloned to protect against subsequent modifications + * @throws InvalidAlgorithmParameterException + * @throws CertPathValidatorException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that the returned List is immutable, and each " + + "PKIXCertPathChecker in the List " + + "is cloned to protect against subsequent modifications.", + targets = { + @TestTarget( + methodName = "getCertPathCheckers", + methodArgs = {} + ) + }) + public final void testGetCertPathCheckers03() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List<PKIXCertPathChecker> l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + p.setCertPathCheckers(l); + // retrieve checker and modify it + PKIXCertPathChecker cpc1 = p.getCertPathCheckers().get(0); + cpc1.init(true); + assertTrue("modifiedOk", cpc1.isForwardCheckingSupported()); + // retrieve checker again and check + // that its state has not been changed + // by the above modification + PKIXCertPathChecker cpc2 = p.getCertPathCheckers().get(0); + assertFalse("isCloned", cpc2.isForwardCheckingSupported()); + } + + /** + * Test #1 for <code>setCertPathCheckers(List)</code> method<br> + * Assertion: sets a <code>List</code> of additional + * certification path checkers + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "setCertPathCheckers", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertPathCheckers01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List<PKIXCertPathChecker> l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + p.setCertPathCheckers(l); + List l1 = p.getCertPathCheckers(); + assertNotNull("notNull", l1); + assertFalse("isNotEmpty", l1.isEmpty()); + } + + /** + * Test #2 for <code>setCertPathCheckers(List)</code> method<br> + * Assertion: <code>List</code> ... may be null + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "setCertPathCheckers", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertPathCheckers02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setCertPathCheckers(null); + List<PKIXCertPathChecker> l1 = p.getCertPathCheckers(); + assertNotNull("notNull1", l1); + assertTrue("isEmpty1", l1.isEmpty()); + p.setCertPathCheckers(new ArrayList<PKIXCertPathChecker>()); + List l2 = p.getCertPathCheckers(); + assertNotNull("notNull2", l2); + assertTrue("isEmpty2", l2.isEmpty()); + } + + /** + * Test #3 for <code>setCertPathCheckers(List)</code> method<br> + * Assertion: <code>List</code> supplied here is copied and each + * <code>PKIXCertPathChecker</code> in the list is cloned to protect + * against subsequent modifications + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "setCertPathCheckers", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertPathCheckers03() throws Exception { + // checks that list copied + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List<PKIXCertPathChecker> l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + p.setCertPathCheckers(l); + // modify list + l.clear(); + // retrieve list and check + // that its state has not been changed + // by the above modification + assertFalse("isCopied", p.getCertPathCheckers().isEmpty()); + } + + /** + * Test #4 for <code>setCertPathCheckers(List)</code> method<br> + * Assertion: <code>List</code> supplied here is copied and each + * <code>PKIXCertPathChecker</code> in the list is cloned to protect + * against subsequent modifications + * @throws InvalidAlgorithmParameterException + * @throws InvalidAlgorithmParameterException + * @throws CertPathValidatorException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "setCertPathCheckers", + methodArgs = {java.util.List.class} + ) + }) + public final void testSetCertPathCheckers04() throws Exception { + // checks that checkers cloned + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List<PKIXCertPathChecker> l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + p.setCertPathCheckers(l); + // modify checker + cpc.init(true); + // retrieve list and check that CertPathChecker's + // state it contains has not been changed by the + // above modification + PKIXCertPathChecker cpc1 = p.getCertPathCheckers().get(0); + assertFalse("isCopied", cpc1.isForwardCheckingSupported()); + } + + /** + * Test #5 for <code>setCertPathCheckers(List)</code> method<br> + * Assertion: <code>ClassCastException</code> - + * if any of the elements in the list are not of type + * <code>java.security.cert.PKIXCertPathChecker</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verify exception.", + targets = { + @TestTarget( + methodName = "setCertPathCheckers", + methodArgs = {java.util.List.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testSetCertPathCheckers05() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + // add wrong object to the list + assertTrue("addedOk", l.add(new Object())); + + try { + p.setCertPathCheckers(l); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + } + } + + /** + * Test #1 for <code>addCertPathChecker(PKIXCertPathChecker)</code> method<br> + * Assertion: adds a <code>CertPathChecker</code> to the end of the + * list of <code>CertPathChecker</code>s + * @throws CertPathValidatorException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addCertPathChecker", + methodArgs = {java.security.cert.PKIXCertPathChecker.class} + ) + }) + public final void testAddCertPathChecker01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List<PKIXCertPathChecker> l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + p.setCertPathCheckers(l); + // create one more PKIXCertPathChecker + PKIXCertPathChecker cpc1 = TestUtils.getTestCertPathChecker(); + cpc1.init(true); + p.addCertPathChecker(cpc1); + // check that we have two PKIXCertPathCheckers and + // they are in right order + List l1 = p.getCertPathCheckers(); + assertEquals("listSize", 2, l1.size()); + assertFalse("order1", + ((PKIXCertPathChecker)l1.get(0)).isForwardCheckingSupported()); + assertTrue("order2", + ((PKIXCertPathChecker)l1.get(1)).isForwardCheckingSupported()); + } + + /** + * Test #2 for <code>addCertPathChecker(PKIXCertPathChecker)</code> method<br> + * Assertion: if null, the checker is ignored (not added to list). + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that if PKIXCertPathChecker parameter is null, " + + "the checker is ignored (not added to list).", + targets = { + @TestTarget( + methodName = "addCertPathChecker", + methodArgs = {java.security.cert.PKIXCertPathChecker.class} + ) + }) + public final void testAddCertPathChecker02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + List<PKIXCertPathChecker> l = new ArrayList<PKIXCertPathChecker>(); + assertTrue("addedOk", l.add(cpc)); + p.setCertPathCheckers(l); + // try to add null + p.addCertPathChecker(null); + // check that we have one PKIXCertPathChecker + List l1 = p.getCertPathCheckers(); + assertEquals("listSize", 1, l1.size()); + } + + /** + * Test #3 for <code>addCertPathChecker(PKIXCertPathChecker)</code> method<br> + * Assertion: <code>PKIXCertPathChecker</code> is cloned to protect + * against subsequent modifications + * @throws InvalidAlgorithmParameterException + * @throws CertPathValidatorException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that PKIXCertPathChecker is cloned to protect " + + "against subsequent modifications.", + targets = { + @TestTarget( + methodName = "addCertPathChecker", + methodArgs = {java.security.cert.PKIXCertPathChecker.class} + ) + }) + public final void testAddCertPathChecker03() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + // checks that checkers cloned + PKIXParameters p = new PKIXParameters(taSet); + PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker(); + + p.addCertPathChecker(cpc); + // modify checker + cpc.init(true); + // retrieve list and check that CertPathChecker's + // state it contains has not been changed by the + // above modification + List l = p.getCertPathCheckers(); + PKIXCertPathChecker cpc1 = (PKIXCertPathChecker)l.get(0); + assertEquals("listSize", 1, l.size()); + assertFalse("isCopied", cpc1.isForwardCheckingSupported()); + } + + /** + * Test #1 for <code>getDate()</code> method<br> + * Assertion: the <code>Date</code>, or <code>null</code> if not set + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getDate", + methodArgs = {} + ) + }) + public final void testGetDate01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + // the Date has not been set + // the method must return null + assertNull("null", p.getDate()); + Date currentDate = new Date(); + p.setDate(currentDate); + // the Date returned must match + assertEquals("notNull", currentDate, p.getDate()); + } + + /** + * Test #2 for <code>getDate()</code> method<br> + * Assertion: <code>Date</code> returned is copied to protect + * against subsequent modifications + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that returned Date is copied to protect" + + " against subsequent modifications.", + targets = { + @TestTarget( + methodName = "getDate", + methodArgs = {} + ) + }) + public final void testGetDate02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + Date currentDate = new Date(); + p.setDate((Date)currentDate.clone()); + Date ret1 = p.getDate(); + // modify Date returned + ret1.setTime(0L); + // check that internal Date has not been + // changed by the above modification + assertEquals(currentDate, p.getDate()); + } + + /** + * @tests java.security.cert.PKIXParameters#setDate(Date) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setDate", + methodArgs = {java.util.Date.class} + ) + }) + public final void _test_setDateLjava_util_Date() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + assertNotNull("could not create test TrustAnchor set", taSet); + + // test: 'date' is unset and param is null + PKIXParameters p = new PKIXParameters(taSet); + p.setDate(null); + assertNull(p.getDate()); + + // test: 'date' is not null + p = new PKIXParameters(taSet); + Date toBeSet = new Date(555L); + p.setDate(toBeSet); + assertEquals(555L, p.getDate().getTime()); + // modify initial 'date' - it should be copied by constructor + toBeSet.setTime(0L); + // check that internal 'date' has not been + // changed by the above modification + assertEquals(555L, p.getDate().getTime()); + // set another 'date' + p.setDate(new Date(333L)); + assertEquals(333L, p.getDate().getTime()); + + // Regression for HARMONY-2882 (non-bug difference from RI) + p = new PKIXParameters(taSet); + p.setDate(new Date(555L)); + p.setDate(null); // reset 'date' back to current time + assertNotNull(p.getDate()); + assertEquals(Calendar.getInstance().getTime(), p.getDate()); + } + + /** + * Test #1 for <code>getInitialPolicies()</code> method<br> + * Assertion: The default return value is an empty <code>Set</code> + * Assertion: Never returns <code>null</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInitialPolicies method returns an empty Set " + + "and never null.", + targets = { + @TestTarget( + methodName = "getInitialPolicies", + methodArgs = {} + ) + }) + public final void testGetInitialPolicies01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertNotNull("notNull", p.getInitialPolicies()); + assertTrue("isEmpty", p.getInitialPolicies().isEmpty()); + } + + /** + * Test #2 for <code>getInitialPolicies()</code> method<br> + * Assertion: returns an immutable <code>Set</code> of initial + * policy OIDs in <code>String</code> format<br> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getInitialPolicies method returns an immutable " + + "Set of initial policy in String format.", + targets = { + @TestTarget( + methodName = "getInitialPolicies", + methodArgs = {} + ) + }) + public final void testGetInitialPolicies02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + Set<String> s = p.getInitialPolicies(); + try { + // try to modify returned set + s.add((String)new Object()); + fail("must be immutable"); + } catch (Exception e) { + } + } + + /** + * Test #1 for <code>setInitialPolicies(Set)</code> method<br> + * Assertion: sets the <code>Set</code> of initial policy + * identifiers (OID strings) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify ClassCastException.", + targets = { + @TestTarget( + methodName = "setInitialPolicies", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetInitialPolicies01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + Set<String> s = new HashSet<String>(); + s.add("1.2.3.4.5.6.7"); + PKIXParameters p = new PKIXParameters(taSet); + p.setInitialPolicies(s); + assertEquals(1, p.getInitialPolicies().size()); + } + + /** + * Test #2 for <code>setInitialPolicies(Set)</code> method<br> + * Assertion: <code>Set</code> may be <code>null</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "setInitialPolicies", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetInitialPolicies02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setInitialPolicies(null); + assertTrue(p.getInitialPolicies().isEmpty()); + } + + /** + * Test #3 for <code>setInitialPolicies(Set)</code> method<br> + * Assertion: <code>Set</code> may be empty + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify ClassCastException.", + targets = { + @TestTarget( + methodName = "setInitialPolicies", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetInitialPolicies03() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + p.setInitialPolicies(new HashSet<String>()); + assertTrue(p.getInitialPolicies().isEmpty()); + } + + /** + * Test #4 for <code>setInitialPolicies(Set)</code> method<br> + * Assertion: <code>Set</code> is copied to protect against + * subsequent modifications + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that Set is copied to protect against " + + "subsequent modifications.", + targets = { + @TestTarget( + methodName = "setInitialPolicies", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetInitialPolicies04() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + Set<String> s = new HashSet<String>(); + s.add("1.2.3.4.5.6.7"); + s.add("1.2.3.4.5.6.8"); + PKIXParameters p = new PKIXParameters(taSet); + p.setInitialPolicies(s); + // modify original set + s.clear(); + // check that set maintained internally has + // not been changed by the above modification + assertEquals(2, p.getInitialPolicies().size()); + } + + /** + * Test #5 for <code>setInitialPolicies(Set)</code> method<br> + * Assertion: <code>ClassCastException</code> - + * if any of the elements in the set are not of type <code>String</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies ClassCastException.", + targets = { + @TestTarget( + methodName = "setInitialPolicies", + methodArgs = {java.util.Set.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testSetInitialPolicies05() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + Set s = new HashSet(); + s.add("1.2.3.4.5.6.7"); + s.add(new Object()); + PKIXParameters p = new PKIXParameters(taSet); + try { + p.setInitialPolicies(s); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + } + } + + /** + * Test #1 for <code>getTrustAnchors()</code> method<br> + * Assertion: an immutable <code>Set</code> of <code>TrustAnchors</code> + * (never <code>null</code>) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getTrustAnchors returns an immutable Set of " + + "TrustAnchors, and never null.", + targets = { + @TestTarget( + methodName = "getTrustAnchors", + methodArgs = {} + ) + }) + public final void testGetTrustAnchors01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertNotNull("notNull", p.getTrustAnchors()); + } + + /** + * Test #2 for <code>getTrustAnchors()</code> method<br> + * Assertion: an immutable <code>Set</code> of <code>TrustAnchors</code> + * (never <code>null</code>) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getTrustAnchors returns an immutable set of " + + "TrustAnchors, and never null.", + targets = { + @TestTarget( + methodName = "getTrustAnchors", + methodArgs = {} + ) + }) + public final void testGetTrustAnchors02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + Set<TrustAnchor> s = p.getTrustAnchors(); + try { + // try to modify returned set + s.add((TrustAnchor)new Object()); + fail("must be immutable"); + } catch (Exception e) { + } + } + + /** + * Test #1 for <code>setTrustAnchors(Set)</code> method<br> + * Assertion: Sets the <code>Set</code> of most-trusted CAs + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "setTrustAnchors", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetTrustAnchors01() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + Set<TrustAnchor> taSet1 = TestUtils.getTrustAnchorSet(); + PKIXParameters p = new PKIXParameters(taSet); + p.setTrustAnchors(taSet1); + assertFalse(p.getTrustAnchors().isEmpty()); + } + + /** + * Test #2 for <code>setTrustAnchors(Set)</code> method<br> + * Assertion: <code>InvalidAlgorithmParameterException</code> - + * if the specified <code>Set</code> is empty + * (<code>trustAnchors.isEmpty() == true</code>) + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies InvalidAlgorithmParameterException.", + targets = { + @TestTarget( + methodName = "setTrustAnchors", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetTrustAnchors02() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + try { + // use empty set + p.setTrustAnchors(new HashSet<TrustAnchor>()); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + } + } + + /** + * Test #3 for <code>setTrustAnchors(Set)</code> method<br> + * Assertion: <code>NullPointerException</code> - + * if the specified <code>Set</code> is <code>null</code>) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "setTrustAnchors", + methodArgs = {java.util.Set.class} + ) + }) + public final void testSetTrustAnchors03() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + try { + // use null + p.setTrustAnchors(null); + fail("NPE expected"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for <code>setTrustAnchors(Set)</code> method<br> + * Assertion: <code>ClassCastException</code> - + * if any of the elements in the set are not of type + * <code>java.security.cert.TrustAnchor</code> + * @throws InvalidAlgorithmParameterException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies ClassCastException.", + targets = { + @TestTarget( + methodName = "setTrustAnchors", + methodArgs = {java.util.Set.class} + ) + }) + @SuppressWarnings("unchecked") + public final void testSetTrustAnchors04() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + Set s = new HashSet(p.getTrustAnchors()); + s.add(new Object()); + try { + p.setTrustAnchors(s); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + } + } + + /** + * Test for <code>toString</code> method<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() throws Exception { + Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet(); + if (taSet == null) { + fail(getName() + ": not performed (could not create test TrustAnchor set)"); + } + + PKIXParameters p = new PKIXParameters(taSet); + assertNotNull(p.toString()); + + PKIXParameters p1 = null; + try { + p1.toString(); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } +} diff --git a/security/src/test/java/tests/security/cert/PolicyQualifierInfoTest.java b/security/src/test/java/tests/security/cert/PolicyQualifierInfoTest.java new file mode 100644 index 0000000..b7c5b19 --- /dev/null +++ b/security/src/test/java/tests/security/cert/PolicyQualifierInfoTest.java @@ -0,0 +1,420 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.security.cert.PolicyQualifierInfo; +import java.util.Arrays; + +/** + * PolicyQualifierInfo test + * + */ +@TestTargetClass(PolicyQualifierInfo.class) +public class PolicyQualifierInfoTest extends TestCase { + + /** + * Constructor for PolicyQualifierInfoTest. + * @param name + */ + public PolicyQualifierInfoTest(String name) { + super(name); + } + + /** + * Test #1 for <code>PolicyQualifierInfo</code> constructor<br> + * Assertion: throws <code>IOException</code> if byte array + * parameter does not represent a valid and parsable policy + * qualifier info + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException and IOException.", + targets = { + @TestTarget( + methodName = "PolicyQualifierInfo", + methodArgs = {byte[].class} + ) + }) + public final void test_Ctor() throws IOException { + try { + // pass null + new PolicyQualifierInfo(null); + fail("No expected NullPointerException"); + } catch (NullPointerException e) { + } + + try { + // pass empty array + new PolicyQualifierInfo(new byte[0]); + fail("IOE expected"); + } catch (IOException e) { + } + + + try { + // pass invalid array + new PolicyQualifierInfo( + new byte[] {(byte)0x06, (byte)0x03, + (byte)0x81, (byte)0x34, (byte)0x03}); + fail("IOE expected"); + } catch (IOException e) { + } + } + + /** + * Test #2 for <code>PolicyQualifierInfo</code> constructor<br> + * Assertion: throws <code>IOException</code> if byte array + * parameter does not represent a valid and parsable policy + * qualifier info + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "PolicyQualifierInfo", + methodArgs = {byte[].class} + ) + }) + public final void testPolicyQualifierInfo02() { + // get valid encoding + byte[] encoding = getDerEncoding(); + // corrupt root seq length + encoding[1] = (byte)0x27; + + try { + // pass invalid array + new PolicyQualifierInfo(encoding); + fail("IOE expected"); + } catch (IOException e) { + } + + + // get valid encoding + encoding = getDerEncoding(); + // corrupt policy qualifier ID: + // - change OID to the Relative OID + encoding[2] = (byte)13; + try { + // pass invalid array + new PolicyQualifierInfo(encoding); + fail("IOE expected"); + } catch (IOException e) { + } + } + + /** + * Test #3 for <code>PolicyQualifierInfo</code> constructor<br> + * Assertion: Creates an instance of <code>PolicyQualifierInfo</code> + * from the encoded bytes + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "PolicyQualifierInfo", + methodArgs = {byte[].class} + ) + }) + public final void testPolicyQualifierInfo03() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + // pass valid array + new PolicyQualifierInfo(encoding); + } + + /** + * Test #4 for <code>PolicyQualifierInfo</code> constructor<br> + * Assertion: The encoded byte array is copied on construction + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with encoded byte array copied " + + "on construction.", + targets = { + @TestTarget( + methodName = "PolicyQualifierInfo", + methodArgs = {byte[].class} + ) + }) + public final void testPolicyQualifierInfo04() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + byte[] encodingCopy = encoding.clone(); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encodingCopy); + // get encoding + byte[] encodingRet = i.getEncoded(); + // check returned array + assertTrue(Arrays.equals(encoding, encodingRet)); + // modify input + encodingCopy[0] = (byte)0; + // get encoding again + byte[] encodingRet1 = i.getEncoded(); + // check that above modification did not change + // internal state of the PolicyQualifierInfo instance + assertTrue(Arrays.equals(encoding, encodingRet1)); + } + + /** + * Test #1 for <code>getEncoded()</code> method + * Assertion: Returns the ASN.1 DER encoded form of + * this <code>PolicyQualifierInfo</code> + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded01() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encoding); + // get encoding + byte[] encodingRet = i.getEncoded(); + // check returned array + assertTrue(Arrays.equals(encoding, encodingRet)); + } + + /** + * Test #2 for <code>getEncoded()</code> method + * Assertion: a copy is returned each time + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded02() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + byte[] encodingCopy = encoding.clone(); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encodingCopy); + // get encoding + byte[] encodingRet = i.getEncoded(); + // modify returned array + encodingRet[0] = (byte)0; + // get encoding again + byte[] encodingRet1 = i.getEncoded(); + // check that above modification did not change + // internal state of the PolicyQualifierInfo instance + assertTrue(Arrays.equals(encoding, encodingRet1)); + } + + /** + * Test #1 for <code>getPolicyQualifier()</code> method + * Assertion: Returns the ASN.1 DER encoded form of + * this <code>PolicyQualifierInfo</code> + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPolicyQualifier", + methodArgs = {} + ) + }) + public final void testGetPolicyQualifier01() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + // get policy qualifier encoding + byte[] pqEncoding = new byte[28]; + System.arraycopy(encoding, 12, pqEncoding, 0, pqEncoding.length); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encoding); + // get encoding + byte[] pqEncodingRet = i.getPolicyQualifier(); + // check returned array + assertTrue(Arrays.equals(pqEncoding, pqEncodingRet)); + } + + /** + * Test #2 for <code>getPolicyQualifier()</code> method + * Assertion: a copy is returned each time + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPolicyQualifier", + methodArgs = {} + ) + }) + public final void testGetPolicyQualifier02() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + // get policy qualifier encoding + byte[] pqEncoding = new byte[28]; + System.arraycopy(encoding, 12, pqEncoding, 0, pqEncoding.length); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encoding); + // get encoding + byte[] pqEncodingRet = i.getPolicyQualifier(); + // modify returned array + pqEncodingRet[0] = (byte)0; + // get encoding again + byte[] pqEncodingRet1 = i.getPolicyQualifier(); + // + assertNotSame(pqEncodingRet, pqEncodingRet1); + // check that above modification did not change + // internal state of the PolicyQualifierInfo instance + assertTrue(Arrays.equals(pqEncoding, pqEncodingRet1)); + } + + /** + * Test for <code>getPolicyQualifierId()</code> method + * Assertion: Returns the <code>policyQualifierId</code> + * field of this <code>PolicyQualifierInfo</code>. + * The <code>policyQualifierId</code> is an Object Identifier (OID) + * represented by a set of nonnegative integers separated by periods + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPolicyQualifierId", + methodArgs = {} + ) + }) + public final void testGetPolicyQualifierId() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encoding); + // get OID as String and check it + assertEquals("1.3.6.1.5.5.7.2.1", i.getPolicyQualifierId()); + + // get valid encoding + encoding = getDerEncoding(); + // change OID to 1.3.98437.82818.1 + encoding[5] = (byte)0x86; + encoding[6] = (byte)0x81; + encoding[8] = (byte)0x85; + encoding[9] = (byte)0x87; + i = new PolicyQualifierInfo(encoding); + // get OID as String and check it + assertEquals("1.3.98437.82818.1", i.getPolicyQualifierId()); + } + + /** + * Test for <code>toString()</code> method + * Assertion: returns description of the contents of this + * <code>PolicyQualifierInfo</code> as printable <code>String</code> + * @throws IOException + * + * @throws IOException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() throws IOException { + // get valid encoding + byte[] encoding = getDerEncoding(); + // pass valid array + PolicyQualifierInfo i = new PolicyQualifierInfo(encoding); + + assertNotNull(i.toString()); + } + + // + // Private stuff + // + + /** + * Returns valid DER encoding for the following ASN.1 definition + * (as specified in RFC 3280 - + * Internet X.509 Public Key Infrastructure. + * Certificate and Certificate Revocation List (CRL) Profile. + * http://www.ietf.org/rfc/rfc3280.txt): + * + * PolicyQualifierInfo ::= SEQUENCE { + * policyQualifierId PolicyQualifierId, + * qualifier ANY DEFINED BY policyQualifierId + * } + * + * where policyQualifierId (OID) is + * 1.3.6.1.5.5.7.2.1 + * and qualifier (IA5String) is + * "http://www.qq.com/stmt.txt" + * + * (data generated by own encoder during test development) + */ + private static final byte[] getDerEncoding() { + // DO NOT MODIFY! + return new byte[] { + (byte)0x30, (byte)0x26, // tag Seq, length + (byte)0x06, (byte)0x08, // tag OID, length + (byte)0x2b, (byte)0x06, (byte)0x01, (byte)0x05, // oid value + (byte)0x05, (byte)0x07, (byte)0x02, (byte)0x01, // oid value + (byte)0x16, (byte)0x1a, // tag IA5String, length + (byte)0x68, (byte)0x74, (byte)0x74, (byte)0x70, // IA5String value + (byte)0x3a, (byte)0x2f, (byte)0x2f, (byte)0x77, // IA5String value + (byte)0x77, (byte)0x77, (byte)0x2e, (byte)0x71, // IA5String value + (byte)0x71, (byte)0x2e, (byte)0x63, (byte)0x6f, // IA5String value + (byte)0x6d, (byte)0x2f, (byte)0x73, (byte)0x74, // IA5String value + (byte)0x6d, (byte)0x74, (byte)0x2e, (byte)0x74, // IA5String value + (byte)0x78, (byte)0x74 // IA5String value + }; + } +} diff --git a/security/src/test/java/tests/security/cert/TrustAnchorTest.java b/security/src/test/java/tests/security/cert/TrustAnchorTest.java new file mode 100644 index 0000000..589ab8b --- /dev/null +++ b/security/src/test/java/tests/security/cert/TrustAnchorTest.java @@ -0,0 +1,945 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.security.PublicKey; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.TrustAnchor; +import java.security.cert.X509Certificate; +import java.security.spec.InvalidKeySpecException; +import java.util.Arrays; + +import javax.security.auth.x500.X500Principal; + +import org.apache.harmony.security.tests.support.cert.TestUtils; +import org.apache.harmony.security.tests.support.TestKeyPair; + +/** + * Unit tests for <code>TrustAnchor</code> + */ +@TestTargetClass(TrustAnchor.class) +public class TrustAnchorTest extends TestCase { + private static final String keyAlg = "DSA"; + // Sample of some valid CA name + private static final String validCaNameRfc2253 = + "CN=Test CA,"+ + "OU=Testing Division,"+ + "O=Test It All,"+ + "L=Test Town,"+ + "ST=Testifornia,"+ + "C=Testland"; + + /** + * Test #1 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: valid parameters passed<br> + * Expected: must pass without any exceptions + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.lang.String.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorStringPublicKeybyteArray01() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + // sub testcase 1 + new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding()); + // sub testcase 2 + new TrustAnchor(validCaNameRfc2253, pk, getEncodingPSOnly()); + // sub testcase 3 + new TrustAnchor(validCaNameRfc2253, pk, getEncodingESOnly()); + // sub testcase 4 + new TrustAnchor(validCaNameRfc2253, pk, getEncodingNoMinMax()); + } + + /** + * Test #2 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: <code>null</code> as nameConstraints passed<br> + * Expected: must pass without any exceptions + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.lang.String.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorStringPublicKeybyteArray02() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + new TrustAnchor(validCaNameRfc2253, pk, null); + } + + /** + * Test #3 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br> + * Assertion: nameConstraints cloned by the constructor<br> + * Test preconditions: modify passed nameConstraints<br> + * Expected: modification must not change object internal state + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.lang.String.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorStringPublicKeybyteArray03() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + byte[] nc = getEncodingPSOnly(); + byte[] ncCopy = nc.clone(); + // sub testcase 5 - nameConstraints can be null + TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, ncCopy); + // modify + ncCopy[0]=(byte)0; + // check that above modification did not change + // object internal state + assertTrue(Arrays.equals(nc, ta.getNameConstraints())); + } + + /** + * Test #4 for <code>TrustAnchor(String, PublicKey, byte[])</code> constructor<br> + * Assertion: <code>NullPointerException</code> if <code>caName</code> + * or <code>caPublicKey</code> parameter is <code>null</code><br> + * Test preconditions: pass <code>null</code> as mentioned parameter<br> + * Expected: NullPointerException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies exceptions.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.lang.String.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorStringPublicKeybyteArray04() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + // sub testcase 1: 'caName' param is null + try { + new TrustAnchor((String)null, pk, getEncodingPSOnly()); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // sub testcase 2: 'caPublicKey' param is null + try { + new TrustAnchor(validCaNameRfc2253, null, getEncodingPSOnly()); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // sub testcase 3: 'caName' and 'caPublicKey' params are null + try { + new TrustAnchor((String)null, null, getEncodingPSOnly()); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // sub testcase 4: 'caName' param is empty + try { + new TrustAnchor("", pk, getEncodingPSOnly()); + fail("IllegalArgumentException has not been thrown"); + } catch (IllegalArgumentException ok) { + } + + // sub testcase 5: 'caName' param is incorrect distinguished name + try { + new TrustAnchor("AID.11.12=A", pk, getEncodingPSOnly()); + fail("IllegalArgumentException has not been thrown"); + } catch (IllegalArgumentException ok) { + } + } + + /** + * Test #1 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: valid parameters passed<br> + * Expected: must pass without any exceptions + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {javax.security.auth.x500.X500Principal.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorX500PrincipalPublicKeybyteArray01() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + X500Principal x500p = new X500Principal(validCaNameRfc2253); + // sub testcase 1 + new TrustAnchor(x500p, pk, getFullEncoding()); + // sub testcase 2 + new TrustAnchor(x500p, pk, getEncodingPSOnly()); + // sub testcase 3 + new TrustAnchor(x500p, pk, getEncodingESOnly()); + // sub testcase 4 + new TrustAnchor(x500p, pk, getEncodingNoMinMax()); + } + + /** + * Test #2 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: <code>null</code> as nameConstraints passed<br> + * Expected: must pass without any exceptions + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {javax.security.auth.x500.X500Principal.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorX500PrincipalPublicKeybyteArray02() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + X500Principal x500p = new X500Principal(validCaNameRfc2253); + + new TrustAnchor(x500p, pk, null); + } + + /** + * Test #3 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br> + * Assertion: nameConstraints cloned by the constructor<br> + * Test preconditions: modify passed nameConstraints<br> + * Expected: modification must not change object internal state + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies TrustAnchor with copied byte array.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {javax.security.auth.x500.X500Principal.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorX500PrincipalPublicKeybyteArray03() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + byte[] nc = getEncodingPSOnly(); + byte[] ncCopy = nc.clone(); + // sub testcase 5 - nameConstraints can be null + TrustAnchor ta = new TrustAnchor(new X500Principal(validCaNameRfc2253), + pk, ncCopy); + // modify + ncCopy[0]=(byte)0; + // check that above modification did not change + // object internal state + assertTrue(Arrays.equals(nc, ta.getNameConstraints())); + } + + /** + * Test #4 for <code>TrustAnchor(X500Principal, PublicKey, byte[])</code> constructor<br> + * Assertion: <code>NullPointerException</code> if <code>caPrincipal</code> + * or <code>caPublicKey</code> parameter is <code>null</code><br> + * Test preconditions: pass <code>null</code> as mentioned parameter<br> + * Expected: NullPointerException + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {javax.security.auth.x500.X500Principal.class, java.security.PublicKey.class, byte[].class} + ) + }) + public final void testTrustAnchorX500PrincipalPublicKeybyteArray04() + throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + X500Principal x500p = new X500Principal(validCaNameRfc2253); + // sub testcase 1 + try { + new TrustAnchor((X500Principal)null, + pk, getEncodingPSOnly()); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // sub testcase 2 + try { + new TrustAnchor(x500p, null, getEncodingPSOnly()); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + // sub testcase 3 + try { + new TrustAnchor((X500Principal)null, null, + getEncodingPSOnly()); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + + } + + /** + * Test #1 for <code>TrustAnchor(X509Certificate, byte[])</code> + * constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: valid parameters passed<br> + * Expected: must pass without any exceptions + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.security.cert.X509Certificate.class, byte[].class} + ) + }) + public final void testTrustAnchorX509CertificatebyteArray01() + throws CertificateException { + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + // sub testcase 1 + TrustAnchor ta1 = new TrustAnchor(pemCert, getFullEncoding()); + assertNull(ta1.getCA()); + assertNull(ta1.getCAName()); + assertNull(ta1.getCAPublicKey()); + assertTrue(Arrays.equals(getFullEncoding(), ta1.getNameConstraints())); + assertEquals(pemCert, ta1.getTrustedCert()); + + // sub testcase 2 + TrustAnchor ta2 = new TrustAnchor(pemCert, getEncodingPSOnly()); + assertNull(ta2.getCA()); + assertNull(ta2.getCAName()); + assertNull(ta2.getCAPublicKey()); + assertTrue(Arrays.equals(getEncodingPSOnly(), ta2.getNameConstraints())); + assertEquals(pemCert, ta2.getTrustedCert()); + + // sub testcase 3 + TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingESOnly()); + assertNull(ta3.getCA()); + assertNull(ta3.getCAName()); + assertNull(ta3.getCAPublicKey()); + assertTrue(Arrays.equals(getEncodingESOnly(), ta3.getNameConstraints())); + assertEquals(pemCert, ta3.getTrustedCert()); + + // sub testcase 4 + TrustAnchor ta4 = new TrustAnchor(pemCert, getEncodingNoMinMax()); + assertNull(ta4.getCA()); + assertNull(ta4.getCAName()); + assertNull(ta4.getCAPublicKey()); + assertTrue(Arrays.equals(getEncodingNoMinMax(), ta4 + .getNameConstraints())); + assertEquals(pemCert, ta4.getTrustedCert()); + } + + /** + * Test #2 for <code>TrustAnchor(X509Certificate, byte[])</code> + * constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: <code>null</code> as X509Certificate passed<br> + * Expected: <code>NullPointerException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.security.cert.X509Certificate.class, byte[].class} + ) + }) + public final void testTrustAnchorX509CertificatebyteArray02() + throws Exception { + + try { + new TrustAnchor(null, getFullEncoding()); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * Test #3 for <code>TrustAnchor(X509Certificate, byte[])</code> + * constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: <code>null</code> as nameConstraints passed<br> + * Expected: must pass without any exceptions + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with null as nameConstraints parameter.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.security.cert.X509Certificate.class, byte[].class} + ) + }) + public final void testTrustAnchorX509CertificatebyteArray03() + throws Exception { + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + try { + new TrustAnchor(pemCert, null); + } catch (Exception e) { + fail("Unexpected exeption " + e.getMessage()); + } + } + + /** + * Test #4 for <code>TrustAnchor(X509Certificate, byte[])</code> + * constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: pass not valid name constraints array Expected: + * IllegalArgumentException + * + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.security.cert.X509Certificate.class, byte[].class} + ) + }) + public final void testTrustAnchorX509CertificatebyteArray04() + throws Exception { + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + try { + new TrustAnchor(pemCert, + new byte[] { (byte) 1, (byte) 2, (byte) 3 }); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + // expected + } + } + + /** + * Test #5 for <code>TrustAnchor(X509Certificate, byte[])</code> + * constructor<br> + * Assertion: creates <code>TrustAnchor</code> instance<br> + * Test preconditions: both parameters are passed as null<br> + * Expected: <code>NullPointerException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "TrustAnchor", + methodArgs = {java.security.cert.X509Certificate.class, byte[].class} + ) + }) + public final void testTrustAnchorX509CertificatebyteArray05() + throws Exception { + + try { + new TrustAnchor(null, null); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * Test #1 for <code>getCAPublicKey()</code> method<br> + * + * Assertion: returns most trusted CA public key</code><br> + * Test preconditions: valid name passed to the constructor<br> + * Expected: the same name must be returned by the method<br> + * + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCAPublicKey", + methodArgs = {} + ) + }) + public final void testGetCAPublicKey01() throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + // sub testcase 1 + TrustAnchor ta = + new TrustAnchor(validCaNameRfc2253, pk, null); + assertEquals("equals1", pk, ta.getCAPublicKey()); + // sub testcase 2 + X500Principal x500p = new X500Principal(validCaNameRfc2253); + ta = new TrustAnchor(x500p, pk, null); + assertEquals("equals2", pk, ta.getCAPublicKey()); + } + + + /** + * Test #1 for <code>getCAName()</code> method<br> + * + * Assertion: returns most trusted CA name as <code>String</code><br> + * Test preconditions: valid name passed to the constructor<br> + * Expected: the same name must be returned by the method<br> + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCAName", + methodArgs = {} + ) + }) + public final void testGetCAName01() throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + // sub testcase 1 + TrustAnchor ta = + new TrustAnchor(validCaNameRfc2253, pk, null); + assertEquals("equals1", validCaNameRfc2253, ta.getCAName()); + // sub testcase 2 + X500Principal x500p = new X500Principal(validCaNameRfc2253); + ta = new TrustAnchor(x500p, pk, null); + assertEquals("equals2", validCaNameRfc2253, ta.getCAName()); + } + + /** + * Test #2 for <code>getCAName()</code> method<br> + * + * Assertion: returns ... <code>null</code> if <code>TrustAnchor</code> + * was not specified as trusted certificate<br> + * Test preconditions: test object is not specified as trusted certificate<br> + * Expected: <code>null</code> as return value<br> + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getTrustedCert returns null if TrustAnchor " + + "was not specified as trusted certificate.", + targets = { + @TestTarget( + methodName = "getTrustedCert", + methodArgs = {} + ) + }) + public final void testGetTrustedCer02() throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + // sub testcase 1 + TrustAnchor ta = + new TrustAnchor(validCaNameRfc2253, pk, null); + assertNull("null1", ta.getTrustedCert()); + // sub testcase 2 + X500Principal x500p = new X500Principal(validCaNameRfc2253); + ta = new TrustAnchor(x500p, pk, null); + assertNull("null2", ta.getTrustedCert()); + } + + /** + * Test #1 for <code>getNameConstraints()</code> method<br> + * + * Assertion: Returns the name constraints parameter.<br> + * Test preconditions: valid parameters are passed to the constructors<br> + * Expected: the valid parameters must be returned by the method<br> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getNameConstraints", + methodArgs = {} + ) + }) + public final void testGetNameConstraints01() throws Exception { + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, + getFullEncoding()); + assertTrue(Arrays.equals(getFullEncoding(), ta1.getNameConstraints())); + + X500Principal x500p = new X500Principal(validCaNameRfc2253); + TrustAnchor ta2 = new TrustAnchor(x500p, pk, getEncodingNoMinMax()); + assertTrue(Arrays.equals(getEncodingNoMinMax(), ta2 + .getNameConstraints())); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingPSOnly()); + assertTrue(Arrays.equals(getEncodingPSOnly(), ta3.getNameConstraints())); + } + + /** + * Test #2 for <code>getNameConstraints()</code> method<br> + * + * Assertion: Returns the name constraints parameter.<br> + * Test preconditions: null parameters are passed to the constructors<br> + * Expected: the null parameters must be returned by the method<br> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getNameConstraints returns null.", + targets = { + @TestTarget( + methodName = "getNameConstraints", + methodArgs = {} + ) + }) + public final void testGetNameConstraints02() throws Exception { + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, null); + assertNull(ta1.getNameConstraints()); + + X500Principal x500p = new X500Principal(validCaNameRfc2253); + TrustAnchor ta2 = new TrustAnchor(x500p, pk, null); + assertNull(ta2.getNameConstraints()); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + TrustAnchor ta3 = new TrustAnchor(pemCert, null); + assertNull(ta3.getNameConstraints()); + } + + /** + * Test #1 for <code>toString()</code> method<br> + * + * Assertion: returns a formatted string describing the TrustAnchor<br> + * Test preconditions: valid parameters are passed to the constructors<br> + * Expected: not null string<br> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public final void testToString() throws Exception { + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + TrustAnchor ta1 = new TrustAnchor(validCaNameRfc2253, pk, + getFullEncoding()); + assertNotNull(ta1.toString()); + + X500Principal x500p = new X500Principal(validCaNameRfc2253); + TrustAnchor ta2 = new TrustAnchor(x500p, pk, getEncodingNoMinMax()); + assertNotNull(ta2.toString()); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + TrustAnchor ta3 = new TrustAnchor(pemCert, getEncodingPSOnly()); + assertNotNull(ta3.toString()); + } + + /** + * Test #1 for <code>getCA()</code> method<br> + * + * Assertion: returns most trusted CA<br> + * Test preconditions: valid CA or CA name passed to the constructor<br> + * Expected: the same CA ot the CA with the same name must be returned + * by the method<br> + * @throws InvalidKeySpecException + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCA", + methodArgs = {} + ) + }) + public final void testGetCA01() throws Exception { + + PublicKey pk = new TestKeyPair(keyAlg).getPublic(); + + // sub testcase 1 + TrustAnchor ta = + new TrustAnchor(validCaNameRfc2253, pk, null); + X500Principal ca = ta.getCA(); + assertEquals("equals1", validCaNameRfc2253, ca.getName()); + // sub testcase 2 + X500Principal x500p = new X500Principal(validCaNameRfc2253); + ta = new TrustAnchor(x500p, pk, null); + assertEquals("equals2", x500p, ta.getCA()); + } + + // + // Private stuff + // + + /* + * The following methods return valid DER encoding + * for the following ASN.1 definition (as specified in RFC 3280 - + * Internet X.509 Public Key Infrastructure. + * Certificate and Certificate Revocation List (CRL) Profile. + * http://www.ietf.org/rfc/rfc3280.txt): + * + * NameConstraints ::= SEQUENCE { + * permittedSubtrees [0] GeneralSubtrees OPTIONAL, + * excludedSubtrees [1] GeneralSubtrees OPTIONAL } + * + * GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree + * + * GeneralSubtree ::= SEQUENCE { + * base GeneralName, + * minimum [0] BaseDistance DEFAULT 0, + * maximum [1] BaseDistance OPTIONAL } + * + * BaseDistance ::= INTEGER (0..MAX) + * + * GeneralName ::= CHOICE { + * otherName [0] OtherName, + * rfc822Name [1] IA5String, + * dNSName [2] IA5String, + * x400Address [3] ORAddress, + * directoryName [4] Name, + * ediPartyName [5] EDIPartyName, + * uniformResourceIdentifier [6] IA5String, + * iPAddress [7] OCTET STRING, + * registeredID [8] OBJECT IDENTIFIER} + */ + + // + // Full NameConstraints encoding + // (generated by own encoder class created during test development) + // + // @return Full NameConstraints encoding + // with all OPTIONAL values presented. + // + private static final byte[] getFullEncoding() { + // DO NOT MODIFY! + return new byte[] { + (byte)0x30,(byte)0x81,(byte)0x8c,(byte)0xa0, + (byte)0x44,(byte)0x30,(byte)0x16,(byte)0x86, + (byte)0x0e,(byte)0x66,(byte)0x69,(byte)0x6c, + (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f, + (byte)0x66,(byte)0x6f,(byte)0x6f,(byte)0x2e, + (byte)0x63,(byte)0x6f,(byte)0x6d,(byte)0x80, + (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01, + (byte)0x01,(byte)0x30,(byte)0x16,(byte)0x86, + (byte)0x0e,(byte)0x66,(byte)0x69,(byte)0x6c, + (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f, + (byte)0x62,(byte)0x61,(byte)0x72,(byte)0x2e, + (byte)0x63,(byte)0x6f,(byte)0x6d,(byte)0x80, + (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01, + (byte)0x01,(byte)0x30,(byte)0x12,(byte)0x86, + (byte)0x0a,(byte)0x66,(byte)0x69,(byte)0x6c, + (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f, + (byte)0x6d,(byte)0x75,(byte)0x75,(byte)0x80, + (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01, + (byte)0x01,(byte)0xa1,(byte)0x44,(byte)0x30, + (byte)0x16,(byte)0x86,(byte)0x0e,(byte)0x68, + (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a, + (byte)0x2f,(byte)0x2f,(byte)0x66,(byte)0x6f, + (byte)0x6f,(byte)0x2e,(byte)0x63,(byte)0x6f, + (byte)0x6d,(byte)0x80,(byte)0x01,(byte)0x00, + (byte)0x81,(byte)0x01,(byte)0x01,(byte)0x30, + (byte)0x16,(byte)0x86,(byte)0x0e,(byte)0x68, + (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a, + (byte)0x2f,(byte)0x2f,(byte)0x62,(byte)0x61, + (byte)0x72,(byte)0x2e,(byte)0x63,(byte)0x6f, + (byte)0x6d,(byte)0x80,(byte)0x01,(byte)0x00, + (byte)0x81,(byte)0x01,(byte)0x01,(byte)0x30, + (byte)0x12,(byte)0x86,(byte)0x0a,(byte)0x68, + (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a, + (byte)0x2f,(byte)0x2f,(byte)0x6d,(byte)0x75, + (byte)0x75,(byte)0x80,(byte)0x01,(byte)0x00, + (byte)0x81,(byte)0x01,(byte)0x01 + }; + } + + // + // NameConstraints encoding without excludedSubtrees + // (generated by own encoder class created during test development) + // + // @return NameConstraints encoding with + // permittedSubtrees only; all OPTIONAL + // values in permittedSubtrees are presented. + // + private static final byte[] getEncodingPSOnly() { + // DO NOT MODIFY! + return new byte[] { + (byte)0x30,(byte)0x46,(byte)0xa0,(byte)0x44, + (byte)0x30,(byte)0x16,(byte)0x86,(byte)0x0e, + (byte)0x66,(byte)0x69,(byte)0x6c,(byte)0x65, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x66, + (byte)0x6f,(byte)0x6f,(byte)0x2e,(byte)0x63, + (byte)0x6f,(byte)0x6d,(byte)0x80,(byte)0x01, + (byte)0x00,(byte)0x81,(byte)0x01,(byte)0x01, + (byte)0x30,(byte)0x16,(byte)0x86,(byte)0x0e, + (byte)0x66,(byte)0x69,(byte)0x6c,(byte)0x65, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x62, + (byte)0x61,(byte)0x72,(byte)0x2e,(byte)0x63, + (byte)0x6f,(byte)0x6d,(byte)0x80,(byte)0x01, + (byte)0x00,(byte)0x81,(byte)0x01,(byte)0x01, + (byte)0x30,(byte)0x12,(byte)0x86,(byte)0x0a, + (byte)0x66,(byte)0x69,(byte)0x6c,(byte)0x65, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x6d, + (byte)0x75,(byte)0x75,(byte)0x80,(byte)0x01, + (byte)0x00,(byte)0x81,(byte)0x01,(byte)0x01, + }; + } + + // + // NameConstraints encoding without permittedSubtrees + // (generated by own encoder class created during test development) + // + // @return NameConstraints encoding with + // excludedSubtrees only; all OPTIONAL + // values in excludedSubtrees are presented. + // + private static final byte[] getEncodingESOnly() { + // DO NOT MODIFY! + return new byte[] { + (byte)0x30,(byte)0x46,(byte)0xa1,(byte)0x44, + (byte)0x30,(byte)0x16,(byte)0x86,(byte)0x0e, + (byte)0x68,(byte)0x74,(byte)0x74,(byte)0x70, // http + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x66, // ://f + (byte)0x6f,(byte)0x6f,(byte)0x2e,(byte)0x63, // oo.c + (byte)0x6f,(byte)0x6d,(byte)0x80,(byte)0x01, // om + (byte)0x00,(byte)0x81,(byte)0x01,(byte)0x01, + (byte)0x30,(byte)0x16,(byte)0x86,(byte)0x0e, + (byte)0x68,(byte)0x74,(byte)0x74,(byte)0x70, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x62, + (byte)0x61,(byte)0x72,(byte)0x2e,(byte)0x63, + (byte)0x6f,(byte)0x6d,(byte)0x80,(byte)0x01, + (byte)0x00,(byte)0x81,(byte)0x01,(byte)0x01, + (byte)0x30,(byte)0x12,(byte)0x86,(byte)0x0a, + (byte)0x68,(byte)0x74,(byte)0x74,(byte)0x70, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x6d, + (byte)0x75,(byte)0x75,(byte)0x80,(byte)0x01, + (byte)0x00,(byte)0x81,(byte)0x01,(byte)0x01, + }; + } + + // + // NameConstraints full encoding with all (OPTIONAL) + // minimum/maximum GeneralSubtree fields OMITTED + // (generated by own encoder class created during test development) + // + // @return Full NameConstraints encoding + // with all (OPTIONAL) minimum/maximum + // GeneralSubtree fields OMITTED + // + private static final byte[] getEncodingNoMinMax() { + // DO NOT MODIFY! + return new byte[] { + (byte)0x30,(byte)0x68,(byte)0xa0,(byte)0x32, + (byte)0x30,(byte)0x10,(byte)0x86,(byte)0x0e, + (byte)0x66,(byte)0x69,(byte)0x6c,(byte)0x65, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x66, + (byte)0x6f,(byte)0x6f,(byte)0x2e,(byte)0x63, + (byte)0x6f,(byte)0x6d,(byte)0x30,(byte)0x10, + (byte)0x86,(byte)0x0e,(byte)0x66,(byte)0x69, + (byte)0x6c,(byte)0x65,(byte)0x3a,(byte)0x2f, + (byte)0x2f,(byte)0x62,(byte)0x61,(byte)0x72, + (byte)0x2e,(byte)0x63,(byte)0x6f,(byte)0x6d, + (byte)0x30,(byte)0x0c,(byte)0x86,(byte)0x0a, + (byte)0x66,(byte)0x69,(byte)0x6c,(byte)0x65, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x6d, + (byte)0x75,(byte)0x75,(byte)0xa1,(byte)0x32, + (byte)0x30,(byte)0x10,(byte)0x86,(byte)0x0e, + (byte)0x68,(byte)0x74,(byte)0x74,(byte)0x70, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x66, + (byte)0x6f,(byte)0x6f,(byte)0x2e,(byte)0x63, + (byte)0x6f,(byte)0x6d,(byte)0x30,(byte)0x10, + (byte)0x86,(byte)0x0e,(byte)0x68,(byte)0x74, + (byte)0x74,(byte)0x70,(byte)0x3a,(byte)0x2f, + (byte)0x2f,(byte)0x62,(byte)0x61,(byte)0x72, + (byte)0x2e,(byte)0x63,(byte)0x6f,(byte)0x6d, + (byte)0x30,(byte)0x0c,(byte)0x86,(byte)0x0a, + (byte)0x68,(byte)0x74,(byte)0x74,(byte)0x70, + (byte)0x3a,(byte)0x2f,(byte)0x2f,(byte)0x6d, + (byte)0x75,(byte)0x75, + }; + } + +} diff --git a/security/src/test/java/tests/security/cert/X509CRL2Test.java b/security/src/test/java/tests/security/cert/X509CRL2Test.java new file mode 100644 index 0000000..76c1239 --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CRL2Test.java @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.InputStream; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CRLException; +import java.security.cert.Certificate; +import java.security.cert.CertificateFactory; +import java.security.cert.X509CRL; +import java.security.cert.X509CRLEntry; +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import tests.support.resource.Support_Resources; + +@TestTargetClass(X509CRL.class) +public class X509CRL2Test extends TestCase { + + private X509Certificate pemCert = null; + + protected void setUp() throws Exception { + + InputStream is = Support_Resources + .getResourceStream("hyts_certificate_PEM.txt"); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + pemCert = (X509Certificate) certFact.generateCertificate(is); + } + + /** + * @tests java.security.cert.X509CRL#getExtensionValue(java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getExtensionValue", + methodArgs = {String.class} + ) + }) + public void _test_getExtensionValueLjava_lang_String() { + if (pemCert != null) { + Vector<String> extensionOids = new Vector<String>(); + extensionOids.addAll(pemCert.getCriticalExtensionOIDs()); + extensionOids.addAll(pemCert.getNonCriticalExtensionOIDs()); + Iterator i = extensionOids.iterator(); + while (i.hasNext()) { + String oid = (String) i.next(); + byte[] value = pemCert.getExtensionValue(oid); + if (value != null && value.length > 0) { + // check that it is an encoded as a OCTET STRING + assertTrue("The extension value for the oid " + oid + + " was not encoded as an OCTET STRING", + value[0] == 0x04); + } + }// end while + } else { + fail("Unable to obtain X509Certificate"); + } + } + + /** + * @tests java.security.cert.X509CRL#X509CRL() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "X509CRL", + methodArgs = {} + ) + }) + public void _test_X509CRL() { + MyX509CRL crl = new MyX509CRL(); + assertEquals("X.509", crl.getType()); + } + + class MyX509CRL extends X509CRL { + + public MyX509CRL() { + super(); + } + + @Override + public byte[] getEncoded() throws CRLException { + return null; + } + + @Override + public Principal getIssuerDN() { + return null; + } + + @Override + public Date getNextUpdate() { + return null; + } + + @Override + public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) { + return null; + } + + @Override + public Set<? extends X509CRLEntry> getRevokedCertificates() { + return null; + } + + @Override + public String getSigAlgName() { + return null; + } + + @Override + public String getSigAlgOID() { + return null; + } + + @Override + public byte[] getSigAlgParams() { + return null; + } + + @Override + public byte[] getSignature() { + return null; + } + + @Override + public byte[] getTBSCertList() throws CRLException { + return null; + } + + @Override + public Date getThisUpdate() { + return null; + } + + @Override + public int getVersion() { + return 0; + } + + @Override + public void verify(PublicKey key) throws CRLException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + @Override + public void verify(PublicKey key, String sigProvider) + throws CRLException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + + @Override + public boolean isRevoked(Certificate cert) { + return false; + } + + @Override + public String toString() { + return null; + } + + public Set<String> getCriticalExtensionOIDs() { + return null; + } + + public byte[] getExtensionValue(String oid) { + return null; + } + + public Set<String> getNonCriticalExtensionOIDs() { + return null; + } + + public boolean hasUnsupportedCriticalExtension() { + return false; + } + } + +} diff --git a/security/src/test/java/tests/security/cert/X509CRLEntry2Test.java b/security/src/test/java/tests/security/cert/X509CRLEntry2Test.java new file mode 100644 index 0000000..299f377 --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CRLEntry2Test.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.InputStream; +import java.security.cert.CertificateFactory; +import java.security.cert.X509CRLEntry; +import java.security.cert.X509Certificate; +import java.util.Iterator; +import java.util.Vector; + +import tests.support.resource.Support_Resources; + +@TestTargetClass(X509CRLEntry.class) +public class X509CRLEntry2Test extends TestCase { + + private X509Certificate pemCert = null; + + protected void setUp() throws Exception { + + InputStream is = Support_Resources + .getResourceStream("hyts_certificate_PEM.txt"); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + pemCert = (X509Certificate) certFact.generateCertificate(is); + } + + /** + * @tests java.security.cert.X509CRLEntry#getExtensionValue(java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getExtensionValue", + methodArgs = {String.class} + ) + }) + public void _test_getExtensionValueLjava_lang_String() { + if (pemCert != null) { + Vector<String> extensionOids = new Vector<String>(); + extensionOids.addAll(pemCert.getCriticalExtensionOIDs()); + extensionOids.addAll(pemCert.getNonCriticalExtensionOIDs()); + Iterator i = extensionOids.iterator(); + while (i.hasNext()) { + String oid = (String) i.next(); + byte[] value = pemCert.getExtensionValue(oid); + if (value != null && value.length > 0) { + // check that it is an encoded as a OCTET STRING + assertTrue("The extension value for the oid " + oid + + " was not encoded as an OCTET STRING", + value[0] == 0x04); + } + }// end while + } else { + fail("Unable to obtain X509Certificate"); + } + } +} diff --git a/security/src/test/java/tests/security/cert/X509CRLEntryTest.java b/security/src/test/java/tests/security/cert/X509CRLEntryTest.java new file mode 100644 index 0000000..61f85c1 --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CRLEntryTest.java @@ -0,0 +1,236 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.math.BigInteger; +import java.security.cert.CRLException; +import java.security.cert.X509CRLEntry; +import java.util.Date; +import java.util.Set; + +/** + */ +@TestTargetClass(X509CRLEntry.class) +public class X509CRLEntryTest extends TestCase { + + X509CRLEntry tbt_crlentry; + + /** + * The stub class used for testing of non abstract methods. + */ + private class TBTCRLEntry extends X509CRLEntry { + public TBTCRLEntry() { + super(); + } + + public Set<String> getNonCriticalExtensionOIDs() { + return null; + } + + public Set<String> getCriticalExtensionOIDs() { + return null; + } + + public byte[] getExtensionValue(String oid) { + return null; + } + + public boolean hasUnsupportedCriticalExtension() { + return false; + } + + public byte[] getEncoded() throws CRLException { + return null; + } + + public BigInteger getSerialNumber() { + return null; + } + + public Date getRevocationDate() { + return null; + } + + public boolean hasExtensions() { + return false; + } + + public String toString() { + return null; + } + } + + public X509CRLEntryTest() { + tbt_crlentry = new TBTCRLEntry() { + public byte[] getEncoded() throws CRLException { + return new byte[] {1, 2, 3}; + } + }; + } + + /** + * X509CRLEntry() method testing. Tests for creating object. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "X509CRLEntry", + methodArgs = {} + ) + }) + public void testX509CRLEntry() { + TBTCRLEntry tbt_crlentry = new TBTCRLEntry(); + + assertNull(tbt_crlentry.getCertificateIssuer()); + assertNull(tbt_crlentry.getCriticalExtensionOIDs()); + try { + assertNull(tbt_crlentry.getEncoded()); + } catch (CRLException e) { + fail("Unexpected exception " + e.getMessage()); + } + assertNull(tbt_crlentry.getNonCriticalExtensionOIDs()); + assertNull(tbt_crlentry.getRevocationDate()); + + } + + /** + * equals(Object other) method testing. Tests the correctness of equal + * operation: it should be reflexive, symmetric, transitive, consistent + * and should be false on null object. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public void testEquals() { + TBTCRLEntry tbt_crlentry_1 = new TBTCRLEntry() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + + TBTCRLEntry tbt_crlentry_2 = new TBTCRLEntry() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + + TBTCRLEntry tbt_crlentry_3 = new TBTCRLEntry() { + public byte[] getEncoded() { + return new byte[] {3, 2, 1}; + } + }; + + // checking for reflexive law: + assertTrue("The equivalence relation should be reflexive.", + tbt_crlentry.equals(tbt_crlentry)); + + assertEquals("The CRL Entries with equals encoded form should be equal", + tbt_crlentry, tbt_crlentry_1); + // checking for symmetric law: + assertTrue("The equivalence relation should be symmetric.", + tbt_crlentry_1.equals(tbt_crlentry)); + + assertEquals("The CRL Entries with equals encoded form should be equal", + tbt_crlentry_1, tbt_crlentry_2); + // checking for transitive law: + assertTrue("The equivalence relation should be transitive.", + tbt_crlentry.equals(tbt_crlentry_2)); + + assertFalse("Should not be equal to null object.", + tbt_crlentry.equals(null)); + + assertFalse("The CRL Entries with differing encoded form " + + "should not be equal.", + tbt_crlentry.equals(tbt_crlentry_3)); + assertFalse("The CRL Entries should not be equals to the object " + + "which is not an instance of X509CRLEntry.", + tbt_crlentry.equals(new Object())); + } + + /** + * hashCode() method testing. Tests that for equal objects hash codes + * are equal. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public void testHashCode() { + TBTCRLEntry tbt_crlentry_1 = new TBTCRLEntry() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + assertTrue("Equal objects should have the same hash codes.", + tbt_crlentry.hashCode() == tbt_crlentry_1.hashCode()); + } + + /** + * getCertificateIssuer() method testing. Tests if the method throws + * appropriate exception. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificateIssuer", + methodArgs = {} + ) + }) + public void testGetCertificateIssuer() { + assertNull("The default implementation should return null.", + tbt_crlentry.getCertificateIssuer()); + } + + public static Test suite() { + return new TestSuite(X509CRLEntryTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/security/src/test/java/tests/security/cert/X509CRLSelector2Test.java b/security/src/test/java/tests/security/cert/X509CRLSelector2Test.java new file mode 100644 index 0000000..1e4da4f --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CRLSelector2Test.java @@ -0,0 +1,805 @@ +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CRL; +import java.security.cert.CRLException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509CRL; +import java.security.cert.X509CRLEntry; +import java.security.cert.X509CRLSelector; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Set; + +import org.apache.harmony.security.tests.support.cert.TestUtils; +import org.apache.harmony.security.asn1.ASN1Integer; +import org.apache.harmony.security.asn1.ASN1OctetString; + +import javax.security.auth.x500.X500Principal; +@TestTargetClass(X509CRLSelector.class) +public class X509CRLSelector2Test extends TestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * constructor testing. + * + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "X509CRLSelector", + methodArgs = {} + ) + }) + public void testX509CRLSelector() { + X509CRLSelector selector = new X509CRLSelector(); + assertNull(selector.getDateAndTime()); + assertNull(selector.getCertificateChecking()); + assertNull(selector.getIssuerNames()); + assertNull(selector.getIssuers()); + assertNull(selector.getMaxCRL()); + assertNull(selector.getMinCRL()); + } + + /** + * addIssuer(X500Principal issuer) method testing. Tests if CRLs with + * specified issuers match the selector, and if not specified issuer does + * not match the selector. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addIssuer", + methodArgs = {javax.security.auth.x500.X500Principal.class} + ) + }) + public void testAddIssuerLjavax_security_auth_x500_X500Principal02() { + X509CRLSelector selector = new X509CRLSelector(); + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + CRL crl1 = new TestCRL(iss1); + CRL crl2 = new TestCRL(iss2); + + selector.addIssuer(iss1); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl1)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl2)); + selector.addIssuer(iss2); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl2)); + } + + /** + * addIssuerName(String name) method testing. Tests if CRLs with specified + * issuers match the selector, and if not specified issuer does not match + * the selector. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify IOException.", + targets = { + @TestTarget( + methodName = "addIssuerName", + methodArgs = {java.lang.String.class} + ) + }) + public void testAddIssuerNameLjava_lang_String03() { + X509CRLSelector selector = new X509CRLSelector(); + String iss1 = "O=First Org."; + String iss2 = "O=Second Org."; + TestCRL crl1 = new TestCRL(new X500Principal(iss1)); + TestCRL crl2 = new TestCRL(new X500Principal(iss2)); + + try { + selector.addIssuerName(iss1); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + assertTrue("The CRL should match the selection criteria.", selector + .match(crl1)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl2)); + try { + selector.addIssuerName(iss2); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + assertTrue("The CRL should match the selection criteria.", selector + .match(crl2)); + } + + /** + * setIssuerNames(Collection <?> names) method testing. Tests if CRLs with + * any issuers match the selector in the case of null issuerNames criteria, + * if specified issuers match the selector, if not specified issuer does not + * match the selector, and if the internal collection of issuer names is + * copied during initialization. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setIssuerNames", + methodArgs = {java.util.Collection.class} + ) + }) + @SuppressWarnings("unchecked") + public void testSetIssuerNamesLjava_util_Collection02() { + X509CRLSelector selector = new X509CRLSelector(); + String iss1 = "O=First Org."; + byte[] iss2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + + String iss3 = "O=Third Org."; + TestCRL crl1 = new TestCRL(new X500Principal(iss1)); + TestCRL crl2 = new TestCRL(new X500Principal(iss2)); + TestCRL crl3 = new TestCRL(new X500Principal(iss3)); + + try { + selector.setIssuerNames(null); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + assertTrue("Any CRL issuers should match in the case of null issuers.", + selector.match(crl1) && selector.match(crl2)); + + ArrayList issuers = new ArrayList(2); + issuers.add(iss1); + issuers.add(iss2); + try { + selector.setIssuerNames(issuers); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + assertTrue("The CRL should match the selection criteria.", selector + .match(crl1) + && selector.match(crl2)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl3)); + issuers.add(iss3); + assertFalse("The internal issuer collection is not protected " + + "against the modifications.", selector.match(crl3)); + } + + /** + * setIssuers(Collection <X500Principal> issuers) method testing. Tests if + * CRLs with any issuers match the selector in the case of null issuerNames + * criteria, if specified issuers match the selector, and if not specified + * issuer does not match the selector. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setIssuers", + methodArgs = {java.util.Collection.class} + ) + }) + public void testSetIssuersLjava_util_Collection() { + X509CRLSelector selector = new X509CRLSelector(); + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + X500Principal iss3 = new X500Principal("O=Third Org."); + TestCRL crl1 = new TestCRL(iss1); + TestCRL crl2 = new TestCRL(iss2); + TestCRL crl3 = new TestCRL(iss3); + + selector.setIssuers(null); + assertTrue("Any CRL issuers should match in the case of null issuers.", + selector.match(crl1) && selector.match(crl2)); + + ArrayList<X500Principal> issuers = new ArrayList<X500Principal>(2); + issuers.add(iss1); + issuers.add(iss2); + selector.setIssuers(issuers); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl1) + && selector.match(crl2)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl3)); + issuers.add(iss3); + assertFalse("The internal issuer collection is not protected " + + "against the modifications.", selector.match(crl3)); + } + + /** + * addIssuerName(byte[] name) method testing. Tests if CRLs with specified + * issuers match the selector, and if not specified issuer does not match + * the selector. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify IOException.", + targets = { + @TestTarget( + methodName = "addIssuerName", + methodArgs = {byte[].class} + ) + }) + public void testAddIssuerName$B() { + X509CRLSelector selector = new X509CRLSelector(); + byte[] iss1 = new byte[] + // manually obtained DER encoding of "O=First Org." issuer name; + { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, + 116, 32, 79, 114, 103, 46 }; + byte[] iss2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + TestCRL crl1 = new TestCRL(new X500Principal(iss1)); + TestCRL crl2 = new TestCRL(new X500Principal(iss2)); + + try { + selector.addIssuerName(iss1); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + assertTrue("The CRL should match the selection criteria.", selector + .match(crl1)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl2)); + try { + selector.addIssuerName(iss2); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + assertTrue("The CRL should match the selection criteria.", selector + .match(crl2)); + } + + /** + * setMinCRLNumber(BigInteger minCRL) method testing. Tests if CRLs with any + * crl number value match the selector in the case of null crlNumber + * criteria, if specified minCRL value matches the selector, and if CRL with + * inappropriate crlNumber value does not match the selector. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setMinCRLNumber", + methodArgs = {java.math.BigInteger.class} + ) + }) + public void testSetMinCRLNumberLjava_math_BigInteger() { + X509CRLSelector selector = new X509CRLSelector(); + BigInteger minCRL = new BigInteger("10000"); + CRL crl = new TestCRL(minCRL); + + selector.setMinCRLNumber(null); + assertTrue("Any CRL should match in the case of null minCRLNumber.", + selector.match(crl)); + selector.setMinCRLNumber(minCRL); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + selector.setMinCRLNumber(new BigInteger("10001")); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl)); + } + + /** + * setMaxCRLNumber(BigInteger maxCRL) method testing. Tests if CRLs with any + * crl number value match the selector in the case of null crlNumber + * criteria, if specified maxCRL value matches the selector, and if CRL with + * inappropriate crlNumber value does not match the selector. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setMaxCRLNumber", + methodArgs = {java.math.BigInteger.class} + ) + }) + public void testSetMaxCRLNumberLjava_math_BigInteger() { + X509CRLSelector selector = new X509CRLSelector(); + BigInteger maxCRL = new BigInteger("10000"); + TestCRL crl = new TestCRL(maxCRL); + + selector.setMaxCRLNumber(null); + assertTrue("Any CRL should match in the case of null minCRLNumber.", + selector.match(crl)); + selector.setMaxCRLNumber(maxCRL); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + selector.setMaxCRLNumber(new BigInteger("9999")); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl)); + } + + /** + * setDateAndTime(Date dateAndTime) method testing. Tests if CRLs with any + * update dates match the selector in the case of null dateAndTime criteria, + * if correct dates match and incorrect do not match the selector. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setDateAndTime", + methodArgs = {java.util.Date.class} + ) + }) + public void testSetDateAndTimeLjava_util_Date() { + X509CRLSelector selector = new X509CRLSelector(); + TestCRL crl = new TestCRL(new Date(200), new Date(300)); + selector.setDateAndTime(null); + assertTrue("Any CRL should match in the case of null dateAndTime.", + selector.match(crl)); + selector.setDateAndTime(new Date(200)); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + selector.setDateAndTime(new Date(250)); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + selector.setDateAndTime(new Date(300)); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + selector.setDateAndTime(new Date(150)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl)); + selector.setDateAndTime(new Date(350)); + assertFalse("The CRL should not match the selection criteria.", + selector.match(crl)); + } + + /** + * setCertificateChecking(X509Certificate) method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setCertificateChecking", + methodArgs = {java.security.cert.X509Certificate.class} + ) + }) + public void testSetCertificateCheckingLjava_X509Certificate() + throws CertificateException { + X509CRLSelector selector = new X509CRLSelector(); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate cert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + TestCRL crl = new TestCRL(); + selector.setCertificateChecking(cert); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + assertEquals(cert, selector.getCertificateChecking()); + + selector.setCertificateChecking(null); + assertTrue("The CRL should match the selection criteria.", selector + .match(crl)); + assertNull(selector.getCertificateChecking()); + } + + /** + * getIssuers() method testing. Tests if the method return null in the case + * of not specified issuers, if the returned collection corresponds to the + * specified issuers and this collection is unmodifiable. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuers", + methodArgs = {} + ) + }) + public void testGetIssuers() { + X509CRLSelector selector = new X509CRLSelector(); + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + X500Principal iss3 = new X500Principal("O=Third Org."); + assertNull("The collection should be null.", selector.getIssuers()); + selector.addIssuer(iss1); + selector.addIssuer(iss2); + Collection<X500Principal> result = selector.getIssuers(); + try { + result.add(iss3); + fail("The returned collection should be unmodifiable."); + } catch (UnsupportedOperationException e) { + } + assertTrue("The collection should contain the specified DN.", result + .contains(iss2)); + } + + /** + * getIssuerNames() method testing. Tests if the method return null in the + * case of not specified issuers, if the returned collection corresponds to + * the specified issuers. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuerNames", + methodArgs = {} + ) + }) + public void testGetIssuerNames() { + X509CRLSelector selector = new X509CRLSelector(); + byte[] iss1 = new byte[] + // manually obtained DER encoding of "O=First Org." issuer name; + { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, + 116, 32, 79, 114, 103, 46 }; + byte[] iss2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + assertNull("The collection should be null.", selector.getIssuerNames()); + try { + selector.addIssuerName(iss1); + selector.addIssuerName(iss2); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + Collection<Object> result = selector.getIssuerNames(); + assertEquals("The collection should contain all of the specified DNs.", + 2, result.size()); + } + + /** + * getMinCRL() method testing. Tests if the method return null in the case + * of not specified minCRL criteria, and if the returned value corresponds + * to the specified one. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMinCRL", + methodArgs = {} + ) + }) + public void testGetMinCRL() { + X509CRLSelector selector = new X509CRLSelector(); + assertNull("Initially the minCRL should be null.", selector.getMinCRL()); + BigInteger minCRL = new BigInteger("10000"); + selector.setMinCRLNumber(minCRL); + assertTrue("The result should be equal to specified.", minCRL + .equals(selector.getMinCRL())); + } + + /** + * getMaxCRL() method testing. Tests if the method return null in the case + * of not specified maxCRL criteria, and if the returned value corresponds + * to the specified one. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMaxCRL", + methodArgs = {} + ) + }) + public void testGetMaxCRL() { + X509CRLSelector selector = new X509CRLSelector(); + assertNull("Initially the maxCRL should be null.", selector.getMaxCRL()); + BigInteger maxCRL = new BigInteger("10000"); + selector.setMaxCRLNumber(maxCRL); + assertTrue("The result should be equal to specified.", maxCRL + .equals(selector.getMaxCRL())); + } + + /** + * getDateAndTime() method testing. Tests if the method return null in the + * case of not specified dateAndTime criteria, and if the returned value + * corresponds to the specified one. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDateAndTime", + methodArgs = {} + ) + }) + public void testGetDateAndTime() { + X509CRLSelector selector = new X509CRLSelector(); + assertNull("Initially the dateAndTime criteria should be null.", + selector.getDateAndTime()); + Date date = new Date(200); + selector.setDateAndTime(date); + assertTrue("The result should be equal to specified.", date + .equals(selector.getDateAndTime())); + } + + /** + * getCertificateChecking() method testing. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificateChecking", + methodArgs = {} + ) + }) + public void testGetCertificateCheckingLjava_X509Certificate() + throws CertificateException { + X509CRLSelector selector = new X509CRLSelector(); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate cert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + selector.setCertificateChecking(cert); + assertEquals(cert, selector.getCertificateChecking()); + + selector.setCertificateChecking(null); + assertNull(selector.getCertificateChecking()); + } + + /** + * match(CRL crl) method testing. Tests if the null object matches to the + * selector or not. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify not null value as parameter.", + targets = { + @TestTarget( + methodName = "match", + methodArgs = {java.security.cert.CRL.class} + ) + }) + public void testMatchLjava_security_cert_X509CRL() { + X509CRLSelector selector = new X509CRLSelector(); + assertFalse("The null object should not match", selector + .match((X509CRL) null)); + } + + /** + * clone() method testing. Tests if the selector is cloned correctly: the + * crl which matche to the initial selector should match to the clone and + * the change of clone should not cause the change of initial selector. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public void testClone() { + X509CRLSelector selector = new X509CRLSelector(); + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + X500Principal iss3 = new X500Principal("O=Third Org."); + BigInteger minCRL = new BigInteger("10000"); + BigInteger maxCRL = new BigInteger("10000"); + Date date = new Date(200); + + selector.addIssuer(iss1); + selector.addIssuer(iss2); + selector.setMinCRLNumber(minCRL); + selector.setMaxCRLNumber(maxCRL); + selector.setDateAndTime(date); + + X509CRLSelector clone = (X509CRLSelector) selector.clone(); + TestCRL crl = new TestCRL(iss1); + crl.setCrlNumber(minCRL); + crl.setUpdateDates(new Date(200), new Date(200)); + assertTrue("The specified CRL should match the clone selector.", + selector.match(crl)); + + clone.addIssuer(iss3); + assertFalse("The changes of the clone selector should not cause " + + "the changes of initial object", selector.getIssuerNames() + .size() == 3); + } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public void testToString() { + X509CRLSelector selector = new X509CRLSelector(); + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + BigInteger minCRL = new BigInteger("10000"); + BigInteger maxCRL = new BigInteger("10000"); + Date date = new Date(200); + + selector.addIssuer(iss1); + selector.addIssuer(iss2); + selector.setMinCRLNumber(minCRL); + selector.setMaxCRLNumber(maxCRL); + selector.setDateAndTime(date); + + assertNotNull("The result should not be null.", selector.toString()); + } + + /** + * The abstract class stub implementation. + */ + private class TestCRL extends X509CRL { + + private X500Principal principal = null; + + private BigInteger crlNumber = null; + + private Date thisUpdate = null; + + private Date nextUpdate = null; + + public TestCRL() { + } + + public TestCRL(X500Principal principal) { + this.principal = principal; + } + + public TestCRL(Date thisUpdate, Date nextUpdate) { + setUpdateDates(thisUpdate, nextUpdate); + } + + public TestCRL(BigInteger crlNumber) { + setCrlNumber(crlNumber); + } + + public void setUpdateDates(Date thisUpdate, Date nextUpdate) { + this.thisUpdate = thisUpdate; + this.nextUpdate = nextUpdate; + } + + public void setCrlNumber(BigInteger crlNumber) { + this.crlNumber = crlNumber; + } + + public X500Principal getIssuerX500Principal() { + return principal; + } + + public String toString() { + return null; + } + + public boolean isRevoked(Certificate cert) { + return true; + } + + public Set<String> getNonCriticalExtensionOIDs() { + return null; + } + + public Set<String> getCriticalExtensionOIDs() { + return null; + } + + public byte[] getExtensionValue(String oid) { + if ("2.5.29.20".equals(oid) && (crlNumber != null)) { + return ASN1OctetString.getInstance().encode( + ASN1Integer.getInstance().encode( + crlNumber.toByteArray())); + } + return null; + } + + public boolean hasUnsupportedCriticalExtension() { + return false; + } + + public byte[] getEncoded() { + return null; + } + + public void verify(PublicKey key) throws CRLException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + public void verify(PublicKey key, String sigProvider) + throws CRLException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + + public int getVersion() { + return 2; + } + + public Principal getIssuerDN() { + return null; + } + + public Date getThisUpdate() { + return thisUpdate; + } + + public Date getNextUpdate() { + return nextUpdate; + } + + public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) { + return null; + } + + public Set<X509CRLEntry> getRevokedCertificates() { + return null; + } + + public byte[] getTBSCertList() { + return null; + } + + public byte[] getSignature() { + return null; + } + + public String getSigAlgName() { + return null; + } + + public String getSigAlgOID() { + return null; + } + + public byte[] getSigAlgParams() { + return null; + } + } +} diff --git a/security/src/test/java/tests/security/cert/X509CRLSelectorTest.java b/security/src/test/java/tests/security/cert/X509CRLSelectorTest.java new file mode 100644 index 0000000..f2f6d3c --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CRLSelectorTest.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.security.cert.X509CRLSelector; +import java.util.Iterator; +import java.util.TreeSet; + +import javax.security.auth.x500.X500Principal; + +@TestTargetClass(X509CRLSelector.class) +public class X509CRLSelectorTest extends TestCase { + + /** + * @tests java.security.cert.X509CRLSelector#addIssuer(javax.security.auth.x500.X500Principal) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addIssuer", + methodArgs = {X500Principal.class} + ) + }) + public void test_addIssuerLjavax_security_auth_x500_X500Principal01() + throws Exception { + //Regression for HARMONY-465 + X509CRLSelector obj = new X509CRLSelector(); + try { + obj.addIssuer((X500Principal) null); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * @tests java.security.cert.X509CRLSelector#addIssuerName(java.lang.String) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "addIssuerName", + methodArgs = {java.lang.String.class} + ) + }) + public void test_addIssuerNameLjava_lang_String01() throws Exception { + //Regression for HARMONY-465 + X509CRLSelector obj = new X509CRLSelector(); + try { + obj.addIssuerName("234"); + fail("IOException expected"); + } catch (IOException e) { + // expected + } + + // Regression for HARMONY-1076 + try { + new X509CRLSelector().addIssuerName("w=y"); + fail("IOException expected"); + } catch (IOException e) { + // expected + } + } + + /** + * @tests java.security.cert.X509CRLSelector#addIssuerName(java.lang.String) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "addIssuerName", + methodArgs = {java.lang.String.class} + ) + }) + public void test_addIssuerNameLjava_lang_String02() throws IOException { + // Regression for HARMONY-736 + X509CRLSelector selector = new X509CRLSelector(); + + // no exception for null + selector.addIssuerName((String) null); + } + + + /** + * @tests java.security.cert.X509CRLSelector#addIssuerName(byte[]) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "addIssuerName", + methodArgs = {byte[].class} + ) + }) + public void test_addIssuerName$B_3() throws Exception { + //Regression for HARMONY-465 + X509CRLSelector obj = new X509CRLSelector(); + try { + obj.addIssuerName(new byte[] { (byte) 2, (byte) 3, (byte) 4 }); + fail("IOException expected"); + } catch (IOException e) { + // expected + } + } + + /** + * @tests java.security.cert.X509CRLSelector#addIssuerName(byte[]) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "addIssuerName", + methodArgs = {byte[].class} + ) + }) + public void test_addIssuerName$B_4() throws Exception { + //Regression for HARMONY-465 + X509CRLSelector obj = new X509CRLSelector(); + try { + obj.addIssuerName((byte[]) null); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * @tests setIssuerNames(Collection <?> names) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "setIssuerNames", + methodArgs = {java.util.Collection.class} + ) + }) + public void test_setIssuerNamesLjava_util_Collection01() throws IOException { + // Regression for HARMONY-737 + X509CRLSelector selector = new X509CRLSelector(); + selector.setIssuerNames(new TreeSet<Comparable>() { + private static final long serialVersionUID = 6009545505321092498L; + + public Iterator<Comparable> iterator() { + return null; + } + }); + } +} diff --git a/security/src/test/java/tests/security/cert/X509CRLTest.java b/security/src/test/java/tests/security/cert/X509CRLTest.java new file mode 100644 index 0000000..1724cbe --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CRLTest.java @@ -0,0 +1,312 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Alexander Y. Kleymenov +* @version $Revision$ +*/ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CRLException; +import java.security.cert.Certificate; +import java.security.cert.X509CRL; +import java.security.cert.X509CRLEntry; +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.Set; + +import javax.security.auth.x500.X500Principal; + +import org.apache.harmony.security.tests.support.cert.TestUtils; +/** + */ +@TestTargetClass(X509CRL.class) +public class X509CRLTest extends TestCase { + + private X509CRL tbt_crl; + + /** + * The stub class used for testing of non abstract methods. + */ + private class TBTCRL extends X509CRL { + public String toString() { + return null; + } + + public boolean isRevoked(Certificate cert) { + return true; + } + + public Set<String> getNonCriticalExtensionOIDs() { + return null; + } + + public Set<String> getCriticalExtensionOIDs() { + return null; + } + + public byte[] getExtensionValue(String oid) { + return null; + } + + public boolean hasUnsupportedCriticalExtension() { + return false; + } + + public byte[] getEncoded() { + return null; + } + + public void verify(PublicKey key) + throws CRLException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException + { + } + + public void verify(PublicKey key, String sigProvider) + throws CRLException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException + { + } + + public int getVersion() { + return 2; + } + + public Principal getIssuerDN() { + return null; + } + + public Date getThisUpdate() { + return null; + } + + public Date getNextUpdate() { + return null; + } + + public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) { + return null; + } + + public Set<X509CRLEntry> getRevokedCertificates() { + return null; + } + + public byte[] getTBSCertList() { + return null; + } + + public byte[] getSignature() { + return null; + } + + public String getSigAlgName() { + return null; + } + + public String getSigAlgOID() { + return null; + } + + public byte[] getSigAlgParams() { + return null; + } + } + + + public X509CRLTest() { + tbt_crl = new TBTCRL() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + } + + /** + * getType() method testing. Tests that getType() method returns + * the value "X.509" + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public void testGetType() { + assertEquals("The type of X509CRL should be X.509", + tbt_crl.getType(), "X.509"); + } + + /** + * equals(Object other) method testing. Tests the correctness of equal + * operation: it should be reflexive, symmetric, transitive, consistent + * and should be false on null object. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public void testEquals() { + TBTCRL tbt_crl_1 = new TBTCRL() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + + TBTCRL tbt_crl_2 = new TBTCRL() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + + TBTCRL tbt_crl_3 = new TBTCRL() { + public byte[] getEncoded() { + return new byte[] {3, 2, 1}; + } + }; + + // checking for reflexive law: + assertTrue("The equivalence relation should be reflexive.", + tbt_crl.equals(tbt_crl)); + + assertEquals("The CRLs with equal encoded form should be equal", + tbt_crl, tbt_crl_1); + // checking for symmetric law: + assertTrue("The equivalence relation should be symmetric.", + tbt_crl_1.equals(tbt_crl)); + + assertEquals("The CRLs with equal encoded form should be equal", + tbt_crl_1, tbt_crl_2); + // checking for transitive law: + assertTrue("The equivalence relation should be transitive.", + tbt_crl.equals(tbt_crl_2)); + + assertFalse("Should not be equal to null object.", + tbt_crl.equals(null)); + + assertFalse("The CRLs with differing encoded form should not be equal", + tbt_crl.equals(tbt_crl_3)); + assertFalse("The CRL should not be equals to the object which is not " + + "an instance of X509CRL", tbt_crl.equals(new Object())); + } + + /** + * hashCode() method testing. Tests that for equal objects hash codes + * are equal. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public void testHashCode() { + TBTCRL tbt_crl_1 = new TBTCRL() { + public byte[] getEncoded() { + return new byte[] {1, 2, 3}; + } + }; + assertTrue("Equal objects should have the same hash codes.", + tbt_crl.hashCode() == tbt_crl_1.hashCode()); + } + + /** + * @tests java.security.cert.X509CRL#getIssuerX500Principal() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuerX500Principal", + methodArgs = {} + ) + }) + public void testGetIssuerX500Principal() { + // return valid encoding + TBTCRL crl = new TBTCRL() { + public byte[] getEncoded() { + return TestUtils.getX509CRL_v1(); + }; + }; + + assertEquals(new X500Principal("CN=Z"), crl.getIssuerX500Principal()); + } + + /** + * getRevokedCertificate(X509Certificate certificate) method testing. + * Check if the default implementation throws NullPointerException + * on null input data. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getRevokedCertificate", + methodArgs = {java.security.cert.X509Certificate.class} + ) + }) + public void testGetRevokedCertificate() { + try { + tbt_crl.getRevokedCertificate((X509Certificate) null); + fail("NullPointerException should be thrown " + + "in the case of null input data."); + } catch (NullPointerException e) { + } + } + + public static Test suite() { + return new TestSuite(X509CRLTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} + diff --git a/security/src/test/java/tests/security/cert/X509CertSelectorTest.java b/security/src/test/java/tests/security/cert/X509CertSelectorTest.java new file mode 100644 index 0000000..47ea3e9 --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509CertSelectorTest.java @@ -0,0 +1,2471 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.CertificateParsingException; +import java.security.cert.X509CertSelector; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.security.auth.x500.X500Principal; + + +import org.apache.harmony.security.tests.support.cert.TestUtils; +import org.apache.harmony.security.tests.support.TestKeyPair; +import org.apache.harmony.security.asn1.ASN1Boolean; +import org.apache.harmony.security.asn1.ASN1Integer; +import org.apache.harmony.security.asn1.ASN1OctetString; +import org.apache.harmony.security.asn1.ASN1Oid; +import org.apache.harmony.security.asn1.ASN1Sequence; +import org.apache.harmony.security.asn1.ASN1Type; +import org.apache.harmony.security.x501.Name; +import org.apache.harmony.security.x509.CertificatePolicies; +import org.apache.harmony.security.x509.GeneralName; +import org.apache.harmony.security.x509.GeneralNames; +import org.apache.harmony.security.x509.GeneralSubtree; +import org.apache.harmony.security.x509.GeneralSubtrees; +import org.apache.harmony.security.x509.NameConstraints; +import org.apache.harmony.security.x509.ORAddress; +import org.apache.harmony.security.x509.OtherName; +import org.apache.harmony.security.x509.PolicyInformation; +import org.apache.harmony.security.x509.PrivateKeyUsagePeriod; + +/** + * X509CertSelectorTest + */ +@TestTargetClass(X509CertSelector.class) +public class X509CertSelectorTest extends TestCase { + + /** + * @tests java.security.cert.X509CertSelector#addSubjectAlternativeName(int, byte[]) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "addPathToName", + methodArgs = {int.class, byte[].class} + ) + }) + public void test_addSubjectAlternativeNameLintLbyte_array() throws IOException { + // Regression for HARMONY-2487 + int[] types = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + for (int i = 0; i < types.length; i++) { + try { + new X509CertSelector().addSubjectAlternativeName(types[i], + (byte[]) null); + fail("No expected NullPointerException for type: " + i); + } catch (NullPointerException e) { + } + } + } + + /** + * @tests java.security.cert.X509CertSelector#addSubjectAlternativeName(int, String) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "addSubjectAlternativeName", + methodArgs = {int.class, java.lang.String.class} + ) + }) + public void test_addSubjectAlternativeNameLintLjava_lang_String() { + // Regression for HARMONY-727 + int[] types = { 0, 2, 3, 4, 5, 6, 7, 8 }; + for (int i = 0; i < types.length; i++) { + try { + new X509CertSelector().addSubjectAlternativeName(types[i], + "0xDFRF"); + fail("IOException expected"); + } catch (IOException e) { + } + } + } + + /** + * @tests java.security.cert.X509CertSelector#addPathToName(int, byte[]) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "addPathToName", + methodArgs = {int.class, byte[].class} + ) + }) + public void test_addPathToNameLintLbyte_array() throws IOException { + // Regression for HARMONY-2487 + int[] types = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + for (int i = 0; i < types.length; i++) { + try { + new X509CertSelector().addPathToName(types[i], (byte[]) null); + fail("No expected NullPointerException for type: " + i); + } catch (NullPointerException e) { + } + } + } + + /** + * @tests java.security.cert.X509CertSelector#addPathToName(int, String) + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "addPathToName", + methodArgs = {int.class, java.lang.String.class} + ) + }) + public void test_addPathToNameLintLjava_lang_String() { + // Regression for HARMONY-724 + for (int type = 0; type <= 8; type++) { + try { + new X509CertSelector().addPathToName(type, (String) null); + fail("IOException expected!"); + } catch (IOException ioe) { + // expected + } + } + } + + /** + * @tests java.security.cert.X509CertSelector#X509CertSelector() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "X509CertSelector", + methodArgs = {} + ) + }) + public void test_X509CertSelector() { + X509CertSelector selector = null; + try { + selector = new X509CertSelector(); + } catch (Exception e) { + fail("Unexpected exception " + e.getMessage()); + } + assertEquals(-1, selector.getBasicConstraints()); + assertTrue(selector.getMatchAllSubjectAltNames()); + } + + /** + * @tests java.security.cert.X509CertSelector#clone() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "clone", + methodArgs = {} + ) + }) + public void test_clone() throws Exception { + X509CertSelector selector = new X509CertSelector(); + X509CertSelector selector1 = (X509CertSelector) selector.clone(); + + assertEquals(selector.getMatchAllSubjectAltNames(), selector1 + .getMatchAllSubjectAltNames()); + assertEquals(selector.getAuthorityKeyIdentifier(), selector1 + .getAuthorityKeyIdentifier()); + assertEquals(selector.getBasicConstraints(), selector1 + .getBasicConstraints()); + assertEquals(selector.getCertificate(), selector1.getCertificate()); + assertEquals(selector.getCertificateValid(), selector1 + .getCertificateValid()); + assertEquals(selector.getExtendedKeyUsage(), selector1 + .getExtendedKeyUsage()); + assertEquals(selector.getIssuer(), selector1.getIssuer()); + assertEquals(selector.getIssuerAsBytes(), selector1.getIssuerAsBytes()); + assertEquals(selector.getIssuerAsString(), selector1 + .getIssuerAsString()); + assertEquals(selector.getKeyUsage(), selector1.getKeyUsage()); + assertEquals(selector.getNameConstraints(), selector1 + .getNameConstraints()); + assertEquals(selector.getPathToNames(), selector1.getPathToNames()); + assertEquals(selector.getPolicy(), selector1.getPolicy()); + assertEquals(selector.getPrivateKeyValid(), selector1 + .getPrivateKeyValid()); + assertEquals(selector.getSerialNumber(), selector1.getSerialNumber()); + assertEquals(selector.getSubject(), selector1.getSubject()); + assertEquals(selector.getSubjectAlternativeNames(), selector1 + .getSubjectAlternativeNames()); + assertEquals(selector.getSubjectAsBytes(), selector1 + .getSubjectAsBytes()); + assertEquals(selector.getSubjectAsString(), selector1 + .getSubjectAsString()); + assertEquals(selector.getSubjectKeyIdentifier(), selector1 + .getSubjectKeyIdentifier()); + assertEquals(selector.getSubjectPublicKey(), selector1 + .getSubjectPublicKey()); + assertEquals(selector.getSubjectPublicKeyAlgID(), selector1 + .getSubjectPublicKeyAlgID()); + + selector = null; + try { + selector.clone(); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * @tests java.security.cert.X509CertSelector#getAuthorityKeyIdentifier() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAuthorityKeyIdentifier", + methodArgs = {} + ) + }) + public void test_getAuthorityKeyIdentifier() { + byte[] akid1 = new byte[] { 4, 5, 1, 2, 3, 4, 5 }; // random value + byte[] akid2 = new byte[] { 4, 5, 5, 4, 3, 2, 1 }; // random value + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector + .getAuthorityKeyIdentifier()); + selector.setAuthorityKeyIdentifier(akid1); + assertTrue("The returned keyID should be equal to specified", Arrays + .equals(akid1, selector.getAuthorityKeyIdentifier())); + assertTrue("The returned keyID should be equal to specified", Arrays + .equals(akid1, selector.getAuthorityKeyIdentifier())); + assertFalse("The returned keyID should differ", Arrays.equals(akid2, + selector.getAuthorityKeyIdentifier())); + } + + /** + * @tests java.security.cert.X509CertSelector#getBasicConstraints() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getBasicConstraints", + methodArgs = {} + ) + }) + public void test_getBasicConstraints() { + X509CertSelector selector = new X509CertSelector(); + int[] validValues = { 2, 1, 0, 1, 2, 3, 10, 20 }; + for (int i = 0; i < validValues.length; i++) { + selector.setBasicConstraints(validValues[i]); + assertEquals(validValues[i], selector.getBasicConstraints()); + } + } + + /** + * @tests java.security.cert.X509CertSelector#getCertificate() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificate", + methodArgs = {} + ) + }) + public void test_getCertificate() throws CertificateException { + X509CertSelector selector = new X509CertSelector(); + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate cert1 = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + X509Certificate cert2 = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v1())); + + selector.setCertificate(cert1); + assertEquals(cert1, selector.getCertificate()); + + selector.setCertificate(cert2); + assertEquals(cert2, selector.getCertificate()); + + selector.setCertificate(null); + assertNull(selector.getCertificate()); + } + + /** + * @tests java.security.cert.X509CertSelector#getCertificateValid() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificateValid", + methodArgs = {} + ) + }) + public void test_getCertificateValid() { + Date date1 = new Date(100); + Date date2 = new Date(200); + Date date3 = Calendar.getInstance().getTime(); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector + .getCertificateValid()); + selector.setCertificateValid(date1); + assertTrue("The returned date should be equal to specified", date1 + .equals(selector.getCertificateValid())); + selector.getCertificateValid().setTime(200); + assertTrue("The returned date should be equal to specified", date1 + .equals(selector.getCertificateValid())); + assertFalse("The returned date should differ", date2.equals(selector + .getCertificateValid())); + selector.setCertificateValid(date3); + assertTrue("The returned date should be equal to specified", date3 + .equals(selector.getCertificateValid())); + selector.setCertificateValid(null); + assertNull(selector.getCertificateValid()); + } + + /** + * @tests java.security.cert.X509CertSelector#getExtendedKeyUsage() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getExtendedKeyUsage", + methodArgs = {} + ) + }) + public void test_getExtendedKeyUsage() { + HashSet<String> ku = new HashSet<String>(Arrays + .asList(new String[] { "1.3.6.1.5.5.7.3.1", + "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", + "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", + "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", + "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" })); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector + .getExtendedKeyUsage()); + try { + selector.setExtendedKeyUsage(ku); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue( + "The returned extendedKeyUsage should be equal to specified", + ku.equals(selector.getExtendedKeyUsage())); + try { + selector.getExtendedKeyUsage().add("KRIBLEGRABLI"); + fail("The returned Set should be immutable."); + } catch (UnsupportedOperationException e) { + // expected + } + } + + /** + * @tests java.security.cert.X509CertSelector#getIssuer() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuer", + methodArgs = {} + ) + }) + public void test_getIssuer() { + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getIssuer()); + selector.setIssuer(iss1); + assertEquals("The returned issuer should be equal to specified", iss1, + selector.getIssuer()); + assertFalse("The returned issuer should differ", iss2.equals(selector + .getIssuer())); + } + + /** + * @tests java.security.cert.X509CertSelector#getIssuerAsBytes() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuerAsBytes", + methodArgs = {} + ) + }) + public void test_getIssuerAsBytes() { + byte[] name1 = new byte[] + // manually obtained DER encoding of "O=First Org." issuer name; + { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, + 116, 32, 79, 114, 103, 46 }; + + byte[] name2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + X500Principal iss1 = new X500Principal(name1); + X500Principal iss2 = new X500Principal(name2); + X509CertSelector selector = new X509CertSelector(); + + try { + assertNull("Selector should return null", selector + .getIssuerAsBytes()); + selector.setIssuer(iss1); + assertTrue("The returned issuer should be equal to specified", + Arrays.equals(name1, selector.getIssuerAsBytes())); + assertFalse("The returned issuer should differ", name2 + .equals(selector.getIssuerAsBytes())); + selector.setIssuer(iss2); + assertTrue("The returned issuer should be equal to specified", + Arrays.equals(name2, selector.getIssuerAsBytes())); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + } + + /** + * @tests java.security.cert.X509CertSelector#getIssuerAsString() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuerAsString", + methodArgs = {} + ) + }) + public void test_getIssuerAsString() { + String name1 = "O=First Org."; + String name2 = "O=Second Org."; + X500Principal iss1 = new X500Principal(name1); + X500Principal iss2 = new X500Principal(name2); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getIssuerAsString()); + selector.setIssuer(iss1); + assertEquals("The returned issuer should be equal to specified", name1, + selector.getIssuerAsString()); + assertFalse("The returned issuer should differ", name2.equals(selector + .getIssuerAsString())); + selector.setIssuer(iss2); + assertEquals("The returned issuer should be equal to specified", name2, + selector.getIssuerAsString()); + } + + /** + * @tests java.security.cert.X509CertSelector#getKeyUsage() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getKeyUsage", + methodArgs = {} + ) + }) + public void test_getKeyUsage() { + boolean[] ku = new boolean[] { true, false, true, false, true, false, + true, false, true }; + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getKeyUsage()); + selector.setKeyUsage(ku); + assertTrue("The returned date should be equal to specified", Arrays + .equals(ku, selector.getKeyUsage())); + boolean[] result = selector.getKeyUsage(); + result[0] = !result[0]; + assertTrue("The returned keyUsage should be equal to specified", Arrays + .equals(ku, selector.getKeyUsage())); + } + + /** + * @tests java.security.cert.X509CertSelector#getMatchAllSubjectAltNames() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getMatchAllSubjectAltNames", + methodArgs = {} + ) + }) + public void test_getMatchAllSubjectAltNames() { + X509CertSelector selector = new X509CertSelector(); + assertTrue("The matchAllNames initially should be true", selector + .getMatchAllSubjectAltNames()); + selector.setMatchAllSubjectAltNames(false); + assertFalse("The value should be false", selector + .getMatchAllSubjectAltNames()); + } + + /** + * @tests java.security.cert.X509CertSelector#getNameConstraints() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getNameConstraints", + methodArgs = {} + ) + }) + public void test_getNameConstraints() throws IOException { + GeneralName[] name_constraints = new GeneralName[] { + new GeneralName(1, "822.Name"), + new GeneralName(1, "rfc@822.Name"), + new GeneralName(2, "Name.org"), + new GeneralName(2, "dNS.Name.org"), + + new GeneralName(6, "http://Resource.Id"), + new GeneralName(6, "http://uniform.Resource.Id"), + new GeneralName(7, "1.1.1.1"), + + new GeneralName(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 }), }; + + X509CertSelector selector = new X509CertSelector(); + + for (int i = 0; i < name_constraints.length; i++) { + GeneralSubtree subtree = new GeneralSubtree(name_constraints[i]); + GeneralSubtrees subtrees = new GeneralSubtrees(); + subtrees.addSubtree(subtree); + NameConstraints constraints = new NameConstraints(subtrees, + subtrees); + selector.setNameConstraints(constraints.getEncoded()); + assertTrue(Arrays.equals(constraints.getEncoded(), selector + .getNameConstraints())); + } + } + + /** + * @tests java.security.cert.X509CertSelector#getPathToNames() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPathToNames", + methodArgs = {} + ) + }) + public void test_getPathToNames() { + try { + GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", + new byte[] { 1, 2, 0, 1 })); + GeneralName san1 = new GeneralName(1, "rfc@822.Name"); + GeneralName san2 = new GeneralName(2, "dNSName"); + GeneralName san3 = new GeneralName(new ORAddress()); + GeneralName san4 = new GeneralName(new Name("O=Organization")); + GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id"); + GeneralName san7 = new GeneralName(7, "1.1.1.1"); + GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555"); + + GeneralNames sans1 = new GeneralNames(); + sans1.addName(san0); + sans1.addName(san1); + sans1.addName(san2); + sans1.addName(san3); + sans1.addName(san4); + sans1.addName(san6); + sans1.addName(san7); + sans1.addName(san8); + GeneralNames sans2 = new GeneralNames(); + sans2.addName(san0); + + TestCert cert1 = new TestCert(sans1); + TestCert cert2 = new TestCert(sans2); + X509CertSelector selector = new X509CertSelector(); + selector.setMatchAllSubjectAltNames(true); + + selector.setPathToNames(null); + assertTrue("Any certificate should match in the case of null " + + "subjectAlternativeNames criteria.", selector + .match(cert1) + && selector.match(cert2)); + + Collection<List<?>> sans = sans1.getPairsList(); + + selector.setPathToNames(sans); + + Collection<List<?>> col = selector.getPathToNames(); + Iterator<List<?>> i = col.iterator(); + while (i.hasNext()) { + Object o = i.next(); + if (!(o instanceof List)) { + fail("expected a List"); + } + } + + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + } + + /** + * @tests java.security.cert.X509CertSelector#getPolicy() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPolicy", + methodArgs = {} + ) + }) + public void test_getPolicy() throws IOException { + String[] policies1 = new String[] { "1.3.6.1.5.5.7.3.1", + "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", + "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", + "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" }; + + String[] policies2 = new String[] { "1.3.6.7.3.1" }; + + HashSet<String> p1 = new HashSet<String>(Arrays.asList(policies1)); + HashSet<String> p2 = new HashSet<String>(Arrays.asList(policies2)); + + X509CertSelector selector = new X509CertSelector(); + + selector.setPolicy(null); + assertNull(selector.getPolicy()); + + selector.setPolicy(p1); + assertEquals("The returned date should be equal to specified", p1, selector.getPolicy()); + + selector.setPolicy(p2); + assertEquals("The returned date should be equal to specified", p2, selector.getPolicy()); + } + + /** + * @tests java.security.cert.X509CertSelector#getPrivateKeyValid() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateKeyValid", + methodArgs = {} + ) + }) + public void test_getPrivateKeyValid() { + Date date1 = new Date(100); + Date date2 = new Date(200); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getPrivateKeyValid()); + selector.setPrivateKeyValid(date1); + assertTrue("The returned date should be equal to specified", date1 + .equals(selector.getPrivateKeyValid())); + selector.getPrivateKeyValid().setTime(200); + assertTrue("The returned date should be equal to specified", date1 + .equals(selector.getPrivateKeyValid())); + assertFalse("The returned date should differ", date2.equals(selector + .getPrivateKeyValid())); + } + + /** + * @tests java.security.cert.X509CertSelector#getSerialNumber() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSerialNumber", + methodArgs = {} + ) + }) + public void test_getSerialNumber() { + BigInteger ser1 = new BigInteger("10000"); + BigInteger ser2 = new BigInteger("10001"); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getSerialNumber()); + selector.setSerialNumber(ser1); + assertEquals("The returned serial number should be equal to specified", + ser1, selector.getSerialNumber()); + assertFalse("The returned serial number should differ", ser2 + .equals(selector.getSerialNumber())); + } + + /** + * @tests java.security.cert.X509CertSelector#getSubject() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubject", + methodArgs = {} + ) + }) + public void test_getSubject() { + X500Principal sub1 = new X500Principal("O=First Org."); + X500Principal sub2 = new X500Principal("O=Second Org."); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getSubject()); + selector.setSubject(sub1); + assertEquals("The returned subject should be equal to specified", sub1, + selector.getSubject()); + assertFalse("The returned subject should differ", sub2.equals(selector + .getSubject())); + } + + /** + * @tests java.security.cert.X509CertSelector#getSubjectAlternativeNames() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectAlternativeNames", + methodArgs = {} + ) + }) + public void test_getSubjectAlternativeNames() { + try { + GeneralName san1 = new GeneralName(1, "rfc@822.Name"); + GeneralName san2 = new GeneralName(2, "dNSName"); + + GeneralNames sans = new GeneralNames(); + sans.addName(san1); + sans.addName(san2); + + TestCert cert_1 = new TestCert(sans); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector + .getSubjectAlternativeNames()); + + selector.setSubjectAlternativeNames(sans.getPairsList()); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert_1)); + selector.getSubjectAlternativeNames().clear(); + assertTrue("The modification of initialization object " + + "should not affect the modification " + + "of internal object.", selector.match(cert_1)); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + } + + /** + * @tests java.security.cert.X509CertSelector#getSubjectAsBytes() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectAsBytes", + methodArgs = {} + ) + }) + public void test_getSubjectAsBytes() { + byte[] name1 = new byte[] + // manually obtained DER encoding of "O=First Org." issuer name; + { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, + 116, 32, 79, 114, 103, 46 }; + byte[] name2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + + X500Principal sub1 = new X500Principal(name1); + X500Principal sub2 = new X500Principal(name2); + X509CertSelector selector = new X509CertSelector(); + + try { + assertNull("Selector should return null", selector + .getSubjectAsBytes()); + selector.setSubject(sub1); + assertTrue("The returned issuer should be equal to specified", + Arrays.equals(name1, selector.getSubjectAsBytes())); + assertFalse("The returned issuer should differ", name2 + .equals(selector.getSubjectAsBytes())); + selector.setSubject(sub2); + assertTrue("The returned issuer should be equal to specified", + Arrays.equals(name2, selector.getSubjectAsBytes())); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + } + + /** + * @tests java.security.cert.X509CertSelector#getSubjectAsString() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectAsString", + methodArgs = {} + ) + }) + public void test_getSubjectAsString() { + String name1 = "O=First Org."; + String name2 = "O=Second Org."; + X500Principal sub1 = new X500Principal(name1); + X500Principal sub2 = new X500Principal(name2); + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector.getSubjectAsString()); + selector.setSubject(sub1); + assertEquals("The returned subject should be equal to specified", + name1, selector.getSubjectAsString()); + assertFalse("The returned subject should differ", name2.equals(selector + .getSubjectAsString())); + selector.setSubject(sub2); + assertEquals("The returned subject should be equal to specified", + name2, selector.getSubjectAsString()); + } + + /** + * @tests java.security.cert.X509CertSelector#getSubjectKeyIdentifier() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectKeyIdentifier", + methodArgs = {} + ) + }) + public void test_getSubjectKeyIdentifier() { + byte[] skid1 = new byte[] { 1, 2, 3, 4, 5 }; // random value + byte[] skid2 = new byte[] { 4, 5, 5, 4, 3, 2, 1 }; // random value + X509CertSelector selector = new X509CertSelector(); + + assertNull("Selector should return null", selector + .getSubjectKeyIdentifier()); + selector.setSubjectKeyIdentifier(skid1); + assertTrue("The returned keyID should be equal to specified", Arrays + .equals(skid1, selector.getSubjectKeyIdentifier())); + selector.getSubjectKeyIdentifier()[0]++; + assertTrue("The returned keyID should be equal to specified", Arrays + .equals(skid1, selector.getSubjectKeyIdentifier())); + assertFalse("The returned keyID should differ", Arrays.equals(skid2, + selector.getSubjectKeyIdentifier())); + } + + /** + * @tests java.security.cert.X509CertSelector#getSubjectPublicKey() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectPublicKey", + methodArgs = {} + ) + }) + public void test_getSubjectPublicKey() throws Exception { + + // SubjectPublicKeyInfo ::= SEQUENCE { + // algorithm AlgorithmIdentifier, + // subjectPublicKey BIT STRING } + byte[] enc = { 0x30, 0x0E, // SEQUENCE + 0x30, 0x07, // SEQUENCE + 0x06, 0x02, 0x03, 0x05,// OID + 0x01, 0x01, 0x07, // ANY + 0x03, 0x03, 0x01, 0x01, 0x06, // subjectPublicKey + }; + + X509CertSelector selector = new X509CertSelector(); + + selector.setSubjectPublicKey(enc); + PublicKey key = selector.getSubjectPublicKey(); + assertEquals("0.3.5", key.getAlgorithm()); + assertEquals("X.509", key.getFormat()); + assertTrue(Arrays.equals(enc, key.getEncoded())); + assertNotNull(key.toString()); + + key = new MyPublicKey(); + + selector.setSubjectPublicKey(key); + PublicKey keyActual = selector.getSubjectPublicKey(); + assertEquals(key, keyActual); + assertEquals(key.getAlgorithm(), keyActual.getAlgorithm()); + } + + /** + * @tests java.security.cert.X509CertSelector#getSubjectPublicKeyAlgID() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectPublicKeyAlgID", + methodArgs = {} + ) + }) + public void _test_getSubjectPublicKeyAlgID() { + + X509CertSelector selector = new X509CertSelector(); + String[] validOIDs = { "0.20", "1.25", "2.39", "0.2.10", "1.35.15", + "2.17.89" }; + + assertNull("Selector should return null", selector + .getSubjectPublicKeyAlgID()); + + for (int i = 0; i < validOIDs.length; i++) { + try { + selector.setSubjectPublicKeyAlgID(validOIDs[i]); + assertEquals(validOIDs[i], selector.getSubjectPublicKeyAlgID()); + } catch (IOException e) { + fail("Unexpected exception " + e.getMessage()); + } + } + + String pkaid1 = "1.2.840.113549.1.1.1"; // RSA encryption (source: + // http://asn1.elibel.tm.fr) + String pkaid2 = "1.2.840.113549.1.1.2"; // MD2 with RSA encryption + // (source: + // http://asn1.elibel.tm.fr) + + try { + selector.setSubjectPublicKeyAlgID(pkaid1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The returned oid should be equal to specified", pkaid1 + .equals(selector.getSubjectPublicKeyAlgID())); + assertFalse("The returned oid should differ", pkaid2.equals(selector + .getSubjectPublicKeyAlgID())); + } + + /** + * @tests java.security.cert.X509CertSelector#match(java.security.cert.Certificate) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "match", + methodArgs = {java.security.cert.Certificate.class} + ) + }) + public void test_matchLjava_security_cert_Certificate() + throws CertificateException { + X509CertSelector selector = new X509CertSelector(); + assertFalse(selector.match(null)); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate cert1 = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + X509Certificate cert2 = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v1())); + + selector.setCertificate(cert1); + assertTrue(selector.match(cert1)); + assertFalse(selector.match(cert2)); + + selector.setCertificate(cert2); + assertFalse(selector.match(cert1)); + assertTrue(selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setAuthorityKeyIdentifier(byte[]) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setAuthorityKeyIdentifier", + methodArgs = {byte[].class} + ) + }) + public void test_setAuthorityKeyIdentifierLB$() throws CertificateException { + X509CertSelector selector = new X509CertSelector(); + + byte[] akid1 = new byte[] { 1, 2, 3, 4, 5 }; // random value + byte[] akid2 = new byte[] { 5, 4, 3, 2, 1 }; // random value + TestCert cert1 = new TestCert(akid1); + TestCert cert2 = new TestCert(akid2); + + selector.setAuthorityKeyIdentifier(null); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + assertNull(selector.getAuthorityKeyIdentifier()); + + selector.setAuthorityKeyIdentifier(akid1); + assertTrue("The certificate should not match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setAuthorityKeyIdentifier(akid2); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert1)); + assertTrue("The certificate should not match the selection criteria.", + selector.match(cert2)); + + akid2[0]++; + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setBasicConstraints(int) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setBasicConstraints", + methodArgs = {int.class} + ) + }) + public void test_setBasicConstraintsLint() { + X509CertSelector selector = new X509CertSelector(); + int[] invalidValues = { -3, -4, -5, 1000000000 }; + for (int i = 0; i < invalidValues.length; i++) { + try { + selector.setBasicConstraints(-3); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + // expected + } + } + + int[] validValues = { -2, -1, 0, 1, 2, 3, 10, 20 }; + for (int i = 0; i < validValues.length; i++) { + selector.setBasicConstraints(validValues[i]); + assertEquals(validValues[i], selector.getBasicConstraints()); + } + } + + /** + * @tests java.security.cert.X509CertSelector#setCertificate(java.security.cert.Certificate) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setCertificate", + methodArgs = {java.security.cert.X509Certificate.class} + ) + }) + public void test_setCertificateLjava_security_cert_X509Certificate() + throws CertificateException { + + TestCert cert1 = new TestCert("same certificate"); + TestCert cert2 = new TestCert("other certificate"); + X509CertSelector selector = new X509CertSelector(); + + selector.setCertificate(null); + assertTrue("Any certificates should match in the case of null " + + "certificateEquals criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setCertificate(cert1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setCertificate(cert2); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + selector.setCertificate(null); + assertNull(selector.getCertificate()); + } + + /** + * @tests java.security.cert.X509CertSelector#setCertificateValid(java.util.Date) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCertificateValid", + methodArgs = {} + ) + }) + public void test_setCertificateValidLjava_util_Date() + throws CertificateException { + X509CertSelector selector = new X509CertSelector(); + + Date date1 = new Date(100); + Date date2 = new Date(200); + TestCert cert1 = new TestCert(date1); + TestCert cert2 = new TestCert(date2); + + selector.setCertificateValid(null); + assertNull(selector.getCertificateValid()); + selector.setCertificateValid(date1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setCertificateValid(date2); + date2.setTime(300); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setExtendedKeyUsage(Set<String>) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setExtendedKeyUsage", + methodArgs = {java.util.Set.class} + ) + }) + public void test_setExtendedKeyUsageLjava_util_Set() + throws CertificateException { + HashSet<String> ku1 = new HashSet<String>(Arrays + .asList(new String[] { "1.3.6.1.5.5.7.3.1", + "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", + "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", + "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", + "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" })); + HashSet<String> ku2 = new HashSet<String>(Arrays.asList(new String[] { + "1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", + "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", + "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6" })); + TestCert cert1 = new TestCert(ku1); + TestCert cert2 = new TestCert(ku2); + + X509CertSelector selector = new X509CertSelector(); + + try { + selector.setExtendedKeyUsage(null); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("Any certificate should match in the case of null " + + "extendedKeyUsage criteria.", selector.match(cert1) + && selector.match(cert2)); + try { + selector.setExtendedKeyUsage(ku1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertEquals(ku1, selector.getExtendedKeyUsage()); + + try { + selector.setExtendedKeyUsage(ku2); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertEquals(ku2, selector.getExtendedKeyUsage()); + } + + /** + * @tests java.security.cert.X509CertSelector#setIssuer(byte[]) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setIssuer", + methodArgs = {byte[].class} + ) + }) + public void test_setIssuerLB$() throws CertificateException { + byte[] name1 = new byte[] + // manually obtained DER encoding of "O=First Org." issuer name; + { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, + 116, 32, 79, 114, 103, 46 }; + byte[] name2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + X500Principal iss1 = new X500Principal(name1); + X500Principal iss2 = new X500Principal(name2); + TestCert cert1 = new TestCert(iss1); + TestCert cert2 = new TestCert(iss2); + + X509CertSelector selector = new X509CertSelector(); + + try { + selector.setIssuer((byte[]) null); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("Any certificates should match " + + "in the case of null issuer criteria.", selector.match(cert1) + && selector.match(cert2)); + try { + selector.setIssuer(name1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + try { + selector.setIssuer(name2); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setIssuer(java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setIssuer", + methodArgs = {java.lang.String.class} + ) + }) + public void test_setIssuerLjava_lang_String() throws CertificateException { + + String name1 = "O=First Org."; + String name2 = "O=Second Org."; + X500Principal iss1 = new X500Principal(name1); + X500Principal iss2 = new X500Principal(name2); + TestCert cert1 = new TestCert(iss1); + TestCert cert2 = new TestCert(iss2); + + X509CertSelector selector = new X509CertSelector(); + + try { + selector.setIssuer((String) null); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("Any certificates should match " + + "in the case of null issuer criteria.", selector.match(cert1) + && selector.match(cert2)); + try { + selector.setIssuer(name1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + try { + selector.setIssuer(name2); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setIssuer(javax.security.auth.x500.X500Principal) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setIssuer", + methodArgs = {javax.security.auth.x500.X500Principal.class} + ) + }) + public void test_setIssuerLjavax_security_auth_x500_X500Principal() + throws CertificateException { + X500Principal iss1 = new X500Principal("O=First Org."); + X500Principal iss2 = new X500Principal("O=Second Org."); + TestCert cert1 = new TestCert(iss1); + TestCert cert2 = new TestCert(iss2); + X509CertSelector selector = new X509CertSelector(); + + selector.setIssuer((X500Principal) null); + assertTrue("Any certificates should match " + + "in the case of null issuer criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setIssuer(iss1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setIssuer(iss2); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setKeyUsage(boolean) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setKeyUsage", + methodArgs = {boolean[].class} + ) + }) + public void test_setKeyUsageZ() throws CertificateException { + boolean[] ku1 = new boolean[] { true, true, true, true, true, true, + true, true, true }; + // decipherOnly is disallowed + boolean[] ku2 = new boolean[] { true, true, true, true, true, true, + true, true, false }; + TestCert cert1 = new TestCert(ku1); + TestCert cert2 = new TestCert(ku2); + TestCert cert3 = new TestCert((boolean[]) null); + + X509CertSelector selector = new X509CertSelector(); + + selector.setKeyUsage(null); + assertTrue("Any certificate should match in the case of null " + + "keyUsage criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setKeyUsage(ku1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + assertTrue("The certificate which does not have a keyUsage extension " + + "implicitly allows all keyUsage values.", selector + .match(cert3)); + selector.setKeyUsage(ku2); + ku2[0] = !ku2[0]; + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setMatchAllSubjectAltNames(boolean) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setMatchAllSubjectAltNames", + methodArgs = {boolean.class} + ) + }) + public void test_setMatchAllSubjectAltNamesZ() { + TestCert cert = new TestCert(); + X509CertSelector selector = new X509CertSelector(); + + assertTrue(selector.match(cert)); + + assertFalse(selector.match(null)); + } + + /** + * @tests java.security.cert.X509CertSelector#setNameConstraints(byte[] + * bytes) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setNameConstraints", + methodArgs = {byte[].class} + ) + }) + public void test_setNameConstraintsLB$() throws IOException { + GeneralName[] name_constraints = new GeneralName[] { + new GeneralName(1, "822.Name"), + new GeneralName(1, "rfc@822.Name"), + new GeneralName(2, "Name.org"), + new GeneralName(2, "dNS.Name.org"), + + new GeneralName(6, "http://Resource.Id"), + new GeneralName(6, "http://uniform.Resource.Id"), + new GeneralName(7, "1.1.1.1"), + + new GeneralName(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 }), }; + + X509CertSelector selector = new X509CertSelector(); + + for (int i = 0; i < name_constraints.length; i++) { + GeneralSubtree subtree = new GeneralSubtree(name_constraints[i]); + GeneralSubtrees subtrees = new GeneralSubtrees(); + subtrees.addSubtree(subtree); + NameConstraints constraints = new NameConstraints(subtrees, + subtrees); + selector.setNameConstraints(constraints.getEncoded()); + assertTrue(Arrays.equals(constraints.getEncoded(), selector + .getNameConstraints())); + } + } + + /** + * @tests java.security.cert.X509CertSelector#setPathToNames(Collection<List<?>>) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setPathToNames", + methodArgs = {java.util.Collection.class} + ) + }) + public void test_setPathToNamesLjava_util_Collection() { + try { + GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", + new byte[] { 1, 2, 0, 1 })); + GeneralName san1 = new GeneralName(1, "rfc@822.Name"); + GeneralName san2 = new GeneralName(2, "dNSName"); + GeneralName san3 = new GeneralName(new ORAddress()); + GeneralName san4 = new GeneralName(new Name("O=Organization")); + GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id"); + GeneralName san7 = new GeneralName(7, "1.1.1.1"); + GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555"); + + GeneralNames sans1 = new GeneralNames(); + sans1.addName(san0); + sans1.addName(san1); + sans1.addName(san2); + sans1.addName(san3); + sans1.addName(san4); + sans1.addName(san6); + sans1.addName(san7); + sans1.addName(san8); + GeneralNames sans2 = new GeneralNames(); + sans2.addName(san0); + + TestCert cert1 = new TestCert(sans1); + TestCert cert2 = new TestCert(sans2); + X509CertSelector selector = new X509CertSelector(); + selector.setMatchAllSubjectAltNames(true); + + selector.setPathToNames(null); + assertTrue("Any certificate should match in the case of null " + + "subjectAlternativeNames criteria.", selector + .match(cert1) + && selector.match(cert2)); + + Collection<List<?>> sans = sans1.getPairsList(); + + selector.setPathToNames(sans); + + Collection<List<?>> col = selector.getPathToNames(); + Iterator<List<?>> i = col.iterator(); + while (i.hasNext()) { + Object o = i.next(); + if (!(o instanceof List)) { + fail("expected a List"); + } + } + + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + } + + /** + * @tests java.security.cert.X509CertSelector#setPolicy(Set<String>) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setPolicy", + methodArgs = {java.util.Set.class} + ) + }) + public void test_setPolicyLjava_util_Set() throws IOException { + String[] policies1 = new String[] { "1.3.6.1.5.5.7.3.1", + "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", + "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", + "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" }; + + String[] policies2 = new String[] { "1.3.6.7.3.1" }; + + HashSet<String> p1 = new HashSet<String>(Arrays.asList(policies1)); + HashSet<String> p2 = new HashSet<String>(Arrays.asList(policies2)); + + X509CertSelector selector = new X509CertSelector(); + + TestCert cert1 = new TestCert(policies1); + TestCert cert2 = new TestCert(policies2); + + selector.setPolicy(null); + assertTrue("Any certificate should match in the case of null " + + "privateKeyValid criteria.", selector.match(cert1) + && selector.match(cert2)); + + selector.setPolicy(p1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + + selector.setPolicy(p2); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert1)); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setPrivateKeyValid(java.util.Date) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setPrivateKeyValid", + methodArgs = {java.util.Date.class} + ) + }) + public void test_setPrivateKeyValidLjava_util_Date() + throws CertificateException { + Date date1 = new Date(100000000); + Date date2 = new Date(200000000); + Date date3 = new Date(300000000); + Date date4 = new Date(150000000); + Date date5 = new Date(250000000); + TestCert cert1 = new TestCert(date1, date2); + TestCert cert2 = new TestCert(date2, date3); + + X509CertSelector selector = new X509CertSelector(); + + selector.setPrivateKeyValid(null); + assertTrue("Any certificate should match in the case of null " + + "privateKeyValid criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setPrivateKeyValid(date4); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setPrivateKeyValid(date5); + date5.setTime(date4.getTime()); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSerialNumber(java.math.BigInteger) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSerialNumber", + methodArgs = {java.math.BigInteger.class} + ) + }) + public void test_setSerialNumberLjava_math_BigInteger() + throws CertificateException { + BigInteger ser1 = new BigInteger("10000"); + BigInteger ser2 = new BigInteger("10001"); + TestCert cert1 = new TestCert(ser1); + TestCert cert2 = new TestCert(ser2); + X509CertSelector selector = new X509CertSelector(); + + selector.setSerialNumber(null); + assertTrue("Any certificate should match in the case of null " + + "serialNumber criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setSerialNumber(ser1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setSerialNumber(ser2); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubject(byte[]) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubject", + methodArgs = {byte[].class} + ) + }) + public void test_setSubjectLB$() throws CertificateException { + byte[] name1 = new byte[] + // manually obtained DER encoding of "O=First Org." issuer name; + { 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, + 116, 32, 79, 114, 103, 46 }; + byte[] name2 = new byte[] + // manually obtained DER encoding of "O=Second Org." issuer name; + { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, + 110, 100, 32, 79, 114, 103, 46 }; + X500Principal sub1 = new X500Principal(name1); + X500Principal sub2 = new X500Principal(name2); + TestCert cert1 = new TestCert(sub1); + TestCert cert2 = new TestCert(sub2); + + X509CertSelector selector = new X509CertSelector(); + + try { + selector.setSubject((byte[]) null); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("Any certificates should match " + + "in the case of null issuer criteria.", selector.match(cert1) + && selector.match(cert2)); + try { + selector.setSubject(name1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + try { + selector.setSubject(name2); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubject(java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubject", + methodArgs = {java.lang.String.class} + ) + }) + public void test_setSubjectLjava_lang_String() throws CertificateException { + String name1 = "O=First Org."; + String name2 = "O=Second Org."; + X500Principal sub1 = new X500Principal(name1); + X500Principal sub2 = new X500Principal(name2); + TestCert cert1 = new TestCert(sub1); + TestCert cert2 = new TestCert(sub2); + X509CertSelector selector = new X509CertSelector(); + + try { + selector.setSubject((String) null); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("Any certificates should match " + + "in the case of null subject criteria.", selector + .match(cert1) + && selector.match(cert2)); + try { + selector.setSubject(name1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + try { + selector.setSubject(name2); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubject(javax.security.auth.x500.X500Principal) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubject", + methodArgs = {javax.security.auth.x500.X500Principal.class} + ) + }) + public void test_setSubjectLjavax_security_auth_x500_X500Principal() + throws CertificateException { + X500Principal sub1 = new X500Principal("O=First Org."); + X500Principal sub2 = new X500Principal("O=Second Org."); + TestCert cert1 = new TestCert(sub1); + TestCert cert2 = new TestCert(sub2); + X509CertSelector selector = new X509CertSelector(); + + selector.setSubject((X500Principal) null); + assertTrue("Any certificates should match " + + "in the case of null subjcet criteria.", selector + .match(cert1) + && selector.match(cert2)); + selector.setSubject(sub1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setSubject(sub2); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubjectAlternativeNames(Collection<List<?>>) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectAlternativeNames", + methodArgs = {} + ) + }) + public void test_setSubjectAlternativeNamesLjava_util_Collection() { + + try { + GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", + new byte[] { 1, 2, 0, 1 })); + GeneralName san1 = new GeneralName(1, "rfc@822.Name"); + GeneralName san2 = new GeneralName(2, "dNSName"); + GeneralName san3 = new GeneralName(new ORAddress()); + GeneralName san4 = new GeneralName(new Name("O=Organization")); + GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id"); + GeneralName san7 = new GeneralName(7, "1.1.1.1"); + GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555"); + + GeneralNames sans1 = new GeneralNames(); + sans1.addName(san0); + sans1.addName(san1); + sans1.addName(san2); + sans1.addName(san3); + sans1.addName(san4); + sans1.addName(san6); + sans1.addName(san7); + sans1.addName(san8); + GeneralNames sans2 = new GeneralNames(); + sans2.addName(san0); + + TestCert cert1 = new TestCert(sans1); + TestCert cert2 = new TestCert(sans2); + X509CertSelector selector = new X509CertSelector(); + selector.setMatchAllSubjectAltNames(true); + + selector.setSubjectAlternativeNames(null); + assertTrue("Any certificate should match in the case of null " + + "subjectAlternativeNames criteria.", selector + .match(cert1) + && selector.match(cert2)); + + Collection<List<?>> sans = sans1.getPairsList(); + + selector.setSubjectAlternativeNames(sans); + + Collection<List<?>> col = selector.getSubjectAlternativeNames(); + Iterator<List<?>> i = col.iterator(); + while (i.hasNext()) { + Object o = i.next(); + if (!(o instanceof List)) { + fail("expected a List"); + } + } + + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected IOException was thrown."); + } + } + + /** + * @tests java.security.cert.X509CertSelector#setSubjectKeyIdentifier(byte[]) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubjectKeyIdentifier", + methodArgs = {byte[].class} + ) + }) + public void test_setSubjectKeyIdentifierLB$() throws CertificateException { + byte[] skid1 = new byte[] { 1, 2, 3, 4, 5 }; // random value + byte[] skid2 = new byte[] { 5, 4, 3, 2, 1 }; // random value + TestCert cert1 = new TestCert(skid1); + TestCert cert2 = new TestCert(skid2); + X509CertSelector selector = new X509CertSelector(); + + selector.setSubjectKeyIdentifier(null); + assertTrue("Any certificate should match in the case of null " + + "serialNumber criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setSubjectKeyIdentifier(skid1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setSubjectKeyIdentifier(skid2); + skid2[0]++; + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubjectPublicKey(byte[]) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubjectPublicKey", + methodArgs = {byte[].class} + ) + }) + public void test_setSubjectPublicKeyLB$() throws Exception { + + //SubjectPublicKeyInfo ::= SEQUENCE { + // algorithm AlgorithmIdentifier, + // subjectPublicKey BIT STRING } + byte[] enc = { 0x30, 0x0E, // SEQUENCE + 0x30, 0x07, // SEQUENCE + 0x06, 0x02, 0x03, 0x05,//OID + 0x01, 0x01, 0x07, //ANY + 0x03, 0x03, 0x01, 0x01, 0x06, // subjectPublicKey + }; + + X509CertSelector selector = new X509CertSelector(); + + selector.setSubjectPublicKey(enc); + PublicKey key = selector.getSubjectPublicKey(); + assertEquals("0.3.5", key.getAlgorithm()); + assertEquals("X.509", key.getFormat()); + assertTrue(Arrays.equals(enc, key.getEncoded())); + assertNotNull(key.toString()); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubjectPublicKey(java.security.PublicKey key) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubjectPublicKey", + methodArgs = {java.security.PublicKey.class} + ) + }) + public void test_setSubjectPublicKeyLjava_security_PublicKey() + throws CertificateException { + PublicKey pkey1 = null; + PublicKey pkey2 = null; + try { + pkey1 = new TestKeyPair("RSA").getPublic(); + pkey2 = new TestKeyPair("DSA").getPublic(); + } catch (Exception e) { + fail("Unexpected Exception was thrown: " + e.getMessage()); + } + + TestCert cert1 = new TestCert(pkey1); + TestCert cert2 = new TestCert(pkey2); + X509CertSelector selector = new X509CertSelector(); + + selector.setSubjectPublicKey((PublicKey) null); + assertTrue("Any certificate should match in the case of null " + + "subjectPublicKey criteria.", selector.match(cert1) + && selector.match(cert2)); + selector.setSubjectPublicKey(pkey1); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + selector.setSubjectPublicKey(pkey2); + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#setSubjectPublicKeyAlgID(java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setSubjectPublicKeyAlgID", + methodArgs = {java.lang.String.class} + ) + }) + public void _test_setSubjectPublicKeyAlgIDLjava_lang_String() + throws CertificateException { + + X509CertSelector selector = new X509CertSelector(); + String pkaid1 = "1.2.840.113549.1.1.1"; // RSA (source: + // http://asn1.elibel.tm.fr) + String pkaid2 = "1.2.840.10040.4.1"; // DSA (source: + // http://asn1.elibel.tm.fr) + PublicKey pkey1; + PublicKey pkey2; + try { + pkey1 = new TestKeyPair("RSA").getPublic(); + pkey2 = new TestKeyPair("DSA").getPublic(); + } catch (Exception e) { + e.printStackTrace(); + fail("Unexpected Exception was thrown: " + e.getMessage()); + return; + } + TestCert cert1 = new TestCert(pkey1); + TestCert cert2 = new TestCert(pkey2); + + try { + selector.setSubjectPublicKeyAlgID(null); + } catch (IOException e) { + + fail("Unexpected IOException was thrown."); + } + assertTrue("Any certificate should match in the case of null " + + "subjectPublicKeyAlgID criteria.", selector.match(cert1) + && selector.match(cert2)); + + String[] validOIDs = { "0.20", "1.25", "2.39", "0.2.10", "1.35.15", + "2.17.89", "2.5.29.16", "2.5.29.17", "2.5.29.30", "2.5.29.32", + "2.5.29.37" }; + + for (int i = 0; i < validOIDs.length; i++) { + try { + selector.setSubjectPublicKeyAlgID(validOIDs[i]); + assertEquals(validOIDs[i], selector.getSubjectPublicKeyAlgID()); + } catch (IOException e) { + fail("Unexpected exception " + e.getMessage()); + } + } + + try { + selector.setSubjectPublicKeyAlgID(pkaid1); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert1)); + assertFalse("The certificate should not match the selection criteria.", + selector.match(cert2)); + try { + selector.setSubjectPublicKeyAlgID(pkaid2); + } catch (IOException e) { + fail("Unexpected IOException was thrown."); + } + assertTrue("The certificate should match the selection criteria.", + selector.match(cert2)); + } + + /** + * @tests java.security.cert.X509CertSelector#toString() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public void test_toString() { + X509CertSelector selector = new X509CertSelector(); + assertNotNull(selector.toString()); + } + + public class MyPublicKey implements PublicKey { + private static final long serialVersionUID = 2899528375354645752L; + + public MyPublicKey() { + super(); + } + + public String getAlgorithm() { + return "PublicKey"; + } + + public String getFormat() { + return "Format"; + } + + public byte[] getEncoded() { + return new byte[0]; + } + + public long getSerVerUID() { + return serialVersionUID; + } + } + + private class TestCert extends X509Certificate { + + private static final long serialVersionUID = 176676115254260405L; + + /* Stuff fields */ + protected String equalCriteria = null; // to simplify method equals() + + protected BigInteger serialNumber = null; + + protected X500Principal issuer = null; + + protected X500Principal subject = null; + + protected byte[] keyIdentifier = null; + + protected Date date = null; + + protected Date notBefore = null; + + protected Date notAfter = null; + + protected PublicKey key = null; + + protected boolean[] keyUsage = null; + + protected List<String> extKeyUsage = null; + + protected int pathLen = 1; + + protected GeneralNames sans = null; + + protected byte[] encoding = null; + + protected String[] policies = null; + + protected Collection<List<?>> collection = null; + + protected NameConstraints nameConstraints = null; + + /* Stuff methods */ + public TestCert() { + } + + public TestCert(GeneralNames sans) { + setSubjectAlternativeNames(sans); + } + + public TestCert(NameConstraints nameConstraints) { + this.nameConstraints = nameConstraints; + } + + public TestCert(Collection<List<?>> collection) { + setCollection(collection); + } + + public TestCert(String equalCriteria) { + setEqualCriteria(equalCriteria); + } + + public TestCert(String[] policies) { + setPolicies(policies); + } + + public TestCert(BigInteger serial) { + setSerialNumber(serial); + } + + public TestCert(X500Principal principal) { + setIssuer(principal); + setSubject(principal); + } + + public TestCert(byte[] array) { + setKeyIdentifier(array); + } + + public TestCert(Date date) { + setDate(date); + } + + public TestCert(Date notBefore, Date notAfter) { + setPeriod(notBefore, notAfter); + } + + public TestCert(PublicKey key) { + setPublicKey(key); + } + + public TestCert(boolean[] keyUsage) { + setKeyUsage(keyUsage); + } + + public TestCert(Set<String> extKeyUsage) { + setExtendedKeyUsage(extKeyUsage); + } + + public TestCert(int pathLen) { + this.pathLen = pathLen; + } + + public void setSubjectAlternativeNames(GeneralNames sans) { + this.sans = sans; + } + + public void setCollection(Collection<List<?>> collection) { + this.collection = collection; + } + + public void setPolicies(String[] policies) { + this.policies = policies; + } + + public void setExtendedKeyUsage(Set<String> extKeyUsage) { + this.extKeyUsage = (extKeyUsage == null) ? null : new ArrayList<String>( + extKeyUsage); + } + + public void setKeyUsage(boolean[] keyUsage) { + this.keyUsage = (keyUsage == null) ? null : (boolean[]) keyUsage + .clone(); + } + + public void setPublicKey(PublicKey key) { + this.key = key; + } + + public void setPeriod(Date notBefore, Date notAfter) { + this.notBefore = notBefore; + this.notAfter = notAfter; + } + + public void setSerialNumber(BigInteger serial) { + this.serialNumber = serial; + } + + public void setEqualCriteria(String equalCriteria) { + this.equalCriteria = equalCriteria; + } + + public void setIssuer(X500Principal issuer) { + this.issuer = issuer; + } + + public void setSubject(X500Principal subject) { + this.subject = subject; + } + + public void setKeyIdentifier(byte[] subjectKeyID) { + this.keyIdentifier = (byte[]) subjectKeyID.clone(); + } + + public void setDate(Date date) { + this.date = new Date(date.getTime()); + } + + public void setEncoding(byte[] encoding) { + this.encoding = encoding; + } + + /* Method implementations */ + public boolean equals(Object cert) { + if (cert == null) { + return false; + } + if ((equalCriteria == null) + || (((TestCert) cert).equalCriteria == null)) { + return false; + } else { + return equalCriteria.equals(((TestCert) cert).equalCriteria); + } + } + + public String toString() { + if (equalCriteria != null) { + return equalCriteria; + } + return ""; + } + + public void checkValidity() throws CertificateExpiredException, + CertificateNotYetValidException { + } + + public void checkValidity(Date date) + throws CertificateExpiredException, + CertificateNotYetValidException { + if (this.date == null) { + throw new CertificateExpiredException(); + } + int result = this.date.compareTo(date); + if (result > 0) { + throw new CertificateExpiredException(); + } + if (result < 0) { + throw new CertificateNotYetValidException(); + } + } + + public int getVersion() { + return 3; + } + + public BigInteger getSerialNumber() { + return (serialNumber == null) ? new BigInteger("1111") + : serialNumber; + } + + public Principal getIssuerDN() { + return issuer; + } + + public X500Principal getIssuerX500Principal() { + return issuer; + } + + public Principal getSubjectDN() { + return subject; + } + + public X500Principal getSubjectX500Principal() { + return subject; + } + + public Date getNotBefore() { + return null; + } + + public Date getNotAfter() { + return null; + } + + public byte[] getTBSCertificate() throws CertificateEncodingException { + return null; + } + + public byte[] getSignature() { + return null; + } + + public String getSigAlgName() { + return null; + } + + public String getSigAlgOID() { + return null; + } + + public byte[] getSigAlgParams() { + return null; + } + + public boolean[] getIssuerUniqueID() { + return null; + } + + public boolean[] getSubjectUniqueID() { + return null; + } + + public boolean[] getKeyUsage() { + return keyUsage; + } + + public List<String> getExtendedKeyUsage() + throws CertificateParsingException { + return extKeyUsage; + } + + public int getBasicConstraints() { + return pathLen; + } + + public void verify(PublicKey key) throws CertificateException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + public void verify(PublicKey key, String sigProvider) + throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + + public PublicKey getPublicKey() { + return key; + } + + public byte[] getEncoded() throws CertificateEncodingException { + return encoding; + } + + public Set<String> getNonCriticalExtensionOIDs() { + return null; + } + + public Set<String> getCriticalExtensionOIDs() { + return null; + } + + public byte[] getExtensionValue(String oid) { + + if (("2.5.29.14".equals(oid)) || ("2.5.29.35".equals(oid))) { + // Extension value is represented as an OctetString + return ASN1OctetString.getInstance().encode(keyIdentifier); + } + if ("2.5.29.16".equals(oid)) { + PrivateKeyUsagePeriod pkup = new PrivateKeyUsagePeriod( + notBefore, notAfter); + byte[] encoded = pkup.getEncoded(); + return ASN1OctetString.getInstance().encode(encoded); + } + if (("2.5.29.37".equals(oid)) && (extKeyUsage != null)) { + ASN1Oid[] oa = new ASN1Oid[extKeyUsage.size()]; + String[] val = new String[extKeyUsage.size()]; + Iterator it = extKeyUsage.iterator(); + int id = 0; + while (it.hasNext()) { + oa[id] = ASN1Oid.getInstanceForString(); + val[id++] = (String) it.next(); + } + return ASN1OctetString.getInstance().encode( + new ASN1Sequence(oa).encode(val)); + } + if ("2.5.29.19".equals(oid)) { + return ASN1OctetString.getInstance().encode( + new ASN1Sequence(new ASN1Type[] { + ASN1Boolean.getInstance(), + ASN1Integer.getInstance() }) + .encode(new Object[] { + new Boolean(pathLen != 1), + BigInteger.valueOf(pathLen) + .toByteArray() })); + } + if ("2.5.29.17".equals(oid) && (sans != null)) { + if (sans.getNames() == null) { + return null; + } + return ASN1OctetString.getInstance().encode( + GeneralNames.ASN1.encode(sans)); + } + if ("2.5.29.32".equals(oid) && (policies != null) + && (policies.length > 0)) { + // Certificate Policies Extension (as specified in rfc 3280) + CertificatePolicies certificatePolicies = new CertificatePolicies(); + for (int i = 0; i < policies.length; i++) { + PolicyInformation policyInformation = new PolicyInformation( + policies[i]); + certificatePolicies.addPolicyInformation(policyInformation); + } + return ASN1OctetString.getInstance().encode( + certificatePolicies.getEncoded()); + } + if ("2.5.29.30".equals(oid) && (nameConstraints != null)) { // + // Name + // Constraints + // Extension + // (as + // specified + // in + // rfc + // 3280) + return ASN1OctetString.getInstance().encode( + nameConstraints.getEncoded()); + } + + return null; + } + + public boolean hasUnsupportedCriticalExtension() { + return false; + } + } +} diff --git a/security/src/test/java/tests/security/cert/X509Certificate2Test.java b/security/src/test/java/tests/security/cert/X509Certificate2Test.java new file mode 100644 index 0000000..13b2c8c --- /dev/null +++ b/security/src/test/java/tests/security/cert/X509Certificate2Test.java @@ -0,0 +1,401 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.cert; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.CertificateParsingException; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import javax.security.auth.x500.X500Principal; + +import org.apache.harmony.security.tests.support.cert.TestUtils; +import tests.support.resource.Support_Resources; + +@TestTargetClass(X509Certificate.class) +public class X509Certificate2Test extends junit.framework.TestCase { + + /** + * @tests java.security.cert.X509Certificate#getExtensionValue(java.lang.String) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getExtensionValue", + methodArgs = {String.class} + ) + }) + public void _test_getExtensionValueLjava_lang_String() throws Exception { + + InputStream is = Support_Resources + .getResourceStream("hyts_certificate_PEM.txt"); + + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(is); + + Vector<String> extensionOids = new Vector<String>(); + extensionOids.addAll(pemCert.getCriticalExtensionOIDs()); + extensionOids.addAll(pemCert.getNonCriticalExtensionOIDs()); + Iterator i = extensionOids.iterator(); + while (i.hasNext()) { + String oid = (String) i.next(); + byte[] value = pemCert.getExtensionValue(oid); + if (value != null && value.length > 0) { + // check that it is an encoded as a OCTET STRING + assertEquals("The extension value for the oid " + oid + + " was not encoded as an OCTET STRING", 0x04, value[0]); + } + } + } + + /** + * Test for X.509 Certificate provider + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) + public void test_toString() throws Exception { + + // Regression for HARMONY-3384 + CertificateFactory certFact = CertificateFactory.getInstance("X509"); + X509Certificate pemCert = (X509Certificate) certFact + .generateCertificate(new ByteArrayInputStream(TestUtils + .getX509Certificate_v3())); + + // extension value is empty sequence + byte[] extnValue = pemCert.getExtensionValue("2.5.29.35"); + assertTrue(Arrays.equals(new byte[] { 0x04, 0x02, 0x30, 0x00 }, + extnValue)); + assertNotNull(pemCert.toString()); + // End regression for HARMONY-3384 + } + + /** + * @tests java.security.cert.X509Certificate#X509Certificate() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "X509Certificate", + methodArgs = {} + ) + }) + public void test_X509Certificate() { + MyX509Certificate s = null; + try { + s = new MyX509Certificate(); + } catch (Exception e) { + fail("Unexpected exception " + e.getMessage()); + } + assertEquals("X.509", s.getType()); + } + + // Base64 encoded form of ASN.1 DER encoded X.509 Certificate + // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt) + // (generated by using of classes from + // org.apache.harmony.security.x509 package) + static String base64cert = "MIIByzCCATagAwIBAgICAiswCwYJKoZIhvcNAQEFMB0xGzAZBgNVBAoT" + + "EkNlcnRpZmljYXRlIElzc3VlcjAeFw0wNjA0MjYwNjI4MjJaFw0zMzAz" + + "MDExNjQ0MDlaMB0xGzAZBgNVBAoTEkNlcnRpZmljYXRlIElzc3VlcjCB" + + "nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAkLGLsPdSPDMyP1OUOKu" + + "U3cvbNK5RGaQ3bXc5aDjvApx43BcaoXgt6YD/5yXz0OsIooj5yA37bY" + + "JGcVrvFD5FMPdDd3vjNPQOep0MzG4CdbkaZde5SigPabOMQYS4oUyLBx" + + "W3LGG0mUODe5AGGqtqXU0GlKg4K2je6cCtookCUCAwEAAaMeMBwwGgYD" + + "VR0RAQH/BBAwDoEMcmZjQDgyMi5OYW1lMAsGCSqGSIb3DQEBBQOBgQBZ" + + "pVXj01dOpqnZErUQb50j8lJD1dIaz1eJTvJCSadj7ziV1VtnnapI07c" + + "XEa7ONzcHQTYTG10poHfOK/a0BaULF3GlctDESilwQYbW5BdfpAlZpbH" + + "AFLcUDh6Eq50kc0A/anh/j3mgBNuvbIMo7hHNnZB6k/prswm2BszyLD" + + "yw=="; + + // Base64 encoded form of ASN.1 DER encoded X.509 CRL + // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt) + // (generated by using of classes from + // org.apache.harmony.security.x509 package) + static String base64crl = "MIHXMIGXAgEBMAkGByqGSM44BAMwFTETMBEGA1UEChMKQ1JMIElzc3Vl" + + "chcNMDYwNDI3MDYxMzQ1WhcNMDYwNDI3MDYxNTI1WjBBMD8CAgIrFw0w" + + "NjA0MjcwNjEzNDZaMCowCgYDVR0VBAMKAQEwHAYDVR0YBBUYEzIwMDYw" + + "NDI3MDYxMzQ1LjQ2OFqgDzANMAsGA1UdFAQEBAQEBDAJBgcqhkjOOAQD" + + "AzAAMC0CFQCk0t0DTyu82QpajbBlxX9uXvUDSgIUSBN4g+xTEeexs/0k" + + "9AkjBhjF0Es="; + + // has stub implementation for abstract methods + private static class MyX509Certificate extends X509Certificate { + + private static final long serialVersionUID = -7196694072296607007L; + + public void checkValidity() throws CertificateExpiredException, + CertificateNotYetValidException { + } + + public void checkValidity(Date date) + throws CertificateExpiredException, + CertificateNotYetValidException { + } + + public int getVersion() { + return 3; + } + + public BigInteger getSerialNumber() { + return null; + } + + public Principal getIssuerDN() { + return null; + } + + public Principal getSubjectDN() { + return null; + } + + public Date getNotBefore() { + return null; + } + + public Date getNotAfter() { + return null; + } + + public byte[] getTBSCertificate() throws CertificateEncodingException { + return null; + } + + public byte[] getSignature() { + return null; + } + + public String getSigAlgName() { + return null; + } + + public String getSigAlgOID() { + return null; + } + + public byte[] getSigAlgParams() { + return null; + } + + public boolean[] getIssuerUniqueID() { + return null; + } + + public boolean[] getSubjectUniqueID() { + return null; + } + + public boolean[] getKeyUsage() { + return null; + } + + public int getBasicConstraints() { + return 0; + } + + public void verify(PublicKey key) throws CertificateException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + public void verify(PublicKey key, String sigProvider) + throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + + public String toString() { + return ""; + } + + public PublicKey getPublicKey() { + return null; + } + + public byte[] getEncoded() throws CertificateEncodingException { + return null; + } + + public Set<String> getNonCriticalExtensionOIDs() { + return null; + } + + public Set<String> getCriticalExtensionOIDs() { + return null; + } + + public byte[] getExtensionValue(String oid) { + return null; + } + + public boolean hasUnsupportedCriticalExtension() { + return false; + } + } + + /** + * @tests java.security.cert.X509Certificate#getType() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getType", + methodArgs = {} + ) + }) + public void testGetType() { + assertEquals("X.509", new MyX509Certificate().getType()); + } + + /** + * @tests java.security.cert.X509Certificate#getIssuerX500Principal() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getIssuerX500Principal", + methodArgs = {} + ) + }) + public void testGetIssuerX500Principal() { + // return valid encoding + MyX509Certificate cert = new MyX509Certificate() { + private static final long serialVersionUID = 638659908323741165L; + + public byte[] getEncoded() { + return TestUtils.getX509Certificate_v1(); + }; + }; + + assertEquals(new X500Principal("CN=Z"), cert.getIssuerX500Principal()); + } + + /** + * @tests java.security.cert.X509Certificate#getSubjectX500Principal() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectX500Principal", + methodArgs = {} + ) + }) + public void testGetSubjectX500Principal() { + // return valid encoding + MyX509Certificate cert = new MyX509Certificate() { + private static final long serialVersionUID = -3625913637413840694L; + + public byte[] getEncoded() { + return TestUtils.getX509Certificate_v1(); + }; + }; + + assertEquals(new X500Principal("CN=Y"), cert.getSubjectX500Principal()); + } + + /** + * @tests java.security.cert.X509Certificate#getExtendedKeyUsage() + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateParsingException.", + targets = { + @TestTarget( + methodName = "getExtendedKeyUsage", + methodArgs = {} + ) + }) + public void testGetExtendedKeyUsage() throws CertificateParsingException { + assertNull(new MyX509Certificate().getExtendedKeyUsage()); + } + + /** + * @tests java.security.cert.X509Certificate#getSubjectAlternativeNames() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getSubjectAlternativeNames", + methodArgs = {} + ) + }) + public void testGetSubjectAlternativeNames() + throws CertificateParsingException { + + assertNull(new MyX509Certificate().getSubjectAlternativeNames()); + } + + /** + * @tests java.security.cert.X509Certificate#getIssuerAlternativeNames() + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify CertificateParsingException.", + targets = { + @TestTarget( + methodName = "getIssuerAlternativeNames", + methodArgs = {} + ) + }) + public void testGetIssuerAlternativeNames() + throws CertificateParsingException { + + assertNull(new MyX509Certificate().getIssuerAlternativeNames()); + } + +} diff --git a/security/src/test/java/tests/security/interfaces/AllTests.java b/security/src/test/java/tests/security/interfaces/AllTests.java new file mode 100644 index 0000000..25d765f --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/AllTests.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.interfaces; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package tests.security.interfaces; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package tests.security.interfaces;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(DSAKeyTest.class); + suite.addTestSuite(DSAParamsTest.class); +// suite.addTestSuite(DSAPrivateKeyTest.class); +// suite.addTestSuite(DSAPublicKeyTest.class); +// suite.addTestSuite(ECKeyTest.class); +// suite.addTestSuite(ECPrivateKeyTest.class); +// suite.addTestSuite(ECPublicKeyTest.class); + suite.addTestSuite(RSAKeyTest.class); + suite.addTestSuite(RSAPrivateCrtKeyTest.class); + suite.addTestSuite(RSAPrivateKeyTest.class); + suite.addTestSuite(RSAPublicKeyTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/security/src/test/java/tests/security/interfaces/DSAKeyTest.java b/security/src/test/java/tests/security/interfaces/DSAKeyTest.java new file mode 100644 index 0000000..1e680e8 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/DSAKeyTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.KeyPairGenerator; +import java.security.interfaces.DSAKey; +import java.security.interfaces.DSAParams; +import java.security.spec.DSAParameterSpec; + +@TestTargetClass(DSAKey.class) +public class DSAKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.DSAKey + * #getParams() + * test covers following use cases + * Case 1: check private key + * Case 2: check public key + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParams", + methodArgs = {} + ) + }) + public void test_getParams() throws Exception { + DSAParams param = new DSAParameterSpec(Util.P, Util.Q, Util.G); + + KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA", Util.prov); + gen.initialize((DSAParameterSpec) param); + DSAKey key = null; + + // Case 1: check private key + key = (DSAKey) gen.generateKeyPair().getPrivate(); + assertDSAParamsEquals(param, key.getParams()); + + // Case 2: check public key + key = (DSAKey) gen.generateKeyPair().getPublic(); + assertDSAParamsEquals(param, key.getParams()); + } + + private void assertDSAParamsEquals(DSAParams expected, DSAParams actual) { + assertEquals("P differ", expected.getP(), actual.getP()); + assertEquals("Q differ", expected.getQ(), actual.getQ()); + assertEquals("G differ", expected.getG(), actual.getG()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/DSAParamsTest.java b/security/src/test/java/tests/security/interfaces/DSAParamsTest.java new file mode 100644 index 0000000..606e894 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/DSAParamsTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.interfaces.DSAParams; +import java.security.spec.DSAParameterSpec; + +@TestTargetClass(DSAParams.class) +public class DSAParamsTest extends TestCase { + + private final BigInteger p = new BigInteger("4"); + private final BigInteger q = BigInteger.TEN; + private final BigInteger g = BigInteger.ZERO; + + /** + * @tests java.security.interfaces.DSAParams + * #getG() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getG", + methodArgs = {} + ) + }) + public void test_getG() { + DSAParams params = new DSAParameterSpec(p, q, g); + assertEquals("Invalid G", g, params.getG()); + } + + /** + * @tests java.security.interfaces.DSAParams + * #getP() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getP", + methodArgs = {} + ) + }) + public void test_getP() { + DSAParams params = new DSAParameterSpec(p, q, g); + assertEquals("Invalid P", p, params.getP()); + } + + /** + * @tests java.security.interfaces.DSAParams + * #getQ() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getQ", + methodArgs = {} + ) + }) + public void test_getQ() { + DSAParams params = new DSAParameterSpec(p, q, g); + assertEquals("Invalid Q", q, params.getQ()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/DSAPrivateKeyTest.java b/security/src/test/java/tests/security/interfaces/DSAPrivateKeyTest.java new file mode 100644 index 0000000..e4d4638 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/DSAPrivateKeyTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.KeyPairGenerator; +import java.security.SecureRandom; +import java.security.interfaces.DSAPrivateKey; +import java.security.spec.DSAParameterSpec; + +@TestTargetClass(DSAPrivateKey.class) +public class DSAPrivateKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.DSAPrivateKey + * #getX() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getX", + methodArgs = {} + ) + }) + @SuppressWarnings("serial") + public void test_getX() throws Exception { + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", Util.prov); + keyGen.initialize(new DSAParameterSpec(Util.P, Util.Q, Util.G), + new SecureRandom(new MySecureRandomSpi(), null) { + }); + DSAPrivateKey key = (DSAPrivateKey) keyGen.generateKeyPair().getPrivate(); + assertEquals("Invalid X value", Util.RND_RET, key.getX()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/DSAPublicKeyTest.java b/security/src/test/java/tests/security/interfaces/DSAPublicKeyTest.java new file mode 100644 index 0000000..6c73131 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/DSAPublicKeyTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.SecureRandom; +import java.security.interfaces.DSAPrivateKey; +import java.security.interfaces.DSAPublicKey; +import java.security.spec.DSAParameterSpec; + +@TestTargetClass(DSAPublicKey.class) +public class DSAPublicKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.DSAPublicKey + * #getY() + * test covers following use cases + * Case 1: check with predefined p, q, g, x + * Case 2: check with random p, q, g, x. It takes some time (up to + * minute) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getY", + methodArgs = {} + ) + }) + @SuppressWarnings("serial") + public void test_getY() throws Exception { + KeyPairGenerator keyGen = null; + KeyPair keys = null; + DSAPrivateKey priv = null; + DSAPublicKey publ = null; + + // Case 1: check with predefined p, q, g, x + keyGen = KeyPairGenerator.getInstance("DSA", Util.prov); + keyGen.initialize(new DSAParameterSpec(Util.P, Util.Q, Util.G), + new SecureRandom(new MySecureRandomSpi(), null) { + }); + keys = keyGen.generateKeyPair(); + priv = (DSAPrivateKey) keys.getPrivate(); + publ = (DSAPublicKey) keys.getPublic(); + assertEquals("Invalid Y value", (Util.G.modPow(Util.RND_RET, Util.P)), + publ.getY()); + + // Case 2: check with random p, q, g, x. It takes some time (up to + // minute) + keyGen = KeyPairGenerator.getInstance("DSA", Util.prov); + keys = keyGen.generateKeyPair(); + priv = (DSAPrivateKey) keys.getPrivate(); + publ = (DSAPublicKey) keys.getPublic(); + assertEquals("Invalid Y value", (priv.getParams().getG().modPow( + priv.getX(), priv.getParams().getP())), publ.getY()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/ECKeyTest.java b/security/src/test/java/tests/security/interfaces/ECKeyTest.java new file mode 100644 index 0000000..6a8a733 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/ECKeyTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.KeyPairGenerator; +import java.security.interfaces.ECKey; +import java.security.spec.ECParameterSpec; + +@TestTargetClass(ECKey.class) +public class ECKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.ECKey + * #getParams() + * test covers following use cases + * Case 1: check private key + * Case 2: check public key + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParams", + methodArgs = {} + ) + }) + public void test_getParams() throws Exception { + KeyPairGenerator gen = KeyPairGenerator.getInstance("EC", Util.prov); + gen.initialize(Util.ecParam); + ECKey key = null; + + // Case 1: check private key + key = (ECKey) gen.generateKeyPair().getPrivate(); + assertECParameterSpecEquals(Util.ecParam, key.getParams()); + + // Case 2: check public key + key = (ECKey) gen.generateKeyPair().getPublic(); + assertECParameterSpecEquals(Util.ecParam, key.getParams()); + } + + private void assertECParameterSpecEquals(ECParameterSpec expected, ECParameterSpec actual) { + assertEquals("cofactors don't match", expected.getCofactor(), actual.getCofactor()); + assertEquals("curves don't match", expected.getCurve(), actual.getCurve()); + assertEquals("generator don't match", expected.getGenerator(), actual.getGenerator()); + assertEquals("order don't match", expected.getOrder(), actual.getOrder()); + + } +} diff --git a/security/src/test/java/tests/security/interfaces/ECPrivateKeyTest.java b/security/src/test/java/tests/security/interfaces/ECPrivateKeyTest.java new file mode 100644 index 0000000..9b8471b --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/ECPrivateKeyTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.KeyPairGenerator; +import java.security.SecureRandom; +import java.security.interfaces.ECPrivateKey; + +@TestTargetClass(ECPrivateKey.class) +public class ECPrivateKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.ECPrivateKey + * #getS() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getS", + methodArgs = {} + ) + }) + @SuppressWarnings("serial") + public void test_getS() throws Exception { + KeyPairGenerator gen = KeyPairGenerator.getInstance("EC", Util.prov); + gen.initialize(Util.ecParam, new SecureRandom(new MySecureRandomSpi(), + null) { + }); + ECPrivateKey key = (ECPrivateKey) gen.generateKeyPair().getPrivate(); + assertEquals("Invalid S", Util.RND_RET, key.getS()); + } + +} diff --git a/security/src/test/java/tests/security/interfaces/ECPublicKeyTest.java b/security/src/test/java/tests/security/interfaces/ECPublicKeyTest.java new file mode 100644 index 0000000..a211be2 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/ECPublicKeyTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.KeyPairGenerator; +import java.security.SecureRandom; +import java.security.interfaces.ECPublicKey; +import java.security.spec.ECPoint; + +@TestTargetClass(ECPublicKey.class) +public class ECPublicKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.ECPublicKey + * #getW() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getW", + methodArgs = {} + ) + }) + @SuppressWarnings("serial") + public void test_getW() throws Exception { + KeyPairGenerator gen = KeyPairGenerator.getInstance("EC", Util.prov); + gen.initialize(Util.ecParam, new SecureRandom(new MySecureRandomSpi(), + null) { + }); + ECPublicKey key = (ECPublicKey) gen.generateKeyPair().getPublic(); + assertECPointEquals(new ECPoint(BigInteger.valueOf(4), + BigInteger.valueOf(15)), key.getW()); + } + + private void assertECPointEquals(ECPoint expected, ECPoint actual) { + assertEquals("X coordiates are different", expected.getAffineX(), + actual.getAffineX()); + assertEquals("Y coordiates are different", expected.getAffineY(), + actual.getAffineY()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/RSAKeyTest.java b/security/src/test/java/tests/security/interfaces/RSAKeyTest.java new file mode 100644 index 0000000..6aaebaf --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/RSAKeyTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.interfaces.RSAKey; +import java.security.spec.RSAPrivateKeySpec; +import java.security.spec.RSAPublicKeySpec; + +@TestTargetClass(RSAKey.class) +public class RSAKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.RSAKey + * #getModulus() + * test covers following use cases + * Case 1: check private key + * Case 2: check public key + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getModulus", + methodArgs = {} + ) + }) + public void test_getModulus() throws Exception { + KeyFactory gen = KeyFactory.getInstance("RSA", Util.prov); + final BigInteger n = BigInteger.valueOf(3233); + final BigInteger d = BigInteger.valueOf(2753); + final BigInteger e = BigInteger.valueOf(17); + RSAKey key = null; + + // Case 1: check private key + key = (RSAKey) gen.generatePrivate(new RSAPrivateKeySpec(n, d)); + assertEquals("invalid modulus", n, key.getModulus()); + + // Case 2: check public key + key = (RSAKey) gen.generatePublic(new RSAPublicKeySpec(n, e)); + assertEquals("invalid modulus", n, key.getModulus()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/RSAPrivateCrtKeyTest.java b/security/src/test/java/tests/security/interfaces/RSAPrivateCrtKeyTest.java new file mode 100644 index 0000000..466f095 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/RSAPrivateCrtKeyTest.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.KeyFactory; +import java.security.interfaces.RSAPrivateCrtKey; + +@TestTargetClass(RSAPrivateCrtKey.class) +public class RSAPrivateCrtKeyTest extends TestCase { + + RSAPrivateCrtKey key = null; + + protected void setUp() throws Exception { + super.setUp(); + KeyFactory gen = KeyFactory.getInstance("RSA", Util.prov); + key = (RSAPrivateCrtKey) gen.generatePrivate(Util.rsaCrtParam); + } + + /** + * @tests java.security.interfaces.RSAPrivateCrtKey + * #getCrtCoefficient() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCrtCoefficient", + methodArgs = {} + ) + }) + public void test_getCrtCoefficient() { + assertEquals("invalid CRT coefficient", + Util.rsaCrtParam.getCrtCoefficient(), key.getCrtCoefficient()); + } + + /** + * @tests java.security.interfaces.RSAPrivateCrtKey + * #getPrimeExponentP() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeExponentP", + methodArgs = {} + ) + }) + public void test_getPrimeExponentP() { + assertEquals("invalid prime exponent P", + Util.rsaCrtParam.getPrimeExponentP(), key.getPrimeExponentP()); + } + + /** + * @tests java.security.interfaces.RSAPrivateCrtKey + * #getPrimeExponentQ() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeExponentQ", + methodArgs = {} + ) + }) + public void test_getPrimeExponentQ() { + assertEquals("invalid prime exponent Q", + Util.rsaCrtParam.getPrimeExponentQ(), key.getPrimeExponentQ()); + } + + /** + * @tests java.security.interfaces.RSAPrivateCrtKey + * #getPrimeP() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeP", + methodArgs = {} + ) + }) + public void test_getPrimeP() { + assertEquals("invalid prime P", + Util.rsaCrtParam.getPrimeP(), key.getPrimeP()); + } + + /** + * @tests java.security.interfaces.RSAPrivateCrtKey + * #getPrimeQ() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeQ", + methodArgs = {} + ) + }) + public void test_getPrimeQ() { + assertEquals("invalid prime Q", + Util.rsaCrtParam.getPrimeQ(), key.getPrimeQ()); + } + + /** + * @tests java.security.interfaces.RSAPrivateCrtKey + * #getPublicExponent() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicExponent", + methodArgs = {} + ) + }) + public void test_getPublicExponent() { + assertEquals("invalid public exponent", + Util.rsaCrtParam.getPublicExponent(), key.getPublicExponent()); + } + + protected void tearDown() throws Exception { + key = null; + super.tearDown(); + } +} diff --git a/security/src/test/java/tests/security/interfaces/RSAPrivateKeyTest.java b/security/src/test/java/tests/security/interfaces/RSAPrivateKeyTest.java new file mode 100644 index 0000000..5fb2096 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/RSAPrivateKeyTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.interfaces.RSAPrivateKey; +import java.security.spec.RSAPrivateKeySpec; + +@TestTargetClass(RSAPrivateKey.class) +public class RSAPrivateKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.RSAPrivateKey + * #getPrivateExponent() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateExponent", + methodArgs = {} + ) + }) + public void test_getPrivateExponent() throws Exception { + KeyFactory gen = KeyFactory.getInstance("RSA", Util.prov); + final BigInteger n = BigInteger.valueOf(3233); + final BigInteger d = BigInteger.valueOf(2753); + RSAPrivateKey key = (RSAPrivateKey) gen.generatePrivate(new RSAPrivateKeySpec( + n, d)); + assertEquals("invalid private exponent", d, key.getPrivateExponent()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/RSAPublicKeyTest.java b/security/src/test/java/tests/security/interfaces/RSAPublicKeyTest.java new file mode 100644 index 0000000..f87f982 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/RSAPublicKeyTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.RSAPublicKeySpec; + +@TestTargetClass(RSAPublicKey.class) +public class RSAPublicKeyTest extends TestCase { + + /** + * @tests java.security.interfaces.RSAPublicKey + * #getPublicExponent() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicExponent", + methodArgs = {} + ) + }) + public void test_getPublicExponent() throws Exception { + KeyFactory gen = KeyFactory.getInstance("RSA", Util.prov); + final BigInteger n = BigInteger.valueOf(3233); + final BigInteger e = BigInteger.valueOf(17); + RSAPublicKey key = (RSAPublicKey) gen.generatePublic(new RSAPublicKeySpec( + n, e)); + assertEquals("invalid public exponent", e, key.getPublicExponent()); + } +} diff --git a/security/src/test/java/tests/security/interfaces/Util.java b/security/src/test/java/tests/security/interfaces/Util.java new file mode 100644 index 0000000..c1f3bb7 --- /dev/null +++ b/security/src/test/java/tests/security/interfaces/Util.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests.security.interfaces; +import java.math.BigInteger; +import java.security.Provider; +import java.security.SecureRandomSpi; +import java.security.spec.ECFieldFp; +import java.security.spec.ECParameterSpec; +import java.security.spec.ECPoint; +import java.security.spec.EllipticCurve; +import java.security.spec.RSAPrivateCrtKeySpec; + +/** + * Utility class to provide some constants + */ +class Util { + + /** + * BouncyCastle provider + */ + static final Provider prov = new org.bouncycastle.jce.provider.BouncyCastleProvider(); + + /** + * Valid P for DSA tests + */ + static final BigInteger P = new BigInteger( + "178479572281896551646004364479186243274554253442971675202712037168" + + "82805439171286757012622742273566628953929784385654859898" + + "28019943266498970695878014699423565775500281013661604573" + + "09351370942441879889477647669664876805999161358675121909" + + "02875461840550932624652402732307184862051812119809510467" + + "6997149499533466361"); + + /** + * Valid Q for DSA tests + */ + static final BigInteger Q = new BigInteger( + "764905408100544417452957057404815852894534709423"); + + /** + * Valid G for DSA tests + */ + static final BigInteger G = new BigInteger( + "250346303870482828530842176986393415513071912937041425322012361012" + + "16575725689706821855929265075265423817009497798948914793" + + "36272769721567876826949070538671438636626715308216064610" + + "91161573885991070984580607652541845127399865661520191726" + + "47818913386618968229835178446104566543814577436312685021" + + "713979414153557537"); + + /** + * Value returned using MySecureRandomSpi + */ + static final BigInteger RND_RET = new BigInteger("10"); + + /** + * Valid RSA parameters + */ + static final RSAPrivateCrtKeySpec rsaCrtParam = new RSAPrivateCrtKeySpec( + BigInteger.valueOf(3233), BigInteger.valueOf(17), + BigInteger.valueOf(2753), BigInteger.valueOf(61), + BigInteger.valueOf(53), BigInteger.valueOf(53), + BigInteger.valueOf(49), BigInteger.valueOf(52)); + + /** + * Valid EC parameters + */ + static final ECParameterSpec ecParam = new ECParameterSpec( + new EllipticCurve( + new ECFieldFp(BigInteger.valueOf(23)), + BigInteger.valueOf(5), BigInteger.valueOf(3)), + new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(3)), + BigInteger.valueOf(23), 1); + + private Util() { + } +} + +/** + * Utility class to provide "random" data. + * Returned value is always constant 10 if converted to BigInteger + */ +@SuppressWarnings("serial") +class MySecureRandomSpi extends SecureRandomSpi { + + @Override + protected byte[] engineGenerateSeed(int arg0) { + return null; + } + + @Override + protected void engineNextBytes(byte[] bytes) { + java.util.Arrays.fill(bytes, (byte) 0); + bytes[bytes.length - 1] = (byte) 10; + } + + @Override + protected void engineSetSeed(byte[] arg0) { + return; + } +} + diff --git a/security/src/test/java/tests/security/permissions/JavaIoFileInputStreamTest.java b/security/src/test/java/tests/security/permissions/JavaIoFileInputStreamTest.java new file mode 100644 index 0000000..d9322ee --- /dev/null +++ b/security/src/test/java/tests/security/permissions/JavaIoFileInputStreamTest.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.permissions; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.IOException; + +/* + * This class tests the secrity permissions which are documented in + * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods + * for class java.io.FileInputStream and java.io.FileOutputStream + */ +@TestTargetClass(SecurityManager.class) +public class JavaIoFileInputStreamTest extends TestCase { + + SecurityManager old; + + @Override + protected void setUp() throws Exception { + old = System.getSecurityManager(); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + System.setSecurityManager(old); + super.tearDown(); + } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that FileDescriptor() constructor calls checkRead " + + "method of security manager.", + targets = { + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ), + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ) + }) + public void test_FileInputStream() throws IOException { + class TestSecurityManager extends SecurityManager { + boolean called; + String file; + FileDescriptor fd; + void reset(){ + called = false; + file = null; + fd = null; + } + @Override + public void checkRead(FileDescriptor fd) { + called = true; + this.fd = fd; + super.checkRead(fd); + } + @Override + public void checkRead(String file){ + called = true; + this.file = file; + super.checkRead(file); + } + } + + long id = new java.util.Date().getTime(); + String filename = "SecurityPermissionsTest_"+id; + File f = File.createTempFile(filename, null); + f.deleteOnExit(); + filename = f.getCanonicalPath(); + + TestSecurityManager s = new TestSecurityManager(); + System.setSecurityManager(s); + + s.reset(); + FileDescriptor fd = new FileDescriptor(); + new FileInputStream(fd); + assertTrue("FileDescriptor() ctor must call checkRead on security manager", s.called); + assertEquals("Argument of checkRead is not correct", fd, s.fd); + + s.reset(); + new FileInputStream(filename); + assertTrue("FileDescriptor() ctor must call checkRead on security manager", s.called); + assertEquals("Argument of checkRead is not correct", filename, s.file); + + s.reset(); + new FileInputStream(f); + assertTrue("FileDescriptor() ctor must call checkRead on security manager", s.called); + assertEquals("Argument of checkRead is not correct", filename, s.file); + } + +} diff --git a/security/src/test/java/tests/security/permissions/JavaIoFileOutputStreamTest.java b/security/src/test/java/tests/security/permissions/JavaIoFileOutputStreamTest.java new file mode 100644 index 0000000..8d4452d --- /dev/null +++ b/security/src/test/java/tests/security/permissions/JavaIoFileOutputStreamTest.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.permissions; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileOutputStream; +import java.io.IOException; + +/* + * This class tests the secrity permissions which are documented in + * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods + * for class java.io.FileInputStream and java.io.FileOutputStream + */ +@TestTargetClass(SecurityManager.class) +public class JavaIoFileOutputStreamTest extends TestCase { + + SecurityManager old; + + @Override + protected void setUp() throws Exception { + old = System.getSecurityManager(); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + System.setSecurityManager(old); + super.tearDown(); + } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that FileOutputStream constructor calls checkRead " + + "method of security manager.", + targets = { + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ), + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ) + }) + public void test_FileOutputStream1() throws IOException { + class TestSecurityManager extends SecurityManager { + boolean called; + String file; + FileDescriptor fd; + void reset(){ + called = false; + file = null; + fd = null; + } + @Override + public void checkWrite(FileDescriptor fd) { + called = true; + this.fd = fd; + super.checkWrite(fd); + } + @Override + public void checkWrite(String file){ + called = true; + this.file = file; + super.checkWrite(file); + } + } + + long id = new java.util.Date().getTime(); + String filename = "SecurityPermissionsTest_"+id; + File f = File.createTempFile(filename, null); + f.deleteOnExit(); + filename = f.getCanonicalPath(); + + TestSecurityManager s = new TestSecurityManager(); + System.setSecurityManager(s); + + s.reset(); + FileDescriptor fd = new FileDescriptor(); + new FileOutputStream(fd); + assertTrue("FileOutputStream(FileDescriptor) ctor must call checkWrite on security manager", s.called); + assertEquals("Argument of checkWrite is not correct", fd, s.fd); + + s.reset(); + new FileOutputStream(f); + assertTrue("FileOutputStream(File) ctor must call checkWrite on security manager", s.called); + assertEquals("Argument of checkWrite is not correct", filename, s.file); + + s.reset(); + new FileOutputStream(filename); + assertTrue("FileOutputStream(String) ctor must call checkWrite on security manager", s.called); + assertEquals("Argument of checkWrite is not correct", filename, s.file); + + s.reset(); + new FileOutputStream(filename, true); + assertTrue("FileOutputStream(String,boolean) ctor must call checkWrite on security manager", s.called); + assertEquals("Argument of checkWrite is not correct", filename, s.file); + } + +} diff --git a/security/src/test/java/tests/security/permissions/JavaIoFileTest.java b/security/src/test/java/tests/security/permissions/JavaIoFileTest.java index d0e4982..84b99b6 100644 --- a/security/src/test/java/tests/security/permissions/JavaIoFileTest.java +++ b/security/src/test/java/tests/security/permissions/JavaIoFileTest.java @@ -16,18 +16,24 @@ package tests.security.permissions; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; import java.io.IOException; -import junit.framework.TestCase; - /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.io.File. */ +@TestTargetClass(SecurityManager.class) public class JavaIoFileTest extends TestCase { SecurityManager old; @@ -44,7 +50,16 @@ public class JavaIoFileTest extends TestCase { super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that File.delete and File.deleteOnExit methods " + + "call checkDelete method of security manager.", + targets = { + @TestTarget( + methodName = "checkDelete", + methodArgs = {java.lang.String.class} + ) + }) public void test_File1() throws IOException { class TestSecurityManager extends SecurityManager { boolean called; @@ -83,7 +98,18 @@ public class JavaIoFileTest extends TestCase { assertEquals("Argument of checkDelete is not correct", filename, s.filename); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that File.exists(), File.canRead(), File.isFile(), " + + "File.isDirectory(), File.isHidden(), File.lastModified(), " + + "File.length(), File.list(...), File.listFiles(...) methods " + + "call checkRead method of security manager.", + targets = { + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ) + }) public void test_File2() throws IOException { class TestSecurityManager extends SecurityManager { boolean called; @@ -170,7 +196,16 @@ public class JavaIoFileTest extends TestCase { assertEquals("Argument of checkRead is not correct", filename, s.file); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that write/create methods of File class call " + + "checkWrite method of security manager.", + targets = { + @TestTarget( + methodName = "checkWrite", + methodArgs = {java.lang.String.class} + ) + }) public void test_File3() throws IOException { class TestSecurityManager extends SecurityManager { boolean called; diff --git a/security/src/test/java/tests/security/permissions/JavaIoObjectInputStreamTest.java b/security/src/test/java/tests/security/permissions/JavaIoObjectInputStreamTest.java new file mode 100644 index 0000000..71e769b --- /dev/null +++ b/security/src/test/java/tests/security/permissions/JavaIoObjectInputStreamTest.java @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.permissions; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.NotActiveException; +import java.io.ObjectInputStream; +import java.io.SerializablePermission; +import java.io.StreamCorruptedException; +import java.security.Permission; + +/* + * This class tests the secrity permissions which are documented in + * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods + * for classes + * java.io.ObjectInputStream + * java.io.ObjectOutputStream + */ +@TestTargetClass(SecurityManager.class) +public class JavaIoObjectInputStreamTest extends TestCase { + + SecurityManager old; + + @Override + protected void setUp() throws Exception { + old = System.getSecurityManager(); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + System.setSecurityManager(old); + super.tearDown(); + } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that ObjectInputStream.enableResolveObject method " + + "calls checkPermission of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) + public void test_ObjectInputStream() throws IOException { + class TestSecurityManager extends SecurityManager { + boolean called; + Permission permission; + void reset(){ + called = false; + permission = null; + } + @Override + public void checkPermission(Permission permission){ + if(permission instanceof SerializablePermission){ + called = true; + this.permission = permission; + } + super.checkPermission(permission); + } + } + + // TestObjectInputStream is necessary in order to call enableResolveObject + class TestObjectInputStream extends ObjectInputStream { + TestObjectInputStream(InputStream s) throws StreamCorruptedException, IOException { + super(s); + } + @Override + public boolean enableResolveObject(boolean enable) throws SecurityException { + return super.enableResolveObject(enable); + } + } + + long id = new java.util.Date().getTime(); + String filename = "SecurityPermissionsTest_"+id; + File f = File.createTempFile(filename, null); + f.deleteOnExit(); + + TestObjectInputStream ois = new TestObjectInputStream(new FileInputStream(f)); + + TestSecurityManager s = new TestSecurityManager(); + System.setSecurityManager(s); + + s.reset(); + ois.enableResolveObject(true); + assertTrue("ObjectInputStream.enableResolveObject(boolean) must call checkPermission on security manager", s.called); + assertEquals("Name of SerializablePermission is not correct", "enableSubstitution", s.permission.getName()); + } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that ObjectInputStream constructor calls " + + "checkPermission method of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) + public void test_ObjectInputOutputStream() throws IOException { + class TestSecurityManager extends SecurityManager { + boolean called; + Permission permission; + void reset(){ + called = false; + permission = null; + } + @Override + public void checkPermission(Permission permission){ + if(permission instanceof SerializablePermission){ + called = true; + this.permission = permission; + } + super.checkPermission(permission); + } + } + + // Beginning with J2SE 1.4.0, ObjectOutputStream's public one-argument constructor + // requires the "enableSubclassImplementation" SerializablePermission when invoked + // (either directly or indirectly) by a subclass which overrides + // ObjectOutputStream.putFields or ObjectOutputStream.writeUnshared. + // + // Also beginning with J2SE 1.4.0, ObjectInputStream's public one-argument + // constructor requires the "enableSubclassImplementation" SerializablePermission + // when invoked (either directly or indirectly) by a subclass which overrides + // ObjectInputStream.readFields or ObjectInputStream.readUnshared. + + + class TestObjectInputStream extends ObjectInputStream { + TestObjectInputStream(InputStream s) throws StreamCorruptedException, IOException { + super(s); + } + } + + class TestObjectInputStream_readFields extends ObjectInputStream { + TestObjectInputStream_readFields(InputStream s) throws StreamCorruptedException, IOException { + super(s); + } + @Override + public GetField readFields() throws IOException, ClassNotFoundException, NotActiveException { + return super.readFields(); + } + } + + class TestObjectInputStream_readUnshared extends ObjectInputStream { + TestObjectInputStream_readUnshared(InputStream s) throws StreamCorruptedException, IOException { + super(s); + } + @Override + public Object readUnshared() throws IOException, ClassNotFoundException { + return super.readUnshared(); + } + } + + + long id = new java.util.Date().getTime(); + String filename = "SecurityPermissionsTest_"+id; + File f = File.createTempFile(filename, null); + f.deleteOnExit(); + + TestSecurityManager s = new TestSecurityManager(); + System.setSecurityManager(s); + + s.reset(); + new ObjectInputStream(new FileInputStream(f)); + assertTrue("ObjectInputStream(InputStream) ctor must not call checkPermission on security manager on a class which neither overwrites methods readFields nor readUnshared", !s.called); + + s.reset(); + new TestObjectInputStream(new FileInputStream(f)); + assertTrue("ObjectInputStream(InputStream) ctor must not call checkPermission on security manager on a class which neither overwrites methods readFields nor readUnshared", !s.called); + + s.reset(); + new TestObjectInputStream_readFields(new FileInputStream(f)); + assertTrue("ObjectInputStream(InputStream) ctor must call checkPermission on security manager on a class which overwrites method readFields", s.called); + assertEquals("Name of SerializablePermission is not correct", "enableSubclassImplementation", s.permission.getName()); + + s.reset(); + new TestObjectInputStream_readUnshared(new FileInputStream(f)); + assertTrue("ObjectInputStream(InputStream) ctor must call checkPermission on security manager on a class which overwrites method readUnshared", s.called); + assertEquals("Name of SerializablePermission is not correct", "enableSubclassImplementation", s.permission.getName()); + } + +} diff --git a/security/src/test/java/tests/security/permissions/JavaIoObjectOutputStreamTest.java b/security/src/test/java/tests/security/permissions/JavaIoObjectOutputStreamTest.java new file mode 100644 index 0000000..0ec2f09 --- /dev/null +++ b/security/src/test/java/tests/security/permissions/JavaIoObjectOutputStreamTest.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.permissions; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.SerializablePermission; +import java.io.StreamCorruptedException; +import java.security.Permission; + +/* + * This class tests the secrity permissions which are documented in + * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods + * for classes + * java.io.ObjectInputStream + * java.io.ObjectOutputStream + */ +@TestTargetClass(SecurityManager.class) +public class JavaIoObjectOutputStreamTest extends TestCase { + + SecurityManager old; + + @Override + protected void setUp() throws Exception { + old = System.getSecurityManager(); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + System.setSecurityManager(old); + super.tearDown(); + } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that enableReplaceObject(boolean) method calls " + + "checkPermission on security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) + public void test_ObjectOutputStream() throws IOException { + class TestSecurityManager extends SecurityManager { + boolean called; + Permission permission; + void reset(){ + called = false; + permission = null; + } + @Override + public void checkPermission(Permission permission){ + if(permission instanceof SerializablePermission){ + called = true; + this.permission = permission; + } + super.checkPermission(permission); + } + } + + // TestObjectOutputStream is necessary in order to call enableReplaceObject + class TestObjectOutputStream extends ObjectOutputStream { + TestObjectOutputStream(OutputStream s) throws StreamCorruptedException, IOException { + super(s); + } + @Override + public boolean enableReplaceObject(boolean enable) throws SecurityException { + return super.enableReplaceObject(enable); + } + } + + long id = new java.util.Date().getTime(); + String filename = "SecurityPermissionsTest_"+id; + File f = File.createTempFile(filename, null); + f.deleteOnExit(); + + TestObjectOutputStream ois = new TestObjectOutputStream(new FileOutputStream(f)); + + TestSecurityManager s = new TestSecurityManager(); + System.setSecurityManager(s); + + s.reset(); + ois.enableReplaceObject(true); + assertTrue("ObjectOutputStream.enableReplaceObject(boolean) must call checkPermission on security manager", s.called); + assertEquals("Name of SerializablePermission is not correct", "enableSubstitution", s.permission.getName()); + } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that ObjectOutputStream constructor calls " + + "checkPermission of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) + public void test_ObjectInputOutputStream() throws IOException { + class TestSecurityManager extends SecurityManager { + boolean called; + Permission permission; + void reset(){ + called = false; + permission = null; + } + @Override + public void checkPermission(Permission permission){ + if(permission instanceof SerializablePermission){ + called = true; + this.permission = permission; + } + super.checkPermission(permission); + } + } + + // Beginning with J2SE 1.4.0, ObjectOutputStream's public one-argument constructor + // requires the "enableSubclassImplementation" SerializablePermission when invoked + // (either directly or indirectly) by a subclass which overrides + // ObjectOutputStream.putFields or ObjectOutputStream.writeUnshared. + // + // Also beginning with J2SE 1.4.0, ObjectInputStream's public one-argument + // constructor requires the "enableSubclassImplementation" SerializablePermission + // when invoked (either directly or indirectly) by a subclass which overrides + // ObjectInputStream.readFields or ObjectInputStream.readUnshared. + + class TestObjectOutputStream extends ObjectOutputStream { + TestObjectOutputStream(OutputStream s) throws StreamCorruptedException, IOException { + super(s); + } + } + + class TestObjectOutputStream_putFields extends ObjectOutputStream { + TestObjectOutputStream_putFields(OutputStream s) throws StreamCorruptedException, IOException { + super(s); + } + @Override + public PutField putFields() throws IOException { + return super.putFields(); + } + } + + class TestObjectOutputStream_writeUnshared extends ObjectOutputStream { + TestObjectOutputStream_writeUnshared(OutputStream s) throws StreamCorruptedException, IOException { + super(s); + } + @Override + public void writeUnshared(Object object) throws IOException { + super.writeUnshared(object); + } + + } + + long id = new java.util.Date().getTime(); + String filename = "SecurityPermissionsTest_"+id; + File f = File.createTempFile(filename, null); + f.deleteOnExit(); + + TestSecurityManager s = new TestSecurityManager(); + System.setSecurityManager(s); + + s.reset(); + new ObjectOutputStream(new FileOutputStream(f)); + assertTrue("ObjectOutputStream(OutputStream) ctor must not call checkPermission on security manager on a class which neither overwrites writeUnshared nor putFields", !s.called); + + s.reset(); + new TestObjectOutputStream(new FileOutputStream(f)); + assertTrue("ObjectOutputStream(OutputStream) ctor must not call checkPermission on security manager on a class which neither overwrites writeUnshared nor putFields", !s.called); + + s.reset(); + new TestObjectOutputStream_writeUnshared(new FileOutputStream(f)); + assertTrue("ObjectOutputStream(OutputStream) ctor must call checkPermission on security manager on a class which overwrites method writeUnshared", s.called); + assertEquals("Name of SerializablePermission is not correct", "enableSubclassImplementation", s.permission.getName()); + + s.reset(); + new TestObjectOutputStream_putFields(new FileOutputStream(f)); + assertTrue("ObjectOutputStream(OutputStream) ctor must call checkPermission on security manager on a class which overwrites method putFields", s.called); + assertEquals("Name of SerializablePermission is not correct", "enableSubclassImplementation", s.permission.getName()); + + } + +} diff --git a/security/src/test/java/tests/security/permissions/JavaIoRandomAccessFileTest.java b/security/src/test/java/tests/security/permissions/JavaIoRandomAccessFileTest.java index eab6cb2..5d59862 100644 --- a/security/src/test/java/tests/security/permissions/JavaIoRandomAccessFileTest.java +++ b/security/src/test/java/tests/security/permissions/JavaIoRandomAccessFileTest.java @@ -16,17 +16,22 @@ package tests.security.permissions; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.io.RandomAccessFile */ +@TestTargetClass(SecurityManager.class) public class JavaIoRandomAccessFileTest extends TestCase { SecurityManager old; @@ -43,6 +48,16 @@ public class JavaIoRandomAccessFileTest extends TestCase { super.tearDown(); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that RandomAccessFile constructor calls checkRead " + + "method of security manager.", + targets = { + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ) + }) public void test_RandomAccessFile1() throws IOException { class TestSecurityManager extends SecurityManager { boolean called; @@ -79,7 +94,20 @@ public class JavaIoRandomAccessFileTest extends TestCase { assertEquals("Argument of checkRead is not correct", filename, s.file); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that RandomAccessFile constructor calls " + + "checkReadFile, checkWriteFile methods of security manager.", + targets = { + @TestTarget( + methodName = "checkRead", + methodArgs = {java.lang.String.class} + ), + @TestTarget( + methodName = "checkWrite", + methodArgs = {java.lang.String.class} + ) + }) public void test_RandomAccessFile2() throws IOException { class TestSecurityManager extends SecurityManager { boolean checkReadCalled; diff --git a/security/src/test/java/tests/security/permissions/JavaLangClassLoaderTest.java b/security/src/test/java/tests/security/permissions/JavaLangClassLoaderTest.java index 42747a6..8ab0a24 100644 --- a/security/src/test/java/tests/security/permissions/JavaLangClassLoaderTest.java +++ b/security/src/test/java/tests/security/permissions/JavaLangClassLoaderTest.java @@ -16,15 +16,21 @@ package tests.security.permissions; -import java.security.Permission; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.security.Permission; + /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.lang.ClassLoader */ +@TestTargetClass(SecurityManager.class) public class JavaLangClassLoaderTest extends TestCase { SecurityManager old; @@ -41,7 +47,16 @@ public class JavaLangClassLoaderTest extends TestCase { super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that ClassLoader constructor calls " + + "checkCreateClassLoader of security manager.", + targets = { + @TestTarget( + methodName = "checkCreateClassLoader", + methodArgs = {} + ) + }) public void test_ClassLoaderCtor () { class TestSecurityManager extends SecurityManager { boolean called; @@ -72,6 +87,16 @@ public class JavaLangClassLoaderTest extends TestCase { assertTrue("ClassLoader ctor must call checkCreateClassLoader on security manager", s.called); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that ClassLoader.getSystemClassLoader() checks " + + "RuntimePermission(getClassLoader) of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_getSystemClassLoader () { class TestSecurityManager extends SecurityManager { boolean called; diff --git a/security/src/test/java/tests/security/permissions/JavaLangClassTest.java b/security/src/test/java/tests/security/permissions/JavaLangClassTest.java index fada38f..7f68710 100644 --- a/security/src/test/java/tests/security/permissions/JavaLangClassTest.java +++ b/security/src/test/java/tests/security/permissions/JavaLangClassTest.java @@ -16,15 +16,21 @@ package tests.security.permissions; -import java.security.Permission; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.security.Permission; + /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.lang.Class */ +@TestTargetClass(java.lang.SecurityManager.class) public class JavaLangClassTest extends TestCase { SecurityManager old; @@ -41,7 +47,16 @@ public class JavaLangClassTest extends TestCase { super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that Class.getProtectionDomain() checks " + + "RuntimePermission of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_getProtectionDomain () { class TestSecurityManager extends SecurityManager { boolean called; @@ -67,7 +82,16 @@ public class JavaLangClassTest extends TestCase { c.getProtectionDomain(); assertTrue("Class.getProtectionDomain() must check RuntimePermission(\"getProtectionDomain\") on security manager", s.called); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that forName(String,boolean,Classloader) method " + + "checks RuntimePermission(getClassLoader) of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_Class() throws ClassNotFoundException { class TestSecurityManager extends SecurityManager { boolean called; diff --git a/security/src/test/java/tests/security/permissions/JavaLangSystemTest.java b/security/src/test/java/tests/security/permissions/JavaLangSystemTest.java index 8ac3a30..a1b6dc4 100644 --- a/security/src/test/java/tests/security/permissions/JavaLangSystemTest.java +++ b/security/src/test/java/tests/security/permissions/JavaLangSystemTest.java @@ -16,19 +16,24 @@ package tests.security.permissions; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + import java.io.InputStream; import java.io.PrintStream; import java.security.Permission; import java.util.Properties; import java.util.PropertyPermission; - -import junit.framework.TestCase; - /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.lang.System */ +@TestTargetClass(java.lang.SecurityManager.class) public class JavaLangSystemTest extends TestCase { SecurityManager old; @@ -44,7 +49,16 @@ public class JavaLangSystemTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getProperties calls checkPropertiesAccess " + + "method of security manager.", + targets = { + @TestTarget( + methodName = "checkPropertiesAccess", + methodArgs = {} + ) + }) public void test_Properties() { class TestSecurityManager extends SecurityManager { boolean called; @@ -71,7 +85,16 @@ public class JavaLangSystemTest extends TestCase { System.setProperties(props); assertTrue("System.setProperties must call checkPropertiesAccess on security manager", s.called); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that System.getProperty calls checkPropertyAccess on " + + "security manager.", + targets = { + @TestTarget( + methodName = "checkPropertyAccess", + methodArgs = {java.lang.String.class} + ) + }) public void test_getProperty() { class TestSecurityManager extends SecurityManager { boolean called; @@ -103,7 +126,16 @@ public class JavaLangSystemTest extends TestCase { assertTrue("System.getProperty must call checkPropertyAccess on security manager", s.called); assertEquals("Argument of checkPropertyAccess is not correct", "key", s.key); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that System.setProperty method calls " + + "checkPermission of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_setProperty() { class TestSecurityManager extends SecurityManager { boolean called; @@ -130,7 +162,16 @@ public class JavaLangSystemTest extends TestCase { assertTrue("System.setProperty must call checkPermission on security manager", s.called); assertEquals("Argument of checkPermission is not correct", new PropertyPermission("key", "write"), s.p); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that System.setSecurityManager method checks " + + "security permissions.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_setSecurityManager() { class TestSecurityManager extends SecurityManager { boolean called = false; @@ -149,7 +190,16 @@ public class JavaLangSystemTest extends TestCase { System.setSecurityManager(s); assertTrue("System.setSecurityManager must check security permissions", s.called); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that setIn/Out/Err methods call checkPermission " + + "method of security manager.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_setInOutErr() { class TestSecurityManager extends SecurityManager { boolean called; diff --git a/security/src/test/java/tests/security/permissions/JavaNetDatagramSocketTest.java b/security/src/test/java/tests/security/permissions/JavaNetDatagramSocketTest.java index b7e4a6c..f4a815a 100644 --- a/security/src/test/java/tests/security/permissions/JavaNetDatagramSocketTest.java +++ b/security/src/test/java/tests/security/permissions/JavaNetDatagramSocketTest.java @@ -16,19 +16,25 @@ package tests.security.permissions; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.InetSocketAddress; -import junit.framework.TestCase; - /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.net.DatagramSocket */ +@TestTargetClass(SecurityManager.class) public class JavaNetDatagramSocketTest extends TestCase { SecurityManager old; @@ -44,7 +50,16 @@ public class JavaNetDatagramSocketTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.net.DatagramSocket constructor calls " + + "checkListen of security manager.", + targets = { + @TestTarget( + methodName = "checkListen", + methodArgs = {int.class} + ) + }) public void test_ctor() throws IOException { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/permissions/JavaNetMulticastSocketTest.java b/security/src/test/java/tests/security/permissions/JavaNetMulticastSocketTest.java index cab7b04..cb5be59 100644 --- a/security/src/test/java/tests/security/permissions/JavaNetMulticastSocketTest.java +++ b/security/src/test/java/tests/security/permissions/JavaNetMulticastSocketTest.java @@ -16,16 +16,22 @@ package tests.security.permissions; -import java.io.IOException; -import java.net.MulticastSocket; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.io.IOException; +import java.net.MulticastSocket; + /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.net.MulticastSocket */ +@TestTargetClass(SecurityManager.class) public class JavaNetMulticastSocketTest extends TestCase { SecurityManager old; @@ -41,7 +47,16 @@ public class JavaNetMulticastSocketTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.net.MulticastSocket(int) consructor calls " + + "checkListen of security permissions.", + targets = { + @TestTarget( + methodName = "checkListen", + methodArgs = {int.class} + ) + }) public void test_ctor() throws IOException { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/permissions/JavaNetServerSocketTest.java b/security/src/test/java/tests/security/permissions/JavaNetServerSocketTest.java index 2e43038..b3d39a6 100644 --- a/security/src/test/java/tests/security/permissions/JavaNetServerSocketTest.java +++ b/security/src/test/java/tests/security/permissions/JavaNetServerSocketTest.java @@ -16,16 +16,21 @@ package tests.security.permissions; -import java.io.IOException; -import java.net.ServerSocket; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.io.IOException; +import java.net.ServerSocket; /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.net.ServerSocket */ +@TestTargetClass(SecurityManager.class) public class JavaNetServerSocketTest extends TestCase { SecurityManager old; @@ -41,7 +46,16 @@ public class JavaNetServerSocketTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.net.ServerSocket constructor calls " + + "checkListen of security permissions.", + targets = { + @TestTarget( + methodName = "checkListen", + methodArgs = {int.class} + ) + }) public void test_ctor() throws IOException { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/permissions/JavaNetSocketTest.java b/security/src/test/java/tests/security/permissions/JavaNetSocketTest.java index 97a7519..8ba8f06 100644 --- a/security/src/test/java/tests/security/permissions/JavaNetSocketTest.java +++ b/security/src/test/java/tests/security/permissions/JavaNetSocketTest.java @@ -16,16 +16,21 @@ package tests.security.permissions; -import java.io.IOException; -import java.net.Socket; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.io.IOException; +import java.net.Socket; /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.net.Socket */ +@TestTargetClass(SecurityManager.class) public class JavaNetSocketTest extends TestCase { SecurityManager old; @@ -41,7 +46,16 @@ public class JavaNetSocketTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.net.ServerSocket constructor calls " + + "checkConnect of security permissions.", + targets = { + @TestTarget( + methodName = "checkConnect", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void test_ctor() throws IOException { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/permissions/JavaSecurityPolicyTest.java b/security/src/test/java/tests/security/permissions/JavaSecurityPolicyTest.java index f3e9bbd..a28c340 100644 --- a/security/src/test/java/tests/security/permissions/JavaSecurityPolicyTest.java +++ b/security/src/test/java/tests/security/permissions/JavaSecurityPolicyTest.java @@ -16,17 +16,22 @@ package tests.security.permissions; -import java.security.Permission; -import java.security.Policy; -import java.security.SecurityPermission; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.security.Permission; +import java.security.Policy; +import java.security.SecurityPermission; /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.security.Policy */ +@TestTargetClass(SecurityManager.class) public class JavaSecurityPolicyTest extends TestCase { SecurityManager old; @@ -42,7 +47,16 @@ public class JavaSecurityPolicyTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.security.Policy.getPolicy() method calls " + + "checkPermission of security permissions.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_getPolicy() { class TestSecurityManager extends SecurityManager { boolean called = false; @@ -65,7 +79,16 @@ public class JavaSecurityPolicyTest extends TestCase { Policy.getPolicy(); assertTrue("java.security.Policy.getPolicy() must call checkPermission on security permissions", s.called); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.security.Policy.setPolicy() method calls " + + "checkPermission on security permissions.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_setPolicy() { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/permissions/JavaSecuritySecurityTest.java b/security/src/test/java/tests/security/permissions/JavaSecuritySecurityTest.java index 30a7774..c65886c 100644 --- a/security/src/test/java/tests/security/permissions/JavaSecuritySecurityTest.java +++ b/security/src/test/java/tests/security/permissions/JavaSecuritySecurityTest.java @@ -16,20 +16,25 @@ package tests.security.permissions; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + import java.security.Permission; import java.security.Provider; import java.security.Security; import java.security.SecurityPermission; import java.util.HashSet; import java.util.Set; - -import junit.framework.TestCase; - /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.security.Security */ +@TestTargetClass(SecurityManager.class) public class JavaSecuritySecurityTest extends TestCase { SecurityManager old; @@ -45,7 +50,16 @@ public class JavaSecuritySecurityTest extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that getProperty() method calls checkPermission " + + "method of security permissions.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_getProperty() { class TestSecurityManager extends SecurityManager { boolean called = false; @@ -69,6 +83,16 @@ public class JavaSecuritySecurityTest extends TestCase { assertTrue("java.security.Security.getProperty() must call checkPermission on security permissions", s.called); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that setProperty() method calls checkSecurityAccess " + + "method of security manager.", + targets = { + @TestTarget( + methodName = "checkSecurityAccess", + methodArgs = {java.lang.String.class} + ) + }) public void test_setProperty() { class TestSecurityManager extends SecurityManager { boolean called = false; @@ -93,7 +117,16 @@ public class JavaSecuritySecurityTest extends TestCase { assertTrue("java.security.Security.setProperty() must call checkSecurityAccess on security manager", s.called); assertEquals("Argument of checkSecurityAccess is not correct", "setProperty.key", s.target); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that addProvider(), removeProvider() methods call " + + "checkSecurityAccess method of security manager.", + targets = { + @TestTarget( + methodName = "checkSecurityAccess", + methodArgs = {java.lang.String.class} + ) + }) public void test_Provider() { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/permissions/JavaUtilLocale.java b/security/src/test/java/tests/security/permissions/JavaUtilLocale.java index e0562b1..9f992c6 100644 --- a/security/src/test/java/tests/security/permissions/JavaUtilLocale.java +++ b/security/src/test/java/tests/security/permissions/JavaUtilLocale.java @@ -16,17 +16,22 @@ package tests.security.permissions; -import java.security.Permission; -import java.util.Locale; -import java.util.PropertyPermission; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; import junit.framework.TestCase; +import java.security.Permission; +import java.util.Locale; +import java.util.PropertyPermission; /* * This class tests the secrity permissions which are documented in * http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html#PermsAndMethods * for class java.util.Locale */ +@TestTargetClass(SecurityManager.class) public class JavaUtilLocale extends TestCase { SecurityManager old; @@ -42,7 +47,16 @@ public class JavaUtilLocale extends TestCase { System.setSecurityManager(old); super.tearDown(); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that java.util.Locale.setDefault(Locale) method " + + "calls checkPermission method of security permissions.", + targets = { + @TestTarget( + methodName = "checkPermission", + methodArgs = {java.security.Permission.class} + ) + }) public void test_setDefault() { class TestSecurityManager extends SecurityManager { boolean called = false; diff --git a/security/src/test/java/tests/security/spec/AllTests.java b/security/src/test/java/tests/security/spec/AllTests.java new file mode 100644 index 0000000..b759882 --- /dev/null +++ b/security/src/test/java/tests/security/spec/AllTests.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.spec; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package tests.security.spec; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package tests.security.spec;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(DSAParameterSpecTest.class); + suite.addTestSuite(DSAPrivateKeySpecTest.class); + suite.addTestSuite(DSAPublicKeySpecTest.class); + suite.addTestSuite(ECFieldF2mTest.class); + suite.addTestSuite(ECFieldFpTest.class); + suite.addTestSuite(ECGenParameterSpecTest.class); + suite.addTestSuite(ECParameterSpecTest.class); + suite.addTestSuite(ECPointTest.class); + suite.addTestSuite(ECPrivateKeySpecTest.class); + suite.addTestSuite(ECPublicKeySpecTest.class); + suite.addTestSuite(EllipticCurveTest.class); + suite.addTestSuite(EncodedKeySpec2Test.class); + suite.addTestSuite(EncodedKeySpecTest.class); + suite.addTestSuite(InvalidKeySpecExceptionTest.class); + suite.addTestSuite(InvalidParameterSpecExceptionTest.class); + suite.addTestSuite(MGF1ParameterSpecTest.class); + suite.addTestSuite(PKCS8EncodedKeySpecTest.class); + suite.addTestSuite(PSSParameterSpecTest.class); + suite.addTestSuite(RSAKeyGenParameterSpecTest.class); + suite.addTestSuite(RSAMultiPrimePrivateCrtKeySpecTest.class); + suite.addTestSuite(RSAOtherPrimeInfoTest.class); + suite.addTestSuite(RSAPrivateCrtKeySpecTest.class); + suite.addTestSuite(RSAPrivateKeySpecTest.class); + suite.addTestSuite(RSAPublicKeySpecTest.class); + suite.addTestSuite(X509EncodedKeySpecTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/security/src/test/java/tests/security/spec/DSAParameterSpecTest.java b/security/src/test/java/tests/security/spec/DSAParameterSpecTest.java new file mode 100644 index 0000000..7e135b1 --- /dev/null +++ b/security/src/test/java/tests/security/spec/DSAParameterSpecTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.DSAParameterSpec; + +/** + * Tests for <code>DSAParameterSpec</code> + * + */ +@TestTargetClass(DSAParameterSpec.class) +public class DSAParameterSpecTest extends TestCase { + + /** + * Constructor for DSAParameterSpecTest. + * @param name + */ + public DSAParameterSpecTest(String name) { + super(name); + } + + /** + * Ctor test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "DSAParameterSpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testDSAParameterSpec() { + AlgorithmParameterSpec aps = new DSAParameterSpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3")); + + assertTrue(aps instanceof DSAParameterSpec); + } + + /** + * getG() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getG", + methodArgs = {} + ) + }) + public final void testGetG() { + DSAParameterSpec dps = new DSAParameterSpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3")); + + assertEquals(3, dps.getG().intValue()); + } + + /** + * getP() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getP", + methodArgs = {} + ) + }) + public final void testGetP() { + DSAParameterSpec dps = new DSAParameterSpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3")); + + assertEquals(1, dps.getP().intValue()); + } + + /** + * getQ() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getQ", + methodArgs = {} + ) + }) + public final void testGetQ() { + DSAParameterSpec dps = new DSAParameterSpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3")); + + assertEquals(2, dps.getQ().intValue()); + } +} diff --git a/security/src/test/java/tests/security/spec/DSAPrivateKeySpecTest.java b/security/src/test/java/tests/security/spec/DSAPrivateKeySpecTest.java new file mode 100644 index 0000000..ef80a58 --- /dev/null +++ b/security/src/test/java/tests/security/spec/DSAPrivateKeySpecTest.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.DSAPrivateKeySpec; +import java.security.spec.KeySpec; + +/** + * Tests for <code>DSAPrivateKeySpec</code> + * + */ +@TestTargetClass(DSAPrivateKeySpec.class) +public class DSAPrivateKeySpecTest extends TestCase { + + /** + * Constructor for DSAPrivateKeySpecTest. + * @param name + */ + public DSAPrivateKeySpecTest(String name) { + super(name); + } + + /** + * Test for constructor + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "DSAPrivateKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testDSAPrivateKeySpec() { + KeySpec ks = new DSAPrivateKeySpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3"), + new BigInteger("4")); + + assertTrue(ks instanceof DSAPrivateKeySpec); + } + + /** + * getG() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getG", + methodArgs = {} + ) + }) + public final void testGetG() { + DSAPrivateKeySpec dpks = new DSAPrivateKeySpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3"), + new BigInteger("4")); + + assertEquals(4, dpks.getG().intValue()); + } + + /** + * getP() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getP", + methodArgs = {} + ) + }) + public final void testGetP() { + DSAPrivateKeySpec dpks = new DSAPrivateKeySpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3"), + new BigInteger("4")); + + assertEquals(2, dpks.getP().intValue()); + } + + /** + * getQ() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getQ", + methodArgs = {} + ) + }) + public final void testGetQ() { + DSAPrivateKeySpec dpks = new DSAPrivateKeySpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3"), + new BigInteger("4")); + + assertEquals(3, dpks.getQ().intValue()); + } + + /** + * getX() test + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getX", + methodArgs = {} + ) + }) + public final void testGetX() { + DSAPrivateKeySpec dpks = new DSAPrivateKeySpec( + new BigInteger("1"), + new BigInteger("2"), + new BigInteger("3"), + new BigInteger("4")); + + assertEquals(1, dpks.getX().intValue()); + } + +} diff --git a/security/src/test/java/tests/security/spec/DSAPublicKeySpecTest.java b/security/src/test/java/tests/security/spec/DSAPublicKeySpecTest.java new file mode 100644 index 0000000..f55d0db --- /dev/null +++ b/security/src/test/java/tests/security/spec/DSAPublicKeySpecTest.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.DSAPublicKeySpec; +import java.security.spec.KeySpec; + +/** + * Tests for <code>DSAPublicKeySpec</code> + * + */ +@TestTargetClass(DSAPublicKeySpec.class) +public class DSAPublicKeySpecTest extends TestCase { + + /** + * Constructor for DSAPublicKeySpecTest. + * @param name + */ + public DSAPublicKeySpecTest(String name) { + super(name); + } + + /** + * Test for <code>DSAPublicKeySpec</code> ctor + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "DSAPublicKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testDSAPublicKeySpec() { + KeySpec ks = new DSAPublicKeySpec( + new BigInteger("1"), // y + new BigInteger("2"), // p + new BigInteger("3"), // q + new BigInteger("4"));// g + + assertTrue(ks instanceof DSAPublicKeySpec); + } + + /** + * Test for <code>getG</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getG", + methodArgs = {} + ) + }) + public final void testGetG() { + DSAPublicKeySpec dpks = new DSAPublicKeySpec( + new BigInteger("1"), // y + new BigInteger("2"), // p + new BigInteger("3"), // q + new BigInteger("4"));// g + + assertEquals(4, dpks.getG().intValue()); + } + + /** + * Test for <code>getP</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getP", + methodArgs = {} + ) + }) + public final void testGetP() { + DSAPublicKeySpec dpks = new DSAPublicKeySpec( + new BigInteger("1"), // y + new BigInteger("2"), // p + new BigInteger("3"), // q + new BigInteger("4"));// g + + assertEquals(2, dpks.getP().intValue()); + } + + /** + * Test for <code>getQ</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getQ", + methodArgs = {} + ) + }) + public final void testGetQ() { + DSAPublicKeySpec dpks = new DSAPublicKeySpec( + new BigInteger("1"), // y + new BigInteger("2"), // p + new BigInteger("3"), // q + new BigInteger("4"));// g + + assertEquals(3, dpks.getQ().intValue()); + } + + /** + * Test for <code>getY</code> method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getY", + methodArgs = {} + ) + }) + public final void testGetY() { + DSAPublicKeySpec dpks = new DSAPublicKeySpec( + new BigInteger("1"), // y + new BigInteger("2"), // p + new BigInteger("3"), // q + new BigInteger("4"));// g + + assertEquals(1, dpks.getY().intValue()); + } +} diff --git a/security/src/test/java/tests/security/spec/ECFieldF2mTest.java b/security/src/test/java/tests/security/spec/ECFieldF2mTest.java new file mode 100644 index 0000000..98d8eb2 --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECFieldF2mTest.java @@ -0,0 +1,767 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECFieldF2m; +import java.util.Arrays; + +/** + * Tests for <code>ECFieldF2m</code> class fields and methods. + * + */ +@TestTargetClass(ECFieldF2m.class) +public class ECFieldF2mTest extends TestCase { + + /** + * Support class for this test. + * Encapsulates <code>ECFieldF2m</code> testing + * domain parameters. + * + */ + private static final class ECFieldF2mDomainParams { + + /** + * <code>NPE</code> reference object of class NullPointerException. + * NullPointerException must be thrown by <code>ECFieldF2m</code> + * ctors in some circumstances + */ + static final NullPointerException NPE = new NullPointerException(); + /** + * <code>IArgE</code> reference object of class IllegalArgumentException. + * IllegalArgumentException must be thrown by <code>ECFieldF2m</code> + * ctors in some circumstances + */ + static final IllegalArgumentException IArgE = new IllegalArgumentException(); + + /** + * The <code>m</code> parameter for <code>ECFieldF2m</code> + * ctor for the current test. + */ + final int m; + /** + * The <code>rp</code> parameter for <code>ECFieldF2m</code> + * ctor for the current test. + */ + final BigInteger rp; + /** + * The <code>ks</code> parameter for <code>ECFieldF2m</code> + * ctor for the current test. + */ + final int[] ks; + + + /** + * Exception expected with this parameters set or <code>null</code> + * if no exception expected. + */ + final Exception x; + + /** + * Constructs ECFieldF2mDomainParams + * + * @param m + * @param rp + * @param ks + * @param expectedException + */ + ECFieldF2mDomainParams(final int m, + final BigInteger rp, + final int[] ks, + final Exception expectedException) { + this.m = m; + this.rp = rp; + this.ks = ks; + this.x = expectedException; + } + } + + /** + * Constructor for ECFieldF2mTest. + * @param name + */ + public ECFieldF2mTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Set of parameters used for <code>ECFieldF2m(int)</code> + * constructor tests. + */ + private final ECFieldF2mDomainParams[] intCtorTestParameters = + new ECFieldF2mDomainParams[] { + // set 0: valid m + new ECFieldF2mDomainParams(1, null, null, null), + // set 1: valid m + new ECFieldF2mDomainParams(Integer.MAX_VALUE, null, null, null), + // set 2: invalid m + new ECFieldF2mDomainParams(0, null, null, ECFieldF2mDomainParams.IArgE), + // set 3: invalid m + new ECFieldF2mDomainParams(-1, null, null, ECFieldF2mDomainParams.IArgE) + }; + + /** + * Tests for constructor <code>ECFieldF2m(int)</code><br> + * + * Assertion: constructs new <code>ECFieldF2m</code> object + * using valid parameter m. + * + * Assertion: IllegalArgumentException if m is not positive. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalArgumentException checking missed", + targets = { + @TestTarget( + methodName = "ECFieldF2m", + methodArgs = {int.class} + ) + }) + public final void testECFieldF2mint() { + for(int i=0; i<intCtorTestParameters.length; i++) { + ECFieldF2mDomainParams tp = intCtorTestParameters[i]; + try { + // perform test + new ECFieldF2m(tp.m); + + if (tp.x != null) { + // exception has been expected + fail(getName() + ", set " + i + + " FAILED: expected exception has not been thrown"); + } + } catch (Exception e){ + if (tp.x == null || !e.getClass().isInstance(tp.x)) { + // exception: failure + // if it has not been expected + // or wrong one has been thrown + fail(getName() + ", set " + i + + " FAILED: unexpected " + e); + } + } + } + } + + /** + * Set of parameters used for <code>ECFieldF2m(int, BigInteger)</code> + * constructor tests. + */ + private final ECFieldF2mDomainParams[] intIntArrayCtorTestParameters = + new ECFieldF2mDomainParams[] { + // set 0: valid m and ks - trinomial basis params + new ECFieldF2mDomainParams( + 1999, + null, + new int[] {367}, + null), + // set 1: valid m and ks - pentanomial basis params + new ECFieldF2mDomainParams( + 2000, + null, + new int[] {981,2,1}, + null), + // set 2: valid m, invalid (null) ks + new ECFieldF2mDomainParams( + 1963, + null, + null, + ECFieldF2mDomainParams.NPE), + // set 3: valid m, invalid ks - wrong length + new ECFieldF2mDomainParams( + 1963, + null, + new int[] {981,2}, + ECFieldF2mDomainParams.IArgE), + // set 4: valid m, invalid ks - wrong length + new ECFieldF2mDomainParams( + 1963, + null, + new int[] {981,124,2,1}, + ECFieldF2mDomainParams.IArgE), + // set 5: valid m, invalid ks - wrong value + new ECFieldF2mDomainParams( + 1999, + null, + new int[] {1999}, + ECFieldF2mDomainParams.IArgE), + // set 6: valid m, invalid ks - wrong value + new ECFieldF2mDomainParams( + 1999, + null, + new int[] {0}, + ECFieldF2mDomainParams.IArgE), + // set 7: valid m, invalid ks - wrong values + new ECFieldF2mDomainParams( + 2000, + null, + new int[] {2000,2,1}, + ECFieldF2mDomainParams.IArgE), + // set 8: valid m, invalid ks - wrong values + new ECFieldF2mDomainParams( + 2000, + null, + new int[] {981,2,0}, + ECFieldF2mDomainParams.IArgE), + // set 9: invalid m + new ECFieldF2mDomainParams( + -5, + null, + new int[] {981,2,1}, + ECFieldF2mDomainParams.IArgE), + // set 10: valid m, invalid ks - wrong order + new ECFieldF2mDomainParams( + 2000, + null, + new int[] {981,1,2}, + ECFieldF2mDomainParams.IArgE), + // set 11: valid m, invalid ks - no content + new ECFieldF2mDomainParams( + 2000, + null, + new int[3], + ECFieldF2mDomainParams.IArgE), + // set 12: valid m, invalid ks - length is 0 + new ECFieldF2mDomainParams( + 2000, + null, + new int[0], + ECFieldF2mDomainParams.IArgE), + }; + + /** + * Tests for constructor <code>ECFieldF2m(int m, int[] ks)</code><br> + * + * Assertion: constructs new <code>ECFieldF2m</code> object + * using valid parameters m and rp. ks represents trinomial basis. + * + * Assertion: constructs new <code>ECFieldF2m</code> object + * using valid parameters m and ks. ks represents pentanomial basis. + * + * Assertion: IllegalArgumentException if m is not positive. + * + * Assertion: NullPointerException if ks is null. + * + * Assertion: IllegalArgumentException if ks is invalid. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exception cases weren't checked.", + targets = { + @TestTarget( + methodName = "ECFieldF2m", + methodArgs = {int.class, int[].class} + ) + }) + public final void testECFieldF2mintintArray() { + for(int i=0; i<intIntArrayCtorTestParameters.length; i++) { + ECFieldF2mDomainParams tp = intIntArrayCtorTestParameters[i]; + try { + // perform test + new ECFieldF2m(tp.m, tp.ks); + + if (tp.x != null) { + // exception has been expected + fail(getName() + ", set " + i + + " FAILED: expected exception has not been thrown"); + } + } catch (Exception e){ + if (tp.x == null || !e.getClass().isInstance(tp.x)) { + // exception: failure + // if it has not been expected + // or wrong one has been thrown + fail(getName() + ", set " + i + + " FAILED: unexpected " + e); + } + } + } + } + + /** + * Test #1 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * repeatedly on the same object. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode01() { + ECFieldF2m f = new ECFieldF2m(2000); + int hc = f.hashCode(); + assertTrue(hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode()); + } + + /** + * Test #2 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * repeatedly on the same object. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode02() { + ECFieldF2m f = new ECFieldF2m(2000, new int[] {981, 2, 1}); + int hc = f.hashCode(); + assertTrue(hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode()); + } + + /** + * Test #3 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * on equal (according to the <code>equals(Object)</code> method) objects. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode03() { + assertTrue(new ECFieldF2m(111).hashCode() == + new ECFieldF2m(111).hashCode()); + } + + /** + * Test #4 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * on equal (according to the <code>equals(Object)</code> method) objects. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode04() { + assertTrue(new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode() == + new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode()); + } + + /** + * Test #5 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * on equal (according to the <code>equals(Object)</code> method) objects. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode05() { + assertTrue(new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode() == + new ECFieldF2m(2000, BigInteger.valueOf(0L). + setBit(0).setBit(1).setBit(2). + setBit(981).setBit(2000)).hashCode()); + } + + /** + * Test #1 for <code>equals()</code> method.<br> + * + * Assertion: object equals to itself. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject01() { + ECFieldF2m obj = new ECFieldF2m(1999, new int[] {367}); + assertTrue(obj.equals(obj)); + } + + /** + * Test #2 for <code>equals()</code> method.<br> + * + * Assertion: normal basis - objects equal if their m are equal. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Simple test. Doesn\'t verify other cases.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject02() { + assertTrue(new ECFieldF2m(43).equals(new ECFieldF2m(43))); + } + + /** + * Test #3 for <code>equals()</code> method.<br> + * + * Assertion: trinomial basis - objects equal if their m, and rp + * are mutually equal. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject03() { + assertTrue(new ECFieldF2m(1999, new int[] {367}).equals( + new ECFieldF2m(1999, BigInteger.valueOf(0L). + setBit(0).setBit(367).setBit(1999)))); + } + + /** + * Test #4 for <code>equals()</code> method.<br> + * + * Assertion: pentanomial basis - objects equal if their m, and rp + * are mutually equal. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject04() { + ECFieldF2m f1 = new ECFieldF2m(2000, new int[] {981, 2, 1}); + ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L). + setBit(0).setBit(1).setBit(2). + setBit(981).setBit(2000)); + assertTrue(f1.equals(f2) && f2.equals(f1)); + } + + /** + * Test #5 for <code>equals()</code> method.<br> + * + * Assertion: objects equal if their m, and rp are mutually equal. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject05() { + ECFieldF2m f1 = new ECFieldF2m(2000); + ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L). + setBit(0).setBit(1).setBit(2). + setBit(981).setBit(2000)); + assertFalse(f1.equals(f2) || f2.equals(f1)); + } + + /** + * Test #6 for <code>equals(Object obj)</code> method.<br> + * + * Assertion: returns false if obj is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject06() { + assertFalse(new ECFieldF2m(2000).equals(null)); + } + + /** + * Test #7 for <code>equals(Object obj)</code> method.<br> + * + * Assertion: returns false if obj is not instance of <code>ECFieldF2m</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject07() { + assertFalse(new ECFieldF2m(2000).equals(new Object())); + } + + /** + * Test for <code>getFieldSize()</code> method.<br> + * + * Assertion: returns m value for <code>ECFieldF2m</code> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getFieldSize", + methodArgs = {} + ) + }) + public final void testGetFieldSize() { + assertEquals(2000, new ECFieldF2m(2000).getFieldSize()); + } + + /** + * Test for <code>getM()</code> method.<br> + * + * Assertion: returns m value for <code>ECFieldF2m</code> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getM", + methodArgs = {} + ) + }) + public final void testGetM() { + assertEquals(2000, new ECFieldF2m(2000).getM()); + } + + /** + * Test #1 for <code>getMidTermsOfReductionPolynomial()</code> method.<br> + * + * Assertion: returns mid terms of reduction polynomial + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getMidTermsOfReductionPolynomial method " + + "returns mid terms of reduction polynomial.", + targets = { + @TestTarget( + methodName = "getMidTermsOfReductionPolynomial", + methodArgs = {} + ) + }) + public final void testGetMidTermsOfReductionPolynomial01() { + int[] a = new int[] {981,2,1}; + int[] b = new ECFieldF2m(2000, + BigInteger.valueOf(0L).setBit(0).setBit(1). + setBit(2).setBit(981).setBit(2000)). + getMidTermsOfReductionPolynomial(); + assertTrue(Arrays.equals(a, b)); + } + + /** + * Test #2 for <code>getMidTermsOfReductionPolynomial()</code> method.<br> + * + * Assertion: returns null for normal basis + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getMidTermsOfReductionPolynomial method " + + "returns null for normal basis.", + targets = { + @TestTarget( + methodName = "getMidTermsOfReductionPolynomial", + methodArgs = {} + ) + }) + public final void testGetMidTermsOfReductionPolynomial02() { + assertNull(new ECFieldF2m(2000).getMidTermsOfReductionPolynomial()); + } + + /** + * Test #3 for <code>getMidTermsOfReductionPolynomial()</code> method.<br> + * + * Assertion: returns mid terms of reduction polynomial + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getMidTermsOfReductionPolynomial method " + + "returns mid terms of reduction polynomial.", + targets = { + @TestTarget( + methodName = "getMidTermsOfReductionPolynomial", + methodArgs = {} + ) + }) + public final void testGetMidTermsOfReductionPolynomial03() { + int[] a = new int[] {367}; + int[] b = new ECFieldF2m(1999, a).getMidTermsOfReductionPolynomial(); + assertTrue(Arrays.equals(a, b)); + } + + /** + * Test #1 for <code>getReductionPolynomial()</code> method.<br> + * + * Assertion: returns reduction polynomial + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getReductionPolynomial method returns " + + "reduction polynomial.", + targets = { + @TestTarget( + methodName = "getReductionPolynomial", + methodArgs = {} + ) + }) + public final void testGetReductionPolynomial01() { + BigInteger rp = BigInteger.valueOf(0L).setBit(0).setBit(1).setBit(2). + setBit(981).setBit(2000); + assertTrue(new ECFieldF2m(2000, rp).getReductionPolynomial().equals(rp)); + } + + /** + * Test #2 for <code>getReductionPolynomial()</code> method.<br> + * + * Assertion: returns null for normal basis + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getReductionPolynomial method returns null " + + "for normal basis.", + targets = { + @TestTarget( + methodName = "getReductionPolynomial", + methodArgs = {} + ) + }) + public final void testGetReductionPolynomial02() { + assertNull(new ECFieldF2m(2000).getReductionPolynomial()); + } + + /** + * Tests that object state is preserved against modifications + * through array reference passed to the constructor. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that object state is preserved against " + + "modifications through array reference passed to " + + "the constructor.", + targets = { + @TestTarget( + methodName = "ECFieldF2m", + methodArgs = {int.class, int[].class} + ) + }) + public final void testIsStatePreserved01() { + // reference array + int[] a = new int[] {367}; + // reference array copy + int[] aCopy = a.clone(); + // create obj using copy + ECFieldF2m f = new ECFieldF2m(1999, aCopy); + // modify copy + aCopy[0] = 5; + // compare reference with returned array + assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial())); + } + + /** + * Tests that object state is preserved against + * modifications through array reference returned by + * <code>getMidTermsOfReductionPolynomial()</code> method. + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that object state is preserved against " + + "modifications through array reference returned by " + + "getMidTermsOfReductionPolynomial() method.", + targets = { + @TestTarget( + methodName = "ECFieldF2m", + methodArgs = {int.class, int[].class} + ), + @TestTarget( + methodName = "getMidTermsOfReductionPolynomial", + methodArgs = {} + ) + }) + public final void testIsStatePreserved02() { + // reference array + int[] a = new int[] {981,2,1}; + // reference array copy + int[] aCopy = a.clone(); + // create obj using copy + ECFieldF2m f = new ECFieldF2m(2000, aCopy); + // get array reference and modify returned array + f.getMidTermsOfReductionPolynomial()[0] = 1532; + // compare reference with returned for the second time array + assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial())); + } + +} diff --git a/security/src/test/java/tests/security/spec/ECFieldFpTest.java b/security/src/test/java/tests/security/spec/ECFieldFpTest.java new file mode 100644 index 0000000..98a769c --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECFieldFpTest.java @@ -0,0 +1,321 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECFieldFp; + +/** + * Tests for <code>ECFieldFp</code> class fields and methods. + * + */ +@TestTargetClass(ECFieldFp.class) +public class ECFieldFpTest extends TestCase { + + /** + * Constructor for ECFieldFpTest. + * @param name + */ + public ECFieldFpTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>ECFieldFp</code> constructor + * + * Assertion: creates new object of <code>ECFieldFp</code> class + * using valid <code>p</code> (odd prime) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECFieldFp", + methodArgs = {java.math.BigInteger.class} + ) + }) + public final void testECFieldFp01() { + new ECFieldFp(BigInteger.valueOf(23L)); + } + + /** + * Test #2 for <code>ECFieldFp</code> constructor + * + * Assertion: creates new object of <code>ECFieldFp</code> class + * using valid <code>p</code> (odd but not prime) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECFieldFp", + methodArgs = {java.math.BigInteger.class} + ) + }) + public final void testECFieldFp02() { + new ECFieldFp(BigInteger.valueOf(21L)); + } + + /** + * Test #3 for <code>ECFieldFp</code> constructor + * + * Assertion: IllegalArgumentException if <code>p</code> is not positive + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECFieldFp", + methodArgs = {java.math.BigInteger.class} + ) + }) + public final void testECFieldFp03() { + try { + new ECFieldFp(BigInteger.valueOf(-1L)); + fail(getName() + + " FAILED: expected exception has not been thrown"); + } catch (IllegalArgumentException e) { + } + } + + /** + * Test #4 for <code>ECFieldFp</code> constructor + * + * Assertion: IllegalArgumentException if <code>p</code> is not positive + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECFieldFp", + methodArgs = {java.math.BigInteger.class} + ) + }) + public final void testECFieldFp04() { + try { + new ECFieldFp(BigInteger.valueOf(0L)); + fail(getName() + + " FAILED: expected exception has not been thrown"); + } catch (IllegalArgumentException e) { + } + } + + /** + * Test #4 for <code>ECFieldFp</code> constructor + * + * Assertion: NullPointerException if <code>p</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECFieldFp", + methodArgs = {java.math.BigInteger.class} + ) + }) + public final void testECFieldFp05() { + try { + new ECFieldFp(null); + fail(getName() + + " FAILED: expected exception has not been thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #1 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * repeatedly on the same object. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode01() { + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + int hc = f.hashCode(); + assertTrue(hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode()); + } + + /** + * Test #2 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * on equal (according to the <code>equals(Object)</code> method) objects. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode02() { + assertTrue(new ECFieldFp(BigInteger.valueOf(23L)).hashCode() == + new ECFieldFp(BigInteger.valueOf(23L)).hashCode()); + } + + /** + * Test for <code>getFieldSize()()</code> method.<br> + * + * Assertion: returns field size in bits which is prime size + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getFieldSize", + methodArgs = {} + ) + }) + public final void testGetFieldSize() { + assertEquals(5, new ECFieldFp(BigInteger.valueOf(23L)).getFieldSize()); + } + + /** + * Test for <code>getP()</code> method.<br> + * + * Assertion: returns prime + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getP", + methodArgs = {} + ) + }) + public final void testGetP() { + BigInteger p = BigInteger.valueOf(23L); + assertTrue(p.equals(new ECFieldFp(p).getP())); + } + + /** + * Test #1 for <code>equals()</code> method.<br> + * + * Assertion: object equals to itself. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject01() { + ECFieldFp obj = new ECFieldFp(BigInteger.valueOf(23L)); + assertTrue(obj.equals(obj)); + } + + /** + * Test #2 for <code>equals(Object obj)</code> method.<br> + * + * Assertion: returns false if <code>obj</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject02() { + assertFalse(new ECFieldFp(BigInteger.valueOf(23L)).equals(null)); + } + + /** + * Test #3 for <code>equals(Object obj)</code> method.<br> + * + * Assertion: returns false if <code>obj</code> + * is not instance of <code>ECFieldFp</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject03() { + assertFalse(new ECFieldFp(BigInteger.valueOf(23L)).equals(new Object())); + } + + /** + * Test #4 for <code>equals()</code> method.<br> + * + * Assertion: true if prime values match. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject04() { + assertTrue(new ECFieldFp(BigInteger.valueOf(23L)).equals( + new ECFieldFp(BigInteger.valueOf(23L)))); + } + +} diff --git a/security/src/test/java/tests/security/spec/ECGenParameterSpecTest.java b/security/src/test/java/tests/security/spec/ECGenParameterSpecTest.java new file mode 100644 index 0000000..e30c2ef --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECGenParameterSpecTest.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.ECGenParameterSpec; + +/** + * Tests for <code>ECGenParameterSpec</code> class fields and methods. + * + */ +@TestTargetClass(ECGenParameterSpec.class) +public class ECGenParameterSpecTest extends TestCase { + + /** + * Constructor for ECGenParameterSpecTest. + * @param name + */ + public ECGenParameterSpecTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>ECGenParameterSpec</code> constructor<br> + * + * Assertion: creates new object of <code>ECGenParameterSpec</code> class + * using valid <code>name</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECGenParameterSpec", + methodArgs = {java.lang.String.class} + ) + }) + public final void testECGenParameterSpec01() { + new ECGenParameterSpec("someName"); + } + + /** + * Test #2 for <code>ECGenParameterSpec</code> constructor<br> + * + * Assertion: throws NullPointerException + * if <code>name</code> is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "ECGenParameterSpec", + methodArgs = {java.lang.String.class} + ) + }) + public final void testECGenParameterSpec02() { + try { + new ECGenParameterSpec(null); + fail("NPE expected"); + } catch (NullPointerException ok) {} + } + + /** + * Test for <code>getName()</code> method<br> + * + * Assertion: returns the <code>name</code> + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) + public final void testGetName() { + String name = "someName"; + ECGenParameterSpec ps = new ECGenParameterSpec(name); + assertEquals(name, ps.getName()); + } + +} diff --git a/security/src/test/java/tests/security/spec/ECParameterSpecTest.java b/security/src/test/java/tests/security/spec/ECParameterSpecTest.java new file mode 100644 index 0000000..f5412eb --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECParameterSpecTest.java @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECFieldF2m; +import java.security.spec.ECParameterSpec; +import java.security.spec.ECPoint; +import java.security.spec.EllipticCurve; + +@TestTargetClass(ECParameterSpec.class) +public class ECParameterSpecTest extends TestCase { + + EllipticCurve curve; + + ECPoint ecpoint; + + ECParameterSpec ecps; + + /** + * Constructor for ECParameterSpecTest. + * + * @param name + */ + public ECParameterSpecTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + curve = new EllipticCurve(new ECFieldF2m(2), BigInteger.valueOf(1), + BigInteger.valueOf(1)); + ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1)); + ecps = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1); + } + + protected void tearDown() throws Exception { + curve = null; + ecpoint = null; + ecps = null; + super.tearDown(); + } + + /** + * test for ECParameterSpec(EllipticCurve, ECPoint, BigInteger, int) constructor + * test covers following usecases: + * case 1: creating object with valid parameters + * case 2: NullPointerException - if curve is null + * case 3: NullPointerException - if g is null + * case 4: NullPointerException - if n is null + * case 5: IllegalArgumentException - if n is not positive + * case 6: IllegalArgumentException - if h is not positive + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ECParameterSpec", + methodArgs = {java.security.spec.EllipticCurve.class, java.security.spec.ECPoint.class, java.math.BigInteger.class, int.class} + ) + }) + public void test_constructorLjava_security_spec_EllipticCurveLjava_security_spec_ECPointLjava_math_BigIntegerI() { + + // case 1: creating object with valid parameters + assertEquals("wrong cofactor was returned", 1, ecps.getCofactor()); + assertEquals("wrong elliptic curve", curve, ecps.getCurve()); + assertEquals("wrong generator was returned", ecpoint, ecps + .getGenerator()); + assertEquals("wrong order was reteurned", BigInteger.valueOf(1), ecps + .getOrder()); + + // case 2: NullPointerException - if curve is null. + try { + new ECParameterSpec(null, ecpoint, BigInteger.valueOf(1), 1); + fail("NullPointerException exception has not been thrown"); + } catch (NullPointerException e) { + // expected + } + + // case 3: NullPointerException - if g is null. + try { + new ECParameterSpec(curve, null, BigInteger.valueOf(1), 1); + fail("NullPointerException exception has not been thrown"); + } catch (NullPointerException e) { + // expected + } + + // case 4: NullPointerException - if n is null. + try { + new ECParameterSpec(curve, ecpoint, null, 1); + fail("NullPointerException exception has not been thrown"); + } catch (NullPointerException e) { + // expected + } + + // case 5: IllegalArgumentException - if n is not positive. + try { + new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(-1), 1); + fail("IllegalArgumentException exception has not been thrown"); + } catch (IllegalArgumentException e) { + // expected + } + + // case 6: IllegalArgumentException - if h is not positive. + try { + new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), -1); + fail("IllegalArgumentException exception has not been thrown"); + } catch (IllegalArgumentException e) { + // expected + } + } + + /** + * test for getCurve() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCurve", + methodArgs = {} + ) + }) + public void test_GetCurve() { + assertEquals("wrong elliptic curve", curve, ecps.getCurve()); + } + + /** + * test for getGenerator() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getGenerator", + methodArgs = {} + ) + }) + public void test_GetGenerator() { + assertEquals("wrong generator was returned", ecpoint, ecps + .getGenerator()); + } + + /** + * test for getOrder() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getOrder", + methodArgs = {} + ) + }) + public void test_GetOrder() { + assertEquals("wrong order was reteurned", BigInteger.valueOf(1), ecps + .getOrder()); + } + + /** + * test for getCofactor() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCofactor", + methodArgs = {} + ) + }) + public void test_GetCofactor() { + assertEquals("wrong cofactor was returned", 1, ecps.getCofactor()); + } +} diff --git a/security/src/test/java/tests/security/spec/ECPointTest.java b/security/src/test/java/tests/security/spec/ECPointTest.java new file mode 100644 index 0000000..1b31ae6 --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECPointTest.java @@ -0,0 +1,340 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECPoint; + +/** + * Tests for <code>ECPoint</code> class fields and methods. + * + */ +@TestTargetClass(ECPoint.class) +public class ECPointTest extends TestCase { + + /** + * Constructor for ECPointTest. + * @param name + */ + public ECPointTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test #1 for <code>ECPoint(BigInteger, BigInteger)</code> constructor<br> + * Assertion: creates <code>ECPoint</code> instance<br> + * Test preconditions: valid parameters passed<br> + * Expected: must pass without any exceptions + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive cases.", + targets = { + @TestTarget( + methodName = "ECPoint", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testECPoint01() { + new ECPoint(BigInteger.ZERO, BigInteger.ZERO); + new ECPoint(BigInteger.valueOf(-23456L), BigInteger.valueOf(-23456L)); + new ECPoint(BigInteger.valueOf(123456L), BigInteger.valueOf(123456L)); + new ECPoint(BigInteger.valueOf(-56L), BigInteger.valueOf(234L)); + new ECPoint(BigInteger.valueOf(3456L), BigInteger.valueOf(-2344L)); + } + + /** + * Test #2 for <code>ECPoint(BigInteger x, BigInteger y)</code> constructor<br> + * Assertion: throws <code>NullPointerException</code> if <code>x</code>or + * <code>y</code> is <code>null</code><br> + * Test preconditions: pass <code>null</code> as mentioned parameters<br> + * Expected: must throw <code>NullPointerException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies exceptions.", + targets = { + @TestTarget( + methodName = "ECPoint", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testECPoint02() { + // test case 1: x is null + try { + new ECPoint(null, BigInteger.ZERO); + fail("#1: Expected NPE not thrown"); + } catch (NullPointerException ok) { + } + + + // test case 2: y is null + try { + new ECPoint(BigInteger.ZERO, null); + fail("#2: Expected NPE not thrown"); + } catch (NullPointerException ok) { + } + + + // test case 3: both : x and y are null + try { + new ECPoint(null, null); + fail("#3: Expected NPE not thrown"); + } catch (NullPointerException ok) { + } + } + + /** + * Test #1 for <code>getAffineX()</code> method<br> + * Assertion: returns affine <code>x</code> coordinate<br> + * Test preconditions: <code>ECPoint</code> instance + * created using valid parameters<br> + * Expected: must return affine <code>x</code> coordinate + * which is equal to the one passed to the constructor; + * (both must refer the same object) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getAffineX", + methodArgs = {} + ) + }) + public final void testGetAffineX01() { + BigInteger x = BigInteger.valueOf(-23456L); + ECPoint p = new ECPoint(x, BigInteger.valueOf(23456L)); + BigInteger xRet = p.getAffineX(); + assertEquals(x, xRet); + assertSame(x, xRet); + } + + /** + * Test #2 for <code>getAffineX()</code> method<br> + * Assertion: returns <code>null</code> for <code>ECPoint.POINT_INFINITY</code><br> + * Test preconditions: none<br> + * Expected: must return <code>null</code> for + * <code>ECPoint.POINT_INFINITY</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getAffineX returns null for POINT_INFINITY.", + targets = { + @TestTarget( + methodName = "getAffineX", + methodArgs = {} + ) + }) + public final void testGetAffineX02() { + assertNull(ECPoint.POINT_INFINITY.getAffineX()); + } + + /** + * Test #1 for <code>getAffineY()</code> method<br> + * Assertion: returns affine <code>y</code> coordinate<br> + * Test preconditions: <code>ECPoint</code> instance + * created using valid parameters<br> + * Expected: must return affine <code>y</code> coordinate + * which is equal to the one passed to the constructor; + * (both must refer the same object) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive functionality.", + targets = { + @TestTarget( + methodName = "getAffineY", + methodArgs = {} + ) + }) + public final void testGetAffineY01() { + BigInteger y = BigInteger.valueOf(23456L); + ECPoint p = new ECPoint(BigInteger.valueOf(-23456L), y); + BigInteger yRet = p.getAffineY(); + assertEquals(y, yRet); + assertSame(y, yRet); + } + + /** + * Test #2 for <code>getAffineX()</code> method<br> + * Assertion: returns <code>null</code> for <code>ECPoint.POINT_INFINITY</code><br> + * Test preconditions: none<br> + * Expected: must return <code>null</code> for + * <code>ECPoint.POINT_INFINITY</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getAffineY ruturns null for POINT_INFINITY.", + targets = { + @TestTarget( + methodName = "getAffineY", + methodArgs = {} + ) + }) + public final void testGetAffineY02() { + assertNull(ECPoint.POINT_INFINITY.getAffineY()); + } + + /** + * Test #1 for <code>equals(Object other)</code> method<br> + * Assertion: return true if this and other objects are equal<br> + * Test preconditions: see test comments<br> + * Expected: all objects in this test must be equal + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive cases.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject01() { + // test case 1: must be equal to itself + ECPoint p2=null, p1 = + new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ONE); + assertTrue(p1.equals(p1)); + + // test case 2: equal objects + p1 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ONE); + p2 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.valueOf(1L)); + assertTrue(p1.equals(p2) && p2.equals(p1)); + + // test case 3: equal POINT_INFINITY object(s) + p1 = ECPoint.POINT_INFINITY; + p2 = ECPoint.POINT_INFINITY; + assertTrue(p1.equals(p2) && p2.equals(p1)); + } + + /** + * Test #2 for <code>equals(Object other)</code> method<br> + * Assertion: return false if this and other objects are not equal<br> + * Test preconditions: see test comments<br> + * Expected: all objects in this test must be not equal + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies negative cases.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject02() { + // test case 1: must be not equal to null + ECPoint p2=null, p1 = + new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ONE); + assertFalse(p1.equals(p2)); + + // test case 2: not equal objects - x + p1 = new ECPoint(BigInteger.valueOf(-23457L), BigInteger.ONE); + p2 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.valueOf(1L)); + assertFalse(p1.equals(p2) || p2.equals(p1)); + + // test case 3: not equal objects - y + p1 = new ECPoint(BigInteger.valueOf(-23457L), BigInteger.ONE); + p2 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ZERO); + assertFalse(p1.equals(p2) || p2.equals(p1)); + + // test case 4: not equal - some point and POINT_INFINITY + p1 = ECPoint.POINT_INFINITY; + p2 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ZERO); + assertFalse(p1.equals(p2) || p2.equals(p1)); + } + + /** + * Test #1 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * repeatedly on the same object. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode01() { + ECPoint f = new ECPoint(BigInteger.valueOf(-23457L), BigInteger.ONE); + int hc = f.hashCode(); + assertTrue(hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode() && + hc == f.hashCode()); + + + // the same for POINT_INFINITY + hc = ECPoint.POINT_INFINITY.hashCode(); + assertTrue(hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode() && + hc == ECPoint.POINT_INFINITY.hashCode()); + } + + /** + * Test #2 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * on equal (according to the <code>equals(Object)</code> method) objects. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode02() { + ECPoint p1 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ONE); + ECPoint p2 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.valueOf(1L)); + assertEquals(p1.hashCode(), p2.hashCode()); + } + +} diff --git a/security/src/test/java/tests/security/spec/ECPrivateKeySpecTest.java b/security/src/test/java/tests/security/spec/ECPrivateKeySpecTest.java new file mode 100644 index 0000000..311ecec --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECPrivateKeySpecTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECFieldF2m; +import java.security.spec.ECParameterSpec; +import java.security.spec.ECPoint; +import java.security.spec.ECPrivateKeySpec; +import java.security.spec.EllipticCurve; + +@TestTargetClass(ECPrivateKeySpec.class) +public class ECPrivateKeySpecTest extends TestCase { + + BigInteger s; + + ECParameterSpec ecparams; + + ECPrivateKeySpec ecpks; + + /** + * Constructor for ECPrivateKeySpecTest + * + * @param name + */ + public ECPrivateKeySpecTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + + ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger + .valueOf(1)); + EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger + .valueOf(1), BigInteger.valueOf(1)); + + s = BigInteger.valueOf(1); + ecparams = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1); + ecpks = new ECPrivateKeySpec(s, ecparams); + } + + protected void tearDown() throws Exception { + s = null; + ecparams = null; + ecpks = null; + super.tearDown(); + } + + /** + * test for constructor ECPrivateKeySpec(BigInteger, ECParameterSpec) + * test covers following usecases: + * case 1: creating object with valid parameters + * case 2: catch NullPointerException - if s is null. + * case 3: catch NullPointerException - if params is null. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ECPrivateKeySpec", + methodArgs = {java.math.BigInteger.class, java.security.spec.ECParameterSpec.class} + ) + }) + public void test_constructorLjava_math_BigIntegerLjava_security_spec_ECParameterSpec() { + + // case 1: creating object with valid parameters + assertEquals("wrong private value", s, ecpks.getS()); + assertEquals("wrong parameters", ecparams, ecpks.getParams()); + + // case 2: catch NullPointerException - if s is null. + try { + new ECPrivateKeySpec(null, ecparams); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException e) { + // expected + } + + // case 3: catch NullPointerException - if params is null. + try { + new ECPrivateKeySpec(s, null); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * test for getS() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getS", + methodArgs = {} + ) + }) + public void test_GetS() { + assertEquals("wrong private value", s, ecpks.getS()); + } + + /** + * test for getParams() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParams", + methodArgs = {} + ) + }) + public void test_GetParams() { + assertEquals("wrong parameters", ecparams, ecpks.getParams()); + } +} diff --git a/security/src/test/java/tests/security/spec/ECPublicKeySpecTest.java b/security/src/test/java/tests/security/spec/ECPublicKeySpecTest.java new file mode 100644 index 0000000..0b0f929 --- /dev/null +++ b/security/src/test/java/tests/security/spec/ECPublicKeySpecTest.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECFieldF2m; +import java.security.spec.ECParameterSpec; +import java.security.spec.ECPoint; +import java.security.spec.ECPublicKeySpec; +import java.security.spec.EllipticCurve; + +@TestTargetClass(ECPublicKeySpec.class) +public class ECPublicKeySpecTest extends TestCase { + ECPoint w; + + ECParameterSpec params; + + ECPublicKeySpec ecpks; + + /** + * Constructor for ECPublicKeySpec + * + * @param name + */ + public ECPublicKeySpecTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger + .valueOf(1)); + EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger + .valueOf(1), BigInteger.valueOf(1)); + + w = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1)); + params = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1); + ecpks = new ECPublicKeySpec(w, params); + } + + protected void tearDown() throws Exception { + w = null; + params = null; + ecpks = null; + super.tearDown(); + } + + /** + * test for constructor ECPublicKeySpec(ECPoint, ECParameterSpec) + * test covers following usecases: + * case 1: creating object with valid parameters + * case 2: catch NullPointerException - if w is null. + * case 3: catch NullPointerException - if params is null. + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ECPublicKeySpec", + methodArgs = {java.security.spec.ECPoint.class, java.security.spec.ECParameterSpec.class} + ) + }) + public final void test_constructorLjava_security_spec_ECPointLjava_security_spec_ECParameterSpec() { + + // case 1: creating object with valid parameters + assertEquals("wrong params value", params, ecpks.getParams()); + assertEquals("wrong w value", w, ecpks.getW()); + + // case 2: catch NullPointerException - if w is null. + try { + new ECPublicKeySpec(null, params); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException e) { + // expected + } + + // case 3: catch NullPointerException - if params is null. + try { + new ECPublicKeySpec(w, null); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException e) { + // expected + } + } + + /** + * test for getW() method + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getW", + methodArgs = {} + ) + }) + public final void testGetW() { + assertEquals("wrong w value", w, ecpks.getW()); + } + + /** + * test for getParams() meyhod + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParams", + methodArgs = {} + ) + }) + public final void testGetParams() { + assertEquals("wrong params value", params, ecpks.getParams()); + } +} diff --git a/security/src/test/java/tests/security/spec/EllipticCurveTest.java b/security/src/test/java/tests/security/spec/EllipticCurveTest.java new file mode 100644 index 0000000..c037650 --- /dev/null +++ b/security/src/test/java/tests/security/spec/EllipticCurveTest.java @@ -0,0 +1,850 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.ECField; +import java.security.spec.ECFieldF2m; +import java.security.spec.ECFieldFp; +import java.security.spec.EllipticCurve; +import java.util.Arrays; + +/** + * Tests for <code>EllipticCurve</code> class fields and methods. + * + */ +@TestTargetClass(EllipticCurve.class) +public class EllipticCurveTest extends TestCase { + + /** + * Test #1 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code> + * constructor<br> + * Assertion: creates instance of EllipticCurve<br> + * Test preconditions: valid parameters passed<br> + * Expected: must pass without any exceptions + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive cases.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, + java.math.BigInteger.class, byte[].class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray01() { + // test case 1 parameters set + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + // perform test case 1 + new EllipticCurve(f, a, b, seed); + + // test case 2 parameters set + ECFieldF2m f1 = new ECFieldF2m(5); + a = BigInteger.ZERO; + b = BigInteger.valueOf(23L); + // perform test case 2 + new EllipticCurve(f1, a, b, seed); + + // test case 3 parameters set, + // the seed parameter may be null + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.ONE; + b = BigInteger.valueOf(19L); + seed = null; + // perform test case 3 + new EllipticCurve(f, a, b, seed); + } + + /** + * Test #2 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code> + * constructor<br> + * Assertion: throws <code>NullPointerException</code> if <code>field</code>, + * <code>a</code> or <code>b</code> is <code>null</code><br> + * Test preconditions: pass <code>null</code> as mentioned parameters<br> + * Expected: must throw <code>NullPointerException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, + java.math.BigInteger.class, byte[].class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray02() { + // test case 1 parameters set + ECFieldFp f = null; + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + + // perform test case 1 + try { + new EllipticCurve(f, a, b, seed); + fail("#1: Expected NPE not thrown"); + } catch (NullPointerException ok) {} + + // test case 2 parameters set, + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = null; + b = BigInteger.valueOf(19L); + seed = new byte[24]; + // perform test case 2 + try { + new EllipticCurve(f, a, b, seed); + fail("#2: Expected NPE not thrown"); + } catch (NullPointerException ok) {} + + // test case 3 parameters set, + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.ONE; + b = null; + seed = new byte[24]; + // perform test case 2 + try { + new EllipticCurve(f, a, b, seed); + fail("#3: Expected NPE not thrown"); + } catch (NullPointerException ok) {} + } + + /** + * Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code> + * constructor<br> + * Assertion: throws <code>IllegalArgumentException</code> if + * <code>a</code> or <code>b</code> is not <code>null</code> and not in + * the <code>field</code><br> + * Test preconditions: pass <code>a</code>, <code>b</code> which are + * not in the <code>field</code> of type <code>ECFieldFp</code><br> + * Expected: must throw <code>IllegalArgumentException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, + java.math.BigInteger.class, byte[].class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray03() { + // test case 1 parameters set, + // a is not in field + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.valueOf(24L); + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + + // perform test case 1 + try { + new EllipticCurve(f, a, b, seed); + fail("#1: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 1.1 parameters set, + // b is not in field + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.valueOf(1L); + b = BigInteger.valueOf(23L); + seed = new byte[24]; + // perform test case 1.1 + try { + new EllipticCurve(f, a, b, seed); + fail("#1.1: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 2 parameters set, + // b is not in field + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.valueOf(19L); + b = BigInteger.valueOf(24L); + seed = new byte[24]; + // perform test case 2 + try { + new EllipticCurve(f, a, b, seed); + fail("#2: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 3 parameters set, + // both a and b are not in field + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.valueOf(25L); + b = BigInteger.valueOf(240L); + seed = new byte[24]; + // perform test case 3 + try { + new EllipticCurve(f, a, b, seed); + fail("#3: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + } + + /** + * Test #4 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code> + * constructor<br> + * Assertion: throws <code>IllegalArgumentException</code> if + * <code>a</code> or <code>b</code> is not <code>null</code> and not in + * the <code>field</code><br> + * Test preconditions: pass <code>a</code>, <code>b</code> which are + * not in the <code>field</code> of type <code>ECFieldF2m</code><br> + * Expected: must throw <code>IllegalArgumentException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, + java.math.BigInteger.class, byte[].class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray04() { + // test case 1 parameters set, + // a is not in field + ECFieldF2m f = new ECFieldF2m(5); + BigInteger a = BigInteger.valueOf(32L); + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + + // perform test case 1 + try { + new EllipticCurve(f, a, b, seed); + fail("#1: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 2 parameters set, + // b is not in field + f = new ECFieldF2m(5); + a = BigInteger.valueOf(19L); + b = BigInteger.valueOf(32L); + seed = new byte[24]; + // perform test case 2 + try { + new EllipticCurve(f, a, b, seed); + fail("#2: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 3 parameters set, + // both a and b are not in field + f = new ECFieldF2m(5); + a = BigInteger.valueOf(32L); + b = BigInteger.valueOf(43L); + seed = new byte[24]; + // perform test case 3 + try { + new EllipticCurve(f, a, b, seed); + fail("#3: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + } + + /** + * Test #5 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code> + * constructor<br> + * Assertion: array <code>seed</code> is copied to prevent subsequent modification<br> + * Test preconditions: pass <code>seed</code> to the ctor then modify it<br> + * Expected: getSeed() must return unmodified array + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that byte array of EllipticCurve can't be modified", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, java.math.BigInteger.class, java.math.BigInteger.class, byte[].class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05() { + ECFieldF2m f = new ECFieldF2m(5); + BigInteger a = BigInteger.valueOf(0L); + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + byte[] seedCopy = seed.clone(); + EllipticCurve c = new EllipticCurve(f, a, b, seedCopy); + // modify array passed + seedCopy[0] = (byte) 1; + // check that above modification did not changed + // internal state of test object + assertTrue(Arrays.equals(seed, c.getSeed())); + } + + /** + * Test #1 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code> + * constructor<br> + * Assertion: creates instance of EllipticCurve<br> + * Test preconditions: valid parameters passed, field type is ECFieldFp<br> + * Expected: must pass without any exceptions + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigInteger01() { + // test case 1 parameters set + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + // perform test case 1 + new EllipticCurve(f, a, b); + + // test case 2 parameters set + ECFieldF2m f1 = new ECFieldF2m(5); + a = BigInteger.ZERO; + b = BigInteger.valueOf(23L); + // perform test case 2 + new EllipticCurve(f1, a, b); + + // test case 3 parameters set, + // the seed parameter may be null + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.ONE; + b = BigInteger.valueOf(19L); + // perform test case 3 + new EllipticCurve(f, a, b); + } + + /** + * Test #2 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code> + * constructor<br> + * Assertion: throws <code>NullPointerException</code> if <code>field</code>, + * <code>a</code> or <code>b</code> is <code>null</code><br> + * Test preconditions: pass <code>null</code> as mentioned parameters<br> + * Expected: must throw <code>NullPointerException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigInteger02() { + // test case 1 parameters set + ECFieldFp f = null; + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + + // perform test case 1 + try { + new EllipticCurve(f, a, b); + fail("#1: Expected NPE not thrown"); + } catch (NullPointerException ok) {} + + // test case 2 parameters set, + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = null; + b = BigInteger.valueOf(19L); + // perform test case 2 + try { + new EllipticCurve(f, a, b); + fail("#2: Expected NPE not thrown"); + } catch (NullPointerException ok) {} + + // test case 3 parameters set, + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.ONE; + b = null; + // perform test case 3 + try { + new EllipticCurve(f, a, b); + fail("#3: Expected NPE not thrown"); + } catch (NullPointerException ok) {} + } + + /** + * Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code> + * constructor<br> + * Assertion: throws <code>IllegalArgumentException</code> if + * <code>a</code> or <code>b</code> is not <code>null</code> and not in + * the <code>field</code><br> + * Test preconditions: pass <code>a</code>, <code>b</code> which are + * not in the <code>field</code> of type <code>ECFieldFp</code><br> + * Expected: must throw <code>IllegalArgumentException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigInteger03() { + // test case 1 parameters set, + // a is not in field + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.valueOf(24L); + BigInteger b = BigInteger.valueOf(19L); + + // perform test case 1 + try { + new EllipticCurve(f, a, b); + fail("#1: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 1.1 parameters set, + // a is not in field + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.valueOf(23L); + b = BigInteger.valueOf(19L); + // perform test case 1.1 + try { + new EllipticCurve(f, a, b); + fail("#1.1: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 2 parameters set, + // b is not in field + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.valueOf(19L); + b = BigInteger.valueOf(24L); + // perform test case 2 + try { + new EllipticCurve(f, a, b); + fail("#2: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 3 parameters set, + // both a and b are not in field + f = new ECFieldFp(BigInteger.valueOf(23L)); + a = BigInteger.valueOf(25L); + b = BigInteger.valueOf(240L); + // perform test case 3 + try { + new EllipticCurve(f, a, b); + fail("#3: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + } + + /** + * Test #4 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code> + * constructor<br> + * Assertion: throws <code>IllegalArgumentException</code> if + * <code>a</code> or <code>b</code> is not <code>null</code> and not in + * the <code>field</code><br> + * Test preconditions: pass <code>a</code>, <code>b</code> which are + * not in the <code>field</code> of type <code>ECFieldF2m</code><br> + * Expected: must throw <code>IllegalArgumentException</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigInteger04() { + // test case 1 parameters set, + // a is not in field + ECFieldF2m f = new ECFieldF2m(5); + BigInteger a = BigInteger.valueOf(32L); + BigInteger b = BigInteger.valueOf(19L); + // perform test case 1 + try { + new EllipticCurve(f, a, b); + fail("#1: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 2 parameters set, + // b is not in field + f = new ECFieldF2m(5); + a = BigInteger.valueOf(19L); + b = BigInteger.valueOf(32L); + // perform test case 2 + try { + new EllipticCurve(f, a, b); + fail("#2: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + + // test case 3 parameters set, + // both a and b are not in field + f = new ECFieldF2m(5); + a = BigInteger.valueOf(32L); + b = BigInteger.valueOf(43L); + // perform test case 3 + try { + new EllipticCurve(f, a, b); + fail("#3: Expected IAE not thrown"); + } catch (IllegalArgumentException ok) {} + } + + /** + * Test for <code>getA()</code> method<br> + * Assertion: returns coefficient <code>a</code><br> + * Test preconditions: <code>ECFieldF2m</code> instance + * created using valid parameters<br> + * Expected: must return coefficient <code>a</code> which is equal + * to the one passed to the constructor; (both must refer + * the same object) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getA", + methodArgs = {} + ) + }) + public final void testGetA() { + ECFieldF2m f = new ECFieldF2m(5); + BigInteger a = BigInteger.valueOf(5L); + BigInteger b = BigInteger.valueOf(19L); + EllipticCurve c = new EllipticCurve(f, a, b); + assertEquals(a, c.getA()); + assertSame(a, c.getA()); + } + + /** + * @tests java/security/spec/EllipticCurve#EllipticCurve(EcField,BigInteger,BigInteger) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "EllipticCurve", + methodArgs = {java.security.spec.ECField.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testEllipticCurveECFieldBigIntegerBigInteger05() { + // Regression for Harmony-731 + EllipticCurve ec = new EllipticCurve(new testECField(), BigInteger + .valueOf(4L), BigInteger.ONE); + assertEquals("incorrect a", ec.getA(), BigInteger.valueOf(4L)); + assertEquals("incorrect b", ec.getB(), BigInteger.ONE); + assertEquals("incorrect size", ec.getField().getFieldSize(), 2); + } + + /** + * Test for <code>getB()</code> method<br> + * Assertion: returns coefficient <code>b</code><br> + * Test preconditions: <code>ECFieldF2m</code> instance + * created using valid parameters<br> + * Expected: must return coefficient <code>b</code> which is equal + * to the one passed to the constructor; (both must refer + * the same object) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getB", + methodArgs = {} + ) + }) + public final void testGetB() { + ECFieldF2m f = new ECFieldF2m(5); + BigInteger a = BigInteger.valueOf(5L); + BigInteger b = BigInteger.valueOf(19L); + EllipticCurve c = new EllipticCurve(f, a, b); + assertEquals(b, c.getB()); + assertSame(b, c.getB()); + } + + /** + * Test for <code>getField()</code> method<br> + * Assertion: returns <code>field</code><br> + * Test preconditions: <code>ECFieldF2m</code> instance + * created using valid parameters<br> + * Expected: must return <code>field</code> which is equal + * to the one passed to the constructor; (both must refer + * the same object) + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getField", + methodArgs = {} + ) + }) + public final void testGetField() { + ECFieldF2m f = new ECFieldF2m(5); + BigInteger a = BigInteger.valueOf(5L); + BigInteger b = BigInteger.valueOf(19L); + EllipticCurve c = new EllipticCurve(f, a, b); + assertEquals(f, c.getField()); + assertSame(f, c.getField()); + } + + /** + * Test #1 for <code>getSeed()</code> method<br> + * Assertion: returns <code>seed</code><br> + * Test preconditions: <code>ECFieldF2m</code> instance + * created using valid parameters<br> + * Expected: must return <code>seed</code> which is equal + * to the one passed to the constructor + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getSeed", + methodArgs = {} + ) + }) + public final void testGetSeed01() { + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + EllipticCurve c = new EllipticCurve(f, a, b, seed); + byte[] seedRet = c.getSeed(); + assertNotNull(seedRet); + assertTrue(Arrays.equals(seed, seedRet)); + } + + /** + * Test #2 for <code>getSeed()</code> method<br> + * Assertion: returned array is copied to prevent subsequent modification<br> + * Test preconditions: <code>ECFieldF2m</code> instance + * created using valid parameters; <code>getSeed()</code> + * called and then returned array modified<br> + * Expected: internal state must not be affected by the modification + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that modification of byte array doesn't change " + + "internal state of test object.", + targets = { + @TestTarget( + methodName = "getSeed", + methodArgs = {} + ) + }) + public final void testGetSeed02() { + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + EllipticCurve c = new EllipticCurve(f, a, b, seed.clone()); + byte[] seedRet = c.getSeed(); + // modify returned array + seedRet[0] = (byte) 1; + // check that above modification did not changed + // internal state of test object + assertTrue(Arrays.equals(seed, c.getSeed())); + } + + /** + * Test #3 for <code>getSeed()</code> method<br> + * Assertion: returned array is copied to prevent subsequent modification<br> + * Test preconditions: <code>ECFieldF2m</code> instance + * created using valid parameters<br> + * Expected: repeated method calls must return different refs + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that repeated calls of getSeed method must " + + "return different refs.", + targets = { + @TestTarget( + methodName = "getSeed", + methodArgs = {} + ) + }) + public final void testGetSeed03() { + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.ONE; + BigInteger b = BigInteger.valueOf(19L); + byte[] seed = new byte[24]; + EllipticCurve c = new EllipticCurve(f, a, b, seed); + c.getSeed(); + assertNotSame(c.getSeed(), c.getSeed()); + } + + /** + * @tests java.security.spec.EllipticCurve#getSeed() + * Assertion: null if not specified + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "getSeed", + methodArgs = {} + ) + }) + public final void testGetSeed04() { + //Regression for HARMONY-732 + ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L)); + BigInteger a = BigInteger.ONE; + assertNull(new EllipticCurve(f, a, a).getSeed()); + } + + /** + * Test #1 for <code>equals(Object other)</code> method<br> + * Assertion: return true if this and other objects are equal<br> + * Test preconditions: see test comments<br> + * Expected: all objects in this test must be equal + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) + public final void testEqualsObject01() { + // test case 1: must be equal to itself + EllipticCurve c2 = null, c1 = new EllipticCurve(new ECFieldFp( + BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger + .valueOf(19L)); + assertTrue(c1.equals(c1)); + + // test case 2: equal objects + c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.ONE, BigInteger.valueOf(19L)); + c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.valueOf(1L), BigInteger.valueOf(19L)); + assertTrue(c1.equals(c2) && c2.equals(c1)); + + // test case 3: equal objects with seed not null + c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]); + c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.valueOf(1L), BigInteger.valueOf(19L), new byte[24]); + assertTrue(c1.equals(c2) && c2.equals(c1)); + + // test case 4: equal object and subclass object + c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]); + MyEllipticCurve c3 = new MyEllipticCurve(new ECFieldFp(BigInteger + .valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), + new byte[24]); + assertTrue(c1.equals(c3) && c3.equals(c1)); + + // test case 5: equal objects + c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.ONE, BigInteger.valueOf(19L)); + c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.valueOf(1L), BigInteger.valueOf(19L), null); + assertTrue(c1.equals(c2) && c2.equals(c1)); + } + + /** + * Test #1 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * repeatedly on the same object. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that several calls of hashCode method for " + + "the same objects return the same values.", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode01() { + int hc = 0; + EllipticCurve f = new EllipticCurve(new ECFieldFp(BigInteger + .valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), + new byte[24]); + hc = f.hashCode(); + assertTrue(hc == f.hashCode() && hc == f.hashCode() + && hc == f.hashCode() && hc == f.hashCode() + && hc == f.hashCode() && hc == f.hashCode() + && hc == f.hashCode() && hc == f.hashCode()); + } + + /** + * Test #2 for <code>hashCode()</code> method.<br> + * + * Assertion: must return the same value if invoked + * on equal (according to the <code>equals(Object)</code> method) objects. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) + public final void testHashCode02() { + assertEquals(new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), + BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]) + .hashCode(), new EllipticCurve(new ECFieldFp(BigInteger + .valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), + new byte[24]).hashCode()); + } + + // + // Private stuff + // + + class testECField implements ECField { + + public int getFieldSize() { + return 2; + } + } + + /** + * EllipticCurve subclass for testing purposes + * + */ + private static class MyEllipticCurve extends EllipticCurve { + + MyEllipticCurve(ECField f, BigInteger a, BigInteger b, byte[] seed) { + super(f, a, b, seed); + } + } +} diff --git a/security/src/test/java/tests/security/spec/EncodedKeySpec2Test.java b/security/src/test/java/tests/security/spec/EncodedKeySpec2Test.java new file mode 100644 index 0000000..68f9308 --- /dev/null +++ b/security/src/test/java/tests/security/spec/EncodedKeySpec2Test.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.Key; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.interfaces.DSAPrivateKey; +import java.security.interfaces.DSAPublicKey; +import java.security.spec.EncodedKeySpec; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +@TestTargetClass(EncodedKeySpec.class) +public class EncodedKeySpec2Test extends TestCase { + + /** + * @tests java.security.spec.EncodedKeySpec#getEncoded() + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public void test_getEncoded() throws Exception { + + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); + + keyGen.initialize(1024); + KeyPair keys = keyGen.generateKeyPair(); + + + KeyFactory fact = KeyFactory.getInstance("DSA"); + + + // check public key encoding + byte[] encoded = keys.getPublic().getEncoded(); + Key key = fact.generatePublic(new X509EncodedKeySpec(encoded)); + + assertTrue("public key encodings were different", + isEqual(key, keys.getPublic())); + + // check private key encoding + encoded = keys.getPrivate().getEncoded(); + key = fact.generatePrivate(new PKCS8EncodedKeySpec(encoded)); + + assertTrue("private key encodings were different", + isEqual(key, keys.getPrivate())); + } + + private boolean isEqual(Key key1, Key key2) { + if (key1 instanceof DSAPublicKey && key2 instanceof DSAPublicKey) { + DSAPublicKey dsa1 = ((DSAPublicKey) key1); + DSAPublicKey dsa2 = ((DSAPublicKey) key2); + return dsa1.getY().equals(dsa2.getY()) + && dsa1.getParams().getG().equals(dsa2.getParams().getG()) + && dsa1.getParams().getP().equals(dsa2.getParams().getP()) + && dsa1.getParams().getQ().equals(dsa2.getParams().getQ()); + + } else if (key1 instanceof DSAPrivateKey + && key2 instanceof DSAPrivateKey) { + DSAPrivateKey dsa1 = ((DSAPrivateKey) key1); + DSAPrivateKey dsa2 = ((DSAPrivateKey) key2); + return dsa1.getX().equals(dsa2.getX()) + && dsa1.getParams().getG().equals(dsa2.getParams().getG()) + && dsa1.getParams().getP().equals(dsa2.getParams().getP()) + && dsa1.getParams().getQ().equals(dsa2.getParams().getQ()); + } else { + return false; + } + } +} diff --git a/security/src/test/java/tests/security/spec/EncodedKeySpecTest.java b/security/src/test/java/tests/security/spec/EncodedKeySpecTest.java new file mode 100644 index 0000000..f5e1920 --- /dev/null +++ b/security/src/test/java/tests/security/spec/EncodedKeySpecTest.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Vladimir N. Molotkov + * @version $Revision$ + */ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import org.apache.harmony.security.tests.support.spec.MyEncodedKeySpec; + +import java.security.spec.EncodedKeySpec; +import java.util.Arrays; + +/** + * Tests for <code>EncodedKeySpec</code> class fields and methods. + * + */ +@TestTargetClass(EncodedKeySpec.class) +public class EncodedKeySpecTest extends TestCase { + + /** + * Constructor for EncodedKeySpecTest. + * + * @param name + */ + public EncodedKeySpecTest(String name) { + super(name); + } + + /** + * Tests for constructor <code>EncodedKeySpec(byte[])</code><br> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed", + targets = { + @TestTarget( + methodName = "EncodedKeySpec", + methodArgs = {byte[].class} + ) + }) + public final void testEncodedKeySpec() { + byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 }; + EncodedKeySpec eks = new MyEncodedKeySpec(encodedKey); + + assertTrue("wrong encoded key was returned", Arrays.equals(encodedKey, + eks.getEncoded())); + assertEquals("wrong name of encoding format", "My", eks.getFormat()); + } + + /** + * Tests that <code>getEncoded()</code> method returns valid byte array + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded() { + + byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 }; + EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey); + + /* Get encoded key */ + byte[] ek = meks.getEncoded(); + + /* Check returned array */ + boolean result = true; + for (int i = 0; i < encodedKey.length; i++) { + if (encodedKey[i] != ek[i]) { + /* indicate failure */ + result = false; + } + } + /* passed */ + assertTrue(result); + } + + /** + * Tests that internal state of the object can not be modified by modifying + * initial array value + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that internal state of the object can not be modified " + + "by modifying initial array value.", + targets = { + @TestTarget( + methodName = "EncodedKeySpec", + methodArgs = {byte[].class} + ), + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testIsStatePreserved1() { + /* Create initial byte array */ + byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 }; + + EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey); + + /* Modify initial array's value */ + encodedKey[3] = (byte) 5; + + /* Get encoded key */ + byte[] ek = meks.getEncoded(); + + /* Check that byte value has not been changed */ + assertTrue(ek[3] == (byte) 4); + } + + /** + * Tests that internal state of the object can not be modified using + * returned value of <code>getEncoded()</code> method + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that internal state of the object can not be modified " + + "by modifying initial array value.", + targets = { + @TestTarget( + methodName = "EncodedKeySpec", + methodArgs = {byte[].class} + ), + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testIsStatePreserved2() { + + byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 }; + EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey); + + /* Get encoded key */ + byte[] ek = meks.getEncoded(); + /* Modify returned value */ + ek[3] = (byte) 5; + /* Get encoded key again */ + byte[] ek1 = meks.getEncoded(); + + /* Check that byte value has not been changed */ + assertTrue(ek1[3] == (byte) 4); + } + +} diff --git a/security/src/test/java/tests/security/spec/InvalidKeySpecExceptionTest.java b/security/src/test/java/tests/security/spec/InvalidKeySpecExceptionTest.java new file mode 100644 index 0000000..90ccc69 --- /dev/null +++ b/security/src/test/java/tests/security/spec/InvalidKeySpecExceptionTest.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.InvalidKeySpecException; + +/** + * Tests for <code>InvalidKeySpecException</code> class constructors and + * methods. + * + */ +@TestTargetClass(InvalidKeySpecException.class) +public class InvalidKeySpecExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for InvalidKeySpecExceptionTests. + * + * @param arg0 + */ + public InvalidKeySpecExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>InvalidKeySpecException()</code> constructor Assertion: + * constructs InvalidKeySpecException with no detail message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {} + ) + }) + public void testInvalidKeySpecException01() { + InvalidKeySpecException tE = new InvalidKeySpecException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>InvalidKeySpecException(String)</code> constructor + * Assertion: constructs InvalidKeySpecException with detail message msg. + * Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.String.class} + ) + }) + public void testInvalidKeySpecException02() { + InvalidKeySpecException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new InvalidKeySpecException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>InvalidKeySpecException(String)</code> constructor + * Assertion: constructs InvalidKeySpecException when <code>msg</code> is + * null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.String.class} + ) + }) + public void testInvalidKeySpecException03() { + String msg = null; + InvalidKeySpecException tE = new InvalidKeySpecException(msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>InvalidKeySpecException(Throwable)</code> constructor + * Assertion: constructs InvalidKeySpecException when <code>cause</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testInvalidKeySpecException04() { + Throwable cause = null; + InvalidKeySpecException tE = new InvalidKeySpecException(cause); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>InvalidKeySpecException(Throwable)</code> constructor + * Assertion: constructs InvalidKeySpecException when <code>cause</code> + * is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive cases.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.Throwable.class} + ) + }) + public void testInvalidKeySpecException05() { + InvalidKeySpecException tE = new InvalidKeySpecException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>InvalidKeySpecException(String, Throwable)</code> + * constructor Assertion: constructs InvalidKeySpecException when + * <code>cause</code> is null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testInvalidKeySpecException06() { + InvalidKeySpecException tE = new InvalidKeySpecException(null, null); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>InvalidKeySpecException(String, Throwable)</code> + * constructor Assertion: constructs InvalidKeySpecException when + * <code>cause</code> is null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a cause parameter.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testInvalidKeySpecException07() { + InvalidKeySpecException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new InvalidKeySpecException(msgs[i], null); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>InvalidKeySpecException(String, Throwable)</code> + * constructor Assertion: constructs InvalidKeySpecException when + * <code>cause</code> is not null <code>msg</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a message parameter.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testInvalidKeySpecException08() { + InvalidKeySpecException tE = new InvalidKeySpecException(null, tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + } + + /** + * Test for <code>InvalidKeySpecException(String, Throwable)</code> + * constructor Assertion: constructs InvalidKeySpecException when + * <code>cause</code> is not null <code>msg</code> is not null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "InvalidKeySpecException", + methodArgs = {java.lang.String.class, java.lang.Throwable.class} + ) + }) + public void testInvalidKeySpecException09() { + InvalidKeySpecException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new InvalidKeySpecException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + } + } +} diff --git a/security/src/test/java/tests/security/spec/InvalidParameterSpecExceptionTest.java b/security/src/test/java/tests/security/spec/InvalidParameterSpecExceptionTest.java new file mode 100644 index 0000000..4495f62 --- /dev/null +++ b/security/src/test/java/tests/security/spec/InvalidParameterSpecExceptionTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vera Y. Petrashkova +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.InvalidParameterSpecException; + +/** + * Tests for <code>InvalidParameterSpecException</code> class constructors and + * methods. + * + */ +@TestTargetClass(InvalidParameterSpecException.class) +public class InvalidParameterSpecExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for InvalidParameterSpecExceptionTests. + * + * @param arg0 + */ + public InvalidParameterSpecExceptionTest(String arg0) { + super(arg0); + } + + static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + static Throwable tCause = new Throwable("Throwable for exception"); + + /** + * Test for <code>InvalidParameterSpecException()</code> constructor + * Assertion: constructs InvalidParameterSpecException with no detail + * message + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidParameterSpecException", + methodArgs = {} + ) + }) + public void testInvalidParameterSpecException01() { + InvalidParameterSpecException tE = new InvalidParameterSpecException(); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } + + /** + * Test for <code>InvalidParameterSpecException(String)</code> constructor + * Assertion: constructs InvalidParameterSpecException with detail message + * msg. Parameter <code>msg</code> is not null. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "InvalidParameterSpecException", + methodArgs = {java.lang.String.class} + ) + }) + public void testInvalidParameterSpecException02() { + InvalidParameterSpecException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new InvalidParameterSpecException(msgs[i]); + assertEquals("getMessage() must return: ".concat(msgs[i]), tE + .getMessage(), msgs[i]); + assertNull("getCause() must return null", tE.getCause()); + } + } + + /** + * Test for <code>InvalidParameterSpecException(String)</code> constructor + * Assertion: constructs InvalidParameterSpecException when <code>msg</code> + * is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "InvalidParameterSpecException", + methodArgs = {java.lang.String.class} + ) + }) + public void testInvalidParameterSpecException03() { + String msg = null; + InvalidParameterSpecException tE = new InvalidParameterSpecException( + msg); + assertNull("getMessage() must return null.", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + } +} diff --git a/security/src/test/java/tests/security/spec/MGF1ParameterSpecTest.java b/security/src/test/java/tests/security/spec/MGF1ParameterSpecTest.java new file mode 100644 index 0000000..6643e49 --- /dev/null +++ b/security/src/test/java/tests/security/spec/MGF1ParameterSpecTest.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.MGF1ParameterSpec; + +/** + * Test for MGF1ParameterSpec class + * + */ +@TestTargetClass(MGF1ParameterSpec.class) +public class MGF1ParameterSpecTest extends TestCase { + + /** + * Meaningless algorithm name just for testing purposes + */ + private static final String testAlgName = "TEST"; + + /** + * Constructor for MGF1ParameterSpecTest. + * @param arg0 + */ + public MGF1ParameterSpecTest(String arg0) { + super(arg0); + } + + // + // Tests + // + + /** + * Test #1 for <code>MGF1ParameterSpec</code> constructor<br> + * Assertion: constructs new <code>MGF1ParameterSpec</code> + * object using valid parameter + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies positive case. Empty/invalid parameter checking missed.", + targets = { + @TestTarget( + methodName = "MGF1ParameterSpec", + methodArgs = {java.lang.String.class} + ) + }) + public final void testMGF1ParameterSpec01() { + new MGF1ParameterSpec(testAlgName); + } + + /** + * Test #2 for <code>MGF1ParameterSpec</code> constructor<br> + * Assertion: <code>NullPointerException</code> if parameter is <code>null</code> + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies null as a parameter. Empty/invalid parameter checking missed.", + targets = { + @TestTarget( + methodName = "MGF1ParameterSpec", + methodArgs = {java.lang.String.class} + ) + }) + public final void testMGF1ParameterSpec02() { + try { + new MGF1ParameterSpec(null); + fail("NullPointerException has not been thrown"); + } catch (NullPointerException ok) { + } + } + + /** + * Test for <code>getDigestAlgorithm</code> method<br> + * Assertion: returns the algorithm name of the message + * digest used by the mask generation function + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getDigestAlgorithm", + methodArgs = {} + ) + }) + public final void testGetDigestAlgorithm() { + MGF1ParameterSpec aps = new MGF1ParameterSpec(testAlgName); + assertTrue(testAlgName.equals(aps.getDigestAlgorithm())); + } + + /** + * Test for public static fields and <code>getDigestAlgorithm</code> method<br> + * Assertion: returns the algorithm name of the message + * digest used by the mask generation function + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Field testing", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) + public final void testFieldsGetDigestAlgorithm() { + assertEquals("SHA-1", MGF1ParameterSpec.SHA1.getDigestAlgorithm()); + assertEquals("SHA-256", MGF1ParameterSpec.SHA256.getDigestAlgorithm()); + assertEquals("SHA-384", MGF1ParameterSpec.SHA384.getDigestAlgorithm()); + assertEquals("SHA-512", MGF1ParameterSpec.SHA512.getDigestAlgorithm()); + } +} diff --git a/security/src/test/java/tests/security/spec/PKCS8EncodedKeySpecTest.java b/security/src/test/java/tests/security/spec/PKCS8EncodedKeySpecTest.java new file mode 100644 index 0000000..f49234a --- /dev/null +++ b/security/src/test/java/tests/security/spec/PKCS8EncodedKeySpecTest.java @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.EncodedKeySpec; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Arrays; + +/** + * Tests for <code>PKCS8EncodedKeySpec</code> class fields and methods. + * + */ +@TestTargetClass(PKCS8EncodedKeySpec.class) +public class PKCS8EncodedKeySpecTest extends TestCase { + + /** + * Constructor for PKCS8EncodedKeySpecTest. + * @param name + */ + public PKCS8EncodedKeySpecTest(String name) { + super(name); + } + + // + // Tests + // + + /** + * Test for <code>PKCS8EncodedKeySpec</code> constructor<br> + * Assertion: constructs new <code>PKCS8EncodedKeySpec</code> + * object using valid parameter + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed.", + targets = { + @TestTarget( + methodName = "PKCS8EncodedKeySpec", + methodArgs = {byte[].class} + ) + }) + public final void testPKCS8EncodedKeySpec() { + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + + EncodedKeySpec eks = new PKCS8EncodedKeySpec(encodedKey); + + assertTrue(eks instanceof PKCS8EncodedKeySpec); + } + + /** + * Test for <code>getEncoded()</code> method<br> + * Assertion: returns encoded key + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded() { + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + + PKCS8EncodedKeySpec meks = new PKCS8EncodedKeySpec(encodedKey); + + byte[] ek = meks.getEncoded(); + + assertTrue(Arrays.equals(encodedKey, ek)); + } + + /** + * Test for <code>getFormat()</code> method + * Assertion: returns format name (always "PKCS#8") + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getFormat", + methodArgs = {} + ) + }) + public final void testGetFormat() { + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + + PKCS8EncodedKeySpec meks = new PKCS8EncodedKeySpec(encodedKey); + + assertEquals("PKCS#8", meks.getFormat()); + } + + /** + * Tests that internal state of the object + * can not be changed by modifying initial + * array value + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that internal state of the object " + + "can not be changed by modifying initial " + + "array value.", + targets = { + @TestTarget( + methodName = "PKCS8EncodedKeySpec", + methodArgs = {byte[].class} + ), + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testIsStatePreserved1() { + // Reference array + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + // Reference array's copy will be used for test + byte[] encodedKeyCopy = encodedKey.clone(); + + PKCS8EncodedKeySpec meks = new PKCS8EncodedKeySpec(encodedKeyCopy); + + // Modify initial array's value + encodedKeyCopy[3] = (byte)5; + + // Get encoded key + byte[] ek = meks.getEncoded(); + + // Check using reference array that + // byte value has not been changed + assertTrue(Arrays.equals(encodedKey, ek)); + } + + /** + * Tests that internal state of the object + * can not be modified using returned value + * of <code>getEncoded()</code> method + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that internal state of the object " + + "can not be modified using returned value " + + "of getEncoded() method.", + targets = { + @TestTarget( + methodName = "PKCS8EncodedKeySpec", + methodArgs = {byte[].class} + ), + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testIsStatePreserved2() { + // Reference array + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + // Reference array's copy will be used for test + byte[] encodedKeyCopy = encodedKey.clone(); + + PKCS8EncodedKeySpec meks = new PKCS8EncodedKeySpec(encodedKeyCopy); + + byte[] ek = meks.getEncoded(); + + // Modify returned array + ek[3] = (byte)5; + + // Get encoded key again + byte[] ek1 = meks.getEncoded(); + + // Check using reference array that + // byte value has not been changed + assertTrue(Arrays.equals(encodedKey, ek1)); + } + +} diff --git a/security/src/test/java/tests/security/spec/PSSParameterSpecTest.java b/security/src/test/java/tests/security/spec/PSSParameterSpecTest.java new file mode 100644 index 0000000..af87741 --- /dev/null +++ b/security/src/test/java/tests/security/spec/PSSParameterSpecTest.java @@ -0,0 +1,459 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.MGF1ParameterSpec; +import java.security.spec.PSSParameterSpec; + +/** + * Tests for <code>PSSParameterSpec</code> class (1.5) + * + */ +@TestTargetClass(PSSParameterSpec.class) +public class PSSParameterSpecTest extends TestCase { + + /** + * Constructor for PSSParameterSpecTest. + * + * @param name + */ + public PSSParameterSpecTest(String name) { + super(name); + } + + /** + * Test #1 for <code>PSSParameterSpec(int)</code> ctor<br> + * Assertion: constructs using valid parameter + * <code>PSSParameterSpec<code> object + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameter.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {int.class} + ) + }) + public final void testPSSParameterSpec0101() { + AlgorithmParameterSpec aps = new PSSParameterSpec(20); + assertTrue(aps instanceof PSSParameterSpec); + } + + /** + * Test #2 for <code>PSSParameterSpec(int)</code> ctor<br> + * Assertion: + * throws <code>IllegalArgumentException</code> + * if <code>saltLen</code> less than 0 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {int.class} + ) + }) + public final void testPSSParameterSpec0102() { + try { + new PSSParameterSpec(-1); + fail("Expected IAE not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /** + * Test #1 for + * <code> + * PSSParameterSpec(String,String,AlgorithmParameterSpec,int,int) + * </code> ctor<br> + * Assertion: constructs using valid parameters + * <code>PSSParameterSpec<code> object + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameters.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.security.spec.AlgorithmParameterSpec.class, + int.class, int.class} + ) + }) + public final void testPSSParameterSpec0201() { + AlgorithmParameterSpec aps = new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, 20, 1); + assertTrue(aps instanceof PSSParameterSpec); + } + + /** + * Test #2 for + * <code> + * PSSParameterSpec(String,String,AlgorithmParameterSpec,int,int) + * </code> ctor<br> + * Assertion: + * throws <code>NullPointerException</code> + * if <code>mdName</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.security.spec.AlgorithmParameterSpec.class, + int.class, int.class} + ) + }) + public final void testPSSParameterSpec0202() { + try { + new PSSParameterSpec(null, "MGF1", MGF1ParameterSpec.SHA1, 20, 1); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #3 for + * <code> + * PSSParameterSpec(String,String,AlgorithmParameterSpec,int,int) + * </code> ctor<br> + * Assertion: + * throws <code>NullPointerException</code> + * if <code>mgfName</code> is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.security.spec.AlgorithmParameterSpec.class, + int.class, int.class} + ) + }) + public final void testPSSParameterSpec0203() { + try { + new PSSParameterSpec("SHA-1", null, MGF1ParameterSpec.SHA1, 20, 1); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for + * <code> + * PSSParameterSpec(String,String,AlgorithmParameterSpec,int,int) + * </code> ctor<br> + * Assertion: + * throws <code>IllegalArgumentException<code> + * if <code>saltLen<code> less than 0 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.security.spec.AlgorithmParameterSpec.class, + int.class, int.class} + ) + }) + public final void testPSSParameterSpec0204() { + try { + new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, -20, 1); + fail("Expected IAE not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /** + * Test #5 for + * <code> + * PSSParameterSpec(String,String,AlgorithmParameterSpec,int,int) + * </code> ctor<br> + * Assertion: + * throws <code>IllegalArgumentException</code> + * if <code>trailerField</code> less than 0 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.security.spec.AlgorithmParameterSpec.class, + int.class, int.class} + ) + }) + public final void testPSSParameterSpec0205() { + try { + new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, 20, -1); + fail("Expected IAE not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /** + * Test #6 for + * <code> + * PSSParameterSpec(String,String,AlgorithmParameterSpec,int,int) + * </code> ctor<br> + * Assertion: <code>AlgorithmParameterSpec</code> can be null + * + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as AlgorithmParameterSpec parameter.", + targets = { + @TestTarget( + methodName = "PSSParameterSpec", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.security.spec.AlgorithmParameterSpec.class, + int.class, int.class} + ) + }) + public final void testPSSParameterSpec0206() { + new PSSParameterSpec("SHA-1", "MGF1", null, 20, 1); + } + + /** + * Test for <code>getDigestAlgorithm()</code> method + * Assertion: returns message digest algorithm name + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getDigestAlgorithm", + methodArgs = {} + ) + }) + public final void testGetDigestAlgorithm() { + PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, 20, 1); + assertEquals("SHA-1", pssps.getDigestAlgorithm()); + } + + /** + * Test for <code>getMGFAlgorithm()</code> method + * Assertion: returns mask generation function algorithm name + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getMGFAlgorithm", + methodArgs = {} + ) + }) + public final void testGetMGFAlgorithm() { + PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, 20, 1); + assertEquals("MGF1", pssps.getMGFAlgorithm()); + } + + /** + * Test #1 for <code>getMGFParameters()</code> method + * Assertion: returns mask generation function parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getMGFParameters", + methodArgs = {} + ) + }) + public final void testGetMGFParameters01() { + PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, 20, 1); + assertTrue(MGF1ParameterSpec.SHA1.equals(pssps.getMGFParameters())); + } + + /** + * Test #2 for <code>getMGFParameters()</code> method + * Assertion: returns <code>null</code> + * if <code>null</code> had been passed as + * AlgorithmParameterSpec parameter to the ctor + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getMGFParameters", + methodArgs = {} + ) + }) + public final void testGetMGFParameters02() { + PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1", + null, 20, 1); + assertNull(pssps.getMGFParameters()); + } + + + /** + * Test for <code>getSaltLength()</code> method<br> + * Assertion: returns salt length value + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getSaltLength", + methodArgs = {} + ) + }) + public final void testGetSaltLength() { + PSSParameterSpec pssps = new PSSParameterSpec(20); + assertEquals(20, pssps.getSaltLength()); + } + + /** + * Test for <code>getTrailerField()</code> method<br> + * Assertion: returns trailer field value + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getTrailerField", + methodArgs = {} + ) + }) + public final void testGetTrailerField() { + PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1", + MGF1ParameterSpec.SHA1, 20, 1); + assertEquals(1, pssps.getTrailerField()); + } + + /** + * Test for <code>DEFAULT</code> field<br> + * Assertion: default message digest algorithm name is "SHA-1" + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the name of default message digest algorithm.", + targets = { + @TestTarget( + methodName = "getDigestAlgorithm", + methodArgs = {} + ) + }) + public final void testDEFAULTmdName() { + assertEquals("SHA-1", PSSParameterSpec.DEFAULT.getDigestAlgorithm()); + } + + /** + * Test for <code>DEFAULT</code> field<br> + * Assertion: default mask generation function algorithm name is "MGF1" + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the name of default mask generation function " + + "algorithm.", + targets = { + @TestTarget( + methodName = "getMGFAlgorithm", + methodArgs = {} + ) + }) + public final void testDEFAULTmgfName() { + assertEquals("MGF1", PSSParameterSpec.DEFAULT.getMGFAlgorithm()); + } + + /** + * Test for <code>DEFAULT</code> field<br> + * Assertion: default algorithm parameters for mask + * generation function are <code>MGF1ParameterSpec.SHA1</code> + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies default algorithm parameters for mask generation " + + "function.", + targets = { + @TestTarget( + methodName = "getMGFParameters", + methodArgs = {} + ) + }) + public final void testDEFAULTmgfSpec() { + assertTrue(MGF1ParameterSpec.SHA1.equals(PSSParameterSpec.DEFAULT.getMGFParameters())); + } + + /** + * Test for <code>DEFAULT</code> field<br> + * Assertion: default salt length value is 20 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getSaltLength", + methodArgs = {} + ) + }) + public final void testDEFAULTsaltLen() { + assertEquals(20, PSSParameterSpec.DEFAULT.getSaltLength()); + } + + /** + * Test for <code>DEFAULT</code> field<br> + * Assertion: default trailer field value is 1 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies default trailer field value.", + targets = { + @TestTarget( + methodName = "getTrailerField", + methodArgs = {} + ) + }) + public final void testDEFAULTtrailerField() { + assertEquals(1, PSSParameterSpec.DEFAULT.getTrailerField()); + } +} diff --git a/security/src/test/java/tests/security/spec/RSAKeyGenParameterSpecTest.java b/security/src/test/java/tests/security/spec/RSAKeyGenParameterSpecTest.java new file mode 100644 index 0000000..6814ab4 --- /dev/null +++ b/security/src/test/java/tests/security/spec/RSAKeyGenParameterSpecTest.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; + +/** + * Tests for <code>RSAKeyGenParameterSpec</code> class fields and methods. + * + */ +@TestTargetClass(RSAKeyGenParameterSpec.class) +public class RSAKeyGenParameterSpecTest extends TestCase { + + /** + * Constructor for RSAKeyGenParameterSpecTest. + * @param name + */ + public RSAKeyGenParameterSpecTest(String name) { + super(name); + } + + /** + * Test for <code>RSAKeyGenParameterSpec(int,BigInteger)</code> ctor + * Assertion: constructs <code>RSAKeyGenParameterSpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "RSAKeyGenParameterSpec", + methodArgs = {int.class, java.math.BigInteger.class} + ) + }) + public final void testRSAKeyGenParameterSpec() { + AlgorithmParameterSpec aps = + new RSAKeyGenParameterSpec(512, BigInteger.valueOf(0L)); + assertTrue(aps instanceof RSAKeyGenParameterSpec); + } + + /** + * Test for <code>getKeySize()</code> method<br> + * Assertion: returns key size value + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getKeysize", + methodArgs = {} + ) + }) + public final void testGetKeysize() { + RSAKeyGenParameterSpec rkgps = + new RSAKeyGenParameterSpec(512, BigInteger.valueOf(0L)); + assertEquals(512, rkgps.getKeysize()); + } + + /** + * Test for <code>getPublicExponent()</code> method<br> + * Assertion: returns public exponent value + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicExponent", + methodArgs = {} + ) + }) + public final void testGetPublicExponent() { + RSAKeyGenParameterSpec rkgps = + new RSAKeyGenParameterSpec(512, BigInteger.valueOf(0L)); + assertEquals(0, rkgps.getPublicExponent().intValue()); + } + + /** + * Test for <code>F0</code> field<br> + * Assertion: the public exponent value F0 = 3 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Test for F0 field.", + targets = { + @TestTarget( + methodName = "!Constants", + methodArgs = {} + ) + }) + public final void testF0Value() { + assertEquals(3, RSAKeyGenParameterSpec.F0.intValue()); + } + + /** + * Test for <code>F4</code> field<br> + * Assertion: the public exponent value F0 = 65537 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Test for F4 field.", + targets = { + @TestTarget( + methodName = "!Constants", + methodArgs = {} + ) + }) + public final void testF4Value() { + assertEquals(65537, RSAKeyGenParameterSpec.F4.intValue()); + } + +} diff --git a/security/src/test/java/tests/security/spec/RSAMultiPrimePrivateCrtKeySpecTest.java b/security/src/test/java/tests/security/spec/RSAMultiPrimePrivateCrtKeySpecTest.java new file mode 100644 index 0000000..9078c55 --- /dev/null +++ b/security/src/test/java/tests/security/spec/RSAMultiPrimePrivateCrtKeySpecTest.java @@ -0,0 +1,998 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.KeySpec; +import java.security.spec.RSAMultiPrimePrivateCrtKeySpec; +import java.security.spec.RSAOtherPrimeInfo; +import java.security.spec.RSAPrivateKeySpec; + +/** + * Tests for <code>RSAMultiPrimePrivateCrtKeySpec</code> class fields and methods. + * + */ +@TestTargetClass(RSAMultiPrimePrivateCrtKeySpec.class) +public class RSAMultiPrimePrivateCrtKeySpecTest extends TestCase { + /** + * Reference array of RSAOtherPrimeInfo. DO NOT MODIFY + */ + private static final RSAOtherPrimeInfo[] opi = new RSAOtherPrimeInfo[] { + new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE), + new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE), + new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE) + }; + + /** + * Constructor for RSAMultiPrimePrivateCrtKeySpecTest. + * @param name + */ + public RSAMultiPrimePrivateCrtKeySpecTest(String name) { + super(name); + } + + // Test-cases: + + /** + * Test #1 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: constructs <code>RSAMultiPrimePrivateCrtKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameters.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec01() { + KeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(ks instanceof RSAMultiPrimePrivateCrtKeySpec); + } + + /** + * Test #2 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if modulus is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec02() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + null, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #3 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if publicExponent is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec03() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + null, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if privateExponent is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec04() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + null, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #5 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if primeP is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec05() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #6 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if primeQ is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec06() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #7 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if primeExponentP is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec07() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null, + BigInteger.ONE, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #8 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if primeExponentQ is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec08() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null, + BigInteger.ONE, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #9 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: NullPointerException if crtCoefficient is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec09() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null, + opi); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #10 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: otherPrimeInfo can be null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null otherPrimeInfo.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec10() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null); + } catch (Exception e) { + fail("Unexpected exception is thrown"); + } + } + + /** + * Test #11 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: IllegalArgumentException if otherPrimeInfo length is 0 + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec11() { + try { + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + new RSAOtherPrimeInfo[0]); + fail("Expected IAE not thrown"); + } catch (IllegalArgumentException e) { + } + } + + /** + * Test #12 for + * <code>RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, + * BigInteger publicExponent, + * BigInteger privateExponent, + * BigInteger primeP, + * BigInteger primeQ, + * BigInteger primeExponentP, + * BigInteger primeExponentQ, + * BigInteger crtCoefficient, + * RSAOtherPrimeInfo[] otherPrimeInfo) + * </code> ctor<br> + * Assertion: constructs <code>RSAMultiPrimePrivateCrtKeySpec</code> + * object using valid parameters. Constructed object must be + * instance of RSAPrivateKeySpec. + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor using valid parameters. " + + "Constructed object must be instance of RSAPrivateKeySpec.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.security.spec.RSAOtherPrimeInfo[].class} + ) + }) + public final void testRSAMultiPrimePrivateCrtKeySpec12() { + KeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(ks instanceof RSAPrivateKeySpec); + } + + /** + * Test for <code>getCrtCoefficient()</code> method<br> + * Assertion: returns crt coefficient + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCrtCoefficient", + methodArgs = {} + ) + }) + public final void testGetCrtCoefficient() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getCrtCoefficient())); + } + + /** + * Test for <code>getPrimeExponentP()</code> method<br> + * Assertion: returns prime exponent P + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeExponentP", + methodArgs = {} + ) + }) + public final void testGetPrimeExponentP() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getPrimeExponentP())); + } + + /** + * Test for <code>getPrimeExponentQ()</code> method<br> + * Assertion: returns prime exponent Q + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeExponentQ", + methodArgs = {} + ) + }) + public final void testGetPrimeExponentQ() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getPrimeExponentQ())); + } + + /** + * Test for <code>getPrimeP()</code> method<br> + * Assertion: returns prime P + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeP", + methodArgs = {} + ) + }) + public final void testGetPrimeP() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getPrimeP())); + } + + /** + * Test for <code>getPrimeQ()</code> method<br> + * Assertion: returns prime Q + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeQ", + methodArgs = {} + ) + }) + public final void testGetPrimeQ() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getPrimeQ())); + } + + /** + * Test for <code>getPublicExponent()</code> method<br> + * Assertion: returns public exponent + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicExponent", + methodArgs = {} + ) + }) + public final void testGetPublicExponent() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getPublicExponent())); + } + + /** + * Test #1 for <code>getOtherPrimeInfo()</code> method<br> + * Assertion: returns array of RSAOtherPrimeInfo + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case.", + targets = { + @TestTarget( + methodName = "getOtherPrimeInfo", + methodArgs = {} + ) + }) + public final void testGetOtherPrimeInfo01() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo())); + } + + /** + * Test #2 for <code>getOtherPrimeInfo()</code> method<br> + * Assertion: returns null if null has been passed to the + * constructor as otherPrimeInfo parameter + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that getOtherPrimeInfo returns null if " + + "there are only two prime factors.", + targets = { + @TestTarget( + methodName = "getOtherPrimeInfo", + methodArgs = {} + ) + }) + public final void testGetOtherPrimeInfo02() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + null); + assertNull(ks.getOtherPrimeInfo()); + } + + // + // immutability tests + // + + /** + * Tests that internal state of the object + * can not be modified by modifying initial array + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that internal state of the object can not be modified " + + "by modifying initial array.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ), + @TestTarget( + methodName = "getOtherPrimeInfo", + methodArgs = {} + ) + }) + public final void testIsStatePreserved1() { + // Create initial array + RSAOtherPrimeInfo[] opi1 = opi.clone(); + + RSAMultiPrimePrivateCrtKeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi1); + + // Modify initial array + opi1[2] = new RSAOtherPrimeInfo(BigInteger.ZERO, + BigInteger.ZERO, + BigInteger.ZERO); + + // Check that above modification + // does not affect internal state + assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo())); + } + + /** + * Tests that internal state of the object + * can not be modified using array reference + * returned by <code>getOtherPrimeInfo()</code> + * method + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that internal state of the object can not be " + + "modified using array reference returned by getOtherPrimeInfo() " + + "method.", + targets = { + @TestTarget( + methodName = "RSAMultiPrimePrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.security.spec.RSAOtherPrimeInfo[].class} + ), + @TestTarget( + methodName = "getOtherPrimeInfo", + methodArgs = {} + ) + }) + public final void testIsStatePreserved2() { + // Create initial array + RSAOtherPrimeInfo[] opi1 = opi.clone(); + + RSAMultiPrimePrivateCrtKeySpec ks = new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi1); + + RSAOtherPrimeInfo[] ret = ks.getOtherPrimeInfo(); + + // Modify returned array + ret[2] = new RSAOtherPrimeInfo(BigInteger.ZERO, + BigInteger.ZERO, + BigInteger.ZERO); + + // Check that above modification + // does not affect internal state + assertTrue(checkOtherPrimeInfo(ks.getOtherPrimeInfo())); + } + + // + // Tests for inherited methods + // + + /** + * Test for <code>getModulus()</code> method<br> + * Assertion: returns modulus + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getModulus", + methodArgs = {} + ) + }) + public final void testGetModulus() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getModulus())); + } + + /** + * Test for <code>getPrivateExponent()</code> method<br> + * Assertion: returns private exponent + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateExponent", + methodArgs = {} + ) + }) + public final void testGetPrivateExponent() { + RSAMultiPrimePrivateCrtKeySpec ks = + new RSAMultiPrimePrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + opi); + assertTrue(BigInteger.ONE.equals(ks.getPrivateExponent())); + } + +// private stuff +// + /** + * Compares array passed as a parameter with reference one<br> + * + * <code>private static final RSAOtherPrimeInfo[] opi</code> + * + * @param toBeChecked + * Array to be compared + * @return + * true if arrays are equal + */ + private boolean checkOtherPrimeInfo(RSAOtherPrimeInfo[] toBeChecked) { + if (toBeChecked == null || toBeChecked.length != opi.length) { + return false; + } + for (int i=0; i<opi.length; i++) { + if (opi[i].getPrime().equals(toBeChecked[i].getPrime()) && + opi[i].getExponent().equals(toBeChecked[i].getExponent()) && + opi[i].getCrtCoefficient().equals(toBeChecked[i].getCrtCoefficient())) { + continue; + } + return false; + } + return true; + } + +} diff --git a/security/src/test/java/tests/security/spec/RSAOtherPrimeInfoTest.java b/security/src/test/java/tests/security/spec/RSAOtherPrimeInfoTest.java new file mode 100644 index 0000000..508eb1f --- /dev/null +++ b/security/src/test/java/tests/security/spec/RSAOtherPrimeInfoTest.java @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.RSAOtherPrimeInfo; + +/** + * Tests for <code>RSAOtherPrimeInfo</code> class fields and methods. + * + */ +@TestTargetClass(RSAOtherPrimeInfo.class) +public class RSAOtherPrimeInfoTest extends TestCase { + + /** + * Constructor for RSAOtherPrimeInfoTest. + * @param name + */ + public RSAOtherPrimeInfoTest(String name) { + super(name); + } + + /** + * Test #1 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor + * Assertion: constructs <code>RSAOtherPrimeInfo</code> + * object using valid parameter + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameters.", + targets = { + @TestTarget( + methodName = "RSAOtherPrimeInfo", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class} + ) + }) + public final void testRSAOtherPrimeInfo01() { + Object o = + new RSAOtherPrimeInfo(BigInteger.valueOf(1L), + BigInteger.valueOf(2L), + BigInteger.valueOf(3L)); + assertTrue(o instanceof RSAOtherPrimeInfo); + } + + /** + * Test #2 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor + * Assertion: NullPointerException if prime is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAOtherPrimeInfo", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class} + ) + }) + public final void testRSAOtherPrimeInfo02() { + try { + new RSAOtherPrimeInfo(null, + BigInteger.valueOf(2L), + BigInteger.valueOf(3L)); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #3 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor + * Assertion: NullPointerException if primeExponent is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAOtherPrimeInfo", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class} + ) + }) + public final void testRSAOtherPrimeInfo03() { + try { + new RSAOtherPrimeInfo(BigInteger.valueOf(1L), + null, + BigInteger.valueOf(3L)); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #4 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor + * Assertion: NullPointerException if crtCoefficient is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAOtherPrimeInfo", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class} + ) + }) + public final void testRSAOtherPrimeInfo04() { + try { + new RSAOtherPrimeInfo(BigInteger.valueOf(1L), + BigInteger.valueOf(2L), + null); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test #5 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor + * Assertion: NullPointerException if prime and crtCoefficient is null + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "RSAOtherPrimeInfo", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class} + ) + }) + public final void testRSAOtherPrimeInfo05() { + try { + new RSAOtherPrimeInfo(null, + BigInteger.valueOf(2L), + null); + fail("Expected NPE not thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test for <code>getCrtCoefficient()</code> method<br> + * Assertion: returns CRT coefficient value + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCrtCoefficient", + methodArgs = {} + ) + }) + public final void testGetCrtCoefficient() { + RSAOtherPrimeInfo ropi = + new RSAOtherPrimeInfo(BigInteger.valueOf(1L), + BigInteger.valueOf(2L), + BigInteger.valueOf(3L)); + assertEquals(3L, ropi.getCrtCoefficient().longValue()); + } + + /** + * Test for <code>getPrime()</code> method<br> + * Assertion: returns prime value + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrime", + methodArgs = {} + ) + }) + public final void testGetPrime() { + RSAOtherPrimeInfo ropi = + new RSAOtherPrimeInfo(BigInteger.valueOf(1L), + BigInteger.valueOf(2L), + BigInteger.valueOf(3L)); + assertEquals(1L, ropi.getPrime().longValue()); + } + + /** + * Test for <code>getExponent()</code> method<br> + * Assertion: returns prime exponent value + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getExponent", + methodArgs = {} + ) + }) + public final void testGetExponent() { + RSAOtherPrimeInfo ropi = + new RSAOtherPrimeInfo(BigInteger.valueOf(1L), + BigInteger.valueOf(2L), + BigInteger.valueOf(3L)); + assertEquals(2L, ropi.getExponent().longValue()); + } + +} diff --git a/security/src/test/java/tests/security/spec/RSAPrivateCrtKeySpecTest.java b/security/src/test/java/tests/security/spec/RSAPrivateCrtKeySpecTest.java new file mode 100644 index 0000000..fcbf536 --- /dev/null +++ b/security/src/test/java/tests/security/spec/RSAPrivateCrtKeySpecTest.java @@ -0,0 +1,353 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.KeySpec; +import java.security.spec.RSAPrivateCrtKeySpec; +import java.security.spec.RSAPrivateKeySpec; + +/** + * Tests for <code>RSAPrivateCrtKeySpec</code> class fields and methods + * + */ +@TestTargetClass(RSAPrivateCrtKeySpec.class) +public class RSAPrivateCrtKeySpecTest extends TestCase { + + /** + * Constructor for RSAPrivateCrtKeySpecTest. + * @param name + */ + public RSAPrivateCrtKeySpecTest(String name) { + super(name); + } + + /** + * Test #1 for <code>RSAPrivateCrtKeySpec</code> constructor + * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameters.", + targets = { + @TestTarget( + methodName = "RSAPrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testRSAPrivateCrtKeySpec01() { + KeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(ks instanceof RSAPrivateCrtKeySpec); + } + + /** + * Test #2 for <code>RSAPrivateCrtKeySpec</code> constructor + * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameters.", + targets = { + @TestTarget( + methodName = "RSAPrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testRSAPrivateCrtKeySpec02() { + KeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(ks instanceof RSAPrivateKeySpec); + } + + /** + * Test #3 for <code>RSAPrivateCrtKeySpec</code> constructor + * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "RSAPrivateCrtKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class, + java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testRSAPrivateCrtKeySpec03() { + new RSAPrivateCrtKeySpec( + null, + null, + null, + null, + null, + null, + null, + null); + } + + /** + * Test for <code>getCrtCoefficient()</code> method<br> + * Assertion: returns crt coefficient + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getCrtCoefficient", + methodArgs = {} + ) + }) + public final void testGetCrtCoefficient() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.valueOf(5L)); + assertTrue(BigInteger.valueOf(5L).equals(ks.getCrtCoefficient())); + } + + /** + * Test for <code>getPrimeExponentP()</code> method<br> + * Assertion: returns prime exponent P + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeExponentP", + methodArgs = {} + ) + }) + public final void testGetPrimeExponentP() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.valueOf(5L), + BigInteger.ONE, + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentP())); + } + + /** + * Test for <code>getPrimeExponentQ()</code> method<br> + * Assertion: returns prime exponent Q + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeExponentQ", + methodArgs = {} + ) + }) + public final void testGetPrimeExponentQ() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.valueOf(5L), + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentQ())); + } + + /** + * Test for <code>getPrimeP()</code> method<br> + * Assertion: returns prime P + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeP", + methodArgs = {} + ) + }) + public final void testGetPrimeP() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.valueOf(5L), + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeP())); + } + + /** + * Test for <code>getPrimeQ()</code> method<br> + * Assertion: returns prime Q + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrimeQ", + methodArgs = {} + ) + }) + public final void testGetPrimeQ() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.valueOf(5L), + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeQ())); + } + + /** + * Test for <code>getPublicExponent()</code> method<br> + * Assertion: returns public exponent + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicExponent", + methodArgs = {} + ) + }) + public final void testGetPublicExponent() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.valueOf(5L), + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getPublicExponent())); + } + + // + // Tests for inherited methods + // + + /** + * Test for <code>getModulus()</code> method<br> + * Assertion: returns modulus + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getModulus", + methodArgs = {} + ) + }) + public final void testGetModulus() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.valueOf(5L), + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getModulus())); + } + + /** + * Test for <code>getPrivateExponent()</code> method<br> + * Assertion: returns private exponent + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateExponent", + methodArgs = {} + ) + }) + public final void testGetPrivateExponent() { + RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( + BigInteger.ONE, + BigInteger.ONE, + BigInteger.valueOf(5L), + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE, + BigInteger.ONE); + assertTrue(BigInteger.valueOf(5L).equals(ks.getPrivateExponent())); + } + +} diff --git a/security/src/test/java/tests/security/spec/RSAPrivateKeySpecTest.java b/security/src/test/java/tests/security/spec/RSAPrivateKeySpecTest.java new file mode 100644 index 0000000..1bf5f3d --- /dev/null +++ b/security/src/test/java/tests/security/spec/RSAPrivateKeySpecTest.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.KeySpec; +import java.security.spec.RSAPrivateKeySpec; + +/** + * Tests for <code>RSAPrivateKeySpec</code> class fields and methods + * + */ +@TestTargetClass(RSAPrivateKeySpec.class) +public class RSAPrivateKeySpecTest extends TestCase { + + /** + * Constructor for RSAPrivateKeySpecTest. + * @param name + */ + public RSAPrivateKeySpecTest(String name) { + super(name); + } + + /** + * Test for <code>RSAPrivateKeySpec(BigInteger,BigInteger)</code> ctor + * Assertion: constructs <code>RSAPrivateKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "RSAPrivateKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testRSAPrivateKeySpec() { + KeySpec ks = new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L), + BigInteger.valueOf(3L)); + assertTrue(ks instanceof RSAPrivateKeySpec); + } + + /** + * Test for <code>getModulus()</code> method<br> + * Assertion: returns modulus + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getModulus", + methodArgs = {} + ) + }) + public final void testGetModulus() { + RSAPrivateKeySpec rpks = + new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L), + BigInteger.valueOf(3L)); + assertEquals(1234567890L, rpks.getModulus().longValue()); + } + + /** + * Test for <code>getPrivateExponent()</code> method<br> + * Assertion: returns private exponent + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPrivateExponent", + methodArgs = {} + ) + }) + public final void testGetPrivateExponent() { + RSAPrivateKeySpec rpks = + new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L), + BigInteger.valueOf(3L)); + assertEquals(3L, rpks.getPrivateExponent().longValue()); + } + +} diff --git a/security/src/test/java/tests/security/spec/RSAPublicKeySpecTest.java b/security/src/test/java/tests/security/spec/RSAPublicKeySpecTest.java new file mode 100644 index 0000000..afe9c1a --- /dev/null +++ b/security/src/test/java/tests/security/spec/RSAPublicKeySpecTest.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.math.BigInteger; +import java.security.spec.KeySpec; +import java.security.spec.RSAPublicKeySpec; + +/** + * Tests for <code>RSAPublicKeySpec</code> class fields and methods + * + */ +@TestTargetClass(RSAPublicKeySpec.class) +public class RSAPublicKeySpecTest extends TestCase { + + /** + * Constructor for RSAPublicKeySpecTest. + * @param name + */ + public RSAPublicKeySpecTest(String name) { + super(name); + } + + + /** + * Test #1 for <code>RSAPublicKeySpec</code> constructor + * Assertion: Constructs <code>RSAPublicKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with valid parameters.", + targets = { + @TestTarget( + methodName = "RSAPublicKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testRSAPublicKeySpec01() { + KeySpec ks = + new RSAPublicKeySpec(BigInteger.valueOf(1234567890L), + BigInteger.valueOf(3L)); + + assertTrue(ks instanceof RSAPublicKeySpec); + } + + /** + * Test #2 for <code>RSAPublicKeySpec</code> constructor + * Assertion: Constructs <code>RSAPublicKeySpec</code> + * object using valid parameters + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as parameters.", + targets = { + @TestTarget( + methodName = "RSAPublicKeySpec", + methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} + ) + }) + public final void testRSAPublicKeySpec02() { + KeySpec ks = + new RSAPublicKeySpec(null, null); + + assertTrue(ks instanceof RSAPublicKeySpec); + } + + /** + * Test for <code>getModulus()</code> method<br> + * Assertion: returns modulus + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getModulus", + methodArgs = {} + ) + }) + public final void testGetModulus() { + RSAPublicKeySpec rpks = + new RSAPublicKeySpec(BigInteger.valueOf(1234567890L), + BigInteger.valueOf(3L)); + assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getModulus())); + } + + /** + * Test for <code>getPublicExponent()</code> method<br> + * Assertion: returns public exponent + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getPublicExponent", + methodArgs = {} + ) + }) + public final void testGetPublicExponent() { + RSAPublicKeySpec rpks = + new RSAPublicKeySpec(BigInteger.valueOf(3L), + BigInteger.valueOf(1234567890L)); + assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getPublicExponent())); + } + +} diff --git a/security/src/test/java/tests/security/spec/X509EncodedKeySpecTest.java b/security/src/test/java/tests/security/spec/X509EncodedKeySpecTest.java new file mode 100644 index 0000000..ae2792a --- /dev/null +++ b/security/src/test/java/tests/security/spec/X509EncodedKeySpecTest.java @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @author Vladimir N. Molotkov +* @version $Revision$ +*/ + +package tests.security.spec; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import java.security.spec.EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.Arrays; + +/** + * Tests for <code>X509EncodedKeySpec</code> class fields and methods + * + */ +@TestTargetClass(X509EncodedKeySpec.class) +public class X509EncodedKeySpecTest extends TestCase { + + /** + * Constructor for X509EncodedKeySpecTest. + * @param name + */ + public X509EncodedKeySpecTest(String name) { + super(name); + } + + // + // Test cases + // + + /** + * Test for <code>X509EncodedKeySpec</code> constructor<br> + * Assertion: constructs new <code>X509EncodedKeySpec</code> + * object using valid parameter + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Null parameter checking missed.", + targets = { + @TestTarget( + methodName = "X509EncodedKeySpec", + methodArgs = {byte[].class} + ) + }) + public final void testX509EncodedKeySpec() { + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + + EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey); + + assertTrue(eks instanceof X509EncodedKeySpec); + } + + /** + * Test for <code>getEncoded()</code> method<br> + * Assertion: returns encoded key + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testGetEncoded() { + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + + X509EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey); + + byte[] ek = eks.getEncoded(); + + assertTrue(Arrays.equals(encodedKey, ek)); + } + + /** + * Test for <code>getFormat()</code> method + * Assertion: returns format name (always "X.509") + */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getFormat", + methodArgs = {} + ) + }) + public final void testGetFormat() { + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + + X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKey); + + assertEquals("X.509", meks.getFormat()); + } + + /** + * Tests that internal state of the object + * can not be changed by modifying initial + * array value + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies that internal state of the object " + + "can not be changed by modifying initial " + + "array value.", + targets = { + @TestTarget( + methodName = "X509EncodedKeySpec", + methodArgs = {byte[].class} + ), + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testIsStatePreserved1() { + // Reference array + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + // Reference array's copy will be used for test + byte[] encodedKeyCopy = encodedKey.clone(); + + X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKeyCopy); + + // Modify initial array's value + encodedKeyCopy[3] = (byte)5; + + // Get encoded key + byte[] ek = meks.getEncoded(); + + // Check using reference array that + // byte value has not been changed + assertTrue(Arrays.equals(encodedKey, ek)); + } + + /** + * Tests that internal state of the object + * can not be modified using returned value + * of <code>getEncoded()</code> method + */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "X509EncodedKeySpec", + methodArgs = {byte[].class} + ), + @TestTarget( + methodName = "getEncoded", + methodArgs = {} + ) + }) + public final void testIsStatePreserved2() { + // Reference array + byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4}; + // Reference array's copy will be used for test + byte[] encodedKeyCopy = encodedKey.clone(); + + X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKeyCopy); + + byte[] ek = meks.getEncoded(); + + // Modify returned array + ek[3] = (byte)5; + + // Get encoded key again + byte[] ek1 = meks.getEncoded(); + + // Check using reference array that + // byte value has not been changed + assertTrue(Arrays.equals(encodedKey, ek1)); + } + +} |