diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /tests/auto/qsslkey | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'tests/auto/qsslkey')
48 files changed, 648 insertions, 0 deletions
diff --git a/tests/auto/qsslkey/.gitignore b/tests/auto/qsslkey/.gitignore new file mode 100644 index 0000000..7c9a790 --- /dev/null +++ b/tests/auto/qsslkey/.gitignore @@ -0,0 +1 @@ +tst_qsslkey diff --git a/tests/auto/qsslkey/keys/dsa-pri-1024.der b/tests/auto/qsslkey/keys/dsa-pri-1024.der Binary files differnew file mode 100644 index 0000000..5b4026b --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-1024.der diff --git a/tests/auto/qsslkey/keys/dsa-pri-1024.pem b/tests/auto/qsslkey/keys/dsa-pri-1024.pem new file mode 100644 index 0000000..cdb16c3 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-1024.pem @@ -0,0 +1,12 @@ +-----BEGIN DSA PRIVATE KEY----- +MIIBuwIBAAKBgQDBDNxGlo12UTCZ4S5XxcfQ8pKaYMaPYCpcJqbRMQ89VshZPFus +ZycnITHQ3fjhHyxPfXFwzKFh9cxvJTGyWmazQBj4YOG09DzPs3fvRiIz5zu1bdJ0 +rH0VJNKdbDmdDH2BKssPrqIjQoLNwjQLcE5Ddg2as8dfg6pPi7QVq2+U6wIVAMMh +a50lRJAJckZuztWEkV4I7H03AoGAfRXSIMUWvfnwLIDuuThj5KhFKML0kd0BxrT9 +H0dICi4pTv7DyH7OWhrCS/025aK/AehrfU+QSiceUPxZLSxeyisSgtxWIolp8zgj +1hBPUW/lpMwNgChoKf8EgagHHY4Y0+eLnL7D/5M4hBX9eQLhK3tvaULbkW4pjR+r +nYW9UEMCgYAhRYQ296sCvQlqjhTyj8/VFahXvXnV2YuQ/2QFm0KHXbRXsmR2ectw +NcaBvD87EZ3KRXQiSXzea6WycOw9YXcTmgzLUefHaBkQ38973pmPIrO91HDJqVE0 +GLOIIbh796Y/9z7//BO4yAXQO9jcxeFKwiB2zYluZOVDOiFFgqqbMgIVAK0dcUpb +9EOsRsRdOVI3hIxssc71 +-----END DSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pri-512.der b/tests/auto/qsslkey/keys/dsa-pri-512.der Binary files differnew file mode 100644 index 0000000..0fc977f --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-512.der diff --git a/tests/auto/qsslkey/keys/dsa-pri-512.pem b/tests/auto/qsslkey/keys/dsa-pri-512.pem new file mode 100644 index 0000000..35210e4 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-512.pem @@ -0,0 +1,8 @@ +-----BEGIN DSA PRIVATE KEY----- +MIH4AgEAAkEA2tY9+lNVCnDx//ciofnvm/OPWi7oMQ6XFFfXrpjltIG+9eRQv0j4 +SqcwHpsqcaC4vjsbHFTDR0p8UyUAbrXzLwIVAOKRP6SgXHveEJ//aztaVltEWqBB +AkAj1tdgG3FQBxG5UJQGl53XsOOBJ9xz21RrrrlkqCO9G9ClNjmQ1XzrkBHije1M +Pb6iOLH1aPYiY6svkxaDMb88AkEAzobcabWo6sag70paK/ihZlSbd4EC5Hl1XjtC +5sKFBkjLK3A79f9TobAwDiHzSxdiLNT0xKd+iOKoWZnAj+TJ2AIUI7+wILGkcyW7 +nb4wf7r1HYIo8bk= +-----END DSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pri-576.der b/tests/auto/qsslkey/keys/dsa-pri-576.der Binary files differnew file mode 100644 index 0000000..30cea46 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-576.der diff --git a/tests/auto/qsslkey/keys/dsa-pri-576.pem b/tests/auto/qsslkey/keys/dsa-pri-576.pem new file mode 100644 index 0000000..a398ddc --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-576.pem @@ -0,0 +1,8 @@ +-----BEGIN DSA PRIVATE KEY----- +MIIBDwIBAAJJANeKU0IdVgDc/dVL6vrEjgZW8lMLrUyjYDhu65sl8LaOmamwvozx +ISFjYaeIMPCloHnn2jijsjQpjnlj5rVRT1MYWt2i56jV+wIVANvg9uDO7mNdcuOW +uT+xveysakC9Akg2q1Vi56KzKVR4T2KIS4yTH3bz2wwiWd80p+SylyOkM/fSIrxJ +IRYGugR1WY7lgWAI8E0mJDXKmajpGSvysDHnjdlSpSVSUNICSD9wBxobS/ySpKs+ +ks11XCPyZiMsf+LjUtT7nK5RBTG0PDEw+82MchouPc4YUPGR+Qf64GB7AxBYQpt/ +YhLXtFVCocZUt0HJBwIUHhfcQUujc40YUkOYavxrU+1eQUY= +-----END DSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pri-960.der b/tests/auto/qsslkey/keys/dsa-pri-960.der Binary files differnew file mode 100644 index 0000000..d8291b8 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-960.der diff --git a/tests/auto/qsslkey/keys/dsa-pri-960.pem b/tests/auto/qsslkey/keys/dsa-pri-960.pem new file mode 100644 index 0000000..054c174 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pri-960.pem @@ -0,0 +1,11 @@ +-----BEGIN DSA PRIVATE KEY----- +MIIBnwIBAAJ5AMDmMbjPuQOJOd57ZBya8tICsSbRGo+yStRm0rubqAnjKzgMOZc8 +CWT+/2ddVYKuQCzG0DEYeGyBxGUSP2Z7TQrVJ/4GmHLeHJIiIBT8JAh+yHmDWhNO +sKZbsUtsckwBEuh/1vs++L+PX8QGvHCE6Y+sFTR6xCs6EQIVAO/gigt7sEp3MzIh +cFGLiT6PlbNNAnh+GFk2cJecrMbpw3dT5ilTPZkWm8nyC/1fJwVk4dEdY7yjAnCX +Su1eO1m6RLM/OlVXMT84HKaqA95w09dg8s9LmlrKR5ROH6MXYoOweowFcd/PrJd7 +U3sGRN7cwzVEW8/PZODYJY0Ab0bhpjQYeMObQf61t3iREbUCeB6KXt9DouH7ccWX +keJM0Uf+eXCxPbnMwMsR6ae3F2G/YNlarqkKI3CpuwcKI1Hvq3iitznPPmZJrqlG +ywI+es5axqskbV/7NY6VcwaHVR3FcdSpksxCuG5zP3GEqVS7b3WPj98jBGMb0VB4 +CtK6CpxjC283/Yuy8QIUdyj4ssD0ezN3bhOJtr3fBGWjX6k= +-----END DSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pub-1024.der b/tests/auto/qsslkey/keys/dsa-pub-1024.der Binary files differnew file mode 100644 index 0000000..efff9d2 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-1024.der diff --git a/tests/auto/qsslkey/keys/dsa-pub-1024.pem b/tests/auto/qsslkey/keys/dsa-pub-1024.pem new file mode 100644 index 0000000..f39bc37 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-1024.pem @@ -0,0 +1,12 @@ +-----BEGIN PUBLIC KEY----- +MIIBtjCCASsGByqGSM44BAEwggEeAoGBAMEM3EaWjXZRMJnhLlfFx9Dykppgxo9g +KlwmptExDz1WyFk8W6xnJychMdDd+OEfLE99cXDMoWH1zG8lMbJaZrNAGPhg4bT0 +PM+zd+9GIjPnO7Vt0nSsfRUk0p1sOZ0MfYEqyw+uoiNCgs3CNAtwTkN2DZqzx1+D +qk+LtBWrb5TrAhUAwyFrnSVEkAlyRm7O1YSRXgjsfTcCgYB9FdIgxRa9+fAsgO65 +OGPkqEUowvSR3QHGtP0fR0gKLilO/sPIfs5aGsJL/Tblor8B6Gt9T5BKJx5Q/Fkt +LF7KKxKC3FYiiWnzOCPWEE9Rb+WkzA2AKGgp/wSBqAcdjhjT54ucvsP/kziEFf15 +AuEre29pQtuRbimNH6udhb1QQwOBhAACgYAhRYQ296sCvQlqjhTyj8/VFahXvXnV +2YuQ/2QFm0KHXbRXsmR2ectwNcaBvD87EZ3KRXQiSXzea6WycOw9YXcTmgzLUefH +aBkQ38973pmPIrO91HDJqVE0GLOIIbh796Y/9z7//BO4yAXQO9jcxeFKwiB2zYlu +ZOVDOiFFgqqbMg== +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pub-512.der b/tests/auto/qsslkey/keys/dsa-pub-512.der Binary files differnew file mode 100644 index 0000000..5d60a65 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-512.der diff --git a/tests/auto/qsslkey/keys/dsa-pub-512.pem b/tests/auto/qsslkey/keys/dsa-pub-512.pem new file mode 100644 index 0000000..df5f999 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-512.pem @@ -0,0 +1,8 @@ +-----BEGIN PUBLIC KEY----- +MIHxMIGoBgcqhkjOOAQBMIGcAkEA2tY9+lNVCnDx//ciofnvm/OPWi7oMQ6XFFfX +rpjltIG+9eRQv0j4SqcwHpsqcaC4vjsbHFTDR0p8UyUAbrXzLwIVAOKRP6SgXHve +EJ//aztaVltEWqBBAkAj1tdgG3FQBxG5UJQGl53XsOOBJ9xz21RrrrlkqCO9G9Cl +NjmQ1XzrkBHije1MPb6iOLH1aPYiY6svkxaDMb88A0QAAkEAzobcabWo6sag70pa +K/ihZlSbd4EC5Hl1XjtC5sKFBkjLK3A79f9TobAwDiHzSxdiLNT0xKd+iOKoWZnA +j+TJ2A== +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pub-576.der b/tests/auto/qsslkey/keys/dsa-pub-576.der Binary files differnew file mode 100644 index 0000000..8c67395 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-576.der diff --git a/tests/auto/qsslkey/keys/dsa-pub-576.pem b/tests/auto/qsslkey/keys/dsa-pub-576.pem new file mode 100644 index 0000000..3a594bf --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-576.pem @@ -0,0 +1,8 @@ +-----BEGIN PUBLIC KEY----- +MIIBCDCBuAYHKoZIzjgEATCBrAJJANeKU0IdVgDc/dVL6vrEjgZW8lMLrUyjYDhu +65sl8LaOmamwvozxISFjYaeIMPCloHnn2jijsjQpjnlj5rVRT1MYWt2i56jV+wIV +ANvg9uDO7mNdcuOWuT+xveysakC9Akg2q1Vi56KzKVR4T2KIS4yTH3bz2wwiWd80 +p+SylyOkM/fSIrxJIRYGugR1WY7lgWAI8E0mJDXKmajpGSvysDHnjdlSpSVSUNID +SwACSD9wBxobS/ySpKs+ks11XCPyZiMsf+LjUtT7nK5RBTG0PDEw+82MchouPc4Y +UPGR+Qf64GB7AxBYQpt/YhLXtFVCocZUt0HJBw== +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/dsa-pub-960.der b/tests/auto/qsslkey/keys/dsa-pub-960.der Binary files differnew file mode 100644 index 0000000..58c80e8 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-960.der diff --git a/tests/auto/qsslkey/keys/dsa-pub-960.pem b/tests/auto/qsslkey/keys/dsa-pub-960.pem new file mode 100644 index 0000000..bcdc9e3 --- /dev/null +++ b/tests/auto/qsslkey/keys/dsa-pub-960.pem @@ -0,0 +1,11 @@ +-----BEGIN PUBLIC KEY----- +MIIBmjCCARkGByqGSM44BAEwggEMAnkAwOYxuM+5A4k53ntkHJry0gKxJtEaj7JK +1GbSu5uoCeMrOAw5lzwJZP7/Z11Vgq5ALMbQMRh4bIHEZRI/ZntNCtUn/gaYct4c +kiIgFPwkCH7IeYNaE06wpluxS2xyTAES6H/W+z74v49fxAa8cITpj6wVNHrEKzoR +AhUA7+CKC3uwSnczMiFwUYuJPo+Vs00CeH4YWTZwl5ysxunDd1PmKVM9mRabyfIL +/V8nBWTh0R1jvKMCcJdK7V47WbpEsz86VVcxPzgcpqoD3nDT12Dyz0uaWspHlE4f +oxdig7B6jAVx38+sl3tTewZE3tzDNURbz89k4NgljQBvRuGmNBh4w5tB/rW3eJER +tQN7AAJ4Hope30Oi4ftxxZeR4kzRR/55cLE9uczAyxHpp7cXYb9g2VquqQojcKm7 +BwojUe+reKK3Oc8+ZkmuqUbLAj56zlrGqyRtX/s1jpVzBodVHcVx1KmSzEK4bnM/ +cYSpVLtvdY+P3yMEYxvRUHgK0roKnGMLbzf9i7Lx +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/genkeys.sh b/tests/auto/qsslkey/keys/genkeys.sh new file mode 100755 index 0000000..ee36a6c --- /dev/null +++ b/tests/auto/qsslkey/keys/genkeys.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# This script generates cryptographic keys of different types. + +#--- RSA --------------------------------------------------------------------------- +# Note: RSA doesn't require the key size to be divisible by any particular number +for size in 40 511 512 999 1023 1024 2048 +do + echo -e "\ngenerating RSA private key to PEM file ..." + openssl genrsa -out rsa-pri-$size.pem $size + + echo -e "\ngenerating RSA private key to DER file ..." + openssl rsa -in rsa-pri-$size.pem -out rsa-pri-$size.der -outform DER + + echo -e "\ngenerating RSA public key to PEM file ..." + openssl rsa -in rsa-pri-$size.pem -pubout -out rsa-pub-$size.pem + + echo -e "\ngenerating RSA public key to DER file ..." + openssl rsa -in rsa-pri-$size.pem -pubout -out rsa-pub-$size.der -outform DER +done + +#--- DSA ---------------------------------------------------------------------------- +# Note: DSA requires the key size to be in interval [512, 1024] and be divisible by 64 +for size in 512 576 960 1024 +do + echo -e "\ngenerating DSA parameters to PEM file ..." + openssl dsaparam -out dsapar-$size.pem $size + + echo -e "\ngenerating DSA private key to PEM file ..." + openssl gendsa dsapar-$size.pem -out dsa-pri-$size.pem + + /bin/rm dsapar-$size.pem + + echo -e "\ngenerating DSA private key to DER file ..." + openssl dsa -in dsa-pri-$size.pem -out dsa-pri-$size.der -outform DER + + echo -e "\ngenerating DSA public key to PEM file ..." + openssl dsa -in dsa-pri-$size.pem -pubout -out dsa-pub-$size.pem + + echo -e "\ngenerating DSA public key to DER file ..." + openssl dsa -in dsa-pri-$size.pem -pubout -out dsa-pub-$size.der -outform DER +done diff --git a/tests/auto/qsslkey/keys/rsa-pri-1023.der b/tests/auto/qsslkey/keys/rsa-pri-1023.der Binary files differnew file mode 100644 index 0000000..d23dde8 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-1023.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-1023.pem b/tests/auto/qsslkey/keys/rsa-pri-1023.pem new file mode 100644 index 0000000..bd1c119 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-1023.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICWQIBAAKBgF0LbcbxSbBWA+7N9kaZ1OHRChPCN74g69SuV29p+CkRcgReeZHB +LkEcTERBUn5hw4AlgbmbVEFplLs/bbqS7hOK/Pkz9TCM9wG2j8T2mcPIi8NU8RMc +oNyVINlVduKxSID491sRZuQXLX+CM7klIA7rpcdsfefpuhPu0yTCJ1wJAgMBAAEC +gYAVxvYDqTfREODMxOIOdjTQQaf1JfD8DCKGXePTDN9rZUzlXuNfTPKxhJkJJKzV +LbafSKgLNCLNSJPqG5doIrmcCU4r4qVhjyQtTQ8orFaIKjWgrvIUXh8DIioKOD3o +ikiJvg0A7oL4+F/jHqpeUzzlNOyGRRsNP95DJUor1UuT3QJBAMD7qNUXYxDLtjs9 +VFRRN7KkUvBz4FXD+XwgE1ZrYQEy7IN/ZaHeFGb/59WbQc5LEwDY5N+GFlwWm0pQ +6iZdj4cCQHttdWhXcutPDZOUs6JHq8Q6q9j8USGyhmJ3nOKnbGOLhimvlceW+P0n +AjGnFhicIdr7sht1HgacsfHxT+WD++8CQGQDyRsu9LOmr/oBrevI79HQof9mPpSU +bX8r7Hm0SuDhMHxyEQ0T2IUNCWzF+xPcCqw8vFkv1/S/7plUWBWsFY8CQGnrFMXl +xYiI3m23PjAUsSJD9xTN8hGo0gnN+6PFaQ5DvW4ob7BHroQP5aIWcK/NzH/PXpiR +eKLT9SBapOWgzaECQFp8lWNJpW4dK2w0XafRB3fwQ/OOvv4EWTOCsbHEmNg/RgIG +HKNAZekwBn9lfnYRaKC7z9VtTEy6mmMnaLE6Srw= +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pri-1024.der b/tests/auto/qsslkey/keys/rsa-pri-1024.der Binary files differnew file mode 100644 index 0000000..0ea2059 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-1024.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-1024.pem b/tests/auto/qsslkey/keys/rsa-pri-1024.pem new file mode 100644 index 0000000..f2fc5b0 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-1024.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQDN8qIMJKzoi0rUWBYx7ggiUATFLITKbHQ+sdeb3JKwzHv4pLY1 +YNsQWd+RD1tLUN5qJNrj4b8GWyJ4pipxr9Dq0Ak5b0Qvhuell5a8JVrUSRvsfUvc +VlNY6yv7JZKetCYmCEF/IkRc4RegS8bEOU4lddN3RotDsu6eZ7/sgyPd0wIDAQAB +AoGAIXeecc678oZAQMWXxcFivQC35brYUXTSZyXLXd64T9bLBprtqTr2HnAcbpxK +P7ECk8ktcP7MZiIFNgn6t8LUdik34iMdkzqAG4w4g/qET1ANd+cvGs6Ct5b+82HY +7s4sGXsOyU9BKltHrjSSEn3EIhC58GZQpJADNoiBb63f5kECQQD50SNoeb3LcFs/ +peZNcbpm7yR3BEkDYm94iENmP/Su4Y38OJ/cArmEODj/pg6UAgtq6r5ARjfQUKkz +G+WD421jAkEA0wuJMMRtNh8ellc7BEbmVpgWCOZFjDXAyH0atv+THDnhq5bs4PNh +ldc+PDVO6b3BXxanzrfH19qE9P1xTscw0QJABPKhcuZGXgsho4cToqEIAhXmcP0C +vTBr6MU6IIJPxE7vUvmEIQVkyzuZ1WZij4fi1gFEN12sqVGPqFV7HDua5QJADfTf +V7hFuKSKM0sFfhzqMqPQITqJMuKDIz8SuzNfmShCwkQy2hV+SJh5ZyXnWBHSbeVj +p4oDz0SGMmVoTtthYQJBAOJeHHuQ7M/rZjHWRiVFnyAh/WfBdD1d/4JgfjsHJUEp +yCfMpEw5Nb1vBdlhKIn1tTBUMX5WCeQaZWIi1g9OAnU= +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pri-2048.der b/tests/auto/qsslkey/keys/rsa-pri-2048.der Binary files differnew file mode 100644 index 0000000..194da2a --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-2048.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-2048.pem b/tests/auto/qsslkey/keys/rsa-pri-2048.pem new file mode 100644 index 0000000..125d281 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-2048.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEAuwQ1KqA3hewLXsG9fHD7UI3fQu5ylQiDeRWEwsFovmiDfDNo +7P/VuByvQmVR30p3GzNnZdMsj8jVlLD/Wny1nU/O2T00KQ95SJhiEGGCVWirRf/7 +F1KrFGP7HuiQ76FQwqtRxBDQw3QOm2PXp20EpyzGdYpY13EkY6n0FLumWoJxL+2g +TW0ECyLulxXFK9wXCNWnY+ji5V8VwDfkXk7WXYzMawnFnKNiSJ99jkfJ28lo+Ba8 +LAfvHM6ygeudWndri6pGkA/R0Z3knca6yz5YJCMph5AKgj9beOaLsIWEbdbmZA7f +zuu8QhBK6cjvjUbS6iPVDEfBnI6TOpGPJxvWNwIDAQABAoIBAE5bZfdVJ85Z5y2t +mToBkJrgxpGhnKqq5YMfK//5z2wwGB863xSl4KMCicAU+afH6H2iHQmB4GLiL/Lb +8jG0nNerr6w/w5IMpLFw/22DnXsxnsl2hnrwLTQe7AG4SbnNaiwWYez3arDp+JDM +1XeV6uQsk35+F9k0051agSUKtpmm5Be9bu6lW8a55gJsAvUIrj0eLxXN7nxhI6tL +W1fwylJUX0ACka5SMsFOue7UPxPEGpM2OHI64T3QWpgoaXwyfNyn22u4PHOiWOtt +io/r5Ta61mf8FiSV8X33/nm/yjUpW2EKJuIxA8IWcrADTyQrO5AKq0MFJjQVy8I+ +jrx0pzkCgYEA6LJp/slfTiz6Y9b5GVFY48QL+msorvjuyPdGwEkkCGAjo8E24Lac +91T2Bx3XKxTrqyu8FDwa0RQzXresM0Tqvi3WT/oIauuiZL2U3ef32QQ42tvOWmGM +09hES8Ymx78xFUzh20AdzAfLGaxvQ4Z19yt/aGmZH1/Giyc+TO8rBusCgYEAzb6y +FMQSYvnvQTLI2qUt1h/kjU01JdCkGRgfMyyAW/pYq56vPJBKvsnrH0rDmICY3Cam +Ma4hf7HekfqbIyYw+cklxZHYmVPf16T9Tyopwwltf8k9mULwnsSY7Cti2VBGcAGs +DbgYz9HoJERe2qfgWKuTGXMHTXh5+x28bncecuUCgYAZGITN8bHRoJAwjFK5JEjN +56rTCxOMK1S1X9XFjx3PuW6ejov4mDk9g3A1PEakYtE32LOkCwdpXSBdKrnrnZcj +g5YFchXOUjNlYfzYIdhdE1N+Zw5OOQ8TGdPjyC8Og9QrU+tX1gZgpsaEslAdnDbE +vXA0No9JDu8+urDBY1nkmQKBgCxwErCPhNUh3H49hMpMwPCtpMSsN116iebtodeA +thynnr06oei31Z0NqZ3xnPt0Uw/BvUWfsZaOCV+IPDfESPG6c1EP5jN/vSordZbC +qZB5mc/u3EIdBjGUjt77o/cB8qTAh7PS3nEMilJC/iXF+pvMOxJVGO+vpNELJCbL +zaTNAoGAQ7qhJUUWENzWbuh1g/bYy/980/nhE24iWGwQgFeQOrUnghBLQvUUp7a0 +kwNqZmlxl97HCxusM2T/lZoPvMBWhzfszzbaZchiOWIkbUXiHTrVsRnBHysHTpD+ +bsHGs9ILGSEYymWOErGII5wZ5DJOVUmtzCrgRvyZfxbH/lOZSZc= +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pri-40.der b/tests/auto/qsslkey/keys/rsa-pri-40.der Binary files differnew file mode 100644 index 0000000..227cbbb --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-40.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-40.pem b/tests/auto/qsslkey/keys/rsa-pri-40.pem new file mode 100644 index 0000000..e480b11 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-40.pem @@ -0,0 +1,4 @@ +-----BEGIN RSA PRIVATE KEY----- +MC8CAQACBgC+dq4BGQIDAQABAgVOUamohQIDDtUPAgMM11cCAnzbAgMA350CAwIz +jw== +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pri-511.der b/tests/auto/qsslkey/keys/rsa-pri-511.der Binary files differnew file mode 100644 index 0000000..43da254 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-511.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-511.pem b/tests/auto/qsslkey/keys/rsa-pri-511.pem new file mode 100644 index 0000000..70872d9 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-511.pem @@ -0,0 +1,9 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIBOAIBAAJAVFNCgrdkp5mE62MBco89Ip/tbJdHq09d8Q72Kw0SERi8zoXewZR7 +NwlcAns+boTWCzgRfIs051qZGzao9o+jaQIDAQABAkA111ePSPOew7oH5ZZGBElf +s0eQX2NmcW2k/g2V3Wmcui+ejz9edzsooCXYBiLtfAIHNq0MwOLkl6kmxfoeGgAV +AiEAxnr8EPGStCvtIf4IFKHZdbl/+FanTVec0WqLPW+U2vMCIGzDPosDi74f30vi +78PfdSgy+pp4Sp/0pSttHBrQfyczAiEAkRTa5gO/ScYGG1/WRkacb2o9+ahVuLo/ +HfC0gR7r/zMCIBi+53j7iozsdYKvlHvNWLuXtbr1iY0RPY8+2Pkk3PlPAiB3CDCM +Pu1PssfpwYB0Lr68Mnx1oiZPLZje5HAVzptD6A== +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pri-512.der b/tests/auto/qsslkey/keys/rsa-pri-512.der Binary files differnew file mode 100644 index 0000000..156a1d1 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-512.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-512.pem b/tests/auto/qsslkey/keys/rsa-pri-512.pem new file mode 100644 index 0000000..dda274f --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-512.pem @@ -0,0 +1,9 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIBPAIBAAJBAOyVSr5qVl/cuVAbjSs1cLFi17mJXg8X9vQC9xb4BjHUY9i60vIV +zAaE9knwaNkRwPfxgzp244WGFzXRO7UwHKECAwEAAQJBAOCAMvNKmThSjg90dZuh +FJVfxHIt5nHQPeoDvlGvfsFchWLI42451QTKbXFlSBLb2F4kCVrzLZN5zrGfcagy +pgECIQD4pPthJoUmQVCLqMJKgtFPzfwSetxYe8+BFeBKupSz8QIhAPOU998ZEmzB +YPajTzmUK9SIxk88m93O5GSqC+HS4eOxAiBHbM0xaSlSheynUcEOOmn6LMe+X0Cw +wlAnWqtljBdvYQIhAJiIoPBEcxVHw8CvY91avFfLjuPvwGuWM9AV7Hrt5CcBAiEA +ykI2wY34X9/1rodR/6CXUW5cJq7TCHt8bAsowkXH7bU= +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pri-999.der b/tests/auto/qsslkey/keys/rsa-pri-999.der Binary files differnew file mode 100644 index 0000000..3b3f8ca --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-999.der diff --git a/tests/auto/qsslkey/keys/rsa-pri-999.pem b/tests/auto/qsslkey/keys/rsa-pri-999.pem new file mode 100644 index 0000000..6ed72bf --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pri-999.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICSwIBAAJ9ZTk4kN4YU/14BJi/Fsa0cgMnN7hzZIGD0Tw5kzTBh2SKPkd5TkaM +saWAsI+ZBICDTxEAUJ4y7KW/QchROTjRI04HKBXa30rk51WQ98W9/AEN4+roWeA9 +YQ3V1nIu1lYA+Ypb4/kBW1VI9yeOTxh4QD1zyrBP3CQ1wQrhth8CAwEAAQJ9El4T +uZXTbEouIQdmhUeBLr8Lurypk688sBbxi5ijFWJVA4AMrvt2RDX36BHmfj6jlRFM +sVRDgVWCIvmqY2u8I0YuHoLRc7Xsg6ICQljxz0H5frs2q4suc2AHEbxBstlUWHSQ +fYDyNq/b1xf5+LOCeU6VP9z3ZwtHydACgYECPwzrRsj4dMIs2/i6Vs0Epa8gf4Oc +kw+e1sjigFkvpA/iDJl39wG+lJQkYEfJEY2cfCCIBreof9sKtq6SP3a3kQI/B9XQ +nsjhw71h6lV/dOUFRmSYV7fJDIIqZEA+NvO24kRjbSagKXNKFWRgq/SRzbT9Z4vC +WPhhCYbi6zeU/ZqvAj8Bi/FPgh9IV+KF5pkZtmK3kqZxdT9N8XA5YJSJGOEFXcSw +YuJZfR2AltJIBdRqJb/ejSpwtmWILcItKCkc52ECPwM4rKJsEy6IMbbH2jR0aNvN +Rjlibb2/0rAPHcU4JKwY1AwvglAof4AWGgz46+14iWtGMeykijkBhVCSNKakLwI/ +Bjzrf1iLEl3ylN47Cukse7sKSXI58tUaIJprjihMO/64dVK1ZdkXVGLMft9Eq+7l +wTVe2ajpMWFm9wAD8114 +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-1023.der b/tests/auto/qsslkey/keys/rsa-pub-1023.der Binary files differnew file mode 100644 index 0000000..4b16fdd --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-1023.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-1023.pem b/tests/auto/qsslkey/keys/rsa-pub-1023.pem new file mode 100644 index 0000000..174a135 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-1023.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgF0LbcbxSbBWA+7N9kaZ1OHRChPC +N74g69SuV29p+CkRcgReeZHBLkEcTERBUn5hw4AlgbmbVEFplLs/bbqS7hOK/Pkz +9TCM9wG2j8T2mcPIi8NU8RMcoNyVINlVduKxSID491sRZuQXLX+CM7klIA7rpcds +fefpuhPu0yTCJ1wJAgMBAAE= +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-1024.der b/tests/auto/qsslkey/keys/rsa-pub-1024.der Binary files differnew file mode 100644 index 0000000..9649592 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-1024.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-1024.pem b/tests/auto/qsslkey/keys/rsa-pub-1024.pem new file mode 100644 index 0000000..d5c8da9 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-1024.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDN8qIMJKzoi0rUWBYx7ggiUATF +LITKbHQ+sdeb3JKwzHv4pLY1YNsQWd+RD1tLUN5qJNrj4b8GWyJ4pipxr9Dq0Ak5 +b0Qvhuell5a8JVrUSRvsfUvcVlNY6yv7JZKetCYmCEF/IkRc4RegS8bEOU4lddN3 +RotDsu6eZ7/sgyPd0wIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-2048.der b/tests/auto/qsslkey/keys/rsa-pub-2048.der Binary files differnew file mode 100644 index 0000000..560487b --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-2048.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-2048.pem b/tests/auto/qsslkey/keys/rsa-pub-2048.pem new file mode 100644 index 0000000..95daf33 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-2048.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuwQ1KqA3hewLXsG9fHD7 +UI3fQu5ylQiDeRWEwsFovmiDfDNo7P/VuByvQmVR30p3GzNnZdMsj8jVlLD/Wny1 +nU/O2T00KQ95SJhiEGGCVWirRf/7F1KrFGP7HuiQ76FQwqtRxBDQw3QOm2PXp20E +pyzGdYpY13EkY6n0FLumWoJxL+2gTW0ECyLulxXFK9wXCNWnY+ji5V8VwDfkXk7W +XYzMawnFnKNiSJ99jkfJ28lo+Ba8LAfvHM6ygeudWndri6pGkA/R0Z3knca6yz5Y +JCMph5AKgj9beOaLsIWEbdbmZA7fzuu8QhBK6cjvjUbS6iPVDEfBnI6TOpGPJxvW +NwIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-40.der b/tests/auto/qsslkey/keys/rsa-pub-40.der Binary files differnew file mode 100644 index 0000000..3d789a7 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-40.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-40.pem b/tests/auto/qsslkey/keys/rsa-pub-40.pem new file mode 100644 index 0000000..f053580 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-40.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCEwDQYJKoZIhvcNAQEBBQADEAAwDQIGAL52rgEZAgMBAAE= +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-511.der b/tests/auto/qsslkey/keys/rsa-pub-511.der Binary files differnew file mode 100644 index 0000000..2da3341 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-511.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-511.pem b/tests/auto/qsslkey/keys/rsa-pub-511.pem new file mode 100644 index 0000000..a5135f0 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-511.pem @@ -0,0 +1,4 @@ +-----BEGIN PUBLIC KEY----- +MFswDQYJKoZIhvcNAQEBBQADSgAwRwJAVFNCgrdkp5mE62MBco89Ip/tbJdHq09d +8Q72Kw0SERi8zoXewZR7NwlcAns+boTWCzgRfIs051qZGzao9o+jaQIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-512.der b/tests/auto/qsslkey/keys/rsa-pub-512.der Binary files differnew file mode 100644 index 0000000..372ba8f --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-512.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-512.pem b/tests/auto/qsslkey/keys/rsa-pub-512.pem new file mode 100644 index 0000000..d3a5e58 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-512.pem @@ -0,0 +1,4 @@ +-----BEGIN PUBLIC KEY----- +MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOyVSr5qVl/cuVAbjSs1cLFi17mJXg8X +9vQC9xb4BjHUY9i60vIVzAaE9knwaNkRwPfxgzp244WGFzXRO7UwHKECAwEAAQ== +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/keys/rsa-pub-999.der b/tests/auto/qsslkey/keys/rsa-pub-999.der Binary files differnew file mode 100644 index 0000000..1d28000 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-999.der diff --git a/tests/auto/qsslkey/keys/rsa-pub-999.pem b/tests/auto/qsslkey/keys/rsa-pub-999.pem new file mode 100644 index 0000000..00ba479 --- /dev/null +++ b/tests/auto/qsslkey/keys/rsa-pub-999.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGaMA0GCSqGSIb3DQEBAQUAA4GIADCBhAJ9ZTk4kN4YU/14BJi/Fsa0cgMnN7hz +ZIGD0Tw5kzTBh2SKPkd5TkaMsaWAsI+ZBICDTxEAUJ4y7KW/QchROTjRI04HKBXa +30rk51WQ98W9/AEN4+roWeA9YQ3V1nIu1lYA+Ypb4/kBW1VI9yeOTxh4QD1zyrBP +3CQ1wQrhth8CAwEAAQ== +-----END PUBLIC KEY----- diff --git a/tests/auto/qsslkey/qsslkey.pro b/tests/auto/qsslkey/qsslkey.pro new file mode 100644 index 0000000..5cab3d5 --- /dev/null +++ b/tests/auto/qsslkey/qsslkey.pro @@ -0,0 +1,24 @@ +load(qttest_p4) + +SOURCES += tst_qsslkey.cpp +!wince*:win32:LIBS += -lws2_32 +QT += network + +TARGET = tst_qsslkey + +win32 { + CONFIG(debug, debug|release) { + DESTDIR = debug +} else { + DESTDIR = release + } +} + +wince*: { + keyFiles.sources = keys + keyFiles.path = . + DEPLOYMENT += keyFiles + DEFINES += SRCDIR=\\\".\\\" +} else { + DEFINES+= SRCDIR=\\\"$$PWD\\\" +} diff --git a/tests/auto/qsslkey/tst_qsslkey.cpp b/tests/auto/qsslkey/tst_qsslkey.cpp new file mode 100644 index 0000000..06f9013 --- /dev/null +++ b/tests/auto/qsslkey/tst_qsslkey.cpp @@ -0,0 +1,371 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> +#include <qsslkey.h> +#include <qsslsocket.h> + +#include <QtNetwork/qhostaddress.h> +#include <QtNetwork/qnetworkproxy.h> + +class tst_QSslKey : public QObject +{ + Q_OBJECT + + struct KeyInfo { + QFileInfo fileInfo; + QSsl::KeyAlgorithm algorithm; + QSsl::KeyType type; + int length; + QSsl::EncodingFormat format; + KeyInfo( + const QFileInfo &fileInfo, QSsl::KeyAlgorithm algorithm, QSsl::KeyType type, + int length, QSsl::EncodingFormat format) + : fileInfo(fileInfo), algorithm(algorithm), type(type), length(length) + , format(format) {} + }; + + QList<KeyInfo> keyInfoList; + + void createPlainTestRows(); + +public: + tst_QSslKey(); + virtual ~tst_QSslKey(); + +public slots: + void initTestCase_data(); + void init(); + void cleanup(); + +#ifndef QT_NO_OPENSSL + +private slots: + void emptyConstructor(); + void constructor_data(); + void constructor(); + void copyAndAssign_data(); + void copyAndAssign(); + void equalsOperator(); + void length_data(); + void length(); + void toPemOrDer_data(); + void toPemOrDer(); + void toEncryptedPemOrDer_data(); + void toEncryptedPemOrDer(); + +#endif +}; + +tst_QSslKey::tst_QSslKey() +{ +#ifdef Q_WS_MAC + // applicationDirPath() points to a path inside the app bundle on Mac. + QDir dir(qApp->applicationDirPath() + QLatin1String("/../../../keys")); +#elif defined(Q_OS_WIN) + QDir dir(SRCDIR + QLatin1String("/keys")); // prefer this way to avoid ifdeffery and support shadow builds? +#else + QDir dir(qApp->applicationDirPath() + QLatin1String("/keys")); +#endif + QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable); + QRegExp rx(QLatin1String("^(rsa|dsa)-(pub|pri)-(\\d+)\\.(pem|der)$")); + foreach (QFileInfo fileInfo, fileInfoList) { + if (rx.indexIn(fileInfo.fileName()) >= 0) + keyInfoList << KeyInfo( + fileInfo, + rx.cap(1) == QLatin1String("rsa") ? QSsl::Rsa : QSsl::Dsa, + rx.cap(2) == QLatin1String("pub") ? QSsl::PublicKey : QSsl::PrivateKey, + rx.cap(3).toInt(), + rx.cap(4) == QLatin1String("pem") ? QSsl::Pem : QSsl::Der); + } +} + +tst_QSslKey::~tst_QSslKey() +{ +} + +void tst_QSslKey::initTestCase_data() +{ +} + +void tst_QSslKey::init() +{ +} + +void tst_QSslKey::cleanup() +{ +} + +static QByteArray readFile(const QString &absFilePath) +{ + QFile file(absFilePath); + if (!file.open(QIODevice::ReadOnly)) { + QWARN("failed to open file"); + return QByteArray(); + } + return file.readAll(); +} + +#ifndef QT_NO_OPENSSL + +void tst_QSslKey::emptyConstructor() +{ + if (!QSslSocket::supportsSsl()) + return; + + QSslKey key; + QVERIFY(key.isNull()); + QVERIFY(key.length() < 0); + + QSslKey key2; + QCOMPARE(key, key2); +} + +Q_DECLARE_METATYPE(QSsl::KeyAlgorithm); +Q_DECLARE_METATYPE(QSsl::KeyType); +Q_DECLARE_METATYPE(QSsl::EncodingFormat); + +void tst_QSslKey::createPlainTestRows() +{ + QTest::addColumn<QString>("absFilePath"); + QTest::addColumn<QSsl::KeyAlgorithm>("algorithm"); + QTest::addColumn<QSsl::KeyType>("type"); + QTest::addColumn<int>("length"); + QTest::addColumn<QSsl::EncodingFormat>("format"); + foreach (KeyInfo keyInfo, keyInfoList) { + QTest::newRow(keyInfo.fileInfo.fileName().toLatin1()) + << keyInfo.fileInfo.absoluteFilePath() << keyInfo.algorithm << keyInfo.type + << keyInfo.length << keyInfo.format; + } +} + +void tst_QSslKey::constructor_data() +{ + createPlainTestRows(); +} + +void tst_QSslKey::constructor() +{ + if (!QSslSocket::supportsSsl()) + return; + + QFETCH(QString, absFilePath); + QFETCH(QSsl::KeyAlgorithm, algorithm); + QFETCH(QSsl::KeyType, type); + QFETCH(QSsl::EncodingFormat, format); + + QByteArray encoded = readFile(absFilePath); + QSslKey key(encoded, algorithm, format, type); + QVERIFY(!key.isNull()); +} + +void tst_QSslKey::copyAndAssign_data() +{ + createPlainTestRows(); +} + +void tst_QSslKey::copyAndAssign() +{ + if (!QSslSocket::supportsSsl()) + return; + + QFETCH(QString, absFilePath); + QFETCH(QSsl::KeyAlgorithm, algorithm); + QFETCH(QSsl::KeyType, type); + QFETCH(QSsl::EncodingFormat, format); + + QByteArray encoded = readFile(absFilePath); + QSslKey key(encoded, algorithm, format, type); + + QSslKey copied(key); + QCOMPARE(key, copied); + QCOMPARE(key.algorithm(), copied.algorithm()); + QCOMPARE(key.type(), copied.type()); + QCOMPARE(key.length(), copied.length()); + QCOMPARE(key.toPem(), copied.toPem()); + QCOMPARE(key.toDer(), copied.toDer()); + + QSslKey assigned = key; + QCOMPARE(key, assigned); + QCOMPARE(key.algorithm(), assigned.algorithm()); + QCOMPARE(key.type(), assigned.type()); + QCOMPARE(key.length(), assigned.length()); + QCOMPARE(key.toPem(), assigned.toPem()); + QCOMPARE(key.toDer(), assigned.toDer()); +} + +void tst_QSslKey::equalsOperator() +{ + // ### unimplemented +} + +void tst_QSslKey::length_data() +{ + createPlainTestRows(); +} + +void tst_QSslKey::length() +{ + if (!QSslSocket::supportsSsl()) + return; + + QFETCH(QString, absFilePath); + QFETCH(QSsl::KeyAlgorithm, algorithm); + QFETCH(QSsl::KeyType, type); + QFETCH(int, length); + QFETCH(QSsl::EncodingFormat, format); + + QByteArray encoded = readFile(absFilePath); + QSslKey key(encoded, algorithm, format, type); + QVERIFY(!key.isNull()); + QCOMPARE(key.length(), length); +} + +void tst_QSslKey::toPemOrDer_data() +{ + createPlainTestRows(); +} + +void tst_QSslKey::toPemOrDer() +{ + if (!QSslSocket::supportsSsl()) + return; + + QFETCH(QString, absFilePath); + QFETCH(QSsl::KeyAlgorithm, algorithm); + QFETCH(QSsl::KeyType, type); + QFETCH(QSsl::EncodingFormat, format); + + QByteArray encoded = readFile(absFilePath); + QSslKey key(encoded, algorithm, format, type); + QVERIFY(!key.isNull()); + if (format == QSsl::Pem) + encoded.replace('\r', ""); + QCOMPARE(format == QSsl::Pem ? key.toPem() : key.toDer(), encoded); +} + +void tst_QSslKey::toEncryptedPemOrDer_data() +{ + QTest::addColumn<QString>("absFilePath"); + QTest::addColumn<QSsl::KeyAlgorithm>("algorithm"); + QTest::addColumn<QSsl::KeyType>("type"); + QTest::addColumn<QSsl::EncodingFormat>("format"); + QTest::addColumn<QString>("password"); + + QStringList passwords; + passwords << " " << "foobar" << "foo bar" + << "aAzZ`1234567890-=~!@#$%^&*()_+[]{}\\|;:'\",.<>/?"; // ### add more (?) + foreach (KeyInfo keyInfo, keyInfoList) { + foreach (QString password, passwords) { + QString testName = QString("%1-%2-%3-%4").arg(keyInfo.fileInfo.fileName()) + .arg(keyInfo.algorithm == QSsl::Rsa ? "RSA" : "DSA") + .arg(keyInfo.type == QSsl::PrivateKey ? "PrivateKey" : "PublicKey") + .arg(keyInfo.format == QSsl::Pem ? "PEM" : "DER"); + QTest::newRow(testName.toLatin1()) + << keyInfo.fileInfo.absoluteFilePath() << keyInfo.algorithm << keyInfo.type + << keyInfo.format << password; + } + } +} + +void tst_QSslKey::toEncryptedPemOrDer() +{ + if (!QSslSocket::supportsSsl()) + return; + + QFETCH(QString, absFilePath); + QFETCH(QSsl::KeyAlgorithm, algorithm); + QFETCH(QSsl::KeyType, type); + QFETCH(QSsl::EncodingFormat, format); + QFETCH(QString, password); + + QByteArray plain = readFile(absFilePath); + QSslKey key(plain, algorithm, format, type); + QVERIFY(!key.isNull()); + + QByteArray pwBytes(password.toLatin1()); + + if (type == QSsl::PrivateKey) { + QByteArray encryptedPem = key.toPem(pwBytes); + QVERIFY(!encryptedPem.isEmpty()); + QSslKey keyPem(encryptedPem, algorithm, QSsl::Pem, type, pwBytes); + QVERIFY(!keyPem.isNull()); + QCOMPARE(keyPem, key); + QCOMPARE(keyPem.toPem(), key.toPem()); + } else { + // verify that public keys are never encrypted by toPem() + QByteArray encryptedPem = key.toPem(pwBytes); + QVERIFY(!encryptedPem.isEmpty()); + QByteArray plainPem = key.toPem(); + QVERIFY(!plainPem.isEmpty()); + QCOMPARE(encryptedPem, plainPem); + } + + if (type == QSsl::PrivateKey) { + QByteArray encryptedDer = key.toDer(pwBytes); + // ### at this point, encryptedDer is invalid, hence the below QEXPECT_FAILs + QVERIFY(!encryptedDer.isEmpty()); + QSslKey keyDer(encryptedDer, algorithm, QSsl::Der, type, pwBytes); + if (type == QSsl::PrivateKey) + QEXPECT_FAIL( + QTest::currentDataTag(), "We're not able to decrypt these yet...", Continue); + QVERIFY(!keyDer.isNull()); + if (type == QSsl::PrivateKey) + QEXPECT_FAIL( + QTest::currentDataTag(), "We're not able to decrypt these yet...", Continue); + QCOMPARE(keyDer.toPem(), key.toPem()); + } else { + // verify that public keys are never encrypted by toDer() + QByteArray encryptedDer = key.toDer(pwBytes); + QVERIFY(!encryptedDer.isEmpty()); + QByteArray plainDer = key.toDer(); + QVERIFY(!plainDer.isEmpty()); + QCOMPARE(encryptedDer, plainDer); + } + + // ### add a test to verify that public keys are _decrypted_ correctly (by the ctor) +} + +#endif + +QTEST_MAIN(tst_QSslKey) +#include "tst_qsslkey.moc" |