From: Kyungwook Tak Date: Thu, 13 Aug 2015 11:25:57 +0000 (+0900) Subject: Add more extract field method in Certificate class X-Git-Tag: accepted/tizen/mobile/20150824.134548~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=15d6ea71ec37448e87aad61ee9c1ded480841b09;p=platform%2Fcore%2Fsecurity%2Fcert-svc.git Add more extract field method in Certificate class Change-Id: Icd0ab04c045f13bb02ab850c61beb5309129d948 Signed-off-by: Kyungwook Tak --- diff --git a/packaging/cert-svc.spec b/packaging/cert-svc.spec index 59d2415..ff1a80d 100644 --- a/packaging/cert-svc.spec +++ b/packaging/cert-svc.spec @@ -178,7 +178,6 @@ rm %{TZ_SYS_BIN}/initialize_store_db.sh %{TZ_SYS_RO_APP}/widget/tests/* %{TZ_SYS_ETC}/ssl/certs/8956b9bc.0 %{TZ_SYS_SHARE}/ca-certificates/tizen/* -%{TZ_SYS_SHARE}/cert-svc/pkcs12/* %{TZ_SYS_SHARE}/cert-svc/cert-type/* %{TZ_SYS_SHARE}/cert-svc/certs/root_ca*.der %{TZ_SYS_SHARE}/cert-svc/tests/* diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 92c83f6..57d2a9a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,8 +13,9 @@ # limitations under the License. # -SET(TARGET_VCOREC_TEST "cert-svc-tests-capi") SET(TARGET_TEST_CERT_SVC_OGIG "cert-svc-tests-orig") + +SET(TARGET_CAPI_TEST "cert-svc-tests-capi") SET(TARGET_PKCS12_TEST "cert-svc-tests-pkcs12") SET(TARGET_VCORE_TEST "cert-svc-tests-vcore") diff --git a/tests/capi/CMakeLists.txt b/tests/capi/CMakeLists.txt index 265779c..42c50dd 100644 --- a/tests/capi/CMakeLists.txt +++ b/tests/capi/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,26 +17,32 @@ # @version 1.0 # @brief # +SET(CERT_SVC_CAPI_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -SET(VCOREC_TESTS_SOURCES - ${PROJECT_SOURCE_DIR}/tests/capi/api_tests.cpp - ${PROJECT_SOURCE_DIR}/tests/capi/test_suite_01.cpp +SET(CERT_SVC_CAPI_TESTS_SRCS + ${CERT_SVC_CAPI_TESTS_DIR}/main.cpp + ${CERT_SVC_CAPI_TESTS_DIR}/common-res.cpp + ${CERT_SVC_CAPI_TESTS_DIR}/test-certificate.cpp + ${CERT_SVC_CAPI_TESTS_DIR}/test-primitive.cpp ) INCLUDE_DIRECTORIES( + ${CERT_SVC_CAPI_TESTS_DIR} ${PROJECT_SOURCE_DIR}/vcore/src - ${PROJECT_SOURCE_DIR}/tests/capi ${PROJECT_SOURCE_DIR}/include ) -ADD_EXECUTABLE(${TARGET_VCOREC_TEST} ${VCOREC_TESTS_SOURCES} ${DPL_TEST_SOURCES}) +ADD_EXECUTABLE(${TARGET_CAPI_TEST} + ${CERT_SVC_CAPI_TESTS_SRCS} + ${DPL_TEST_SOURCES} + ) -TARGET_LINK_LIBRARIES(${TARGET_VCOREC_TEST} +TARGET_LINK_LIBRARIES(${TARGET_CAPI_TEST} ${TARGET_VCORE_LIB} ${TEST_DEP_LIBRARIES} ) -INSTALL(TARGETS ${TARGET_VCOREC_TEST} +INSTALL(TARGETS ${TARGET_CAPI_TEST} DESTINATION ${TZ_SYS_BIN} PERMISSIONS OWNER_READ OWNER_WRITE @@ -48,21 +54,9 @@ INSTALL(TARGETS ${TARGET_VCOREC_TEST} ) INSTALL(FILES - ${PROJECT_SOURCE_DIR}/tests/capi/data/cert_a.pem - ${PROJECT_SOURCE_DIR}/tests/capi/data/cert_b.pem - ${PROJECT_SOURCE_DIR}/tests/capi/data/pkey.pem - DESTINATION ${TZ_SYS_SHARE}/cert-svc/pkcs12/test1st - PERMISSIONS OWNER_READ - GROUP_READ - WORLD_READ - ) - -INSTALL(FILES - ${PROJECT_SOURCE_DIR}/tests/capi/data/cert0.pem - ${PROJECT_SOURCE_DIR}/tests/capi/data/cert1.der - ${PROJECT_SOURCE_DIR}/tests/capi/data/cert2fake.pem - ${PROJECT_SOURCE_DIR}/tests/capi/data/cert3fake.der - ${PROJECT_SOURCE_DIR}/tests/capi/data/root_cacert0.pem + ${CERT_SVC_CAPI_TESTS_DIR}/data/root_cacert0.pem + ${CERT_SVC_CAPI_TESTS_DIR}/data/root_ca_cert.pem + ${CERT_SVC_CAPI_TESTS_DIR}/data/second_ca_cert.pem DESTINATION ${TZ_SYS_SHARE}/cert-svc/cert-type/ PERMISSIONS OWNER_READ GROUP_READ diff --git a/tests/capi/api_tests.h b/tests/capi/api_tests.h deleted file mode 100644 index 54416e4..0000000 --- a/tests/capi/api_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ -/* - * @file api_tests.h - * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com) - * @version 1.0 - * @brief This file is the implementation file of main - */ - -#include - -extern CertSvcInstance vinstance; diff --git a/tests/capi/common-res.cpp b/tests/capi/common-res.cpp new file mode 100644 index 0000000..2552a33 --- /dev/null +++ b/tests/capi/common-res.cpp @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/* + * @file common-res.cpp + * @author Kyungwook Tak (k.tak@samsung.com) + * @version 1.0 + * @brief This file is the common resource for certsvc capi test + */ + +#include "common-res.h" + +const std::string TestData::subjectGoogleCA = "/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority"; + +const std::string TestData::googleCA = + "MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG" + "A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz" + "cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2" + "MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV" + "BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt" + "YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN" + "ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE" + "BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is" + "I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G" + "CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do" + "lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc" + "AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mK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ftYjNaKM5n1iZv4j1li49zKf" + "Y5nTLP+vYAvg0owLNYvJ5ncKfY1DACPU4/+tC7TTua95wgj5rwvAXnzgSyOGuSr0" + "fK9DyrH6E0LfXT+WuIQHahm2iSbxqPrChlnp5/EXDTBaO6Qfdpq0BP48ClZebxcA" + "+TYFo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVy" + "YXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUmSpShswvWtEABd+l3WxccRcCydUw" + "HwYDVR0jBBgwFoAUggh/2wAChuhTKqX6WK5nfxQ4yGAwDQYJKoZIhvcNAQEFBQAD" + "gYEAgfnAu/gMJRC/BFwkgvrHL0TV4ffPVAf7RSnZS6ib4IHGgrvXJvL+Qh7vHykv" + "ZIqD2L96nY2EaSNr0yXrT81YROndOQUJNx4Y/W8m6asu4hzANNZqWCbApPDIMK6V" + "cPA1wrKgZqbWp218WBqI2v9pXV0O+jpzxq1+GeQV2UsbRwc="; + +std::string magdaMes = "c2lnbmVkIGRhdGEK"; + +std::string magdaSig = "MC0CFQCL2pDA4S/zsHkDUCWOq7K6ebG14gIUHHoLsbeUd+BEqBXB6XjmcTncBRA="; + +const TestData::SigComponents TestData::magda(magdaCert, magdaMes, magdaSig); + +std::string filipCert = + "MIIC4zCCAkygAwIBAgIJAMdKgvadG/Z+MA0GCSqGSIb3DQEBBQUAMHIxCzAJBgNV" + "BAYTAlBMMQwwCgYDVQQIEwNNYXoxEDAOBgNVBAoTB1NhbXN1bmcxDTALBgNVBAsT" + "BFNQUkMxEDAOBgNVBAMTB1NhbXN1bmcxIjAgBgkqhkiG9w0BCQEWE3NhbXN1bmdA" + "c2Ftc3VuZy5jb20wHhcNMTExMDA1MTIwMDUxWhcNMjExMDAyMTIwMDUxWjB4MQsw" + "CQYDVQQGEwJQTDEMMAoGA1UECBMDTUFaMQwwCgYDVQQHEwNMZWcxDDAKBgNVBAoT" + "A1NhbTENMAsGA1UECxMEU1BSQzEOMAwGA1UEAxMFRmlsaXAxIDAeBgkqhkiG9w0B" + "CQEWEWZpbGlwQHNhbXN1bmcuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB" + "gQDS/sS0wXSCb34ojN8bWFd4Pl9eTLHh18UNGsPpLpp4itdfuc/OgyqaSoDwBzVh" + "EWAVLCTxexUa4Ncva+41NbkW4RCsFzeGs0ktpu1+8Q+v0QEOGqVF2rQkgilzDF/o" + "O56Fxw9vG1OA+qdQd3yOAV2EqLNBPrEYB9K5GFyffrakSQIDAQABo3sweTAJBgNV" + "HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp" + "Y2F0ZTAdBgNVHQ4EFgQUeyy3iV75KtOkpPFd6mnR9dFGZMwwHwYDVR0jBBgwFoAU" + "ggh/2wAChuhTKqX6WK5nfxQ4yGAwDQYJKoZIhvcNAQEFBQADgYEADtv0CBrQ1QCM" + "H9jKFjpSpq7zFKMXQeVtb/Zie823//woicg8kxnP5sS4dJWNXNb1iMLdhgV80g1y" + "t3gTWPxTtFzprQyNiJHTmrbNWXLX1roRVGUE/I8Q4xexqpbNlJIW2Jjm/kqoKfnK" + "xORG6HNPXZV29NY2fDRPPOIYoFQzrXI="; + +std::string filipMes = "Q3plZ28gdHUgc3p1a2Fzej8K"; + +std::string filipSigSHA1 = + "xEIpVjEIUoDkYGtX2ih6Gbya0/gr7OMdvbBKmjqzfNh9GHqwrgjglByeC5sspUzPBUF4Vmg/hZqL" + "gSsxXw9bKEa8c6mTQoNX51IC0ELPsoUMIJF1gGdFu0SzKptvU0+ksiiOM+70+s5t8s3z0G5PeA7O" + "99oq8UlrX7GDlxaoTU4="; + +std::string filipSigSHA256 = + "a5nGT6wnbQ8MLwLkG965E4e1Rv983E+v3nolLvvjuAKnfgWYb+70Da+T9ggYDTjngq+EBgC30w1p" + "EScrwye8ELefvRxDWy1+tWR4QRW/Nd4oN2U/pvozoabDSpe9Cvt0ECEOWKDqIYYnoWFjOiXg9VwD" + "HVVkQXvsSYu6thX/Xsk="; + +const TestData::SigComponents TestData::filipSHA1(filipCert, filipMes, filipSigSHA1); +const TestData::SigComponents TestData::filipSHA256(filipCert, filipMes, filipSigSHA256); + +std::string certChainArr[3] = { + "MIIDXTCCAsagAwIBAgIBAjANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJLUjEO" + "MAwGA1UECAwFU2VvdWwxEDAOBgNVBAoMB1NhbXN1bmcxEzARBgNVBAsMClRpemVu" + "IFRlc3QxFzAVBgNVBAMMDlRlc3QgU2Vjb25kIENBMRswGQYJKoZIhvcNAQkBFgx0" + "dEBnbWFpbC5jb20wHhcNMTQwNjE4MDgxMTA0WhcNMTUwNjE4MDgxMTA0WjB7MQsw" + "CQYDVQQGEwJLUjEOMAwGA1UECAwFU2VvdWwxEDAOBgNVBAoMB1NhbXN1bmcxFzAV" + "BgNVBAsMDlRpemVuIFRlc3QgQUlBMRQwEgYDVQQDDAtUZXN0IFNpZ25lcjEbMBkG" + "CSqGSIb3DQEJARYMdHRAZ21haWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB" + "iQKBgQCwgKw+/71jWXnx4bLLZrTPmE+NrDfHSfZx8yTGYeewMzP6ZlXM8WduxNiq" + "pqm7G2XN182GEXsdoxwa09HtMVGqSGA/BCamD1Z6liHOEb4UTB3ROJ1lZDDkyJ9a" + "gZOfoZst/Aj8+bwV3x3ie+p4a2w/8eSsalrfef2gX6khaSsJOwIDAQABo4HxMIHu" + "MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENl" + "cnRpZmljYXRlMB0GA1UdDgQWBBRL0nKiNUjzh1/LPvZoqLvnVfOZqjAfBgNVHSME" + "GDAWgBSpSfNbE0V2NHn/V5f660v2cWwYgDBzBggrBgEFBQcBAQRnMGUwIQYIKwYB" + "BQUHMAGGFWh0dHA6Ly8xMjcu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"HQ4EFgQUZB5PS54YL7ziMMRzpmueBRrfEggwHwYDVR0jBBgwFoAUZB5PS54YL7zi" + "MMRzpmueBRrfEggwDAYDVR0TBAUwAwEB/zBzBggrBgEFBQcBAQRnMGUwIQYIKwYB" + "BQUHMAGGFWh0dHA6Ly8xMjcuMC4wLjE6ODg4ODBABggrBgEFBQcwAoY0aHR0cDov" + "L1NWUlNlY3VyZS1HMy1haWEudmVyaXNpZ24uY29tL1NWUlNlY3VyZUczLmNlcjAN" + "BgkqhkiG9w0BAQUFAAOBgQAyRJXTZcwRCkRNGZQCO8txHvrmgv8vQwnZZF6SwyY/" + "Bry0fmlehtN52NLjjPEG6u9YFYfzSkjQlVR0qfQ2mNs3d6AKFlOdZOT6cuEIZuKe" + "pDb2Tx5JJbIN6N3fE/lVSW88K9aSCF2n15gYTSVmD0juHuLAoWnIicaa+Sbe2Tsj" + "AQ=="}; +std::vector TestData::certChain(certChainArr, certChainArr + 3); + +std::string certChainSelfSignedArr[2] = { + "MIICdzCCAeACAQcwDQYJKoZIhvcNAQEFBQAwgYIxCzAJBgNVBAYTAktSMQ4wDAYD" + "VQQIDAVTZW91bDEQMA4GA1UECgwHU2Ftc3VuZzETMBEGA1UECwwKVGl6ZW4gVGVz" + "dDEfMB0GA1UEAwwWVGVzdCBSb290IENBIFZlcnNpb24gMTEbMBkGCSqGSIb3DQEJ" + "ARYMdHRAZ21haWwuY29tMB4XDTE0MDYxNDA4MTI1MFoXDTE1MDYxNDA4MTI1MFow" + "gYQxCzAJBgNVBAYTAktSMQ4wDAYDVQQIDAVTZW91bDEQMA4GA1UECgwHU2Ftc3Vu" + "ZzETMBEGA1UECwwKVGl6ZW4gVGVzdDEhMB8GA1UEAwwYVGVzdCBTZWNvbmQgQ0Eg" + "VmVyc2lvbiAxMRswGQYJKoZIhvcNAQkBFgx0dEBnbWFpbC5jb20wgZ8wDQYJKoZI" + "hvcNAQEBBQADgY0AMIGJAoGBAKOqFNxvO2jYcq5kqVehHH5k1D1dY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4GBAOHjfa7nbPKhqR0mGfsscPQZZAZzKq9y" + "ttdjTaNbnybzcJzcN3uwOdYKMf26Dn968nAPkukWe8j6GyMJ1C9LMAWqMn5hl0rI" + "x6mUBfKZrl33BKH4KTYOrt0vnHdrCM2TwMkwMZ5ja5bBnbNrfF4e0HIAMor4rnVP" + "WDSlESMMmtTm"}; +std::vector TestData::certChainSelfSigned(certChainSelfSignedArr, certChainSelfSignedArr + 2); diff --git a/tests/capi/common-res.h b/tests/capi/common-res.h new file mode 100644 index 0000000..c447bfd --- /dev/null +++ b/tests/capi/common-res.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/* + * @file common-res.h + * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com) + * @author Kyungwook Tak (k.tak@samsung.com) + * @version 1.0 + * @brief This file is the common resource for certsvc capi test + */ +#pragma once + +#include +#include + +#include + +extern CertSvcInstance vinstance; + +namespace TestData { + +class SigComponents { +public: + SigComponents(std::string &cert, std::string &mes, std::string &sig) + : certificate(cert) + , message(mes) + , signature(sig) {} + + std::string certificate; + std::string message; + std::string signature; +}; + +extern const std::string subjectGoogleCA; +/* + * Not Before: Jan 29 00:00:00 1996 GMT + * Not After : Aug 1 23:59:59 2028 GMT + */ +extern const std::string googleCA; + +/* + * Signed by googleCA + * Not Before: May 13 00:00:00 2004 GMT + * Not After : May 12 23:59:59 2014 GMT + */ +extern const std::string google2nd; + +/* + * Signed by google2nd + * Not Before: Oct 26 00:00:00 2011 GMT + * Not After : Sep 30 23:59:59 2013 GMT + */ +extern const std::string certEE; + +/* + * Issuer : /C=KO/ST=Kyeongkido/L=Suwon/O=Samsung/OU=SoftwareCenter/CN=TizenSecurity/emailAddress=k.tak@samsung.com + * Subject : /C=PO/ST=SeoulState/L=Seoul/O=SamsungSecond/OU=SoftwareCenterSecond/CN=TizenSecuritySecond/emailAddress=kyungwook.tak@gmail.com + */ +extern const std::string certFullField; + +/* + * Not Before: Oct 5 12:11:33 2011 GMT + * Not After : Oct 2 12:11:33 2021 GMT + */ +extern const SigComponents magda; + +/* + * Not Before: Oct 5 12:00:51 2011 GMT + * Not After : Oct 2 12:00:51 2021 GMT + */ +extern const SigComponents filipSHA1; +extern const SigComponents filipSHA256; + +/* + * Signer + * Not Before: Jun 18 08:11:04 2014 GMT + * Not After : Jun 18 08:11:04 2015 GMT + * + * Second CA + * Not Before: Jun 18 08:10:59 2014 GMT + * Not After : Jun 18 08:10:59 2015 GMT + * + * Root CA + * Not Before: Jun 18 08:10:51 2014 GMT + * Not After : Jun 18 08:10:51 2015 GMT + */ +extern std::vector certChain; + +/* + * Second CA + * Not Before: Jun 14 08:12:50 2014 GMT + * Not After : Jun 14 08:12:50 2015 GMT + * + * Root CA + * Not Before: Jun 14 08:12:35 2014 GMT + * Not After : Jun 14 08:12:35 2015 GMT + */ +extern std::vector certChainSelfSigned; + +} diff --git a/tests/capi/crl_cache.h b/tests/capi/crl_cache.h deleted file mode 100644 index c71dfd9..0000000 --- a/tests/capi/crl_cache.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ -/* - * @file crl_cache.h - * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com) - * @version 1.0 - * @brief Example implementation of memory cache for crl. - */ -#ifndef _CRL_MEMORY_CACHE_H_ -#define _CRL_MEMORY_CACHE_H_ - -#include -#include -#include - -#include -#include - -typedef std::vector BinaryBuffer; - -typedef struct CrlRecord_t { - BinaryBuffer buffer; - time_t nextUpdate; -} CrlRecord; - -typedef std::map MemoryCache; - -void memoryCacheWrite( - const char *distributionPoint, - const char *body, - int bodySize, - time_t nextUpdateTime, - void *userParam) -{ - MemoryCache *cache = static_cast(userParam); - - CrlRecord record; - record.buffer.resize(bodySize); - memcpy(&record.buffer[0], body, bodySize); - record.nextUpdate = nextUpdateTime; - - cache->insert(std::make_pair(std::string(distributionPoint),record)); -} - -int memoryCacheRead( - const char *distributorPoint, - char **body, - int *bodySize, - time_t *nextUpdateTime, - void *userParam) -{ - MemoryCache *cache = static_cast(userParam); - auto iter = cache->find(distributorPoint); - if (iter == cache->end()) { - return 0; - } - CrlRecord record = iter->second; - *bodySize = record.buffer.size(); - *body = new char[*bodySize]; - memcpy(*body, &record.buffer[0], *bodySize); - *nextUpdateTime = record.nextUpdate; - return 1; -} - -void memoryCacheFree( - char *buffer, - void *) -{ - delete[] buffer; -} - -#endif // _CRL_MEMORY_CACHE_H_ - diff --git a/tests/capi/data/cert_a.pem b/tests/capi/data/cert_a.pem deleted file mode 100644 index f062d94..0000000 --- a/tests/capi/data/cert_a.pem +++ /dev/null @@ -1,64 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: - 85:7d:e1:c5:d9:de:7a:20 - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=PL, ST=Mazowieckie, O=Samsung, OU=SPRC, CN=Operator Test Root Certificate/emailAddress=operator@samsung.com - Validity - Not Before: Jan 4 17:34:31 2011 GMT - Not After : Jan 4 17:34:31 2012 GMT - Subject: C=PL, ST=Malopolskie, L=Krakow, O=Samsung, OU=N/A, CN=Operator Test Second Level Certificate/emailAddress=second.operator@samsung.com - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - RSA Public Key: (1024 bit) - Modulus (1024 bit): - 00:ba:3c:58:ca:87:1e:59:68:54:8a:54:34:43:61: - f1:81:e6:35:c1:46:74:16:c7:ff:f9:15:9e:0c:5a: - 6a:89:c1:13:0c:61:2e:ba:00:e0:71:ea:7e:31:ae: - 4e:ef:93:58:51:98:97:f3:bf:8a:9b:b2:c1:b7:0c: - 5f:3f:56:b3:13:3b:d0:80:be:04:66:89:84:50:ca: - fe:f6:f7:6b:05:3b:30:4e:96:9c:5b:c5:80:bc:d6: - be:6e:69:f4:b9:9b:4c:06:7a:ed:37:67:b2:fe:45: - 69:57:62:54:cb:69:69:48:b9:7d:a0:42:f1:b6:dc: - f2:7f:eb:75:2a:d4:83:69:b9 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - D9:F3:11:BF:98:5A:60:12:7A:85:B5:E7:A7:38:4F:CF:51:1D:C6:B2 - X509v3 Authority Key Identifier: - keyid:25:A5:90:9F:4D:3A:A4:19:0A:80:46:5E:F3:FB:20:CE:56:30:33:DA - - Signature Algorithm: sha1WithRSAEncryption - 69:6c:26:81:51:91:a6:e6:11:dc:81:35:03:73:85:4f:2f:29: - 1f:20:f2:23:54:82:ca:8f:b8:a6:e3:3f:cd:72:5e:d7:e7:f5: - 84:8a:33:e2:51:9f:36:4b:30:85:f4:4f:87:c7:9a:69:0b:15: - 6e:92:c7:1f:2f:58:a4:57:f8:c2:cd:59:6c:d2:11:63:ae:bb: - b0:32:3f:09:e7:2e:ad:db:1b:fe:e7:a4:21:43:47:76:e1:de: - 36:bb:26:3f:16:76:20:ed:a4:68:c1:48:ae:2b:95:fb:f6:d2: - f2:7f:74:f6:83:e2:89:06:b5:89:54:6e:7f:cf:88:94:66:e8: - da:32 ------BEGIN CERTIFICATE----- -MIIDPjCCAqegAwIBAgIJAIV94cXZ3nogMA0GC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tpGjBSK4rlfv20vJ/ -dPaD4okGtYlUbn/PiJRm6Noy ------END CERTIFICATE----- diff --git a/tests/capi/data/cert_b.pem b/tests/capi/data/cert_b.pem deleted file mode 100644 index 343241f..0000000 --- a/tests/capi/data/cert_b.pem +++ /dev/null @@ -1,66 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: - 85:7d:e1:c5:d9:de:7a:1f - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=PL, ST=Mazowieckie, O=Samsung, OU=SPRC, CN=Operator Test Root Certificate/emailAddress=operator@samsung.com - Validity - Not Before: Jan 4 17:27:08 2011 GMT - Not After : Jan 3 17:27:08 2014 GMT - Subject: C=PL, ST=Mazowieckie, O=Samsung, OU=SPRC, CN=Operator Test Root Certificate/emailAddress=operator@samsung.com - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - RSA Public Key: (1024 bit) - Modulus (1024 bit): - 00:c3:39:17:a8:f9:d0:69:37:9a:56:44:39:67:10: - 14:a9:4b:a2:0b:c7:fc:a1:e8:e8:f7:1c:06:f4:9c: - 83:f7:37:07:9d:9c:2c:1b:46:43:5f:f1:7b:91:a8: - cd:c0:76:00:d5:9c:c9:28:f7:91:28:b6:97:ec:85: - b1:10:0f:58:2e:f6:6f:98:b6:ab:7b:ca:08:10:7f: - 55:32:bf:32:db:a7:c2:86:83:03:ee:41:0a:24:de: - 17:e3:9d:8f:5b:fa:46:70:78:98:b4:c1:14:77:44: - ab:59:7c:4c:d3:4a:f7:54:f2:30:0d:38:73:95:9f: - 21:0e:a9:86:3e:fc:82:4e:0b - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Subject Key Identifier: - 25:A5:90:9F:4D:3A:A4:19:0A:80:46:5E:F3:FB:20:CE:56:30:33:DA - X509v3 Authority Key Identifier: - keyid:25:A5:90:9F:4D:3A:A4:19:0A:80:46:5E:F3:FB:20:CE:56:30:33:DA - DirName:/C=PL/ST=Mazowieckie/O=Samsung/OU=SPRC/CN=Operator Test Root Certificate/emailAddress=operator@samsung.com - serial:85:7D:E1:C5:D9:DE:7A:1F - - X509v3 Basic Constraints: - CA:TRUE - Signature Algorithm: sha1WithRSAEncryption - b9:d7:72:49:09:d8:6f:61:94:51:40:9d:c3:d3:23:53:97:b8: - 12:ee:cb:dd:57:e6:1f:a2:76:38:5d:42:51:bd:a9:30:19:f7: - 67:5b:a8:67:4a:9e:a1:f0:a9:22:14:94:77:32:27:79:37:9c: - 0a:0f:52:80:14:62:00:94:45:85:3b:fd:ad:b4:c3:20:45:ba: - b7:91:1a:9e:38:51:0f:9b:d5:ce:74:c7:bd:4a:21:9a:2d:b5: - 71:0b:42:d2:95:72:66:fe:eb:11:ad:62:44:6c:32:4e:b4:00: - 37:d7:b8:d5:4b:f6:74:36:78:d6:ae:66:b3:ca:6e:42:ff:cb: - c2:e6 ------BEGIN CERTIFICATE----- -MIIDnzCCAwigAwIBAgIJAIV94cXZ3nofMA0GCSqGSIb3DQEBBQUAMIGSMQswCQYD -VQQGEwJQTDEUMBIGA1UECBMLTWF6b3dpZWNraWUxEDAOBgNVBAoTB1NhbXN1bmcx -DTALBgNVBAsTBFNQUkMxJzAlBgNVBAMTHk9wZXJhdG9yIFRlc3QgUm9vdCBDZXJ0 -aWZpY2F0ZTEjMCEGCSqGSIb3DQEJARYUb3BlcmF0b3JAc2Ftc3VuZy5jb20wHhcN -MTEwMTA0MTcyNzA4WhcNMTQwMTAzMTcyNzA4WjCBkjELMAkGA1UEBhMCUEwxFDAS -BgNVBAgTC01hem93aWVja2llMRAwDgYDVQQKEwdTYW1zdW5nMQ0wCwYDVQQLEwRT -UFJDMScwJQYDVQQDEx5PcGVyYXRvciBUZXN0IFJvb3QgQ2VydGlmaWNhdGUxIzAh -BgkqhkiG9w0BCQEWFG9wZXJhdG9yQHNhbXN1bmcuY29tMIGfMA0GCSqGSIb3DQEB -AQUAA4GNADCBiQKBgQDDOReo+dBpN5pWRDlnEBSpS6ILx/yh6Oj3HAb0nIP3Nwed -nCwbRkNf8XuRqM3AdgDVnMko95EotpfshbEQD1gu9m+Ytqt7yggQf1UyvzLbp8KG -gwPuQQok3hfjnY9b+kZweJi0wRR3RKtZfEzTSvdU8jANOHOVnyEOqYY+/IJOCwID -AQABo4H6MIH3MB0GA1UdDgQWBBQlpZCfTTqkGQqARl7z+yDOVjAz2jCBxwYDVR0j -BIG/MIG8gBQlpZCfTTqkGQqARl7z+yDOVjAz2qGBmKSBlTCBkjELMAkGA1UEBhMC -UEwxFDASBgNVBAgTC01hem93aWVja2llMRAwDgYDVQQKEwdTYW1zdW5nMQ0wCwYD -VQQLEwRTUFJDMScwJQYDVQQDEx5PcGVyYXRvciBUZXN0IFJvb3QgQ2VydGlmaWNh -dGUxIzAhBgkqhkiG9w0BCQEWFG9wZXJhdG9yQHNhbXN1bmcuY29tggkAhX3hxdne -eh8wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQC513JJCdhvYZRRQJ3D -0yNTl7gS7svdV+YfonY4XUJRvakwGfdnW6hnSp6h8KkiFJR3Mid5N5wKD1KAFGIA -lEWFO/2ttMMgRbq3kRqeOFEPm9XOdMe9SiGaLbVxC0LSlXJm/usRrWJEbDJOtAA3 -17jVS/Z0NnjWrmazym5C/8vC5g== ------END CERTIFICATE----- diff --git a/tests/capi/data/pkey.pem b/tests/capi/data/pkey.pem deleted file mode 100644 index ab1214a..0000000 --- a/tests/capi/data/pkey.pem +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,44C051D8935528BB - -iISuf9ELdyP5M0vlWOK4msH09HRAhN+43qRu/RDznpsTs2lX2sJITXXEmJC4EJzS -Zk4jf3ScTj1JsMGlg5k0mZWLmDb4kUxTRVUqJX2W4uUYEmWav7LQHRAsPwNUSMs3 -DzZabSf1vplnKKoL9mMtX4E0mj79AkJp7tARQu4Zn2FDMg/UnCErzhGeoFysztmM -v0Biyrf8yTbatMMr7Ea6rIsKS8KbkEeYDk4LpxBXkMeOutnnUUdhUEXZ/mwgJq2e -+8LLPiWdFsrGxPdub7iuLXidXSpOd9VaC9LN/ORKF+EiJtF+twWSBotxYOtwmtgj -xUHfXBcbaFoPnLKNS0nxwsOHF07LUfsCHzfVm1uGyWFkkLrPfcSjb6PahFlfO6w5 -fv8HnUOgeAjlhK6X+xhmw1tpwMUlmcYmq31eC8rwxP59jNQbhH6GVr5+rEMRHNgp -loC1WqthoRtBEC0bi99VpIHVIepe9G+p40sIropoUWftfDSLl3RtONg5GyyZWQ4a -ROxsiLHDZ7+q8eKkJuYPkiZ61/5MHuOsH5k57PG7ppG6/0p+ED4bTwxxDb6PU4pA -08xUTZQ0CUn1x80o/lKw+1E9TJOTbCvrEJAnMksfOkNkNyedgDJaxfV63wYvnL4+ -BLzCqa6djpe0Mg2olQieV/piRUt7JaGA7bnaMAn+bJ56PzUnMl0/WlxzGTMtHjkf -zUqgLLdxZpJP7zl4XleSfRWlPgL1iN1s84x48ej+MGgOGi7xTgX/sfCLkN4No/8k -c5Po+lQU261XAYNuAjtjUFQP/FgIMM9CnJrDWp8xHZXUJBo0c5lOKg== ------END RSA PRIVATE KEY----- diff --git a/tests/capi/data/root_ca_cert.pem b/tests/capi/data/root_ca_cert.pem new file mode 100644 index 0000000..366ed15 --- /dev/null +++ b/tests/capi/data/root_ca_cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/jCCAmegAwIBAgIJAOifQRE/qMjWMA0GCSqGSIb3DQEBCwUAMIGXMQswCQYD +VQQGEwJLTzETMBEGA1UECAwKS3llb25na2lkbzEOMAwGA1UEBwwFU3V3b24xEDAO +BgNVBAoMB1NhbXN1bmcxFzAVBgNVBAsMDlNvZnR3YXJlQ2VudGVyMRYwFAYDVQQD +DA1UaXplblNlY3VyaXR5MSAwHgYJKoZIhvcNAQkBFhFrLnRha0BzYW1zdW5nLmNv +bTAeFw0xNTA4MTkwNDMyMzhaFw0yNTA4MTYwNDMyMzhaMIGXMQswCQYDVQQGEwJL +TzETMBEGA1UECAwKS3llb25na2lkbzEOMAwGA1UEBwwFU3V3b24xEDAOBgNVBAoM +B1NhbXN1bmcxFzAVBgNVBAsMDlNvZnR3YXJlQ2VudGVyMRYwFAYDVQQDDA1UaXpl +blNlY3VyaXR5MSAwHgYJKoZIhvcNAQkBFhFrLnRha0BzYW1zdW5nLmNvbTCBnzAN +BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAsxwuULOSxFe7LvjS3QtqG3qklShJ9Tfq +CB74hNV8EXUwE/TXynOYOUQwxP7rkNj3ZesakbXXhJy20PUYdJQpUCGblRbOGZUH +vDepFGNzUJg5KnWy4sULss4JYk6lnbtcNfuB5Xyf0na80S0aMplqJGbkJnZ7WMpz +dJsCmENZtBkCAwEAAaNQME4wHQYDVR0OBBYEFGaOiJzaeAr5sI5BCo3iAmk8TbHE +MB8GA1UdIwQYMBaAFGaOiJzaeAr5sI5BCo3iAmk8TbHEMAwGA1UdEwQFMAMBAf8w +DQYJKoZIhvcNAQELBQADgYEAEU/D14Kr6DDogpvBXYsi4MBEUGuLanzIZx3oCthh +UgvTTOz1xIovpYpycUIo1fHbNKoBxEBEEGR/wWRPXQoCW7uRsYyNNxcHDdU8EJig +U8RjCGk3U8086LqTHQRPCTBEVrxrOLTx1Z4AsjyabyZ8uz9te9GQDcQMjLNytyT/ +/I0= +-----END CERTIFICATE----- diff --git a/tests/capi/data/second_ca_cert.pem b/tests/capi/data/second_ca_cert.pem new file mode 100644 index 0000000..28c1144 --- /dev/null +++ b/tests/capi/data/second_ca_cert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICvzCCAigCCQCpduCB5TcrmDANBgkqhkiG9w0BAQsFADCBlzELMAkGA1UEBhMC +S08xEzARBgNVBAgMCkt5ZW9uZ2tpZG8xDjAMBgNVBAcMBVN1d29uMRAwDgYDVQQK +DAdTYW1zdW5nMRcwFQYDVQQLDA5Tb2Z0d2FyZUNlbnRlcjEWMBQGA1UEAwwNVGl6 +ZW5TZWN1cml0eTEgMB4GCSqGSIb3DQEJARYRay50YWtAc2Ftc3VuZy5jb20wHhcN +MTUwODE5MDQzNTQxWhcNMjAwODE3MDQzNTQxWjCBrzELMAkGA1UEBhMCUE8xEzAR +BgNVBAgMClNlb3VsU3RhdGUxDjAMBgNVBAcMBVNlb3VsMRYwFAYDVQQKDA1TYW1z +dW5nU2Vjb25kMR0wGwYDVQQLDBRTb2Z0d2FyZUNlbnRlclNlY29uZDEcMBoGA1UE +AwwTVGl6ZW5TZWN1cml0eVNlY29uZDEmMCQGCSqGSIb3DQEJARYXa3l1bmd3b29r +LnRha0BnbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANgIo6MF +++LfNs3jSC87WRfO4zK/n+/xfPsn+Xwyi4jtsMxk2v/ye/SGESAACdCFFBL/EZ9j +Adu/6kzuKDJ5SpphW++XoUM2YdNxHzf6+z8JK9IPVmhy3b/hQlVbtBiFAMuLOn1D +C0gfTEnYRgZBs3v5Z/N35ZO1FoCz8y9wHmAXAgMBAAEwDQYJKoZIhvcNAQELBQAD +gYEAb3/k6KLLGysGEMFk2rVVvroqGqzeKHfk+t/pbrdGHEr0EIIXIYBk7YCGhMVF +Flw7g6Cpxyo1FQEFQhcdiv4/Iio2/RemtTYRILOnoaHSh9j9Fl1LT69MZq20hjId +8WNW2Ah9APv29fpZQFXo8dMsy1cnh4hJhWVWWttSLUBd1uE= +-----END CERTIFICATE----- diff --git a/tests/capi/api_tests.cpp b/tests/capi/main.cpp similarity index 89% rename from tests/capi/api_tests.cpp rename to tests/capi/main.cpp index ab0702e..b508135 100644 --- a/tests/capi/api_tests.cpp +++ b/tests/capi/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ /* - * @file api_tests.cpp + * @file main.cpp * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com) * @version 1.0 * @brief This file is the implementation file of main @@ -22,7 +22,7 @@ #include -#include +#include "common-res.h" CertSvcInstance vinstance; diff --git a/tests/capi/test-certificate.cpp b/tests/capi/test-certificate.cpp new file mode 100644 index 0000000..c43574b --- /dev/null +++ b/tests/capi/test-certificate.cpp @@ -0,0 +1,619 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "common-res.h" + +void _get_string_field_and_check( + CertSvcCertificate cert, + CertSvcCertificateField field, + const char *expected) +{ + CertSvcString fieldStr; + int result = certsvc_certificate_get_string_field( + cert, + field, + &fieldStr); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, + "Error in certsvc_certificate_get_string_field. " + "field : " << field << " expected : " << expected); + + size_t size; + const char *ptr; + + certsvc_string_to_cstring(fieldStr, &ptr, &size); + + if (ptr != NULL) { + std::cout << "filed[" << field << "] str[" << ptr << "]" << std::endl; + RUNNER_ASSERT_MSG(strncmp(ptr, expected, size) == 0, + "extracted field isn't match to expected value"); + } else { + std::cout << "field[" << field << "] is empty." << std::endl; + } +} + +RUNNER_TEST_GROUP_INIT(T0100_CAPI_CERTIFICATE) + +RUNNER_TEST(T0101_certificate_new_from_file) +{ + CertSvcCertificate cert; + int result = certsvc_certificate_new_from_file( + vinstance, + "/usr/share/cert-svc/cert-type/root_cacert0.pem", + &cert); + RUNNER_ASSERT_MSG(CERTSVC_TRUE == result, "Error reading certificate"); + + CertSvcString string; + + certsvc_certificate_get_string_field( + cert, + CERTSVC_SUBJECT_COMMON_NAME, + &string); + + const char *ptr = "Samsung"; + + const char *buffer; + size_t len; + + certsvc_string_to_cstring(string, &buffer, &len); + + result = strncmp(buffer, ptr, strlen(ptr)); + + RUNNER_ASSERT_MSG(0 == result, "Error reading common name"); + + certsvc_certificate_free(cert); +} + +RUNNER_TEST(T0102_certificate_search) +{ + CertSvcCertificateList handler; + int result = certsvc_certificate_search( + vinstance, + CERTSVC_SUBJECT_COMMON_NAME, + "WAC Application Services Ltd", + &handler); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, + "Error in search method. errcode : " << result); + + CertSvcCertificate cert; + + result = certsvc_certificate_list_get_one(handler, 0, &cert); + + RUNNER_ASSERT_MSG(CERTSVC_TRUE == result, + "Error reading certificate. errcode : " << result); + + CertSvcString string; + + certsvc_certificate_get_string_field( + cert, + CERTSVC_SUBJECT_COUNTRY_NAME, + &string); + + const char *ptr = "GB"; + const char *buffer; + + certsvc_string_to_cstring(string, &buffer, NULL); + + result = strncmp(buffer, ptr, strlen(ptr)); + + RUNNER_ASSERT_MSG(0 == result, "Country does not match. result : " << result); +} + +RUNNER_TEST(T0103_is_signed_by) +{ + CertSvcCertificate cert1, cert2; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::googleCA.c_str()), + TestData::googleCA.size(), + CERTSVC_FORM_DER_BASE64, + &cert1); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error reading certificate"); + + result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::google2nd.c_str()), + TestData::google2nd.size(), + CERTSVC_FORM_DER_BASE64, + &cert2); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error reading certificate"); + + int status; + result = certsvc_certificate_is_signed_by(cert2, cert1, &status); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Chain verification failed"); + RUNNER_ASSERT_MSG(CERTSVC_TRUE == status, "Chain verification failed"); +} + +RUNNER_TEST(T0104_not_before_not_after) +{ + CertSvcCertificate cert; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::google2nd.c_str()), + TestData::google2nd.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error reading certificate"); + + time_t before, after; + result = certsvc_certificate_get_not_before(cert, &before); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error extracting NOT_BEFORE"); + RUNNER_ASSERT_MSG(before == 1084406400, "TODO"); + + result = certsvc_certificate_get_not_after(cert, &after); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error extracting NOT_AFTER"); + //extracted: date --date="May 12 23:59:59 2014 GMT" +%s + RUNNER_ASSERT_MSG(after == 1399939199, "TODO"); +} + +RUNNER_TEST(T01051_cert_get_field_subject) +{ + CertSvcCertificate cert; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::certFullField.c_str()), + TestData::certFullField.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT, + "/C=PO/ST=SeoulState/L=Seoul/O=SamsungSecond/OU=SoftwareCenterSecond/CN=TizenSecuritySecond/emailAddress=kyungwook.tak@gmail.com"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_COMMON_NAME, + "TizenSecuritySecond"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_COUNTRY_NAME, + "PO"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_STATE_NAME, + "SeoulState"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_LOCALITY_NAME, + "Seoul"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_ORGANIZATION_NAME, + "SamsungSecond"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_ORGANIZATION_UNIT_NAME, + "SoftwareCenterSecond"); + + _get_string_field_and_check( + cert, + CERTSVC_SUBJECT_EMAIL_ADDRESS, + "kyungwook.tak@gmail.com"); +} + +RUNNER_TEST(T01052_cert_get_field_issuer) +{ + CertSvcCertificate cert; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::certFullField.c_str()), + TestData::certFullField.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER, + "/C=KO/ST=Kyeongkido/L=Suwon/O=Samsung/OU=SoftwareCenter/CN=TizenSecurity/emailAddress=k.tak@samsung.com"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_COMMON_NAME, + "TizenSecurity"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_COUNTRY_NAME, + "KO"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_STATE_NAME, + "Kyeongkido"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_LOCALITY_NAME, + "Suwon"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_ORGANIZATION_NAME, + "Samsung"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_ORGANIZATION_UNIT_NAME, + "SoftwareCenter"); + + _get_string_field_and_check( + cert, + CERTSVC_ISSUER_EMAIL_ADDRESS, + "k.tak@samsung.com"); +} + +RUNNER_TEST(T01053_cert_get_field_other) +{ + CertSvcCertificate cert; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::certFullField.c_str()), + TestData::certFullField.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + _get_string_field_and_check( + cert, + CERTSVC_VERSION, + "1"); + + _get_string_field_and_check( + cert, + CERTSVC_SERIAL_NUMBER, + "a9:76:e0:81:e5:37:2b:98"); + + _get_string_field_and_check( + cert, + CERTSVC_KEY_ALGO, + "rsaEncryption"); + + _get_string_field_and_check( + cert, + CERTSVC_SIGNATURE_ALGORITHM, + "sha256WithRSAEncryption"); + + _get_string_field_and_check( + cert, + CERTSVC_KEY, + " Public-Key: (1024 bit)\n" + " Modulus:\n" + " 00:d8:08:a3:a3:05:fb:e2:df:36:cd:e3:48:2f:3b:\n" + " 59:17:ce:e3:32:bf:9f:ef:f1:7c:fb:27:f9:7c:32:\n" + " 8b:88:ed:b0:cc:64:da:ff:f2:7b:f4:86:11:20:00:\n" + " 09:d0:85:14:12:ff:11:9f:63:01:db:bf:ea:4c:ee:\n" + " 28:32:79:4a:9a:61:5b:ef:97:a1:43:36:61:d3:71:\n" + " 1f:37:fa:fb:3f:09:2b:d2:0f:56:68:72:dd:bf:e1:\n" + " 42:55:5b:b4:18:85:00:cb:8b:3a:7d:43:0b:48:1f:\n" + " 4c:49:d8:46:06:41:b3:7b:f9:67:f3:77:e5:93:b5:\n" + " 16:80:b3:f3:2f:70:1e:60:17\n" + " Exponent: 65537 (0x10001)\n"); +} + +RUNNER_TEST(T0106_chain_sort) +{ + CertSvcCertificate cert1, cert2, cert3; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::certEE.c_str()), + TestData::certEE.size(), + CERTSVC_FORM_DER_BASE64, + &cert1); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::google2nd.c_str()), + TestData::google2nd.size(), + CERTSVC_FORM_DER_BASE64, + &cert2); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::googleCA.c_str()), + TestData::googleCA.size(), + CERTSVC_FORM_DER_BASE64, + &cert3); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + CertSvcCertificate collection[3]; + collection[0] = cert1; + collection[1] = cert3; + collection[2] = cert2; + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == certsvc_certificate_chain_sort(collection, 3), "FAIL TO SORT CERTIFICATE"); + + RUNNER_ASSERT_MSG(collection[2].privateHandler == cert3.privateHandler, "certsvc_certificate_chain_sort failed"); + + collection[0] = cert1; + collection[1] = cert3; + + RUNNER_ASSERT_MSG(CERTSVC_FAIL == certsvc_certificate_chain_sort(collection, 2), "certsvc_certificate_chain_sort failed"); +} + +RUNNER_TEST_GROUP_INIT(T0200_CAPI_CERTIFICATE_VERIFY) + +RUNNER_TEST(T0201_message_verify_dsa_sha1) +{ + CertSvcString msgb64, sigb64, msg, sig; + + int result = certsvc_string_new( + vinstance, + TestData::magda.message.c_str(), + TestData::magda.message.size(), + &msgb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); + + result = certsvc_string_new(vinstance, + TestData::magda.signature.c_str(), + TestData::magda.signature.size(), + &sigb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading signature."); + + CertSvcCertificate cert; + + result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::magda.certificate.c_str()), + TestData::magda.certificate.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + result = certsvc_base64_decode(msgb64, &msg); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + result = certsvc_base64_decode(sigb64, &sig); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + int status; + result = certsvc_message_verify(cert, msg, sig, "sha1", &status); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); + RUNNER_ASSERT_MSG(status == CERTSVC_TRUE, "Error in verify message."); +} + +RUNNER_TEST(T0202_message_verify_rsa_sha1) +{ + CertSvcString msgb64, sigb64, msg, sig; + + int result = certsvc_string_new( + vinstance, + TestData::filipSHA1.message.c_str(), + TestData::filipSHA1.message.size(), + &msgb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); + + result = certsvc_string_new( + vinstance, + TestData::filipSHA1.signature.c_str(), + TestData::filipSHA1.signature.size(), + &sigb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading signature."); + + CertSvcCertificate cert; + + result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::filipSHA1.certificate.c_str()), + TestData::filipSHA1.certificate.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + result = certsvc_base64_decode(msgb64, &msg); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + result = certsvc_base64_decode(sigb64, &sig); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + int status; + result = certsvc_message_verify(cert, msg, sig, "sha1", &status); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); + RUNNER_ASSERT_MSG(status == CERTSVC_SUCCESS, "Error in verify message."); + + std::string invalidMessage("q3plZ28gdHUgc3p1a2Fzej8K"); + + result = certsvc_string_new( + vinstance, + invalidMessage.c_str(), + invalidMessage.size(), + &msgb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); + + result = certsvc_base64_decode(msgb64, &msg); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + result = certsvc_message_verify(cert, msg, sig, "sha1", &status); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); + RUNNER_ASSERT_MSG(status == CERTSVC_INVALID_SIGNATURE, "Error in verify message."); +} + +RUNNER_TEST(T0203_message_verify_rsa_sha256) +{ + CertSvcString msgb64, sigb64, msg, sig; + + int result = certsvc_string_new( + vinstance, + TestData::filipSHA256.message.c_str(), + TestData::filipSHA256.message.size(), + &msgb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); + + result = certsvc_string_new( + vinstance, + TestData::filipSHA256.signature.c_str(), + TestData::filipSHA256.signature.size(), + &sigb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading signature."); + + CertSvcCertificate cert; + + result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::filipSHA256.certificate.c_str()), + TestData::filipSHA256.certificate.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + result = certsvc_base64_decode(msgb64, &msg); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + result = certsvc_base64_decode(sigb64, &sig); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + int status; + result = certsvc_message_verify(cert, msg, sig, "sha256", &status); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); + RUNNER_ASSERT_MSG(status == CERTSVC_SUCCESS, "Error in verify message."); + + std::string invalidMessage("q3plZ28gdHUgc3p1a2Fzej8K"); + + result = certsvc_string_new( + vinstance, + invalidMessage.c_str(), + invalidMessage.size(), + &msgb64); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); + + result = certsvc_base64_decode(msgb64, &msg); + RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); + + result = certsvc_message_verify(cert, msg, sig, "sha256", &status); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); + RUNNER_ASSERT_MSG(status == CERTSVC_INVALID_SIGNATURE, "Error in verify message."); +} + +RUNNER_TEST(T0204_certificate_verify) +{ + const int MAXC = 3; + CertSvcCertificate certificate[MAXC]; + + size_t certCount = 0; + for (auto &cert : TestData::certChain) + RUNNER_ASSERT_MSG( + CERTSVC_SUCCESS == + certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(cert.c_str()), + cert.size(), + CERTSVC_FORM_DER_BASE64, + &certificate[certCount++]), + "Error reading certificate"); + + int status; + int result = certsvc_certificate_verify(certificate[0], &certificate[1], MAXC-1, NULL, 0, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify(certificate[0], certificate, MAXC-1, NULL, 0, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_FAIL == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify(certificate[0], certificate, 1, certificate, MAXC, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_FAIL == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify(certificate[0], &certificate[2], 1, certificate, MAXC, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == status, "Error in certificate verification process."); + + // certsvc_certificate_verify_with_caflag + result = certsvc_certificate_verify_with_caflag(certificate[0], certificate, MAXC, NULL, 0, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify_with_caflag(certificate[0], certificate, MAXC-1, NULL, 0, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_FAIL == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify_with_caflag(certificate[0], certificate, 1, certificate, MAXC, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_FAIL == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify_with_caflag(certificate[0], &certificate[2], 1, certificate, MAXC, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == status, "Error in certificate verification process."); +} + +RUNNER_TEST(T0205_certificate_verify_with_caflag_selfsign_root) +{ + const int MAXC = 2; + CertSvcCertificate certificate[MAXC]; + + size_t certCount = 0; + for (auto &cert : TestData::certChainSelfSigned) + RUNNER_ASSERT_MSG( + CERTSVC_SUCCESS == + certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(cert.c_str()), + cert.size(), + CERTSVC_FORM_DER_BASE64, + &certificate[certCount++]), + "Error reading certificate"); + + int status; + int result = certsvc_certificate_verify(certificate[0], certificate, MAXC, NULL, 0, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == status, "Error in certificate verification process."); + + result = certsvc_certificate_verify_with_caflag(certificate[0], certificate, MAXC, NULL, 0, &status); + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certificate verification function."); + RUNNER_ASSERT_MSG(CERTSVC_FAIL == status, "Error in certificate verification process."); +} diff --git a/tests/capi/test-primitive.cpp b/tests/capi/test-primitive.cpp new file mode 100644 index 0000000..3644470 --- /dev/null +++ b/tests/capi/test-primitive.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#include +#include + +#include + +#include +#include + +#include "common-res.h" + +RUNNER_TEST_GROUP_INIT(T0300_CAPI_PRIMITIVES) + +RUNNER_TEST(T0301_dup_x509) +{ + const int MAXB = 1024; + + CertSvcCertificate certificate; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::googleCA.c_str()), + TestData::googleCA.size(), + CERTSVC_FORM_DER_BASE64, + &certificate); + + X509 *x509 = NULL; + result = certsvc_certificate_dup_x509(certificate, &x509); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in certsvc_certificate_dup_x509."); + RUNNER_ASSERT_MSG(x509 != NULL, "Error in certsvc_certificate_dup_x509."); + + X509_NAME *name = X509_get_subject_name(x509); + char buffer[MAXB]; + X509_NAME_oneline(name, buffer, MAXB); + + RUNNER_ASSERT_MSG(buffer == TestData::subjectGoogleCA, "Content does not match"); + + certsvc_certificate_free_x509(x509); +} + +RUNNER_TEST(T0302_dup_pubkey_der) +{ + CertSvcCertificate cert; + + int result = certsvc_certificate_new_from_memory( + vinstance, + reinterpret_cast(TestData::googleCA.c_str()), + TestData::googleCA.size(), + CERTSVC_FORM_DER_BASE64, + &cert); + + RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); + + unsigned char *pubkey = NULL; + size_t len = 0; + result = certsvc_certificate_dup_pubkey_der(cert, &pubkey, &len); + + RUNNER_ASSERT_MSG( + CERTSVC_SUCCESS == result, + "Error in certsvc_certificate_dup_pubkey_der. result : " << result); + + RUNNER_ASSERT_MSG( + d2i_PUBKEY(NULL, const_cast(&pubkey), static_cast(len)) != NULL, + "Error in converting returned der pubkey to internal."); +} diff --git a/tests/capi/test_suite_01.cpp b/tests/capi/test_suite_01.cpp deleted file mode 100644 index 5bc0b02..0000000 --- a/tests/capi/test_suite_01.cpp +++ /dev/null @@ -1,851 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ -#include -#include -#include -#include - -#include -#include -#include - -#include - -RUNNER_TEST_GROUP_INIT(CAPI) - -/* - * author: --- - * test: New certificate from file. - * description: Creating new certificate using *.pem file. - * expect: Certificate should be created and has correct string inside.. - */ -RUNNER_TEST(test01_certificate_new_from_file) -{ - CertSvcCertificate cert; - int result = certsvc_certificate_new_from_file( - vinstance, - "/usr/share/cert-svc/cert-type/root_cacert0.pem", - &cert); - RUNNER_ASSERT_MSG(CERTSVC_TRUE == result, "Error reading certificate"); - - CertSvcString string; - - certsvc_certificate_get_string_field( - cert, - CERTSVC_SUBJECT_COMMON_NAME, - &string); - - const char *ptr = "Samsung"; - - const char *buffer; - size_t len; - - certsvc_string_to_cstring(string, &buffer, &len); - - result = strncmp( - buffer, - ptr, - strlen(ptr)); - - RUNNER_ASSERT_MSG(0 == result, "Error reading common name"); - - certsvc_certificate_free(cert); -} - -/* - * author: --- - * test: Searching certificate. - * description: Searching for certificate with specified value. - * expect: Found certificate should had correct string inside. - */ -RUNNER_TEST(test02_certificate_search) -{ - CertSvcCertificateList handler; - int result = certsvc_certificate_search(vinstance, - CERTSVC_SUBJECT_COMMON_NAME, - "WAC Application Services Ltd", - &handler); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in search method. errcode : " << result); - - CertSvcCertificate cert; - - result = certsvc_certificate_list_get_one(handler, 0, &cert); - - RUNNER_ASSERT_MSG(CERTSVC_TRUE == result, "Error reading certificate. errcode : " << result); - - CertSvcString string; - - certsvc_certificate_get_string_field( - cert, - CERTSVC_SUBJECT_COUNTRY_NAME, - &string); - - const char *ptr = "GB"; - const char *buffer; - - certsvc_string_to_cstring(string, &buffer, NULL); - - result = strncmp( - buffer, - ptr, - strlen(ptr)); - - RUNNER_ASSERT_MSG(0 == result, "Country does not match. result : " << result); -} - -/* - * author: --- - * test: Testing certificate sign. - * description: Testing if certificate is signed by proper CA. - * expect: Chain verification should return success. - */ -RUNNER_TEST(test03_is_signed_by) -{ - int result; - std::string googleCA = - "MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG" - "A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz" - "cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2" - "MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV" - "BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt" - "YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN" - "ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE" - "BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is" - "I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G" - "CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do" - "lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc" - "AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k"; - - std::string google2nd = - "MIIDIzCCAoygAwIBAgIEMAAAAjANBgkqhkiG9w0B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qKjbc1YXWrOU/VG+WHgWv"; - - CertSvcCertificate cert1, cert2; - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)googleCA.c_str(), - googleCA.size(), - CERTSVC_FORM_DER_BASE64, - &cert1); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error reading certificate"); - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)google2nd.c_str(), - google2nd.size(), - CERTSVC_FORM_DER_BASE64, - &cert2); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error reading certificate"); - - int status; - result = certsvc_certificate_is_signed_by(cert2, cert1, &status); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Chain verification failed"); - RUNNER_ASSERT_MSG(CERTSVC_TRUE == status, "Chain verification failed"); -} - -/* - * author: --- - * test: Certificate expiring test. - * description: Testing if certificate is valid before / after specified date. - * expect: Certificate should be valid before / after specified date. - */ -RUNNER_TEST(test04_not_before_not_after) -{ - std::string google2nd = - "MIIDIzCCAoygAwIBAgIEMAAAAjANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJV" - "UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNzA1BgNVBAsTLkNsYXNzIDMgUHVi" - "bGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQwNTEzMDAw" - "MDAwWhcNMTQwNTEyMjM1OTU5WjBMMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh" - "d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBD" - "QTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1NNn0I0Vf67NMf59HZGhPwtx" - "PKzMyGT7Y/wySweUvW+Aui/hBJPAM/wJMyPpC3QrccQDxtLN4i/1CWPN/0ilAL/g" - "5/OIty0y3pg25gqtAHvEZEo7hHUD8nCSfQ5i9SGraTaEMXWQ+L/HbIgbBpV8yeWo" - "3nWhLHpo39XKHIdYYBkCAwEAAaOB/jCB+zASBgNVHRMBAf8ECDAGAQH/AgEAMAsG" - "A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAQYwKAYDVR0RBCEwH6QdMBsxGTAX" - "BgNVBAMTEFByaXZhdGVMYWJlbDMtMTUwMQYDVR0fBCowKDAmoCSgIoYgaHR0cDov" - "L2NybC52ZXJpc2lnbi5jb20vcGNhMy5jcmwwMgYIKwYBBQUHAQEEJjAkMCIGCCsG" - "AQUFBzABhhZodHRwOi8vb2NzcC50aGF3dGUuY29tMDQGA1UdJQQtMCsGCCsGAQUF" - "BwMBBggrBgEFBQcDAgYJYIZIAYb4QgQBBgpghkgBhvhFAQgBMA0GCSqGSIb3DQEB" - "BQUAA4GBAFWsY+reod3SkF+fC852vhNRj5PZBSvIG3dLrWlQoe7e3P3bB+noOZTc" - "q3J5Lwa/q4FwxKjt6lM07e8eU9kGx1Yr0Vz00YqOtCuxN5BICEIlxT6Ky3/rbwTR" - "bcV0oveifHtgPHfNDs5IAn8BL7abN+AqKjbc1YXWrOU/VG+WHgWv"; - - CertSvcCertificate cert; - int result; - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char *)google2nd.c_str(), - google2nd.size(), - CERTSVC_FORM_DER_BASE64, - &cert); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error reading certificate"); - - time_t before, after; - result = certsvc_certificate_get_not_before(cert, &before); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error extracting NOT_BEFORE"); - RUNNER_ASSERT_MSG(before == 1084406400, "TODO"); - - result = certsvc_certificate_get_not_after(cert, &after); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error extracting NOT_AFTER"); - //extracted: date --date="May 12 23:59:59 2014 GMT" +%s - RUNNER_ASSERT_MSG(after == 1399939199, "TODO"); -} - -/* - * author: --- - * test: Import fields from certificate. - * description: Getting common name from certificate. - * expect: It should be possible to get common name from certificate. - */ -RUNNER_TEST(test06_cert_get_field) -{ - std::string google2nd = - "MIIDIzCCAoygAwIBAgIEMAAAAjANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJV" - "UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNzA1BgNVBAsTLkNsYXNzIDMgUHVi" - "bGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQwNTEzMDAw" - "MDAwWhcNMTQwNTEyMjM1OTU5WjBMMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh" - "d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBD" - "QTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1NNn0I0Vf67NMf59HZGhPwtx" - "PKzMyGT7Y/wySweUvW+Aui/hBJPAM/wJMyPpC3QrccQDxtLN4i/1CWPN/0ilAL/g" - "5/OIty0y3pg25gqtAHvEZEo7hHUD8nCSfQ5i9SGraTaEMXWQ+L/HbIgbBpV8yeWo" - "3nWhLHpo39XKHIdYYBkCAwEAAaOB/jCB+zASBgNVHRMBAf8ECDAGAQH/AgEAMAsG" - "A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAQYwKAYDVR0RBCEwH6QdMBsxGTAX" - "BgNVBAMTEFByaXZhdGVMYWJlbDMtMTUwMQYDVR0fBCowKDAmoCSgIoYgaHR0cDov" - "L2NybC52ZXJpc2lnbi5jb20vcGNhMy5jcmwwMgYIKwYBBQUHAQEEJjAkMCIGCCsG" - "AQUFBzABhhZodHRwOi8vb2NzcC50aGF3dGUuY29tMDQGA1UdJQQtMCsGCCsGAQUF" - "BwMBBggrBgEFBQcDAgYJYIZIAYb4QgQBBgpghkgBhvhFAQgBMA0GCSqGSIb3DQEB" - "BQUAA4GBAFWsY+reod3SkF+fC852vhNRj5PZBSvIG3dLrWlQoe7e3P3bB+noOZTc" - "q3J5Lwa/q4FwxKjt6lM07e8eU9kGx1Yr0Vz00YqOtCuxN5BICEIlxT6Ky3/rbwTR" - "bcV0oveifHtgPHfNDs5IAn8BL7abN+AqKjbc1YXWrOU/VG+WHgWv"; - - CertSvcCertificate cert; - - int result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)google2nd.c_str(), - google2nd.size(), - CERTSVC_FORM_DER_BASE64, - &cert); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - CertSvcString subject, issuer; - - result = certsvc_certificate_get_string_field( - cert, - CERTSVC_SUBJECT, - &subject); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading SUBJECT field."); - - result = certsvc_certificate_get_string_field( - cert, - CERTSVC_ISSUER, - &issuer); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading ISSUER field."); - - size_t size; - const char *ptr; - - certsvc_string_to_cstring(subject, &ptr, &size); - RUNNER_ASSERT_MSG(0 == strncmp(ptr, "/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA", size), "Subject does not match."); - - certsvc_string_to_cstring(issuer, &ptr, &size); - RUNNER_ASSERT_MSG(0 == strncmp(ptr, "/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority", size), "Issuer does not match."); -} - -/* - * author: --- - * test: Sorting certificates chain. - * description: Certificate chain is being sorted. - * expect: It is possible to sor certificates chain. - */ -RUNNER_TEST(test07_chain_sort) -{ - std::string certEE = - "MIIDIjCCAougAwIBAgIQK59+5colpiUUIEeCdTqbuTANBgkqhkiG9w0BAQUFADBM" - "MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg" - "THRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBDQTAeFw0xMTEwMjYwMDAwMDBaFw0x" - "MzA5MzAyMzU5NTlaMGkxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlh" - "MR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VQQLEy5DbGFz" - "cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2" - "MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV" - "BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt" - "YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN" - "ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE" - "BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is" - "I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G" - "CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do" - "lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc" - "AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k"; - - CertSvcCertificate cert1, cert2, cert3; - - int result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)certEE.c_str(), - certEE.size(), - CERTSVC_FORM_DER_BASE64, - &cert1); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)certCA.c_str(), - certCA.size(), - CERTSVC_FORM_DER_BASE64, - &cert2); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)certRCA.c_str(), - certRCA.size(), - CERTSVC_FORM_DER_BASE64, - &cert3); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - CertSvcCertificate collection[3]; - collection[0] = cert1; - collection[1] = cert3; - collection[2] = cert2; - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == certsvc_certificate_chain_sort(collection, 3), "FAIL TO SORT CERTIFICATE"); - - RUNNER_ASSERT_MSG(collection[2].privateHandler == cert3.privateHandler, "certsvc_certificate_chain_sort failed"); - - collection[0] = cert1; - collection[1] = cert3; - - RUNNER_ASSERT_MSG(CERTSVC_FAIL == certsvc_certificate_chain_sort(collection, 2), "certsvc_certificate_chain_sort failed"); -} - -/* - * author: --- - * test: Verification of DSA SHA1. - * description: Testing certificate DSA SH1. - * expect: Certificate DSA SH1 should be correct. - */ -RUNNER_TEST(test08_message_verify_dsa_sha1) -{ - std::string magda = - "MIIEDzCCA3igAwIBAgIJAMdKgvadG/Z/MA0GCSqGSIb3DQEBBQUAMHIxCzAJBgNV" - "BAYTAlBMMQwwCgYDVQQIEwNNYXoxEDAOBgNVBAoTB1NhbXN1bmcxDTALBgNVBAsT" - "BFNQUkMxEDAOBgNVBAMTB1NhbXN1bmcxIjAgBgkqhkiG9w0BCQEWE3NhbXN1bmdA" - "c2Ftc3VuZy5jb20wHhcNMTExMDA1MTIxMTMzWhcNMjExMDAyMTIxMTMzWjCBijEL" - "MAkGA1UEBhMCUEwxFDASBgNVBAgTC01hem93aWVja2llMRIwEAYDVQQHEwlsZWdp" - "b25vd28xEDAOBgNVBAoTB3NhbXN1bmcxDTALBgNVBAsTBHNwcmMxDjAMBgNVBAMT" - "BW1hZ2RhMSAwHgYJKoZIhvcNAQkBFhFtYWdkYUBzYW1zdW5nLmNvbTCCAbcwggEr" - "BgcqhkjOOAQBMIIBHgKBgQC1PCOasFhlfMc1yjdcp7zkzXGiW+MpVuFlsdYwkAa9" - "sIvNrQLi2ulxcnNBeCHKDbk7U+J3/QwO2XanapQMUqvfjfjL1QQ5Vf7ENUWPNP7c" - "Evx82Nb5jWdHyRfV//TciBZN8GLNEbfhtWlhI6CbDW1AaY0nPZ879rSIk7/aNKZ3" - "FQIVALcr8uQAmnV+3DLIA5nTo0Bg0bjLAoGAJG7meUtQbMulRMdjzeCoya2FXdm+" - "4acvInE9/+MybXTB3bFANMyw6WTvk4K9RK8tm52N95cykTjpAbxqTMaXwkdWbOFd" - "VKAKnyxi/UKtY9Q6NmwJB2hbA1GUzhPko8rEda66CGl0VbyM1lKMJjA+wp9pG110" - "L0ov19Q9fvqKp5UDgYUAAoGBAKxAQg7MqCgkC0MJftYjNaKM5n1iZv4j1li49zKf" - "Y5nTLP+vYAvg0owLNYvJ5ncKfY1DACPU4/+tC7TTua95wgj5rwvAXnzgSyOGuSr0" - "fK9DyrH6E0LfXT+WuIQHahm2iSbxqPrChlnp5/EXDTBaO6Qfdpq0BP48ClZebxcA" - "+TYFo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVy" - "YXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUmSpShswvWtEABd+l3WxccRcCydUw" - "HwYDVR0jBBgwFoAUggh/2wAChuhTKqX6WK5nfxQ4yGAwDQYJKoZIhvcNAQEFBQAD" - "gYEAgfnAu/gMJRC/BFwkgvrHL0TV4ffPVAf7RSnZS6ib4IHGgrvXJvL+Qh7vHykv" - "ZIqD2L96nY2EaSNr0yXrT81YROndOQUJNx4Y/W8m6asu4hzANNZqWCbApPDIMK6V" - "cPA1wrKgZqbWp218WBqI2v9pXV0O+jpzxq1+GeQV2UsbRwc="; - - std::string message = "c2lnbmVkIGRhdGEK"; - std::string signature = "MC0CFQCL2pDA4S/zsHkDUCWOq7K6ebG14gIUHHoLsbeUd+BEqBXB6XjmcTncBRA="; - - CertSvcString msgb64, sigb64, msg, sig; - - int result = certsvc_string_new(vinstance, message.c_str(), message.size(), &msgb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); - - result = certsvc_string_new(vinstance, signature.c_str(), signature.size(), &sigb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading signature."); - - CertSvcCertificate cert; - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)magda.c_str(), - magda.size(), - CERTSVC_FORM_DER_BASE64, - &cert); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - result = certsvc_base64_decode(msgb64, &msg); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - result = certsvc_base64_decode(sigb64, &sig); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - int status; - result = certsvc_message_verify(cert, msg, sig, "sha1", &status); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); - RUNNER_ASSERT_MSG(status == CERTSVC_TRUE, "Error in verify message."); -} - -/* - * author: --- - * test: Verification of RSA SHA1. - * description: Testing certificate RSA SH1. - * expect: Certificate RSA SH1 should be correct. - */ -RUNNER_TEST(test09_message_verify_rsa_sha1) -{ - std::string filip = - "MIIC4zCCAkygAwIBAgIJAMdKgvadG/Z+MA0GCSqGSIb3DQEBBQUAMHIxCzAJBgNV" - "BAYTAlBMMQwwCgYDVQQIEwNNYXoxEDAOBgNVBAoTB1NhbXN1bmcxDTALBgNVBAsT" - "BFNQUkMxEDAOBgNVBAMTB1NhbXN1bmcxIjAgBgkqhkiG9w0BCQEWE3NhbXN1bmdA" - "c2Ftc3VuZy5jb20wHhcNMTExMDA1MTIwMDUxWhcNMjExMDAyMTIwMDUxWjB4MQsw" - "CQYDVQQGEwJQTDEMMAoGA1UECBMDTUFaMQwwCgYDVQQHEwNMZWcxDDAKBgNVBAoT" - "A1NhbTENMAsGA1UECxMEU1BSQzEOMAwGA1UEAxMFRmlsaXAxIDAeBgkqhkiG9w0B" - "CQEWEWZpbGlwQHNhbXN1bmcuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB" - "gQDS/sS0wXSCb34ojN8bWFd4Pl9eTLHh18UNGsPpLpp4itdfuc/OgyqaSoDwBzVh" - "EWAVLCTxexUa4Ncva+41NbkW4RCsFzeGs0ktpu1+8Q+v0QEOGqVF2rQkgilzDF/o" - "O56Fxw9vG1OA+qdQd3yOAV2EqLNBPrEYB9K5GFyffrakSQIDAQABo3sweTAJBgNV" - "HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp" - "Y2F0ZTAdBgNVHQ4EFgQUeyy3iV75KtOkpPFd6mnR9dFGZMwwHwYDVR0jBBgwFoAU" - "ggh/2wAChuhTKqX6WK5nfxQ4yGAwDQYJKoZIhvcNAQEFBQADgYEADtv0CBrQ1QCM" - "H9jKFjpSpq7zFKMXQeVtb/Zie823//woicg8kxnP5sS4dJWNXNb1iMLdhgV80g1y" - "t3gTWPxTtFzprQyNiJHTmrbNWXLX1roRVGUE/I8Q4xexqpbNlJIW2Jjm/kqoKfnK" - "xORG6HNPXZV29NY2fDRPPOIYoFQzrXI="; - - std::string message = "Q3plZ28gdHUgc3p1a2Fzej8K"; - std::string signature = - "xEIpVjEIUoDkYGtX2ih6Gbya0/gr7OMdvbBKmjqzfNh9GHqwrgjglByeC5sspUzPBUF4Vmg/hZqL" - "gSsxXw9bKEa8c6mTQoNX51IC0ELPsoUMIJF1gGdFu0SzKptvU0+ksiiOM+70+s5t8s3z0G5PeA7O" - "99oq8UlrX7GDlxaoTU4="; - - CertSvcString msgb64, sigb64, msg, sig; - - int result = certsvc_string_new(vinstance, message.c_str(), message.size(), &msgb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); - - result = certsvc_string_new(vinstance, signature.c_str(), signature.size(), &sigb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading signature."); - - CertSvcCertificate cert; - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)filip.c_str(), - filip.size(), - CERTSVC_FORM_DER_BASE64, - &cert); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - result = certsvc_base64_decode(msgb64, &msg); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - result = certsvc_base64_decode(sigb64, &sig); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - int status; - result = certsvc_message_verify(cert, msg, sig, "sha1", &status); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); - RUNNER_ASSERT_MSG(status == CERTSVC_SUCCESS, "Error in verify message."); - - message[0] = 'q'; - - result = certsvc_string_new(vinstance, message.c_str(), message.size(), &msgb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); - - result = certsvc_base64_decode(msgb64, &msg); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - result = certsvc_message_verify(cert, msg, sig, "sha1", &status); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); - RUNNER_ASSERT_MSG(status == CERTSVC_INVALID_SIGNATURE, "Error in verify message."); -} - -/* - * author: --- - * test: Verification of RSA SHA1. - * description: Testing certificate RSA SHA256. - * expect: Certificate RSA SH256 should be correct. - */ -RUNNER_TEST(test10_message_verify_rsa_sha256) -{ - std::string filip = - "MIIC4zCCAkygAwIBAgIJAMdKgvadG/Z+MA0GCSqGSIb3DQEBBQUAMHIxCzAJBgNV" - "BAYTAlBMMQwwCgYDVQQIEwNNYXoxEDAOBgNVBAoTB1NhbXN1bmcxDTALBgNVBAsT" - "BFNQUkMxEDAOBgNVBAMTB1NhbXN1bmcxIjAgBgkqhkiG9w0BCQEWE3NhbXN1bmdA" - "c2Ftc3VuZy5jb20wHhcNMTExMDA1MTIwMDUxWhcNMjExMDAyMTIwMDUxWjB4MQsw" - "CQYDVQQGEwJQTDEMMAoGA1UECBMDTUFaMQwwCgYDVQQHEwNMZWcxDDAKBgNVBAoT" - "A1NhbTENMAsGA1UECxMEU1BSQzEOMAwGA1UEAxMFRmlsaXAxIDAeBgkqhkiG9w0B" - "CQEWEWZpbGlwQHNhbXN1bmcuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB" - "gQDS/sS0wXSCb34ojN8bWFd4Pl9eTLHh18UNGsPpLpp4itdfuc/OgyqaSoDwBzVh" - "EWAVLCTxexUa4Ncva+41NbkW4RCsFzeGs0ktpu1+8Q+v0QEOGqVF2rQkgilzDF/o" - "O56Fxw9vG1OA+qdQd3yOAV2EqLNBPrEYB9K5GFyffrakSQIDAQABo3sweTAJBgNV" - "HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp" - "Y2F0ZTAdBgNVHQ4EFgQUeyy3iV75KtOkpPFd6mnR9dFGZMwwHwYDVR0jBBgwFoAU" - "ggh/2wAChuhTKqX6WK5nfxQ4yGAwDQYJKoZIhvcNAQEFBQADgYEADtv0CBrQ1QCM" - "H9jKFjpSpq7zFKMXQeVtb/Zie823//woicg8kxnP5sS4dJWNXNb1iMLdhgV80g1y" - "t3gTWPxTtFzprQyNiJHTmrbNWXLX1roRVGUE/I8Q4xexqpbNlJIW2Jjm/kqoKfnK" - "xORG6HNPXZV29NY2fDRPPOIYoFQzrXI="; - - std::string message = "Q3plZ28gdHUgc3p1a2Fzej8K"; - std::string signature = - "a5nGT6wnbQ8MLwLkG965E4e1Rv983E+v3nolLvvjuAKnfgWYb+70Da+T9ggYDTjngq+EBgC30w1p" - "EScrwye8ELefvRxDWy1+tWR4QRW/Nd4oN2U/pvozoabDSpe9Cvt0ECEOWKDqIYYnoWFjOiXg9VwD" - "HVVkQXvsSYu6thX/Xsk="; - - CertSvcString msgb64, sigb64, msg, sig; - - int result = certsvc_string_new(vinstance, message.c_str(), message.size(), &msgb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); - - result = certsvc_string_new(vinstance, signature.c_str(), signature.size(), &sigb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading signature."); - - CertSvcCertificate cert; - - result = certsvc_certificate_new_from_memory( - vinstance, - (const unsigned char*)filip.c_str(), - filip.size(), - CERTSVC_FORM_DER_BASE64, - &cert); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading certificate."); - - result = certsvc_base64_decode(msgb64, &msg); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - result = certsvc_base64_decode(sigb64, &sig); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - int status; - result = certsvc_message_verify(cert, msg, sig, "sha256", &status); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); - RUNNER_ASSERT_MSG(status == CERTSVC_SUCCESS, "Error in verify message."); - - message[0] = 'q'; - - result = certsvc_string_new(vinstance, message.c_str(), message.size(), &msgb64); - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in reading messsage."); - - result = certsvc_base64_decode(msgb64, &msg); - RUNNER_ASSERT_MSG(result == CERTSVC_TRUE, "Error in decoding base64."); - - result = certsvc_message_verify(cert, msg, sig, "sha256", &status); - - RUNNER_ASSERT_MSG(CERTSVC_SUCCESS == result, "Error in verify message."); - RUNNER_ASSERT_MSG(status == CERTSVC_INVALID_SIGNATURE, "Error in verify message."); -} - -/* - * author: --- - * test: Certificate verification. - * description: Verification of certificates. - * expect: Verification should return expected results. - */ -RUNNER_TEST(test14_certificate_verify) -{ - const int MAXC = 3; - std::string cert[MAXC]; - cert[0] = // aia_signer - "MIIDXTCCAsagAwIBAgIBAjANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJLUjEO" - "MAwGA1UECAwFU2VvdWwxEDAOBgNVBAoMB1NhbXN1bmcxEzARBgNVBAsMClRpemVu" - "IFRlc3QxFzAVBgNVBAMMDlRlc3QgU2Vjb25kIENBMRswGQYJKoZIhvcNAQkBFgx0" - "d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0fmlehtN52NLjjPEG6u9YFYfzSkjQlVR0qfQ2mNs3d6AKFlOdZOT6cuEIZuKe" - "pDb2Tx5JJbIN6N3fE/lVSW88K9aSCF2n15gYTSVmD0juHuLAoWnIicaa+Sbe2Tsj" - "AQ=="; - - CertSvcCertificate certificate[MAXC]; - - int result, status; - - for (int i=0; i -#include - -#include #include +#include -#include +#include #include -RUNNER_TEST_GROUP_INIT(DEPRECATED_API) +RUNNER_TEST_GROUP_INIT(T0100_CERTIFICATE_PARSING) typedef std::unique_ptr> ScopedCertCtx; @@ -34,7 +31,7 @@ typedef std::unique_ptr> ScopedC * description: Loading *.pem file. * expect: *.pem should load with no error. */ -RUNNER_TEST(deprecated_api_test01_pem_positive) +RUNNER_TEST(T0101_pem_positive) { ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final); RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR == @@ -47,7 +44,7 @@ RUNNER_TEST(deprecated_api_test01_pem_positive) * description: Loading *.der file. * expect: *.der file should load with no error. */ -RUNNER_TEST(deprecated_api_test02_der_positive) +RUNNER_TEST(T0102_der_positive) { ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final); RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR == @@ -60,7 +57,7 @@ RUNNER_TEST(deprecated_api_test02_der_positive) * description: Loading *.pem file. * expect: *.pom file should not load and return error. */ -RUNNER_TEST(deprecated_api_test03_pem_negative) +RUNNER_TEST(T0103_pem_negative) { ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final); RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR != @@ -73,7 +70,7 @@ RUNNER_TEST(deprecated_api_test03_pem_negative) * description: Loading *.der file. * expect: *.der file should not load and return error. */ -RUNNER_TEST(deprecated_api_test03_der_negative) +RUNNER_TEST(T0104_der_negative) { ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final); RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR != diff --git a/vcore/cert-svc/ccert.h b/vcore/cert-svc/ccert.h index 1ccfee1..7d09b81 100644 --- a/vcore/cert-svc/ccert.h +++ b/vcore/cert-svc/ccert.h @@ -84,19 +84,25 @@ typedef enum CertSvcCertificateField_t { CERTSVC_SUBJECT_COMMON_NAME, CERTSVC_SUBJECT_COUNTRY_NAME, CERTSVC_SUBJECT_STATE_NAME, + CERTSVC_SUBJECT_LOCALITY_NAME, CERTSVC_SUBJECT_ORGANIZATION_NAME, CERTSVC_SUBJECT_ORGANIZATION_UNIT_NAME, CERTSVC_SUBJECT_EMAIL_ADDRESS, +/* CERTSVC_SUBJECT_UID, */ CERTSVC_ISSUER, CERTSVC_ISSUER_COMMON_NAME, CERTSVC_ISSUER_COUNTRY_NAME, CERTSVC_ISSUER_STATE_NAME, + CERTSVC_ISSUER_LOCALITY_NAME, CERTSVC_ISSUER_ORGANIZATION_NAME, CERTSVC_ISSUER_ORGANIZATION_UNIT_NAME, + CERTSVC_ISSUER_EMAIL_ADDRESS, +/* CERTSVC_ISSUER_UID, */ CERTSVC_VERSION, CERTSVC_SERIAL_NUMBER, CERTSVC_KEY_USAGE, CERTSVC_KEY, + CERTSVC_KEY_ALGO, CERTSVC_SIGNATURE_ALGORITHM } CertSvcCertificateField; diff --git a/vcore/cert-svc/cprimitives.h b/vcore/cert-svc/cprimitives.h index 72eb0c0..37f59d2 100644 --- a/vcore/cert-svc/cprimitives.h +++ b/vcore/cert-svc/cprimitives.h @@ -52,6 +52,17 @@ int certsvc_certificate_dup_x509(CertSvcCertificate certificate, X509** cert); void certsvc_certificate_free_x509(X509 *x509_copy); /** + * Duplicate pubkey in DER form from CertSvcCertificate. + * Remarks: Free returned pubkey after use by free() + * + * @param[in] certificate Pointer to certificate. + * @param[out] pubkey Duplicated certificate in DER form + * @param[out] len Duplicated certificate length + * @return CERTSVC_SUCCESS, CERTSVC_WRONG_ARGUMENT, CERTSVC_FAIL + */ +int certsvc_certificate_dup_pubkey_der(CertSvcCertificate certificate, unsigned char **pubkey, size_t *len); + +/** * This will return pointer to EVP_PKEY base openssl struct. This struct must * be release with function certsvc_pkcs12_free_evp_pkey * diff --git a/vcore/vcore/Certificate.cpp b/vcore/vcore/Certificate.cpp index f5e3cec..052701c 100644 --- a/vcore/vcore/Certificate.cpp +++ b/vcore/vcore/Certificate.cpp @@ -273,6 +273,27 @@ std::string Certificate::getEmailAddres(FieldType type) const return getField(type, NID_pkcs9_emailAddress); } +std::string Certificate::getUID(FieldType type) const +{ + ASN1_BIT_STRING *uid = NULL; + if (type == FIELD_SUBJECT) + uid = m_x509->cert_info->subjectUID; + else + uid = m_x509->cert_info->issuerUID; + + if (uid->data == NULL) + return std::string(); + + char *temp = new char[uid->length + 1]; + memcpy(temp, uid->data, uid->length); + temp[uid->length] = 0; + + std::string uidStr(temp); + delete []temp; + + return uidStr; +} + std::string Certificate::getOCSPURL() const { // TODO verify this code @@ -505,6 +526,30 @@ std::string Certificate::getPublicKeyString() const return result; } +void Certificate::getPublicKeyDER(unsigned char **pubkey, size_t *len) const +{ + if (pubkey == NULL || len == NULL) + VcoreThrowMsg(Certificate::Exception::WrongParamError, "Wrong parameter"); + + EVP_PKEY *pkey = X509_get_pubkey(m_x509); + unsigned char *_pubkey = NULL; + int _len = i2d_PUBKEY(pkey, &_pubkey); + EVP_PKEY_free(pkey); + + if (_pubkey == NULL || _len == 0) + VcoreThrowMsg(Certificate::Exception::OpensslInternalError, + "Error in i2d_PUBKEY"); + + *pubkey = _pubkey; + *len = static_cast(_len); +} + +std::string Certificate::getPublicKeyAlgoString() const +{ + return std::string(static_cast( + OBJ_nid2ln(OBJ_obj2nid(m_x509->cert_info->key->algor->algorithm)))); +} + int Certificate::isCA() const { return X509_check_ca(m_x509); diff --git a/vcore/vcore/Certificate.h b/vcore/vcore/Certificate.h index 1bde60a..9344440 100644 --- a/vcore/vcore/Certificate.h +++ b/vcore/vcore/Certificate.h @@ -56,6 +56,7 @@ public: VCORE_DECLARE_EXCEPTION_TYPE(ValidationCore::Exception, Base); VCORE_DECLARE_EXCEPTION_TYPE(Base, OpensslInternalError); VCORE_DECLARE_EXCEPTION_TYPE(Base, Base64Error); + VCORE_DECLARE_EXCEPTION_TYPE(Base, WrongParamError); }; typedef std::vector Fingerprint; @@ -115,6 +116,9 @@ public: std::string getOrganizationName(FieldType type = FIELD_SUBJECT) const; std::string getOrganizationalUnitName(FieldType type = FIELD_SUBJECT) const; std::string getEmailAddres(FieldType type = FIELD_SUBJECT) const; + + // TODO: UID type is unsigned char. std::string should be changed to unsigned char container + std::string getUID(FieldType type = FIELD_SUBJECT) const; std::string getOCSPURL() const; @@ -150,7 +154,9 @@ public: std::string getSerialNumberString() const; std::string getKeyUsageString() const; std::string getSignatureAlgorithmString() const; + std::string getPublicKeyAlgoString() const; std::string getPublicKeyString() const; + void getPublicKeyDER(unsigned char **pubkey, size_t *len) const; /* * 0 - not CA diff --git a/vcore/vcore/api.cpp b/vcore/vcore/api.cpp index 5f05667..ec62504 100644 --- a/vcore/vcore/api.cpp +++ b/vcore/vcore/api.cpp @@ -206,6 +206,9 @@ public: case CERTSVC_SUBJECT_STATE_NAME: result = certPtr->getStateOrProvinceName(); break; + case CERTSVC_SUBJECT_LOCALITY_NAME: + result = certPtr->getLocalityName(); + break; case CERTSVC_SUBJECT_ORGANIZATION_NAME: result = certPtr->getOrganizationName(); break; @@ -215,18 +218,37 @@ public: case CERTSVC_SUBJECT_EMAIL_ADDRESS: result = certPtr->getEmailAddres(); break; +/* + case CERTSVC_SUBJECT_UID: + result = certPtr->getUID(); + break; +*/ case CERTSVC_ISSUER_COMMON_NAME: result = certPtr->getCommonName(Certificate::FIELD_ISSUER); break; + case CERTSVC_ISSUER_COUNTRY_NAME: + result = certPtr->getCountryName(Certificate::FIELD_ISSUER); + break; case CERTSVC_ISSUER_STATE_NAME: result = certPtr->getStateOrProvinceName(Certificate::FIELD_ISSUER); break; + case CERTSVC_ISSUER_LOCALITY_NAME: + result = certPtr->getLocalityName(Certificate::FIELD_ISSUER); + break; case CERTSVC_ISSUER_ORGANIZATION_NAME: result = certPtr->getOrganizationName(Certificate::FIELD_ISSUER); break; case CERTSVC_ISSUER_ORGANIZATION_UNIT_NAME: result = certPtr->getOrganizationalUnitName(Certificate::FIELD_ISSUER); break; + case CERTSVC_ISSUER_EMAIL_ADDRESS: + result = certPtr->getEmailAddres(Certificate::FIELD_ISSUER); + break; +/* + case CERTSVC_ISSUER_UID: + result = certPtr->getUID(Certificate::FIELD_ISSUER); + break; +*/ case CERTSVC_VERSION: { std::stringstream stream; @@ -243,6 +265,9 @@ public: case CERTSVC_KEY: result = certPtr->getPublicKeyString(); break; + case CERTSVC_KEY_ALGO: + result = certPtr->getPublicKeyAlgoString(); + break; case CERTSVC_SIGNATURE_ALGORITHM: result = certPtr->getSignatureAlgorithmString(); break; @@ -492,6 +517,18 @@ public: return CERTSVC_SUCCESS; } + inline int getPubkeyDER(const CertSvcCertificate &certificate, + unsigned char **pubkey, + size_t *len) + { + auto it = m_certificateMap.find(certificate.privateHandler); + if (it == m_certificateMap.end() || pubkey == NULL || len == NULL) + return CERTSVC_WRONG_ARGUMENT; + + it->second->getPublicKeyDER(pubkey, len); + return CERTSVC_SUCCESS; + } + inline int saveToFile(const CertSvcCertificate &certificate, const char *location) { @@ -1328,6 +1365,17 @@ void certsvc_certificate_free_x509(X509 *x509) X509_free(x509); } +int certsvc_certificate_dup_pubkey_der( + CertSvcCertificate certificate, + unsigned char **pubkey, + size_t *len) +{ + try { + return impl(certificate.privateInstance)->getPubkeyDER(certificate, pubkey, len); + } catch (...) {} + return CERTSVC_FAIL; +} + void certsvc_pkcs12_free_evp_pkey(EVP_PKEY* pkey) { EVP_PKEY_free(pkey);