Skip to content

Commit 45b8d1e

Browse files
committed
Fix file names & unnecessary parts, README
1 parent 32caf98 commit 45b8d1e

File tree

3 files changed

+24
-104
lines changed

3 files changed

+24
-104
lines changed

tls-options/README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,23 @@ Example:
125125

126126
#### Use SMTP client
127127

128-
You can use smtp OVERSSL/STARTTLS client.
128+
You can use SMTP OVER TLS or STARTTLS client.
129129

130-
Example:
130+
- SMTP OVER TLS - [RFC 8314](https://datatracker.ietf.org/doc/html/rfc8314)
131+
132+
- STARTTLS - [RFC 3207](https://datatracker.ietf.org/doc/html/rfc3207)
131133

134+
Example:
132135
```sh
133-
./client-tls-smtp-starttls <SERVER_NAME> <CERT_FILE>
136+
./client-smtp-starttls <SERVER_NAME> <CERT_FILE_PATH>
134137
```
135138

136139
```sh
137-
./client-tls-smtp-overssl <SERVER_NAME> <CERT_FILE>
140+
./client-smtp-over-tls <SERVER_NAME> <CERT_FILE_PATH>
138141
```
139142

143+
When using Gmail SMTP server (```smtp.gmail.com```), you need to configure an app password in your Google account settings.
144+
140145
## Cleaning Up
141146

142147
You can remove executable files by doing:

tls-options/client-tls-smtp-overssl.c renamed to tls-options/client-smtp-over-tls.c

+8-51
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* client-tls-smtp-overssl.c
1+
/* client-smtp-over-tls.c
22
*
33
* Copyright (C) 2006-2025 wolfSSL Inc.
44
*
@@ -38,7 +38,7 @@
3838
#include <wolfssl/wolfcrypt/coding.h>
3939

4040
/* smtp overssl commands */
41-
const char* oversslCmd[19] = {
41+
const char* oversslCmd[17] = {
4242
"220",
4343
"EHLO mail.example.com\r\n",
4444
"250",
@@ -53,8 +53,6 @@ const char* oversslCmd[19] = {
5353
"DATA\r\n",
5454
"354",
5555
"Subject: ",
56-
"To: ",
57-
"From: ",
5856
"250",
5957
"QUIT\r\n",
6058
"221"
@@ -75,7 +73,7 @@ int main(int argc, char** argv)
7573

7674
/* Check for proper calling convention */
7775
if (argc != 3) {
78-
printf("usage: %s <SERVER_NAME> <CERT_FILE>\n", argv[0]);
76+
printf("usage: %s <SERVER_NAME> <CERT_FILE PATH>\n", argv[0]);
7977
return 0;
8078
}
8179

@@ -235,7 +233,6 @@ int main(int argc, char** argv)
235233
goto cleanup;
236234
}
237235

238-
239236
/*Change the line end to CRLF */
240237
strcpy(buff+outLen-1, "\r\n");
241238

@@ -426,48 +423,8 @@ int main(int argc, char** argv)
426423
goto cleanup;
427424
}
428425

429-
/* Receiver mail address */
430-
printf("To: ");
431-
memset(buff, 0, sizeof(buff));
432-
strcpy(buff, oversslCmd[14]);
433-
if (fgets(buff+strlen(oversslCmd[14]), sizeof(buff), stdin) == NULL) {
434-
fprintf(stderr, "ERROR: failed to get message for server\n");
435-
ret = -1;
436-
goto cleanup;
437-
}
438-
439-
strcpy(buff+strlen(buff), "\r\n");
440-
441-
/* Send the receiver mail address to the server */
442-
len = strnlen(buff, sizeof(buff));
443-
if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
444-
fprintf(stderr, "ERROR: failed to send the receiver mail address.\n");
445-
fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
446-
goto cleanup;
447-
}
448-
449-
/* Sender mail address */
450-
printf("From: ");
451-
memset(buff, 0, sizeof(buff));
452-
strcpy(buff, oversslCmd[15]);
453-
if (fgets(buff+strlen(oversslCmd[15]), sizeof(buff), stdin) == NULL) {
454-
fprintf(stderr, "ERROR: failed to get message for server\n");
455-
ret = -1;
456-
goto cleanup;
457-
}
458-
459-
strcpy(buff+strlen(buff), "\r\n");
460-
461-
/* Send the sender mail address to the server */
462-
len = strnlen(buff, sizeof(buff));
463-
if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
464-
fprintf(stderr, "ERROR: failed to send the sender mail address.\n");
465-
fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
466-
goto cleanup;
467-
}
468-
469426
/* main message */
470-
printf("main message: ");
427+
printf("main message: \n");
471428
memset(buff, 0, sizeof(buff));
472429
if (fgets(buff, sizeof(buff), stdin) == NULL) {
473430
fprintf(stderr, "ERROR: failed to get message.\n");
@@ -502,7 +459,7 @@ int main(int argc, char** argv)
502459
goto cleanup;
503460
}
504461
/* Compare if the response is right code or not */
505-
if (!strncmp(buff, oversslCmd[16], strlen(oversslCmd[16]))) {
462+
if (!strncmp(buff, oversslCmd[14], strlen(oversslCmd[14]))) {
506463
printf("%s\n", buff);
507464
} else {
508465
fprintf(stderr, "ERROR: incorrect command received\n");
@@ -512,8 +469,8 @@ int main(int argc, char** argv)
512469

513470
/* Send "QUIT\r\n" to the server */
514471
memset(buff, 0, sizeof(buff));
515-
len = strlen(oversslCmd[17]);
516-
if ((ret = wolfSSL_write(ssl, oversslCmd[17], len)) != len) {
472+
len = strlen(oversslCmd[15]);
473+
if ((ret = wolfSSL_write(ssl, oversslCmd[15], len)) != len) {
517474
fprintf(stderr, "ERROR: failed to send command.\n");
518475
fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
519476
goto cleanup;
@@ -526,7 +483,7 @@ int main(int argc, char** argv)
526483
goto cleanup;
527484
}
528485
/* Compare if the response is right code or not */
529-
if (!strncmp(buff, oversslCmd[18], strlen(oversslCmd[18]))) {
486+
if (!strncmp(buff, oversslCmd[16], strlen(oversslCmd[16]))) {
530487
printf("%s\n", buff);
531488
} else {
532489
fprintf(stderr, "ERROR: incorrect command received\n");

tls-options/client-tls-smtp-starttls.c renamed to tls-options/client-smtp-starttls.c

+7-49
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* client-tls-smtp-starttls.c
1+
/* client-smtp-starttls.c
22
*
33
* Copyright (C) 2006-2025 wolfSSL Inc.
44
*
@@ -38,7 +38,7 @@
3838
#include <wolfssl/wolfcrypt/coding.h>
3939

4040
/* smtp starttls commands */
41-
const char* starttlsCmd[21] = {
41+
const char* starttlsCmd[19] = {
4242
"220",
4343
"EHLO mail.example.com\r\n",
4444
"250",
@@ -55,8 +55,6 @@ const char* starttlsCmd[21] = {
5555
"DATA\r\n",
5656
"354",
5757
"Subject: ",
58-
"To: ",
59-
"From: ",
6058
"250",
6159
"QUIT\r\n",
6260
"221"
@@ -77,7 +75,7 @@ int main(int argc, char** argv)
7775

7876
/* Check for proper calling convention */
7977
if (argc != 3) {
80-
printf("usage: %s <SERVER_NAME> <CERT_FILE>\n", argv[0]);
78+
printf("usage: %s <SERVER_NAME> <CERT_FILE_PATH>\n", argv[0]);
8179
return 0;
8280
}
8381

@@ -451,46 +449,6 @@ int main(int argc, char** argv)
451449
goto cleanup;
452450
}
453451

454-
/* Receiver mail address */
455-
printf("To: ");
456-
memset(buff, 0, sizeof(buff));
457-
strcpy(buff, starttlsCmd[16]);
458-
if (fgets(buff+strlen(starttlsCmd[16]), sizeof(buff), stdin) == NULL) {
459-
fprintf(stderr, "ERROR: failed to get message for server\n");
460-
ret = -1;
461-
goto cleanup;
462-
}
463-
464-
strcpy(buff+strlen(buff), "\r\n");
465-
466-
/* Send the receiver mail address to the server */
467-
len = strnlen(buff, sizeof(buff));
468-
if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
469-
fprintf(stderr, "ERROR: failed to send the receiver mail address.\n");
470-
fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
471-
goto cleanup;
472-
}
473-
474-
/* Sender mail address */
475-
printf("From: ");
476-
memset(buff, 0, sizeof(buff));
477-
strcpy(buff, starttlsCmd[17]);
478-
if (fgets(buff+strlen(starttlsCmd[17]), sizeof(buff), stdin) == NULL) {
479-
fprintf(stderr, "ERROR: failed to get message for server\n");
480-
ret = -1;
481-
goto cleanup;
482-
}
483-
484-
strcpy(buff+strlen(buff), "\r\n");
485-
486-
/* Send the sender mail address to the server */
487-
len = strnlen(buff, sizeof(buff));
488-
if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
489-
fprintf(stderr, "ERROR: failed to send the sender mail address.\n");
490-
fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
491-
goto cleanup;
492-
}
493-
494452
/* main message */
495453
printf("main message: ");
496454
memset(buff, 0, sizeof(buff));
@@ -527,7 +485,7 @@ int main(int argc, char** argv)
527485
goto cleanup;
528486
}
529487
/* Compare if the response is right code or not */
530-
if (!strncmp(buff, starttlsCmd[18], strlen(starttlsCmd[18]))) {
488+
if (!strncmp(buff, starttlsCmd[16], strlen(starttlsCmd[16]))) {
531489
printf("%s\n", buff);
532490
} else {
533491
fprintf(stderr, "ERROR: incorrect command received\n");
@@ -537,8 +495,8 @@ int main(int argc, char** argv)
537495

538496
/* Send "QUIT\r\n" to the server */
539497
memset(buff, 0, sizeof(buff));
540-
len = strlen(starttlsCmd[19]);
541-
if ((ret = wolfSSL_write(ssl, starttlsCmd[19], len)) != len) {
498+
len = strlen(starttlsCmd[17]);
499+
if ((ret = wolfSSL_write(ssl, starttlsCmd[17], len)) != len) {
542500
fprintf(stderr, "ERROR: failed to send command.\n");
543501
fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
544502
goto cleanup;
@@ -551,7 +509,7 @@ int main(int argc, char** argv)
551509
goto cleanup;
552510
}
553511
/* Compare if the response is right code or not */
554-
if (!strncmp(buff, starttlsCmd[20], strlen(starttlsCmd[20]))) {
512+
if (!strncmp(buff, starttlsCmd[18], strlen(starttlsCmd[18]))) {
555513
printf("%s\n", buff);
556514
} else {
557515
fprintf(stderr, "ERROR: incorrect command received\n");

0 commit comments

Comments
 (0)