Add PKIX build 91/2491/18
authorSachin Agrawal <sachin.agrawal@intel.com>
Fri, 18 Sep 2015 23:47:56 +0000 (16:47 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Fri, 18 Sep 2015 23:52:26 +0000 (23:52 +0000)
To build with X.509 support:
scons SECURED=1 DTLS_WITH_X509=1

Change-Id: I63f0b9e4b1efa6f5871ee23d30ed5975424366ef
Signed-off-by: Dmytro Zhuravlev <d.zhuravlev@samsung.com>
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2491

build_common/SConscript
extlibs/asn1cert/SConscript
resource/csdk/SConscript
resource/csdk/connectivity/src/SConscript
resource/csdk/security/SConscript
resource/csdk/security/provisioning/SConscript
resource/csdk/security/provisioning/ck_manager/SConscript [new file with mode: 0644]
resource/csdk/security/provisioning/ck_manager/tools/SConscript [new file with mode: 0644]
resource/csdk/security/provisioning/ck_manager/unittest/SConscript [new file with mode: 0644]
resource/csdk/security/provisioning/sample/SConscript
resource/csdk/security/provisioning/unittest/SConscript

index 7f4c650..b7a1732 100644 (file)
@@ -87,6 +87,7 @@ else:
 
 help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
 help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
+help_vars.Add(EnumVariable('DTLS_WITH_X509', 'DTLS with X.509 support', '0', allowed_values=('0', '1')))
 help_vars.Add(EnumVariable('TEST', 'Run unit tests', '0', allowed_values=('0', '1')))
 help_vars.Add(BoolVariable('LOGGING', 'Enable stack logging', logging_default))
 help_vars.Add(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload))
index c2ccdc9..2700770 100644 (file)
@@ -48,6 +48,10 @@ if target_os in targets_need_asn1:
        asn1_env.Configure(src_dir + '/extlibs/asn1cert', './asn1c-0.9.27/asn1c/asn1c certificate.asn')
        asn1_env.Configure(src_dir + '/extlibs/asn1cert', './asn1c-0.9.27/asn1c/asn1c crl.asn')
        asn1_env.Configure(src_dir + '/extlibs/asn1cert', './asn1c-0.9.27/asn1c/asn1c csr.asn')
+       asn1_env.Configure(src_dir + '/extlibs/asn1cert', 'rm converter-sample.c')
 
-
+       #Build asn1 as static library
+       asn1_src = Glob('*.c')
+       asn1_lib = asn1_env.StaticLibrary('asn1', asn1_src)
+       asn1_env.InstallTarget(asn1_lib, 'libasn1')
 
index a9e30c8..06512a5 100644 (file)
@@ -68,6 +68,7 @@ liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 
 if target_os in ['android', 'linux', 'tizen']:
        liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
+
        if with_ra:
                liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
 
@@ -96,6 +97,9 @@ if env.get('SECURED') == '1':
 if env.get('LOGGING'):
        liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
+if env.get('DTLS_WITH_X509') == '1':
+       liboctbstack_env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
+
 liboctbstack_env.Append(LIBS = ['c_common'])
 
 ######################################################################
index 78255b6..58334a0 100644 (file)
@@ -56,6 +56,16 @@ if env.get('SECURED') == '1':
                                                 'adapter_util/caadapternetdtls.c')])
        env.AppendUnique(CPPPATH = [os.path.join(root_dir,
                                                  'external/inc')])
+if env.get('DTLS_WITH_X509') == '1':
+       src_dir = env.get('SRC_DIR')
+       env.AppendUnique(CPPPATH = [src_dir + '/resource/csdk/connectivity/inc/pkix'])
+       env.AppendUnique(CPPPATH = [src_dir + '/extlibs/tinydtls/ecc/'])
+       env.AppendUnique(CPPPATH = [src_dir + '/extlibs/tinydtls/sha2/'])
+       env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
+       if not env.get('RELEASE'):
+               env.AppendUnique(CPPDEFINES = ['X509_DEBUG'])
+       pkix_src = Glob('adapter_util/pkix/*.c');
+       env.AppendUnique(CA_SRC = pkix_src)
 
 ca_common_src = None
 if ca_os == 'arduino':
index 0266046..c07f00c 100755 (executable)
@@ -78,6 +78,9 @@ if target_os in ['darwin', 'ios']:
 if not env.get('RELEASE'):
        libocsrm_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
+if env.get('DTLS_WITH_X509') == '1':
+       libocsrm_env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
+
 ######################################################################
 # Source files and Targets
 ######################################################################
@@ -121,6 +124,11 @@ else:
                OCSRM_SRC + 'base64.c'
                ]
 
+if env.get('DTLS_WITH_X509') == '1' and env.get('SECURED') == '1':
+       crl_src = [OCSRM_SRC + 'crlresource.c']
+       libocsrm_src  = libocsrm_src + crl_src
+
+
 libocsrm = libocsrm_env.StaticLibrary('libocsrm', libocsrm_src)
 
 libocsrm_env.InstallTarget(libocsrm, 'libocsrm')
index 86317a1..9c5a094 100644 (file)
@@ -45,7 +45,11 @@ provisioning_env.AppendUnique(CPPPATH = [
                '../../connectivity/lib/libcoap-4.1.1',
                '../../connectivity/api',
                '../include',
-               '../include/internal'
+               '../include/internal',
+               '../../../../extlibs/tinydtls/ecc',
+               '../../../../extlibs/tinydtls/sha2',
+               '../../../../extlibs/asn1cert',
+               'ck_manager/include'
                ])
 target_os = env.get('TARGET_OS')
 provisioning_env.AppendUnique(CFLAGS = ['-D__WITH_DTLS__'])
@@ -64,6 +68,9 @@ provisioning_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connecti
 
 provisioning_env.AppendUnique(LIBS = ['tinydtls'])
 
+if env.get('DTLS_WITH_X509') == '1':
+       provisioning_env.AppendUnique(LIBS = ['CKManger'])
+
 provisioning_env.ParseConfig('pkg-config --libs glib-2.0');
 
 if target_os == 'android':
@@ -92,6 +99,9 @@ provisioningserver = provisioning_env.StaticLibrary('ocpmapi', provisioning_src)
 provisioning_env.InstallTarget(provisioningserver, 'libocpmapi')
 provisioning_env.UserInstallTargetLib(provisioningserver, 'libocpmapi')
 
+if env.get('DTLS_WITH_X509') == '1':
+       SConscript('ck_manager/SConscript')
+
 if target_os in ['linux']:
        SConscript('sample/SConscript')
 
diff --git a/resource/csdk/security/provisioning/ck_manager/SConscript b/resource/csdk/security/provisioning/ck_manager/SConscript
new file mode 100644 (file)
index 0000000..0a95b5e
--- /dev/null
@@ -0,0 +1,47 @@
+# SConscript file for Local PKI project
+
+Import('env')
+
+x509_env = env.Clone()
+
+EXTLIBS_DIR = "/extlibs/"
+
+# Includes
+INCLUDE_DIRS = []
+
+src_dir = x509_env.get('SRC_DIR')
+
+SConscript(src_dir + '/extlibs/asn1cert/SConscript')
+
+#Internal sources
+INCLUDE_DIRS.append(src_dir +'/resource/csdk/security/provisioning/ck_manager/include/');
+INCLUDE_DIRS.append(src_dir + '/resource/csdk/connectivity/inc/pkix/');
+
+#External sources
+INCLUDE_DIRS.append(src_dir + '/extlibs/tinydtls/ecc/');
+INCLUDE_DIRS.append(src_dir + '/extlibs/tinydtls/sha2/');
+INCLUDE_DIRS.append(src_dir + '/extlibs/asn1cert/');
+INCLUDE_DIRS.append(src_dir + '/extlibs/cjson/');
+
+#OIC incude
+INCLUDE_DIRS.append(src_dir + '/resource/csdk/security/include/');
+INCLUDE_DIRS.append(src_dir + '/resource/csdk/security/include/internal/');
+INCLUDE_DIRS.append(src_dir + '/resource/csdk/stack/include/');
+
+DEFINES = ['WITH_SHA256', 'uECC_CURVE=uECC_secp256r1', 'X509_DEBUG']
+
+x509_env.AppendUnique(CPPPATH = INCLUDE_DIRS)
+x509_env.AppendUnique(CPPDEFINES = DEFINES)
+
+#Encoder/Decoder source code
+ckmanager_src = Glob('src/*.c')
+
+#Build static libraries
+ckmStaticLib = x509_env.StaticLibrary('CKManager', ckmanager_src)
+
+x509_env.InstallTarget(ckmStaticLib, 'libCKManager')
+
+#x509_env.AppendUnique(LIBS = ['ocsrm'])
+x509_env.AppendUnique(LIBS = ['asn1'])
+x509_env.AppendUnique(LIBS = ['Base64'])
+x509_env.AppendUnique(LIBS = ['Json'])
diff --git a/resource/csdk/security/provisioning/ck_manager/tools/SConscript b/resource/csdk/security/provisioning/ck_manager/tools/SConscript
new file mode 100644 (file)
index 0000000..1d98120
--- /dev/null
@@ -0,0 +1,59 @@
+# //******************************************************************
+# //
+# // Copyright 2015 Samsung Electronics 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.
+# //
+# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# SConscript file for Local PKI google tests
+
+Import('env')
+
+import os
+import os.path
+tools_env = env.Clone()
+
+src_dir = tools_env.get('SRC_DIR')
+
+######################################################################
+# Build flags
+######################################################################
+tools_env.PrependUnique(CPPPATH = [
+        '../include/',
+        '../../../../../../extlibs/asn1cert',
+        '../../../../../../extlibs/tinydtls/ecc',
+         '../../../../../../extlibs/tinydtls/sha2',
+         '../../../../connectivity/inc/pkix/'
+               ])
+tools_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+
+tools_env.AppendUnique(LIBS = ['CKManager'])
+tools_env.AppendUnique(LIBS = ['asn1'])
+tools_env.AppendUnique(LIBS = ['octbstack'])
+tools_env.AppendUnique(LIBS = ['tinydtls'])
+tools_env.AppendUnique(LIBS = ['connectivity_abstraction'])
+
+if not env.get('RELEASE'):
+       tools_env.AppendUnique(CPPDEFINES = ['X509_DEBUG'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+x509_check = tools_env.Program('x509_check', ['x509_check.c'])
+x509_issue = tools_env.Program('x509_issue', ['x509_issue.c'])
+
+
+
diff --git a/resource/csdk/security/provisioning/ck_manager/unittest/SConscript b/resource/csdk/security/provisioning/ck_manager/unittest/SConscript
new file mode 100644 (file)
index 0000000..f92fcdf
--- /dev/null
@@ -0,0 +1,100 @@
+# //******************************************************************
+# //
+# // Copyright 2015 Samsung Electronics 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.
+# //
+# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# SConscript file for Local PKI google tests
+
+Import('env')
+
+import os
+import os.path
+pki_test_env = env.Clone()
+
+src_dir = pki_test_env.get('SRC_DIR')
+
+######################################################################
+# Build flags
+######################################################################
+pki_test_env.PrependUnique(CPPPATH = ['../include/',
+                               '../include/internal',
+                               '../../include',
+                               '../../include/internal',
+                               '../../../include',
+                               '../../../include/internal',
+                               '../../../../connectivity/inc',
+                               '../../../../connectivity/api',
+                               '../../../../logger/include',
+                               '../../../../stack/include',
+                               '../../../../../oc_logger/include',
+                               '../../../../../../extlibs/gtest/gtest-1.7.0/include',
+                               '../../../../../../extlibs/asn1cert',
+                               '../../../../../../extlibs/tinydtls',
+                               '../../../../../../extlibs/tinydtls/ecc',
+                               '../../../../../../extlibs/tinydtls/sha2'
+               ])
+pki_test_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+pki_test_env.AppendUnique(LIBS = ['pthread'])
+pki_test_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+pki_test_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
+
+pki_test_env.AppendUnique(LIBS = ['octbstack'])
+pki_test_env.AppendUnique(LIBS = ['CKManager'])
+pki_test_env.AppendUnique(LIBS = ['asn1'])
+pki_test_env.AppendUnique(LIBS = ['gtest'])
+pki_test_env.AppendUnique(LIBS = ['gtest_main'])
+
+if env.get('SECURED') == '1':
+    pki_test_env.AppendUnique(LIBS = ['tinydtls'])
+
+if not env.get('RELEASE'):
+       pki_test_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+unittest = pki_test_env.Program('unittest', ['pki_test.cpp'])
+
+Alias("test", [unittest])
+
+
+
+unittest_src_dir = src_dir + '/resource/csdk/security/provisioning/ck_manager/unittest/test_data/'
+unittest_build_dir = env.get('BUILD_DIR') +'/resource/csdk/security/provisioning/ck_manager/unittest'
+
+pki_test_env.Alias("install",env.Install( unittest_build_dir, [ unittest_src_dir + '01.der',
+                                                               unittest_src_dir + 'cacert.der',
+                                                               unittest_src_dir + 'capub.der',
+                                                               unittest_src_dir + 'cert_chain.dat',
+                                                               unittest_src_dir + 'chain.der',
+                                                               unittest_src_dir + 'CKMInfo.json' ]))
+
+env.AppendTarget('test')
+if env.get('TEST') == '1':
+       target_os = env.get('TARGET_OS')
+       if target_os == 'linux':
+               out_dir = env.get('BUILD_DIR')
+               result_dir = env.get('BUILD_DIR') + '/test_out/'
+               if not os.path.isdir(result_dir):
+                       os.makedirs(result_dir)
+               pki_test_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
+               pki_test_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
+               pki_test_env.AppendENVPath('LD_LIBRARY_PATH', [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
+               ut = pki_test_env.Command ('ut', None, out_dir + '/resource/csdk/security/unittest/unittest')
+AlwaysBuild ('ut')
+
index 46e270e..f81da3e 100644 (file)
@@ -55,6 +55,9 @@ provisioning_env.PrependUnique(LIBS = ['ocpmapi','oc', 'oc_logger', 'ocsrm','m',
 
 if env.get('SECURED') == '1':
     provisioning_env.AppendUnique(LIBS = ['tinydtls'])
+if env.get('DTLS_WITH_X509') == '1':
+       provisioning_env.AppendUnique(LIBS = ['CKManager'])
+       provisioning_env.AppendUnique(LIBS = ['asn1'])
 provisioning_env.ParseConfig('pkg-config --libs glib-2.0');
 
 provisioning_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
index 8a95db0..5fe4ea0 100644 (file)
@@ -58,6 +58,9 @@ sptest_env.PrependUnique(LIBS = [   'ocpmapi',
 
 if env.get('SECURED') == '1':
     sptest_env.AppendUnique(LIBS = ['tinydtls'])
+if env.get('DTLS_WITH_X509') == '1':
+       sptest_env.AppendUnique(LIBS = ['CKManager'])
+       sptest_env.AppendUnique(LIBS = ['asn1'])
 
 if not env.get('RELEASE'):
        sptest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])