aboutsummaryrefslogtreecommitdiffstats
path: root/libparc/parc/security/command-line
diff options
context:
space:
mode:
authorMauro Sardara <msardara+fdio@cisco.com>2018-12-18 11:05:49 +0000
committerGerrit Code Review <gerrit@fd.io>2018-12-18 11:05:49 +0000
commitcada1143501a48effc483e3873596c22849926b5 (patch)
tree93a1da95d69b69328a1e7d3621447797f65137c9 /libparc/parc/security/command-line
parent726949d76a7207694d5a1eee84ef134a8e539115 (diff)
parenta45edf23c2463ac9a4723a24792a6c5c89b1e021 (diff)
Merge "Adding gitreview config file for this branch sub project"
Diffstat (limited to 'libparc/parc/security/command-line')
-rw-r--r--libparc/parc/security/command-line/.gitignore1
-rw-r--r--libparc/parc/security/command-line/CMakeLists.txt8
-rw-r--r--libparc/parc/security/command-line/parc-publickey.c128
-rw-r--r--libparc/parc/security/command-line/parcPublicKey_About.c44
-rwxr-xr-xlibparc/parc/security/command-line/parcPublicKey_About.h54
5 files changed, 235 insertions, 0 deletions
diff --git a/libparc/parc/security/command-line/.gitignore b/libparc/parc/security/command-line/.gitignore
new file mode 100644
index 00000000..988c6e03
--- /dev/null
+++ b/libparc/parc/security/command-line/.gitignore
@@ -0,0 +1 @@
+parc_publickey
diff --git a/libparc/parc/security/command-line/CMakeLists.txt b/libparc/parc/security/command-line/CMakeLists.txt
new file mode 100644
index 00000000..27825978
--- /dev/null
+++ b/libparc/parc/security/command-line/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(PARC_PUBLICKEY_SRC
+ parc-publickey.c
+ parcPublicKey_About.c
+ )
+
+add_executable(parc-publickey ${PARC_PUBLICKEY_SRC})
+target_link_libraries(parc-publickey ${PARC_BIN_LIBRARIES})
+install( TARGETS parc-publickey COMPONENT library RUNTIME DESTINATION bin )
diff --git a/libparc/parc/security/command-line/parc-publickey.c b/libparc/parc/security/command-line/parc-publickey.c
new file mode 100644
index 00000000..56d35935
--- /dev/null
+++ b/libparc/parc/security/command-line/parc-publickey.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 <config.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <LongBow/runtime.h>
+
+#include <parc/algol/parc_ArrayList.h>
+#include <parc/security/parc_Security.h>
+#include <parc/security/parc_Pkcs12KeyStore.h>
+#include <parc/security/parc_PublicKeySigner.h>
+
+void
+parcPublicKey_Create(PARCArrayList *args)
+{
+ unsigned int keyLength = 1024;
+ unsigned int validityDays = 30;
+
+ char *fileName = parcArrayList_Get(args, 2);
+ char *password = parcArrayList_Get(args, 3);
+ char *subjectName = parcArrayList_Get(args, 4);
+ PARCSigningAlgorithm signAlgo = PARCSigningAlgorithm_RSA;
+
+ if (parcArrayList_Size(args) > 5) {
+ keyLength = (unsigned int) strtoul(parcArrayList_Get(args, 5), NULL, 10);
+ }
+
+ if (parcArrayList_Size(args) > 6) {
+ validityDays = (unsigned int) strtoul(parcArrayList_Get(args, 6), NULL, 10);
+ }
+
+ bool result = parcPkcs12KeyStore_CreateFile(fileName, password, subjectName, signAlgo, keyLength, validityDays);
+ if (!result) {
+ printf("Error: %s %s", fileName, strerror(errno));
+ return;
+ }
+ printf("Created %s, key length %d valid for %d days.\n", fileName, keyLength, validityDays);
+}
+
+void
+parcPublicKey_Validate(PARCArrayList *args)
+{
+ char *fileName = parcArrayList_Get(args, 2);
+ char *password = parcArrayList_Get(args, 3);
+
+ PARCPkcs12KeyStore *keyStore = parcPkcs12KeyStore_Open(fileName, password, PARCCryptoHashType_SHA256);
+ PARCKeyStore *publicKeyStore = parcKeyStore_Create(keyStore, PARCPkcs12KeyStoreAsKeyStore);
+
+ PARCPublicKeySigner *signer = parcPublicKeySigner_Create(publicKeyStore, PARCCryptoSuite_RSA_SHA256);
+ PARCSigner *pkSigner = parcSigner_Create(signer, PARCPublicKeySignerAsSigner);
+
+ parcKeyStore_Release(&publicKeyStore);
+ parcPkcs12KeyStore_Release(&keyStore);
+
+ if (pkSigner == NULL) {
+ printf("Invalid %s\n", fileName);
+ return;
+ }
+ printf("Valid %s\n", fileName);
+}
+
+void
+printUsage(char *progName)
+{
+ printf("usage: %s [-h | --help] [[-c | --create] fileName password subjectName [keyLength validityDays] | [-v | --validate] fileName password]\n", progName);
+ printf("\n");
+ printf("\n");
+ printf("Create and validate PKCS12 keystores that are used with the CCNx code.\n");
+ printf("\n");
+ printf("optional arguments:\n");
+ printf("\t-h, --help\tShow this help message and exit\n");
+ printf("\t-c, --create\tCreate a PKCS12 keystore with the given filename, password, subject name, and optional key length and validity length (in days)\n");
+ printf("\n");
+ printf("\t\t\texample: ./parc_publickey -c keyfile.pkcs12 <password> <subject name> 1024 365\n");
+ printf("\n");
+ printf("\t-v, --validate\tValidate a PKCS12 file with the given password\n");
+ printf("\n");
+ printf("\t\t\texample: ./parc_publickey -v keyfile.pkcs12 <password>");
+ printf("\n");
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *programName = "parc_publickey";
+ if (argc < 2) {
+ printUsage(programName);
+ exit(1);
+ }
+
+ PARCArrayList *args = parcArrayList_Create(NULL);
+ parcArrayList_AddAll(args, (void **) argv, argc);
+
+ parcSecurity_Init();
+
+ char *arg = parcArrayList_Get(args, 1);
+ if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
+ printUsage(programName);
+ return 0;
+ } else if (strcmp(arg, "-c") == 0 || strcmp(arg, "--create") == 0) {
+ parcPublicKey_Create(args);
+ } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--validate") == 0) {
+ parcPublicKey_Validate(args);
+ } else {
+ printUsage(programName);
+ exit(1);
+ }
+
+ parcSecurity_Fini();
+ return 0;
+}
diff --git a/libparc/parc/security/command-line/parcPublicKey_About.c b/libparc/parc/security/command-line/parcPublicKey_About.c
new file mode 100644
index 00000000..6a242cf4
--- /dev/null
+++ b/libparc/parc/security/command-line/parcPublicKey_About.c
@@ -0,0 +1,44 @@
+// DO NOT EDIT THIS FILE. IT IS AUTOMATICALLY GENERATED.
+// longbow-generate-about 1.0.20170206.46e2c73a 2017-02-06T08:50:09Z
+
+#include "parcPublicKey_About.h"
+
+const char *parcPublicKey_What = "@(#)" "PARC public key " RELEASE_VERSION " 2017-02-15T13:31:10.603139"
+ "@(#)" "\tCopyright (c) 2017 Cisco and/or its affiliates.";
+
+const char *
+parcPublicKeyAbout_Name(void)
+{
+ return "PARC public key";
+}
+
+const char *
+parcPublicKeyAbout_Version(void)
+{
+ return RELEASE_VERSION;
+}
+
+const char *
+parcPublicKeyAbout_About(void)
+{
+ return "PARC public key "RELEASE_VERSION " 2017-02-15T13:31:10.603139" "\nCopyright (c) 2017 Cisco and/or its affiliates.\n";
+}
+
+const char *
+parcPublicKeyAbout_MiniNotice(void)
+{
+ return "Copyright (c) 2017 Cisco and/or its affiliates.\n";
+}
+
+const char *
+parcPublicKeyAbout_ShortNotice(void)
+{
+ return "Copyright (c) 2017 Cisco and/or its affiliates.\n";
+}
+
+const char *
+parcPublicKeyAbout_LongNotice(void)
+{
+ return "Copyright (c) 2017 Cisco and/or its affiliates.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at:\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n";
+}
+
diff --git a/libparc/parc/security/command-line/parcPublicKey_About.h b/libparc/parc/security/command-line/parcPublicKey_About.h
new file mode 100755
index 00000000..64670ad8
--- /dev/null
+++ b/libparc/parc/security/command-line/parcPublicKey_About.h
@@ -0,0 +1,54 @@
+// DO NOT EDIT THIS FILE. IT IS AUTOMATICALLY GENERATED.
+// longbow-generate-about 1.0.20170206.46e2c73a 2017-02-06T08:50:09Z
+
+#ifndef parcPublicKey_About_h
+#define parcPublicKey_About_h
+/**
+ * Embedded string containing information for the what(1) command.
+ *
+ */
+extern const char *parcPublicKey_What;
+
+/**
+ * Return the name as a C string.
+ *
+ * @return The name as a C string.
+ */
+const char *parcPublicKeyAbout_Name(void);
+
+/**
+ * Return the version as a C string.
+ *
+ * @return The version as a C string.
+ */
+const char *parcPublicKeyAbout_Version(void);
+
+/**
+ * Return the About text as a C string.
+ *
+ * @return The About text as a C string.
+ */
+const char *parcPublicKeyAbout_About(void);
+
+/**
+ * Return the minimum copyright notice as a C string.
+ *
+ * @return The minimum copyright notice as a C string.
+ */
+const char *parcPublicKeyAbout_MiniNotice(void);
+
+/**
+ * Return the short copyright notice as a C string.
+ *
+ * @return The short copyright notice as a C string.
+ */
+const char *parcPublicKeyAbout_ShortNotice(void);
+
+/**
+ * Return the long copyright notice as a C string.
+ *
+ * @return The long copyright notice as a C string.
+ */
+const char *parcPublicKeyAbout_LongNotice(void);
+
+#endif // parcPublicKey_About_h