Add ASN.1 for PKIX
authorDmytro Zhuravlev <d.zhuravlev@samsung.com>
Thu, 30 Jul 2015 15:24:42 +0000 (18:24 +0300)
committerSachin Agrawal <sachin.agrawal@intel.com>
Tue, 1 Sep 2015 17:01:26 +0000 (17:01 +0000)
External library used for generating X.509 certificate,
certificate revocation list (CRL) and certificate signing request (CSR)

Change-Id: Id273b26fc6ea1901dfc564a7cad9ec0b0abe8ef1
Signed-off-by: Dmytro Zhuravlev <d.zhuravlev@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2005
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
extlibs/asn1cert/SConscript [new file with mode: 0644]
extlibs/asn1cert/certificate.asn [new file with mode: 0644]
extlibs/asn1cert/crl.asn [new file with mode: 0644]
extlibs/asn1cert/csr.asn [new file with mode: 0644]

diff --git a/extlibs/asn1cert/SConscript b/extlibs/asn1cert/SConscript
new file mode 100644 (file)
index 0000000..c2ccdc9
--- /dev/null
@@ -0,0 +1,53 @@
+##
+# Script to generate ASN.1 source code.
+# If asn1 compiler is not installed get it and install it.
+#
+##
+
+import os
+
+Import('env')
+
+asn1_env = env.Clone()
+
+target_os = asn1_env.get('TARGET_OS')
+src_dir = asn1_env.get('SRC_DIR')
+
+targets_need_asn1 = ['linux']
+asn1c_dir      = src_dir + '/extlibs/asn1cert/asn1c-0.9.27'
+asn1c_gz_file = src_dir + '/extlibs/asn1cert/asn1c-0.9.27.tar.gz'
+asn1c_url      = 'http://lionet.info/soft/asn1c-0.9.27.tar.gz'
+asn1c_file = src_dir + '/extlibs/asn1cert/asn1c-0.9.27/asn1c/asn1c'
+
+if target_os in targets_need_asn1:
+       print '*** Checking for installation of asn1c-0.9.27 ***'
+
+       if not os.path.exists(asn1c_dir):
+               # If the asn1 gz file is not already present, download it
+               if not os.path.exists(asn1c_gz_file):
+                       asn1c_gz = asn1_env.Download(asn1c_gz_file, asn1c_url)
+               else:
+                       asn1c_gz = asn1c_gz_file
+
+               # Ungz asn1c
+               print 'Unzipping asn1 compiler'
+               asn1_env.UnpackAll(asn1c_dir, asn1c_gz)
+       if os.path.exists(asn1c_dir):
+               if not os.path.exists(asn1c_file):
+                       # Run configure on asn1
+                       print 'Configuring asn1 compiler'
+                       if asn1_env.get('CROSS_COMPILE'):
+                               asn1_env.Configure(asn1c_dir, './configure --host=' + asn1_env['CROSS_COMPILE'])
+                       else:
+                               asn1_env.Configure(asn1c_dir, './configure')
+
+                       # Run make on asn1
+                       print 'Making asn1 compiler'
+                       asn1_env.Configure(asn1c_dir, 'make')
+       print 'Generating Source Code:'
+       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')
+
+
+
diff --git a/extlibs/asn1cert/certificate.asn b/extlibs/asn1cert/certificate.asn
new file mode 100644 (file)
index 0000000..c5053a9
--- /dev/null
@@ -0,0 +1,61 @@
+CERTIFICATE DEFINITIONS ::= BEGIN\r
+\r
+Certificate ::= SEQUENCE {\r
+        tbsCertificate      TBSCertificate,\r
+        signatureAlgorithm  AlgorithmIdentifier,\r
+        signatureValue      BIT STRING\r
+}\r
+\r
+AlgorithmIdentifier ::= SEQUENCE {\r
+        algorithm       OBJECT IDENTIFIER,\r
+        id-ecPublicKey         OBJECT IDENTIFIER OPTIONAL,\r
+        nul                            NULL OPTIONAL\r
+}\r
+\r
+TBSCertificate ::= SEQUENCE {\r
+        version         [0]    EXPLICIT Version DEFAULT v1,\r
+        serialNumber           CertificateSerialNumber,\r
+        signature              AlgorithmIdentifier,\r
+        issuer                 Name,\r
+        validity               Validity,\r
+        subject                Name,\r
+        subjectPublicKeyInfo   SubjectPublicKeyInfo\r
+}\r
+\r
+Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }\r
+\r
+CertificateSerialNumber ::= INTEGER\r
+\r
+Name ::= RDNSequence\r
+\r
+RDNSequence ::= SEQUENCE OF RelativeDistinguishedName\r
+\r
+RelativeDistinguishedName ::= SET OF AttributeTypeAndValue\r
+\r
+AttributeTypeAndValue ::= SEQUENCE {\r
+     type     AttributeType,\r
+     value    AttributeValue}\r
+\r
+AttributeType ::= OBJECT IDENTIFIER\r
+\r
+AttributeValue ::= UTF8String\r
+\r
+Validity ::= SEQUENCE {\r
+        notBefore   Time,\r
+        notAfter    Time\r
+}\r
+\r
+Time ::= UTCTime\r
+\r
+SubjectPublicKeyInfo ::= SEQUENCE {\r
+        algorithm           AlgorithmIdentifier,\r
+        subjectPublicKey    BIT STRING\r
+}\r
+\r
+ECDSA-Sig-Value ::= SEQUENCE {\r
+          r  INTEGER,\r
+          s  INTEGER\r
+}\r
+\r
+END\r
+
diff --git a/extlibs/asn1cert/crl.asn b/extlibs/asn1cert/crl.asn
new file mode 100644 (file)
index 0000000..c73cb64
--- /dev/null
@@ -0,0 +1,45 @@
+CRL DEFINITIONS ::= BEGIN
+
+CertificateRevocationList  ::=  SEQUENCE  {
+    tbsCertList          TBSCertList,
+    signatureAlgorithm   AlgorithmIdentifier,
+    signatureValue       BIT STRING  }
+
+TBSCertList  ::=  SEQUENCE  {
+    signature               AlgorithmIdentifier,
+    issuer                  Name,
+    thisUpdate              Time,
+    revokedCertificates     SEQUENCE OF CertificateRevocationInfo
+                           }
+
+CertificateRevocationInfo ::= SEQUENCE  {
+    userCertificate         CertificateSerialNumber,
+    revocationDate          Time
+          }
+
+AlgorithmIdentifier ::= SEQUENCE {
+    algorithm          OBJECT IDENTIFIER,
+    id-ecPublicKey     OBJECT IDENTIFIER OPTIONAL,
+    nul                        NULL OPTIONAL
+}
+
+CertificateSerialNumber ::= INTEGER
+
+Time ::= UTCTime
+
+Name ::= RDNSequence
+
+RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
+
+RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
+
+AttributeTypeAndValue ::= SEQUENCE {
+     type     AttributeType,
+     value    AttributeValue }
+
+AttributeType ::= OBJECT IDENTIFIER
+
+AttributeValue ::= UTF8String
+
+END
+
diff --git a/extlibs/asn1cert/csr.asn b/extlibs/asn1cert/csr.asn
new file mode 100644 (file)
index 0000000..f51fe2c
--- /dev/null
@@ -0,0 +1,42 @@
+CSR DEFINITIONS ::= BEGIN
+
+-- Certificate requests
+
+CertificationRequest ::= SEQUENCE {
+    certificationRequestInfo CertificationRequestInfo,
+    signatureAlgorithm AlgorithmIdentifier,
+    signature          BIT STRING
+}
+
+CertificationRequestInfo ::= SEQUENCE {
+    version       INTEGER { v1(0) },
+    subject       Name,
+    subjectPKInfo SubjectPublicKeyInfo
+}
+
+SubjectPublicKeyInfo ::= SEQUENCE {
+    algorithm        AlgorithmIdentifier,
+    subjectPublicKey BIT STRING
+}
+
+AlgorithmIdentifier ::= SEQUENCE {
+    algorithm       OBJECT IDENTIFIER,
+    id-ecPublicKey  OBJECT IDENTIFIER OPTIONAL,
+    nul             NULL OPTIONAL
+}
+
+Name ::= RDNSequence
+
+RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
+
+RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
+
+AttributeTypeAndValue ::= SEQUENCE {
+     type     AttributeType,
+     value    AttributeValue }
+
+AttributeType ::= OBJECT IDENTIFIER
+
+AttributeValue ::= UTF8String
+
+END