32#include <seclabel_api.h>
34#include "ms_example.h"
46#define FIRST_SEQ_NUM 2
49int seq_num_val_1 = FIRST_SEQ_NUM;
50int seq_num_val_2 = FIRST_SEQ_NUM + 100;
54int send_ia5_as_att = 0;
60static char *optstr =
"u37m:d:p:w:M:D:P:W:r:o:O:r:g:G:c:l:R:y:C:iaqsAve:x:b:f:Y:S:j:";
63static char *default_recip =
"/CN=P7User1/OU=sales/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
66static char *content_id =
"030924.140212";
67static const char text[] =
"First line\r\nSecond line\r\n";
69int adding_sec_label = 1;
73static void usage(
void) ;
83 struct X400msSession *sp
86static int setup_default_new_sec_env(
87 struct X400msSession *sp,
88 char *identity_filename,
93static int setup_default_old_sec_env(
94 struct X400msSession *sp,
101static int setup_msg_new_sec_env(
102 struct X400msMessage *mp,
103 char *identity_filename,
108static int setup_msg_old_sec_env(
109 struct X400msMessage *mp,
115static int setup_recip_new_sec_env(
116 struct X400Recipient *rp,
117 char *identity_filename,
121static int setup_recip_old_sec_env(
122 struct X400Recipient *rp,
132 struct X400msMessage *mp,
136static int add_content(
137 struct X400msMessage *mp
140static int add_binary_bp(
141 struct X400msMessage *mp
145 struct X400msMessage *mp
148static int add_ia5_str(
149 struct X400msMessage *mp
165 char password[BUFSIZ];
167 if (get_args(argc, argv, optstr)) {
172 printf(
"Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
173 contype = ic_fgetc(x400_contype, stdin);
175 ic_fgetc(x400_contype, stdin);
177 if ( contype <
'0' ||
'2' < contype )
178 contype = x400_contype;
183 def_oraddr = x400_ms_user_addr;
184 def_dn = x400_ms_user_dn;
185 def_pa = x400_ms_presentation_address;
187 def_oraddr = x400_mta_user_addr;
188 def_dn = x400_mta_user_dn;
189 def_pa = x400_mta_presentation_address;
192 printf(
"Your ORAddress [%s] > ", def_oraddr);
193 ic_fgets (orn,
sizeof orn, stdin);
195 if ( orn[strlen(orn)-1] ==
'\n' )
196 orn[strlen(orn)-1] =
'\0';
199 strcpy(orn, def_oraddr);
202 printf (
"Password [%s]: ",
203 contype == 0 ? x400_p7_password : x400_p3_password);
204 if ( ic_fgets (password,
sizeof password, stdin) == NULL )
207 if (password[strlen(password)-1] ==
'\n' )
208 password[strlen(password)-1] =
'\0';
209 if (password[0] ==
'\0')
210 strcpy(password, contype == 0 ? x400_p7_password : x400_p3_password);
213 printf(
"Presentation Address [%s] > ", def_pa);
214 ic_fgets (pa,
sizeof pa, stdin);
216 if ( pa[strlen(pa)-1] ==
'\n' )
217 pa[strlen(pa)-1] =
'\0';
222 printf(
"sending message using session 1\n");
223 if ((status = send_msg(contype, orn, def_dn, pa, password))
225 fprintf (stderr,
"Error in sending message\n");
230 printf(
"sending message using session 2\n");
231 if ((status = send_msg(contype, orn, def_dn, pa, password))
233 fprintf (stderr,
"Error sending message\n");
249 struct X400msSession *sp;
256 status =
X400msOpen (contype, orn, def_dn, password, pa, &nummsg, &sp);
258 fprintf (stderr,
"Error in Open: %s\n",
X400msError (status));
259 fprintf (stderr,
"%s %s %s\n", orn, def_dn, pa);
280 if (use_new_sec_env) {
281 status = setup_default_new_sec_env(sp, identity_filename, passphrase);
283 status = setup_default_old_sec_env(sp, security_id,
284 identity_dn, passphrase);
288 fprintf (stderr,
"Can't setup security environment\n");
292 printf(
"sending message 1\n");
293 status = submit_msg(orn, sp);
295 fprintf (stderr,
"Can't submit\n");
315 fprintf (stderr,
"X400msClose returned error: %s\n",
X400msError (status));
321static int submit_msg(
323 struct X400msSession *sp
326 struct X400msMessage *mp;
328 struct X400Recipient *rp2;
331 static int msg_num = 0;
336 if (x400_default_recipient != NULL) {
337 recip = x400_default_recipient;
338 recip2 = x400_default_recipient;
340 recip = default_recip;
341 recip2 = default_recip;
344 printf(
"Message recipient [%s]: ", recip);
345 ic_fgets (tmp,
sizeof tmp, stdin);
347 if ( tmp[strlen(tmp)-1] ==
'\n' )
348 tmp[strlen(tmp)-1] =
'\0';
349 if (strlen(tmp) != 0) {
351 recip2 = strdup(tmp);
354 printf(
"Subject [%s]: ", subject);
355 ic_fgets (tmp,
sizeof tmp, stdin);
357 if ( tmp[strlen(tmp)-1] ==
'\n' )
358 tmp[strlen(tmp)-1] =
'\0';
359 if (strlen(tmp) != 0)
360 subject = strdup(tmp);
365 fprintf (stderr,
"x400msMsgNew returned error: %s\n",
370#ifdef use_diff_sec_env_second_msg
374 status = setup_msg_sec_env(mp,
"/root",
375 "cn=P7User1,o=Address Book,c=GB",
"secret");
377 fprintf (stderr,
"setup_msg_sec_env returned error: %s\n",
392 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
396 fprintf (stderr,
"encrypting message as S4406 (PCT) \n");
408 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
412 fprintf (stderr,
"Adding MOAC\n");
420 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
426 "CN=originator;c=gb", -1);
428 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
433 if (adding_sec_label) {
434 status = add_sec_label (mp);
436 fprintf (stderr,
"Failed to add Security Label: %s\n",
440 fprintf (stderr,
"added Security Label\n");
446 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
463 printf(
"military message priority is %d (%s) \n",
464 x400_default_priority,
465 get_x400_pty_str_from_4406(x400_default_priority));
467 get_x400_pty_from_4406(x400_default_priority));
471 printf(
"military message priority qualifer is %d ( 0 - low, 1 - high)\n",
472 get_x400_pty_qual_from_4406(x400_default_priority));
474 get_x400_pty_qual_from_4406(x400_default_priority));
481 char tmp_buffer[255];
483 snprintf(tmp_buffer, 244,
"%s '%s' '%.19s'",
484 subject, get_x400_pty_str_from_4406(x400_default_priority), ctime(&t));
485 printf(
"Subject is '%s'\n", tmp_buffer);
488 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
498 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
503 fprintf (stderr,
"add_recip() returned error: %s\n",
519 fprintf (stderr,
"add_content() returned error: %s\n",
526 fprintf (stderr,
"x400msMsgSend returned error: %s\n",
530 printf(
"Message submitted successfully\n");
535 fprintf (stderr,
"x400msMsgDelete returned error: %s\n",
546 struct X400msMessage *mp,
551 struct X400Recipient *rp;
556 fprintf (stderr,
"x400msRecipNew returned error: %s\n",
564 fprintf (stderr,
"x400msRecipAddIntParam returned error: %s\n",
572 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
578 "CN=recipient;c=gb", -1);
580 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
588 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
596 fprintf (stderr,
"X400msRecipAddIntParam returned error: %s\n",
602 fprintf (stderr,
"requesting token\n");
605 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
615 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
619 fprintf (stderr,
"Added sequence number %d for token\n", seq_num_val_1);
630 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
638 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
646static int setup_default_new_sec_env(
647 struct X400msSession *sp,
654 fprintf (stderr,
"using new_sec_nv %s\n", idf);
661 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
669 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
677 fprintf (stderr,
"X400msTestSecurityEnv returned error: %s\n",
686static int setup_default_old_sec_env(
687 struct X400msSession *sp,
695 fprintf (stderr,
"using old_sec_nv\n");
705 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
713 fprintf (stderr,
"X400msSetStrDefault returned error: %s\n",
721static int setup_msg_new_sec_env(
722 struct X400msMessage *mp,
723 char *identity_filename,
733 identity_filename, -1);
735 fprintf (stderr,
"X400msMsgAddStrParam returned error: %s\n",
740 printf(
"setting up new message security env %s\n", identity_filename);
745 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
752static int setup_msg_old_sec_env(
753 struct X400msMessage *mp,
761 printf(
"setting up message security env %s\n",
id);
768 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
776 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
781 printf(
"setting up new message security env %s\n", identity_filename);
786 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
793static int setup_recip_new_sec_env(
794 struct X400Recipient *rp,
795 char *identity_filename,
801 printf(
"setting up recipient security env %s\n", identity_filename);
807 identity_filename, -1);
809 fprintf (stderr,
"X400msRecipAddStrParam returned error: %s\n",
817 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
826static int setup_recip_old_sec_env(
827 struct X400Recipient *rp,
835 printf(
"setting up recipient security env %s\n",
id);
842 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
849 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
857 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
866static int add_content(
867 struct X400msMessage *mp
892 fprintf (stderr,
"x400ms returned error: %s\n",
X400msError (status));
895 printf(
"Sent 8859 attachment as string:\n%s\n", text);
897 if (send_ia5_as_att) {
902 printf(
"failed to add X400_T_IA5TEXT attachment\n");
905 printf(
"Sent IA5 as first attachment:\n%s\n", text);
908 if (num_of_ia5_bytes == 0) {
911 printf(
"failed to add X400_T_IA5TEXT BP\n");
914 printf(
"Sent IA5 as string in message \n%s\n", text);
916 status = add_ia5_str(mp);
918 printf(
"failed to add IA5 str\n");
927 printf(
"failed to add X400_T_ISO8859_1, attachment\n");
930 printf(
"Sent 8859-1 as attachment:\n%s\n", text);
933 status = add_binary_bp(mp);
935 printf(
"failed to add X400_T_BINARY BP\n");
940 status = add_ftbp(mp);
942 printf(
"failed to add X400_T_BINARY BP\n");
948 if (filename_to_send != NULL) {
949 binary_data = (
char *) malloc(100000);
950 if ( binary_data == NULL )
952 fp = fopen(filename_to_send,
"r");
953 if (fp == (FILE *)NULL) {
954 printf(
"Cannot open binary file\n");
957 if ((fs = fread (binary_data,
sizeof(
char), 100000/
sizeof(
char), fp))
959 printf(
"Cannot read from binary file\n");
966 printf(
"failed to add X400_T_BINARY BP\n");
972 printf(
"failed to add X400_T_IA5TEXT BP\n");
975 printf(
"Sent IA5 as string in message \n%s\n", text);
980 printf(
"no binary file set - not sending X400_T_BINARY\n");
986static int add_ia5_str(
987 struct X400msMessage *mp
993 char *sample_ia5 = {
"Here is some sample text to put into the IA5 attachment."};
995 if ((tmp = malloc(num_of_ia5_bytes + 1)) == NULL) {
996 printf(
"failed to malloc %d bytes\n", num_of_ia5_bytes);
1000 for (i = strlen(text) ; i < num_of_ia5_bytes ; i++)
1001 tmp[i] = sample_ia5[i%strlen(sample_ia5)];
1006 printf(
"failed to add X400_T_IA5TEXT BP\n");
1009 printf(
"Sent %d bytes IA5 as string in message \n%s\n", i, tmp);
1014static int add_binary_bp(
1015 struct X400msMessage *mp
1024 if (filename_to_send != NULL) {
1025 fp = fopen(filename_to_send,
"rb");
1026 if (fp == (FILE *)NULL) {
1027 printf(
"Cannot open binary file\n");
1030 binary_data = (
char *) malloc(bin_bp_size);
1031 if ( binary_data == NULL )
1033 if ((fs = fread (binary_data,
sizeof(
char),
1034 bin_bp_size/
sizeof(
char), fp) ) == -1) {
1035 printf(
"Cannot read from binary file\n");
1041 if (fs < bin_bp_size) {
1042 printf(
"Cannot read %d bytes from binary file (got %d)\n",
1051 printf(
"failed to add X400_T_BINARY BP\n");
1054 printf(
"Sent %d bytes as X400_T_BINARY BP\n", fs);
1056 printf(
"no binary file set - not sending X400_T_BINARY\n");
1063 struct X400msMessage *mp
1070 struct X400Bodypart *bp;
1073 if (filename_to_send != NULL) {
1074 fp = fopen(filename_to_send,
"rb");
1075 if (fp == (FILE *)NULL) {
1076 printf(
"Cannot open binary file\n");
1079 binary_data = (
char *) malloc(bin_bp_size);
1080 if ( binary_data == NULL )
1082 if ((fs = fread (binary_data,
sizeof(
char),
1083 bin_bp_size/
sizeof(
char), fp) ) == -1) {
1084 printf(
"Cannot read from binary file\n");
1090 if (fs < bin_bp_size) {
1091 printf(
"Cannot read %d bytes from binary file (got %d)\n",
1100 "Test FTBP File", -1);
1105 "20160801060101.0Z", -1);
1107 "20160801060202.0Z", -1);
1113 printf(
"failed to add X400_T_FTBP BP\n");
1116 printf(
"Sent %d bytes as X400_T_FTBP BP\n", fs);
1118 printf(
"no binary file set - not sending X400_T_FTBP\n");
1124static void usage(
void) {
1125printf(
"usage: %s\n", optstr);
1126 printf(
"\t where:\n");
1127 printf(
"\t -u : Don't prompt to override defaults \n");
1128 printf(
"\t -3 : Use P3 connection \n");
1129 printf(
"\t -7 : Use P7 connection \n");
1130 printf(
"\t -m : OR Address in P7 bind arg \n");
1131 printf(
"\t -d : DN in P7 bind arg \n");
1132 printf(
"\t -p : Presentation Address of P7 Store \n");
1133 printf(
"\t -w : P7 password of P7 user \n");
1134 printf(
"\t -M : OR Address in P3 bind arg \n");
1135 printf(
"\t -D : DN in P3 bind arg \n");
1136 printf(
"\t -P : Presentation Address of P3 server\n");
1137 printf(
"\t -W : P3 password of P3 user \n");
1138 printf(
"\t -o : Originator \n");
1139 printf(
"\t -O : Originator Return Address \n");
1140 printf(
"\t -r : Recipient\n");
1141 printf(
"\t -l : Logline\n");
1142 printf(
"\t -R : Report requests\n");
1143 printf(
"\t\t : 0 - none, 1 - non-delivery, 2 - delivery (implies 1)\n");
1144 printf(
"\t -y : Military Priority \n");
1145 printf(
"\t\t 0 - deferred, 1 - routine, 2 - priority \n");
1146 printf(
"\t\t 3 - immediate, 4 - flash, 5 - override \n");
1147 printf(
"\t -C : Content Type (2/22/772/OID) \n");
1148 printf(
"\t -i : Implicit conversion prohibited = TRUE \n");
1149 printf(
"\t -a : Alternate Recipient Prohibited = TRUE \n");
1150 printf(
"\t -q : Content Return Request = TRUE \n");
1151 printf(
"\t -s : Disclosure of Recipient = FALSE \n");
1152 printf(
"\t -A : Recipient Reassignment Prohibited = FALSE \n");
1153 printf(
"\t -v : Conversion with Loss Prohibited = FALSE \n");
1154 printf(
"\t -e : Security Environment (dir with x509 subdir): obsolete, use -Y <p12file>\n");
1155 printf(
"\t -x : DN of X.509 Digital Identity\n");
1156 printf(
"\t -b : Passphrase for private key in PKCS12 file\n");
1157 printf(
"\t -f : Filename to transfer as binary bp\n");
1158 printf(
"\t -Y : Filename of PKCS12 file containing Digital Identity\n");
1159 printf(
"\t -S : Number of bytes to put into Binary BP and FTBP (default 100)\n");
1160 printf(
"\t -j : Number of bytes to put into IA5 BP (default 100)\n");
int X400BodypartAddStrParam(struct X400Bodypart *bp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the body part.
int X400BodypartAddIntParam(struct X400Bodypart *bp, int paramtype, int value)
Add integer-valued parameter to the body part.
int X400BodypartNew(int type, struct X400Bodypart **bpp)
Create a new body part object.
int X400msMsgAddStrParam(struct X400msMessage *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msMsgAddBodypart(struct X400msMessage *mp, struct X400Bodypart *bp)
int X400msRecipAddIntParam(struct X400Recipient *rp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msMsgAddIntParam(struct X400msMessage *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msRecipNew(struct X400msMessage *mp, int type, struct X400Recipient **rpp)
Add new recipient to a message.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
int X400msRecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msTestSecurityEnv(struct X400msSession *sp)
Test the default Security Environment.
int X400msMsgSend(struct X400msMessage *mp)
Send message object.
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.
int X400msMsgAddAttachment(struct X400msMessage *mp, int type, const char *string, size_t length)
Add attachment to the message.
int X400msMsgNew(struct X400msSession *sp, int type, struct X400msMessage **mpp)
Creates new message.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
int X400msOpen(int type, const char *oraddr, const char *dirname, const char *credentials, const char *pa, int *messages, struct X400msSession **spp)
Open a session to a Message Store (P7) or MTA (P3) in synchronous mode.
#define X400_S_DIRECTORY_NAME
#define X400_S_OR_ADDRESS
#define X400_N_FTBP_OBJECT_SIZE
#define X400_S_FTBP_FILENAME
#define X400_S_FTBP_MODIFICATION_DATE
#define X400_S_FTBP_CREATION_DATE
#define X400_S_FTBP_CONTENT_DESCRIPTION
#define X400_N_PROOF_OF_DEL_REQ
#define X400_S_LOG_CONFIGURATION_FILE
#define X400_N_MMTS_PRIORITY_QUALIFIER
#define X400_S_CONTENT_IDENTIFIER
#define X400_S_EXTERNAL_CONTENT_TYPE
#define X400_N_REPORT_REQUEST
#define X400_N_NOTIFICATION_REQUEST
#define X400_N_PRECEDENCE
#define X400_RECIP_STANDARD
#define X400_N_MSGTOK_SEQ_NUM
#define X400_S_SEC_IDENTITY_DN
#define X400_B_SEC_GEN_MOAC
#define X400_B_SEC_GEN_MESSAGE_TOKEN
#define X400_B_SEC_CONTENT_INTEGRITY_CHECK
#define X400_S_SEC_IDENTITY_FILE
#define X400_S_SEC_IDENTITY
#define X400_S_SEC_IDENTITY_PASSPHRASE
X400 MA/MS (P3/P7) Interface.