Skip to content

Commit a52e8d8

Browse files
committed
Update branch with current state
1 parent 2f9bfe8 commit a52e8d8

12 files changed

+272
-782
lines changed

Diff for: app/Makefile.am

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ bin_PROGRAMS = amvp_app
88

99
amvp_app_includedir=$(includedir)/amvp
1010
amvp_app_SOURCES = ${tmp_sources}
11-
amvp_app_CFLAGS = -g -fPIE $(LIBAMVP_CFLAGS) $(SSL_CFLAGS) $(FOM_CFLAGS) $(SAFEC_CFLAGS) $(COND_ALG_CFLAGS)
12-
amvp_app_LDFLAGS = $(LIBAMVP_LDFLAGS) $(SSL_LDFLAGS) $(FOM_LDFLAGS)
11+
amvp_app_CFLAGS = -g -fPIE $(LIBAMVP_CFLAGS) $(SSL_CFLAGS) $(SAFEC_CFLAGS) $(COND_ALG_CFLAGS)
12+
amvp_app_LDFLAGS = $(LIBAMVP_LDFLAGS) $(SSL_LDFLAGS)
1313
amvp_app_LDADD = $(ADDL_LIB_DEPENDENCIES)
1414

1515
if FORCE_STATIC
@@ -20,7 +20,3 @@ if ! BUILDING_OFFLINE
2020
amvp_app_LDFLAGS += $(LIBCURL_LDFLAGS)
2121
amvp_app_CFLAGS += $(LIBCURL_CFLAGS)
2222
endif
23-
24-
if USE_FOM_OBJ
25-
amvp_app_LDADD += $(FOM_OBJ_DIR)/fipscanister.o
26-
endif

Diff for: app/app_cli.c

+49-149
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include "amvp/amvp.h"
1515
#include "safe_lib.h"
1616

17-
#include <openssl/crypto.h>
18-
#include <openssl/evp.h>
19-
2017
#define AMVP_APP_HELP_MSG "Use amvp_app --help for more information."
2118

2219
static void print_usage(int code) {
@@ -159,7 +156,7 @@ static void print_usage(int code) {
159156
printf("To get info about a created module from the AMVP server:\n");
160157
printf(" --get_module <module_info_file>\n");
161158
printf("To request module certificate using a predefined request file:\n");
162-
printf(" --module_cert_req <request_file>\n");
159+
printf(" --module_cert_req --with_module <module_id_number> --with_vendor <vendor_id_number> --with-contact <CMVP contact ID> ...\n");
163160
printf("\n");
164161
printf("To post all resources a predefined resource json file:\n");
165162
printf(" --post_resources <resource_file>\n");
@@ -194,27 +191,6 @@ static void print_usage(int code) {
194191

195192
static void print_version_info(void) {
196193
printf("\nAMVP library version(protocol version): %s(%s)\n\n", amvp_version(), amvp_protocol_version());
197-
printf(" Runtime mode: yes\n");
198-
#if OPENSSL_VERSION_NUMBER < 0x30000000L
199-
if (FIPS_mode()) {
200-
printf(" FIPS mode: yes\n");
201-
} else {
202-
printf(" FIPS mode: no\n");
203-
}
204-
#else
205-
if (EVP_default_properties_is_fips_enabled(NULL)) {
206-
printf(" FIPS by default: yes\n");
207-
} else {
208-
printf(" FIPS by default: no\n");
209-
}
210-
#endif
211-
212-
#ifdef OPENSSL_VERSION_TEXT
213-
printf("Compiled SSL version: %s\n", OPENSSL_VERSION_TEXT);
214-
#else
215-
printf("Compiled SSL version: not detected\n");
216-
#endif
217-
printf(" Linked SSL version: %s\n", OpenSSL_version(OPENSSL_VERSION));
218194
}
219195

220196
static ko_longopt_t longopts[] = {
@@ -227,24 +203,6 @@ static ko_longopt_t longopts[] = {
227203
{ "verbose", ko_no_argument, 307 },
228204
{ "none", ko_no_argument, 308 },
229205
{ "sample", ko_no_argument, 309 },
230-
{ "aes", ko_no_argument, 310 },
231-
{ "tdes", ko_no_argument, 311 },
232-
{ "hash", ko_no_argument, 312 },
233-
{ "cmac", ko_no_argument, 313 },
234-
{ "hmac", ko_no_argument, 314 },
235-
{ "kdf", ko_no_argument, 315 },
236-
{ "dsa", ko_no_argument, 316 },
237-
{ "rsa", ko_no_argument, 317 },
238-
{ "drbg", ko_no_argument, 318 },
239-
{ "ecdsa", ko_no_argument, 319 },
240-
{ "kas_ecc", ko_no_argument, 320 },
241-
{ "kas_ffc", ko_no_argument, 321 },
242-
{ "safe_primes", ko_no_argument, 322 },
243-
{ "kas_ifc", ko_no_argument, 323 },
244-
{ "kts_ifc", ko_no_argument, 324 },
245-
{ "kda", ko_no_argument, 325 },
246-
{ "kmac", ko_no_argument, 326 },
247-
{ "all_algs", ko_no_argument, 350 },
248206
{ "manual_registration", ko_required_argument, 400 },
249207
{ "kat", ko_required_argument, 401 },
250208
{ "fips_validation", ko_required_argument, 402 },
@@ -264,13 +222,13 @@ static ko_longopt_t longopts[] = {
264222
{ "cost", ko_no_argument, 416 },
265223
{ "debug", ko_no_argument, 417 },
266224
{ "get_registration", ko_no_argument, 418 },
267-
{ "module_cert_req", ko_required_argument, 419 },
225+
{ "module_cert_req", ko_no_argument, 419 },
268226
{ "post_resources", ko_required_argument, 420 },
269227
{ "create_module", ko_required_argument, 421 },
270228
{ "get_module", ko_required_argument, 422 },
271-
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
272-
{ "disable_fips", ko_no_argument, 500 },
273-
#endif
229+
{ "with_module", ko_required_argument, 423 },
230+
{ "with_vendor", ko_required_argument, 424} ,
231+
{ "with_contact", ko_required_argument, 425 } ,
274232
{ NULL, 0, 0 }
275233
};
276234

@@ -279,26 +237,6 @@ static void default_config(APP_CONFIG *cfg) {
279237
cfg->level = AMVP_LOG_LVL_STATUS;
280238
}
281239

282-
static void enable_all_algorithms(APP_CONFIG *cfg) {
283-
cfg->aes = 1;
284-
cfg->tdes = 1;
285-
cfg->hash = 1;
286-
cfg->cmac = 1;
287-
cfg->hmac = 1;
288-
cfg->kmac = 1;
289-
cfg->dsa = 1;
290-
cfg->kas_ffc = 1;
291-
cfg->safe_primes = 1;
292-
cfg->rsa = 1;
293-
cfg->drbg = 1;
294-
cfg->ecdsa = 1;
295-
cfg->kas_ecc = 1;
296-
cfg->kas_ifc = 1;
297-
cfg->kda = 1;
298-
cfg->kts_ifc = 1;
299-
cfg->kdf = 1;
300-
}
301-
302240
static const char* lookup_arg_name(int c) {
303241
int i = 0;
304242
int arrlen = sizeof(longopts) / sizeof(ko_longopt_t);
@@ -325,7 +263,7 @@ static int check_option_length(const char *opt, int c, int maxAllowed) {
325263

326264
int ingest_cli(APP_CONFIG *cfg, int argc, char **argv) {
327265
ketopt_t opt = KETOPT_INIT;
328-
int c = 0, diff = 0, len = 0;
266+
int c = 0, diff = 0, tmp = 0;
329267

330268
cfg->empty_alg = 1;
331269

@@ -343,12 +281,12 @@ int ingest_cli(APP_CONFIG *cfg, int argc, char **argv) {
343281
case 'h':
344282
case 302:
345283
if (opt.arg) {
346-
len = strnlen_s(opt.arg, JSON_FILENAME_LENGTH + 1);
347-
if (len > JSON_FILENAME_LENGTH || len <= 0) {
284+
tmp = strnlen_s(opt.arg, JSON_FILENAME_LENGTH + 1);
285+
if (tmp > JSON_FILENAME_LENGTH || tmp <= 0) {
348286
printf("invalid help option length\n");
349287
return 1;
350288
}
351-
strncmp_s(opt.arg, len, "--verbose", 9, &diff);
289+
strncmp_s(opt.arg, tmp, "--verbose", 9, &diff);
352290
if (!diff) {
353291
print_usage(AMVP_LOG_LVL_VERBOSE);
354292
} else {
@@ -379,80 +317,6 @@ int ingest_cli(APP_CONFIG *cfg, int argc, char **argv) {
379317
case 309:
380318
cfg->sample = 1;
381319
break;
382-
case 310:
383-
cfg->aes = 1;
384-
cfg->empty_alg = 0;
385-
break;
386-
case 311:
387-
cfg->tdes = 1;
388-
cfg->empty_alg = 0;
389-
break;
390-
case 312:
391-
cfg->hash = 1;
392-
cfg->empty_alg = 0;
393-
break;
394-
case 313:
395-
cfg->cmac = 1;
396-
cfg->empty_alg = 0;
397-
break;
398-
case 314:
399-
cfg->hmac = 1;
400-
cfg->empty_alg = 0;
401-
break;
402-
case 315:
403-
cfg->kdf = 1;
404-
cfg->empty_alg = 0;
405-
break;
406-
case 316:
407-
cfg->dsa = 1;
408-
cfg->empty_alg = 0;
409-
break;
410-
case 317:
411-
cfg->rsa = 1;
412-
cfg->empty_alg = 0;
413-
break;
414-
case 318:
415-
cfg->drbg = 1;
416-
cfg->empty_alg = 0;
417-
break;
418-
case 319:
419-
cfg->ecdsa = 1;
420-
cfg->empty_alg = 0;
421-
break;
422-
case 320:
423-
cfg->kas_ecc = 1;
424-
cfg->empty_alg = 0;
425-
break;
426-
case 321:
427-
cfg->kas_ffc = 1;
428-
cfg->empty_alg = 0;
429-
break;
430-
case 322:
431-
cfg->safe_primes = 1;
432-
cfg->empty_alg = 0;
433-
break;
434-
case 323:
435-
cfg->kas_ifc = 1;
436-
cfg->empty_alg = 0;
437-
break;
438-
case 324:
439-
cfg->kts_ifc = 1;
440-
cfg->empty_alg = 0;
441-
break;
442-
case 325:
443-
cfg->kda = 1;
444-
cfg->empty_alg = 0;
445-
break;
446-
case 326:
447-
cfg->kmac = 1;
448-
cfg->empty_alg = 0;
449-
break;
450-
case 'a':
451-
case 350:
452-
enable_all_algorithms(cfg);
453-
cfg->empty_alg = 0;
454-
cfg->testall = 1;
455-
break;
456320

457321
case 400:
458322
cfg->manual_reg = 1;
@@ -600,10 +464,6 @@ int ingest_cli(APP_CONFIG *cfg, int argc, char **argv) {
600464

601465
case 419:
602466
cfg->mod_cert_req = 1;
603-
if (!check_option_length(opt.arg, c, JSON_FILENAME_LENGTH)) {
604-
return 1;
605-
}
606-
strcpy_s(cfg->mod_cert_req_file, JSON_FILENAME_LENGTH + 1, opt.arg);
607467
break;
608468

609469
case 420:
@@ -630,6 +490,37 @@ int ingest_cli(APP_CONFIG *cfg, int argc, char **argv) {
630490
strcpy_s(cfg->get_module_file, JSON_FILENAME_LENGTH + 1, opt.arg);
631491
break;
632492

493+
case 423:
494+
tmp = atoi(opt.arg);
495+
if (!tmp) {
496+
printf("Invalid module ID format\n");
497+
return 1;
498+
}
499+
printf("Module ID: %d\n", tmp);
500+
cfg->module_id = tmp;
501+
break;
502+
503+
case 424:
504+
tmp = atoi(opt.arg);
505+
if (!tmp) {
506+
printf("Invalid vendor ID format\n");
507+
return 1;
508+
}
509+
cfg->vendor_id = tmp;
510+
break;
511+
512+
case 425:
513+
if (cfg->num_contacts >= AMVP_MAX_CONTACTS_PER_CERT_REQ) {
514+
printf("Too many contacts provided for cert req\n");
515+
return 1;
516+
}
517+
if (!check_option_length(opt.arg, c, AMVP_CONTACT_STR_MAX_LEN)) {
518+
return 1;
519+
}
520+
strcpy_s(cfg->contact_ids[cfg->num_contacts], AMVP_CONTACT_STR_MAX_LEN + 1, opt.arg);
521+
cfg->num_contacts++;
522+
break;
523+
633524
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
634525
case 500:
635526
cfg->disable_fips = 1;
@@ -671,6 +562,15 @@ int ingest_cli(APP_CONFIG *cfg, int argc, char **argv) {
671562
return 1;
672563
}
673564

565+
if (cfg->mod_cert_req && (!cfg->module_id || !cfg->vendor_id || !cfg->num_contacts)) {
566+
printf("Module cert request requires module module ID, vendor ID, and at least one contact ID to be provided\n");
567+
return 1;
568+
}
569+
570+
if (!cfg->mod_cert_req && (cfg->module_id || cfg->vendor_id || cfg->num_contacts)) {
571+
printf("Warning: Module ID/Vendor ID/Contact ID provided, but not performing a cert request. These options will be ignored\n");
572+
}
573+
674574
printf("\n");
675575

676576
return 0;

Diff for: app/app_lcl.h

+4-20
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,15 @@ typedef struct app_config {
7272
char create_module_file[JSON_FILENAME_LENGTH + 1];
7373
char get_module_file[JSON_FILENAME_LENGTH + 1];
7474
char post_resources_filename[JSON_FILENAME_LENGTH + 1];
75+
char contact_ids[AMVP_MAX_CONTACTS_PER_CERT_REQ][AMVP_CONTACT_STR_MAX_LEN + 1];
7576

76-
/*
77-
* Algorithm Flags
78-
* 0 is off, 1 is on
79-
*/
80-
int aes; int tdes;
81-
int hash; int cmac; int hmac; int kmac;
82-
int dsa; int rsa;
83-
int drbg; int ecdsa;
84-
int kas_ecc; int kas_ffc; int kas_ifc; int kda; int kts_ifc;
85-
int kdf;
86-
int safe_primes;
77+
int num_contacts;
8778
int mod_cert_req;
8879
int post_resources;
8980
int create_module;
9081
int get_module;
82+
int module_id;
83+
int vendor_id;
9184
int testall; /* So the app can check whether the user indicated to test all possible algorithms */
9285
} APP_CONFIG;
9386

@@ -98,15 +91,6 @@ unsigned int swap_uint_endian(unsigned int i);
9891
int check_is_little_endian(void);
9992
char *remove_str_const(const char *str);
10093
int save_string_to_file(const char *str, const char *path);
101-
int get_nid_for_curve(AMVP_EC_CURVE curve);
102-
const EVP_MD *get_md_for_hash_alg(AMVP_HASH_ALG alg);
103-
const char *get_md_string_for_hash_alg(AMVP_HASH_ALG alg, int *md_size);
104-
char *ec_point_to_pub_key(unsigned char *x, int x_len, unsigned char *y, int y_len, int *key_len);
105-
106-
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
107-
AMVP_RESULT fips_sanity_check(void);
108-
const char *get_string_from_oid(unsigned char *oid, int oid_len);
109-
#endif
11094

11195
#ifdef __cplusplus
11296
}

Diff for: app/app_main.c

+5-14
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,9 @@
1515
* It will default to 127.0.0.1 port 443 if no arguments are given.
1616
*/
1717
#include <stdio.h>
18-
#include <openssl/rsa.h>
19-
#include <openssl/bn.h>
2018

2119
#include "app_lcl.h"
2220

23-
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
24-
#include <openssl/provider.h>
25-
#include <openssl/evp.h>
26-
#ifdef _WIN32
27-
#include <Windows.h>
28-
#else
29-
#include <unistd.h>
30-
#endif
31-
#endif
32-
3321
#include "safe_mem_lib.h"
3422
#include "safe_str_lib.h"
3523

@@ -182,6 +170,7 @@ int main(int argc, char **argv) {
182170
* This may or may not be turned on...
183171
*/
184172
if (app_setup_two_factor_auth(ctx)) {
173+
printf("Error setting up two factor auth\n");
185174
goto end;
186175
}
187176

@@ -264,7 +253,6 @@ int main(int argc, char **argv) {
264253
if (reg) free(reg);
265254
goto end;
266255
}
267-
268256
if (cfg.kat) {
269257
rv = amvp_load_kat_filename(ctx, cfg.kat_file);
270258
goto end;
@@ -350,7 +338,10 @@ int main(int argc, char **argv) {
350338
}
351339

352340
if (cfg.mod_cert_req) {
353-
rv = amvp_mark_as_cert_req(ctx, cfg.mod_cert_req_file);
341+
rv = amvp_mark_as_cert_req(ctx, cfg.module_id, cfg.vendor_id);
342+
for (diff = 0; diff < cfg.num_contacts; diff++) {
343+
amvp_cert_req_add_contact(ctx, cfg.contact_ids[diff]);
344+
}
354345
}
355346

356347
if (cfg.create_module) {

0 commit comments

Comments
 (0)